sanity-plugin-seo-copilot 0.2.15 → 0.2.17
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/README.md +63 -50
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +898 -809
- package/dist/index.mjs +822 -733
- package/package.json +5 -7
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/sanity.json +0 -3
- package/src/components/ChatPanel.tsx +0 -311
- package/src/components/ConfigContext.tsx +0 -22
- package/src/components/FeedbackButton.tsx +0 -218
- package/src/components/KeywordBadge.tsx +0 -50
- package/src/components/KeywordPanel.tsx +0 -1234
- package/src/components/OnboardingPopup.tsx +0 -108
- package/src/components/PlacementIndicators.tsx +0 -80
- package/src/components/ReportProblemButton.tsx +0 -212
- package/src/components/SEOCopilotPanel.tsx +0 -1287
- package/src/components/ScoreDonut.tsx +0 -158
- package/src/components/SeedKeywordInput.tsx +0 -128
- package/src/components/ShimmerLoader.tsx +0 -123
- package/src/components/TabBar.tsx +0 -373
- package/src/components/styles.ts +0 -158
- package/src/components/tabs/AEOTab.tsx +0 -585
- package/src/components/tabs/LinkingTab.tsx +0 -446
- package/src/components/tabs/MetaTab.tsx +0 -431
- package/src/components/tabs/SummaryTab.tsx +0 -405
- package/src/components/tabs/TechnicalTab.tsx +0 -933
- package/src/hooks/useDocumentContent.ts +0 -48
- package/src/hooks/useKeywordAnalysis.ts +0 -292
- package/src/hooks/useSEOChat.ts +0 -254
- package/src/index.ts +0 -18
- package/src/inspector.ts +0 -58
- package/src/lib/api.ts +0 -262
- package/src/lib/apiKey.ts +0 -30
- package/src/lib/documentExtract.ts +0 -422
- package/src/lib/geoAnalysis.ts +0 -122
- package/src/lib/persistence.ts +0 -69
- package/src/lib/scoring.ts +0 -197
- package/src/lib/summary.ts +0 -645
- package/src/lib/types.ts +0 -212
- package/src/lib/utils.ts +0 -35
- package/v2-incompatible.js +0 -10
|
@@ -1,1287 +0,0 @@
|
|
|
1
|
-
import { useState, useRef, useCallback, useEffect, useMemo, Suspense } from "react";
|
|
2
|
-
import { useWorkspace } from "sanity";
|
|
3
|
-
import { createPortal } from "react-dom";
|
|
4
|
-
import { useDocumentContent } from "../hooks/useDocumentContent";
|
|
5
|
-
import { useKeywordAnalysis } from "../hooks/useKeywordAnalysis";
|
|
6
|
-
import { useSEOChat } from "../hooks/useSEOChat";
|
|
7
|
-
import { useConfig, ConfigProvider } from "./ConfigContext";
|
|
8
|
-
import { KeywordPanel } from "./KeywordPanel";
|
|
9
|
-
import { ChatPanel } from "./ChatPanel";
|
|
10
|
-
import { TabBar } from "./TabBar";
|
|
11
|
-
import { OnboardingInfoButton, OnboardingCard } from "./OnboardingPopup";
|
|
12
|
-
import { ReportProblemButton } from "./ReportProblemButton";
|
|
13
|
-
import { SummaryTab } from "./tabs/SummaryTab";
|
|
14
|
-
import { AEOTab } from "./tabs/AEOTab";
|
|
15
|
-
import { LinkingTab } from "./tabs/LinkingTab";
|
|
16
|
-
import { MetaTab } from "./tabs/MetaTab";
|
|
17
|
-
import { TechnicalTab } from "./tabs/TechnicalTab";
|
|
18
|
-
import { INJECTED_CSS, MJH_GOLD, MJH_BLUE, MJH_SLATE, PANEL_BG, CHAT_ZONE_BG, RECS_ZONE_BG } from "./styles";
|
|
19
|
-
import { fetchContentSuggestions, fetchLinkingSuggestions, checkLinks } from "../lib/api";
|
|
20
|
-
import { usePersistentState, loadLocal, saveLocal } from "../lib/persistence";
|
|
21
|
-
import type { SEOCopilotConfig } from "../index";
|
|
22
|
-
import type { SEOAnalysis, DeepAnalysis, TabId, ChatMessage, ContentSuggestions, LinkingSuggestion, SummaryItem, LinkCheckResult } from "../lib/types";
|
|
23
|
-
|
|
24
|
-
interface SEOCopilotPanelProps {
|
|
25
|
-
config: SEOCopilotConfig;
|
|
26
|
-
onClose?: () => void;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function LogoIcon() {
|
|
30
|
-
return (
|
|
31
|
-
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
|
|
32
|
-
<rect x="1" y="3" width="4" height="10" rx="1" fill={MJH_GOLD} opacity="1" />
|
|
33
|
-
<rect x="6" y="1" width="4" height="14" rx="1" fill={MJH_GOLD} opacity="0.85" />
|
|
34
|
-
<rect x="11" y="5" width="4" height="8" rx="1" fill={MJH_GOLD} opacity="0.6" />
|
|
35
|
-
</svg>
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
interface PanelContentProps {
|
|
40
|
-
initialPublication?: string;
|
|
41
|
-
isFloating?: boolean;
|
|
42
|
-
isFullscreen?: boolean;
|
|
43
|
-
onToggleFloat?: () => void;
|
|
44
|
-
onToggleFullscreen?: () => void;
|
|
45
|
-
onClose?: () => void;
|
|
46
|
-
floatPos?: { x: number; y: number };
|
|
47
|
-
onDragStart?: (e: React.MouseEvent) => void;
|
|
48
|
-
seedKeywords: string[];
|
|
49
|
-
onSeedsChange: (seeds: string[]) => void;
|
|
50
|
-
text: string;
|
|
51
|
-
docLoading: boolean;
|
|
52
|
-
documentFields: import("../lib/types").DocumentFields;
|
|
53
|
-
documentId?: string;
|
|
54
|
-
documentType?: string;
|
|
55
|
-
sanityBaseUrl?: string;
|
|
56
|
-
selectedPrimary?: string;
|
|
57
|
-
onSelectPrimary?: (term: string) => void;
|
|
58
|
-
selectedSecondary?: string;
|
|
59
|
-
onSelectSecondary?: (term: string) => void;
|
|
60
|
-
// Lifted state - survives float/dock toggle (which remounts PanelContent)
|
|
61
|
-
activeTab: TabId;
|
|
62
|
-
onActiveTabChange: (id: TabId) => void;
|
|
63
|
-
chatOpen: boolean;
|
|
64
|
-
onChatOpenChange: (open: boolean) => void;
|
|
65
|
-
splitPercent: number;
|
|
66
|
-
onSplitPercentChange: (pct: number) => void;
|
|
67
|
-
externalAnalysis: {
|
|
68
|
-
analysis: SEOAnalysis | null;
|
|
69
|
-
isLoading: boolean;
|
|
70
|
-
isVolumesLoading: boolean;
|
|
71
|
-
error: string | null;
|
|
72
|
-
deepAnalysis: DeepAnalysis | null;
|
|
73
|
-
isDeepLoading: boolean;
|
|
74
|
-
runDeepAnalysis: () => void;
|
|
75
|
-
refreshVolumes: () => void;
|
|
76
|
-
aeoContentChanged: boolean;
|
|
77
|
-
};
|
|
78
|
-
chatState: {
|
|
79
|
-
messages: ChatMessage[];
|
|
80
|
-
isStreaming: boolean;
|
|
81
|
-
sendMessage: (text: string) => Promise<void>;
|
|
82
|
-
clearChat: () => void;
|
|
83
|
-
};
|
|
84
|
-
aeoOps: {
|
|
85
|
-
contentSuggestions: ContentSuggestions | null;
|
|
86
|
-
isCSLoading: boolean;
|
|
87
|
-
csError: string | null;
|
|
88
|
-
loadContentSuggestions: () => void;
|
|
89
|
-
};
|
|
90
|
-
linkingOps: {
|
|
91
|
-
suggestions: LinkingSuggestion[];
|
|
92
|
-
isLoading: boolean;
|
|
93
|
-
error: string | null;
|
|
94
|
-
isStale: boolean;
|
|
95
|
-
refresh: () => void;
|
|
96
|
-
};
|
|
97
|
-
technicalOps: {
|
|
98
|
-
linkCheckResults: LinkCheckResult[];
|
|
99
|
-
isLinkCheckLoading: boolean;
|
|
100
|
-
linkCheckError: string | null;
|
|
101
|
-
hasRunLinkCheck: boolean;
|
|
102
|
-
onCheckLinks: () => void;
|
|
103
|
-
};
|
|
104
|
-
summaryOps: {
|
|
105
|
-
isAnyLoading: boolean;
|
|
106
|
-
onGenerateAll: () => void;
|
|
107
|
-
onItemClick: (item: SummaryItem) => void;
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function PanelContent({
|
|
112
|
-
initialPublication,
|
|
113
|
-
isFloating,
|
|
114
|
-
isFullscreen,
|
|
115
|
-
onToggleFloat,
|
|
116
|
-
onToggleFullscreen,
|
|
117
|
-
onClose,
|
|
118
|
-
floatPos: _floatPos,
|
|
119
|
-
onDragStart,
|
|
120
|
-
seedKeywords,
|
|
121
|
-
onSeedsChange,
|
|
122
|
-
text,
|
|
123
|
-
docLoading,
|
|
124
|
-
documentFields,
|
|
125
|
-
documentId,
|
|
126
|
-
documentType,
|
|
127
|
-
sanityBaseUrl,
|
|
128
|
-
selectedPrimary,
|
|
129
|
-
onSelectPrimary,
|
|
130
|
-
selectedSecondary,
|
|
131
|
-
onSelectSecondary,
|
|
132
|
-
activeTab,
|
|
133
|
-
onActiveTabChange,
|
|
134
|
-
chatOpen,
|
|
135
|
-
onChatOpenChange,
|
|
136
|
-
splitPercent,
|
|
137
|
-
onSplitPercentChange,
|
|
138
|
-
externalAnalysis,
|
|
139
|
-
chatState,
|
|
140
|
-
aeoOps,
|
|
141
|
-
linkingOps,
|
|
142
|
-
technicalOps,
|
|
143
|
-
summaryOps,
|
|
144
|
-
}: PanelContentProps) {
|
|
145
|
-
const publication = initialPublication;
|
|
146
|
-
const isLoading = externalAnalysis.isLoading;
|
|
147
|
-
const keywordAnalysisState = externalAnalysis;
|
|
148
|
-
|
|
149
|
-
// Effective primary keyword (selected override else top candidate from analysis)
|
|
150
|
-
const effectivePrimary =
|
|
151
|
-
selectedPrimary ||
|
|
152
|
-
externalAnalysis.analysis?.primaryKeyword?.term ||
|
|
153
|
-
"";
|
|
154
|
-
// Effective secondary keyword - purely the user's optional choice (no auto-default).
|
|
155
|
-
const effectiveSecondary = selectedSecondary || "";
|
|
156
|
-
|
|
157
|
-
// Draggable divider between tab content and chat - splitPercent is lifted to parent for persistence
|
|
158
|
-
const containerRef = useRef<HTMLDivElement>(null);
|
|
159
|
-
const dragging = useRef(false);
|
|
160
|
-
|
|
161
|
-
const onMouseDown = useCallback(() => {
|
|
162
|
-
dragging.current = true;
|
|
163
|
-
document.body.style.cursor = "row-resize";
|
|
164
|
-
document.body.style.userSelect = "none";
|
|
165
|
-
}, []);
|
|
166
|
-
|
|
167
|
-
useEffect(() => {
|
|
168
|
-
const onMouseMove = (e: MouseEvent) => {
|
|
169
|
-
if (!dragging.current || !containerRef.current) return;
|
|
170
|
-
const rect = containerRef.current.getBoundingClientRect();
|
|
171
|
-
const pct = ((e.clientY - rect.top) / rect.height) * 100;
|
|
172
|
-
onSplitPercentChange(Math.min(85, Math.max(15, pct)));
|
|
173
|
-
};
|
|
174
|
-
const onMouseUp = () => {
|
|
175
|
-
dragging.current = false;
|
|
176
|
-
document.body.style.cursor = "";
|
|
177
|
-
document.body.style.userSelect = "";
|
|
178
|
-
};
|
|
179
|
-
window.addEventListener("mousemove", onMouseMove);
|
|
180
|
-
window.addEventListener("mouseup", onMouseUp);
|
|
181
|
-
return () => {
|
|
182
|
-
window.removeEventListener("mousemove", onMouseMove);
|
|
183
|
-
window.removeEventListener("mouseup", onMouseUp);
|
|
184
|
-
};
|
|
185
|
-
}, [onSplitPercentChange]);
|
|
186
|
-
|
|
187
|
-
const headerCursor = isFloating ? "grab" : "default";
|
|
188
|
-
|
|
189
|
-
// ---- First-run onboarding popup --------------------------------------------
|
|
190
|
-
// Per-publication: shows the first time an editor opens Copilot for a site, then
|
|
191
|
-
// collapses to the (i) icon. We only mark the site "onboarded" once they actually
|
|
192
|
-
// engage (dismiss / open via the icon / switch a tab) - if they open and never
|
|
193
|
-
// touch it, it shows again next session. The 5s auto-fade alone does NOT onboard.
|
|
194
|
-
const onboardSite = publication || "default";
|
|
195
|
-
const onboardKey = `seo-copilot-onboarded-${onboardSite}`;
|
|
196
|
-
const onboardSessionKey = `seo-copilot-onboard-shown-${onboardSite}`;
|
|
197
|
-
const [popupMode, setPopupMode] = useState<"hidden" | "auto" | "persistent">("hidden");
|
|
198
|
-
const [popupClosing, setPopupClosing] = useState(false);
|
|
199
|
-
const onboardTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
200
|
-
const onboardFadeRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
201
|
-
|
|
202
|
-
useEffect(() => {
|
|
203
|
-
let onboarded = false;
|
|
204
|
-
let shownThisSession = false;
|
|
205
|
-
try { onboarded = localStorage.getItem(onboardKey) === "1"; } catch { /* ignore */ }
|
|
206
|
-
try { shownThisSession = sessionStorage.getItem(onboardSessionKey) === "1"; } catch { /* ignore */ }
|
|
207
|
-
if (!onboarded && !shownThisSession) {
|
|
208
|
-
setPopupMode("auto");
|
|
209
|
-
try { sessionStorage.setItem(onboardSessionKey, "1"); } catch { /* ignore */ }
|
|
210
|
-
onboardTimerRef.current = setTimeout(() => {
|
|
211
|
-
// Auto-fade to the (i) icon. Does NOT mark onboarded.
|
|
212
|
-
setPopupClosing(true);
|
|
213
|
-
onboardFadeRef.current = setTimeout(() => { setPopupMode("hidden"); setPopupClosing(false); }, 180);
|
|
214
|
-
}, 8000);
|
|
215
|
-
}
|
|
216
|
-
return () => {
|
|
217
|
-
if (onboardTimerRef.current) clearTimeout(onboardTimerRef.current);
|
|
218
|
-
if (onboardFadeRef.current) clearTimeout(onboardFadeRef.current);
|
|
219
|
-
};
|
|
220
|
-
// Re-run only when the site changes.
|
|
221
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
222
|
-
}, [onboardKey, onboardSessionKey]);
|
|
223
|
-
|
|
224
|
-
const markOnboarded = useCallback(() => {
|
|
225
|
-
try { localStorage.setItem(onboardKey, "1"); } catch { /* ignore */ }
|
|
226
|
-
}, [onboardKey]);
|
|
227
|
-
|
|
228
|
-
const dismissPopup = useCallback(() => {
|
|
229
|
-
if (onboardTimerRef.current) clearTimeout(onboardTimerRef.current);
|
|
230
|
-
if (onboardFadeRef.current) clearTimeout(onboardFadeRef.current);
|
|
231
|
-
markOnboarded();
|
|
232
|
-
setPopupClosing(true);
|
|
233
|
-
onboardFadeRef.current = setTimeout(() => { setPopupMode("hidden"); setPopupClosing(false); }, 180);
|
|
234
|
-
}, [markOnboarded]);
|
|
235
|
-
|
|
236
|
-
const openPopupPersistent = useCallback(() => {
|
|
237
|
-
if (onboardTimerRef.current) clearTimeout(onboardTimerRef.current);
|
|
238
|
-
if (onboardFadeRef.current) clearTimeout(onboardFadeRef.current);
|
|
239
|
-
markOnboarded();
|
|
240
|
-
setPopupClosing(false);
|
|
241
|
-
setPopupMode("persistent");
|
|
242
|
-
}, [markOnboarded]);
|
|
243
|
-
|
|
244
|
-
// Switching tabs counts as engagement - onboard the site and clear the popup.
|
|
245
|
-
const handleTabChange = useCallback((id: TabId) => {
|
|
246
|
-
markOnboarded();
|
|
247
|
-
if (onboardTimerRef.current) clearTimeout(onboardTimerRef.current);
|
|
248
|
-
if (onboardFadeRef.current) clearTimeout(onboardFadeRef.current);
|
|
249
|
-
setPopupClosing(true);
|
|
250
|
-
onboardFadeRef.current = setTimeout(() => { setPopupMode("hidden"); setPopupClosing(false); }, 120);
|
|
251
|
-
onActiveTabChange(id);
|
|
252
|
-
}, [markOnboarded, onActiveTabChange]);
|
|
253
|
-
|
|
254
|
-
const tabDefs = [
|
|
255
|
-
{ id: "summary" as TabId, label: "Summary", isHub: true, loading: summaryOps.isAnyLoading },
|
|
256
|
-
{ id: "keywords" as TabId, label: "Keywords", loading: keywordAnalysisState.isLoading || keywordAnalysisState.isVolumesLoading },
|
|
257
|
-
{ id: "aeo" as TabId, label: "AEO/GEO", loading: keywordAnalysisState.isDeepLoading },
|
|
258
|
-
{ id: "linking" as TabId, label: "Linking", beta: true, loading: linkingOps.isLoading },
|
|
259
|
-
{ id: "meta" as TabId, label: "Meta", beta: true },
|
|
260
|
-
{ id: "technical" as TabId, label: "Other Recs", beta: true, loading: technicalOps.isLinkCheckLoading },
|
|
261
|
-
];
|
|
262
|
-
|
|
263
|
-
return (
|
|
264
|
-
<div
|
|
265
|
-
className="seo-copilot-panel"
|
|
266
|
-
style={{
|
|
267
|
-
height: "100%",
|
|
268
|
-
display: "flex",
|
|
269
|
-
flexDirection: "column",
|
|
270
|
-
// backgroundColor (longhand) so the sheen background-image in INJECTED_CSS isn't reset
|
|
271
|
-
backgroundColor: PANEL_BG,
|
|
272
|
-
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif",
|
|
273
|
-
opacity: 1,
|
|
274
|
-
position: "relative",
|
|
275
|
-
}}
|
|
276
|
-
>
|
|
277
|
-
<style dangerouslySetInnerHTML={{ __html: INJECTED_CSS }} />
|
|
278
|
-
|
|
279
|
-
{/* First-run onboarding popup (collapses to the (i) icon in the header) */}
|
|
280
|
-
{popupMode !== "hidden" && <OnboardingCard onDismiss={dismissPopup} closing={popupClosing} />}
|
|
281
|
-
|
|
282
|
-
{/* Header */}
|
|
283
|
-
<div
|
|
284
|
-
onMouseDown={isFloating ? onDragStart : undefined}
|
|
285
|
-
style={{
|
|
286
|
-
position: "relative",
|
|
287
|
-
display: "flex",
|
|
288
|
-
alignItems: "center",
|
|
289
|
-
justifyContent: "space-between",
|
|
290
|
-
padding: "14px 16px",
|
|
291
|
-
background: `linear-gradient(180deg, #FFFFFF 0%, ${PANEL_BG} 100%)`,
|
|
292
|
-
boxShadow: "0 1px 0 rgba(0,0,0,0.04)",
|
|
293
|
-
zIndex: 10,
|
|
294
|
-
cursor: headerCursor,
|
|
295
|
-
userSelect: "none",
|
|
296
|
-
flexShrink: 0,
|
|
297
|
-
}}
|
|
298
|
-
>
|
|
299
|
-
<div style={{ display: "flex", alignItems: "center", gap: 6 }}>
|
|
300
|
-
<LogoIcon />
|
|
301
|
-
<span style={{ fontWeight: 700, fontSize: 15, letterSpacing: "-0.01em" }}>
|
|
302
|
-
<span style={{ color: MJH_GOLD }}>SEO</span>
|
|
303
|
-
<span style={{ color: MJH_SLATE }}> copilot</span>
|
|
304
|
-
</span>
|
|
305
|
-
</div>
|
|
306
|
-
<div style={{ display: "flex", alignItems: "center", gap: isFloating ? 4 : 6 }}>
|
|
307
|
-
<OnboardingInfoButton onClick={openPopupPersistent} />
|
|
308
|
-
<ReportProblemButton
|
|
309
|
-
activeTab={activeTab}
|
|
310
|
-
publication={publication}
|
|
311
|
-
documentId={documentId}
|
|
312
|
-
documentType={documentType}
|
|
313
|
-
primaryKeyword={effectivePrimary}
|
|
314
|
-
/>
|
|
315
|
-
{isFloating && onToggleFullscreen && (
|
|
316
|
-
<button
|
|
317
|
-
onClick={(e) => {
|
|
318
|
-
e.stopPropagation();
|
|
319
|
-
onToggleFullscreen();
|
|
320
|
-
}}
|
|
321
|
-
onMouseDown={(e) => e.stopPropagation()}
|
|
322
|
-
style={{
|
|
323
|
-
background: isFullscreen ? "rgba(230,192,27,0.15)" : "rgba(0,0,0,0.04)",
|
|
324
|
-
border: "none",
|
|
325
|
-
borderRadius: 6,
|
|
326
|
-
cursor: "pointer",
|
|
327
|
-
padding: "4px 8px",
|
|
328
|
-
display: "flex",
|
|
329
|
-
alignItems: "center",
|
|
330
|
-
gap: 4,
|
|
331
|
-
color: isFullscreen ? "#8B7310" : "#6b7280",
|
|
332
|
-
fontSize: 10,
|
|
333
|
-
fontWeight: 600,
|
|
334
|
-
transition: "all 150ms",
|
|
335
|
-
}}
|
|
336
|
-
>
|
|
337
|
-
{isFullscreen ? (
|
|
338
|
-
<>
|
|
339
|
-
<svg width="12" height="12" viewBox="0 0 20 20" fill="currentColor">
|
|
340
|
-
<path d="M3.28 2.22a.75.75 0 00-1.06 1.06L5.44 6.5H3.75a.75.75 0 000 1.5h4.5A.75.75 0 009 7.25v-4.5a.75.75 0 00-1.5 0v1.69L4.28 1.22a.75.75 0 00-1 1zM16.72 17.78a.75.75 0 001.06-1.06L14.56 13.5h1.69a.75.75 0 000-1.5h-4.5a.75.75 0 00-.75.75v4.5a.75.75 0 001.5 0v-1.69l3.22 3.22z" />
|
|
341
|
-
</svg>
|
|
342
|
-
Exit fullscreen
|
|
343
|
-
</>
|
|
344
|
-
) : (
|
|
345
|
-
<>
|
|
346
|
-
<svg width="12" height="12" viewBox="0 0 20 20" fill="currentColor">
|
|
347
|
-
<path d="M13.28 7.78l3.22-3.22v1.69a.75.75 0 001.5 0v-4.5a.75.75 0 00-.75-.75h-4.5a.75.75 0 000 1.5h1.69l-3.22 3.22a.75.75 0 001.06 1.06zM2 17.25a.75.75 0 001.5 0v-1.69l3.22 3.22a.75.75 0 001.06-1.06L4.56 14.5h1.69a.75.75 0 000-1.5h-4.5a.75.75 0 00-.75.75v4.5z" />
|
|
348
|
-
</svg>
|
|
349
|
-
Fullscreen
|
|
350
|
-
</>
|
|
351
|
-
)}
|
|
352
|
-
</button>
|
|
353
|
-
)}
|
|
354
|
-
{isFloating && onToggleFloat && (
|
|
355
|
-
<button
|
|
356
|
-
onClick={(e) => {
|
|
357
|
-
e.stopPropagation();
|
|
358
|
-
onToggleFloat();
|
|
359
|
-
}}
|
|
360
|
-
onMouseDown={(e) => e.stopPropagation()}
|
|
361
|
-
style={{
|
|
362
|
-
background: "rgba(0,93,172,0.08)",
|
|
363
|
-
border: "none",
|
|
364
|
-
borderRadius: 6,
|
|
365
|
-
cursor: "pointer",
|
|
366
|
-
padding: "4px 8px",
|
|
367
|
-
display: "flex",
|
|
368
|
-
alignItems: "center",
|
|
369
|
-
gap: 4,
|
|
370
|
-
color: MJH_BLUE,
|
|
371
|
-
fontSize: 10,
|
|
372
|
-
fontWeight: 600,
|
|
373
|
-
transition: "all 150ms",
|
|
374
|
-
}}
|
|
375
|
-
>
|
|
376
|
-
<svg width="12" height="12" viewBox="0 0 20 20" fill="currentColor">
|
|
377
|
-
<path
|
|
378
|
-
fillRule="evenodd"
|
|
379
|
-
d="M4.25 2A2.25 2.25 0 002 4.25v11.5A2.25 2.25 0 004.25 18h11.5A2.25 2.25 0 0018 15.75V4.25A2.25 2.25 0 0015.75 2H4.25zM3.5 4.25a.75.75 0 01.75-.75h11.5a.75.75 0 01.75.75v11.5a.75.75 0 01-.75.75H4.25a.75.75 0 01-.75-.75V4.25z"
|
|
380
|
-
clipRule="evenodd"
|
|
381
|
-
/>
|
|
382
|
-
</svg>
|
|
383
|
-
Dock
|
|
384
|
-
</button>
|
|
385
|
-
)}
|
|
386
|
-
{!isFloating && onToggleFloat && (
|
|
387
|
-
<button
|
|
388
|
-
onClick={(e) => {
|
|
389
|
-
e.stopPropagation();
|
|
390
|
-
onToggleFloat();
|
|
391
|
-
}}
|
|
392
|
-
onMouseDown={(e) => e.stopPropagation()}
|
|
393
|
-
style={{
|
|
394
|
-
background: "none",
|
|
395
|
-
border: "none",
|
|
396
|
-
cursor: "pointer",
|
|
397
|
-
padding: 2,
|
|
398
|
-
display: "flex",
|
|
399
|
-
alignItems: "center",
|
|
400
|
-
color: "#9ca3af",
|
|
401
|
-
transition: "color 150ms",
|
|
402
|
-
}}
|
|
403
|
-
title="Pop out"
|
|
404
|
-
>
|
|
405
|
-
<svg width="14" height="14" viewBox="0 0 20 20" fill="currentColor">
|
|
406
|
-
<path d="M4.25 5.5a.75.75 0 00-.75.75v8.5c0 .414.336.75.75.75h8.5a.75.75 0 00.75-.75v-4a.75.75 0 011.5 0v4A2.25 2.25 0 0112.75 17h-8.5A2.25 2.25 0 012 14.75v-8.5A2.25 2.25 0 014.25 4h5a.75.75 0 010 1.5h-5z" />
|
|
407
|
-
<path d="M6.194 12.753a.75.75 0 001.06.053L16.5 4.44v2.81a.75.75 0 001.5 0v-4.5a.75.75 0 00-.75-.75h-4.5a.75.75 0 000 1.5h2.553l-9.056 8.194a.75.75 0 00-.053 1.06z" />
|
|
408
|
-
</svg>
|
|
409
|
-
</button>
|
|
410
|
-
)}
|
|
411
|
-
{isLoading && (
|
|
412
|
-
<div
|
|
413
|
-
style={{
|
|
414
|
-
width: 8,
|
|
415
|
-
height: 8,
|
|
416
|
-
borderRadius: "50%",
|
|
417
|
-
background: MJH_GOLD,
|
|
418
|
-
animation: "content-pulse 2s ease-in-out infinite",
|
|
419
|
-
}}
|
|
420
|
-
/>
|
|
421
|
-
)}
|
|
422
|
-
{onClose && (
|
|
423
|
-
<button
|
|
424
|
-
onClick={(e) => {
|
|
425
|
-
e.stopPropagation();
|
|
426
|
-
onClose();
|
|
427
|
-
}}
|
|
428
|
-
onMouseDown={(e) => e.stopPropagation()}
|
|
429
|
-
style={{
|
|
430
|
-
background: "none",
|
|
431
|
-
border: "none",
|
|
432
|
-
cursor: "pointer",
|
|
433
|
-
padding: 2,
|
|
434
|
-
display: "flex",
|
|
435
|
-
alignItems: "center",
|
|
436
|
-
color: "#9ca3af",
|
|
437
|
-
transition: "color 150ms",
|
|
438
|
-
}}
|
|
439
|
-
title="Close"
|
|
440
|
-
>
|
|
441
|
-
<svg width="14" height="14" viewBox="0 0 20 20" fill="currentColor">
|
|
442
|
-
<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" />
|
|
443
|
-
</svg>
|
|
444
|
-
</button>
|
|
445
|
-
)}
|
|
446
|
-
</div>
|
|
447
|
-
<div
|
|
448
|
-
style={{
|
|
449
|
-
position: "absolute",
|
|
450
|
-
bottom: 3,
|
|
451
|
-
left: 38,
|
|
452
|
-
fontSize: 9,
|
|
453
|
-
color: "rgba(0,0,0,0.42)",
|
|
454
|
-
fontWeight: 400,
|
|
455
|
-
fontStyle: "italic",
|
|
456
|
-
letterSpacing: "0.02em",
|
|
457
|
-
}}
|
|
458
|
-
>
|
|
459
|
-
More eyes on your expertise
|
|
460
|
-
</div>
|
|
461
|
-
</div>
|
|
462
|
-
|
|
463
|
-
{/* Tab Bar */}
|
|
464
|
-
<TabBar tabs={tabDefs} activeTab={activeTab} onTabChange={handleTabChange} />
|
|
465
|
-
|
|
466
|
-
{/* Universal AI disclaimer - lives once at the panel level so every tab
|
|
467
|
-
inherits it. Subtle muted strip; the editor sees it on every screen. */}
|
|
468
|
-
<div
|
|
469
|
-
style={{
|
|
470
|
-
padding: "5px 12px",
|
|
471
|
-
fontSize: 10,
|
|
472
|
-
color: "#6b7280",
|
|
473
|
-
lineHeight: 1.4,
|
|
474
|
-
textAlign: "center",
|
|
475
|
-
background: "rgba(255,255,255,0.45)",
|
|
476
|
-
borderBottom: "1px solid rgba(0,0,0,0.06)",
|
|
477
|
-
flexShrink: 0,
|
|
478
|
-
}}
|
|
479
|
-
>
|
|
480
|
-
Recommendations are generated by AI. Verify details before publishing.
|
|
481
|
-
</div>
|
|
482
|
-
|
|
483
|
-
{/* Tab content + chat split */}
|
|
484
|
-
<div ref={containerRef} style={{ flex: 1, display: "flex", flexDirection: "column", overflow: "hidden" }}>
|
|
485
|
-
{/* Tab content area (the "recommendations" zone) - all tabs mounted, hidden
|
|
486
|
-
when inactive to preserve state. Carries the warm gold zone gradient that
|
|
487
|
-
mirrors the chat's blue gradient below (gold = analysis, blue = chat). */}
|
|
488
|
-
<div
|
|
489
|
-
style={{
|
|
490
|
-
height: chatOpen ? `${splitPercent}%` : undefined,
|
|
491
|
-
flex: chatOpen ? undefined : 1,
|
|
492
|
-
overflow: "auto",
|
|
493
|
-
minHeight: 0,
|
|
494
|
-
background: RECS_ZONE_BG,
|
|
495
|
-
}}
|
|
496
|
-
>
|
|
497
|
-
<div style={{ display: activeTab === "keywords" ? "block" : "none" }}>
|
|
498
|
-
{/* key forces full remount when document changes so all internal state resets cleanly */}
|
|
499
|
-
<KeywordPanel
|
|
500
|
-
key={documentId || "default"}
|
|
501
|
-
text={text}
|
|
502
|
-
publication={publication}
|
|
503
|
-
seedKeywords={seedKeywords}
|
|
504
|
-
onSeedsChange={onSeedsChange}
|
|
505
|
-
onSelectPrimary={onSelectPrimary}
|
|
506
|
-
secondaryKeyword={effectiveSecondary}
|
|
507
|
-
onSelectSecondary={onSelectSecondary}
|
|
508
|
-
documentFields={documentFields}
|
|
509
|
-
documentId={documentId}
|
|
510
|
-
externalAnalysis={keywordAnalysisState}
|
|
511
|
-
/>
|
|
512
|
-
</div>
|
|
513
|
-
<div style={{ display: activeTab === "summary" ? "block" : "none" }}>
|
|
514
|
-
<SummaryTab
|
|
515
|
-
text={text}
|
|
516
|
-
analysis={keywordAnalysisState.analysis}
|
|
517
|
-
deepAnalysis={keywordAnalysisState.deepAnalysis}
|
|
518
|
-
documentFields={documentFields}
|
|
519
|
-
primaryKeyword={effectivePrimary}
|
|
520
|
-
secondaryKeyword={effectiveSecondary}
|
|
521
|
-
linkingSuggestions={linkingOps.suggestions}
|
|
522
|
-
linkCheckResults={technicalOps.linkCheckResults}
|
|
523
|
-
isAnyLoading={summaryOps.isAnyLoading}
|
|
524
|
-
onGenerateAll={summaryOps.onGenerateAll}
|
|
525
|
-
onItemClick={summaryOps.onItemClick}
|
|
526
|
-
/>
|
|
527
|
-
</div>
|
|
528
|
-
<div style={{ display: activeTab === "aeo" ? "block" : "none" }}>
|
|
529
|
-
<AEOTab
|
|
530
|
-
text={text}
|
|
531
|
-
deepAnalysis={keywordAnalysisState.deepAnalysis}
|
|
532
|
-
isDeepLoading={keywordAnalysisState.isDeepLoading}
|
|
533
|
-
publication={publication}
|
|
534
|
-
runDeepAnalysis={keywordAnalysisState.runDeepAnalysis}
|
|
535
|
-
aeoContentChanged={keywordAnalysisState.aeoContentChanged}
|
|
536
|
-
headings={documentFields?.headings}
|
|
537
|
-
contentSuggestions={aeoOps.contentSuggestions}
|
|
538
|
-
isCSLoading={aeoOps.isCSLoading}
|
|
539
|
-
csError={aeoOps.csError}
|
|
540
|
-
loadContentSuggestions={aeoOps.loadContentSuggestions}
|
|
541
|
-
/>
|
|
542
|
-
</div>
|
|
543
|
-
<div style={{ display: activeTab === "linking" ? "block" : "none" }}>
|
|
544
|
-
<LinkingTab
|
|
545
|
-
analysis={keywordAnalysisState.analysis}
|
|
546
|
-
suggestions={linkingOps.suggestions}
|
|
547
|
-
isLoading={linkingOps.isLoading}
|
|
548
|
-
error={linkingOps.error}
|
|
549
|
-
isStale={linkingOps.isStale}
|
|
550
|
-
onRefresh={linkingOps.refresh}
|
|
551
|
-
documentId={documentId}
|
|
552
|
-
publication={publication}
|
|
553
|
-
text={text}
|
|
554
|
-
sanityBaseUrl={sanityBaseUrl}
|
|
555
|
-
documentType={documentType}
|
|
556
|
-
/>
|
|
557
|
-
</div>
|
|
558
|
-
<div style={{ display: activeTab === "meta" ? "block" : "none" }}>
|
|
559
|
-
<MetaTab documentFields={documentFields} primaryKeyword={effectivePrimary} secondaryKeyword={effectiveSecondary} isLoading={docLoading} />
|
|
560
|
-
</div>
|
|
561
|
-
<div style={{ display: activeTab === "technical" ? "block" : "none" }}>
|
|
562
|
-
<TechnicalTab
|
|
563
|
-
text={text}
|
|
564
|
-
documentFields={documentFields}
|
|
565
|
-
isLoading={docLoading}
|
|
566
|
-
primaryKeyword={effectivePrimary}
|
|
567
|
-
secondaryKeyword={effectiveSecondary}
|
|
568
|
-
linkCheckResults={technicalOps.linkCheckResults}
|
|
569
|
-
isLinkCheckLoading={technicalOps.isLinkCheckLoading}
|
|
570
|
-
linkCheckError={technicalOps.linkCheckError}
|
|
571
|
-
hasRunLinkCheck={technicalOps.hasRunLinkCheck}
|
|
572
|
-
onCheckLinks={technicalOps.onCheckLinks}
|
|
573
|
-
/>
|
|
574
|
-
</div>
|
|
575
|
-
</div>
|
|
576
|
-
|
|
577
|
-
{/* Draggable Divider */}
|
|
578
|
-
{chatOpen && (
|
|
579
|
-
<div
|
|
580
|
-
onMouseDown={onMouseDown}
|
|
581
|
-
style={{
|
|
582
|
-
height: 6,
|
|
583
|
-
cursor: "row-resize",
|
|
584
|
-
background: "linear-gradient(180deg, rgba(0,0,0,0.04) 0%, rgba(0,0,0,0.08) 50%, rgba(0,0,0,0.04) 100%)",
|
|
585
|
-
display: "flex",
|
|
586
|
-
alignItems: "center",
|
|
587
|
-
justifyContent: "center",
|
|
588
|
-
flexShrink: 0,
|
|
589
|
-
}}
|
|
590
|
-
>
|
|
591
|
-
<div style={{ width: 32, height: 2, borderRadius: 1, background: "#d1d5db" }} />
|
|
592
|
-
</div>
|
|
593
|
-
)}
|
|
594
|
-
|
|
595
|
-
{/* Persistent Chat zone - same component, always mounted; hidden when
|
|
596
|
-
collapsed. The blue zone gradient lives HERE (on the wrapper) so the
|
|
597
|
-
collapse/expand toggle bar, the messages, and the composer all read as
|
|
598
|
-
one continuous blue zone - the toggle is part of the chat, not the gold
|
|
599
|
-
panel. (ChatPanel itself is transparent and frosts over this.) */}
|
|
600
|
-
<div
|
|
601
|
-
style={{
|
|
602
|
-
height: chatOpen ? `${100 - splitPercent}%` : "auto",
|
|
603
|
-
overflow: "hidden",
|
|
604
|
-
display: "flex",
|
|
605
|
-
flexDirection: "column",
|
|
606
|
-
flexShrink: chatOpen ? undefined : 0,
|
|
607
|
-
minHeight: 0,
|
|
608
|
-
background: CHAT_ZONE_BG,
|
|
609
|
-
}}
|
|
610
|
-
>
|
|
611
|
-
<button
|
|
612
|
-
onClick={() => onChatOpenChange(!chatOpen)}
|
|
613
|
-
style={{
|
|
614
|
-
width: "100%",
|
|
615
|
-
padding: "4px 12px",
|
|
616
|
-
display: "flex",
|
|
617
|
-
alignItems: "center",
|
|
618
|
-
justifyContent: "space-between",
|
|
619
|
-
background: "transparent",
|
|
620
|
-
border: "none",
|
|
621
|
-
// The toggle is the top edge of the blue glass chat zone: a soft
|
|
622
|
-
// white rim reads as glass (not a hard black seam), and the inner
|
|
623
|
-
// divider when open stays whisper-light so toggle->messages flows.
|
|
624
|
-
borderTop: "1px solid rgba(255,255,255,0.55)",
|
|
625
|
-
borderBottom: chatOpen ? "1px solid rgba(255,255,255,0.45)" : "none",
|
|
626
|
-
cursor: "pointer",
|
|
627
|
-
flexShrink: 0,
|
|
628
|
-
}}
|
|
629
|
-
>
|
|
630
|
-
<span
|
|
631
|
-
style={{
|
|
632
|
-
fontSize: 10,
|
|
633
|
-
fontWeight: 700,
|
|
634
|
-
textTransform: "uppercase",
|
|
635
|
-
letterSpacing: "0.05em",
|
|
636
|
-
color: "rgba(0,0,0,0.55)",
|
|
637
|
-
}}
|
|
638
|
-
>
|
|
639
|
-
Chat
|
|
640
|
-
</span>
|
|
641
|
-
<svg
|
|
642
|
-
width="12"
|
|
643
|
-
height="12"
|
|
644
|
-
viewBox="0 0 20 20"
|
|
645
|
-
fill="rgba(0,0,0,0.55)"
|
|
646
|
-
style={{ transform: chatOpen ? "rotate(0deg)" : "rotate(-90deg)", transition: "transform 200ms" }}
|
|
647
|
-
>
|
|
648
|
-
<path
|
|
649
|
-
fillRule="evenodd"
|
|
650
|
-
d="M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z"
|
|
651
|
-
clipRule="evenodd"
|
|
652
|
-
/>
|
|
653
|
-
</svg>
|
|
654
|
-
</button>
|
|
655
|
-
<div
|
|
656
|
-
style={{
|
|
657
|
-
flex: chatOpen ? 1 : 0,
|
|
658
|
-
overflow: "hidden",
|
|
659
|
-
display: chatOpen ? "flex" : "none",
|
|
660
|
-
flexDirection: "column",
|
|
661
|
-
minHeight: 0,
|
|
662
|
-
}}
|
|
663
|
-
>
|
|
664
|
-
<ChatPanel
|
|
665
|
-
messages={chatState.messages}
|
|
666
|
-
isStreaming={chatState.isStreaming}
|
|
667
|
-
sendMessage={chatState.sendMessage}
|
|
668
|
-
clearChat={chatState.clearChat}
|
|
669
|
-
documentId={documentId}
|
|
670
|
-
/>
|
|
671
|
-
</div>
|
|
672
|
-
</div>
|
|
673
|
-
</div>
|
|
674
|
-
|
|
675
|
-
</div>
|
|
676
|
-
);
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
// Inner component that hosts lifted state and renders PanelContent.
|
|
680
|
-
function SEOCopilotInner({ config, onClose }: { config: SEOCopilotConfig; onClose?: () => void }) {
|
|
681
|
-
// Float / dock state - persisted globally so the user's preferred mode survives reloads.
|
|
682
|
-
const [isFloating, setIsFloating] = usePersistentState<boolean>("seo-copilot-ui-floating", false);
|
|
683
|
-
const [isFullscreen, setIsFullscreen] = usePersistentState<boolean>("seo-copilot-ui-fullscreen", false);
|
|
684
|
-
const [floatPos, setFloatPos] = usePersistentState<{ x: number; y: number }>(
|
|
685
|
-
"seo-copilot-ui-float-pos",
|
|
686
|
-
{ x: typeof window !== "undefined" ? window.innerWidth - 420 : 400, y: 80 }
|
|
687
|
-
);
|
|
688
|
-
const [floatSize, setFloatSize] = usePersistentState<{ width: number; height: number }>(
|
|
689
|
-
"seo-copilot-ui-float-size",
|
|
690
|
-
{ width: 380, height: typeof window !== "undefined" ? Math.round(window.innerHeight * 0.8) : 600 }
|
|
691
|
-
);
|
|
692
|
-
const dragOffset = useRef<{ dx: number; dy: number } | null>(null);
|
|
693
|
-
const resizeStart = useRef<{ startX: number; startY: number; startW: number; startH: number } | null>(null);
|
|
694
|
-
const activeDragCleanupRef = useRef<(() => void) | null>(null);
|
|
695
|
-
const activeResizeCleanupRef = useRef<(() => void) | null>(null);
|
|
696
|
-
|
|
697
|
-
const { text, isLoading: docLoading, documentFields, documentId, documentType } = useDocumentContent();
|
|
698
|
-
const { apiUrl } = useConfig();
|
|
699
|
-
|
|
700
|
-
// Resolve which Sanity dataset (= MJH publication) to read from. Each Studio
|
|
701
|
-
// workspace is bound to exactly one dataset, so the CURRENT workspace's
|
|
702
|
-
// dataset IS the publication. Prefer an explicit config.publication override,
|
|
703
|
-
// otherwise use the live workspace dataset. This makes the plugin work on
|
|
704
|
-
// every publication (onclive, hcplive, ajmc, ...) with zero per-workspace
|
|
705
|
-
// config - without it, a plugin installed as `seoCopilot({ apiUrl })` sends
|
|
706
|
-
// no publication and the backend falls back to the wrong/empty dataset.
|
|
707
|
-
const workspace = useWorkspace();
|
|
708
|
-
const effectivePublication = config.publication || workspace?.dataset;
|
|
709
|
-
|
|
710
|
-
// Studio origin + basePath - used to build "Inside Sanity" links that open a
|
|
711
|
-
// suggested article in a NEW Studio tab (leaving the editor's current tab alone).
|
|
712
|
-
const sanityBaseUrl = useMemo(() => {
|
|
713
|
-
if (typeof window === "undefined") return undefined;
|
|
714
|
-
const basePath = (workspace?.basePath || "/").replace(/\/+$/, "");
|
|
715
|
-
return `${window.location.origin}${basePath}`;
|
|
716
|
-
}, [workspace?.basePath]);
|
|
717
|
-
|
|
718
|
-
const seedCacheKey = documentId ? `seo-copilot-cache-${documentId}` : "seo-copilot-cache-v2";
|
|
719
|
-
const loadSeedsFromCache = useCallback((): string[] => {
|
|
720
|
-
try {
|
|
721
|
-
const c = localStorage.getItem(seedCacheKey);
|
|
722
|
-
if (c) return JSON.parse(c).seeds || [];
|
|
723
|
-
} catch {}
|
|
724
|
-
return [];
|
|
725
|
-
}, [seedCacheKey]);
|
|
726
|
-
const [seedKeywords, setSeedKeywordsRaw] = useState<string[]>(loadSeedsFromCache);
|
|
727
|
-
const setSeedKeywords = useCallback(
|
|
728
|
-
(seeds: string[]) => {
|
|
729
|
-
setSeedKeywordsRaw(seeds);
|
|
730
|
-
try {
|
|
731
|
-
const c = JSON.parse(localStorage.getItem(seedCacheKey) || "{}");
|
|
732
|
-
localStorage.setItem(seedCacheKey, JSON.stringify({ ...c, seeds }));
|
|
733
|
-
} catch {}
|
|
734
|
-
},
|
|
735
|
-
[seedCacheKey]
|
|
736
|
-
);
|
|
737
|
-
|
|
738
|
-
// Per-doc state - persisted under doc-scoped keys so a return to the doc restores everything
|
|
739
|
-
const selectedPrimaryKey = documentId ? `seo-copilot-primary-${documentId}` : "seo-copilot-primary-default";
|
|
740
|
-
const [selectedPrimary, setSelectedPrimary] = usePersistentState<string | undefined>(selectedPrimaryKey, undefined);
|
|
741
|
-
// Optional secondary target keyword - audits check the article against both.
|
|
742
|
-
const selectedSecondaryKey = documentId ? `seo-copilot-secondary-${documentId}` : "seo-copilot-secondary-default";
|
|
743
|
-
const [selectedSecondary, setSelectedSecondary] = usePersistentState<string>(selectedSecondaryKey, "");
|
|
744
|
-
|
|
745
|
-
// Reload seed cache when documentId changes (Sanity may reuse the inspector instance)
|
|
746
|
-
const seedsInitializedRef = useRef(false);
|
|
747
|
-
useEffect(() => {
|
|
748
|
-
if (!seedsInitializedRef.current) {
|
|
749
|
-
seedsInitializedRef.current = true;
|
|
750
|
-
return;
|
|
751
|
-
}
|
|
752
|
-
setSeedKeywordsRaw(loadSeedsFromCache());
|
|
753
|
-
}, [documentId, loadSeedsFromCache]);
|
|
754
|
-
|
|
755
|
-
// activeTab is intentionally NOT persisted - every fresh panel mount starts on
|
|
756
|
-
// Keywords, the workflow entry point. (Float / dock toggle keeps the same component
|
|
757
|
-
// instance, so the user's tab choice survives that without needing localStorage.)
|
|
758
|
-
const [activeTab, setActiveTab] = useState<TabId>("keywords");
|
|
759
|
-
// Chat is a collapsible bottom drawer - collapsed by default so tab content gets the
|
|
760
|
-
// full panel height. (Key bumped to -v35 so the old default-open value is dropped.)
|
|
761
|
-
const [chatOpen, setChatOpen] = usePersistentState<boolean>("seo-copilot-ui-chat-open-v35", false);
|
|
762
|
-
const [splitPercent, setSplitPercent] = usePersistentState<number>("seo-copilot-ui-split", 70);
|
|
763
|
-
|
|
764
|
-
const keywordAnalysisState = useKeywordAnalysis(text, apiUrl, effectivePublication, seedKeywords, documentFields, selectedPrimary, documentId, selectedSecondary);
|
|
765
|
-
|
|
766
|
-
// Effective primary (matches PanelContent's resolution)
|
|
767
|
-
const effectivePrimary = selectedPrimary || keywordAnalysisState.analysis?.primaryKeyword?.term || "";
|
|
768
|
-
|
|
769
|
-
// Clear the secondary keyword if the user promotes it to primary - otherwise both
|
|
770
|
-
// slots hold the same term and all secondary-coverage audits produce false positives.
|
|
771
|
-
useEffect(() => {
|
|
772
|
-
if (selectedSecondary && effectivePrimary && selectedSecondary.toLowerCase() === effectivePrimary.toLowerCase()) {
|
|
773
|
-
setSelectedSecondary("");
|
|
774
|
-
}
|
|
775
|
-
}, [effectivePrimary, selectedSecondary, setSelectedSecondary]);
|
|
776
|
-
|
|
777
|
-
// Build keyword panel data (consumed by chat). Lifted here so chat hook lives at top level.
|
|
778
|
-
const keywordPanelData = useMemo(() => {
|
|
779
|
-
const analysis = keywordAnalysisState.analysis;
|
|
780
|
-
if (!analysis) return undefined;
|
|
781
|
-
return {
|
|
782
|
-
primaryKeyword: { term: analysis.primaryKeyword.term, volume: analysis.primaryKeyword.volume },
|
|
783
|
-
supportingKeywords: (analysis.supportingKeywords || []).map((kw) => ({ term: kw.term, volume: kw.volume })),
|
|
784
|
-
missingKeywords: analysis.missingKeywords.map((kw) => ({ term: kw.term, volume: kw.volume })),
|
|
785
|
-
aeoData: keywordAnalysisState.deepAnalysis?.aeo
|
|
786
|
-
? {
|
|
787
|
-
questionHeadings: (keywordAnalysisState.deepAnalysis.aeo.questionHeadings || []).map((h) => ({
|
|
788
|
-
suggestedHeading: h.suggestedHeading,
|
|
789
|
-
rationale: h.rationale,
|
|
790
|
-
})),
|
|
791
|
-
}
|
|
792
|
-
: undefined,
|
|
793
|
-
};
|
|
794
|
-
}, [keywordAnalysisState.analysis, keywordAnalysisState.deepAnalysis]);
|
|
795
|
-
|
|
796
|
-
// Chat hook lifted here so in-flight streams survive PanelContent remount (undock)
|
|
797
|
-
const chatHookState = useSEOChat(apiUrl, text, effectivePublication, keywordPanelData, documentId);
|
|
798
|
-
|
|
799
|
-
// AEO content suggestions - lifted to SEOCopilotInner so in-flight requests survive undock,
|
|
800
|
-
// and PERSISTED per-doc so generated suggestions come back after reload.
|
|
801
|
-
// (FAQ output removed 2026-05 after Google sunset FAQ rich results.)
|
|
802
|
-
const contentSuggestionsKey = documentId ? `seo-copilot-content-suggestions-${documentId}` : "seo-copilot-content-suggestions-default";
|
|
803
|
-
const [contentSuggestions, setContentSuggestions] = usePersistentState<ContentSuggestions | null>(contentSuggestionsKey, null);
|
|
804
|
-
const [isCSLoading, setIsCSLoading] = useState(false);
|
|
805
|
-
const [csError, setCsError] = useState<string | null>(null);
|
|
806
|
-
const aeoOpVersionRef = useRef(0);
|
|
807
|
-
const csAbortRef = useRef<AbortController | null>(null);
|
|
808
|
-
// Only reset *transient* state on doc change. Persisted state is reloaded automatically
|
|
809
|
-
// by usePersistentState when its key changes.
|
|
810
|
-
const didInitAeoRef = useRef(false);
|
|
811
|
-
useEffect(() => {
|
|
812
|
-
if (!didInitAeoRef.current) {
|
|
813
|
-
didInitAeoRef.current = true;
|
|
814
|
-
return;
|
|
815
|
-
}
|
|
816
|
-
aeoOpVersionRef.current += 1;
|
|
817
|
-
setIsCSLoading(false);
|
|
818
|
-
setCsError(null);
|
|
819
|
-
}, [documentId]);
|
|
820
|
-
|
|
821
|
-
const loadContentSuggestions = useCallback(async () => {
|
|
822
|
-
const myVersion = aeoOpVersionRef.current;
|
|
823
|
-
setIsCSLoading(true);
|
|
824
|
-
setCsError(null);
|
|
825
|
-
try {
|
|
826
|
-
csAbortRef.current?.abort(); const csController = new AbortController(); csAbortRef.current = csController;
|
|
827
|
-
const data = await fetchContentSuggestions(apiUrl, text, effectivePrimary, effectivePublication, csController.signal);
|
|
828
|
-
// This call was superseded by a newer one (e.g. rapid re-click). Bail silently so the
|
|
829
|
-
// aborted call's empty result does not flash a false "No suggestions returned" error.
|
|
830
|
-
if (csController.signal.aborted) return;
|
|
831
|
-
if (aeoOpVersionRef.current !== myVersion) return;
|
|
832
|
-
if (
|
|
833
|
-
data.keyTakeaways.length === 0 &&
|
|
834
|
-
data.infographicOpportunities.length === 0 &&
|
|
835
|
-
data.bulletListItems.length === 0
|
|
836
|
-
) {
|
|
837
|
-
setCsError("No suggestions returned. Try again with more content.");
|
|
838
|
-
} else {
|
|
839
|
-
setContentSuggestions(data);
|
|
840
|
-
}
|
|
841
|
-
} catch {
|
|
842
|
-
if (aeoOpVersionRef.current !== myVersion) return;
|
|
843
|
-
setCsError("Could not generate content suggestions. Try again.");
|
|
844
|
-
}
|
|
845
|
-
if (aeoOpVersionRef.current !== myVersion) return;
|
|
846
|
-
setIsCSLoading(false);
|
|
847
|
-
}, [apiUrl, text, effectivePrimary, effectivePublication]);
|
|
848
|
-
|
|
849
|
-
// Smart Linking - lifted state, persisted per-doc so suggestions survive remount.
|
|
850
|
-
// Auto-runs when keywords stabilize; user can also refresh manually.
|
|
851
|
-
const linkingKey = documentId ? `seo-copilot-linking-${documentId}` : "seo-copilot-linking-default";
|
|
852
|
-
const [linkingSuggestions, setLinkingSuggestions] = usePersistentState<LinkingSuggestion[]>(linkingKey, []);
|
|
853
|
-
const [isLinkingLoading, setIsLinkingLoading] = useState(false);
|
|
854
|
-
const [linkingError, setLinkingError] = useState<string | null>(null);
|
|
855
|
-
// The article text at the moment we last fetched - used to flag stale suggestions.
|
|
856
|
-
const [linkingFetchedText, setLinkingFetchedText] = useState("");
|
|
857
|
-
const linkingVersionRef = useRef(0);
|
|
858
|
-
const linkingAbortRef = useRef<AbortController | null>(null);
|
|
859
|
-
const didInitLinkingRef = useRef(false);
|
|
860
|
-
// Tracks the keyword signature we last fetched for, so the auto-fetch effect can skip
|
|
861
|
-
// re-fetching when persisted suggestions already cover the current doc. Declared here
|
|
862
|
-
// (not next to the effect) so the doc-change reset below can clear it.
|
|
863
|
-
const lastLinkingFetchKey = useRef<string>("");
|
|
864
|
-
useEffect(() => {
|
|
865
|
-
if (!didInitLinkingRef.current) {
|
|
866
|
-
didInitLinkingRef.current = true;
|
|
867
|
-
return;
|
|
868
|
-
}
|
|
869
|
-
linkingVersionRef.current += 1;
|
|
870
|
-
setIsLinkingLoading(false);
|
|
871
|
-
setLinkingError(null);
|
|
872
|
-
// Clear the fetch key so the auto-fetch effect re-evaluates for the new document
|
|
873
|
-
// and correctly skips when that doc already has persisted suggestions.
|
|
874
|
-
lastLinkingFetchKey.current = "";
|
|
875
|
-
}, [documentId]);
|
|
876
|
-
|
|
877
|
-
const supportingKeywordsForLinking = useMemo(() => {
|
|
878
|
-
const base = (keywordAnalysisState.analysis?.supportingKeywords || [])
|
|
879
|
-
.map((kw) => kw.term)
|
|
880
|
-
.filter(Boolean);
|
|
881
|
-
// Lead with the user's chosen secondary keyword so Linking weights it too.
|
|
882
|
-
const merged = selectedSecondary ? [selectedSecondary, ...base.filter((t) => t.toLowerCase() !== selectedSecondary.toLowerCase())] : base;
|
|
883
|
-
return merged.slice(0, 5);
|
|
884
|
-
}, [keywordAnalysisState.analysis, selectedSecondary]);
|
|
885
|
-
|
|
886
|
-
const refreshLinkingSuggestions = useCallback(async () => {
|
|
887
|
-
if (!text || text.trim().length < 50) return;
|
|
888
|
-
if (!effectivePrimary) return;
|
|
889
|
-
const myVersion = linkingVersionRef.current;
|
|
890
|
-
setIsLinkingLoading(true);
|
|
891
|
-
setLinkingError(null);
|
|
892
|
-
try {
|
|
893
|
-
linkingAbortRef.current?.abort(); const linkingController = new AbortController(); linkingAbortRef.current = linkingController;
|
|
894
|
-
const suggestions = await fetchLinkingSuggestions(
|
|
895
|
-
apiUrl,
|
|
896
|
-
text,
|
|
897
|
-
effectivePrimary,
|
|
898
|
-
supportingKeywordsForLinking,
|
|
899
|
-
documentId,
|
|
900
|
-
effectivePublication,
|
|
901
|
-
linkingController.signal
|
|
902
|
-
);
|
|
903
|
-
// Superseded by a newer fetch (e.g. rapid re-click). Bail before the aborted call's
|
|
904
|
-
// empty result overwrites the good persisted suggestions.
|
|
905
|
-
if (linkingController.signal.aborted) return;
|
|
906
|
-
if (linkingVersionRef.current !== myVersion) return;
|
|
907
|
-
setLinkingSuggestions(suggestions);
|
|
908
|
-
setLinkingFetchedText(text);
|
|
909
|
-
} catch {
|
|
910
|
-
if (linkingVersionRef.current !== myVersion) return;
|
|
911
|
-
setLinkingError("Could not fetch linking suggestions. Try again.");
|
|
912
|
-
}
|
|
913
|
-
if (linkingVersionRef.current !== myVersion) return;
|
|
914
|
-
setIsLinkingLoading(false);
|
|
915
|
-
}, [apiUrl, text, effectivePrimary, supportingKeywordsForLinking, documentId, effectivePublication]);
|
|
916
|
-
|
|
917
|
-
// Stale = the article changed materially since we last fetched suggestions.
|
|
918
|
-
const isLinkingStale = useMemo(() => {
|
|
919
|
-
if (!linkingFetchedText || linkingSuggestions.length === 0) return false;
|
|
920
|
-
if (Math.abs(text.length - linkingFetchedText.length) > 150) return true;
|
|
921
|
-
return text.slice(0, 300) !== linkingFetchedText.slice(0, 300);
|
|
922
|
-
}, [text, linkingFetchedText, linkingSuggestions.length]);
|
|
923
|
-
|
|
924
|
-
// Auto-fetch when primary keyword first resolves (and content is present)
|
|
925
|
-
useEffect(() => {
|
|
926
|
-
if (!text || text.trim().length < 50 || !effectivePrimary) return;
|
|
927
|
-
const fetchKey = `${documentId || "_"}|${effectivePrimary}|${supportingKeywordsForLinking.join(",")}`;
|
|
928
|
-
if (fetchKey === lastLinkingFetchKey.current) return;
|
|
929
|
-
if (linkingSuggestions.length > 0 && lastLinkingFetchKey.current === "") {
|
|
930
|
-
// We have persisted suggestions for this doc - skip auto-fetch on remount.
|
|
931
|
-
lastLinkingFetchKey.current = fetchKey;
|
|
932
|
-
return;
|
|
933
|
-
}
|
|
934
|
-
lastLinkingFetchKey.current = fetchKey;
|
|
935
|
-
refreshLinkingSuggestions();
|
|
936
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
937
|
-
}, [effectivePrimary, supportingKeywordsForLinking.join("|"), documentId]);
|
|
938
|
-
|
|
939
|
-
// ---- Link-check state (Technical tab) ----------------------------------
|
|
940
|
-
// Lifted here so the editor's check results survive tab switches and undock.
|
|
941
|
-
// Persisted per-document so opening the same article tomorrow shows the last run.
|
|
942
|
-
const linkCheckKey = documentId ? `seo-copilot-link-check-${documentId}` : "seo-copilot-link-check-default";
|
|
943
|
-
const [linkCheckResults, setLinkCheckResults] = usePersistentState<LinkCheckResult[]>(linkCheckKey, []);
|
|
944
|
-
const [hasRunLinkCheck, setHasRunLinkCheck] = usePersistentState<boolean>(`${linkCheckKey}-ran`, false);
|
|
945
|
-
const [isLinkCheckLoading, setIsLinkCheckLoading] = useState(false);
|
|
946
|
-
const [linkCheckError, setLinkCheckError] = useState<string | null>(null);
|
|
947
|
-
const linkCheckVersionRef = useRef(0);
|
|
948
|
-
const didInitLinkCheckRef = useRef(false);
|
|
949
|
-
useEffect(() => {
|
|
950
|
-
if (!didInitLinkCheckRef.current) {
|
|
951
|
-
didInitLinkCheckRef.current = true;
|
|
952
|
-
return;
|
|
953
|
-
}
|
|
954
|
-
linkCheckVersionRef.current += 1;
|
|
955
|
-
setIsLinkCheckLoading(false);
|
|
956
|
-
setLinkCheckError(null);
|
|
957
|
-
}, [documentId]);
|
|
958
|
-
|
|
959
|
-
const runLinkCheck = useCallback(async () => {
|
|
960
|
-
const urls = documentFields?.bodyLinks || [];
|
|
961
|
-
if (urls.length === 0) {
|
|
962
|
-
setHasRunLinkCheck(true);
|
|
963
|
-
setLinkCheckResults([]);
|
|
964
|
-
return;
|
|
965
|
-
}
|
|
966
|
-
const myVersion = linkCheckVersionRef.current;
|
|
967
|
-
setIsLinkCheckLoading(true);
|
|
968
|
-
setLinkCheckError(null);
|
|
969
|
-
try {
|
|
970
|
-
const results = await checkLinks(apiUrl, urls);
|
|
971
|
-
if (linkCheckVersionRef.current !== myVersion) return;
|
|
972
|
-
if (results.length === 0) {
|
|
973
|
-
setLinkCheckError("Could not reach the link checker. Try again.");
|
|
974
|
-
} else {
|
|
975
|
-
setLinkCheckResults(results);
|
|
976
|
-
setHasRunLinkCheck(true);
|
|
977
|
-
}
|
|
978
|
-
} catch {
|
|
979
|
-
if (linkCheckVersionRef.current !== myVersion) return;
|
|
980
|
-
setLinkCheckError("Link check failed. Try again.");
|
|
981
|
-
}
|
|
982
|
-
if (linkCheckVersionRef.current !== myVersion) return;
|
|
983
|
-
setIsLinkCheckLoading(false);
|
|
984
|
-
}, [apiUrl, documentFields?.bodyLinks, setHasRunLinkCheck, setLinkCheckResults]);
|
|
985
|
-
|
|
986
|
-
// Cleanup any active drag/resize listeners if the component unmounts mid-gesture.
|
|
987
|
-
useEffect(() => {
|
|
988
|
-
return () => {
|
|
989
|
-
activeDragCleanupRef.current?.();
|
|
990
|
-
activeResizeCleanupRef.current?.();
|
|
991
|
-
csAbortRef.current?.abort();
|
|
992
|
-
linkingAbortRef.current?.abort();
|
|
993
|
-
};
|
|
994
|
-
}, []);
|
|
995
|
-
|
|
996
|
-
// Re-run the WHOLE copilot (deep analysis + content suggestions + linking + link check),
|
|
997
|
-
// the same set the Summary tab's "Generate everything" button fires.
|
|
998
|
-
const runAllAnalyses = () => {
|
|
999
|
-
keywordAnalysisState.runDeepAnalysis();
|
|
1000
|
-
if (text && text.trim().length >= 100) loadContentSuggestions();
|
|
1001
|
-
if (text && text.trim().length >= 50 && effectivePrimary) refreshLinkingSuggestions();
|
|
1002
|
-
if ((documentFields?.bodyLinks || []).length > 0) runLinkCheck();
|
|
1003
|
-
};
|
|
1004
|
-
const runAllRef = useRef(runAllAnalyses);
|
|
1005
|
-
runAllRef.current = runAllAnalyses;
|
|
1006
|
-
|
|
1007
|
-
// Choosing or changing the secondary keyword on the CURRENT document re-runs everything so
|
|
1008
|
-
// every tab re-optimizes toward both keywords. Skip document switches and the first mount
|
|
1009
|
-
// (those are not user picks, just cache loads).
|
|
1010
|
-
const secAutoRunRef = useRef<{ doc?: string; sec: string; init: boolean }>({ doc: documentId, sec: selectedSecondary, init: true });
|
|
1011
|
-
useEffect(() => {
|
|
1012
|
-
const prev = secAutoRunRef.current;
|
|
1013
|
-
const docChanged = prev.doc !== documentId;
|
|
1014
|
-
const secChanged = prev.sec !== selectedSecondary;
|
|
1015
|
-
secAutoRunRef.current = { doc: documentId, sec: selectedSecondary, init: false };
|
|
1016
|
-
if (prev.init || docChanged || !secChanged) return;
|
|
1017
|
-
// Debounce so clicking THROUGH several secondary options only fires one full run-all.
|
|
1018
|
-
const t = setTimeout(() => runAllRef.current(), 1500);
|
|
1019
|
-
return () => clearTimeout(t);
|
|
1020
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1021
|
-
}, [selectedSecondary, documentId]);
|
|
1022
|
-
|
|
1023
|
-
const handleDragStart = useCallback(
|
|
1024
|
-
(e: React.MouseEvent) => {
|
|
1025
|
-
dragOffset.current = {
|
|
1026
|
-
dx: e.clientX - floatPos.x,
|
|
1027
|
-
dy: e.clientY - floatPos.y,
|
|
1028
|
-
};
|
|
1029
|
-
|
|
1030
|
-
const onMouseMove = (ev: MouseEvent) => {
|
|
1031
|
-
if (!dragOffset.current) return;
|
|
1032
|
-
setFloatPos({
|
|
1033
|
-
x: ev.clientX - dragOffset.current.dx,
|
|
1034
|
-
y: ev.clientY - dragOffset.current.dy,
|
|
1035
|
-
});
|
|
1036
|
-
};
|
|
1037
|
-
const onMouseUp = () => {
|
|
1038
|
-
activeDragCleanupRef.current = null;
|
|
1039
|
-
dragOffset.current = null;
|
|
1040
|
-
window.removeEventListener("mousemove", onMouseMove);
|
|
1041
|
-
window.removeEventListener("mouseup", onMouseUp);
|
|
1042
|
-
document.body.style.cursor = "";
|
|
1043
|
-
document.body.style.userSelect = "";
|
|
1044
|
-
};
|
|
1045
|
-
document.body.style.cursor = "grabbing";
|
|
1046
|
-
document.body.style.userSelect = "none";
|
|
1047
|
-
window.addEventListener("mousemove", onMouseMove);
|
|
1048
|
-
window.addEventListener("mouseup", onMouseUp);
|
|
1049
|
-
activeDragCleanupRef.current = () => {
|
|
1050
|
-
window.removeEventListener("mousemove", onMouseMove);
|
|
1051
|
-
window.removeEventListener("mouseup", onMouseUp);
|
|
1052
|
-
document.body.style.cursor = "";
|
|
1053
|
-
document.body.style.userSelect = "";
|
|
1054
|
-
};
|
|
1055
|
-
},
|
|
1056
|
-
[floatPos]
|
|
1057
|
-
);
|
|
1058
|
-
|
|
1059
|
-
const handleResizeStart = useCallback(
|
|
1060
|
-
(e: React.MouseEvent) => {
|
|
1061
|
-
e.preventDefault();
|
|
1062
|
-
e.stopPropagation();
|
|
1063
|
-
resizeStart.current = { startX: e.clientX, startY: e.clientY, startW: floatSize.width, startH: floatSize.height };
|
|
1064
|
-
document.body.style.cursor = "nwse-resize";
|
|
1065
|
-
document.body.style.userSelect = "none";
|
|
1066
|
-
const onMouseMove = (ev: MouseEvent) => {
|
|
1067
|
-
if (!resizeStart.current) return;
|
|
1068
|
-
const newW = Math.max(320, resizeStart.current.startW + (ev.clientX - resizeStart.current.startX));
|
|
1069
|
-
const newH = Math.max(300, resizeStart.current.startH + (ev.clientY - resizeStart.current.startY));
|
|
1070
|
-
setFloatSize({ width: newW, height: newH });
|
|
1071
|
-
};
|
|
1072
|
-
const onMouseUp = () => {
|
|
1073
|
-
activeResizeCleanupRef.current = null;
|
|
1074
|
-
resizeStart.current = null;
|
|
1075
|
-
document.body.style.cursor = "";
|
|
1076
|
-
document.body.style.userSelect = "";
|
|
1077
|
-
window.removeEventListener("mousemove", onMouseMove);
|
|
1078
|
-
window.removeEventListener("mouseup", onMouseUp);
|
|
1079
|
-
};
|
|
1080
|
-
window.addEventListener("mousemove", onMouseMove);
|
|
1081
|
-
window.addEventListener("mouseup", onMouseUp);
|
|
1082
|
-
activeResizeCleanupRef.current = () => {
|
|
1083
|
-
window.removeEventListener("mousemove", onMouseMove);
|
|
1084
|
-
window.removeEventListener("mouseup", onMouseUp);
|
|
1085
|
-
document.body.style.cursor = "";
|
|
1086
|
-
document.body.style.userSelect = "";
|
|
1087
|
-
};
|
|
1088
|
-
},
|
|
1089
|
-
[floatSize]
|
|
1090
|
-
);
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
const panelContent = (
|
|
1094
|
-
<PanelContent
|
|
1095
|
-
initialPublication={effectivePublication}
|
|
1096
|
-
isFloating={isFloating}
|
|
1097
|
-
isFullscreen={isFullscreen}
|
|
1098
|
-
onToggleFloat={() => {
|
|
1099
|
-
setIsFloating((v) => !v);
|
|
1100
|
-
setIsFullscreen(false);
|
|
1101
|
-
}}
|
|
1102
|
-
onToggleFullscreen={() => setIsFullscreen((v) => !v)}
|
|
1103
|
-
onClose={onClose}
|
|
1104
|
-
floatPos={floatPos}
|
|
1105
|
-
onDragStart={handleDragStart}
|
|
1106
|
-
seedKeywords={seedKeywords}
|
|
1107
|
-
onSeedsChange={setSeedKeywords}
|
|
1108
|
-
text={text}
|
|
1109
|
-
docLoading={docLoading}
|
|
1110
|
-
documentFields={documentFields}
|
|
1111
|
-
documentId={documentId}
|
|
1112
|
-
documentType={documentType}
|
|
1113
|
-
sanityBaseUrl={sanityBaseUrl}
|
|
1114
|
-
selectedPrimary={selectedPrimary}
|
|
1115
|
-
onSelectPrimary={setSelectedPrimary}
|
|
1116
|
-
selectedSecondary={selectedSecondary}
|
|
1117
|
-
onSelectSecondary={setSelectedSecondary}
|
|
1118
|
-
activeTab={activeTab}
|
|
1119
|
-
onActiveTabChange={setActiveTab}
|
|
1120
|
-
chatOpen={chatOpen}
|
|
1121
|
-
onChatOpenChange={setChatOpen}
|
|
1122
|
-
splitPercent={splitPercent}
|
|
1123
|
-
onSplitPercentChange={setSplitPercent}
|
|
1124
|
-
externalAnalysis={{
|
|
1125
|
-
analysis: keywordAnalysisState.analysis,
|
|
1126
|
-
isLoading: keywordAnalysisState.isLoading,
|
|
1127
|
-
isVolumesLoading: keywordAnalysisState.isVolumesLoading,
|
|
1128
|
-
error: keywordAnalysisState.error,
|
|
1129
|
-
deepAnalysis: keywordAnalysisState.deepAnalysis,
|
|
1130
|
-
isDeepLoading: keywordAnalysisState.isDeepLoading,
|
|
1131
|
-
runDeepAnalysis: keywordAnalysisState.runDeepAnalysis,
|
|
1132
|
-
refreshVolumes: keywordAnalysisState.refreshVolumes,
|
|
1133
|
-
aeoContentChanged: keywordAnalysisState.aeoContentChanged,
|
|
1134
|
-
}}
|
|
1135
|
-
chatState={chatHookState}
|
|
1136
|
-
aeoOps={{
|
|
1137
|
-
contentSuggestions,
|
|
1138
|
-
isCSLoading,
|
|
1139
|
-
csError,
|
|
1140
|
-
loadContentSuggestions,
|
|
1141
|
-
}}
|
|
1142
|
-
linkingOps={{
|
|
1143
|
-
suggestions: linkingSuggestions,
|
|
1144
|
-
isLoading: isLinkingLoading,
|
|
1145
|
-
error: linkingError,
|
|
1146
|
-
isStale: isLinkingStale,
|
|
1147
|
-
refresh: refreshLinkingSuggestions,
|
|
1148
|
-
}}
|
|
1149
|
-
technicalOps={{
|
|
1150
|
-
linkCheckResults,
|
|
1151
|
-
isLinkCheckLoading,
|
|
1152
|
-
linkCheckError,
|
|
1153
|
-
hasRunLinkCheck,
|
|
1154
|
-
onCheckLinks: runLinkCheck,
|
|
1155
|
-
}}
|
|
1156
|
-
summaryOps={{
|
|
1157
|
-
isAnyLoading:
|
|
1158
|
-
keywordAnalysisState.isLoading ||
|
|
1159
|
-
keywordAnalysisState.isVolumesLoading ||
|
|
1160
|
-
keywordAnalysisState.isDeepLoading ||
|
|
1161
|
-
isCSLoading ||
|
|
1162
|
-
isLinkingLoading ||
|
|
1163
|
-
isLinkCheckLoading,
|
|
1164
|
-
onGenerateAll: runAllAnalyses,
|
|
1165
|
-
onItemClick: (item) => {
|
|
1166
|
-
setActiveTab(item.jumpTo.tab);
|
|
1167
|
-
const id = item.jumpTo.anchorId;
|
|
1168
|
-
if (!id) return;
|
|
1169
|
-
// The destination tab goes display:none -> block on tab switch; give React a
|
|
1170
|
-
// beat to commit before scrolling, then flash the card so the editor sees it.
|
|
1171
|
-
setTimeout(() => {
|
|
1172
|
-
const el = typeof document !== "undefined" ? document.getElementById(id) : null;
|
|
1173
|
-
if (!el) return;
|
|
1174
|
-
el.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
1175
|
-
el.classList.add("seo-copilot-flash");
|
|
1176
|
-
setTimeout(() => el.classList.remove("seo-copilot-flash"), 1400);
|
|
1177
|
-
}, 80);
|
|
1178
|
-
},
|
|
1179
|
-
}}
|
|
1180
|
-
/>
|
|
1181
|
-
);
|
|
1182
|
-
|
|
1183
|
-
const floatingPanel = (
|
|
1184
|
-
<div
|
|
1185
|
-
style={{
|
|
1186
|
-
position: "fixed",
|
|
1187
|
-
left: isFullscreen ? 0 : floatPos.x,
|
|
1188
|
-
top: isFullscreen ? 0 : floatPos.y,
|
|
1189
|
-
width: isFullscreen ? "100vw" : floatSize.width,
|
|
1190
|
-
height: isFullscreen ? "100vh" : floatSize.height,
|
|
1191
|
-
zIndex: 2147483647,
|
|
1192
|
-
borderRadius: isFullscreen ? 0 : 12,
|
|
1193
|
-
overflow: "hidden",
|
|
1194
|
-
boxShadow: isFullscreen ? "none" : "0 8px 32px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.10)",
|
|
1195
|
-
border: isFullscreen ? "none" : "1px solid rgba(0,0,0,0.08)",
|
|
1196
|
-
background: PANEL_BG,
|
|
1197
|
-
}}
|
|
1198
|
-
>
|
|
1199
|
-
{panelContent}
|
|
1200
|
-
{!isFullscreen && (
|
|
1201
|
-
<div
|
|
1202
|
-
onMouseDown={handleResizeStart}
|
|
1203
|
-
style={{
|
|
1204
|
-
position: "absolute",
|
|
1205
|
-
bottom: 0,
|
|
1206
|
-
right: 0,
|
|
1207
|
-
width: 16,
|
|
1208
|
-
height: 16,
|
|
1209
|
-
cursor: "nwse-resize",
|
|
1210
|
-
display: "flex",
|
|
1211
|
-
alignItems: "center",
|
|
1212
|
-
justifyContent: "center",
|
|
1213
|
-
}}
|
|
1214
|
-
>
|
|
1215
|
-
<svg width="10" height="10" viewBox="0 0 10 10" fill="#9ca3af">
|
|
1216
|
-
<path d="M9 1v8H1" fill="none" stroke="#9ca3af" strokeWidth="1.5" strokeLinecap="round" />
|
|
1217
|
-
<path d="M9 5v4H5" fill="none" stroke="#9ca3af" strokeWidth="1.5" strokeLinecap="round" />
|
|
1218
|
-
</svg>
|
|
1219
|
-
</div>
|
|
1220
|
-
)}
|
|
1221
|
-
</div>
|
|
1222
|
-
);
|
|
1223
|
-
|
|
1224
|
-
if (isFloating) {
|
|
1225
|
-
return (
|
|
1226
|
-
<>
|
|
1227
|
-
<div
|
|
1228
|
-
style={{
|
|
1229
|
-
height: "100%",
|
|
1230
|
-
background: PANEL_BG,
|
|
1231
|
-
display: "flex",
|
|
1232
|
-
alignItems: "center",
|
|
1233
|
-
justifyContent: "center",
|
|
1234
|
-
}}
|
|
1235
|
-
>
|
|
1236
|
-
<span style={{ fontSize: 12, color: "rgba(0,0,0,0.5)" }}>SEO Copilot is floating</span>
|
|
1237
|
-
</div>
|
|
1238
|
-
{typeof document !== "undefined" && createPortal(floatingPanel, document.body)}
|
|
1239
|
-
</>
|
|
1240
|
-
);
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
return (
|
|
1244
|
-
<div style={{ height: "100%", background: PANEL_BG, position: "relative" as const, zIndex: 1 }}>
|
|
1245
|
-
{panelContent}
|
|
1246
|
-
</div>
|
|
1247
|
-
);
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
export default function SEOCopilotPanel({ config, onClose }: SEOCopilotPanelProps) {
|
|
1251
|
-
return (
|
|
1252
|
-
<Suspense
|
|
1253
|
-
fallback={
|
|
1254
|
-
<div style={{ padding: 16, display: "flex", alignItems: "center", gap: 12 }}>
|
|
1255
|
-
<LoadingBars />
|
|
1256
|
-
<span style={{ fontSize: 12, color: "#4b5563" }}>Loading SEO Copilot...</span>
|
|
1257
|
-
</div>
|
|
1258
|
-
}
|
|
1259
|
-
>
|
|
1260
|
-
<ConfigProvider config={config}>
|
|
1261
|
-
<SEOCopilotInner config={config} onClose={onClose} />
|
|
1262
|
-
</ConfigProvider>
|
|
1263
|
-
</Suspense>
|
|
1264
|
-
);
|
|
1265
|
-
}
|
|
1266
|
-
|
|
1267
|
-
export function LoadingBars({ size = "sm", color = MJH_GOLD }: { size?: "xs" | "sm"; color?: string }) {
|
|
1268
|
-
const barWidth = size === "xs" ? 4 : 6;
|
|
1269
|
-
const containerHeight = size === "xs" ? 10 : 14;
|
|
1270
|
-
|
|
1271
|
-
return (
|
|
1272
|
-
<div style={{ display: "inline-flex", alignItems: "flex-end", gap: 2, height: containerHeight }}>
|
|
1273
|
-
{[1, 2, 3].map((i) => (
|
|
1274
|
-
<div
|
|
1275
|
-
key={i}
|
|
1276
|
-
style={{
|
|
1277
|
-
width: barWidth,
|
|
1278
|
-
height: 8,
|
|
1279
|
-
borderRadius: 2,
|
|
1280
|
-
background: color,
|
|
1281
|
-
animation: `bar-shift-${i} 1.4s ease-in-out infinite`,
|
|
1282
|
-
}}
|
|
1283
|
-
/>
|
|
1284
|
-
))}
|
|
1285
|
-
</div>
|
|
1286
|
-
);
|
|
1287
|
-
}
|