Merge pull request #5961 from open-webui/dev

refac: floating buttons
This commit is contained in:
Timothy Jaeryang Baek 2024-10-07 07:55:39 +02:00 committed by GitHub
commit ad7bc624c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -23,14 +23,18 @@
let floatingInputValue = ''; let floatingInputValue = '';
const updateButtonPosition = (event) => { const updateButtonPosition = (event) => {
if (
!contentContainerElement?.contains(event.target) &&
!buttonsContainerElement?.contains(event.target)
) {
closeFloatingButtons();
return;
}
setTimeout(async () => { setTimeout(async () => {
await tick(); await tick();
// Check if the event target is within the content container if (!contentContainerElement?.contains(event.target)) return;
if (!contentContainerElement?.contains(event.target)) {
closeFloatingButtons();
return;
}
let selection = window.getSelection(); let selection = window.getSelection();
@ -51,8 +55,9 @@
// Calculate space available on the right // Calculate space available on the right
const spaceOnRight = parentRect.width - (left + buttonsContainerElement.offsetWidth); const spaceOnRight = parentRect.width - (left + buttonsContainerElement.offsetWidth);
if (spaceOnRight < 0) { let thirdScreenWidth = window.innerWidth / 3;
// Not enough space on the right, position using 'right'
if (spaceOnRight < thirdScreenWidth) {
const right = parentRect.right - rect.right; const right = parentRect.right - rect.right;
buttonsContainerElement.style.right = `${right}px`; buttonsContainerElement.style.right = `${right}px`;
buttonsContainerElement.style.left = 'auto'; // Reset left buttonsContainerElement.style.left = 'auto'; // Reset left