@elliemae/ds-chat 3.3.0-next.6 → 3.3.0-next.9

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 (37) hide show
  1. package/dist/cjs/Code-review - 20 june 2022.md +119 -0
  2. package/dist/cjs/exported-related/bubble/props.js.map +1 -1
  3. package/dist/cjs/parts/chat-container-messages-list/ChatContainerMessagesList.js +11 -208
  4. package/dist/cjs/parts/chat-container-messages-list/ChatContainerMessagesList.js.map +2 -2
  5. package/dist/cjs/parts/chat-container-messages-list/styled.js.map +1 -1
  6. package/dist/cjs/parts/chat-container-messages-list/useActionRef.js +58 -0
  7. package/dist/cjs/parts/chat-container-messages-list/useActionRef.js.map +7 -0
  8. package/dist/cjs/parts/chat-container-messages-list/useChatContainerMessageList.js +100 -0
  9. package/dist/cjs/parts/chat-container-messages-list/useChatContainerMessageList.js.map +7 -0
  10. package/dist/cjs/parts/chat-container-messages-list/useFocusAndScrollHelpers.js +78 -0
  11. package/dist/cjs/parts/chat-container-messages-list/useFocusAndScrollHelpers.js.map +7 -0
  12. package/dist/cjs/parts/chat-container-messages-list/useGetNewMessages.js.map +2 -2
  13. package/dist/cjs/parts/chat-container-messages-list/useGlobalEventListener.js +56 -0
  14. package/dist/cjs/parts/chat-container-messages-list/useGlobalEventListener.js.map +7 -0
  15. package/dist/cjs/parts/chat-container-messages-list/useKeyboard.js +136 -0
  16. package/dist/cjs/parts/chat-container-messages-list/useKeyboard.js.map +7 -0
  17. package/dist/cjs/react-desc-prop-types.js +20 -20
  18. package/dist/cjs/react-desc-prop-types.js.map +2 -2
  19. package/dist/esm/Code-review - 20 june 2022.md +119 -0
  20. package/dist/esm/exported-related/bubble/props.js.map +1 -1
  21. package/dist/esm/parts/chat-container-messages-list/ChatContainerMessagesList.js +13 -215
  22. package/dist/esm/parts/chat-container-messages-list/ChatContainerMessagesList.js.map +2 -2
  23. package/dist/esm/parts/chat-container-messages-list/styled.js.map +1 -1
  24. package/dist/esm/parts/chat-container-messages-list/useActionRef.js +36 -0
  25. package/dist/esm/parts/chat-container-messages-list/useActionRef.js.map +7 -0
  26. package/dist/esm/parts/chat-container-messages-list/useChatContainerMessageList.js +82 -0
  27. package/dist/esm/parts/chat-container-messages-list/useChatContainerMessageList.js.map +7 -0
  28. package/dist/esm/parts/chat-container-messages-list/useFocusAndScrollHelpers.js +56 -0
  29. package/dist/esm/parts/chat-container-messages-list/useFocusAndScrollHelpers.js.map +7 -0
  30. package/dist/esm/parts/chat-container-messages-list/useGetNewMessages.js.map +2 -2
  31. package/dist/esm/parts/chat-container-messages-list/useGlobalEventListener.js +34 -0
  32. package/dist/esm/parts/chat-container-messages-list/useGlobalEventListener.js.map +7 -0
  33. package/dist/esm/parts/chat-container-messages-list/useKeyboard.js +114 -0
  34. package/dist/esm/parts/chat-container-messages-list/useKeyboard.js.map +7 -0
  35. package/dist/esm/react-desc-prop-types.js +10 -10
  36. package/dist/esm/react-desc-prop-types.js.map +2 -2
  37. package/package.json +10 -10
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/exported-related/bubble/props.ts"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { PropTypes } from '@elliemae/ds-utilities';\nimport React from 'react';\n\n// eslint-disable-next-line no-unused-vars\nfunction noop<T extends unknown[]>(..._args: T): void {}\nexport const BUBBLE_TYPES = {\n SENDER: 'SENDER',\n RECIPIENT: 'RECIPIENT',\n DELIMITER: 'DELIMITER',\n SYSTEM: 'SYSTEM',\n};\n\nexport type BubbleTypesKeys = keyof typeof BUBBLE_TYPES;\nexport type BubbleTypesValues = typeof BUBBLE_TYPES[BubbleTypesKeys];\n\nexport interface BubblePropsT {\n dsId: string | number;\n type: BubbleTypesValues;\n title?: string;\n body: string;\n time: string;\n errorMessage: string | React.ReactChild;\n helpMessage: string | React.ReactChild;\n onClick: (id: string | number) => void;\n}\n\nexport const defaultBubbleProps: BubblePropsT = {\n dsId: '',\n type: BUBBLE_TYPES.SENDER,\n time: '',\n body: '',\n onClick: noop,\n errorMessage: '',\n helpMessage: '',\n};\n\nexport const BubblesPropTypes = {\n dsId: PropTypes.oneOfType([PropTypes.string, PropTypes.number])\n .description('Unique id for bubble')\n .defaultValue(defaultBubbleProps.dsId),\n type: PropTypes.oneOf([BUBBLE_TYPES.RECIPIENT, BUBBLE_TYPES.SENDER])\n .isRequired.description('Define bubble type ')\n .defaultValue(defaultBubbleProps.type),\n title: PropTypes.string.description('Title of the bubble').defaultValue(defaultBubbleProps.title),\n time: PropTypes.string.isRequired.description('Time of the bubble').defaultValue(defaultBubbleProps.title),\n body: PropTypes.oneOfType([PropTypes.string, PropTypes.element])\n .isRequired.description('Bubble content')\n .defaultValue(defaultBubbleProps.body),\n onClick: PropTypes.func.description('Callback when the bubble is tapped').defaultValue(defaultBubbleProps.onClick),\n errorMessage: PropTypes.oneOfType([PropTypes.string, PropTypes.element])\n .description('Error message to display at bottom of the bubble')\n .defaultValue(defaultBubbleProps.onClick),\n helpMessage: PropTypes.oneOfType([PropTypes.string, PropTypes.element])\n .description('Help message to display at bottom of the bubble')\n .defaultValue(defaultBubbleProps.onClick),\n};\n\nexport const propsArrowBubble = {\n type: PropTypes.oneOf([BUBBLE_TYPES.RECIPIENT, BUBBLE_TYPES.SENDER]).isRequired.defaultValue(defaultBubbleProps.type),\n};\n"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { PropTypes } from '@elliemae/ds-utilities';\nimport React from 'react';\n\n// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars\nfunction noop<T extends unknown[]>(..._args: T): void {}\nexport const BUBBLE_TYPES = {\n SENDER: 'SENDER',\n RECIPIENT: 'RECIPIENT',\n DELIMITER: 'DELIMITER',\n SYSTEM: 'SYSTEM',\n};\n\nexport type BubbleTypesKeys = keyof typeof BUBBLE_TYPES;\nexport type BubbleTypesValues = typeof BUBBLE_TYPES[BubbleTypesKeys];\n\nexport interface BubblePropsT {\n dsId: string | number;\n type: BubbleTypesValues;\n title?: string;\n body: string;\n time: string;\n errorMessage: string | React.ReactChild;\n helpMessage: string | React.ReactChild;\n onClick: (id: string | number) => void;\n}\n\nexport const defaultBubbleProps: BubblePropsT = {\n dsId: '',\n type: BUBBLE_TYPES.SENDER,\n time: '',\n body: '',\n onClick: noop,\n errorMessage: '',\n helpMessage: '',\n};\n\nexport const BubblesPropTypes = {\n dsId: PropTypes.oneOfType([PropTypes.string, PropTypes.number])\n .description('Unique id for bubble')\n .defaultValue(defaultBubbleProps.dsId),\n type: PropTypes.oneOf([BUBBLE_TYPES.RECIPIENT, BUBBLE_TYPES.SENDER])\n .isRequired.description('Define bubble type ')\n .defaultValue(defaultBubbleProps.type),\n title: PropTypes.string.description('Title of the bubble').defaultValue(defaultBubbleProps.title),\n time: PropTypes.string.isRequired.description('Time of the bubble').defaultValue(defaultBubbleProps.title),\n body: PropTypes.oneOfType([PropTypes.string, PropTypes.element])\n .isRequired.description('Bubble content')\n .defaultValue(defaultBubbleProps.body),\n onClick: PropTypes.func.description('Callback when the bubble is tapped').defaultValue(defaultBubbleProps.onClick),\n errorMessage: PropTypes.oneOfType([PropTypes.string, PropTypes.element])\n .description('Error message to display at bottom of the bubble')\n .defaultValue(defaultBubbleProps.onClick),\n helpMessage: PropTypes.oneOfType([PropTypes.string, PropTypes.element])\n .description('Help message to display at bottom of the bubble')\n .defaultValue(defaultBubbleProps.onClick),\n};\n\nexport const propsArrowBubble = {\n type: PropTypes.oneOf([BUBBLE_TYPES.RECIPIENT, BUBBLE_TYPES.SENDER]).isRequired.defaultValue(defaultBubbleProps.type),\n};\n"],
5
5
  "mappings": ";AAAA;ACAA;AAIA,iBAAsC,OAAgB;AAAC;AAChD,MAAM,eAAe;AAAA,EAC1B,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,WAAW;AAAA,EACX,QAAQ;AACV;AAgBO,MAAM,qBAAmC;AAAA,EAC9C,MAAM;AAAA,EACN,MAAM,aAAa;AAAA,EACnB,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AAAA,EACT,cAAc;AAAA,EACd,aAAa;AACf;AAEO,MAAM,mBAAmB;AAAA,EAC9B,MAAM,UAAU,UAAU,CAAC,UAAU,QAAQ,UAAU,MAAM,CAAC,EAC3D,YAAY,sBAAsB,EAClC,aAAa,mBAAmB,IAAI;AAAA,EACvC,MAAM,UAAU,MAAM,CAAC,aAAa,WAAW,aAAa,MAAM,CAAC,EAChE,WAAW,YAAY,qBAAqB,EAC5C,aAAa,mBAAmB,IAAI;AAAA,EACvC,OAAO,UAAU,OAAO,YAAY,qBAAqB,EAAE,aAAa,mBAAmB,KAAK;AAAA,EAChG,MAAM,UAAU,OAAO,WAAW,YAAY,oBAAoB,EAAE,aAAa,mBAAmB,KAAK;AAAA,EACzG,MAAM,UAAU,UAAU,CAAC,UAAU,QAAQ,UAAU,OAAO,CAAC,EAC5D,WAAW,YAAY,gBAAgB,EACvC,aAAa,mBAAmB,IAAI;AAAA,EACvC,SAAS,UAAU,KAAK,YAAY,oCAAoC,EAAE,aAAa,mBAAmB,OAAO;AAAA,EACjH,cAAc,UAAU,UAAU,CAAC,UAAU,QAAQ,UAAU,OAAO,CAAC,EACpE,YAAY,kDAAkD,EAC9D,aAAa,mBAAmB,OAAO;AAAA,EAC1C,aAAa,UAAU,UAAU,CAAC,UAAU,QAAQ,UAAU,OAAO,CAAC,EACnE,YAAY,iDAAiD,EAC7D,aAAa,mBAAmB,OAAO;AAC5C;AAEO,MAAM,mBAAmB;AAAA,EAC9B,MAAM,UAAU,MAAM,CAAC,aAAa,WAAW,aAAa,MAAM,CAAC,EAAE,WAAW,aAAa,mBAAmB,IAAI;AACtH;",
6
6
  "names": []
7
7
  }
@@ -1,15 +1,8 @@
1
1
  "use strict";
2
2
  import * as React from "react";
3
3
  import React2 from "react";
4
- import {
5
- useMemoMergePropsWithDefault,
6
- useGetGlobalAttributes,
7
- useValidateTypescriptPropTypes,
8
- describe
9
- } from "@elliemae/ds-utilities";
10
- import { useVirtual } from "react-virtual";
4
+ import { describe } from "@elliemae/ds-utilities";
11
5
  import DSButton from "@elliemae/ds-button";
12
- import { debounce } from "lodash";
13
6
  import { ChatBubble, BUBBLE_TYPES } from "../../exported-related/bubble";
14
7
  import { MessageDelimiter } from "../../exported-related/message-delimiter";
15
8
  import { SystemMessage } from "../../exported-related/system-message";
@@ -22,217 +15,22 @@ import {
22
15
  ListItem,
23
16
  StyledNewMessagesHiddenContainer
24
17
  } from "./styled";
25
- import { ChatContainerMessagesListPropTypes, defaultPropsMessagesList } from "../../react-desc-prop-types";
18
+ import { ChatContainerMessagesListPropTypes } from "../../react-desc-prop-types";
26
19
  import { useGetNewMessages } from "./useGetNewMessages";
27
- const getPadding = ({ hasMoreItems, bannerPosition, isLoading }) => {
28
- const padding = {
29
- paddingStart: 0,
30
- paddingEnd: -5
31
- };
32
- if ([hasMoreItems, bannerPosition, isLoading].some((item) => item === "top"))
33
- padding.paddingStart = 42;
34
- else if ([hasMoreItems, bannerPosition, isLoading].some((item) => item === "bottom"))
35
- padding.paddingEnd = 42;
36
- return padding;
37
- };
20
+ import { useChatContainerMessageList } from "./useChatContainerMessageList";
38
21
  const ChatContainerMessagesList = (props) => {
39
- const propsWithDefault = useMemoMergePropsWithDefault(props, defaultPropsMessagesList);
40
- useValidateTypescriptPropTypes(propsWithDefault, ChatContainerMessagesListPropTypes);
41
- const globalAttributes = useGetGlobalAttributes(propsWithDefault);
42
- const {
43
- sendingText,
44
- bannerPosition,
45
- sendingMessages,
46
- messages,
47
- actionRef,
48
- onScrollEnds,
49
- getMoreMessages,
50
- hasMoreItems,
51
- isLoading,
52
- bannerRef
53
- } = propsWithDefault;
54
- const pendingOnScroll = React2.useRef(false);
55
- const loadMoreRef = React2.useRef(null);
56
- const virtualListRef = React2.useRef();
57
22
  const {
58
- scrollToIndex: vScroll,
59
- totalSize,
60
- virtualItems
61
- } = useVirtual({
62
- size: messages?.length,
63
- parentRef: virtualListRef,
64
- overscan: 15,
65
- ...getPadding({ hasMoreItems, bannerPosition, isLoading }),
66
- estimateSize: React2.useCallback(() => 80, [])
67
- });
23
+ propsWithDefault,
24
+ globalAttributes,
25
+ useVirtualHelpers,
26
+ handleKey,
27
+ handleListKey,
28
+ loadMoreRef,
29
+ virtualListRef
30
+ } = useChatContainerMessageList(props);
31
+ const { sendingText, sendingMessages, messages, getMoreMessages, hasMoreItems, isLoading } = propsWithDefault;
32
+ const { totalSize, virtualItems } = useVirtualHelpers;
68
33
  const newMessages = useGetNewMessages(messages);
69
- const debouncedScroll = React2.useMemo(() => debounce(() => {
70
- if (document.visibilityState === "hidden") {
71
- pendingOnScroll.current = true;
72
- return [];
73
- }
74
- if (!virtualListRef.current)
75
- return [];
76
- pendingOnScroll.current = false;
77
- const { bottom, top } = virtualListRef.current?.getBoundingClientRect();
78
- const list = virtualListRef.current.querySelectorAll('[data-element="chat-element-list-item"]');
79
- const indexList = [];
80
- list.forEach((item) => {
81
- const { top: itemTop } = item.getBoundingClientRect();
82
- const itemPadding = 10;
83
- if (itemTop + itemPadding < bottom && itemTop + itemPadding > top)
84
- indexList.push(item.dataset.index);
85
- });
86
- if (onScrollEnds)
87
- onScrollEnds(indexList);
88
- return indexList;
89
- }, 500), [onScrollEnds]);
90
- const onScrollStop = React2.useCallback(debouncedScroll, [debouncedScroll]);
91
- const onlyFocus = React2.useCallback((index) => {
92
- virtualListRef.current.querySelector(`[data-index="${index}"]`).focus();
93
- }, []);
94
- const scrollAndFocus = React2.useCallback((index, b = { align: "center" }) => {
95
- vScroll(index, b);
96
- setTimeout(() => {
97
- onlyFocus(index);
98
- }, 300);
99
- onScrollStop();
100
- }, [onScrollStop, onlyFocus, vScroll]);
101
- const checkPendingOnScroll = React2.useCallback(() => {
102
- if (pendingOnScroll.current === true)
103
- onScrollStop();
104
- }, [onScrollStop]);
105
- React2.useEffect(() => {
106
- if (actionRef && actionRef.current) {
107
- actionRef.current.scrollToIndex = (a, b = { align: "center" }) => {
108
- vScroll(a, b);
109
- onScrollStop();
110
- };
111
- actionRef.current.getMessagesInView = onScrollStop;
112
- onScrollStop();
113
- actionRef.current.focusToIndex = (a, b = { align: "center" }) => {
114
- scrollAndFocus(a, b);
115
- };
116
- actionRef.current.focusToIndexWithoutScroll = onlyFocus;
117
- actionRef.current.focusToList = () => {
118
- virtualListRef.current?.focus();
119
- };
120
- }
121
- }, [actionRef, onScrollStop, onlyFocus, scrollAndFocus, vScroll]);
122
- React2.useEffect(() => {
123
- let handlerCallback = null;
124
- const localVirtualRef = virtualListRef.current;
125
- const onScroll = () => {
126
- if (handlerCallback)
127
- clearTimeout(handlerCallback);
128
- handlerCallback = setTimeout(onScrollStop, 300);
129
- };
130
- if (onScrollEnds) {
131
- virtualListRef.current.addEventListener("scroll", onScroll);
132
- }
133
- document.addEventListener("visibilitychange", checkPendingOnScroll);
134
- return () => {
135
- if (handlerCallback)
136
- clearTimeout(handlerCallback);
137
- if (onScrollEnds)
138
- localVirtualRef.removeEventListener("scroll", onScroll);
139
- document.removeEventListener("visibilitychange", checkPendingOnScroll);
140
- };
141
- }, [onScrollStop, onScrollEnds, checkPendingOnScroll]);
142
- const handleKey = React2.useCallback((e) => {
143
- const { key } = e;
144
- const index = Number(e.currentTarget.dataset.index);
145
- e.stopPropagation();
146
- switch (key) {
147
- case "ArrowUp":
148
- e.preventDefault();
149
- if (index > 0) {
150
- (virtualListRef.current?.querySelector(`[data-index="${index - 1}"]`)).focus();
151
- } else if (hasMoreItems === "top") {
152
- loadMoreRef.current?.focus();
153
- }
154
- break;
155
- case "ArrowDown":
156
- e.preventDefault();
157
- if (index < messages?.length - 1) {
158
- (virtualListRef.current?.querySelector(`[data-index="${index + 1}"]`)).focus();
159
- }
160
- break;
161
- case "Home":
162
- e.preventDefault();
163
- scrollAndFocus(0);
164
- break;
165
- case "End":
166
- e.preventDefault();
167
- scrollAndFocus(messages?.length - 1);
168
- break;
169
- case "Tab":
170
- if (hasMoreItems === "bottom" && !e.shiftKey) {
171
- e.preventDefault();
172
- loadMoreRef.current?.focus();
173
- } else if (hasMoreItems === "top" && e.shiftKey) {
174
- e.preventDefault();
175
- loadMoreRef.current?.focus();
176
- } else if (!e.shiftKey) {
177
- if (bannerPosition) {
178
- e.preventDefault();
179
- bannerRef?.current?.focusOnWrapper();
180
- }
181
- } else {
182
- e.preventDefault();
183
- virtualListRef.current?.focus();
184
- }
185
- break;
186
- default:
187
- break;
188
- }
189
- }, [bannerRef, hasMoreItems, messages?.length, bannerPosition, scrollAndFocus]);
190
- const handleListKey = React2.useCallback((e) => {
191
- const { key } = e;
192
- switch (key) {
193
- case "ArrowUp":
194
- e.preventDefault();
195
- if (document.activeElement !== loadMoreRef.current) {
196
- onlyFocus(onScrollStop()?.shift());
197
- }
198
- break;
199
- case "ArrowDown":
200
- e.preventDefault();
201
- if (document.activeElement === loadMoreRef.current) {
202
- virtualListRef.current.querySelector(`[data-index="0"]`).focus();
203
- } else {
204
- onlyFocus(onScrollStop()?.pop());
205
- }
206
- break;
207
- case "Home":
208
- e.preventDefault();
209
- scrollAndFocus(0);
210
- break;
211
- case "End":
212
- e.preventDefault();
213
- scrollAndFocus(messages?.length - 1);
214
- break;
215
- case "Tab":
216
- if (document.activeElement !== loadMoreRef.current) {
217
- if (hasMoreItems === "bottom" && !e.shiftKey) {
218
- e.preventDefault();
219
- loadMoreRef.current?.focus();
220
- } else if (!e.shiftKey) {
221
- e.preventDefault();
222
- actionRef.current.focusToComposer();
223
- }
224
- } else if (!e.shiftKey) {
225
- e.preventDefault();
226
- actionRef.current.focusToComposer();
227
- } else {
228
- e.preventDefault();
229
- virtualListRef.current?.focus();
230
- }
231
- break;
232
- default:
233
- break;
234
- }
235
- }, [actionRef, hasMoreItems, messages?.length, onScrollStop, onlyFocus, scrollAndFocus]);
236
34
  const render = React2.useMemo(() => virtualItems.map((virtualItem) => {
237
35
  const { index, measureRef, start } = virtualItem;
238
36
  const row = messages[index];
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/chat-container-messages-list/ChatContainerMessagesList.tsx"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\n/* eslint-disable jsx-a11y/no-noninteractive-tabindex */\n/* eslint-disable max-lines */\nimport React, { CSSProperties, WeakValidationMap } from 'react';\nimport {\n useMemoMergePropsWithDefault,\n useGetGlobalAttributes,\n useValidateTypescriptPropTypes,\n describe,\n} from '@elliemae/ds-utilities';\nimport { useVirtual } from 'react-virtual';\nimport DSButton from '@elliemae/ds-button';\nimport { debounce } from 'lodash';\nimport { ChatBubble, BUBBLE_TYPES } from '../../exported-related/bubble';\nimport { MessageDelimiter } from '../../exported-related/message-delimiter';\nimport { SystemMessage } from '../../exported-related/system-message';\nimport {\n StyledWrapperListItem,\n StyledChatContainerContentList,\n StyledChatContainerContentListScroll,\n StyledWrapper,\n StyledLoadMoreContainer,\n ListItem,\n StyledNewMessagesHiddenContainer,\n} from './styled';\nimport { DSChatT, ChatContainerMessagesListPropTypes, defaultPropsMessagesList } from '../../react-desc-prop-types';\nimport { useGetNewMessages } from './useGetNewMessages';\n\nconst getPadding = ({ hasMoreItems, bannerPosition, isLoading }: DSChatT.GetPaddingT) => {\n const padding = {\n paddingStart: 0,\n paddingEnd: -5,\n };\n if ([hasMoreItems, bannerPosition, isLoading].some((item) => item === 'top')) padding.paddingStart = 42;\n else if ([hasMoreItems, bannerPosition, isLoading].some((item) => item === 'bottom')) padding.paddingEnd = 42;\n return padding;\n};\nconst ChatContainerMessagesList: React.ComponentType<DSChatT.MessagesListProps> = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault<DSChatT.MessagesListProps>(props, defaultPropsMessagesList);\n useValidateTypescriptPropTypes<DSChatT.MessagesListProps>(propsWithDefault, ChatContainerMessagesListPropTypes);\n const globalAttributes = useGetGlobalAttributes(propsWithDefault);\n const {\n sendingText,\n bannerPosition,\n sendingMessages,\n messages,\n actionRef,\n onScrollEnds,\n getMoreMessages,\n hasMoreItems,\n isLoading,\n bannerRef,\n } = propsWithDefault;\n const pendingOnScroll = React.useRef(false);\n const loadMoreRef = React.useRef(null);\n const virtualListRef = React.useRef<HTMLDivElement>();\n // estimateSize should not be really required given what was stated on\n // https://github.com/tannerlinsley/react-virtual/issues/23\n const {\n scrollToIndex: vScroll,\n totalSize,\n virtualItems,\n } = useVirtual({\n size: messages?.length,\n parentRef: virtualListRef,\n overscan: 15,\n ...getPadding({ hasMoreItems, bannerPosition, isLoading }),\n estimateSize: React.useCallback(() => 80, []),\n });\n\n const newMessages = useGetNewMessages(messages);\n\n const debouncedScroll = React.useMemo(\n () =>\n debounce((): number[] => {\n if (document.visibilityState === 'hidden') {\n pendingOnScroll.current = true;\n return [];\n }\n if (!virtualListRef.current) return [];\n pendingOnScroll.current = false;\n const { bottom, top } = virtualListRef.current?.getBoundingClientRect();\n\n const list = virtualListRef.current.querySelectorAll(\n '[data-element=\"chat-element-list-item\"]',\n ) as NodeListOf<HTMLDivElement>;\n const indexList = [];\n list.forEach((item: HTMLElement) => {\n const { top: itemTop } = item.getBoundingClientRect();\n\n const itemPadding = 10;\n if (itemTop + itemPadding < bottom && itemTop + itemPadding > top) indexList.push(item.dataset.index);\n });\n if (onScrollEnds) onScrollEnds(indexList);\n return indexList;\n }, 500),\n [onScrollEnds],\n );\n\n const onScrollStop = React.useCallback(debouncedScroll, [debouncedScroll]);\n\n const onlyFocus = React.useCallback((index?: number) => {\n (virtualListRef.current.querySelector(`[data-index=\"${index}\"]`) as HTMLDivElement).focus();\n }, []);\n\n const scrollAndFocus = React.useCallback(\n (index: number, b = { align: 'center' }) => {\n vScroll(index, b);\n setTimeout(() => {\n onlyFocus(index);\n }, 300);\n onScrollStop();\n },\n [onScrollStop, onlyFocus, vScroll],\n );\n\n const checkPendingOnScroll = React.useCallback(() => {\n if (pendingOnScroll.current === true) onScrollStop();\n }, [onScrollStop]);\n\n React.useEffect(() => {\n if (actionRef && actionRef.current) {\n actionRef.current.scrollToIndex = (a, b = { align: 'center' }) => {\n vScroll(a, b as any);\n onScrollStop();\n };\n actionRef.current.getMessagesInView = onScrollStop;\n onScrollStop(); // init useMemo due to debounce use.\n actionRef.current.focusToIndex = (a, b = { align: 'center' } as ScrollToOptions) => {\n scrollAndFocus(a, b);\n };\n actionRef.current.focusToIndexWithoutScroll = onlyFocus;\n actionRef.current.focusToList = () => {\n virtualListRef.current?.focus();\n };\n }\n }, [actionRef, onScrollStop, onlyFocus, scrollAndFocus, vScroll]);\n\n React.useEffect(() => {\n let handlerCallback = null;\n const localVirtualRef = virtualListRef.current;\n const onScroll = () => {\n if (handlerCallback) clearTimeout(handlerCallback);\n handlerCallback = setTimeout(onScrollStop, 300);\n };\n if (onScrollEnds) {\n virtualListRef.current.addEventListener('scroll', onScroll);\n }\n document.addEventListener('visibilitychange', checkPendingOnScroll);\n return () => {\n if (handlerCallback) clearTimeout(handlerCallback);\n if (onScrollEnds) localVirtualRef.removeEventListener('scroll', onScroll);\n document.removeEventListener('visibilitychange', checkPendingOnScroll);\n };\n }, [onScrollStop, onScrollEnds, checkPendingOnScroll]);\n\n const handleKey = React.useCallback(\n (e: React.KeyboardEvent) => {\n const { key } = e;\n const index = Number(e.currentTarget.dataset.index);\n e.stopPropagation();\n switch (key) {\n case 'ArrowUp':\n e.preventDefault();\n if (index > 0) {\n (virtualListRef.current?.querySelector(`[data-index=\"${index - 1}\"]`) as HTMLDivElement).focus();\n } else if (hasMoreItems === 'top') {\n loadMoreRef.current?.focus();\n }\n break;\n case 'ArrowDown':\n e.preventDefault();\n if (index < messages?.length - 1) {\n (virtualListRef.current?.querySelector(`[data-index=\"${index + 1}\"]`) as HTMLDivElement).focus();\n }\n break;\n case 'Home':\n e.preventDefault();\n scrollAndFocus(0);\n break;\n case 'End':\n e.preventDefault();\n scrollAndFocus(messages?.length - 1);\n break;\n case 'Tab':\n if (hasMoreItems === 'bottom' && !e.shiftKey) {\n e.preventDefault();\n loadMoreRef.current?.focus();\n } else if (hasMoreItems === 'top' && e.shiftKey) {\n e.preventDefault();\n loadMoreRef.current?.focus();\n } else if (!e.shiftKey) {\n if (bannerPosition) {\n e.preventDefault();\n bannerRef?.current?.focusOnWrapper();\n }\n } else {\n e.preventDefault();\n virtualListRef.current?.focus();\n }\n break;\n default:\n break;\n }\n },\n [bannerRef, hasMoreItems, messages?.length, bannerPosition, scrollAndFocus],\n );\n const handleListKey = React.useCallback(\n (e: React.KeyboardEvent) => {\n const { key } = e;\n switch (key) {\n case 'ArrowUp':\n e.preventDefault();\n if (document.activeElement !== loadMoreRef.current) {\n onlyFocus(onScrollStop()?.shift());\n }\n break;\n case 'ArrowDown':\n e.preventDefault();\n if (document.activeElement === loadMoreRef.current) {\n (virtualListRef.current.querySelector(`[data-index=\"0\"]`) as HTMLDivElement).focus();\n } else {\n onlyFocus(onScrollStop()?.pop());\n }\n break;\n case 'Home':\n e.preventDefault();\n scrollAndFocus(0);\n break;\n case 'End':\n e.preventDefault();\n scrollAndFocus(messages?.length - 1);\n break;\n case 'Tab':\n if (document.activeElement !== loadMoreRef.current) {\n if (hasMoreItems === 'bottom' && !e.shiftKey) {\n e.preventDefault();\n loadMoreRef.current?.focus();\n } else if (!e.shiftKey) {\n e.preventDefault();\n actionRef.current.focusToComposer();\n }\n } else if (!e.shiftKey) {\n e.preventDefault();\n actionRef.current.focusToComposer();\n } else {\n e.preventDefault();\n virtualListRef.current?.focus();\n }\n break;\n default:\n break;\n }\n },\n [actionRef, hasMoreItems, messages?.length, onScrollStop, onlyFocus, scrollAndFocus],\n );\n\n const render = React.useMemo(\n () =>\n virtualItems.map((virtualItem) => {\n const { index, measureRef, start } = virtualItem;\n const row = messages[index];\n const isSending = sendingMessages && sendingMessages.find((m) => m === row.dsId);\n const style: CSSProperties = {\n position: 'absolute',\n top: 0,\n left: 0,\n transform: `translateY(${start}px)`,\n width: '100%',\n };\n\n return (\n <ListItem\n data-element=\"chat-element-list-item\"\n data-index={index}\n key={`ds-chat-bubble-${index}-${row.dsId}-${row.type}`}\n style={style}\n ref={measureRef}\n tabIndex={-1}\n onKeyDown={handleKey}\n role=\"listitem\"\n >\n <StyledWrapperListItem type={row.type}>\n {row.type === BUBBLE_TYPES.SENDER || row.type === BUBBLE_TYPES.RECIPIENT ? (\n // eslint-disable-next-line eslint-comments/no-unlimited-disable\n <ChatBubble {...row} helpMessage={isSending ? sendingText : row.helpMessage} />\n ) : null}\n {row.type === BUBBLE_TYPES.DELIMITER ? <MessageDelimiter {...row} /> : null}\n {row.type === BUBBLE_TYPES.SYSTEM ? <SystemMessage {...row} /> : null}\n </StyledWrapperListItem>\n </ListItem>\n );\n }),\n [virtualItems, messages, sendingMessages, handleKey, sendingText],\n );\n\n return (\n <StyledWrapper {...globalAttributes}>\n <StyledChatContainerContentList\n data-testid=\"chat-thread-container\"\n tabIndex={0}\n ref={virtualListRef as React.RefObject<HTMLDivElement>}\n role=\"list\"\n onKeyDown={handleListKey}\n >\n <StyledChatContainerContentListScroll height={`${totalSize}px`}>\n {!isLoading && hasMoreItems ? (\n <StyledLoadMoreContainer hasMoreItems={hasMoreItems}>\n <DSButton\n labelText=\"Load More\"\n buttonType=\"secondary\"\n onClick={getMoreMessages}\n data-testid=\"ds-chat-load-more-btn\"\n innerRef={loadMoreRef}\n />\n </StyledLoadMoreContainer>\n ) : null}\n {render}\n </StyledChatContainerContentListScroll>\n </StyledChatContainerContentList>\n {/* We repeat the render with the new available messages */}\n <StyledNewMessagesHiddenContainer aria-live=\"polite\" aria-hidden=\"false\">\n {newMessages.map((newMessage) => (\n <p key={newMessage.dsId}>\n {newMessage.title} {newMessage.time} {newMessage.body} {newMessage.errorMessage} {newMessage.helpMessage}\n </p>\n ))}\n </StyledNewMessagesHiddenContainer>\n </StyledWrapper>\n );\n};\n\nChatContainerMessagesList.propTypes = ChatContainerMessagesListPropTypes as WeakValidationMap<unknown>;\nChatContainerMessagesList.displayName = 'ChatContainerMessagesList';\nconst ChatContainerMessagesListWithSchema = describe(ChatContainerMessagesList);\nChatContainerMessagesListWithSchema.propTypes = ChatContainerMessagesListPropTypes as WeakValidationMap<unknown>;\n\nexport { ChatContainerMessagesList, ChatContainerMessagesListWithSchema };\n"],
5
- "mappings": ";AAAA;ACGA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA;AACA;AAEA,MAAM,aAAa,CAAC,EAAE,cAAc,gBAAgB,gBAAqC;AACvF,QAAM,UAAU;AAAA,IACd,cAAc;AAAA,IACd,YAAY;AAAA,EACd;AACA,MAAI,CAAC,cAAc,gBAAgB,SAAS,EAAE,KAAK,CAAC,SAAS,SAAS,KAAK;AAAG,YAAQ,eAAe;AAAA,WAC5F,CAAC,cAAc,gBAAgB,SAAS,EAAE,KAAK,CAAC,SAAS,SAAS,QAAQ;AAAG,YAAQ,aAAa;AAC3G,SAAO;AACT;AACA,MAAM,4BAA4E,CAAC,UAAU;AAC3F,QAAM,mBAAmB,6BAAwD,OAAO,wBAAwB;AAChH,iCAA0D,kBAAkB,kCAAkC;AAC9G,QAAM,mBAAmB,uBAAuB,gBAAgB;AAChE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,MACE;AACJ,QAAM,kBAAkB,OAAM,OAAO,KAAK;AAC1C,QAAM,cAAc,OAAM,OAAO,IAAI;AACrC,QAAM,iBAAiB,OAAM,OAAuB;AAGpD,QAAM;AAAA,IACJ,eAAe;AAAA,IACf;AAAA,IACA;AAAA,MACE,WAAW;AAAA,IACb,MAAM,UAAU;AAAA,IAChB,WAAW;AAAA,IACX,UAAU;AAAA,IACV,GAAG,WAAW,EAAE,cAAc,gBAAgB,UAAU,CAAC;AAAA,IACzD,cAAc,OAAM,YAAY,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KAAa,IAC3E,MACH,IAAI,SAAS,aAAa,YAAY,qCAAC;AAAA,MAAkB,GAAG;AAAA,KAAK,IAAK,MACtE,IAAI,SAAS,aAAa,SAAS,qCAAC;AAAA,MAAe,GAAG;AAAA,KAAK,IAAK,IACnE,CACF;AAAA,EAEJ,CAAC,GACH,CAAC,cAAc,UAAU,iBAAiB,WAAW,WAAW,CAClE;AAEA,SACE,qCAAC;AAAA,IAAe,GAAG;AAAA,KACjB,qCAAC;AAAA,IACC,eAAY;AAAA,IACZ,UAAU;AAAA,IACV,KAAK;AAAA,IACL,MAAK;AAAA,IACL,WAAW;AAAA,KAEX,qCAAC;AAAA,IAAqC,QAAQ,GAAG;AAAA,KAC9C,CAAC,aAAa,eACb,qCAAC;AAAA,IAAwB;AAAA,KACvB,qCAAC;AAAA,IACC,WAAU;AAAA,IACV,YAAW;AAAA,IACX,SAAS;AAAA,IACT,eAAY;AAAA,IACZ,UAAU;AAAA,GACZ,CACF,IACE,MACH,MACH,CACF,GAEA,qCAAC;AAAA,IAAiC,aAAU;AAAA,IAAS,eAAY;AAAA,KAC9D,YAAY,IAAI,CAAC,eAChB,qCAAC;AAAA,IAAE,KAAK,WAAW;AAAA,KAChB,WAAW,OAAM,KAAE,WAAW,MAAK,KAAE,WAAW,MAAK,KAAE,WAAW,cAAa,KAAE,WAAW,WAC/F,CACD,CACH,CACF;AAEJ;AAEA,0BAA0B,YAAY;AACtC,0BAA0B,cAAc;AACxC,MAAM,sCAAsC,SAAS,yBAAyB;AAC9E,oCAAoC,YAAY;",
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\n/* eslint-disable jsx-a11y/no-noninteractive-tabindex */\n/* eslint-disable max-lines */\nimport React, { CSSProperties, WeakValidationMap } from 'react';\nimport { describe } from '@elliemae/ds-utilities';\nimport DSButton from '@elliemae/ds-button';\nimport { ChatBubble, BUBBLE_TYPES } from '../../exported-related/bubble';\nimport { MessageDelimiter } from '../../exported-related/message-delimiter';\nimport { SystemMessage } from '../../exported-related/system-message';\nimport {\n StyledWrapperListItem,\n StyledChatContainerContentList,\n StyledChatContainerContentListScroll,\n StyledWrapper,\n StyledLoadMoreContainer,\n ListItem,\n StyledNewMessagesHiddenContainer,\n} from './styled';\nimport { DSChatT, ChatContainerMessagesListPropTypes } from '../../react-desc-prop-types';\nimport { useGetNewMessages } from './useGetNewMessages';\nimport { useChatContainerMessageList } from './useChatContainerMessageList';\n\nconst ChatContainerMessagesList: React.ComponentType<DSChatT.MessagesListProps> = (props) => {\n const {\n propsWithDefault,\n globalAttributes,\n useVirtualHelpers,\n handleKey,\n handleListKey,\n loadMoreRef,\n virtualListRef,\n } = useChatContainerMessageList(props);\n\n const { sendingText, sendingMessages, messages, getMoreMessages, hasMoreItems, isLoading } = propsWithDefault;\n const { totalSize, virtualItems } = useVirtualHelpers;\n\n const newMessages = useGetNewMessages(messages);\n\n const render = React.useMemo(\n () =>\n virtualItems.map((virtualItem) => {\n const { index, measureRef, start } = virtualItem;\n const row = messages[index];\n const isSending = sendingMessages && sendingMessages.find((m) => m === row.dsId);\n const style: CSSProperties = {\n position: 'absolute',\n top: 0,\n left: 0,\n transform: `translateY(${start}px)`,\n width: '100%',\n };\n\n return (\n <ListItem\n data-element=\"chat-element-list-item\"\n data-index={index}\n key={`ds-chat-bubble-${index}-${row.dsId}-${row.type}`}\n style={style}\n ref={measureRef}\n tabIndex={-1}\n onKeyDown={handleKey}\n role=\"listitem\"\n >\n <StyledWrapperListItem type={row.type}>\n {row.type === BUBBLE_TYPES.SENDER || row.type === BUBBLE_TYPES.RECIPIENT ? (\n // eslint-disable-next-line eslint-comments/no-unlimited-disable\n <ChatBubble {...row} helpMessage={isSending ? sendingText : row.helpMessage} />\n ) : null}\n {row.type === BUBBLE_TYPES.DELIMITER ? <MessageDelimiter {...row} /> : null}\n {row.type === BUBBLE_TYPES.SYSTEM ? <SystemMessage {...row} /> : null}\n </StyledWrapperListItem>\n </ListItem>\n );\n }),\n [virtualItems, messages, sendingMessages, handleKey, sendingText],\n );\n\n return (\n <StyledWrapper {...globalAttributes}>\n <StyledChatContainerContentList\n data-testid=\"chat-thread-container\"\n tabIndex={0}\n ref={virtualListRef as React.RefObject<HTMLDivElement>}\n role=\"list\"\n onKeyDown={handleListKey}\n >\n <StyledChatContainerContentListScroll height={`${totalSize}px`}>\n {!isLoading && hasMoreItems ? (\n <StyledLoadMoreContainer hasMoreItems={hasMoreItems}>\n <DSButton\n labelText=\"Load More\"\n buttonType=\"secondary\"\n onClick={getMoreMessages}\n data-testid=\"ds-chat-load-more-btn\"\n innerRef={loadMoreRef}\n />\n </StyledLoadMoreContainer>\n ) : null}\n {render}\n </StyledChatContainerContentListScroll>\n </StyledChatContainerContentList>\n {/* We repeat the render with the new available messages */}\n <StyledNewMessagesHiddenContainer aria-live=\"polite\" aria-hidden=\"false\">\n {newMessages.map((newMessage) => (\n <p key={newMessage.dsId}>\n {newMessage.title} {newMessage.time} {newMessage.body} {newMessage.errorMessage} {newMessage.helpMessage}\n </p>\n ))}\n </StyledNewMessagesHiddenContainer>\n </StyledWrapper>\n );\n};\n\nChatContainerMessagesList.propTypes = ChatContainerMessagesListPropTypes as WeakValidationMap<unknown>;\nChatContainerMessagesList.displayName = 'ChatContainerMessagesList';\nconst ChatContainerMessagesListWithSchema = describe(ChatContainerMessagesList);\nChatContainerMessagesListWithSchema.propTypes = ChatContainerMessagesListPropTypes as WeakValidationMap<unknown>;\n\nexport { ChatContainerMessagesList, ChatContainerMessagesListWithSchema };\n"],
5
+ "mappings": ";AAAA;ACGA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA;AACA;AACA;AAEA,MAAM,4BAA4E,CAAC,UAAU;AAC3F,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,MACE,4BAA4B,KAAK;AAErC,QAAM,EAAE,aAAa,i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ACb,qCAAC;AAAA,IAAwB;AAAA,KACvB,qCAAC;AAAA,IACC,WAAU;AAAA,IACV,YAAW;AAAA,IACX,SAAS;AAAA,IACT,eAAY;AAAA,IACZ,UAAU;AAAA,GACZ,CACF,IACE,MACH,MACH,CACF,GAEA,qCAAC;AAAA,IAAiC,aAAU;AAAA,IAAS,eAAY;AAAA,KAC9D,YAAY,IAAI,CAAC,eAChB,qCAAC;AAAA,IAAE,KAAK,WAAW;AAAA,KAChB,WAAW,OAAM,KAAE,WAAW,MAAK,KAAE,WAAW,MAAK,KAAE,WAAW,cAAa,KAAE,WAAW,WAC/F,CACD,CACH,CACF;AAEJ;AAEA,0BAA0B,YAAY;AACtC,0BAA0B,cAAc;AACxC,MAAM,sCAAsC,SAAS,yBAAyB;AAC9E,oCAAoC,YAAY;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/chat-container-messages-list/styled.ts"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { styled } from '@elliemae/ds-system';\nimport { BUBBLE_TYPES } from '../../exported-related/bubble/index';\nimport { BubbleProps } from '../../exported-related/bubble/props';\n\nexport const StyledWrapper = styled.div`\n width: 100%;\n height: 100%;\n`;\n\n// list\nexport const StyledWrapperListItem = styled.div<Partial<BubbleProps>>`\n min-width: 100%;\n ${(props) =>\n props.type === BUBBLE_TYPES.SENDER &&\n `padding: ${props.theme.space.xxs} ${props.theme.space.xxs} ${props.theme.space.xxs} 13%\n `};\n ${(props) =>\n props.type === BUBBLE_TYPES.RECIPIENT &&\n `padding: ${props.theme.space.xxs} 13% ${props.theme.space.xxs}\n ${props.theme.space.xxs}\n `};\n ${(props) =>\n props.type === BUBBLE_TYPES.SYSTEM &&\n `padding: ${props.theme.space.xxs} 0px\n `};\n`;\n\nexport const StyledChatContainerContentList = styled.div`\n width: 100%;\n height: 100%;\n padding: ${(props) => props.theme.space.xs};\n padding-bottom: 0;\n overflow-y: auto;\n overflow-x: hidden;\n`;\n\nexport const StyledNewMessagesHiddenContainer = styled.div`\n position: absolute;\n width: 1px;\n height: 1px;\n margin: -1px;\n border: 0;\n padding: 0;\n overflow: hidden;\n clip: rect(0 0 0 0);\n clip-path: inset(100%);\n white-space: nowrap;\n`;\n\nexport const StyledChatContainerContentListScroll = styled.div<{ height: string }>`\n width: 100%;\n height: ${(props) => props.height};\n position: relative;\n`;\n\nexport const StyledLoadMoreContainer = styled.div<{ hasMoreItems?: 'top' | 'bottom' }>`\n position: absolute;\n width: calc(100% + ${(props) => props.theme.space.xxs});\n padding: ${(props) => props.theme.space.xxs};\n left: -${(props) => props.theme.space.xxs};\n right: -${(props) => props.theme.space.xxs};\n display: grid;\n justify-content: center;\n align-items: center;\n ${(props) => (props.hasMoreItems === 'top' ? 'top: 0;' : '')}\n ${(props) => (props.hasMoreItems === 'bottom' ? 'bottom: 0;' : '')}\n`;\nexport const ListItem = styled.div`\n &:focus,\n &:focus-visible {\n outline: none;\n &:after {\n content: '';\n display: block;\n position: absolute;\n top: 0;\n left: -${(props) => props.theme.space.xxs};\n pointer-events: none;\n border-radius: 2px;\n background-color: #ebedf0;\n width: calc(100% + 24px);\n border: 2px solid #1e79c2;\n height: 100%;\n z-index: -1;\n }\n }\n`;\n"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { styled } from '@elliemae/ds-system';\nimport { BUBBLE_TYPES } from '../../exported-related/bubble/index';\nimport { BubblePropsT } from '../../exported-related/bubble/props';\n\nexport const StyledWrapper = styled.div`\n width: 100%;\n height: 100%;\n`;\n\n// list\nexport const StyledWrapperListItem = styled.div<Partial<BubblePropsT>>`\n min-width: 100%;\n ${(props) =>\n props.type === BUBBLE_TYPES.SENDER &&\n `padding: ${props.theme.space.xxs} ${props.theme.space.xxs} ${props.theme.space.xxs} 13%\n `};\n ${(props) =>\n props.type === BUBBLE_TYPES.RECIPIENT &&\n `padding: ${props.theme.space.xxs} 13% ${props.theme.space.xxs}\n ${props.theme.space.xxs}\n `};\n ${(props) =>\n props.type === BUBBLE_TYPES.SYSTEM &&\n `padding: ${props.theme.space.xxs} 0px\n `};\n`;\n\nexport const StyledChatContainerContentList = styled.div`\n width: 100%;\n height: 100%;\n padding: ${(props) => props.theme.space.xs};\n padding-bottom: 0;\n overflow-y: auto;\n overflow-x: hidden;\n`;\n\nexport const StyledNewMessagesHiddenContainer = styled.div`\n position: absolute;\n width: 1px;\n height: 1px;\n margin: -1px;\n border: 0;\n padding: 0;\n overflow: hidden;\n clip: rect(0 0 0 0);\n clip-path: inset(100%);\n white-space: nowrap;\n`;\n\nexport const StyledChatContainerContentListScroll = styled.div<{ height: string }>`\n width: 100%;\n height: ${(props) => props.height};\n position: relative;\n`;\n\nexport const StyledLoadMoreContainer = styled.div<{ hasMoreItems?: 'top' | 'bottom' }>`\n position: absolute;\n width: calc(100% + ${(props) => props.theme.space.xxs});\n padding: ${(props) => props.theme.space.xxs};\n left: -${(props) => props.theme.space.xxs};\n right: -${(props) => props.theme.space.xxs};\n display: grid;\n justify-content: center;\n align-items: center;\n ${(props) => (props.hasMoreItems === 'top' ? 'top: 0;' : '')}\n ${(props) => (props.hasMoreItems === 'bottom' ? 'bottom: 0;' : '')}\n`;\nexport const ListItem = styled.div`\n &:focus,\n &:focus-visible {\n outline: none;\n &:after {\n content: '';\n display: block;\n position: absolute;\n top: 0;\n left: -${(props) => props.theme.space.xxs};\n pointer-events: none;\n border-radius: 2px;\n background-color: #ebedf0;\n width: calc(100% + 24px);\n border: 2px solid #1e79c2;\n height: 100%;\n z-index: -1;\n }\n }\n`;\n"],
5
5
  "mappings": ";AAAA;ACAA;AACA;AAGO,MAAM,gBAAgB,OAAO;AAAA;AAAA;AAAA;AAM7B,MAAM,wBAAwB,OAAO;AAAA;AAAA,IAExC,CAAC,UACD,MAAM,SAAS,aAAa,UAC5B,YAAY,MAAM,MAAM,MAAM,OAAO,MAAM,MAAM,MAAM,OAAO,MAAM,MAAM,MAAM;AAAA;AAAA,IAEhF,CAAC,UACD,MAAM,SAAS,aAAa,aAC5B,YAAY,MAAM,MAAM,MAAM,WAAW,MAAM,MAAM,MAAM;AAAA,MACzD,MAAM,MAAM,MAAM;AAAA;AAAA,IAEpB,CAAC,UACD,MAAM,SAAS,aAAa,UAC5B,YAAY,MAAM,MAAM,MAAM;AAAA;AAAA;AAI3B,MAAM,iCAAiC,OAAO;AAAA;AAAA;AAAA,aAGxC,CAAC,UAAU,MAAM,MAAM,MAAM;AAAA;AAAA;AAAA;AAAA;AAMnC,MAAM,mCAAmC,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAahD,MAAM,uCAAuC,OAAO;AAAA;AAAA,YAE/C,CAAC,UAAU,MAAM;AAAA;AAAA;AAItB,MAAM,0BAA0B,OAAO;AAAA;AAAA,uBAEvB,CAAC,UAAU,MAAM,MAAM,MAAM;AAAA,aACvC,CAAC,UAAU,MAAM,MAAM,MAAM;AAAA,WAC/B,CAAC,UAAU,MAAM,MAAM,MAAM;AAAA,YAC5B,CAAC,UAAU,MAAM,MAAM,MAAM;AAAA;AAAA;AAAA;AAAA,IAIrC,CAAC,UAAW,MAAM,iBAAiB,QAAQ,YAAY;AAAA,IACvD,CAAC,UAAW,MAAM,iBAAiB,WAAW,eAAe;AAAA;AAE1D,MAAM,WAAW,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAShB,CAAC,UAAU,MAAM,MAAM,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ import * as React from "react";
3
+ import React2 from "react";
4
+ const useActionRef = ({
5
+ actionRef,
6
+ useVirtualHelpers: { scrollToIndex: vScroll },
7
+ virtualListRef,
8
+ onScrollStop,
9
+ onlyFocus,
10
+ scrollAndFocus
11
+ }) => {
12
+ React2.useEffect(() => {
13
+ if (actionRef && actionRef.current) {
14
+ const scrollToIndex = (index, opts = { align: "center" }) => {
15
+ vScroll(index, opts);
16
+ onScrollStop();
17
+ };
18
+ const focusToIndex = (index, opts = { align: "center" }) => {
19
+ scrollAndFocus(index, opts);
20
+ };
21
+ const focusToList = () => {
22
+ virtualListRef.current?.focus();
23
+ };
24
+ actionRef.current.scrollToIndex = scrollToIndex;
25
+ actionRef.current.getMessagesInView = onScrollStop;
26
+ onScrollStop();
27
+ actionRef.current.focusToIndex = focusToIndex;
28
+ actionRef.current.focusToIndexWithoutScroll = onlyFocus;
29
+ actionRef.current.focusToList = focusToList;
30
+ }
31
+ }, [actionRef, onScrollStop, onlyFocus, scrollAndFocus, vScroll, virtualListRef]);
32
+ };
33
+ export {
34
+ useActionRef
35
+ };
36
+ //# sourceMappingURL=useActionRef.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/chat-container-messages-list/useActionRef.ts"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\n/* eslint-disable jsx-a11y/no-noninteractive-tabindex */\n/* eslint-disable max-lines */\nimport React from 'react';\nimport { type DebouncedFunc } from 'lodash';\nimport { useVirtual } from 'react-virtual';\nimport { DSChatT } from '../../react-desc-prop-types';\n\ntype UseActionRefArgs = {\n actionRef: DSChatT.ActionRef;\n useVirtualHelpers: ReturnType<typeof useVirtual>;\n virtualListRef: React.MutableRefObject<HTMLDivElement | undefined>;\n onScrollStop: DebouncedFunc<() => string[]>;\n onlyFocus: (index?: number) => void;\n scrollAndFocus: (index: number, opts?: DSChatT.ScrollToIndexOptions) => void;\n};\n\nexport const useActionRef = ({\n actionRef,\n useVirtualHelpers: { scrollToIndex: vScroll },\n virtualListRef,\n onScrollStop,\n onlyFocus,\n scrollAndFocus,\n}: UseActionRefArgs) => {\n React.useEffect(() => {\n if (actionRef && actionRef.current) {\n const scrollToIndex: DSChatT.ActionRef['current']['scrollToIndex'] = (index, opts = { align: 'center' }) => {\n vScroll(index, opts);\n onScrollStop();\n };\n const focusToIndex: DSChatT.ActionRef['current']['focusToIndex'] = (index, opts = { align: 'center' }) => {\n scrollAndFocus(index, opts);\n };\n const focusToList = () => {\n virtualListRef.current?.focus();\n };\n\n actionRef.current.scrollToIndex = scrollToIndex;\n actionRef.current.getMessagesInView = onScrollStop;\n // I have no idea what the next line refeers to\n // keeping this from original code to avoid any possible breaking-change\n onScrollStop(); // init useMemo due to debounce use.\n actionRef.current.focusToIndex = focusToIndex;\n actionRef.current.focusToIndexWithoutScroll = onlyFocus;\n actionRef.current.focusToList = focusToList;\n }\n }, [actionRef, onScrollStop, onlyFocus, scrollAndFocus, vScroll, virtualListRef]);\n};\n"],
5
+ "mappings": ";AAAA;ACGA;AAcO,MAAM,eAAe,CAAC;AAAA,EAC3B;AAAA,EACA,mBAAmB,EAAE,eAAe;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,MACsB;AACtB,SAAM,UAAU,MAAM;AACpB,QAAI,aAAa,UAAU,SAAS;AAClC,YAAM,gBAA+D,CAAC,OAAO,OAAO,EAAE,OAAO,SAAS,MAAM;AAC1G,gBAAQ,OAAO,IAAI;AACnB,qBAAa;AAAA,MACf;AACA,YAAM,eAA6D,CAAC,OAAO,OAAO,EAAE,OAAO,SAAS,MAAM;AACxG,uBAAe,OAAO,IAAI;AAAA,MAC5B;AACA,YAAM,cAAc,MAAM;AACxB,uBAAe,SAAS,MAAM;AAAA,MAChC;AAEA,gBAAU,QAAQ,gBAAgB;AAClC,gBAAU,QAAQ,oBAAoB;AAGtC,mBAAa;AACb,gBAAU,QAAQ,eAAe;AACjC,gBAAU,QAAQ,4BAA4B;AAC9C,gBAAU,QAAQ,cAAc;AAAA,IAClC;AAAA,EACF,GAAG,CAAC,WAAW,cAAc,WAAW,gBAAgB,SAAS,cAAc,CAAC;AAClF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ import * as React from "react";
3
+ import React2 from "react";
4
+ import {
5
+ useMemoMergePropsWithDefault,
6
+ useGetGlobalAttributes,
7
+ useValidateTypescriptPropTypes
8
+ } from "@elliemae/ds-utilities";
9
+ import { useVirtual } from "react-virtual";
10
+ import { useActionRef } from "./useActionRef";
11
+ import { useGlobalEventListener } from "./useGlobalEventListener";
12
+ import { useKeyboard } from "./useKeyboard";
13
+ import { useFocusAndScrollHelpers } from "./useFocusAndScrollHelpers";
14
+ import { ChatContainerMessagesListPropTypes, defaultPropsMessagesList } from "../../react-desc-prop-types";
15
+ const getPadding = ({ hasMoreItems, bannerPosition, isLoading }) => {
16
+ const padding = {
17
+ paddingStart: 0,
18
+ paddingEnd: -5
19
+ };
20
+ if ([hasMoreItems, bannerPosition, isLoading].some((item) => item === "top"))
21
+ padding.paddingStart = 42;
22
+ else if ([hasMoreItems, bannerPosition, isLoading].some((item) => item === "bottom"))
23
+ padding.paddingEnd = 42;
24
+ return padding;
25
+ };
26
+ const useChatContainerMessageList = (props) => {
27
+ const propsWithDefault = useMemoMergePropsWithDefault(props, defaultPropsMessagesList);
28
+ useValidateTypescriptPropTypes(propsWithDefault, ChatContainerMessagesListPropTypes);
29
+ const globalAttributes = useGetGlobalAttributes(propsWithDefault);
30
+ const loadMoreRef = React2.useRef();
31
+ const virtualListRef = React2.useRef();
32
+ const pendingOnScroll = React2.useRef(false);
33
+ const { bannerPosition, messages, actionRef, hasMoreItems, isLoading } = propsWithDefault;
34
+ const useVirtualHelpers = useVirtual({
35
+ size: messages?.length,
36
+ parentRef: virtualListRef,
37
+ overscan: 15,
38
+ ...getPadding({ hasMoreItems, bannerPosition, isLoading }),
39
+ estimateSize: React2.useCallback(() => 80, [])
40
+ });
41
+ const { onScrollStop, onlyFocus, scrollAndFocus, checkPendingOnScroll } = useFocusAndScrollHelpers({
42
+ propsWithDefault,
43
+ useVirtualHelpers,
44
+ pendingOnScroll,
45
+ virtualListRef
46
+ });
47
+ useActionRef({
48
+ actionRef,
49
+ useVirtualHelpers,
50
+ virtualListRef,
51
+ onScrollStop,
52
+ onlyFocus,
53
+ scrollAndFocus
54
+ });
55
+ useGlobalEventListener({
56
+ propsWithDefault,
57
+ virtualListRef,
58
+ onScrollStop,
59
+ checkPendingOnScroll
60
+ });
61
+ const keyboardMethods = useKeyboard({
62
+ propsWithDefault,
63
+ actionRef,
64
+ virtualListRef,
65
+ loadMoreRef,
66
+ scrollAndFocus,
67
+ onlyFocus,
68
+ onScrollStop
69
+ });
70
+ return React2.useMemo(() => ({
71
+ propsWithDefault,
72
+ globalAttributes,
73
+ useVirtualHelpers,
74
+ loadMoreRef,
75
+ virtualListRef,
76
+ ...keyboardMethods
77
+ }), [globalAttributes, keyboardMethods, propsWithDefault, useVirtualHelpers, loadMoreRef, virtualListRef]);
78
+ };
79
+ export {
80
+ useChatContainerMessageList
81
+ };
82
+ //# sourceMappingURL=useChatContainerMessageList.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/chat-container-messages-list/useChatContainerMessageList.ts"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\n/* eslint-disable jsx-a11y/no-noninteractive-tabindex */\n/* eslint-disable max-lines */\nimport React from 'react';\nimport {\n useMemoMergePropsWithDefault,\n useGetGlobalAttributes,\n useValidateTypescriptPropTypes,\n} from '@elliemae/ds-utilities';\nimport { useVirtual } from 'react-virtual';\nimport { useActionRef } from './useActionRef';\nimport { useGlobalEventListener } from './useGlobalEventListener';\nimport { useKeyboard } from './useKeyboard';\nimport { useFocusAndScrollHelpers } from './useFocusAndScrollHelpers';\nimport { DSChatT, ChatContainerMessagesListPropTypes, defaultPropsMessagesList } from '../../react-desc-prop-types';\n\nconst getPadding = ({ hasMoreItems, bannerPosition, isLoading }: DSChatT.GetPaddingT) => {\n const padding = {\n paddingStart: 0,\n paddingEnd: -5,\n };\n if ([hasMoreItems, bannerPosition, isLoading].some((item) => item === 'top')) padding.paddingStart = 42;\n else if ([hasMoreItems, bannerPosition, isLoading].some((item) => item === 'bottom')) padding.paddingEnd = 42;\n return padding;\n};\n\ntype UseChatContainerMessageList = (props: DSChatT.MessagesListProps) => {\n propsWithDefault: DSChatT.MessagesListProps;\n globalAttributes: ReturnType<typeof useGetGlobalAttributes>;\n useVirtualHelpers: ReturnType<typeof useVirtual>;\n loadMoreRef: React.MutableRefObject<HTMLButtonElement | undefined>;\n virtualListRef: React.MutableRefObject<HTMLDivElement | undefined>;\n} & ReturnType<typeof useKeyboard>;\n\nexport const useChatContainerMessageList: UseChatContainerMessageList = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault<DSChatT.MessagesListProps>(props, defaultPropsMessagesList);\n useValidateTypescriptPropTypes<DSChatT.MessagesListProps>(propsWithDefault, ChatContainerMessagesListPropTypes);\n const globalAttributes = useGetGlobalAttributes(propsWithDefault);\n const loadMoreRef = React.useRef<HTMLButtonElement>();\n const virtualListRef = React.useRef<HTMLDivElement>();\n\n const pendingOnScroll = React.useRef(false);\n const { bannerPosition, messages, actionRef, hasMoreItems, isLoading } = propsWithDefault;\n const useVirtualHelpers = useVirtual({\n size: messages?.length,\n parentRef: virtualListRef,\n overscan: 15,\n ...getPadding({ hasMoreItems, bannerPosition, isLoading }),\n // estimateSize should not be really required given what was stated on\n // https://github.com/tannerlinsley/react-virtual/issues/23\n estimateSize: React.useCallback(() => 80, []),\n });\n\n const { onScrollStop, onlyFocus, scrollAndFocus, checkPendingOnScroll } = useFocusAndScrollHelpers({\n propsWithDefault,\n useVirtualHelpers,\n pendingOnScroll,\n virtualListRef,\n });\n\n useActionRef({\n actionRef,\n useVirtualHelpers,\n virtualListRef,\n onScrollStop,\n onlyFocus,\n scrollAndFocus,\n });\n\n useGlobalEventListener({\n propsWithDefault,\n virtualListRef,\n onScrollStop,\n checkPendingOnScroll,\n });\n\n const keyboardMethods = useKeyboard({\n propsWithDefault,\n actionRef,\n virtualListRef,\n loadMoreRef,\n scrollAndFocus,\n onlyFocus,\n onScrollStop,\n });\n\n return React.useMemo(\n () => ({\n propsWithDefault,\n globalAttributes,\n useVirtualHelpers,\n loadMoreRef,\n virtualListRef,\n ...keyboardMethods,\n }),\n [globalAttributes, keyboardMethods, propsWithDefault, useVirtualHelpers, loadMoreRef, virtualListRef],\n );\n};\n"],
5
+ "mappings": ";AAAA;ACGA;AACA;AAAA;AAAA;AAAA;AAAA;AAKA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAM,aAAa,CAAC,EAAE,cAAc,gBAAgB,gBAAqC;AACvF,QAAM,UAAU;AAAA,IACd,cAAc;AAAA,IACd,YAAY;AAAA,EACd;AACA,MAAI,CAAC,cAAc,gBAAgB,SAAS,EAAE,KAAK,CAAC,SAAS,SAAS,KAAK;AAAG,YAAQ,eAAe;AAAA,WAC5F,CAAC,cAAc,gBAAgB,SAAS,EAAE,KAAK,CAAC,SAAS,SAAS,QAAQ;AAAG,YAAQ,aAAa;AAC3G,SAAO;AACT;AAUO,MAAM,8BAA2D,CAAC,UAAU;AACjF,QAAM,mBAAmB,6BAAwD,OAAO,wBAAwB;AAChH,iCAA0D,kBAAkB,kCAAkC;AAC9G,QAAM,mBAAmB,uBAAuB,gBAAgB;AAChE,QAAM,cAAc,OAAM,OAA0B;AACpD,QAAM,iBAAiB,OAAM,OAAuB;AAEpD,QAAM,kBAAkB,OAAM,OAAO,KAAK;AAC1C,QAAM,EAAE,gBAAgB,UAAU,WAAW,cAAc,cAAc;AACzE,QAAM,oBAAoB,WAAW;AAAA,IACnC,MAAM,UAAU;AAAA,IAChB,WAAW;AAAA,IACX,UAAU;AAAA,IACV,GAAG,WAAW,EAAE,cAAc,gBAAgB,UAAU,CAAC;AAAA,IAGzD,cAAc,OAAM,YAAY,MAAM,IAAI,CAAC,CAAC;AAAA,EAC9C,CAAC;AAED,QAAM,EAAE,cAAc,WAAW,gBAAgB,yBAAyB,yBAAyB;AAAA,IACjG;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,eAAa;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,yBAAuB;AAAA,IACrB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,QAAM,kBAAkB,YAAY;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,SAAO,OAAM,QACX,MAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,IACA,CAAC,kBAAkB,iBAAiB,kBAAkB,mBAAmB,aAAa,cAAc,CACtG;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ import * as React from "react";
3
+ import React2 from "react";
4
+ import { debounce } from "lodash";
5
+ const useFocusAndScrollHelpers = ({
6
+ propsWithDefault: { onScrollEnds },
7
+ useVirtualHelpers: { scrollToIndex: vScroll },
8
+ pendingOnScroll,
9
+ virtualListRef
10
+ }) => {
11
+ const onScrollStop = React2.useMemo(() => debounce(() => {
12
+ if (document.visibilityState === "hidden") {
13
+ pendingOnScroll.current = true;
14
+ return [];
15
+ }
16
+ if (!virtualListRef.current)
17
+ return [];
18
+ pendingOnScroll.current = false;
19
+ const { bottom, top } = virtualListRef.current?.getBoundingClientRect() || {};
20
+ const list = virtualListRef.current.querySelectorAll('[data-element="chat-element-list-item"]');
21
+ const indexList = [];
22
+ list.forEach((item) => {
23
+ const { top: itemTop } = item.getBoundingClientRect();
24
+ const itemPadding = 10;
25
+ if (itemTop + itemPadding < bottom && itemTop + itemPadding > top)
26
+ indexList.push(item.dataset.index || "");
27
+ });
28
+ if (onScrollEnds)
29
+ onScrollEnds(indexList);
30
+ return indexList;
31
+ }, 500), [onScrollEnds, pendingOnScroll, virtualListRef]);
32
+ const onlyFocus = React2.useCallback((index) => {
33
+ virtualListRef.current?.querySelector(`[data-index="${index || ""}"]`)?.focus();
34
+ }, [virtualListRef]);
35
+ const scrollAndFocus = React2.useCallback((index, opts = { align: "center" }) => {
36
+ vScroll(index, opts);
37
+ setTimeout(() => {
38
+ onlyFocus(index);
39
+ }, 300);
40
+ onScrollStop();
41
+ }, [onScrollStop, onlyFocus, vScroll]);
42
+ const checkPendingOnScroll = React2.useCallback(() => {
43
+ if (pendingOnScroll.current === true)
44
+ onScrollStop();
45
+ }, [onScrollStop, pendingOnScroll]);
46
+ return React2.useMemo(() => ({
47
+ onScrollStop,
48
+ onlyFocus,
49
+ scrollAndFocus,
50
+ checkPendingOnScroll
51
+ }), [onScrollStop, onlyFocus, scrollAndFocus, checkPendingOnScroll]);
52
+ };
53
+ export {
54
+ useFocusAndScrollHelpers
55
+ };
56
+ //# sourceMappingURL=useFocusAndScrollHelpers.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/chat-container-messages-list/useFocusAndScrollHelpers.ts"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\n/* eslint-disable jsx-a11y/no-noninteractive-tabindex */\n/* eslint-disable max-lines */\nimport React from 'react';\nimport { useVirtual } from 'react-virtual';\nimport { debounce } from 'lodash';\nimport { DSChatT } from '../../react-desc-prop-types';\n\ntype UseFocusAndScrollHelpersArgs = {\n propsWithDefault: DSChatT.MessagesListProps;\n useVirtualHelpers: ReturnType<typeof useVirtual>;\n pendingOnScroll: React.MutableRefObject<boolean>;\n virtualListRef: React.MutableRefObject<HTMLDivElement | undefined>;\n};\n\nexport const useFocusAndScrollHelpers = ({\n propsWithDefault: { onScrollEnds },\n useVirtualHelpers: { scrollToIndex: vScroll },\n pendingOnScroll,\n virtualListRef,\n}: UseFocusAndScrollHelpersArgs) => {\n const onScrollStop = React.useMemo(\n () =>\n debounce((): string[] => {\n if (document.visibilityState === 'hidden') {\n pendingOnScroll.current = true;\n return [];\n }\n if (!virtualListRef.current) return [];\n pendingOnScroll.current = false;\n const { bottom, top } = virtualListRef.current?.getBoundingClientRect() || {};\n\n const list = virtualListRef.current.querySelectorAll<HTMLElement>('[data-element=\"chat-element-list-item\"]');\n const indexList: Array<string> = [];\n list.forEach((item: HTMLElement) => {\n const { top: itemTop } = item.getBoundingClientRect();\n\n const itemPadding = 10;\n if (itemTop + itemPadding < bottom && itemTop + itemPadding > top) indexList.push(item.dataset.index || '');\n });\n if (onScrollEnds) onScrollEnds(indexList);\n return indexList;\n }, 500),\n [onScrollEnds, pendingOnScroll, virtualListRef],\n );\n\n const onlyFocus = React.useCallback(\n (index?: number | string) => {\n (virtualListRef.current?.querySelector(`[data-index=\"${index || ''}\"]`) as HTMLDivElement)?.focus();\n },\n [virtualListRef],\n );\n\n const scrollAndFocus = React.useCallback(\n (index: number, opts = { align: 'center' } as DSChatT.ScrollToIndexOptions) => {\n vScroll(index, opts);\n setTimeout(() => {\n onlyFocus(index);\n }, 300);\n onScrollStop();\n },\n [onScrollStop, onlyFocus, vScroll],\n );\n\n const checkPendingOnScroll = React.useCallback(() => {\n if (pendingOnScroll.current === true) onScrollStop();\n }, [onScrollStop, pendingOnScroll]);\n\n return React.useMemo(\n () => ({\n onScrollStop,\n onlyFocus,\n scrollAndFocus,\n checkPendingOnScroll,\n }),\n [onScrollStop, onlyFocus, scrollAndFocus, checkPendingOnScroll],\n );\n};\n"],
5
+ "mappings": ";AAAA;ACGA;AAEA;AAUO,MAAM,2BAA2B,CAAC;AAAA,EACvC,kBAAkB,EAAE;AAAA,EACpB,mBAAmB,EAAE,eAAe;AAAA,EACpC;AAAA,EACA;AAAA,MACkC;AAClC,QAAM,eAAe,OAAM,QACzB,MACE,SAAS,MAAgB;AACvB,QAAI,SAAS,oBAAoB,U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2
  "version": 3,
3
3
  "sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/chat-container-messages-list/useGetNewMessages.tsx"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useMemo, useState } from 'react';\nimport { BubbleProps } from '../bubble/props';\n\nexport const useGetNewMessages = (messages: BubbleProps[]) => {\n const [seenMessages, setSeenMessages] = useState<Record<BubbleProps['dsId'], true>>({});\n const newMessages = useMemo(() => {\n const list: BubbleProps[] = [];\n messages.forEach((message) => {\n if (!(message.dsId in seenMessages)) {\n list.push(message);\n }\n });\n setSeenMessages(Object.fromEntries(messages.map((m) => [m.dsId, true])));\n return list;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [messages]);\n\n return newMessages;\n};\n"],
5
- "mappings": ";AAAA;ACAA;AAGO,MAAM,oBAAoB,CAAC,aAA4B;AAC5D,QAAM,CAAC,cAAc,mBAAmB,SAA4C,CAAC,CAAC;AACtF,QAAM,cAAc,QAAQ,MAAM;AAChC,UAAM,OAAsB,CAAC;AAC7B,aAAS,QAAQ,CAAC,YAAY;AAC5B,UAAI,CAAE,SAAQ,QAAQ,eAAe;AACnC,aAAK,KAAK,OAAO;AAAA,MACnB;AAAA,IACF,CAAC;AACD,oBAAgB,OAAO,YAAY,SAAS,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC,CAAC;AACvE,WAAO;AAAA,EAET,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AACT;",
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useMemo, useState } from 'react';\nimport { BubblePropsT } from '../../exported-related/bubble/props';\n\nexport const useGetNewMessages = (messages: BubblePropsT[]) => {\n const [seenMessages, setSeenMessages] = useState<Record<BubblePropsT['dsId'], true>>({});\n const newMessages = useMemo(() => {\n const list: BubblePropsT[] = [];\n messages.forEach((message) => {\n if (!(message.dsId in seenMessages)) {\n list.push(message);\n }\n });\n setSeenMessages(Object.fromEntries(messages.map((m) => [m.dsId, true])));\n return list;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [messages]);\n\n return newMessages;\n};\n"],
5
+ "mappings": ";AAAA;ACAA;AAGO,MAAM,oBAAoB,CAAC,aAA6B;AAC7D,QAAM,CAAC,cAAc,mBAAmB,SAA6C,CAAC,CAAC;AACvF,QAAM,cAAc,QAAQ,MAAM;AAChC,UAAM,OAAuB,CAAC;AAC9B,aAAS,QAAQ,CAAC,YAAY;AAC5B,UAAI,CAAE,SAAQ,QAAQ,eAAe;AACnC,aAAK,KAAK,OAAO;AAAA,MACnB;AAAA,IACF,CAAC;AACD,oBAAgB,OAAO,YAAY,SAAS,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC,CAAC;AACvE,WAAO;AAAA,EAET,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ import * as React from "react";
3
+ import React2 from "react";
4
+ const useGlobalEventListener = ({
5
+ propsWithDefault: { onScrollEnds },
6
+ virtualListRef,
7
+ onScrollStop,
8
+ checkPendingOnScroll
9
+ }) => {
10
+ React2.useEffect(() => {
11
+ let handlerCallback;
12
+ const localVirtualRef = virtualListRef.current;
13
+ const onScroll = () => {
14
+ if (handlerCallback)
15
+ clearTimeout(handlerCallback);
16
+ handlerCallback = setTimeout(onScrollStop, 300);
17
+ };
18
+ if (onScrollEnds) {
19
+ virtualListRef.current?.addEventListener("scroll", onScroll);
20
+ }
21
+ document.addEventListener("visibilitychange", checkPendingOnScroll);
22
+ return () => {
23
+ if (handlerCallback)
24
+ clearTimeout(handlerCallback);
25
+ if (onScrollEnds)
26
+ localVirtualRef.removeEventListener("scroll", onScroll);
27
+ document.removeEventListener("visibilitychange", checkPendingOnScroll);
28
+ };
29
+ }, [onScrollStop, onScrollEnds, checkPendingOnScroll, virtualListRef]);
30
+ };
31
+ export {
32
+ useGlobalEventListener
33
+ };
34
+ //# sourceMappingURL=useGlobalEventListener.js.map