react-smart-copy 1.14.1 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -1
- package/dist/index.cjs +523 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +145 -1
- package/dist/index.d.ts +145 -1
- package/dist/index.js +523 -35
- package/dist/index.js.map +1 -1
- package/dist/link.cjs +2 -2
- package/dist/link.cjs.map +1 -1
- package/dist/link.js +2 -2
- package/dist/link.js.map +1 -1
- package/dist/share.cjs +641 -0
- package/dist/share.cjs.map +1 -0
- package/dist/share.d.cts +248 -0
- package/dist/share.d.ts +248 -0
- package/dist/share.js +638 -0
- package/dist/share.js.map +1 -0
- package/package.json +37 -4
package/README.md
CHANGED
|
@@ -33,6 +33,7 @@ ID PLT-29018 [Copy]
|
|
|
33
33
|
- **`react-smart-copy/code`**: copy code blocks the way developers expect (a terminal session copies as its commands, gutters and prompts stay behind, colours survive in Docs and Slack), paste code cleaned and indented, and catch Trojan Source, invisible identifiers and lookalike letters
|
|
34
34
|
- **`react-smart-copy/image`**: get pasted photos and screenshots ready to upload. It removes GPS location, camera data and hidden thumbnails without touching a pixel, and fits size and byte limits, re-encoding only when it has to
|
|
35
35
|
- **`react-smart-copy/link`**: "Copy link" buttons that paste as a titled link in Slack, Docs and Notion and as the URL in editors, links that scroll to a highlighted passage, tracking parameters removed, and pasting a URL over selected text to make a link
|
|
36
|
+
- **`react-smart-copy/share`**: one "Share" button that opens the share sheet on phones and copies a titled link on desktop, with honest states: a closed share sheet is never an error
|
|
36
37
|
- **`react-smart-copy/capture`**: copy an `<svg>` or any piece of your UI as a PNG
|
|
37
38
|
- Every failure is a typed, classified error. Nothing silently no-ops
|
|
38
39
|
- Unstyled. Works with Tailwind, CSS modules, CSS-in-JS, shadcn, MUI, Ant Design
|
|
@@ -56,6 +57,7 @@ This package only promises what browsers actually support.
|
|
|
56
57
|
| Code (blocks, sessions, diffs) | ✅ | `react-smart-copy/code`: plain text plus monospaced, highlighted HTML; commands without prompts or output; Trojan Source checks on paste |
|
|
57
58
|
| Pasted images, made safe | ✅ paste | `react-smart-copy/image`: removes location and camera metadata losslessly; resizes and compresses under a byte budget |
|
|
58
59
|
| Links (titled, to a passage) | ✅ | `react-smart-copy/link`: a titled `<a>` plus the URL; `text/uri-list` when dragged; text fragment links; never `javascript:` |
|
|
60
|
+
| Share sheet (Web Share API) | ✅ with copy fallback | `react-smart-copy/share`: the share sheet on phones and tablets, a titled link copied elsewhere; files where the share sheet takes them |
|
|
59
61
|
| SVG (icons, charts, logos) | ✅ as PNG | `svgToPngBlob()` from `react-smart-copy/capture` rasterises natively, no dependency. Raw SVG is not a clipboard image format |
|
|
60
62
|
| A section of your UI as an image | ✅ bring a rasteriser | Browsers have no "screenshot this element" API. `captureElement()` wraps one you choose (e.g. `modern-screenshot`) with limits and checks |
|
|
61
63
|
| Files (PDF, DOCX, ZIP) | ❌ | Not writable to the system clipboard by any browser API |
|
|
@@ -932,6 +934,67 @@ usePaste({ accept: ["text", "html", "text/uri-list"], onPaste: (result) => {
|
|
|
932
934
|
| `maxTitleLength` | 300 | |
|
|
933
935
|
| `maxWords` / `contextWords` | 10 / 4 | text fragments |
|
|
934
936
|
|
|
937
|
+
## Share, or copy the link
|
|
938
|
+
|
|
939
|
+
`react-smart-copy/share` is one button that does the right thing on every device: the
|
|
940
|
+
share sheet on phones and tablets, where people expect it, and a copied titled link on
|
|
941
|
+
desktop. `useShare` comes from `react-smart-copy`; without React, use
|
|
942
|
+
`shareOrCopy` from `react-smart-copy/share` (about 4.4 kB).
|
|
943
|
+
|
|
944
|
+
```tsx
|
|
945
|
+
import { useShare } from "react-smart-copy";
|
|
946
|
+
|
|
947
|
+
function ShareButton({ url, title }: { url: string; title: string }) {
|
|
948
|
+
const { share, status, method } = useShare({ clean: true });
|
|
949
|
+
return (
|
|
950
|
+
<button type="button" onClick={() => void share({ url, title })}>
|
|
951
|
+
{status === "copied" ? "Link copied" : status === "shared" ? "Shared" : method === "native" ? "Share…" : "Copy link"}
|
|
952
|
+
</button>
|
|
953
|
+
);
|
|
954
|
+
}
|
|
955
|
+
```
|
|
956
|
+
|
|
957
|
+
**Honest outcomes.** `share()` never rejects. It resolves to `shared`, `copied` (with a
|
|
958
|
+
`reason`: `preferred`, `unsupported` or `fallback`), `cancelled` or `error`. Closing the
|
|
959
|
+
share sheet is `cancelled`, and the status goes back to `idle`: it is not an error, and it
|
|
960
|
+
never triggers a surprise copy. When the share sheet fails for another reason (an iframe
|
|
961
|
+
without the `web-share` permission, content it rejects), the link is copied instead.
|
|
962
|
+
`fallback: false` reports the error instead. `describeShareError(error, method)` gives a
|
|
963
|
+
sentence for each.
|
|
964
|
+
|
|
965
|
+
**Labelled correctly.** `method` says what the button will do, `"native"` or `"copy"`, so
|
|
966
|
+
the label can say "Share…" or "Copy link". It is `"copy"` during server rendering and
|
|
967
|
+
hydration, so there is no mismatch. Then it follows the device, including a tablet that
|
|
968
|
+
gets a keyboard and a mouse.
|
|
969
|
+
|
|
970
|
+
| `mode` | What happens |
|
|
971
|
+
| ------ | ------------ |
|
|
972
|
+
| `"auto"` (default) | the share sheet on touch-first devices (`(hover: none) and (pointer: coarse)`), copy elsewhere |
|
|
973
|
+
| `"native"` | the share sheet wherever the browser has one (also desktop Safari, and Edge and Chrome on Windows and macOS) |
|
|
974
|
+
| `"copy"` | always copy |
|
|
975
|
+
|
|
976
|
+
**What is shared.** `url`, `title`, `text` and `files`. The URL is checked like every link
|
|
977
|
+
in `react-smart-copy/link`: only safe schemes, with credentials removed, and tracking
|
|
978
|
+
parameters removed with `clean: true`. The title is cleaned of hidden characters. Files go
|
|
979
|
+
only to a share sheet that accepts them (`navigator.canShare`); otherwise the link is
|
|
980
|
+
copied. The copy is a titled link (`linkPayload`), or the text when there is no URL.
|
|
981
|
+
`copy` sets your own.
|
|
982
|
+
|
|
983
|
+
Without React, `shareOrCopy(content, options)` resolves to the same outcomes, and
|
|
984
|
+
`shareMethod(options)` says how it would share:
|
|
985
|
+
|
|
986
|
+
```ts
|
|
987
|
+
import { shareOrCopy } from "react-smart-copy/share";
|
|
988
|
+
|
|
989
|
+
button.addEventListener("click", async () => {
|
|
990
|
+
const outcome = await shareOrCopy({ url: location.href, title: document.title });
|
|
991
|
+
if (outcome.status === "copied") toast("Link copied");
|
|
992
|
+
});
|
|
993
|
+
```
|
|
994
|
+
|
|
995
|
+
Call `share()` directly in the click handler. The share sheet needs the click's user
|
|
996
|
+
activation, so don't `await` anything before it.
|
|
997
|
+
|
|
935
998
|
## Only one "Copied" at a time
|
|
936
999
|
|
|
937
1000
|
Wrap a table or list in `<CopyGroup>`. A new successful copy returns the previously copied
|
|
@@ -1383,7 +1446,8 @@ embedded webviews. Where a capability is missing you get a typed error, never a
|
|
|
1383
1446
|
- ~~**1.11** `react-smart-copy/markdown` — paste rich content as Markdown, with undo intact~~ shipped
|
|
1384
1447
|
- ~~**1.12** `react-smart-copy/code` — copy code blocks and sessions cleanly, paste code safely, detect Trojan Source and homoglyphs~~ shipped
|
|
1385
1448
|
- ~~**1.13** `react-smart-copy/image` — pasted images without location or camera metadata, fitted to size and byte limits~~ shipped
|
|
1386
|
-
-
|
|
1449
|
+
- ~~**1.14** `react-smart-copy/link` — links that paste well everywhere, links to a passage, tracking parameters removed, paste a URL over text to make a link~~ shipped
|
|
1450
|
+
- **1.15** `react-smart-copy/share` — the share sheet on phones, a copied titled link everywhere else, with honest outcomes
|
|
1387
1451
|
|
|
1388
1452
|
Full history: [CHANGELOG.md](./CHANGELOG.md) or the [Releases page](https://suprabhat02.github.io/react-smart-copy/#releases).
|
|
1389
1453
|
|