@connectif/ui-components 2.0.6 → 2.0.8

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.
@@ -20,6 +20,10 @@ export type ChatProps = React.PropsWithChildren<{
20
20
  * Number that change to trigger scroll to class in scrollToLastClassName
21
21
  */
22
22
  triggerScroll?: number;
23
+ /**
24
+ * Distance between elements to calculate scrolled height. By default 12px because is margin top in chatMessage.
25
+ */
26
+ gapBetweenElements?: number;
23
27
  }>;
24
- declare const Chat: ({ children, header, backgroundColor, scrollToLastClassName, scrollbarColor, triggerScroll }: ChatProps) => import("react/jsx-runtime").JSX.Element;
28
+ declare const Chat: ({ children, header, backgroundColor, scrollToLastClassName, scrollbarColor, triggerScroll, gapBetweenElements }: ChatProps) => import("react/jsx-runtime").JSX.Element;
25
29
  export default Chat;
package/dist/index.js CHANGED
@@ -13908,7 +13908,8 @@ var Chat = ({
13908
13908
  backgroundColor: backgroundColor2,
13909
13909
  scrollToLastClassName,
13910
13910
  scrollbarColor,
13911
- triggerScroll
13911
+ triggerScroll,
13912
+ gapBetweenElements = 12
13912
13913
  }) => {
13913
13914
  const ref = React36.useRef(null);
13914
13915
  const innerRef = React36.useRef(null);
@@ -13929,21 +13930,40 @@ var Chat = ({
13929
13930
  setIsInitialize(true);
13930
13931
  return () => observer.disconnect();
13931
13932
  }, []);
13933
+ const getPaddingBottom = React36.useCallback(
13934
+ (lastElementClass, clientHeight) => {
13935
+ if (lastElementClass && innerRef.current) {
13936
+ let lastChildren = innerRef.current.children[innerRef.current.children.length - 1];
13937
+ if (!lastChildren) {
13938
+ lastChildren = lastElementClass;
13939
+ }
13940
+ const scrollTo = lastElementClass.offsetTop - lastElementClass.offsetHeight - gapBetweenElements;
13941
+ const innerRefScroll = lastChildren.offsetTop;
13942
+ const scrolledHeight = innerRefScroll - scrollTo;
13943
+ return clientHeight - scrolledHeight;
13944
+ }
13945
+ return PADDING_BOTTOM;
13946
+ },
13947
+ [gapBetweenElements]
13948
+ );
13932
13949
  React36.useEffect(() => {
13933
13950
  const container = ref.current;
13934
13951
  if (!container) {
13935
13952
  return;
13936
13953
  }
13937
- if (innerRef.current && innerRef.current.style.paddingBottom !== "0px" && innerRef.current.style.paddingBottom !== `${PADDING_BOTTOM}px` && innerRef.current.style.paddingBottom !== "") {
13938
- const paddingBottom = parseInt(
13939
- innerRef.current.style.paddingBottom || "0",
13940
- 10
13954
+ const elements = container.querySelectorAll(
13955
+ `.${scrollToLastClassName}`
13956
+ );
13957
+ const lastElementClass = elements[elements.length - 1];
13958
+ if (lastElementClass && innerRef.current && innerRef.current.style.paddingBottom !== `${PADDING_BOTTOM}px`) {
13959
+ const clientHeight = container.clientHeight - PADDING_BOTTOM;
13960
+ const paddingBottom = getPaddingBottom(
13961
+ lastElementClass,
13962
+ clientHeight
13941
13963
  );
13942
- const childrenHeight = innerRef.current.scrollHeight - paddingBottom;
13943
- const childrenHeightVisible = childrenHeight - container.scrollTop;
13944
- innerRef.current.style.paddingBottom = childrenHeightVisible > container.clientHeight ? "0px" : `${container.clientHeight - childrenHeightVisible}px`;
13964
+ innerRef.current.style.paddingBottom = paddingBottom >= clientHeight ? `${PADDING_BOTTOM}px` : `${paddingBottom}px`;
13945
13965
  }
13946
- }, [children]);
13966
+ }, [children, getPaddingBottom, scrollToLastClassName]);
13947
13967
  React36.useEffect(() => {
13948
13968
  const container = ref.current;
13949
13969
  if (!container || !scrollToLastClassName || !triggerScroll) {
@@ -13952,13 +13972,24 @@ var Chat = ({
13952
13972
  const elements = container.querySelectorAll(
13953
13973
  `.${scrollToLastClassName}`
13954
13974
  );
13955
- const last = elements[elements.length - 1];
13956
- if (last && innerRef.current) {
13957
- const paddingBottom = container.clientHeight - last.offsetHeight;
13975
+ const lastElementClass = elements[elements.length - 1];
13976
+ if (lastElementClass && innerRef.current) {
13977
+ const paddingBottom = getPaddingBottom(
13978
+ lastElementClass,
13979
+ container.clientHeight - PADDING_BOTTOM
13980
+ );
13958
13981
  innerRef.current.style.paddingBottom = `${paddingBottom}px`;
13959
- last.scrollIntoView({ behavior: "smooth", block: "start" });
13982
+ lastElementClass.scrollIntoView({
13983
+ behavior: "smooth",
13984
+ block: "start"
13985
+ });
13960
13986
  }
13961
- }, [scrollToLastClassName, triggerScroll]);
13987
+ }, [
13988
+ gapBetweenElements,
13989
+ getPaddingBottom,
13990
+ scrollToLastClassName,
13991
+ triggerScroll
13992
+ ]);
13962
13993
  return /* @__PURE__ */ jsxs36(
13963
13994
  Stack5,
13964
13995
  {
@@ -22720,10 +22751,6 @@ var TextEditor = function TextEditor2({
22720
22751
  icon: "sourcecode",
22721
22752
  onAction: () => {
22722
22753
  showCodeEditor();
22723
- const button = document.querySelector(
22724
- "button.tox-tbtn--enabled"
22725
- );
22726
- typeof button?.click === "function" && button.click();
22727
22754
  }
22728
22755
  });
22729
22756
  const setupProp = init?.setup;
@@ -26096,27 +26123,27 @@ var MinimizableWindow = React86.forwardRef(function MinimizableWindow2({
26096
26123
  var MinimizableWindow_default = MinimizableWindow;
26097
26124
 
26098
26125
  // src/hooks/useFormatters.ts
26099
- import { useCallback as useCallback18, useContext as useContext16 } from "react";
26126
+ import { useCallback as useCallback19, useContext as useContext16 } from "react";
26100
26127
  var useFormatters = () => {
26101
26128
  const { locale, currency, timezone } = useContext16(IntlContext);
26102
26129
  return {
26103
- formatCompactNumber: useCallback18(
26130
+ formatCompactNumber: useCallback19(
26104
26131
  (value) => formatCompactNumber(value, locale),
26105
26132
  [locale]
26106
26133
  ),
26107
- formatNumber: useCallback18(
26134
+ formatNumber: useCallback19(
26108
26135
  (value, fractionSize) => formatNumber(value, locale, fractionSize),
26109
26136
  [locale]
26110
26137
  ),
26111
- formatPercentage: useCallback18(
26138
+ formatPercentage: useCallback19(
26112
26139
  (value, fractionSize) => formatPercentage(value, locale, fractionSize),
26113
26140
  [locale]
26114
26141
  ),
26115
- formatCurrency: useCallback18(
26142
+ formatCurrency: useCallback19(
26116
26143
  (value, notation) => formatCurrency(value, locale, currency, notation),
26117
26144
  [currency, locale]
26118
26145
  ),
26119
- formatDate: useCallback18(
26146
+ formatDate: useCallback19(
26120
26147
  (date, format2) => formatDate(date, locale, timezone, format2),
26121
26148
  [locale, timezone]
26122
26149
  )