doccupine 0.0.133 → 0.0.134

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 (143) hide show
  1. package/README.md +40 -1
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +274 -19
  4. package/dist/lib/config-manager.d.ts +8 -1
  5. package/dist/lib/config-manager.js +98 -4
  6. package/dist/lib/openapi-types.d.ts +120 -0
  7. package/dist/lib/openapi-types.js +14 -0
  8. package/dist/lib/openapi.d.ts +52 -0
  9. package/dist/lib/openapi.js +603 -0
  10. package/dist/lib/structures.js +28 -2
  11. package/dist/lib/types.d.ts +22 -0
  12. package/dist/lib/utils.d.ts +8 -0
  13. package/dist/lib/utils.js +14 -0
  14. package/dist/templates/app/api/playground/route.d.ts +1 -0
  15. package/dist/templates/app/api/playground/route.js +199 -0
  16. package/dist/templates/components/Docs.d.ts +1 -1
  17. package/dist/templates/components/Docs.js +11 -2
  18. package/dist/templates/components/SideBar.d.ts +1 -1
  19. package/dist/templates/components/SideBar.js +10 -0
  20. package/dist/templates/components/layout/Accordion.d.ts +1 -1
  21. package/dist/templates/components/layout/Accordion.js +3 -2
  22. package/dist/templates/components/layout/ActionBar.d.ts +1 -1
  23. package/dist/templates/components/layout/ActionBar.js +21 -14
  24. package/dist/templates/components/layout/ApiPlayground.d.ts +1 -0
  25. package/dist/templates/components/layout/ApiPlayground.js +1083 -0
  26. package/dist/templates/components/layout/ApiPlaygroundDemo.d.ts +1 -0
  27. package/dist/templates/components/layout/ApiPlaygroundDemo.js +81 -0
  28. package/dist/templates/components/layout/Code.d.ts +1 -1
  29. package/dist/templates/components/layout/Code.js +10 -22
  30. package/dist/templates/components/layout/CopyButton.d.ts +1 -0
  31. package/dist/templates/components/layout/CopyButton.js +68 -0
  32. package/dist/templates/components/layout/DocsComponents.d.ts +1 -1
  33. package/dist/templates/components/layout/DocsComponents.js +39 -0
  34. package/dist/templates/components/layout/Mermaid.d.ts +1 -1
  35. package/dist/templates/components/layout/Mermaid.js +21 -3
  36. package/dist/templates/components/layout/SharedStyles.d.ts +1 -1
  37. package/dist/templates/components/layout/SharedStyles.js +0 -4
  38. package/dist/templates/components/layout/Steps.d.ts +1 -1
  39. package/dist/templates/components/layout/Steps.js +0 -1
  40. package/dist/templates/components/layout/Update.d.ts +1 -1
  41. package/dist/templates/components/layout/Update.js +2 -1
  42. package/dist/templates/mdx/accordion.mdx.d.ts +1 -1
  43. package/dist/templates/mdx/accordion.mdx.js +19 -1
  44. package/dist/templates/mdx/ai-assistant.mdx.d.ts +1 -1
  45. package/dist/templates/mdx/ai-assistant.mdx.js +3 -2
  46. package/dist/templates/mdx/analytics.mdx.d.ts +1 -1
  47. package/dist/templates/mdx/analytics.mdx.js +2 -2
  48. package/dist/templates/mdx/api-playground.mdx.d.ts +1 -0
  49. package/dist/templates/mdx/api-playground.mdx.js +158 -0
  50. package/dist/templates/mdx/authentication.mdx.d.ts +1 -1
  51. package/dist/templates/mdx/authentication.mdx.js +3 -3
  52. package/dist/templates/mdx/buttons.mdx.d.ts +1 -1
  53. package/dist/templates/mdx/buttons.mdx.js +1 -1
  54. package/dist/templates/mdx/callouts.mdx.d.ts +1 -1
  55. package/dist/templates/mdx/callouts.mdx.js +1 -1
  56. package/dist/templates/mdx/cards.mdx.d.ts +1 -1
  57. package/dist/templates/mdx/cards.mdx.js +1 -1
  58. package/dist/templates/mdx/color-swatches.mdx.d.ts +1 -1
  59. package/dist/templates/mdx/color-swatches.mdx.js +1 -1
  60. package/dist/templates/mdx/commands.mdx.d.ts +1 -1
  61. package/dist/templates/mdx/commands.mdx.js +3 -2
  62. package/dist/templates/mdx/components.mdx.d.ts +1 -1
  63. package/dist/templates/mdx/components.mdx.js +12 -9
  64. package/dist/templates/mdx/deployment-and-hosting.mdx.d.ts +1 -1
  65. package/dist/templates/mdx/deployment-and-hosting.mdx.js +4 -3
  66. package/dist/templates/mdx/fields.mdx.d.ts +1 -1
  67. package/dist/templates/mdx/fields.mdx.js +1 -1
  68. package/dist/templates/mdx/fonts.mdx.d.ts +1 -1
  69. package/dist/templates/mdx/fonts.mdx.js +2 -2
  70. package/dist/templates/mdx/footer-links.mdx.d.ts +1 -1
  71. package/dist/templates/mdx/footer-links.mdx.js +1 -1
  72. package/dist/templates/mdx/frames.mdx.d.ts +1 -1
  73. package/dist/templates/mdx/frames.mdx.js +1 -1
  74. package/dist/templates/mdx/globals.mdx.d.ts +1 -1
  75. package/dist/templates/mdx/globals.mdx.js +1 -1
  76. package/dist/templates/mdx/icons.mdx.d.ts +1 -1
  77. package/dist/templates/mdx/icons.mdx.js +1 -1
  78. package/dist/templates/mdx/image-and-embeds.mdx.d.ts +1 -1
  79. package/dist/templates/mdx/image-and-embeds.mdx.js +1 -1
  80. package/dist/templates/mdx/media-and-assets.mdx.d.ts +1 -1
  81. package/dist/templates/mdx/media-and-assets.mdx.js +2 -2
  82. package/dist/templates/mdx/mermaid.mdx.d.ts +1 -1
  83. package/dist/templates/mdx/mermaid.mdx.js +1 -1
  84. package/dist/templates/mdx/model-context-protocol.mdx.d.ts +1 -1
  85. package/dist/templates/mdx/model-context-protocol.mdx.js +2 -2
  86. package/dist/templates/mdx/navigation.mdx.d.ts +1 -1
  87. package/dist/templates/mdx/navigation.mdx.js +22 -11
  88. package/dist/templates/mdx/platform/ai-assistant.mdx.d.ts +1 -1
  89. package/dist/templates/mdx/platform/ai-assistant.mdx.js +4 -3
  90. package/dist/templates/mdx/platform/analytics.mdx.d.ts +1 -1
  91. package/dist/templates/mdx/platform/analytics.mdx.js +2 -2
  92. package/dist/templates/mdx/platform/api-playground.mdx.d.ts +1 -0
  93. package/dist/templates/mdx/platform/api-playground.mdx.js +62 -0
  94. package/dist/templates/mdx/platform/billing.mdx.d.ts +1 -1
  95. package/dist/templates/mdx/platform/billing.mdx.js +1 -1
  96. package/dist/templates/mdx/platform/build-and-deploy.mdx.d.ts +1 -1
  97. package/dist/templates/mdx/platform/build-and-deploy.mdx.js +1 -1
  98. package/dist/templates/mdx/platform/creating-a-project.mdx.d.ts +1 -1
  99. package/dist/templates/mdx/platform/creating-a-project.mdx.js +12 -2
  100. package/dist/templates/mdx/platform/custom-domains.mdx.d.ts +1 -1
  101. package/dist/templates/mdx/platform/custom-domains.mdx.js +1 -1
  102. package/dist/templates/mdx/platform/fonts-settings.mdx.d.ts +1 -1
  103. package/dist/templates/mdx/platform/fonts-settings.mdx.js +1 -1
  104. package/dist/templates/mdx/platform/footer-links.mdx.d.ts +1 -0
  105. package/dist/templates/mdx/platform/footer-links.mdx.js +47 -0
  106. package/dist/templates/mdx/platform/import-from-github.mdx.d.ts +1 -0
  107. package/dist/templates/mdx/platform/import-from-github.mdx.js +91 -0
  108. package/dist/templates/mdx/platform/mcp.mdx.d.ts +1 -1
  109. package/dist/templates/mdx/platform/mcp.mdx.js +3 -3
  110. package/dist/templates/mdx/platform/project-settings.mdx.d.ts +1 -1
  111. package/dist/templates/mdx/platform/project-settings.mdx.js +1 -1
  112. package/dist/templates/mdx/platform/self-updating-docs.mdx.d.ts +1 -0
  113. package/dist/templates/mdx/platform/self-updating-docs.mdx.js +113 -0
  114. package/dist/templates/mdx/platform/team-members.mdx.d.ts +1 -1
  115. package/dist/templates/mdx/platform/team-members.mdx.js +1 -1
  116. package/dist/templates/mdx/sections.mdx.d.ts +1 -1
  117. package/dist/templates/mdx/sections.mdx.js +1 -1
  118. package/dist/templates/mdx/steps.mdx.d.ts +1 -1
  119. package/dist/templates/mdx/steps.mdx.js +1 -1
  120. package/dist/templates/mdx/tabs.mdx.d.ts +1 -1
  121. package/dist/templates/mdx/tabs.mdx.js +1 -1
  122. package/dist/templates/mdx/theme.mdx.d.ts +1 -1
  123. package/dist/templates/mdx/theme.mdx.js +1 -1
  124. package/dist/templates/mdx/update.mdx.d.ts +1 -1
  125. package/dist/templates/mdx/update.mdx.js +1 -1
  126. package/dist/templates/mdx/what-is-doccupine.mdx.d.ts +1 -1
  127. package/dist/templates/mdx/what-is-doccupine.mdx.js +1 -1
  128. package/dist/templates/package.js +6 -6
  129. package/dist/templates/services/openapi/playgroundAllowlistStub.d.ts +1 -0
  130. package/dist/templates/services/openapi/playgroundAllowlistStub.js +4 -0
  131. package/dist/templates/types/openapi.d.ts +1 -0
  132. package/dist/templates/types/openapi.js +93 -0
  133. package/dist/templates/utils/apiAnchors.d.ts +1 -0
  134. package/dist/templates/utils/apiAnchors.js +39 -0
  135. package/dist/templates/utils/apiSnippets.d.ts +1 -0
  136. package/dist/templates/utils/apiSnippets.js +94 -0
  137. package/dist/templates/utils/orderNavItems.d.ts +1 -1
  138. package/dist/templates/utils/orderNavItems.js +3 -0
  139. package/dist/templates/utils/playgroundAllowlist.d.ts +1 -0
  140. package/dist/templates/utils/playgroundAllowlist.js +70 -0
  141. package/dist/templates/utils/ssrfGuard.d.ts +1 -0
  142. package/dist/templates/utils/ssrfGuard.js +217 -0
  143. package/package.json +3 -2
@@ -74,13 +74,23 @@ import { buildDocsIndexScriptTemplate } from "../templates/scripts/build-docs-in
74
74
  import { posthogServerTemplate } from "../templates/lib/posthog.js";
75
75
  import { siteGateTemplate } from "../templates/lib/siteGate.js";
76
76
  import { styledDTemplate } from "../templates/types/styled.js";
77
+ import { openapiTypesTemplate } from "../templates/types/openapi.js";
77
78
  import { orderNavItemsTemplate } from "../templates/utils/orderNavItems.js";
78
79
  import { rateLimitTemplate } from "../templates/utils/rateLimit.js";
79
80
  import { brandingTemplate } from "../templates/utils/branding.js";
80
81
  import { configTemplate } from "../templates/utils/config.js";
82
+ import { playgroundAllowlistTemplate } from "../templates/utils/playgroundAllowlist.js";
83
+ import { ssrfGuardTemplate } from "../templates/utils/ssrfGuard.js";
84
+ import { apiSnippetsTemplate } from "../templates/utils/apiSnippets.js";
85
+ import { playgroundRoutesTemplate } from "../templates/app/api/playground/route.js";
86
+ import { playgroundAllowlistStubTemplate } from "../templates/services/openapi/playgroundAllowlistStub.js";
87
+ import { copyButtonTemplate } from "../templates/components/layout/CopyButton.js";
88
+ import { apiPlaygroundTemplate } from "../templates/components/layout/ApiPlayground.js";
89
+ import { apiPlaygroundDemoTemplate } from "../templates/components/layout/ApiPlaygroundDemo.js";
81
90
  import { accordionMdxTemplate } from "../templates/mdx/accordion.mdx.js";
82
91
  import { aiAssistantMdxTemplate } from "../templates/mdx/ai-assistant.mdx.js";
83
92
  import { analyticsMdxTemplate } from "../templates/mdx/analytics.mdx.js";
93
+ import { apiPlaygroundMdxTemplate } from "../templates/mdx/api-playground.mdx.js";
84
94
  import { authenticationMdxTemplate } from "../templates/mdx/authentication.mdx.js";
85
95
  import { buttonsMdxTemplate } from "../templates/mdx/buttons.mdx.js";
86
96
  import { calloutsMdxTemplate } from "../templates/mdx/callouts.mdx.js";
@@ -115,12 +125,15 @@ import { platformIndexMdxTemplate } from "../templates/mdx/platform/index.mdx.js
115
125
  import { platformFileEditorMdxTemplate } from "../templates/mdx/platform/file-editor.mdx.js";
116
126
  import { platformPublishingMdxTemplate } from "../templates/mdx/platform/publishing.mdx.js";
117
127
  import { platformCreatingAProjectMdxTemplate } from "../templates/mdx/platform/creating-a-project.mdx.js";
128
+ import { platformImportFromGithubMdxTemplate } from "../templates/mdx/platform/import-from-github.mdx.js";
129
+ import { platformSelfUpdatingDocsMdxTemplate } from "../templates/mdx/platform/self-updating-docs.mdx.js";
118
130
  import { platformSiteSettingsMdxTemplate } from "../templates/mdx/platform/site-settings.mdx.js";
119
131
  import { platformThemeSettingsMdxTemplate } from "../templates/mdx/platform/theme-settings.mdx.js";
120
132
  import { platformNavigationSettingsMdxTemplate } from "../templates/mdx/platform/navigation-settings.mdx.js";
121
133
  import { platformFontsSettingsMdxTemplate } from "../templates/mdx/platform/fonts-settings.mdx.js";
122
- import { platformExternalLinksMdxTemplate } from "../templates/mdx/platform/external-links.mdx.js";
134
+ import { platformFooterLinksMdxTemplate } from "../templates/mdx/platform/footer-links.mdx.js";
123
135
  import { platformAnalyticsMdxTemplate } from "../templates/mdx/platform/analytics.mdx.js";
136
+ import { platformApiPlaygroundMdxTemplate } from "../templates/mdx/platform/api-playground.mdx.js";
124
137
  import { platformAiAssistantMdxTemplate } from "../templates/mdx/platform/ai-assistant.mdx.js";
125
138
  import { platformMcpMdxTemplate } from "../templates/mdx/platform/mcp.mdx.js";
126
139
  import { platformCustomDomainsMdxTemplate } from "../templates/mdx/platform/custom-domains.mdx.js";
@@ -144,6 +157,7 @@ export const appStructure = {
144
157
  "app/api/mcp/route.ts": mcpRoutesTemplate,
145
158
  "app/api/rag/route.ts": ragRoutesTemplate,
146
159
  "app/api/search/route.ts": searchRoutesTemplate,
160
+ "app/api/playground/route.ts": playgroundRoutesTemplate,
147
161
  "services/search.ts": searchServiceTemplate,
148
162
  "services/mcp/index.ts": mcpIndexTemplate,
149
163
  "services/mcp/server.ts": mcpServerTemplate,
@@ -155,8 +169,10 @@ export const appStructure = {
155
169
  "services/llm/factory.ts": llmFactoryTemplate,
156
170
  "services/llm/index.ts": llmIndexTemplate,
157
171
  "services/llm/types.ts": llmTypesTemplate,
172
+ "services/openapi/playground-allowlist.json": playgroundAllowlistStubTemplate,
158
173
  "scripts/build-docs-index.mts": buildDocsIndexScriptTemplate,
159
174
  "types/styled.d.ts": styledDTemplate,
175
+ "types/openapi.ts": openapiTypesTemplate,
160
176
  "lib/posthog.ts": posthogServerTemplate,
161
177
  "lib/siteGate.ts": siteGateTemplate,
162
178
  "utils/branding.ts": brandingTemplate,
@@ -166,6 +182,9 @@ export const appStructure = {
166
182
  "utils/rateLimit.ts": rateLimitTemplate,
167
183
  "utils/rehypeCodeMeta.ts": rehypeCodeMetaTemplate,
168
184
  "utils/config.ts": configTemplate,
185
+ "utils/playgroundAllowlist.ts": playgroundAllowlistTemplate,
186
+ "utils/ssrfGuard.ts": ssrfGuardTemplate,
187
+ "utils/apiSnippets.ts": apiSnippetsTemplate,
169
188
  "components/Chat.tsx": chatTemplate,
170
189
  "components/LockBodyScroll.ts": lockBodyScrollTemplate,
171
190
  "components/Docs.tsx": docsTemplate,
@@ -181,12 +200,15 @@ export const appStructure = {
181
200
  "components/Spinner.tsx": spinnerTemplate,
182
201
  "components/layout/Accordion.tsx": accordionTemplate,
183
202
  "components/layout/ActionBar.tsx": actionBarTemplate,
203
+ "components/layout/ApiPlayground.tsx": apiPlaygroundTemplate,
204
+ "components/layout/ApiPlaygroundDemo.tsx": apiPlaygroundDemoTemplate,
184
205
  "components/layout/Button.tsx": buttonTemplate,
185
206
  "components/layout/Callout.tsx": calloutTemplate,
186
207
  "components/layout/Card.tsx": cardTemplate,
187
208
  "components/layout/CherryThemeProvider.tsx": cherryThemeProviderTemplate,
188
209
  "components/layout/ColorSwatch.tsx": colorSwatchTemplate,
189
210
  "components/layout/Code.tsx": codeTemplate,
211
+ "components/layout/CopyButton.tsx": copyButtonTemplate,
190
212
  "components/layout/Columns.tsx": columnsTemplate,
191
213
  "components/layout/DemoTheme.tsx": demoThemeTemplate,
192
214
  "components/layout/DocsComponents.tsx": docsComponentsTemplate,
@@ -223,6 +245,7 @@ export const startingDocsStructure = {
223
245
  "accordion.mdx": accordionMdxTemplate,
224
246
  "ai-assistant.mdx": aiAssistantMdxTemplate,
225
247
  "analytics.mdx": analyticsMdxTemplate,
248
+ "api-playground.mdx": apiPlaygroundMdxTemplate,
226
249
  "authentication.mdx": authenticationMdxTemplate,
227
250
  "buttons.mdx": buttonsMdxTemplate,
228
251
  "callouts.mdx": calloutsMdxTemplate,
@@ -257,14 +280,17 @@ export const startingDocsStructure = {
257
280
  "platform/file-editor.mdx": platformFileEditorMdxTemplate,
258
281
  "platform/publishing.mdx": platformPublishingMdxTemplate,
259
282
  "platform/creating-a-project.mdx": platformCreatingAProjectMdxTemplate,
283
+ "platform/import-from-github.mdx": platformImportFromGithubMdxTemplate,
284
+ "platform/self-updating-docs.mdx": platformSelfUpdatingDocsMdxTemplate,
260
285
  "platform/site-settings.mdx": platformSiteSettingsMdxTemplate,
261
286
  "platform/theme-settings.mdx": platformThemeSettingsMdxTemplate,
262
287
  "platform/navigation-settings.mdx": platformNavigationSettingsMdxTemplate,
263
288
  "platform/fonts-settings.mdx": platformFontsSettingsMdxTemplate,
264
- "platform/external-links.mdx": platformExternalLinksMdxTemplate,
289
+ "platform/footer-links.mdx": platformFooterLinksMdxTemplate,
265
290
  "platform/analytics.mdx": platformAnalyticsMdxTemplate,
266
291
  "platform/ai-assistant.mdx": platformAiAssistantMdxTemplate,
267
292
  "platform/mcp.mdx": platformMcpMdxTemplate,
293
+ "platform/api-playground.mdx": platformApiPlaygroundMdxTemplate,
268
294
  "platform/custom-domains.mdx": platformCustomDomainsMdxTemplate,
269
295
  "platform/build-and-deploy.mdx": platformBuildAndDeployMdxTemplate,
270
296
  "platform/team-members.mdx": platformTeamMembersMdxTemplate,
@@ -17,6 +17,11 @@ export interface PageMeta {
17
17
  navIcon?: string;
18
18
  categoryIcon?: string;
19
19
  lastModified?: string;
20
+ /** HTTP verb (e.g. "GET") for synthetic OpenAPI endpoint pages. Set only on
21
+ * generated API-reference pages so the sidebar can render a method badge;
22
+ * omitted on hand-written MDX pages so their serialized nav objects are
23
+ * unchanged. */
24
+ httpMethod?: string;
20
25
  }
21
26
  export interface SectionConfig {
22
27
  label: string;
@@ -31,6 +36,23 @@ export interface DoccupineConfig {
31
36
  * ("pnpm" or "npm"), overriding auto-detection. Also settable per run via
32
37
  * the `--package-manager` flag, which takes precedence over this field. */
33
38
  packageManager?: string;
39
+ /** Optional OpenAPI spec(s) that drive the generated API reference section.
40
+ * Accepts a single path, a list of paths, or named-spec objects; all forms
41
+ * are normalized to `NormalizedOpenApiSpec[]` internally. */
42
+ openapi?: string | string[] | OpenApiSpecConfig[];
43
+ }
44
+ /** A named OpenAPI spec entry as authored in `doccupine.json`. */
45
+ export interface OpenApiSpecConfig {
46
+ /** Display/namespace name; defaults to the file basename when omitted. Used
47
+ * as the sidebar section and route namespace when more than one spec. */
48
+ name?: string;
49
+ /** Path to a `.json`/`.yaml`/`.yml` OpenAPI document, project-relative. */
50
+ file: string;
51
+ }
52
+ /** Internal, fully-resolved form every `openapi` config shape collapses to. */
53
+ export interface NormalizedOpenApiSpec {
54
+ name: string;
55
+ file: string;
34
56
  }
35
57
  export interface FontConfig {
36
58
  [key: string]: any;
@@ -18,3 +18,11 @@ export declare function findAvailablePort(startPort: number): Promise<number>;
18
18
  export declare function generateSlug(filePath: string): string;
19
19
  export declare function getFullSlug(pageSlug: string, sectionSlug: string): string;
20
20
  export declare function escapeTemplateContent(content: string): string;
21
+ /**
22
+ * Renders `value` as a JS string literal using the same quote Prettier would
23
+ * choose: double by default, switching to single when that needs fewer escapes
24
+ * (JSON text, for instance, is full of `"`). Backslashes and the chosen quote
25
+ * are escaped. Lets generated code embed a string in a form Prettier leaves
26
+ * untouched, so emitted files stay format-stable without running a formatter.
27
+ */
28
+ export declare function toJsStringLiteral(value: string): string;
package/dist/lib/utils.js CHANGED
@@ -94,3 +94,17 @@ export function escapeTemplateContent(content) {
94
94
  .replace(/`/g, "\\`")
95
95
  .replace(/\$\{/g, "\\${");
96
96
  }
97
+ /**
98
+ * Renders `value` as a JS string literal using the same quote Prettier would
99
+ * choose: double by default, switching to single when that needs fewer escapes
100
+ * (JSON text, for instance, is full of `"`). Backslashes and the chosen quote
101
+ * are escaped. Lets generated code embed a string in a form Prettier leaves
102
+ * untouched, so emitted files stay format-stable without running a formatter.
103
+ */
104
+ export function toJsStringLiteral(value) {
105
+ const doubleQuotes = (value.match(/"/g) || []).length;
106
+ const singleQuotes = (value.match(/'/g) || []).length;
107
+ const quote = singleQuotes < doubleQuotes ? "'" : '"';
108
+ const escaped = value.replace(/\\/g, "\\\\").split(quote).join(`\\${quote}`);
109
+ return `${quote}${escaped}${quote}`;
110
+ }
@@ -0,0 +1 @@
1
+ export declare const playgroundRoutesTemplate = "import { NextResponse } from \"next/server\";\nimport { z } from \"zod\";\nimport { rateLimit } from \"@/utils/rateLimit\";\nimport { matchAllowlist } from \"@/utils/playgroundAllowlist\";\nimport { guardedFetch, BlockedError } from \"@/utils/ssrfGuard\";\n\n// The playground proxy runs server-side so it can call APIs that block\n// cross-origin browser requests. It is NOT an open forward proxy: every target\n// is gated by the build-time allowlist (derived from the OpenAPI servers) and\n// then re-validated against private/metadata IP ranges before any socket opens.\nexport const runtime = \"nodejs\";\nexport const maxDuration = 40;\n\nconst MAX_REQUEST_BYTES = 1_000_000;\nconst MAX_RESPONSE_BYTES = 5_000_000;\nconst TIMEOUT_MS = 30_000;\n\nconst envelopeSchema = z.object({\n targetUrl: z.string().url().max(4096),\n method: z.enum([\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\", \"HEAD\", \"OPTIONS\"]),\n headers: z.record(z.string().max(256), z.string().max(8192)).optional(),\n body: z.string().max(MAX_REQUEST_BYTES).optional(),\n bodyEncoding: z.enum([\"utf8\", \"base64\"]).optional(),\n});\n\n// Headers we never forward upstream: hop-by-hop, or identity/cookie headers\n// that would either leak the docs origin or be set incorrectly.\nconst BLOCKED_REQUEST_HEADERS = new Set([\n \"connection\",\n \"keep-alive\",\n \"proxy-authenticate\",\n \"proxy-authorization\",\n \"te\",\n \"trailer\",\n \"transfer-encoding\",\n \"upgrade\",\n \"host\",\n \"content-length\",\n \"cookie\",\n \"origin\",\n \"referer\",\n \"forwarded\",\n \"x-forwarded-for\",\n \"x-forwarded-host\",\n \"x-forwarded-proto\",\n]);\n\n// The only response headers echoed back to the client. Notably excludes\n// set-cookie, authorization, and www-authenticate.\nconst SAFE_RESPONSE_HEADERS = new Set([\n \"content-type\",\n \"content-length\",\n \"content-language\",\n \"content-disposition\",\n \"cache-control\",\n \"etag\",\n \"last-modified\",\n \"date\",\n \"location\",\n \"retry-after\",\n]);\n\nfunction hasControlChars(value: string): boolean {\n return (\n value.includes(String.fromCharCode(10)) ||\n value.includes(String.fromCharCode(13))\n );\n}\n\nfunction isTextContentType(contentType: string | null): boolean {\n if (!contentType) return false;\n const t = contentType.toLowerCase();\n return (\n t.startsWith(\"text/\") ||\n t.includes(\"json\") ||\n t.includes(\"xml\") ||\n t.includes(\"javascript\") ||\n t.includes(\"x-www-form-urlencoded\") ||\n t.includes(\"csv\")\n );\n}\n\nexport async function POST(req: Request) {\n const ip =\n req.headers.get(\"x-forwarded-for\")?.split(\",\")[0]?.trim() ?? \"unknown\";\n const { allowed, retryAfter } = rateLimit(ip);\n if (!allowed) {\n return NextResponse.json(\n { error: \"Too many requests\" },\n { status: 429, headers: { \"Retry-After\": String(retryAfter) } },\n );\n }\n\n let raw: unknown;\n try {\n raw = await req.json();\n } catch {\n return NextResponse.json({ error: \"Invalid JSON body\" }, { status: 400 });\n }\n\n const parsed = envelopeSchema.safeParse(raw);\n if (!parsed.success) {\n return NextResponse.json(\n { error: \"Invalid request\", details: parsed.error.issues },\n { status: 400 },\n );\n }\n\n const { targetUrl, method, headers = {}, body, bodyEncoding } = parsed.data;\n\n const entry = matchAllowlist(targetUrl);\n if (!entry) {\n console.warn(\"[playground] blocked: non-allowlisted target\");\n return NextResponse.json(\n { error: \"This request target is not allowed by the API reference.\" },\n { status: 403 },\n );\n }\n\n if (Object.keys(headers).length > 50) {\n return NextResponse.json({ error: \"Too many headers\" }, { status: 400 });\n }\n\n const outboundHeaders: Record<string, string> = {};\n for (const [key, value] of Object.entries(headers)) {\n const lower = key.toLowerCase();\n if (BLOCKED_REQUEST_HEADERS.has(lower)) continue;\n if (hasControlChars(key) || hasControlChars(value)) continue;\n outboundHeaders[key] = value;\n }\n outboundHeaders[\"user-agent\"] =\n outboundHeaders[\"user-agent\"] ?? \"Doccupine-API-Playground\";\n // Ask for an unencoded body so the response byte cap is measured accurately.\n outboundHeaders[\"accept-encoding\"] = \"identity\";\n\n let bodyBuffer: Buffer | undefined;\n if (body !== undefined && method !== \"GET\" && method !== \"HEAD\") {\n bodyBuffer = Buffer.from(\n body,\n bodyEncoding === \"base64\" ? \"base64\" : \"utf8\",\n );\n }\n\n try {\n const result = await guardedFetch(targetUrl, entry, {\n method,\n headers: outboundHeaders,\n body: bodyBuffer,\n timeoutMs: TIMEOUT_MS,\n maxBytes: MAX_RESPONSE_BYTES,\n });\n\n const safeHeaders: Record<string, string> = {};\n let contentType: string | null = null;\n for (const [key, value] of Object.entries(result.headers)) {\n if (key === \"content-type\") contentType = value;\n if (SAFE_RESPONSE_HEADERS.has(key)) safeHeaders[key] = value;\n }\n\n const isText = isTextContentType(contentType);\n\n // Deliberately do NOT log the request/response here: the full URL (path and\n // query) and headers can carry reader secrets. Only blocked/failed attempts\n // are logged below via console.warn, and those record no sensitive values.\n return NextResponse.json({\n status: result.status,\n statusText: result.statusText,\n headers: safeHeaders,\n contentType,\n bodyEncoding: isText ? \"utf8\" : \"base64\",\n body: result.body.toString(isText ? \"utf8\" : \"base64\"),\n truncated: result.truncated,\n byteLength: result.body.length,\n durationMs: result.durationMs,\n });\n } catch (error) {\n if (error instanceof BlockedError) {\n console.warn(\"[playground] \" + error.reason);\n return NextResponse.json(\n { error: \"This request target is not allowed.\" },\n { status: 403 },\n );\n }\n const message = error instanceof Error ? error.message : \"\";\n if (message === \"timeout\") {\n console.warn(\"[playground] upstream timeout\");\n return NextResponse.json(\n { error: \"The upstream request timed out.\" },\n { status: 504 },\n );\n }\n console.warn(\"[playground] upstream request failed\");\n return NextResponse.json(\n { error: \"The upstream request failed.\" },\n { status: 502 },\n );\n }\n}\n";
@@ -0,0 +1,199 @@
1
+ export const playgroundRoutesTemplate = `import { NextResponse } from "next/server";
2
+ import { z } from "zod";
3
+ import { rateLimit } from "@/utils/rateLimit";
4
+ import { matchAllowlist } from "@/utils/playgroundAllowlist";
5
+ import { guardedFetch, BlockedError } from "@/utils/ssrfGuard";
6
+
7
+ // The playground proxy runs server-side so it can call APIs that block
8
+ // cross-origin browser requests. It is NOT an open forward proxy: every target
9
+ // is gated by the build-time allowlist (derived from the OpenAPI servers) and
10
+ // then re-validated against private/metadata IP ranges before any socket opens.
11
+ export const runtime = "nodejs";
12
+ export const maxDuration = 40;
13
+
14
+ const MAX_REQUEST_BYTES = 1_000_000;
15
+ const MAX_RESPONSE_BYTES = 5_000_000;
16
+ const TIMEOUT_MS = 30_000;
17
+
18
+ const envelopeSchema = z.object({
19
+ targetUrl: z.string().url().max(4096),
20
+ method: z.enum(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"]),
21
+ headers: z.record(z.string().max(256), z.string().max(8192)).optional(),
22
+ body: z.string().max(MAX_REQUEST_BYTES).optional(),
23
+ bodyEncoding: z.enum(["utf8", "base64"]).optional(),
24
+ });
25
+
26
+ // Headers we never forward upstream: hop-by-hop, or identity/cookie headers
27
+ // that would either leak the docs origin or be set incorrectly.
28
+ const BLOCKED_REQUEST_HEADERS = new Set([
29
+ "connection",
30
+ "keep-alive",
31
+ "proxy-authenticate",
32
+ "proxy-authorization",
33
+ "te",
34
+ "trailer",
35
+ "transfer-encoding",
36
+ "upgrade",
37
+ "host",
38
+ "content-length",
39
+ "cookie",
40
+ "origin",
41
+ "referer",
42
+ "forwarded",
43
+ "x-forwarded-for",
44
+ "x-forwarded-host",
45
+ "x-forwarded-proto",
46
+ ]);
47
+
48
+ // The only response headers echoed back to the client. Notably excludes
49
+ // set-cookie, authorization, and www-authenticate.
50
+ const SAFE_RESPONSE_HEADERS = new Set([
51
+ "content-type",
52
+ "content-length",
53
+ "content-language",
54
+ "content-disposition",
55
+ "cache-control",
56
+ "etag",
57
+ "last-modified",
58
+ "date",
59
+ "location",
60
+ "retry-after",
61
+ ]);
62
+
63
+ function hasControlChars(value: string): boolean {
64
+ return (
65
+ value.includes(String.fromCharCode(10)) ||
66
+ value.includes(String.fromCharCode(13))
67
+ );
68
+ }
69
+
70
+ function isTextContentType(contentType: string | null): boolean {
71
+ if (!contentType) return false;
72
+ const t = contentType.toLowerCase();
73
+ return (
74
+ t.startsWith("text/") ||
75
+ t.includes("json") ||
76
+ t.includes("xml") ||
77
+ t.includes("javascript") ||
78
+ t.includes("x-www-form-urlencoded") ||
79
+ t.includes("csv")
80
+ );
81
+ }
82
+
83
+ export async function POST(req: Request) {
84
+ const ip =
85
+ req.headers.get("x-forwarded-for")?.split(",")[0]?.trim() ?? "unknown";
86
+ const { allowed, retryAfter } = rateLimit(ip);
87
+ if (!allowed) {
88
+ return NextResponse.json(
89
+ { error: "Too many requests" },
90
+ { status: 429, headers: { "Retry-After": String(retryAfter) } },
91
+ );
92
+ }
93
+
94
+ let raw: unknown;
95
+ try {
96
+ raw = await req.json();
97
+ } catch {
98
+ return NextResponse.json({ error: "Invalid JSON body" }, { status: 400 });
99
+ }
100
+
101
+ const parsed = envelopeSchema.safeParse(raw);
102
+ if (!parsed.success) {
103
+ return NextResponse.json(
104
+ { error: "Invalid request", details: parsed.error.issues },
105
+ { status: 400 },
106
+ );
107
+ }
108
+
109
+ const { targetUrl, method, headers = {}, body, bodyEncoding } = parsed.data;
110
+
111
+ const entry = matchAllowlist(targetUrl);
112
+ if (!entry) {
113
+ console.warn("[playground] blocked: non-allowlisted target");
114
+ return NextResponse.json(
115
+ { error: "This request target is not allowed by the API reference." },
116
+ { status: 403 },
117
+ );
118
+ }
119
+
120
+ if (Object.keys(headers).length > 50) {
121
+ return NextResponse.json({ error: "Too many headers" }, { status: 400 });
122
+ }
123
+
124
+ const outboundHeaders: Record<string, string> = {};
125
+ for (const [key, value] of Object.entries(headers)) {
126
+ const lower = key.toLowerCase();
127
+ if (BLOCKED_REQUEST_HEADERS.has(lower)) continue;
128
+ if (hasControlChars(key) || hasControlChars(value)) continue;
129
+ outboundHeaders[key] = value;
130
+ }
131
+ outboundHeaders["user-agent"] =
132
+ outboundHeaders["user-agent"] ?? "Doccupine-API-Playground";
133
+ // Ask for an unencoded body so the response byte cap is measured accurately.
134
+ outboundHeaders["accept-encoding"] = "identity";
135
+
136
+ let bodyBuffer: Buffer | undefined;
137
+ if (body !== undefined && method !== "GET" && method !== "HEAD") {
138
+ bodyBuffer = Buffer.from(
139
+ body,
140
+ bodyEncoding === "base64" ? "base64" : "utf8",
141
+ );
142
+ }
143
+
144
+ try {
145
+ const result = await guardedFetch(targetUrl, entry, {
146
+ method,
147
+ headers: outboundHeaders,
148
+ body: bodyBuffer,
149
+ timeoutMs: TIMEOUT_MS,
150
+ maxBytes: MAX_RESPONSE_BYTES,
151
+ });
152
+
153
+ const safeHeaders: Record<string, string> = {};
154
+ let contentType: string | null = null;
155
+ for (const [key, value] of Object.entries(result.headers)) {
156
+ if (key === "content-type") contentType = value;
157
+ if (SAFE_RESPONSE_HEADERS.has(key)) safeHeaders[key] = value;
158
+ }
159
+
160
+ const isText = isTextContentType(contentType);
161
+
162
+ // Deliberately do NOT log the request/response here: the full URL (path and
163
+ // query) and headers can carry reader secrets. Only blocked/failed attempts
164
+ // are logged below via console.warn, and those record no sensitive values.
165
+ return NextResponse.json({
166
+ status: result.status,
167
+ statusText: result.statusText,
168
+ headers: safeHeaders,
169
+ contentType,
170
+ bodyEncoding: isText ? "utf8" : "base64",
171
+ body: result.body.toString(isText ? "utf8" : "base64"),
172
+ truncated: result.truncated,
173
+ byteLength: result.body.length,
174
+ durationMs: result.durationMs,
175
+ });
176
+ } catch (error) {
177
+ if (error instanceof BlockedError) {
178
+ console.warn("[playground] " + error.reason);
179
+ return NextResponse.json(
180
+ { error: "This request target is not allowed." },
181
+ { status: 403 },
182
+ );
183
+ }
184
+ const message = error instanceof Error ? error.message : "";
185
+ if (message === "timeout") {
186
+ console.warn("[playground] upstream timeout");
187
+ return NextResponse.json(
188
+ { error: "The upstream request timed out." },
189
+ { status: 504 },
190
+ );
191
+ }
192
+ console.warn("[playground] upstream request failed");
193
+ return NextResponse.json(
194
+ { error: "The upstream request failed." },
195
+ { status: 502 },
196
+ );
197
+ }
198
+ }
199
+ `;
@@ -1 +1 @@
1
- export declare const docsTemplate = "import React from \"react\";\nimport { Flex } from \"cherry-styled-components\";\nimport {\n DocsContainer,\n StyledMarkdownContainer,\n StyledMissingComponent,\n} from \"@/components/layout/DocsComponents\";\nimport { MDXRemote } from \"next-mdx-remote/rsc\";\nimport remarkGfm from \"remark-gfm\";\nimport { useMDXComponents } from \"@/components/MDXComponents\";\nimport { createMermaidPre } from \"@/components/MermaidPre\";\nimport { DocsSideBar } from \"@/components/DocsSideBar\";\nimport { ActionBar } from \"@/components/layout/ActionBar\";\nimport { createSlugger } from \"@/components/layout/Slug\";\nimport { rehypeCodeMeta } from \"@/utils/rehypeCodeMeta\";\n\ninterface DocsProps {\n content: string;\n sourcePath?: string;\n}\n\ninterface Heading {\n id: string;\n text: string;\n level: number;\n}\n\nfunction extractHeadings(content: string): Heading[] {\n const contentWithoutCodeBlocks = content.replace(/```[\\s\\S]*?```/g, \"\");\n const entries: { text: string; level: number; position: number }[] = [];\n let match;\n\n // Markdown headings (# .. ######)\n const headingRegex = /^(#{1,6})\\s+(.+)$/gm;\n while ((match = headingRegex.exec(contentWithoutCodeBlocks)) !== null) {\n const level = match[1].length;\n const text = match[2].trim();\n entries.push({ text, level, position: match.index });\n }\n\n // <Update label=\"...\"> blocks surface their label as a top-level entry\n const updateRegex = /<Update\\b[^>]*?\\blabel=[\"']([^\"']+)[\"'][^>]*>/g;\n while ((match = updateRegex.exec(contentWithoutCodeBlocks)) !== null) {\n entries.push({ text: match[1].trim(), level: 1, position: match.index });\n }\n\n // Assign ids in document order with a shared slugger so repeated heading\n // text produces unique anchors (\"setup\", \"setup-1\", ...) that stay in sync\n // with the ids rendered by MDXComponents/Update.\n const slug = createSlugger();\n return entries\n .sort((a, b) => a.position - b.position)\n .map(({ text, level }) => ({ id: slug(text), text, level }));\n}\n\nfunction extractComponentNames(source: string): string[] {\n const stripped = source\n .replace(/```[\\s\\S]*?```/g, \"\")\n .replace(/`[^`]*`/g, \"\");\n const tagRegex = /<([A-Z][a-zA-Z0-9]*)/g;\n const names = new Set<string>();\n let match;\n while ((match = tagRegex.exec(stripped)) !== null) {\n names.add(match[1]);\n }\n return Array.from(names);\n}\n\nfunction MissingComponent({\n componentName,\n children: _children,\n}: {\n componentName: string;\n children?: React.ReactNode;\n}) {\n return (\n <StyledMissingComponent>\n Missing component: &lt;{componentName} /&gt;\n </StyledMissingComponent>\n );\n}\n\nfunction Docs({ content, sourcePath }: DocsProps) {\n const headings = extractHeadings(content);\n const components = useMDXComponents({ pre: createMermaidPre(sourcePath) });\n\n const knownNames = Object.keys(components);\n const usedNames = extractComponentNames(content);\n const missingNames = usedNames.filter((name) => !knownNames.includes(name));\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const stubs: Record<string, React.ComponentType<any>> = {};\n for (const name of missingNames) {\n stubs[name] = ({ children }: { children?: React.ReactNode }) => (\n <MissingComponent componentName={name}>{children}</MissingComponent>\n );\n }\n\n const allComponents = { ...components, ...stubs };\n\n return (\n <>\n <DocsContainer>\n <ActionBar content={content}>\n <Flex $gap={20}>\n <StyledMarkdownContainer>\n {content && (\n <MDXRemote\n source={content}\n options={{\n blockJS: false,\n mdxOptions: {\n remarkPlugins: [remarkGfm],\n rehypePlugins: [rehypeCodeMeta],\n },\n }}\n components={allComponents}\n />\n )}\n </StyledMarkdownContainer>\n </Flex>\n </ActionBar>\n </DocsContainer>\n <DocsSideBar headings={headings} />\n </>\n );\n}\n\nexport { Docs };\n";
1
+ export declare const docsTemplate = "import React from \"react\";\nimport { Flex } from \"cherry-styled-components\";\nimport {\n DocsContainer,\n StyledMarkdownContainer,\n StyledMissingComponent,\n} from \"@/components/layout/DocsComponents\";\nimport { MDXRemote } from \"next-mdx-remote/rsc\";\nimport remarkGfm from \"remark-gfm\";\nimport { useMDXComponents } from \"@/components/MDXComponents\";\nimport { createMermaidPre } from \"@/components/MermaidPre\";\nimport { DocsSideBar } from \"@/components/DocsSideBar\";\nimport { ActionBar } from \"@/components/layout/ActionBar\";\nimport { ApiPlaygroundDemo } from \"@/components/layout/ApiPlaygroundDemo\";\nimport { createSlugger } from \"@/components/layout/Slug\";\nimport { rehypeCodeMeta } from \"@/utils/rehypeCodeMeta\";\n\ninterface DocsProps {\n content: string;\n sourcePath?: string;\n // Extra content rendered inside the markdown column, after the MDX body.\n // Used to place generated widgets (e.g. the API playground) inside the docs\n // content area rather than outside its layout.\n children?: React.ReactNode;\n}\n\ninterface Heading {\n id: string;\n text: string;\n level: number;\n}\n\nfunction extractHeadings(content: string): Heading[] {\n const contentWithoutCodeBlocks = content.replace(/```[\\s\\S]*?```/g, \"\");\n const entries: { text: string; level: number; position: number }[] = [];\n let match;\n\n // Markdown headings (# .. ######)\n const headingRegex = /^(#{1,6})\\s+(.+)$/gm;\n while ((match = headingRegex.exec(contentWithoutCodeBlocks)) !== null) {\n const level = match[1].length;\n const text = match[2].trim();\n entries.push({ text, level, position: match.index });\n }\n\n // <Update label=\"...\"> blocks surface their label as a top-level entry\n const updateRegex = /<Update\\b[^>]*?\\blabel=[\"']([^\"']+)[\"'][^>]*>/g;\n while ((match = updateRegex.exec(contentWithoutCodeBlocks)) !== null) {\n entries.push({ text: match[1].trim(), level: 1, position: match.index });\n }\n\n // Assign ids in document order with a shared slugger so repeated heading\n // text produces unique anchors (\"setup\", \"setup-1\", ...) that stay in sync\n // with the ids rendered by MDXComponents/Update.\n const slug = createSlugger();\n return entries\n .sort((a, b) => a.position - b.position)\n .map(({ text, level }) => ({ id: slug(text), text, level }));\n}\n\nfunction extractComponentNames(source: string): string[] {\n const stripped = source\n .replace(/```[\\s\\S]*?```/g, \"\")\n .replace(/`[^`]*`/g, \"\");\n const tagRegex = /<([A-Z][a-zA-Z0-9]*)/g;\n const names = new Set<string>();\n let match;\n while ((match = tagRegex.exec(stripped)) !== null) {\n names.add(match[1]);\n }\n return Array.from(names);\n}\n\nfunction MissingComponent({\n componentName,\n children: _children,\n}: {\n componentName: string;\n children?: React.ReactNode;\n}) {\n return (\n <StyledMissingComponent>\n Missing component: &lt;{componentName} /&gt;\n </StyledMissingComponent>\n );\n}\n\nfunction Docs({ content, sourcePath, children }: DocsProps) {\n const headings = extractHeadings(content);\n const components = useMDXComponents({\n pre: createMermaidPre(sourcePath),\n ApiPlaygroundDemo,\n });\n\n const knownNames = Object.keys(components);\n const usedNames = extractComponentNames(content);\n const missingNames = usedNames.filter((name) => !knownNames.includes(name));\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const stubs: Record<string, React.ComponentType<any>> = {};\n for (const name of missingNames) {\n stubs[name] = ({ children }: { children?: React.ReactNode }) => (\n <MissingComponent componentName={name}>{children}</MissingComponent>\n );\n }\n\n const allComponents = { ...components, ...stubs };\n\n return (\n <>\n <DocsContainer>\n <ActionBar content={content}>\n <Flex $gap={20}>\n <StyledMarkdownContainer>\n {children}\n {content && (\n <MDXRemote\n source={content}\n options={{\n blockJS: false,\n mdxOptions: {\n remarkPlugins: [remarkGfm],\n rehypePlugins: [rehypeCodeMeta],\n },\n }}\n components={allComponents}\n />\n )}\n </StyledMarkdownContainer>\n </Flex>\n </ActionBar>\n </DocsContainer>\n <DocsSideBar headings={headings} />\n </>\n );\n}\n\nexport { Docs };\n";
@@ -11,12 +11,17 @@ import { useMDXComponents } from "@/components/MDXComponents";
11
11
  import { createMermaidPre } from "@/components/MermaidPre";
12
12
  import { DocsSideBar } from "@/components/DocsSideBar";
13
13
  import { ActionBar } from "@/components/layout/ActionBar";
14
+ import { ApiPlaygroundDemo } from "@/components/layout/ApiPlaygroundDemo";
14
15
  import { createSlugger } from "@/components/layout/Slug";
15
16
  import { rehypeCodeMeta } from "@/utils/rehypeCodeMeta";
16
17
 
17
18
  interface DocsProps {
18
19
  content: string;
19
20
  sourcePath?: string;
21
+ // Extra content rendered inside the markdown column, after the MDX body.
22
+ // Used to place generated widgets (e.g. the API playground) inside the docs
23
+ // content area rather than outside its layout.
24
+ children?: React.ReactNode;
20
25
  }
21
26
 
22
27
  interface Heading {
@@ -80,9 +85,12 @@ function MissingComponent({
80
85
  );
81
86
  }
82
87
 
83
- function Docs({ content, sourcePath }: DocsProps) {
88
+ function Docs({ content, sourcePath, children }: DocsProps) {
84
89
  const headings = extractHeadings(content);
85
- const components = useMDXComponents({ pre: createMermaidPre(sourcePath) });
90
+ const components = useMDXComponents({
91
+ pre: createMermaidPre(sourcePath),
92
+ ApiPlaygroundDemo,
93
+ });
86
94
 
87
95
  const knownNames = Object.keys(components);
88
96
  const usedNames = extractComponentNames(content);
@@ -104,6 +112,7 @@ function Docs({ content, sourcePath }: DocsProps) {
104
112
  <ActionBar content={content}>
105
113
  <Flex $gap={20}>
106
114
  <StyledMarkdownContainer>
115
+ {children}
107
116
  {content && (
108
117
  <MDXRemote
109
118
  source={content}
@@ -1 +1 @@
1
- export declare const sideBarTemplate = "\"use client\";\nimport { useContext, useEffect, useRef, useState } from \"react\";\nimport { usePathname } from \"next/navigation\";\nimport { Flex, Space, ThemeToggle } from \"cherry-styled-components\";\nimport {\n DocsSidebar,\n SectionBarContext,\n StyledSidebar,\n StyledSidebarList,\n StyledSidebarListItem,\n StyledStrong,\n StyledSidebarListItemLink,\n StyledSidebarGroupButton,\n StyledSidebarGroupRow,\n StyledSidebarGroupLink,\n StyledSidebarGroupChevron,\n StyledSidebarGroupContent,\n StyledSidebarFooter,\n StyleMobileBar,\n StyledMobileBurger,\n} from \"@/components/layout/DocsComponents\";\nimport { Icon } from \"@/components/layout/Icon\";\nimport { useLockBodyScroll } from \"@/components/LockBodyScroll\";\n\n// A link can be a leaf (slug + title) or a group with nested children. Both the\n// category icon and the per-link icon are optional Lucide names.\ntype NavItemLink = {\n slug?: string;\n title: string;\n icon?: string;\n links?: NavItemLink[];\n};\n\ntype NavItem = {\n label: string;\n icon?: string;\n links: NavItemLink[];\n};\n\ninterface SideBarProps {\n result: NavItem[];\n}\n\nfunction linkContainsActivePath(link: NavItemLink, pathname: string): boolean {\n if (link.slug !== undefined && pathname === `/${link.slug}`) {\n return true;\n }\n return (link.links ?? []).some((child) =>\n linkContainsActivePath(child, pathname),\n );\n}\n\nfunction SidebarNavLink({\n link,\n depth,\n pathname,\n onNavigate,\n}: {\n link: NavItemLink;\n depth: number;\n pathname: string;\n onNavigate: () => void;\n}) {\n const children = link.links ?? [];\n const hasChildren = children.length > 0;\n const href = link.slug !== undefined ? `/${link.slug}` : undefined;\n const isActive = href !== undefined && pathname === href;\n const indent = { paddingLeft: `${20 + depth * 14}px` };\n\n // Open collapsible groups that contain the active page so deep links land\n // with their ancestors already expanded.\n const [isOpen, setIsOpen] = useState(\n hasChildren\n ? children.some((child) => linkContainsActivePath(child, pathname))\n : false,\n );\n\n if (!hasChildren) {\n return (\n <StyledSidebarListItem>\n <StyledSidebarListItemLink\n href={href ?? \"#\"}\n $isActive={isActive}\n aria-current={isActive ? \"page\" : undefined}\n onClick={onNavigate}\n style={indent}\n >\n {link.icon && <Icon name={link.icon} size={16} />}\n {link.title}\n </StyledSidebarListItemLink>\n </StyledSidebarListItem>\n );\n }\n\n const toggle = () => setIsOpen((prev) => !prev);\n const toggleLabel = isOpen\n ? `Collapse ${link.title}`\n : `Expand ${link.title}`;\n const groupActive = linkContainsActivePath(link, pathname);\n\n return (\n <li>\n {href !== undefined ? (\n <StyledSidebarGroupRow\n $isActive={groupActive}\n $isOpen={isOpen}\n style={indent}\n >\n <StyledSidebarGroupLink\n href={href}\n aria-current={pathname === href ? \"page\" : undefined}\n onClick={onNavigate}\n >\n {link.icon && <Icon name={link.icon} size={16} />}\n {link.title}\n </StyledSidebarGroupLink>\n <StyledSidebarGroupChevron\n type=\"button\"\n onClick={toggle}\n aria-expanded={isOpen}\n aria-label={toggleLabel}\n >\n <Icon name=\"chevron-right\" size={16} />\n </StyledSidebarGroupChevron>\n </StyledSidebarGroupRow>\n ) : (\n <StyledSidebarGroupButton\n type=\"button\"\n onClick={toggle}\n $isActive={groupActive}\n $isOpen={isOpen}\n style={indent}\n aria-expanded={isOpen}\n aria-label={toggleLabel}\n >\n {link.icon && <Icon name={link.icon} size={16} />}\n {link.title}\n <Icon name=\"chevron-right\" size={16} />\n </StyledSidebarGroupButton>\n )}\n <StyledSidebarGroupContent $isOpen={isOpen}>\n {children.map((child: NavItemLink, index: number) => (\n <SidebarNavLink\n key={index}\n link={child}\n depth={depth + 1}\n pathname={pathname}\n onNavigate={onNavigate}\n />\n ))}\n </StyledSidebarGroupContent>\n </li>\n );\n}\n\nfunction SideBar({ result }: SideBarProps) {\n const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);\n const hasSectionBar = useContext(SectionBarContext);\n const pathname = usePathname();\n const navRef = useRef<HTMLElement>(null);\n const footerRef = useRef<HTMLDivElement>(null);\n\n useLockBodyScroll(isMobileMenuOpen);\n\n // Bring the current page's link into view within the sidebar's own scroll\n // area when it starts off-screen (deep pages, in-content links, search).\n // Scoped to the nav via scrollTo so the main document never jumps.\n useEffect(() => {\n const nav = navRef.current;\n if (!nav) return;\n const active = nav.querySelector<HTMLElement>('[aria-current=\"page\"]');\n if (!active) return;\n\n const navRect = nav.getBoundingClientRect();\n const activeRect = active.getBoundingClientRect();\n\n // The theme-toggle footer is sticky over the bottom of the scroll area\n // (~60px tall), so links underneath it are covered rather than visible.\n // Clamp the visible bottom to the footer's top edge when it's pinned.\n const footerRect = footerRef.current?.getBoundingClientRect();\n const visibleBottom = footerRect\n ? Math.min(navRect.bottom, footerRect.top)\n : navRect.bottom;\n\n const isOutOfView =\n activeRect.top < navRect.top || activeRect.bottom > visibleBottom;\n if (!isOutOfView) return;\n\n // Center within the visible band (nav top .. footer top), not the full\n // nav height, so the link never settles behind the footer.\n const visibleHeight = visibleBottom - navRect.top;\n const target =\n nav.scrollTop +\n (activeRect.top - navRect.top) -\n (visibleHeight - active.clientHeight) / 2;\n\n // Animate the scroll, but honor users who opt out of motion.\n const prefersReducedMotion = window.matchMedia(\n \"(prefers-reduced-motion: reduce)\",\n ).matches;\n nav.scrollTo({\n top: Math.max(0, target),\n behavior: prefersReducedMotion ? \"auto\" : \"smooth\",\n });\n }, [pathname]);\n\n return (\n <DocsSidebar>\n <StyleMobileBar\n onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)}\n $isActive={isMobileMenuOpen}\n aria-label={\n isMobileMenuOpen ? \"Close navigation menu\" : \"Open navigation menu\"\n }\n aria-expanded={isMobileMenuOpen}\n >\n <StyledMobileBurger $isActive={isMobileMenuOpen} />\n </StyleMobileBar>\n\n <StyledSidebar\n ref={navRef}\n $isActive={isMobileMenuOpen}\n $hasSectionBar={hasSectionBar}\n >\n {result &&\n result.map((item: NavItem, index: number) => {\n return (\n <StyledSidebarList key={index}>\n <StyledSidebarListItem>\n <StyledStrong>\n {item.icon && <Icon name={item.icon} size={16} />}\n {item.label}\n </StyledStrong>{\" \"}\n </StyledSidebarListItem>\n <li>\n <Space $size={20} />\n </li>\n {item.links &&\n item.links.map((link: NavItemLink, indexChild: number) => (\n <SidebarNavLink\n key={indexChild}\n link={link}\n depth={0}\n pathname={pathname}\n onNavigate={() => setIsMobileMenuOpen(false)}\n />\n ))}\n <li aria-hidden=\"true\">\n <Space $size={20} />\n </li>\n </StyledSidebarList>\n );\n })}\n <StyledSidebarFooter ref={footerRef}>\n <Flex $xsJustifyContent=\"flex-start\" $lgJustifyContent=\"flex-end\">\n <ThemeToggle $shortcut />\n </Flex>\n </StyledSidebarFooter>\n </StyledSidebar>\n </DocsSidebar>\n );\n}\n\nexport { SideBar };\n";
1
+ export declare const sideBarTemplate = "\"use client\";\nimport { useContext, useEffect, useRef, useState } from \"react\";\nimport { usePathname } from \"next/navigation\";\nimport { Flex, Space, ThemeToggle } from \"cherry-styled-components\";\nimport {\n DocsSidebar,\n SectionBarContext,\n StyledSidebar,\n StyledSidebarList,\n StyledSidebarListItem,\n StyledStrong,\n StyledSidebarListItemLink,\n StyledSidebarMethodTag,\n StyledSidebarGroupButton,\n StyledSidebarGroupRow,\n StyledSidebarGroupLink,\n StyledSidebarGroupChevron,\n StyledSidebarGroupContent,\n StyledSidebarFooter,\n StyleMobileBar,\n StyledMobileBurger,\n} from \"@/components/layout/DocsComponents\";\nimport { Icon } from \"@/components/layout/Icon\";\nimport { useLockBodyScroll } from \"@/components/LockBodyScroll\";\n\n// A link can be a leaf (slug + title) or a group with nested children. Both the\n// category icon and the per-link icon are optional Lucide names.\ntype NavItemLink = {\n slug?: string;\n title: string;\n icon?: string;\n httpMethod?: string;\n links?: NavItemLink[];\n};\n\ntype NavItem = {\n label: string;\n icon?: string;\n links: NavItemLink[];\n};\n\ninterface SideBarProps {\n result: NavItem[];\n}\n\nfunction linkContainsActivePath(link: NavItemLink, pathname: string): boolean {\n if (link.slug !== undefined && pathname === `/${link.slug}`) {\n return true;\n }\n return (link.links ?? []).some((child) =>\n linkContainsActivePath(child, pathname),\n );\n}\n\nfunction SidebarNavLink({\n link,\n depth,\n pathname,\n onNavigate,\n}: {\n link: NavItemLink;\n depth: number;\n pathname: string;\n onNavigate: () => void;\n}) {\n const children = link.links ?? [];\n const hasChildren = children.length > 0;\n const href = link.slug !== undefined ? `/${link.slug}` : undefined;\n const isActive = href !== undefined && pathname === href;\n const indent = { paddingLeft: `${20 + depth * 14}px` };\n\n // Open collapsible groups that contain the active page so deep links land\n // with their ancestors already expanded.\n const [isOpen, setIsOpen] = useState(\n hasChildren\n ? children.some((child) => linkContainsActivePath(child, pathname))\n : false,\n );\n\n if (!hasChildren) {\n return (\n <StyledSidebarListItem>\n <StyledSidebarListItemLink\n href={href ?? \"#\"}\n $isActive={isActive}\n aria-current={isActive ? \"page\" : undefined}\n onClick={onNavigate}\n style={indent}\n >\n {link.httpMethod && (\n <StyledSidebarMethodTag\n $method={link.httpMethod}\n $isActive={isActive}\n >\n {link.httpMethod}\n </StyledSidebarMethodTag>\n )}\n {link.icon && <Icon name={link.icon} size={16} />}\n {link.title}\n </StyledSidebarListItemLink>\n </StyledSidebarListItem>\n );\n }\n\n const toggle = () => setIsOpen((prev) => !prev);\n const toggleLabel = isOpen\n ? `Collapse ${link.title}`\n : `Expand ${link.title}`;\n const groupActive = linkContainsActivePath(link, pathname);\n\n return (\n <li>\n {href !== undefined ? (\n <StyledSidebarGroupRow\n $isActive={groupActive}\n $isOpen={isOpen}\n style={indent}\n >\n <StyledSidebarGroupLink\n href={href}\n aria-current={pathname === href ? \"page\" : undefined}\n onClick={onNavigate}\n >\n {link.icon && <Icon name={link.icon} size={16} />}\n {link.title}\n </StyledSidebarGroupLink>\n <StyledSidebarGroupChevron\n type=\"button\"\n onClick={toggle}\n aria-expanded={isOpen}\n aria-label={toggleLabel}\n >\n <Icon name=\"chevron-right\" size={16} />\n </StyledSidebarGroupChevron>\n </StyledSidebarGroupRow>\n ) : (\n <StyledSidebarGroupButton\n type=\"button\"\n onClick={toggle}\n $isActive={groupActive}\n $isOpen={isOpen}\n style={indent}\n aria-expanded={isOpen}\n aria-label={toggleLabel}\n >\n {link.icon && <Icon name={link.icon} size={16} />}\n {link.title}\n <Icon name=\"chevron-right\" size={16} />\n </StyledSidebarGroupButton>\n )}\n <StyledSidebarGroupContent $isOpen={isOpen}>\n {children.map((child: NavItemLink, index: number) => (\n <SidebarNavLink\n key={index}\n link={child}\n depth={depth + 1}\n pathname={pathname}\n onNavigate={onNavigate}\n />\n ))}\n </StyledSidebarGroupContent>\n </li>\n );\n}\n\nfunction SideBar({ result }: SideBarProps) {\n const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);\n const hasSectionBar = useContext(SectionBarContext);\n const pathname = usePathname();\n const navRef = useRef<HTMLElement>(null);\n const footerRef = useRef<HTMLDivElement>(null);\n\n useLockBodyScroll(isMobileMenuOpen);\n\n // Bring the current page's link into view within the sidebar's own scroll\n // area when it starts off-screen (deep pages, in-content links, search).\n // Scoped to the nav via scrollTo so the main document never jumps.\n useEffect(() => {\n const nav = navRef.current;\n if (!nav) return;\n const active = nav.querySelector<HTMLElement>('[aria-current=\"page\"]');\n if (!active) return;\n\n const navRect = nav.getBoundingClientRect();\n const activeRect = active.getBoundingClientRect();\n\n // The theme-toggle footer is sticky over the bottom of the scroll area\n // (~60px tall), so links underneath it are covered rather than visible.\n // Clamp the visible bottom to the footer's top edge when it's pinned.\n const footerRect = footerRef.current?.getBoundingClientRect();\n const visibleBottom = footerRect\n ? Math.min(navRect.bottom, footerRect.top)\n : navRect.bottom;\n\n const isOutOfView =\n activeRect.top < navRect.top || activeRect.bottom > visibleBottom;\n if (!isOutOfView) return;\n\n // Center within the visible band (nav top .. footer top), not the full\n // nav height, so the link never settles behind the footer.\n const visibleHeight = visibleBottom - navRect.top;\n const target =\n nav.scrollTop +\n (activeRect.top - navRect.top) -\n (visibleHeight - active.clientHeight) / 2;\n\n // Animate the scroll, but honor users who opt out of motion.\n const prefersReducedMotion = window.matchMedia(\n \"(prefers-reduced-motion: reduce)\",\n ).matches;\n nav.scrollTo({\n top: Math.max(0, target),\n behavior: prefersReducedMotion ? \"auto\" : \"smooth\",\n });\n }, [pathname]);\n\n return (\n <DocsSidebar>\n <StyleMobileBar\n onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)}\n $isActive={isMobileMenuOpen}\n aria-label={\n isMobileMenuOpen ? \"Close navigation menu\" : \"Open navigation menu\"\n }\n aria-expanded={isMobileMenuOpen}\n >\n <StyledMobileBurger $isActive={isMobileMenuOpen} />\n </StyleMobileBar>\n\n <StyledSidebar\n ref={navRef}\n $isActive={isMobileMenuOpen}\n $hasSectionBar={hasSectionBar}\n >\n {result &&\n result.map((item: NavItem, index: number) => {\n return (\n <StyledSidebarList key={index}>\n <StyledSidebarListItem>\n <StyledStrong>\n {item.icon && <Icon name={item.icon} size={16} />}\n {item.label}\n </StyledStrong>{\" \"}\n </StyledSidebarListItem>\n <li>\n <Space $size={20} />\n </li>\n {item.links &&\n item.links.map((link: NavItemLink, indexChild: number) => (\n <SidebarNavLink\n key={indexChild}\n link={link}\n depth={0}\n pathname={pathname}\n onNavigate={() => setIsMobileMenuOpen(false)}\n />\n ))}\n <li aria-hidden=\"true\">\n <Space $size={20} />\n </li>\n </StyledSidebarList>\n );\n })}\n <StyledSidebarFooter ref={footerRef}>\n <Flex $xsJustifyContent=\"flex-start\" $lgJustifyContent=\"flex-end\">\n <ThemeToggle $shortcut />\n </Flex>\n </StyledSidebarFooter>\n </StyledSidebar>\n </DocsSidebar>\n );\n}\n\nexport { SideBar };\n";
@@ -10,6 +10,7 @@ import {
10
10
  StyledSidebarListItem,
11
11
  StyledStrong,
12
12
  StyledSidebarListItemLink,
13
+ StyledSidebarMethodTag,
13
14
  StyledSidebarGroupButton,
14
15
  StyledSidebarGroupRow,
15
16
  StyledSidebarGroupLink,
@@ -28,6 +29,7 @@ type NavItemLink = {
28
29
  slug?: string;
29
30
  title: string;
30
31
  icon?: string;
32
+ httpMethod?: string;
31
33
  links?: NavItemLink[];
32
34
  };
33
35
 
@@ -85,6 +87,14 @@ function SidebarNavLink({
85
87
  onClick={onNavigate}
86
88
  style={indent}
87
89
  >
90
+ {link.httpMethod && (
91
+ <StyledSidebarMethodTag
92
+ $method={link.httpMethod}
93
+ $isActive={isActive}
94
+ >
95
+ {link.httpMethod}
96
+ </StyledSidebarMethodTag>
97
+ )}
88
98
  {link.icon && <Icon name={link.icon} size={16} />}
89
99
  {link.title}
90
100
  </StyledSidebarListItemLink>
@@ -1 +1 @@
1
- export declare const accordionTemplate = "\"use client\";\nimport { useId, useState } from \"react\";\nimport styled, { css } from \"styled-components\";\nimport { styledText } from \"cherry-styled-components\";\nimport { Theme } from \"@/app/theme\";\nimport { Icon } from \"@/components/layout/Icon\";\n\nconst StyledAccordion = styled.div<{ theme: Theme }>`\n background: ${({ theme }) => theme.colors.light};\n border: solid 1px ${({ theme }) => theme.colors.grayLight};\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n padding: 20px;\n margin: 0;\n ${({ theme }) => styledText(theme)};\n width: 100%;\n`;\n\nconst StyledAccordionTitle = styled.button<{ theme: Theme; $isOpen: boolean }>`\n appearance: none;\n display: block;\n width: 100%;\n border: none;\n background: none;\n text-align: left;\n font: inherit;\n cursor: pointer;\n margin: 0;\n padding: 0 40px 0 0;\n ${({ theme }) => styledText(theme)};\n font-weight: 700;\n color: ${({ theme }) => theme.colors.primary};\n transition: color 0.3s ease;\n position: relative;\n\n &:hover {\n color: ${({ theme }) => theme.colors.primaryDark};\n }\n\n & .lucide-chevron-down {\n position: absolute;\n top: 50%;\n transform: translateY(-50%);\n right: 0;\n transition: transform 0.3s ease;\n\n ${({ $isOpen }) =>\n $isOpen &&\n css`\n transform: translateY(-50%) rotate(180deg);\n `}\n }\n`;\n\nconst StyledAccordionContent = styled.div<{ theme: Theme; $isOpen: boolean }>`\n ${({ theme }) => styledText(theme)};\n color: ${({ theme }) => theme.colors.grayDark};\n height: 0;\n overflow: clip;\n transition: all 0.3s ease;\n display: flex;\n flex-direction: column;\n gap: 20px;\n flex-wrap: wrap;\n flex: 1;\n\n ${({ $isOpen }) =>\n $isOpen &&\n css`\n margin: 20px 0 0;\n height: auto;\n `}\n`;\n\ninterface AccordionProps extends React.HTMLAttributes<HTMLDivElement> {\n children: React.ReactNode;\n title: string;\n}\n\nfunction Accordion({ children, title }: AccordionProps) {\n const [isOpen, setIsOpen] = useState(false);\n const contentId = useId();\n\n return (\n <StyledAccordion>\n <StyledAccordionTitle\n type=\"button\"\n onClick={() => setIsOpen(!isOpen)}\n $isOpen={isOpen}\n aria-expanded={isOpen}\n aria-controls={contentId}\n >\n {title} <Icon name=\"ChevronDown\" />\n </StyledAccordionTitle>\n <StyledAccordionContent id={contentId} role=\"region\" $isOpen={isOpen}>\n {children}\n </StyledAccordionContent>\n </StyledAccordion>\n );\n}\n\nexport { Accordion };\n";
1
+ export declare const accordionTemplate = "\"use client\";\nimport { useId, useState } from \"react\";\nimport styled, { css } from \"styled-components\";\nimport { styledText } from \"cherry-styled-components\";\nimport { Theme } from \"@/app/theme\";\nimport { Icon } from \"@/components/layout/Icon\";\n\nconst StyledAccordion = styled.div<{ theme: Theme }>`\n background: ${({ theme }) => theme.colors.light};\n border: solid 1px ${({ theme }) => theme.colors.grayLight};\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n padding: 20px;\n margin: 0;\n ${({ theme }) => styledText(theme)};\n width: 100%;\n`;\n\nconst StyledAccordionTitle = styled.button<{ theme: Theme; $isOpen: boolean }>`\n appearance: none;\n display: block;\n width: 100%;\n border: none;\n background: none;\n text-align: left;\n font: inherit;\n cursor: pointer;\n margin: 0;\n padding: 0 40px 0 0;\n ${({ theme }) => styledText(theme)};\n font-weight: 700;\n color: ${({ theme }) => theme.colors.primary};\n transition: color 0.3s ease;\n position: relative;\n\n &:hover {\n color: ${({ theme }) => theme.colors.primaryDark};\n }\n\n & .lucide-chevron-down {\n position: absolute;\n top: 50%;\n transform: translateY(-50%);\n right: 0;\n transition: transform 0.3s ease;\n\n ${({ $isOpen }) =>\n $isOpen &&\n css`\n transform: translateY(-50%) rotate(180deg);\n `}\n }\n`;\n\nconst StyledAccordionContent = styled.div<{ theme: Theme; $isOpen: boolean }>`\n ${({ theme }) => styledText(theme)};\n color: ${({ theme }) => theme.colors.grayDark};\n height: 0;\n overflow: clip;\n transition: all 0.3s ease;\n display: flex;\n flex-direction: column;\n gap: 20px;\n flex-wrap: wrap;\n flex: 1;\n\n ${({ $isOpen }) =>\n $isOpen &&\n css`\n margin: 20px 0 0;\n height: auto;\n `}\n`;\n\ninterface AccordionProps extends React.HTMLAttributes<HTMLDivElement> {\n children: React.ReactNode;\n title: string;\n defaultOpen?: boolean;\n}\n\nfunction Accordion({ children, title, defaultOpen = false }: AccordionProps) {\n const [isOpen, setIsOpen] = useState(defaultOpen);\n const contentId = useId();\n\n return (\n <StyledAccordion>\n <StyledAccordionTitle\n type=\"button\"\n onClick={() => setIsOpen(!isOpen)}\n $isOpen={isOpen}\n aria-expanded={isOpen}\n aria-controls={contentId}\n >\n {title} <Icon name=\"ChevronDown\" />\n </StyledAccordionTitle>\n <StyledAccordionContent id={contentId} role=\"region\" $isOpen={isOpen}>\n {children}\n </StyledAccordionContent>\n </StyledAccordion>\n );\n}\n\nexport { Accordion };\n";
@@ -74,10 +74,11 @@ const StyledAccordionContent = styled.div<{ theme: Theme; $isOpen: boolean }>\`
74
74
  interface AccordionProps extends React.HTMLAttributes<HTMLDivElement> {
75
75
  children: React.ReactNode;
76
76
  title: string;
77
+ defaultOpen?: boolean;
77
78
  }
78
79
 
79
- function Accordion({ children, title }: AccordionProps) {
80
- const [isOpen, setIsOpen] = useState(false);
80
+ function Accordion({ children, title, defaultOpen = false }: AccordionProps) {
81
+ const [isOpen, setIsOpen] = useState(defaultOpen);
81
82
  const contentId = useId();
82
83
 
83
84
  return (
@@ -1 +1 @@
1
- export declare const actionBarTemplate = "\"use client\";\nimport { useContext, useState } from \"react\";\nimport styled, { css } from \"styled-components\";\nimport { Icon } from \"@/components/layout/Icon\";\nimport { mq, Theme } from \"@/app/theme\";\nimport {\n interactiveStyles,\n resetButton,\n Textarea,\n} from \"cherry-styled-components\";\nimport { SectionBarContext } from \"@/components/layout/DocsComponents\";\nimport { StyledSmallButton } from \"@/components/layout/SharedStyled\";\n\ninterface ActionBarProps {\n children: React.ReactNode;\n content: string;\n}\n\nconst StyledActionBar = styled.div<{\n theme: Theme;\n $isChatOpen?: boolean;\n}>`\n border-bottom: solid 1px ${({ theme }) => theme.colors.grayLight};\n left: 0;\n padding: 12px 0;\n display: flex;\n justify-content: space-between;\n width: 100%;\n max-width: 640px;\n margin: auto;\n transition: all 0.3s ease;\n\n ${mq(\"lg\")} {\n padding: 12px 0;\n }\n`;\n\nconst StyledActionBarContent = styled.div`\n margin: auto 0;\n`;\n\nconst StyledCopyButton = styled(StyledSmallButton)<{\n theme: Theme;\n $copied: boolean;\n}>`\n border: solid 1px\n ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.grayLight};\n color: ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.primary};\n\n & svg.lucide {\n color: ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.primary};\n }\n`;\n\n// Mirrors the geometry and interaction of Cherry's ThemeToggle so the two\n// pills look identical side by side: interactiveStyles supplies the border\n// highlight + focus/active rings (no scale effect), and the space-between\n// layout with 6px padding puts each 16px icon's center exactly where the\n// 24px knob's center sits in its resting (left: 2px) and active\n// (translateX(26px)) positions.\nconst StyledToggle = styled.button<{ theme: Theme; $isActive?: boolean }>`\n ${resetButton}\n ${interactiveStyles}\n width: 56px;\n height: 30px;\n border-radius: 30px;\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 0 6px;\n position: relative;\n margin: auto 0;\n background: ${({ theme }) => theme.colors.light};\n border-color: ${({ theme }) => theme.colors.grayLight};\n\n &::after {\n content: \"\";\n position: absolute;\n top: 2px;\n left: 2px;\n width: 24px;\n height: 24px;\n border-radius: 50%;\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 20%, transparent)`};\n transition: all 0.3s ease;\n z-index: 1;\n ${({ $isActive }) =>\n !$isActive &&\n css`\n transform: translateX(26px);\n `}\n }\n\n & svg {\n width: 16px;\n height: 16px;\n object-fit: contain;\n transition: all 0.3s ease;\n position: relative;\n z-index: 2;\n }\n\n & svg[stroke] {\n stroke: ${({ theme }) => theme.colors.primary};\n }\n\n &:hover svg[stroke] {\n stroke: ${({ theme }) => theme.colors.accent};\n }\n`;\n\nconst StyledContent = styled.div<{\n theme: Theme;\n $hasSectionBar?: boolean;\n}>`\n padding-top: 20px;\n transition: all 0.3s ease;\n\n & textarea {\n max-width: 640px;\n margin: auto;\n width: 100%;\n height: 100%;\n min-height: calc(\n 100vh - ${({ $hasSectionBar }) => ($hasSectionBar ? 202 : 160)}px\n );\n\n ${mq(\"lg\")} {\n min-height: calc(100vh - 159px);\n }\n }\n`;\n\nfunction ActionBar({ children, content }: ActionBarProps) {\n const [isView, setIsView] = useState(true);\n const [copied, setCopied] = useState(false);\n const hasSectionBar = useContext(SectionBarContext);\n\n const handleCopyContent = async () => {\n try {\n await navigator.clipboard.writeText(content);\n setCopied(true);\n setTimeout(() => setCopied(false), 2000);\n } catch (err) {\n console.error(\"Failed to copy:\", err);\n }\n };\n\n return (\n <>\n <StyledActionBar>\n <StyledCopyButton onClick={handleCopyContent} $copied={copied}>\n {copied ? (\n <>\n <Icon name=\"check\" size={16} />\n Copied!\n </>\n ) : (\n <>\n <Icon name=\"copy\" size={16} />\n Copy content\n </>\n )}\n </StyledCopyButton>\n <StyledActionBarContent>\n <StyledToggle\n onClick={() => setIsView(!isView)}\n aria-label=\"Toggle View\"\n $isActive={isView}\n >\n <Icon name=\"Eye\" />\n <Icon name=\"CodeXml\" />\n </StyledToggle>\n </StyledActionBarContent>\n </StyledActionBar>\n {isView && (\n <StyledContent $hasSectionBar={hasSectionBar}>{children}</StyledContent>\n )}\n {!isView && (\n <StyledContent $hasSectionBar={hasSectionBar}>\n <Textarea defaultValue={content} $fullWidth />\n </StyledContent>\n )}\n </>\n );\n}\n\nexport { ActionBar };\n";
1
+ export declare const actionBarTemplate = "\"use client\";\nimport { useContext, useState } from \"react\";\nimport styled, { css } from \"styled-components\";\nimport { Icon } from \"@/components/layout/Icon\";\nimport { mq, Theme } from \"@/app/theme\";\nimport {\n interactiveStyles,\n resetButton,\n Textarea,\n} from \"cherry-styled-components\";\nimport { SectionBarContext } from \"@/components/layout/DocsComponents\";\nimport { StyledSmallButton } from \"@/components/layout/SharedStyled\";\n\ninterface ActionBarProps {\n children: React.ReactNode;\n content: string;\n}\n\nconst StyledActionBar = styled.div<{\n theme: Theme;\n $isChatOpen?: boolean;\n}>`\n border-bottom: solid 1px ${({ theme }) => theme.colors.grayLight};\n left: 0;\n padding: 12px 0;\n display: flex;\n justify-content: space-between;\n width: 100%;\n max-width: 640px;\n margin: auto;\n transition: all 0.3s ease;\n\n ${mq(\"lg\")} {\n padding: 12px 0;\n }\n`;\n\nconst StyledActionBarContent = styled.div`\n margin: auto 0;\n`;\n\nconst StyledCopyButton = styled(StyledSmallButton)<{\n theme: Theme;\n $copied: boolean;\n}>`\n border: solid 1px\n ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.grayLight};\n color: ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.primary};\n\n & svg.lucide {\n color: ${({ theme, $copied }) =>\n $copied ? theme.colors.success : theme.colors.primary};\n }\n`;\n\n// Mirrors the geometry and interaction of Cherry's ThemeToggle so the two\n// pills look identical side by side: interactiveStyles supplies the border\n// highlight + focus/active rings (no scale effect), and the space-between\n// layout with 6px padding puts each 16px icon's center exactly where the\n// 24px knob's center sits in its resting (left: 2px) and active\n// (translateX(26px)) positions.\nconst StyledToggle = styled.button<{ theme: Theme; $isActive?: boolean }>`\n ${resetButton}\n ${interactiveStyles}\n width: 56px;\n height: 30px;\n border-radius: 30px;\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 0 6px;\n position: relative;\n margin: auto 0;\n background: ${({ theme }) => theme.colors.light};\n border-color: ${({ theme }) => theme.colors.grayLight};\n\n &::after {\n content: \"\";\n position: absolute;\n top: 2px;\n left: 2px;\n width: 24px;\n height: 24px;\n border-radius: 50%;\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 20%, transparent)`};\n transition: all 0.3s ease;\n z-index: 1;\n ${({ $isActive }) =>\n !$isActive &&\n css`\n transform: translateX(26px);\n `}\n }\n\n & svg {\n width: 16px;\n height: 16px;\n object-fit: contain;\n transition: all 0.3s ease;\n position: relative;\n z-index: 2;\n }\n\n & svg[stroke] {\n stroke: ${({ theme }) => theme.colors.primary};\n }\n\n &:hover svg[stroke] {\n stroke: ${({ theme }) => theme.colors.accent};\n }\n`;\n\n// The raw-content view renders a full-viewport textarea. That rule is scoped to\n// the raw view (`$raw`) so it never leaks into textareas rendered inside page\n// content - e.g. the API playground's request-body editor, which sits inside\n// this same ActionBar in the normal (view) mode.\nconst StyledContent = styled.div<{\n theme: Theme;\n $hasSectionBar?: boolean;\n $raw?: boolean;\n}>`\n padding-top: 20px;\n transition: all 0.3s ease;\n\n ${({ $raw, $hasSectionBar }) =>\n $raw &&\n css`\n & textarea {\n max-width: 640px;\n margin: auto;\n width: 100%;\n height: 100%;\n min-height: calc(100vh - ${$hasSectionBar ? 202 : 160}px);\n\n ${mq(\"lg\")} {\n min-height: calc(100vh - 159px);\n }\n }\n `}\n`;\n\nfunction ActionBar({ children, content }: ActionBarProps) {\n const [isView, setIsView] = useState(true);\n const [copied, setCopied] = useState(false);\n const hasSectionBar = useContext(SectionBarContext);\n\n const handleCopyContent = async () => {\n try {\n await navigator.clipboard.writeText(content);\n setCopied(true);\n setTimeout(() => setCopied(false), 2000);\n } catch (err) {\n console.error(\"Failed to copy:\", err);\n }\n };\n\n return (\n <>\n <StyledActionBar>\n <StyledCopyButton onClick={handleCopyContent} $copied={copied}>\n {copied ? (\n <>\n <Icon name=\"check\" size={16} />\n Copied!\n </>\n ) : (\n <>\n <Icon name=\"copy\" size={16} />\n Copy content\n </>\n )}\n </StyledCopyButton>\n <StyledActionBarContent>\n <StyledToggle\n onClick={() => setIsView(!isView)}\n aria-label=\"Toggle View\"\n $isActive={isView}\n >\n <Icon name=\"Eye\" />\n <Icon name=\"CodeXml\" />\n </StyledToggle>\n </StyledActionBarContent>\n </StyledActionBar>\n {isView && (\n <StyledContent $hasSectionBar={hasSectionBar}>{children}</StyledContent>\n )}\n {!isView && (\n <StyledContent $hasSectionBar={hasSectionBar} $raw>\n <Textarea defaultValue={content} $fullWidth />\n </StyledContent>\n )}\n </>\n );\n}\n\nexport { ActionBar };\n";