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,15 +23,19 @@
let floatingInputValue = ''; let floatingInputValue = '';
const updateButtonPosition = (event) => { const updateButtonPosition = (event) => {
setTimeout(async () => { if (
await tick(); !contentContainerElement?.contains(event.target) &&
!buttonsContainerElement?.contains(event.target)
// Check if the event target is within the content container ) {
if (!contentContainerElement?.contains(event.target)) {
closeFloatingButtons(); closeFloatingButtons();
return; return;
} }
setTimeout(async () => {
await tick();
if (!contentContainerElement?.contains(event.target)) return;
let selection = window.getSelection(); let selection = window.getSelection();
if (selection.toString().trim().length > 0) { if (selection.toString().trim().length > 0) {
@ -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