@apia/components 3.0.21 → 3.0.23

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.
package/dist/index.js CHANGED
@@ -1,18 +1,18 @@
1
1
  import uniqueId$2 from 'lodash-es/uniqueId';
2
- import { findScrollContainer, useUpdateEffect, focus, focusSelector, getFocusSelector, addBoundary, useCombinedRefs, usePrevious, EventEmitter, useMount, getLabel, getSpecificParent, isChild, useUnmount, StatefulEmitter, debugDispatcher, customEvents, getDateFormat, persistentStorage, disableChildrenFocus, enableChildrenFocus, decodeHTMLEntities, useDebouncedCallback, getIndex, noNaN, useLatest, useSubscription } from '@apia/util';
2
+ import { findScrollContainer, useUpdateEffect, focus, focusSelector, getFocusSelector, addBoundary, useCombinedRefs, usePrevious, EventEmitter, useMount, getLabel, getSpecificParent, isChild, useUnmount, StatefulEmitter, debugDispatcher, customEvents, getDateFormat, persistentStorage, disableChildrenFocus, enableChildrenFocus, decodeHTMLEntities, useDebouncedCallback, getIndex, noNaN, useLatest, useSubscription, AudioRecorder } from '@apia/util';
3
3
  import { jsx, Fragment, jsxs } from '@apia/theme/jsx-runtime';
4
4
  import * as React from 'react';
5
5
  import React__default, { createContext, useContext, useMemo, useEffect, useState, useCallback, useRef, forwardRef, Fragment as Fragment$1, useDeferredValue, lazy, Suspense, useTransition, Children, memo, isValidElement, cloneElement } from 'react';
6
6
  import usePortal from 'react-cool-portal';
7
7
  import { CSSTransition } from 'react-transition-group';
8
- import { Box, getVariant, useBreakpointIndex, Close, responsive, spacing, Heading, Spinner, Button, createElement, Select, Input, Flex, IconButton as IconButton$1, Image, injectStyles, focusOutline, makeStyledComponent, useThemeUI, Label, Progress, Grid } from '@apia/theme';
8
+ import { Box, getVariant, useBreakpointIndex, Close, responsive, spacing, Heading, Spinner, Button, createElement, Select, Input, Flex, IconButton as IconButton$1, Image, injectStyles, focusOutline, makeStyledComponent, useThemeUI, Label, Progress, Grid, Form, Textarea } from '@apia/theme';
9
9
  import { uniqueId as uniqueId$1, defaultNotifier, NotificationsList } from '@apia/notifications';
10
10
  import ReactFocusLock, { FreeFocusInside } from 'react-focus-lock';
11
11
  import { useBreakpointIndex as useBreakpointIndex$1 } from '@theme-ui/match-media';
12
+ import { isIconName, Icon as Icon$1, icons, FileIcon } from '@apia/icons';
12
13
  import { useMenuState, ControlledMenu, MenuItem, MenuDivider, SubMenu } from '@szhsin/react-menu';
13
- import { makeAutoObservable, observable, reaction } from 'mobx';
14
+ import { makeAutoObservable, observable, reaction, makeObservable, action } from 'mobx';
14
15
  import { shallowEqual } from '@apia/store';
15
- import { isIconName, Icon as Icon$1, icons } from '@apia/icons';
16
16
  import AnimateHeight from 'react-animate-height';
17
17
  import { useUpdateEffect as useUpdateEffect$1 } from 'ahooks';
18
18
  import dayjs from 'dayjs';
@@ -23,6 +23,8 @@ import { observer } from 'mobx-react-lite';
23
23
  import { createFAsomeStore } from '@apia/dom-store';
24
24
  import { BarLoader } from 'react-spinners';
25
25
  import { keyframes } from '@emotion/react';
26
+ import { Collector } from '@apia/validations';
27
+ import { IconButton as IconButton$2, ApiaUtil as ApiaUtil$1 } from '@apia/components';
26
28
 
27
29
  const AccordionContext = createContext(null);
28
30
  const AccordionItemContext = createContext(null);
@@ -33,10 +35,10 @@ const useAccordionContext = () => {
33
35
  return context;
34
36
  };
35
37
 
36
- var __defProp$h = Object.defineProperty;
37
- var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
38
- var __publicField$h = (obj, key, value) => {
39
- __defNormalProp$h(obj, typeof key !== "symbol" ? key + "" : key, value);
38
+ var __defProp$l = Object.defineProperty;
39
+ var __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
40
+ var __publicField$l = (obj, key, value) => {
41
+ __defNormalProp$l(obj, typeof key !== "symbol" ? key + "" : key, value);
40
42
  return value;
41
43
  };
42
44
  function makeItemStateSelectorHook(handler) {
@@ -68,10 +70,10 @@ class AccordionHandler {
68
70
  constructor(id, props) {
69
71
  this.id = id;
70
72
  this.props = props;
71
- __publicField$h(this, "itemsState", {});
72
- __publicField$h(this, "itemsStateListeners", {});
73
- __publicField$h(this, "propsListeners", []);
74
- __publicField$h(this, "hooks", {
73
+ __publicField$l(this, "itemsState", {});
74
+ __publicField$l(this, "itemsStateListeners", {});
75
+ __publicField$l(this, "propsListeners", []);
76
+ __publicField$l(this, "hooks", {
75
77
  useAccordionContextProvider: () => {
76
78
  const Provider = useMemo(
77
79
  () => ({ children }) => /* @__PURE__ */ jsx(AccordionContext.Provider, { value: this, children }),
@@ -1007,10 +1009,10 @@ const WindowModal = forwardRef(
1007
1009
  }
1008
1010
  );
1009
1011
 
1010
- var __defProp$g = Object.defineProperty;
1011
- var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1012
- var __publicField$g = (obj, key, value) => {
1013
- __defNormalProp$g(obj, typeof key !== "symbol" ? key + "" : key, value);
1012
+ var __defProp$k = Object.defineProperty;
1013
+ var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1014
+ var __publicField$k = (obj, key, value) => {
1015
+ __defNormalProp$k(obj, typeof key !== "symbol" ? key + "" : key, value);
1014
1016
  return value;
1015
1017
  };
1016
1018
  var __accessCheck$c = (obj, member, msg) => {
@@ -1075,7 +1077,7 @@ _onDestroyCb = new WeakMap();
1075
1077
  const BodyScrollLock = new (_a$1 = class {
1076
1078
  constructor() {
1077
1079
  __privateAdd$c(this, _evaluate);
1078
- __publicField$g(this, "lockers", []);
1080
+ __publicField$k(this, "lockers", []);
1079
1081
  }
1080
1082
  getLocker() {
1081
1083
  const locker = new BodyScrollLocker();
@@ -1349,7 +1351,8 @@ Modal.displayName = "Modal";
1349
1351
  const OpenModal = (props) => {
1350
1352
  const modalProps = useModal({
1351
1353
  isDefaultOpen: true,
1352
- onExited: props.onExited
1354
+ onExited: props.onExited,
1355
+ onClose: props.onClose
1353
1356
  });
1354
1357
  const previousOpenProp = usePrevious(props.isOpen);
1355
1358
  if (previousOpenProp.current !== props.isOpen && !props.isOpen) {
@@ -1363,6 +1366,10 @@ const OpenModal = (props) => {
1363
1366
  {
1364
1367
  ...props,
1365
1368
  ...modalProps,
1369
+ onClose: () => {
1370
+ modalProps.onClose?.();
1371
+ props.onClose?.();
1372
+ },
1366
1373
  onExited: () => {
1367
1374
  props.onClose?.();
1368
1375
  if (!hasConfirmed.current) {
@@ -1397,10 +1404,10 @@ const OpenModal = (props) => {
1397
1404
  );
1398
1405
  };
1399
1406
 
1400
- var __defProp$f = Object.defineProperty;
1401
- var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1402
- var __publicField$f = (obj, key, value) => {
1403
- __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
1407
+ var __defProp$j = Object.defineProperty;
1408
+ var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1409
+ var __publicField$j = (obj, key, value) => {
1410
+ __defNormalProp$j(obj, typeof key !== "symbol" ? key + "" : key, value);
1404
1411
  return value;
1405
1412
  };
1406
1413
  var __accessCheck$b = (obj, member, msg) => {
@@ -1451,6 +1458,7 @@ class ApiaUtilModals {
1451
1458
  {
1452
1459
  ...ev,
1453
1460
  isOpen: true,
1461
+ onClose: ev.onClose,
1454
1462
  onExited: () => {
1455
1463
  ev.onExited?.();
1456
1464
  setModals(
@@ -1480,7 +1488,7 @@ class ApiaUtilModals {
1480
1488
  });
1481
1489
  return modals;
1482
1490
  });
1483
- __publicField$f(this, "Component", () => {
1491
+ __publicField$j(this, "Component", () => {
1484
1492
  const modals = __privateGet$8(this, _useModalsList).call(this);
1485
1493
  return /* @__PURE__ */ jsx(Fragment, { children: modals.map((current) => /* @__PURE__ */ jsx(OpenModal, { ...current }, current.id)) });
1486
1494
  });
@@ -1489,6 +1497,9 @@ class ApiaUtilModals {
1489
1497
  this.open(cevent.detail);
1490
1498
  });
1491
1499
  }
1500
+ close(id) {
1501
+ __privateGet$8(this, _emitter$4).emit("close", id);
1502
+ }
1492
1503
  open(props) {
1493
1504
  const id = props.id ?? `modal_${__privateWrapper$2(this, _maxId$1)._++}`;
1494
1505
  __privateGet$8(this, _emitter$4).emit("open", { ...props, id });
@@ -1501,29 +1512,29 @@ _emitter$4 = new WeakMap();
1501
1512
  _maxId$1 = new WeakMap();
1502
1513
  _useModalsList = new WeakMap();
1503
1514
 
1504
- var __defProp$e = Object.defineProperty;
1505
- var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1506
- var __publicField$e = (obj, key, value) => {
1507
- __defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
1515
+ var __defProp$i = Object.defineProperty;
1516
+ var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1517
+ var __publicField$i = (obj, key, value) => {
1518
+ __defNormalProp$i(obj, typeof key !== "symbol" ? key + "" : key, value);
1508
1519
  return value;
1509
1520
  };
1510
1521
  class ApiaUtilNotifications {
1511
1522
  constructor() {
1512
- __publicField$e(this, "close", (id) => {
1523
+ __publicField$i(this, "close", (id) => {
1513
1524
  defaultNotifier.close(id);
1514
1525
  });
1515
- __publicField$e(this, "closeAll", () => {
1526
+ __publicField$i(this, "closeAll", () => {
1516
1527
  defaultNotifier.closeAll();
1517
1528
  });
1518
- __publicField$e(this, "notify", (notification) => {
1529
+ __publicField$i(this, "notify", (notification) => {
1519
1530
  defaultNotifier.notify({
1520
1531
  ...notification,
1521
1532
  type: notification.type ?? "warning"
1522
1533
  });
1523
1534
  });
1524
1535
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1525
- __publicField$e(this, "useSelector", (selector) => defaultNotifier.useSelector(selector));
1526
- __publicField$e(this, "Component", () => {
1536
+ __publicField$i(this, "useSelector", (selector) => defaultNotifier.useSelector(selector));
1537
+ __publicField$i(this, "Component", () => {
1527
1538
  return /* @__PURE__ */ jsx(NotificationsList, {});
1528
1539
  });
1529
1540
  }
@@ -1854,10 +1865,10 @@ const TabsList = observer(
1854
1865
  }
1855
1866
  );
1856
1867
 
1857
- var __defProp$d = Object.defineProperty;
1858
- var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1859
- var __publicField$d = (obj, key, value) => {
1860
- __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
1868
+ var __defProp$h = Object.defineProperty;
1869
+ var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1870
+ var __publicField$h = (obj, key, value) => {
1871
+ __defNormalProp$h(obj, typeof key !== "symbol" ? key + "" : key, value);
1861
1872
  return value;
1862
1873
  };
1863
1874
  var __accessCheck$a = (obj, member, msg) => {
@@ -1898,7 +1909,7 @@ class TabsController {
1898
1909
  this.id = id;
1899
1910
  this.props = props;
1900
1911
  __privateAdd$a(this, _innerAppend);
1901
- __publicField$d(this, "state", {
1912
+ __publicField$h(this, "state", {
1902
1913
  openTabs: /* @__PURE__ */ new Set(),
1903
1914
  tabs: /* @__PURE__ */ new Map(),
1904
1915
  timestamp: 0
@@ -2545,10 +2556,10 @@ const AlertModal = ({ children, onClose, title }) => {
2545
2556
  );
2546
2557
  };
2547
2558
 
2548
- var __defProp$c = Object.defineProperty;
2549
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2550
- var __publicField$c = (obj, key, value) => {
2551
- __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
2559
+ var __defProp$g = Object.defineProperty;
2560
+ var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2561
+ var __publicField$g = (obj, key, value) => {
2562
+ __defNormalProp$g(obj, typeof key !== "symbol" ? key + "" : key, value);
2552
2563
  return value;
2553
2564
  };
2554
2565
  var __accessCheck$9 = (obj, member, msg) => {
@@ -2583,7 +2594,7 @@ class ApiaUtilDialogs {
2583
2594
  __privateAdd$9(this, _emitter$3, new EventEmitter());
2584
2595
  __privateAdd$9(this, _maxIdAlert, 0);
2585
2596
  __privateAdd$9(this, _maxIdConfirm, 0);
2586
- __publicField$c(this, "Component", () => {
2597
+ __publicField$g(this, "Component", () => {
2587
2598
  const [confirmDialogs, setConfirmDialogs] = useState([]);
2588
2599
  const [alertsDialogs, setAlertsDialogs] = useState(
2589
2600
  []
@@ -2865,25 +2876,25 @@ parseCellValue_fn = function(cellValue) {
2865
2876
  return cellValue.match(/^\s*"?([^"]+)"?[\s\r\n]*$/)?.[1] ?? cellValue;
2866
2877
  };
2867
2878
 
2868
- var __defProp$b = Object.defineProperty;
2869
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2870
- var __publicField$b = (obj, key, value) => {
2871
- __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
2879
+ var __defProp$f = Object.defineProperty;
2880
+ var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2881
+ var __publicField$f = (obj, key, value) => {
2882
+ __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
2872
2883
  return value;
2873
2884
  };
2874
- let maxId = 0;
2885
+ let maxId$1 = 0;
2875
2886
  class ApiaUtilTooltip {
2876
2887
  constructor(props, close) {
2877
2888
  this.props = props;
2878
2889
  this.close = close;
2879
- __publicField$b(this, "id", `tooltip__${maxId++}`);
2890
+ __publicField$f(this, "id", `tooltip__${maxId$1++}`);
2880
2891
  }
2881
2892
  }
2882
2893
 
2883
- var __defProp$a = Object.defineProperty;
2884
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2885
- var __publicField$a = (obj, key, value) => {
2886
- __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
2894
+ var __defProp$e = Object.defineProperty;
2895
+ var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2896
+ var __publicField$e = (obj, key, value) => {
2897
+ __defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
2887
2898
  return value;
2888
2899
  };
2889
2900
  var __accessCheck$7 = (obj, member, msg) => {
@@ -2917,7 +2928,7 @@ class AutomaticTooltip {
2917
2928
  __privateAdd$7(this, _tooltipTimeout, 0);
2918
2929
  __privateAdd$7(this, _unsuscribe, null);
2919
2930
  __privateAdd$7(this, _tooltipController, null);
2920
- __publicField$a(this, "ref", (el) => {
2931
+ __publicField$e(this, "ref", (el) => {
2921
2932
  var _a, _b;
2922
2933
  (_a = __privateGet$6(this, _unsuscribe)) == null ? void 0 : _a.call(this);
2923
2934
  const listener = () => {
@@ -2935,9 +2946,6 @@ class AutomaticTooltip {
2935
2946
  };
2936
2947
  const reset = () => {
2937
2948
  clearTimeout(__privateGet$6(this, _tooltipTimeout));
2938
- if (__privateGet$6(this, _tooltip)?.closeOnMouseLeaveAttachedElement) {
2939
- __privateGet$6(this, _tooltipController)?.close();
2940
- }
2941
2949
  };
2942
2950
  if (el) {
2943
2951
  el.addEventListener("mousemove", listener);
@@ -2952,7 +2960,7 @@ class AutomaticTooltip {
2952
2960
  }
2953
2961
  });
2954
2962
  __privateAdd$7(this, _tooltip, null);
2955
- __publicField$a(this, "update", (tooltip) => {
2963
+ __publicField$e(this, "update", (tooltip) => {
2956
2964
  __privateSet$5(this, _tooltip, tooltip);
2957
2965
  });
2958
2966
  __privateSet$5(this, _tooltip, tooltip);
@@ -3062,19 +3070,23 @@ function calculateTooltipPosition({
3062
3070
  const availableTopSpace = actualAnchorPoint.top;
3063
3071
  const availableLeftSpace = actualAnchorPoint.left;
3064
3072
  const availableRightSpace = window.innerWidth - actualAnchorPoint.left;
3065
- const isEnoughToRight = (minSize?.width ?? 0) <= availableRightSpace;
3066
- const isEnoughToLeft = (minSize?.width ?? 0) <= availableLeftSpace;
3067
- const isEnoughToBottom = (minSize?.height ?? 0) <= availableBottomSpace;
3068
- const isEnoughToTop = (minSize?.height ?? 0) <= availableTopSpace;
3073
+ const isEnoughToRight = ((preferredSize?.width !== "auto" ? preferredSize?.width : void 0) ?? minSize?.width ?? 0) <= availableRightSpace;
3074
+ const isEnoughToLeft = ((preferredSize?.width !== "auto" ? preferredSize?.width : void 0) ?? minSize?.width ?? 0) <= availableLeftSpace;
3075
+ const isEnoughToBottom = ((preferredSize?.height !== "auto" ? preferredSize?.height : void 0) ?? minSize?.height ?? 0) <= availableBottomSpace;
3076
+ const isEnoughToTop = ((preferredSize?.height !== "auto" ? preferredSize?.height : void 0) ?? minSize?.height ?? 0) <= availableTopSpace;
3069
3077
  const preferredWidth = preferredSize.width === "auto" ? Infinity : preferredSize.width;
3070
3078
  const preferredHeight = preferredSize.height === "auto" ? Infinity : preferredSize.height;
3071
3079
  const position = {
3072
3080
  "& > *": {
3073
3081
  width: "100%",
3074
- height: "100%"
3082
+ height: "100%",
3083
+ overflow: "auto"
3075
3084
  },
3076
- width: preferredSize.width === "auto" ? "auto" : "100%",
3077
- height: preferredSize.height === "auto" ? "auto" : "100%"
3085
+ display: "flex",
3086
+ flexDirection: "column",
3087
+ overflow: "hidden",
3088
+ width: preferredSize.width === "auto" ? "auto" : void 0,
3089
+ height: preferredSize.height === "auto" ? "auto" : void 0
3078
3090
  };
3079
3091
  if (preferredOrientationX === "left") {
3080
3092
  if (isEnoughToLeft) {
@@ -3300,10 +3312,10 @@ const Tooltip = ({
3300
3312
  );
3301
3313
  };
3302
3314
 
3303
- var __defProp$9 = Object.defineProperty;
3304
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3305
- var __publicField$9 = (obj, key, value) => {
3306
- __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
3315
+ var __defProp$d = Object.defineProperty;
3316
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3317
+ var __publicField$d = (obj, key, value) => {
3318
+ __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
3307
3319
  return value;
3308
3320
  };
3309
3321
  var __accessCheck$6 = (obj, member, msg) => {
@@ -3323,7 +3335,7 @@ var _emitter$2, _shoutChangedList;
3323
3335
  class ApiaUtilTooltips {
3324
3336
  constructor() {
3325
3337
  __privateAdd$6(this, _emitter$2, new EventEmitter());
3326
- __publicField$9(this, "tooltips", []);
3338
+ __publicField$d(this, "tooltips", []);
3327
3339
  __privateAdd$6(this, _shoutChangedList, () => {
3328
3340
  __privateGet$5(this, _emitter$2).emit("changedList", [...this.tooltips]);
3329
3341
  });
@@ -3331,7 +3343,7 @@ class ApiaUtilTooltips {
3331
3343
  * Permite crear un tooltip que se abrirá automáticamente al estar parado
3332
3344
  * sobre un elemento durante 300ms
3333
3345
  */
3334
- __publicField$9(this, "useHover", (tooltip) => {
3346
+ __publicField$d(this, "useHover", (tooltip) => {
3335
3347
  let tt = void 0;
3336
3348
  tt = useMemo(() => {
3337
3349
  tt?.ref(null);
@@ -3342,15 +3354,15 @@ class ApiaUtilTooltips {
3342
3354
  });
3343
3355
  return tt;
3344
3356
  });
3345
- __publicField$9(this, "close", (id) => {
3357
+ __publicField$d(this, "close", (id) => {
3346
3358
  this.tooltips = this.tooltips.filter((current) => current.id !== id);
3347
3359
  __privateGet$5(this, _shoutChangedList).call(this);
3348
3360
  });
3349
- __publicField$9(this, "closeAll", () => {
3361
+ __publicField$d(this, "closeAll", () => {
3350
3362
  this.tooltips = [];
3351
3363
  __privateGet$5(this, _shoutChangedList).call(this);
3352
3364
  });
3353
- __publicField$9(this, "open", (tooltip) => {
3365
+ __publicField$d(this, "open", (tooltip) => {
3354
3366
  const controller = new ApiaUtilTooltip(tooltip, () => {
3355
3367
  this.close(controller.id);
3356
3368
  controller.props.onClose?.();
@@ -3363,7 +3375,7 @@ class ApiaUtilTooltips {
3363
3375
  __privateGet$5(this, _shoutChangedList).call(this);
3364
3376
  return controller;
3365
3377
  });
3366
- __publicField$9(this, "Component", () => {
3378
+ __publicField$d(this, "Component", () => {
3367
3379
  const [tooltips, setTooltips] = useState(this.tooltips);
3368
3380
  useMount(() => {
3369
3381
  const unsuscribeToList = __privateGet$5(this, _emitter$2).on("changedList", (ev) => {
@@ -3399,10 +3411,10 @@ class ApiaUtilTooltips {
3399
3411
  _emitter$2 = new WeakMap();
3400
3412
  _shoutChangedList = new WeakMap();
3401
3413
 
3402
- var __defProp$8 = Object.defineProperty;
3403
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3404
- var __publicField$8 = (obj, key, value) => {
3405
- __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
3414
+ var __defProp$c = Object.defineProperty;
3415
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3416
+ var __publicField$c = (obj, key, value) => {
3417
+ __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
3406
3418
  return value;
3407
3419
  };
3408
3420
  var __accessCheck$5 = (obj, member, msg) => {
@@ -3439,7 +3451,7 @@ class ApiaUtilMenu {
3439
3451
  constructor() {
3440
3452
  __privateAdd$5(this, _emitter$1, new EventEmitter());
3441
3453
  __privateAdd$5(this, _items$1, []);
3442
- __publicField$8(this, "menuProps", null);
3454
+ __publicField$c(this, "menuProps", null);
3443
3455
  __privateAdd$5(this, _hooks, {
3444
3456
  useIsOpen: () => {
3445
3457
  const [isOpen, setIsOpen] = useState(false);
@@ -3454,10 +3466,10 @@ class ApiaUtilMenu {
3454
3466
  ];
3455
3467
  }
3456
3468
  });
3457
- __publicField$8(this, "close", () => {
3469
+ __publicField$c(this, "close", () => {
3458
3470
  __privateGet$4(this, _emitter$1).emit("toggle", false);
3459
3471
  });
3460
- __publicField$8(this, "open", ({
3472
+ __publicField$c(this, "open", ({
3461
3473
  menuProps,
3462
3474
  items
3463
3475
  }) => {
@@ -3473,10 +3485,15 @@ class ApiaUtilMenu {
3473
3485
  if (isSubmenu(current)) {
3474
3486
  return /* @__PURE__ */ jsx(SubMenu, { label: current.label, children: __privateGet$4(this, _RenderMenu).call(this, current) }, `submenu${__privateWrapper(this, _maxId)._++}`);
3475
3487
  }
3476
- return /* @__PURE__ */ createElement(MenuItem, { ...current, key: current.key });
3488
+ const children = current.icon ? /* @__PURE__ */ jsxs(Box, { className: "withIcon", children: [
3489
+ /* @__PURE__ */ jsx(Icon$1, { name: current.icon, title: current.title }),
3490
+ " ",
3491
+ current.children
3492
+ ] }) : current.children;
3493
+ return /* @__PURE__ */ createElement(MenuItem, { ...current, key: current.key }, children);
3477
3494
  }) });
3478
3495
  });
3479
- __publicField$8(this, "Component", () => {
3496
+ __publicField$c(this, "Component", () => {
3480
3497
  const [isOpen, close] = __privateGet$4(this, _hooks).useIsOpen();
3481
3498
  if (!isOpen)
3482
3499
  return null;
@@ -3501,17 +3518,17 @@ _hooks = new WeakMap();
3501
3518
  _maxId = new WeakMap();
3502
3519
  _RenderMenu = new WeakMap();
3503
3520
 
3504
- var __defProp$7 = Object.defineProperty;
3505
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3506
- var __publicField$7 = (obj, key, value) => {
3507
- __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
3521
+ var __defProp$b = Object.defineProperty;
3522
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3523
+ var __publicField$b = (obj, key, value) => {
3524
+ __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
3508
3525
  return value;
3509
3526
  };
3510
3527
  class ApiaUtilMouse extends EventEmitter {
3511
3528
  constructor() {
3512
3529
  super();
3513
- __publicField$7(this, "x", 0);
3514
- __publicField$7(this, "y", 0);
3530
+ __publicField$b(this, "x", 0);
3531
+ __publicField$b(this, "y", 0);
3515
3532
  document.addEventListener("mousemove", (ev) => {
3516
3533
  this.x = ev.clientX;
3517
3534
  this.y = ev.clientY;
@@ -3523,10 +3540,10 @@ class ApiaUtilMouse extends EventEmitter {
3523
3540
  }
3524
3541
  }
3525
3542
 
3526
- var __defProp$6 = Object.defineProperty;
3527
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3528
- var __publicField$6 = (obj, key, value) => {
3529
- __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
3543
+ var __defProp$a = Object.defineProperty;
3544
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3545
+ var __publicField$a = (obj, key, value) => {
3546
+ __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
3530
3547
  return value;
3531
3548
  };
3532
3549
  var __accessCheck$4 = (obj, member, msg) => {
@@ -3550,15 +3567,15 @@ var __privateSet$3 = (obj, member, value, setter) => {
3550
3567
  var _instance;
3551
3568
  const _ApiaUtil = class _ApiaUtil {
3552
3569
  constructor() {
3553
- __publicField$6(this, "dialogs");
3554
- __publicField$6(this, "menu");
3555
- __publicField$6(this, "modals");
3556
- __publicField$6(this, "mouse");
3557
- __publicField$6(this, "notifications");
3558
- __publicField$6(this, "parsers");
3559
- __publicField$6(this, "tabs");
3560
- __publicField$6(this, "tooltips");
3561
- __publicField$6(this, "Component", () => {
3570
+ __publicField$a(this, "dialogs");
3571
+ __publicField$a(this, "menu");
3572
+ __publicField$a(this, "modals");
3573
+ __publicField$a(this, "mouse");
3574
+ __publicField$a(this, "notifications");
3575
+ __publicField$a(this, "parsers");
3576
+ __publicField$a(this, "tabs");
3577
+ __publicField$a(this, "tooltips");
3578
+ __publicField$a(this, "Component", () => {
3562
3579
  return /* @__PURE__ */ jsxs(Fragment, { children: [
3563
3580
  /* @__PURE__ */ jsx(this.dialogs.Component, {}),
3564
3581
  /* @__PURE__ */ jsx(this.modals.Component, {}),
@@ -3587,22 +3604,22 @@ _instance = new WeakMap();
3587
3604
  __privateAdd$4(_ApiaUtil, _instance, void 0);
3588
3605
  let ApiaUtil = _ApiaUtil;
3589
3606
 
3590
- var __defProp$5 = Object.defineProperty;
3591
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3592
- var __publicField$5 = (obj, key, value) => {
3593
- __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
3607
+ var __defProp$9 = Object.defineProperty;
3608
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3609
+ var __publicField$9 = (obj, key, value) => {
3610
+ __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
3594
3611
  return value;
3595
3612
  };
3596
3613
  class ScreenLocker {
3597
3614
  constructor() {
3598
- __publicField$5(this, "emitter", new StatefulEmitter({
3615
+ __publicField$9(this, "emitter", new StatefulEmitter({
3599
3616
  locks: {
3600
3617
  common: { count: 0 },
3601
3618
  linear: { count: 0 },
3602
3619
  white: { count: 1 }
3603
3620
  }
3604
3621
  }));
3605
- __publicField$5(this, "lock", (options) => {
3622
+ __publicField$9(this, "lock", (options) => {
3606
3623
  this.emitter.setState("locks", (s) => {
3607
3624
  const key = options?.type ?? "common";
3608
3625
  return {
@@ -3618,11 +3635,11 @@ class ScreenLocker {
3618
3635
  };
3619
3636
  });
3620
3637
  });
3621
- __publicField$5(this, "hasReleased", false);
3638
+ __publicField$9(this, "hasReleased", false);
3622
3639
  /**
3623
3640
  * This method will work once, then, the action will be ignored. The ScreenLocker starts always locked on white, when this method is called, all listeners of onRelease will be called and the lock will be released.
3624
3641
  */
3625
- __publicField$5(this, "release", () => {
3642
+ __publicField$9(this, "release", () => {
3626
3643
  if (this.hasReleased)
3627
3644
  return;
3628
3645
  this.hasReleased = true;
@@ -3638,11 +3655,11 @@ class ScreenLocker {
3638
3655
  /**
3639
3656
  * This method notifies when the screenLock is released by the first time.
3640
3657
  */
3641
- __publicField$5(this, "onRelease", this.emitter.on.bind(this.emitter, "release"));
3658
+ __publicField$9(this, "onRelease", this.emitter.on.bind(this.emitter, "release"));
3642
3659
  /**
3643
3660
  * This component is the responsible for putting the lock courtain in the browser when it's required. It must be used once per application.
3644
3661
  */
3645
- __publicField$5(this, "Component", () => {
3662
+ __publicField$9(this, "Component", () => {
3646
3663
  const locks = this.emitter.useState("locks");
3647
3664
  const style = {
3648
3665
  alignItems: "center",
@@ -3712,10 +3729,10 @@ const OptionsBox = observer(() => {
3712
3729
  }) });
3713
3730
  });
3714
3731
 
3715
- var __defProp$4 = Object.defineProperty;
3716
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3717
- var __publicField$4 = (obj, key, value) => {
3718
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
3732
+ var __defProp$8 = Object.defineProperty;
3733
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3734
+ var __publicField$8 = (obj, key, value) => {
3735
+ __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
3719
3736
  return value;
3720
3737
  };
3721
3738
  var __accessCheck$3 = (obj, member, msg) => {
@@ -3739,7 +3756,7 @@ var __privateSet$2 = (obj, member, value, setter) => {
3739
3756
  var _actualSearch, _makeSearch, _search;
3740
3757
  class AutocompleteController {
3741
3758
  constructor(properties) {
3742
- __publicField$4(this, "state", {
3759
+ __publicField$8(this, "state", {
3743
3760
  disabled: false,
3744
3761
  id: uniqueId$3("autocomplete"),
3745
3762
  loading: false,
@@ -3764,7 +3781,7 @@ class AutocompleteController {
3764
3781
  return debounce(__privateGet$2(this, _actualSearch), this.state.searchDebounce);
3765
3782
  });
3766
3783
  __privateAdd$3(this, _search, __privateGet$2(this, _makeSearch).call(this));
3767
- __publicField$4(this, "tooltipRef", null);
3784
+ __publicField$8(this, "tooltipRef", null);
3768
3785
  Object.assign(this.state, properties);
3769
3786
  if (properties.value) {
3770
3787
  this.state.showValue = properties.value;
@@ -4424,10 +4441,10 @@ const Checkbox$1 = forwardRef(
4424
4441
  );
4425
4442
  Checkbox$1.displayName = "Checkbox";
4426
4443
 
4427
- var __defProp$3 = Object.defineProperty;
4428
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4429
- var __publicField$3 = (obj, key, value) => {
4430
- __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
4444
+ var __defProp$7 = Object.defineProperty;
4445
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4446
+ var __publicField$7 = (obj, key, value) => {
4447
+ __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
4431
4448
  return value;
4432
4449
  };
4433
4450
  var __accessCheck$2 = (obj, member, msg) => {
@@ -4452,7 +4469,7 @@ var _onFocusCallbacks, _a;
4452
4469
  const historySize = 50;
4453
4470
  const globalFocus = new (_a = class {
4454
4471
  constructor() {
4455
- __publicField$3(this, "focused", []);
4472
+ __publicField$7(this, "focused", []);
4456
4473
  __privateAdd$2(this, _onFocusCallbacks, []);
4457
4474
  debugDispatcher.on(
4458
4475
  "focusHistory",
@@ -4687,8 +4704,11 @@ const DateInput = React__default.forwardRef(
4687
4704
  const shoutOnChange = React__default.useCallback(
4688
4705
  (newValue) => {
4689
4706
  if (newValue !== lastEmittedValue.current && onChange) {
4690
- lastEmittedValue.current = newValue;
4691
- return onChange(newValue);
4707
+ const result = onChange(newValue);
4708
+ if (result) {
4709
+ lastEmittedValue.current = newValue;
4710
+ }
4711
+ return result;
4692
4712
  }
4693
4713
  return true;
4694
4714
  },
@@ -5924,10 +5944,10 @@ const ListboxItem = memo(
5924
5944
  );
5925
5945
  ListboxItem.displayName = "ListboxItem";
5926
5946
 
5927
- var __defProp$2 = Object.defineProperty;
5928
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5929
- var __publicField$2 = (obj, key, value) => {
5930
- __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
5947
+ var __defProp$6 = Object.defineProperty;
5948
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5949
+ var __publicField$6 = (obj, key, value) => {
5950
+ __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
5931
5951
  return value;
5932
5952
  };
5933
5953
  var __accessCheck$1 = (obj, member, msg) => {
@@ -5949,10 +5969,10 @@ class WaiTypeAhead extends EventEmitter {
5949
5969
  super();
5950
5970
  __privateAdd$1(this, _restoreTimeout);
5951
5971
  __privateAdd$1(this, _shout);
5952
- __publicField$2(this, "frequency", 2.5);
5972
+ __publicField$6(this, "frequency", 2.5);
5953
5973
  // Keys per second
5954
- __publicField$2(this, "timeout", 0);
5955
- __publicField$2(this, "typing", "");
5974
+ __publicField$6(this, "timeout", 0);
5975
+ __publicField$6(this, "typing", "");
5956
5976
  const { onMultipleKeys, onSingleKey, onTypeUpdate } = props ?? {};
5957
5977
  if (onMultipleKeys)
5958
5978
  this.on("multipleKeys", onMultipleKeys);
@@ -7524,18 +7544,18 @@ function importComponent(path) {
7524
7544
  });
7525
7545
  }
7526
7546
 
7527
- var __defProp$1 = Object.defineProperty;
7528
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7529
- var __publicField$1 = (obj, key, value) => {
7530
- __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
7547
+ var __defProp$5 = Object.defineProperty;
7548
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7549
+ var __publicField$5 = (obj, key, value) => {
7550
+ __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
7531
7551
  return value;
7532
7552
  };
7533
7553
  class ToolbarController extends EventEmitter {
7534
7554
  constructor() {
7535
7555
  super(...arguments);
7536
- __publicField$1(this, "eventListeners", {});
7537
- __publicField$1(this, "itemsState", {});
7538
- __publicField$1(this, "hooks", {
7556
+ __publicField$5(this, "eventListeners", {});
7557
+ __publicField$5(this, "itemsState", {});
7558
+ __publicField$5(this, "hooks", {
7539
7559
  useItemState: (id, initialState) => {
7540
7560
  const [state, setState] = useState(initialState);
7541
7561
  useEffect(() => {
@@ -7549,11 +7569,11 @@ class ToolbarController extends EventEmitter {
7549
7569
  return state;
7550
7570
  }
7551
7571
  });
7552
- __publicField$1(this, "setItemState", (id, newState) => {
7572
+ __publicField$5(this, "setItemState", (id, newState) => {
7553
7573
  this.itemsState[id] = { ...this.itemsState[id], ...newState };
7554
7574
  this.emit("updateItemState", id);
7555
7575
  });
7556
- __publicField$1(this, "Context", ({ children }) => {
7576
+ __publicField$5(this, "Context", ({ children }) => {
7557
7577
  return /* @__PURE__ */ jsx(ToolbarControllerContext.Provider, { value: this, children });
7558
7578
  });
7559
7579
  }
@@ -7724,10 +7744,10 @@ const Toolbar = ({
7724
7744
  ) });
7725
7745
  };
7726
7746
 
7727
- var __defProp = Object.defineProperty;
7728
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7729
- var __publicField = (obj, key, value) => {
7730
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7747
+ var __defProp$4 = Object.defineProperty;
7748
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7749
+ var __publicField$4 = (obj, key, value) => {
7750
+ __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
7731
7751
  return value;
7732
7752
  };
7733
7753
  var __accessCheck = (obj, member, msg) => {
@@ -7758,7 +7778,7 @@ class SortableListHandler {
7758
7778
  constructor() {
7759
7779
  __privateAdd(this, _emitter, new EventEmitter());
7760
7780
  __privateAdd(this, _items, []);
7761
- __publicField(this, "updateChildren", (items) => {
7781
+ __publicField$4(this, "updateChildren", (items) => {
7762
7782
  __privateSet(this, _items, Children.toArray(items).filter(
7763
7783
  (el) => isValidElement(el)
7764
7784
  ));
@@ -7776,7 +7796,7 @@ class SortableListHandler {
7776
7796
  __privateGet(this, _items).splice(insertIndex + (after ? 1 : 0), 0, item);
7777
7797
  __privateGet(this, _emitter).emit("sort", null);
7778
7798
  });
7779
- __publicField(this, "useItemEvents", () => {
7799
+ __publicField$4(this, "useItemEvents", () => {
7780
7800
  const unsuscribe = useRef(() => {
7781
7801
  });
7782
7802
  const ref = useCallback((el) => {
@@ -7818,7 +7838,7 @@ class SortableListHandler {
7818
7838
  }, []);
7819
7839
  return ref;
7820
7840
  });
7821
- __publicField(this, "useSortChange", (onSortChange) => {
7841
+ __publicField$4(this, "useSortChange", (onSortChange) => {
7822
7842
  useSubscription({
7823
7843
  makeSubscription: () => {
7824
7844
  return __privateGet(this, _emitter).on("sort", () => {
@@ -7827,7 +7847,7 @@ class SortableListHandler {
7827
7847
  }
7828
7848
  });
7829
7849
  });
7830
- __publicField(this, "useWrapperEvents", () => {
7850
+ __publicField$4(this, "useWrapperEvents", () => {
7831
7851
  const unsuscribe = useRef(() => {
7832
7852
  });
7833
7853
  const ref = useCallback((el) => {
@@ -7940,5 +7960,838 @@ const SortableList = makeStyledComponent(
7940
7960
  UnstyledSortableList
7941
7961
  );
7942
7962
 
7943
- export { Accordion, AccordionContext, AccordionItem, AccordionItemButton, AccordionItemContent, AccordionItemContext, AlertModal, ApiaFilter, ApiaUtil, ApiaUtilModalHandler, ApiaUtilTooltip, AutoEllipsis, Autocomplete, AutocompleteController, AutogrowTextarea, BaseButton, CalendarModal, Captcha, Checkbox$1 as Checkbox, CollapsiblePanel, Confirm, ConfirmModal, ContainerWithHeader, DateInput, DefaultIconRenderer, DefaultTabsLabelRenderer, DialogButtonBar, FieldErrorMessage, FieldLabel, IconButton, IconInput, IconsList, LabelBox, LinearLoader$1 as LinearLoader, ListSkeletonLoader, Listbox, ListboxItem, LoaderSpinner$1 as LoaderSpinner, Modal, NumberInput, Overlay, ProgressBar$1 as ProgressBar, RequiredMark, ScreenLocker, SimpleButton, SortableList, SortableListItem, Tab, Tabs, TabsContent, TabsController, TabsList, Toolbar, ToolbarController, ToolbarIconButton, ToolbarInput, ToolbarSelect, ToolbarSeparator, ToolbarTextButton, UnstyledSortableList, WaiTypeAhead, getFieldErrorStyles, getFieldTouchedStyles, importComponent, makeResponsiveComponent, parseNumberInputValueToNumber, parseNumberValueToNumberInput, useAccordionContext, useModal, useModalContext, useOtherTagButton };
7963
+ var __defProp$3 = Object.defineProperty;
7964
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7965
+ var __publicField$3 = (obj, key, value) => {
7966
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
7967
+ return value;
7968
+ };
7969
+ let maxId = 0;
7970
+ class ChatMessage {
7971
+ constructor(message = "", messageType = "user", attachments = [], reference = null) {
7972
+ this.message = message;
7973
+ this.messageType = messageType;
7974
+ this.attachments = attachments;
7975
+ this.reference = reference;
7976
+ __publicField$3(this, "id");
7977
+ __publicField$3(this, "clone", () => new ChatMessage(
7978
+ this.message,
7979
+ this.messageType,
7980
+ this.attachments.map((x) => {
7981
+ return { ...x };
7982
+ }),
7983
+ this.reference
7984
+ ));
7985
+ this.id = maxId++;
7986
+ if (messageType === "response")
7987
+ this.messageType = "system";
7988
+ if (typeof message === "string")
7989
+ this.message = message;
7990
+ makeObservable(this, {
7991
+ attachments: observable,
7992
+ message: observable,
7993
+ messageType: observable,
7994
+ reference: observable
7995
+ });
7996
+ }
7997
+ removeAttachment(attachment) {
7998
+ this.attachments = this.attachments.filter(
7999
+ (current) => current !== attachment
8000
+ );
8001
+ }
8002
+ addAttachmentDescription(attachment, description) {
8003
+ const a = this.attachments.find((current) => current === attachment);
8004
+ if (a) {
8005
+ a.description = description;
8006
+ }
8007
+ }
8008
+ }
8009
+
8010
+ const AutoscrollContainer = ({ children }) => {
8011
+ const observer = useRef(null);
8012
+ const unsuscribe = useRef(null);
8013
+ const isFullScrolled = useRef(false);
8014
+ const hasInited = useRef(false);
8015
+ const ref = useCallback((el) => {
8016
+ if (!el)
8017
+ return;
8018
+ if (!hasInited.current) {
8019
+ hasInited.current = true;
8020
+ el.scrollTo({
8021
+ top: el.getBoundingClientRect().height,
8022
+ behavior: "auto"
8023
+ });
8024
+ isFullScrolled.current = true;
8025
+ }
8026
+ observer.current?.disconnect();
8027
+ unsuscribe.current?.();
8028
+ observer.current = new MutationObserver(([mutation]) => {
8029
+ if (mutation && mutation.target instanceof HTMLElement) {
8030
+ if (isFullScrolled.current && el.scrollTop !== el.scrollHeight - el.offsetHeight) {
8031
+ el.scrollTo({
8032
+ top: el.scrollHeight,
8033
+ behavior: "smooth"
8034
+ });
8035
+ }
8036
+ }
8037
+ });
8038
+ observer.current.observe(el, { childList: true, subtree: true });
8039
+ const handleScroll = (ev) => {
8040
+ if (ev.target === el && el instanceof HTMLElement) {
8041
+ setTimeout(() => {
8042
+ isFullScrolled.current = Math.abs(el.scrollTop - (el.scrollHeight - el.offsetHeight)) < 150;
8043
+ }, 100);
8044
+ }
8045
+ };
8046
+ el.addEventListener("scroll", handleScroll);
8047
+ unsuscribe.current = () => {
8048
+ el.removeEventListener("scroll", handleScroll);
8049
+ };
8050
+ }, []);
8051
+ return /* @__PURE__ */ jsx(
8052
+ Box,
8053
+ {
8054
+ ...getVariant("layout.common.components.autoscrollContainer"),
8055
+ className: "autoscrollContainer",
8056
+ ref,
8057
+ children
8058
+ }
8059
+ );
8060
+ };
8061
+
8062
+ function getBase64FromFile(f) {
8063
+ return ((f2) => new Promise((resolve, reject) => {
8064
+ const reader = new FileReader();
8065
+ reader.readAsDataURL(f2);
8066
+ reader.onload = () => resolve(reader.result);
8067
+ reader.onerror = () => reject();
8068
+ }))(f);
8069
+ }
8070
+ function getBase64FromBlob(b) {
8071
+ return ((blob) => new Promise((resolve, reject) => {
8072
+ const reader = new FileReader();
8073
+ reader.onloadend = () => {
8074
+ const base64String = reader.result;
8075
+ resolve(base64String);
8076
+ };
8077
+ reader.onerror = reject;
8078
+ reader.readAsDataURL(blob);
8079
+ }))(b);
8080
+ }
8081
+ function getFileExtension(name) {
8082
+ return name.split(".").at(-1);
8083
+ }
8084
+ function isImage(base64) {
8085
+ const imageRegex = /^data:image\/(png|jpeg|jpg|gif|webp|bmp|tiff);base64,/;
8086
+ return imageRegex.test(base64);
8087
+ }
8088
+
8089
+ const FileAttachment = observer(
8090
+ ({
8091
+ attachment,
8092
+ onAddDescription,
8093
+ onRemove
8094
+ }) => {
8095
+ const { ref } = ApiaUtil.instance.tooltips.useHover({
8096
+ preferredOrientationX: "left",
8097
+ preferredOrientationY: "top",
8098
+ minSize: {
8099
+ width: 200,
8100
+ height: 400
8101
+ },
8102
+ attachToMousePosition: true,
8103
+ closeOnMouseLeaveAttachedElement: true,
8104
+ children: /* @__PURE__ */ jsxs(
8105
+ Box,
8106
+ {
8107
+ sx: {
8108
+ display: "flex",
8109
+ alignItems: "center",
8110
+ flexDirection: "column"
8111
+ },
8112
+ children: [
8113
+ /* @__PURE__ */ jsx("h1", { children: attachment.name }),
8114
+ /* @__PURE__ */ jsx("img", { src: attachment.value }),
8115
+ attachment.description && /* @__PURE__ */ jsx(Label, { children: attachment.description })
8116
+ ]
8117
+ }
8118
+ )
8119
+ });
8120
+ return /* @__PURE__ */ jsxs(
8121
+ Box,
8122
+ {
8123
+ id: `file_box_${attachment.id}`,
8124
+ className: "file_box",
8125
+ ref: isImage(attachment.value) ? ref : null,
8126
+ children: [
8127
+ /* @__PURE__ */ jsx(FileIcon, { className: "file_box__icon", docName: attachment.name }),
8128
+ /* @__PURE__ */ jsx(Box, { className: "file_box__name", title: attachment.name, children: attachment.name }),
8129
+ onAddDescription && /* @__PURE__ */ jsx(
8130
+ IconButton,
8131
+ {
8132
+ icon: "Edit",
8133
+ className: "file_box__description",
8134
+ onClick: () => {
8135
+ const collector = new Collector();
8136
+ collector.add(
8137
+ new collector.fields.textarea(
8138
+ "desc",
8139
+ getLabel("lblDesc").text,
8140
+ { initialValue: attachment.description }
8141
+ )
8142
+ );
8143
+ collector.show({
8144
+ onConfirm: (ev) => {
8145
+ if (ev) {
8146
+ onAddDescription(attachment, ev.desc);
8147
+ }
8148
+ return true;
8149
+ }
8150
+ });
8151
+ },
8152
+ variant: "icon-only"
8153
+ }
8154
+ ),
8155
+ onRemove && /* @__PURE__ */ jsx(
8156
+ IconButton,
8157
+ {
8158
+ icon: "Close",
8159
+ className: "file_box__remove",
8160
+ onClick: onRemove,
8161
+ variant: "icon-only"
8162
+ }
8163
+ )
8164
+ ]
8165
+ }
8166
+ );
8167
+ }
8168
+ );
8169
+
8170
+ const Attachments = observer(
8171
+ ({
8172
+ attachments,
8173
+ onRemove,
8174
+ onAddDescription
8175
+ }) => {
8176
+ if (!attachments.length)
8177
+ return null;
8178
+ return /* @__PURE__ */ jsx(
8179
+ Box,
8180
+ {
8181
+ className: "attachments",
8182
+ ...getVariant("layout.common.newChat.attachments"),
8183
+ children: attachments.map((x) => /* @__PURE__ */ jsx(
8184
+ FileAttachment,
8185
+ {
8186
+ attachment: x,
8187
+ onRemove: onRemove ? () => onRemove(x) : void 0,
8188
+ onAddDescription
8189
+ },
8190
+ x.id
8191
+ ))
8192
+ }
8193
+ );
8194
+ }
8195
+ );
8196
+
8197
+ const Message = observer(
8198
+ ({
8199
+ className,
8200
+ type,
8201
+ id,
8202
+ message,
8203
+ attachments,
8204
+ reference
8205
+ }) => {
8206
+ return /* @__PURE__ */ jsxs(
8207
+ Box,
8208
+ {
8209
+ as: "pre",
8210
+ className: `history_message ${className || ""} ${type}`,
8211
+ children: [
8212
+ /* @__PURE__ */ jsx(
8213
+ Box,
8214
+ {
8215
+ className: "history_message__content",
8216
+ ...typeof message === "string" ? { dangerouslySetInnerHTML: { __html: message } } : { children: message }
8217
+ }
8218
+ ),
8219
+ attachments.length > 0 && /* @__PURE__ */ jsx(Attachments, { attachments }),
8220
+ reference && /* @__PURE__ */ jsx(Box, { className: "history_message__references", children: reference })
8221
+ ]
8222
+ },
8223
+ id
8224
+ );
8225
+ }
8226
+ );
8227
+
8228
+ const History = observer(({ messages }) => {
8229
+ let currentType = "";
8230
+ return /* @__PURE__ */ jsx(AutoscrollContainer, { children: /* @__PURE__ */ jsx(
8231
+ Box,
8232
+ {
8233
+ ...getVariant("layout.common.newChat.history"),
8234
+ className: "chat_history",
8235
+ children: messages.map((current, i) => {
8236
+ let first = false;
8237
+ let last = false;
8238
+ if (currentType !== current.messageType) {
8239
+ currentType = current.messageType;
8240
+ first = true;
8241
+ }
8242
+ if (i === messages.length - 1 || messages[i + 1].messageType !== current.messageType) {
8243
+ last = true;
8244
+ }
8245
+ return /* @__PURE__ */ jsx(
8246
+ Message,
8247
+ {
8248
+ className: first ? "first" : last ? "last" : void 0,
8249
+ type: current.messageType,
8250
+ id: String(current.id),
8251
+ attachments: current.attachments,
8252
+ reference: current.reference,
8253
+ message: current.message
8254
+ }
8255
+ );
8256
+ })
8257
+ }
8258
+ ) });
8259
+ });
8260
+
8261
+ const TextArea = observer(
8262
+ ({
8263
+ isLoading,
8264
+ isRecording,
8265
+ disablePrevButton,
8266
+ disableNextButton,
8267
+ onSubmit,
8268
+ onChange,
8269
+ onClearHistory,
8270
+ onAttach,
8271
+ onRecord,
8272
+ onVideoRecord,
8273
+ onPrev,
8274
+ onNext,
8275
+ value
8276
+ }) => {
8277
+ const fileInputRef = useRef(null);
8278
+ const searchControlsRef = useRef(null);
8279
+ const recordButton = /* @__PURE__ */ jsx(
8280
+ IconButton$2,
8281
+ {
8282
+ className: `${isRecording ? "isRecording" : ""}`,
8283
+ variant: "icon-only",
8284
+ onClick: onRecord,
8285
+ disabled: isLoading && !isRecording,
8286
+ sx: {
8287
+ color: isRecording ? "red" : void 0
8288
+ },
8289
+ icon: isRecording ? "Stop" : "Microphone",
8290
+ id: "transcribeAudio",
8291
+ iconSize: "Sm",
8292
+ title: getLabel("lblAiRecordAudio").text
8293
+ }
8294
+ );
8295
+ const handleAttachments = async (ev) => {
8296
+ if (ev.target.files) {
8297
+ for await (const f of ev.target.files) {
8298
+ const base64 = await getBase64FromFile(f);
8299
+ onAttach({
8300
+ value: base64,
8301
+ name: f.name,
8302
+ id: f.name
8303
+ });
8304
+ }
8305
+ ev.target.value = "";
8306
+ }
8307
+ };
8308
+ const menuItemsList = [
8309
+ {
8310
+ children: getLabel("btnUpload").text,
8311
+ title: getLabel("btnUpload").text,
8312
+ icon: "File",
8313
+ onClick: () => fileInputRef.current?.click(),
8314
+ key: "2"
8315
+ },
8316
+ {
8317
+ title: getLabel("lblOpenCamera").text,
8318
+ children: getLabel("lblOpenCamera").text,
8319
+ icon: "Camera",
8320
+ onClick: onVideoRecord,
8321
+ key: "3"
8322
+ },
8323
+ {
8324
+ title: getLabel("lblAiRecordAudio").text,
8325
+ children: getLabel("lblAiRecordAudio").text,
8326
+ key: "4",
8327
+ onClick: (event) => onRecord(event),
8328
+ icon: isRecording ? "Stop" : "Microphone"
8329
+ },
8330
+ "separator",
8331
+ {
8332
+ icon: "ArrowLeft",
8333
+ children: getLabel("btnAiPrevious").text,
8334
+ title: getLabel("btnAiPrevious").text,
8335
+ onClick: onPrev,
8336
+ disabled: disablePrevButton,
8337
+ key: "0"
8338
+ },
8339
+ {
8340
+ icon: "ArrowRight",
8341
+ children: getLabel("btnAiNext").text,
8342
+ title: getLabel("btnAiNext").text,
8343
+ onClick: onNext,
8344
+ disabled: disableNextButton,
8345
+ key: "1"
8346
+ },
8347
+ "separator",
8348
+ {
8349
+ icon: "Trash",
8350
+ onClick: onClearHistory,
8351
+ key: "5",
8352
+ children: getLabel("btnAiDeleteMessages").text,
8353
+ title: getLabel("btnAiDeleteMessages").text
8354
+ }
8355
+ ];
8356
+ return /* @__PURE__ */ jsxs(
8357
+ Form,
8358
+ {
8359
+ onSubmit: (ev) => {
8360
+ ev.preventDefault();
8361
+ onSubmit();
8362
+ },
8363
+ className: "search_controls",
8364
+ ...getVariant("layout.common.newChat.form"),
8365
+ children: [
8366
+ /* @__PURE__ */ jsx(
8367
+ Textarea,
8368
+ {
8369
+ ref: searchControlsRef,
8370
+ "aria-label": (
8371
+ /** TODO: Crear etiqueta para búsqueda */
8372
+ "Frase de b\xFAsqueda"
8373
+ ),
8374
+ value,
8375
+ className: "searchTextArea",
8376
+ onChange: (ev) => onChange(ev.target.value),
8377
+ onKeyDown: (ev) => {
8378
+ if (ev.code === "Enter" && !ev.shiftKey) {
8379
+ ev.preventDefault();
8380
+ ev.target.closest("form").querySelector('[type="submit"]').click();
8381
+ }
8382
+ }
8383
+ }
8384
+ ),
8385
+ /* @__PURE__ */ jsx(
8386
+ "input",
8387
+ {
8388
+ ref: fileInputRef,
8389
+ id: "invisible__attach__file",
8390
+ type: "file",
8391
+ multiple: true,
8392
+ onChange: handleAttachments,
8393
+ sx: { display: "none" }
8394
+ }
8395
+ ),
8396
+ /* @__PURE__ */ jsx(
8397
+ IconButton$2,
8398
+ {
8399
+ className: "ChatBarButton",
8400
+ disabled: isLoading,
8401
+ icon: "Ellipsis",
8402
+ variant: "icon-only",
8403
+ iconSize: "Sm",
8404
+ onClick: (ev) => {
8405
+ ApiaUtil$1.instance.menu.open({
8406
+ menuProps: {
8407
+ anchorPoint: { x: ev.clientX, y: ev.clientY }
8408
+ },
8409
+ items: menuItemsList
8410
+ });
8411
+ }
8412
+ }
8413
+ ),
8414
+ isRecording ? recordButton : /* @__PURE__ */ jsx(
8415
+ IconButton$2,
8416
+ {
8417
+ className: "ChatBarButton",
8418
+ isLoading,
8419
+ icon: "ArrowRight",
8420
+ variant: "icon-only",
8421
+ iconSize: "Sm",
8422
+ title: getLabel("btnBus").title,
8423
+ type: "submit"
8424
+ }
8425
+ )
8426
+ ]
8427
+ }
8428
+ );
8429
+ }
8430
+ );
8431
+
8432
+ var __defProp$2 = Object.defineProperty;
8433
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8434
+ var __publicField$2 = (obj, key, value) => {
8435
+ __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
8436
+ return value;
8437
+ };
8438
+ class CameraController {
8439
+ constructor() {
8440
+ __publicField$2(this, "state", {
8441
+ videoStream: null,
8442
+ isOpen: false
8443
+ });
8444
+ __publicField$2(this, "currentCapture", null);
8445
+ __publicField$2(this, "videoElement");
8446
+ __publicField$2(this, "Component", () => {
8447
+ return /* @__PURE__ */ jsx(
8448
+ "video",
8449
+ {
8450
+ ref: (el) => {
8451
+ if (el) {
8452
+ el.srcObject = this.videoElement.srcObject;
8453
+ el.autoplay = true;
8454
+ el.playsInline = true;
8455
+ }
8456
+ },
8457
+ style: { width: "100%", height: "auto" }
8458
+ }
8459
+ );
8460
+ });
8461
+ makeObservable(this, {
8462
+ state: observable,
8463
+ openCamera: action,
8464
+ closeCamera: action
8465
+ });
8466
+ this.videoElement = document.createElement("video");
8467
+ this.videoElement.autoplay = true;
8468
+ this.videoElement.playsInline = true;
8469
+ }
8470
+ async openCamera() {
8471
+ try {
8472
+ const stream = await navigator.mediaDevices.getUserMedia({ video: true });
8473
+ this.state.videoStream = stream;
8474
+ this.videoElement.srcObject = stream;
8475
+ this.state.isOpen = true;
8476
+ ApiaUtil$1.instance.modals.open({
8477
+ children: /* @__PURE__ */ jsx(this.Component, {}),
8478
+ onConfirm: () => {
8479
+ this.closeCamera();
8480
+ },
8481
+ onClose: () => {
8482
+ this.closeCamera();
8483
+ }
8484
+ });
8485
+ } catch (error) {
8486
+ console.error("Error while accessing the camera:", error);
8487
+ this.state.isOpen = false;
8488
+ this.closeCamera();
8489
+ }
8490
+ }
8491
+ async closeCamera() {
8492
+ if (!this.videoElement.srcObject)
8493
+ return null;
8494
+ const canvas = document.createElement("canvas");
8495
+ canvas.width = this.videoElement.videoWidth;
8496
+ canvas.height = this.videoElement.videoHeight;
8497
+ const ctx = canvas.getContext("2d");
8498
+ if (ctx)
8499
+ ctx.drawImage(this.videoElement, 0, 0, canvas.width, canvas.height);
8500
+ this.currentCapture = await new Promise((resolve) => {
8501
+ canvas.toBlob((blob) => {
8502
+ if (blob) {
8503
+ const file = new File([blob], "captured_image.jpg", {
8504
+ type: "image/jpeg"
8505
+ });
8506
+ resolve(file);
8507
+ } else {
8508
+ this.closeCamera();
8509
+ }
8510
+ }, "image/jpeg");
8511
+ }).finally(() => {
8512
+ this.state.videoStream?.getTracks().forEach((track) => track.stop());
8513
+ this.state.videoStream = null;
8514
+ this.videoElement.srcObject = null;
8515
+ this.state.isOpen = false;
8516
+ });
8517
+ }
8518
+ pop() {
8519
+ const returnFile = this.currentCapture;
8520
+ this.currentCapture = null;
8521
+ return returnFile;
8522
+ }
8523
+ }
8524
+
8525
+ var __defProp$1 = Object.defineProperty;
8526
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8527
+ var __publicField$1 = (obj, key, value) => {
8528
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
8529
+ return value;
8530
+ };
8531
+ class ChatController {
8532
+ constructor(props, onMessageSubmit) {
8533
+ this.onMessageSubmit = onMessageSubmit;
8534
+ __publicField$1(this, "currentIndex", 0);
8535
+ __publicField$1(this, "state", {
8536
+ isLoading: false,
8537
+ canRecord: true,
8538
+ canAttach: true,
8539
+ maxAttachmentsSize: 100,
8540
+ messages: [],
8541
+ currentMessage: new ChatMessage("", "user")
8542
+ });
8543
+ __publicField$1(this, "internalAudioRecorder", new AudioRecorder());
8544
+ __publicField$1(this, "internalCameraRecorder", new CameraController());
8545
+ __publicField$1(this, "maxId", 0);
8546
+ __publicField$1(this, "audioRecorder", {
8547
+ start: () => {
8548
+ this.state.isLoading = true;
8549
+ this.internalAudioRecorder.start().then(async (blob) => {
8550
+ this.state.currentMessage.attachments.push({
8551
+ id: String(this.maxId++),
8552
+ name: `userRecord_${this.audioRecorder.record++}.wav`,
8553
+ value: await getBase64FromBlob(blob)
8554
+ });
8555
+ this.handleSubmit();
8556
+ }).finally(() => {
8557
+ this.state.isLoading = false;
8558
+ });
8559
+ },
8560
+ stop: async () => {
8561
+ this.internalAudioRecorder.stop();
8562
+ },
8563
+ record: 0,
8564
+ state: this.internalAudioRecorder.state
8565
+ });
8566
+ __publicField$1(this, "handleSubmit", async () => {
8567
+ if (this.state.currentMessage.message || this.state.currentMessage.attachments.length > 0) {
8568
+ this.state.isLoading = true;
8569
+ await this.onMessageSubmit({
8570
+ message: this.state.currentMessage,
8571
+ ...this.getAdditionalProps()
8572
+ });
8573
+ this.state.isLoading = false;
8574
+ this.state.currentMessage = new ChatMessage("", "user");
8575
+ }
8576
+ });
8577
+ __publicField$1(this, "History", observer(() => /* @__PURE__ */ jsx(History, { messages: this.state.messages })));
8578
+ __publicField$1(this, "Attachments", observer(() => /* @__PURE__ */ jsx(
8579
+ Attachments,
8580
+ {
8581
+ attachments: this.state.currentMessage.attachments,
8582
+ onRemove: (a) => {
8583
+ this.removeAttachment(a);
8584
+ },
8585
+ onAddDescription: (a, ev) => this.state.currentMessage.addAttachmentDescription(a, ev)
8586
+ }
8587
+ )));
8588
+ __publicField$1(this, "TextArea", observer(() => /* @__PURE__ */ jsx(
8589
+ TextArea,
8590
+ {
8591
+ value: this.state.currentMessage.message,
8592
+ isLoading: this.state.isLoading,
8593
+ isRecording: this.internalAudioRecorder.state.recording,
8594
+ disablePrevButton: !this.canGoPrev(),
8595
+ disableNextButton: !this.canGoNext(),
8596
+ onChange: (ev) => {
8597
+ this.state.currentMessage.message = ev;
8598
+ },
8599
+ onSubmit: () => this.handleSubmit(),
8600
+ onClearHistory: () => {
8601
+ this.clearHistory();
8602
+ },
8603
+ onAttach: async (ev) => {
8604
+ this.state.currentMessage.attachments.push({
8605
+ ...ev,
8606
+ id: String(this.maxId++)
8607
+ });
8608
+ },
8609
+ onRecord: () => {
8610
+ !this.internalAudioRecorder.state.recording ? this.audioRecorder.start() : this.audioRecorder.stop();
8611
+ },
8612
+ onVideoRecord: async () => {
8613
+ !this.internalCameraRecorder.state.isOpen && await this.internalCameraRecorder.openCamera();
8614
+ await new Promise((resolve, _) => {
8615
+ const checkCapture = async () => {
8616
+ if (!this.internalCameraRecorder.state.isOpen) {
8617
+ const capture = this.internalCameraRecorder.pop();
8618
+ if (capture) {
8619
+ this.state.currentMessage.attachments.push({
8620
+ id: String(this.maxId++),
8621
+ name: capture.name,
8622
+ value: await getBase64FromFile(capture)
8623
+ });
8624
+ return resolve();
8625
+ }
8626
+ } else {
8627
+ requestAnimationFrame(checkCapture);
8628
+ }
8629
+ };
8630
+ checkCapture();
8631
+ });
8632
+ },
8633
+ onPrev: () => {
8634
+ this.prevMessage();
8635
+ },
8636
+ onNext: () => {
8637
+ this.nextMessage();
8638
+ },
8639
+ attachments: []
8640
+ }
8641
+ )));
8642
+ __publicField$1(this, "Renderer", () => /* @__PURE__ */ jsxs(
8643
+ Box,
8644
+ {
8645
+ ...getVariant("layout.common.newChat.controller"),
8646
+ className: "chat_controller",
8647
+ children: [
8648
+ /* @__PURE__ */ jsx(this.History, {}),
8649
+ /* @__PURE__ */ jsx(this.Attachments, {}),
8650
+ /* @__PURE__ */ jsx(this.TextArea, {})
8651
+ ]
8652
+ }
8653
+ ));
8654
+ this.state = Object.assign({}, this.state, props);
8655
+ makeObservable(this, { state: observable });
8656
+ }
8657
+ removeMessage(idx) {
8658
+ this.state.messages = this.state.messages.filter((_, i) => i !== idx);
8659
+ }
8660
+ addMessage(message) {
8661
+ this.state.messages.push(message);
8662
+ this.currentIndex = this.state.messages.length;
8663
+ }
8664
+ clearHistory() {
8665
+ this.state.messages = [];
8666
+ }
8667
+ clearMessage() {
8668
+ this.state.currentMessage = new ChatMessage("", "user");
8669
+ }
8670
+ removeAttachment(attachment) {
8671
+ this.state.currentMessage.removeAttachment(attachment);
8672
+ }
8673
+ isForHistory(message) {
8674
+ return message && message.messageType === "user";
8675
+ }
8676
+ canGoNext() {
8677
+ let condition = false;
8678
+ const slice = this.state.messages.slice(
8679
+ this.currentIndex,
8680
+ this.state.messages.length
8681
+ );
8682
+ const n = slice.length;
8683
+ if (this.currentIndex + 1 > n) {
8684
+ return condition;
8685
+ }
8686
+ for (let i = 0; i < n && !condition; i++) {
8687
+ const current = slice[i];
8688
+ condition = current.messageType === "user";
8689
+ }
8690
+ return condition;
8691
+ }
8692
+ canGoPrev() {
8693
+ let condition = false;
8694
+ if (this.currentIndex - 1 === -1) {
8695
+ return condition;
8696
+ }
8697
+ for (let i = this.state.messages.slice(0, this.currentIndex).length - 1; i >= 0 && !condition; i--) {
8698
+ const current = this.state.messages[i];
8699
+ condition = current.messageType === "user";
8700
+ }
8701
+ return condition;
8702
+ }
8703
+ nextMessage() {
8704
+ let newCurrentMessage = void 0;
8705
+ let i = this.currentIndex;
8706
+ const n = this.state.messages.length;
8707
+ if (n === 0 || n - 1 === i) {
8708
+ return;
8709
+ }
8710
+ while (!newCurrentMessage && i < n - 1) {
8711
+ newCurrentMessage = this.state.messages[i + 1];
8712
+ i++;
8713
+ if (this.isForHistory(newCurrentMessage)) {
8714
+ this.state.currentMessage = newCurrentMessage.clone();
8715
+ break;
8716
+ } else {
8717
+ newCurrentMessage = void 0;
8718
+ }
8719
+ if (i === this.currentIndex) {
8720
+ break;
8721
+ }
8722
+ }
8723
+ this.currentIndex = i;
8724
+ }
8725
+ prevMessage() {
8726
+ let newCurrentMessage = void 0;
8727
+ let i = this.currentIndex;
8728
+ const n = this.state.messages.length;
8729
+ if (n === 0 || i === 0) {
8730
+ return;
8731
+ }
8732
+ while (!newCurrentMessage && i > 0) {
8733
+ newCurrentMessage = this.state.messages[i - 1];
8734
+ i--;
8735
+ if (this.isForHistory(newCurrentMessage)) {
8736
+ this.state.currentMessage = newCurrentMessage.clone();
8737
+ break;
8738
+ } else {
8739
+ newCurrentMessage = void 0;
8740
+ }
8741
+ if (i === this.currentIndex) {
8742
+ break;
8743
+ }
8744
+ }
8745
+ this.currentIndex = i;
8746
+ }
8747
+ getAdditionalProps() {
8748
+ return {};
8749
+ }
8750
+ }
8751
+
8752
+ var __defProp = Object.defineProperty;
8753
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8754
+ var __publicField = (obj, key, value) => {
8755
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8756
+ return value;
8757
+ };
8758
+ class FloatingChatController extends ChatController {
8759
+ constructor(props, onMessageSubmit, modalTitle) {
8760
+ super({ ...props, isVisible: true }, onMessageSubmit);
8761
+ this.modalTitle = modalTitle;
8762
+ __publicField(this, "Window", observer(() => {
8763
+ return this.state.isVisible ? /* @__PURE__ */ jsx(
8764
+ IconButton,
8765
+ {
8766
+ className: "chat_controller__open",
8767
+ icon: "Magic",
8768
+ size: "Md",
8769
+ variant: "icon-outline",
8770
+ onClick: () => {
8771
+ this.state.isVisible = false;
8772
+ this.open(() => {
8773
+ this.state.isVisible = true;
8774
+ });
8775
+ }
8776
+ }
8777
+ ) : null;
8778
+ }));
8779
+ makeObservable({ open: action });
8780
+ }
8781
+ open(onClose) {
8782
+ ApiaUtil.instance.modals.open({
8783
+ variant: "layout.common.newChat.assistant.floatingAssistant",
8784
+ defaultPosition: {
8785
+ bottom: "10px",
8786
+ right: "10px"
8787
+ },
8788
+ draggable: true,
8789
+ children: /* @__PURE__ */ jsx(this.Renderer, {}),
8790
+ onClose,
8791
+ title: this.modalTitle
8792
+ });
8793
+ }
8794
+ }
8795
+
8796
+ export { Accordion, AccordionContext, AccordionItem, AccordionItemButton, AccordionItemContent, AccordionItemContext, AlertModal, ApiaFilter, ApiaUtil, ApiaUtilModalHandler, ApiaUtilTooltip, AutoEllipsis, Autocomplete, AutocompleteController, AutogrowTextarea, AutoscrollContainer, BaseButton, CalendarModal, Captcha, ChatController, ChatMessage, Checkbox$1 as Checkbox, CollapsiblePanel, Confirm, ConfirmModal, ContainerWithHeader, DateInput, DefaultIconRenderer, DefaultTabsLabelRenderer, DialogButtonBar, FieldErrorMessage, FieldLabel, FloatingChatController, IconButton, IconInput, IconsList, LabelBox, LinearLoader$1 as LinearLoader, ListSkeletonLoader, Listbox, ListboxItem, LoaderSpinner$1 as LoaderSpinner, Modal, NumberInput, Overlay, ProgressBar$1 as ProgressBar, RequiredMark, ScreenLocker, SimpleButton, SortableList, SortableListItem, Tab, Tabs, TabsContent, TabsController, TabsList, Toolbar, ToolbarController, ToolbarIconButton, ToolbarInput, ToolbarSelect, ToolbarSeparator, ToolbarTextButton, UnstyledSortableList, WaiTypeAhead, getBase64FromBlob, getBase64FromFile, getFieldErrorStyles, getFieldTouchedStyles, getFileExtension, importComponent, isImage, makeResponsiveComponent, parseNumberInputValueToNumber, parseNumberValueToNumberInput, useAccordionContext, useModal, useModalContext, useOtherTagButton };
7944
8797
  //# sourceMappingURL=index.js.map