social components inlay.at
atproto components sdui
86
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 46 lines 1.1 kB view raw
1import type { l } from "@atproto/lex"; 2 3export const BRAND = Symbol.for("$"); 4 5export type Element = { 6 type: l.NsidString; 7 key?: string; 8 props?: l.LexMap; 9}; 10 11export type LexiconComponent = { 12 readonly $nsid: l.NsidString; 13}; 14 15export function createElement( 16 type: l.NsidString, 17 key?: string, 18 props?: Record<string, unknown> | null 19): Element { 20 const el: Record<string, unknown> = { $: BRAND, type }; 21 if (key != null) el.key = key; 22 if (props != null) el.props = props; 23 return el as Element; 24} 25 26export function isValidElement(value: unknown): value is Element { 27 return ( 28 typeof value === "object" && 29 value !== null && 30 (value as { $?: unknown }).$ === BRAND 31 ); 32} 33 34export function keyStaticChildren<T>(children: T): T { 35 if (Array.isArray(children)) { 36 return children.map((child, i) => 37 isValidElement(child) && child.key == null 38 ? { ...child, key: String(i) } 39 : child 40 ) as T; 41 } 42 if (isValidElement(children) && children.key == null) { 43 return { ...children, key: "0" } as T; 44 } 45 return children; 46}