sanity-plugin-seo-copilot 0.2.14 → 0.2.16

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.
Files changed (40) hide show
  1. package/README.md +63 -50
  2. package/dist/index.js +868 -797
  3. package/dist/index.mjs +791 -720
  4. package/package.json +9 -8
  5. package/dist/index.js.map +0 -1
  6. package/dist/index.mjs.map +0 -1
  7. package/sanity.json +0 -3
  8. package/src/components/ChatPanel.tsx +0 -311
  9. package/src/components/ConfigContext.tsx +0 -22
  10. package/src/components/FeedbackButton.tsx +0 -218
  11. package/src/components/KeywordBadge.tsx +0 -50
  12. package/src/components/KeywordPanel.tsx +0 -1233
  13. package/src/components/OnboardingPopup.tsx +0 -108
  14. package/src/components/PlacementIndicators.tsx +0 -80
  15. package/src/components/ReportProblemButton.tsx +0 -212
  16. package/src/components/SEOCopilotPanel.tsx +0 -1287
  17. package/src/components/ScoreDonut.tsx +0 -158
  18. package/src/components/SeedKeywordInput.tsx +0 -128
  19. package/src/components/ShimmerLoader.tsx +0 -123
  20. package/src/components/TabBar.tsx +0 -373
  21. package/src/components/styles.ts +0 -158
  22. package/src/components/tabs/AEOTab.tsx +0 -585
  23. package/src/components/tabs/LinkingTab.tsx +0 -446
  24. package/src/components/tabs/MetaTab.tsx +0 -431
  25. package/src/components/tabs/SummaryTab.tsx +0 -405
  26. package/src/components/tabs/TechnicalTab.tsx +0 -933
  27. package/src/hooks/useDocumentContent.ts +0 -48
  28. package/src/hooks/useKeywordAnalysis.ts +0 -292
  29. package/src/hooks/useSEOChat.ts +0 -254
  30. package/src/index.ts +0 -16
  31. package/src/inspector.ts +0 -58
  32. package/src/lib/api.ts +0 -260
  33. package/src/lib/documentExtract.ts +0 -422
  34. package/src/lib/geoAnalysis.ts +0 -122
  35. package/src/lib/persistence.ts +0 -69
  36. package/src/lib/scoring.ts +0 -197
  37. package/src/lib/summary.ts +0 -645
  38. package/src/lib/types.ts +0 -212
  39. package/src/lib/utils.ts +0 -35
  40. package/v2-incompatible.js +0 -10
@@ -1,405 +0,0 @@
1
- import { useMemo, useState } from "react";
2
- import { LoadingBars } from "../SEOCopilotPanel";
3
- import { ShimmerLoader, DEFAULT_GENERATE_ALL_MESSAGES } from "../ShimmerLoader";
4
- import { calculateContentScoreDetailed, type ContentScore } from "../../lib/scoring";
5
- import { buildSummaryItems } from "../../lib/summary";
6
- import { MJH_BLUE, MJH_GOLD } from "../styles";
7
- import type {
8
- SEOAnalysis,
9
- DeepAnalysis,
10
- DocumentFields,
11
- LinkingSuggestion,
12
- LinkCheckResult,
13
- SummaryItem,
14
- SummarySeverity,
15
- } from "../../lib/types";
16
-
17
- interface SummaryTabProps {
18
- text: string;
19
- analysis: SEOAnalysis | null;
20
- deepAnalysis: DeepAnalysis | null;
21
- documentFields?: DocumentFields;
22
- linkingSuggestions: LinkingSuggestion[];
23
- linkCheckResults?: LinkCheckResult[];
24
- // The editor's SELECTED primary keyword (effectivePrimary). The score uses this
25
- // so it updates instantly on selection instead of waiting for the re-analysis.
26
- primaryKeyword?: string;
27
- // Optional secondary target keyword - summary items flag where it's missing.
28
- secondaryKeyword?: string;
29
- isAnyLoading: boolean;
30
- onGenerateAll: () => void;
31
- onItemClick: (item: SummaryItem) => void;
32
- }
33
-
34
- type FilterKey = "all" | "error" | "warning" | "opportunity";
35
-
36
- const cardStyle: React.CSSProperties = {
37
- borderRadius: 14,
38
- background: "rgba(255,255,255,0.55)",
39
- backdropFilter: "blur(16px) saturate(170%)",
40
- WebkitBackdropFilter: "blur(16px) saturate(170%)",
41
- boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.85), inset 1.5px 2px 1px -1px rgba(255,255,255,1), inset -2px -3px 2px -1px rgba(255,255,255,0.6), 0 2px 6px rgba(0,0,0,0.07), 0 10px 26px rgba(0,0,0,0.08)",
42
- padding: "14px",
43
- };
44
-
45
- // Display labels for the "Go to ..." jump buttons. MUST stay in sync with the tab
46
- // labels in SEOCopilotPanel's tabDefs - notably the internal id "technical" is
47
- // shown to editors as "Other Recs", and "aeo" as "AEO/GEO".
48
- const TAB_LABEL: Record<string, string> = {
49
- summary: "Summary",
50
- keywords: "Keywords",
51
- aeo: "AEO/GEO",
52
- linking: "Linking",
53
- meta: "Meta",
54
- technical: "Other Recs",
55
- };
56
-
57
- function scoreColors(score: number): { bg: string; text: string; label: string } {
58
- if (score >= 70) return { bg: "rgba(22,163,74,0.1)", text: "#16a34a", label: "Strong" };
59
- if (score >= 40) return { bg: "rgba(230,192,27,0.15)", text: "#8B7310", label: "Decent" };
60
- return { bg: "rgba(220,38,38,0.08)", text: "#dc2626", label: "Needs work" };
61
- }
62
-
63
- // Qualitative tier for a single score component. We deliberately show a word + color,
64
- // not "points / max" - the underlying numbers are coarse heuristics, and a precise-looking
65
- // "17 / 25" implies an accuracy the rubric doesn't actually have.
66
- function componentTier(pct: number): { label: string; color: string; bar: string } {
67
- if (pct >= 75) return { label: "Strong", color: "#16a34a", bar: "#16a34a" };
68
- if (pct >= 40) return { label: "OK", color: "#8B7310", bar: "#E6C01B" };
69
- return { label: "Low", color: "#dc2626", bar: "#dc2626" };
70
- }
71
-
72
- // The score card. The breakdown is ALWAYS visible - the overall tier is just a roll-up
73
- // of the components below it. No raw numbers: each row reads as a colored "vibe" (Strong /
74
- // OK / Low) so editors focus on what's weak, not on chasing an arbitrary point total.
75
- function ScoreBadge({ score, breakdown }: { score: number; breakdown: ContentScore["components"] }) {
76
- const c = scoreColors(score);
77
- return (
78
- <div style={cardStyle}>
79
- {/* Top row: qualitative tier + label (no number) */}
80
- <div style={{ display: "flex", alignItems: "center", gap: 14 }}>
81
- <div
82
- style={{
83
- width: 56,
84
- height: 56,
85
- borderRadius: "50%",
86
- background: c.bg,
87
- display: "flex",
88
- alignItems: "center",
89
- justifyContent: "center",
90
- flexShrink: 0,
91
- }}
92
- >
93
- {/* Solid status disc - a color cue, not a number */}
94
- <div style={{ width: 22, height: 22, borderRadius: "50%", background: c.text, opacity: 0.9 }} />
95
- </div>
96
- <div style={{ flex: 1, minWidth: 0 }}>
97
- <div style={{ fontSize: 10.5, textTransform: "uppercase", letterSpacing: "0.06em", color: "#4b5563", fontWeight: 600, marginBottom: 2 }}>
98
- Content Score
99
- </div>
100
- <div style={{ fontSize: 16, fontWeight: 700, color: c.text }}>{c.label}</div>
101
- </div>
102
- </div>
103
-
104
- {/* Always-visible breakdown - each row shows what's driving the score, as a vibe */}
105
- {breakdown.length > 0 && (
106
- <div style={{ marginTop: 12, display: "flex", flexDirection: "column", gap: 8 }}>
107
- {breakdown.map((comp, i) => {
108
- const pct = comp.max > 0 ? (comp.points / comp.max) * 100 : 0;
109
- const tier = componentTier(pct);
110
- return (
111
- <div key={i}>
112
- <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", marginBottom: 3 }}>
113
- <span style={{ fontSize: 11, fontWeight: 600, color: "#1f2937" }}>{comp.label}</span>
114
- <span style={{ fontSize: 9.5, fontWeight: 700, textTransform: "uppercase", letterSpacing: "0.04em", color: tier.color }}>
115
- {tier.label}
116
- </span>
117
- </div>
118
- <div style={{ height: 4, background: "#f1f5f9", borderRadius: 99, overflow: "hidden", marginBottom: 4 }}>
119
- <div style={{ width: `${pct}%`, height: "100%", background: tier.bar, transition: "width 200ms" }} />
120
- </div>
121
- <div style={{ fontSize: 10.5, color: "#4b5563", lineHeight: 1.4 }}>{comp.detail}</div>
122
- </div>
123
- );
124
- })}
125
- </div>
126
- )}
127
- </div>
128
- );
129
- }
130
-
131
- function severityVisual(s: SummarySeverity) {
132
- if (s === "error") return { dot: "#dc2626", bg: "rgba(220,38,38,0.08)" };
133
- if (s === "warning") return { dot: "#E6C01B", bg: "rgba(230,192,27,0.15)" };
134
- return { dot: MJH_BLUE, bg: "rgba(0,93,172,0.06)" };
135
- }
136
-
137
- // One issue / warning / opportunity. Everything is visible up front - no expand
138
- // state, no "click to see why". Clicking the card jumps to the source tab.
139
- function ItemCard({ item, onClick }: { item: SummaryItem; onClick: () => void }) {
140
- const v = severityVisual(item.severity);
141
- const tab = item.jumpTo.tab;
142
- const tabLabel = TAB_LABEL[tab] ?? tab.charAt(0).toUpperCase() + tab.slice(1);
143
- return (
144
- <div
145
- onClick={onClick}
146
- style={{
147
- padding: "10px 12px",
148
- background: "rgba(255,255,255,0.55)",
149
- backdropFilter: "blur(16px) saturate(170%)",
150
- WebkitBackdropFilter: "blur(16px) saturate(170%)",
151
- borderRadius: 10,
152
- boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.5), inset 1.2px 1.5px 0 -1px rgba(255,255,255,0.85), 0 1px 3px rgba(0,0,0,0.05), 0 4px 12px rgba(0,0,0,0.05)",
153
- display: "flex",
154
- flexDirection: "column",
155
- gap: 6,
156
- cursor: "pointer",
157
- }}
158
- >
159
- <div style={{ display: "flex", alignItems: "flex-start", gap: 9 }}>
160
- <div
161
- style={{
162
- width: 8,
163
- height: 8,
164
- borderRadius: "50%",
165
- background: v.dot,
166
- marginTop: 5,
167
- flexShrink: 0,
168
- }}
169
- />
170
- <div style={{ flex: 1, minWidth: 0 }}>
171
- <div style={{ fontSize: 12, fontWeight: 700, color: "#1f2937", marginBottom: 2 }}>{item.label}</div>
172
- <div style={{ fontSize: 11, color: "#374151", lineHeight: 1.5 }}>{item.description}</div>
173
- </div>
174
- </div>
175
- {/* How to fix - always visible, inline, severity-tinted */}
176
- <div
177
- style={{
178
- padding: "7px 10px",
179
- background: v.bg,
180
- borderRadius: 6,
181
- fontSize: 11,
182
- color: "#1f2937",
183
- lineHeight: 1.55,
184
- }}
185
- >
186
- <span style={{ fontWeight: 700, color: "#4b5563", letterSpacing: "0.04em", fontSize: 9.5, textTransform: "uppercase", marginRight: 6 }}>
187
- Fix
188
- </span>
189
- {item.howToFix}
190
- </div>
191
- {item.jumpTo.tab !== "summary" && (
192
- <div style={{ display: "flex", justifyContent: "flex-end" }}>
193
- <span style={{ fontSize: 10, fontWeight: 700, color: MJH_BLUE }}>
194
- Go to {tabLabel} ›
195
- </span>
196
- </div>
197
- )}
198
- </div>
199
- );
200
- }
201
-
202
- function FilterChip({
203
- active,
204
- onClick,
205
- label,
206
- count,
207
- dotColor,
208
- }: {
209
- active: boolean;
210
- onClick: () => void;
211
- label: string;
212
- count: number;
213
- dotColor?: string;
214
- }) {
215
- return (
216
- <button
217
- onClick={onClick}
218
- style={{
219
- padding: "4px 9px",
220
- background: active ? "#1f2937" : "#ffffff",
221
- color: active ? "#ffffff" : "#4b5563",
222
- border: active ? "1px solid #1f2937" : "1px solid rgba(0,0,0,0.08)",
223
- borderRadius: 99,
224
- cursor: "pointer",
225
- fontSize: 11,
226
- fontWeight: 600,
227
- display: "flex",
228
- alignItems: "center",
229
- gap: 5,
230
- transition: "all 150ms",
231
- }}
232
- >
233
- {dotColor && (
234
- <span style={{ width: 6, height: 6, borderRadius: "50%", background: dotColor, display: "inline-block" }} />
235
- )}
236
- <span>{label}</span>
237
- <span style={{ fontSize: 10, opacity: 0.8 }}>{count}</span>
238
- </button>
239
- );
240
- }
241
-
242
- export function SummaryTab({
243
- text,
244
- analysis,
245
- deepAnalysis,
246
- documentFields,
247
- linkingSuggestions,
248
- linkCheckResults,
249
- primaryKeyword,
250
- secondaryKeyword,
251
- isAnyLoading,
252
- onGenerateAll,
253
- onItemClick,
254
- }: SummaryTabProps) {
255
- const scoreDetail = useMemo(() => {
256
- if (!analysis) return null;
257
- // Score against the editor's SELECTED primary so the score updates the instant
258
- // they pick a different candidate (no wait for the focus re-analysis round-trip).
259
- const scored =
260
- primaryKeyword && analysis.primaryKeyword && primaryKeyword !== analysis.primaryKeyword.term
261
- ? { ...analysis, primaryKeyword: { ...analysis.primaryKeyword, term: primaryKeyword } }
262
- : analysis;
263
- return calculateContentScoreDetailed(text, scored, documentFields);
264
- }, [text, analysis, documentFields, primaryKeyword]);
265
- const score = scoreDetail?.total ?? null;
266
-
267
- const items = useMemo(
268
- () =>
269
- buildSummaryItems({
270
- analysis,
271
- deepAnalysis,
272
- documentFields,
273
- contentScore: score,
274
- linkingSuggestions,
275
- linkCheckResults,
276
- text,
277
- primaryKeyword,
278
- secondaryKeyword,
279
- }),
280
- [analysis, deepAnalysis, documentFields, score, linkingSuggestions, linkCheckResults, text, primaryKeyword, secondaryKeyword]
281
- );
282
-
283
- const [filter, setFilter] = useState<FilterKey>("all");
284
- const counts = useMemo(
285
- () => ({
286
- all: items.length,
287
- error: items.filter((i) => i.severity === "error").length,
288
- warning: items.filter((i) => i.severity === "warning").length,
289
- opportunity: items.filter((i) => i.severity === "opportunity").length,
290
- }),
291
- [items]
292
- );
293
- const filtered = filter === "all" ? items : items.filter((i) => i.severity === filter);
294
-
295
- if (!analysis) {
296
- return (
297
- <div style={{ padding: 24, textAlign: "center" }}>
298
- <div style={{ fontSize: 13, color: "#4b5563", fontWeight: 500 }}>Start with the Keywords tab</div>
299
- <div style={{ fontSize: 11, color: "#4b5563", marginTop: 4 }}>
300
- Once keywords are analyzed, the summary appears here.
301
- </div>
302
- </div>
303
- );
304
- }
305
-
306
- return (
307
- <div style={{ padding: 12, display: "flex", flexDirection: "column", gap: 12 }}>
308
- {/* Content Score badge */}
309
- {score != null && scoreDetail && <ScoreBadge score={score} breakdown={scoreDetail.components} />}
310
-
311
- {/* Generate everything - runs the analyses that fill the AEO/GEO, Linking,
312
- and Other Recs tabs in parallel. Their results flow back into this Summary
313
- via buildSummaryItems, so editors see new issues here as each one finishes. */}
314
- <div style={cardStyle}>
315
- {isAnyLoading ? (
316
- <div style={{ display: "flex", alignItems: "center", justifyContent: "center", padding: "4px 0" }}>
317
- <ShimmerLoader messages={DEFAULT_GENERATE_ALL_MESSAGES} />
318
- </div>
319
- ) : (
320
- <button
321
- onClick={onGenerateAll}
322
- disabled={!text || text.trim().length < 100}
323
- style={{
324
- width: "100%",
325
- padding: "10px 14px",
326
- fontSize: 12,
327
- fontWeight: 700,
328
- color: !text || text.trim().length < 100 ? "#9ca3af" : "#1f2937",
329
- background: !text || text.trim().length < 100 ? "#e5e7eb" : "linear-gradient(135deg, rgba(230,192,27,0.82), rgba(230,192,27,0.98))",
330
- backdropFilter: "blur(10px) saturate(160%)",
331
- WebkitBackdropFilter: "blur(10px) saturate(160%)",
332
- boxShadow: !text || text.trim().length < 100 ? "none" : "inset 0 1px 1px rgba(255,255,255,0.6), inset 0 -1px 2px rgba(0,0,0,0.12), 0 2px 8px rgba(230,192,27,0.32)",
333
- border: "none",
334
- borderRadius: 8,
335
- cursor: !text || text.trim().length < 100 ? "not-allowed" : "pointer",
336
- display: "flex",
337
- alignItems: "center",
338
- justifyContent: "center",
339
- gap: 8,
340
- transition: "all 150ms",
341
- letterSpacing: "0.01em",
342
- }}
343
- >
344
- Run all analyses
345
- </button>
346
- )}
347
- <div style={{ fontSize: 10.5, color: "#4b5563", marginTop: 8, lineHeight: 1.5 }}>
348
- Runs the analyses that fill the <strong>AEO/GEO</strong>, <strong>Linking</strong>, and <strong>Other Recs</strong> tabs. New issues they find appear in this Summary as each one finishes.
349
- </div>
350
- </div>
351
-
352
- {/* Filter chips */}
353
- <div style={{ display: "flex", flexWrap: "wrap", gap: 6 }}>
354
- <FilterChip active={filter === "all"} onClick={() => setFilter("all")} label="All" count={counts.all} />
355
- <FilterChip active={filter === "error"} onClick={() => setFilter("error")} label="Errors" count={counts.error} dotColor="#dc2626" />
356
- <FilterChip active={filter === "warning"} onClick={() => setFilter("warning")} label="Warnings" count={counts.warning} dotColor="#E6C01B" />
357
- <FilterChip active={filter === "opportunity"} onClick={() => setFilter("opportunity")} label="Opportunities" count={counts.opportunity} dotColor={MJH_BLUE} />
358
- </div>
359
-
360
- {/* Items list */}
361
- <div id="anchor-summary-issues" style={{ display: "flex", flexDirection: "column", gap: 8 }}>
362
- {filtered.length === 0 ? (
363
- <div style={{ ...cardStyle, textAlign: "center", padding: "20px 14px" }}>
364
- {items.length === 0 ? (
365
- <>
366
- <div
367
- style={{
368
- width: 40,
369
- height: 40,
370
- borderRadius: "50%",
371
- background: "rgba(22,163,74,0.1)",
372
- display: "flex",
373
- alignItems: "center",
374
- justifyContent: "center",
375
- margin: "0 auto 8px",
376
- }}
377
- >
378
- <svg width="20" height="20" viewBox="0 0 20 20" fill="#16a34a">
379
- <path fillRule="evenodd" d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z" clipRule="evenodd" />
380
- </svg>
381
- </div>
382
- <div style={{ fontSize: 13, color: "#16a34a", fontWeight: 700 }}>Looking good</div>
383
- <div style={{ fontSize: 11, color: "#4b5563", marginTop: 2 }}>
384
- No issues found for this article.
385
- </div>
386
- </>
387
- ) : (
388
- <div style={{ fontSize: 12, color: "#4b5563" }}>Nothing in this category.</div>
389
- )}
390
- </div>
391
- ) : (
392
- filtered.map((item) => <ItemCard key={item.id} item={item} onClick={() => onItemClick(item)} />)
393
- )}
394
- </div>
395
-
396
- {/* Loading hint when something's still running and we have partial data */}
397
- {isAnyLoading && items.length > 0 && (
398
- <div style={{ display: "flex", alignItems: "center", justifyContent: "center", gap: 6, padding: "4px 0" }}>
399
- <LoadingBars size="xs" color={MJH_BLUE} />
400
- <span style={{ fontSize: 10, color: "#4b5563" }}>Still checking...</span>
401
- </div>
402
- )}
403
- </div>
404
- );
405
- }