feat(FontVirtualList): add font pairs support
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
- Renders a virtualized list of fonts
|
- Renders a virtualized list of fonts
|
||||||
- Handles font registration with the manager
|
- Handles font registration with the manager
|
||||||
-->
|
-->
|
||||||
<script lang="ts" generics="T extends { id: string }">
|
<script lang="ts" generics="T extends ({ id: string } | [{ id: string }, { id: string }])">
|
||||||
import { VirtualList } from '$shared/ui';
|
import { VirtualList } from '$shared/ui';
|
||||||
import type { ComponentProps } from 'svelte';
|
import type { ComponentProps } from 'svelte';
|
||||||
import { appliedFontsManager } from '../../model';
|
import { appliedFontsManager } from '../../model';
|
||||||
@@ -16,7 +16,12 @@ let { items, children, onVisibleItemsChange, ...rest }: Props = $props();
|
|||||||
|
|
||||||
function handleInternalVisibleChange(visibleItems: T[]) {
|
function handleInternalVisibleChange(visibleItems: T[]) {
|
||||||
// Auto-register fonts with the manager
|
// Auto-register fonts with the manager
|
||||||
const slugs = visibleItems.map(item => item.id);
|
const slugs = visibleItems.map(item => {
|
||||||
|
if (Array.isArray(item)) {
|
||||||
|
return item.map(font => font.id);
|
||||||
|
}
|
||||||
|
return item.id;
|
||||||
|
}).flat();
|
||||||
appliedFontsManager.registerFonts(slugs);
|
appliedFontsManager.registerFonts(slugs);
|
||||||
|
|
||||||
// Forward the call to any external listener
|
// Forward the call to any external listener
|
||||||
|
|||||||
Reference in New Issue
Block a user