@elliemae/ds-chat-container 3.80.0-next.8 → 3.80.0-next.80

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 (60) hide show
  1. package/dist/cjs/DSChatContainerDefinitions.js +7 -1
  2. package/dist/cjs/DSChatContainerDefinitions.js.map +2 -2
  3. package/dist/cjs/parts/chat-composer/ChatContainerComposer.js +0 -1
  4. package/dist/cjs/parts/chat-composer/ChatContainerComposer.js.map +2 -2
  5. package/dist/cjs/parts/chat-composer/styled.js +4 -0
  6. package/dist/cjs/parts/chat-composer/styled.js.map +2 -2
  7. package/dist/cjs/parts/chat-container-messages-list/ChatContainerMessagesList.js +134 -69
  8. package/dist/cjs/parts/chat-container-messages-list/ChatContainerMessagesList.js.map +2 -2
  9. package/dist/cjs/parts/chat-container-messages-list/styled.js +33 -35
  10. package/dist/cjs/parts/chat-container-messages-list/styled.js.map +2 -2
  11. package/dist/cjs/parts/chat-container-messages-list/useActionRef.js +2 -5
  12. package/dist/cjs/parts/chat-container-messages-list/useActionRef.js.map +2 -2
  13. package/dist/cjs/parts/chat-container-messages-list/useChatContainerMessageList.js +33 -20
  14. package/dist/cjs/parts/chat-container-messages-list/useChatContainerMessageList.js.map +2 -2
  15. package/dist/cjs/parts/chat-container-messages-list/useFocusAndScrollHelpers.js +38 -43
  16. package/dist/cjs/parts/chat-container-messages-list/useFocusAndScrollHelpers.js.map +2 -2
  17. package/dist/cjs/parts/chat-container-messages-list/useGlobalEventListener.js.map +1 -1
  18. package/dist/cjs/parts/chat-container-messages-list/useKeyboard.js +8 -15
  19. package/dist/cjs/parts/chat-container-messages-list/useKeyboard.js.map +2 -2
  20. package/dist/cjs/parts/chat-container-messages-list/useMessageFocusTracker.js +132 -0
  21. package/dist/cjs/parts/chat-container-messages-list/useMessageFocusTracker.js.map +7 -0
  22. package/dist/cjs/react-desc-prop-types.js +39 -23
  23. package/dist/cjs/react-desc-prop-types.js.map +2 -2
  24. package/dist/cjs/typescript-testing/typescript-chat-container-valid.js +31 -0
  25. package/dist/cjs/typescript-testing/typescript-chat-container-valid.js.map +2 -2
  26. package/dist/esm/DSChatContainerDefinitions.js +7 -1
  27. package/dist/esm/DSChatContainerDefinitions.js.map +2 -2
  28. package/dist/esm/parts/chat-composer/ChatContainerComposer.js +0 -1
  29. package/dist/esm/parts/chat-composer/ChatContainerComposer.js.map +2 -2
  30. package/dist/esm/parts/chat-composer/styled.js +4 -0
  31. package/dist/esm/parts/chat-composer/styled.js.map +2 -2
  32. package/dist/esm/parts/chat-container-messages-list/ChatContainerMessagesList.js +135 -72
  33. package/dist/esm/parts/chat-container-messages-list/ChatContainerMessagesList.js.map +2 -2
  34. package/dist/esm/parts/chat-container-messages-list/styled.js +33 -35
  35. package/dist/esm/parts/chat-container-messages-list/styled.js.map +2 -2
  36. package/dist/esm/parts/chat-container-messages-list/useActionRef.js +2 -5
  37. package/dist/esm/parts/chat-container-messages-list/useActionRef.js.map +2 -2
  38. package/dist/esm/parts/chat-container-messages-list/useChatContainerMessageList.js +33 -20
  39. package/dist/esm/parts/chat-container-messages-list/useChatContainerMessageList.js.map +2 -2
  40. package/dist/esm/parts/chat-container-messages-list/useFocusAndScrollHelpers.js +39 -44
  41. package/dist/esm/parts/chat-container-messages-list/useFocusAndScrollHelpers.js.map +2 -2
  42. package/dist/esm/parts/chat-container-messages-list/useGlobalEventListener.js.map +1 -1
  43. package/dist/esm/parts/chat-container-messages-list/useKeyboard.js +8 -15
  44. package/dist/esm/parts/chat-container-messages-list/useKeyboard.js.map +2 -2
  45. package/dist/esm/parts/chat-container-messages-list/useMessageFocusTracker.js +102 -0
  46. package/dist/esm/parts/chat-container-messages-list/useMessageFocusTracker.js.map +7 -0
  47. package/dist/esm/react-desc-prop-types.js +40 -24
  48. package/dist/esm/react-desc-prop-types.js.map +2 -2
  49. package/dist/esm/typescript-testing/typescript-chat-container-valid.js +31 -0
  50. package/dist/esm/typescript-testing/typescript-chat-container-valid.js.map +2 -2
  51. package/dist/types/DSChatContainerDefinitions.d.ts +8 -0
  52. package/dist/types/parts/chat-container-messages-list/styled.d.ts +18 -5
  53. package/dist/types/parts/chat-container-messages-list/useActionRef.d.ts +4 -6
  54. package/dist/types/parts/chat-container-messages-list/useChatContainerMessageList.d.ts +7 -3
  55. package/dist/types/parts/chat-container-messages-list/useFocusAndScrollHelpers.d.ts +9 -6
  56. package/dist/types/parts/chat-container-messages-list/useGlobalEventListener.d.ts +1 -1
  57. package/dist/types/parts/chat-container-messages-list/useKeyboard.d.ts +7 -3
  58. package/dist/types/parts/chat-container-messages-list/useMessageFocusTracker.d.ts +52 -0
  59. package/dist/types/react-desc-prop-types.d.ts +800 -789
  60. package/package.json +17 -17
@@ -1,41 +1,36 @@
1
1
  import * as React from "react";
2
2
  import React2 from "react";
3
- import { debounce, throttle } from "lodash-es";
3
+ import { debounce } from "lodash-es";
4
+ import { getMessageFocusId, getMessagePositionId } from "./useMessageFocusTracker.js";
4
5
  const useFocusAndScrollHelpers = ({
5
- propsWithDefault: { onScrollEnds },
6
- useVirtualHelpers: { scrollToIndex: vScroll },
6
+ propsWithDefault: { onScrollEnds, messages },
7
+ fastListActionRef,
7
8
  pendingOnScroll,
8
- virtualListRef
9
+ trackFocusMessage
9
10
  }) => {
11
+ const vScroll = React2.useCallback(
12
+ (index, opts) => {
13
+ const scrollOnce = () => {
14
+ const fastList = fastListActionRef.current;
15
+ const offset = fastList.getOffsetForIndex?.(index, opts?.align ?? "center");
16
+ if (offset !== void 0) fastList.scrollToOffset?.(offset, { behavior: opts?.behavior });
17
+ };
18
+ scrollOnce();
19
+ requestAnimationFrame(scrollOnce);
20
+ },
21
+ [fastListActionRef]
22
+ );
10
23
  const computeVisibleItems = React2.useCallback(() => {
11
24
  if (document.visibilityState === "hidden") {
12
25
  pendingOnScroll.current = true;
13
26
  return [];
14
27
  }
15
- if (!virtualListRef.current) return [];
28
+ const visibleItems = fastListActionRef.current.getVisibleItems?.() ?? [];
29
+ if (visibleItems.length === 0) return [];
16
30
  pendingOnScroll.current = false;
17
- const { bottom, top } = virtualListRef.current.getBoundingClientRect();
18
- const list = virtualListRef.current.querySelectorAll('[data-element="chat-element-list-item"]');
19
- const indexList = [];
20
- list.forEach((item) => {
21
- const { top: itemTop } = item.getBoundingClientRect();
22
- const itemPadding = 10;
23
- if (itemTop + itemPadding < bottom && itemTop + itemPadding > top) indexList.push(item.dataset.index || "");
24
- });
25
- return indexList;
26
- }, [pendingOnScroll, virtualListRef]);
27
- const visibleItemsCache = React2.useRef([]);
28
- const updateCache = React2.useMemo(
29
- () => throttle(
30
- () => {
31
- visibleItemsCache.current = computeVisibleItems();
32
- },
33
- 500,
34
- { leading: true }
35
- ),
36
- [computeVisibleItems]
37
- );
38
- const getMessagesInView = React2.useCallback(() => [...visibleItemsCache.current], []);
31
+ return visibleItems.map(String);
32
+ }, [fastListActionRef, pendingOnScroll]);
33
+ const getMessagesInView = computeVisibleItems;
39
34
  const onScrollStop = React2.useMemo(
40
35
  () => debounce(() => {
41
36
  const indexList = computeVisibleItems();
@@ -46,39 +41,39 @@ const useFocusAndScrollHelpers = ({
46
41
  );
47
42
  const onlyFocus = React2.useCallback(
48
43
  (index) => {
49
- virtualListRef.current?.querySelector(`[data-index="${index}"]`)?.focus();
44
+ const position = Number(index);
45
+ const row = messages?.[position];
46
+ const mounted = fastListActionRef.current.getMountedItems?.() ?? [];
47
+ if (row && mounted.includes(position))
48
+ trackFocusMessage(getMessageFocusId(row, position), { preventScroll: true });
50
49
  },
51
- [virtualListRef]
50
+ [messages, fastListActionRef, trackFocusMessage]
52
51
  );
53
52
  const scrollAndFocus = React2.useCallback(
54
- (index) => {
55
- vScroll(index, { align: "center" });
53
+ (index, opts = { align: "center" }) => {
54
+ const row = messages?.[index];
55
+ const messageId = row ? getMessageFocusId(row, index) : getMessagePositionId(index);
56
+ trackFocusMessage(messageId, { preventScroll: true });
57
+ vScroll(index, opts);
56
58
  requestAnimationFrame(() => {
57
- vScroll(index, { align: "center" });
59
+ vScroll(index, opts);
58
60
  });
59
- setTimeout(() => {
60
- onlyFocus(index.toString());
61
- }, 300);
62
- updateCache();
63
61
  },
64
- [updateCache, onlyFocus, vScroll]
62
+ [messages, trackFocusMessage, vScroll]
65
63
  );
66
64
  const checkPendingOnScroll = React2.useCallback(() => {
67
- if (pendingOnScroll.current === true) {
68
- updateCache();
69
- onScrollStop();
70
- }
71
- }, [updateCache, onScrollStop, pendingOnScroll]);
65
+ if (pendingOnScroll.current === true) onScrollStop();
66
+ }, [onScrollStop, pendingOnScroll]);
72
67
  return React2.useMemo(
73
68
  () => ({
69
+ vScroll,
74
70
  onScrollStop,
75
- updateCache,
76
71
  getMessagesInView,
77
72
  onlyFocus,
78
73
  scrollAndFocus,
79
74
  checkPendingOnScroll
80
75
  }),
81
- [onScrollStop, updateCache, getMessagesInView, onlyFocus, scrollAndFocus, checkPendingOnScroll]
76
+ [vScroll, onScrollStop, getMessagesInView, onlyFocus, scrollAndFocus, checkPendingOnScroll]
82
77
  );
83
78
  };
84
79
  export {
@@ -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/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 type { useVirtual } from 'react-virtual';\nimport { debounce, throttle } from 'lodash-es';\nimport type { DSChatT } from '../../react-desc-prop-types.js';\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 // Pure DOM read \u2014 no side effects beyond pendingOnScroll flag and getBoundingClientRect queries.\n const computeVisibleItems = React.useCallback((): 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 const list = virtualListRef.current.querySelectorAll<HTMLElement>('[data-element=\"chat-element-list-item\"]');\n const indexList: string[] = [];\n list.forEach((item: HTMLElement) => {\n const { top: itemTop } = item.getBoundingClientRect();\n const itemPadding = 10;\n if (itemTop + itemPadding < bottom && itemTop + itemPadding > top) indexList.push(item.dataset.index || '');\n });\n return indexList;\n }, [pendingOnScroll, virtualListRef]);\n\n // Throttled with leading: populates the cache immediately on first call and keeps it\n // fresh. No side effects beyond DOM reads \u2014 onScrollEnds is not involved.\n const visibleItemsCache = React.useRef<string[]>([]);\n const updateCache = React.useMemo(\n () =>\n throttle(\n () => {\n visibleItemsCache.current = computeVisibleItems();\n },\n 500,\n { leading: true },\n ),\n [computeVisibleItems],\n );\n\n // Synchronous getter \u2014 returns a copy so callers using .pop()/.shift() don't mutate the cache.\n const getMessagesInView = React.useCallback((): string[] => [...visibleItemsCache.current], []);\n\n // Debounced trailing: notifies onScrollEnds consumers after scrolling settles.\n // Semantics and timing unchanged \u2014 this path is isolated from the cache.\n const onScrollStop = React.useMemo(\n () =>\n debounce((): string[] => {\n const indexList = computeVisibleItems();\n if (onScrollEnds) onScrollEnds(indexList);\n return indexList;\n }, 500),\n [computeVisibleItems, onScrollEnds],\n ) as () => string[];\n\n const onlyFocus = React.useCallback(\n (index: string) => {\n (virtualListRef.current?.querySelector(`[data-index=\"${index}\"]`) as HTMLDivElement)?.focus();\n },\n [virtualListRef],\n );\n\n const scrollAndFocus = React.useCallback(\n (index: number) => {\n vScroll(index, { align: 'center' });\n /* [PUI-15629](https://jira.elliemae.io/browse/PUI-15629)\n * requestAnimationFrame is needed because the first scroll might not calculate positions\n * correctly if the DOM hasn't been fully updated yet. By waiting for the next animation\n * frame, we ensure that:\n * 1. The DOM has been updated with new positions after the first scroll\n * 2. Element height and position measurements are accurate\n * 3. The second scroll can center the element with correct measurements\n *\n * TODO: It might be worth consider upgrading to react-virtual v3(@tanstack/react-virtual), which handles DOM measurements and scroll\n * synchronization better. This RAF workaround might not be necessary with v3.\n */\n requestAnimationFrame(() => {\n vScroll(index, { align: 'center' });\n });\n\n setTimeout(() => {\n onlyFocus(index.toString());\n }, 300);\n\n updateCache();\n },\n [updateCache, onlyFocus, vScroll],\n );\n\n const checkPendingOnScroll = React.useCallback(() => {\n if (pendingOnScroll.current === true) {\n updateCache();\n onScrollStop();\n }\n }, [updateCache, onScrollStop, pendingOnScroll]);\n\n return React.useMemo(\n () => ({\n onScrollStop,\n updateCache,\n getMessagesInView,\n onlyFocus,\n scrollAndFocus,\n checkPendingOnScroll,\n }),\n [onScrollStop, updateCache, getMessagesInView, onlyFocus, scrollAndFocus, checkPendingOnScroll],\n );\n};\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACGvB,OAAOA,YAAW;AAElB,SAAS,UAAU,gBAAgB;AAU5B,MAAM,2BAA2B,CAAC;AAAA,EACvC,kBAAkB,EAAE,aAAa;AAAA,EACjC,mBAAmB,EAAE,eAAe,QAAQ;AAAA,EAC5C;AAAA,EACA;AACF,MAAoC;AAElC,QAAM,sBAAsBA,OAAM,YAAY,MAAgB;AAC5D,QAAI,SAAS,oBAAoB,UAAU;AACzC,sBAAgB,UAAU;AAC1B,aAAO,CAAC;AAAA,IACV;AACA,QAAI,CAAC,eAAe,QAAS,QAAO,CAAC;AACrC,oBAAgB,UAAU;AAC1B,UAAM,EAAE,QAAQ,IAAI,IAAI,eAAe,QAAQ,sBAAsB;AACrE,UAAM,OAAO,eAAe,QAAQ,iBAA8B,yCAAyC;AAC3G,UAAM,YAAsB,CAAC;AAC7B,SAAK,QAAQ,CA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AAA,EAClC;AAEA,QAAM,uBAAuBA,OAAM,YAAY,MAAM;AACnD,QAAI,gBAAgB,YAAY,MAAM;AACpC,kBAAY;AACZ,mBAAa;AAAA,IACf;AAAA,EACF,GAAG,CAAC,aAAa,cAAc,eAAe,CAAC;AAE/C,SAAOA,OAAM;AAAA,IACX,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA,CAAC,cAAc,aAAa,mBAAmB,WAAW,gBAAgB,oBAAoB;AAAA,EAChG;AACF;",
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 { debounce } from 'lodash-es';\nimport type { DSFastListT } from '@elliemae/ds-fast-list';\nimport type { DSChatT } from '../../react-desc-prop-types.js';\nimport { getMessageFocusId, getMessagePositionId } from './useMessageFocusTracker.js';\nimport type { MessageId } from './useMessageFocusTracker.js';\n\ntype UseFocusAndScrollHelpersArgs = {\n propsWithDefault: DSChatT.MessagesListProps;\n fastListActionRef: React.MutableRefObject<DSFastListT.ActionRef>;\n pendingOnScroll: React.MutableRefObject<boolean>;\n trackFocusMessage: (messageId: MessageId, options?: { preventScroll?: boolean }) => void;\n};\n\nexport const useFocusAndScrollHelpers = ({\n propsWithDefault: { onScrollEnds, messages },\n fastListActionRef,\n pendingOnScroll,\n trackFocusMessage,\n}: UseFocusAndScrollHelpersArgs) => {\n /**\n * Does not use `scrollTo` (the virtualizer's `scrollToIndex`): since @tanstack/react-virtual v3 every call\n * starts a loop that checks the position on the following frames and scrolls again, up to 10 times, and it\n * cannot tell the user's scrolling from its own, so a user who scrolls while it runs is pulled back to the\n * target over and over (PUI-19237). This scrolls the way react-virtual v2's `scrollToIndex` did instead:\n * once now and once on the next frame, when the items just rendered have been measured, and never again.\n */\n const vScroll = React.useCallback(\n (index: number, opts?: DSChatT.ScrollActionOptions) => {\n const scrollOnce = () => {\n const fastList = fastListActionRef.current;\n /** The chat's own default alignment also applies when only `behavior` is provided. */\n const offset = fastList.getOffsetForIndex?.(index, opts?.align ?? 'center');\n if (offset !== undefined) fastList.scrollToOffset?.(offset, { behavior: opts?.behavior });\n };\n scrollOnce();\n requestAnimationFrame(scrollOnce);\n },\n [fastListActionRef],\n );\n\n /**\n * Evaluated at call time from `ds-fast-list`'s `getVisibleItems()` (the virtualizer's own pre-overscan\n * viewport range), so it always reflects the current viewport, including after the user scrolls by hand.\n * It is empty before the container's first real measurement.\n */\n const computeVisibleItems = React.useCallback((): string[] => {\n if (document.visibilityState === 'hidden') {\n pendingOnScroll.current = true;\n return [];\n }\n const visibleItems = fastListActionRef.current.getVisibleItems?.() ?? [];\n if (visibleItems.length === 0) return [];\n pendingOnScroll.current = false;\n return visibleItems.map(String);\n }, [fastListActionRef, pendingOnScroll]);\n\n // Each call returns a fresh array, so callers using .pop()/.shift() can't affect later calls.\n const getMessagesInView = computeVisibleItems;\n\n // Debounced trailing: notifies onScrollEnds consumers after scrolling settles.\n const onScrollStop = React.useMemo(\n () =>\n debounce((): string[] => {\n const indexList = computeVisibleItems();\n if (onScrollEnds) onScrollEnds(indexList);\n return indexList;\n }, 500),\n [computeVisibleItems, onScrollEnds],\n ) as () => string[];\n\n /**\n * Focuses a message only if it is mounted now: it never focuses one later, when it scrolls into view. It never\n * scrolls either, as its name says, even when the message is only partly visible.\n */\n const onlyFocus = React.useCallback(\n (index: string) => {\n const position = Number(index);\n const row = messages?.[position];\n const mounted = fastListActionRef.current.getMountedItems?.() ?? [];\n if (row && mounted.includes(position))\n trackFocusMessage(getMessageFocusId(row, position), { preventScroll: true });\n },\n [messages, fastListActionRef, trackFocusMessage],\n );\n\n const scrollAndFocus = React.useCallback(\n (index: number, opts: DSChatT.ScrollActionOptions = { align: 'center' }) => {\n const row = messages?.[index];\n /** A message not rendered yet (added in the same handler) is targeted by its position; `vScroll`'s second write runs after the commit. */\n const messageId = row ? getMessageFocusId(row, index) : getMessagePositionId(index);\n trackFocusMessage(messageId, { preventScroll: true });\n vScroll(index, opts);\n /* [PUI-15629](https://jira.elliemae.io/browse/PUI-15629)\n * requestAnimationFrame is needed because the first scroll might not calculate positions\n * correctly if the DOM hasn't been fully updated yet. By waiting for the next animation\n * frame, we ensure that:\n * 1. The DOM has been updated with new positions after the first scroll\n * 2. Element height and position measurements are accurate\n * 3. The second scroll can align the element with correct measurements\n */\n requestAnimationFrame(() => {\n vScroll(index, opts);\n });\n },\n [messages, trackFocusMessage, vScroll],\n );\n\n const checkPendingOnScroll = React.useCallback(() => {\n if (pendingOnScroll.current === true) onScrollStop();\n }, [onScrollStop, pendingOnScroll]);\n\n return React.useMemo(\n () => ({\n vScroll,\n onScrollStop,\n getMessagesInView,\n onlyFocus,\n scrollAndFocus,\n checkPendingOnScroll,\n }),\n [vScroll, onScrollStop, getMessagesInView, onlyFocus, scrollAndFocus, checkPendingOnScroll],\n );\n};\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACGvB,OAAOA,YAAW;AAClB,SAAS,gBAAgB;AAGzB,SAAS,mBAAmB,4BAA4B;AAUjD,MAAM,2BAA2B,CAAC;AAAA,EACvC,kBAAkB,EAAE,cAAc,SAAS;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AACF,MAAoC;AAQlC,QAAM,UAAUA,OAAM;AAAA,IACpB,CAAC,OAAe,SAAuC;AACrD,YAAM,aAAa,MAAM;AACvB,cAAM,WAAW,kBAAkB;AAEnC,cAAM,SAAS,SAAS,oBAAoB,OAAO,MAAM,SAAS,QAAQ;AAC1E,YAAI,WAAW,OAAW,UAAS,iBAAiB,QAAQ,EAAE,UAAU,MAAM,SAAS,CAAC;AAAA,MAC1F;AACA,iBAAW;AACX,4BAAsB,UAAU;AAAA,IAClC;AAAA,IACA,CAAC,iBAAiB;AAAA,EACpB;AAOA,QAAM,sBAAsBA,OAAM,YAAY,MAAgB;AAC5D,QAAI,SAAS,o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AI,gBAAgB,YAAY,KAAM,cAAa;AAAA,EACrD,GAAG,CAAC,cAAc,eAAe,CAAC;AAElC,SAAOA,OAAM;AAAA,IACX,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA,CAAC,SAAS,cAAc,mBAAmB,WAAW,gBAAgB,oBAAoB;AAAA,EAC5F;AACF;",
6
6
  "names": ["React"]
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/useGlobalEventListener.tsx"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\nimport { type TypescriptHelpersT } from '@elliemae/ds-typescript-helpers';\nimport { type DSChatT } from '../../react-desc-prop-types.js';\n\ntype UseGlobalEventListenerArgs = {\n propsWithDefault: DSChatT.MessagesListProps;\n virtualListRef: React.MutableRefObject<HTMLDivElement | undefined>;\n onScrollStop: () => string[];\n checkPendingOnScroll: TypescriptHelpersT.GenericFunc;\n};\n\nexport const useGlobalEventListener = ({\n propsWithDefault: { onScrollEnds },\n virtualListRef,\n onScrollStop,\n checkPendingOnScroll,\n}: UseGlobalEventListenerArgs) => {\n React.useEffect(() => {\n let handlerCallback: ReturnType<typeof setTimeout>;\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) localVirtualRef.removeEventListener('scroll', onScroll);\n document.removeEventListener('visibilitychange', checkPendingOnScroll);\n };\n }, [onScrollStop, onScrollEnds, checkPendingOnScroll, virtualListRef]);\n};\n"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\nimport { type TypescriptHelpersT } from '@elliemae/ds-typescript-helpers';\nimport { type DSChatT } from '../../react-desc-prop-types.js';\n\ntype UseGlobalEventListenerArgs = {\n propsWithDefault: DSChatT.MessagesListProps;\n virtualListRef: React.MutableRefObject<HTMLDivElement | null>;\n onScrollStop: () => string[];\n checkPendingOnScroll: TypescriptHelpersT.GenericFunc;\n};\n\nexport const useGlobalEventListener = ({\n propsWithDefault: { onScrollEnds },\n virtualListRef,\n onScrollStop,\n checkPendingOnScroll,\n}: UseGlobalEventListenerArgs) => {\n React.useEffect(() => {\n let handlerCallback: ReturnType<typeof setTimeout>;\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) localVirtualRef.removeEventListener('scroll', onScroll);\n document.removeEventListener('visibilitychange', checkPendingOnScroll);\n };\n }, [onScrollStop, onScrollEnds, checkPendingOnScroll, virtualListRef]);\n};\n"],
5
5
  "mappings": "AAAA,YAAY,WAAW;ACAvB,OAAOA,YAAW;AAWX,MAAM,yBAAyB,CAAC;AAAA,EACrC,kBAAkB,EAAE,aAAa;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AACF,MAAkC;AAChC,EAAAA,OAAM,UAAU,MAAM;AACpB,QAAI;AACJ,UAAM,kBAAkB,eAAe;AACvC,UAAM,WAAW,MAAM;AACrB,UAAI,gBAAiB,cAAa,eAAe;AACjD,wBAAkB,WAAW,cAAc,GAAG;AAAA,IAChD;AACA,QAAI,cAAc;AAChB,qBAAe,SAAS,iBAAiB,UAAU,QAAQ;AAAA,IAC7D;AACA,aAAS,iBAAiB,oBAAoB,oBAAoB;AAClE,WAAO,MAAM;AACX,UAAI,gBAAiB,cAAa,eAAe;AACjD,UAAI,gBAAgB,gBAAiB,iBAAgB,oBAAoB,UAAU,QAAQ;AAC3F,eAAS,oBAAoB,oBAAoB,oBAAoB;AAAA,IACvE;AAAA,EACF,GAAG,CAAC,cAAc,cAAc,sBAAsB,cAAc,CAAC;AACvE;",
6
6
  "names": ["React"]
7
7
  }
@@ -1,5 +1,6 @@
1
1
  import * as React from "react";
2
2
  import React2 from "react";
3
+ import { getMessageFocusId } from "./useMessageFocusTracker.js";
3
4
  const getIsNumber = (val) => Number.isInteger(val);
4
5
  const useKeyboard = ({
5
6
  propsWithDefault: { hasMoreItems, messages, bannerPosition, bannerRef },
@@ -8,7 +9,8 @@ const useKeyboard = ({
8
9
  loadMoreRef,
9
10
  scrollAndFocus,
10
11
  onlyFocus,
11
- getMessagesInView
12
+ getMessagesInView,
13
+ trackFocusMessage
12
14
  }) => {
13
15
  const handleKey = React2.useCallback(
14
16
  (e) => {
@@ -20,7 +22,7 @@ const useKeyboard = ({
20
22
  case "ArrowUp":
21
23
  e.preventDefault();
22
24
  if (index && index > 0) {
23
- (virtualListRef.current?.querySelector(`[data-index="${index - 1}"]`)).focus();
25
+ trackFocusMessage(getMessageFocusId(messages[index - 1], index - 1));
24
26
  } else if (hasMoreItems === "top") {
25
27
  loadMoreRef.current?.focus();
26
28
  }
@@ -28,7 +30,7 @@ const useKeyboard = ({
28
30
  case "ArrowDown":
29
31
  e.preventDefault();
30
32
  if (messages?.length && isIndexNumber && index < messages.length - 1) {
31
- (virtualListRef.current?.querySelector(`[data-index="${index + 1}"]`)).focus();
33
+ trackFocusMessage(getMessageFocusId(messages[index + 1], index + 1));
32
34
  }
33
35
  break;
34
36
  case "Home":
@@ -60,7 +62,7 @@ const useKeyboard = ({
60
62
  break;
61
63
  }
62
64
  },
63
- [hasMoreItems, messages.length, scrollAndFocus, virtualListRef, loadMoreRef, bannerPosition, bannerRef]
65
+ [hasMoreItems, messages, scrollAndFocus, virtualListRef, loadMoreRef, bannerPosition, bannerRef, trackFocusMessage]
64
66
  );
65
67
  const handleListKey = React2.useCallback(
66
68
  (e) => {
@@ -76,7 +78,7 @@ const useKeyboard = ({
76
78
  case "ArrowDown":
77
79
  e.preventDefault();
78
80
  if (document.activeElement === loadMoreRef.current) {
79
- virtualListRef.current?.querySelector(`[data-index="0"]`)?.focus();
81
+ onlyFocus("0");
80
82
  } else {
81
83
  const id = getMessagesInView()?.pop();
82
84
  if (id) onlyFocus(id);
@@ -111,16 +113,7 @@ const useKeyboard = ({
111
113
  break;
112
114
  }
113
115
  },
114
- [
115
- actionRef,
116
- hasMoreItems,
117
- loadMoreRef,
118
- messages.length,
119
- getMessagesInView,
120
- onlyFocus,
121
- scrollAndFocus,
122
- virtualListRef
123
- ]
116
+ [actionRef, hasMoreItems, loadMoreRef, messages, getMessagesInView, onlyFocus, scrollAndFocus, virtualListRef]
124
117
  );
125
118
  return React2.useMemo(() => ({ handleKey, handleListKey }), [handleKey, handleListKey]);
126
119
  };
@@ -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/useKeyboard.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 { DSChatT } from '../../react-desc-prop-types.js';\n\ntype UseKeyboardArgs = {\n propsWithDefault: DSChatT.MessagesListProps;\n actionRef: DSChatT.ActionRef;\n virtualListRef: React.MutableRefObject<HTMLDivElement | undefined>;\n loadMoreRef: React.MutableRefObject<HTMLButtonElement | undefined>;\n scrollAndFocus: (index: number, opts?: DSChatT.ScrollToIndexOptions) => void;\n onlyFocus: (index: string) => void;\n getMessagesInView: () => string[];\n};\n\nconst getIsNumber = (val: unknown): val is number => Number.isInteger(val);\n\nexport const useKeyboard = ({\n propsWithDefault: { hasMoreItems, messages, bannerPosition, bannerRef },\n actionRef,\n virtualListRef,\n loadMoreRef,\n scrollAndFocus,\n onlyFocus,\n getMessagesInView,\n}: UseKeyboardArgs) => {\n const handleKey = React.useCallback(\n (e: React.KeyboardEvent<HTMLElement>) => {\n const { key, currentTarget } = e;\n const index = currentTarget.dataset?.index ? Number(currentTarget.dataset.index) : undefined;\n const isIndexNumber = getIsNumber(index);\n e.stopPropagation();\n switch (key) {\n case 'ArrowUp':\n e.preventDefault();\n if (index && 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 (messages?.length && isIndexNumber && 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 if (messages?.length) 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 [hasMoreItems, messages.length, scrollAndFocus, virtualListRef, loadMoreRef, bannerPosition, bannerRef],\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 const id = getMessagesInView()?.shift();\n if (id) onlyFocus(id);\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 const id = getMessagesInView()?.pop();\n if (id) onlyFocus(id);\n }\n break;\n case 'Home':\n e.preventDefault();\n scrollAndFocus(0);\n break;\n case 'End':\n e.preventDefault();\n if (messages?.length) 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 [\n actionRef,\n hasMoreItems,\n loadMoreRef,\n messages.length,\n getMessagesInView,\n onlyFocus,\n scrollAndFocus,\n virtualListRef,\n ],\n );\n\n return React.useMemo(() => ({ handleKey, handleListKey }), [handleKey, handleListKey]);\n};\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACGvB,OAAOA,YAAW;AAalB,MAAM,cAAc,CAAC,QAAgC,OAAO,UAAU,GAAG;AAElE,MAAM,cAAc,CAAC;AAAA,EAC1B,kBAAkB,EAAE,cAAc,UAAU,gBAAgB,UAAU;AAAA,EACtE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAuB;AACrB,QAAM,YAAYA,OAAM;AAAA,IACtB,CAAC,MAAwC;AACvC,YAAM,EAAE,KAAK,cAAc,IAAI;AAC/B,YAAM,QAAQ,cAAc,SAAS,QAAQ,OAAO,cAAc,QAAQ,KAAK,IAAI;AACnF,YAAM,gBAAgB,YAAY,KAAK;AACvC,QAAE,gBAAgB;AAClB,cAAQ,KAAK;AAAA,QACX,KAAK;AACH,YAAE,eAAe;AACjB,cAAI,SAAS,QAAQ,GAAG;AACtB,aAAC,eAAe,SAAS,cAAc,gBAAgB,QAAQ,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AAe;AACjB,cAAI,SAAS,kBAAkB,YAAY,SAAS;AAClD,YAAC,eAAe,SAAS,cAAc,kBAAkB,GAAsB,MAAM;AAAA,UACvF,OAAO;AACL,kBAAM,KAAK,kBAAkB,GAAG,IAAI;AACpC,gBAAI,GAAI,WAAU,EAAE;AAAA,UACtB;AACA;AAAA,QACF,KAAK;AACH,YAAE,eAAe;AACjB,yBAAe,CAAC;AAChB;AAAA,QACF,KAAK;AACH,YAAE,eAAe;AACjB,cAAI,UAAU,OAAQ,gBAAe,SAAS,SAAS,CAAC;AACxD;AAAA,QACF,KAAK;AACH,cAAI,SAAS,kBAAkB,YAAY,SAAS;AAClD,gBAAI,iBAAiB,YAAY,CAAC,EAAE,UAAU;AAC5C,gBAAE,eAAe;AACjB,0BAAY,SAAS,MAAM;AAAA,YAC7B,WAAW,CAAC,EAAE,UAAU;AACtB,gBAAE,eAAe;AACjB,wBAAU,SAAS,kBAAkB;AAAA,YACvC;AAAA,UACF,WAAW,CAAC,EAAE,UAAU;AACtB,cAAE,eAAe;AACjB,sBAAU,SAAS,kBAAkB;AAAA,UACvC,OAAO;AACL,cAAE,eAAe;AACjB,2BAAe,SAAS,MAAM;AAAA,UAChC;AACA;AAAA,QACF;AACE;AAAA,MACJ;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA,SAAS;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAOA,OAAM,QAAQ,OAAO,EAAE,WAAW,cAAc,IAAI,CAAC,WAAW,aAAa,CAAC;AACvF;",
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 { DSChatT } from '../../react-desc-prop-types.js';\nimport { getMessageFocusId } from './useMessageFocusTracker.js';\nimport type { MessageId } from './useMessageFocusTracker.js';\n\ntype UseKeyboardArgs = {\n propsWithDefault: DSChatT.MessagesListProps;\n actionRef: DSChatT.ActionRef;\n virtualListRef: React.MutableRefObject<HTMLDivElement | null>;\n loadMoreRef: React.MutableRefObject<HTMLButtonElement | undefined>;\n scrollAndFocus: (index: number, opts?: DSChatT.ScrollActionOptions) => void;\n onlyFocus: (index: string) => void;\n getMessagesInView: () => string[];\n trackFocusMessage: (messageId: MessageId, options?: { preventScroll?: boolean }) => void;\n};\n\nconst getIsNumber = (val: unknown): val is number => Number.isInteger(val);\n\nexport const useKeyboard = ({\n propsWithDefault: { hasMoreItems, messages, bannerPosition, bannerRef },\n actionRef,\n virtualListRef,\n loadMoreRef,\n scrollAndFocus,\n onlyFocus,\n getMessagesInView,\n trackFocusMessage,\n}: UseKeyboardArgs) => {\n const handleKey = React.useCallback(\n (e: React.KeyboardEvent<HTMLElement>) => {\n const { key, currentTarget } = e;\n const index = currentTarget.dataset?.index ? Number(currentTarget.dataset.index) : undefined;\n const isIndexNumber = getIsNumber(index);\n e.stopPropagation();\n switch (key) {\n case 'ArrowUp':\n e.preventDefault();\n if (index && index > 0) {\n trackFocusMessage(getMessageFocusId(messages[index - 1], index - 1));\n } else if (hasMoreItems === 'top') {\n loadMoreRef.current?.focus();\n }\n break;\n case 'ArrowDown':\n e.preventDefault();\n if (messages?.length && isIndexNumber && index < messages.length - 1) {\n trackFocusMessage(getMessageFocusId(messages[index + 1], index + 1));\n }\n break;\n case 'Home':\n e.preventDefault();\n scrollAndFocus(0);\n break;\n case 'End':\n e.preventDefault();\n if (messages?.length) 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 [hasMoreItems, messages, scrollAndFocus, virtualListRef, loadMoreRef, bannerPosition, bannerRef, trackFocusMessage],\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 const id = getMessagesInView()?.shift();\n if (id) onlyFocus(id);\n }\n break;\n case 'ArrowDown':\n e.preventDefault();\n if (document.activeElement === loadMoreRef.current) {\n onlyFocus('0');\n } else {\n const id = getMessagesInView()?.pop();\n if (id) onlyFocus(id);\n }\n break;\n case 'Home':\n e.preventDefault();\n scrollAndFocus(0);\n break;\n case 'End':\n e.preventDefault();\n if (messages?.length) 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, loadMoreRef, messages, getMessagesInView, onlyFocus, scrollAndFocus, virtualListRef],\n );\n\n return React.useMemo(() => ({ handleKey, handleListKey }), [handleKey, handleListKey]);\n};\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACGvB,OAAOA,YAAW;AAElB,SAAS,yBAAyB;AAclC,MAAM,cAAc,CAAC,QAAgC,OAAO,UAAU,GAAG;AAElE,MAAM,cAAc,CAAC;AAAA,EAC1B,kBAAkB,EAAE,cAAc,UAAU,gBAAgB,UAAU;AAAA,EACtE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAuB;AACrB,QAAM,YAAYA,OAAM;AAAA,IACtB,CAA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"]
7
7
  }
@@ -0,0 +1,102 @@
1
+ import * as React from "react";
2
+ import React2 from "react";
3
+ const getMessageFocusId = (message, index) => message.dsId === void 0 || message.dsId === null ? `index:${index}` : `id:${typeof message.dsId}:${message.dsId}`;
4
+ const getMessagePositionId = (index) => `position:${index}`;
5
+ const useMessageFocusTracker = (virtualListRef) => {
6
+ const [focusRequest, setFocusRequest] = React2.useState(null);
7
+ const lastRequestId = React2.useRef(0);
8
+ const fulfilledRequestId = React2.useRef(0);
9
+ const requestOrigin = React2.useRef(null);
10
+ const trackFocusMessage = React2.useCallback(
11
+ (messageId, { preventScroll = false } = {}) => {
12
+ lastRequestId.current += 1;
13
+ requestOrigin.current = document.activeElement;
14
+ setFocusRequest({ messageId, requestId: lastRequestId.current, preventScroll });
15
+ },
16
+ []
17
+ );
18
+ const trackFocusResetter = React2.useCallback(() => {
19
+ fulfilledRequestId.current = lastRequestId.current;
20
+ setFocusRequest(null);
21
+ }, []);
22
+ const trackFocusedMessage = React2.useCallback((messageId) => {
23
+ fulfilledRequestId.current = lastRequestId.current;
24
+ setFocusRequest(
25
+ (previous) => previous?.messageId === messageId ? previous : { messageId, requestId: lastRequestId.current, preventScroll: false }
26
+ );
27
+ }, []);
28
+ const mayTakeFocus = React2.useCallback(
29
+ (requestId, target) => {
30
+ const active = document.activeElement;
31
+ const isPending = requestId > fulfilledRequestId.current;
32
+ if (!active || active === document.body) return isPending ? "request" : "restore";
33
+ if (isPending && active === requestOrigin.current) return "request";
34
+ if (!target?.contains(active)) trackFocusResetter();
35
+ return null;
36
+ },
37
+ [trackFocusResetter]
38
+ );
39
+ const markFulfilled = React2.useCallback((requestId) => {
40
+ fulfilledRequestId.current = Math.max(fulfilledRequestId.current, requestId);
41
+ }, []);
42
+ const listenersCleanup = React2.useRef(null);
43
+ const listRootRef = React2.useCallback(
44
+ (node) => {
45
+ listenersCleanup.current?.();
46
+ listenersCleanup.current = null;
47
+ if (!node) return;
48
+ const onDocumentFocusIn = (e) => {
49
+ const target = e.composedPath()[0] ?? e.target;
50
+ if (!virtualListRef.current?.contains(target)) trackFocusResetter();
51
+ };
52
+ const endPendingRequest = () => {
53
+ if (lastRequestId.current > fulfilledRequestId.current) trackFocusResetter();
54
+ };
55
+ const userScrollEvents = ["wheel", "touchstart", "pointerdown"];
56
+ document.addEventListener("focusin", onDocumentFocusIn);
57
+ userScrollEvents.forEach((type) => node.addEventListener(type, endPendingRequest, { passive: true }));
58
+ listenersCleanup.current = () => {
59
+ document.removeEventListener("focusin", onDocumentFocusIn);
60
+ userScrollEvents.forEach((type) => node.removeEventListener(type, endPendingRequest));
61
+ };
62
+ },
63
+ [virtualListRef, trackFocusResetter]
64
+ );
65
+ const handleFocusOut = React2.useCallback(
66
+ (e) => {
67
+ const related = e.relatedTarget;
68
+ if (related && e.currentTarget.contains(related)) return;
69
+ if (!related && !document.hasFocus()) return;
70
+ trackFocusResetter();
71
+ },
72
+ [trackFocusResetter]
73
+ );
74
+ return React2.useMemo(
75
+ () => ({
76
+ focusRequest,
77
+ trackFocusMessage,
78
+ trackFocusResetter,
79
+ trackFocusedMessage,
80
+ mayTakeFocus,
81
+ markFulfilled,
82
+ handleFocusOut,
83
+ listRootRef
84
+ }),
85
+ [
86
+ focusRequest,
87
+ trackFocusMessage,
88
+ trackFocusResetter,
89
+ trackFocusedMessage,
90
+ mayTakeFocus,
91
+ markFulfilled,
92
+ handleFocusOut,
93
+ listRootRef
94
+ ]
95
+ );
96
+ };
97
+ export {
98
+ getMessageFocusId,
99
+ getMessagePositionId,
100
+ useMessageFocusTracker
101
+ };
102
+ //# sourceMappingURL=useMessageFocusTracker.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/chat-container-messages-list/useMessageFocusTracker.ts"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\n\n/** Focus identity of a message, from `getMessageFocusId`. */\nexport type MessageId = string;\n\n/**\n * Identity the focus intent is kept by: the message's `dsId`, which survives index shifts. `dsId` is required by\n * the types but not at runtime, so a message without one falls back to its index (the focus then follows the\n * position, as it did before the focus tracker) instead of matching every other id-less message. The two forms\n * carry different prefixes so a `dsId` can never equal an index fallback, and the type of the `dsId` is kept so\n * `3` and `'3'` stay different messages, as with a direct comparison.\n */\nexport const getMessageFocusId = (message: { dsId?: string | number | null }, index: number): MessageId =>\n message.dsId === undefined || message.dsId === null ? `index:${index}` : `id:${typeof message.dsId}:${message.dsId}`;\n\n/**\n * Target by position, for a request made before the message exists in the rendered list (for example\n * `focusToIndex` called right after the consumer adds a message): the item at that index focuses itself when it\n * mounts, and its real focus then moves the intent to its identity.\n */\nexport const getMessagePositionId = (index: number): MessageId => `position:${index}`;\n\nexport type MessageFocusRequest = {\n /** Identity of the message to focus, from `getMessageFocusId`. */\n messageId: MessageId;\n /** Incremented by every explicit request, so asking again for the current target focuses it again. */\n requestId: number;\n /** `true` when the caller scrolls to the message itself, so focusing must not scroll as well. */\n preventScroll: boolean;\n};\n\ntype TrackFocusOptions = { preventScroll?: boolean };\n\n/**\n * Message focus through the focus-tracker pattern: handlers declare which message should have the focus, and\n * only that message's `ItemRenderer` focuses itself from its ref callback, once React has committed it. Nothing\n * here moves the focus directly.\n *\n * Removing a focused message never clears the intent: React does not dispatch `onBlur` for a focused node it\n * removes itself (measured for a prepend and for a message scrolled out of the virtual window). The intent is\n * cleared by real focus moves: leaving the list (`handleFocusOut`), a `focusin` on a non-message element of the\n * list, any `focusin` outside the list while an intent exists (also when the focus was on the page, where no\n * event crosses the list), and a remount that finds the focus elsewhere (`mayTakeFocus`).\n */\nexport const useMessageFocusTracker = (virtualListRef: React.MutableRefObject<HTMLDivElement | null>) => {\n const [focusRequest, setFocusRequest] = React.useState<MessageFocusRequest | null>(null);\n const lastRequestId = React.useRef(0);\n const fulfilledRequestId = React.useRef(0);\n /** The element that had the focus when the last explicit request was made. */\n const requestOrigin = React.useRef<Element | null>(null);\n\n const trackFocusMessage = React.useCallback(\n (messageId: MessageId, { preventScroll = false }: TrackFocusOptions = {}) => {\n lastRequestId.current += 1;\n requestOrigin.current = document.activeElement;\n setFocusRequest({ messageId, requestId: lastRequestId.current, preventScroll });\n },\n [],\n );\n\n const trackFocusResetter = React.useCallback(() => {\n fulfilledRequestId.current = lastRequestId.current;\n setFocusRequest(null);\n }, []);\n\n /**\n * Keeps the intent equal to the message that actually has the focus (the item itself or a descendant, such as a\n * link in its body), without re-focusing it. The real focus closes any pending request: this invariant keeps the\n * new intent passive, so the guard in `mayTakeFocus` neither takes the focus from the user nor drops the intent.\n */\n const trackFocusedMessage = React.useCallback((messageId: MessageId) => {\n fulfilledRequestId.current = lastRequestId.current;\n setFocusRequest((previous) =>\n previous?.messageId === messageId\n ? previous\n : { messageId, requestId: lastRequestId.current, preventScroll: false },\n );\n }, []);\n\n /**\n * Whether the target (the message's own item wrapper) may take the focus now, and how:\n * - `'request'`: an explicit request not yet fulfilled, from `body` or from the element focused when it was made;\n * it focuses with the request's own `preventScroll`.\n * - `'restore'`: a target that only remounts (scrolled back into view, or shifted by older messages), from\n * `body`; it focuses without scrolling, so restoring the focus never moves the list (the scroll offset is\n * the consumer's to change).\n * - `null`: not now. If the focus is already inside the target (for example on a link in its body), nothing\n * changes; if it is anywhere else, the user moved away and the intent is cleared, pending or passive.\n */\n const mayTakeFocus = React.useCallback(\n (requestId: number, target: Element | null): 'request' | 'restore' | null => {\n const active = document.activeElement;\n const isPending = requestId > fulfilledRequestId.current;\n if (!active || active === document.body) return isPending ? 'request' : 'restore';\n if (isPending && active === requestOrigin.current) return 'request';\n if (!target?.contains(active)) trackFocusResetter();\n return null;\n },\n [trackFocusResetter],\n );\n\n const markFulfilled = React.useCallback((requestId: number) => {\n fulfilledRequestId.current = Math.max(fulfilledRequestId.current, requestId);\n }, []);\n\n const listenersCleanup = React.useRef<(() => void) | null>(null);\n /**\n * Ref callback for the list wrapper. It subscribes, in the commit phase like the focus itself, to what no React\n * handler on the list sees:\n * - a `focusin` anywhere outside the list clears the intent, even when the focus was on the page and no event\n * crossed the list (for example a message scrolled away, then the composer focused and blurred);\n * - the user scrolling the list by hand (wheel, touch, scrollbar) cancels a pending request, so a target that\n * mounts much later never takes the focus, from the element the request was made from or from `body`.\n */\n const listRootRef = React.useCallback(\n (node: HTMLElement | null) => {\n listenersCleanup.current?.();\n listenersCleanup.current = null;\n if (!node) return;\n const onDocumentFocusIn = (e: FocusEvent) => {\n /** `composedPath` sees the real target when the chat is rendered inside a shadow root. */\n const target = (e.composedPath()[0] ?? e.target) as Node;\n if (!virtualListRef.current?.contains(target)) trackFocusResetter();\n };\n /** Clears a pending request (not a passive intent): marking it fulfilled would still let it restore from `body`. */\n const endPendingRequest = () => {\n if (lastRequestId.current > fulfilledRequestId.current) trackFocusResetter();\n };\n const userScrollEvents = ['wheel', 'touchstart', 'pointerdown'] as const;\n document.addEventListener('focusin', onDocumentFocusIn);\n userScrollEvents.forEach((type) => node.addEventListener(type, endPendingRequest, { passive: true }));\n listenersCleanup.current = () => {\n document.removeEventListener('focusin', onDocumentFocusIn);\n userScrollEvents.forEach((type) => node.removeEventListener(type, endPendingRequest));\n };\n },\n [virtualListRef, trackFocusResetter],\n );\n\n /** `focusout` on the list wrapper: clears the intent when the focus leaves the message list or goes to the page. */\n const handleFocusOut = React.useCallback(\n (e: React.FocusEvent<HTMLElement>) => {\n const related = e.relatedTarget as Node | null;\n if (related && e.currentTarget.contains(related)) return;\n /** Switching to another window blurs the message without the user moving the focus in the page. */\n if (!related && !document.hasFocus()) return;\n trackFocusResetter();\n },\n [trackFocusResetter],\n );\n\n return React.useMemo(\n () => ({\n focusRequest,\n trackFocusMessage,\n trackFocusResetter,\n trackFocusedMessage,\n mayTakeFocus,\n markFulfilled,\n handleFocusOut,\n listRootRef,\n }),\n [\n focusRequest,\n trackFocusMessage,\n trackFocusResetter,\n trackFocusedMessage,\n mayTakeFocus,\n markFulfilled,\n handleFocusOut,\n listRootRef,\n ],\n );\n};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IACrB;AAAA,IACA,CAAC,kBAAkB;AAAA,EACrB;AAEA,SAAOA,OAAM;AAAA,IACX,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
6
+ "names": ["React"]
7
+ }
@@ -1,6 +1,7 @@
1
1
  import * as React from "react";
2
- import { PropTypes, globalAttributesPropTypes } from "@elliemae/ds-props-helpers";
2
+ import { PropTypes, getPropsPerSlotPropTypes, globalAttributesPropTypes } from "@elliemae/ds-props-helpers";
3
3
  import { BANNER_TYPES } from "@elliemae/ds-banner";
4
+ import { DSChatContainerSlotName, DSChatContainerSlots } from "./DSChatContainerDefinitions.js";
4
5
  function noop(..._args) {
5
6
  }
6
7
  const defaultPropsComposer = {
@@ -23,7 +24,7 @@ const defaultPropsComposer = {
23
24
  const ChatComposerPropTypes = {
24
25
  placeholder: PropTypes.string.description("Input Placeholder").defaultValue(defaultPropsComposer.placeholder),
25
26
  inputValue: PropTypes.string.description("Input value").defaultValue(defaultPropsComposer.inputValue),
26
- ariaMaxLengthMessage: PropTypes.string.description("Aria message for Max length message when exceeded").defaultValue(defaultPropsComposer.maxLengthMessage),
27
+ ariaMaxLengthMessage: PropTypes.string.description("Aria message for Max length message when exceeded").defaultValue(defaultPropsComposer.ariaMaxLengthMessage),
27
28
  maxLengthMessage: PropTypes.string.description("Max length message").defaultValue(defaultPropsComposer.maxLengthMessage),
28
29
  onChange: PropTypes.func.description("Called when the user types").defaultValue(defaultPropsComposer.onChange),
29
30
  onResize: PropTypes.func.description("Called the input changes his height").defaultValue(defaultPropsComposer.onResize),
@@ -31,19 +32,22 @@ const ChatComposerPropTypes = {
31
32
  onFocus: PropTypes.func.description("Input focus").defaultValue(defaultPropsComposer.onFocus),
32
33
  onBlur: PropTypes.func.description("Input blur").defaultValue(defaultPropsComposer.onBlur),
33
34
  onKeyDown: PropTypes.func.description("Input on key down").defaultValue(defaultPropsComposer.onKeyDown),
34
- maxHeight: PropTypes.number.description("Max height of the composer. Use 0 for no limit").defaultValue(defaultPropsComposer.onBlur),
35
+ maxHeight: PropTypes.number.description("Max height of the composer. Use 0 for no limit").defaultValue(defaultPropsComposer.maxHeight),
35
36
  inputMaxLength: PropTypes.number.description("Max length of the composer. `undefined` for no limit").defaultValue(defaultPropsComposer.inputMaxLength),
36
37
  buttonDisabled: PropTypes.bool.description("Control the disabled for the send button").defaultValue(defaultPropsComposer.buttonDisabled),
37
- dataTestid: PropTypes.string.description("Data testid").defaultValue(defaultPropsComposer.placeholder),
38
+ dataTestid: PropTypes.string.description("Data testid").defaultValue(defaultPropsComposer.dataTestid),
38
39
  actionRef: PropTypes.object.description(
39
40
  `Reference:
40
41
  {
41
- scrollToIndex?: (n: number, opts: { align: 'end' | 'center' | 'start' }) => void,
42
- getMessagesInView?: () => number[],
43
- focusToIndex?: (n: number) => void,
42
+ scrollToIndex?: (n: number, opts?: { align?: 'start' | 'center' | 'end' | 'auto', behavior?: 'auto' | 'smooth' }) => void,
43
+ focusToIndex?: (n: number, opts?: { align?: 'start' | 'center' | 'end' | 'auto', behavior?: 'auto' | 'smooth' }) => void,
44
+ getMessagesInView?: () => string[],
45
+ focusToIndexWithoutScroll?: (n: string) => void,
44
46
  focusToList?: () => void,
45
47
  focusToComposer?: () => void,
46
48
  focusToSend?: () => void,
49
+ focusOnBanner?: () => void,
50
+ focusOnBannerLink?: () => void,
47
51
  }
48
52
 
49
53
  `
@@ -62,18 +66,21 @@ const defaultPropsMessagesList = {
62
66
  bannerRef: void 0
63
67
  };
64
68
  const ChatContainerMessagesListPropTypes = {
69
+ ...getPropsPerSlotPropTypes(DSChatContainerSlotName, DSChatContainerSlots),
65
70
  ...globalAttributesPropTypes,
66
71
  messages: PropTypes.arrayOf(PropTypes.object).description("The array of out-of-the-box items you want to render inside the ChatMessageList").defaultValue(defaultPropsMessagesList.messages),
67
72
  actionRef: PropTypes.object.description(
68
73
  `Reference:
69
74
  {
70
- scrollToIndex?: (n: number, opts: { align: 'end' | 'center' | 'start' }) => void,
71
- getMessagesInView: () => number[],
72
- focusToIndex: (n: number) => void,
73
- focusToIndexWithoutScroll: (n: number) => void,
74
- focusToList: () => void,
75
- focusToComposer: () => void,
76
- focusToSend: () => void,
75
+ scrollToIndex?: (n: number, opts?: { align?: 'start' | 'center' | 'end' | 'auto', behavior?: 'auto' | 'smooth' }) => void,
76
+ focusToIndex?: (n: number, opts?: { align?: 'start' | 'center' | 'end' | 'auto', behavior?: 'auto' | 'smooth' }) => void,
77
+ getMessagesInView?: () => string[],
78
+ focusToIndexWithoutScroll?: (n: string) => void,
79
+ focusToList?: () => void,
80
+ focusToComposer?: () => void,
81
+ focusToSend?: () => void,
82
+ focusOnBanner?: () => void,
83
+ focusOnBannerLink?: () => void,
77
84
  }
78
85
 
79
86
  `
@@ -85,7 +92,9 @@ const ChatContainerMessagesListPropTypes = {
85
92
  hasMoreItems: PropTypes.oneOf(["top", "bottom", void 0]).description(
86
93
  "Show Load More button at the `top` or `bottom` of the container"
87
94
  ),
88
- getMoreMessages: PropTypes.func.description("Called when the user clicks on load more").defaultValue(defaultPropsMessagesList.getMoreMessages),
95
+ getMoreMessages: PropTypes.func.description(
96
+ "Called when the user clicks on load more. When older messages are added at the start of `messages`, the list keeps its scroll offset, so the messages in view shift; call `actionRef.current.scrollToIndex` after updating `messages` to bring the user back to where they were"
97
+ ).defaultValue(defaultPropsMessagesList.getMoreMessages),
89
98
  sendingMessages: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.arrayOf(PropTypes.number)]).description("Array of ids of sending messages").defaultValue(defaultPropsMessagesList.sendingMessages),
90
99
  sendingText: PropTypes.string.description("Label description for messages in sending status").defaultValue(defaultPropsMessagesList.sendingText)
91
100
  };
@@ -111,7 +120,9 @@ const defaultProps = {
111
120
  };
112
121
  const ChatContainerPropTypes = {
113
122
  ...globalAttributesPropTypes,
114
- messagesListProps: PropTypes.object.description('ChatMessageList props "messages" / "onScrollEnds"').defaultValue(defaultProps.messagesListProps),
123
+ messagesListProps: PropTypes.object.description(
124
+ 'ChatMessageList props "messages" / "onScrollEnds", plus the "dsChatcontainerMessagesListScrollArea" slot prop (object or function) for the scroll area'
125
+ ).defaultValue(defaultProps.messagesListProps),
115
126
  composerProps: PropTypes.object.description("Composer configuration").defaultValue(defaultProps.composerProps),
116
127
  autoScroll: PropTypes.bool.description("Auto scroll to bottom on resize").defaultValue(defaultProps.autoScroll),
117
128
  device: PropTypes.string.description("Option to render mobile or desktop style composer").defaultValue(defaultProps.device),
@@ -121,9 +132,11 @@ const ChatContainerPropTypes = {
121
132
  hasMoreItems: PropTypes.oneOf(["top", "bottom", void 0]).description(
122
133
  "Show Load More button at the `top` or `bottom` of the container"
123
134
  ),
124
- getMoreMessages: PropTypes.func.description("Called when the user clicks on load more").defaultValue(defaultProps.getMoreMessages),
135
+ getMoreMessages: PropTypes.func.description(
136
+ "Called when the user clicks on load more. When older messages are added at the start of `messages`, the list keeps its scroll offset, so the messages in view shift; call `actionRef.current.scrollToIndex` after updating `messages` to bring the user back to where they were"
137
+ ).defaultValue(defaultProps.getMoreMessages),
125
138
  bannerPosition: PropTypes.oneOf(["top", "bottom", void 0]).description(
126
- "Show Loading messages indicator at the `top` or `bottom` of the container"
139
+ "Show the unread messages banner (configured with `bannerProps`) at the `top` or `bottom` of the container"
127
140
  ),
128
141
  bannerProps: PropTypes.object.description(
129
142
  `Banner configuration:
@@ -139,12 +152,15 @@ const ChatContainerPropTypes = {
139
152
  actionRef: PropTypes.object.description(
140
153
  `Reference:
141
154
  {
142
- scrollToIndex: (n: number) => void,
143
- getMessagesInView: () => number[],
144
- focusToIndex: (n: number) => void,
145
- focusToList: () => void,
146
- focusToComposer: () => void,
147
- focusToSend: () => void,
155
+ scrollToIndex?: (n: number, opts?: { align?: 'start' | 'center' | 'end' | 'auto', behavior?: 'auto' | 'smooth' }) => void,
156
+ focusToIndex?: (n: number, opts?: { align?: 'start' | 'center' | 'end' | 'auto', behavior?: 'auto' | 'smooth' }) => void,
157
+ getMessagesInView?: () => string[],
158
+ focusToIndexWithoutScroll?: (n: string) => void,
159
+ focusToList?: () => void,
160
+ focusToComposer?: () => void,
161
+ focusToSend?: () => void,
162
+ focusOnBanner?: () => void,
163
+ focusOnBannerLink?: () => void,
148
164
  }
149
165
 
150
166
  `