sanity-plugin-seo-copilot 0.2.12 → 0.2.13

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 CHANGED
@@ -302,16 +302,15 @@ function safeParseJson(text) {
302
302
  throw new Error("Invalid JSON response from server");
303
303
  }
304
304
  }
305
- async function fetchAnalysis(apiUrl, content, mode, publication, seedKeywords, documentFields, focusKeyword, signal) {
305
+ async function fetchAnalysis(apiUrl, content, mode, publication, seedKeywords, documentFields, focusKeyword, secondaryKeyword, signal) {
306
306
  const response = await fetch(`${apiUrl}/api/seo-copilot/analyze`, {
307
307
  method: "POST",
308
308
  headers: { "Content-Type": "application/json" },
309
- body: JSON.stringify({ content, mode, publication, seedKeywords, documentFields, focusKeyword }),
309
+ body: JSON.stringify({ content, mode, publication, seedKeywords, documentFields, focusKeyword, secondaryKeyword }),
310
310
  signal
311
311
  });
312
312
  const text = await response.text();
313
313
  if (!response.ok) {
314
- const err = safeParseJson(text);
315
314
  if (response.status === 429) throw new Error("Analysis service is busy. Please try again.");
316
315
  if (response.status >= 500) throw new Error("Could not reach the SEO service.");
317
316
  throw new Error("Something went wrong analyzing this document.");
@@ -326,7 +325,6 @@ async function fetchChatStream(apiUrl, messages, documentContext, publication, k
326
325
  signal
327
326
  });
328
327
  if (!response.ok) {
329
- const err = await response.json().catch(() => ({ error: "Request failed" }));
330
328
  if (response.status === 429) throw new Error("Analysis service is busy. Please try again.");
331
329
  if (response.status >= 500) throw new Error("Could not reach the SEO service.");
332
330
  throw new Error("Something went wrong. Please try again.");
@@ -348,7 +346,6 @@ async function lookupKeywords(apiUrl, keywords, signal) {
348
346
  signal
349
347
  });
350
348
  if (!response.ok) {
351
- const err = await response.json().catch(() => ({ error: "Request failed" }));
352
349
  if (response.status === 429) throw new Error("Analysis service is busy. Please try again.");
353
350
  if (response.status >= 500) throw new Error("Could not reach the SEO service.");
354
351
  throw new Error("Something went wrong. Please try again.");
@@ -461,7 +458,7 @@ function mergeVolumes(analysis, volumeMap) {
461
458
  });
462
459
  return updated;
463
460
  }
464
- function useKeywordAnalysis(text, apiUrl, publication, seedKeywords, documentFields, focusPrimary, documentId) {
461
+ function useKeywordAnalysis(text, apiUrl, publication, seedKeywords, documentFields, focusPrimary, documentId, focusSecondary) {
465
462
  const cacheKey = documentId ? `seo-copilot-cache-${documentId}` : "seo-copilot-cache-v2";
466
463
  const loadCached = (0, import_react2.useCallback)(() => {
467
464
  try {
@@ -514,7 +511,7 @@ function useKeywordAnalysis(text, apiUrl, publication, seedKeywords, documentFie
514
511
  localStorage.setItem(cacheKey, JSON.stringify({ ...prev, analysis: withVolumes }));
515
512
  } catch {
516
513
  }
517
- }, [cacheKey]);
514
+ }, [cacheKey, loadCached]);
518
515
  const setDeepAnalysis = (0, import_react2.useCallback)((val) => {
519
516
  setDeepAnalysisRaw(val);
520
517
  try {
@@ -522,7 +519,7 @@ function useKeywordAnalysis(text, apiUrl, publication, seedKeywords, documentFie
522
519
  localStorage.setItem(cacheKey, JSON.stringify({ ...prev, deepAnalysis: val }));
523
520
  } catch {
524
521
  }
525
- }, [cacheKey]);
522
+ }, [cacheKey, loadCached]);
526
523
  const effectiveSeeds = seedKeywords;
527
524
  (0, import_react2.useEffect)(() => {
528
525
  if (deepAnalysis && aeoTextSnapshot && text !== aeoTextSnapshot) {
@@ -590,7 +587,7 @@ function useKeywordAnalysis(text, apiUrl, publication, seedKeywords, documentFie
590
587
  const controller = new AbortController();
591
588
  setIsLoading(true);
592
589
  setError(null);
593
- fetchAnalysis(apiUrl, text, "realtime", publication, effectiveSeeds, documentFields, focusPrimary, controller.signal).then((result) => {
590
+ fetchAnalysis(apiUrl, text, "realtime", publication, effectiveSeeds, documentFields, focusPrimary, focusSecondary, controller.signal).then((result) => {
594
591
  if (cancelled) return;
595
592
  const analysisResult = result;
596
593
  lastAnalysisRef.current = analysisResult;
@@ -620,7 +617,7 @@ function useKeywordAnalysis(text, apiUrl, publication, seedKeywords, documentFie
620
617
  cancelled = true;
621
618
  controller.abort();
622
619
  };
623
- }, [text, apiUrl, publication, effectiveSeeds?.join(","), focusPrimary, JSON.stringify(documentFields)]);
620
+ }, [text, apiUrl, publication, effectiveSeeds?.join(","), focusPrimary, focusSecondary, JSON.stringify(documentFields)]);
624
621
  const refreshVolumes = (0, import_react2.useCallback)(() => {
625
622
  const current = lastAnalysisRef.current || analysis;
626
623
  if (!current) return;
@@ -636,7 +633,7 @@ function useKeywordAnalysis(text, apiUrl, publication, seedKeywords, documentFie
636
633
  deepAbortRef.current?.abort();
637
634
  const deepController = new AbortController();
638
635
  deepAbortRef.current = deepController;
639
- fetchAnalysis(apiUrl, text, "deep", publication, effectiveSeeds, documentFields, focusPrimary, deepController.signal).then((result) => {
636
+ fetchAnalysis(apiUrl, text, "deep", publication, effectiveSeeds, documentFields, focusPrimary, focusSecondary, deepController.signal).then((result) => {
640
637
  if (docVersionRef.current !== myVersion) return;
641
638
  setDeepAnalysis(result);
642
639
  setIsDeepLoading(false);
@@ -646,7 +643,7 @@ function useKeywordAnalysis(text, apiUrl, publication, seedKeywords, documentFie
646
643
  setError(err.message);
647
644
  setIsDeepLoading(false);
648
645
  });
649
- }, [text, apiUrl, publication, effectiveSeeds?.join(","), documentFields, focusPrimary]);
646
+ }, [text, apiUrl, publication, effectiveSeeds?.join(","), documentFields, focusPrimary, focusSecondary]);
650
647
  return {
651
648
  analysis,
652
649
  isLoading,
@@ -991,6 +988,13 @@ var INJECTED_CSS = `
991
988
  from { opacity: 1; transform: translateY(0) scale(1); }
992
989
  to { opacity: 0; transform: translateY(-6px) scale(0.97); }
993
990
  }
991
+ @keyframes seo-copilot-sec-float {
992
+ 0%, 100% { transform: translateY(0); }
993
+ 50% { transform: translateY(-1.5px); }
994
+ }
995
+ @media (prefers-reduced-motion: reduce) {
996
+ .seo-copilot-sec-circle { animation: none !important; }
997
+ }
994
998
  .prose-chat { font-size: 12.5px; line-height: 1.65; color: #475569; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; }
995
999
  .prose-chat h1 { font-size: 14px; font-weight: 700; color: #1e293b; margin: 10px 0 5px 0; line-height: 1.35; }
996
1000
  .prose-chat h2, .prose-chat h3 { font-size: 13px; font-weight: 700; color: #1e293b; margin: 10px 0 5px 0; line-height: 1.35; }
@@ -1740,119 +1744,6 @@ function PrimaryKeywordSelector({
1740
1744
  }) })
1741
1745
  ] });
1742
1746
  }
1743
- function SecondaryKeywordSelector({
1744
- options,
1745
- selectedTerm,
1746
- onSelect
1747
- }) {
1748
- const [customInputOpen, setCustomInputOpen] = (0, import_react9.useState)(false);
1749
- const [customValue, setCustomValue] = (0, import_react9.useState)("");
1750
- const handleCustomSubmit = () => {
1751
- const trimmed = customValue.trim();
1752
- if (trimmed) {
1753
- onSelect(trimmed);
1754
- setCustomValue("");
1755
- setCustomInputOpen(false);
1756
- }
1757
- };
1758
- const opts = selectedTerm && !options.some((o) => o.term.toLowerCase() === selectedTerm.toLowerCase()) ? [...options, { term: selectedTerm, volume: null }] : options;
1759
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: cardStyle, children: [
1760
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1761
- SectionHeader,
1762
- {
1763
- label: "Secondary Keyword",
1764
- iconColor: MJH_BLUE,
1765
- actionButton: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: 6 }, children: [
1766
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: { fontSize: 9, fontWeight: 700, letterSpacing: "0.05em", textTransform: "uppercase", color: "#9ca3af" }, children: "Optional" }),
1767
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PencilButton, { onClick: () => setCustomInputOpen(!customInputOpen), active: customInputOpen })
1768
- ] })
1769
- }
1770
- ),
1771
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { fontSize: 11, color: "#4b5563", lineHeight: 1.5, marginBottom: 8 }, children: "Pick one more keyword to optimize for. Copilot then checks your title, meta, URL, headings, and images against both keywords." }),
1772
- customInputOpen && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { marginBottom: 8, display: "flex", gap: 6 }, children: [
1773
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1774
- "input",
1775
- {
1776
- type: "text",
1777
- value: customValue,
1778
- onChange: (e) => setCustomValue(e.target.value),
1779
- onKeyDown: (e) => {
1780
- if (e.key === "Enter") handleCustomSubmit();
1781
- },
1782
- placeholder: "Type a custom secondary keyword",
1783
- autoFocus: true,
1784
- style: { flex: 1, padding: "5px 8px", fontSize: 12, borderRadius: 8, border: "1px solid #e5e7eb", outline: "none", fontFamily: "inherit" }
1785
- }
1786
- ),
1787
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1788
- "button",
1789
- {
1790
- onClick: handleCustomSubmit,
1791
- disabled: !customValue.trim(),
1792
- style: {
1793
- padding: "5px 10px",
1794
- fontSize: 11,
1795
- fontWeight: 600,
1796
- borderRadius: 6,
1797
- border: "none",
1798
- background: customValue.trim() ? MJH_BLUE : "#e5e7eb",
1799
- color: customValue.trim() ? "#ffffff" : "#9ca3af",
1800
- cursor: customValue.trim() ? "pointer" : "not-allowed"
1801
- },
1802
- children: "Set"
1803
- }
1804
- )
1805
- ] }),
1806
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: 6 }, children: [
1807
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SecondaryOptionRow, { term: "", label: "None", selected: !selectedTerm, onSelect: () => onSelect("") }),
1808
- opts.map((o) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1809
- SecondaryOptionRow,
1810
- {
1811
- term: o.term,
1812
- label: o.term,
1813
- volume: o.volume,
1814
- selected: o.term === selectedTerm,
1815
- onSelect: () => onSelect(o.term)
1816
- },
1817
- o.term
1818
- ))
1819
- ] })
1820
- ] });
1821
- }
1822
- function SecondaryOptionRow({ term, label, volume, selected, onSelect }) {
1823
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1824
- "div",
1825
- {
1826
- onClick: onSelect,
1827
- style: {
1828
- display: "flex",
1829
- alignItems: "center",
1830
- gap: 8,
1831
- padding: "6px 8px",
1832
- borderRadius: 8,
1833
- cursor: "pointer",
1834
- background: selected ? "rgba(0,93,172,0.06)" : "transparent",
1835
- border: selected ? "1px solid rgba(0,93,172,0.2)" : "1px solid transparent",
1836
- transition: "all 150ms"
1837
- },
1838
- children: [
1839
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: {
1840
- width: 14,
1841
- height: 14,
1842
- borderRadius: "50%",
1843
- border: selected ? "none" : "2px solid #d1d5db",
1844
- background: selected ? MJH_BLUE : "transparent",
1845
- flexShrink: 0,
1846
- display: "flex",
1847
- alignItems: "center",
1848
- justifyContent: "center"
1849
- }, children: selected && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { width: 6, height: 6, borderRadius: "50%", background: "#ffffff" } }) }),
1850
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: { fontSize: 12, fontWeight: selected ? 600 : 400, color: term ? selected ? "#00468a" : "#374151" : "#6b7280", flex: 1, minWidth: 0 }, children: label }),
1851
- volume != null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: { fontSize: 11, fontWeight: 600, color: "#1f2937" }, children: volume === 0 ? "N/A" : `${abbrevVol(volume)}/mo` })
1852
- ]
1853
- }
1854
- );
1855
- }
1856
1747
  var PLACEMENT_FILTERS = [
1857
1748
  { key: "inBody", label: "Body", letter: "B" },
1858
1749
  { key: "inTitle", label: "Title", letter: "T" },
@@ -1871,6 +1762,8 @@ function computePlacementClient(term, content, fields) {
1871
1762
  inUrl: fields?.slug?.toLowerCase().includes(lower) ?? false
1872
1763
  };
1873
1764
  }
1765
+ var SECONDARY_PURPLE = "#9B59B6";
1766
+ var SECONDARY_PURPLE_TEXT = "#7D3C98";
1874
1767
  function SuggestedKeywordsCard({
1875
1768
  keywords,
1876
1769
  text,
@@ -1879,7 +1772,10 @@ function SuggestedKeywordsCard({
1879
1772
  documentFields,
1880
1773
  refreshVolumes,
1881
1774
  isVolumesLoading,
1882
- documentId
1775
+ documentId,
1776
+ secondaryKeyword,
1777
+ onSelectSecondary,
1778
+ primaryTerm
1883
1779
  }) {
1884
1780
  const docScope = documentId || "default";
1885
1781
  const [helpData, setHelpData] = usePersistentState(
@@ -1900,6 +1796,11 @@ function SuggestedKeywordsCard({
1900
1796
  []
1901
1797
  );
1902
1798
  const [isGeneratingMore, setIsGeneratingMore] = (0, import_react9.useState)(false);
1799
+ const [secSelecting, setSecSelecting] = (0, import_react9.useState)(false);
1800
+ const startSecSelecting = () => {
1801
+ setExpanded(true);
1802
+ setSecSelecting(true);
1803
+ };
1903
1804
  const [sortAsc, setSortAsc] = usePersistentState("seo-copilot-ui-keywords-sort-asc", false);
1904
1805
  const filtersKey = `seo-copilot-ui-keywords-filters-${docScope}`;
1905
1806
  const [activeFilters, setActiveFiltersRaw] = (0, import_react9.useState)(
@@ -2026,10 +1927,18 @@ function SuggestedKeywordsCard({
2026
1927
  if (pA !== pB) return pB - pA;
2027
1928
  return b.volume - a.volume;
2028
1929
  });
2029
- const allKeywords = [...sorted, ...extraKeywords.filter((ek) => !sorted.some((s) => s.term.toLowerCase() === ek.term.toLowerCase()))];
1930
+ const merged = [...sorted, ...extraKeywords.filter((ek) => !sorted.some((s) => s.term.toLowerCase() === ek.term.toLowerCase()))];
1931
+ const hasVol = (k) => k.volume != null && k.volume > 0;
1932
+ const withVol = merged.filter(hasVol);
1933
+ const allKeywords = isVolumesLoading || withVol.length === 0 ? merged : withVol;
2030
1934
  const visible = expanded ? allKeywords : allKeywords.slice(0, INITIAL_SHOW);
2031
1935
  const hiddenCount = allKeywords.length - INITIAL_SHOW;
2032
1936
  const missingCount = keywords.filter((kw) => !kw.inContent).length;
1937
+ const secLower = (secondaryKeyword || "").toLowerCase();
1938
+ const primaryLower = (primaryTerm || "").toLowerCase();
1939
+ const isSecondaryRow = (term) => secLower !== "" && term.toLowerCase() === secLower;
1940
+ const isPrimaryRow = (term) => primaryLower !== "" && term.toLowerCase() === primaryLower;
1941
+ const secondaryInList = secLower !== "" && allKeywords.some((k) => k.term.toLowerCase() === secLower);
2033
1942
  const generateMoreKeywords = async () => {
2034
1943
  setIsGeneratingMore(true);
2035
1944
  try {
@@ -2052,7 +1961,15 @@ function SuggestedKeywordsCard({
2052
1961
  }
2053
1962
  setIsGeneratingMore(false);
2054
1963
  };
2055
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: cardStyle, children: [
1964
+ const didBackfillRef = (0, import_react9.useRef)(false);
1965
+ (0, import_react9.useEffect)(() => {
1966
+ if (didBackfillRef.current) return;
1967
+ if (isVolumesLoading || isGeneratingMore || keywords.length === 0) return;
1968
+ didBackfillRef.current = true;
1969
+ const volCount = [...keywords, ...extraKeywords].filter((k) => k.volume != null && k.volume > 0).length;
1970
+ if (volCount < 8) generateMoreKeywords();
1971
+ }, [keywords, isVolumesLoading]);
1972
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: secSelecting ? { ...cardStyle, border: `1.5px solid ${SECONDARY_PURPLE}`, boxShadow: [cardStyle.boxShadow, `0 0 0 1px rgba(155,89,182,0.25)`].filter(Boolean).join(", ") } : cardStyle, children: [
2056
1973
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: 6, marginBottom: 8 }, children: [
2057
1974
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { width: 6, height: 6, borderRadius: "50%", background: MJH_BLUE, flexShrink: 0 } }),
2058
1975
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: { fontSize: 10, textTransform: "uppercase", letterSpacing: "0.05em", color: "#4b5563", fontWeight: 600, flex: 1 }, children: "Supporting Keywords" }),
@@ -2207,6 +2124,86 @@ function SuggestedKeywordsCard({
2207
2124
  ] }),
2208
2125
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PencilButton, { onClick: () => setManualInputOpen(!manualInputOpen), active: manualInputOpen })
2209
2126
  ] }),
2127
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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 }, children: secSelecting ? "Selection mode on. Pick a keyword below to set it as the secondary keyword." : "" }),
2128
+ onSelectSecondary && (secSelecting ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: {
2129
+ display: "flex",
2130
+ alignItems: "center",
2131
+ justifyContent: "space-between",
2132
+ gap: 8,
2133
+ marginBottom: 8,
2134
+ padding: "5px 10px",
2135
+ borderRadius: 8,
2136
+ background: "rgba(155,89,182,0.08)",
2137
+ border: `1px solid rgba(155,89,182,0.35)`
2138
+ }, children: [
2139
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: { fontSize: 11, fontWeight: 600, color: SECONDARY_PURPLE_TEXT }, children: "Pick a keyword below to set as secondary." }),
2140
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2141
+ "button",
2142
+ {
2143
+ onClick: () => setSecSelecting(false),
2144
+ style: { background: "none", border: "none", cursor: "pointer", fontSize: 11, fontWeight: 600, color: "#6b7280", padding: 2, fontFamily: "inherit" },
2145
+ children: "Cancel"
2146
+ }
2147
+ )
2148
+ ] }) : secondaryKeyword ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: {
2149
+ display: "flex",
2150
+ alignItems: "center",
2151
+ gap: 8,
2152
+ marginBottom: 8,
2153
+ padding: "5px 10px",
2154
+ borderRadius: 8,
2155
+ background: "rgba(155,89,182,0.08)",
2156
+ border: `1px solid rgba(155,89,182,0.35)`
2157
+ }, children: [
2158
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { width: 8, height: 8, borderRadius: "50%", background: SECONDARY_PURPLE, flexShrink: 0 } }),
2159
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { style: { fontSize: 11, fontWeight: 600, color: SECONDARY_PURPLE_TEXT, flex: 1, minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: [
2160
+ "Secondary: ",
2161
+ secondaryKeyword
2162
+ ] }),
2163
+ !secondaryInList && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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 }, children: "not in list" }),
2164
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2165
+ "button",
2166
+ {
2167
+ onClick: startSecSelecting,
2168
+ style: { background: "none", border: "none", cursor: "pointer", fontSize: 11, fontWeight: 600, color: SECONDARY_PURPLE_TEXT, padding: 2, fontFamily: "inherit" },
2169
+ children: "Change"
2170
+ }
2171
+ ),
2172
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2173
+ "button",
2174
+ {
2175
+ onClick: () => onSelectSecondary(""),
2176
+ title: "Clear secondary keyword",
2177
+ "aria-label": "Clear secondary keyword",
2178
+ style: { background: "none", border: "none", cursor: "pointer", fontSize: 14, lineHeight: 1, color: "#9ca3af", padding: 2, fontFamily: "inherit" },
2179
+ children: "\xD7"
2180
+ }
2181
+ )
2182
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2183
+ "button",
2184
+ {
2185
+ onClick: startSecSelecting,
2186
+ style: {
2187
+ display: "inline-flex",
2188
+ alignItems: "center",
2189
+ gap: 6,
2190
+ marginBottom: 8,
2191
+ padding: "4px 10px",
2192
+ borderRadius: 8,
2193
+ cursor: "pointer",
2194
+ background: "rgba(155,89,182,0.08)",
2195
+ border: `1px solid rgba(155,89,182,0.4)`,
2196
+ color: SECONDARY_PURPLE_TEXT,
2197
+ fontSize: 11,
2198
+ fontWeight: 600,
2199
+ fontFamily: "inherit"
2200
+ },
2201
+ children: [
2202
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { width: 11, height: 11, borderRadius: "50%", border: `2px solid ${SECONDARY_PURPLE}`, flexShrink: 0 } }),
2203
+ "Click to choose a secondary keyword."
2204
+ ]
2205
+ }
2206
+ )),
2210
2207
  manualInputOpen && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { marginBottom: 8, display: "flex", gap: 6 }, children: [
2211
2208
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2212
2209
  "input",
@@ -2250,14 +2247,46 @@ function SuggestedKeywordsCard({
2250
2247
  borderBottom: i < visible.length - 1 ? "1px solid #f3f4f6" : "none",
2251
2248
  minHeight: 28
2252
2249
  }, children: [
2253
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: {
2250
+ secSelecting && onSelectSecondary ? isPrimaryRow(kw.term) ? (
2251
+ // The active primary keyword cannot also be the secondary - show a muted,
2252
+ // non-selectable marker instead of a pickable circle.
2253
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { title: "Already your primary keyword", style: { width: 14, height: 14, borderRadius: "50%", flexShrink: 0, border: "2px solid #e5e7eb", background: "transparent" } })
2254
+ ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2255
+ "button",
2256
+ {
2257
+ className: "seo-copilot-sec-circle",
2258
+ onClick: () => {
2259
+ onSelectSecondary(kw.term);
2260
+ setSecSelecting(false);
2261
+ },
2262
+ "aria-label": `Set ${kw.term} as the secondary keyword`,
2263
+ title: `Set "${kw.term}" as the secondary keyword`,
2264
+ style: {
2265
+ width: 14,
2266
+ height: 14,
2267
+ borderRadius: "50%",
2268
+ flexShrink: 0,
2269
+ padding: 0,
2270
+ border: `2px solid ${SECONDARY_PURPLE}`,
2271
+ background: "transparent",
2272
+ cursor: "pointer",
2273
+ animation: "seo-copilot-sec-float 1.8s ease-in-out infinite",
2274
+ animationDelay: `${i % 5 * 0.12}s`
2275
+ }
2276
+ }
2277
+ ) : isSecondaryRow(kw.term) ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { width: 8, height: 8, borderRadius: "50%", background: SECONDARY_PURPLE, flexShrink: 0 } }) : secondaryKeyword ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { width: 8, height: 8, flexShrink: 0 } }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: {
2254
2278
  width: 8,
2255
2279
  height: 8,
2256
2280
  borderRadius: "50%",
2257
2281
  flexShrink: 0,
2258
2282
  background: kw.inContent ? "#16a34a" : "#d1d5db"
2259
2283
  } }),
2260
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: { fontSize: 12, fontWeight: kw.inContent ? 500 : 600, flexGrow: 1, color: "#1f2937" }, children: kw.term }),
2284
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: {
2285
+ fontSize: 12,
2286
+ fontWeight: isSecondaryRow(kw.term) ? 700 : kw.inContent ? 500 : 600,
2287
+ flexGrow: 1,
2288
+ color: !secSelecting && isSecondaryRow(kw.term) ? SECONDARY_PURPLE_TEXT : "#1f2937"
2289
+ }, children: kw.term }),
2261
2290
  enrichingTerms.has(kw.term) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(LoadingBars, { size: "xs", color: "#6b7280" }),
2262
2291
  !enrichingTerms.has(kw.term) && kw.volume != null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: { fontSize: 10.5, fontWeight: 600, color: "#1f2937", flexShrink: 0 }, title: "Monthly searches", children: kw.volume === 0 ? "N/A" : `${abbrevVol(kw.volume)}/mo` }),
2263
2292
  kw.placement && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PlacementIndicators, { placement: kw.placement }),
@@ -2396,26 +2425,10 @@ function KeywordPanel({
2396
2425
  ...c,
2397
2426
  placement: computePlacementClient(c.term, text, documentFields)
2398
2427
  }));
2399
- const activeTerm = candidates.find((c) => c.term === selectedPrimaryTerm) ? selectedPrimaryTerm : candidates[0]?.term ?? "";
2400
- const activeTermLower = activeTerm.toLowerCase();
2401
- const secondaryOptions = [];
2402
- const seenSecondary = /* @__PURE__ */ new Set();
2403
- for (const c of candidates) {
2404
- const key = c.term.toLowerCase();
2405
- if (key === activeTermLower) continue;
2406
- if (!seenSecondary.has(key)) {
2407
- seenSecondary.add(key);
2408
- secondaryOptions.push({ term: c.term, volume: c.volume });
2409
- }
2410
- }
2411
- for (const kw of suggestedKeywords) {
2412
- const key = kw.term.toLowerCase();
2413
- if (key === activeTermLower) continue;
2414
- if (!seenSecondary.has(key)) {
2415
- seenSecondary.add(key);
2416
- secondaryOptions.push({ term: kw.term, volume: kw.volume });
2417
- }
2418
- }
2428
+ const candHasVol = (c) => c.volume != null && c.volume > 0;
2429
+ const candWithVol = candidates.filter(candHasVol);
2430
+ const visibleCandidates = isVolumesLoading || candWithVol.length === 0 ? candidates : candWithVol;
2431
+ const activeTerm = visibleCandidates.find((c) => c.term === selectedPrimaryTerm) ? selectedPrimaryTerm : visibleCandidates[0]?.term ?? "";
2419
2432
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { padding: 12, display: "flex", flexDirection: "column", gap: 12 }, children: [
2420
2433
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: {
2421
2434
  ...cardStyle,
@@ -2428,13 +2441,13 @@ function KeywordPanel({
2428
2441
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: "Primary" }),
2429
2442
  " keyword (required) and, optionally, one ",
2430
2443
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: "Secondary" }),
2431
- " keyword. Copilot optimizes the whole article - title, meta, URL, headings, and images - toward both."
2444
+ " keyword. Copilot then optimizes its recommendations toward both."
2432
2445
  ] }) }),
2433
2446
  onSeedsChange && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SeedKeywordInput, { seeds: seedKeywords, onSeedsChange }),
2434
2447
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2435
2448
  PrimaryKeywordSelector,
2436
2449
  {
2437
- candidates,
2450
+ candidates: visibleCandidates,
2438
2451
  selectedTerm: activeTerm,
2439
2452
  onSelect: (term) => {
2440
2453
  setSelectedPrimaryTerm(term);
@@ -2443,15 +2456,7 @@ function KeywordPanel({
2443
2456
  publication
2444
2457
  }
2445
2458
  ),
2446
- onSelectSecondary && secondaryOptions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2447
- SecondaryKeywordSelector,
2448
- {
2449
- options: secondaryOptions,
2450
- selectedTerm: secondaryKeyword,
2451
- onSelect: (term) => onSelectSecondary(term)
2452
- }
2453
- ),
2454
- suggestedKeywords.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2459
+ (suggestedKeywords.length > 0 || !!onSelectSecondary) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2455
2460
  SuggestedKeywordsCard,
2456
2461
  {
2457
2462
  keywords: suggestedKeywords,
@@ -2461,7 +2466,10 @@ function KeywordPanel({
2461
2466
  documentFields,
2462
2467
  refreshVolumes,
2463
2468
  isVolumesLoading,
2464
- documentId
2469
+ documentId,
2470
+ secondaryKeyword,
2471
+ onSelectSecondary,
2472
+ primaryTerm: activeTerm
2465
2473
  },
2466
2474
  documentId || "default"
2467
2475
  ),
@@ -2469,6 +2477,10 @@ function KeywordPanel({
2469
2477
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(LoadingBars, { size: "xs", color: MJH_GOLD }),
2470
2478
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: { fontSize: 10, color: "#4b5563" }, children: "Checking search volumes..." })
2471
2479
  ] }),
2480
+ error && analysis && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { padding: "4px 12px", fontSize: 11, color: "#dc2626" }, children: [
2481
+ "Could not refresh analysis: ",
2482
+ error
2483
+ ] }),
2472
2484
  isLoading && analysis && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: 6, justifyContent: "center" }, children: [
2473
2485
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(LoadingBars, { size: "xs", color: "#9ca3af" }),
2474
2486
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: { fontSize: 10, color: "#4b5563" }, children: "Updating insights..." })
@@ -3487,7 +3499,7 @@ function buildSummaryItems(input) {
3487
3499
  severity: "warning",
3488
3500
  label: "Meta description is short",
3489
3501
  description: `Meta description is ${len} characters - below the 120-160 ideal.`,
3490
- howToFix: "Expand the description to 120-160 characters so you don't leave SERP space empty.",
3502
+ howToFix: "Expand the description to 120-160 characters so the full description shows in search.",
3491
3503
  jumpTo: { tab: "meta", anchorId: "anchor-meta-description" }
3492
3504
  });
3493
3505
  } else if (len > 160) {
@@ -4547,6 +4559,14 @@ function AEOTab({
4547
4559
  "div",
4548
4560
  {
4549
4561
  onClick: runDeepAnalysis,
4562
+ role: "button",
4563
+ tabIndex: 0,
4564
+ onKeyDown: (e) => {
4565
+ if (e.key === "Enter" || e.key === " ") {
4566
+ e.preventDefault();
4567
+ runDeepAnalysis();
4568
+ }
4569
+ },
4550
4570
  style: {
4551
4571
  padding: "8px 12px",
4552
4572
  background: "#fffbeb",
@@ -6716,7 +6736,6 @@ function PanelContent({
6716
6736
  text,
6717
6737
  deepAnalysis: keywordAnalysisState.deepAnalysis,
6718
6738
  isDeepLoading: keywordAnalysisState.isDeepLoading,
6719
- primaryKeyword: effectivePrimary,
6720
6739
  publication,
6721
6740
  runDeepAnalysis: keywordAnalysisState.runDeepAnalysis,
6722
6741
  aeoContentChanged: keywordAnalysisState.aeoContentChanged,
@@ -6936,7 +6955,7 @@ function SEOCopilotInner({ config, onClose }) {
6936
6955
  const [activeTab, setActiveTab] = (0, import_react18.useState)("keywords");
6937
6956
  const [chatOpen, setChatOpen] = usePersistentState("seo-copilot-ui-chat-open-v35", false);
6938
6957
  const [splitPercent, setSplitPercent] = usePersistentState("seo-copilot-ui-split", 70);
6939
- const keywordAnalysisState = useKeywordAnalysis(text, apiUrl, effectivePublication, seedKeywords, documentFields, selectedPrimary, documentId);
6958
+ const keywordAnalysisState = useKeywordAnalysis(text, apiUrl, effectivePublication, seedKeywords, documentFields, selectedPrimary, documentId, selectedSecondary);
6940
6959
  const effectivePrimary = selectedPrimary || keywordAnalysisState.analysis?.primaryKeyword?.term || "";
6941
6960
  (0, import_react18.useEffect)(() => {
6942
6961
  if (selectedSecondary && effectivePrimary && selectedSecondary.toLowerCase() === effectivePrimary.toLowerCase()) {
@@ -7118,6 +7137,24 @@ function SEOCopilotInner({ config, onClose }) {
7118
7137
  linkingAbortRef.current?.abort();
7119
7138
  };
7120
7139
  }, []);
7140
+ const runAllAnalyses = () => {
7141
+ keywordAnalysisState.runDeepAnalysis();
7142
+ if (text && text.trim().length >= 100) loadContentSuggestions();
7143
+ if (text && text.trim().length >= 50 && effectivePrimary) refreshLinkingSuggestions();
7144
+ if ((documentFields?.bodyLinks || []).length > 0) runLinkCheck();
7145
+ };
7146
+ const runAllRef = (0, import_react18.useRef)(runAllAnalyses);
7147
+ runAllRef.current = runAllAnalyses;
7148
+ const secAutoRunRef = (0, import_react18.useRef)({ doc: documentId, sec: selectedSecondary, init: true });
7149
+ (0, import_react18.useEffect)(() => {
7150
+ const prev = secAutoRunRef.current;
7151
+ const docChanged = prev.doc !== documentId;
7152
+ const secChanged = prev.sec !== selectedSecondary;
7153
+ secAutoRunRef.current = { doc: documentId, sec: selectedSecondary, init: false };
7154
+ if (prev.init || docChanged || !secChanged) return;
7155
+ const t = setTimeout(() => runAllRef.current(), 1500);
7156
+ return () => clearTimeout(t);
7157
+ }, [selectedSecondary, documentId]);
7121
7158
  const handleDragStart = (0, import_react18.useCallback)(
7122
7159
  (e) => {
7123
7160
  dragOffset.current = {
@@ -7250,12 +7287,7 @@ function SEOCopilotInner({ config, onClose }) {
7250
7287
  },
7251
7288
  summaryOps: {
7252
7289
  isAnyLoading: keywordAnalysisState.isLoading || keywordAnalysisState.isVolumesLoading || keywordAnalysisState.isDeepLoading || isCSLoading || isLinkingLoading || isLinkCheckLoading,
7253
- onGenerateAll: () => {
7254
- keywordAnalysisState.runDeepAnalysis();
7255
- if (text && text.trim().length >= 100) loadContentSuggestions();
7256
- if (text && text.trim().length >= 50 && effectivePrimary) refreshLinkingSuggestions();
7257
- if ((documentFields?.bodyLinks || []).length > 0) runLinkCheck();
7258
- },
7290
+ onGenerateAll: runAllAnalyses,
7259
7291
  onItemClick: (item) => {
7260
7292
  setActiveTab(item.jumpTo.tab);
7261
7293
  const id = item.jumpTo.anchorId;