2024-05-16 16:24:50 +02:00
|
|
|
<script lang="ts">
|
2026-10-17 16:39:41 +02:00
|
|
|
import { getContext, setContext, type Snippet } from 'svelte';
|
|
|
|
|
import { CollapsibleTreeState, StuckRows } from './utils.svelte';
|
|
|
|
|
import { stickyKey, type StickyLevel } from './sticky';
|
2024-05-16 16:24:50 +02:00
|
|
|
|
2025-06-21 21:07:36 +02:00
|
|
|
const {
|
|
|
|
|
defaultState = 'open',
|
|
|
|
|
side = 'right',
|
|
|
|
|
nohover = false,
|
|
|
|
|
slotInsideTrigger = true,
|
2026-10-17 16:39:41 +02:00
|
|
|
sticky = false,
|
2025-06-21 21:07:36 +02:00
|
|
|
children,
|
|
|
|
|
}: {
|
|
|
|
|
defaultState?: 'open' | 'closed';
|
|
|
|
|
side?: 'left' | 'right';
|
|
|
|
|
nohover?: boolean;
|
|
|
|
|
slotInsideTrigger?: boolean;
|
2026-10-17 16:39:41 +02:00
|
|
|
/**
|
|
|
|
|
* The rows of the nodes stick to the top of the scrolled area while some of the content of
|
|
|
|
|
* their node is in view, each under the rows of the nodes it is in. A tree in a tree is
|
|
|
|
|
* like its node.
|
|
|
|
|
*/
|
|
|
|
|
sticky?: boolean;
|
2025-06-21 21:07:36 +02:00
|
|
|
children: Snippet;
|
|
|
|
|
} = $props();
|
2024-05-16 18:18:42 +02:00
|
|
|
|
2025-06-21 21:07:36 +02:00
|
|
|
let open = $state(new CollapsibleTreeState(defaultState));
|
2024-05-16 16:24:50 +02:00
|
|
|
|
2025-02-02 11:17:22 +01:00
|
|
|
setContext('collapsible-tree-state', open);
|
|
|
|
|
setContext('collapsible-tree-side', side);
|
|
|
|
|
setContext('collapsible-tree-nohover', nohover);
|
|
|
|
|
setContext('collapsible-tree-parent-id', 'root');
|
|
|
|
|
setContext('collapsible-tree-slot-inside-trigger', slotInsideTrigger);
|
2026-10-17 16:39:41 +02:00
|
|
|
setContext<StickyLevel>(
|
|
|
|
|
stickyKey,
|
|
|
|
|
getContext<StickyLevel | undefined>(stickyKey) ?? {
|
|
|
|
|
enabled: sticky,
|
|
|
|
|
top: 0,
|
|
|
|
|
depth: 0,
|
|
|
|
|
stuckRows: new StuckRows(),
|
|
|
|
|
}
|
|
|
|
|
);
|
2024-05-16 16:24:50 +02:00
|
|
|
</script>
|
|
|
|
|
|
2025-06-21 21:07:36 +02:00
|
|
|
{@render children()}
|