sanity-plugin-seo-copilot 0.1.0 → 0.1.2
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 +50 -50
- package/dist/index.js +77 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +56 -56
- package/sanity.json +3 -3
- package/src/components/FeedbackButton.tsx +213 -208
- package/src/components/KeywordPanel.tsx +1173 -1165
- package/src/hooks/useKeywordAnalysis.ts +226 -225
- package/src/hooks/useSEOChat.ts +178 -169
- package/v2-incompatible.js +10 -10
package/package.json
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "sanity-plugin-seo-copilot",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "AI-powered SEO writing assistant for Sanity Studio",
|
|
5
|
-
"keywords": ["sanity", "sanity-plugin", "seo", "copilot"],
|
|
6
|
-
"license": "UNLICENSED",
|
|
7
|
-
"author": "MJH Life Sciences",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"source": "./src/index.ts",
|
|
11
|
-
"import": "./dist/index.mjs",
|
|
12
|
-
"require": "./dist/index.js",
|
|
13
|
-
"default": "./dist/index.js"
|
|
14
|
-
},
|
|
15
|
-
"./package.json": "./package.json"
|
|
16
|
-
},
|
|
17
|
-
"main": "./dist/index.js",
|
|
18
|
-
"module": "./dist/index.mjs",
|
|
19
|
-
"types": "./dist/index.d.ts",
|
|
20
|
-
"files": [
|
|
21
|
-
"dist",
|
|
22
|
-
"sanity.json",
|
|
23
|
-
"src",
|
|
24
|
-
"v2-incompatible.js"
|
|
25
|
-
],
|
|
26
|
-
"scripts": {
|
|
27
|
-
"build": "tsup",
|
|
28
|
-
"prepublishOnly": "npm run build"
|
|
29
|
-
},
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"react-markdown": "^10.1.0",
|
|
32
|
-
"remark-gfm": "^4.0.1"
|
|
33
|
-
},
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
"@sanity/icons": "^3.7.4",
|
|
36
|
-
"@sanity/ui": "^3.1.13",
|
|
37
|
-
"@types/react": "^19.0.0",
|
|
38
|
-
"@types/react-dom": "^19.2.3",
|
|
39
|
-
"react": "^19.2.4",
|
|
40
|
-
"react-dom": "^19.2.4",
|
|
41
|
-
"sanity": "^5.13.0",
|
|
42
|
-
"styled-components": "^6.3.11",
|
|
43
|
-
"tsup": "^8.0.0",
|
|
44
|
-
"typescript": "^5.9.3"
|
|
45
|
-
},
|
|
46
|
-
"peerDependencies": {
|
|
47
|
-
"@sanity/icons": "^3.0.0",
|
|
48
|
-
"@sanity/ui": "^2.0.0",
|
|
49
|
-
"react": "^18.0.0 || ^19.0.0",
|
|
50
|
-
"sanity": "^3.0.0",
|
|
51
|
-
"styled-components": "^6.0.0"
|
|
52
|
-
},
|
|
53
|
-
"engines": {
|
|
54
|
-
"node": ">=18"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "sanity-plugin-seo-copilot",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "AI-powered SEO writing assistant for Sanity Studio",
|
|
5
|
+
"keywords": ["sanity", "sanity-plugin", "seo", "copilot"],
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"author": "MJH Life Sciences",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"source": "./src/index.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"module": "./dist/index.mjs",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"sanity.json",
|
|
23
|
+
"src",
|
|
24
|
+
"v2-incompatible.js"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup",
|
|
28
|
+
"prepublishOnly": "npm run build"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"react-markdown": "^10.1.0",
|
|
32
|
+
"remark-gfm": "^4.0.1"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@sanity/icons": "^3.7.4",
|
|
36
|
+
"@sanity/ui": "^3.1.13",
|
|
37
|
+
"@types/react": "^19.0.0",
|
|
38
|
+
"@types/react-dom": "^19.2.3",
|
|
39
|
+
"react": "^19.2.4",
|
|
40
|
+
"react-dom": "^19.2.4",
|
|
41
|
+
"sanity": "^5.13.0",
|
|
42
|
+
"styled-components": "^6.3.11",
|
|
43
|
+
"tsup": "^8.0.0",
|
|
44
|
+
"typescript": "^5.9.3"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@sanity/icons": "^3.0.0",
|
|
48
|
+
"@sanity/ui": "^2.0.0 || ^3.0.0",
|
|
49
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
50
|
+
"sanity": "^3.0.0",
|
|
51
|
+
"styled-components": "^6.0.0"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=18"
|
|
55
|
+
}
|
|
56
|
+
}
|
package/sanity.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
{
|
|
2
|
-
"parts": []
|
|
3
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"parts": []
|
|
3
|
+
}
|
|
@@ -1,208 +1,213 @@
|
|
|
1
|
-
import { useState, useRef, useEffect } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const [
|
|
17
|
-
const [
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
1
|
+
import { useState, useRef, useEffect } from "react";
|
|
2
|
+
import { useCurrentUser } from "sanity";
|
|
3
|
+
import { useConfig } from "./ConfigContext";
|
|
4
|
+
import { submitFeedback } from "../lib/api";
|
|
5
|
+
|
|
6
|
+
interface FeedbackButtonProps {
|
|
7
|
+
suggestionType: string;
|
|
8
|
+
suggestionText: string;
|
|
9
|
+
documentId?: string;
|
|
10
|
+
publication?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function FeedbackButton({ suggestionType, suggestionText, documentId, publication }: FeedbackButtonProps) {
|
|
14
|
+
const { apiUrl } = useConfig();
|
|
15
|
+
const sanityUser = useCurrentUser();
|
|
16
|
+
const [vote, setVote] = useState<"up" | "down" | null>(null);
|
|
17
|
+
const [showReasonPopup, setShowReasonPopup] = useState(false);
|
|
18
|
+
const [reason, setReason] = useState("");
|
|
19
|
+
const [submitted, setSubmitted] = useState(false);
|
|
20
|
+
const popupRef = useRef<HTMLDivElement>(null);
|
|
21
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
22
|
+
|
|
23
|
+
// Close popup on outside click
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!showReasonPopup) return;
|
|
26
|
+
const handler = (e: MouseEvent) => {
|
|
27
|
+
if (popupRef.current && !popupRef.current.contains(e.target as Node)) {
|
|
28
|
+
setShowReasonPopup(false);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
document.addEventListener("mousedown", handler);
|
|
32
|
+
return () => document.removeEventListener("mousedown", handler);
|
|
33
|
+
}, [showReasonPopup]);
|
|
34
|
+
|
|
35
|
+
// Focus input when popup opens
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (showReasonPopup) {
|
|
38
|
+
setTimeout(() => inputRef.current?.focus(), 50);
|
|
39
|
+
}
|
|
40
|
+
}, [showReasonPopup]);
|
|
41
|
+
|
|
42
|
+
const handleVote = async (v: "up" | "down") => {
|
|
43
|
+
if (v === "down" && vote !== "down") {
|
|
44
|
+
setVote("down");
|
|
45
|
+
setShowReasonPopup(true);
|
|
46
|
+
setSubmitted(false);
|
|
47
|
+
// Submit the vote immediately
|
|
48
|
+
try {
|
|
49
|
+
await submitFeedback(apiUrl, {
|
|
50
|
+
suggestion_type: suggestionType,
|
|
51
|
+
suggestion_text: suggestionText,
|
|
52
|
+
vote: "down",
|
|
53
|
+
document_id: documentId,
|
|
54
|
+
publication,
|
|
55
|
+
user_id: sanityUser?.id,
|
|
56
|
+
});
|
|
57
|
+
} catch { /* silent */ }
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const newVote = vote === v ? null : v;
|
|
62
|
+
setVote(newVote);
|
|
63
|
+
setShowReasonPopup(false);
|
|
64
|
+
if (newVote) {
|
|
65
|
+
try {
|
|
66
|
+
await submitFeedback(apiUrl, {
|
|
67
|
+
suggestion_type: suggestionType,
|
|
68
|
+
suggestion_text: suggestionText,
|
|
69
|
+
vote: newVote,
|
|
70
|
+
document_id: documentId,
|
|
71
|
+
publication,
|
|
72
|
+
user_id: sanityUser?.id,
|
|
73
|
+
});
|
|
74
|
+
} catch { /* silent */ }
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const handleSubmitReason = async () => {
|
|
79
|
+
const trimmed = reason.trim();
|
|
80
|
+
if (trimmed) {
|
|
81
|
+
try {
|
|
82
|
+
await submitFeedback(apiUrl, {
|
|
83
|
+
suggestion_type: suggestionType + "_reason",
|
|
84
|
+
suggestion_text: suggestionText + " | REASON: " + trimmed,
|
|
85
|
+
vote: "down",
|
|
86
|
+
document_id: documentId,
|
|
87
|
+
publication,
|
|
88
|
+
user_id: sanityUser?.id,
|
|
89
|
+
});
|
|
90
|
+
} catch { /* silent */ }
|
|
91
|
+
}
|
|
92
|
+
setSubmitted(true);
|
|
93
|
+
setTimeout(() => {
|
|
94
|
+
setShowReasonPopup(false);
|
|
95
|
+
setReason("");
|
|
96
|
+
}, 1000);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<div style={{ display: "flex", alignItems: "center", gap: 2, flexShrink: 0, position: "relative" }}>
|
|
101
|
+
<button
|
|
102
|
+
onClick={() => handleVote("up")}
|
|
103
|
+
style={{
|
|
104
|
+
background: "none",
|
|
105
|
+
border: "none",
|
|
106
|
+
cursor: "pointer",
|
|
107
|
+
padding: 1,
|
|
108
|
+
fontSize: 12,
|
|
109
|
+
color: vote === "up" ? "#16a34a" : "#d1d5db",
|
|
110
|
+
transition: "color 150ms",
|
|
111
|
+
lineHeight: 1,
|
|
112
|
+
display: "flex",
|
|
113
|
+
}}
|
|
114
|
+
title="Good suggestion"
|
|
115
|
+
>
|
|
116
|
+
<svg width="12" height="12" viewBox="0 0 20 20" fill="currentColor">
|
|
117
|
+
<path d="M1 8.25a1.25 1.25 0 112.5 0v7.5a1.25 1.25 0 11-2.5 0v-7.5zM11 3V1.7c0-.268.14-.526.395-.607A2 2 0 0114 3c0 .995-.182 1.948-.514 2.826-.204.54.166 1.174.744 1.174h2.52c1.243 0 2.261 1.01 2.146 2.247a23.864 23.864 0 01-1.341 5.974 1.637 1.637 0 01-1.555 1.029H6.5V7.5L11 3z" />
|
|
118
|
+
</svg>
|
|
119
|
+
</button>
|
|
120
|
+
<button
|
|
121
|
+
onClick={() => handleVote("down")}
|
|
122
|
+
style={{
|
|
123
|
+
background: "none",
|
|
124
|
+
border: "none",
|
|
125
|
+
cursor: "pointer",
|
|
126
|
+
padding: 1,
|
|
127
|
+
fontSize: 12,
|
|
128
|
+
color: vote === "down" ? "#dc2626" : "#d1d5db",
|
|
129
|
+
transition: "color 150ms",
|
|
130
|
+
lineHeight: 1,
|
|
131
|
+
display: "flex",
|
|
132
|
+
}}
|
|
133
|
+
title="Not helpful"
|
|
134
|
+
>
|
|
135
|
+
<svg width="12" height="12" viewBox="0 0 20 20" fill="currentColor">
|
|
136
|
+
<path d="M19 11.75a1.25 1.25 0 11-2.5 0v-7.5a1.25 1.25 0 112.5 0v7.5zM9 17v1.3c0 .268-.14.526-.395.607A2 2 0 016 17c0-.995.182-1.948.514-2.826.204-.54-.166-1.174-.744-1.174H3.25c-1.243 0-2.261-1.01-2.146-2.247a23.864 23.864 0 011.341-5.974A1.637 1.637 0 014 3.75h9.5V12.5L9 17z" />
|
|
137
|
+
</svg>
|
|
138
|
+
</button>
|
|
139
|
+
|
|
140
|
+
{/* Thumbs down reason popup */}
|
|
141
|
+
{showReasonPopup && (
|
|
142
|
+
<div
|
|
143
|
+
ref={popupRef}
|
|
144
|
+
style={{
|
|
145
|
+
position: "absolute",
|
|
146
|
+
top: "100%",
|
|
147
|
+
right: 0,
|
|
148
|
+
marginTop: 4,
|
|
149
|
+
width: 220,
|
|
150
|
+
padding: 10,
|
|
151
|
+
borderRadius: 10,
|
|
152
|
+
background: "#ffffff",
|
|
153
|
+
boxShadow: "0 4px 16px rgba(0,0,0,0.15), 0 1px 4px rgba(0,0,0,0.1)",
|
|
154
|
+
zIndex: 100,
|
|
155
|
+
border: "1px solid #e5e7eb",
|
|
156
|
+
}}
|
|
157
|
+
>
|
|
158
|
+
{submitted ? (
|
|
159
|
+
<div style={{ fontSize: 11, color: "#16a34a", textAlign: "center", padding: "4px 0" }}>
|
|
160
|
+
Thanks for the feedback!
|
|
161
|
+
</div>
|
|
162
|
+
) : (
|
|
163
|
+
<>
|
|
164
|
+
<div style={{ fontSize: 11, fontWeight: 600, color: "#374151", marginBottom: 6 }}>
|
|
165
|
+
Sorry! What went wrong?
|
|
166
|
+
</div>
|
|
167
|
+
<input
|
|
168
|
+
ref={inputRef}
|
|
169
|
+
type="text"
|
|
170
|
+
value={reason}
|
|
171
|
+
onChange={(e) => setReason(e.target.value)}
|
|
172
|
+
onKeyDown={(e) => { if (e.key === "Enter") handleSubmitReason(); }}
|
|
173
|
+
placeholder="Tell us what to improve..."
|
|
174
|
+
style={{
|
|
175
|
+
width: "100%",
|
|
176
|
+
padding: "5px 8px",
|
|
177
|
+
fontSize: 11,
|
|
178
|
+
borderRadius: 6,
|
|
179
|
+
border: "1px solid #e5e7eb",
|
|
180
|
+
outline: "none",
|
|
181
|
+
fontFamily: "inherit",
|
|
182
|
+
boxSizing: "border-box",
|
|
183
|
+
}}
|
|
184
|
+
/>
|
|
185
|
+
<div style={{ display: "flex", justifyContent: "flex-end", marginTop: 6, gap: 4 }}>
|
|
186
|
+
<button
|
|
187
|
+
onClick={() => { setShowReasonPopup(false); setReason(""); }}
|
|
188
|
+
style={{
|
|
189
|
+
padding: "3px 8px", fontSize: 10, borderRadius: 4,
|
|
190
|
+
border: "1px solid #e5e7eb", background: "#ffffff", color: "#6b7280",
|
|
191
|
+
cursor: "pointer",
|
|
192
|
+
}}
|
|
193
|
+
>
|
|
194
|
+
Skip
|
|
195
|
+
</button>
|
|
196
|
+
<button
|
|
197
|
+
onClick={handleSubmitReason}
|
|
198
|
+
style={{
|
|
199
|
+
padding: "3px 8px", fontSize: 10, borderRadius: 4,
|
|
200
|
+
border: "none", background: "#dc2626", color: "#ffffff",
|
|
201
|
+
cursor: "pointer", fontWeight: 600,
|
|
202
|
+
}}
|
|
203
|
+
>
|
|
204
|
+
Submit
|
|
205
|
+
</button>
|
|
206
|
+
</div>
|
|
207
|
+
</>
|
|
208
|
+
)}
|
|
209
|
+
</div>
|
|
210
|
+
)}
|
|
211
|
+
</div>
|
|
212
|
+
);
|
|
213
|
+
}
|