# Microblogging Post Creator ## Example ```svelte
{ if (!embeds.some((em) => em.type === 'link' && em.embed.type === 'external' && em.embed.external.href === e.href)) { embeds = [ ...embeds, { type: 'link', embed: { type: 'external', external: { href: e.href, thumb: '', title: e.text, description: '' } } } ]; } }} onimageadded={(files) => { const newEmbeds: EmbedItem[] = files.map((f) => { const url = URL.createObjectURL(f); return { type: 'image', image: { alt: f.name, thumb: url, fullsize: url } }; }); embeds = [...embeds, ...newEmbeds]; }} onvideoadded={(files) => { for (const f of files) { const url = URL.createObjectURL(f); embeds = [ ...embeds, { type: 'video', embed: { type: 'video', video: { playlist: url, thumb: '', alt: f.name } } } ]; } }} > {#if embeds.length > 0}
{#each embeds as item, i}
{#if item.type === 'image'} {:else} {/if}
{/each}
{/if}
``` ## Documentation ## Usage ```svelte ``` ## Features - **@mentions** - Provide a `searchMentions` function to enable mention support. Type `@` followed by at least 2 characters to trigger the search popup. - **Links** - URLs are automatically detected and linked. - **#hashtags** - Hashtags are visually highlighted in the editor. - **Embeds** - When a link is added and no embed exists, the `embed` prop is automatically set to `{ type: 'link', url, text }`. Provide an `embedPreview` snippet to render it. - **Character count** - Shows remaining characters with color indicators (amber < 20, red when over limit). ## Bluesky Integration Use the provided helpers for Bluesky: ```svelte ``` ## Embeds Bind the `embed` prop and provide an `embedPreview` snippet to show embed previews: ```svelte {#snippet embedPreview({ embed, removeEmbed })}
{embed.url}
{/snippet}
``` ## API Reference ### MicrobloggingPostCreator A platform-agnostic microblogging post editor with support for @mentions, auto-linked URLs, #hashtags, and embeds. Includes Bluesky helpers for easy integration. | Prop | Type | Default | Description | |------|------|---------|-------------| | content | `{ text: string; json: JSONContent }` | `-` | The post content with plain text and editor JSON. (bindable) | | placeholder | `string` | `"What's on your mind?"` | Placeholder text shown when the editor is empty. | | maxLength | `number` | `300` | Maximum character count. A counter is displayed that changes color as the limit approaches. | | searchMentions | `(query: string) => Promise` | `-` | Async function to search for mentionable users. When provided, enables @mention support with a popup menu. Use `createBlueskyMentionSearch()` for Bluesky. | | embed | `unknown` | `-` | The current embed data. Automatically populated with `{ type: "link", url, text }` when a link is added and no embed exists yet. (bindable) | | onlinkadded | `(event: LinkAddedEvent) => void` | `-` | Callback invoked when a link is added to the editor. Receives `{ href, text, editor }`. | | embedPreview | `Snippet<[{ embed: unknown; removeEmbed: () => void }]>` | `-` | Snippet to render the embed preview below the editor. | | mentionItem | `Snippet<[{ item: MentionItem; isActive: boolean; select: () => void }]>` | `-` | Custom snippet for rendering mention menu items. Falls back to a default with avatar and display name. | | onupdate | `(content: MicrobloggingPostContent) => void` | `-` | Callback invoked whenever the post content changes. | | editor | `Readable` | `-` | The underlying tiptap editor instance (svelte-tiptap store). (bindable) | | ref | `HTMLDivElement` | `-` | Reference to the container element. (bindable) | | class | `string` | `-` | Additional CSS classes for the container. |