@usepatch/widget 0.1.0 → 0.2.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 +18 -1
- package/dist/index.cjs +5 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
The embeddable feedback widget for [Patch](https://usepatch.dev). Drop it into your preview deployments and clients can pin comments directly on the page, no account required.
|
|
4
4
|
|
|
5
|
+
Works in any React app: Next.js, Vite, React Router, Astro, and more.
|
|
6
|
+
|
|
5
7
|
## Install
|
|
6
8
|
|
|
7
9
|
```sh
|
|
@@ -29,11 +31,26 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
29
31
|
}
|
|
30
32
|
```
|
|
31
33
|
|
|
34
|
+
In Astro, render it as a client island in your layout:
|
|
35
|
+
|
|
36
|
+
```astro
|
|
37
|
+
---
|
|
38
|
+
import { Patch } from "@usepatch/widget";
|
|
39
|
+
---
|
|
40
|
+
<html>
|
|
41
|
+
<body>
|
|
42
|
+
<slot />
|
|
43
|
+
<Patch client:only="react" />
|
|
44
|
+
</body>
|
|
45
|
+
</html>
|
|
46
|
+
```
|
|
47
|
+
|
|
32
48
|
The widget needs your project token, found in your Patch project settings. It resolves in this order:
|
|
33
49
|
|
|
34
50
|
1. The `projectToken` prop: `<Patch projectToken="pk_..." />`
|
|
35
51
|
2. `NEXT_PUBLIC_PATCH_TOKEN` (Next.js)
|
|
36
|
-
3. `VITE_PATCH_TOKEN` (Vite)
|
|
52
|
+
3. `VITE_PATCH_TOKEN` (Vite / React Router)
|
|
53
|
+
4. `PUBLIC_PATCH_TOKEN` (Astro)
|
|
37
54
|
|
|
38
55
|
Project tokens are publishable keys, safe to expose in client-side code.
|
|
39
56
|
|
package/dist/index.cjs
CHANGED
|
@@ -2073,7 +2073,7 @@ function useWidgetUiStore() {
|
|
|
2073
2073
|
}
|
|
2074
2074
|
|
|
2075
2075
|
// src/env-token-resolver.ts
|
|
2076
|
-
var MESSAGE = "[Patch] No project token found. Pass `projectToken` as a prop, or set NEXT_PUBLIC_PATCH_TOKEN (Next.js)
|
|
2076
|
+
var MESSAGE = "[Patch] No project token found. Pass `projectToken` as a prop, or set NEXT_PUBLIC_PATCH_TOKEN (Next.js), VITE_PATCH_TOKEN (Vite / React Router), or PUBLIC_PATCH_TOKEN (Astro) in your env.";
|
|
2077
2077
|
function resolveProjectToken(input) {
|
|
2078
2078
|
const fromProp = input.prop?.trim();
|
|
2079
2079
|
if (fromProp) return fromProp;
|
|
@@ -2081,6 +2081,8 @@ function resolveProjectToken(input) {
|
|
|
2081
2081
|
if (fromNext) return fromNext;
|
|
2082
2082
|
const fromVite = input.importMetaEnv?.VITE_PATCH_TOKEN?.trim();
|
|
2083
2083
|
if (fromVite) return fromVite;
|
|
2084
|
+
const fromAstro = input.importMetaEnv?.PUBLIC_PATCH_TOKEN?.trim();
|
|
2085
|
+
if (fromAstro) return fromAstro;
|
|
2084
2086
|
throw new Error(MESSAGE);
|
|
2085
2087
|
}
|
|
2086
2088
|
function readImportMetaEnv() {
|
|
@@ -2171,7 +2173,8 @@ function splitAvatarValue(value) {
|
|
|
2171
2173
|
if (value.startsWith(AVATAR_SEED_PREFIX)) {
|
|
2172
2174
|
return { url: null, seed: value.slice(AVATAR_SEED_PREFIX.length) || null };
|
|
2173
2175
|
}
|
|
2174
|
-
return { url: value, seed: null };
|
|
2176
|
+
if (/^https?:\/\//i.test(value)) return { url: value, seed: null };
|
|
2177
|
+
return { url: null, seed: value };
|
|
2175
2178
|
}
|
|
2176
2179
|
|
|
2177
2180
|
// ../shared/src/client-avatars.ts
|