# Concept

> How gpdoc's headless editor, plugins, and GPUI views fit together.

In the Quickstart, registering Paragraph and Bold gives you a window where you can select a word and make it bold. The same edit works in a Rust program without a window. In both cases the plugins define what the editor can do, and the core `Editor` owns the document that changes.

Plugins contribute to EditorConfig. Its schema and commands configure the core Editor, and its views configure the GPUI EditorView. A headless caller or the GPUI view can run commands on the core.

## What belongs to the editor?

A `Document` is an immutable tree. Suppose you type “Hello world” in a paragraph, select “world”, and click **Bold**. The paragraph now reads Hello **world**. Here is the JSON that `Document::to_json()` saves.

```json
{
  "type": "doc",
  "content": [
    {
      "type": "paragraph",
      "content": [
        { "type": "text", "text": "Hello " },
        { "type": "text", "text": "world", "marks": [{ "type": "bold" }] }
      ]
    }
  ]
}
```

Each `content` array holds a node’s children. The root `doc` has one paragraph, and that paragraph has two text nodes because only “world” carries the `bold` mark. The cursor position and undo history belong to the editing session, so two editors can open this JSON and move their selections independently. [Document JSON and Tiptap compatibility](/docs/tiptap/).

The click sends the Bold plugin’s `Toggle` command from `EditorView` to the core. Its handler proposes a `Transaction` that adds the mark. The editor applies the change and records it for Undo. The GPUI view reads the updated document and draws the word in bold. A headless test can call the same command and inspect the mark directly. [Run the headless formatting example](/docs/plugins/#format-a-selection).

## How plugins fit together

The application chooses its features when it builds an `EditorConfig`.

```rust
let config = gpdoc::EditorConfig::builder()
    .plugin(gpdoc_plugin_paragraph::paragraph())
    .plugin(gpdoc_plugin_bold::bold())
    .build()?;
```

Each feature uses `gpdoc-plugin` to declare what it contributes through a `PluginSpec`. Paragraph supplies a default text block. Bold supplies the mark, commands for changing it, and rules for recognizing it as you type or paste. At `.build()`, gpdoc combines the declarations into one `Schema` describing valid documents and checks that shortcuts refer to registered commands.

The `gpdoc` crate exposes this configuration to the app. A headless program can use it with `Editor::from_document`. With GPUI enabled, `EditorConfig::open` wraps a core editor in an `EditorView` and uses the plugins’ views for rendering and interaction. For a feature like Table, the row and cell nodes belong to the schema, inserting a row is an editing command, and laying out the grid is the view’s job. [Explore Table](/docs/plugins/structure/table/).

## Default views and custom compositions

When a plugin declares a default with `gpui_default_view`, registering the plugin **without `with_view`** installs that view automatically in GPUI. For example, a checklist configured with Paragraph, Task List, and `.plugin(task_item())` already shows a clickable checkbox beside each editable task.

To use your own layout, replace that registration with `.plugin(app_task_item)`. Calling `with_view` selects the entire view composition for this task item. The plugin exposes `task_rows` so your replacement can reuse its interactive parts. This is the headless UI pattern familiar from [Radix Primitives](https://www.radix-ui.com/primitives/docs/overview/introduction) and [Base UI](https://base-ui.com/react/overview/quick-start#assemble-a-component).

```rust
use gpdoc::PluginViewExt;
use gpdoc_plugin_task_list::{task_item, task_rows};
use gpui::{div, prelude::*};


let app_task_item = task_item().with_view(|| {
    task_rows(|task, _, _| {
        let label = if task.checked { "Reopen" } else { "Mark done" };
        div().flex()
            .child(div().flex_1().child(task.content))
            .child(task.checkbox.child(label))
    })
});
```

This row puts a labeled control **after** the task text. The app chooses the layout and label. The plugin supplies `task.content`, the editor-owned text, and `task.checkbox`, the click target that updates the document’s `checked` attribute and focuses the editor. The same composition pattern works for a slash menu. The plugin handles filtering and keyboard navigation while the app assembles the popover, list, and rows. [Compose a slash menu](/docs/plugins/behavior/slash-command/#compose-a-slash-menu).

For editing behavior such as a shortcut or typing rule, customize the settings exposed by the plugin with `.extend(...)`. [Build a document plugin](/docs/plugins/custom/first-plugin/) or [render a plugin in GPUI](/docs/plugins/custom/gpui/).