# Inline editor

A single-block text editor with marks and lists, driven by a toolbar.

Section: Blocks / Editor
Page: https://ui.heyramzi.com/components/inline-editor
Import path: `@heyramzi/ui/editor/inline-editor`

## Import

```ts
import InlineEditor, { type InlineDoc, type InlineEditorApi, } from "@heyramzi/ui/editor/inline-editor";
import { Button } from "@heyramzi/ui/shadcn/button";
```

## Usage

```svelte
<InlineEditor
  {doc}
  placeholder="Write a note"
  onDocChange={(next) => (doc = next)}
  onExit={() => api?.focus()}
  onReady={(editor) => (api = editor)}
/>
```

## Demo

```svelte
<script lang="ts">
	import InlineEditor, {
		type InlineDoc,
		type InlineEditorApi,
	} from "@heyramzi/ui/editor/inline-editor";
	import "@heyramzi/ui/editor/content.css";
	import { Button } from "@heyramzi/ui/shadcn/button";
	import { TextB, TextItalic, ListBullets } from "phosphor-svelte";

	let doc = $state<InlineDoc>({
		type: "doc",
		content: [
			{
				type: "paragraph",
				content: [
					{ type: "text", text: "Call Brightwell Studio about the " },
					{ type: "text", text: "revised scope", marks: [{ type: "bold" }] },
					{ type: "text", text: " before Friday." },
				],
			},
			{
				type: "bulletList",
				content: [
					{
						type: "listItem",
						content: [
							{ type: "paragraph", content: [{ type: "text", text: "Send the updated quote" }] },
						],
					},
					{
						type: "listItem",
						content: [
							{ type: "paragraph", content: [{ type: "text", text: "Book the handover session" }] },
						],
					},
				],
			},
		],
	});
	let api = $state<InlineEditorApi>();
</script>

<div class="w-full max-w-md rounded-xl border border-border bg-card">
	<div class="flex items-center gap-1 border-b border-border p-1.5">
		<Button variant="ghost" size="sm" icon aria-label="Bold" onclick={() => api?.toggle("bold")}
			><TextB aria-hidden="true" class="size-4" /></Button
		>
		<Button variant="ghost" size="sm" icon aria-label="Italic" onclick={() => api?.toggle("italic")}
			><TextItalic aria-hidden="true" class="size-4" /></Button
		>
		<Button
			variant="ghost"
			size="sm"
			icon
			aria-label="Bullet list"
			onclick={() => api?.toggle("bulletList")}
			><ListBullets aria-hidden="true" class="size-4" /></Button
		>
	</div>
	<InlineEditor
		{doc}
		placeholder="Write a note"
		class="tiptap-content min-h-28 p-3 text-sm outline-none"
		onDocChange={(next) => (doc = next)}
		onExit={() => api?.focus()}
		onReady={(a) => (api = a)}
	/>
</div>
```

## API

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `doc` | `InlineDoc` |  | required |
| `placeholder` | `string` | `""` |  |
| `class` | `string` | `""` |  |
| `inline` | `boolean` | `false` | Marks only: bold, italic, strike, code and link. No lists, so a table cell stays a line of words. |
| `at` | `{ x: number; y: number }` |  | Where the click landed, so the caret opens there. Without it the caret goes to the end. |
| `selectAll` | `boolean` | `false` | Opens with all the text selected, so the first key replaces it. |
| `seed` | `string` |  | Opens with the text replaced by these characters and the caret after them. |
| `onDocChange` | `(doc: InlineDoc) => void` |  | required |
| `onExit` | `() => void` |  | required |
| `onLink` | `() => void` |  |  |
| `onState` | `() => void` |  |  |
| `onReady` | `(api: InlineEditorApi) => void` |  |  |
| `label` | `string` | `"Text editor"` | The editable region's accessible name. |
