@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,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
- }