@stainless-api/docs-ui 0.1.0-beta.6 → 0.1.0-beta.61

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 (206) hide show
  1. package/dist/breadcrumbs-BVskoBYz.d.ts +25 -0
  2. package/dist/breadcrumbs-C9LLJyuJ.d.ts +25 -0
  3. package/dist/breadcrumbs-CqA6kow2.js +63 -0
  4. package/dist/chunk-BN_g-Awi.js +18 -0
  5. package/dist/cli-0bJ66S1r.js +157 -0
  6. package/dist/component-CjJJYIxG.js +23 -0
  7. package/dist/component-generics-BC_P155r.d.ts +30 -0
  8. package/dist/component-generics-BkwbbxJF.d.ts +30 -0
  9. package/dist/component-generics-POFirVVb.js +45 -0
  10. package/dist/components/MaskedInput.d.ts +14 -0
  11. package/dist/components/MaskedInput.js +76 -0
  12. package/dist/components/breadcrumbs.d.ts +2 -0
  13. package/dist/components/breadcrumbs.js +9 -0
  14. package/dist/components/icons.d.ts +60 -0
  15. package/dist/components/icons.js +3 -0
  16. package/dist/components/index.d.ts +10 -0
  17. package/dist/components/index.js +18 -0
  18. package/dist/components/method.d.ts +2 -0
  19. package/dist/components/method.js +10 -0
  20. package/dist/components/overview.d.ts +2 -0
  21. package/dist/components/overview.js +11 -0
  22. package/dist/components/primitives.d.ts +2 -0
  23. package/dist/components/primitives.js +8 -0
  24. package/dist/components/properties.d.ts +2 -0
  25. package/dist/components/properties.js +9 -0
  26. package/dist/components/sdk.d.ts +2 -0
  27. package/dist/components/sdk.js +10 -0
  28. package/dist/components/sidebar.d.ts +2 -0
  29. package/dist/components/sidebar.js +9 -0
  30. package/dist/components/snippets.d.ts +3 -0
  31. package/dist/components/snippets.js +9 -0
  32. package/dist/components-FEHnQBJC.js +70 -0
  33. package/dist/contexts/component-generics.d.ts +2 -0
  34. package/dist/contexts/component-generics.js +3 -0
  35. package/dist/contexts/component-types.d.ts +16 -0
  36. package/dist/contexts/component-types.js +0 -0
  37. package/dist/contexts/component.d.ts +29 -0
  38. package/dist/contexts/component.js +28 -0
  39. package/dist/contexts/docs.d.ts +2 -0
  40. package/dist/contexts/docs.js +3 -0
  41. package/dist/contexts/index.d.ts +22 -0
  42. package/dist/contexts/index.js +7 -0
  43. package/dist/contexts/markdown.d.ts +2 -0
  44. package/dist/contexts/markdown.js +4 -0
  45. package/dist/contexts/navigation.d.ts +2 -0
  46. package/dist/contexts/navigation.js +3 -0
  47. package/dist/contexts/use-components.d.ts +14 -0
  48. package/dist/contexts/use-components.js +4 -0
  49. package/dist/contexts-CeV_L_Iy.js +39 -0
  50. package/dist/csharp-Dl2RIiYP.js +283 -0
  51. package/dist/docs--qWFuJCM.d.ts +46 -0
  52. package/dist/docs-DSFRsmbQ.d.ts +46 -0
  53. package/dist/docs-Di94viZV.js +54 -0
  54. package/dist/go-DuKdRGqU.js +303 -0
  55. package/dist/http-C7bu4oCl.js +331 -0
  56. package/dist/icons-BYKn5X8E.js +885 -0
  57. package/dist/index-C0qvL4yP.d.ts +15 -0
  58. package/dist/index-DE1vA8T2.d.ts +302 -0
  59. package/dist/index-DsFyACw9.d.ts +15 -0
  60. package/dist/index-FDM-j9s-.d.ts +302 -0
  61. package/dist/index-zNpvNvtN.d.ts +1691 -0
  62. package/dist/index.d.ts +19 -0
  63. package/dist/index.js +30 -7542
  64. package/dist/java-DSyzO-6F.js +403 -0
  65. package/dist/languages/cli.d.ts +11 -0
  66. package/dist/languages/cli.js +20 -0
  67. package/dist/languages/csharp.d.ts +11 -0
  68. package/dist/languages/csharp.js +9 -0
  69. package/dist/languages/go.d.ts +11 -0
  70. package/dist/languages/go.js +9 -0
  71. package/dist/languages/http.d.ts +11 -0
  72. package/dist/languages/http.js +19 -0
  73. package/dist/languages/index.d.ts +11 -0
  74. package/dist/languages/index.js +27 -0
  75. package/dist/languages/java.d.ts +11 -0
  76. package/dist/languages/java.js +9 -0
  77. package/dist/languages/python.d.ts +11 -0
  78. package/dist/languages/python.js +9 -0
  79. package/dist/languages/ruby.d.ts +11 -0
  80. package/dist/languages/ruby.js +9 -0
  81. package/dist/languages/typescript.d.ts +11 -0
  82. package/dist/languages/typescript.js +9 -0
  83. package/dist/languages-BO5YJ6cy.js +28 -0
  84. package/dist/markdown/index.d.ts +12 -0
  85. package/dist/markdown/index.js +105 -0
  86. package/dist/markdown/md.d.ts +15 -0
  87. package/dist/markdown/md.js +41 -0
  88. package/dist/markdown/printer.d.ts +13 -0
  89. package/dist/markdown/printer.js +98 -0
  90. package/dist/markdown/utils.d.ts +21 -0
  91. package/dist/markdown/utils.js +31 -0
  92. package/dist/markdown-B517MrZh.d.ts +22 -0
  93. package/dist/markdown-C7Tb41LZ.d.ts +22 -0
  94. package/dist/markdown-D2JWyRws.js +49 -0
  95. package/dist/method-BaQEZVlw.d.ts +59 -0
  96. package/dist/method-Dln4ZTIB.d.ts +59 -0
  97. package/dist/method-jTnA0G8m.js +90 -0
  98. package/dist/navigation-XhIgqXwM.d.ts +29 -0
  99. package/dist/navigation-aoYZ_tl4.js +24 -0
  100. package/dist/navigation-rKdts-BR.d.ts +29 -0
  101. package/dist/overview-B3kgyac2.d.ts +39 -0
  102. package/dist/overview-BnagZfH1.js +139 -0
  103. package/dist/overview-Dp-gGl3v.d.ts +39 -0
  104. package/dist/primitives-B6zu2rrx.d.ts +105 -0
  105. package/dist/primitives-DQLc9kN7.js +250 -0
  106. package/dist/primitives-VtUGoYwX.d.ts +105 -0
  107. package/dist/properties-Bun4nfUE.d.ts +54 -0
  108. package/dist/properties-DGL2J11L.js +131 -0
  109. package/dist/properties-ZOIqpkET.d.ts +54 -0
  110. package/dist/python-D8ABqtn1.js +269 -0
  111. package/dist/routing-Ce0_tBW6.js +197 -0
  112. package/dist/routing-CtbZJru_.d.ts +54 -0
  113. package/dist/routing.d.ts +2 -0
  114. package/dist/routing.js +3 -180
  115. package/dist/ruby-261jvCjl.js +387 -0
  116. package/dist/sdk-BebFnWYL.d.ts +118 -0
  117. package/dist/sdk-CIxaNoAs.d.ts +118 -0
  118. package/dist/sdk-GGpyGTao.js +338 -0
  119. package/dist/sidebar-BWno0E4w.js +85 -0
  120. package/dist/sidebar-CLsIJZZf.d.ts +36 -0
  121. package/dist/sidebar-D4m_pVpS.d.ts +36 -0
  122. package/dist/snippets-CwVjwsAo.d.ts +53 -0
  123. package/dist/snippets-Ym3mnHO3.d.ts +53 -0
  124. package/dist/snippets-kI8eNs1F.js +164 -0
  125. package/dist/spec.d.ts +65 -0
  126. package/dist/spec.js +167 -0
  127. package/dist/style-LwfvXElj.js +170 -0
  128. package/dist/style.d.ts +169 -0
  129. package/dist/style.js +3 -0
  130. package/dist/styles/main.css +722 -755
  131. package/dist/styles/main.js +0 -0
  132. package/dist/styles/primitives.css +322 -459
  133. package/dist/styles/primitives.js +0 -0
  134. package/dist/styles/resets.css +32 -41
  135. package/dist/styles/resets.js +0 -0
  136. package/dist/styles/search.css +192 -270
  137. package/dist/styles/search.js +0 -0
  138. package/dist/styles/sidebar.css +56 -61
  139. package/dist/styles/sidebar.js +0 -0
  140. package/dist/styles/variables.css +26 -89
  141. package/dist/styles/variables.js +0 -0
  142. package/dist/styles.css +3145 -0
  143. package/dist/styles.mjs +1 -0
  144. package/dist/typescript-D924WidI.js +449 -0
  145. package/dist/use-components-BUz3GbO4.js +7 -0
  146. package/dist/utils-D01mAUfQ.js +32 -0
  147. package/dist/utils.d.ts +14 -0
  148. package/dist/utils.js +3 -0
  149. package/package.json +73 -21
  150. package/dist/mcp.js +0 -16003
  151. package/dist/styles/snippets.css +0 -132
  152. package/src/components/breadcrumbs.tsx +0 -94
  153. package/src/components/chat.tsx +0 -154
  154. package/src/components/dropdown.tsx +0 -91
  155. package/src/components/icons.tsx +0 -584
  156. package/src/components/index.ts +0 -9
  157. package/src/components/method.tsx +0 -144
  158. package/src/components/overview.tsx +0 -159
  159. package/src/components/primitives.tsx +0 -284
  160. package/src/components/properties.tsx +0 -130
  161. package/src/components/scripts/dropdown.ts +0 -78
  162. package/src/components/sdk.tsx +0 -402
  163. package/src/components/sidebar.tsx +0 -99
  164. package/src/components/snippets.tsx +0 -179
  165. package/src/contexts/component-generics.tsx +0 -48
  166. package/src/contexts/component-types.tsx +0 -5
  167. package/src/contexts/component.tsx +0 -32
  168. package/src/contexts/docs.tsx +0 -75
  169. package/src/contexts/index.tsx +0 -17
  170. package/src/contexts/markdown.tsx +0 -43
  171. package/src/contexts/navigation.tsx +0 -44
  172. package/src/contexts/search.tsx +0 -28
  173. package/src/contexts/use-components.tsx +0 -4
  174. package/src/index.ts +0 -6
  175. package/src/languages/go.tsx +0 -281
  176. package/src/languages/http.tsx +0 -321
  177. package/src/languages/index.ts +0 -26
  178. package/src/languages/java.tsx +0 -358
  179. package/src/languages/python.tsx +0 -255
  180. package/src/languages/ruby.tsx +0 -320
  181. package/src/languages/typescript.tsx +0 -393
  182. package/src/markdown/index.ts +0 -107
  183. package/src/markdown/md.ts +0 -45
  184. package/src/markdown/utils.ts +0 -49
  185. package/src/routing.ts +0 -238
  186. package/src/search/form.tsx +0 -127
  187. package/src/search/index.tsx +0 -1
  188. package/src/search/indexer.ts +0 -246
  189. package/src/search/mcp.ts +0 -61
  190. package/src/search/printer.tsx +0 -86
  191. package/src/search/providers/algolia.ts +0 -88
  192. package/src/search/providers/fuse.ts +0 -19
  193. package/src/search/providers/pagefind.ts +0 -17
  194. package/src/search/providers/walker.ts +0 -30
  195. package/src/search/results.tsx +0 -181
  196. package/src/search/state.ts +0 -64
  197. package/src/search/types.ts +0 -116
  198. package/src/style.ts +0 -197
  199. package/src/styles/main.css +0 -993
  200. package/src/styles/primitives.css +0 -573
  201. package/src/styles/resets.css +0 -47
  202. package/src/styles/search.css +0 -342
  203. package/src/styles/sidebar.css +0 -87
  204. package/src/styles/snippets.css +0 -132
  205. package/src/styles/variables.css +0 -90
  206. package/src/utils.ts +0 -41
@@ -1,358 +0,0 @@
1
- import * as React from 'react';
2
- import type * as AST from '~/lib/json-spec-v2/JavaAST';
3
-
4
- import { useLanguage, useLanguageComponents } from '../contexts';
5
- import { useComponents } from '../contexts/use-components';
6
- import style from '../style';
7
- import { PropertyFn } from '.';
8
-
9
- function showFullType(type: AST.JavaType) {
10
- return (
11
- type.kind === 'JavaTypeReference' &&
12
- (type.typeName === 'List' || (type.typeParameters && type.typeParameters.length > 0))
13
- );
14
- }
15
-
16
- const constStyle = {
17
- string: style.LiteralString,
18
- number: style.LiteralNumeric,
19
- boolean: style.LiteralBoolean,
20
- };
21
-
22
- type TypeProps = {
23
- type: AST.JavaType;
24
- optional?: boolean;
25
- };
26
-
27
- export function TypeName({ type, optional }: TypeProps) {
28
- const Lang = useLanguageComponents();
29
-
30
- if (type.kind === 'JavaTypeReference' && type.typeName === 'List') return 'List';
31
-
32
- return <Lang.Type type={type} optional={optional} />;
33
- }
34
-
35
- export function Type({ type, optional }: TypeProps) {
36
- const language = useLanguage();
37
- const Lang = useLanguageComponents();
38
- const { Join, SDKReference } = useComponents();
39
-
40
- switch (type.kind) {
41
- case 'JavaTypeReference': {
42
- const name = type.typeName.split('.').at(-1);
43
- const params = type.typeParameters?.map((param, key) => (
44
- <Lang.Type key={key} type={param} optional={optional} />
45
- ));
46
-
47
- return (
48
- <span className={style.Type}>
49
- <SDKReference stainlessPath={type.$ref}>{name}</SDKReference>
50
- {params && params.length > 0 ? (
51
- <>
52
- <span className={style.TypeBracket}>{'<'}</span>
53
- <Join items={params} limit={3}>
54
- <span className={style.TextOperator}>, </span>
55
- </Join>
56
- <span className={style.TypeBracket}>{'>'}</span>
57
- </>
58
- ) : null}
59
- </span>
60
- );
61
- }
62
-
63
- case 'JavaTypeClass':
64
- case 'JavaTypeUnion':
65
- return (
66
- <span className={style.Type}>
67
- <span className={style.TypeKeyword}>class</span>
68
- </span>
69
- );
70
-
71
- case 'JavaTypeEnum':
72
- return (
73
- <span className={style.Type}>
74
- <span className={style.TypeKeyword}>{language === 'kotlin' ? 'enum class' : 'enum'}</span>
75
- </span>
76
- );
77
-
78
- case 'JavaTypeVoid':
79
- return (
80
- <span className={style.Type}>
81
- <span className={style.TypeKeyword}>{language === 'kotlin' ? 'Nothing?' : 'Void'}</span>
82
- </span>
83
- );
84
-
85
- case 'JavaTypeBoolean':
86
- return (
87
- <span className={style.Type}>
88
- <span className={style.TypeKeyword}>
89
- {language === 'kotlin' || optional ? 'Boolean' : 'boolean'}
90
- </span>
91
- </span>
92
- );
93
-
94
- case 'JavaTypeDouble':
95
- return (
96
- <span className={style.Type}>
97
- <span className={style.TypeKeyword}>{language === 'kotlin' || optional ? 'Double' : 'double'}</span>
98
- </span>
99
- );
100
-
101
- case 'JavaTypeLong':
102
- return (
103
- <span className={style.Type}>
104
- <span className={style.TypeKeyword}>{language === 'kotlin' || optional ? 'Long' : 'long'}</span>
105
- </span>
106
- );
107
-
108
- case 'JavaTypeString':
109
- return (
110
- <span className={style.Type}>
111
- <span className={style.TypeString}>String</span>
112
- </span>
113
- );
114
-
115
- case 'JavaTypeConstant':
116
- return (
117
- <span className={style.Type}>
118
- <span className={style.TypeKeyword}>JsonValue</span>;
119
- </span>
120
- );
121
- }
122
- }
123
-
124
- export type MethodSignatureProps = {
125
- decl: AST.JavaDeclFunction;
126
- };
127
-
128
- export function MethodSignature({ decl }: MethodSignatureProps) {
129
- const Lang = useLanguageComponents();
130
- const language = useLanguage();
131
- const { Join, Tooltip } = useComponents();
132
-
133
- const params = decl.parameters.map((param, i) => (
134
- <React.Fragment key={i}>
135
- <Tooltip content={<Lang.Type type={param.typeAnnotation} />}>
136
- <span className={style.TextIdentifier}>{param.ident}</span>
137
- {param.hasDefault && (
138
- <>
139
- {' '}
140
- <span className={style.TextOperator}>=</span> <Lang.Type type={param.typeAnnotation} />
141
- <span className={style.TextOperator}>.</span>
142
- <span className={style.TextIdentifier}>none</span>
143
- <span className={style.TextOperator}>()</span>
144
- </>
145
- )}
146
- </Tooltip>
147
- </React.Fragment>
148
- ));
149
-
150
- return (
151
- <div className={style.MethodSignature}>
152
- <span className={style.SignatureTitle}>
153
- {decl.returnType && language !== 'kotlin' && (
154
- <span className={style.SignatureReturns}>
155
- <Lang.Type type={decl.returnType} />{' '}
156
- </span>
157
- )}
158
- {decl.qualified && (
159
- <span className={style.SignatureQualified}>
160
- <span className={style.TextIdentifier}>{decl.qualified?.slice(0, -decl.ident.length)}</span>
161
- </span>
162
- )}
163
- <span className={style.SignatureName}>
164
- <span className={style.TextIdentifier}>{decl.ident}</span>
165
- </span>
166
- <span className={style.MethodSignature}>
167
- <span className={style.SignatureParen}>{'('}</span>
168
-
169
- <span className={style.SignatureParams}>
170
- <Join items={params}>
171
- <span className={style.TextOperator}>{', '}</span>
172
- </Join>
173
- </span>
174
-
175
- <span className={style.SignatureParen}>{')'} </span>
176
- {decl.returnType && language === 'kotlin' && (
177
- <>
178
- <span className={style.TextOperator}>:</span> <Lang.Type type={decl.returnType} />
179
- </>
180
- )}
181
- </span>
182
- </span>
183
- </div>
184
- );
185
- }
186
-
187
- export type PropertyProps = {
188
- decl: AST.JavaDeclaration;
189
- children?: PropertyFn;
190
- };
191
-
192
- export function Property({ decl, children }: PropertyProps) {
193
- const Docs = useComponents();
194
- const Lang = useLanguageComponents();
195
- const language = useLanguage();
196
-
197
- if (!decl) return null;
198
-
199
- switch (decl.kind) {
200
- case 'JavaDeclProperty': {
201
- const typeRaw = <Lang.Type type={decl.type} optional={decl.optional} />;
202
- const typeWrapped = decl.optional ? (
203
- <>
204
- <span className={style.TypeKeyword}>Optional</span>
205
- <span className={style.TypeBracket}>{'<'}</span>
206
- {typeRaw}
207
- <span className={style.TypeBracket}>{'>'}</span>
208
- </>
209
- ) : (
210
- typeRaw
211
- );
212
-
213
- const badges = (
214
- <>
215
- {decl.type.kind === 'JavaTypeConstant' && (
216
- <Docs.Tooltip content={<span className={style.TextIdentifier}>{decl.type.value}</span>}>
217
- <span className={style.TextIdentifier}>constant</span>
218
- </Docs.Tooltip>
219
- )}
220
- </>
221
- );
222
-
223
- return children({
224
- name: decl.ident,
225
- typeName: <Lang.TypeName type={decl.type} optional={decl.optional} />,
226
- type: showFullType(decl.type) && typeWrapped,
227
- badges,
228
- });
229
- }
230
-
231
- case 'JavaDeclConst':
232
- return children({
233
- name: decl.ident,
234
- typeName: 'const',
235
- type: <span className={constStyle[typeof decl.value]}>{JSON.stringify(decl.value)}</span>,
236
- });
237
-
238
- case 'JavaDeclType': {
239
- const typeName =
240
- decl.type.kind === 'JavaTypeUnion'
241
- ? 'union'
242
- : decl.type.kind === 'JavaTypeEnum'
243
- ? language === 'kotlin'
244
- ? 'enum class'
245
- : 'enum'
246
- : 'class';
247
-
248
- return children({ name: decl.ident, typeName });
249
- }
250
-
251
- case 'JavaDeclReference':
252
- return children({ type: <Lang.Type type={decl.type} /> });
253
- }
254
- }
255
-
256
- export type DeclarationProps = {
257
- decl: AST.JavaDeclaration;
258
- };
259
-
260
- export function Declaration({ decl }: DeclarationProps) {
261
- const Docs = useComponents();
262
- const Lang = useLanguageComponents();
263
- const language = useLanguage();
264
-
265
- if (!decl) return null;
266
-
267
- switch (decl.kind) {
268
- case 'JavaDeclConst':
269
- return (
270
- <>
271
- <span className={style.TextIdentifier}>{decl.ident}</span>
272
- <span className={style.TextPunctuation}>{'('}</span>
273
- {JSON.stringify(decl.value)}
274
- <span className={style.TextPunctuation}>{')'}</span>
275
- </>
276
- );
277
-
278
- case 'JavaDeclType': {
279
- const keyword =
280
- decl.type.kind === 'JavaTypeEnum' ? (language === 'kotlin' ? 'enum class' : 'enum') : 'class';
281
-
282
- return (
283
- <>
284
- <span className={style.TextKeyword}>{keyword}</span>{' '}
285
- <span className={style.TextIdentifier}>{decl.ident}</span>
286
- <span className={style.TextPunctuation}>:</span>
287
- {decl.type.kind === 'JavaTypeUnion' && (
288
- <>
289
- {' '}
290
- <Docs.Tooltip content="A class that can be one of several variants.">
291
- <Docs.Badge id="java-union">union</Docs.Badge>
292
- </Docs.Tooltip>{' '}
293
- </>
294
- )}
295
- </>
296
- );
297
- }
298
-
299
- case 'JavaDeclProperty': {
300
- const inlineType = <Lang.Type type={decl.type} optional={decl.optional} />;
301
-
302
- const ident = (
303
- <span className={style.TypePropertyName}>
304
- <span className={style.TextIdentifier}>{decl.ident}</span>
305
- </span>
306
- );
307
-
308
- const suffix =
309
- decl.type.kind === 'JavaTypeConstant' ? (
310
- <>
311
- {' '}
312
- <Docs.Tooltip content={<span className={style.TextIdentifier}>{decl.type.value}</span>}>
313
- <Docs.Badge id="java-constant">constant</Docs.Badge>
314
- </Docs.Tooltip>
315
- </>
316
- ) : null;
317
-
318
- if (language === 'kotlin')
319
- return (
320
- <>
321
- {ident}
322
- <span className={style.TextPunctuation}>:</span>{' '}
323
- {decl.optional ? (
324
- <>
325
- <span className={style.TypeReference}>Optional</span>
326
- <span className={style.TypeBracket}>{'<'}</span>
327
- {inlineType}
328
- <span className={style.TypeBracket}>{'>'}</span>
329
- </>
330
- ) : (
331
- inlineType
332
- )}
333
- {suffix}
334
- </>
335
- );
336
-
337
- return (
338
- <>
339
- {decl.optional ? (
340
- <>
341
- <span className={style.TypeReference}>Optional</span>
342
- <span className={style.TypeBracket}>{'<'}</span>
343
- {inlineType}
344
- <span className={style.TypeBracket}>{'>'}</span>
345
- </>
346
- ) : (
347
- inlineType
348
- )}{' '}
349
- {ident}
350
- {suffix}
351
- </>
352
- );
353
- }
354
-
355
- case 'JavaDeclReference':
356
- return <Lang.Type type={decl.type} />;
357
- }
358
- }
@@ -1,255 +0,0 @@
1
- import * as React from 'react';
2
- import type * as AST from '~/lib/json-spec-v2/PythonAST';
3
- import { useLanguageComponents } from '../contexts';
4
- import { useComponents } from '../contexts/use-components';
5
- import style from '../style';
6
- import { PropertyFn } from '.';
7
-
8
- const constStyle = {
9
- string: style.LiteralString,
10
- number: style.LiteralNumeric,
11
- boolean: style.LiteralBoolean,
12
- };
13
-
14
- function showFullType(type: AST.PythonType) {
15
- if (type.kind !== 'PythonTypeReference') return false;
16
- return type.typeName === 'Optional' ? showFullType(type.typeParameters[0]) : type.typeParameters.length > 0;
17
- }
18
-
19
- type TypeProps = {
20
- type: AST.PythonType;
21
- };
22
-
23
- export function TypeName({ type }: TypeProps) {
24
- const Lang = useLanguageComponents();
25
-
26
- if (type.kind === 'PythonTypeReference') {
27
- switch (type.typeName) {
28
- case 'Optional':
29
- return <Lang.TypeName type={type.typeParameters[0]} />;
30
- case 'List':
31
- case 'Iterable':
32
- case 'Literal':
33
- case 'Union':
34
- return type.typeName.toLowerCase();
35
- }
36
- }
37
-
38
- return <Lang.Type type={type} />;
39
- }
40
-
41
- export function Type({ type }: TypeProps) {
42
- const Lang = useLanguageComponents();
43
- const { Join, SDKReference } = useComponents();
44
-
45
- switch (type.kind) {
46
- case 'PythonTypeAny':
47
- case 'PythonTypeUnknown':
48
- case 'PythonTypeInt':
49
- case 'PythonTypeFloat':
50
- case 'PythonTypeBool':
51
- return (
52
- <span className={style.Type}>
53
- <span className={style.TypeKeyword}>{type.kind.slice(10).toLowerCase()}</span>
54
- </span>
55
- );
56
-
57
- case 'PythonTypeString':
58
- return (
59
- <span className={style.Type}>
60
- <span className={style.TypeString}>str</span>
61
- </span>
62
- );
63
-
64
- case 'PythonTypeLiteral':
65
- return (
66
- <span className={style.Type}>
67
- <span className={constStyle[typeof type.literal.value]}>{JSON.stringify(type.literal.value)}</span>
68
- </span>
69
- );
70
-
71
- case 'PythonTypeArray':
72
- return (
73
- <span className={style.Type}>
74
- <span className={style.TypeArray}>{'Array<'}</span>
75
- <Lang.Type type={type.elementType} />
76
- <span className={style.TypeArray}>{'>'}</span>
77
- </span>
78
- );
79
-
80
- case 'PythonTypeClass':
81
- return (
82
- <span className={style.Type}>
83
- <span className={style.TypeKeyword}>class</span>
84
- </span>
85
- );
86
-
87
- case 'PythonTypeMap':
88
- return (
89
- <span className={style.Type}>
90
- <span className={style.TypeKeyword}>Dict</span>
91
- </span>
92
- );
93
-
94
- case 'PythonTypeReference': {
95
- const params = type.typeParameters?.map((param, key) => <Lang.Type key={key} type={param} />);
96
-
97
- return (
98
- <span className={style.Type}>
99
- <span className={type.typeName === 'Optional' ? style.TypeArray : ''}>
100
- <SDKReference stainlessPath={type.$ref}>{type.typeName}</SDKReference>
101
- </span>
102
- {params && params.length > 0 && (
103
- <>
104
- <span className={style.TypeBracket}>{'['}</span>
105
- <Join items={params} limit={3}>
106
- <span className={style.TextOperator}>, </span>
107
- </Join>
108
- <span className={style.TypeBracket}>{']'}</span>
109
- </>
110
- )}
111
- </span>
112
- );
113
- }
114
- }
115
- }
116
-
117
- export type MethodSignatureProps = {
118
- decl: AST.PythonDeclFunction;
119
- };
120
-
121
- export function MethodSignature({ decl }: MethodSignatureProps) {
122
- const Lang = useLanguageComponents();
123
- const { Join, Tooltip } = useComponents();
124
-
125
- const params = decl.parameters.map((param, i) => (
126
- <React.Fragment key={i}>
127
- <Tooltip content={<Lang.Type type={param.type} />}>
128
- <span className={style.TextIdentifier}>{param.ident}</span>
129
- </Tooltip>
130
- </React.Fragment>
131
- ));
132
-
133
- return (
134
- <div className={style.MethodSignature}>
135
- <span className={style.SignatureTitle}>
136
- {decl.async && <span className={style.TextKeyword}>async </span>}
137
- {decl.qualified && (
138
- <span className={style.SignatureQualified}>
139
- <span className={style.TextIdentifier}>{decl.qualified?.slice(0, -decl.ident.length)}</span>
140
- </span>
141
- )}
142
- <span className={style.SignatureName}>
143
- <span className={style.TextIdentifier}>{decl.ident}</span>
144
- </span>
145
- <span className={style.MethodSignature}>
146
- <span className={style.SignatureParen}>{'('}</span>
147
-
148
- <span className={style.SignatureParams}>
149
- <Join items={params}>
150
- <span className={style.TextOperator}>{', '}</span>
151
- </Join>
152
- </span>
153
-
154
- <span className={style.SignatureParen}>{')'} </span>
155
- {decl.returns && (
156
- <>
157
- <span className={style.TextOperator}>{' -> '}</span>
158
- <Lang.Type type={decl.returns} />
159
- </>
160
- )}
161
- </span>
162
- </span>
163
- </div>
164
- );
165
- }
166
-
167
- export type PropertyProps = {
168
- decl: AST.PythonDeclaration;
169
- children?: PropertyFn;
170
- };
171
-
172
- export function Property({ decl, children }: PropertyProps) {
173
- const Lang = useLanguageComponents();
174
-
175
- if (!decl) return;
176
-
177
- switch (decl.kind) {
178
- case 'PythonDeclProperty':
179
- return children({
180
- name: decl.ident,
181
- typeName: <Lang.TypeName type={decl.type} />,
182
- type: showFullType(decl.type) && <Lang.Type type={decl.type} />,
183
- });
184
-
185
- case 'PythonDeclClass':
186
- return children({ name: decl.ident, typeName: 'class' });
187
-
188
- case 'PythonDeclType':
189
- return children({
190
- name: decl.ident,
191
- typeName: 'type',
192
- type: <Lang.Type type={decl.type} />,
193
- });
194
-
195
- case 'PythonDeclReference':
196
- return children({ type: <Lang.Type type={decl.type} /> });
197
- }
198
- }
199
-
200
- export type DeclarationProps = { decl: AST.PythonDeclaration };
201
-
202
- export function Declaration({ decl }: DeclarationProps) {
203
- const Lang = useLanguageComponents();
204
-
205
- if (!decl) return;
206
-
207
- switch (decl.kind) {
208
- case 'PythonDeclProperty':
209
- const nullable =
210
- decl.type.kind === 'PythonTypeReference' &&
211
- decl.type.typeName === 'Optional' &&
212
- (decl.type.typeParameters ?? []).length > 0;
213
-
214
- return (
215
- <>
216
- <span className={style.TypePropertyName}>
217
- <span className={style.TextIdentifier}>{decl.ident}</span>
218
- </span>
219
- <span className={style.TextPunctuation}>: </span>
220
- {decl.optional && !nullable ? (
221
- <>
222
- <span className={style.TypePlain}>Optional</span>
223
- <span className={style.TypeBracket}>{'['}</span>
224
- <Lang.Type type={decl.type} />
225
- <span className={style.TypeBrace}>{']'}</span>
226
- </>
227
- ) : (
228
- <Lang.Type type={decl.type} />
229
- )}
230
- </>
231
- );
232
-
233
- case 'PythonDeclClass':
234
- return (
235
- <>
236
- <span className={style.TextKeyword}>class </span>
237
- <span className={style.TextIdentifier}>{decl.ident}</span>
238
- <span className={style.TextPunctuation}>: </span>
239
- <span className={`${style.TypePreviewContent} ${style.TextPunctuation}`}>…</span>
240
- </>
241
- );
242
-
243
- case 'PythonDeclType':
244
- return (
245
- <>
246
- <span className={style.TextIdentifier}>{decl.ident}</span>
247
- <span className={style.TextOperator}> = </span>
248
- <Lang.Type type={decl.type} />
249
- </>
250
- );
251
-
252
- case 'PythonDeclReference':
253
- return <Lang.Type type={decl.type} />;
254
- }
255
- }