@gravity-ui/aikit 3.2.2-beta.f0dbff1ff439ff6700c0db13ca8818f66a2bc182.0 → 3.3.0

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.
@@ -46,7 +46,7 @@
46
46
  display: flex;
47
47
  align-items: baseline;
48
48
  gap: 12px;
49
- padding: 6px 0;
49
+ padding: 6px var(--g-spacing-3);
50
50
  }
51
51
  .g-aikit-changed-files-summary__content .g-aikit-diff-stat {
52
52
  flex-shrink: 0;
@@ -16,6 +16,7 @@ function ChatContentV2({ header, composer, children, streaming = false, waitingF
16
16
  const content = (0, react_1.useRef)(null);
17
17
  const footer = (0, react_1.useRef)(null);
18
18
  const following = (0, react_1.useRef)(true);
19
+ const scrollTarget = (0, react_1.useRef)();
19
20
  const previous = (0, react_1.useRef)({ historyKey, height: 0 });
20
21
  const [scrolled, setScrolled] = (0, react_1.useState)(false);
21
22
  const [away, setAway] = (0, react_1.useState)(false);
@@ -28,39 +29,66 @@ function ChatContentV2({ header, composer, children, streaming = false, waitingF
28
29
  setScrolled(el.scrollTop > 0);
29
30
  setAway(el.scrollHeight - el.clientHeight - el.scrollTop > 24);
30
31
  }, []);
32
+ const followToBottom = (0, react_1.useCallback)(() => {
33
+ const el = viewport.current;
34
+ if (!el) {
35
+ return;
36
+ }
37
+ // Keep the follow intent until the native animation reaches its original target.
38
+ // Content may have grown in the meantime; reconcile to the latest bottom on arrival.
39
+ if (scrollTarget.current !== undefined &&
40
+ el.scrollTop >= Math.min(scrollTarget.current, el.scrollHeight - el.clientHeight) - 1) {
41
+ scrollTarget.current = undefined;
42
+ following.current = true;
43
+ }
44
+ if (following.current) {
45
+ el.scrollTop = el.scrollHeight;
46
+ }
47
+ }, []);
48
+ const cancelScrollToBottom = (0, react_1.useCallback)(() => {
49
+ if (scrollTarget.current === undefined) {
50
+ return;
51
+ }
52
+ scrollTarget.current = undefined;
53
+ following.current = false;
54
+ const el = viewport.current;
55
+ if (el) {
56
+ el.scrollTo({ top: el.scrollTop, behavior: 'auto' });
57
+ }
58
+ }, []);
31
59
  const preserve = (0, react_1.useCallback)((change) => {
32
60
  var _a;
33
61
  const el = viewport.current;
34
62
  const top = (_a = el === null || el === void 0 ? void 0 : el.scrollTop) !== null && _a !== void 0 ? _a : 0;
63
+ cancelScrollToBottom();
35
64
  following.current = false;
36
65
  (0, react_dom_1.flushSync)(change);
37
66
  if (el) {
38
67
  el.scrollTop = top;
39
68
  }
40
69
  update();
41
- }, [update]);
70
+ }, [cancelScrollToBottom, update]);
42
71
  (0, uikit_1.useLayoutEffect)(() => {
43
72
  const el = viewport.current;
44
73
  if (!el) {
45
74
  return;
46
75
  }
47
76
  if (previous.current.historyKey !== historyKey) {
77
+ cancelScrollToBottom();
48
78
  el.scrollTop += el.scrollHeight - previous.current.height;
49
79
  }
50
- else if (following.current) {
51
- el.scrollTop = el.scrollHeight;
80
+ else {
81
+ followToBottom();
52
82
  }
53
83
  previous.current = { historyKey, height: el.scrollHeight };
54
84
  update();
55
- }, [children, historyKey, height, update]);
85
+ }, [children, historyKey, height, cancelScrollToBottom, followToBottom, update]);
56
86
  (0, uikit_1.useLayoutEffect)(() => {
57
87
  const observer = new ResizeObserver(() => {
58
88
  var _a, _b;
59
89
  setHeight((_b = (_a = footer.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) !== null && _b !== void 0 ? _b : 0);
60
90
  const el = viewport.current;
61
- if (el && following.current) {
62
- el.scrollTop = el.scrollHeight;
63
- }
91
+ followToBottom();
64
92
  if (el) {
65
93
  previous.current.height = el.scrollHeight;
66
94
  }
@@ -76,20 +104,44 @@ function ChatContentV2({ header, composer, children, streaming = false, waitingF
76
104
  observer.observe(footer.current);
77
105
  }
78
106
  return () => observer.disconnect();
79
- }, [update]);
80
- return ((0, jsx_runtime_1.jsx)(chatLayoutChange_1.LayoutChangeContext.Provider, { value: preserve, children: (0, jsx_runtime_1.jsxs)("div", { className: `g-aikit-chat-content-v2 ${className !== null && className !== void 0 ? className : ''}`, children: [header && (0, jsx_runtime_1.jsx)("div", { className: "g-aikit-chat-content-v2__header", children: header }), (0, jsx_runtime_1.jsxs)("div", { className: "g-aikit-chat-content-v2__body", children: [scrolled && (0, jsx_runtime_1.jsx)("div", { className: "g-aikit-chat-content-v2__top-fade" }), (0, jsx_runtime_1.jsx)("div", { ref: viewport, className: "g-aikit-chat-content-v2__viewport", onScroll: () => {
107
+ }, [followToBottom, update]);
108
+ return ((0, jsx_runtime_1.jsx)(chatLayoutChange_1.LayoutChangeContext.Provider, { value: preserve, children: (0, jsx_runtime_1.jsxs)("div", { className: `g-aikit-chat-content-v2 ${className !== null && className !== void 0 ? className : ''}`, children: [header && (0, jsx_runtime_1.jsx)("div", { className: "g-aikit-chat-content-v2__header", children: header }), (0, jsx_runtime_1.jsxs)("div", { className: "g-aikit-chat-content-v2__body", children: [scrolled && (0, jsx_runtime_1.jsx)("div", { className: "g-aikit-chat-content-v2__top-fade" }), (0, jsx_runtime_1.jsx)("div", { ref: viewport, className: "g-aikit-chat-content-v2__viewport", onWheel: cancelScrollToBottom, onTouchStart: cancelScrollToBottom, onPointerDown: cancelScrollToBottom, onKeyDown: (event) => {
109
+ if ([
110
+ 'ArrowUp',
111
+ 'ArrowDown',
112
+ 'PageUp',
113
+ 'PageDown',
114
+ 'Home',
115
+ 'End',
116
+ ' ',
117
+ ].includes(event.key)) {
118
+ cancelScrollToBottom();
119
+ }
120
+ }, onScroll: () => {
81
121
  const el = viewport.current;
82
122
  if (!el) {
83
123
  return;
84
124
  }
85
- following.current =
86
- el.scrollHeight - el.clientHeight - el.scrollTop <= 24;
125
+ if (scrollTarget.current === undefined) {
126
+ following.current =
127
+ el.scrollHeight - el.clientHeight - el.scrollTop <= 24;
128
+ }
129
+ else {
130
+ followToBottom();
131
+ }
87
132
  update();
88
133
  }, children: (0, jsx_runtime_1.jsx)("div", { ref: content, style: { paddingBottom: height + 28 }, children: children }) }), (0, jsx_runtime_1.jsx)("div", { ref: footer, className: "g-aikit-chat-content-v2__composer", children: composer }), away && ((0, jsx_runtime_1.jsx)(ScrollToBottomButton_1.ScrollToBottomButton, { streaming: streaming, waitingForApproval: waitingForApproval, className: "g-aikit-chat-content-v2__down", style: { bottom: height + 12 }, onClick: () => {
89
- following.current = true;
90
134
  const el = viewport.current;
91
135
  if (el) {
92
- el.scrollTop = el.scrollHeight;
136
+ following.current = false;
137
+ scrollTarget.current = el.scrollHeight - el.clientHeight;
138
+ el.scrollTo({
139
+ top: el.scrollHeight,
140
+ behavior: window.matchMedia('(prefers-reduced-motion: reduce)').matches
141
+ ? 'auto'
142
+ : 'smooth',
143
+ });
144
+ followToBottom();
93
145
  }
94
146
  update();
95
147
  } }))] })] }) }));
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../../../../../src","sources":["components/templates/ChatContentV2/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;AAyBb,sCAwHC;;AA/ID,iCAAoE;AAEpE,6CAAkD;AAClD,yCAAoC;AAEpC,yEAAoE;AACpE,oFAAsE;AAEtE,+BAA8B;AAc9B,gEAAgE;AAChE,SAAgB,aAAa,CAAC,EAC1B,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,SAAS,GAAG,KAAK,EACjB,kBAAkB,GAAG,KAAK,EAC1B,SAAS,EACT,UAAU,GACO;IACjB,MAAM,QAAQ,GAAG,IAAA,cAAM,EAAiB,IAAI,CAAC,CAAC;IAC9C,MAAM,OAAO,GAAG,IAAA,cAAM,EAAiB,IAAI,CAAC,CAAC;IAC7C,MAAM,MAAM,GAAG,IAAA,cAAM,EAAiB,IAAI,CAAC,CAAC;IAC5C,MAAM,SAAS,GAAG,IAAA,cAAM,EAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,QAAQ,GAAG,IAAA,cAAM,EAAC,EAAC,UAAU,EAAE,MAAM,EAAE,CAAC,EAAC,CAAC,CAAC;IACjD,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,IAAA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GAAG,IAAI,CAAC;gCACzB,MAAM,EAAE,GAAG,QAAQ,CAAC,OAAO,CAAC;gCAC5B,IAAI,EAAE,EAAE,CAAC;oCACL,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC,YAAY,CAAC;gCACnC,CAAC;gCACD,MAAM,EAAE,CAAC;4BACb,CAAC,GACH,CACL,IACC,IACJ,GACqB,CAClC,CAAC;AACN,CAAC;AAED,uEAAoE;AAA5D,uHAAA,mBAAmB,OAAA","sourcesContent":["'use client';\n\nimport {type ReactNode, useCallback, useRef, useState} from 'react';\n\nimport {useLayoutEffect} from '@gravity-ui/uikit';\nimport {flushSync} from 'react-dom';\n\nimport {LayoutChangeContext} from '../../../utils/chatLayoutChange';\nimport {ScrollToBottomButton} from '../../atoms/ScrollToBottomButton';\n\nimport './ChatContentV2.scss';\n\n/** @experimental May change or be removed in minor releases. */\nexport interface ChatContentV2Props {\n header?: ReactNode;\n composer?: ReactNode;\n children?: ReactNode;\n streaming?: boolean;\n waitingForApproval?: boolean;\n className?: string;\n /** Change when prepending history to retain the visible region. */\n historyKey?: string | number;\n}\n\n/** @experimental May change or be removed in minor releases. */\nexport function ChatContentV2({\n header,\n composer,\n children,\n streaming = false,\n waitingForApproval = false,\n className,\n historyKey,\n}: ChatContentV2Props) {\n const viewport = useRef<HTMLDivElement>(null);\n const content = useRef<HTMLDivElement>(null);\n const footer = useRef<HTMLDivElement>(null);\n const following = useRef(true);\n const previous = useRef({historyKey, height: 0});\n const [scrolled, setScrolled] = useState(false);\n const [away, setAway] = useState(false);\n const [height, setHeight] = useState(0);\n const update = useCallback(() => {\n const el = viewport.current;\n if (!el) {\n return;\n }\n setScrolled(el.scrollTop > 0);\n setAway(el.scrollHeight - el.clientHeight - el.scrollTop > 24);\n }, []);\n const preserve = useCallback(\n (change: () => void) => {\n const el = viewport.current;\n const top = el?.scrollTop ?? 0;\n following.current = false;\n flushSync(change);\n if (el) {\n el.scrollTop = top;\n }\n update();\n },\n [update],\n );\n useLayoutEffect(() => {\n const el = viewport.current;\n if (!el) {\n return;\n }\n if (previous.current.historyKey !== historyKey) {\n el.scrollTop += el.scrollHeight - previous.current.height;\n } else if (following.current) {\n el.scrollTop = el.scrollHeight;\n }\n previous.current = {historyKey, height: el.scrollHeight};\n update();\n }, [children, historyKey, height, update]);\n useLayoutEffect(() => {\n const observer = new ResizeObserver(() => {\n setHeight(footer.current?.offsetHeight ?? 0);\n const el = viewport.current;\n if (el && following.current) {\n el.scrollTop = el.scrollHeight;\n }\n if (el) {\n previous.current.height = el.scrollHeight;\n }\n update();\n });\n if (viewport.current) {\n observer.observe(viewport.current);\n }\n if (content.current) {\n observer.observe(content.current);\n }\n if (footer.current) {\n observer.observe(footer.current);\n }\n return () => observer.disconnect();\n }, [update]);\n return (\n <LayoutChangeContext.Provider value={preserve}>\n <div className={`g-aikit-chat-content-v2 ${className ?? ''}`}>\n {header && <div className=\"g-aikit-chat-content-v2__header\">{header}</div>}\n <div className=\"g-aikit-chat-content-v2__body\">\n {scrolled && <div className=\"g-aikit-chat-content-v2__top-fade\" />}\n <div\n ref={viewport}\n className=\"g-aikit-chat-content-v2__viewport\"\n onScroll={() => {\n const el = viewport.current;\n if (!el) {\n return;\n }\n following.current =\n el.scrollHeight - el.clientHeight - el.scrollTop <= 24;\n update();\n }}\n >\n <div ref={content} style={{paddingBottom: height + 28}}>\n {children}\n </div>\n </div>\n <div ref={footer} className=\"g-aikit-chat-content-v2__composer\">\n {composer}\n </div>\n {away && (\n <ScrollToBottomButton\n streaming={streaming}\n waitingForApproval={waitingForApproval}\n className=\"g-aikit-chat-content-v2__down\"\n style={{bottom: height + 12}}\n onClick={() => {\n following.current = true;\n const el = viewport.current;\n if (el) {\n el.scrollTop = el.scrollHeight;\n }\n update();\n }}\n />\n )}\n </div>\n </div>\n </LayoutChangeContext.Provider>\n );\n}\n\nexport {useChatLayoutChange} from '../../../utils/chatLayoutChange';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"../../../../../src","sources":["components/templ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R,GAAG,EAAE,EAAE,CAAC,YAAY;wCACpB,QAAQ,EAAE,MAAM,CAAC,UAAU,CACvB,kCAAkC,CACrC,CAAC,OAAO;4CACL,CAAC,CAAC,MAAM;4CACR,CAAC,CAAC,QAAQ;qCACjB,CAAC,CAAC;oCACH,cAAc,EAAE,CAAC;gCACrB,CAAC;gCACD,MAAM,EAAE,CAAC;4BACb,CAAC,GACH,CACL,IACC,IACJ,GACqB,CAClC,CAAC;AACN,CAAC;AAED,uEAAoE;AAA5D,uHAAA,mBAAmB,OAAA","sourcesContent":["'use client';\n\nimport {type ReactNode, useCallback, useRef, useState} from 'react';\n\nimport {useLayoutEffect} from '@gravity-ui/uikit';\nimport {flushSync} from 'react-dom';\n\nimport {LayoutChangeContext} from '../../../utils/chatLayoutChange';\nimport {ScrollToBottomButton} from '../../atoms/ScrollToBottomButton';\n\nimport './ChatContentV2.scss';\n\n/** @experimental May change or be removed in minor releases. */\nexport interface ChatContentV2Props {\n header?: ReactNode;\n composer?: ReactNode;\n children?: ReactNode;\n streaming?: boolean;\n waitingForApproval?: boolean;\n className?: string;\n /** Change when prepending history to retain the visible region. */\n historyKey?: string | number;\n}\n\n/** @experimental May change or be removed in minor releases. */\nexport function ChatContentV2({\n header,\n composer,\n children,\n streaming = false,\n waitingForApproval = false,\n className,\n historyKey,\n}: ChatContentV2Props) {\n const viewport = useRef<HTMLDivElement>(null);\n const content = useRef<HTMLDivElement>(null);\n const footer = useRef<HTMLDivElement>(null);\n const following = useRef(true);\n const scrollTarget = useRef<number>();\n const previous = useRef({historyKey, height: 0});\n const [scrolled, setScrolled] = useState(false);\n const [away, setAway] = useState(false);\n const [height, setHeight] = useState(0);\n const update = useCallback(() => {\n const el = viewport.current;\n if (!el) {\n return;\n }\n setScrolled(el.scrollTop > 0);\n setAway(el.scrollHeight - el.clientHeight - el.scrollTop > 24);\n }, []);\n const followToBottom = useCallback(() => {\n const el = viewport.current;\n if (!el) {\n return;\n }\n // Keep the follow intent until the native animation reaches its original target.\n // Content may have grown in the meantime; reconcile to the latest bottom on arrival.\n if (\n scrollTarget.current !== undefined &&\n el.scrollTop >= Math.min(scrollTarget.current, el.scrollHeight - el.clientHeight) - 1\n ) {\n scrollTarget.current = undefined;\n following.current = true;\n }\n if (following.current) {\n el.scrollTop = el.scrollHeight;\n }\n }, []);\n const cancelScrollToBottom = useCallback(() => {\n if (scrollTarget.current === undefined) {\n return;\n }\n scrollTarget.current = undefined;\n following.current = false;\n const el = viewport.current;\n if (el) {\n el.scrollTo({top: el.scrollTop, behavior: 'auto'});\n }\n }, []);\n const preserve = useCallback(\n (change: () => void) => {\n const el = viewport.current;\n const top = el?.scrollTop ?? 0;\n cancelScrollToBottom();\n following.current = false;\n flushSync(change);\n if (el) {\n el.scrollTop = top;\n }\n update();\n },\n [cancelScrollToBottom, update],\n );\n useLayoutEffect(() => {\n const el = viewport.current;\n if (!el) {\n return;\n }\n if (previous.current.historyKey !== historyKey) {\n cancelScrollToBottom();\n el.scrollTop += el.scrollHeight - previous.current.height;\n } else {\n followToBottom();\n }\n previous.current = {historyKey, height: el.scrollHeight};\n update();\n }, [children, historyKey, height, cancelScrollToBottom, followToBottom, update]);\n useLayoutEffect(() => {\n const observer = new ResizeObserver(() => {\n setHeight(footer.current?.offsetHeight ?? 0);\n const el = viewport.current;\n followToBottom();\n if (el) {\n previous.current.height = el.scrollHeight;\n }\n update();\n });\n if (viewport.current) {\n observer.observe(viewport.current);\n }\n if (content.current) {\n observer.observe(content.current);\n }\n if (footer.current) {\n observer.observe(footer.current);\n }\n return () => observer.disconnect();\n }, [followToBottom, update]);\n return (\n <LayoutChangeContext.Provider value={preserve}>\n <div className={`g-aikit-chat-content-v2 ${className ?? ''}`}>\n {header && <div className=\"g-aikit-chat-content-v2__header\">{header}</div>}\n <div className=\"g-aikit-chat-content-v2__body\">\n {scrolled && <div className=\"g-aikit-chat-content-v2__top-fade\" />}\n <div\n ref={viewport}\n className=\"g-aikit-chat-content-v2__viewport\"\n onWheel={cancelScrollToBottom}\n onTouchStart={cancelScrollToBottom}\n onPointerDown={cancelScrollToBottom}\n onKeyDown={(event) => {\n if (\n [\n 'ArrowUp',\n 'ArrowDown',\n 'PageUp',\n 'PageDown',\n 'Home',\n 'End',\n ' ',\n ].includes(event.key)\n ) {\n cancelScrollToBottom();\n }\n }}\n onScroll={() => {\n const el = viewport.current;\n if (!el) {\n return;\n }\n if (scrollTarget.current === undefined) {\n following.current =\n el.scrollHeight - el.clientHeight - el.scrollTop <= 24;\n } else {\n followToBottom();\n }\n update();\n }}\n >\n <div ref={content} style={{paddingBottom: height + 28}}>\n {children}\n </div>\n </div>\n <div ref={footer} className=\"g-aikit-chat-content-v2__composer\">\n {composer}\n </div>\n {away && (\n <ScrollToBottomButton\n streaming={streaming}\n waitingForApproval={waitingForApproval}\n className=\"g-aikit-chat-content-v2__down\"\n style={{bottom: height + 12}}\n onClick={() => {\n const el = viewport.current;\n if (el) {\n following.current = false;\n scrollTarget.current = el.scrollHeight - el.clientHeight;\n el.scrollTo({\n top: el.scrollHeight,\n behavior: window.matchMedia(\n '(prefers-reduced-motion: reduce)',\n ).matches\n ? 'auto'\n : 'smooth',\n });\n followToBottom();\n }\n update();\n }}\n />\n )}\n </div>\n </div>\n </LayoutChangeContext.Provider>\n );\n}\n\nexport {useChatLayoutChange} from '../../../utils/chatLayoutChange';\n"]}
@@ -1 +1 @@
1
- {"version":"3.2.2-beta.f0dbff1ff439ff6700c0db13ca8818f66a2bc182.0","type":"commonjs","sideEffects":["*.css","*.scss"]}
1
+ {"version":"3.3.0","type":"commonjs","sideEffects":["*.css","*.scss"]}
@@ -46,7 +46,7 @@
46
46
  display: flex;
47
47
  align-items: baseline;
48
48
  gap: 12px;
49
- padding: 6px 0;
49
+ padding: 6px var(--g-spacing-3);
50
50
  }
51
51
  .g-aikit-changed-files-summary__content .g-aikit-diff-stat {
52
52
  flex-shrink: 0;
@@ -12,6 +12,7 @@ export function ChatContentV2({ header, composer, children, streaming = false, w
12
12
  const content = useRef(null);
13
13
  const footer = useRef(null);
14
14
  const following = useRef(true);
15
+ const scrollTarget = useRef();
15
16
  const previous = useRef({ historyKey, height: 0 });
16
17
  const [scrolled, setScrolled] = useState(false);
17
18
  const [away, setAway] = useState(false);
@@ -24,39 +25,66 @@ export function ChatContentV2({ header, composer, children, streaming = false, w
24
25
  setScrolled(el.scrollTop > 0);
25
26
  setAway(el.scrollHeight - el.clientHeight - el.scrollTop > 24);
26
27
  }, []);
28
+ const followToBottom = useCallback(() => {
29
+ const el = viewport.current;
30
+ if (!el) {
31
+ return;
32
+ }
33
+ // Keep the follow intent until the native animation reaches its original target.
34
+ // Content may have grown in the meantime; reconcile to the latest bottom on arrival.
35
+ if (scrollTarget.current !== undefined &&
36
+ el.scrollTop >= Math.min(scrollTarget.current, el.scrollHeight - el.clientHeight) - 1) {
37
+ scrollTarget.current = undefined;
38
+ following.current = true;
39
+ }
40
+ if (following.current) {
41
+ el.scrollTop = el.scrollHeight;
42
+ }
43
+ }, []);
44
+ const cancelScrollToBottom = useCallback(() => {
45
+ if (scrollTarget.current === undefined) {
46
+ return;
47
+ }
48
+ scrollTarget.current = undefined;
49
+ following.current = false;
50
+ const el = viewport.current;
51
+ if (el) {
52
+ el.scrollTo({ top: el.scrollTop, behavior: 'auto' });
53
+ }
54
+ }, []);
27
55
  const preserve = useCallback((change) => {
28
56
  var _a;
29
57
  const el = viewport.current;
30
58
  const top = (_a = el === null || el === void 0 ? void 0 : el.scrollTop) !== null && _a !== void 0 ? _a : 0;
59
+ cancelScrollToBottom();
31
60
  following.current = false;
32
61
  flushSync(change);
33
62
  if (el) {
34
63
  el.scrollTop = top;
35
64
  }
36
65
  update();
37
- }, [update]);
66
+ }, [cancelScrollToBottom, update]);
38
67
  useLayoutEffect(() => {
39
68
  const el = viewport.current;
40
69
  if (!el) {
41
70
  return;
42
71
  }
43
72
  if (previous.current.historyKey !== historyKey) {
73
+ cancelScrollToBottom();
44
74
  el.scrollTop += el.scrollHeight - previous.current.height;
45
75
  }
46
- else if (following.current) {
47
- el.scrollTop = el.scrollHeight;
76
+ else {
77
+ followToBottom();
48
78
  }
49
79
  previous.current = { historyKey, height: el.scrollHeight };
50
80
  update();
51
- }, [children, historyKey, height, update]);
81
+ }, [children, historyKey, height, cancelScrollToBottom, followToBottom, update]);
52
82
  useLayoutEffect(() => {
53
83
  const observer = new ResizeObserver(() => {
54
84
  var _a, _b;
55
85
  setHeight((_b = (_a = footer.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) !== null && _b !== void 0 ? _b : 0);
56
86
  const el = viewport.current;
57
- if (el && following.current) {
58
- el.scrollTop = el.scrollHeight;
59
- }
87
+ followToBottom();
60
88
  if (el) {
61
89
  previous.current.height = el.scrollHeight;
62
90
  }
@@ -72,20 +100,44 @@ export function ChatContentV2({ header, composer, children, streaming = false, w
72
100
  observer.observe(footer.current);
73
101
  }
74
102
  return () => observer.disconnect();
75
- }, [update]);
76
- return (_jsx(LayoutChangeContext.Provider, { value: preserve, children: _jsxs("div", { className: `g-aikit-chat-content-v2 ${className !== null && className !== void 0 ? className : ''}`, children: [header && _jsx("div", { className: "g-aikit-chat-content-v2__header", children: header }), _jsxs("div", { className: "g-aikit-chat-content-v2__body", children: [scrolled && _jsx("div", { className: "g-aikit-chat-content-v2__top-fade" }), _jsx("div", { ref: viewport, className: "g-aikit-chat-content-v2__viewport", onScroll: () => {
103
+ }, [followToBottom, update]);
104
+ return (_jsx(LayoutChangeContext.Provider, { value: preserve, children: _jsxs("div", { className: `g-aikit-chat-content-v2 ${className !== null && className !== void 0 ? className : ''}`, children: [header && _jsx("div", { className: "g-aikit-chat-content-v2__header", children: header }), _jsxs("div", { className: "g-aikit-chat-content-v2__body", children: [scrolled && _jsx("div", { className: "g-aikit-chat-content-v2__top-fade" }), _jsx("div", { ref: viewport, className: "g-aikit-chat-content-v2__viewport", onWheel: cancelScrollToBottom, onTouchStart: cancelScrollToBottom, onPointerDown: cancelScrollToBottom, onKeyDown: (event) => {
105
+ if ([
106
+ 'ArrowUp',
107
+ 'ArrowDown',
108
+ 'PageUp',
109
+ 'PageDown',
110
+ 'Home',
111
+ 'End',
112
+ ' ',
113
+ ].includes(event.key)) {
114
+ cancelScrollToBottom();
115
+ }
116
+ }, onScroll: () => {
77
117
  const el = viewport.current;
78
118
  if (!el) {
79
119
  return;
80
120
  }
81
- following.current =
82
- el.scrollHeight - el.clientHeight - el.scrollTop <= 24;
121
+ if (scrollTarget.current === undefined) {
122
+ following.current =
123
+ el.scrollHeight - el.clientHeight - el.scrollTop <= 24;
124
+ }
125
+ else {
126
+ followToBottom();
127
+ }
83
128
  update();
84
129
  }, children: _jsx("div", { ref: content, style: { paddingBottom: height + 28 }, children: children }) }), _jsx("div", { ref: footer, className: "g-aikit-chat-content-v2__composer", children: composer }), away && (_jsx(ScrollToBottomButton, { streaming: streaming, waitingForApproval: waitingForApproval, className: "g-aikit-chat-content-v2__down", style: { bottom: height + 12 }, onClick: () => {
85
- following.current = true;
86
130
  const el = viewport.current;
87
131
  if (el) {
88
- el.scrollTop = el.scrollHeight;
132
+ following.current = false;
133
+ scrollTarget.current = el.scrollHeight - el.clientHeight;
134
+ el.scrollTo({
135
+ top: el.scrollHeight,
136
+ behavior: window.matchMedia('(prefers-reduced-motion: reduce)').matches
137
+ ? 'auto'
138
+ : 'smooth',
139
+ });
140
+ followToBottom();
89
141
  }
90
142
  update();
91
143
  } }))] })] }) }));
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../../../../../src","sources":["components/templates/ChatContentV2/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAiB,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAEpE,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,SAAS,EAAC,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAC,mBAAmB,EAAC,2CAAwC;AACpE,OAAO,EAAC,oBAAoB,EAAC,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,CAAC,SAAS,IAAI,EAAE,CAAC;gCAC3D,MAAM,EAAE,CAAC;4BACb,CAAC,YAED,cAAK,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,EAAC,aAAa,EAAE,MAAM,GAAG,EAAE,EAAC,YACjD,QAAQ,GACP,GACJ,EACN,cAAK,GAAG,EAAE,MAAM,EAAE,SAAS,EAAC,mCAAmC,YAC1D,QAAQ,GACP,EACL,IAAI,IAAI,CACL,KAAC,oBAAoB,IACjB,SAAS,EAAE,SAAS,EACpB,kBAAkB,EAAE,kBAAkB,EACtC,SAAS,EAAC,+BAA+B,EACzC,KAAK,EAAE,EAAC,MAAM,EAAE,MAAM,GAAG,EAAE,EAAC,EAC5B,OAAO,EAAE,GAAG,EAAE;gCACV,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC;gCACzB,MAAM,EAAE,GAAG,QAAQ,CAAC,OAAO,CAAC;gCAC5B,IAAI,EAAE,EAAE,CAAC;oCACL,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC,YAAY,CAAC;gCACnC,CAAC;gCACD,MAAM,EAAE,CAAC;4BACb,CAAC,GACH,CACL,IACC,IACJ,GACqB,CAClC,CAAC;AACN,CAAC;AAED,OAAO,EAAC,mBAAmB,EAAC,2CAAwC","sourcesContent":["'use client';\n\nimport {type ReactNode, useCallback, useRef, useState} from 'react';\n\nimport {useLayoutEffect} from '@gravity-ui/uikit';\nimport {flushSync} from 'react-dom';\n\nimport {LayoutChangeContext} from '../../../utils/chatLayoutChange';\nimport {ScrollToBottomButton} from '../../atoms/ScrollToBottomButton';\n\nimport './ChatContentV2.scss';\n\n/** @experimental May change or be removed in minor releases. */\nexport interface ChatContentV2Props {\n header?: ReactNode;\n composer?: ReactNode;\n children?: ReactNode;\n streaming?: boolean;\n waitingForApproval?: boolean;\n className?: string;\n /** Change when prepending history to retain the visible region. */\n historyKey?: string | number;\n}\n\n/** @experimental May change or be removed in minor releases. */\nexport function ChatContentV2({\n header,\n composer,\n children,\n streaming = false,\n waitingForApproval = false,\n className,\n historyKey,\n}: ChatContentV2Props) {\n const viewport = useRef<HTMLDivElement>(null);\n const content = useRef<HTMLDivElement>(null);\n const footer = useRef<HTMLDivElement>(null);\n const following = useRef(true);\n const previous = useRef({historyKey, height: 0});\n const [scrolled, setScrolled] = useState(false);\n const [away, setAway] = useState(false);\n const [height, setHeight] = useState(0);\n const update = useCallback(() => {\n const el = viewport.current;\n if (!el) {\n return;\n }\n setScrolled(el.scrollTop > 0);\n setAway(el.scrollHeight - el.clientHeight - el.scrollTop > 24);\n }, []);\n const preserve = useCallback(\n (change: () => void) => {\n const el = viewport.current;\n const top = el?.scrollTop ?? 0;\n following.current = false;\n flushSync(change);\n if (el) {\n el.scrollTop = top;\n }\n update();\n },\n [update],\n );\n useLayoutEffect(() => {\n const el = viewport.current;\n if (!el) {\n return;\n }\n if (previous.current.historyKey !== historyKey) {\n el.scrollTop += el.scrollHeight - previous.current.height;\n } else if (following.current) {\n el.scrollTop = el.scrollHeight;\n }\n previous.current = {historyKey, height: el.scrollHeight};\n update();\n }, [children, historyKey, height, update]);\n useLayoutEffect(() => {\n const observer = new ResizeObserver(() => {\n setHeight(footer.current?.offsetHeight ?? 0);\n const el = viewport.current;\n if (el && following.current) {\n el.scrollTop = el.scrollHeight;\n }\n if (el) {\n previous.current.height = el.scrollHeight;\n }\n update();\n });\n if (viewport.current) {\n observer.observe(viewport.current);\n }\n if (content.current) {\n observer.observe(content.current);\n }\n if (footer.current) {\n observer.observe(footer.current);\n }\n return () => observer.disconnect();\n }, [update]);\n return (\n <LayoutChangeContext.Provider value={preserve}>\n <div className={`g-aikit-chat-content-v2 ${className ?? ''}`}>\n {header && <div className=\"g-aikit-chat-content-v2__header\">{header}</div>}\n <div className=\"g-aikit-chat-content-v2__body\">\n {scrolled && <div className=\"g-aikit-chat-content-v2__top-fade\" />}\n <div\n ref={viewport}\n className=\"g-aikit-chat-content-v2__viewport\"\n onScroll={() => {\n const el = viewport.current;\n if (!el) {\n return;\n }\n following.current =\n el.scrollHeight - el.clientHeight - el.scrollTop <= 24;\n update();\n }}\n >\n <div ref={content} style={{paddingBottom: height + 28}}>\n {children}\n </div>\n </div>\n <div ref={footer} className=\"g-aikit-chat-content-v2__composer\">\n {composer}\n </div>\n {away && (\n <ScrollToBottomButton\n streaming={streaming}\n waitingForApproval={waitingForApproval}\n className=\"g-aikit-chat-content-v2__down\"\n style={{bottom: height + 12}}\n onClick={() => {\n following.current = true;\n const el = viewport.current;\n if (el) {\n el.scrollTop = el.scrollHeight;\n }\n update();\n }}\n />\n )}\n </div>\n </div>\n </LayoutChangeContext.Provider>\n );\n}\n\nexport {useChatLayoutChange} from '../../../utils/chatLayoutChange';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"../../../../../src","sources":["components/templates/ChatContentV2/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAiB,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAEpE,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,SAAS,EAAC,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAC,mBAAmB,EAAC,2CAAwC;AACpE,OAAO,EAAC,oBAAoB,EAAC,kDAAyC;AAEtE,6BAA8B;AAc9B,gEAAgE;AAChE,MAAM,UAAU,aAAa,CAAC,EAC1B,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,SAAS,GAAG,KAAK,EACjB,kBAAkB,GAAG,KAAK,EAC1B,SAAS,EACT,UAAU,GACO;IACjB,MAAM,QAAQ,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAC9C,MAAM,OAAO,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAC7C,MAAM,MAAM,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAC5C,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,YAAY,GAAG,MAAM,EA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,GACP,GACJ,EACN,cAAK,GAAG,EAAE,MAAM,EAAE,SAAS,EAAC,mCAAmC,YAC1D,QAAQ,GACP,EACL,IAAI,IAAI,CACL,KAAC,oBAAoB,IACjB,SAAS,EAAE,SAAS,EACpB,kBAAkB,EAAE,kBAAkB,EACtC,SAAS,EAAC,+BAA+B,EACzC,KAAK,EAAE,EAAC,MAAM,EAAE,MAAM,GAAG,EAAE,EAAC,EAC5B,OAAO,EAAE,GAAG,EAAE;gCACV,MAAM,EAAE,GAAG,QAAQ,CAAC,OAAO,CAAC;gCAC5B,IAAI,EAAE,EAAE,CAAC;oCACL,SAAS,CAAC,OAAO,GAAG,KAAK,CAAC;oCAC1B,YAAY,CAAC,OAAO,GAAG,EAAE,CAAC,YAAY,GAAG,EAAE,CAAC,YAAY,CAAC;oCACzD,EAAE,CAAC,QAAQ,CAAC;wCACR,GAAG,EAAE,EAAE,CAAC,YAAY;wCACpB,QAAQ,EAAE,MAAM,CAAC,UAAU,CACvB,kCAAkC,CACrC,CAAC,OAAO;4CACL,CAAC,CAAC,MAAM;4CACR,CAAC,CAAC,QAAQ;qCACjB,CAAC,CAAC;oCACH,cAAc,EAAE,CAAC;gCACrB,CAAC;gCACD,MAAM,EAAE,CAAC;4BACb,CAAC,GACH,CACL,IACC,IACJ,GACqB,CAClC,CAAC;AACN,CAAC;AAED,OAAO,EAAC,mBAAmB,EAAC,2CAAwC","sourcesContent":["'use client';\n\nimport {type ReactNode, useCallback, useRef, useState} from 'react';\n\nimport {useLayoutEffect} from '@gravity-ui/uikit';\nimport {flushSync} from 'react-dom';\n\nimport {LayoutChangeContext} from '../../../utils/chatLayoutChange';\nimport {ScrollToBottomButton} from '../../atoms/ScrollToBottomButton';\n\nimport './ChatContentV2.scss';\n\n/** @experimental May change or be removed in minor releases. */\nexport interface ChatContentV2Props {\n header?: ReactNode;\n composer?: ReactNode;\n children?: ReactNode;\n streaming?: boolean;\n waitingForApproval?: boolean;\n className?: string;\n /** Change when prepending history to retain the visible region. */\n historyKey?: string | number;\n}\n\n/** @experimental May change or be removed in minor releases. */\nexport function ChatContentV2({\n header,\n composer,\n children,\n streaming = false,\n waitingForApproval = false,\n className,\n historyKey,\n}: ChatContentV2Props) {\n const viewport = useRef<HTMLDivElement>(null);\n const content = useRef<HTMLDivElement>(null);\n const footer = useRef<HTMLDivElement>(null);\n const following = useRef(true);\n const scrollTarget = useRef<number>();\n const previous = useRef({historyKey, height: 0});\n const [scrolled, setScrolled] = useState(false);\n const [away, setAway] = useState(false);\n const [height, setHeight] = useState(0);\n const update = useCallback(() => {\n const el = viewport.current;\n if (!el) {\n return;\n }\n setScrolled(el.scrollTop > 0);\n setAway(el.scrollHeight - el.clientHeight - el.scrollTop > 24);\n }, []);\n const followToBottom = useCallback(() => {\n const el = viewport.current;\n if (!el) {\n return;\n }\n // Keep the follow intent until the native animation reaches its original target.\n // Content may have grown in the meantime; reconcile to the latest bottom on arrival.\n if (\n scrollTarget.current !== undefined &&\n el.scrollTop >= Math.min(scrollTarget.current, el.scrollHeight - el.clientHeight) - 1\n ) {\n scrollTarget.current = undefined;\n following.current = true;\n }\n if (following.current) {\n el.scrollTop = el.scrollHeight;\n }\n }, []);\n const cancelScrollToBottom = useCallback(() => {\n if (scrollTarget.current === undefined) {\n return;\n }\n scrollTarget.current = undefined;\n following.current = false;\n const el = viewport.current;\n if (el) {\n el.scrollTo({top: el.scrollTop, behavior: 'auto'});\n }\n }, []);\n const preserve = useCallback(\n (change: () => void) => {\n const el = viewport.current;\n const top = el?.scrollTop ?? 0;\n cancelScrollToBottom();\n following.current = false;\n flushSync(change);\n if (el) {\n el.scrollTop = top;\n }\n update();\n },\n [cancelScrollToBottom, update],\n );\n useLayoutEffect(() => {\n const el = viewport.current;\n if (!el) {\n return;\n }\n if (previous.current.historyKey !== historyKey) {\n cancelScrollToBottom();\n el.scrollTop += el.scrollHeight - previous.current.height;\n } else {\n followToBottom();\n }\n previous.current = {historyKey, height: el.scrollHeight};\n update();\n }, [children, historyKey, height, cancelScrollToBottom, followToBottom, update]);\n useLayoutEffect(() => {\n const observer = new ResizeObserver(() => {\n setHeight(footer.current?.offsetHeight ?? 0);\n const el = viewport.current;\n followToBottom();\n if (el) {\n previous.current.height = el.scrollHeight;\n }\n update();\n });\n if (viewport.current) {\n observer.observe(viewport.current);\n }\n if (content.current) {\n observer.observe(content.current);\n }\n if (footer.current) {\n observer.observe(footer.current);\n }\n return () => observer.disconnect();\n }, [followToBottom, update]);\n return (\n <LayoutChangeContext.Provider value={preserve}>\n <div className={`g-aikit-chat-content-v2 ${className ?? ''}`}>\n {header && <div className=\"g-aikit-chat-content-v2__header\">{header}</div>}\n <div className=\"g-aikit-chat-content-v2__body\">\n {scrolled && <div className=\"g-aikit-chat-content-v2__top-fade\" />}\n <div\n ref={viewport}\n className=\"g-aikit-chat-content-v2__viewport\"\n onWheel={cancelScrollToBottom}\n onTouchStart={cancelScrollToBottom}\n onPointerDown={cancelScrollToBottom}\n onKeyDown={(event) => {\n if (\n [\n 'ArrowUp',\n 'ArrowDown',\n 'PageUp',\n 'PageDown',\n 'Home',\n 'End',\n ' ',\n ].includes(event.key)\n ) {\n cancelScrollToBottom();\n }\n }}\n onScroll={() => {\n const el = viewport.current;\n if (!el) {\n return;\n }\n if (scrollTarget.current === undefined) {\n following.current =\n el.scrollHeight - el.clientHeight - el.scrollTop <= 24;\n } else {\n followToBottom();\n }\n update();\n }}\n >\n <div ref={content} style={{paddingBottom: height + 28}}>\n {children}\n </div>\n </div>\n <div ref={footer} className=\"g-aikit-chat-content-v2__composer\">\n {composer}\n </div>\n {away && (\n <ScrollToBottomButton\n streaming={streaming}\n waitingForApproval={waitingForApproval}\n className=\"g-aikit-chat-content-v2__down\"\n style={{bottom: height + 12}}\n onClick={() => {\n const el = viewport.current;\n if (el) {\n following.current = false;\n scrollTarget.current = el.scrollHeight - el.clientHeight;\n el.scrollTo({\n top: el.scrollHeight,\n behavior: window.matchMedia(\n '(prefers-reduced-motion: reduce)',\n ).matches\n ? 'auto'\n : 'smooth',\n });\n followToBottom();\n }\n update();\n }}\n />\n )}\n </div>\n </div>\n </LayoutChangeContext.Provider>\n );\n}\n\nexport {useChatLayoutChange} from '../../../utils/chatLayoutChange';\n"]}
@@ -1 +1 @@
1
- {"version":"3.2.2-beta.f0dbff1ff439ff6700c0db13ca8818f66a2bc182.0","type":"module","sideEffects":["*.css","*.scss"]}
1
+ {"version":"3.3.0","type":"module","sideEffects":["*.css","*.scss"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/aikit",
3
- "version": "3.2.2-beta.f0dbff1ff439ff6700c0db13ca8818f66a2bc182.0",
3
+ "version": "3.3.0",
4
4
  "description": "Gravity UI base kit for building ai assistant chats",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",