@stainless-api/docs-ui 0.1.0-beta.5 → 0.1.0-beta.51

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 (212) hide show
  1. package/dist/breadcrumbs-BdYnaHA8.d.ts +20 -0
  2. package/dist/breadcrumbs-CA7GmW_8.d.ts +20 -0
  3. package/dist/breadcrumbs-nSFZO5Gf.js +63 -0
  4. package/dist/chunk-DRcLgZ1e.js +18 -0
  5. package/dist/component-DRO8kQSp.js +23 -0
  6. package/dist/component-generics-B6Fn47Mz.js +45 -0
  7. package/dist/component-generics-BHFUK06s.d.ts +30 -0
  8. package/dist/component-generics-BJSyydZ-.d.ts +30 -0
  9. package/dist/components/MaskedInput.d.ts +14 -0
  10. package/dist/components/MaskedInput.js +76 -0
  11. package/dist/components/breadcrumbs.d.ts +2 -0
  12. package/dist/components/breadcrumbs.js +9 -0
  13. package/dist/components/icons.d.ts +55 -0
  14. package/dist/components/icons.js +3 -0
  15. package/dist/components/index.d.ts +10 -0
  16. package/dist/components/index.js +18 -0
  17. package/dist/components/method.d.ts +2 -0
  18. package/dist/components/method.js +10 -0
  19. package/dist/components/overview.d.ts +2 -0
  20. package/dist/components/overview.js +11 -0
  21. package/dist/components/primitives.d.ts +2 -0
  22. package/dist/components/primitives.js +8 -0
  23. package/dist/components/properties.d.ts +2 -0
  24. package/dist/components/properties.js +9 -0
  25. package/dist/components/sdk.d.ts +2 -0
  26. package/dist/components/sdk.js +10 -0
  27. package/dist/components/sidebar.d.ts +2 -0
  28. package/dist/components/sidebar.js +11 -0
  29. package/dist/components/snippets.d.ts +3 -0
  30. package/dist/components/snippets.js +9 -0
  31. package/dist/components-D7M-BwNI.js +71 -0
  32. package/dist/contexts/component-generics.d.ts +2 -0
  33. package/dist/contexts/component-generics.js +3 -0
  34. package/dist/contexts/component-types.d.ts +16 -0
  35. package/dist/contexts/component-types.js +0 -0
  36. package/dist/contexts/component.d.ts +29 -0
  37. package/dist/contexts/component.js +27 -0
  38. package/dist/contexts/docs.d.ts +2 -0
  39. package/dist/contexts/docs.js +3 -0
  40. package/dist/contexts/index.d.ts +16 -0
  41. package/dist/contexts/index.js +7 -0
  42. package/dist/contexts/markdown.d.ts +2 -0
  43. package/dist/contexts/markdown.js +4 -0
  44. package/dist/contexts/navigation.d.ts +2 -0
  45. package/dist/contexts/navigation.js +3 -0
  46. package/dist/contexts/use-components.d.ts +14 -0
  47. package/dist/contexts/use-components.js +4 -0
  48. package/dist/contexts-p3rRZDlM.js +39 -0
  49. package/dist/csharp-CDSxfCZE.js +283 -0
  50. package/dist/docs-BUS__I1m.d.ts +47 -0
  51. package/dist/docs-CXqi26jB.js +54 -0
  52. package/dist/docs-fKyo35eI.d.ts +47 -0
  53. package/dist/go-1c3S5ETL.js +303 -0
  54. package/dist/http-2QNWXH9t.js +330 -0
  55. package/dist/icons-Ckod9aod.js +869 -0
  56. package/dist/index-5Yl-BBg3.d.ts +15 -0
  57. package/dist/index-9LRO8R1a.d.ts +274 -0
  58. package/dist/index-CBIJwoyp.d.ts +13 -0
  59. package/dist/index-ClCZKGcw.d.ts +274 -0
  60. package/dist/index-pMKpm2Jk.d.ts +13 -0
  61. package/dist/index-q3bZhNWj.d.ts +15 -0
  62. package/dist/index.d.ts +19 -0
  63. package/dist/index.js +29 -7542
  64. package/dist/java-BbjF_oUI.js +403 -0
  65. package/dist/languages/csharp.d.ts +11 -0
  66. package/dist/languages/csharp.js +9 -0
  67. package/dist/languages/go.d.ts +11 -0
  68. package/dist/languages/go.js +9 -0
  69. package/dist/languages/http.d.ts +11 -0
  70. package/dist/languages/http.js +19 -0
  71. package/dist/languages/index.d.ts +11 -0
  72. package/dist/languages/index.js +26 -0
  73. package/dist/languages/java.d.ts +11 -0
  74. package/dist/languages/java.js +9 -0
  75. package/dist/languages/python.d.ts +11 -0
  76. package/dist/languages/python.js +9 -0
  77. package/dist/languages/ruby.d.ts +11 -0
  78. package/dist/languages/ruby.js +9 -0
  79. package/dist/languages/typescript.d.ts +11 -0
  80. package/dist/languages/typescript.js +9 -0
  81. package/dist/languages-BCYZjzuS.js +26 -0
  82. package/dist/markdown/index.d.ts +12 -0
  83. package/dist/markdown/index.js +104 -0
  84. package/dist/markdown/md.d.ts +15 -0
  85. package/dist/markdown/md.js +3 -0
  86. package/dist/markdown/printer.d.ts +2 -0
  87. package/dist/markdown/printer.js +28 -0
  88. package/dist/markdown/utils.d.ts +3 -0
  89. package/dist/markdown/utils.js +3 -0
  90. package/dist/markdown-C8o8WrwG.d.ts +22 -0
  91. package/dist/markdown-CqJohZei.d.ts +22 -0
  92. package/dist/markdown-CxdeWgjV.js +48 -0
  93. package/dist/md-oM2tUaCA.js +41 -0
  94. package/dist/method-CE08mUME.js +115 -0
  95. package/dist/method-CMt6uyix.d.ts +71 -0
  96. package/dist/method-r5UAB40b.d.ts +71 -0
  97. package/dist/navigation-9_4wRkcT.d.ts +29 -0
  98. package/dist/navigation-C5TN0SgC.js +24 -0
  99. package/dist/navigation-zuoWsXzh.d.ts +29 -0
  100. package/dist/overview-DXmLmmr7.d.ts +39 -0
  101. package/dist/overview-S2hUqPXA.js +139 -0
  102. package/dist/overview-ixhAhHj8.d.ts +39 -0
  103. package/dist/primitives-BIWfwN5L.js +258 -0
  104. package/dist/primitives-BVXfSSiS.d.ts +97 -0
  105. package/dist/primitives-Bl0wzAGo.d.ts +97 -0
  106. package/dist/printer-DBw4S_Jn.d.ts +13 -0
  107. package/dist/printer-bNxiG6UB.js +74 -0
  108. package/dist/properties-C-NU_ghj.d.ts +54 -0
  109. package/dist/properties-GT9ixNTg.d.ts +54 -0
  110. package/dist/properties-jlGW3USi.js +131 -0
  111. package/dist/python-USOwFDv_.js +279 -0
  112. package/dist/routing-CMqh1cTZ.d.ts +54 -0
  113. package/dist/routing-Wbb7YECB.js +194 -0
  114. package/dist/routing.d.ts +2 -0
  115. package/dist/routing.js +3 -180
  116. package/dist/ruby-CSvGbSLe.js +387 -0
  117. package/dist/sdk-B5W3VipN.d.ts +118 -0
  118. package/dist/sdk-CS6A3HW3.d.ts +118 -0
  119. package/dist/sdk-CSCbbn3O.js +336 -0
  120. package/dist/sidebar-C3fZrgmP.d.ts +36 -0
  121. package/dist/sidebar-CWyvCrJ0.js +81 -0
  122. package/dist/sidebar-CbCLUteD.d.ts +36 -0
  123. package/dist/snippets-BQLXEIf6.js +161 -0
  124. package/dist/snippets-C72s2IwS.d.ts +51 -0
  125. package/dist/snippets-DcFph7ir.d.ts +51 -0
  126. package/dist/spec.d.ts +65 -0
  127. package/dist/spec.js +167 -0
  128. package/dist/style-D7RO5ymE.d.ts +168 -0
  129. package/dist/style-gnVEeXFj.js +169 -0
  130. package/dist/style.d.ts +2 -0
  131. package/dist/style.js +3 -0
  132. package/dist/styles/main.css +727 -754
  133. package/dist/styles/main.js +0 -0
  134. package/dist/styles/primitives.css +317 -461
  135. package/dist/styles/primitives.js +0 -0
  136. package/dist/styles/resets.css +32 -41
  137. package/dist/styles/resets.js +0 -0
  138. package/dist/styles/search.css +175 -274
  139. package/dist/styles/search.js +0 -0
  140. package/dist/styles/sidebar.css +59 -60
  141. package/dist/styles/sidebar.js +0 -0
  142. package/dist/styles/variables.css +26 -89
  143. package/dist/styles/variables.js +0 -0
  144. package/dist/styles.css +2910 -0
  145. package/dist/styles.mjs +1 -0
  146. package/dist/typescript-DXG9psK3.js +449 -0
  147. package/dist/use-components-RWQbviGq.js +7 -0
  148. package/dist/utils-CqnL9Fc3.js +31 -0
  149. package/dist/utils-DGnJ6mcU.d.ts +21 -0
  150. package/dist/utils-D_1AWSRX.js +32 -0
  151. package/dist/utils-d8paVwKN.d.ts +14 -0
  152. package/dist/utils-uQbtk0-_.d.ts +21 -0
  153. package/dist/utils.d.ts +2 -0
  154. package/dist/utils.js +3 -0
  155. package/package.json +73 -21
  156. package/dist/mcp.js +0 -16003
  157. package/dist/styles/snippets.css +0 -132
  158. package/src/components/breadcrumbs.tsx +0 -94
  159. package/src/components/chat.tsx +0 -154
  160. package/src/components/dropdown.tsx +0 -91
  161. package/src/components/icons.tsx +0 -584
  162. package/src/components/index.ts +0 -9
  163. package/src/components/method.tsx +0 -144
  164. package/src/components/overview.tsx +0 -159
  165. package/src/components/primitives.tsx +0 -284
  166. package/src/components/properties.tsx +0 -130
  167. package/src/components/scripts/dropdown.ts +0 -78
  168. package/src/components/sdk.tsx +0 -402
  169. package/src/components/sidebar.tsx +0 -99
  170. package/src/components/snippets.tsx +0 -179
  171. package/src/contexts/component-generics.tsx +0 -48
  172. package/src/contexts/component-types.tsx +0 -5
  173. package/src/contexts/component.tsx +0 -32
  174. package/src/contexts/docs.tsx +0 -75
  175. package/src/contexts/index.tsx +0 -17
  176. package/src/contexts/markdown.tsx +0 -43
  177. package/src/contexts/navigation.tsx +0 -44
  178. package/src/contexts/search.tsx +0 -28
  179. package/src/contexts/use-components.tsx +0 -4
  180. package/src/index.ts +0 -6
  181. package/src/languages/go.tsx +0 -281
  182. package/src/languages/http.tsx +0 -321
  183. package/src/languages/index.ts +0 -26
  184. package/src/languages/java.tsx +0 -358
  185. package/src/languages/python.tsx +0 -255
  186. package/src/languages/ruby.tsx +0 -320
  187. package/src/languages/typescript.tsx +0 -393
  188. package/src/markdown/index.ts +0 -107
  189. package/src/markdown/md.ts +0 -45
  190. package/src/markdown/utils.ts +0 -49
  191. package/src/routing.ts +0 -238
  192. package/src/search/form.tsx +0 -127
  193. package/src/search/index.tsx +0 -1
  194. package/src/search/indexer.ts +0 -246
  195. package/src/search/mcp.ts +0 -61
  196. package/src/search/printer.tsx +0 -86
  197. package/src/search/providers/algolia.ts +0 -88
  198. package/src/search/providers/fuse.ts +0 -19
  199. package/src/search/providers/pagefind.ts +0 -17
  200. package/src/search/providers/walker.ts +0 -30
  201. package/src/search/results.tsx +0 -181
  202. package/src/search/state.ts +0 -64
  203. package/src/search/types.ts +0 -116
  204. package/src/style.ts +0 -197
  205. package/src/styles/main.css +0 -993
  206. package/src/styles/primitives.css +0 -573
  207. package/src/styles/resets.css +0 -47
  208. package/src/styles/search.css +0 -342
  209. package/src/styles/sidebar.css +0 -87
  210. package/src/styles/snippets.css +0 -132
  211. package/src/styles/variables.css +0 -90
  212. package/src/utils.ts +0 -41
@@ -1,130 +0,0 @@
1
- import React, { type ReactNode } from 'react';
2
- import { useLanguage, useSettings } from '../contexts';
3
- import { useComponents } from '../contexts/use-components';
4
- import style from '../style';
5
- import { ArrowDownWideNarrowIcon, ArrowUpNarrowWideIcon } from 'lucide-react';
6
-
7
- export type PropertyToggleProps = {
8
- target: string;
9
- };
10
-
11
- export function PropertyToggle({ target }: PropertyToggleProps) {
12
- return (
13
- <span
14
- className={style.ExpandToggle}
15
- data-stldocs-property-toggle-expanded="false"
16
- data-stldocs-property-toggle-target={target}
17
- >
18
- <span className={style.ExpandToggleContent}>
19
- Expand <ArrowDownWideNarrowIcon className={style.Icon} size={16} />
20
- </span>
21
- <span className={style.ExpandToggleContent}>
22
- Collapse <ArrowUpNarrowWideIcon className={style.Icon} size={16} />
23
- </span>
24
- </span>
25
- );
26
- }
27
-
28
- export type PropertyDescriptionProps = {
29
- description?: string;
30
- };
31
-
32
- export function PropertyDescription({ description }: PropertyDescriptionProps) {
33
- const { Markdown } = useComponents();
34
-
35
- if (description)
36
- return (
37
- <div className={style.PropertyDescription}>
38
- <Markdown content={description} />
39
- </div>
40
- );
41
- }
42
-
43
- export type PropertyProps = {
44
- id?: string;
45
- name?: ReactNode;
46
- typeName?: ReactNode;
47
- badges?: ReactNode;
48
- type?: ReactNode;
49
- description?: string;
50
- expand?: boolean;
51
- deprecated?: boolean | string;
52
- additional?: ReactNode;
53
- declaration?: ReactNode;
54
- constraints?: ReactNode;
55
- children?: ReactNode;
56
- };
57
-
58
- export function Property({
59
- id,
60
- name,
61
- typeName,
62
- badges,
63
- type,
64
- declaration,
65
- description,
66
- deprecated,
67
- expand,
68
- additional,
69
- constraints,
70
- children,
71
- }: PropertyProps) {
72
- const Docs = useComponents();
73
- const language = useLanguage();
74
-
75
- const { collapseDescription, types } = useSettings().properties ?? {};
76
-
77
- const textContent = (
78
- <>
79
- {typeof deprecated === 'string' && <div className={style.PropertyDeprecatedMessage}>{deprecated}</div>}
80
- {description && <Docs.PropertyDescription description={description} />}
81
- {constraints && <div className={style.PropertyContent}>{constraints}</div>}
82
- </>
83
- );
84
-
85
- const rich = (
86
- <>
87
- <div className={style.PropertyDeclaration}>
88
- {deprecated && <span className={style.PropertyDeprecated}>Deprecated</span>}
89
- {declaration}
90
- {badges && <span className={style.PropertyBadges}>{badges}</span>}
91
- </div>
92
- {collapseDescription === false ? textContent : null}
93
- </>
94
- );
95
-
96
- const simple = (
97
- <>
98
- {name && (
99
- <div className={style.PropertyHeader}>
100
- {deprecated && <span className={style.PropertyDeprecated}>Deprecated</span>}
101
- {name && <span className={style.PropertyName}>{name}</span>}
102
- {typeName && <span className={style.PropertyTypeName}>{typeName}</span>}
103
- {badges && <span className={style.PropertyBadges}>{badges}</span>}
104
- </div>
105
- )}
106
- {type && <div className={style.PropertyType}>{type}</div>}
107
- {collapseDescription === false ? textContent : null}
108
- </>
109
- );
110
-
111
- const content = (
112
- <div id={id} className={style.PropertyInfo}>
113
- {types === 'simple' ? simple : rich}
114
- </div>
115
- );
116
-
117
- return (
118
- <div className={style.Property} data-stldocs-language={language}>
119
- {children || (collapseDescription !== false && description) ? (
120
- <Docs.Expander summary={content} muted={!children} open={expand}>
121
- {collapseDescription !== false ? textContent : null}
122
- {additional}
123
- {children && <div className={style.PropertyChildren}>{children}</div>}
124
- </Docs.Expander>
125
- ) : (
126
- content
127
- )}
128
- </div>
129
- );
130
- }
@@ -1,78 +0,0 @@
1
- export function initDropdown({
2
- dropdownId,
3
- onSelect,
4
- isFixed,
5
- }: {
6
- dropdownId: string;
7
- onSelect?: (value: string) => void;
8
- isFixed?: boolean;
9
- }) {
10
- const dropdown = document.getElementById(dropdownId);
11
- if (!dropdown) return;
12
-
13
- const button = dropdown.querySelector('button');
14
- const menu = dropdown.querySelector('.stldocs-dropdown-menu');
15
-
16
- if (!button || !menu) return;
17
-
18
- let isOpen = false;
19
-
20
- function toggleDropdown() {
21
- if (!button || !menu) return;
22
-
23
- isOpen = !isOpen;
24
-
25
- if (isOpen) {
26
- if (isFixed) {
27
- // Calculate position for fixed dropdown
28
- const buttonRect = button.getBoundingClientRect();
29
- (menu as HTMLElement).style.top = `${buttonRect.bottom}px`;
30
- (menu as HTMLElement).style.left = `${buttonRect.left}px`;
31
- }
32
- menu.classList.add('open');
33
- button.setAttribute('aria-expanded', 'true');
34
- } else {
35
- menu.classList.remove('open');
36
- button.setAttribute('aria-expanded', 'false');
37
- }
38
- }
39
-
40
- function closeDropdown() {
41
- if (!button || !menu) return;
42
-
43
- isOpen = false;
44
- menu.classList.remove('open');
45
- button.setAttribute('aria-expanded', 'false');
46
- }
47
-
48
- // Toggle dropdown on button click
49
- button.addEventListener('click', (e) => {
50
- toggleDropdown();
51
- });
52
-
53
- // Close dropdown when clicking outside
54
- document.addEventListener('click', (e) => {
55
- if (!dropdown.contains(e.target as Node)) {
56
- closeDropdown();
57
- }
58
- });
59
-
60
- // Close dropdown when pressing Escape
61
- document.addEventListener('keydown', (e) => {
62
- if (e.key === 'Escape' && isOpen) {
63
- closeDropdown();
64
- }
65
- });
66
-
67
- // Close dropdown when clicking on dropdown items
68
- const dropdownItems = menu.querySelectorAll('.stldocs-dropdown-item');
69
- dropdownItems.forEach((item) => {
70
- item.addEventListener('click', () => {
71
- closeDropdown();
72
- const selectedValue = item.getAttribute('data-dropdown-value');
73
- if (selectedValue && onSelect) {
74
- onSelect(selectedValue);
75
- }
76
- });
77
- });
78
- }
@@ -1,402 +0,0 @@
1
- import * as React from 'react';
2
- import type * as SDKJSON from '~/lib/json-spec-v2/types';
3
- import { useComponents } from '../contexts/use-components';
4
- import {
5
- useLanguageComponents,
6
- useDeclaration,
7
- useLanguage,
8
- useSpec,
9
- useContentPanelLayout,
10
- useSettings,
11
- useNavigation,
12
- } from '../contexts';
13
- import style from '../style';
14
- import { DocsLanguage, getLanguageSnippet } from '../routing';
15
- import { BookOpen, Copy, Github } from 'lucide-react';
16
- import clsx from 'clsx';
17
- import {
18
- GoIcon,
19
- JavaIcon,
20
- KotlinIcon,
21
- PythonIcon,
22
- RubyIcon,
23
- TerraformIcon,
24
- TypescriptIcon,
25
- CurlIcon,
26
- PowershellIcon,
27
- } from './icons';
28
- import { Button } from '@stainless-api/ui-primitives';
29
-
30
- export type PropertyModelContextType = {
31
- modelPath?: string;
32
- propertyPath?: string;
33
- };
34
-
35
- export const PropertyModelContext = React.createContext<PropertyModelContextType>(null);
36
- export function usePropertyModel() {
37
- return React.useContext(PropertyModelContext);
38
- }
39
-
40
- export type ReferenceNestingContextType = string[];
41
- export const ReferenceNestingContext = React.createContext<ReferenceNestingContextType>([]);
42
- export function useReferenceNesting() {
43
- return React.useContext(ReferenceNestingContext);
44
- }
45
-
46
- export type SDKSnippetLanguagesType = Record<SDKJSON.SnippetLanguage, { name: string; icon: string }>;
47
-
48
- export const SDKSnippetLanguages: SDKSnippetLanguagesType = {
49
- 'node.default': { name: 'TypeScript', icon: 'typescript' },
50
- 'typescript.default': { name: 'TypeScript', icon: 'typescript' },
51
- 'python.default': { name: 'Python', icon: 'python' },
52
- 'go.default': { name: 'Go', icon: 'go' },
53
- 'java.default': { name: 'Java', icon: 'java' },
54
- 'kotlin.default': { name: 'Kotlin', icon: 'kotlin' },
55
- 'http.curl': { name: 'cURL', icon: 'http' },
56
- 'http.powershell': { name: 'Powershell', icon: 'powershell' },
57
- 'terraform.default': { name: 'Terraform', icon: 'terraform' },
58
- 'ruby.default': { name: 'Ruby', icon: 'ruby' },
59
- };
60
-
61
- export type TransformRequestSnippetFn = ({
62
- snippet,
63
- language,
64
- }: {
65
- snippet: string;
66
- language: DocsLanguage;
67
- }) => string;
68
-
69
- type SDKChildrenProps = {
70
- paths: SDKJSON.ID[];
71
- expand?: boolean;
72
- depth?: number;
73
- };
74
-
75
- export function SDKChildren({ paths, expand, depth }: SDKChildrenProps) {
76
- const Docs = useComponents();
77
-
78
- return (
79
- <div className={style.Properties}>
80
- {paths.map((path, i) => (
81
- <Docs.SDKDeclaration path={path} key={i} expand={expand} depth={depth} />
82
- ))}
83
- </div>
84
- );
85
- }
86
-
87
- type SDKDeclarationProps = {
88
- path: string;
89
- expand?: boolean;
90
- depth?: number;
91
- };
92
-
93
- export function SDKDeclaration({ path, expand, depth = 0 }: SDKDeclarationProps) {
94
- const Lang = useLanguageComponents();
95
- const Docs = useComponents();
96
- const decl = useDeclaration(path);
97
- const settings = useSettings();
98
- const model = usePropertyModel();
99
- const nesting = useReferenceNesting();
100
- const { selectedPath } = useNavigation();
101
-
102
- if (!decl) return null;
103
-
104
- if (decl.kind.endsWith('Reference')) {
105
- const refId = decl['type']['$ref'];
106
- if (refId && refId !== path && !nesting.includes(refId)) {
107
- return (
108
- <ReferenceNestingContext.Provider value={[...nesting, refId]}>
109
- <SDKDeclaration path={refId} expand={expand} depth={depth} />
110
- </ReferenceNestingContext.Provider>
111
- );
112
- }
113
- }
114
-
115
- const isUnion = 'childrenParentSchema' in decl && ['enum', 'union'].includes(decl.childrenParentSchema);
116
- const id = model?.propertyPath ? `${model.propertyPath} + ${path}` : path;
117
- const shouldExpand =
118
- (selectedPath.startsWith(path) && nesting.length < 1) ||
119
- (settings.properties?.expandDepth && depth <= settings.properties?.expandDepth && !isUnion) ||
120
- expand;
121
-
122
- const content = (
123
- <Lang.Property decl={decl}>
124
- {({ ...props }) => (
125
- <Docs.Property
126
- id={id}
127
- expand={shouldExpand}
128
- constraints={decl['constraints'] && <Docs.SDKConstraints constraints={decl['constraints']} />}
129
- declaration={<Lang.Declaration decl={decl} />}
130
- description={decl['docstring']}
131
- deprecated={decl.deprecated}
132
- {...props}
133
- >
134
- {'children' in decl &&
135
- decl.children.length > 0 &&
136
- (settings.properties?.includeModelProperties !== false || !('modelPath' in decl)) && (
137
- <>
138
- {isUnion && <div className={style.PropertyAnnotation}>Accepts one of the following:</div>}
139
- <Docs.SDKChildren paths={decl.children} depth={depth + 1} />
140
- </>
141
- )}
142
- </Docs.Property>
143
- )}
144
- </Lang.Property>
145
- );
146
-
147
- if ('modelPath' in decl) {
148
- const value = { modelPath: decl.modelPath, propertyPath: decl.stainlessPath };
149
- return <PropertyModelContext.Provider value={value}>{content}</PropertyModelContext.Provider>;
150
- }
151
-
152
- return content;
153
- }
154
-
155
- export type SDKConstraintsProps = {
156
- constraints?: Record<string, any>;
157
- };
158
-
159
- export function SDKConstraints({ constraints }: SDKConstraintsProps) {
160
- if (constraints)
161
- return (
162
- <div className={style.PropertyConstraints}>
163
- {Object.entries(constraints).map(([name, value]) => (
164
- <div className={style.PropertyConstraint} key={name}>
165
- <span className={style.PropertyConstraintName}>{name}</span>
166
- <span className={style.PropertyConstraintValue}>{value}</span>
167
- </div>
168
- ))}
169
- </div>
170
- );
171
- }
172
-
173
- type SDKIconProps = {
174
- language: SDKJSON.SnippetLanguage;
175
- size?: number;
176
- };
177
-
178
- const snippetIcons: Record<
179
- SDKJSON.SnippetLanguage,
180
- ({ className }: { className?: string }) => React.JSX.Element
181
- > = {
182
- 'node.default': TypescriptIcon,
183
- 'typescript.default': TypescriptIcon,
184
- 'go.default': GoIcon,
185
- 'python.default': PythonIcon,
186
- 'terraform.default': TerraformIcon,
187
- 'http.curl': CurlIcon,
188
- 'http.powershell': PowershellIcon,
189
- 'ruby.default': RubyIcon,
190
- 'java.default': JavaIcon,
191
- 'kotlin.default': KotlinIcon,
192
- };
193
-
194
- export function SDKIcon({ language }: SDKIconProps) {
195
- const LangIcon = snippetIcons[language];
196
- if (!LangIcon) return null;
197
- return <LangIcon className={clsx(style.Icon, language.split('.').shift())} />;
198
- }
199
-
200
- export type SDKRequestTitleProps = {
201
- snippetLanguage: SDKJSON.SnippetLanguage;
202
- };
203
-
204
- export function SDKRequestTitle({ snippetLanguage }: SDKRequestTitleProps) {
205
- const languageName = SDKSnippetLanguages[snippetLanguage]?.name;
206
-
207
- return (
208
- <span className={style.SnippetRequestTitleLanguage}>
209
- <SDKIcon language={snippetLanguage} /> {languageName}
210
- </span>
211
- );
212
- }
213
-
214
- type SDKExampleProps = {
215
- method: SDKJSON.Method;
216
- transformRequestSnippet?: TransformRequestSnippetFn;
217
- };
218
-
219
- export function SDKExample({ method, transformRequestSnippet }: SDKExampleProps) {
220
- // TODO: support language variants in snippets
221
- const Docs = useComponents();
222
- const language = useLanguage();
223
- const snippetLanguage = getLanguageSnippet(language);
224
-
225
- return (
226
- <Docs.Snippet
227
- requestTitle={<Docs.SDKRequestTitle snippetLanguage={snippetLanguage} />}
228
- method={method}
229
- transformRequestSnippet={transformRequestSnippet}
230
- />
231
- );
232
- }
233
-
234
- export type SDKMethodProps = {
235
- method: SDKJSON.Method;
236
- transformRequestSnippet?: TransformRequestSnippetFn;
237
- };
238
-
239
- export function SDKMethodHeader({ method }: SDKMethodProps) {
240
- const Docs = useComponents();
241
- const Lang = useLanguageComponents();
242
- const decl = useDeclaration(method.stainlessPath);
243
-
244
- return (
245
- <Docs.MethodHeader
246
- title={method.summary ?? method.title}
247
- signature={<Lang.MethodSignature decl={decl} />}
248
- badges={method.deprecated && <Docs.Badge id="deprecated">Deprecated</Docs.Badge>}
249
- >
250
- <Docs.MethodRoute httpMethod={method.httpMethod} endpoint={method.endpoint.split(' ', 2).at(-1)} />
251
- </Docs.MethodHeader>
252
- );
253
- }
254
-
255
- export function SDKMethodInfo({ method }: SDKMethodProps) {
256
- const Docs = useComponents();
257
- const Lang = useLanguageComponents();
258
- const decl = useDeclaration(method.stainlessPath);
259
- const spec = useSpec();
260
- const language = useLanguage();
261
-
262
- if (Lang.MethodInfo) return <Lang.MethodInfo decl={decl} />;
263
-
264
- function shouldExpand(items: SDKJSON.ID[]) {
265
- if (items.length > 1) return false;
266
- const decl = spec?.decls?.[language]?.[items[0]];
267
- return decl && 'children' in decl && decl.children.length > 0;
268
- }
269
-
270
- return (
271
- <Docs.MethodInfo
272
- parameters={
273
- 'paramsChildren' in decl &&
274
- Array.isArray(decl.paramsChildren) &&
275
- decl.paramsChildren.length > 0 && (
276
- <Docs.SDKChildren expand={shouldExpand(decl.paramsChildren)} paths={decl.paramsChildren} />
277
- )
278
- }
279
- returns={
280
- 'responseChildren' in decl &&
281
- decl.responseChildren.length > 0 && (
282
- <Docs.SDKChildren expand={shouldExpand(decl.responseChildren)} paths={decl.responseChildren} />
283
- )
284
- }
285
- />
286
- );
287
- }
288
-
289
- export function SDKMethod({ method, transformRequestSnippet }: SDKMethodProps) {
290
- const Docs = useComponents();
291
- const decl = useDeclaration(method?.stainlessPath);
292
- const layout = useContentPanelLayout();
293
-
294
- if (!decl) return;
295
-
296
- return (
297
- <Docs.Method
298
- id={method.stainlessPath}
299
- header={<Docs.SDKMethodHeader method={method} />}
300
- className={clsx({
301
- [style.MethodSinglePane]: layout === 'single-pane',
302
- [style.MethodDoublePane]: layout === 'double-pane',
303
- })}
304
- >
305
- <div className={style.MethodContentColumn}>
306
- <Docs.MethodDescription description={method.description} />
307
- <Docs.SDKMethodInfo method={method} />
308
- </div>
309
- <div className={style.MethodExample + ' not-content'}>
310
- <Docs.SDKExample method={method} transformRequestSnippet={transformRequestSnippet} />
311
- </div>
312
- <div className={style.MethodResponseColumn}>
313
- <h5>Returns Examples</h5>
314
- <Docs.SnippetResponse responses={method.exampleResponses} />
315
- </div>
316
- </Docs.Method>
317
- );
318
- }
319
-
320
- export type SDKModelProps = {
321
- model: SDKJSON.Model;
322
- };
323
-
324
- export function SDKModel({ model }: SDKModelProps) {
325
- const Docs = useComponents();
326
- const decl = useDeclaration(`${model.stainlessPath} > (schema)`);
327
-
328
- if (!decl) return null;
329
-
330
- return (
331
- <div className={style.Model} tabIndex={0}>
332
- <div className={style.ResourceContentProperties}>
333
- <Docs.SDKDeclaration path={`${model.stainlessPath} > (schema)`} />
334
- </div>
335
- </div>
336
- );
337
- }
338
-
339
- type SDKReferenceProps = {
340
- stainlessPath: string;
341
- children?: React.ReactNode;
342
- };
343
-
344
- export function SDKReference({ stainlessPath, children }: SDKReferenceProps) {
345
- const Docs = useComponents();
346
-
347
- if (!stainlessPath || !stainlessPath.endsWith('(schema)')) return children;
348
-
349
- const link = (
350
- <span className={style.TypeReference}>
351
- <Docs.Link stainlessPath={stainlessPath}>{children}</Docs.Link>
352
- </span>
353
- );
354
-
355
- return link;
356
- }
357
-
358
- type SDKLanguageBlockProps = {
359
- language: DocsLanguage;
360
- version: string;
361
- install: string;
362
- links: {
363
- repo: string;
364
- docs: string;
365
- };
366
- };
367
-
368
- export function SDKLanguageBlock({ language, version, install, links }: SDKLanguageBlockProps) {
369
- const Docs = useComponents();
370
- const lang = `${language}.default` as SDKJSON.SnippetLanguage;
371
-
372
- return (
373
- <div className={style.LanguageBlock}>
374
- <div className={style.LanguageBlockContent}>
375
- <div className={style.LanguageBlockContentIcon}>
376
- <Docs.SDKIcon language={lang} size={24} />
377
- </div>
378
- <div className={style.LanguageBlockContentInfo}>
379
- <div className={style.LanguageBlockContentInfoLanguage}>{Docs.SDKSnippetLanguages[lang].name}</div>
380
- <div className={style.LanguageBlockContentInfoVersion}>{version}</div>
381
- </div>
382
- </div>
383
-
384
- <div className={style.LanguageBlockInstall} data-stldocs-copy-parent>
385
- <pre data-stldocs-copy-content>{install}</pre>{' '}
386
- <button data-stldocs-snippet-copy>
387
- <Copy size={16} className={style.Icon} />
388
- </button>
389
- </div>
390
-
391
- <div className={style.LanguageBlockLinks}>
392
- <Button href={links.repo} variant="outline">
393
- <Button.Icon icon={Github} />
394
- </Button>
395
- <Button href={links.docs} variant="outline">
396
- <Button.Icon icon={BookOpen} />
397
- <Button.Label>Read Docs</Button.Label>
398
- </Button>
399
- </div>
400
- </div>
401
- );
402
- }
@@ -1,99 +0,0 @@
1
- import * as React from 'react';
2
- import type * as SDKJSON from '~/lib/json-spec-v2/types';
3
- import { useNavigation } from '../contexts';
4
- import { useComponents } from '../contexts/use-components';
5
- import { ChevronDown, ChevronRight } from 'lucide-react';
6
- import style from '../style';
7
- import { MethodIconBadge } from './method';
8
- import { isResourceEmpty } from '../utils';
9
-
10
- type SidebarExpanderProps = {
11
- open?: boolean;
12
- summary: React.ReactNode;
13
- children?: React.ReactNode;
14
- };
15
-
16
- export function SidebarExpander({ open, summary, children }: SidebarExpanderProps) {
17
- return (
18
- <details className={style.SidebarExpander} open={open}>
19
- <summary className={style.ExpanderSummary}>
20
- <div className={style.ExpanderSummaryContent}>{summary}</div>
21
- <div className={style.ExpanderSummaryIcon}>
22
- <ChevronRight size={16} strokeWidth={1} className={style.Icon} />
23
- <ChevronDown size={16} strokeWidth={1} className={style.Icon} />
24
- </div>
25
- </summary>
26
- <div className={style.ExpanderContent}>{children}</div>
27
- </details>
28
- );
29
- }
30
-
31
- export type SidebarMethodProps = {
32
- method: SDKJSON.Method;
33
- };
34
-
35
- export function SidebarMethod({ method }: SidebarMethodProps) {
36
- const Docs = useComponents();
37
- const { selectedPath } = useNavigation();
38
-
39
- return (
40
- <div className={style.SidebarMethod} data-selected={method.stainlessPath === selectedPath}>
41
- <MethodIconBadge httpMethod={method.httpMethod} />
42
- <Docs.Link stainlessPath={method.stainlessPath}>{method.summary}</Docs.Link>
43
- </div>
44
- );
45
- }
46
-
47
- export type SidebarResourceProps = {
48
- resource: SDKJSON.Resource;
49
- };
50
-
51
- export function SidebarResource({ resource }: SidebarResourceProps) {
52
- const Docs = useComponents();
53
- const { selectedPath, navigationPath } = useNavigation();
54
- const subresources = Object.values(resource.subresources).map((sub) => (
55
- <SidebarResource resource={sub} key={sub.stainlessPath} />
56
- ));
57
-
58
- const methods = Object.values(resource.methods).map((method) => (
59
- <SidebarMethod method={method} key={method.stainlessPath} />
60
- ));
61
-
62
- const hasChildren = subresources.length > 0 || methods.length > 0;
63
-
64
- const title = (
65
- <div className={style.SidebarResourceTitle}>
66
- <Docs.Link stainlessPath={resource.stainlessPath}>{resource.title}</Docs.Link>
67
- </div>
68
- );
69
-
70
- return (
71
- <div className={style.SidebarResource} data-selected={resource.stainlessPath === selectedPath}>
72
- {hasChildren ? (
73
- <SidebarExpander summary={title} open={true}>
74
- {methods}
75
- {subresources}
76
- </SidebarExpander>
77
- ) : (
78
- title
79
- )}
80
- </div>
81
- );
82
- }
83
-
84
- export type SidebarProps = {
85
- resources: SDKJSON.Resource[];
86
- selectedPath?: string;
87
- };
88
-
89
- export function Sidebar({ resources }: SidebarProps) {
90
- return (
91
- <div className={`${style.Root} ${style.Sidebar}`}>
92
- {resources
93
- .filter((resource) => !isResourceEmpty(resource))
94
- .map((resource) => (
95
- <SidebarResource resource={resource} key={resource.stainlessPath} />
96
- ))}
97
- </div>
98
- );
99
- }