Smart Paste

Pro

A button that fills a form from text on the clipboard — an email signature, a contact card, a support ticket, a `Label: value` list. A resolver maps the text to field values (your AI gateway behind your own endpoint, or the built-in reader that runs on the device), and the answer is checked and typed against your field list before `(filled)` emits it: unknown keys dropped, numbers, booleans and dates coerced, select values held to their options.

</>sv-smart-paste smart pasteaiclipboardautofillform fillextractpastellmresolvercontact
import { SvSmartPasteComponent } from '@styloviz-pro/forms/smart-paste';

Demo & usage

Basic usage

Pro

Usage example — open the gallery for the full interactive demo.

Pro

An interactive demo for this component lives in the gallery.

Open live demo

More examples

Signal Forms — one update fills the form

Pro

Describe the fields once; the result is keyed by `name` and already typed (a number for `number`, `YYYY-MM-DD` for `date`, `true`/`false` for `boolean`), so it spreads straight into the model. `missing` lists required fields nothing filled.

Your AI gateway, behind your own endpoint

Pro

`svSmartPasteFetchResolver` POSTs `{ text, fields }` to the URL you give it (relative or http(s) only), reads `{ values }` back, and passes the abort signal, so Cancel stops the request. Keep the model key on the server.

A resolver of your own

Pro

Any `({ text, fields, signal }) => Promise<Record<string, unknown>>`. Its answer may be sloppy — the component coerces it, and `svSmartPasteCoerce` is exported so a server can reach the same verdict.

When to use

  • People retype details they already have in front of them — a lead from an email signature, a customer from a support ticket, an address from a chat.
  • You have, or plan, an AI gateway and want its output checked against the form before anything is filled.
  • For many records at once use the Import Wizard; for one value use the field itself.

Compare with

  • Import Wizard — Import Wizard brings in many records from a CSV. Smart Paste fills ONE form from a scrap of free text.
  • Smart Textarea — Smart Textarea helps write text. Smart Paste reads text someone already has and turns it into field values.

Async states

None — this component has nothing to load, so it has no loading, empty or error state to drive.

Inputs

NameTypeDefaultDescription
fieldsreadonly SvSmartPasteField[][]The fields to fill: `{ name, label, type?, description?, options?, required?, aliases? }`. Entries with an empty or repeated `name` are ignored; with none, the button is disabled.
resolverSvSmartPasteResolver | nullnullMaps the text to values: `({ text, fields, signal }) => Promise<Record<string, unknown>>`. `null` uses the on-device heuristic resolver. The result is validated and coerced before `(filled)`. The text is sent wherever this sends it.
disabledbooleanfalseDisable the button (and `pasteText()`).
sizeSvSmartPasteSize'md'Button size.
variantSvSmartPasteVariant'outline'Button treatment.
maxLengthnumber10_000The most characters of pasted text accepted; longer text fails with `TOO_LONG` and is not sent.
confirmbooleanfalseShow the mapped values with Apply / Discard before emitting `(filled)`.
labelsPartial<SvSmartPasteLabels>{}Per-instance text, merged over the registry's `formsPro` labels.

Outputs

EventPayload typeDescription
filledSvSmartPasteResultCoerced values to apply: `{ values, skipped, missing, text }`. Emitted after Apply when `confirm` is on.
failedSvDataErrorThe resolver failed or the text was refused (`code: 'TOO_LONG'`); the message is also shown with Try again when retryable.
pastingboolean`true` when a resolve starts, `false` when it ends — done, failed or cancelled.

Customization & theming

  • `fields` (`{ name, label, type?, description?, options?, required?, aliases? }`; types `text` `email` `phone` `number` `date` `select` `boolean` `textarea`), `resolver`, `confirm`, `maxLength` (default 10,000; longer text fails with `TOO_LONG` and is not sent), `disabled`.
  • `size` (`sm` / `md` / `lg`) and `variant` (`primary` / `secondary` / `outline` / `ghost`) follow `sv-button`.
  • Outputs: `filled`, `failed` (an `SvDataError`), `pasting` (true / false). Methods: `pasteText(text)` for a paste source of your own, `cancel()`.
  • Every visible and spoken string is a `smartPaste…` label in the `formsPro` namespace, in 12 language packs; `labels` overrides them per instance.

Forms integration

  • sv-smart-paste — Output-driven, not a ControlValueAccessor. It fills many fields at once, not one value: `(filled)` carries `{ values, skipped, missing, text }` keyed by your field names — apply it with `model.update(v => ({ ...v, ...e.values }))` (Signal Forms) or `form.patchValue(e.values)` (reactive forms).

Best practices

  • Do: Turn on `confirm` when the resolver is a model: the user sees what will be filled, and what was left out and why, before the form changes.
  • Do: Give each field a `description` and `aliases` — a model reads the description, the on-device reader matches the aliases ("Mobile", "E-mail").
  • Don't: Don’t put a model API key in a resolver that runs in the browser. Post to your own endpoint with `svSmartPasteFetchResolver` and call the model there.
  • Tip: Without a `resolver` the built-in reader runs on the device and nothing is sent — a useful default, and a fallback when the gateway is down.

Accessibility

  • A native `<button>`; while resolving it carries `aria-busy` and becomes Cancel, so the request can always be stopped from the keyboard.
  • Where the browser will not share the clipboard, a labelled textarea opens in place (`aria-expanded` / `aria-controls` on the button) and takes focus; pasting into it fills at once, Ctrl/⌘+Enter fills what was typed, Escape closes it and returns focus.
  • The confirm preview is a labelled section that takes focus, lists values as a description list and skipped values with their reason; Escape discards.
  • The outcome is spoken through the live announcer — “Filled 4 fields, 1 skipped.” — and failures show in an error shell with Try again.

Feedback on Smart Paste

Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.

Loads giscus.app and GitHub — nothing is fetched until you click.