@rolster/react-components 19.7.13 → 19.8.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +21 -21
  2. package/dist/cjs/index.cjs +789 -546
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/es/index.mjs +786 -548
  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 -1
  44. package/dist/esm/index.js +3 -1
  45. package/dist/esm/index.js.map +1 -1
  46. package/package.json +5 -5
  47. package/dist/esm/components/atoms/SwapHover/SwapHover.d.ts +0 -8
  48. package/dist/esm/components/atoms/SwapHover/SwapHover.js +0 -7
  49. package/dist/esm/components/atoms/SwapHover/SwapHover.js.map +0 -1
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: {}};
@@ -1255,11 +1255,6 @@ function RlsSkeletonTextComponent({ active, children, rlsTheme }) {
1255
1255
  }
1256
1256
  const RlsSkeletonText = memo(RlsSkeletonTextComponent);
1257
1257
 
1258
- function RlsSwapHoverComponent({ children, content, identifier, rlsTheme }) {
1259
- return (jsxRuntimeExports.jsxs("div", { id: identifier, className: "rls-swap-hover", "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-swap-hover__primary", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-swap-hover__secondary", children: content })] }));
1260
- }
1261
- const RlsHoverSwap = memo(RlsSwapHoverComponent);
1262
-
1263
1258
  function RlsSwitchComponent({ checked, capsule, disabled, identifier, onClick, rlsTheme }) {
1264
1259
  const className = renderClassStatus('rls-switch', {
1265
1260
  checked,
@@ -1636,6 +1631,89 @@ const reactI18n = i18n({
1636
1631
  }
1637
1632
  });
1638
1633
 
1634
+ function getScrollableAncestors(element) {
1635
+ const ancestors = [];
1636
+ let parent = element.parentElement;
1637
+ while (parent && parent !== document.body) {
1638
+ const { overflow, overflowX, overflowY } = getComputedStyle(parent);
1639
+ if (/auto|scroll|hidden/.test(`${overflow}${overflowX}${overflowY}`)) {
1640
+ ancestors.push(parent);
1641
+ }
1642
+ parent = parent.parentElement;
1643
+ }
1644
+ return ancestors;
1645
+ }
1646
+ function anchorIsVisible(rect, scrollables) {
1647
+ if (!rect.width || !rect.height) {
1648
+ return false;
1649
+ }
1650
+ let top = 0;
1651
+ let left = 0;
1652
+ let bottom = window.innerHeight;
1653
+ let right = window.innerWidth;
1654
+ for (const scrollable of scrollables) {
1655
+ const scrollableRect = scrollable.getBoundingClientRect();
1656
+ top = Math.max(top, scrollableRect.top);
1657
+ left = Math.max(left, scrollableRect.left);
1658
+ bottom = Math.min(bottom, scrollableRect.bottom);
1659
+ right = Math.min(right, scrollableRect.right);
1660
+ }
1661
+ return (rect.bottom > top &&
1662
+ rect.top < bottom &&
1663
+ rect.right > left &&
1664
+ rect.left < right);
1665
+ }
1666
+ function useSuggestionsPortalController(visible, refAnchor, onHiddenAnchor) {
1667
+ const [mounted, setMounted] = useState(false);
1668
+ const [style, setStyle] = useState();
1669
+ const [theme, setTheme] = useState();
1670
+ useEffect(() => {
1671
+ setMounted(true);
1672
+ }, []);
1673
+ const onAnchorHidden = useEffectEvent(() => {
1674
+ onHiddenAnchor?.();
1675
+ });
1676
+ useEffect(() => {
1677
+ const anchor = refAnchor?.current;
1678
+ if (!mounted || !visible || !anchor) {
1679
+ return;
1680
+ }
1681
+ setTheme((anchor.closest('[rls-theme]')?.getAttribute('rls-theme') ??
1682
+ undefined));
1683
+ const scrollables = getScrollableAncestors(anchor);
1684
+ let frame = 0;
1685
+ function reposition() {
1686
+ if (!anchor) {
1687
+ return;
1688
+ }
1689
+ const rect = anchor.getBoundingClientRect();
1690
+ if (!anchorIsVisible(rect, scrollables)) {
1691
+ onAnchorHidden();
1692
+ return;
1693
+ }
1694
+ setStyle({
1695
+ '--pvt-portal-top': `${rect.bottom}px`,
1696
+ '--pvt-portal-bottom': `${window.innerHeight - rect.top}px`,
1697
+ '--pvt-portal-left': `${rect.left}px`,
1698
+ '--pvt-portal-width': `${rect.width}px`
1699
+ });
1700
+ }
1701
+ function requestReposition() {
1702
+ cancelAnimationFrame(frame);
1703
+ frame = requestAnimationFrame(reposition);
1704
+ }
1705
+ reposition();
1706
+ window.addEventListener('scroll', requestReposition, true);
1707
+ window.addEventListener('resize', requestReposition);
1708
+ return () => {
1709
+ cancelAnimationFrame(frame);
1710
+ window.removeEventListener('scroll', requestReposition, true);
1711
+ window.removeEventListener('resize', requestReposition);
1712
+ };
1713
+ }, [mounted, visible, refAnchor]);
1714
+ return { active: mounted && !!refAnchor, style, theme };
1715
+ }
1716
+
1639
1717
  function RlsFieldListLi({ element, onClickElement, onKeydownElement, render }) {
1640
1718
  const onClick = useMemo(() => {
1641
1719
  return onClickElement(element);
@@ -1645,7 +1723,8 @@ function RlsFieldListLi({ element, onClickElement, onKeydownElement, render }) {
1645
1723
  }, [element, onKeydownElement]);
1646
1724
  return (jsxRuntimeExports.jsx("li", { className: "rls-field-list__element", tabIndex: -1, onClick: onClick, onKeyDown: onKeyDown, children: render(element) }));
1647
1725
  }
1648
- function RlsFieldListSuggestionsComponent({ elements, action, disabled, higher, render, renderEmpty, searchControl, visible, onClickBackdrop, onClickElement, onKeydownElement, refList, rlsTheme }) {
1726
+ function RlsFieldListSuggestionsComponent({ elements, action, disabled, higher, render, renderEmpty, searchControl, visible, onClickBackdrop, onClickElement, onHiddenAnchor, onKeydownElement, refAnchor, refList, refSuggestions, rlsTheme }) {
1727
+ const portal = useSuggestionsPortalController(visible, refAnchor, onHiddenAnchor);
1649
1728
  const [labels, setLabels] = useState({
1650
1729
  listEmptyDescription: reactI18n('listEmptyDescription'),
1651
1730
  listEmptyTitle: reactI18n('listEmptyTitle')
@@ -1661,6 +1740,7 @@ function RlsFieldListSuggestionsComponent({ elements, action, disabled, higher,
1661
1740
  const className = renderClassStatus('rls-field-list__suggestions', {
1662
1741
  disabled,
1663
1742
  higher,
1743
+ portal: portal.active,
1664
1744
  visible
1665
1745
  });
1666
1746
  const onChangePattern = useCallback((event) => {
@@ -1673,7 +1753,8 @@ function RlsFieldListSuggestionsComponent({ elements, action, disabled, higher,
1673
1753
  }
1674
1754
  }, [action?.onClick, action?.keepOpen, onClickBackdrop]);
1675
1755
  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 })] }));
1756
+ const suggestions = (jsxRuntimeExports.jsxs("div", { ref: refSuggestions, className: className, style: portal.active ? portal.style : undefined, "rls-theme": rlsTheme ?? portal.theme, children: [jsxRuntimeExports.jsxs("div", { className: "rls-field-list__suggestions__body", children: [jsxRuntimeExports.jsxs("ul", { ref: refList, className: "rls-field-list__ul", children: [searchControl && (jsxRuntimeExports.jsxs("div", { className: "rls-field-list__ul__search", children: [jsxRuntimeExports.jsx("input", { className: "rls-field-list__ul__control", ref: searchControl.refInput, type: "text", placeholder: searchControl.placeholder, value: searchControl.pattern, onChange: onChangePattern, onFocus: searchControl.onFocus, onBlur: searchControl.onBlur, onKeyDown: searchControl.onKeyDown, disabled: disabled || searching }), searchControl.onSearch && (jsxRuntimeExports.jsx("button", { disabled: disabled || searching, onClick: searchControl.onSearch, children: jsxRuntimeExports.jsx(RlsIcon, { value: "search" }) }))] })), searching && jsxRuntimeExports.jsx(RlsProgressBar, { indeterminate: true }), elements.map((element, index) => (jsxRuntimeExports.jsx(RlsFieldListLi, { element: element, onClickElement: onClickElement, onKeydownElement: onKeydownElement, render: render }, index))), !elements.length && (jsxRuntimeExports.jsx("li", { className: "rls-field-list__empty", children: renderEmpty ? (renderEmpty()) : (jsxRuntimeExports.jsxs("div", { className: "rls-field-list__empty__description", children: [jsxRuntimeExports.jsx("span", { className: "rls-label-font-bold rls-truncate", children: labels.listEmptyTitle }), jsxRuntimeExports.jsx("p", { className: "rls-caption-font-regular", children: labels.listEmptyDescription })] })) }))] }), action && (jsxRuntimeExports.jsx("div", { className: "rls-field-list__action", children: jsxRuntimeExports.jsxs("button", { type: "button", disabled: disabled || action.disabled, onClick: onClickAction, children: [action.icon && jsxRuntimeExports.jsx(RlsIcon, { value: action.icon }), jsxRuntimeExports.jsx("span", { className: "rls-field-list__action__description", children: action.description })] }) }))] }), jsxRuntimeExports.jsx("div", { className: "rls-field-list__backdrop", onClick: onClickBackdrop })] }));
1757
+ return portal.active ? createPortal(suggestions, document.body) : suggestions;
1677
1758
  }
1678
1759
  const RlsFieldListSuggestions = memo(RlsFieldListSuggestionsComponent);
1679
1760
 
@@ -2375,161 +2456,6 @@ function RlsCardComponent({ children, className, outline, rlsTheme }) {
2375
2456
  }
2376
2457
  const RlsCard = memo(RlsCardComponent);
2377
2458
 
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
2459
  const MAX_LIST_HEIGHT_REM$1 = 90;
2534
2460
  const FALLBACK_REM_SIZE$1 = 16;
2535
2461
  function getRemSize$1() {
@@ -2571,6 +2497,7 @@ function useListController({ suggestions, automatic, formControl, reference }) {
2571
2497
  const refContent = useRef(null);
2572
2498
  const refList = useRef(null);
2573
2499
  const refInput = useRef(null);
2500
+ const refSuggestions = useRef(null);
2574
2501
  const listIsOpen = useRef(false);
2575
2502
  const stableSuggestions = useStableSuggestions(suggestions);
2576
2503
  const collection = useMemo(() => new ListCollection(stableSuggestions, reference), [stableSuggestions, reference]);
@@ -2585,7 +2512,8 @@ function useListController({ suggestions, automatic, formControl, reference }) {
2585
2512
  const valueProtected = useRef(undefined);
2586
2513
  useEffect(() => {
2587
2514
  function onCloseSuggestions({ target }) {
2588
- if (!refContent?.current?.contains(target)) {
2515
+ if (!refContent?.current?.contains(target) &&
2516
+ !refSuggestions?.current?.contains(target)) {
2589
2517
  refreshState((state) => ({ ...state, listIsVisible: false }));
2590
2518
  }
2591
2519
  }
@@ -2602,7 +2530,29 @@ function useListController({ suggestions, automatic, formControl, reference }) {
2602
2530
  formControl?.touch();
2603
2531
  }
2604
2532
  }, [state.listIsVisible]);
2605
- useEffect(() => {
2533
+ const setState = useCallback((state) => {
2534
+ const newState = state.listIsVisible
2535
+ ? {
2536
+ ...state,
2537
+ higher: shouldDisplayHigher$1(refContent.current, refList.current)
2538
+ }
2539
+ : state;
2540
+ refreshState((currentState) => ({ ...currentState, ...newState }));
2541
+ }, []);
2542
+ const setFormValue = useCallback((element, valueIsDefault = false) => {
2543
+ refreshState((state) => ({
2544
+ ...state,
2545
+ value: element?.description || ''
2546
+ }));
2547
+ changeValueInternal.current = true;
2548
+ if (valueIsDefault) {
2549
+ formControl?.setDefaultValue(element?.value);
2550
+ }
2551
+ else {
2552
+ formControl?.setValue(element?.value);
2553
+ }
2554
+ }, [formControl]);
2555
+ const reconcileFormValue = useEffectEvent(() => {
2606
2556
  if (!changeValueInternal.current) {
2607
2557
  if (formControl?.value) {
2608
2558
  const element = collection.find(formControl.value);
@@ -2638,29 +2588,10 @@ function useListController({ suggestions, automatic, formControl, reference }) {
2638
2588
  }
2639
2589
  }
2640
2590
  changeValueInternal.current = false;
2591
+ });
2592
+ useEffect(() => {
2593
+ reconcileFormValue();
2641
2594
  }, [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
2595
  const navigationInput = useCallback((event) => {
2665
2596
  if (state.listIsVisible) {
2666
2597
  const newPosition = navigationListFromInput({
@@ -2689,6 +2620,7 @@ function useListController({ suggestions, automatic, formControl, reference }) {
2689
2620
  refContent,
2690
2621
  refInput,
2691
2622
  refList,
2623
+ refSuggestions,
2692
2624
  setFormValue,
2693
2625
  setState
2694
2626
  }), [state, navigationElement, navigationInput, setFormValue, setState]);
@@ -2850,9 +2782,9 @@ function useFieldAutocomplete(props) {
2850
2782
  ]);
2851
2783
  }
2852
2784
 
2853
- function RlsFieldAutocompleteTemplateComponent(props) {
2785
+ function RlsChooserAutocompleteTemplateComponent(props) {
2854
2786
  const autocomplete = useFieldAutocomplete(props);
2855
- const { render, action, children, formControl, msgErrorDisabled, onSearch, placeholder, rlsTheme, searching } = props;
2787
+ const { render, action, children, formControl, onSearch, rlsTheme, searching } = props;
2856
2788
  const [listInputPlaceholder, setListInputPlaceholder] = useState(reactI18n('listInputPlaceholder'));
2857
2789
  useEffect(() => {
2858
2790
  return i18nSubscribe(() => {
@@ -2865,13 +2797,11 @@ function RlsFieldAutocompleteTemplateComponent(props) {
2865
2797
  const disabled = useMemo(() => {
2866
2798
  return formControl?.disabled || props.disabled;
2867
2799
  }, [formControl?.disabled, props.disabled]);
2868
- const className = renderClassStatus('rls-field-box', {
2800
+ const className = renderClassStatus('rls-chooser', {
2869
2801
  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 ?? ''}`);
2802
+ visible: autocomplete.listIsVisible,
2803
+ disabled
2804
+ }, `rls-chooser-autocomplete ${props.className ?? ''}`);
2875
2805
  const onClickPattern = useCallback(() => {
2876
2806
  onSearch?.(autocomplete.pattern);
2877
2807
  }, [onSearch, autocomplete.pattern]);
@@ -2881,6 +2811,18 @@ function RlsFieldAutocompleteTemplateComponent(props) {
2881
2811
  }
2882
2812
  autocomplete.onKeydownInput(event);
2883
2813
  }, [autocomplete.onKeydownInput, onSearch, autocomplete.pattern]);
2814
+ const onKeydownTrigger = useCallback((event) => {
2815
+ switch (event.code) {
2816
+ case 'Space':
2817
+ case 'Enter':
2818
+ event.preventDefault();
2819
+ autocomplete.onClickControl();
2820
+ break;
2821
+ case 'Escape':
2822
+ autocomplete.onClickBackdrop();
2823
+ break;
2824
+ }
2825
+ }, [autocomplete.onClickControl, autocomplete.onClickBackdrop]);
2884
2826
  const searchControl = useMemo(() => ({
2885
2827
  pattern: autocomplete.pattern,
2886
2828
  placeholder: listInputPlaceholder,
@@ -2903,24 +2845,582 @@ function RlsFieldAutocompleteTemplateComponent(props) {
2903
2845
  onClickPattern,
2904
2846
  onSearch
2905
2847
  ]);
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) {
2848
+ return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: autocomplete.refContent, className: className, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-chooser__trigger", role: "combobox", "aria-expanded": autocomplete.listIsVisible, "aria-haspopup": "listbox", "aria-disabled": disabled || undefined, tabIndex: disabled ? -1 : 0, onClick: disabled ? undefined : autocomplete.onClickControl, onKeyDown: disabled ? undefined : onKeydownTrigger, children: typeof children === 'function'
2849
+ ? children({
2850
+ description: autocomplete.value,
2851
+ listIsVisible: autocomplete.listIsVisible,
2852
+ pattern: autocomplete.pattern,
2853
+ value: formControl?.value ?? props.value
2854
+ })
2855
+ : children }), jsxRuntimeExports.jsx(RlsFieldListSuggestions, { elements: autocomplete.coincidences, visible: autocomplete.listIsVisible, action: action, disabled: disabled, higher: autocomplete.higher, render: render, refAnchor: autocomplete.refContent, refList: autocomplete.refList, refSuggestions: autocomplete.refSuggestions, searchControl: searchControl, onClickElement: autocomplete.onClickElement, onKeydownElement: autocomplete.onKeydownElement, onClickBackdrop: autocomplete.onClickBackdrop, onHiddenAnchor: autocomplete.onClickBackdrop })] }));
2856
+ }
2857
+ const RlsChooserAutocompleteTemplate = memo(RlsChooserAutocompleteTemplateComponent);
2858
+ function RlsChooserAutocompleteComponent(props) {
2910
2859
  const render = useCallback((element) => (jsxRuntimeExports.jsx(RlsBallot, { className: "rls-field-list__ballot", subtitle: element.subtitle, img: element.img, initials: element.initials, children: jsxRuntimeExports.jsx("span", { children: element.title }) })), []);
2911
- return jsxRuntimeExports.jsx(RlsFieldAutocompleteTemplate, { ...props, render: render });
2860
+ return jsxRuntimeExports.jsx(RlsChooserAutocompleteTemplate, { ...props, render: render });
2912
2861
  }
2913
- const RlsFieldAutocomplete = memo(RlsFieldAutocompleteComponent);
2862
+ const RlsChooserAutocomplete = memo(RlsChooserAutocompleteComponent);
2914
2863
 
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);
2864
+ const MAX_LIST_HEIGHT_REM = 90;
2865
+ const FALLBACK_REM_SIZE = 16;
2866
+ function getRemSize() {
2867
+ if (typeof window === 'undefined') {
2868
+ return FALLBACK_REM_SIZE;
2869
+ }
2870
+ const fontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
2871
+ return fontSize > 0 ? fontSize : FALLBACK_REM_SIZE;
2872
+ }
2873
+ function shouldDisplayHigher(content, list) {
2874
+ if (!content) {
2875
+ return false;
2876
+ }
2877
+ const { top, bottom } = content.getBoundingClientRect();
2878
+ const spaceAbove = top;
2879
+ const spaceBelow = window.innerHeight - bottom;
2880
+ const maxHeight = MAX_LIST_HEIGHT_REM * getRemSize();
2881
+ const desiredHeight = Math.min(list?.scrollHeight || maxHeight, maxHeight);
2882
+ if (spaceBelow >= desiredHeight) {
2883
+ return false;
2884
+ }
2885
+ if (spaceAbove >= desiredHeight) {
2886
+ return true;
2887
+ }
2888
+ return spaceAbove > spaceBelow;
2889
+ }
2890
+ function useFieldList(props) {
2891
+ const { suggestions, disabled } = props;
2892
+ const refContent = useRef(null);
2893
+ const refList = useRef(null);
2894
+ const refSuggestions = useRef(null);
2895
+ const formControl = props.formControl;
2896
+ const [state, setState] = useState({
2897
+ higher: false,
2898
+ listIsVisible: false
2899
+ });
2900
+ const [selected, setSelected] = useState([]);
2901
+ useEffect(() => {
2902
+ function onCloseSuggestions({ target }) {
2903
+ if (!refContent?.current?.contains(target) &&
2904
+ !refSuggestions?.current?.contains(target)) {
2905
+ setState((state) => ({ ...state, listIsVisible: false }));
2906
+ }
2907
+ }
2908
+ document.addEventListener('click', onCloseSuggestions);
2909
+ return () => {
2910
+ document.removeEventListener('click', onCloseSuggestions);
2911
+ };
2912
+ }, []);
2913
+ useEffect(() => {
2914
+ const formValue = formControl?.value;
2915
+ if (formValue !== undefined && formValue !== null && formValue.length) {
2916
+ setSelected(suggestions.filter((state) => formValue.some((value) => state.compareTo(value))));
2917
+ }
2918
+ else {
2919
+ setSelected([]);
2920
+ }
2921
+ }, [formControl?.value, suggestions]);
2922
+ const setListState = useCallback((controllerState) => {
2923
+ setState((state) => {
2924
+ const newState = controllerState.listIsVisible !== undefined
2925
+ ? {
2926
+ ...controllerState,
2927
+ ...(controllerState.listIsVisible
2928
+ ? {
2929
+ higher: shouldDisplayHigher(refContent.current, refList.current)
2930
+ }
2931
+ : {})
2932
+ }
2933
+ : controllerState;
2934
+ return { ...state, ...newState };
2935
+ });
2936
+ }, []);
2937
+ const toggleElement = useCallback((element) => {
2938
+ const alreadySelected = selected.some((state) => state.compareTo(element.value));
2939
+ const newSelected = alreadySelected
2940
+ ? selected.filter((state) => !state.compareTo(element.value))
2941
+ : [...selected, element];
2942
+ const newValues = newSelected.map((state) => state.value);
2943
+ setSelected(newSelected);
2944
+ formControl?.setValue(newValues);
2945
+ props.onValue?.(newValues);
2946
+ }, [selected, formControl, props.onValue]);
2947
+ const isSelected = useCallback((element) => {
2948
+ return selected.some((state) => state.compareTo(element.value));
2949
+ }, [selected]);
2950
+ const onClickInput = useCallback(() => {
2951
+ if (!props.readOnly) {
2952
+ setListState({ listIsVisible: true });
2953
+ }
2954
+ }, [setListState, props.readOnly]);
2955
+ const onClickBackdrop = useCallback(() => {
2956
+ setListState({ listIsVisible: false });
2957
+ }, [setListState]);
2958
+ const onClickAction = useCallback(() => {
2959
+ if (!disabled && !props.readOnly) {
2960
+ setListState({ listIsVisible: !state.listIsVisible });
2961
+ }
2962
+ }, [disabled, props.readOnly, setListState, state.listIsVisible]);
2963
+ const onClickElement = useCallback((element) => {
2964
+ return () => {
2965
+ toggleElement(element);
2966
+ };
2967
+ }, [toggleElement]);
2968
+ const onRemoveElement = useCallback((element) => {
2969
+ return (event) => {
2970
+ event.stopPropagation();
2971
+ const newSelected = selected.filter((state) => !state.compareTo(element.value));
2972
+ const newValues = newSelected.map((state) => state.value);
2973
+ setSelected(newSelected);
2974
+ formControl?.setValue(newValues);
2975
+ props.onValue?.(newValues);
2976
+ };
2977
+ }, [selected, formControl, props.onValue]);
2978
+ const onKeydownElement = useCallback((element) => {
2979
+ return (event) => {
2980
+ if (event.code === 'Enter') {
2981
+ toggleElement(element);
2982
+ }
2983
+ };
2984
+ }, [toggleElement]);
2985
+ return useMemo(() => ({
2986
+ ...state,
2987
+ selected,
2988
+ refContent,
2989
+ refList,
2990
+ refSuggestions,
2991
+ isSelected,
2992
+ onClickAction,
2993
+ onClickBackdrop,
2994
+ onClickElement,
2995
+ onClickInput,
2996
+ onKeydownElement,
2997
+ onRemoveElement
2998
+ }), [
2999
+ state,
3000
+ selected,
3001
+ isSelected,
3002
+ onClickAction,
3003
+ onClickBackdrop,
3004
+ onClickElement,
3005
+ onClickInput,
3006
+ onKeydownElement,
3007
+ onRemoveElement
3008
+ ]);
3009
+ }
3010
+
3011
+ function RlsChooserListTemplateComponent(props) {
3012
+ const fieldList = useFieldList(props);
3013
+ const { render, suggestions, action, children, formControl, rlsTheme } = props;
3014
+ const disabled = useMemo(() => {
3015
+ return formControl?.disabled || props.disabled;
3016
+ }, [formControl?.disabled, props.disabled]);
3017
+ const className = renderClassStatus('rls-chooser', {
3018
+ visible: fieldList.listIsVisible,
3019
+ disabled
3020
+ }, `rls-chooser-list ${props.className ?? ''}`);
3021
+ const onKeydownTrigger = useCallback((event) => {
3022
+ switch (event.code) {
3023
+ case 'Space':
3024
+ case 'Enter':
3025
+ event.preventDefault();
3026
+ fieldList.onClickAction();
3027
+ break;
3028
+ case 'Escape':
3029
+ fieldList.onClickBackdrop();
3030
+ break;
3031
+ }
3032
+ }, [fieldList.onClickAction, fieldList.onClickBackdrop]);
3033
+ const renderWithCheckbox = useCallback((element) => (jsxRuntimeExports.jsxs("div", { className: "rls-field-list__multi__element", children: [jsxRuntimeExports.jsx(RlsCheckBox, { checked: fieldList.isSelected(element) }), render(element)] })), [fieldList.isSelected, render]);
3034
+ return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: fieldList.refContent, className: className, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-chooser__trigger", role: "combobox", "aria-expanded": fieldList.listIsVisible, "aria-haspopup": "listbox", "aria-disabled": disabled || undefined, tabIndex: disabled ? -1 : 0, onClick: disabled ? undefined : fieldList.onClickAction, onKeyDown: disabled ? undefined : onKeydownTrigger, children: typeof children === 'function'
3035
+ ? children({
3036
+ listIsVisible: fieldList.listIsVisible,
3037
+ selected: fieldList.selected
3038
+ })
3039
+ : children }), jsxRuntimeExports.jsx(RlsFieldListSuggestions, { elements: suggestions, visible: fieldList.listIsVisible, action: action, disabled: disabled, higher: fieldList.higher, render: renderWithCheckbox, refAnchor: fieldList.refContent, refList: fieldList.refList, refSuggestions: fieldList.refSuggestions, onClickElement: fieldList.onClickElement, onKeydownElement: fieldList.onKeydownElement, onClickBackdrop: fieldList.onClickBackdrop, onHiddenAnchor: fieldList.onClickBackdrop })] }));
3040
+ }
3041
+ const RlsChooserListTemplate = memo(RlsChooserListTemplateComponent);
3042
+ function RlsChooserListComponent(props) {
3043
+ const render = useCallback((element) => (jsxRuntimeExports.jsx(RlsBallot, { className: "rls-field-list__ballot", subtitle: element.subtitle, img: element.img, initials: element.initials, children: jsxRuntimeExports.jsx("span", { children: element.title }) })), []);
3044
+ return jsxRuntimeExports.jsx(RlsChooserListTemplate, { ...props, render: render });
3045
+ }
3046
+ const RlsChooserList = memo(RlsChooserListComponent);
3047
+
3048
+ function useFieldSelect(props) {
3049
+ const controller = useListController(props);
3050
+ useEffect(() => {
3051
+ if (props.disabled) {
3052
+ controller.setState({ focused: false });
3053
+ }
3054
+ }, [props.disabled]);
3055
+ const onFocusInput = useCallback(() => {
3056
+ controller.setState({ focused: true });
3057
+ }, [controller.setState]);
3058
+ const onBlurInput = useCallback(() => {
3059
+ controller.setState({ focused: false });
3060
+ }, [controller.setState]);
3061
+ const onClickInput = useCallback(() => {
3062
+ if (!props.readOnly) {
3063
+ controller.setState({ listIsVisible: true });
3064
+ }
3065
+ }, [controller.setState, props.readOnly]);
3066
+ const onKeydownInput = useCallback((event) => {
3067
+ switch (event.code) {
3068
+ case 'Space':
3069
+ case 'Enter':
3070
+ controller.setState({ listIsVisible: true });
3071
+ break;
3072
+ case 'Escape':
3073
+ case 'Tab':
3074
+ controller.setState({ listIsVisible: false });
3075
+ break;
3076
+ default:
3077
+ controller.navigationInput(event);
3078
+ break;
3079
+ }
3080
+ }, [controller.setState, controller.navigationInput]);
3081
+ const onClickAction = useCallback(() => {
3082
+ const removable = !props.unremovable && !!controller.value;
3083
+ if (removable) {
3084
+ controller.setState({ listIsVisible: false });
3085
+ controller.setFormValue(undefined);
3086
+ props.onValue?.(props.value);
3087
+ }
3088
+ else {
3089
+ const listIsVisible = !controller.listIsVisible;
3090
+ controller.setState({ listIsVisible });
3091
+ if (listIsVisible) {
3092
+ controller.refInput?.current?.focus();
3093
+ }
3094
+ }
3095
+ }, [
3096
+ controller.listIsVisible,
3097
+ controller.value,
3098
+ controller.setState,
3099
+ controller.setFormValue,
3100
+ props.unremovable,
3101
+ props.onValue
3102
+ ]);
3103
+ const onClickBackdrop = useCallback(() => {
3104
+ controller.setState({ listIsVisible: false });
3105
+ }, [controller.setState]);
3106
+ const onChange = useCallback((element) => {
3107
+ if (!props.disabled) {
3108
+ controller.refInput?.current?.focus();
3109
+ }
3110
+ if (props.onSelect) {
3111
+ controller.setState({ listIsVisible: false });
3112
+ if (element.value) {
3113
+ props.onSelect(element.value);
3114
+ }
3115
+ }
3116
+ else {
3117
+ controller.setFormValue(element);
3118
+ controller.setState({ listIsVisible: false });
3119
+ }
3120
+ props.onValue?.(element.value);
3121
+ }, [
3122
+ controller.setState,
3123
+ controller.setFormValue,
3124
+ props.onSelect,
3125
+ props.onValue,
3126
+ props.disabled
3127
+ ]);
3128
+ const onClickElement = useCallback((element) => {
3129
+ return () => {
3130
+ onChange(element);
3131
+ };
3132
+ }, [onChange]);
3133
+ const onKeydownElement = useCallback((element) => {
3134
+ return (event) => {
3135
+ if (event.code === 'Enter') {
3136
+ onChange(element);
3137
+ }
3138
+ else {
3139
+ controller.navigationElement(event);
3140
+ }
3141
+ };
3142
+ }, [onChange, controller.navigationElement]);
3143
+ return useMemo(() => ({
3144
+ ...controller,
3145
+ onBlurInput,
3146
+ onClickAction,
3147
+ onClickBackdrop,
3148
+ onClickInput,
3149
+ onClickElement,
3150
+ onFocusInput,
3151
+ onKeydownElement,
3152
+ onKeydownInput
3153
+ }), [
3154
+ controller,
3155
+ onBlurInput,
3156
+ onClickAction,
3157
+ onClickBackdrop,
3158
+ onClickInput,
3159
+ onClickElement,
3160
+ onFocusInput,
3161
+ onKeydownElement,
3162
+ onKeydownInput
3163
+ ]);
3164
+ }
3165
+
3166
+ function RlsChooserSelectTemplateComponent(props) {
3167
+ const select = useFieldSelect({ ...props, unremovable: true });
3168
+ const { render, suggestions, action, children, formControl, rlsTheme } = props;
3169
+ const disabled = useMemo(() => {
3170
+ return formControl?.disabled || props.disabled;
3171
+ }, [formControl?.disabled, props.disabled]);
3172
+ const className = renderClassStatus('rls-chooser', {
3173
+ focused: select.focused && !disabled,
3174
+ visible: select.listIsVisible,
3175
+ disabled
3176
+ }, `rls-chooser-select ${props.className ?? ''}`);
3177
+ const onKeydownTrigger = useCallback((event) => {
3178
+ if (event.code === 'Space') {
3179
+ event.preventDefault();
3180
+ }
3181
+ select.onKeydownInput(event);
3182
+ }, [select.onKeydownInput]);
3183
+ return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: select.refContent, className: className, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-chooser__trigger", role: "combobox", "aria-expanded": select.listIsVisible, "aria-haspopup": "listbox", "aria-disabled": disabled || undefined, tabIndex: disabled ? -1 : 0, onClick: disabled ? undefined : select.onClickAction, onKeyDown: disabled ? undefined : onKeydownTrigger, onFocus: select.onFocusInput, onBlur: select.onBlurInput, children: typeof children === 'function'
3184
+ ? children({
3185
+ description: select.value,
3186
+ listIsVisible: select.listIsVisible,
3187
+ value: formControl?.value ?? props.value
3188
+ })
3189
+ : children }), jsxRuntimeExports.jsx(RlsFieldListSuggestions, { elements: suggestions, visible: select.listIsVisible, action: action, disabled: disabled, higher: select.higher, render: render, refAnchor: select.refContent, refList: select.refList, refSuggestions: select.refSuggestions, onClickElement: select.onClickElement, onKeydownElement: select.onKeydownElement, onClickBackdrop: select.onClickBackdrop, onHiddenAnchor: select.onClickBackdrop })] }));
3190
+ }
3191
+ const RlsChooserSelectTemplate = memo(RlsChooserSelectTemplateComponent);
3192
+ function RlsChooserSelectComponent(props) {
3193
+ const render = useCallback((element) => (jsxRuntimeExports.jsx(RlsBallot, { className: "rls-field-list__ballot", subtitle: element.subtitle, img: element.img, initials: element.initials, children: jsxRuntimeExports.jsx("span", { children: element.title }) })), []);
3194
+ return jsxRuntimeExports.jsx(RlsChooserSelectTemplate, { ...props, render: render });
3195
+ }
3196
+ const RlsChooserSelect = memo(RlsChooserSelectComponent);
3197
+
3198
+ class ConfirmationResult extends SealedPartial {
3199
+ static approved() {
3200
+ return new ConfirmationResult('approved');
3201
+ }
3202
+ static reject() {
3203
+ return new ConfirmationResult('reject');
3204
+ }
3205
+ }
3206
+ function RlsConfirmationComponent({ approved, className, content, reject, rlsTheme, subtitle, title, visible }) {
3207
+ const classConfirmation = renderClassStatus('rls-confirmation', { visible }, className);
3208
+ return (jsxRuntimeExports.jsxs("div", { className: classConfirmation, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: "rls-confirmation__component", children: [jsxRuntimeExports.jsxs("div", { className: "rls-confirmation__header", children: [title && jsxRuntimeExports.jsx("div", { className: "rls-confirmation__title", children: title }), subtitle && (jsxRuntimeExports.jsx("div", { className: "rls-confirmation__subtitle", children: subtitle }))] }), jsxRuntimeExports.jsx("div", { className: "rls-confirmation__body", children: content && (jsxRuntimeExports.jsx("div", { className: "rls-confirmation__content", children: content })) }), (approved || reject) && (jsxRuntimeExports.jsx("div", { className: "rls-confirmation__footer", children: jsxRuntimeExports.jsxs("div", { className: "rls-confirmation__actions", children: [approved && (jsxRuntimeExports.jsx(RlsButton, { identifier: approved.identifier, type: approved.type, onClick: approved.onClick, disabled: approved.disabled, rlsTheme: approved.rlsTheme, children: approved.label })), reject && (jsxRuntimeExports.jsx(RlsButton, { identifier: reject.identifier, type: reject.type, onClick: reject.onClick, disabled: reject.disabled, rlsTheme: reject.rlsTheme, children: reject.label }))] }) }))] }), jsxRuntimeExports.jsx("div", { className: "rls-confirmation__backdrop" })] }));
3209
+ }
3210
+ const RlsConfirmation = memo(RlsConfirmationComponent);
3211
+ const RlsConfirmationBase = RlsConfirmation;
3212
+ function useConfirmation() {
3213
+ const [config, setConfig] = useState({});
3214
+ const [visible, setVisible] = useState(false);
3215
+ const configRef = useRef(config);
3216
+ configRef.current = config;
3217
+ const visibleRef = useRef(visible);
3218
+ visibleRef.current = visible;
3219
+ const RlsConfirmation = useMemo(() => {
3220
+ return function RlsConfirmation(props) {
3221
+ return ReactDOM.createPortal(jsxRuntimeExports.jsx(RlsConfirmationBase, { ...props, ...configRef.current, visible: visibleRef.current }), document.body);
3222
+ };
3223
+ }, []);
3224
+ const confirmation = useCallback((options) => {
3225
+ return new Promise((resolve) => {
3226
+ setConfig({
3227
+ ...options,
3228
+ approved: {
3229
+ label: options.approved?.label ?? reactI18n('confirmationActionApproved'),
3230
+ onClick: () => {
3231
+ setVisible(false);
3232
+ resolve(ConfirmationResult.approved());
3233
+ },
3234
+ type: options.approved?.type ?? 'raised',
3235
+ disabled: options.approved?.disabled,
3236
+ identifier: options.approved?.identifier,
3237
+ rlsTheme: options.approved?.rlsTheme
3238
+ },
3239
+ reject: options.reject
3240
+ ? {
3241
+ label: options.reject.label,
3242
+ onClick: () => {
3243
+ setVisible(false);
3244
+ resolve(ConfirmationResult.reject());
3245
+ },
3246
+ type: options.reject.type ?? 'flat',
3247
+ disabled: options.reject.disabled,
3248
+ identifier: options.reject.identifier,
3249
+ rlsTheme: options.reject.rlsTheme
3250
+ }
3251
+ : undefined
3252
+ });
3253
+ setVisible(true);
3254
+ });
3255
+ }, []);
3256
+ return {
3257
+ confirmation,
3258
+ RlsConfirmation
3259
+ };
3260
+ }
3261
+
3262
+ function createObserver(options) {
3263
+ const { setScrolleable, table } = options;
3264
+ const observer = new ResizeObserver(() => {
3265
+ const scrollHeight = table.scrollHeight || 0;
3266
+ const clientHeight = table.clientHeight || 0;
3267
+ setScrolleable(scrollHeight > clientHeight);
3268
+ });
3269
+ observer.observe(table);
3270
+ return observer;
3271
+ }
3272
+ function useDatatable(table) {
3273
+ const [scrolleable, setScrolleable] = useState(false);
3274
+ const refTable = useRef(table ? table : null);
3275
+ useEffect(() => {
3276
+ const observer = refTable.current &&
3277
+ createObserver({ setScrolleable, table: refTable.current });
3278
+ return () => {
3279
+ observer?.disconnect();
3280
+ };
3281
+ }, []);
3282
+ return { refTable, scrolleable };
3283
+ }
3284
+
3285
+ function RlsDatatableComponent({ children, footer, header, identifier, rlsTheme, resizable, summary, table, toolbar }) {
3286
+ const datatable = useDatatable(table);
3287
+ const className = renderClassStatus('rls-datatable', {
3288
+ resizable,
3289
+ scrolleable: resizable && datatable?.scrolleable
3290
+ });
3291
+ return (jsxRuntimeExports.jsxs("div", { className: className, "rls-theme": rlsTheme, children: [toolbar && jsxRuntimeExports.jsx("div", { className: "rls-datatable__toolbar", children: toolbar }), jsxRuntimeExports.jsx("div", { className: "rls-datatable__table", children: jsxRuntimeExports.jsxs("table", { id: identifier, children: [header && jsxRuntimeExports.jsx("thead", { className: "rls-datatable__head", children: header }), jsxRuntimeExports.jsx("tbody", { ref: datatable?.refTable, className: "rls-datatable__body", children: children })] }) }), summary && jsxRuntimeExports.jsx("div", { className: "rls-datatable__summary", children: summary }), footer && jsxRuntimeExports.jsx("div", { className: "rls-datatable__footer", children: footer })] }));
3292
+ }
3293
+ const RlsDatatable = memo(RlsDatatableComponent);
3294
+ function RlsDatatableHeaderComponent({ children, identifier, rlsTheme }) {
3295
+ return (jsxRuntimeExports.jsx("tr", { id: identifier, className: "rls-datatable__header", "rls-theme": rlsTheme, children: children }));
3296
+ }
3297
+ const RlsDatatableHeader = memo(RlsDatatableHeaderComponent);
3298
+ function RlsDatatableTitleComponent({ actions, children, className, control, identifier, rlsTheme, truncated }) {
3299
+ const classNameTitle = renderClassStatus('rls-datatable__title', { actions, control, truncated }, className);
3300
+ return (jsxRuntimeExports.jsx("th", { id: identifier, className: classNameTitle, "rls-theme": rlsTheme, children: children }));
3301
+ }
3302
+ const RlsDatatableTitle = memo(RlsDatatableTitleComponent);
3303
+ function RlsDatatableSubheaderComponent({ children, className, identifier, rlsTheme }) {
3304
+ const classNameSubheader = renderClassStatus('rls-datatable__subheader', {}, className);
3305
+ return (jsxRuntimeExports.jsx("tr", { id: identifier, className: classNameSubheader, "rls-theme": rlsTheme, children: children }));
3306
+ }
3307
+ const RlsDatatableSubheader = memo(RlsDatatableSubheaderComponent);
3308
+ function RlsDatatableRecordComponent({ children, className, error, identifier, info, rlsTheme, success, truncated, warning }) {
3309
+ const classNameRecord = renderClassStatus('rls-datatable__record', { error, info, truncated, success, warning }, className);
3310
+ return (jsxRuntimeExports.jsx("tr", { id: identifier, className: classNameRecord, "rls-theme": rlsTheme, children: children }));
3311
+ }
3312
+ const RlsDatatableRecord = memo(RlsDatatableRecordComponent);
3313
+ function RlsDatatableTotalsComponent({ children, className, error, identifier, info, rlsTheme, success, truncated, warning }) {
3314
+ const classNameTotals = renderClassStatus('rls-datatable__totals', { error, info, truncated, success, warning }, className);
3315
+ return (jsxRuntimeExports.jsx("div", { id: identifier, className: classNameTotals, "rls-theme": rlsTheme, children: children }));
3316
+ }
3317
+ const RlsDatatableTotals = memo(RlsDatatableTotalsComponent);
3318
+ function RlsDatatableCellComponent({ actions, children, className, control, identifier, rlsTheme, truncated }) {
3319
+ const classNameCell = renderClassStatus('rls-datatable__cell', { actions, control, truncated }, className);
3320
+ return (jsxRuntimeExports.jsx("td", { id: identifier, className: classNameCell, "rls-theme": rlsTheme, children: children }));
3321
+ }
3322
+ const RlsDatatableCell = memo(RlsDatatableCellComponent);
3323
+ function RlsDatatableDataComponent({ actions, children, className, control, identifier, truncated }) {
3324
+ const classNameData = renderClassStatus('rls-datatable__data', { actions, control, truncated }, className);
3325
+ return (jsxRuntimeExports.jsx("div", { id: identifier, className: classNameData, children: children }));
3326
+ }
3327
+ const RlsDatatableData = memo(RlsDatatableDataComponent);
3328
+ function RlsDatatableFloatingComponent({ children, className, identifier, invested, rlsTheme }) {
3329
+ const classNameFloating = renderClassStatus('rls-datatable__floating', { invested }, className);
3330
+ return (jsxRuntimeExports.jsx("td", { id: identifier, className: classNameFloating, "rls-theme": rlsTheme, children: children }));
3331
+ }
3332
+ const RlsDatatableFloating = memo(RlsDatatableFloatingComponent);
3333
+
3334
+ function RlsDropdownComponent({ children, controller, rlsTheme }) {
3335
+ const className = renderClassStatus('rls-dropdown', {
3336
+ visible: controller.visible
3337
+ });
3338
+ useEffect(() => {
3339
+ function onCloseDropdown({ target }) {
3340
+ if (!controller.component.current.contains(target)) {
3341
+ controller.close();
3342
+ }
3343
+ }
3344
+ document.addEventListener('click', onCloseDropdown);
3345
+ return () => {
3346
+ document.removeEventListener('click', onCloseDropdown);
3347
+ };
3348
+ }, []);
3349
+ return (jsxRuntimeExports.jsx("div", { ref: controller.component, className: className, "rls-theme": rlsTheme, children: jsxRuntimeExports.jsx("div", { className: "rls-dropdown__content", children: children }) }));
3350
+ }
3351
+ const RlsDropdown = memo(RlsDropdownComponent);
3352
+
3353
+ function RlsFieldAutocompleteTemplateComponent(props) {
3354
+ const autocomplete = useFieldAutocomplete(props);
3355
+ const { render, action, children, formControl, msgErrorDisabled, onSearch, placeholder, rlsTheme, searching } = props;
3356
+ const [listInputPlaceholder, setListInputPlaceholder] = useState(reactI18n('listInputPlaceholder'));
3357
+ useEffect(() => {
3358
+ return i18nSubscribe(() => {
3359
+ setListInputPlaceholder(reactI18n('listInputPlaceholder'));
3360
+ });
3361
+ }, []);
3362
+ useEffect(() => {
3363
+ props.onInput?.(autocomplete.pattern);
3364
+ }, [autocomplete.pattern, props.onInput]);
3365
+ const disabled = useMemo(() => {
3366
+ return formControl?.disabled || props.disabled;
3367
+ }, [formControl?.disabled, props.disabled]);
3368
+ const className = renderClassStatus('rls-field-box', {
3369
+ focused: autocomplete.focused && !disabled,
3370
+ error: formControl?.wrong,
3371
+ disabled,
3372
+ readonly: props.readOnly,
3373
+ selected: !!autocomplete.value
3374
+ }, `rls-field-list rls-field-autocomplete ${props.className ?? ''}`);
3375
+ const onClickPattern = useCallback(() => {
3376
+ onSearch?.(autocomplete.pattern);
3377
+ }, [onSearch, autocomplete.pattern]);
3378
+ const onKeyDownPattern = useCallback((event) => {
3379
+ if (event.key === 'Enter') {
3380
+ onSearch?.(autocomplete.pattern);
3381
+ }
3382
+ autocomplete.onKeydownInput(event);
3383
+ }, [autocomplete.onKeydownInput, onSearch, autocomplete.pattern]);
3384
+ const searchControl = useMemo(() => ({
3385
+ pattern: autocomplete.pattern,
3386
+ placeholder: listInputPlaceholder,
3387
+ searching,
3388
+ refInput: autocomplete.refInput,
3389
+ onChange: autocomplete.setPattern,
3390
+ onFocus: autocomplete.onFocusInput,
3391
+ onBlur: autocomplete.onBlurInput,
3392
+ onKeyDown: onKeyDownPattern,
3393
+ onSearch: onSearch ? onClickPattern : undefined
3394
+ }), [
3395
+ autocomplete.pattern,
3396
+ autocomplete.refInput,
3397
+ autocomplete.setPattern,
3398
+ autocomplete.onFocusInput,
3399
+ autocomplete.onBlurInput,
3400
+ listInputPlaceholder,
3401
+ searching,
3402
+ onKeyDownPattern,
3403
+ onClickPattern,
3404
+ onSearch
3405
+ ]);
3406
+ return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: autocomplete.refContent, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { className: "rls-field-list__control", readOnly: true, disabled: disabled, placeholder: placeholder, value: autocomplete.value, onClick: autocomplete.onClickControl }), !props.readOnly && !disabled && (jsxRuntimeExports.jsx(RlsButtonIcon, { icon: autocomplete.value ? 'trash-2' : 'arrow-ios-down', onClick: autocomplete.onClickAction }))] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl })), jsxRuntimeExports.jsx(RlsFieldListSuggestions, { elements: autocomplete.coincidences, visible: autocomplete.listIsVisible, action: action, disabled: disabled, higher: autocomplete.higher, render: render, refAnchor: autocomplete.refContent, refList: autocomplete.refList, refSuggestions: autocomplete.refSuggestions, searchControl: searchControl, onClickElement: autocomplete.onClickElement, onKeydownElement: autocomplete.onKeydownElement, onClickBackdrop: autocomplete.onClickBackdrop, onHiddenAnchor: autocomplete.onClickBackdrop })] }));
3407
+ }
3408
+ const RlsFieldAutocompleteTemplate = memo(RlsFieldAutocompleteTemplateComponent);
3409
+ function RlsFieldAutocompleteComponent(props) {
3410
+ const render = useCallback((element) => (jsxRuntimeExports.jsx(RlsBallot, { className: "rls-field-list__ballot", subtitle: element.subtitle, img: element.img, initials: element.initials, children: jsxRuntimeExports.jsx("span", { children: element.title }) })), []);
3411
+ return jsxRuntimeExports.jsx(RlsFieldAutocompleteTemplate, { ...props, render: render });
3412
+ }
3413
+ const RlsFieldAutocomplete = memo(RlsFieldAutocompleteComponent);
3414
+
3415
+ function RlsModalComponent({ autoclose, children, className, controller, onBackdrop, visible, rlsTheme }) {
3416
+ const classNameModal = renderClassStatus('rls-modal', { visible: controller?.visible ?? visible }, className);
3417
+ const onClickBackdrop = useCallback(() => {
3418
+ if (autoclose) {
3419
+ controller?.close();
3420
+ }
3421
+ onBackdrop?.();
3422
+ }, [autoclose, controller, onBackdrop]);
3423
+ return ReactDOM.createPortal(jsxRuntimeExports.jsxs("div", { className: classNameModal, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-modal__component", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-modal__backdrop", onClick: onClickBackdrop })] }), document.body);
2924
3424
  }
2925
3425
  const RlsModal = memo(RlsModalComponent);
2926
3426
 
@@ -3695,192 +4195,48 @@ function RlsFieldDateRangeComponent({ children, date, disabled: disabledProps, f
3695
4195
  const disabled = useMemo(() => {
3696
4196
  return formControl?.disabled || disabledProps;
3697
4197
  }, [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);
4198
+ const className = renderClassStatus('rls-field-box', {
4199
+ disabled,
4200
+ readonly: readOnly
4201
+ });
4202
+ const dateRangeValue = useMemo(() => {
4203
+ return formControl ? formControl.value : value;
4204
+ }, [formControl?.value, value]);
4205
+ const status = useMemo(() => {
4206
+ return {
4207
+ icon: dateRangeValue ? 'trash-2' : 'calendar',
4208
+ valueInput: dateRangeValue ? rangeFormatTemplate(dateRangeValue) : ''
3786
4209
  };
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]);
4210
+ }, [dateRangeValue]);
3825
4211
  const onClickInput = useCallback(() => {
3826
- if (!props.readOnly) {
3827
- setListState({ listIsVisible: true });
4212
+ if (!readOnly) {
4213
+ setModalIsVisible(true);
3828
4214
  }
3829
- }, [setListState, props.readOnly]);
3830
- const onClickBackdrop = useCallback(() => {
3831
- setListState({ listIsVisible: false });
3832
- }, [setListState]);
4215
+ }, [readOnly]);
4216
+ const onChange = useCallback((value) => {
4217
+ setValue(value);
4218
+ onValue?.(value);
4219
+ }, [onValue]);
3833
4220
  const onClickAction = useCallback(() => {
3834
- if (!disabled && !props.readOnly) {
3835
- setListState({ listIsVisible: !state.listIsVisible });
4221
+ if (dateRangeValue) {
4222
+ formControl?.setValue(valueInitial);
4223
+ formControl?.touch();
4224
+ onChange(valueInitial);
3836
4225
  }
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
- ]);
4226
+ else {
4227
+ setModalIsVisible(true);
4228
+ }
4229
+ }, [dateRangeValue, formControl, valueInitial, onChange]);
4230
+ const onCloseModal = useCallback((dateRange) => {
4231
+ if (dateRange) {
4232
+ onChange(dateRange);
4233
+ }
4234
+ formControl?.touch();
4235
+ setModalIsVisible(false);
4236
+ }, [formControl, onChange]);
4237
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: "rls-field-date-range", "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: className, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { className: "rls-field-date-range__control", type: "text", value: status.valueInput, readOnly: true, placeholder: placeholder, onClick: onClickInput, disabled: disabled }), !readOnly && !disabled && (jsxRuntimeExports.jsx(RlsButtonIcon, { icon: status.icon, onClick: onClickAction }))] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }), jsxRuntimeExports.jsx(RlsModalDateRange, { visible: modalIsVisible, formControl: formControl, date: currentDate, disabled: disabled, maxDate: maxDate, minDate: minDate, onClose: onCloseModal, rlsTheme: rlsTheme })] }));
3883
4238
  }
4239
+ const RlsFieldDateRange = memo(RlsFieldDateRangeComponent);
3884
4240
 
3885
4241
  function RlsFieldListInner({ render, suggestions, action, children, formControl, fieldList, msgErrorDisabled, placeholder, rlsTheme, ...props }) {
3886
4242
  const disabled = useMemo(() => {
@@ -3893,7 +4249,7 @@ function RlsFieldListInner({ render, suggestions, action, children, formControl,
3893
4249
  readonly: props.readOnly
3894
4250
  }, `rls-field-list rls-field-list__multi ${props.className ?? ''}`);
3895
4251
  const renderWithCheckbox = useCallback((element) => (jsxRuntimeExports.jsxs("div", { className: "rls-field-list__multi__element", children: [jsxRuntimeExports.jsx(RlsCheckBox, { checked: fieldList.isSelected(element) }), render(element)] })), [fieldList.isSelected, render]);
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 })] }));
4252
+ return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: fieldList.refContent, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("div", { className: "rls-field-list__multi__chips", onClick: disabled ? undefined : fieldList.onClickInput, children: !fieldList.selected.length && placeholder ? (jsxRuntimeExports.jsx("span", { className: "rls-field-list__multi__placeholder", children: placeholder })) : (fieldList.selected.map((item, index) => (jsxRuntimeExports.jsxs("div", { className: "rls-field-list__multi__chip", children: [jsxRuntimeExports.jsx("span", { className: "rls-field-list__multi__chip__description", children: item.description }), !props.readOnly && !disabled && (jsxRuntimeExports.jsx("button", { className: "rls-field-list__multi__chip__remove", onClick: fieldList.onRemoveElement(item), children: jsxRuntimeExports.jsx(RlsIcon, { value: "close" }) }))] }, index)))) }), !props.readOnly && !disabled && (jsxRuntimeExports.jsx(RlsButtonIcon, { icon: "arrow-ios-down", onClick: fieldList.onClickAction }))] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl })), jsxRuntimeExports.jsx(RlsFieldListSuggestions, { elements: suggestions, visible: fieldList.listIsVisible, action: action, disabled: disabled, higher: fieldList.higher, render: renderWithCheckbox, refAnchor: fieldList.refContent, refList: fieldList.refList, refSuggestions: fieldList.refSuggestions, onClickElement: fieldList.onClickElement, onKeydownElement: fieldList.onKeydownElement, onClickBackdrop: fieldList.onClickBackdrop, onHiddenAnchor: fieldList.onClickBackdrop })] }));
3897
4253
  }
3898
4254
  function RlsFieldListTemplateComponent(props) {
3899
4255
  const fieldList = useFieldList(props);
@@ -3907,124 +4263,6 @@ function RlsFieldListComponent(props) {
3907
4263
  }
3908
4264
  const RlsFieldList = memo(RlsFieldListComponent);
3909
4265
 
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
4266
  function RlsFieldSelectTemplateComponent(props) {
4029
4267
  const select = useFieldSelect(props);
4030
4268
  const { render, suggestions, action, children, formControl, msgErrorDisabled, placeholder, rlsTheme, unremovable } = props;
@@ -4037,7 +4275,7 @@ function RlsFieldSelectTemplateComponent(props) {
4037
4275
  disabled: disabled,
4038
4276
  readonly: props.readOnly
4039
4277
  }, `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 })] }));
4278
+ return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: select.refContent, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { ref: select.refInput, className: "rls-field-list__control", readOnly: true, placeholder: placeholder, value: select.value, onFocus: select.onFocusInput, onBlur: select.onBlurInput, onClick: select.onClickInput, onKeyDown: select.onKeydownInput, disabled: disabled }), !props.readOnly && !disabled && (jsxRuntimeExports.jsx(RlsButtonIcon, { icon: !unremovable && !!select.value ? 'close' : 'arrow-ios-down', onClick: select.onClickAction }))] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl })), jsxRuntimeExports.jsx(RlsFieldListSuggestions, { elements: suggestions, visible: select.listIsVisible, action: action, disabled: disabled, higher: select.higher, render: render, refAnchor: select.refContent, refList: select.refList, refSuggestions: select.refSuggestions, onClickElement: select.onClickElement, onKeydownElement: select.onKeydownElement, onClickBackdrop: select.onClickBackdrop, onHiddenAnchor: select.onClickBackdrop })] }));
4041
4279
  }
4042
4280
  const RlsFieldSelectTemplate = memo(RlsFieldSelectTemplateComponent);
4043
4281
  function RlsFieldSelectComponent(props) {
@@ -4052,54 +4290,56 @@ function RlsFormNavigationComponent({ children, className, controller, visible,
4052
4290
  }
4053
4291
  const RlsFormNavigation = memo(RlsFormNavigationComponent);
4054
4292
 
4055
- function useRelocationOnComponent({ container, element, onDrag }) {
4293
+ function useRelocationOnComponent({ container: containerRef, element: elementRef, onDrag }) {
4056
4294
  const position = useRef({ x: 0, y: 0 });
4057
4295
  const dragOffset = useRef({ x: 0, y: 0 });
4058
4296
  const dragging = useRef(false);
4059
- const getClientX = useCallback((positionX) => {
4297
+ function getClientX(positionX) {
4060
4298
  let clientX = position.current.x + positionX - dragOffset.current.x;
4061
4299
  if (clientX < 0) {
4062
4300
  clientX = 0;
4063
4301
  }
4064
4302
  else {
4065
- const width = clientX + element.current.offsetWidth;
4066
- if (width > container.current.offsetWidth) {
4067
- clientX = container.current.offsetWidth - element.current.offsetWidth;
4303
+ const width = clientX + elementRef.current.offsetWidth;
4304
+ if (width > containerRef.current.offsetWidth) {
4305
+ clientX =
4306
+ containerRef.current.offsetWidth - elementRef.current.offsetWidth;
4068
4307
  }
4069
4308
  }
4070
4309
  return clientX;
4071
- }, []);
4072
- const getClientY = useCallback((positionY) => {
4310
+ }
4311
+ function getClientY(positionY) {
4073
4312
  let clientY = position.current.y + positionY - dragOffset.current.y;
4074
4313
  if (clientY < 0) {
4075
4314
  clientY = 0;
4076
4315
  }
4077
4316
  else {
4078
- const height = clientY + element.current.offsetHeight;
4079
- if (height > container.current.offsetHeight) {
4080
- clientY = container.current.offsetHeight - element.current.offsetHeight;
4317
+ const height = clientY + elementRef.current.offsetHeight;
4318
+ if (height > containerRef.current.offsetHeight) {
4319
+ clientY =
4320
+ containerRef.current.offsetHeight - elementRef.current.offsetHeight;
4081
4321
  }
4082
4322
  }
4083
4323
  return clientY;
4084
- }, []);
4085
- const start = useCallback((positionX, positionY) => {
4324
+ }
4325
+ const start = useEffectEvent((positionX, positionY) => {
4086
4326
  dragOffset.current = {
4087
4327
  x: positionX,
4088
4328
  y: positionY
4089
4329
  };
4090
4330
  position.current = {
4091
- x: element.current.offsetLeft,
4092
- y: element.current.offsetTop
4331
+ x: elementRef.current.offsetLeft,
4332
+ y: elementRef.current.offsetTop
4093
4333
  };
4094
4334
  dragging.current = true;
4095
- }, []);
4096
- const relocation = useCallback((positionX, positionY) => {
4335
+ });
4336
+ const relocation = useEffectEvent((positionX, positionY) => {
4097
4337
  const clientX = getClientX(positionX);
4098
4338
  const clientY = getClientY(positionY);
4099
- element.current.style.top = `${clientY}px`;
4100
- element.current.style.left = `${clientX}px`;
4339
+ elementRef.current.style.top = `${clientY}px`;
4340
+ elementRef.current.style.left = `${clientX}px`;
4101
4341
  onDrag?.();
4102
- }, []);
4342
+ });
4103
4343
  useEffect(() => {
4104
4344
  const mousedown = (event) => {
4105
4345
  start(event.clientX, event.clientY);
@@ -4127,30 +4367,28 @@ function useRelocationOnComponent({ container, element, onDrag }) {
4127
4367
  const touchend = () => {
4128
4368
  dragging.current = false;
4129
4369
  };
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);
4370
+ elementRef.current.addEventListener('mousedown', mousedown);
4371
+ elementRef.current.addEventListener('mousemove', mousemove);
4372
+ elementRef.current.addEventListener('mouseup', mouseup);
4373
+ elementRef.current.addEventListener('touchstart', touchstart);
4374
+ elementRef.current.addEventListener('touchmove', touchmove);
4375
+ elementRef.current.addEventListener('touchend', touchend);
4136
4376
  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);
4377
+ elementRef.current?.removeEventListener('mousedown', mousedown);
4378
+ elementRef.current?.removeEventListener('mousemove', mousemove);
4379
+ elementRef.current?.removeEventListener('mouseup', mouseup);
4380
+ elementRef.current?.removeEventListener('touchstart', touchstart);
4381
+ elementRef.current?.removeEventListener('touchmove', touchmove);
4382
+ elementRef.current?.removeEventListener('touchend', touchend);
4143
4383
  };
4144
4384
  }, []);
4145
4385
  }
4146
4386
 
4147
4387
  function useResize({ refElement, onResize }) {
4148
4388
  const dimension = useRef({ height: 0, width: 0 });
4149
- const onResizeRef = useRef(onResize);
4150
- onResizeRef.current = onResize;
4151
- const observer = useCallback((entries) => {
4389
+ const observer = useEffectEvent((entries) => {
4152
4390
  const { height, width } = entries[0].contentRect;
4153
- onResizeRef.current?.({
4391
+ onResize?.({
4154
4392
  current: dimension.current,
4155
4393
  dimension: {
4156
4394
  height,
@@ -4158,13 +4396,13 @@ function useResize({ refElement, onResize }) {
4158
4396
  }
4159
4397
  });
4160
4398
  dimension.current = { height, width };
4161
- }, []);
4399
+ });
4162
4400
  useEffect(() => {
4163
4401
  dimension.current = {
4164
4402
  height: refElement.current.offsetHeight,
4165
4403
  width: refElement.current.offsetWidth
4166
4404
  };
4167
- const resizeObserver = new ResizeObserver(observer);
4405
+ const resizeObserver = new ResizeObserver((entries) => observer(entries));
4168
4406
  resizeObserver.observe(refElement.current);
4169
4407
  return () => {
4170
4408
  resizeObserver.disconnect();
@@ -4829,5 +5067,5 @@ function toggleAppTheme() {
4829
5067
  return theme;
4830
5068
  }
4831
5069
 
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 };
5070
+ export { ConfirmationResult, DEFAULT_COLOR, RlsAccordion, RlsAlert, RlsAmount, RlsApplication, RlsAreaText, RlsAvatar, RlsBadge, RlsBallot, RlsBody, RlsBottomSheet, RlsBreadcrumb, RlsButton, RlsButtonAction, RlsButtonIcon, RlsButtonOption, RlsButtonProgress, RlsButtonStepper, RlsButtonToggle, RlsCard, RlsCheckBox, RlsCheckBoxControl, RlsChooserAutocomplete, RlsChooserAutocompleteTemplate, RlsChooserList, RlsChooserListTemplate, RlsChooserSelect, RlsChooserSelectTemplate, RlsConfirmation, RlsContent, RlsContext, RlsDatatable, RlsDatatableCell, RlsDatatableData, RlsDatatableFloating, RlsDatatableHeader, RlsDatatableRecord, RlsDatatableSubheader, RlsDatatableTitle, RlsDatatableTotals, RlsDropdown, RlsFieldArea, RlsFieldAutocomplete, RlsFieldAutocompleteTemplate, RlsFieldClock, RlsFieldColor, RlsFieldDate, RlsFieldDateRange, RlsFieldDecimal, RlsFieldFile, RlsFieldList, RlsFieldListSuggestions, RlsFieldListTemplate, RlsFieldMoney, RlsFieldNumber, RlsFieldPassword, RlsFieldPercentage, RlsFieldReadonly, RlsFieldSelect, RlsFieldSelectTemplate, RlsFieldText, RlsFormNavigation, RlsIcon, RlsImage, RlsImageChooser, RlsImageEditor, RlsInput, RlsInputCounter, RlsInputDecimal, RlsInputMoney, RlsInputNumber, RlsInputPassword, RlsInputPercentage, RlsInputSearch, RlsInputText, RlsLabel, RlsLabelCheckBox, RlsLabelRadioButton, RlsLabelSwitch, RlsLed, RlsMessageEmpty, RlsMessageFormError, RlsMessageIcon, RlsModal, RlsModalClock, RlsModalDate, RlsModalDateRange, RlsModalSheet, RlsNavbar, RlsNavbarMenu, RlsPagination, RlsPickerClock, RlsPickerColor, RlsPickerDate, RlsPickerDateRange, RlsPickerDay, RlsPickerDayRange, RlsPickerMonth, RlsPickerSelectorTitle, RlsPickerYear, RlsPoster, RlsProgressBar, RlsProgressCircular, RlsRadioButton, RlsSkeleton, RlsSkeletonText, RlsSlider, RlsSnackbar, RlsSpinner, RlsSwitch, RlsSwitchControl, RlsTabs, RlsTabularText, RlsToolbar, calculateImgDimension, generateThemePalette, getAppTheme, hexIsValid, hexToHsl, hexToHsv, hexToRgb, hslToHex, hsvToHex, hsvToRgb, normalizeHex, rangeFormatTemplate, renderClassStatus, rgbToHex, rgbToHsl, rgbToHsv, setAppTheme, setDesignSystem, setErrorsI18n, setThemeColor, toggleAppTheme, useConfirmation, useDatatable, useDesingSystemController, useDropdownController, useFieldAutocomplete, useFieldList, useFieldSelect, useFormSingleSelectionController, useFormToggleController, useImageEditorController, useListController, useNotifications, usePortalController, useRelocationOnComponent, useResize, useRlsContext, useSnackbar, useTabsController };
4833
5071
  //# sourceMappingURL=index.mjs.map