Skip to content

Commit

Permalink
Fixes for exporting chat for cases when it contains iFrames
Browse files Browse the repository at this point in the history
Fixes for displaying iFrames
  • Loading branch information
annmirosh committed Oct 7, 2024
1 parent 918ab4c commit aea91f4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 25 deletions.
71 changes: 48 additions & 23 deletions dist/alan_lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -8739,11 +8739,11 @@
if (href2) {
entry.link = href2;
}
var description = fetch("summary", children) || fetch("content", children);
var description = fetch2("summary", children) || fetch2("content", children);
if (description) {
entry.description = description;
}
var pubDate = fetch("updated", children);
var pubDate = fetch2("updated", children);
if (pubDate) {
entry.pubDate = new Date(pubDate);
}
Expand All @@ -8757,7 +8757,7 @@
feed.link = href;
}
addConditionally(feed, "description", "subtitle", childs);
var updated = fetch("updated", childs);
var updated = fetch2("updated", childs);
if (updated) {
feed.updated = new Date(updated);
}
Expand All @@ -8777,7 +8777,7 @@
addConditionally(entry, "title", "title", children);
addConditionally(entry, "link", "link", children);
addConditionally(entry, "description", "description", children);
var pubDate = fetch("pubDate", children) || fetch("dc:date", children);
var pubDate = fetch2("pubDate", children) || fetch2("dc:date", children);
if (pubDate)
entry.pubDate = new Date(pubDate);
return entry;
Expand All @@ -8786,7 +8786,7 @@
addConditionally(feed, "title", "title", childs);
addConditionally(feed, "link", "link", childs);
addConditionally(feed, "description", "description", childs);
var updated = fetch("lastBuildDate", childs);
var updated = fetch2("lastBuildDate", childs);
if (updated) {
feed.updated = new Date(updated);
}
Expand Down Expand Up @@ -8832,7 +8832,7 @@
function getOneElement(tagName, node) {
return (0, legacy_js_1.getElementsByTagName)(tagName, node, true, 1)[0];
}
function fetch(tagName, where, recurse) {
function fetch2(tagName, where, recurse) {
if (recurse === void 0) {
recurse = false;
}
Expand All @@ -8842,7 +8842,7 @@
if (recurse === void 0) {
recurse = false;
}
var val = fetch(tagName, where, recurse);
var val = fetch2(tagName, where, recurse);
if (val)
obj[prop] = val;
}
Expand Down Expand Up @@ -12311,11 +12311,11 @@
if (href2) {
entry.link = href2;
}
var description = fetch("summary", children) || fetch("content", children);
var description = fetch2("summary", children) || fetch2("content", children);
if (description) {
entry.description = description;
}
var pubDate = fetch("updated", children);
var pubDate = fetch2("updated", children);
if (pubDate) {
entry.pubDate = new Date(pubDate);
}
Expand All @@ -12329,7 +12329,7 @@
feed.link = href;
}
addConditionally(feed, "description", "subtitle", childs);
var updated = fetch("updated", childs);
var updated = fetch2("updated", childs);
if (updated) {
feed.updated = new Date(updated);
}
Expand All @@ -12349,7 +12349,7 @@
addConditionally(entry, "title", "title", children);
addConditionally(entry, "link", "link", children);
addConditionally(entry, "description", "description", children);
var pubDate = fetch("pubDate", children) || fetch("dc:date", children);
var pubDate = fetch2("pubDate", children) || fetch2("dc:date", children);
if (pubDate)
entry.pubDate = new Date(pubDate);
return entry;
Expand All @@ -12358,7 +12358,7 @@
addConditionally(feed, "title", "title", childs);
addConditionally(feed, "link", "link", childs);
addConditionally(feed, "description", "description", childs);
var updated = fetch("lastBuildDate", childs);
var updated = fetch2("lastBuildDate", childs);
if (updated) {
feed.updated = new Date(updated);
}
Expand Down Expand Up @@ -12404,7 +12404,7 @@
function getOneElement(tagName, node) {
return (0, legacy_js_1.getElementsByTagName)(tagName, node, true, 1)[0];
}
function fetch(tagName, where, recurse) {
function fetch2(tagName, where, recurse) {
if (recurse === void 0) {
recurse = false;
}
Expand All @@ -12414,7 +12414,7 @@
if (recurse === void 0) {
recurse = false;
}
var val = fetch(tagName, where, recurse);
var val = fetch2(tagName, where, recurse);
if (val)
obj[prop] = val;
}
Expand Down Expand Up @@ -93484,8 +93484,25 @@ code.hljs {
}

// alan_btn/src/textChat/saveChatStateToFile.ts
function saveChatState(chatName, chatEl, projectId, headContent, codeContent) {
const alanBtnContent = chatEl.outerHTML;
async function saveChatState(chatName, chatEl, width, projectId, headContent, codeContent) {
const chatConteiner = chatEl.cloneNode(true);
const iframes = Array.from(chatConteiner.querySelectorAll("iframe"));
for (let iframe of iframes) {
const srcUrl = iframe.getAttribute("src");
try {
const response = await fetch(srcUrl);
if (!response.ok) {
console.error(`Error fetching content from ${srcUrl}: ${response.statusText}`);
continue;
}
const htmlContent = await response.text();
iframe.removeAttribute("src");
iframe.setAttribute("srcdoc", htmlContent);
iframe.setAttribute("sandbox", "allow-scripts allow-same-origin");
} catch (error) {
console.error(`Failed to fetch or process iframe from ${srcUrl}:`, error);
}
}
const alanMainClass = "alan-" + projectId;
const newHtmlContent = `
<!DOCTYPE html>
Expand All @@ -93508,11 +93525,15 @@ code.hljs {
}
.alan-btn__history-chat-header {
margin: 0px auto;
max-width: 500px;
max-width: ${width}px;
width: ${width}px;
min-width: ${width}px;
}
.alan-history-inner-content {
margin: 0px auto;
max-width: 500px;
max-width: ${width}px;
width: ${width}px;
min-width: ${width}px;
height:100%;
box-shadow: 0px 1px 3px rgba(16, 39, 126, 0.2);
}
Expand All @@ -93524,7 +93545,7 @@ code.hljs {
<h1>Alan Text Chat History</h1>
</div>
<div class="alan-btn__history-chat alan-history-inner-content">
${alanBtnContent}
${chatConteiner.outerHTML}
</div>
</div>
${codeContent ? codeContent : ""}
Expand Down Expand Up @@ -93560,8 +93581,8 @@ code.hljs {
function adjustIFrameSize(iframeMsgData) {
const maxIFrameHeight = 1400;
var { height, width, iframeId } = iframeMsgData;
height = height + 20;
width = width + 20;
height = height;
width = width;
const iframeEls = document.querySelectorAll("#" + iframeId);
iframeEls.forEach((iframeEl) => {
iframeEl.style.height = (+height > maxIFrameHeight ? maxIFrameHeight : height) + "px";
Expand All @@ -93578,7 +93599,7 @@ code.hljs {
// alan_btn/alan_btn.ts
var import_lodash2 = __toESM(require_lodash());
(function(ns) {
uiState.lib.version = "alan-version.1.8.64".replace("alan-version.", "");
uiState.lib.version = "alan-version.1.8.65".replace("alan-version.", "");
if (window.alanBtn) {
console.warn("Alan: the Alan Button source code has already added (v." + uiState.lib.version + ")");
}
Expand Down Expand Up @@ -96495,7 +96516,11 @@ ${LEARN_MORE_LABEL}
rightHeaderIconsHolder.appendChild(expandCollapseChatBtnImg);
saveChatStateBtnImg.addEventListener("click", () => {
const headContent = document.head.innerHTML;
saveChatState(title, document.querySelector("#chatMessagesWrapper"), getProjectId(), headContent);
const initChat = document.querySelector("#chatMessagesWrapper");
if (!initChat)
return;
const chatWidth2 = initChat.clientWidth;
saveChatState(title, initChat, chatWidth2, getProjectId(), headContent);
});
expandCollapseChatBtnImg.addEventListener("click", expandCollapseTextChat);
addNeedClassesToExpandCollapseBtn(expandCollapseChatBtnImg);
Expand Down
2 changes: 1 addition & 1 deletion dist/alan_lib.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alan-ai/alan-sdk-web",
"version": "1.8.64",
"version": "1.8.65",
"description": "Alan Web SDK: a lightweight JavaScript library for adding a voice experience to your website or web application",
"keywords": [
"alan sdk web",
Expand Down

0 comments on commit aea91f4

Please sign in to comment.