llmasaservice-ui 0.6.3 → 0.6.4

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/dist/index.js CHANGED
@@ -212,6 +212,7 @@ var ChatPanel = ({
212
212
  const [lastPrompt, setLastPrompt] = (0, import_react3.useState)(null);
213
213
  const [hasScroll, setHasScroll] = (0, import_react3.useState)(false);
214
214
  const bottomRef = (0, import_react3.useRef)(null);
215
+ const bottomPanelRef = (0, import_react3.useRef)(null);
215
216
  const [isAtBottom, setIsAtBottom] = (0, import_react3.useState)(true);
216
217
  const [isEmailModalOpen, setIsEmailModalOpen] = (0, import_react3.useState)(false);
217
218
  const [isCallToActionModalOpen, setIsCallToActionModalOpen] = (0, import_react3.useState)(false);
@@ -315,12 +316,18 @@ var ChatPanel = ({
315
316
  var _a, _b;
316
317
  if (scrollToEnd) {
317
318
  if (window.top !== window.self) {
318
- (_a = bottomRef.current) == null ? void 0 : _a.scrollIntoView({ behavior: "smooth", block: "end" });
319
319
  const frameElement = window.frameElement;
320
320
  if (frameElement) {
321
- window.parent.scrollTo({
322
- top: frameElement.getBoundingClientRect().top + window.scrollY,
323
- behavior: "smooth"
321
+ const frameRect = frameElement.getBoundingClientRect();
322
+ if (frameRect.bottom <= window.innerHeight) {
323
+ window.parent.scrollTo({
324
+ top: frameRect.bottom + window.scrollY - window.innerHeight,
325
+ behavior: "smooth"
326
+ });
327
+ }
328
+ (_a = bottomRef.current) == null ? void 0 : _a.scrollIntoView({
329
+ behavior: "smooth",
330
+ block: "end"
324
331
  });
325
332
  }
326
333
  } else {
@@ -1052,7 +1059,7 @@ var ChatPanel = ({
1052
1059
  },
1053
1060
  "llmasaservice.io"
1054
1061
  )))
1055
- ));
1062
+ ), /* @__PURE__ */ import_react3.default.createElement("div", { ref: bottomPanelRef }));
1056
1063
  };
1057
1064
  var ChatPanel_default = ChatPanel;
1058
1065
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.mjs CHANGED
@@ -179,6 +179,7 @@ var ChatPanel = ({
179
179
  const [lastPrompt, setLastPrompt] = useState3(null);
180
180
  const [hasScroll, setHasScroll] = useState3(false);
181
181
  const bottomRef = useRef(null);
182
+ const bottomPanelRef = useRef(null);
182
183
  const [isAtBottom, setIsAtBottom] = useState3(true);
183
184
  const [isEmailModalOpen, setIsEmailModalOpen] = useState3(false);
184
185
  const [isCallToActionModalOpen, setIsCallToActionModalOpen] = useState3(false);
@@ -282,12 +283,18 @@ var ChatPanel = ({
282
283
  var _a, _b;
283
284
  if (scrollToEnd) {
284
285
  if (window.top !== window.self) {
285
- (_a = bottomRef.current) == null ? void 0 : _a.scrollIntoView({ behavior: "smooth", block: "end" });
286
286
  const frameElement = window.frameElement;
287
287
  if (frameElement) {
288
- window.parent.scrollTo({
289
- top: frameElement.getBoundingClientRect().top + window.scrollY,
290
- behavior: "smooth"
288
+ const frameRect = frameElement.getBoundingClientRect();
289
+ if (frameRect.bottom <= window.innerHeight) {
290
+ window.parent.scrollTo({
291
+ top: frameRect.bottom + window.scrollY - window.innerHeight,
292
+ behavior: "smooth"
293
+ });
294
+ }
295
+ (_a = bottomRef.current) == null ? void 0 : _a.scrollIntoView({
296
+ behavior: "smooth",
297
+ block: "end"
291
298
  });
292
299
  }
293
300
  } else {
@@ -1019,7 +1026,7 @@ var ChatPanel = ({
1019
1026
  },
1020
1027
  "llmasaservice.io"
1021
1028
  )))
1022
- ));
1029
+ ), /* @__PURE__ */ React3.createElement("div", { ref: bottomPanelRef }));
1023
1030
  };
1024
1031
  var ChatPanel_default = ChatPanel;
1025
1032
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "llmasaservice-ui",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "description": "Prebuilt UI components for LLMAsAService.io",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/ChatPanel.tsx CHANGED
@@ -116,6 +116,7 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
116
116
  const [lastPrompt, setLastPrompt] = useState<string | null>(null);
117
117
  const [hasScroll, setHasScroll] = useState(false);
118
118
  const bottomRef = useRef<HTMLDivElement | null>(null);
119
+ const bottomPanelRef = useRef<HTMLDivElement | null>(null);
119
120
  const [isAtBottom, setIsAtBottom] = useState(true);
120
121
  const [isEmailModalOpen, setIsEmailModalOpen] = useState(false);
121
122
  const [isCallToActionModalOpen, setIsCallToActionModalOpen] = useState(false);
@@ -248,16 +249,32 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
248
249
 
249
250
  useEffect(() => {
250
251
  if (scrollToEnd) {
251
-
252
252
  if (window.top !== window.self) {
253
253
  // If the ChatPanel is within an iframe
254
- bottomRef.current?.scrollIntoView({ behavior: "smooth", block: "end" });
255
254
  const frameElement = window.frameElement;
256
255
  if (frameElement) {
257
- window.parent.scrollTo({
258
- top: frameElement.getBoundingClientRect().top + window.scrollY,
256
+ const frameRect = frameElement.getBoundingClientRect();
257
+ if (frameRect.bottom <= window.innerHeight) {
258
+ // Scroll the parent window to position the iframe at the bottom of the screen
259
+ window.parent.scrollTo({
260
+ top: frameRect.bottom + window.scrollY - window.innerHeight,
261
+ behavior: "smooth",
262
+ });
263
+ }
264
+
265
+ bottomRef.current?.scrollIntoView({
259
266
  behavior: "smooth",
267
+ block: "end",
260
268
  });
269
+
270
+ /*
271
+ // Scroll the content within the iframe
272
+ setTimeout(() => {
273
+ bottomRef.current?.scrollIntoView({
274
+ behavior: "smooth",
275
+ block: "end",
276
+ });
277
+ }, 300);*/
261
278
  }
262
279
  } else {
263
280
  // If the ChatPanel is not within an iframe
@@ -1055,6 +1072,7 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
1055
1072
  </div>
1056
1073
  )}
1057
1074
  </div>
1075
+ <div ref={bottomPanelRef} />
1058
1076
  </>
1059
1077
  );
1060
1078
  };