SimpleChatTCRV:ImagePopOver: To view and if reqd del before submit
Also had forgotten to rename to image_urls, when switching from single image with its corresponding field image_url to image_urls, wrt removing the same after it has been added to the content array.
This commit is contained in:
parent
720818f8e7
commit
15dcd4a0a3
|
|
@ -61,6 +61,10 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
<div id="popover-image" popover="auto">
|
||||||
|
<img id="poimage-img"></img>
|
||||||
|
<button id="poimage-del" title="delete"> ❌ </button>
|
||||||
|
</div>
|
||||||
<div id="user-in-div" class="role-user">
|
<div id="user-in-div" class="role-user">
|
||||||
<div id="user-in-imgs"></div>
|
<div id="user-in-imgs"></div>
|
||||||
<div class="sameline">
|
<div class="sameline">
|
||||||
|
|
|
||||||
|
|
@ -835,6 +835,9 @@ Cleanup in general
|
||||||
* Chat button to toggle sessions buttons and system prompt.
|
* Chat button to toggle sessions buttons and system prompt.
|
||||||
* Use unix date format markers wrt sys_date_time toolcall, also add w (day of week).
|
* Use unix date format markers wrt sys_date_time toolcall, also add w (day of week).
|
||||||
* Free up the useful vertical space by merging chat sessions buttons/tabs into heading
|
* Free up the useful vertical space by merging chat sessions buttons/tabs into heading
|
||||||
|
* Allow user to load multiple images and submit to ai as part of a single user message.
|
||||||
|
* Use popover ui to allow user to view larger versions of loaded images as well as remove before submitting
|
||||||
|
to ai, if and when needed.
|
||||||
|
|
||||||
|
|
||||||
#### ToDo
|
#### ToDo
|
||||||
|
|
|
||||||
|
|
@ -189,6 +189,10 @@ body {
|
||||||
max-width: 12vmin;
|
max-width: 12vmin;
|
||||||
max-height: 12vmin;
|
max-height: 12vmin;
|
||||||
}
|
}
|
||||||
|
#poimage-img {
|
||||||
|
max-width: 60vmin;
|
||||||
|
max-height: 60vmin;
|
||||||
|
}
|
||||||
#user-in {
|
#user-in {
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
padding: 1.6vmin 2vmin;
|
padding: 1.6vmin 2vmin;
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,11 @@ class NSChatMessage {
|
||||||
this.tool_calls = structuredClone(tool_calls)
|
this.tool_calls = structuredClone(tool_calls)
|
||||||
this.tool_call_id = tool_call_id
|
this.tool_call_id = tool_call_id
|
||||||
this.name = name
|
this.name = name
|
||||||
|
if (image_urls) {
|
||||||
|
if (image_urls.length <= 0) {
|
||||||
|
image_urls = undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
this.image_urls = structuredClone(image_urls)
|
this.image_urls = structuredClone(image_urls)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -625,7 +630,7 @@ class SimpleChat {
|
||||||
}
|
}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
tmsg.ns.content = tMixed
|
tmsg.ns.content = tMixed
|
||||||
tmsg.ns_delete("image_url")
|
tmsg.ns_delete("image_urls")
|
||||||
}
|
}
|
||||||
chat.push(tmsg.ns);
|
chat.push(tmsg.ns);
|
||||||
}
|
}
|
||||||
|
|
@ -1085,6 +1090,20 @@ class MultiChatUI {
|
||||||
this.elPopoverChatMsgDelBtn = /** @type{HTMLElement} */(document.getElementById("popover-chatmsg-del"));
|
this.elPopoverChatMsgDelBtn = /** @type{HTMLElement} */(document.getElementById("popover-chatmsg-del"));
|
||||||
this.uniqIdChatMsgPO = -1;
|
this.uniqIdChatMsgPO = -1;
|
||||||
|
|
||||||
|
// image popover menu
|
||||||
|
this.elPOImage = /** @type{HTMLElement} */(document.getElementById("popover-image"));
|
||||||
|
this.elPOImageImg = /** @type{HTMLImageElement} */(document.getElementById("poimage-img"));
|
||||||
|
this.elPOImageDel = /** @type{HTMLButtonElement} */(document.getElementById("poimage-del"));
|
||||||
|
this.elPOImageDel.addEventListener('click', (ev)=>{
|
||||||
|
if (this.uniqIdImagePO < 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.dataurl_plus_del(this.uniqIdImagePO)
|
||||||
|
this.uniqIdImagePO = -1;
|
||||||
|
this.elPOImage.hidePopover()
|
||||||
|
})
|
||||||
|
this.uniqIdImagePO = -1;
|
||||||
|
|
||||||
// Save any placeholder set by default like through html, to restore where needed
|
// Save any placeholder set by default like through html, to restore where needed
|
||||||
this.elInUser.dataset.placeholder = this.elInUser.placeholder
|
this.elInUser.dataset.placeholder = this.elInUser.placeholder
|
||||||
// Setup Image loading button and flow
|
// Setup Image loading button and flow
|
||||||
|
|
@ -1179,11 +1198,29 @@ class MultiChatUI {
|
||||||
if (typeof(dataUrl) == 'string') {
|
if (typeof(dataUrl) == 'string') {
|
||||||
this.me.dataURLs.push(dataUrl)
|
this.me.dataURLs.push(dataUrl)
|
||||||
let elImg = document.createElement('img')
|
let elImg = document.createElement('img')
|
||||||
|
let imgIndex = this.me.dataURLs.length-1
|
||||||
|
elImg.id = `uiimg-${imgIndex}`
|
||||||
elImg.src = dataUrl
|
elImg.src = dataUrl
|
||||||
|
elImg.addEventListener('click', (ev)=>{
|
||||||
|
this.uniqIdImagePO = imgIndex;
|
||||||
|
this.elPOImageImg.src = /** @type{string} */(this.me.dataURLs[this.uniqIdImagePO]);
|
||||||
|
this.elPOImage.showPopover()
|
||||||
|
})
|
||||||
this.elDivUserInImgs.appendChild(elImg)
|
this.elDivUserInImgs.appendChild(elImg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the dataurl, as well as shown image.
|
||||||
|
* @param {number} imgIndex
|
||||||
|
*/
|
||||||
|
dataurl_plus_del(imgIndex) {
|
||||||
|
let id = `uiimg-${imgIndex}`
|
||||||
|
this.me.dataURLs[imgIndex] = null
|
||||||
|
let elImg = document.querySelector(`[id="${id}"]`)
|
||||||
|
elImg?.remove()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the stored dataUrl
|
* Get the stored dataUrl
|
||||||
* @param {number} index
|
* @param {number} index
|
||||||
|
|
@ -1675,9 +1712,14 @@ class MultiChatUI {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
let images = undefined
|
let images = []
|
||||||
if (this.me.dataURLs.length > 0) {
|
if (this.me.dataURLs.length > 0) {
|
||||||
images = /** @type{Array<string>} */(this.me.dataURLs)
|
for (const img of this.me.dataURLs) {
|
||||||
|
if (img == null) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
images.push(/** @type{string} */(img))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.chatmsg_addsmart_uishow(chat.chatId, new ChatMessageEx(new NSChatMessage(Roles.User, content, undefined, undefined, undefined, undefined, images)))
|
this.chatmsg_addsmart_uishow(chat.chatId, new ChatMessageEx(new NSChatMessage(Roles.User, content, undefined, undefined, undefined, undefined, images)))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue