@stainless-api/docs-ui 0.1.0-beta.3 → 0.1.0-beta.30

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 (187) hide show
  1. package/dist/breadcrumbs-wJ7A9MGt.d.ts +20 -0
  2. package/dist/chunk-DsStOjWQ.js +13 -0
  3. package/dist/component-generics--y1IC_M-.d.ts +30 -0
  4. package/dist/component-generics-D3ybuN5r.js +45 -0
  5. package/dist/components/breadcrumbs.d.ts +2 -0
  6. package/dist/components/breadcrumbs.js +15 -0
  7. package/dist/components/chat.d.ts +14 -0
  8. package/dist/components/chat.js +142 -0
  9. package/dist/components/icons.d.ts +50 -0
  10. package/dist/components/icons.js +3 -0
  11. package/dist/components/index.d.ts +11 -0
  12. package/dist/components/index.js +15 -0
  13. package/dist/components/method.d.ts +2 -0
  14. package/dist/components/method.js +15 -0
  15. package/dist/components/overview.d.ts +2 -0
  16. package/dist/components/overview.js +15 -0
  17. package/dist/components/primitives.d.ts +2 -0
  18. package/dist/components/primitives.js +15 -0
  19. package/dist/components/properties.d.ts +2 -0
  20. package/dist/components/properties.js +15 -0
  21. package/dist/components/sdk.d.ts +3 -0
  22. package/dist/components/sdk.js +15 -0
  23. package/dist/components/sidebar.d.ts +2 -0
  24. package/dist/components/sidebar.js +15 -0
  25. package/dist/components/snippets.d.ts +4 -0
  26. package/dist/components/snippets.js +15 -0
  27. package/dist/contexts/component-generics.d.ts +2 -0
  28. package/dist/contexts/component-generics.js +3 -0
  29. package/dist/contexts/component-types.d.ts +17 -0
  30. package/dist/contexts/component-types.js +0 -0
  31. package/dist/contexts/component.d.ts +30 -0
  32. package/dist/contexts/component.js +15 -0
  33. package/dist/contexts/docs.d.ts +2 -0
  34. package/dist/contexts/docs.js +3 -0
  35. package/dist/contexts/index.d.ts +19 -0
  36. package/dist/contexts/index.js +15 -0
  37. package/dist/contexts/markdown.d.ts +2 -0
  38. package/dist/contexts/markdown.js +4 -0
  39. package/dist/contexts/navigation.d.ts +3 -0
  40. package/dist/contexts/navigation.js +3 -0
  41. package/dist/contexts/search.d.ts +4 -0
  42. package/dist/contexts/search.js +15 -0
  43. package/dist/contexts/use-components.d.ts +15 -0
  44. package/dist/contexts/use-components.js +4 -0
  45. package/dist/contexts-CMNI3ctP.js +3799 -0
  46. package/dist/docs-BvahWQ28.d.ts +46 -0
  47. package/dist/docs-CopwX9a7.js +54 -0
  48. package/dist/icons-yb-Jhkmg.js +753 -0
  49. package/dist/index-BmPNhnpe.d.ts +14 -0
  50. package/dist/index-D5NMSAld.d.ts +240 -0
  51. package/dist/index-rVFBdVz8.d.ts +15 -0
  52. package/dist/index.d.ts +21 -0
  53. package/dist/index.js +15 -7542
  54. package/dist/languages/go.d.ts +12 -0
  55. package/dist/languages/go.js +15 -0
  56. package/dist/languages/http.d.ts +12 -0
  57. package/dist/languages/http.js +15 -0
  58. package/dist/languages/index.d.ts +12 -0
  59. package/dist/languages/index.js +15 -0
  60. package/dist/languages/java.d.ts +12 -0
  61. package/dist/languages/java.js +15 -0
  62. package/dist/languages/python.d.ts +12 -0
  63. package/dist/languages/python.js +15 -0
  64. package/dist/languages/ruby.d.ts +12 -0
  65. package/dist/languages/ruby.js +15 -0
  66. package/dist/languages/typescript.d.ts +12 -0
  67. package/dist/languages/typescript.js +15 -0
  68. package/dist/markdown/index.d.ts +12 -0
  69. package/dist/markdown/index.js +15 -0
  70. package/dist/markdown/md.d.ts +15 -0
  71. package/dist/markdown/md.js +3 -0
  72. package/dist/markdown/utils.d.ts +4 -0
  73. package/dist/markdown/utils.js +3 -0
  74. package/dist/markdown-BmpyokB7.js +43 -0
  75. package/dist/markdown-w5UpIiGc.d.ts +22 -0
  76. package/dist/md-DxiV1_vy.js +41 -0
  77. package/dist/method-CLpRObBV.d.ts +71 -0
  78. package/dist/navigation-Blr3LaES.d.ts +29 -0
  79. package/dist/navigation-CGr5_w6z.js +24 -0
  80. package/dist/overview-DBnqhjAg.d.ts +39 -0
  81. package/dist/pagefind-BaK1krMe.js +15 -0
  82. package/dist/primitives-BFubD3w8.d.ts +99 -0
  83. package/dist/properties-DeQRa6VK.d.ts +46 -0
  84. package/dist/routing-8itEXLx6.js +189 -0
  85. package/dist/routing-DNN8R6bZ.d.ts +54 -0
  86. package/dist/routing.d.ts +2 -0
  87. package/dist/routing.js +3 -180
  88. package/dist/sdk-BVQyp5Dw.d.ts +119 -0
  89. package/dist/search/index.d.ts +26 -0
  90. package/dist/search/index.js +334 -0
  91. package/dist/search/providers/algolia.d.ts +24 -0
  92. package/dist/search/providers/algolia.js +15 -0
  93. package/dist/search/providers/fuse.d.ts +18 -0
  94. package/dist/search/providers/fuse.js +30 -0
  95. package/dist/search/providers/pagefind.d.ts +7 -0
  96. package/dist/search/providers/pagefind.js +3 -0
  97. package/dist/search/providers/walker.d.ts +9 -0
  98. package/dist/search/providers/walker.js +34 -0
  99. package/dist/search/types.d.ts +3 -0
  100. package/dist/search/types.js +3 -0
  101. package/dist/search-CPp6HpUy.d.ts +21 -0
  102. package/dist/sidebar-BoPLeaxp.d.ts +36 -0
  103. package/dist/snippets-DLHH_Voi.d.ts +46 -0
  104. package/dist/style-BEMLtSIK.d.ts +172 -0
  105. package/dist/style-CPgcT0Fw.js +173 -0
  106. package/dist/style.d.ts +2 -0
  107. package/dist/style.js +3 -0
  108. package/dist/styles/main.css +763 -736
  109. package/dist/styles/main.js +0 -0
  110. package/dist/styles/primitives.css +285 -464
  111. package/dist/styles/primitives.js +0 -0
  112. package/dist/styles/resets.css +34 -41
  113. package/dist/styles/resets.js +0 -0
  114. package/dist/styles/search.css +266 -248
  115. package/dist/styles/search.js +0 -0
  116. package/dist/styles/sidebar.css +59 -60
  117. package/dist/styles/sidebar.js +0 -0
  118. package/dist/styles/snippets.css +87 -88
  119. package/dist/styles/snippets.js +0 -0
  120. package/dist/styles/variables.css +87 -89
  121. package/dist/styles/variables.js +0 -0
  122. package/dist/types-DNSz4kuM.d.ts +83 -0
  123. package/dist/types-__XoFvJ_.js +34 -0
  124. package/dist/use-components-BHEwm0mE.js +7 -0
  125. package/dist/utils-2FmcHPHp.js +32 -0
  126. package/dist/utils-BCfb0F9R.js +30 -0
  127. package/dist/utils-D43p_yTd.d.ts +14 -0
  128. package/dist/utils-DVi3gJLL.d.ts +21 -0
  129. package/dist/utils.d.ts +2 -0
  130. package/dist/utils.js +4 -0
  131. package/package.json +78 -16
  132. package/dist/mcp.js +0 -16003
  133. package/src/components/breadcrumbs.tsx +0 -94
  134. package/src/components/chat.tsx +0 -154
  135. package/src/components/dropdown.tsx +0 -91
  136. package/src/components/icons.tsx +0 -584
  137. package/src/components/index.ts +0 -9
  138. package/src/components/method.tsx +0 -144
  139. package/src/components/overview.tsx +0 -159
  140. package/src/components/primitives.tsx +0 -284
  141. package/src/components/properties.tsx +0 -130
  142. package/src/components/scripts/dropdown.ts +0 -78
  143. package/src/components/sdk.tsx +0 -402
  144. package/src/components/sidebar.tsx +0 -99
  145. package/src/components/snippets.tsx +0 -179
  146. package/src/contexts/component-generics.tsx +0 -48
  147. package/src/contexts/component-types.tsx +0 -5
  148. package/src/contexts/component.tsx +0 -32
  149. package/src/contexts/docs.tsx +0 -75
  150. package/src/contexts/index.tsx +0 -17
  151. package/src/contexts/markdown.tsx +0 -43
  152. package/src/contexts/navigation.tsx +0 -44
  153. package/src/contexts/search.tsx +0 -28
  154. package/src/contexts/use-components.tsx +0 -4
  155. package/src/index.ts +0 -6
  156. package/src/languages/go.tsx +0 -281
  157. package/src/languages/http.tsx +0 -321
  158. package/src/languages/index.ts +0 -26
  159. package/src/languages/java.tsx +0 -358
  160. package/src/languages/python.tsx +0 -255
  161. package/src/languages/ruby.tsx +0 -320
  162. package/src/languages/typescript.tsx +0 -393
  163. package/src/markdown/index.ts +0 -107
  164. package/src/markdown/md.ts +0 -45
  165. package/src/markdown/utils.ts +0 -49
  166. package/src/routing.ts +0 -238
  167. package/src/search/form.tsx +0 -127
  168. package/src/search/index.tsx +0 -1
  169. package/src/search/indexer.ts +0 -246
  170. package/src/search/mcp.ts +0 -61
  171. package/src/search/printer.tsx +0 -86
  172. package/src/search/providers/algolia.ts +0 -88
  173. package/src/search/providers/fuse.ts +0 -19
  174. package/src/search/providers/pagefind.ts +0 -17
  175. package/src/search/providers/walker.ts +0 -30
  176. package/src/search/results.tsx +0 -181
  177. package/src/search/state.ts +0 -64
  178. package/src/search/types.ts +0 -116
  179. package/src/style.ts +0 -197
  180. package/src/styles/main.css +0 -993
  181. package/src/styles/primitives.css +0 -572
  182. package/src/styles/resets.css +0 -47
  183. package/src/styles/search.css +0 -342
  184. package/src/styles/sidebar.css +0 -87
  185. package/src/styles/snippets.css +0 -132
  186. package/src/styles/variables.css +0 -90
  187. 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
- }