import type { CardDefinition } from '../../types'; import { listRecords } from '$lib/atproto'; import MarginCard from './MarginCard.svelte'; import MarginCardSettings from './MarginCardSettings.svelte'; export type MarginEntry = { type: 'bookmark' | 'annotation' | 'highlight'; uri: string; value: any; createdAt: string; }; export const MarginCardDefinition = { type: 'margin', contentComponent: MarginCard, settingsComponent: MarginCardSettings, createNew: (card) => { card.w = 4; card.mobileW = 8; card.h = 4; card.mobileH = 6; }, loadData: async (_items, { did }) => { const [bookmarks, annotations, highlights] = await Promise.all([ listRecords({ did, collection: 'at.margin.bookmark' }).catch(() => []), listRecords({ did, collection: 'at.margin.annotation' }).catch(() => []), listRecords({ did, collection: 'at.margin.highlight' }).catch(() => []) ]); const entries: MarginEntry[] = [ ...bookmarks.map((r: any) => ({ type: 'bookmark' as const, uri: r.uri, value: r.value, createdAt: r.value.createdAt })), ...annotations.map((r: any) => ({ type: 'annotation' as const, uri: r.uri, value: r.value, createdAt: r.value.createdAt })), ...highlights.map((r: any) => ({ type: 'highlight' as const, uri: r.uri, value: r.value, createdAt: r.value.createdAt })) ]; entries.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()); return entries; }, minH: 2, canHaveLabel: true, keywords: ['margin', 'bookmarks', 'annotations', 'highlights', 'reading', 'web'], groups: ['Social'], name: 'Margin highlights, bookmarks, annotations', icon: `` } as CardDefinition & { type: 'margin' };