open-webui/src/lib/components/notes/NotePanel.svelte

109 lines
2.6 KiB
Svelte
Raw Normal View History

2025-07-07 14:26:52 +00:00
<script lang="ts">
2025-07-08 10:51:50 +00:00
import { onDestroy, onMount, tick } from 'svelte';
2025-07-07 14:26:52 +00:00
import { Pane, PaneResizer } from 'paneforge';
import Drawer from '../common/Drawer.svelte';
import EllipsisVertical from '../icons/EllipsisVertical.svelte';
export let show = false;
export let pane = null;
2025-07-07 20:07:50 +00:00
export let containerId = 'note-container';
2025-07-07 14:26:52 +00:00
let mediaQuery;
let largeScreen = false;
let minSize = 0;
const handleMediaQuery = async (e) => {
if (e.matches) {
largeScreen = true;
} else {
largeScreen = false;
pane = null;
}
};
onMount(() => {
2025-07-07 20:07:50 +00:00
// listen to resize 1000px
mediaQuery = window.matchMedia('(min-width: 1000px)');
2025-07-07 14:26:52 +00:00
mediaQuery.addEventListener('change', handleMediaQuery);
handleMediaQuery(mediaQuery);
2025-07-07 20:07:50 +00:00
// Select the container element you want to observe
const container = document.getElementById(containerId);
// initialize the minSize based on the container width
minSize = Math.floor((400 / container.clientWidth) * 100);
// Create a new ResizeObserver instance
const resizeObserver = new ResizeObserver((entries) => {
for (let entry of entries) {
const width = entry.contentRect.width;
// calculate the percentage of 200px
const percentage = (400 / width) * 100;
// set the minSize to the percentage, must be an integer
minSize = Math.floor(percentage);
2025-07-08 08:39:04 +00:00
if (show) {
if (pane && pane.isExpanded() && pane.getSize() < minSize) {
pane.resize(minSize);
}
}
2025-07-07 20:07:50 +00:00
}
});
// Start observing the container's size changes
resizeObserver.observe(container);
2025-07-07 14:26:52 +00:00
});
onDestroy(() => {
mediaQuery.removeEventListener('change', handleMediaQuery);
});
</script>
{#if !largeScreen}
{#if show}
<Drawer
{show}
onClose={() => {
show = false;
}}
>
2025-07-09 00:53:31 +00:00
<div class=" px-3.5 py-2.5 h-screen max-h-dvh flex flex-col">
2025-07-07 14:26:52 +00:00
<slot />
</div>
</Drawer>
{/if}
{:else if show}
<PaneResizer
2025-07-12 18:14:41 +00:00
class="relative flex w-2 items-center justify-center bg-background group bg-white dark:shadow-lg dark:bg-gray-850 border-l border-gray-50 dark:border-gray-850"
2025-07-07 14:26:52 +00:00
>
<div class="z-10 flex h-7 w-5 items-center justify-center rounded-xs">
<EllipsisVertical className="size-4 invisible group-hover:visible" />
</div>
</PaneResizer>
<Pane
bind:pane
2025-07-08 10:51:50 +00:00
defaultSize={Math.max(20, minSize)}
2025-07-07 20:07:50 +00:00
{minSize}
2025-07-07 14:26:52 +00:00
onCollapse={() => {
show = false;
}}
collapsible={true}
class=" z-10 "
>
{#if show}
<div class="flex max-h-full min-h-full">
<div
2025-09-12 17:43:05 +00:00
class="w-full pt-2 bg-white dark:shadow-lg dark:bg-gray-850 z-40 pointer-events-auto overflow-y-auto scrollbar-hidden flex flex-col"
2025-07-07 14:26:52 +00:00
>
<slot />
</div>
</div>
{/if}
</Pane>
{/if}