2025-07-07 14:26:52 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { onDestroy, onMount } from 'svelte';
|
|
|
|
|
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-07 15:32:41 +00:00
|
|
|
<div class=" px-3.5 py-2.5 h-screen flex flex-col">
|
2025-07-07 14:26:52 +00:00
|
|
|
<slot />
|
|
|
|
|
</div>
|
|
|
|
|
</Drawer>
|
|
|
|
|
{/if}
|
|
|
|
|
{:else if show}
|
|
|
|
|
<PaneResizer
|
|
|
|
|
class="relative flex w-2 items-center justify-center bg-background group bg-white dark:shadow-lg dark:bg-gray-850 border border-gray-100 dark:border-gray-850"
|
|
|
|
|
>
|
|
|
|
|
<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-07 20:07:50 +00:00
|
|
|
defaultSize={20}
|
|
|
|
|
{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-07-07 15:26:12 +00:00
|
|
|
class="w-full pl-1.5 pr-2.5 pt-2 bg-white dark:shadow-lg dark:bg-gray-850 border border-gray-100 dark:border-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}
|