@meshagent/meshagent-tailwind 0.55.0 → 0.55.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +34 -3
- package/dist/cjs/chat/agent-thread.d.ts +42 -7
- package/dist/cjs/chat/agent-thread.js +422 -183
- package/dist/cjs/chat/chat-input-state.d.ts +2 -0
- package/dist/cjs/chat/chat-input-state.js +41 -0
- package/dist/cjs/chat/chat-input.d.ts +14 -2
- package/dist/cjs/chat/chat-input.js +41 -76
- package/dist/cjs/chat/chat-scroller.js +45 -43
- package/dist/cjs/chat/chat-thread-timeline.d.ts +2 -0
- package/dist/cjs/chat/chat-thread-timeline.js +83 -10
- package/dist/cjs/chat/composer-action-button.d.ts +11 -0
- package/dist/cjs/chat/composer-action-button.js +68 -0
- package/dist/cjs/chat/use-chat-virtualizer.d.ts +14 -17
- package/dist/cjs/chat/use-chat-virtualizer.js +288 -222
- package/dist/cjs/chat/virtualization.d.ts +0 -5
- package/dist/cjs/chat/virtualization.js +4 -6
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/esm/chat/agent-thread.d.ts +42 -7
- package/dist/esm/chat/agent-thread.js +424 -186
- package/dist/esm/chat/chat-input-state.d.ts +2 -0
- package/dist/esm/chat/chat-input-state.js +21 -0
- package/dist/esm/chat/chat-input.d.ts +14 -2
- package/dist/esm/chat/chat-input.js +41 -76
- package/dist/esm/chat/chat-scroller.js +46 -44
- package/dist/esm/chat/chat-thread-timeline.d.ts +2 -0
- package/dist/esm/chat/chat-thread-timeline.js +83 -10
- package/dist/esm/chat/composer-action-button.d.ts +11 -0
- package/dist/esm/chat/composer-action-button.js +48 -0
- package/dist/esm/chat/use-chat-virtualizer.d.ts +14 -17
- package/dist/esm/chat/use-chat-virtualizer.js +290 -226
- package/dist/esm/chat/virtualization.d.ts +0 -5
- package/dist/esm/chat/virtualization.js +4 -6
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/index.css +1 -1
- package/package.json +6 -5
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useCallback,
|
|
3
|
-
useEffect,
|
|
4
3
|
useLayoutEffect,
|
|
5
4
|
useMemo,
|
|
6
5
|
useReducer,
|
|
@@ -10,25 +9,21 @@ import {
|
|
|
10
9
|
buildPageHeights,
|
|
11
10
|
buildPrefixHeights,
|
|
12
11
|
createPages,
|
|
13
|
-
|
|
12
|
+
getSpacerHeights,
|
|
14
13
|
getVisiblePageRange,
|
|
15
|
-
isNearBottom
|
|
16
|
-
shouldAdjustScrollForHeightChange
|
|
14
|
+
isNearBottom
|
|
17
15
|
} from "./virtualization.js";
|
|
16
|
+
const RESIZE_QUIET_MS = 100;
|
|
17
|
+
const RESIZE_MAX_WAIT_MS = 300;
|
|
18
|
+
const SCROLL_EPSILON = 1;
|
|
18
19
|
function getInitialVisibleRange(pageCount, overscanPages) {
|
|
19
|
-
|
|
20
|
-
return { first: 0, last: -1 };
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
20
|
+
return pageCount === 0 ? { first: 0, last: -1 } : {
|
|
23
21
|
first: Math.max(0, pageCount - 1 - Math.max(0, overscanPages)),
|
|
24
22
|
last: pageCount - 1
|
|
25
23
|
};
|
|
26
24
|
}
|
|
27
25
|
function clampVisibleRange(range, pageCount) {
|
|
28
|
-
|
|
29
|
-
return { first: 0, last: -1 };
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
26
|
+
return pageCount === 0 ? { first: 0, last: -1 } : {
|
|
32
27
|
first: Math.min(pageCount - 1, Math.max(0, range.first)),
|
|
33
28
|
last: Math.min(pageCount - 1, Math.max(0, range.last))
|
|
34
29
|
};
|
|
@@ -39,157 +34,103 @@ function createChatVirtualizerState({
|
|
|
39
34
|
}) {
|
|
40
35
|
return {
|
|
41
36
|
visibleRange: getInitialVisibleRange(pageCount, overscanPages),
|
|
42
|
-
measuredHeights: /* @__PURE__ */ new Map()
|
|
43
|
-
bottomAdjustment: 0
|
|
37
|
+
measuredHeights: /* @__PURE__ */ new Map()
|
|
44
38
|
};
|
|
45
39
|
}
|
|
46
|
-
function areRangesEqual(
|
|
47
|
-
return
|
|
48
|
-
}
|
|
49
|
-
function pruneMeasuredHeights(measuredHeights, pageCount) {
|
|
50
|
-
let didPrune = false;
|
|
51
|
-
const nextMeasuredHeights = /* @__PURE__ */ new Map();
|
|
52
|
-
for (const [pageIndex, height] of measuredHeights) {
|
|
53
|
-
if (pageIndex >= pageCount) {
|
|
54
|
-
didPrune = true;
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
nextMeasuredHeights.set(pageIndex, height);
|
|
58
|
-
}
|
|
59
|
-
return didPrune ? nextMeasuredHeights : measuredHeights;
|
|
40
|
+
function areRangesEqual(a, b) {
|
|
41
|
+
return a.first === b.first && a.last === b.last;
|
|
60
42
|
}
|
|
61
43
|
function chatVirtualizerReducer(state, action) {
|
|
62
44
|
switch (action.type) {
|
|
45
|
+
case "reset": {
|
|
46
|
+
return createChatVirtualizerState(action);
|
|
47
|
+
}
|
|
63
48
|
case "setVisibleRange": {
|
|
64
|
-
|
|
65
|
-
return state;
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
...state,
|
|
69
|
-
visibleRange: action.range
|
|
70
|
-
};
|
|
49
|
+
return areRangesEqual(state.visibleRange, action.range) ? state : { ...state, visibleRange: action.range };
|
|
71
50
|
}
|
|
72
51
|
case "syncPageWindow": {
|
|
73
52
|
const visibleRange = state.visibleRange.last === -1 ? getInitialVisibleRange(action.pageCount, action.overscanPages) : clampVisibleRange(state.visibleRange, action.pageCount);
|
|
74
|
-
const measuredHeights = pruneMeasuredHeights(state.measuredHeights, action.pageCount);
|
|
75
|
-
if (areRangesEqual(state.visibleRange, visibleRange) && measuredHeights === state.measuredHeights) {
|
|
76
|
-
return state;
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
...state,
|
|
80
|
-
visibleRange,
|
|
81
|
-
measuredHeights
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
case "measurePage": {
|
|
85
|
-
const roundedHeight = Math.ceil(action.height);
|
|
86
|
-
const previousHeight = state.measuredHeights.get(action.pageIndex) ?? 0;
|
|
87
|
-
if (previousHeight === roundedHeight) {
|
|
88
|
-
return state;
|
|
89
|
-
}
|
|
90
|
-
const heightDelta = roundedHeight - previousHeight;
|
|
91
53
|
const measuredHeights = new Map(state.measuredHeights);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
54
|
+
for (const index of measuredHeights.keys()) {
|
|
55
|
+
if (index >= action.pageCount) {
|
|
56
|
+
measuredHeights.delete(index);
|
|
57
|
+
}
|
|
96
58
|
}
|
|
97
|
-
return {
|
|
98
|
-
...state,
|
|
99
|
-
measuredHeights,
|
|
100
|
-
bottomAdjustment: state.bottomAdjustment + (action.shouldAdjustBottom ? heightDelta : 0)
|
|
101
|
-
};
|
|
59
|
+
return areRangesEqual(state.visibleRange, visibleRange) && measuredHeights.size === state.measuredHeights.size ? state : { visibleRange, measuredHeights };
|
|
102
60
|
}
|
|
103
|
-
case "
|
|
104
|
-
|
|
105
|
-
|
|
61
|
+
case "measurePages": {
|
|
62
|
+
const measuredHeights = new Map(state.measuredHeights);
|
|
63
|
+
for (const [index, height] of action.heights) {
|
|
64
|
+
measuredHeights.set(index, height);
|
|
106
65
|
}
|
|
107
|
-
return {
|
|
108
|
-
...state,
|
|
109
|
-
bottomAdjustment: 0
|
|
110
|
-
};
|
|
66
|
+
return { ...state, measuredHeights };
|
|
111
67
|
}
|
|
112
68
|
}
|
|
113
69
|
}
|
|
114
|
-
function
|
|
115
|
-
|
|
116
|
-
|
|
70
|
+
function cancelResizeTimers(runtime) {
|
|
71
|
+
window.clearTimeout(runtime.quietTimer);
|
|
72
|
+
window.clearTimeout(runtime.maxTimer);
|
|
73
|
+
runtime.quietTimer = void 0;
|
|
74
|
+
runtime.maxTimer = void 0;
|
|
117
75
|
}
|
|
118
|
-
function
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
76
|
+
function captureAnchors(element, runtime) {
|
|
77
|
+
const rect = element.getBoundingClientRect();
|
|
78
|
+
runtime.anchors = [];
|
|
79
|
+
runtime.lastScrollTop = element.scrollTop;
|
|
80
|
+
runtime.lastScrollHeight = element.scrollHeight;
|
|
81
|
+
if (runtime.isAtBottom) {
|
|
82
|
+
return;
|
|
122
83
|
}
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
);
|
|
135
|
-
const pageIndex = closestPageElement instanceof HTMLElement ? Number(closestPageElement.dataset.pageIndex) : Number.NaN;
|
|
136
|
-
if (messageId && Number.isInteger(pageIndex)) {
|
|
137
|
-
const anchor = {
|
|
138
|
-
messageId,
|
|
139
|
-
offsetTop: messageRect.top - scrollRect.top,
|
|
140
|
-
pageIndex
|
|
141
|
-
};
|
|
142
|
-
runtime.anchor = anchor;
|
|
143
|
-
return anchor;
|
|
144
|
-
}
|
|
145
|
-
runtime.anchor = void 0;
|
|
146
|
-
return void 0;
|
|
84
|
+
for (const message of Array.from(
|
|
85
|
+
element.querySelectorAll(
|
|
86
|
+
".chat-scroll__message[data-message-id]"
|
|
87
|
+
)
|
|
88
|
+
)) {
|
|
89
|
+
const messageRect = message.getBoundingClientRect();
|
|
90
|
+
if (messageRect.bottom > rect.top && messageRect.top < rect.bottom && message.dataset.messageId) {
|
|
91
|
+
runtime.anchors.push({
|
|
92
|
+
messageId: message.dataset.messageId,
|
|
93
|
+
offsetTop: messageRect.top - rect.top
|
|
94
|
+
});
|
|
147
95
|
}
|
|
148
96
|
}
|
|
149
|
-
runtime.anchor = void 0;
|
|
150
|
-
return void 0;
|
|
151
97
|
}
|
|
152
|
-
function
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return bottomAdjustment !== 0;
|
|
157
|
-
}
|
|
158
|
-
const messageElement = scrollElement.querySelector(
|
|
159
|
-
getMessageSelector(anchor.messageId)
|
|
98
|
+
function writeScrollTop(element, runtime, target) {
|
|
99
|
+
const clampedTarget = Math.max(
|
|
100
|
+
0,
|
|
101
|
+
Math.min(target, element.scrollHeight - element.clientHeight)
|
|
160
102
|
);
|
|
161
|
-
if (
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
const scrollRect = scrollElement.getBoundingClientRect();
|
|
166
|
-
const messageRect = messageElement.getBoundingClientRect();
|
|
167
|
-
const nextOffsetTop = messageRect.top - scrollRect.top;
|
|
168
|
-
const offsetDelta = nextOffsetTop - anchor.offsetTop;
|
|
169
|
-
if (offsetDelta !== 0) {
|
|
170
|
-
scrollElement.scrollTop += offsetDelta;
|
|
103
|
+
if (Math.abs(element.scrollTop - clampedTarget) > SCROLL_EPSILON) {
|
|
104
|
+
element.scrollTop = clampedTarget;
|
|
105
|
+
runtime.expectedScrollTop = element.scrollTop;
|
|
171
106
|
}
|
|
172
|
-
if (bottomAdjustment !== 0) {
|
|
173
|
-
scrollElement.scrollTop += bottomAdjustment;
|
|
174
|
-
}
|
|
175
|
-
runtime.anchor = void 0;
|
|
176
|
-
return bottomAdjustment !== 0;
|
|
177
107
|
}
|
|
178
|
-
function
|
|
179
|
-
if (
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
108
|
+
function restoreAnchors(element, runtime) {
|
|
109
|
+
if (runtime.isAtBottom) {
|
|
110
|
+
writeScrollTop(element, runtime, element.scrollHeight);
|
|
111
|
+
} else {
|
|
112
|
+
const messages = new Map(
|
|
113
|
+
Array.from(
|
|
114
|
+
element.querySelectorAll(
|
|
115
|
+
".chat-scroll__message[data-message-id]"
|
|
116
|
+
),
|
|
117
|
+
(message) => [message.dataset.messageId, message]
|
|
118
|
+
)
|
|
119
|
+
);
|
|
120
|
+
for (const anchor of runtime.anchors) {
|
|
121
|
+
const message = messages.get(anchor.messageId);
|
|
122
|
+
if (message) {
|
|
123
|
+
const offset = message.getBoundingClientRect().top - element.getBoundingClientRect().top;
|
|
124
|
+
writeScrollTop(
|
|
125
|
+
element,
|
|
126
|
+
runtime,
|
|
127
|
+
element.scrollTop + offset - anchor.offsetTop
|
|
128
|
+
);
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
191
132
|
}
|
|
192
|
-
|
|
133
|
+
captureAnchors(element, runtime);
|
|
193
134
|
}
|
|
194
135
|
function useChatVirtualizer({
|
|
195
136
|
messages,
|
|
@@ -200,126 +141,249 @@ function useChatVirtualizer({
|
|
|
200
141
|
}) {
|
|
201
142
|
const scrollRef = useRef(null);
|
|
202
143
|
const runtimeRef = useRef({
|
|
144
|
+
active: true,
|
|
203
145
|
isAtBottom: true,
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
146
|
+
anchors: [],
|
|
147
|
+
expectedScrollTop: void 0,
|
|
148
|
+
lastScrollTop: 0,
|
|
149
|
+
lastScrollHeight: 0,
|
|
150
|
+
userScrollIntent: false,
|
|
151
|
+
quietTimer: void 0,
|
|
152
|
+
maxTimer: void 0,
|
|
207
153
|
frameId: void 0,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
154
|
+
pages: /* @__PURE__ */ new Map(),
|
|
155
|
+
pending: /* @__PURE__ */ new Map(),
|
|
156
|
+
newPages: false,
|
|
157
|
+
needsRestore: true,
|
|
158
|
+
messageIds: /* @__PURE__ */ new Set(),
|
|
159
|
+
pageSize
|
|
213
160
|
});
|
|
214
161
|
const pages = useMemo(
|
|
215
162
|
() => createPages([...messages].reverse(), pageSize),
|
|
216
163
|
[messages, pageSize]
|
|
217
164
|
);
|
|
165
|
+
const messageIds = useMemo(
|
|
166
|
+
() => new Set(messages.map(getMessageId)),
|
|
167
|
+
[messages, getMessageId]
|
|
168
|
+
);
|
|
218
169
|
const pageCount = pages.length;
|
|
219
170
|
const [state, dispatch] = useReducer(
|
|
220
171
|
chatVirtualizerReducer,
|
|
221
172
|
{ pageCount, overscanPages },
|
|
222
173
|
createChatVirtualizerState
|
|
223
174
|
);
|
|
224
|
-
const
|
|
225
|
-
const
|
|
226
|
-
() => buildPageHeights(pageCount, state.measuredHeights),
|
|
175
|
+
const visibleRange = clampVisibleRange(state.visibleRange, pageCount);
|
|
176
|
+
const prefixHeights = useMemo(
|
|
177
|
+
() => buildPrefixHeights(buildPageHeights(pageCount, state.measuredHeights)),
|
|
227
178
|
[pageCount, state.measuredHeights]
|
|
228
179
|
);
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
|
|
180
|
+
const geometryRef = useRef({
|
|
181
|
+
prefixHeights,
|
|
182
|
+
visibleRange,
|
|
183
|
+
pageCount,
|
|
184
|
+
overscanPages,
|
|
185
|
+
bottomThresholdPx
|
|
186
|
+
});
|
|
187
|
+
const flushMeasurements = useCallback(() => {
|
|
188
|
+
const runtime = runtimeRef.current;
|
|
189
|
+
const heights = /* @__PURE__ */ new Map();
|
|
190
|
+
cancelResizeTimers(runtime);
|
|
191
|
+
for (const [index, page] of runtime.pending) {
|
|
192
|
+
if (runtime.pages.get(index) === page) {
|
|
193
|
+
heights.set(index, page.height);
|
|
194
|
+
}
|
|
243
195
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
});
|
|
250
|
-
|
|
196
|
+
runtime.pending.clear();
|
|
197
|
+
if (!runtime.active || heights.size === 0) {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
runtime.needsRestore = true;
|
|
201
|
+
dispatch({ type: "measurePages", heights });
|
|
202
|
+
return true;
|
|
203
|
+
}, []);
|
|
204
|
+
const registerPage = useCallback(
|
|
205
|
+
(index, element) => {
|
|
206
|
+
const runtime = runtimeRef.current;
|
|
207
|
+
const page = { element, height: element.getBoundingClientRect().height };
|
|
208
|
+
let observing = true;
|
|
209
|
+
runtime.active = true;
|
|
210
|
+
runtime.pages.set(index, page);
|
|
211
|
+
runtime.pending.set(index, page);
|
|
212
|
+
runtime.newPages = true;
|
|
213
|
+
runtime.needsRestore = true;
|
|
214
|
+
const observer = new ResizeObserver(() => {
|
|
215
|
+
if (!observing || !runtime.active || runtime.pages.get(index) !== page) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const height = element.getBoundingClientRect().height;
|
|
219
|
+
if (page.height === height) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
page.height = height;
|
|
223
|
+
runtime.pending.set(index, page);
|
|
224
|
+
window.clearTimeout(runtime.quietTimer);
|
|
225
|
+
runtime.quietTimer = window.setTimeout(
|
|
226
|
+
flushMeasurements,
|
|
227
|
+
RESIZE_QUIET_MS
|
|
228
|
+
);
|
|
229
|
+
if (runtime.maxTimer === void 0) {
|
|
230
|
+
runtime.maxTimer = window.setTimeout(
|
|
231
|
+
flushMeasurements,
|
|
232
|
+
RESIZE_MAX_WAIT_MS
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
observer.observe(element);
|
|
237
|
+
return () => {
|
|
238
|
+
observing = false;
|
|
239
|
+
observer.disconnect();
|
|
240
|
+
if (runtime.pages.get(index) === page) {
|
|
241
|
+
runtime.pages.delete(index);
|
|
242
|
+
runtime.pending.delete(index);
|
|
243
|
+
}
|
|
244
|
+
if (runtime.pending.size === 0) {
|
|
245
|
+
cancelResizeTimers(runtime);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
},
|
|
249
|
+
[flushMeasurements]
|
|
250
|
+
);
|
|
251
|
+
const updateVisibleRange = useCallback(() => {
|
|
252
|
+
const element = scrollRef.current;
|
|
253
|
+
const runtime = runtimeRef.current;
|
|
254
|
+
const geometry = geometryRef.current;
|
|
255
|
+
if (!element || runtime.pending.size > 0) {
|
|
251
256
|
return;
|
|
252
257
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
258
|
+
const range = clampVisibleRange(
|
|
259
|
+
getVisiblePageRange({
|
|
260
|
+
prefixHeights: geometry.prefixHeights,
|
|
261
|
+
scrollTop: element.scrollTop,
|
|
262
|
+
viewportHeight: element.clientHeight,
|
|
263
|
+
overscanPages: geometry.overscanPages
|
|
264
|
+
}),
|
|
265
|
+
geometry.pageCount
|
|
266
|
+
);
|
|
267
|
+
if (!areRangesEqual(range, geometry.visibleRange)) {
|
|
268
|
+
runtime.needsRestore = true;
|
|
269
|
+
dispatch({ type: "setVisibleRange", range });
|
|
270
|
+
}
|
|
257
271
|
}, []);
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
const shouldAdjustBottom = anchor ? shouldAdjustScrollForHeightChange({
|
|
262
|
-
changedPageIndex: pageIndex,
|
|
263
|
-
firstVisiblePageIndex: anchor.pageIndex,
|
|
264
|
-
isAtBottom: currentRuntime.isAtBottom
|
|
265
|
-
}) : false;
|
|
266
|
-
dispatch({ type: "measurePage", pageIndex, height, shouldAdjustBottom });
|
|
272
|
+
const handleScrollIntent = useCallback(() => {
|
|
273
|
+
runtimeRef.current.userScrollIntent = true;
|
|
274
|
+
runtimeRef.current.expectedScrollTop = void 0;
|
|
267
275
|
}, []);
|
|
268
|
-
|
|
269
|
-
const
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
currentRuntime,
|
|
274
|
-
state.bottomAdjustment
|
|
275
|
-
);
|
|
276
|
-
if (shouldClearBottomAdjustment) {
|
|
277
|
-
dispatch({ type: "clearBottomAdjustment" });
|
|
276
|
+
const handleScroll = useCallback(() => {
|
|
277
|
+
const element = scrollRef.current;
|
|
278
|
+
const runtime = runtimeRef.current;
|
|
279
|
+
if (!element) {
|
|
280
|
+
return;
|
|
278
281
|
}
|
|
279
|
-
|
|
282
|
+
const expected = runtime.expectedScrollTop;
|
|
283
|
+
const layoutClamped = element.scrollHeight < runtime.lastScrollHeight && runtime.lastScrollTop > element.scrollHeight - element.clientHeight && Math.abs(
|
|
284
|
+
element.scrollTop - Math.max(0, element.scrollHeight - element.clientHeight)
|
|
285
|
+
) <= SCROLL_EPSILON;
|
|
286
|
+
if (!runtime.userScrollIntent && (expected !== void 0 && Math.abs(expected - element.scrollTop) <= SCROLL_EPSILON || layoutClamped)) {
|
|
287
|
+
runtime.expectedScrollTop = void 0;
|
|
280
288
|
return;
|
|
281
289
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
290
|
+
runtime.userScrollIntent = false;
|
|
291
|
+
runtime.expectedScrollTop = void 0;
|
|
292
|
+
runtime.isAtBottom = isNearBottom({
|
|
293
|
+
scrollTop: element.scrollTop,
|
|
294
|
+
scrollHeight: element.scrollHeight,
|
|
295
|
+
clientHeight: element.clientHeight,
|
|
296
|
+
thresholdPx: geometryRef.current.bottomThresholdPx
|
|
297
|
+
});
|
|
298
|
+
captureAnchors(element, runtime);
|
|
299
|
+
if (runtime.pending.size > 0) {
|
|
300
|
+
flushMeasurements();
|
|
301
|
+
}
|
|
302
|
+
if (runtime.frameId === void 0) {
|
|
303
|
+
runtime.frameId = window.requestAnimationFrame(() => {
|
|
304
|
+
runtime.frameId = void 0;
|
|
305
|
+
updateVisibleRange();
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
}, [flushMeasurements, updateVisibleRange]);
|
|
285
309
|
useLayoutEffect(() => {
|
|
286
|
-
const
|
|
287
|
-
const
|
|
288
|
-
const
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
310
|
+
const runtime = runtimeRef.current;
|
|
311
|
+
const element = scrollRef.current;
|
|
312
|
+
const replaced = runtime.pageSize !== pageSize || runtime.messageIds.size > 0 && !Array.from(messageIds).some((id) => runtime.messageIds.has(id));
|
|
313
|
+
const addedPageAtBottom = runtime.isAtBottom && pageCount > geometryRef.current.pageCount;
|
|
314
|
+
geometryRef.current = {
|
|
315
|
+
prefixHeights,
|
|
316
|
+
visibleRange,
|
|
317
|
+
pageCount,
|
|
318
|
+
overscanPages,
|
|
319
|
+
bottomThresholdPx
|
|
320
|
+
};
|
|
321
|
+
runtime.active = true;
|
|
322
|
+
runtime.messageIds = messageIds;
|
|
323
|
+
runtime.pageSize = pageSize;
|
|
324
|
+
if (replaced) {
|
|
325
|
+
cancelResizeTimers(runtime);
|
|
326
|
+
window.cancelAnimationFrame(runtime.frameId ?? 0);
|
|
327
|
+
runtime.frameId = void 0;
|
|
328
|
+
runtime.pending.clear();
|
|
329
|
+
runtime.anchors = [];
|
|
330
|
+
runtime.expectedScrollTop = void 0;
|
|
331
|
+
runtime.isAtBottom = true;
|
|
332
|
+
runtime.userScrollIntent = false;
|
|
333
|
+
runtime.needsRestore = true;
|
|
334
|
+
runtime.newPages = true;
|
|
335
|
+
for (const [index, page] of runtime.pages) {
|
|
336
|
+
page.height = page.element.getBoundingClientRect().height;
|
|
337
|
+
runtime.pending.set(index, page);
|
|
338
|
+
}
|
|
339
|
+
dispatch({ type: "reset", pageCount, overscanPages });
|
|
294
340
|
return;
|
|
295
341
|
}
|
|
296
|
-
if (!
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
updateVisibleRange(scrollElement, currentRuntime, dispatch);
|
|
301
|
-
return;
|
|
342
|
+
if (!areRangesEqual(state.visibleRange, visibleRange) || state.visibleRange.last === -1 && pageCount > 0 || Array.from(state.measuredHeights.keys()).some(
|
|
343
|
+
(index) => index >= pageCount
|
|
344
|
+
)) {
|
|
345
|
+
dispatch({ type: "syncPageWindow", pageCount, overscanPages });
|
|
302
346
|
}
|
|
303
|
-
if (
|
|
304
|
-
|
|
305
|
-
|
|
347
|
+
if (addedPageAtBottom) {
|
|
348
|
+
runtime.needsRestore = true;
|
|
349
|
+
dispatch({
|
|
350
|
+
type: "setVisibleRange",
|
|
351
|
+
range: {
|
|
352
|
+
first: visibleRange.first,
|
|
353
|
+
last: pageCount - 1
|
|
354
|
+
}
|
|
355
|
+
});
|
|
306
356
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
if (frameId !== void 0) {
|
|
312
|
-
window.cancelAnimationFrame(frameId);
|
|
357
|
+
if (runtime.newPages) {
|
|
358
|
+
runtime.newPages = false;
|
|
359
|
+
if (flushMeasurements()) {
|
|
360
|
+
return;
|
|
313
361
|
}
|
|
314
|
-
}
|
|
315
|
-
|
|
362
|
+
}
|
|
363
|
+
if (element && runtime.needsRestore && runtime.pending.size === 0) {
|
|
364
|
+
runtime.needsRestore = false;
|
|
365
|
+
restoreAnchors(element, runtime);
|
|
366
|
+
updateVisibleRange();
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
useLayoutEffect(
|
|
370
|
+
() => () => {
|
|
371
|
+
const runtime = runtimeRef.current;
|
|
372
|
+
runtime.active = false;
|
|
373
|
+
cancelResizeTimers(runtime);
|
|
374
|
+
window.cancelAnimationFrame(runtime.frameId ?? 0);
|
|
375
|
+
runtime.frameId = void 0;
|
|
376
|
+
runtime.pending.clear();
|
|
377
|
+
},
|
|
378
|
+
[]
|
|
379
|
+
);
|
|
316
380
|
return {
|
|
317
381
|
scrollRef,
|
|
318
|
-
visiblePages,
|
|
319
|
-
|
|
320
|
-
windowBottom: virtualWindowMetrics.bottom + state.bottomAdjustment,
|
|
382
|
+
visiblePages: visibleRange.last >= visibleRange.first ? pages.slice(visibleRange.first, visibleRange.last + 1) : [],
|
|
383
|
+
spacerHeights: getSpacerHeights(prefixHeights, visibleRange),
|
|
321
384
|
handleScroll,
|
|
322
|
-
|
|
385
|
+
handleScrollIntent,
|
|
386
|
+
registerPage
|
|
323
387
|
};
|
|
324
388
|
}
|
|
325
389
|
export {
|
|
@@ -37,8 +37,3 @@ export declare function isNearBottom(args: {
|
|
|
37
37
|
clientHeight: number;
|
|
38
38
|
thresholdPx: number;
|
|
39
39
|
}): boolean;
|
|
40
|
-
export declare function shouldAdjustScrollForHeightChange(args: {
|
|
41
|
-
changedPageIndex: number;
|
|
42
|
-
firstVisiblePageIndex: number;
|
|
43
|
-
isAtBottom: boolean;
|
|
44
|
-
}): boolean;
|
|
@@ -20,7 +20,9 @@ function buildPageHeights(pageCount, measuredHeights) {
|
|
|
20
20
|
const heights = [];
|
|
21
21
|
for (let index = 0; index < pageCount; index += 1) {
|
|
22
22
|
const measuredHeight = measuredHeights.get(index);
|
|
23
|
-
heights.push(
|
|
23
|
+
heights.push(
|
|
24
|
+
measuredHeight !== void 0 && measuredHeight > 0 ? measuredHeight : 0
|
|
25
|
+
);
|
|
24
26
|
}
|
|
25
27
|
return heights;
|
|
26
28
|
}
|
|
@@ -104,9 +106,6 @@ function getVirtualWindowMetrics(prefixHeights, range) {
|
|
|
104
106
|
function isNearBottom(args) {
|
|
105
107
|
return args.scrollHeight - args.scrollTop - args.clientHeight <= Math.max(0, args.thresholdPx);
|
|
106
108
|
}
|
|
107
|
-
function shouldAdjustScrollForHeightChange(args) {
|
|
108
|
-
return !args.isAtBottom && args.changedPageIndex <= Math.max(0, args.firstVisiblePageIndex);
|
|
109
|
-
}
|
|
110
109
|
export {
|
|
111
110
|
DEFAULT_OVERSCAN_PAGES,
|
|
112
111
|
DEFAULT_PAGE_SIZE,
|
|
@@ -118,6 +117,5 @@ export {
|
|
|
118
117
|
getTotalHeight,
|
|
119
118
|
getVirtualWindowMetrics,
|
|
120
119
|
getVisiblePageRange,
|
|
121
|
-
isNearBottom
|
|
122
|
-
shouldAdjustScrollForHeightChange
|
|
120
|
+
isNearBottom
|
|
123
121
|
};
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { ChatFeedWidget } from './chat/chat-feed-widget.js';
|
|
|
3
3
|
export type { ToolCall, ToolCallStatus } from './chat/chat-feed-widget.js';
|
|
4
4
|
export * from './chat/chat-hooks.js';
|
|
5
5
|
export * from './chat/chat-input.js';
|
|
6
|
+
export * from './chat/composer-action-button.js';
|
|
6
7
|
export * from './chat/chat-message.js';
|
|
7
8
|
export * from './chat/chat-typing-indicator.js';
|
|
8
9
|
export * from './chat/conversation-descriptor.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./chat/chat-bot-view.js";
|
|
|
2
2
|
import { ChatFeedWidget } from "./chat/chat-feed-widget.js";
|
|
3
3
|
export * from "./chat/chat-hooks.js";
|
|
4
4
|
export * from "./chat/chat-input.js";
|
|
5
|
+
export * from "./chat/composer-action-button.js";
|
|
5
6
|
export * from "./chat/chat-message.js";
|
|
6
7
|
export * from "./chat/chat-typing-indicator.js";
|
|
7
8
|
export * from "./chat/conversation-descriptor.js";
|