Repository navigation
v1.7.0
Minor Changes
-
8d467d7: Control what native copy puts on the clipboard:
useCopyInterceptorUntil now every copy the library handled started from a button. The copies people make most
often are native: select, then Ctrl/⌘+C, Ctrl/⌘+X or the context menu. Those can now be
rewritten, redacted or blocked inside any element.const { ref } = useCopyInterceptor<HTMLElement>({ transform: ({ text }) => `${text}\n\nSource: ${location.href}`, }); return <article ref={ref}>…</article>;
The transform receives the selection (
text,html, a detachedfragmentsafe to mutate,
thefieldfor inputs, andkind) and returns a string or a text/HTML/JSON/multi payload to
write instead,falseto block the copy, or nothing to leave it alone.- Works everywhere, no prompt. Writes go through the copy event's
clipboardData, so
there is no permission request and no HTTPS requirement. Only strings can be written this
way: image payloads andasynctransforms are compile errors. - Fails closed. A transform that throws or returns something unwritable blocks the copy
and reportsonError, the safe default for redaction.failureMode: "native"lets the
original copy through instead. - Cuts behave like cuts. In inputs and
contenteditable, the selection is still removed
after your content is written, through the browser's editing path (undo works, React sees
input). A blocked cut deletes nothing. - Deterministic overlap. One document listener serves every scope. When a selection
touches several, exactly one handles it: highestpriority, then innermost, then document
order. The winner sees the whole selection, so a high-priority redaction scope masks
content copied across it and its neighbours. - Framework-agnostic core.
registerCopyInterceptor(element, options)and
interceptCopyEvent(event, options)inreact-smart-copy/core;readCopySelection(event)
for custom handlers.
Tree-shaken:
useCopy,usePaste,CopyFieldandPasteFieldare unchanged in size.
useCopyInterceptoron its own is 2.28 kB (min + brotli).Not a security boundary: users can still screenshot or open dev tools. It guards against
accidental copying of sensitive values. - Works everywhere, no prompt. Writes go through the copy event's