

<Callout type="warning" title="Deprecated">
  `Document` is deprecated. Use [`Editor`](/components/editor) for new document
  rendering, editing, and comment workflows.
</Callout>

## Overview [#overview]

Document renders markdown, HTML, or TipTap JSON through a shared read-only viewer. Feature providers such as `Document.Annotatable` add focused behavior around that viewer while leaving document data, persistence, and backend sync with the consumer.

## Usage [#usage]

```tsx
import {
  Document,
  type AnnotatableProps,
  type AnnotationData,
  type DocumentContentType,
  type DocumentProps,
  useAnnotatable,
  useHasSelection,
} from "@tilt-legal/cubitt-components/document";
```

```tsx
<Document content={markdownContent}>
  <Document.Viewer />
</Document>
```

```tsx
<Document content={markdownContent}>
  <Document.Annotatable
    annotations={annotations}
    onAnnotationCreate={handleCreate}
    onAnnotationUpdate={handleUpdate}
    onAnnotationDelete={handleDelete}
  >
    <Document.Viewer />
    <Document.Annotation.Sidebar />
    <Document.Toolbar.Selection>
      <Document.Annotation.AddButton />
    </Document.Toolbar.Selection>
  </Document.Annotatable>
</Document>
```

```tsx
<Document content={markdownContent}>
  <Document.Annotatable
    annotations={annotations}
    onAnnotationCreate={handleCreate}
    onAnnotationUpdate={handleUpdate}
    onAnnotationDelete={handleDelete}
  >
    <Document.Viewer />
    <Document.Annotation.Sidebar>
      <Document.Annotation.Sidebar.Header />
      <Document.Annotation.Sidebar.List>
        {annotations.map((annotation) => (
          <Document.Annotation.Sidebar.Card
            annotation={annotation}
            key={annotation.id}
          />
        ))}
      </Document.Annotation.Sidebar.List>
      <Document.Annotation.Sidebar.Empty />
    </Document.Annotation.Sidebar>
  </Document.Annotatable>
</Document>
```

## Examples [#examples]

### Viewer [#viewer]

<Tabs items="['Preview', 'Code']">
  <Tab value="Preview">
    <Preview name="DocumentViewerExample" />
  </Tab>

  <Tab value="Code">
    ```tsx
    <Document content={markdownContent}>
      <Document.Viewer />
    </Document>
    ```
  </Tab>
</Tabs>

### Annotated Sidebar [#annotated-sidebar]

<Tabs items="['Preview', 'Code']">
  <Tab value="Preview">
    <Preview name="DocumentAnnotatedSidebarExample" />
  </Tab>

  <Tab value="Code">
    ```tsx
    <Document content={markdownContent}>
      <Document.Annotatable
        annotations={annotations}
        onAnnotationCreate={handleCreate}
        onAnnotationUpdate={handleUpdate}
        onAnnotationDelete={handleDelete}
      >
        <Document.Viewer />
        <Document.Annotation.Sidebar />
        <Document.Toolbar.Selection>
          <Document.Annotation.AddButton />
        </Document.Toolbar.Selection>
      </Document.Annotatable>
    </Document>
    ```
  </Tab>
</Tabs>

## Architecture [#architecture]

```text
Document
├── Document.Viewer
├── Document.Toolbar.Selection
├── Document.Annotatable
│   └── Document.Annotation.*
└── Document.Editable (future)
```

### Namespaces [#namespaces]

| Namespace               | Components                                     |
| ----------------------- | ---------------------------------------------- |
| `Document.Toolbar.*`    | `Selection`                                    |
| `Document.Annotation.*` | `Sidebar`, `AddButton`, hooks                  |
| `Sidebar.*`             | `Header`, `List`, `Empty`, `Card`              |
| `Sidebar.Card.*`        | `Header`, `Textarea`, `Citation`, `Menu`, more |

## Props [#props]

### Document [#document]

| Prop            | Type                             | Default      | Description                         |
| --------------- | -------------------------------- | ------------ | ----------------------------------- |
| `content`       | `string \| JSONContent`          | -            | Document content                    |
| `contentType`   | `"markdown" \| "html" \| "json"` | `"markdown"` | Format of the content               |
| `extensions`    | `Extension[]`                    | -            | Additional TipTap extensions        |
| `editorOptions` | `Partial<EditorOptions>`         | -            | TipTap editor options               |
| `className`     | `string`                         | -            | Layout class for the root container |

### Document.Viewer [#documentviewer]

| Prop        | Type     | Description                 |
| ----------- | -------- | --------------------------- |
| `className` | `string` | Layout class for the viewer |
