Repository navigation
v1.3.0
Minor Changes
-
a2f4b7a: Lifecycle callbacks, consistent
maxBytes, andPasteResult.imageFiles.-
New:
onCancel(reason).useCopy,usePaste,createCopyMachineandcreatePasteMachineacceptonCancel, called once when an in-flight operation is cancelled:'reset','disconnect'(unmount), or for paste'superseded'(a paste event replaced a Clipboard API read). It is not called when nothing was in flight, so React Strict Mode's extra mount/unmount is silent. The newCopyCancelReasonandPasteCancelReasontypes are exported. (The callback is namedonCancelrather thanonReleaseso it isn't confused withCopyGroup's internal hand-off.) -
New:
onReset(). Called whenreset()moves a copy or paste out of a non-idle state. Whenreset()cancels work,onCancel('reset')runs first, thenonReset(). It is not called for the automaticresetAfterMstimer or aCopyGrouphand-off. -
New:
PasteResult.imageFiles. These are the entries offilesthat were verified as images. They keep their file names (retyped from their bytes when needed) and can go straight intoFormData. Clipboard API image blobs, which have no names, stay inimagesonly. The paste machine derivesimageFilesfrom every adapter's result, so the field is always consistent. -
Changed:
maxBytescounts UTF-8 bytes on every paste path. Before this release, paste events andreadText()measured strings in UTF-16 code units, whilenavigator.clipboard.read()chargedBlob.size. The same text could therefore pass on one path and fail on another. Strings are now measured as they would be encoded, without allocating a copy. Non-ASCII text counts more than before:'日本'is 6 bytes, not 2. If you set a tightmaxBytesfor CJK or emoji-heavy content, check your limit. -
Changed: if a custom adapter (typically untyped JavaScript) resolves a result without
imagesorfiles, the paste now ends in anerrorstate. Before, the incomplete object was stored as a successful read. -
Tests: 427 at 100% coverage, including type-level tests for the new API.
-
Size (brotli):
Bundle 1.3.0 1.2.0 useCopy3.42 kB 3.37 kB usePaste3.79 kB 3.59 kB PasteField6.37 kB 6.18 kB CopyField+CopyGroup5.55 kB 5.51 kB core 5.86 kB 5.66 kB capture 3.54 kB unchanged
Heads-up for TypeScript users. No runtime behaviour you rely on is removed, but:
- Building results by hand.
PasteResultgains a requiredimageFiles. If you buildPasteResultobjects by hand, for example in test mocks oronPastefixtures, addimageFiles: []. - Custom adapters.
PasteAdapter.read()now resolvesPasteReadResult, which isPasteResultwithoutimageFiles. Existing adapters that return a fullPasteResultkeep compiling. - Reading adapters directly. If you store
createBrowserPasteAdapter().read()in a variable typedPasteResult, change it toPasteReadResult. - Options types.
UseCopyOptions,UsePasteOptionsand the machine options gain the optionalonResetandonCancel.
-