@redocly/theme 0.69.0-next.1 → 0.69.0-next.3

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 (52) hide show
  1. package/lib/components/Badge/Badge.d.ts +3 -1
  2. package/lib/components/Badge/Badge.js +7 -2
  3. package/lib/components/Buttons/ConnectMCPButton.js +43 -14
  4. package/lib/components/MCP/McpConnectionTabs.d.ts +7 -0
  5. package/lib/components/MCP/McpConnectionTabs.js +151 -0
  6. package/lib/core/constants/mcp.d.ts +2 -0
  7. package/lib/core/constants/mcp.js +8 -1
  8. package/lib/core/hooks/use-active-heading.js +59 -15
  9. package/lib/core/hooks/use-active-section-id.js +3 -1
  10. package/lib/core/hooks/use-connect-mcp-button.d.ts +1 -1
  11. package/lib/core/hooks/use-connect-mcp-button.js +16 -13
  12. package/lib/core/styles/global.js +6 -1
  13. package/lib/core/types/catalog.d.ts +2 -0
  14. package/lib/core/types/l10n.d.ts +1 -1
  15. package/lib/core/types/mcp.d.ts +1 -1
  16. package/lib/core/utils/mcp.d.ts +5 -0
  17. package/lib/core/utils/mcp.js +35 -0
  18. package/lib/icons/CodexIcon/CodexIcon.d.ts +25 -0
  19. package/lib/icons/CodexIcon/CodexIcon.js +22 -0
  20. package/lib/layouts/McpNotAllowed.js +5 -3
  21. package/lib/markdoc/components/Cards/Card.d.ts +8 -1
  22. package/lib/markdoc/components/Cards/Card.js +55 -16
  23. package/lib/markdoc/components/Cards/CardBadge.d.ts +9 -0
  24. package/lib/markdoc/components/Cards/CardBadge.js +30 -0
  25. package/lib/markdoc/components/Cards/CardIcon.d.ts +5 -4
  26. package/lib/markdoc/components/Cards/CardIcon.js +6 -3
  27. package/lib/markdoc/components/Cards/variables.dark.js +32 -0
  28. package/lib/markdoc/components/Cards/variables.js +76 -4
  29. package/lib/markdoc/tags/card.js +14 -0
  30. package/lib/markdoc/tags/connect-mcp.js +2 -1
  31. package/package.json +2 -2
  32. package/src/components/Badge/Badge.tsx +16 -2
  33. package/src/components/Buttons/ConnectMCPButton.tsx +44 -14
  34. package/src/components/MCP/McpConnectionTabs.tsx +263 -0
  35. package/src/core/constants/mcp.ts +10 -0
  36. package/src/core/hooks/use-active-heading.ts +79 -15
  37. package/src/core/hooks/use-active-section-id.ts +3 -1
  38. package/src/core/hooks/use-connect-mcp-button.ts +23 -15
  39. package/src/core/styles/global.ts +6 -1
  40. package/src/core/types/catalog.ts +3 -0
  41. package/src/core/types/l10n.ts +17 -0
  42. package/src/core/types/mcp.ts +1 -1
  43. package/src/core/utils/mcp.ts +39 -0
  44. package/src/icons/CodexIcon/CodexIcon.tsx +23 -0
  45. package/src/layouts/McpNotAllowed.tsx +4 -2
  46. package/src/markdoc/components/Cards/Card.tsx +79 -14
  47. package/src/markdoc/components/Cards/CardBadge.tsx +39 -0
  48. package/src/markdoc/components/Cards/CardIcon.tsx +16 -5
  49. package/src/markdoc/components/Cards/variables.dark.ts +32 -0
  50. package/src/markdoc/components/Cards/variables.ts +76 -4
  51. package/src/markdoc/tags/card.ts +14 -0
  52. package/src/markdoc/tags/connect-mcp.ts +3 -1
@@ -5,5 +5,7 @@ export type BadgeProps = PropsWithChildren<{
5
5
  key?: string;
6
6
  className?: string;
7
7
  icon?: string;
8
+ /** Inline SVG content for the icon */
9
+ iconRawContent?: string;
8
10
  }>;
9
- export declare function Badge({ icon, children, deprecated, color, ...props }: BadgeProps): JSX.Element;
11
+ export declare function Badge({ icon, iconRawContent, children, deprecated, color, ...props }: BadgeProps): JSX.Element;
@@ -52,9 +52,9 @@ const react_1 = __importDefault(require("react"));
52
52
  const styled_components_1 = __importStar(require("styled-components"));
53
53
  const GenericIcon_1 = require("../../icons/GenericIcon/GenericIcon");
54
54
  function Badge(_a) {
55
- var { icon, children, deprecated, color } = _a, props = __rest(_a, ["icon", "children", "deprecated", "color"]);
55
+ var { icon, iconRawContent, children, deprecated, color } = _a, props = __rest(_a, ["icon", "iconRawContent", "children", "deprecated", "color"]);
56
56
  return (react_1.default.createElement(BadgeComponent, Object.assign({}, props, { $color: color, $deprecated: deprecated, "data-component-name": "Badge/Badge" }),
57
- icon ? react_1.default.createElement(BadgeIcon, { icon: icon }) : null,
57
+ icon || iconRawContent ? react_1.default.createElement(BadgeIcon, { icon: icon, rawContent: iconRawContent }) : null,
58
58
  children));
59
59
  }
60
60
  const BadgeComponent = styled_components_1.default.span `
@@ -82,5 +82,10 @@ const BadgeIcon = (0, styled_components_1.default)(GenericIcon_1.GenericIcon) `
82
82
  margin-right: var(--spacing-xxs);
83
83
  flex-shrink: 0;
84
84
  vertical-align: middle;
85
+
86
+ /* For inline SVG to align properly */
87
+ svg {
88
+ display: block;
89
+ }
85
90
  `;
86
91
  //# sourceMappingURL=Badge.js.map
@@ -44,11 +44,14 @@ const DropdownMenuItem_1 = require("../../components/Dropdown/DropdownMenuItem")
44
44
  const Button_1 = require("../../components/Button/Button");
45
45
  const CursorIcon_1 = require("../../icons/CursorIcon/CursorIcon");
46
46
  const VSCodeIcon_1 = require("../../icons/VSCodeIcon/VSCodeIcon");
47
+ const ClaudeIcon_1 = require("../../icons/ClaudeIcon/ClaudeIcon");
48
+ const CodexIcon_1 = require("../../icons/CodexIcon/CodexIcon");
47
49
  const CopyIcon_1 = require("../../icons/CopyIcon/CopyIcon");
48
50
  const CheckmarkFilledIcon_1 = require("../../icons/CheckmarkFilledIcon/CheckmarkFilledIcon");
49
51
  const ChevronDownIcon_1 = require("../../icons/ChevronDownIcon/ChevronDownIcon");
50
52
  const ChevronUpIcon_1 = require("../../icons/ChevronUpIcon/ChevronUpIcon");
51
53
  const hooks_1 = require("../../core/hooks");
54
+ const constants_1 = require("../../core/constants");
52
55
  const MENU_OPTIONS = [
53
56
  {
54
57
  key: 'cursor',
@@ -66,6 +69,22 @@ const MENU_OPTIONS = [
66
69
  descriptionTranslationKey: 'page.actions.connectMcp.vscodeDescription',
67
70
  descriptionDefault: 'Install MCP server on VS Code',
68
71
  },
72
+ {
73
+ key: 'claude-code',
74
+ icon: ClaudeIcon_1.ClaudeIcon,
75
+ titleTranslationKey: 'page.actions.connectMcp.claudeCode',
76
+ titleDefault: 'Connect to Claude Code',
77
+ descriptionTranslationKey: 'page.actions.connectMcp.claudeCodeDescription',
78
+ descriptionDefault: 'Copy the Claude Code CLI command',
79
+ },
80
+ {
81
+ key: 'codex',
82
+ icon: CodexIcon_1.CodexIcon,
83
+ titleTranslationKey: 'page.actions.connectMcp.codex',
84
+ titleDefault: 'Connect to Codex CLI',
85
+ descriptionTranslationKey: 'page.actions.connectMcp.codexDescription',
86
+ descriptionDefault: 'Copy the Codex CLI command',
87
+ },
69
88
  {
70
89
  key: 'copy',
71
90
  icon: CopyIcon_1.CopyIcon,
@@ -75,12 +94,14 @@ const MENU_OPTIONS = [
75
94
  descriptionDefault: 'Copy MCP JSON Configuration',
76
95
  },
77
96
  ];
78
- function ConnectMCPButton({ placement = 'bottom', alignment = 'end', options = ['cursor', 'vscode', 'copy'], }) {
97
+ // Copy actions keep the dropdown open so the copied checkmark is visible.
98
+ const COPY_OPTIONS = ['claude-code', 'codex', 'copy'];
99
+ function ConnectMCPButton({ placement = 'bottom', alignment = 'end', options = constants_1.DEFAULT_MCP_OPTIONS, }) {
79
100
  const { useTranslate } = (0, hooks_1.useThemeHooks)();
80
101
  const { translate } = useTranslate();
81
102
  const [isOpen, setIsOpen] = (0, react_1.useState)(false);
82
103
  const wrapperRef = (0, react_1.useRef)(null);
83
- const { isCopied, visibleOptions, handleAction } = (0, hooks_1.useConnectMCPButton)({ options });
104
+ const { copiedOption, visibleOptions, handleAction } = (0, hooks_1.useConnectMCPButton)({ options });
84
105
  (0, hooks_1.useOutsideClick)(wrapperRef, () => setIsOpen(false));
85
106
  const menuOptions = MENU_OPTIONS.filter((option) => visibleOptions.includes(option.key));
86
107
  const primaryOption = menuOptions[0];
@@ -88,12 +109,12 @@ function ConnectMCPButton({ placement = 'bottom', alignment = 'end', options = [
88
109
  if (!primaryOption)
89
110
  return null;
90
111
  const PrimaryIcon = primaryOption.icon;
91
- // When copy is the primary action there is no dropdown item to show the copied state, so the
92
- // primary button itself must reflect it.
93
- const showPrimaryCopied = primaryOption.key === 'copy' && isCopied;
112
+ const showPrimaryCopied = copiedOption === primaryOption.key;
94
113
  const handleMenuAction = (key) => {
95
114
  handleAction(key);
96
- setIsOpen(false);
115
+ if (!COPY_OPTIONS.includes(key)) {
116
+ setIsOpen(false);
117
+ }
97
118
  };
98
119
  return (react_1.default.createElement(ConnectMCPButtonWrapper, { ref: wrapperRef, "data-component-name": "Buttons/ConnectMCPButton" },
99
120
  react_1.default.createElement(SplitButtonGroup, null,
@@ -102,7 +123,7 @@ function ConnectMCPButton({ placement = 'bottom', alignment = 'end', options = [
102
123
  isOpen && dropdownOptions.length > 0 && (react_1.default.createElement(DropdownWrapper, { $placement: placement, $alignment: alignment },
103
124
  react_1.default.createElement(DropdownMenu_1.DropdownMenu, null, dropdownOptions.map((option) => {
104
125
  const Icon = option.icon;
105
- const showCheckmark = option.key === 'copy' && isCopied;
126
+ const showCheckmark = copiedOption === option.key;
106
127
  return (react_1.default.createElement(DropdownMenuItem_1.DropdownMenuItem, { key: option.key, onAction: () => handleMenuAction(option.key) },
107
128
  react_1.default.createElement(MenuItemContent, null,
108
129
  react_1.default.createElement(MenuItemIcon, null, showCheckmark ? (react_1.default.createElement(CheckmarkFilledIcon_1.CheckmarkFilledIcon, { color: "var(--color-success-base)" })) : (react_1.default.createElement(Icon, null))),
@@ -119,16 +140,24 @@ const SplitButtonGroup = styled_components_1.default.div `
119
140
  display: inline-flex;
120
141
  align-items: stretch;
121
142
  `;
143
+ /* Doubled selectors outrank the base button class in any style injection order,
144
+ and margin: 0 keeps themed button margins from splitting the group apart. */
122
145
  const PrimaryButton = (0, styled_components_1.default)(Button_1.Button) `
123
- --button-gap: var(--connect-mcp-button-gap);
124
- border-top-right-radius: 0;
125
- border-bottom-right-radius: 0;
146
+ && {
147
+ --button-gap: var(--connect-mcp-button-gap);
148
+ margin: 0;
149
+ border-top-right-radius: 0;
150
+ border-bottom-right-radius: 0;
151
+ }
126
152
  `;
127
153
  const ChevronButton = (0, styled_components_1.default)(Button_1.Button) `
128
- border-top-left-radius: 0;
129
- border-bottom-left-radius: 0;
130
- border-left: none;
131
- padding-inline: var(--connect-mcp-button-chevron-padding-inline);
154
+ && {
155
+ margin: 0;
156
+ border-top-left-radius: 0;
157
+ border-bottom-left-radius: 0;
158
+ border-left: none;
159
+ padding-inline: var(--connect-mcp-button-chevron-padding-inline);
160
+ }
132
161
  `;
133
162
  const DropdownWrapper = styled_components_1.default.div `
134
163
  position: absolute;
@@ -0,0 +1,7 @@
1
+ import type { JSX } from 'react';
2
+ export type McpConnectionTab = 'claude' | 'chatgpt' | 'json';
3
+ export type McpConnectionTabsProps = {
4
+ options?: McpConnectionTab[];
5
+ className?: string;
6
+ };
7
+ export declare function McpConnectionTabs({ options, className, }: McpConnectionTabsProps): JSX.Element | null;
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.McpConnectionTabs = McpConnectionTabs;
40
+ const react_1 = __importStar(require("react"));
41
+ const styled_components_1 = __importDefault(require("styled-components"));
42
+ const hooks_1 = require("../../core/hooks");
43
+ const utils_1 = require("../../core/utils");
44
+ const CodeBlock_1 = require("../../components/CodeBlock/CodeBlock");
45
+ const ClaudeIcon_1 = require("../../icons/ClaudeIcon/ClaudeIcon");
46
+ const ChatGptIcon_1 = require("../../icons/ChatGptIcon/ChatGptIcon");
47
+ const Tabs_1 = require("../../markdoc/components/Tabs/Tabs");
48
+ const TabItemFragment_1 = require("../../markdoc/components/Tabs/TabItemFragment");
49
+ const NumberedList_1 = require("../../markdoc/components/NumberedList/NumberedList");
50
+ const NumberedItem_1 = require("../../markdoc/components/NumberedList/NumberedItem");
51
+ const DEFAULT_TAB_OPTIONS = ['claude', 'chatgpt', 'json'];
52
+ const TAB_LABELS = {
53
+ claude: {
54
+ translationKey: 'page.mcpNotAllowed.tabs.claude',
55
+ defaultLabel: 'Claude',
56
+ icon: ClaudeIcon_1.ClaudeIcon,
57
+ },
58
+ chatgpt: {
59
+ translationKey: 'page.mcpNotAllowed.tabs.chatgpt',
60
+ defaultLabel: 'ChatGPT',
61
+ icon: ChatGptIcon_1.ChatGptIcon,
62
+ },
63
+ json: { translationKey: 'page.mcpNotAllowed.tabs.json', defaultLabel: 'JSON' },
64
+ };
65
+ // The report control is docs feedback, not useful on the connection page.
66
+ const CODE_BLOCK_HEADER = { controls: { copy: {}, report: { hidden: true } } };
67
+ function McpConnectionTabs({ options = DEFAULT_TAB_OPTIONS, className, }) {
68
+ const { useTranslate } = (0, hooks_1.useThemeHooks)();
69
+ const { translate } = useTranslate();
70
+ const { serverName, serverUrl, isMcpDisabled } = (0, hooks_1.useMCPConfig)();
71
+ // The SSR markup of error pages is cached with the build-time origin, so the
72
+ // tabs remount after hydration to pick up the real browser origin.
73
+ const [hydrated, setHydrated] = (0, react_1.useState)(false);
74
+ (0, react_1.useEffect)(() => setHydrated(true), []);
75
+ if (isMcpDisabled) {
76
+ return null;
77
+ }
78
+ const connection = { serverName, url: serverUrl };
79
+ return (react_1.default.createElement(McpConnectionTabsWrapper, { key: hydrated ? 'client' : 'ssr', "data-component-name": "MCP/McpConnectionTabs", "data-testid": "mcp-connection-tabs", className: className },
80
+ react_1.default.createElement(Tabs_1.Tabs, { size: Tabs_1.TabsSize.SMALL }, options.map((option) => {
81
+ const { translationKey, defaultLabel, icon: TabIcon } = TAB_LABELS[option];
82
+ return (react_1.default.createElement(TabItemFragment_1.TabItemFragment, { key: option, label: translate(translationKey, defaultLabel), icon: TabIcon ? react_1.default.createElement(TabIcon, null) : undefined }, renderTabContent(option, connection, translate)));
83
+ }))));
84
+ }
85
+ function renderTabContent(option, connection, translate) {
86
+ const terminalHint = (react_1.default.createElement(TabHint, null, translate('page.mcpNotAllowed.snippets.terminal.hint', 'Run this command in your terminal:')));
87
+ const urlBlock = react_1.default.createElement(CodeBlock_1.CodeBlock, { lang: "text", source: connection.url, header: CODE_BLOCK_HEADER });
88
+ const assistantPromptClient = {
89
+ headline: translate('page.mcpNotAllowed.snippets.prompt.headline', 'Prompt'),
90
+ content: (react_1.default.createElement(react_1.default.Fragment, null,
91
+ react_1.default.createElement(TabHint, null, translate('page.mcpNotAllowed.snippets.prompt.hint', 'Or paste this prompt into the chat to have it add the server for you:')),
92
+ react_1.default.createElement(CodeBlock_1.CodeBlock, { lang: "text", source: (0, utils_1.generateMcpInstallPrompt)(connection), header: CODE_BLOCK_HEADER, wrapContents: true }))),
93
+ };
94
+ switch (option) {
95
+ case 'claude':
96
+ return renderClientList([
97
+ {
98
+ headline: translate('page.mcpNotAllowed.snippets.claudeCode.headline', 'Claude Code'),
99
+ content: (react_1.default.createElement(react_1.default.Fragment, null,
100
+ terminalHint,
101
+ react_1.default.createElement(CodeBlock_1.CodeBlock, { lang: "shell", source: (0, utils_1.generateClaudeCodeCommand)(connection), header: CODE_BLOCK_HEADER, wrapContents: true }))),
102
+ },
103
+ {
104
+ headline: translate('page.mcpNotAllowed.snippets.claudeDesktop.headline', 'Claude Desktop'),
105
+ content: (react_1.default.createElement(react_1.default.Fragment, null,
106
+ react_1.default.createElement(TabHint, null, translate('page.mcpNotAllowed.snippets.claudeDesktop.instruction', 'In Claude Desktop, open Settings → Developer → Edit Config, add this to the configuration file, and restart Claude Desktop:')),
107
+ react_1.default.createElement(CodeBlock_1.CodeBlock, { lang: "json", source: (0, utils_1.generateClaudeDesktopConfig)(connection), header: CODE_BLOCK_HEADER }))),
108
+ },
109
+ ]);
110
+ case 'chatgpt':
111
+ return renderClientList([
112
+ {
113
+ headline: translate('page.mcpNotAllowed.snippets.codexCli.headline', 'Codex CLI'),
114
+ content: (react_1.default.createElement(react_1.default.Fragment, null,
115
+ terminalHint,
116
+ react_1.default.createElement(CodeBlock_1.CodeBlock, { lang: "shell", source: (0, utils_1.generateCodexCommand)(connection), header: CODE_BLOCK_HEADER, wrapContents: true }))),
117
+ },
118
+ {
119
+ headline: translate('page.mcpNotAllowed.snippets.chatgptApp.headline', 'ChatGPT desktop app'),
120
+ content: (react_1.default.createElement(react_1.default.Fragment, null,
121
+ react_1.default.createElement(TabHint, null, translate('page.mcpNotAllowed.snippets.chatgptApp.instruction', 'In the ChatGPT desktop app, go to Settings → Plugins → MCPs and add a server with the "Streamable HTTP" type and this URL (restart the app afterwards):')),
122
+ urlBlock)),
123
+ },
124
+ assistantPromptClient,
125
+ ]);
126
+ case 'json':
127
+ return (react_1.default.createElement(react_1.default.Fragment, null,
128
+ react_1.default.createElement(TabHint, null, translate('page.mcpNotAllowed.snippets.json.hint', 'Add this server entry to your MCP client configuration file:')),
129
+ react_1.default.createElement(CodeBlock_1.CodeBlock, { lang: "json", source: JSON.stringify({ [connection.serverName]: { url: connection.url, description: 'MCP Server' } }, null, 2), header: CODE_BLOCK_HEADER })));
130
+ }
131
+ }
132
+ function renderClientList(clients) {
133
+ return (react_1.default.createElement(NumberedList_1.NumberedList, null, clients.map((client, index) => (react_1.default.createElement(NumberedItem_1.NumberedItem, { key: index, type: "dot", size: "small", headline: client.headline, index: index + 1, isLast: index === clients.length - 1 }, client.content)))));
134
+ }
135
+ const McpConnectionTabsWrapper = styled_components_1.default.div `
136
+ --md-numbered-list-margin: 0 0 var(--spacing-sm);
137
+
138
+ font-size: var(--page-mcp-405-snippets-font-size);
139
+ line-height: var(--page-mcp-405-snippets-line-height);
140
+ text-align: left;
141
+
142
+ /* The copy control floats over the code, so wrapped lines need room to clear it. */
143
+ pre[data-testid='source-code'] {
144
+ padding-right: var(--page-mcp-405-snippets-code-padding-right);
145
+ }
146
+ `;
147
+ const TabHint = styled_components_1.default.p `
148
+ margin: 0 0 var(--spacing-xs);
149
+ color: var(--page-mcp-405-snippets-hint-text-color);
150
+ `;
151
+ //# sourceMappingURL=McpConnectionTabs.js.map
@@ -1 +1,3 @@
1
+ import type { MCPOption } from '../types/mcp';
1
2
  export declare const DEFAULT_MCP_SERVER_NAME = "mcp-server";
3
+ export declare const DEFAULT_MCP_OPTIONS: MCPOption[];
@@ -1,5 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_MCP_SERVER_NAME = void 0;
3
+ exports.DEFAULT_MCP_OPTIONS = exports.DEFAULT_MCP_SERVER_NAME = void 0;
4
4
  exports.DEFAULT_MCP_SERVER_NAME = 'mcp-server';
5
+ exports.DEFAULT_MCP_OPTIONS = [
6
+ 'cursor',
7
+ 'vscode',
8
+ 'claude-code',
9
+ 'codex',
10
+ 'copy',
11
+ ];
5
12
  //# sourceMappingURL=mcp.js.map
@@ -5,16 +5,20 @@ const react_1 = require("react");
5
5
  const react_router_1 = require("react-router");
6
6
  const utils_1 = require("../utils");
7
7
  const constants_1 = require("../constants");
8
+ const TARGET_TOLERANCE = 2;
8
9
  function useActiveHeading(contentElement, displayedHeadings) {
9
10
  const [heading, setHeading] = (0, react_1.useState)(undefined);
10
11
  const [headingElements, setHeadingElements] = (0, react_1.useState)([]);
11
12
  const headingElementsRef = (0, react_1.useRef)({});
12
13
  const displayedHeadingsRef = (0, react_1.useRef)(displayedHeadings);
13
14
  const lockObserver = (0, react_1.useRef)(false);
15
+ const clickScroll = (0, react_1.useRef)(null);
14
16
  const location = (0, react_router_1.useLocation)();
15
17
  (0, react_1.useEffect)(() => {
16
18
  setHeading(undefined);
17
19
  headingElementsRef.current = {};
20
+ clickScroll.current = null;
21
+ lockObserver.current = false;
18
22
  }, [location.pathname]);
19
23
  (0, react_1.useEffect)(() => {
20
24
  displayedHeadingsRef.current = displayedHeadings;
@@ -98,13 +102,13 @@ function useActiveHeading(contentElement, displayedHeadings) {
98
102
  }, [calculateVirtualPositions]);
99
103
  const intersectionCallback = (0, react_1.useCallback)((entries) => {
100
104
  var _a, _b, _c;
101
- if (lockObserver.current) {
102
- return;
103
- }
104
105
  headingElementsRef.current = entries.reduce((map, entry) => {
105
106
  map[entry.target.id] = entry;
106
107
  return map;
107
108
  }, headingElementsRef.current);
109
+ if (lockObserver.current) {
110
+ return;
111
+ }
108
112
  if (isTopOfPage()) {
109
113
  const newHeading = ((_a = headingElements[0]) === null || _a === void 0 ? void 0 : _a.id) || undefined;
110
114
  setHeading(newHeading);
@@ -145,18 +149,56 @@ function useActiveHeading(contentElement, displayedHeadings) {
145
149
  }
146
150
  setHeading(visibleHeadings[0].target.id);
147
151
  }, [getIndexFromId, headingElements, getTriggerOffset, findActiveHeaderByVirtualPosition]);
152
+ const releaseClickScroll = (0, react_1.useCallback)(() => {
153
+ clickScroll.current = null;
154
+ lockObserver.current = false;
155
+ }, []);
156
+ const trackClickScroll = (0, react_1.useCallback)(() => {
157
+ const clickScrollState = clickScroll.current;
158
+ if (!clickScrollState) {
159
+ return;
160
+ }
161
+ const { top } = clickScrollState.target.getBoundingClientRect();
162
+ if (clickScrollState.reached) {
163
+ if (top >= 0 && top <= getTriggerOffset()) {
164
+ return;
165
+ }
166
+ }
167
+ else {
168
+ const distance = Math.abs(top - clickScrollState.scrollMargin);
169
+ if (distance <= TARGET_TOLERANCE) {
170
+ clickScrollState.reached = true;
171
+ return;
172
+ }
173
+ if (distance <= clickScrollState.closestDistance + TARGET_TOLERANCE) {
174
+ clickScrollState.closestDistance = Math.min(clickScrollState.closestDistance, distance);
175
+ return;
176
+ }
177
+ }
178
+ releaseClickScroll();
179
+ intersectionCallback([]);
180
+ }, [releaseClickScroll, intersectionCallback, getTriggerOffset]);
148
181
  const handleHeadingClick = (0, react_1.useCallback)((headingId) => {
149
- lockObserver.current = true;
182
+ releaseClickScroll();
150
183
  setHeading(headingId);
151
- const headingElement = headingElements.find((el) => el.id === headingId);
152
- if (headingElement && headingElement.scrollIntoView) {
153
- headingElement.scrollIntoView({ behavior: 'smooth', block: 'start' });
154
- }
155
- setTimeout(() => {
156
- headingElementsRef.current = {};
157
- lockObserver.current = false;
158
- }, 300);
159
- }, [headingElements]);
184
+ const target = document.getElementById(headingId) || headingElements.find((el) => el.id === headingId);
185
+ if (!(target === null || target === void 0 ? void 0 : target.scrollIntoView)) {
186
+ return;
187
+ }
188
+ target.scrollIntoView({ behavior: 'smooth', block: 'start' });
189
+ if (!target.getClientRects().length) {
190
+ return;
191
+ }
192
+ const scrollMargin = parseFloat(getComputedStyle(target).scrollMarginTop) || 0;
193
+ const distance = Math.abs(target.getBoundingClientRect().top - scrollMargin);
194
+ lockObserver.current = true;
195
+ clickScroll.current = {
196
+ target,
197
+ scrollMargin,
198
+ closestDistance: distance,
199
+ reached: distance <= TARGET_TOLERANCE,
200
+ };
201
+ }, [headingElements, releaseClickScroll]);
160
202
  (0, react_1.useEffect)(() => {
161
203
  var _a;
162
204
  if (!contentElement) {
@@ -203,8 +245,10 @@ function useActiveHeading(contentElement, displayedHeadings) {
203
245
  });
204
246
  const handleScroll = () => {
205
247
  var _a;
206
- if (lockObserver.current)
248
+ if (clickScroll.current) {
249
+ trackClickScroll();
207
250
  return;
251
+ }
208
252
  if (isTopOfPage()) {
209
253
  setHeading(((_a = headingElements[0]) === null || _a === void 0 ? void 0 : _a.id) || undefined);
210
254
  }
@@ -214,7 +258,7 @@ function useActiveHeading(contentElement, displayedHeadings) {
214
258
  observer.disconnect();
215
259
  window.removeEventListener('scroll', handleScroll);
216
260
  };
217
- }, [headingElements, intersectionCallback, getTriggerOffset]);
261
+ }, [headingElements, intersectionCallback, getTriggerOffset, trackClickScroll]);
218
262
  return { heading, handleHeadingClick };
219
263
  }
220
264
  //# sourceMappingURL=use-active-heading.js.map
@@ -45,10 +45,12 @@ function useActiveSectionId(location, hasOverviewPage = false, withNavbar = true
45
45
  return;
46
46
  }
47
47
  window.addEventListener('scroll', scrollListener, { capture: false });
48
- setTimeout(() => {
48
+ const initialRead = setTimeout(() => {
49
49
  scrollListener();
50
50
  }, 10);
51
51
  return () => {
52
+ clearTimeout(initialRead);
53
+ scrollListener.cancel();
52
54
  window.removeEventListener('scroll', scrollListener);
53
55
  };
54
56
  }, [location, heightOffset, scrollListener]);
@@ -3,7 +3,7 @@ export type McpButtonOptions = {
3
3
  options?: MCPOption[];
4
4
  };
5
5
  export type McpButtonSettings = {
6
- isCopied: boolean;
6
+ copiedOption: MCPOption | null;
7
7
  cursorUrl: string;
8
8
  vscodeUrl: string;
9
9
  triggerButtonText: string;
@@ -9,24 +9,27 @@ const lodash_debounce_1 = __importDefault(require("lodash.debounce"));
9
9
  const use_theme_hooks_1 = require("./use-theme-hooks");
10
10
  const use_mcp_config_1 = require("./use-mcp-config");
11
11
  const clipboard_service_1 = require("../utils/clipboard-service");
12
+ const mcp_1 = require("../constants/mcp");
13
+ const mcp_2 = require("../utils/mcp");
12
14
  const COPIED_RESET_TIMEOUT = 1000;
13
- function useConnectMCPButton({ options = ['cursor', 'vscode', 'copy'], } = {}) {
15
+ function useConnectMCPButton({ options = mcp_1.DEFAULT_MCP_OPTIONS, } = {}) {
14
16
  const { useTranslate } = (0, use_theme_hooks_1.useThemeHooks)();
15
17
  const { translate } = useTranslate();
16
18
  const { serverName, serverUrl, cursorUrl, vscodeUrl } = (0, use_mcp_config_1.useMCPConfig)();
17
- const [isCopied, setIsCopied] = (0, react_1.useState)(false);
19
+ const [copiedOption, setCopiedOption] = (0, react_1.useState)(null);
18
20
  // eslint-disable-next-line react-hooks/exhaustive-deps
19
- const resetCopied = (0, react_1.useCallback)((0, lodash_debounce_1.default)(() => setIsCopied(false), COPIED_RESET_TIMEOUT), []);
21
+ const resetCopied = (0, react_1.useCallback)((0, lodash_debounce_1.default)(() => setCopiedOption(null), COPIED_RESET_TIMEOUT), []);
20
22
  const handleAction = (0, react_1.useCallback)((action) => {
21
- if (action === 'copy') {
22
- const config = {
23
- [serverName]: {
24
- url: serverUrl,
25
- description: 'MCP Server',
26
- },
27
- };
28
- clipboard_service_1.ClipboardService.copyCustom(JSON.stringify(config, null, 2));
29
- setIsCopied(true);
23
+ const connection = { serverName, url: serverUrl };
24
+ const copyTextMap = {
25
+ copy: JSON.stringify({ [serverName]: { url: serverUrl, description: 'MCP Server' } }, null, 2),
26
+ 'claude-code': (0, mcp_2.generateClaudeCodeCommand)(connection),
27
+ codex: (0, mcp_2.generateCodexCommand)(connection),
28
+ };
29
+ const copyText = copyTextMap[action];
30
+ if (copyText !== undefined) {
31
+ clipboard_service_1.ClipboardService.copyCustom(copyText);
32
+ setCopiedOption(action);
30
33
  resetCopied();
31
34
  return;
32
35
  }
@@ -39,7 +42,7 @@ function useConnectMCPButton({ options = ['cursor', 'vscode', 'copy'], } = {}) {
39
42
  const triggerButtonText = (0, react_1.useMemo)(() => translate('page.actions.connectMcp', 'Connect MCP'), [translate]);
40
43
  const visibleOptions = (0, react_1.useMemo)(() => options.filter(Boolean), [options]);
41
44
  return {
42
- isCopied,
45
+ copiedOption,
43
46
  cursorUrl,
44
47
  vscodeUrl,
45
48
  triggerButtonText,
@@ -1037,8 +1037,8 @@ const pages = (0, styled_components_1.css) `
1037
1037
 
1038
1038
  --page-mcp-405-status-text-color: var(--text-color-helper);
1039
1039
  --page-mcp-405-status-font-size: var(--font-size-lg); // @presenter FontSize
1040
- --page-mcp-405-status-line-height: var(--line-height-lg); // @presenter LineHeight
1041
1040
  --page-mcp-405-status-font-weight: var(--font-weight-semibold); // @presenter FontWeight
1041
+ --page-mcp-405-status-line-height: var(--line-height-lg); // @presenter LineHeight
1042
1042
 
1043
1043
  --page-mcp-405-title-text-color: var(--text-color-primary);
1044
1044
  --page-mcp-405-title-font-size: 42px; // @presenter FontSize
@@ -1054,6 +1054,11 @@ const pages = (0, styled_components_1.css) `
1054
1054
  --page-mcp-405-description-font-size-mobile: var(--font-size-lg);
1055
1055
  --page-mcp-405-description-line-height-mobile: var(--line-height-lg);
1056
1056
 
1057
+ --page-mcp-405-snippets-font-size: var(--font-size-base); // @presenter FontSize
1058
+ --page-mcp-405-snippets-line-height: var(--line-height-base); // @presenter LineHeight
1059
+ --page-mcp-405-snippets-hint-text-color: var(--text-color-secondary);
1060
+ --page-mcp-405-snippets-code-padding-right: var(--spacing-xxl);
1061
+
1057
1062
  // @tokens End
1058
1063
 
1059
1064
  /**
@@ -180,6 +180,8 @@ export type BffCatalogList<T> = {
180
180
  export type BffCatalogEntityList = BffCatalogList<BffCatalogEntity>;
181
181
  export type BffCatalogRelatedEntityList = BffCatalogList<BffCatalogRelatedEntity>;
182
182
  export type Page = {
183
+ nextPage?: string | null;
184
+ previousPage?: string | null;
183
185
  endCursor: string | null;
184
186
  startCursor: string | null;
185
187
  hasNextPage: boolean;