sanity-plugin-seo-copilot 0.1.2 → 0.2.1
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/dist/index.js +4729 -895
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4722 -888
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/components/ChatPanel.tsx +87 -69
- package/src/components/FeedbackButton.tsx +2 -2
- package/src/components/KeywordBadge.tsx +50 -50
- package/src/components/KeywordPanel.tsx +97 -226
- package/src/components/PlacementIndicators.tsx +80 -76
- package/src/components/SEOCopilotPanel.tsx +712 -165
- package/src/components/ScoreDonut.tsx +158 -0
- package/src/components/SeedKeywordInput.tsx +128 -125
- package/src/components/ShimmerLoader.tsx +119 -0
- package/src/components/TabBar.tsx +370 -0
- package/src/components/styles.ts +66 -0
- package/src/components/tabs/AEOTab.tsx +573 -0
- package/src/components/tabs/LinkingTab.tsx +343 -0
- package/src/components/tabs/MetaTab.tsx +417 -0
- package/src/components/tabs/SummaryTab.tsx +384 -0
- package/src/components/tabs/TechnicalTab.tsx +776 -0
- package/src/hooks/useDocumentContent.ts +216 -99
- package/src/hooks/useKeywordAnalysis.ts +28 -8
- package/src/hooks/useSEOChat.ts +38 -11
- package/src/lib/api.ts +109 -13
- package/src/lib/geoAnalysis.ts +109 -0
- package/src/lib/persistence.ts +69 -0
- package/src/lib/scoring.ts +147 -0
- package/src/lib/summary.ts +504 -0
- package/src/lib/types.ts +197 -108
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sanity-plugin-seo-copilot",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "AI-powered SEO writing assistant for Sanity Studio",
|
|
5
5
|
"keywords": ["sanity", "sanity-plugin", "seo", "copilot"],
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@sanity/icons": "^3.0.0",
|
|
48
48
|
"@sanity/ui": "^2.0.0 || ^3.0.0",
|
|
49
49
|
"react": "^18.0.0 || ^19.0.0",
|
|
50
|
-
"sanity": "^3.0.0",
|
|
50
|
+
"sanity": "^3.0.0 || ^5.0.0",
|
|
51
51
|
"styled-components": "^6.0.0"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
@@ -1,26 +1,17 @@
|
|
|
1
1
|
import { useState, useRef, useEffect } from "react";
|
|
2
2
|
import ReactMarkdown from "react-markdown";
|
|
3
3
|
import remarkGfm from "remark-gfm";
|
|
4
|
-
import { useDocumentPane } from "sanity/structure";
|
|
5
|
-
import { useSEOChat } from "../hooks/useSEOChat";
|
|
6
|
-
import { useConfig } from "./ConfigContext";
|
|
7
4
|
import { LoadingBars } from "./SEOCopilotPanel";
|
|
8
5
|
import { MJH_GOLD, MJH_BLUE, USER_BLUE, USER_BLUE_BORDER, MJH_SLATE } from "./styles";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
primaryKeyword?: { term: string; volume: number | null };
|
|
12
|
-
supportingKeywords?: { term: string; volume: number | null }[];
|
|
13
|
-
missingKeywords?: { term: string; volume: number | null }[];
|
|
14
|
-
aeoData?: {
|
|
15
|
-
questionHeadings: { suggestedHeading: string; rationale: string }[];
|
|
16
|
-
faqSuggestions: { question: string; answer: string }[];
|
|
17
|
-
};
|
|
18
|
-
}
|
|
6
|
+
import { usePersistentState } from "../lib/persistence";
|
|
7
|
+
import type { ChatMessage } from "../lib/types";
|
|
19
8
|
|
|
20
9
|
interface ChatPanelProps {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
messages: ChatMessage[];
|
|
11
|
+
isStreaming: boolean;
|
|
12
|
+
sendMessage: (text: string) => Promise<void>;
|
|
13
|
+
clearChat: () => void;
|
|
14
|
+
documentId?: string;
|
|
24
15
|
}
|
|
25
16
|
|
|
26
17
|
const SUGGESTIONS = [
|
|
@@ -40,12 +31,10 @@ function LogoIcon() {
|
|
|
40
31
|
);
|
|
41
32
|
}
|
|
42
33
|
|
|
43
|
-
export function ChatPanel({
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const { messages, isStreaming, sendMessage, clearChat } = useSEOChat(apiUrl, text, publication, keywordPanelData, documentId);
|
|
48
|
-
const [input, setInput] = useState("");
|
|
34
|
+
export function ChatPanel({ messages, isStreaming, sendMessage, clearChat, documentId }: ChatPanelProps) {
|
|
35
|
+
// Input is per-doc and persisted - if a user types a question, undocks, the text stays.
|
|
36
|
+
const inputKey = documentId ? `seo-copilot-chat-input-${documentId}` : "seo-copilot-chat-input-default";
|
|
37
|
+
const [input, setInput] = usePersistentState<string>(inputKey, "");
|
|
49
38
|
const [inputFocused, setInputFocused] = useState(false);
|
|
50
39
|
const [hoveredSuggestion, setHoveredSuggestion] = useState<number | null>(null);
|
|
51
40
|
const [clearHovered, setClearHovered] = useState(false);
|
|
@@ -55,6 +44,9 @@ export function ChatPanel({ text, publication, keywordPanelData }: ChatPanelProp
|
|
|
55
44
|
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
56
45
|
}, [messages]);
|
|
57
46
|
|
|
47
|
+
// Input is persisted per-doc via usePersistentState - no manual reset needed.
|
|
48
|
+
// The key changes when documentId changes, so the new doc's input loads automatically.
|
|
49
|
+
|
|
58
50
|
const handleSend = () => {
|
|
59
51
|
const trimmed = input.trim();
|
|
60
52
|
if (!trimmed || isStreaming) return;
|
|
@@ -76,7 +68,18 @@ export function ChatPanel({ text, publication, keywordPanelData }: ChatPanelProp
|
|
|
76
68
|
);
|
|
77
69
|
|
|
78
70
|
return (
|
|
79
|
-
<div
|
|
71
|
+
<div
|
|
72
|
+
style={{
|
|
73
|
+
position: "relative",
|
|
74
|
+
flex: 1,
|
|
75
|
+
minHeight: 0,
|
|
76
|
+
// Transparent: the blue chat-zone gradient (CHAT_ZONE_BG) lives on the
|
|
77
|
+
// shared wrapper one level up, so the toggle bar, these messages, and the
|
|
78
|
+
// composer all sit on ONE continuous gradient with no seam. The glass
|
|
79
|
+
// bubbles + composer frost over it.
|
|
80
|
+
background: "transparent",
|
|
81
|
+
}}
|
|
82
|
+
>
|
|
80
83
|
{/* Absolute inner creates a definite-height context so flex children respect bounds */}
|
|
81
84
|
<div style={{ position: "absolute", top: 0, left: 0, right: 0, bottom: 0, display: "flex", flexDirection: "column" }}>
|
|
82
85
|
{/* Messages Area - scrollable */}
|
|
@@ -86,7 +89,7 @@ export function ChatPanel({ text, publication, keywordPanelData }: ChatPanelProp
|
|
|
86
89
|
{/* Welcome */}
|
|
87
90
|
<div style={{ display: "flex", alignItems: "center", gap: 8, marginBottom: 4 }}>
|
|
88
91
|
<LogoIcon />
|
|
89
|
-
<span style={{ fontSize: 12, fontWeight: 600, color: "#
|
|
92
|
+
<span style={{ fontSize: 12, fontWeight: 600, color: "#4b5563" }}>
|
|
90
93
|
Welcome to SEO Copilot! Ask anything about your content.
|
|
91
94
|
</span>
|
|
92
95
|
</div>
|
|
@@ -103,10 +106,12 @@ export function ChatPanel({ text, publication, keywordPanelData }: ChatPanelProp
|
|
|
103
106
|
padding: "10px 14px",
|
|
104
107
|
borderRadius: 12,
|
|
105
108
|
fontSize: 12.5,
|
|
106
|
-
color: "#
|
|
107
|
-
background: hoveredSuggestion === i ? USER_BLUE : "
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
color: "#1f2937",
|
|
110
|
+
background: hoveredSuggestion === i ? USER_BLUE : "rgba(255,255,255,0.5)",
|
|
111
|
+
backdropFilter: "blur(16px) saturate(170%)",
|
|
112
|
+
WebkitBackdropFilter: "blur(16px) saturate(170%)",
|
|
113
|
+
border: `1px solid ${hoveredSuggestion === i ? USER_BLUE_BORDER : "rgba(255,255,255,0.6)"}`,
|
|
114
|
+
boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.4), 0 1px 2px rgba(0,0,0,0.04)",
|
|
110
115
|
cursor: "pointer",
|
|
111
116
|
transition: "all 200ms ease",
|
|
112
117
|
}}
|
|
@@ -145,10 +150,12 @@ export function ChatPanel({ text, publication, keywordPanelData }: ChatPanelProp
|
|
|
145
150
|
color: "#1e293b",
|
|
146
151
|
}
|
|
147
152
|
: {
|
|
148
|
-
background: "
|
|
149
|
-
|
|
153
|
+
background: "rgba(255,255,255,0.55)",
|
|
154
|
+
backdropFilter: "blur(16px) saturate(170%)",
|
|
155
|
+
WebkitBackdropFilter: "blur(16px) saturate(170%)",
|
|
156
|
+
boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.5), 0 1px 3px rgba(0,0,0,0.06)",
|
|
150
157
|
borderBottomLeftRadius: 6,
|
|
151
|
-
color: "#
|
|
158
|
+
color: "#1f2937",
|
|
152
159
|
}),
|
|
153
160
|
}}
|
|
154
161
|
>
|
|
@@ -188,8 +195,10 @@ export function ChatPanel({ text, publication, keywordPanelData }: ChatPanelProp
|
|
|
188
195
|
padding: 12,
|
|
189
196
|
borderRadius: 16,
|
|
190
197
|
borderBottomLeftRadius: 4,
|
|
191
|
-
background: "
|
|
192
|
-
|
|
198
|
+
background: "rgba(255,255,255,0.55)",
|
|
199
|
+
backdropFilter: "blur(16px) saturate(170%)",
|
|
200
|
+
WebkitBackdropFilter: "blur(16px) saturate(170%)",
|
|
201
|
+
boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.5), 0 1px 3px rgba(0,0,0,0.06)",
|
|
193
202
|
}}
|
|
194
203
|
>
|
|
195
204
|
<LoadingBars size="xs" />
|
|
@@ -202,18 +211,47 @@ export function ChatPanel({ text, publication, keywordPanelData }: ChatPanelProp
|
|
|
202
211
|
)}
|
|
203
212
|
</div>
|
|
204
213
|
|
|
205
|
-
{/* Input
|
|
214
|
+
{/* Input bar - sits at the very bottom of the panel, fully opaque so no
|
|
215
|
+
panel gold bleeds through. Clear is folded in as a trash icon on the
|
|
216
|
+
left so there's no separate strip beneath the input. */}
|
|
206
217
|
<div
|
|
207
218
|
style={{
|
|
208
219
|
display: "flex",
|
|
220
|
+
alignItems: "center",
|
|
209
221
|
gap: 8,
|
|
210
222
|
padding: 12,
|
|
211
|
-
borderTop: "1px solid
|
|
212
|
-
background: "rgba(255,255,255,0.
|
|
213
|
-
backdropFilter: "blur(
|
|
223
|
+
borderTop: "1px solid rgba(255,255,255,0.55)",
|
|
224
|
+
background: "rgba(255,255,255,0.4)",
|
|
225
|
+
backdropFilter: "blur(16px) saturate(170%)",
|
|
226
|
+
WebkitBackdropFilter: "blur(16px) saturate(170%)",
|
|
227
|
+
boxShadow: "inset 0 1px 0 rgba(255,255,255,0.65), 0 -3px 10px rgba(0,0,0,0.04)",
|
|
214
228
|
flexShrink: 0,
|
|
215
229
|
}}
|
|
216
230
|
>
|
|
231
|
+
{messages.length > 0 && (
|
|
232
|
+
<button
|
|
233
|
+
onClick={clearChat}
|
|
234
|
+
onMouseEnter={() => setClearHovered(true)}
|
|
235
|
+
onMouseLeave={() => setClearHovered(false)}
|
|
236
|
+
title="Clear conversation"
|
|
237
|
+
aria-label="Clear conversation"
|
|
238
|
+
style={{
|
|
239
|
+
background: "none",
|
|
240
|
+
border: "none",
|
|
241
|
+
cursor: "pointer",
|
|
242
|
+
padding: 4,
|
|
243
|
+
display: "flex",
|
|
244
|
+
alignItems: "center",
|
|
245
|
+
color: clearHovered ? "#ef4444" : "#9ca3af",
|
|
246
|
+
transition: "color 150ms",
|
|
247
|
+
flexShrink: 0,
|
|
248
|
+
}}
|
|
249
|
+
>
|
|
250
|
+
<svg width="14" height="14" viewBox="0 0 20 20" fill="currentColor">
|
|
251
|
+
<path fillRule="evenodd" d="M8.75 1A2.75 2.75 0 006 3.75v.443c-.795.077-1.584.176-2.365.298a.75.75 0 10.23 1.482l.149-.022.841 10.518A2.75 2.75 0 007.596 19h4.807a2.75 2.75 0 002.742-2.53l.841-10.519.149.023a.75.75 0 00.23-1.482A41.03 41.03 0 0014 4.193V3.75A2.75 2.75 0 0011.25 1h-2.5zM10 4c.84 0 1.673.025 2.5.075V3.75c0-.69-.56-1.25-1.25-1.25h-2.5c-.69 0-1.25.56-1.25 1.25v.325C8.327 4.025 9.16 4 10 4zM8.58 7.72a.75.75 0 00-1.5.06l.3 7.5a.75.75 0 101.5-.06l-.3-7.5zm4.34.06a.75.75 0 10-1.5-.06l-.3 7.5a.75.75 0 101.5.06l.3-7.5z" clipRule="evenodd" />
|
|
252
|
+
</svg>
|
|
253
|
+
</button>
|
|
254
|
+
)}
|
|
217
255
|
<input
|
|
218
256
|
type="text"
|
|
219
257
|
value={input}
|
|
@@ -227,10 +265,15 @@ export function ChatPanel({ text, publication, keywordPanelData }: ChatPanelProp
|
|
|
227
265
|
flex: 1,
|
|
228
266
|
padding: "8px 12px",
|
|
229
267
|
fontSize: 12,
|
|
268
|
+
color: "#1f2937",
|
|
230
269
|
borderRadius: 12,
|
|
231
|
-
border: `1px solid ${inputFocused ? MJH_BLUE : "
|
|
232
|
-
background: "
|
|
233
|
-
|
|
270
|
+
border: `1px solid ${inputFocused ? MJH_BLUE : "rgba(255,255,255,0.8)"}`,
|
|
271
|
+
background: "rgba(255,255,255,0.6)",
|
|
272
|
+
backdropFilter: "blur(8px)",
|
|
273
|
+
WebkitBackdropFilter: "blur(8px)",
|
|
274
|
+
boxShadow: inputFocused
|
|
275
|
+
? "0 0 0 3px rgba(0,93,172,0.12), inset 0 0 0 1px rgba(255,255,255,0.5)"
|
|
276
|
+
: "inset 0 0 0 1px rgba(255,255,255,0.5), 0 1px 2px rgba(0,0,0,0.04)",
|
|
234
277
|
outline: "none",
|
|
235
278
|
opacity: isStreaming ? 0.4 : 1,
|
|
236
279
|
transition: "border-color 150ms, box-shadow 150ms",
|
|
@@ -244,8 +287,10 @@ export function ChatPanel({ text, publication, keywordPanelData }: ChatPanelProp
|
|
|
244
287
|
borderRadius: 12,
|
|
245
288
|
border: "none",
|
|
246
289
|
color: "#ffffff",
|
|
247
|
-
background:
|
|
248
|
-
|
|
290
|
+
background: "linear-gradient(135deg, rgba(0,93,172,0.88), rgba(0,74,138,0.96))",
|
|
291
|
+
backdropFilter: "blur(10px) saturate(160%)",
|
|
292
|
+
WebkitBackdropFilter: "blur(10px) saturate(160%)",
|
|
293
|
+
boxShadow: "inset 0 1px 1px rgba(255,255,255,0.45), inset 0 -1px 2px rgba(0,0,0,0.2), 0 2px 7px rgba(0,93,172,0.32)",
|
|
249
294
|
cursor: isStreaming || !input.trim() ? "not-allowed" : "pointer",
|
|
250
295
|
opacity: isStreaming || !input.trim() ? 0.4 : 1,
|
|
251
296
|
transition: "all 150ms",
|
|
@@ -258,33 +303,6 @@ export function ChatPanel({ text, publication, keywordPanelData }: ChatPanelProp
|
|
|
258
303
|
</svg>
|
|
259
304
|
</button>
|
|
260
305
|
</div>
|
|
261
|
-
|
|
262
|
-
{/* Clear */}
|
|
263
|
-
{messages.length > 0 && (
|
|
264
|
-
<div style={{ display: "flex", justifyContent: "flex-end", padding: "0 12px 8px", flexShrink: 0 }}>
|
|
265
|
-
<button
|
|
266
|
-
onClick={clearChat}
|
|
267
|
-
onMouseEnter={() => setClearHovered(true)}
|
|
268
|
-
onMouseLeave={() => setClearHovered(false)}
|
|
269
|
-
style={{
|
|
270
|
-
background: "none",
|
|
271
|
-
border: "none",
|
|
272
|
-
fontSize: 10,
|
|
273
|
-
color: clearHovered ? "#ef4444" : "#d1d5db",
|
|
274
|
-
cursor: "pointer",
|
|
275
|
-
display: "flex",
|
|
276
|
-
alignItems: "center",
|
|
277
|
-
gap: 4,
|
|
278
|
-
transition: "color 150ms",
|
|
279
|
-
}}
|
|
280
|
-
>
|
|
281
|
-
<svg width="12" height="12" viewBox="0 0 20 20" fill="currentColor">
|
|
282
|
-
<path fillRule="evenodd" d="M8.75 1A2.75 2.75 0 006 3.75v.443c-.795.077-1.584.176-2.365.298a.75.75 0 10.23 1.482l.149-.022.841 10.518A2.75 2.75 0 007.596 19h4.807a2.75 2.75 0 002.742-2.53l.841-10.519.149.023a.75.75 0 00.23-1.482A41.03 41.03 0 0014 4.193V3.75A2.75 2.75 0 0011.25 1h-2.5zM10 4c.84 0 1.673.025 2.5.075V3.75c0-.69-.56-1.25-1.25-1.25h-2.5c-.69 0-1.25.56-1.25 1.25v.325C8.327 4.025 9.16 4 10 4zM8.58 7.72a.75.75 0 00-1.5.06l.3 7.5a.75.75 0 101.5-.06l-.3-7.5zm4.34.06a.75.75 0 10-1.5-.06l-.3 7.5a.75.75 0 101.5.06l.3-7.5z" clipRule="evenodd" />
|
|
283
|
-
</svg>
|
|
284
|
-
Clear
|
|
285
|
-
</button>
|
|
286
|
-
</div>
|
|
287
|
-
)}
|
|
288
306
|
</div>
|
|
289
307
|
</div>
|
|
290
308
|
);
|
|
@@ -161,7 +161,7 @@ export function FeedbackButton({ suggestionType, suggestionText, documentId, pub
|
|
|
161
161
|
</div>
|
|
162
162
|
) : (
|
|
163
163
|
<>
|
|
164
|
-
<div style={{ fontSize: 11, fontWeight: 600, color: "#
|
|
164
|
+
<div style={{ fontSize: 11, fontWeight: 600, color: "#1f2937", marginBottom: 6 }}>
|
|
165
165
|
Sorry! What went wrong?
|
|
166
166
|
</div>
|
|
167
167
|
<input
|
|
@@ -187,7 +187,7 @@ export function FeedbackButton({ suggestionType, suggestionText, documentId, pub
|
|
|
187
187
|
onClick={() => { setShowReasonPopup(false); setReason(""); }}
|
|
188
188
|
style={{
|
|
189
189
|
padding: "3px 8px", fontSize: 10, borderRadius: 4,
|
|
190
|
-
border: "1px solid #e5e7eb", background: "#ffffff", color: "#
|
|
190
|
+
border: "1px solid #e5e7eb", background: "#ffffff", color: "#4b5563",
|
|
191
191
|
cursor: "pointer",
|
|
192
192
|
}}
|
|
193
193
|
>
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { MJH_BLUE } from "./styles";
|
|
2
|
-
import { PlacementIndicators } from "./PlacementIndicators";
|
|
3
|
-
import type { KeywordPlacement } from "../lib/types";
|
|
4
|
-
|
|
5
|
-
interface KeywordBadgeProps {
|
|
6
|
-
term: string;
|
|
7
|
-
volume?: number | null;
|
|
8
|
-
type: "primary" | "supporting" | "missing";
|
|
9
|
-
inContent?: boolean;
|
|
10
|
-
placement?: KeywordPlacement;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const colorMap = {
|
|
14
|
-
primary: { bg: "rgba(220,252,231,0.8)", text: "#166534" },
|
|
15
|
-
supporting: { bg: "rgba(0,93,172,0.1)", text: MJH_BLUE },
|
|
16
|
-
missing: { bg: "rgba(230,192,27,0.15)", text: "#8B7310" },
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
function formatVolume(volume: number | null | undefined): string {
|
|
20
|
-
if (volume === null || volume === undefined) return "";
|
|
21
|
-
if (volume === 0) return "N/A";
|
|
22
|
-
return volume.toLocaleString();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function KeywordBadge({ term, volume, type, inContent, placement }: KeywordBadgeProps) {
|
|
26
|
-
const colors = colorMap[type];
|
|
27
|
-
const volumeStr = formatVolume(volume);
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<div style={{ display: "flex", alignItems: "center", gap: 6, padding: "2px 0", flexWrap: "wrap" }}>
|
|
31
|
-
<span
|
|
32
|
-
style={{
|
|
33
|
-
borderRadius: 99,
|
|
34
|
-
padding: "2px 10px",
|
|
35
|
-
fontSize: 12,
|
|
36
|
-
fontWeight: 500,
|
|
37
|
-
whiteSpace: "nowrap",
|
|
38
|
-
background: colors.bg,
|
|
39
|
-
color: colors.text,
|
|
40
|
-
}}
|
|
41
|
-
>
|
|
42
|
-
{term}
|
|
43
|
-
</span>
|
|
44
|
-
{volumeStr && (
|
|
45
|
-
<span style={{ fontSize: 12, color: "#
|
|
46
|
-
)}
|
|
47
|
-
<PlacementIndicators placement={placement} />
|
|
48
|
-
</div>
|
|
49
|
-
);
|
|
50
|
-
}
|
|
1
|
+
import { MJH_BLUE } from "./styles";
|
|
2
|
+
import { PlacementIndicators } from "./PlacementIndicators";
|
|
3
|
+
import type { KeywordPlacement } from "../lib/types";
|
|
4
|
+
|
|
5
|
+
interface KeywordBadgeProps {
|
|
6
|
+
term: string;
|
|
7
|
+
volume?: number | null;
|
|
8
|
+
type: "primary" | "supporting" | "missing";
|
|
9
|
+
inContent?: boolean;
|
|
10
|
+
placement?: KeywordPlacement;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const colorMap = {
|
|
14
|
+
primary: { bg: "rgba(220,252,231,0.8)", text: "#166534" },
|
|
15
|
+
supporting: { bg: "rgba(0,93,172,0.1)", text: MJH_BLUE },
|
|
16
|
+
missing: { bg: "rgba(230,192,27,0.15)", text: "#8B7310" },
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function formatVolume(volume: number | null | undefined): string {
|
|
20
|
+
if (volume === null || volume === undefined) return "";
|
|
21
|
+
if (volume === 0) return "N/A";
|
|
22
|
+
return volume.toLocaleString();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function KeywordBadge({ term, volume, type, inContent, placement }: KeywordBadgeProps) {
|
|
26
|
+
const colors = colorMap[type];
|
|
27
|
+
const volumeStr = formatVolume(volume);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div style={{ display: "flex", alignItems: "center", gap: 6, padding: "2px 0", flexWrap: "wrap" }}>
|
|
31
|
+
<span
|
|
32
|
+
style={{
|
|
33
|
+
borderRadius: 99,
|
|
34
|
+
padding: "2px 10px",
|
|
35
|
+
fontSize: 12,
|
|
36
|
+
fontWeight: 500,
|
|
37
|
+
whiteSpace: "nowrap",
|
|
38
|
+
background: colors.bg,
|
|
39
|
+
color: colors.text,
|
|
40
|
+
}}
|
|
41
|
+
>
|
|
42
|
+
{term}
|
|
43
|
+
</span>
|
|
44
|
+
{volumeStr && (
|
|
45
|
+
<span style={{ fontSize: 12, color: "#4b5563" }}>{volumeStr === "N/A" ? volumeStr : `${volumeStr}/mo`}</span>
|
|
46
|
+
)}
|
|
47
|
+
<PlacementIndicators placement={placement} />
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
}
|