sanity-plugin-seo-copilot 0.2.15 → 0.2.16

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.
Files changed (41) hide show
  1. package/README.md +63 -50
  2. package/dist/index.js +841 -782
  3. package/dist/index.mjs +763 -704
  4. package/package.json +62 -64
  5. package/dist/index.js.map +0 -1
  6. package/dist/index.mjs.map +0 -1
  7. package/sanity.json +0 -3
  8. package/src/components/ChatPanel.tsx +0 -311
  9. package/src/components/ConfigContext.tsx +0 -22
  10. package/src/components/FeedbackButton.tsx +0 -218
  11. package/src/components/KeywordBadge.tsx +0 -50
  12. package/src/components/KeywordPanel.tsx +0 -1234
  13. package/src/components/OnboardingPopup.tsx +0 -108
  14. package/src/components/PlacementIndicators.tsx +0 -80
  15. package/src/components/ReportProblemButton.tsx +0 -212
  16. package/src/components/SEOCopilotPanel.tsx +0 -1287
  17. package/src/components/ScoreDonut.tsx +0 -158
  18. package/src/components/SeedKeywordInput.tsx +0 -128
  19. package/src/components/ShimmerLoader.tsx +0 -123
  20. package/src/components/TabBar.tsx +0 -373
  21. package/src/components/styles.ts +0 -158
  22. package/src/components/tabs/AEOTab.tsx +0 -585
  23. package/src/components/tabs/LinkingTab.tsx +0 -446
  24. package/src/components/tabs/MetaTab.tsx +0 -431
  25. package/src/components/tabs/SummaryTab.tsx +0 -405
  26. package/src/components/tabs/TechnicalTab.tsx +0 -933
  27. package/src/hooks/useDocumentContent.ts +0 -48
  28. package/src/hooks/useKeywordAnalysis.ts +0 -292
  29. package/src/hooks/useSEOChat.ts +0 -254
  30. package/src/index.ts +0 -18
  31. package/src/inspector.ts +0 -58
  32. package/src/lib/api.ts +0 -262
  33. package/src/lib/apiKey.ts +0 -30
  34. package/src/lib/documentExtract.ts +0 -422
  35. package/src/lib/geoAnalysis.ts +0 -122
  36. package/src/lib/persistence.ts +0 -69
  37. package/src/lib/scoring.ts +0 -197
  38. package/src/lib/summary.ts +0 -645
  39. package/src/lib/types.ts +0 -212
  40. package/src/lib/utils.ts +0 -35
  41. package/v2-incompatible.js +0 -10
@@ -1,108 +0,0 @@
1
- import { MJH_BLUE } from "./styles";
2
-
3
- // Small (i) button that lives in the panel header next to the pop-out control. The
4
- // first-run popup collapses into this; clicking it re-opens the popup.
5
- export function OnboardingInfoButton({ onClick }: { onClick: () => void }) {
6
- return (
7
- <button
8
- onClick={(e) => { e.stopPropagation(); onClick(); }}
9
- onMouseDown={(e) => e.stopPropagation()}
10
- style={{
11
- background: "rgba(0,93,172,0.08)",
12
- border: "none",
13
- borderRadius: "50%",
14
- width: 20,
15
- height: 20,
16
- cursor: "pointer",
17
- padding: 0,
18
- display: "flex",
19
- alignItems: "center",
20
- justifyContent: "center",
21
- color: MJH_BLUE,
22
- flexShrink: 0,
23
- }}
24
- title="How SEO Copilot works"
25
- aria-label="How SEO Copilot works"
26
- >
27
- <svg width="13" height="13" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
28
- <path fillRule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z" clipRule="evenodd" />
29
- </svg>
30
- </button>
31
- );
32
- }
33
-
34
- // First-run onboarding popup. Amorphous MJH-blue glass. Clicking anywhere on the
35
- // dimmed backdrop, the X, or "Got it" dismisses it (fades out to the info icon).
36
- export function OnboardingCard({ onDismiss, closing }: { onDismiss: () => void; closing: boolean }) {
37
- return (
38
- <>
39
- {/* Click-anywhere backdrop - very light so it doesn't feel like a hard modal. */}
40
- <div
41
- onClick={onDismiss}
42
- style={{
43
- position: "absolute",
44
- inset: 0,
45
- zIndex: 60,
46
- background: "transparent",
47
- cursor: "pointer",
48
- }}
49
- />
50
- <div
51
- onClick={(e) => e.stopPropagation()}
52
- style={{
53
- position: "absolute",
54
- top: 50,
55
- right: 10,
56
- left: 10,
57
- maxWidth: 320,
58
- marginLeft: "auto",
59
- zIndex: 61,
60
- borderRadius: 18,
61
- padding: "14px 16px 16px",
62
- // Amorphous blue glass
63
- background: "linear-gradient(155deg, rgba(0,93,172,0.16), rgba(0,93,172,0.08))",
64
- backdropFilter: "blur(20px) saturate(170%)",
65
- WebkitBackdropFilter: "blur(20px) saturate(170%)",
66
- boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.55), inset 1.5px 2px 1px -1px rgba(255,255,255,0.9), 0 10px 30px rgba(0,93,172,0.22), 0 2px 8px rgba(0,0,0,0.12)",
67
- animation: `${closing ? "onboard-out" : "onboard-in"} ${closing ? 200 : 240}ms ease-out forwards`,
68
- }}
69
- >
70
- <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 8, marginBottom: 6 }}>
71
- <span style={{ fontSize: 13, fontWeight: 800, color: "#00468a", letterSpacing: "-0.01em" }}>
72
- Welcome to SEO Copilot
73
- </span>
74
- <button
75
- onClick={onDismiss}
76
- style={{ background: "none", border: "none", cursor: "pointer", padding: 2, display: "flex", color: "#00468a", opacity: 1 }}
77
- title="Dismiss"
78
- aria-label="Dismiss"
79
- >
80
- <svg width="14" height="14" viewBox="0 0 20 20" fill="currentColor">
81
- <path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z" />
82
- </svg>
83
- </button>
84
- </div>
85
- <div style={{ fontSize: 11.5, color: "#13335a", lineHeight: 1.6 }}>
86
- Start on the <strong>Keywords</strong> tab. Choose one <strong>Primary</strong> keyword (required) and, optionally, one <strong>Secondary</strong> keyword. Copilot then optimizes its recommendations toward both.
87
- </div>
88
- <button
89
- onClick={onDismiss}
90
- style={{
91
- marginTop: 12,
92
- width: "100%",
93
- padding: "7px 12px",
94
- fontSize: 11.5,
95
- fontWeight: 700,
96
- color: "#ffffff",
97
- background: MJH_BLUE,
98
- border: "none",
99
- borderRadius: 8,
100
- cursor: "pointer",
101
- }}
102
- >
103
- Got it
104
- </button>
105
- </div>
106
- </>
107
- );
108
- }
@@ -1,80 +0,0 @@
1
- import { useState } from "react";
2
- import type { KeywordPlacement } from "../lib/types";
3
-
4
- interface PlacementIndicatorsProps {
5
- placement?: KeywordPlacement;
6
- }
7
-
8
- const indicators = [
9
- { key: "inBody" as const, letter: "B", tooltip: "Keyword in body" },
10
- { key: "inTitle" as const, letter: "T", tooltip: "Keyword in title" },
11
- { key: "inMetaDescription" as const, letter: "D", tooltip: "Keyword in meta description" },
12
- { key: "inImages" as const, letter: "I", tooltip: "Keyword in image names" },
13
- { key: "inUrl" as const, letter: "U", tooltip: "Keyword in URL" },
14
- ];
15
-
16
- function IndicatorDot({ letter, active, tooltip }: { letter: string; active: boolean; tooltip: string }) {
17
- const [hovered, setHovered] = useState(false);
18
-
19
- return (
20
- <span
21
- onMouseEnter={() => setHovered(true)}
22
- onMouseLeave={() => setHovered(false)}
23
- style={{
24
- position: "relative",
25
- display: "inline-flex",
26
- alignItems: "center",
27
- justifyContent: "center",
28
- width: 16,
29
- height: 16,
30
- borderRadius: "50%",
31
- fontSize: 8,
32
- fontWeight: 700,
33
- lineHeight: 1,
34
- cursor: "default",
35
- flexShrink: 0,
36
- // Inactive = a solid WHITE disc (was a near-invisible faint-grey ring on
37
- // transparent) so each indicator reads clearly on the warm panel; a light
38
- // edge + soft lift keep it defined even on a white card. Active = green.
39
- background: active ? "#16a34a" : "#ffffff",
40
- color: active ? "#ffffff" : "#94a3b8",
41
- border: active ? "none" : "1.5px solid #cbd5e1",
42
- boxShadow: active ? "none" : "0 1px 2px rgba(0,0,0,0.07)",
43
- transition: "all 150ms",
44
- }}
45
- >
46
- {letter}
47
- {hovered && (
48
- <span style={{
49
- position: "absolute",
50
- bottom: "100%",
51
- left: "50%",
52
- transform: "translateX(-50%)",
53
- marginBottom: 4,
54
- padding: "2px 6px",
55
- borderRadius: 4,
56
- background: "#1f2937",
57
- color: "#ffffff",
58
- fontSize: 10,
59
- whiteSpace: "nowrap",
60
- pointerEvents: "none",
61
- zIndex: 10,
62
- }}>
63
- {tooltip}
64
- </span>
65
- )}
66
- </span>
67
- );
68
- }
69
-
70
- export function PlacementIndicators({ placement }: PlacementIndicatorsProps) {
71
- if (!placement) return null;
72
-
73
- return (
74
- <div style={{ display: "flex", alignItems: "center", gap: 2 }}>
75
- {indicators.map(({ key, letter, tooltip }) => (
76
- <IndicatorDot key={key} letter={letter} active={placement[key]} tooltip={tooltip} />
77
- ))}
78
- </div>
79
- );
80
- }
@@ -1,212 +0,0 @@
1
- import { useState, useRef, useEffect } from "react";
2
- import { useCurrentUser } from "sanity";
3
- import { useConfig } from "./ConfigContext";
4
- import { submitFeedback } from "../lib/api";
5
- import { MJH_BLUE } from "./styles";
6
-
7
- interface ReportProblemButtonProps {
8
- activeTab?: string;
9
- publication?: string;
10
- documentId?: string;
11
- documentType?: string;
12
- primaryKeyword?: string;
13
- }
14
-
15
- // Header "Report a problem" affordance. Opens a small message box AND captures
16
- // structured context (which surface + tab was open, the doc + publication + keyword,
17
- // the URL, the user agent) so we can debug widespread-adoption issues - not just read
18
- // the written note. Posts to the shared /feedback endpoint as suggestion_type
19
- // "bug_report". Never throws into the UI; failures are swallowed.
20
- export function ReportProblemButton({ activeTab, publication, documentId, documentType, primaryKeyword }: ReportProblemButtonProps) {
21
- const { apiUrl } = useConfig();
22
- const sanityUser = useCurrentUser();
23
- const [open, setOpen] = useState(false);
24
- const [text, setText] = useState("");
25
- const [submitting, setSubmitting] = useState(false);
26
- const [submitted, setSubmitted] = useState(false);
27
- const [failed, setFailed] = useState(false);
28
- const popRef = useRef<HTMLDivElement>(null);
29
- const textareaRef = useRef<HTMLTextAreaElement>(null);
30
- const closeTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
31
- const mounted = useRef(true);
32
-
33
- useEffect(() => () => { mounted.current = false; if (closeTimer.current) clearTimeout(closeTimer.current); }, []);
34
-
35
- // Close on outside click.
36
- useEffect(() => {
37
- if (!open) return;
38
- const handler = (e: MouseEvent) => {
39
- if (popRef.current && !popRef.current.contains(e.target as Node)) setOpen(false);
40
- };
41
- document.addEventListener("mousedown", handler);
42
- return () => document.removeEventListener("mousedown", handler);
43
- }, [open]);
44
-
45
- // Focus the textarea when the dialog opens.
46
- useEffect(() => {
47
- if (open) setTimeout(() => textareaRef.current?.focus(), 50);
48
- }, [open]);
49
-
50
- const handleSubmit = async () => {
51
- const trimmed = text.trim();
52
- if (!trimmed || submitting) return;
53
- setFailed(false);
54
- setSubmitting(true);
55
- try {
56
- await submitFeedback(apiUrl, {
57
- suggestion_type: "bug_report",
58
- suggestion_text: trimmed.slice(0, 10000),
59
- vote: "down",
60
- document_id: documentId,
61
- publication,
62
- user_id: sanityUser?.id,
63
- context: {
64
- surface: "sanity-plugin",
65
- activeTab,
66
- primaryKeyword: primaryKeyword || undefined,
67
- documentType,
68
- url: typeof window !== "undefined" && /^https?:\/\//i.test(window.location.href) ? window.location.href.slice(0, 500) : undefined,
69
- userAgent: typeof navigator !== "undefined" ? navigator.userAgent.slice(0, 500) : undefined,
70
- timestamp: new Date().toISOString(),
71
- },
72
- });
73
- } catch (e) {
74
- // Show a real error + keep the box open so the report isn't silently lost. Log it too.
75
- console.error("[SEO Copilot] failed to send problem report:", e);
76
- if (mounted.current) { setSubmitting(false); setFailed(true); }
77
- return;
78
- }
79
- if (!mounted.current) return;
80
- setSubmitting(false);
81
- setSubmitted(true);
82
- closeTimer.current = setTimeout(() => {
83
- if (!mounted.current) return;
84
- setOpen(false);
85
- setSubmitted(false);
86
- setText("");
87
- }, 1500);
88
- };
89
-
90
- return (
91
- <div style={{ position: "relative", display: "flex" }}>
92
- <button
93
- type="button"
94
- onClick={(e) => { e.stopPropagation(); if (closeTimer.current) { clearTimeout(closeTimer.current); closeTimer.current = null; } setOpen((o) => !o); }}
95
- onMouseDown={(e) => e.stopPropagation()}
96
- aria-label="Report a problem"
97
- title="Report a problem"
98
- style={{
99
- display: "inline-flex",
100
- alignItems: "center",
101
- gap: 4,
102
- padding: "3px 8px",
103
- borderRadius: 99,
104
- border: `1px solid ${open ? MJH_BLUE : "#d1d5db"}`,
105
- background: open ? "rgba(0,93,172,0.08)" : "rgba(255,255,255,0.6)",
106
- cursor: "pointer",
107
- fontSize: 10,
108
- fontWeight: 600,
109
- color: open ? MJH_BLUE : "#6b7280",
110
- whiteSpace: "nowrap",
111
- transition: "all 150ms",
112
- }}
113
- >
114
- <svg width="11" height="11" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
115
- <path d="M3 2.75a.75.75 0 00-1.5 0v14.5a.75.75 0 001.5 0v-4.392l1.657-.348a6.449 6.449 0 014.271.572 7.948 7.948 0 005.965.524l2.078-.64A.75.75 0 0017.5 12.25v-8.5a.75.75 0 00-.904-.734l-1.74.348a7.948 7.948 0 01-5.965-.524 6.449 6.449 0 00-4.271-.572L3 2.842V2.75z" />
116
- </svg>
117
- Report a problem
118
- </button>
119
-
120
- {open && (
121
- <div
122
- ref={popRef}
123
- onMouseDown={(e) => e.stopPropagation()}
124
- style={{
125
- position: "absolute",
126
- top: "100%",
127
- right: 0,
128
- marginTop: 6,
129
- width: 260,
130
- padding: 12,
131
- borderRadius: 10,
132
- background: "#ffffff",
133
- boxShadow: "0 6px 22px rgba(0,0,0,0.16), 0 1px 4px rgba(0,0,0,0.1)",
134
- border: "1px solid #e5e7eb",
135
- zIndex: 100,
136
- }}
137
- >
138
- {submitted ? (
139
- <div style={{ fontSize: 12, color: "#16a34a", textAlign: "center", padding: "6px 0", fontWeight: 600 }}>
140
- Thanks - we got it.
141
- </div>
142
- ) : (
143
- <>
144
- <div style={{ fontSize: 12, fontWeight: 700, color: "#1f2937", marginBottom: 3 }}>
145
- Report a problem
146
- </div>
147
- <div style={{ fontSize: 10.5, color: "#6b7280", marginBottom: 8, lineHeight: 1.45 }}>
148
- Beta - tell us what went wrong. We also note which tab you&apos;re on to help us track it down.
149
- </div>
150
- {failed && (
151
- <div style={{ fontSize: 10.5, color: "#dc2626", marginBottom: 8, lineHeight: 1.45, fontWeight: 600 }}>
152
- Couldn&apos;t send - please try again.
153
- </div>
154
- )}
155
- <textarea
156
- ref={textareaRef}
157
- value={text}
158
- onChange={(e) => setText(e.target.value)}
159
- onKeyDown={(e) => {
160
- if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) { e.preventDefault(); handleSubmit(); }
161
- }}
162
- placeholder="What happened? The more detail, the better."
163
- rows={4}
164
- maxLength={4000}
165
- style={{
166
- width: "100%",
167
- padding: "6px 8px",
168
- fontSize: 11,
169
- borderRadius: 6,
170
- border: "1px solid #e5e7eb",
171
- outline: "none",
172
- fontFamily: "inherit",
173
- resize: "vertical",
174
- boxSizing: "border-box",
175
- lineHeight: 1.5,
176
- }}
177
- />
178
- <div style={{ display: "flex", justifyContent: "flex-end", marginTop: 8, gap: 6 }}>
179
- <button
180
- type="button"
181
- onClick={() => { setOpen(false); setText(""); }}
182
- style={{
183
- padding: "4px 10px", fontSize: 10.5, borderRadius: 5,
184
- border: "1px solid #e5e7eb", background: "#ffffff", color: "#4b5563",
185
- cursor: "pointer",
186
- }}
187
- >
188
- Cancel
189
- </button>
190
- <button
191
- type="button"
192
- onClick={handleSubmit}
193
- disabled={!text.trim() || submitting}
194
- style={{
195
- padding: "4px 12px", fontSize: 10.5, borderRadius: 5,
196
- border: "none",
197
- background: !text.trim() || submitting ? "#cbd5e1" : MJH_BLUE,
198
- color: "#ffffff",
199
- cursor: !text.trim() || submitting ? "default" : "pointer",
200
- fontWeight: 700,
201
- }}
202
- >
203
- {submitting ? "Sending..." : "Send"}
204
- </button>
205
- </div>
206
- </>
207
- )}
208
- </div>
209
- )}
210
- </div>
211
- );
212
- }