# @salmonui/chat/smart-paste API reference

> 8 exported symbols of @salmonui/chat/smart-paste: 1 function, 6 interfaces and 1 type.

Canonical: https://salmonui.dev/docs/reference/chat/smart-paste

```ts
import { … } from '@salmonui/chat/smart-paste';
```

## Functions

### useSmartPaste

Kind: function

Page: https://salmonui.dev/docs/reference/chat/smart-paste/useSmartPaste

```ts
function useSmartPaste(formRef: RefObject<HTMLElement | null>, adapter: SmartPasteAdapter, options?: SmartPasteOptions): SmartPaste;
```

Smart paste for the form (or any container) behind `formRef`: pair it with
any `Button` (`onClick={() => paste()}`, `aria-busy={pending}`).

## Interfaces

### SmartPaste

Kind: interface

Page: https://salmonui.dev/docs/reference/chat/smart-paste/SmartPaste

```ts
interface SmartPaste {
    readonly paste: (text?: string) => Promise<SmartPasteResult>;
    readonly pending: boolean;
}
```

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `paste` | `readonly paste: (text?: string) => Promise<SmartPasteResult>;` |  | Without an argument reads `navigator.clipboard.readText()` (call it from the click handler, inside the user gesture); with `text` uses that text. Rejects with the adapter's error, the clipboard error, or an `AbortError` when a newer paste or unmount aborted it. |
| `pending` | `readonly pending: boolean;` |  | True while a paste waits for the clipboard or the adapter. |

### SmartPasteCustomField

Kind: interface

Page: https://salmonui.dev/docs/reference/chat/smart-paste/SmartPasteCustomField

```ts
interface SmartPasteCustomField extends SmartPasteField {
    readonly fill: (value: unknown) => boolean | void;
}
```

A field the hook cannot reach as a native control (for example a Salmon `Select`): described and filled by the application.

Members (7):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `fill` | `readonly fill: (value: unknown) => boolean \| void;` |  | Applies the adapter's value; return `false` when it does not fit, so the field is reported as skipped. |
| `name` | `name: string;` | inherited | The field's `name` (or `id` when it has no name); the key of the adapter's answer. |
| `label` | `label?: string;` | optional, inherited | Text of the associated `<label>`, `aria-labelledby`, `aria-label` or group `<legend>`. |
| `description` | `description?: string;` | optional, inherited | `data-salmon-paste-description`, else the `aria-describedby` text (the Field description). |
| `type` | `type: string;` | inherited | Input `type`, or `'textarea'`, `'select'`, `'checkbox'`, `'radio'`, or the custom field's type. |
| `options` | `options?: readonly string[];` | optional, inherited | Allowed values: `<option>` values, radio values, or the values of a checkbox group. |
| `multiple` | `multiple?: boolean;` | optional, inherited | A multiple `<select>` or a checkbox group: the answer is an array. |

### SmartPasteField

Kind: interface

Page: https://salmonui.dev/docs/reference/chat/smart-paste/SmartPasteField

```ts
interface SmartPasteField {
    readonly name: string;
    readonly label?: string;
    readonly description?: string;
    readonly type: string;
    readonly options?: readonly string[];
    readonly multiple?: boolean;
}
```

What the adapter learns about one field.

Members (6):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `name` | `readonly name: string;` |  | The field's `name` (or `id` when it has no name); the key of the adapter's answer. |
| `label` | `readonly label?: string;` | optional | Text of the associated `<label>`, `aria-labelledby`, `aria-label` or group `<legend>`. |
| `description` | `readonly description?: string;` | optional | `data-salmon-paste-description`, else the `aria-describedby` text (the Field description). |
| `type` | `readonly type: string;` |  | Input `type`, or `'textarea'`, `'select'`, `'checkbox'`, `'radio'`, or the custom field's type. |
| `options` | `readonly options?: readonly string[];` | optional | Allowed values: `<option>` values, radio values, or the values of a checkbox group. |
| `multiple` | `readonly multiple?: boolean;` | optional | A multiple `<select>` or a checkbox group: the answer is an array. |

### SmartPasteOptions

Kind: interface

Page: https://salmonui.dev/docs/reference/chat/smart-paste/SmartPasteOptions

```ts
interface SmartPasteOptions {
    readonly fields?: readonly SmartPasteCustomField[] | undefined;
}
```

Members (1):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `fields` | `readonly fields?: readonly SmartPasteCustomField[] \| undefined;` | optional | Fields that are not native controls (a Salmon `Select`, `Combobox`, `DatePicker`): described to the adapter and filled by `fill`. |

### SmartPasteRequest

Kind: interface

Page: https://salmonui.dev/docs/reference/chat/smart-paste/SmartPasteRequest

```ts
interface SmartPasteRequest {
    readonly clipboardText: string;
    readonly fields: readonly SmartPasteField[];
}
```

What the adapter receives: the pasted text and the field descriptors, never other page data.

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `clipboardText` | `readonly clipboardText: string;` |  |  |
| `fields` | `readonly fields: readonly SmartPasteField[];` |  |  |

### SmartPasteResult

Kind: interface

Page: https://salmonui.dev/docs/reference/chat/smart-paste/SmartPasteResult

```ts
interface SmartPasteResult {
    readonly filled: readonly string[];
    readonly skipped: readonly string[];
}
```

Field names filled, and the described fields the answer did not fill.

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `filled` | `readonly filled: readonly string[];` |  |  |
| `skipped` | `readonly skipped: readonly string[];` |  |  |

## Types

### SmartPasteAdapter

Kind: type

Page: https://salmonui.dev/docs/reference/chat/smart-paste/SmartPasteAdapter

```ts
type SmartPasteAdapter = (request: SmartPasteRequest, init: {
    readonly signal: AbortSignal;
}) => Promise<string | Readonly<Record<string, unknown>>>;
```

Returns a JSON object keyed by field name, or JSON text of one.
