# Default kit

`@writeon/kit` is a ready-made UI on top of the headless controllers: one CSS file, a toolbar, and the advanced UI.

## Use it

**React**

```tsx
import { fetchUploader } from '@writeon/advanced'
import { advancedSchema } from '@writeon/advanced/schema'
import { basic } from '@writeon/core/presets'
import '@writeon/kit/style.css'
import { Advanced, Toolbar } from '@writeon/kit/react'
import { EditorContent, useEditor } from '@writeon/react'

const extensions = [...basic(), advancedSchema()]

// Uploads go to your endpoint, which answers with { url }.
const upload = fetchUploader({ url: '/api/images' })

interface Person {
  id: string
  label: string
}
declare function searchPeople(query: string): Promise<Person[]>

export function Editor() {
  const editor = useEditor({ extensions, label: 'Message' })

  return (
    <div className="rte-root">
      <Toolbar editor={editor} />
      <EditorContent editor={editor} className="rte-content" />

      {/* Loaded on demand, after mount. */}
      <Advanced
        editor={editor}
        upload={upload}
        mentions={searchPeople}
      />
    </div>
  )
}
```

**Vue**

```vue
<script setup lang="ts">
import { advancedSchema } from '@writeon/advanced/schema'
import { basic } from '@writeon/core/presets'
import '@writeon/kit/style.css'
import { Advanced, Toolbar } from '@writeon/kit/vue'
import uz from '@writeon/ui/locales/uz'
import { EditorContent, useEditor } from '@writeon/vue'

const editor = useEditor({
  extensions: [...basic(), advancedSchema()],
  label: 'Xabar',
})
</script>

<template>
  <div class="rte-root">
    <!-- Buttons, menus and announcements in Uzbek. -->
    <Toolbar :editor="editor" :messages="uz" />
    <EditorContent :editor="editor" class="rte-content" />
    <Advanced :editor="editor" :messages="uz" />
  </div>
</template>
```

**Vanilla**

```ts
import { advancedSchema } from '@writeon/advanced/schema'
import { createEditor } from '@writeon/core'
import { basic } from '@writeon/core/presets'
import '@writeon/kit/style.css'
import { mountToolbar } from '@writeon/kit'

// <div class="rte-root">
//   <div id="toolbar"></div>
//   <div id="editor" class="rte-content"></div>
// </div>
const root = document.querySelector<HTMLElement>('.rte-root')
const toolbarHost = document.querySelector<HTMLElement>('#toolbar')
const element = document.querySelector<HTMLElement>('#editor')
if (!root || !toolbarHost || !element) {
  throw new Error('Missing elements')
}

const editor = createEditor({
  element,
  extensions: [...basic(), advancedSchema()],
  label: 'Notes',
})
mountToolbar(toolbarHost, editor)

// The advanced UI and its behaviour come in a separate chunk.
const { mountAdvanced } = await import('@writeon/kit/advanced')
mountAdvanced(root, editor, { slash: true })
```

- `.rte-root` is the frame; `.rte-content` styles the document (headings, lists, code, tables, task lists, images, mentions) without Tailwind Typography.
- `<Toolbar>` / `mountToolbar()`: undo/redo, text style menu, marks, lists, quote, clear formatting, link, tooltips. Options: `messages`, `blockTypes`, `headingLevels`, `link`, `exclude`, `mobile`.
- `<Advanced>` / `mountAdvanced()` needs `advancedSchema()` in the editor. It turns on the advanced behaviour and adds:
  - image, table, task list and code block buttons to the toolbar;
  - the image dialog, and with `upload`, uploads from the device, drop and paste;
  - the `/` command menu (`slash`), `@` mentions (`mentions`), and the selection bubble (`bubble`).

Its code is a separate chunk, loaded after mount.

## Theme

Every colour, radius and font is a CSS variable on `.rte-root`:

```css
.rte-root {
  --rte-color-accent: #0d9488;
  --rte-color-accent-soft: #ccfbf1;
  --rte-color-accent-text: #115e59;
  --rte-radius: 4px;
  --rte-font: "Inter", sans-serif;
}
```

Dark mode follows the system. To choose explicitly, set `data-theme="dark"` or `data-theme="light"` on `.rte-root` or any ancestor.

Each kit rule has the specificity of one class, so CSS resets such as Tailwind's preflight do not undo it, and any rule of yours with one class overrides it.

## On phones

On touch screens the toolbar docks above the on-screen keyboard while the editor has focus, and scrolls sideways. The selection bubble is off there, because the system shows its own menu. Turn docking off with `mobile: false`.

## Size

About 3 KB of JavaScript and 3.5 KB of CSS (gzip) for the toolbar and styles; the advanced UI is about 11 KB, including Floating UI, loaded on demand.
