@stainless-api/docs-ui 0.1.0-beta.29 → 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 (194) hide show
  1. package/dist/{breadcrumbs-D5viAm7a.d.ts → breadcrumbs-wJ7A9MGt.d.ts} +2 -2
  2. package/dist/{component-generics-BnrVqdQj.d.ts → component-generics--y1IC_M-.d.ts} +2 -1
  3. package/dist/{component-generics-Df4EDvxk.js → component-generics-D3ybuN5r.js} +5 -1
  4. package/dist/components/breadcrumbs.d.ts +1 -1
  5. package/dist/components/breadcrumbs.js +13 -14
  6. package/dist/components/chat.d.ts +3 -3
  7. package/dist/components/chat.js +64 -50
  8. package/dist/components/icons.d.ts +10 -10
  9. package/dist/components/icons.js +1 -1
  10. package/dist/components/index.d.ts +11 -12
  11. package/dist/components/index.js +14 -15
  12. package/dist/components/method.d.ts +1 -1
  13. package/dist/components/method.js +13 -14
  14. package/dist/components/overview.d.ts +1 -1
  15. package/dist/components/overview.js +13 -14
  16. package/dist/components/primitives.d.ts +1 -1
  17. package/dist/components/primitives.js +13 -14
  18. package/dist/components/properties.d.ts +1 -1
  19. package/dist/components/properties.js +13 -14
  20. package/dist/components/sdk.d.ts +2 -2
  21. package/dist/components/sdk.js +13 -14
  22. package/dist/components/sidebar.d.ts +1 -1
  23. package/dist/components/sidebar.js +13 -14
  24. package/dist/components/snippets.d.ts +3 -3
  25. package/dist/components/snippets.js +13 -14
  26. package/dist/contexts/component-generics.d.ts +1 -1
  27. package/dist/contexts/component-generics.js +1 -1
  28. package/dist/contexts/component-types.d.ts +11 -12
  29. package/dist/contexts/component-types.js +0 -1
  30. package/dist/contexts/component.d.ts +14 -14
  31. package/dist/contexts/component.js +13 -14
  32. package/dist/contexts/docs.d.ts +1 -1
  33. package/dist/contexts/docs.js +1 -1
  34. package/dist/contexts/index.d.ts +18 -19
  35. package/dist/contexts/index.js +13 -14
  36. package/dist/contexts/markdown.d.ts +1 -1
  37. package/dist/contexts/markdown.js +2 -2
  38. package/dist/contexts/navigation.d.ts +2 -2
  39. package/dist/contexts/navigation.js +1 -1
  40. package/dist/contexts/search.d.ts +3 -3
  41. package/dist/contexts/search.js +13 -14
  42. package/dist/contexts/use-components.d.ts +10 -11
  43. package/dist/contexts/use-components.js +2 -2
  44. package/dist/contexts-CMNI3ctP.js +3799 -0
  45. package/dist/{docs-DhNaW0DE.d.ts → docs-BvahWQ28.d.ts} +2 -1
  46. package/dist/{docs-Cj25B-Sh.js → docs-CopwX9a7.js} +5 -1
  47. package/dist/icons-yb-Jhkmg.js +753 -0
  48. package/dist/{index-d8_VR8Z5.d.ts → index-BmPNhnpe.d.ts} +6 -6
  49. package/dist/{index-BXO3gZup.d.ts → index-D5NMSAld.d.ts} +26 -25
  50. package/dist/index-rVFBdVz8.d.ts +15 -0
  51. package/dist/index.d.ts +20 -21
  52. package/dist/index.js +15 -7700
  53. package/dist/languages/go.d.ts +11 -12
  54. package/dist/languages/go.js +13 -14
  55. package/dist/languages/http.d.ts +11 -12
  56. package/dist/languages/http.js +13 -14
  57. package/dist/languages/index.d.ts +11 -12
  58. package/dist/languages/index.js +13 -14
  59. package/dist/languages/java.d.ts +11 -12
  60. package/dist/languages/java.js +13 -14
  61. package/dist/languages/python.d.ts +11 -12
  62. package/dist/languages/python.js +13 -14
  63. package/dist/languages/ruby.d.ts +11 -12
  64. package/dist/languages/ruby.js +13 -14
  65. package/dist/languages/typescript.d.ts +11 -12
  66. package/dist/languages/typescript.js +13 -14
  67. package/dist/markdown/index.d.ts +3 -3
  68. package/dist/markdown/index.js +13 -14
  69. package/dist/markdown/md.js +1 -1
  70. package/dist/markdown/utils.d.ts +3 -3
  71. package/dist/markdown/utils.js +1 -1
  72. package/dist/{markdown-DunIdqFE.js → markdown-BmpyokB7.js} +9 -5
  73. package/dist/{markdown-DN8KaRR2.d.ts → markdown-w5UpIiGc.d.ts} +2 -1
  74. package/dist/{method-c3XDArUn.d.ts → method-CLpRObBV.d.ts} +7 -6
  75. package/dist/{navigation-BSn6PX-7.d.ts → navigation-Blr3LaES.d.ts} +3 -2
  76. package/dist/{navigation-CuCg3le8.js → navigation-CGr5_w6z.js} +5 -1
  77. package/dist/{overview-D21weqVJ.d.ts → overview-DBnqhjAg.d.ts} +6 -6
  78. package/dist/{primitives-iB9fIrMF.d.ts → primitives-BFubD3w8.d.ts} +9 -8
  79. package/dist/{properties-Ba6F_GGj.d.ts → properties-DeQRa6VK.d.ts} +4 -4
  80. package/dist/{routing-C8oZYLsf.js → routing-8itEXLx6.js} +1 -1
  81. package/dist/{routing-BE6Vrs-z.d.ts → routing-DNN8R6bZ.d.ts} +1 -1
  82. package/dist/routing.d.ts +1 -1
  83. package/dist/routing.js +3 -180
  84. package/dist/{sdk-D2x2l6JH.d.ts → sdk-BVQyp5Dw.d.ts} +14 -13
  85. package/dist/search/index.d.ts +6 -6
  86. package/dist/search/index.js +233 -110
  87. package/dist/search/providers/algolia.d.ts +2 -2
  88. package/dist/search/providers/algolia.js +13 -14
  89. package/dist/search/providers/fuse.d.ts +2 -2
  90. package/dist/search/providers/fuse.js +13 -14
  91. package/dist/search/providers/pagefind.d.ts +2 -2
  92. package/dist/search/providers/pagefind.js +1 -1
  93. package/dist/search/providers/walker.d.ts +2 -2
  94. package/dist/search/providers/walker.js +13 -14
  95. package/dist/search/types.d.ts +2 -2
  96. package/dist/search/types.js +1 -1
  97. package/dist/{search-KMqOU2tz.d.ts → search-CPp6HpUy.d.ts} +3 -2
  98. package/dist/{sidebar-B1X4gmY2.d.ts → sidebar-BoPLeaxp.d.ts} +5 -4
  99. package/dist/{snippets-BApdMOXp.d.ts → snippets-DLHH_Voi.d.ts} +7 -6
  100. package/dist/{style-BWu-Pqcm.d.ts → style-BEMLtSIK.d.ts} +0 -10
  101. package/dist/{style-CkbsakoF.js → style-CPgcT0Fw.js} +1 -11
  102. package/dist/style.d.ts +1 -1
  103. package/dist/style.js +1 -1
  104. package/dist/styles/main.css +51 -20
  105. package/dist/styles/main.js +0 -0
  106. package/dist/styles/primitives.css +1 -0
  107. package/dist/styles/primitives.js +0 -0
  108. package/dist/styles/resets.css +1 -0
  109. package/dist/styles/resets.js +0 -0
  110. package/dist/styles/search.css +1 -0
  111. package/dist/styles/search.js +0 -0
  112. package/dist/styles/sidebar.css +1 -0
  113. package/dist/styles/sidebar.js +0 -0
  114. package/dist/styles/snippets.css +1 -0
  115. package/dist/styles/snippets.js +0 -0
  116. package/dist/styles/variables.css +2 -0
  117. package/dist/styles/variables.js +0 -0
  118. package/dist/{types-BLgvxY4i.d.ts → types-DNSz4kuM.d.ts} +1 -1
  119. package/dist/{use-components-DI-AbT-D.js → use-components-BHEwm0mE.js} +1 -1
  120. package/dist/{utils-BhYTrLot.js → utils-2FmcHPHp.js} +2 -2
  121. package/dist/{utils-B9JL_XWH.d.ts → utils-DVi3gJLL.d.ts} +2 -2
  122. package/dist/utils.d.ts +1 -1
  123. package/dist/utils.js +2 -2
  124. package/package.json +63 -10
  125. package/dist/components/dropdown.d.ts +0 -2
  126. package/dist/components/dropdown.js +0 -4
  127. package/dist/components/scripts/dropdown.d.ts +0 -12
  128. package/dist/components/scripts/dropdown.js +0 -50
  129. package/dist/contexts-DO0sMzym.js +0 -2581
  130. package/dist/dropdown-Dv9VAYCW.d.ts +0 -42
  131. package/dist/dropdown-kUhwBigR.js +0 -38
  132. package/dist/icons--8QR-PrL.js +0 -222
  133. package/dist/index-BW6OPqAo.d.ts +0 -16
  134. package/dist/mcp.cjs +0 -983418
  135. package/src/components/breadcrumbs.tsx +0 -94
  136. package/src/components/chat.tsx +0 -157
  137. package/src/components/icons.tsx +0 -584
  138. package/src/components/index.ts +0 -8
  139. package/src/components/method.tsx +0 -145
  140. package/src/components/overview.tsx +0 -172
  141. package/src/components/primitives.tsx +0 -301
  142. package/src/components/properties.tsx +0 -132
  143. package/src/components/sdk.tsx +0 -408
  144. package/src/components/sidebar.tsx +0 -99
  145. package/src/components/snippets.tsx +0 -197
  146. package/src/contexts/component-generics.tsx +0 -43
  147. package/src/contexts/component-types.tsx +0 -5
  148. package/src/contexts/component.tsx +0 -32
  149. package/src/contexts/docs.tsx +0 -86
  150. package/src/contexts/index.tsx +0 -20
  151. package/src/contexts/markdown.tsx +0 -44
  152. package/src/contexts/navigation.tsx +0 -44
  153. package/src/contexts/search.tsx +0 -27
  154. package/src/contexts/use-components.tsx +0 -4
  155. package/src/hooks/use-strict-context.tsx +0 -16
  156. package/src/index.ts +0 -6
  157. package/src/languages/go.tsx +0 -281
  158. package/src/languages/http.tsx +0 -329
  159. package/src/languages/index.ts +0 -26
  160. package/src/languages/java.tsx +0 -358
  161. package/src/languages/python.tsx +0 -258
  162. package/src/languages/ruby.tsx +0 -327
  163. package/src/languages/typescript.tsx +0 -399
  164. package/src/markdown/index.ts +0 -112
  165. package/src/markdown/md.ts +0 -45
  166. package/src/markdown/utils.ts +0 -52
  167. package/src/routing.ts +0 -238
  168. package/src/search/form.tsx +0 -130
  169. package/src/search/index.tsx +0 -1
  170. package/src/search/indexer.ts +0 -248
  171. package/src/search/mcp.ts +0 -156
  172. package/src/search/printer.tsx +0 -86
  173. package/src/search/providers/algolia.ts +0 -88
  174. package/src/search/providers/fuse.ts +0 -19
  175. package/src/search/providers/pagefind.ts +0 -17
  176. package/src/search/providers/walker.ts +0 -32
  177. package/src/search/results.tsx +0 -183
  178. package/src/search/state.ts +0 -64
  179. package/src/search/types.ts +0 -116
  180. package/src/style.ts +0 -185
  181. package/src/styles/main.css +0 -989
  182. package/src/styles/primitives.css +0 -392
  183. package/src/styles/resets.css +0 -39
  184. package/src/styles/search.css +0 -359
  185. package/src/styles/sidebar.css +0 -85
  186. package/src/styles/snippets.css +0 -130
  187. package/src/styles/variables.css +0 -86
  188. package/src/utils.ts +0 -40
  189. /package/dist/{chunk-Bp6m_JJh.js → chunk-DsStOjWQ.js} +0 -0
  190. /package/dist/{md-Dg8aOyMA.js → md-DxiV1_vy.js} +0 -0
  191. /package/dist/{pagefind-ChrPfuVv.js → pagefind-BaK1krMe.js} +0 -0
  192. /package/dist/{types-DFN4M1Sp.js → types-__XoFvJ_.js} +0 -0
  193. /package/dist/{utils-ByZH9QWT.js → utils-BCfb0F9R.js} +0 -0
  194. /package/dist/{utils-DlayebL1.d.ts → utils-D43p_yTd.d.ts} +0 -0
@@ -1,358 +0,0 @@
1
- import * as React from 'react';
2
- import { JavaAST as AST } from '@stainless/sdk-json';
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: Record<string, string> = {
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,258 +0,0 @@
1
- import * as React from 'react';
2
- import { PythonAST as AST } from '@stainless/sdk-json';
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: Record<string, string> = {
9
- string: style.LiteralString,
10
- number: style.LiteralNumeric,
11
- boolean: style.LiteralBoolean,
12
- };
13
-
14
- function showFullType(type: AST.PythonType): boolean {
15
- if (type.kind !== 'PythonTypeReference') return false;
16
- return type.typeName === 'Optional'
17
- ? showFullType(type.typeParameters![0]!)
18
- : type.typeParameters!.length > 0;
19
- }
20
-
21
- type TypeProps = {
22
- type: AST.PythonType;
23
- };
24
-
25
- export function TypeName({ type }: TypeProps) {
26
- const Lang = useLanguageComponents();
27
-
28
- if (type.kind === 'PythonTypeReference') {
29
- switch (type.typeName) {
30
- case 'Optional':
31
- return <Lang.TypeName type={type.typeParameters![0]!} />;
32
- case 'List':
33
- case 'Iterable':
34
- case 'Literal':
35
- case 'Union':
36
- return type.typeName.toLowerCase();
37
- }
38
- }
39
-
40
- return <Lang.Type type={type} />;
41
- }
42
-
43
- export function Type({ type }: TypeProps) {
44
- const Lang = useLanguageComponents();
45
- const { Join, SDKReference } = useComponents();
46
-
47
- switch (type.kind) {
48
- case 'PythonTypeAny':
49
- case 'PythonTypeUnknown':
50
- case 'PythonTypeInt':
51
- case 'PythonTypeFloat':
52
- case 'PythonTypeBool':
53
- return (
54
- <span className={style.Type}>
55
- <span className={style.TypeKeyword}>{type.kind.slice(10).toLowerCase()}</span>
56
- </span>
57
- );
58
-
59
- case 'PythonTypeString':
60
- return (
61
- <span className={style.Type}>
62
- <span className={style.TypeString}>str</span>
63
- </span>
64
- );
65
-
66
- case 'PythonTypeLiteral':
67
- return (
68
- <span className={style.Type}>
69
- <span className={constStyle[typeof type.literal.value]!}>{JSON.stringify(type.literal.value)}</span>
70
- </span>
71
- );
72
-
73
- case 'PythonTypeArray':
74
- return (
75
- <span className={style.Type}>
76
- <span className={style.TypeArray}>{'Array<'}</span>
77
- <Lang.Type type={type.elementType} />
78
- <span className={style.TypeArray}>{'>'}</span>
79
- </span>
80
- );
81
-
82
- case 'PythonTypeClass':
83
- return (
84
- <span className={style.Type}>
85
- <span className={style.TypeKeyword}>class</span>
86
- </span>
87
- );
88
-
89
- case 'PythonTypeMap':
90
- return (
91
- <span className={style.Type}>
92
- <span className={style.TypeKeyword}>Dict</span>
93
- </span>
94
- );
95
-
96
- case 'PythonTypeReference': {
97
- const params = type.typeParameters?.map((param, key) => <Lang.Type key={key} type={param} />);
98
-
99
- return (
100
- <span className={style.Type}>
101
- <span className={type.typeName === 'Optional' ? style.TypeArray : ''}>
102
- <SDKReference stainlessPath={type.$ref!}>{type.typeName}</SDKReference>
103
- </span>
104
- {params && params.length > 0 && (
105
- <>
106
- <span className={style.TypeBracket}>{'['}</span>
107
- <Join items={params} limit={3}>
108
- <span className={style.TextOperator}>, </span>
109
- </Join>
110
- <span className={style.TypeBracket}>{']'}</span>
111
- </>
112
- )}
113
- </span>
114
- );
115
- }
116
- }
117
- }
118
-
119
- export type MethodSignatureProps = {
120
- decl: AST.PythonDeclFunction;
121
- };
122
-
123
- export function MethodSignature({ decl }: MethodSignatureProps) {
124
- const Lang = useLanguageComponents();
125
- const { Join, Tooltip } = useComponents();
126
-
127
- const params = decl.parameters.map((param, i) => (
128
- <React.Fragment key={i}>
129
- <Tooltip content={<Lang.Type type={param.type} />}>
130
- <span className={style.TextIdentifier}>{param.ident}</span>
131
- </Tooltip>
132
- </React.Fragment>
133
- ));
134
-
135
- return (
136
- <div className={style.MethodSignature}>
137
- <span className={style.SignatureTitle}>
138
- {decl.async && <span className={style.TextKeyword}>async </span>}
139
- {decl.qualified && (
140
- <span className={style.SignatureQualified}>
141
- <span className={style.TextIdentifier}>{decl.qualified?.slice(0, -decl.ident.length)}</span>
142
- </span>
143
- )}
144
- <span className={style.SignatureName}>
145
- <span className={style.TextIdentifier}>{decl.ident}</span>
146
- </span>
147
- <span className={style.MethodSignature}>
148
- <span className={style.SignatureParen}>{'('}</span>
149
-
150
- <span className={style.SignatureParams}>
151
- <Join items={params}>
152
- <span className={style.TextOperator}>{', '}</span>
153
- </Join>
154
- </span>
155
-
156
- <span className={style.SignatureParen}>{')'} </span>
157
- {decl.returns && (
158
- <>
159
- <span className={style.TextOperator}>{' -> '}</span>
160
- <Lang.Type type={decl.returns} />
161
- </>
162
- )}
163
- </span>
164
- </span>
165
- </div>
166
- );
167
- }
168
-
169
- export type PropertyProps = {
170
- decl: AST.PythonDeclaration;
171
- children: PropertyFn;
172
- };
173
-
174
- export function Property({ decl, children }: PropertyProps) {
175
- const Lang = useLanguageComponents();
176
-
177
- if (!decl) return;
178
-
179
- switch (decl.kind) {
180
- case 'PythonDeclProperty':
181
- return children({
182
- name: decl.ident,
183
- typeName: <Lang.TypeName type={decl.type} />,
184
- type: showFullType(decl.type) && <Lang.Type type={decl.type} />,
185
- });
186
-
187
- case 'PythonDeclClass':
188
- return children({ name: decl.ident, typeName: 'class' });
189
-
190
- case 'PythonDeclType':
191
- return children({
192
- name: decl.ident,
193
- typeName: 'type',
194
- type: <Lang.Type type={decl.type} />,
195
- });
196
-
197
- case 'PythonDeclReference':
198
- return children({ type: <Lang.Type type={decl.type} /> });
199
- }
200
- }
201
-
202
- export type DeclarationProps = { decl: AST.PythonDeclaration };
203
-
204
- export function Declaration({ decl }: DeclarationProps) {
205
- const Lang = useLanguageComponents();
206
-
207
- if (!decl) return;
208
-
209
- switch (decl.kind) {
210
- case 'PythonDeclProperty': {
211
- const nullable =
212
- decl.type.kind === 'PythonTypeReference' &&
213
- decl.type.typeName === 'Optional' &&
214
- (decl.type.typeParameters ?? []).length > 0;
215
-
216
- return (
217
- <>
218
- <span className={style.TypePropertyName}>
219
- <span className={style.TextIdentifier}>{decl.ident}</span>
220
- </span>
221
- <span className={style.TextPunctuation}>: </span>
222
- {decl.optional && !nullable ? (
223
- <>
224
- <span className={style.TypePlain}>Optional</span>
225
- <span className={style.TypeBracket}>{'['}</span>
226
- <Lang.Type type={decl.type} />
227
- <span className={style.TypeBrace}>{']'}</span>
228
- </>
229
- ) : (
230
- <Lang.Type type={decl.type} />
231
- )}
232
- </>
233
- );
234
- }
235
-
236
- case 'PythonDeclClass':
237
- return (
238
- <>
239
- <span className={style.TextKeyword}>class </span>
240
- <span className={style.TextIdentifier}>{decl.ident}</span>
241
- <span className={style.TextPunctuation}>: </span>
242
- <span className={`${style.TypePreviewContent} ${style.TextPunctuation}`}>…</span>
243
- </>
244
- );
245
-
246
- case 'PythonDeclType':
247
- return (
248
- <>
249
- <span className={style.TextIdentifier}>{decl.ident}</span>
250
- <span className={style.TextOperator}> = </span>
251
- <Lang.Type type={decl.type} />
252
- </>
253
- );
254
-
255
- case 'PythonDeclReference':
256
- return <Lang.Type type={decl.type} />;
257
- }
258
- }