Repository navigation
v1.10.0
Minor Changes
-
7a41986: Add
react-smart-copy/structured: typed, versioned, validated application data on the clipboard.defineClipFormat({ id, version, schema, migrate, encode, text, html })defines a format. The schema can be any Standard Schema (Zod, Valibot, ArkType, Effect Schema) or a plain validator function, and the value type is inferred from it.clipPayload(format, value)builds a payload forcopy(), auseCopyInterceptortransform or auseDragCopysource. It carries the data three ways: a web custom format (web application/vnd.<id>+json), a custom clipboard type, and a hidden envelope in the HTML, plus readable text and HTML for other apps. Every browser and paste path gets at least one.readClip(source, format)/readClipSyncread the data from aPasteResult, aDataTransferor a payload, and returnok,absent,invalidorunsupported-version. They never throw for clipboard content.clipAccept(...formats)returns theacceptlist forusePasteandPasteField.- Security: carriers are size-checked before they are parsed (
maxBytes, default 8 MiB), own__proto__keys are dropped, migrations run before the schema validates, and copying rejects valuesJSON.stringifywould silently change (NaN,BigInt,Map,Set, functions).
Core additions, all backward compatible:
multipayload items acceptoptional: true. An optional item is written only whenClipboardItem.supports()confirms its type, and is skipped otherwise instead of failing the copy.- Copy and drag events skip web custom formats, which only the async Clipboard API can write.
acceptaccepts web custom formats ('web application/vnd.acme+json'), and+jsontypes arrive as strings. Wildcards never match either kind, so they must be listed exactly, asimage/svg+xmlalready had to be.- New helpers
normalizeClipboardTypeandisWebCustomFormat.