sanity-plugin-seo-copilot 0.2.5 → 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 +1123 -537
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1125 -539
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/KeywordPanel.tsx +164 -1
- package/src/components/OnboardingPopup.tsx +108 -0
- package/src/components/SEOCopilotPanel.tsx +105 -7
- package/src/components/styles.ts +8 -0
- package/src/components/tabs/LinkingTab.tsx +77 -4
- package/src/components/tabs/MetaTab.tsx +31 -109
- package/src/components/tabs/SummaryTab.tsx +19 -4
- package/src/components/tabs/TechnicalTab.tsx +132 -1
- package/src/hooks/useDocumentContent.ts +48 -47
- package/src/hooks/useKeywordAnalysis.ts +21 -4
- package/src/hooks/useSEOChat.ts +45 -9
- package/src/lib/api.ts +25 -7
- package/src/lib/documentExtract.ts +268 -257
- package/src/lib/scoring.ts +41 -14
- package/src/lib/summary.ts +116 -27
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;
|
|
@@ -173,7 +177,7 @@ function LightbulbButton({ onClick, isLoading }: { onClick: () => void; isLoadin
|
|
|
173
177
|
pointerEvents: "none",
|
|
174
178
|
zIndex: 10,
|
|
175
179
|
}}>
|
|
176
|
-
|
|
180
|
+
See suggestion
|
|
177
181
|
</span>
|
|
178
182
|
)}
|
|
179
183
|
</span>
|
|
@@ -424,6 +428,128 @@ function PrimaryKeywordSelector({
|
|
|
424
428
|
);
|
|
425
429
|
}
|
|
426
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
|
+
|
|
427
553
|
const PLACEMENT_FILTERS: { key: PlacementKey; label: string; letter: string }[] = [
|
|
428
554
|
{ key: "inBody", label: "Body", letter: "B" },
|
|
429
555
|
{ key: "inTitle", label: "Title", letter: "T" },
|
|
@@ -900,6 +1026,8 @@ export function KeywordPanel({
|
|
|
900
1026
|
seedKeywords = [],
|
|
901
1027
|
onSeedsChange,
|
|
902
1028
|
onSelectPrimary,
|
|
1029
|
+
secondaryKeyword = "",
|
|
1030
|
+
onSelectSecondary,
|
|
903
1031
|
documentFields,
|
|
904
1032
|
documentId,
|
|
905
1033
|
externalAnalysis,
|
|
@@ -994,8 +1122,34 @@ export function KeywordPanel({
|
|
|
994
1122
|
? selectedPrimaryTerm
|
|
995
1123
|
: candidates[0]?.term ?? "";
|
|
996
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
|
+
|
|
997
1139
|
return (
|
|
998
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
|
+
|
|
999
1153
|
{/* Desired Keywords */}
|
|
1000
1154
|
{onSeedsChange && (
|
|
1001
1155
|
<SeedKeywordInput seeds={seedKeywords} onSeedsChange={onSeedsChange} />
|
|
@@ -1009,6 +1163,15 @@ export function KeywordPanel({
|
|
|
1009
1163
|
publication={publication}
|
|
1010
1164
|
/>
|
|
1011
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
|
+
|
|
1012
1175
|
{/* Supporting Keywords */}
|
|
1013
1176
|
{suggestedKeywords.length > 0 && (
|
|
1014
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
|
+
}
|
|
@@ -8,6 +8,7 @@ import { useConfig, ConfigProvider } from "./ConfigContext";
|
|
|
8
8
|
import { KeywordPanel } from "./KeywordPanel";
|
|
9
9
|
import { ChatPanel } from "./ChatPanel";
|
|
10
10
|
import { TabBar } from "./TabBar";
|
|
11
|
+
import { OnboardingInfoButton, OnboardingCard } from "./OnboardingPopup";
|
|
11
12
|
import { SummaryTab } from "./tabs/SummaryTab";
|
|
12
13
|
import { AEOTab } from "./tabs/AEOTab";
|
|
13
14
|
import { LinkingTab } from "./tabs/LinkingTab";
|
|
@@ -49,8 +50,12 @@ interface PanelContentProps {
|
|
|
49
50
|
docLoading: boolean;
|
|
50
51
|
documentFields: import("../lib/types").DocumentFields;
|
|
51
52
|
documentId?: string;
|
|
53
|
+
documentType?: string;
|
|
54
|
+
sanityBaseUrl?: string;
|
|
52
55
|
selectedPrimary?: string;
|
|
53
56
|
onSelectPrimary?: (term: string) => void;
|
|
57
|
+
selectedSecondary?: string;
|
|
58
|
+
onSelectSecondary?: (term: string) => void;
|
|
54
59
|
// Lifted state - survives float/dock toggle (which remounts PanelContent)
|
|
55
60
|
activeTab: TabId;
|
|
56
61
|
onActiveTabChange: (id: TabId) => void;
|
|
@@ -117,8 +122,12 @@ function PanelContent({
|
|
|
117
122
|
docLoading,
|
|
118
123
|
documentFields,
|
|
119
124
|
documentId,
|
|
125
|
+
documentType,
|
|
126
|
+
sanityBaseUrl,
|
|
120
127
|
selectedPrimary,
|
|
121
128
|
onSelectPrimary,
|
|
129
|
+
selectedSecondary,
|
|
130
|
+
onSelectSecondary,
|
|
122
131
|
activeTab,
|
|
123
132
|
onActiveTabChange,
|
|
124
133
|
chatOpen,
|
|
@@ -141,6 +150,8 @@ function PanelContent({
|
|
|
141
150
|
selectedPrimary ||
|
|
142
151
|
externalAnalysis.analysis?.primaryKeyword?.term ||
|
|
143
152
|
"";
|
|
153
|
+
// Effective secondary keyword - purely the user's optional choice (no auto-default).
|
|
154
|
+
const effectiveSecondary = selectedSecondary || "";
|
|
144
155
|
|
|
145
156
|
// Draggable divider between tab content and chat - splitPercent is lifted to parent for persistence
|
|
146
157
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
@@ -174,6 +185,63 @@ function PanelContent({
|
|
|
174
185
|
|
|
175
186
|
const headerCursor = isFloating ? "grab" : "default";
|
|
176
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
|
+
|
|
177
245
|
const tabDefs = [
|
|
178
246
|
{ id: "summary" as TabId, label: "Summary", isHub: true, loading: summaryOps.isAnyLoading },
|
|
179
247
|
{ id: "keywords" as TabId, label: "Keywords", loading: keywordAnalysisState.isLoading || keywordAnalysisState.isVolumesLoading },
|
|
@@ -194,10 +262,14 @@ function PanelContent({
|
|
|
194
262
|
backgroundColor: PANEL_BG,
|
|
195
263
|
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif",
|
|
196
264
|
opacity: 1,
|
|
265
|
+
position: "relative",
|
|
197
266
|
}}
|
|
198
267
|
>
|
|
199
268
|
<style dangerouslySetInnerHTML={{ __html: INJECTED_CSS }} />
|
|
200
269
|
|
|
270
|
+
{/* First-run onboarding popup (collapses to the (i) icon in the header) */}
|
|
271
|
+
{popupMode !== "hidden" && <OnboardingCard onDismiss={dismissPopup} closing={popupClosing} />}
|
|
272
|
+
|
|
201
273
|
{/* Header */}
|
|
202
274
|
<div
|
|
203
275
|
onMouseDown={isFloating ? onDragStart : undefined}
|
|
@@ -223,6 +295,7 @@ function PanelContent({
|
|
|
223
295
|
</span>
|
|
224
296
|
</div>
|
|
225
297
|
<div style={{ display: "flex", alignItems: "center", gap: isFloating ? 4 : 6 }}>
|
|
298
|
+
<OnboardingInfoButton onClick={openPopupPersistent} />
|
|
226
299
|
{isFloating && onToggleFullscreen && (
|
|
227
300
|
<button
|
|
228
301
|
onClick={(e) => {
|
|
@@ -372,7 +445,7 @@ function PanelContent({
|
|
|
372
445
|
</div>
|
|
373
446
|
|
|
374
447
|
{/* Tab Bar */}
|
|
375
|
-
<TabBar tabs={tabDefs} activeTab={activeTab} onTabChange={
|
|
448
|
+
<TabBar tabs={tabDefs} activeTab={activeTab} onTabChange={handleTabChange} />
|
|
376
449
|
|
|
377
450
|
{/* Universal AI disclaimer - lives once at the panel level so every tab
|
|
378
451
|
inherits it. Subtle muted strip; the editor sees it on every screen. */}
|
|
@@ -414,6 +487,8 @@ function PanelContent({
|
|
|
414
487
|
seedKeywords={seedKeywords}
|
|
415
488
|
onSeedsChange={onSeedsChange}
|
|
416
489
|
onSelectPrimary={onSelectPrimary}
|
|
490
|
+
secondaryKeyword={effectiveSecondary}
|
|
491
|
+
onSelectSecondary={onSelectSecondary}
|
|
417
492
|
documentFields={documentFields}
|
|
418
493
|
documentId={documentId}
|
|
419
494
|
externalAnalysis={keywordAnalysisState}
|
|
@@ -425,6 +500,8 @@ function PanelContent({
|
|
|
425
500
|
analysis={keywordAnalysisState.analysis}
|
|
426
501
|
deepAnalysis={keywordAnalysisState.deepAnalysis}
|
|
427
502
|
documentFields={documentFields}
|
|
503
|
+
primaryKeyword={effectivePrimary}
|
|
504
|
+
secondaryKeyword={effectiveSecondary}
|
|
428
505
|
linkingSuggestions={linkingOps.suggestions}
|
|
429
506
|
linkCheckResults={technicalOps.linkCheckResults}
|
|
430
507
|
isAnyLoading={summaryOps.isAnyLoading}
|
|
@@ -459,16 +536,20 @@ function PanelContent({
|
|
|
459
536
|
documentId={documentId}
|
|
460
537
|
publication={publication}
|
|
461
538
|
text={text}
|
|
539
|
+
sanityBaseUrl={sanityBaseUrl}
|
|
540
|
+
documentType={documentType}
|
|
462
541
|
/>
|
|
463
542
|
</div>
|
|
464
543
|
<div style={{ display: activeTab === "meta" ? "block" : "none" }}>
|
|
465
|
-
<MetaTab documentFields={documentFields} primaryKeyword={effectivePrimary} isLoading={docLoading} />
|
|
544
|
+
<MetaTab documentFields={documentFields} primaryKeyword={effectivePrimary} secondaryKeyword={effectiveSecondary} isLoading={docLoading} />
|
|
466
545
|
</div>
|
|
467
546
|
<div style={{ display: activeTab === "technical" ? "block" : "none" }}>
|
|
468
547
|
<TechnicalTab
|
|
469
548
|
text={text}
|
|
470
549
|
documentFields={documentFields}
|
|
471
550
|
isLoading={docLoading}
|
|
551
|
+
primaryKeyword={effectivePrimary}
|
|
552
|
+
secondaryKeyword={effectiveSecondary}
|
|
472
553
|
linkCheckResults={technicalOps.linkCheckResults}
|
|
473
554
|
isLinkCheckLoading={technicalOps.isLinkCheckLoading}
|
|
474
555
|
linkCheckError={technicalOps.linkCheckError}
|
|
@@ -596,7 +677,7 @@ function SEOCopilotInner({ config, onClose }: { config: SEOCopilotConfig; onClos
|
|
|
596
677
|
const dragOffset = useRef<{ dx: number; dy: number } | null>(null);
|
|
597
678
|
const resizeStart = useRef<{ startX: number; startY: number; startW: number; startH: number } | null>(null);
|
|
598
679
|
|
|
599
|
-
const { text, isLoading: docLoading, documentFields, documentId } = useDocumentContent();
|
|
680
|
+
const { text, isLoading: docLoading, documentFields, documentId, documentType } = useDocumentContent();
|
|
600
681
|
const { apiUrl } = useConfig();
|
|
601
682
|
|
|
602
683
|
// Resolve which Sanity dataset (= MJH publication) to read from. Each Studio
|
|
@@ -609,6 +690,14 @@ function SEOCopilotInner({ config, onClose }: { config: SEOCopilotConfig; onClos
|
|
|
609
690
|
const workspace = useWorkspace();
|
|
610
691
|
const effectivePublication = config.publication || workspace?.dataset;
|
|
611
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
|
+
|
|
612
701
|
const seedCacheKey = documentId ? `seo-copilot-cache-${documentId}` : "seo-copilot-cache-v2";
|
|
613
702
|
const loadSeedsFromCache = useCallback((): string[] => {
|
|
614
703
|
try {
|
|
@@ -632,6 +721,9 @@ function SEOCopilotInner({ config, onClose }: { config: SEOCopilotConfig; onClos
|
|
|
632
721
|
// Per-doc state - persisted under doc-scoped keys so a return to the doc restores everything
|
|
633
722
|
const selectedPrimaryKey = documentId ? `seo-copilot-primary-${documentId}` : "seo-copilot-primary-default";
|
|
634
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, "");
|
|
635
727
|
|
|
636
728
|
// Reload seed cache when documentId changes (Sanity may reuse the inspector instance)
|
|
637
729
|
const seedsInitializedRef = useRef(false);
|
|
@@ -752,11 +844,13 @@ function SEOCopilotInner({ config, onClose }: { config: SEOCopilotConfig; onClos
|
|
|
752
844
|
}, [documentId]);
|
|
753
845
|
|
|
754
846
|
const supportingKeywordsForLinking = useMemo(() => {
|
|
755
|
-
|
|
847
|
+
const base = (keywordAnalysisState.analysis?.supportingKeywords || [])
|
|
756
848
|
.map((kw) => kw.term)
|
|
757
|
-
.filter(Boolean)
|
|
758
|
-
|
|
759
|
-
|
|
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]);
|
|
760
854
|
|
|
761
855
|
const refreshLinkingSuggestions = useCallback(async () => {
|
|
762
856
|
if (!text || text.trim().length < 50) return;
|
|
@@ -928,8 +1022,12 @@ function SEOCopilotInner({ config, onClose }: { config: SEOCopilotConfig; onClos
|
|
|
928
1022
|
docLoading={docLoading}
|
|
929
1023
|
documentFields={documentFields}
|
|
930
1024
|
documentId={documentId}
|
|
1025
|
+
documentType={documentType}
|
|
1026
|
+
sanityBaseUrl={sanityBaseUrl}
|
|
931
1027
|
selectedPrimary={selectedPrimary}
|
|
932
1028
|
onSelectPrimary={setSelectedPrimary}
|
|
1029
|
+
selectedSecondary={selectedSecondary}
|
|
1030
|
+
onSelectSecondary={setSelectedSecondary}
|
|
933
1031
|
activeTab={activeTab}
|
|
934
1032
|
onActiveTabChange={setActiveTab}
|
|
935
1033
|
chatOpen={chatOpen}
|
package/src/components/styles.ts
CHANGED
|
@@ -30,6 +30,14 @@ export const INJECTED_CSS = `
|
|
|
30
30
|
0%, 100% { opacity: 0.5; }
|
|
31
31
|
50% { opacity: 1; }
|
|
32
32
|
}
|
|
33
|
+
@keyframes onboard-in {
|
|
34
|
+
from { opacity: 0; transform: translateY(-6px) scale(0.97); }
|
|
35
|
+
to { opacity: 1; transform: translateY(0) scale(1); }
|
|
36
|
+
}
|
|
37
|
+
@keyframes onboard-out {
|
|
38
|
+
from { opacity: 1; transform: translateY(0) scale(1); }
|
|
39
|
+
to { opacity: 0; transform: translateY(-6px) scale(0.97); }
|
|
40
|
+
}
|
|
33
41
|
.prose-chat { font-size: 12.5px; line-height: 1.65; color: #475569; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; }
|
|
34
42
|
.prose-chat h1 { font-size: 14px; font-weight: 700; color: #1e293b; margin: 10px 0 5px 0; line-height: 1.35; }
|
|
35
43
|
.prose-chat h2, .prose-chat h3 { font-size: 13px; font-weight: 700; color: #1e293b; margin: 10px 0 5px 0; line-height: 1.35; }
|