2026-01-18 15:55:07 +03:00
|
|
|
<!--
|
|
|
|
|
Component: FontVirtualList
|
|
|
|
|
- Renders a virtualized list of fonts
|
|
|
|
|
- Handles font registration with the manager
|
|
|
|
|
-->
|
2026-02-02 12:18:20 +03:00
|
|
|
<script lang="ts" generics="T extends UnifiedFont">
|
|
|
|
|
import type { FontConfigRequest } from '$entities/Font/model/store/appliedFontsStore/appliedFontsStore.svelte';
|
2026-01-18 12:55:25 +03:00
|
|
|
import { VirtualList } from '$shared/ui';
|
|
|
|
|
import type { ComponentProps } from 'svelte';
|
2026-02-02 12:18:20 +03:00
|
|
|
import {
|
|
|
|
|
type UnifiedFont,
|
|
|
|
|
appliedFontsManager,
|
|
|
|
|
} from '../../model';
|
2026-01-18 12:55:25 +03:00
|
|
|
|
|
|
|
|
interface Props extends Omit<ComponentProps<typeof VirtualList<T>>, 'onVisibleItemsChange'> {
|
|
|
|
|
onVisibleItemsChange?: (items: T[]) => void;
|
2026-01-30 19:21:47 +03:00
|
|
|
onNearBottom?: (lastVisibleIndex: number) => void;
|
2026-02-02 12:18:20 +03:00
|
|
|
weight: number;
|
2026-01-18 12:55:25 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-02 12:18:20 +03:00
|
|
|
let { items, children, onVisibleItemsChange, onNearBottom, weight, ...rest }: Props = $props();
|
2026-01-18 12:55:25 +03:00
|
|
|
|
|
|
|
|
function handleInternalVisibleChange(visibleItems: T[]) {
|
|
|
|
|
// Auto-register fonts with the manager
|
2026-02-02 12:18:20 +03:00
|
|
|
const configs = visibleItems.map<FontConfigRequest>(item => ({
|
|
|
|
|
id: item.id,
|
|
|
|
|
name: item.name,
|
|
|
|
|
weight,
|
|
|
|
|
url: item.styles.regular!,
|
|
|
|
|
}));
|
|
|
|
|
appliedFontsManager.touch(configs);
|
2026-01-18 12:55:25 +03:00
|
|
|
|
2026-02-02 12:18:20 +03:00
|
|
|
// // Forward the call to any external listener
|
|
|
|
|
// onVisibleItemsChange?.(visibleItems);
|
2026-01-18 12:55:25 +03:00
|
|
|
}
|
2026-01-30 19:21:47 +03:00
|
|
|
|
|
|
|
|
function handleNearBottom(lastVisibleIndex: number) {
|
|
|
|
|
// Forward the call to any external listener
|
|
|
|
|
onNearBottom?.(lastVisibleIndex);
|
|
|
|
|
}
|
2026-01-18 12:55:25 +03:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<VirtualList
|
|
|
|
|
{items}
|
|
|
|
|
{...rest}
|
|
|
|
|
onVisibleItemsChange={handleInternalVisibleChange}
|
2026-01-30 19:21:47 +03:00
|
|
|
onNearBottom={handleNearBottom}
|
2026-01-18 12:55:25 +03:00
|
|
|
>
|
|
|
|
|
{#snippet children(scope)}
|
|
|
|
|
{@render children(scope)}
|
|
|
|
|
{/snippet}
|
|
|
|
|
</VirtualList>
|