sanity-plugin-seo-copilot 0.2.12 → 0.2.14
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 +1506 -1086
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1474 -1054
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/KeywordPanel.tsx +190 -176
- package/src/components/ReportProblemButton.tsx +212 -0
- package/src/components/SEOCopilotPanel.tsx +37 -9
- package/src/components/styles.ts +7 -0
- package/src/components/tabs/AEOTab.tsx +5 -1
- package/src/components/tabs/LinkingTab.tsx +39 -13
- package/src/components/tabs/MetaTab.tsx +122 -24
- package/src/components/tabs/SummaryTab.tsx +21 -15
- package/src/components/tabs/TechnicalTab.tsx +276 -269
- package/src/hooks/useKeywordAnalysis.ts +8 -7
- package/src/lib/api.ts +21 -52
- package/src/lib/documentExtract.ts +168 -14
- package/src/lib/scoring.ts +4 -4
- package/src/lib/summary.ts +23 -14
- package/src/lib/types.ts +12 -0
package/package.json
CHANGED
|
@@ -68,15 +68,6 @@ const cardStyle = {
|
|
|
68
68
|
padding: "14px",
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
-
function BulletItem({ text }: { text: string }) {
|
|
72
|
-
return (
|
|
73
|
-
<div style={{ display: "flex", gap: 8, alignItems: "flex-start", padding: "2px 0" }}>
|
|
74
|
-
<div style={{ width: 6, height: 6, borderRadius: "50%", marginTop: 6, background: MJH_GOLD, flexShrink: 0 }} />
|
|
75
|
-
<span style={{ fontSize: 12, color: "#1f2937", lineHeight: 1.6 }}>{text}</span>
|
|
76
|
-
</div>
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
71
|
interface KeywordHelpSuggestion {
|
|
81
72
|
type: "change" | "add";
|
|
82
73
|
original?: string;
|
|
@@ -430,129 +421,6 @@ function PrimaryKeywordSelector({
|
|
|
430
421
|
);
|
|
431
422
|
}
|
|
432
423
|
|
|
433
|
-
function SecondaryKeywordSelector({
|
|
434
|
-
options,
|
|
435
|
-
selectedTerm,
|
|
436
|
-
onSelect,
|
|
437
|
-
}: {
|
|
438
|
-
options: { term: string; volume: number | null }[];
|
|
439
|
-
selectedTerm: string;
|
|
440
|
-
onSelect: (term: string) => void;
|
|
441
|
-
}) {
|
|
442
|
-
const [customInputOpen, setCustomInputOpen] = useState(false);
|
|
443
|
-
const [customValue, setCustomValue] = useState("");
|
|
444
|
-
|
|
445
|
-
const handleCustomSubmit = () => {
|
|
446
|
-
const trimmed = customValue.trim();
|
|
447
|
-
if (trimmed) {
|
|
448
|
-
onSelect(trimmed);
|
|
449
|
-
setCustomValue("");
|
|
450
|
-
setCustomInputOpen(false);
|
|
451
|
-
}
|
|
452
|
-
};
|
|
453
|
-
|
|
454
|
-
// The selected secondary may be a custom term not present in `options` - append it
|
|
455
|
-
// so the radio still shows as selected. Case-insensitive check so a filtered-out
|
|
456
|
-
// primary (removed via lowercase comparison) is not re-added here.
|
|
457
|
-
const opts = selectedTerm && !options.some((o) => o.term.toLowerCase() === selectedTerm.toLowerCase())
|
|
458
|
-
? [...options, { term: selectedTerm, volume: null }]
|
|
459
|
-
: options;
|
|
460
|
-
|
|
461
|
-
return (
|
|
462
|
-
<div style={cardStyle}>
|
|
463
|
-
<SectionHeader
|
|
464
|
-
label="Secondary Keyword"
|
|
465
|
-
iconColor={MJH_BLUE}
|
|
466
|
-
actionButton={
|
|
467
|
-
<div style={{ display: "flex", alignItems: "center", gap: 6 }}>
|
|
468
|
-
<span style={{ fontSize: 9, fontWeight: 700, letterSpacing: "0.05em", textTransform: "uppercase", color: "#9ca3af" }}>Optional</span>
|
|
469
|
-
<PencilButton onClick={() => setCustomInputOpen(!customInputOpen)} active={customInputOpen} />
|
|
470
|
-
</div>
|
|
471
|
-
}
|
|
472
|
-
/>
|
|
473
|
-
|
|
474
|
-
<div style={{ fontSize: 11, color: "#4b5563", lineHeight: 1.5, marginBottom: 8 }}>
|
|
475
|
-
Pick one more keyword to optimize for. Copilot then checks your title, meta, URL, headings, and images against both keywords.
|
|
476
|
-
</div>
|
|
477
|
-
|
|
478
|
-
{customInputOpen && (
|
|
479
|
-
<div style={{ marginBottom: 8, display: "flex", gap: 6 }}>
|
|
480
|
-
<input
|
|
481
|
-
type="text"
|
|
482
|
-
value={customValue}
|
|
483
|
-
onChange={(e) => setCustomValue(e.target.value)}
|
|
484
|
-
onKeyDown={(e) => { if (e.key === "Enter") handleCustomSubmit(); }}
|
|
485
|
-
placeholder="Type a custom secondary keyword"
|
|
486
|
-
autoFocus
|
|
487
|
-
style={{ flex: 1, padding: "5px 8px", fontSize: 12, borderRadius: 8, border: "1px solid #e5e7eb", outline: "none", fontFamily: "inherit" }}
|
|
488
|
-
/>
|
|
489
|
-
<button
|
|
490
|
-
onClick={handleCustomSubmit}
|
|
491
|
-
disabled={!customValue.trim()}
|
|
492
|
-
style={{
|
|
493
|
-
padding: "5px 10px", fontSize: 11, fontWeight: 600, borderRadius: 6, border: "none",
|
|
494
|
-
background: customValue.trim() ? MJH_BLUE : "#e5e7eb",
|
|
495
|
-
color: customValue.trim() ? "#ffffff" : "#9ca3af",
|
|
496
|
-
cursor: customValue.trim() ? "pointer" : "not-allowed",
|
|
497
|
-
}}
|
|
498
|
-
>
|
|
499
|
-
Set
|
|
500
|
-
</button>
|
|
501
|
-
</div>
|
|
502
|
-
)}
|
|
503
|
-
|
|
504
|
-
<div style={{ display: "flex", flexDirection: "column", gap: 6 }}>
|
|
505
|
-
{/* None option - secondary is optional */}
|
|
506
|
-
<SecondaryOptionRow term="" label="None" selected={!selectedTerm} onSelect={() => onSelect("")} />
|
|
507
|
-
{opts.map((o) => (
|
|
508
|
-
<SecondaryOptionRow
|
|
509
|
-
key={o.term}
|
|
510
|
-
term={o.term}
|
|
511
|
-
label={o.term}
|
|
512
|
-
volume={o.volume}
|
|
513
|
-
selected={o.term === selectedTerm}
|
|
514
|
-
onSelect={() => onSelect(o.term)}
|
|
515
|
-
/>
|
|
516
|
-
))}
|
|
517
|
-
</div>
|
|
518
|
-
</div>
|
|
519
|
-
);
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
function SecondaryOptionRow({ term, label, volume, selected, onSelect }: { term: string; label: string; volume?: number | null; selected: boolean; onSelect: () => void }) {
|
|
523
|
-
return (
|
|
524
|
-
<div
|
|
525
|
-
onClick={onSelect}
|
|
526
|
-
style={{
|
|
527
|
-
display: "flex",
|
|
528
|
-
alignItems: "center",
|
|
529
|
-
gap: 8,
|
|
530
|
-
padding: "6px 8px",
|
|
531
|
-
borderRadius: 8,
|
|
532
|
-
cursor: "pointer",
|
|
533
|
-
background: selected ? "rgba(0,93,172,0.06)" : "transparent",
|
|
534
|
-
border: selected ? "1px solid rgba(0,93,172,0.2)" : "1px solid transparent",
|
|
535
|
-
transition: "all 150ms",
|
|
536
|
-
}}
|
|
537
|
-
>
|
|
538
|
-
<div style={{
|
|
539
|
-
width: 14, height: 14, borderRadius: "50%",
|
|
540
|
-
border: selected ? "none" : "2px solid #d1d5db",
|
|
541
|
-
background: selected ? MJH_BLUE : "transparent",
|
|
542
|
-
flexShrink: 0, display: "flex", alignItems: "center", justifyContent: "center",
|
|
543
|
-
}}>
|
|
544
|
-
{selected && <div style={{ width: 6, height: 6, borderRadius: "50%", background: "#ffffff" }} />}
|
|
545
|
-
</div>
|
|
546
|
-
<span style={{ fontSize: 12, fontWeight: selected ? 600 : 400, color: term ? (selected ? "#00468a" : "#374151") : "#6b7280", flex: 1, minWidth: 0 }}>
|
|
547
|
-
{label}
|
|
548
|
-
</span>
|
|
549
|
-
{volume != null && (
|
|
550
|
-
<span style={{ fontSize: 11, fontWeight: 600, color: "#1f2937" }}>{volume === 0 ? "N/A" : `${abbrevVol(volume)}/mo`}</span>
|
|
551
|
-
)}
|
|
552
|
-
</div>
|
|
553
|
-
);
|
|
554
|
-
}
|
|
555
|
-
|
|
556
424
|
const PLACEMENT_FILTERS: { key: PlacementKey; label: string; letter: string }[] = [
|
|
557
425
|
{ key: "inBody", label: "Body", letter: "B" },
|
|
558
426
|
{ key: "inTitle", label: "Title", letter: "T" },
|
|
@@ -574,6 +442,13 @@ function computePlacementClient(term: string, content: string, fields?: Document
|
|
|
574
442
|
};
|
|
575
443
|
}
|
|
576
444
|
|
|
445
|
+
// Colorblind-safe purple (matches the ScoreDonut section-fit slice). Used as the
|
|
446
|
+
// distinct accent for the secondary-keyword chooser folded into Supporting Keywords.
|
|
447
|
+
const SECONDARY_PURPLE = "#9B59B6";
|
|
448
|
+
// Darker purple for small (<=12px) text so it clears WCAG AA 4.5:1 on the light panel.
|
|
449
|
+
// Circles, dots and borders keep the brighter brand purple above.
|
|
450
|
+
const SECONDARY_PURPLE_TEXT = "#7D3C98";
|
|
451
|
+
|
|
577
452
|
function SuggestedKeywordsCard({
|
|
578
453
|
keywords,
|
|
579
454
|
text,
|
|
@@ -583,6 +458,9 @@ function SuggestedKeywordsCard({
|
|
|
583
458
|
refreshVolumes,
|
|
584
459
|
isVolumesLoading,
|
|
585
460
|
documentId,
|
|
461
|
+
secondaryKeyword,
|
|
462
|
+
onSelectSecondary,
|
|
463
|
+
primaryTerm,
|
|
586
464
|
}: {
|
|
587
465
|
keywords: SuggestedKeyword[];
|
|
588
466
|
text: string;
|
|
@@ -592,6 +470,9 @@ function SuggestedKeywordsCard({
|
|
|
592
470
|
refreshVolumes?: () => void;
|
|
593
471
|
isVolumesLoading?: boolean;
|
|
594
472
|
documentId?: string;
|
|
473
|
+
secondaryKeyword?: string;
|
|
474
|
+
onSelectSecondary?: (term: string) => void;
|
|
475
|
+
primaryTerm?: string;
|
|
595
476
|
}) {
|
|
596
477
|
// Per-doc persistence: manual keywords, generated "more" keywords, and cached
|
|
597
478
|
// AI keyword help survive dock/undock and full page reload.
|
|
@@ -614,6 +495,12 @@ function SuggestedKeywordsCard({
|
|
|
614
495
|
[]
|
|
615
496
|
);
|
|
616
497
|
const [isGeneratingMore, setIsGeneratingMore] = useState(false);
|
|
498
|
+
// Secondary-keyword selection mode: when on, supporting rows swap their status dot
|
|
499
|
+
// for a clickable purple circle so the editor can pick one as the secondary target.
|
|
500
|
+
const [secSelecting, setSecSelecting] = useState(false);
|
|
501
|
+
// Entering selection mode expands the list so a circle appears next to EVERY supporting
|
|
502
|
+
// keyword (spec), not just the first INITIAL_SHOW rows visible while collapsed.
|
|
503
|
+
const startSecSelecting = () => { setExpanded(true); setSecSelecting(true); };
|
|
617
504
|
const [sortAsc, setSortAsc] = usePersistentState<boolean>("seo-copilot-ui-keywords-sort-asc", false);
|
|
618
505
|
// Active filters - persist as array since JSON.stringify can't round-trip a Set.
|
|
619
506
|
const filtersKey = `seo-copilot-ui-keywords-filters-${docScope}`;
|
|
@@ -756,10 +643,26 @@ function SuggestedKeywordsCard({
|
|
|
756
643
|
});
|
|
757
644
|
|
|
758
645
|
// Merge extra generated keywords into the list
|
|
759
|
-
const
|
|
646
|
+
const merged = [...sorted, ...extraKeywords.filter((ek) => !sorted.some((s) => s.term.toLowerCase() === ek.term.toLowerCase()))];
|
|
647
|
+
// Hide N/A (no-search-volume) keywords entirely - editors only want terms with real volume.
|
|
648
|
+
// Two guards stop this from ever flashing an empty list: (1) while volumes are still loading
|
|
649
|
+
// every term reads as 0, so keep showing them until the lookup settles; (2) if NOTHING has
|
|
650
|
+
// volume (e.g. SEMrush failed, or a very niche topic) fall back to showing all of them.
|
|
651
|
+
const hasVol = (k: SuggestedKeyword) => k.volume != null && k.volume > 0;
|
|
652
|
+
const withVol = merged.filter(hasVol);
|
|
653
|
+
const allKeywords = isVolumesLoading || withVol.length === 0 ? merged : withVol;
|
|
760
654
|
const visible = expanded ? allKeywords : allKeywords.slice(0, INITIAL_SHOW);
|
|
761
655
|
const hiddenCount = allKeywords.length - INITIAL_SHOW;
|
|
762
656
|
const missingCount = keywords.filter((kw) => !kw.inContent).length;
|
|
657
|
+
// Secondary-keyword matching is case-insensitive so a stored secondary still highlights
|
|
658
|
+
// its row after re-analysis re-cases the term. `secondaryInList` flags an orphan secondary
|
|
659
|
+
// (set but no longer present in the list) so the banner can say so. `isPrimaryRow` stops the
|
|
660
|
+
// active primary from being offered as its own secondary.
|
|
661
|
+
const secLower = (secondaryKeyword || "").toLowerCase();
|
|
662
|
+
const primaryLower = (primaryTerm || "").toLowerCase();
|
|
663
|
+
const isSecondaryRow = (term: string) => secLower !== "" && term.toLowerCase() === secLower;
|
|
664
|
+
const isPrimaryRow = (term: string) => primaryLower !== "" && term.toLowerCase() === primaryLower;
|
|
665
|
+
const secondaryInList = secLower !== "" && allKeywords.some((k) => k.term.toLowerCase() === secLower);
|
|
763
666
|
|
|
764
667
|
const generateMoreKeywords = async () => {
|
|
765
668
|
setIsGeneratingMore(true);
|
|
@@ -783,8 +686,24 @@ function SuggestedKeywordsCard({
|
|
|
783
686
|
setIsGeneratingMore(false);
|
|
784
687
|
};
|
|
785
688
|
|
|
689
|
+
// Auto-backfill ONCE per document: if, after volumes settle, the list is thin on real-volume
|
|
690
|
+
// terms, pull more keywords a single time so the editor sees a full list. Bounded to one
|
|
691
|
+
// backfill per document open (the card remounts per document) so it never loops or burns the
|
|
692
|
+
// keyword API on every keystroke or secondary change.
|
|
693
|
+
const didBackfillRef = useRef(false);
|
|
694
|
+
useEffect(() => {
|
|
695
|
+
if (didBackfillRef.current) return;
|
|
696
|
+
if (isVolumesLoading || isGeneratingMore || keywords.length === 0) return;
|
|
697
|
+
didBackfillRef.current = true;
|
|
698
|
+
const volCount = [...keywords, ...extraKeywords].filter((k) => k.volume != null && k.volume > 0).length;
|
|
699
|
+
if (volCount < 8) generateMoreKeywords();
|
|
700
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
701
|
+
}, [keywords, isVolumesLoading]);
|
|
702
|
+
|
|
786
703
|
return (
|
|
787
|
-
<div style={
|
|
704
|
+
<div style={secSelecting
|
|
705
|
+
? { ...cardStyle, border: `1.5px solid ${SECONDARY_PURPLE}`, boxShadow: [cardStyle.boxShadow, `0 0 0 1px rgba(155,89,182,0.25)`].filter(Boolean).join(", ") }
|
|
706
|
+
: cardStyle}>
|
|
788
707
|
{/* Header row with count, sort, filter, pencil */}
|
|
789
708
|
<div style={{ display: "flex", alignItems: "center", gap: 6, marginBottom: 8 }}>
|
|
790
709
|
<div style={{ width: 6, height: 6, borderRadius: "50%", background: MJH_BLUE, flexShrink: 0 }} />
|
|
@@ -902,6 +821,76 @@ function SuggestedKeywordsCard({
|
|
|
902
821
|
<PencilButton onClick={() => setManualInputOpen(!manualInputOpen)} active={manualInputOpen} />
|
|
903
822
|
</div>
|
|
904
823
|
|
|
824
|
+
{/* Secondary-keyword chooser - folded into Supporting Keywords per spec.
|
|
825
|
+
Idle: a clickable purple notice. Selecting: a hint + cancel. Chosen: the
|
|
826
|
+
picked term in purple with Change / clear. */}
|
|
827
|
+
{/* Screen-reader announcement when selection mode toggles on. */}
|
|
828
|
+
<span aria-live="polite" style={{ position: "absolute", width: 1, height: 1, padding: 0, margin: -1, overflow: "hidden", clip: "rect(0 0 0 0)", whiteSpace: "nowrap", border: 0 }}>
|
|
829
|
+
{secSelecting ? "Selection mode on. Pick a keyword below to set it as the secondary keyword." : ""}
|
|
830
|
+
</span>
|
|
831
|
+
{onSelectSecondary && (
|
|
832
|
+
secSelecting ? (
|
|
833
|
+
<div style={{
|
|
834
|
+
display: "flex", alignItems: "center", justifyContent: "space-between", gap: 8,
|
|
835
|
+
marginBottom: 8, padding: "5px 10px", borderRadius: 8,
|
|
836
|
+
background: "rgba(155,89,182,0.08)", border: `1px solid rgba(155,89,182,0.35)`,
|
|
837
|
+
}}>
|
|
838
|
+
<span style={{ fontSize: 11, fontWeight: 600, color: SECONDARY_PURPLE_TEXT }}>
|
|
839
|
+
Pick a keyword below to set as secondary.
|
|
840
|
+
</span>
|
|
841
|
+
<button
|
|
842
|
+
onClick={() => setSecSelecting(false)}
|
|
843
|
+
style={{ background: "none", border: "none", cursor: "pointer", fontSize: 11, fontWeight: 600, color: "#6b7280", padding: 2, fontFamily: "inherit" }}
|
|
844
|
+
>
|
|
845
|
+
Cancel
|
|
846
|
+
</button>
|
|
847
|
+
</div>
|
|
848
|
+
) : secondaryKeyword ? (
|
|
849
|
+
<div style={{
|
|
850
|
+
display: "flex", alignItems: "center", gap: 8, marginBottom: 8,
|
|
851
|
+
padding: "5px 10px", borderRadius: 8,
|
|
852
|
+
background: "rgba(155,89,182,0.08)", border: `1px solid rgba(155,89,182,0.35)`,
|
|
853
|
+
}}>
|
|
854
|
+
<div style={{ width: 8, height: 8, borderRadius: "50%", background: SECONDARY_PURPLE, flexShrink: 0 }} />
|
|
855
|
+
<span style={{ fontSize: 11, fontWeight: 600, color: SECONDARY_PURPLE_TEXT, flex: 1, minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>
|
|
856
|
+
Secondary: {secondaryKeyword}
|
|
857
|
+
</span>
|
|
858
|
+
{!secondaryInList && (
|
|
859
|
+
<span title="This keyword is no longer in the list below - re-pick or clear it." style={{ fontSize: 9.5, fontWeight: 600, fontStyle: "italic", color: "#9ca3af", flexShrink: 0 }}>
|
|
860
|
+
not in list
|
|
861
|
+
</span>
|
|
862
|
+
)}
|
|
863
|
+
<button
|
|
864
|
+
onClick={startSecSelecting}
|
|
865
|
+
style={{ background: "none", border: "none", cursor: "pointer", fontSize: 11, fontWeight: 600, color: SECONDARY_PURPLE_TEXT, padding: 2, fontFamily: "inherit" }}
|
|
866
|
+
>
|
|
867
|
+
Change
|
|
868
|
+
</button>
|
|
869
|
+
<button
|
|
870
|
+
onClick={() => onSelectSecondary("")}
|
|
871
|
+
title="Clear secondary keyword"
|
|
872
|
+
aria-label="Clear secondary keyword"
|
|
873
|
+
style={{ background: "none", border: "none", cursor: "pointer", fontSize: 14, lineHeight: 1, color: "#9ca3af", padding: 2, fontFamily: "inherit" }}
|
|
874
|
+
>
|
|
875
|
+
×
|
|
876
|
+
</button>
|
|
877
|
+
</div>
|
|
878
|
+
) : (
|
|
879
|
+
<button
|
|
880
|
+
onClick={startSecSelecting}
|
|
881
|
+
style={{
|
|
882
|
+
display: "inline-flex", alignItems: "center", gap: 6, marginBottom: 8,
|
|
883
|
+
padding: "4px 10px", borderRadius: 8, cursor: "pointer",
|
|
884
|
+
background: "rgba(155,89,182,0.08)", border: `1px solid rgba(155,89,182,0.4)`,
|
|
885
|
+
color: SECONDARY_PURPLE_TEXT, fontSize: 11, fontWeight: 600, fontFamily: "inherit",
|
|
886
|
+
}}
|
|
887
|
+
>
|
|
888
|
+
<div style={{ width: 11, height: 11, borderRadius: "50%", border: `2px solid ${SECONDARY_PURPLE}`, flexShrink: 0 }} />
|
|
889
|
+
Click to choose a secondary keyword.
|
|
890
|
+
</button>
|
|
891
|
+
)
|
|
892
|
+
)}
|
|
893
|
+
|
|
905
894
|
{/* Manual keyword input */}
|
|
906
895
|
{manualInputOpen && (
|
|
907
896
|
<div style={{ marginBottom: 8, display: "flex", gap: 6 }}>
|
|
@@ -939,15 +928,46 @@ function SuggestedKeywordsCard({
|
|
|
939
928
|
borderBottom: i < visible.length - 1 ? "1px solid #f3f4f6" : "none",
|
|
940
929
|
minHeight: 28,
|
|
941
930
|
}}>
|
|
942
|
-
{/*
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
931
|
+
{/* Left indicator. Selection mode: a floating purple circle to pick this
|
|
932
|
+
keyword as secondary. Otherwise: the chosen secondary shows a filled
|
|
933
|
+
purple dot, the other keywords show nothing once a secondary is set,
|
|
934
|
+
and with no secondary chosen the normal in-content status dot. */}
|
|
935
|
+
{secSelecting && onSelectSecondary ? (
|
|
936
|
+
isPrimaryRow(kw.term) ? (
|
|
937
|
+
// The active primary keyword cannot also be the secondary - show a muted,
|
|
938
|
+
// non-selectable marker instead of a pickable circle.
|
|
939
|
+
<div title="Already your primary keyword" style={{ width: 14, height: 14, borderRadius: "50%", flexShrink: 0, border: "2px solid #e5e7eb", background: "transparent" }} />
|
|
940
|
+
) : (
|
|
941
|
+
<button
|
|
942
|
+
className="seo-copilot-sec-circle"
|
|
943
|
+
onClick={() => { onSelectSecondary(kw.term); setSecSelecting(false); }}
|
|
944
|
+
aria-label={`Set ${kw.term} as the secondary keyword`}
|
|
945
|
+
title={`Set "${kw.term}" as the secondary keyword`}
|
|
946
|
+
style={{
|
|
947
|
+
width: 14, height: 14, borderRadius: "50%", flexShrink: 0, padding: 0,
|
|
948
|
+
border: `2px solid ${SECONDARY_PURPLE}`, background: "transparent", cursor: "pointer",
|
|
949
|
+
animation: "seo-copilot-sec-float 1.8s ease-in-out infinite",
|
|
950
|
+
animationDelay: `${(i % 5) * 0.12}s`,
|
|
951
|
+
}}
|
|
952
|
+
/>
|
|
953
|
+
)
|
|
954
|
+
) : isSecondaryRow(kw.term) ? (
|
|
955
|
+
<div style={{ width: 8, height: 8, borderRadius: "50%", background: SECONDARY_PURPLE, flexShrink: 0 }} />
|
|
956
|
+
) : secondaryKeyword ? (
|
|
957
|
+
<div style={{ width: 8, height: 8, flexShrink: 0 }} />
|
|
958
|
+
) : (
|
|
959
|
+
<div style={{
|
|
960
|
+
width: 8, height: 8, borderRadius: "50%", flexShrink: 0,
|
|
961
|
+
background: kw.inContent ? "#16a34a" : "#d1d5db",
|
|
962
|
+
}} />
|
|
963
|
+
)}
|
|
964
|
+
{/* Term - dark gray normally; purple + bold when it is the chosen secondary. */}
|
|
965
|
+
<span style={{
|
|
966
|
+
fontSize: 12,
|
|
967
|
+
fontWeight: isSecondaryRow(kw.term) ? 700 : kw.inContent ? 500 : 600,
|
|
968
|
+
flexGrow: 1,
|
|
969
|
+
color: !secSelecting && isSecondaryRow(kw.term) ? SECONDARY_PURPLE_TEXT : "#1f2937",
|
|
970
|
+
}}>
|
|
951
971
|
{kw.term}
|
|
952
972
|
</span>
|
|
953
973
|
{/* Loading indicator for enriching manual keywords */}
|
|
@@ -1124,27 +1144,17 @@ export function KeywordPanel({
|
|
|
1124
1144
|
...c,
|
|
1125
1145
|
placement: computePlacementClient(c.term, text, documentFields),
|
|
1126
1146
|
}));
|
|
1127
|
-
|
|
1128
|
-
//
|
|
1129
|
-
|
|
1147
|
+
// Hide N/A (no-search-volume) primary candidates once volumes have loaded, same as the
|
|
1148
|
+
// supporting list - but always keep at least one so the selector is never empty (while
|
|
1149
|
+
// volumes load, or if every candidate is N/A, show them all).
|
|
1150
|
+
const candHasVol = (c: { volume: number | null }) => c.volume != null && c.volume > 0;
|
|
1151
|
+
const candWithVol = candidates.filter(candHasVol);
|
|
1152
|
+
const visibleCandidates = isVolumesLoading || candWithVol.length === 0 ? candidates : candWithVol;
|
|
1153
|
+
|
|
1154
|
+
// Ensure selectedPrimaryTerm is in the visible candidates, otherwise default to first
|
|
1155
|
+
const activeTerm = visibleCandidates.find((c) => c.term === selectedPrimaryTerm)
|
|
1130
1156
|
? selectedPrimaryTerm
|
|
1131
|
-
:
|
|
1132
|
-
|
|
1133
|
-
// Secondary options = same candidate pool as primary + supporting keywords, deduped,
|
|
1134
|
-
// with the currently-active primary filtered out so editors can't pick the same keyword twice.
|
|
1135
|
-
const activeTermLower = activeTerm.toLowerCase();
|
|
1136
|
-
const secondaryOptions: { term: string; volume: number | null }[] = [];
|
|
1137
|
-
const seenSecondary = new Set<string>();
|
|
1138
|
-
for (const c of candidates) {
|
|
1139
|
-
const key = c.term.toLowerCase();
|
|
1140
|
-
if (key === activeTermLower) continue;
|
|
1141
|
-
if (!seenSecondary.has(key)) { seenSecondary.add(key); secondaryOptions.push({ term: c.term, volume: c.volume }); }
|
|
1142
|
-
}
|
|
1143
|
-
for (const kw of suggestedKeywords) {
|
|
1144
|
-
const key = kw.term.toLowerCase();
|
|
1145
|
-
if (key === activeTermLower) continue;
|
|
1146
|
-
if (!seenSecondary.has(key)) { seenSecondary.add(key); secondaryOptions.push({ term: kw.term, volume: kw.volume }); }
|
|
1147
|
-
}
|
|
1157
|
+
: visibleCandidates[0]?.term ?? "";
|
|
1148
1158
|
|
|
1149
1159
|
return (
|
|
1150
1160
|
<div style={{ padding: 12, display: "flex", flexDirection: "column", gap: 12 }}>
|
|
@@ -1156,7 +1166,7 @@ export function KeywordPanel({
|
|
|
1156
1166
|
boxShadow: "inset 0 0 0 1px rgba(0,93,172,0.12)",
|
|
1157
1167
|
}}>
|
|
1158
1168
|
<div style={{ fontSize: 11.5, color: "#1f2937", lineHeight: 1.55 }}>
|
|
1159
|
-
<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
|
|
1169
|
+
<strong style={{ color: "#00468a" }}>Choose your target keywords.</strong> Pick one <strong>Primary</strong> keyword (required) and, optionally, one <strong>Secondary</strong> keyword. Copilot then optimizes its recommendations toward both.
|
|
1160
1170
|
</div>
|
|
1161
1171
|
</div>
|
|
1162
1172
|
|
|
@@ -1167,23 +1177,17 @@ export function KeywordPanel({
|
|
|
1167
1177
|
|
|
1168
1178
|
{/* Primary Keyword Selector */}
|
|
1169
1179
|
<PrimaryKeywordSelector
|
|
1170
|
-
candidates={
|
|
1180
|
+
candidates={visibleCandidates}
|
|
1171
1181
|
selectedTerm={activeTerm}
|
|
1172
1182
|
onSelect={(term: string) => { setSelectedPrimaryTerm(term); onSelectPrimary?.(term); }}
|
|
1173
1183
|
publication={publication}
|
|
1174
1184
|
/>
|
|
1175
1185
|
|
|
1176
|
-
{/*
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
onSelect={(term: string) => onSelectSecondary(term)}
|
|
1182
|
-
/>
|
|
1183
|
-
)}
|
|
1184
|
-
|
|
1185
|
-
{/* Supporting Keywords */}
|
|
1186
|
-
{suggestedKeywords.length > 0 && (
|
|
1186
|
+
{/* Supporting Keywords (the secondary-keyword chooser is folded into this card).
|
|
1187
|
+
Render when there are supporting keywords OR when secondary selection is enabled,
|
|
1188
|
+
so the secondary chooser stays reachable even before any supporting keyword exists
|
|
1189
|
+
(the editor can pencil-add one, then pick it). */}
|
|
1190
|
+
{(suggestedKeywords.length > 0 || !!onSelectSecondary) && (
|
|
1187
1191
|
<SuggestedKeywordsCard
|
|
1188
1192
|
key={documentId || "default"}
|
|
1189
1193
|
keywords={suggestedKeywords}
|
|
@@ -1194,6 +1198,9 @@ export function KeywordPanel({
|
|
|
1194
1198
|
refreshVolumes={refreshVolumes}
|
|
1195
1199
|
isVolumesLoading={isVolumesLoading}
|
|
1196
1200
|
documentId={documentId}
|
|
1201
|
+
secondaryKeyword={secondaryKeyword}
|
|
1202
|
+
onSelectSecondary={onSelectSecondary}
|
|
1203
|
+
primaryTerm={activeTerm}
|
|
1197
1204
|
/>
|
|
1198
1205
|
)}
|
|
1199
1206
|
|
|
@@ -1207,6 +1214,13 @@ export function KeywordPanel({
|
|
|
1207
1214
|
</div>
|
|
1208
1215
|
)}
|
|
1209
1216
|
|
|
1217
|
+
{/* Background-refresh error banner - shown when a refresh fails but prior data still exists */}
|
|
1218
|
+
{error && analysis && (
|
|
1219
|
+
<div style={{ padding: "4px 12px", fontSize: 11, color: "#dc2626" }}>
|
|
1220
|
+
Could not refresh analysis: {error}
|
|
1221
|
+
</div>
|
|
1222
|
+
)}
|
|
1223
|
+
|
|
1210
1224
|
{/* Updating indicator */}
|
|
1211
1225
|
{isLoading && analysis && (
|
|
1212
1226
|
<div style={{ display: "flex", alignItems: "center", gap: 6, justifyContent: "center" }}>
|