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/package.json CHANGED
@@ -1,56 +1,56 @@
1
- {
2
- "name": "sanity-plugin-seo-copilot",
3
- "version": "0.1.0",
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 { useConfig } from "./ConfigContext";
3
- import { submitFeedback } from "../lib/api";
4
-
5
- interface FeedbackButtonProps {
6
- suggestionType: string;
7
- suggestionText: string;
8
- documentId?: string;
9
- publication?: string;
10
- }
11
-
12
- export function FeedbackButton({ suggestionType, suggestionText, documentId, publication }: FeedbackButtonProps) {
13
- const { apiUrl } = useConfig();
14
- const [vote, setVote] = useState<"up" | "down" | null>(null);
15
- const [showReasonPopup, setShowReasonPopup] = useState(false);
16
- const [reason, setReason] = useState("");
17
- const [submitted, setSubmitted] = useState(false);
18
- const popupRef = useRef<HTMLDivElement>(null);
19
- const inputRef = useRef<HTMLInputElement>(null);
20
-
21
- // Close popup on outside click
22
- useEffect(() => {
23
- if (!showReasonPopup) return;
24
- const handler = (e: MouseEvent) => {
25
- if (popupRef.current && !popupRef.current.contains(e.target as Node)) {
26
- setShowReasonPopup(false);
27
- }
28
- };
29
- document.addEventListener("mousedown", handler);
30
- return () => document.removeEventListener("mousedown", handler);
31
- }, [showReasonPopup]);
32
-
33
- // Focus input when popup opens
34
- useEffect(() => {
35
- if (showReasonPopup) {
36
- setTimeout(() => inputRef.current?.focus(), 50);
37
- }
38
- }, [showReasonPopup]);
39
-
40
- const handleVote = async (v: "up" | "down") => {
41
- if (v === "down" && vote !== "down") {
42
- setVote("down");
43
- setShowReasonPopup(true);
44
- setSubmitted(false);
45
- // Submit the vote immediately
46
- try {
47
- await submitFeedback(apiUrl, {
48
- suggestion_type: suggestionType,
49
- suggestion_text: suggestionText,
50
- vote: "down",
51
- document_id: documentId,
52
- publication,
53
- });
54
- } catch { /* silent */ }
55
- return;
56
- }
57
-
58
- const newVote = vote === v ? null : v;
59
- setVote(newVote);
60
- setShowReasonPopup(false);
61
- if (newVote) {
62
- try {
63
- await submitFeedback(apiUrl, {
64
- suggestion_type: suggestionType,
65
- suggestion_text: suggestionText,
66
- vote: newVote,
67
- document_id: documentId,
68
- publication,
69
- });
70
- } catch { /* silent */ }
71
- }
72
- };
73
-
74
- const handleSubmitReason = async () => {
75
- const trimmed = reason.trim();
76
- if (trimmed) {
77
- try {
78
- await submitFeedback(apiUrl, {
79
- suggestion_type: suggestionType + "_reason",
80
- suggestion_text: suggestionText + " | REASON: " + trimmed,
81
- vote: "down",
82
- document_id: documentId,
83
- publication,
84
- });
85
- } catch { /* silent */ }
86
- }
87
- setSubmitted(true);
88
- setTimeout(() => {
89
- setShowReasonPopup(false);
90
- setReason("");
91
- }, 1000);
92
- };
93
-
94
- return (
95
- <div style={{ display: "flex", alignItems: "center", gap: 2, flexShrink: 0, position: "relative" }}>
96
- <button
97
- onClick={() => handleVote("up")}
98
- style={{
99
- background: "none",
100
- border: "none",
101
- cursor: "pointer",
102
- padding: 1,
103
- fontSize: 12,
104
- color: vote === "up" ? "#16a34a" : "#d1d5db",
105
- transition: "color 150ms",
106
- lineHeight: 1,
107
- display: "flex",
108
- }}
109
- title="Good suggestion"
110
- >
111
- <svg width="12" height="12" viewBox="0 0 20 20" fill="currentColor">
112
- <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" />
113
- </svg>
114
- </button>
115
- <button
116
- onClick={() => handleVote("down")}
117
- style={{
118
- background: "none",
119
- border: "none",
120
- cursor: "pointer",
121
- padding: 1,
122
- fontSize: 12,
123
- color: vote === "down" ? "#dc2626" : "#d1d5db",
124
- transition: "color 150ms",
125
- lineHeight: 1,
126
- display: "flex",
127
- }}
128
- title="Not helpful"
129
- >
130
- <svg width="12" height="12" viewBox="0 0 20 20" fill="currentColor">
131
- <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" />
132
- </svg>
133
- </button>
134
-
135
- {/* Thumbs down reason popup */}
136
- {showReasonPopup && (
137
- <div
138
- ref={popupRef}
139
- style={{
140
- position: "absolute",
141
- top: "100%",
142
- right: 0,
143
- marginTop: 4,
144
- width: 220,
145
- padding: 10,
146
- borderRadius: 10,
147
- background: "#ffffff",
148
- boxShadow: "0 4px 16px rgba(0,0,0,0.15), 0 1px 4px rgba(0,0,0,0.1)",
149
- zIndex: 100,
150
- border: "1px solid #e5e7eb",
151
- }}
152
- >
153
- {submitted ? (
154
- <div style={{ fontSize: 11, color: "#16a34a", textAlign: "center", padding: "4px 0" }}>
155
- Thanks for the feedback!
156
- </div>
157
- ) : (
158
- <>
159
- <div style={{ fontSize: 11, fontWeight: 600, color: "#374151", marginBottom: 6 }}>
160
- Sorry! What went wrong?
161
- </div>
162
- <input
163
- ref={inputRef}
164
- type="text"
165
- value={reason}
166
- onChange={(e) => setReason(e.target.value)}
167
- onKeyDown={(e) => { if (e.key === "Enter") handleSubmitReason(); }}
168
- placeholder="Tell us what to improve..."
169
- style={{
170
- width: "100%",
171
- padding: "5px 8px",
172
- fontSize: 11,
173
- borderRadius: 6,
174
- border: "1px solid #e5e7eb",
175
- outline: "none",
176
- fontFamily: "inherit",
177
- boxSizing: "border-box",
178
- }}
179
- />
180
- <div style={{ display: "flex", justifyContent: "flex-end", marginTop: 6, gap: 4 }}>
181
- <button
182
- onClick={() => { setShowReasonPopup(false); setReason(""); }}
183
- style={{
184
- padding: "3px 8px", fontSize: 10, borderRadius: 4,
185
- border: "1px solid #e5e7eb", background: "#ffffff", color: "#6b7280",
186
- cursor: "pointer",
187
- }}
188
- >
189
- Skip
190
- </button>
191
- <button
192
- onClick={handleSubmitReason}
193
- style={{
194
- padding: "3px 8px", fontSize: 10, borderRadius: 4,
195
- border: "none", background: "#dc2626", color: "#ffffff",
196
- cursor: "pointer", fontWeight: 600,
197
- }}
198
- >
199
- Submit
200
- </button>
201
- </div>
202
- </>
203
- )}
204
- </div>
205
- )}
206
- </div>
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
+ }