react-sharesheet 1.9.1 → 1.10.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 +48 -13
- package/dist/content.d.mts +3 -3
- package/dist/content.d.ts +3 -3
- package/dist/content.js +12 -5
- package/dist/content.js.map +1 -1
- package/dist/content.mjs +11 -5
- package/dist/content.mjs.map +1 -1
- package/dist/drawer.d.mts +3 -3
- package/dist/drawer.d.ts +3 -3
- package/dist/drawer.js +14 -5
- package/dist/drawer.js.map +1 -1
- package/dist/drawer.mjs +13 -5
- package/dist/drawer.mjs.map +1 -1
- package/dist/{headless-lxSw27f0.d.ts → headless-CEUr7QJE.d.ts} +5 -14
- package/dist/{headless-x5iUF86E.d.mts → headless-JYVQPj9Q.d.mts} +5 -14
- package/dist/headless.d.mts +2 -2
- package/dist/headless.d.ts +2 -2
- package/dist/headless.js +6 -2
- package/dist/headless.js.map +1 -1
- package/dist/headless.mjs +7 -3
- package/dist/headless.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +10 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -4
- package/dist/index.mjs.map +1 -1
- package/dist/{platforms-BtmTZmgl.d.mts → platforms-B1VXTDkO.d.mts} +20 -2
- package/dist/{platforms-BtmTZmgl.d.ts → platforms-B1VXTDkO.d.ts} +20 -2
- package/package.json +2 -2
- package/src/ShareSheetContent.tsx +4 -2
- package/src/ShareSheetDrawer.tsx +2 -0
- package/src/__tests__/preview-fetch.test.tsx +82 -0
- package/src/content.ts +1 -0
- package/src/drawer.ts +1 -0
- package/src/headless.ts +1 -1
- package/src/hooks.ts +12 -5
- package/src/index.ts +1 -1
- package/src/og-fetcher.ts +6 -1
- package/src/types.ts +8 -1
package/src/content.ts
CHANGED
|
@@ -2,3 +2,4 @@ export { ShareSheetContent, ShareMenuContent } from "./ShareSheetContent";
|
|
|
2
2
|
export type { ShareSheetContentProps, ShareSheetContentClassNames, ShareMenuContentProps, ShareMenuContentClassNames, ShareOption } from "./types";
|
|
3
3
|
export { CSS_VARS_UI, CSS_VAR_UI_DEFAULTS, CSS_VARS, CSS_VAR_DEFAULTS } from "./types";
|
|
4
4
|
export { PLATFORM_COLORS, PLATFORM_CSS_VARS } from "./platforms";
|
|
5
|
+
export { fetchOGData, type OGData, type OGFetcher } from "./og-fetcher";
|
package/src/drawer.ts
CHANGED
|
@@ -2,3 +2,4 @@ export { ShareSheetDrawer, ShareMenuDrawer } from "./ShareSheetDrawer";
|
|
|
2
2
|
export type { ShareSheetDrawerProps, ShareSheetDrawerClassNames, ShareMenuDrawerProps, ShareMenuDrawerClassNames, ShareOption } from "./types";
|
|
3
3
|
export { CSS_VARS_UI, CSS_VAR_UI_DEFAULTS, CSS_VARS, CSS_VAR_DEFAULTS } from "./types";
|
|
4
4
|
export { PLATFORM_COLORS, PLATFORM_CSS_VARS } from "./platforms";
|
|
5
|
+
export { fetchOGData, type OGData, type OGFetcher } from "./og-fetcher";
|
package/src/headless.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
export { useShareSheet, useShareMenu, useOGData, type UseShareSheetOptions, type UseShareMenuOptions } from "./hooks";
|
|
4
4
|
|
|
5
5
|
// OG Data fetcher
|
|
6
|
-
export { fetchOGData, clearOGCache, type OGData } from "./og-fetcher";
|
|
6
|
+
export { fetchOGData, clearOGCache, type OGData, type OGFetcher } from "./og-fetcher";
|
|
7
7
|
|
|
8
8
|
export {
|
|
9
9
|
shareToWhatsApp,
|
package/src/hooks.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { useMemo, useState, useCallback, useEffect } from "react";
|
|
3
|
+
import { useMemo, useState, useCallback, useEffect, useRef } from "react";
|
|
4
4
|
import { getSafeUrl, isMobileDevice, getAllPlatformAvailability } from "./utils";
|
|
5
|
-
import { fetchOGData, type OGData } from "./og-fetcher";
|
|
5
|
+
import { fetchOGData, type OGData, type OGFetcher } from "./og-fetcher";
|
|
6
6
|
import {
|
|
7
7
|
shareToWhatsApp,
|
|
8
8
|
shareToTelegram,
|
|
@@ -279,9 +279,10 @@ export function useShareSheet({
|
|
|
279
279
|
|
|
280
280
|
/**
|
|
281
281
|
* Hook to fetch OG (Open Graph) data from a URL.
|
|
282
|
-
*
|
|
282
|
+
* Fetches with `fetcher`, the Microlink lookup (`fetchOGData`, cached) unless another is given:
|
|
283
|
+
* calling this hook is the opt-in, since the lookup sends `url` to a third party.
|
|
283
284
|
*/
|
|
284
|
-
export function useOGData(url: string | undefined): {
|
|
285
|
+
export function useOGData(url: string | undefined, fetcher: OGFetcher = fetchOGData): {
|
|
285
286
|
ogData: OGData | null;
|
|
286
287
|
loading: boolean;
|
|
287
288
|
error: string | null;
|
|
@@ -289,6 +290,12 @@ export function useOGData(url: string | undefined): {
|
|
|
289
290
|
const [ogData, setOgData] = useState<OGData | null>(null);
|
|
290
291
|
const [loading, setLoading] = useState(false);
|
|
291
292
|
const [error, setError] = useState<string | null>(null);
|
|
293
|
+
// Read at fetch time, so an inline fetcher does not refetch on every render
|
|
294
|
+
// (this effect runs before the one below in the same commit)
|
|
295
|
+
const fetcherRef = useRef(fetcher);
|
|
296
|
+
useEffect(() => {
|
|
297
|
+
fetcherRef.current = fetcher;
|
|
298
|
+
});
|
|
292
299
|
|
|
293
300
|
useEffect(() => {
|
|
294
301
|
if (!url) {
|
|
@@ -302,7 +309,7 @@ export function useOGData(url: string | undefined): {
|
|
|
302
309
|
setLoading(true);
|
|
303
310
|
setError(null);
|
|
304
311
|
|
|
305
|
-
|
|
312
|
+
fetcherRef.current(url)
|
|
306
313
|
.then((data) => {
|
|
307
314
|
if (!cancelled) {
|
|
308
315
|
setOgData(data);
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { ShareSheetDrawer, ShareMenuDrawer } from "./ShareSheetDrawer";
|
|
|
6
6
|
export { useShareSheet, useShareMenu, useOGData, type UseShareSheetOptions, type UseShareMenuOptions } from "./hooks";
|
|
7
7
|
|
|
8
8
|
// OG Data fetcher
|
|
9
|
-
export { fetchOGData, clearOGCache, type OGData } from "./og-fetcher";
|
|
9
|
+
export { fetchOGData, clearOGCache, type OGData, type OGFetcher } from "./og-fetcher";
|
|
10
10
|
|
|
11
11
|
// Types
|
|
12
12
|
export type {
|
package/src/og-fetcher.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
// OG
|
|
1
|
+
// OG data fetcher using the Microlink API (free, no API key required).
|
|
2
|
+
// The sheet never calls it on its own: a caller opts in with `fetchPreview={fetchOGData}`,
|
|
3
|
+
// because the lookup sends the shared link to a third party.
|
|
2
4
|
|
|
3
5
|
export interface OGData {
|
|
4
6
|
title?: string;
|
|
@@ -8,6 +10,9 @@ export interface OGData {
|
|
|
8
10
|
siteName?: string;
|
|
9
11
|
}
|
|
10
12
|
|
|
13
|
+
/** Looks up a link's card. Resolves to null when there is none. */
|
|
14
|
+
export type OGFetcher = (url: string) => Promise<OGData | null>;
|
|
15
|
+
|
|
11
16
|
export interface OGFetchResult {
|
|
12
17
|
data: OGData | null;
|
|
13
18
|
loading: boolean;
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
+
import type { OGFetcher } from "./og-fetcher";
|
|
2
3
|
|
|
3
4
|
/** CSS variable names for UI elements (non-platform specific) */
|
|
4
5
|
export const CSS_VARS_UI = {
|
|
@@ -100,7 +101,7 @@ export interface ShareSheetDrawerClassNames extends ShareSheetContentClassNames
|
|
|
100
101
|
export interface ShareSheetContentProps {
|
|
101
102
|
/** Title displayed at the top of the sheet */
|
|
102
103
|
title?: string;
|
|
103
|
-
/** URL to share
|
|
104
|
+
/** URL to share */
|
|
104
105
|
shareUrl: string;
|
|
105
106
|
/** Text to share alongside the URL */
|
|
106
107
|
shareText: string;
|
|
@@ -110,6 +111,12 @@ export interface ShareSheetContentProps {
|
|
|
110
111
|
downloadFilename?: string;
|
|
111
112
|
/** Custom preview image URL (skips OG fetching if provided) */
|
|
112
113
|
previewImage?: string | null;
|
|
114
|
+
/**
|
|
115
|
+
* Looks up the link's card when there is no `previewImage`. Unset (the default), no request
|
|
116
|
+
* leaves the page and the sheet shows a link placeholder. Pass `fetchOGData` for the Microlink
|
|
117
|
+
* lookup the sheet made by itself before 1.10.0: it sends `shareUrl` to api.microlink.io.
|
|
118
|
+
*/
|
|
119
|
+
fetchPreview?: OGFetcher;
|
|
113
120
|
/** File to share via native share (data URL or Blob) - takes priority over URL sharing */
|
|
114
121
|
shareFile?: string | Blob | null;
|
|
115
122
|
/** Filename for the shared file */
|