sanity-plugin-seo-copilot 0.2.1 → 0.2.7
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 +1407 -638
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1407 -638
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/KeywordPanel.tsx +170 -5
- package/src/components/OnboardingPopup.tsx +108 -0
- package/src/components/SEOCopilotPanel.tsx +123 -14
- package/src/components/styles.ts +8 -0
- package/src/components/tabs/AEOTab.tsx +9 -3
- package/src/components/tabs/LinkingTab.tsx +77 -4
- package/src/components/tabs/MetaTab.tsx +40 -115
- package/src/components/tabs/SummaryTab.tsx +19 -4
- package/src/components/tabs/TechnicalTab.tsx +200 -29
- package/src/hooks/useDocumentContent.ts +6 -174
- package/src/hooks/useKeywordAnalysis.ts +33 -4
- package/src/hooks/useSEOChat.ts +61 -16
- package/src/lib/api.ts +25 -7
- package/src/lib/documentExtract.ts +268 -0
- package/src/lib/geoAnalysis.ts +16 -3
- package/src/lib/scoring.ts +69 -19
- package/src/lib/summary.ts +169 -28
- package/src/lib/types.ts +4 -1
package/package.json
CHANGED
|
@@ -18,6 +18,10 @@ interface KeywordPanelProps {
|
|
|
18
18
|
seedKeywords?: string[];
|
|
19
19
|
onSeedsChange?: (seeds: string[]) => void;
|
|
20
20
|
onSelectPrimary?: (term: string) => void;
|
|
21
|
+
// Optional secondary/supporting target keyword. Audits check the article against
|
|
22
|
+
// BOTH the primary and this secondary keyword. "" / undefined = none selected.
|
|
23
|
+
secondaryKeyword?: string;
|
|
24
|
+
onSelectSecondary?: (term: string) => void;
|
|
21
25
|
documentFields?: DocumentFields;
|
|
22
26
|
// Used as key for SuggestedKeywordsCard to remount on doc change (resets manualKeywords/extraKeywords/helpData)
|
|
23
27
|
documentId?: string;
|
|
@@ -96,7 +100,9 @@ function placementCount(p?: import("../lib/types").KeywordPlacement): number {
|
|
|
96
100
|
|
|
97
101
|
type PlacementKey = "inBody" | "inTitle" | "inMetaDescription" | "inImages" | "inUrl" | "none";
|
|
98
102
|
|
|
99
|
-
/** Merge supporting + missing into one list,
|
|
103
|
+
/** Merge supporting + missing into one list, sorted by placement count then volume desc.
|
|
104
|
+
* Note: 0-volume terms are intentionally KEPT - niche clinical long-tail terms often
|
|
105
|
+
* have no SEMrush data but are still worth targeting for topical authority. */
|
|
100
106
|
function buildSuggestedKeywords(
|
|
101
107
|
supporting: { term: string; volume: number | null; inContent: boolean; placement?: import("../lib/types").KeywordPlacement }[],
|
|
102
108
|
missing: { term: string; volume: number | null; reason: string; placement?: import("../lib/types").KeywordPlacement }[],
|
|
@@ -171,7 +177,7 @@ function LightbulbButton({ onClick, isLoading }: { onClick: () => void; isLoadin
|
|
|
171
177
|
pointerEvents: "none",
|
|
172
178
|
zIndex: 10,
|
|
173
179
|
}}>
|
|
174
|
-
|
|
180
|
+
See suggestion
|
|
175
181
|
</span>
|
|
176
182
|
)}
|
|
177
183
|
</span>
|
|
@@ -401,10 +407,10 @@ function PrimaryKeywordSelector({
|
|
|
401
407
|
{candidate.term}
|
|
402
408
|
</span>
|
|
403
409
|
{candidate.volume != null && (
|
|
404
|
-
<span style={{ fontSize: 11, fontWeight: 600, color: "#1f2937" }}>{abbrevVol(candidate.volume)}/mo</span>
|
|
410
|
+
<span style={{ fontSize: 11, fontWeight: 600, color: "#1f2937" }}>{candidate.volume === 0 ? "N/A" : `${abbrevVol(candidate.volume)}/mo`}</span>
|
|
405
411
|
)}
|
|
406
412
|
<span style={{ fontSize: 10, color: "#1f2937" }}>
|
|
407
|
-
{Math.round(candidate.confidence * 100)}% confidence
|
|
413
|
+
{Math.round((candidate.confidence ?? 0) * 100)}% confidence
|
|
408
414
|
</span>
|
|
409
415
|
</div>
|
|
410
416
|
{candidate.placement && (
|
|
@@ -422,6 +428,128 @@ function PrimaryKeywordSelector({
|
|
|
422
428
|
);
|
|
423
429
|
}
|
|
424
430
|
|
|
431
|
+
function SecondaryKeywordSelector({
|
|
432
|
+
options,
|
|
433
|
+
selectedTerm,
|
|
434
|
+
onSelect,
|
|
435
|
+
}: {
|
|
436
|
+
options: { term: string; volume: number | null }[];
|
|
437
|
+
selectedTerm: string;
|
|
438
|
+
onSelect: (term: string) => void;
|
|
439
|
+
}) {
|
|
440
|
+
const [customInputOpen, setCustomInputOpen] = useState(false);
|
|
441
|
+
const [customValue, setCustomValue] = useState("");
|
|
442
|
+
|
|
443
|
+
const handleCustomSubmit = () => {
|
|
444
|
+
const trimmed = customValue.trim();
|
|
445
|
+
if (trimmed) {
|
|
446
|
+
onSelect(trimmed);
|
|
447
|
+
setCustomValue("");
|
|
448
|
+
setCustomInputOpen(false);
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
// The selected secondary may be a custom term not present in `options` - append it
|
|
453
|
+
// so the radio still shows as selected.
|
|
454
|
+
const opts = selectedTerm && !options.some((o) => o.term === selectedTerm)
|
|
455
|
+
? [...options, { term: selectedTerm, volume: null }]
|
|
456
|
+
: options;
|
|
457
|
+
|
|
458
|
+
return (
|
|
459
|
+
<div style={cardStyle}>
|
|
460
|
+
<SectionHeader
|
|
461
|
+
label="Secondary Keyword"
|
|
462
|
+
iconColor={MJH_BLUE}
|
|
463
|
+
actionButton={
|
|
464
|
+
<div style={{ display: "flex", alignItems: "center", gap: 6 }}>
|
|
465
|
+
<span style={{ fontSize: 9, fontWeight: 700, letterSpacing: "0.05em", textTransform: "uppercase", color: "#9ca3af" }}>Optional</span>
|
|
466
|
+
<PencilButton onClick={() => setCustomInputOpen(!customInputOpen)} active={customInputOpen} />
|
|
467
|
+
</div>
|
|
468
|
+
}
|
|
469
|
+
/>
|
|
470
|
+
|
|
471
|
+
<div style={{ fontSize: 11, color: "#4b5563", lineHeight: 1.5, marginBottom: 8 }}>
|
|
472
|
+
Pick one more keyword to optimize for. Copilot then checks your title, meta, URL, headings, and images against both keywords.
|
|
473
|
+
</div>
|
|
474
|
+
|
|
475
|
+
{customInputOpen && (
|
|
476
|
+
<div style={{ marginBottom: 8, display: "flex", gap: 6 }}>
|
|
477
|
+
<input
|
|
478
|
+
type="text"
|
|
479
|
+
value={customValue}
|
|
480
|
+
onChange={(e) => setCustomValue(e.target.value)}
|
|
481
|
+
onKeyDown={(e) => { if (e.key === "Enter") handleCustomSubmit(); }}
|
|
482
|
+
placeholder="Type a custom secondary keyword"
|
|
483
|
+
autoFocus
|
|
484
|
+
style={{ flex: 1, padding: "5px 8px", fontSize: 12, borderRadius: 8, border: "1px solid #e5e7eb", outline: "none", fontFamily: "inherit" }}
|
|
485
|
+
/>
|
|
486
|
+
<button
|
|
487
|
+
onClick={handleCustomSubmit}
|
|
488
|
+
disabled={!customValue.trim()}
|
|
489
|
+
style={{
|
|
490
|
+
padding: "5px 10px", fontSize: 11, fontWeight: 600, borderRadius: 6, border: "none",
|
|
491
|
+
background: customValue.trim() ? MJH_BLUE : "#e5e7eb",
|
|
492
|
+
color: customValue.trim() ? "#ffffff" : "#9ca3af",
|
|
493
|
+
cursor: customValue.trim() ? "pointer" : "not-allowed",
|
|
494
|
+
}}
|
|
495
|
+
>
|
|
496
|
+
Set
|
|
497
|
+
</button>
|
|
498
|
+
</div>
|
|
499
|
+
)}
|
|
500
|
+
|
|
501
|
+
<div style={{ display: "flex", flexDirection: "column", gap: 6 }}>
|
|
502
|
+
{/* None option - secondary is optional */}
|
|
503
|
+
<SecondaryOptionRow term="" label="None" selected={!selectedTerm} onSelect={() => onSelect("")} />
|
|
504
|
+
{opts.map((o) => (
|
|
505
|
+
<SecondaryOptionRow
|
|
506
|
+
key={o.term}
|
|
507
|
+
term={o.term}
|
|
508
|
+
label={o.term}
|
|
509
|
+
volume={o.volume}
|
|
510
|
+
selected={o.term === selectedTerm}
|
|
511
|
+
onSelect={() => onSelect(o.term)}
|
|
512
|
+
/>
|
|
513
|
+
))}
|
|
514
|
+
</div>
|
|
515
|
+
</div>
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function SecondaryOptionRow({ term, label, volume, selected, onSelect }: { term: string; label: string; volume?: number | null; selected: boolean; onSelect: () => void }) {
|
|
520
|
+
return (
|
|
521
|
+
<div
|
|
522
|
+
onClick={onSelect}
|
|
523
|
+
style={{
|
|
524
|
+
display: "flex",
|
|
525
|
+
alignItems: "center",
|
|
526
|
+
gap: 8,
|
|
527
|
+
padding: "6px 8px",
|
|
528
|
+
borderRadius: 8,
|
|
529
|
+
cursor: "pointer",
|
|
530
|
+
background: selected ? "rgba(0,93,172,0.06)" : "transparent",
|
|
531
|
+
border: selected ? "1px solid rgba(0,93,172,0.2)" : "1px solid transparent",
|
|
532
|
+
transition: "all 150ms",
|
|
533
|
+
}}
|
|
534
|
+
>
|
|
535
|
+
<div style={{
|
|
536
|
+
width: 14, height: 14, borderRadius: "50%",
|
|
537
|
+
border: selected ? "none" : "2px solid #d1d5db",
|
|
538
|
+
background: selected ? MJH_BLUE : "transparent",
|
|
539
|
+
flexShrink: 0, display: "flex", alignItems: "center", justifyContent: "center",
|
|
540
|
+
}}>
|
|
541
|
+
{selected && <div style={{ width: 6, height: 6, borderRadius: "50%", background: "#ffffff" }} />}
|
|
542
|
+
</div>
|
|
543
|
+
<span style={{ fontSize: 12, fontWeight: selected ? 600 : 400, color: term ? (selected ? "#00468a" : "#374151") : "#6b7280", flex: 1, minWidth: 0 }}>
|
|
544
|
+
{label}
|
|
545
|
+
</span>
|
|
546
|
+
{volume != null && (
|
|
547
|
+
<span style={{ fontSize: 11, fontWeight: 600, color: "#1f2937" }}>{volume === 0 ? "N/A" : `${abbrevVol(volume)}/mo`}</span>
|
|
548
|
+
)}
|
|
549
|
+
</div>
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
|
|
425
553
|
const PLACEMENT_FILTERS: { key: PlacementKey; label: string; letter: string }[] = [
|
|
426
554
|
{ key: "inBody", label: "Body", letter: "B" },
|
|
427
555
|
{ key: "inTitle", label: "Title", letter: "T" },
|
|
@@ -821,7 +949,7 @@ function SuggestedKeywordsCard({
|
|
|
821
949
|
{enrichingTerms.has(kw.term) && <LoadingBars size="xs" color="#6b7280" />}
|
|
822
950
|
{/* Abbreviated monthly search volume - readable, not whisper-gray. */}
|
|
823
951
|
{!enrichingTerms.has(kw.term) && kw.volume != null && (
|
|
824
|
-
<span style={{ fontSize: 10.5, fontWeight: 600, color: "#1f2937", flexShrink: 0 }} title="Monthly searches">{abbrevVol(kw.volume)}/mo</span>
|
|
952
|
+
<span style={{ fontSize: 10.5, fontWeight: 600, color: "#1f2937", flexShrink: 0 }} title="Monthly searches">{kw.volume === 0 ? "N/A" : `${abbrevVol(kw.volume)}/mo`}</span>
|
|
825
953
|
)}
|
|
826
954
|
{/* Placement indicators */}
|
|
827
955
|
{kw.placement && <PlacementIndicators placement={kw.placement} />}
|
|
@@ -898,6 +1026,8 @@ export function KeywordPanel({
|
|
|
898
1026
|
seedKeywords = [],
|
|
899
1027
|
onSeedsChange,
|
|
900
1028
|
onSelectPrimary,
|
|
1029
|
+
secondaryKeyword = "",
|
|
1030
|
+
onSelectSecondary,
|
|
901
1031
|
documentFields,
|
|
902
1032
|
documentId,
|
|
903
1033
|
externalAnalysis,
|
|
@@ -992,8 +1122,34 @@ export function KeywordPanel({
|
|
|
992
1122
|
? selectedPrimaryTerm
|
|
993
1123
|
: candidates[0]?.term ?? "";
|
|
994
1124
|
|
|
1125
|
+
// Secondary options = the same candidate pool as primary, plus the suggested
|
|
1126
|
+
// supporting keywords (deduped). The primary term is intentionally NOT removed -
|
|
1127
|
+
// both selectors draw from one shared pool.
|
|
1128
|
+
const secondaryOptions: { term: string; volume: number | null }[] = [];
|
|
1129
|
+
const seenSecondary = new Set<string>();
|
|
1130
|
+
for (const c of candidates) {
|
|
1131
|
+
const key = c.term.toLowerCase();
|
|
1132
|
+
if (!seenSecondary.has(key)) { seenSecondary.add(key); secondaryOptions.push({ term: c.term, volume: c.volume }); }
|
|
1133
|
+
}
|
|
1134
|
+
for (const kw of suggestedKeywords) {
|
|
1135
|
+
const key = kw.term.toLowerCase();
|
|
1136
|
+
if (!seenSecondary.has(key)) { seenSecondary.add(key); secondaryOptions.push({ term: kw.term, volume: kw.volume }); }
|
|
1137
|
+
}
|
|
1138
|
+
|
|
995
1139
|
return (
|
|
996
1140
|
<div style={{ padding: 12, display: "flex", flexDirection: "column", gap: 12 }}>
|
|
1141
|
+
{/* On-page instructions: the two-keyword target process */}
|
|
1142
|
+
<div style={{
|
|
1143
|
+
...cardStyle,
|
|
1144
|
+
padding: "11px 13px",
|
|
1145
|
+
background: "rgba(0,93,172,0.05)",
|
|
1146
|
+
boxShadow: "inset 0 0 0 1px rgba(0,93,172,0.12)",
|
|
1147
|
+
}}>
|
|
1148
|
+
<div style={{ fontSize: 11.5, color: "#1f2937", lineHeight: 1.55 }}>
|
|
1149
|
+
<strong style={{ color: "#00468a" }}>Choose your target keywords.</strong> Pick one <strong>Primary</strong> keyword (required) and, optionally, one <strong>Secondary</strong> keyword. Copilot optimizes the whole article - title, meta, URL, headings, and images - toward both.
|
|
1150
|
+
</div>
|
|
1151
|
+
</div>
|
|
1152
|
+
|
|
997
1153
|
{/* Desired Keywords */}
|
|
998
1154
|
{onSeedsChange && (
|
|
999
1155
|
<SeedKeywordInput seeds={seedKeywords} onSeedsChange={onSeedsChange} />
|
|
@@ -1007,6 +1163,15 @@ export function KeywordPanel({
|
|
|
1007
1163
|
publication={publication}
|
|
1008
1164
|
/>
|
|
1009
1165
|
|
|
1166
|
+
{/* Secondary Keyword Selector (optional) */}
|
|
1167
|
+
{onSelectSecondary && secondaryOptions.length > 0 && (
|
|
1168
|
+
<SecondaryKeywordSelector
|
|
1169
|
+
options={secondaryOptions}
|
|
1170
|
+
selectedTerm={secondaryKeyword}
|
|
1171
|
+
onSelect={(term: string) => onSelectSecondary(term)}
|
|
1172
|
+
/>
|
|
1173
|
+
)}
|
|
1174
|
+
|
|
1010
1175
|
{/* Supporting Keywords */}
|
|
1011
1176
|
{suggestedKeywords.length > 0 && (
|
|
1012
1177
|
<SuggestedKeywordsCard
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { MJH_BLUE } from "./styles";
|
|
2
|
+
|
|
3
|
+
// Small (i) button that lives in the panel header next to the pop-out control. The
|
|
4
|
+
// first-run popup collapses into this; clicking it re-opens the popup.
|
|
5
|
+
export function OnboardingInfoButton({ onClick }: { onClick: () => void }) {
|
|
6
|
+
return (
|
|
7
|
+
<button
|
|
8
|
+
onClick={(e) => { e.stopPropagation(); onClick(); }}
|
|
9
|
+
onMouseDown={(e) => e.stopPropagation()}
|
|
10
|
+
style={{
|
|
11
|
+
background: "rgba(0,93,172,0.08)",
|
|
12
|
+
border: "none",
|
|
13
|
+
borderRadius: "50%",
|
|
14
|
+
width: 20,
|
|
15
|
+
height: 20,
|
|
16
|
+
cursor: "pointer",
|
|
17
|
+
padding: 0,
|
|
18
|
+
display: "flex",
|
|
19
|
+
alignItems: "center",
|
|
20
|
+
justifyContent: "center",
|
|
21
|
+
color: MJH_BLUE,
|
|
22
|
+
flexShrink: 0,
|
|
23
|
+
}}
|
|
24
|
+
title="How SEO Copilot works"
|
|
25
|
+
aria-label="How SEO Copilot works"
|
|
26
|
+
>
|
|
27
|
+
<svg width="13" height="13" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
|
28
|
+
<path fillRule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z" clipRule="evenodd" />
|
|
29
|
+
</svg>
|
|
30
|
+
</button>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// First-run onboarding popup. Amorphous MJH-blue glass. Clicking anywhere on the
|
|
35
|
+
// dimmed backdrop, the X, or "Got it" dismisses it (fades out to the info icon).
|
|
36
|
+
export function OnboardingCard({ onDismiss, closing }: { onDismiss: () => void; closing: boolean }) {
|
|
37
|
+
return (
|
|
38
|
+
<>
|
|
39
|
+
{/* Click-anywhere backdrop - very light so it doesn't feel like a hard modal. */}
|
|
40
|
+
<div
|
|
41
|
+
onClick={onDismiss}
|
|
42
|
+
style={{
|
|
43
|
+
position: "absolute",
|
|
44
|
+
inset: 0,
|
|
45
|
+
zIndex: 60,
|
|
46
|
+
background: "transparent",
|
|
47
|
+
cursor: "pointer",
|
|
48
|
+
}}
|
|
49
|
+
/>
|
|
50
|
+
<div
|
|
51
|
+
onClick={(e) => e.stopPropagation()}
|
|
52
|
+
style={{
|
|
53
|
+
position: "absolute",
|
|
54
|
+
top: 50,
|
|
55
|
+
right: 10,
|
|
56
|
+
left: 10,
|
|
57
|
+
maxWidth: 320,
|
|
58
|
+
marginLeft: "auto",
|
|
59
|
+
zIndex: 61,
|
|
60
|
+
borderRadius: 18,
|
|
61
|
+
padding: "14px 16px 16px",
|
|
62
|
+
// Amorphous blue glass
|
|
63
|
+
background: "linear-gradient(155deg, rgba(0,93,172,0.16), rgba(0,93,172,0.08))",
|
|
64
|
+
backdropFilter: "blur(20px) saturate(170%)",
|
|
65
|
+
WebkitBackdropFilter: "blur(20px) saturate(170%)",
|
|
66
|
+
boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.55), inset 1.5px 2px 1px -1px rgba(255,255,255,0.9), 0 10px 30px rgba(0,93,172,0.22), 0 2px 8px rgba(0,0,0,0.12)",
|
|
67
|
+
animation: `${closing ? "onboard-out" : "onboard-in"} ${closing ? 180 : 240}ms ease-out forwards`,
|
|
68
|
+
}}
|
|
69
|
+
>
|
|
70
|
+
<div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 8, marginBottom: 6 }}>
|
|
71
|
+
<span style={{ fontSize: 13, fontWeight: 800, color: "#00468a", letterSpacing: "-0.01em" }}>
|
|
72
|
+
Welcome to SEO Copilot
|
|
73
|
+
</span>
|
|
74
|
+
<button
|
|
75
|
+
onClick={onDismiss}
|
|
76
|
+
style={{ background: "none", border: "none", cursor: "pointer", padding: 2, display: "flex", color: "#00468a", opacity: 0.7 }}
|
|
77
|
+
title="Dismiss"
|
|
78
|
+
aria-label="Dismiss"
|
|
79
|
+
>
|
|
80
|
+
<svg width="14" height="14" viewBox="0 0 20 20" fill="currentColor">
|
|
81
|
+
<path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z" />
|
|
82
|
+
</svg>
|
|
83
|
+
</button>
|
|
84
|
+
</div>
|
|
85
|
+
<div style={{ fontSize: 11.5, color: "#13335a", lineHeight: 1.6 }}>
|
|
86
|
+
Start on the <strong>Keywords</strong> tab. Choose one <strong>Primary</strong> keyword (required) and, optionally, one <strong>Secondary</strong> keyword. Copilot then optimizes the whole article - title, meta, URL, headings, and images - toward both.
|
|
87
|
+
</div>
|
|
88
|
+
<button
|
|
89
|
+
onClick={onDismiss}
|
|
90
|
+
style={{
|
|
91
|
+
marginTop: 12,
|
|
92
|
+
width: "100%",
|
|
93
|
+
padding: "7px 12px",
|
|
94
|
+
fontSize: 11.5,
|
|
95
|
+
fontWeight: 700,
|
|
96
|
+
color: "#ffffff",
|
|
97
|
+
background: MJH_BLUE,
|
|
98
|
+
border: "none",
|
|
99
|
+
borderRadius: 8,
|
|
100
|
+
cursor: "pointer",
|
|
101
|
+
}}
|
|
102
|
+
>
|
|
103
|
+
Got it
|
|
104
|
+
</button>
|
|
105
|
+
</div>
|
|
106
|
+
</>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useState, useRef, useCallback, useEffect, useMemo, Suspense } from "react";
|
|
2
|
+
import { useWorkspace } from "sanity";
|
|
2
3
|
import { createPortal } from "react-dom";
|
|
3
4
|
import { useDocumentContent } from "../hooks/useDocumentContent";
|
|
4
5
|
import { useKeywordAnalysis } from "../hooks/useKeywordAnalysis";
|
|
@@ -7,6 +8,7 @@ import { useConfig, ConfigProvider } from "./ConfigContext";
|
|
|
7
8
|
import { KeywordPanel } from "./KeywordPanel";
|
|
8
9
|
import { ChatPanel } from "./ChatPanel";
|
|
9
10
|
import { TabBar } from "./TabBar";
|
|
11
|
+
import { OnboardingInfoButton, OnboardingCard } from "./OnboardingPopup";
|
|
10
12
|
import { SummaryTab } from "./tabs/SummaryTab";
|
|
11
13
|
import { AEOTab } from "./tabs/AEOTab";
|
|
12
14
|
import { LinkingTab } from "./tabs/LinkingTab";
|
|
@@ -48,8 +50,12 @@ interface PanelContentProps {
|
|
|
48
50
|
docLoading: boolean;
|
|
49
51
|
documentFields: import("../lib/types").DocumentFields;
|
|
50
52
|
documentId?: string;
|
|
53
|
+
documentType?: string;
|
|
54
|
+
sanityBaseUrl?: string;
|
|
51
55
|
selectedPrimary?: string;
|
|
52
56
|
onSelectPrimary?: (term: string) => void;
|
|
57
|
+
selectedSecondary?: string;
|
|
58
|
+
onSelectSecondary?: (term: string) => void;
|
|
53
59
|
// Lifted state - survives float/dock toggle (which remounts PanelContent)
|
|
54
60
|
activeTab: TabId;
|
|
55
61
|
onActiveTabChange: (id: TabId) => void;
|
|
@@ -116,8 +122,12 @@ function PanelContent({
|
|
|
116
122
|
docLoading,
|
|
117
123
|
documentFields,
|
|
118
124
|
documentId,
|
|
125
|
+
documentType,
|
|
126
|
+
sanityBaseUrl,
|
|
119
127
|
selectedPrimary,
|
|
120
128
|
onSelectPrimary,
|
|
129
|
+
selectedSecondary,
|
|
130
|
+
onSelectSecondary,
|
|
121
131
|
activeTab,
|
|
122
132
|
onActiveTabChange,
|
|
123
133
|
chatOpen,
|
|
@@ -140,6 +150,8 @@ function PanelContent({
|
|
|
140
150
|
selectedPrimary ||
|
|
141
151
|
externalAnalysis.analysis?.primaryKeyword?.term ||
|
|
142
152
|
"";
|
|
153
|
+
// Effective secondary keyword - purely the user's optional choice (no auto-default).
|
|
154
|
+
const effectiveSecondary = selectedSecondary || "";
|
|
143
155
|
|
|
144
156
|
// Draggable divider between tab content and chat - splitPercent is lifted to parent for persistence
|
|
145
157
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
@@ -173,6 +185,63 @@ function PanelContent({
|
|
|
173
185
|
|
|
174
186
|
const headerCursor = isFloating ? "grab" : "default";
|
|
175
187
|
|
|
188
|
+
// ---- First-run onboarding popup --------------------------------------------
|
|
189
|
+
// Per-publication: shows the first time an editor opens Copilot for a site, then
|
|
190
|
+
// collapses to the (i) icon. We only mark the site "onboarded" once they actually
|
|
191
|
+
// engage (dismiss / open via the icon / switch a tab) - if they open and never
|
|
192
|
+
// touch it, it shows again next session. The 5s auto-fade alone does NOT onboard.
|
|
193
|
+
const onboardSite = publication || "default";
|
|
194
|
+
const onboardKey = `seo-copilot-onboarded-${onboardSite}`;
|
|
195
|
+
const onboardSessionKey = `seo-copilot-onboard-shown-${onboardSite}`;
|
|
196
|
+
const [popupMode, setPopupMode] = useState<"hidden" | "auto" | "persistent">("hidden");
|
|
197
|
+
const [popupClosing, setPopupClosing] = useState(false);
|
|
198
|
+
const onboardTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
199
|
+
|
|
200
|
+
useEffect(() => {
|
|
201
|
+
let onboarded = false;
|
|
202
|
+
let shownThisSession = false;
|
|
203
|
+
try { onboarded = localStorage.getItem(onboardKey) === "1"; } catch { /* ignore */ }
|
|
204
|
+
try { shownThisSession = sessionStorage.getItem(onboardSessionKey) === "1"; } catch { /* ignore */ }
|
|
205
|
+
if (!onboarded && !shownThisSession) {
|
|
206
|
+
setPopupMode("auto");
|
|
207
|
+
try { sessionStorage.setItem(onboardSessionKey, "1"); } catch { /* ignore */ }
|
|
208
|
+
onboardTimerRef.current = setTimeout(() => {
|
|
209
|
+
// Auto-fade to the (i) icon. Does NOT mark onboarded.
|
|
210
|
+
setPopupClosing(true);
|
|
211
|
+
setTimeout(() => { setPopupMode("hidden"); setPopupClosing(false); }, 180);
|
|
212
|
+
}, 5000);
|
|
213
|
+
}
|
|
214
|
+
return () => { if (onboardTimerRef.current) clearTimeout(onboardTimerRef.current); };
|
|
215
|
+
// Re-run only when the site changes.
|
|
216
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
217
|
+
}, [onboardKey, onboardSessionKey]);
|
|
218
|
+
|
|
219
|
+
const markOnboarded = useCallback(() => {
|
|
220
|
+
try { localStorage.setItem(onboardKey, "1"); } catch { /* ignore */ }
|
|
221
|
+
}, [onboardKey]);
|
|
222
|
+
|
|
223
|
+
const dismissPopup = useCallback(() => {
|
|
224
|
+
if (onboardTimerRef.current) clearTimeout(onboardTimerRef.current);
|
|
225
|
+
markOnboarded();
|
|
226
|
+
setPopupClosing(true);
|
|
227
|
+
setTimeout(() => { setPopupMode("hidden"); setPopupClosing(false); }, 180);
|
|
228
|
+
}, [markOnboarded]);
|
|
229
|
+
|
|
230
|
+
const openPopupPersistent = useCallback(() => {
|
|
231
|
+
if (onboardTimerRef.current) clearTimeout(onboardTimerRef.current);
|
|
232
|
+
markOnboarded();
|
|
233
|
+
setPopupClosing(false);
|
|
234
|
+
setPopupMode("persistent");
|
|
235
|
+
}, [markOnboarded]);
|
|
236
|
+
|
|
237
|
+
// Switching tabs counts as engagement - onboard the site and clear the popup.
|
|
238
|
+
const handleTabChange = useCallback((id: TabId) => {
|
|
239
|
+
markOnboarded();
|
|
240
|
+
if (onboardTimerRef.current) clearTimeout(onboardTimerRef.current);
|
|
241
|
+
setPopupMode((m) => (m === "hidden" ? m : "hidden"));
|
|
242
|
+
onActiveTabChange(id);
|
|
243
|
+
}, [markOnboarded, onActiveTabChange]);
|
|
244
|
+
|
|
176
245
|
const tabDefs = [
|
|
177
246
|
{ id: "summary" as TabId, label: "Summary", isHub: true, loading: summaryOps.isAnyLoading },
|
|
178
247
|
{ id: "keywords" as TabId, label: "Keywords", loading: keywordAnalysisState.isLoading || keywordAnalysisState.isVolumesLoading },
|
|
@@ -193,10 +262,14 @@ function PanelContent({
|
|
|
193
262
|
backgroundColor: PANEL_BG,
|
|
194
263
|
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif",
|
|
195
264
|
opacity: 1,
|
|
265
|
+
position: "relative",
|
|
196
266
|
}}
|
|
197
267
|
>
|
|
198
268
|
<style dangerouslySetInnerHTML={{ __html: INJECTED_CSS }} />
|
|
199
269
|
|
|
270
|
+
{/* First-run onboarding popup (collapses to the (i) icon in the header) */}
|
|
271
|
+
{popupMode !== "hidden" && <OnboardingCard onDismiss={dismissPopup} closing={popupClosing} />}
|
|
272
|
+
|
|
200
273
|
{/* Header */}
|
|
201
274
|
<div
|
|
202
275
|
onMouseDown={isFloating ? onDragStart : undefined}
|
|
@@ -222,6 +295,7 @@ function PanelContent({
|
|
|
222
295
|
</span>
|
|
223
296
|
</div>
|
|
224
297
|
<div style={{ display: "flex", alignItems: "center", gap: isFloating ? 4 : 6 }}>
|
|
298
|
+
<OnboardingInfoButton onClick={openPopupPersistent} />
|
|
225
299
|
{isFloating && onToggleFullscreen && (
|
|
226
300
|
<button
|
|
227
301
|
onClick={(e) => {
|
|
@@ -371,7 +445,7 @@ function PanelContent({
|
|
|
371
445
|
</div>
|
|
372
446
|
|
|
373
447
|
{/* Tab Bar */}
|
|
374
|
-
<TabBar tabs={tabDefs} activeTab={activeTab} onTabChange={
|
|
448
|
+
<TabBar tabs={tabDefs} activeTab={activeTab} onTabChange={handleTabChange} />
|
|
375
449
|
|
|
376
450
|
{/* Universal AI disclaimer - lives once at the panel level so every tab
|
|
377
451
|
inherits it. Subtle muted strip; the editor sees it on every screen. */}
|
|
@@ -413,6 +487,8 @@ function PanelContent({
|
|
|
413
487
|
seedKeywords={seedKeywords}
|
|
414
488
|
onSeedsChange={onSeedsChange}
|
|
415
489
|
onSelectPrimary={onSelectPrimary}
|
|
490
|
+
secondaryKeyword={effectiveSecondary}
|
|
491
|
+
onSelectSecondary={onSelectSecondary}
|
|
416
492
|
documentFields={documentFields}
|
|
417
493
|
documentId={documentId}
|
|
418
494
|
externalAnalysis={keywordAnalysisState}
|
|
@@ -424,6 +500,8 @@ function PanelContent({
|
|
|
424
500
|
analysis={keywordAnalysisState.analysis}
|
|
425
501
|
deepAnalysis={keywordAnalysisState.deepAnalysis}
|
|
426
502
|
documentFields={documentFields}
|
|
503
|
+
primaryKeyword={effectivePrimary}
|
|
504
|
+
secondaryKeyword={effectiveSecondary}
|
|
427
505
|
linkingSuggestions={linkingOps.suggestions}
|
|
428
506
|
linkCheckResults={technicalOps.linkCheckResults}
|
|
429
507
|
isAnyLoading={summaryOps.isAnyLoading}
|
|
@@ -458,16 +536,20 @@ function PanelContent({
|
|
|
458
536
|
documentId={documentId}
|
|
459
537
|
publication={publication}
|
|
460
538
|
text={text}
|
|
539
|
+
sanityBaseUrl={sanityBaseUrl}
|
|
540
|
+
documentType={documentType}
|
|
461
541
|
/>
|
|
462
542
|
</div>
|
|
463
543
|
<div style={{ display: activeTab === "meta" ? "block" : "none" }}>
|
|
464
|
-
<MetaTab documentFields={documentFields} primaryKeyword={effectivePrimary} isLoading={docLoading} />
|
|
544
|
+
<MetaTab documentFields={documentFields} primaryKeyword={effectivePrimary} secondaryKeyword={effectiveSecondary} isLoading={docLoading} />
|
|
465
545
|
</div>
|
|
466
546
|
<div style={{ display: activeTab === "technical" ? "block" : "none" }}>
|
|
467
547
|
<TechnicalTab
|
|
468
548
|
text={text}
|
|
469
549
|
documentFields={documentFields}
|
|
470
550
|
isLoading={docLoading}
|
|
551
|
+
primaryKeyword={effectivePrimary}
|
|
552
|
+
secondaryKeyword={effectiveSecondary}
|
|
471
553
|
linkCheckResults={technicalOps.linkCheckResults}
|
|
472
554
|
isLinkCheckLoading={technicalOps.isLinkCheckLoading}
|
|
473
555
|
linkCheckError={technicalOps.linkCheckError}
|
|
@@ -595,9 +677,27 @@ function SEOCopilotInner({ config, onClose }: { config: SEOCopilotConfig; onClos
|
|
|
595
677
|
const dragOffset = useRef<{ dx: number; dy: number } | null>(null);
|
|
596
678
|
const resizeStart = useRef<{ startX: number; startY: number; startW: number; startH: number } | null>(null);
|
|
597
679
|
|
|
598
|
-
const { text, isLoading: docLoading, documentFields, documentId } = useDocumentContent();
|
|
680
|
+
const { text, isLoading: docLoading, documentFields, documentId, documentType } = useDocumentContent();
|
|
599
681
|
const { apiUrl } = useConfig();
|
|
600
682
|
|
|
683
|
+
// Resolve which Sanity dataset (= MJH publication) to read from. Each Studio
|
|
684
|
+
// workspace is bound to exactly one dataset, so the CURRENT workspace's
|
|
685
|
+
// dataset IS the publication. Prefer an explicit config.publication override,
|
|
686
|
+
// otherwise use the live workspace dataset. This makes the plugin work on
|
|
687
|
+
// every publication (onclive, hcplive, ajmc, ...) with zero per-workspace
|
|
688
|
+
// config - without it, a plugin installed as `seoCopilot({ apiUrl })` sends
|
|
689
|
+
// no publication and the backend falls back to the wrong/empty dataset.
|
|
690
|
+
const workspace = useWorkspace();
|
|
691
|
+
const effectivePublication = config.publication || workspace?.dataset;
|
|
692
|
+
|
|
693
|
+
// Studio origin + basePath - used to build "Inside Sanity" links that open a
|
|
694
|
+
// suggested article in a NEW Studio tab (leaving the editor's current tab alone).
|
|
695
|
+
const sanityBaseUrl = useMemo(() => {
|
|
696
|
+
if (typeof window === "undefined") return undefined;
|
|
697
|
+
const basePath = (workspace?.basePath || "/").replace(/\/+$/, "");
|
|
698
|
+
return `${window.location.origin}${basePath}`;
|
|
699
|
+
}, [workspace?.basePath]);
|
|
700
|
+
|
|
601
701
|
const seedCacheKey = documentId ? `seo-copilot-cache-${documentId}` : "seo-copilot-cache-v2";
|
|
602
702
|
const loadSeedsFromCache = useCallback((): string[] => {
|
|
603
703
|
try {
|
|
@@ -621,6 +721,9 @@ function SEOCopilotInner({ config, onClose }: { config: SEOCopilotConfig; onClos
|
|
|
621
721
|
// Per-doc state - persisted under doc-scoped keys so a return to the doc restores everything
|
|
622
722
|
const selectedPrimaryKey = documentId ? `seo-copilot-primary-${documentId}` : "seo-copilot-primary-default";
|
|
623
723
|
const [selectedPrimary, setSelectedPrimary] = usePersistentState<string | undefined>(selectedPrimaryKey, undefined);
|
|
724
|
+
// Optional secondary target keyword - audits check the article against both.
|
|
725
|
+
const selectedSecondaryKey = documentId ? `seo-copilot-secondary-${documentId}` : "seo-copilot-secondary-default";
|
|
726
|
+
const [selectedSecondary, setSelectedSecondary] = usePersistentState<string>(selectedSecondaryKey, "");
|
|
624
727
|
|
|
625
728
|
// Reload seed cache when documentId changes (Sanity may reuse the inspector instance)
|
|
626
729
|
const seedsInitializedRef = useRef(false);
|
|
@@ -641,7 +744,7 @@ function SEOCopilotInner({ config, onClose }: { config: SEOCopilotConfig; onClos
|
|
|
641
744
|
const [chatOpen, setChatOpen] = usePersistentState<boolean>("seo-copilot-ui-chat-open-v35", false);
|
|
642
745
|
const [splitPercent, setSplitPercent] = usePersistentState<number>("seo-copilot-ui-split", 70);
|
|
643
746
|
|
|
644
|
-
const keywordAnalysisState = useKeywordAnalysis(text, apiUrl,
|
|
747
|
+
const keywordAnalysisState = useKeywordAnalysis(text, apiUrl, effectivePublication, seedKeywords, documentFields, selectedPrimary, documentId);
|
|
645
748
|
|
|
646
749
|
// Effective primary (matches PanelContent's resolution)
|
|
647
750
|
const effectivePrimary = selectedPrimary || keywordAnalysisState.analysis?.primaryKeyword?.term || "";
|
|
@@ -666,7 +769,7 @@ function SEOCopilotInner({ config, onClose }: { config: SEOCopilotConfig; onClos
|
|
|
666
769
|
}, [keywordAnalysisState.analysis, keywordAnalysisState.deepAnalysis]);
|
|
667
770
|
|
|
668
771
|
// Chat hook lifted here so in-flight streams survive PanelContent remount (undock)
|
|
669
|
-
const chatHookState = useSEOChat(apiUrl, text,
|
|
772
|
+
const chatHookState = useSEOChat(apiUrl, text, effectivePublication, keywordPanelData, documentId);
|
|
670
773
|
|
|
671
774
|
// AEO content suggestions - lifted to SEOCopilotInner so in-flight requests survive undock,
|
|
672
775
|
// and PERSISTED per-doc so generated suggestions come back after reload.
|
|
@@ -694,7 +797,7 @@ function SEOCopilotInner({ config, onClose }: { config: SEOCopilotConfig; onClos
|
|
|
694
797
|
setIsCSLoading(true);
|
|
695
798
|
setCsError(null);
|
|
696
799
|
try {
|
|
697
|
-
const data = await fetchContentSuggestions(apiUrl, text, effectivePrimary,
|
|
800
|
+
const data = await fetchContentSuggestions(apiUrl, text, effectivePrimary, effectivePublication);
|
|
698
801
|
if (aeoOpVersionRef.current !== myVersion) return;
|
|
699
802
|
if (
|
|
700
803
|
data.keyTakeaways.length === 0 &&
|
|
@@ -711,7 +814,7 @@ function SEOCopilotInner({ config, onClose }: { config: SEOCopilotConfig; onClos
|
|
|
711
814
|
}
|
|
712
815
|
if (aeoOpVersionRef.current !== myVersion) return;
|
|
713
816
|
setIsCSLoading(false);
|
|
714
|
-
}, [apiUrl, text, effectivePrimary,
|
|
817
|
+
}, [apiUrl, text, effectivePrimary, effectivePublication]);
|
|
715
818
|
|
|
716
819
|
// Smart Linking - lifted state, persisted per-doc so suggestions survive remount.
|
|
717
820
|
// Auto-runs when keywords stabilize; user can also refresh manually.
|
|
@@ -741,11 +844,13 @@ function SEOCopilotInner({ config, onClose }: { config: SEOCopilotConfig; onClos
|
|
|
741
844
|
}, [documentId]);
|
|
742
845
|
|
|
743
846
|
const supportingKeywordsForLinking = useMemo(() => {
|
|
744
|
-
|
|
847
|
+
const base = (keywordAnalysisState.analysis?.supportingKeywords || [])
|
|
745
848
|
.map((kw) => kw.term)
|
|
746
|
-
.filter(Boolean)
|
|
747
|
-
|
|
748
|
-
|
|
849
|
+
.filter(Boolean);
|
|
850
|
+
// Lead with the user's chosen secondary keyword so Linking weights it too.
|
|
851
|
+
const merged = selectedSecondary ? [selectedSecondary, ...base.filter((t) => t.toLowerCase() !== selectedSecondary.toLowerCase())] : base;
|
|
852
|
+
return merged.slice(0, 5);
|
|
853
|
+
}, [keywordAnalysisState.analysis, selectedSecondary]);
|
|
749
854
|
|
|
750
855
|
const refreshLinkingSuggestions = useCallback(async () => {
|
|
751
856
|
if (!text || text.trim().length < 50) return;
|
|
@@ -760,7 +865,7 @@ function SEOCopilotInner({ config, onClose }: { config: SEOCopilotConfig; onClos
|
|
|
760
865
|
effectivePrimary,
|
|
761
866
|
supportingKeywordsForLinking,
|
|
762
867
|
documentId,
|
|
763
|
-
|
|
868
|
+
effectivePublication
|
|
764
869
|
);
|
|
765
870
|
if (linkingVersionRef.current !== myVersion) return;
|
|
766
871
|
setLinkingSuggestions(suggestions);
|
|
@@ -771,7 +876,7 @@ function SEOCopilotInner({ config, onClose }: { config: SEOCopilotConfig; onClos
|
|
|
771
876
|
}
|
|
772
877
|
if (linkingVersionRef.current !== myVersion) return;
|
|
773
878
|
setIsLinkingLoading(false);
|
|
774
|
-
}, [apiUrl, text, effectivePrimary, supportingKeywordsForLinking, documentId,
|
|
879
|
+
}, [apiUrl, text, effectivePrimary, supportingKeywordsForLinking, documentId, effectivePublication]);
|
|
775
880
|
|
|
776
881
|
// Stale = the article changed materially since we last fetched suggestions.
|
|
777
882
|
const isLinkingStale = useMemo(() => {
|
|
@@ -900,7 +1005,7 @@ function SEOCopilotInner({ config, onClose }: { config: SEOCopilotConfig; onClos
|
|
|
900
1005
|
|
|
901
1006
|
const panelContent = (
|
|
902
1007
|
<PanelContent
|
|
903
|
-
initialPublication={
|
|
1008
|
+
initialPublication={effectivePublication}
|
|
904
1009
|
isFloating={isFloating}
|
|
905
1010
|
isFullscreen={isFullscreen}
|
|
906
1011
|
onToggleFloat={() => {
|
|
@@ -917,8 +1022,12 @@ function SEOCopilotInner({ config, onClose }: { config: SEOCopilotConfig; onClos
|
|
|
917
1022
|
docLoading={docLoading}
|
|
918
1023
|
documentFields={documentFields}
|
|
919
1024
|
documentId={documentId}
|
|
1025
|
+
documentType={documentType}
|
|
1026
|
+
sanityBaseUrl={sanityBaseUrl}
|
|
920
1027
|
selectedPrimary={selectedPrimary}
|
|
921
1028
|
onSelectPrimary={setSelectedPrimary}
|
|
1029
|
+
selectedSecondary={selectedSecondary}
|
|
1030
|
+
onSelectSecondary={setSelectedSecondary}
|
|
922
1031
|
activeTab={activeTab}
|
|
923
1032
|
onActiveTabChange={setActiveTab}
|
|
924
1033
|
chatOpen={chatOpen}
|