Repository navigation
v1.2.0
Minor Changes
-
Paste retry, cancellation and
PasteField.Preview.- New: paste
retry().usePasteandcreatePasteMachinegainretry(),canRetryand amaxRetriesoption (default 3), matching the copy side. After a retryable failure of the Paste button (permission denied, page not focused, timeout),retry()reads the clipboard again; past the cap it fails withmax-retries-exceeded. Keyboard-paste failures reportnot-retryable, because the event's data is gone once it has been handled.canRetryPasteState()is exported for vanilla use, andPasteField.Triggerrender props now includecanRetry. - New: cancellation. Every copy and paste gets an
AbortSignalthat fires onreset(), on unmount, or when a newer paste supersedes it, and never after the operation has finished. Late results were already ignored; now the work itself stops. Lazy image sources and custom adapters receive it as an optional last argument (OperationContext),captureSource/captureImagestop rasterising (combined with anysignalyou pass, without leaking listeners on browsers lackingAbortSignal.any), and the browser paste adapter stops reading further clipboard items. Existing adapters and sources keep working unchanged. - Changed: cancelled operations resolve
{ status: 'ignored', reason: 'cancelled' }. If a copy or paste fails after you cancelled it (reset, unmount, superseded), the promise you awaited now resolvesignored/cancelledinstead oferror, andonErroris not called. Code that shows a toast forstatus === 'error'no longer reports failures for work the user walked away from. - New:
PasteField.Preview. Shows what was pasted: text (truncated atmaxTextLength), image thumbnails withimageAlttext, and non-image file names. It never renders pasted HTML. Object URLs are revoked when the result changes and on unmount. Pass a function child to render{ result, imageUrls }yourself, andplaceholderfor the empty state. - Fix:
useCopy().canRetrynow readsmaxRetriesfrom the effective options, the same ones the machine uses. - Docs: the README's
PasteFieldexample passedonPastetoPasteField.Root, which has no such prop. It now goes inpasteOptions. - Tests: 398 at 100% coverage, including StrictMode runs of
CopyGroupandPasteField.Preview, and type-level tests for the paste API. - Size (brotli):
PasteFieldwithPreview6.18 kB (was 5.40),usePaste3.59 kB (was 3.16),useCopy3.37 kB (was 3.22),CopyField+CopyGroup5.51 kB (was 5.37), core 5.66 kB (was 5.47), capture 3.54 kB (was 3.41).
Heads-up for TypeScript users. All changes are additive, but if you build these types by hand (for example in test mocks), you'll need the new members:
PasteErrorStategainssourceandretryCountPasteMachinegainsretry;UsePasteResult(and soPasteFieldContextValue) gainsretryandcanRetryPasteFieldTriggerRenderPropsgainscanRetryPasteIgnoredReasongains'nothing-to-retry','not-retryable'and'cancelled';CopyIgnoredReasongains'cancelled'. An exhaustiveswitchover ignored reasons needs the new cases.
- New: paste