@stainless-api/docs-ui 0.1.0-beta.7 → 0.1.0-beta.70

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 (215) hide show
  1. package/dist/breadcrumbs-BhYwbXkc.d.ts +25 -0
  2. package/dist/breadcrumbs-Cvm5Ifm7.d.ts +25 -0
  3. package/dist/breadcrumbs-DA4WgDhR.js +63 -0
  4. package/dist/chunk-BN_g-Awi.js +18 -0
  5. package/dist/cli-F3kMmeoJ.js +166 -0
  6. package/dist/component-P9sn5yyG.js +23 -0
  7. package/dist/component-generics-ByGsYTc8.d.ts +30 -0
  8. package/dist/component-generics-POFirVVb.js +45 -0
  9. package/dist/component-generics-zU0Pqx8m.d.ts +30 -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 +11 -0
  17. package/dist/components/index.js +19 -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-sidebar.d.ts +2 -0
  27. package/dist/components/sdk-sidebar.js +10 -0
  28. package/dist/components/sdk.d.ts +2 -0
  29. package/dist/components/sdk.js +10 -0
  30. package/dist/components/snippets.d.ts +3 -0
  31. package/dist/components/snippets.js +9 -0
  32. package/dist/components/stl-sidebar.d.ts +2 -0
  33. package/dist/components/stl-sidebar.js +5 -0
  34. package/dist/components-w1JmIrB0.js +71 -0
  35. package/dist/contexts/component-generics.d.ts +2 -0
  36. package/dist/contexts/component-generics.js +3 -0
  37. package/dist/contexts/component-types.d.ts +17 -0
  38. package/dist/contexts/component-types.js +0 -0
  39. package/dist/contexts/component.d.ts +30 -0
  40. package/dist/contexts/component.js +30 -0
  41. package/dist/contexts/docs.d.ts +2 -0
  42. package/dist/contexts/docs.js +3 -0
  43. package/dist/contexts/index.d.ts +23 -0
  44. package/dist/contexts/index.js +7 -0
  45. package/dist/contexts/markdown.d.ts +2 -0
  46. package/dist/contexts/markdown.js +4 -0
  47. package/dist/contexts/navigation.d.ts +2 -0
  48. package/dist/contexts/navigation.js +3 -0
  49. package/dist/contexts/use-components.d.ts +15 -0
  50. package/dist/contexts/use-components.js +4 -0
  51. package/dist/contexts-CVj20VV4.js +41 -0
  52. package/dist/csharp-D6_jlynY.js +283 -0
  53. package/dist/docs-BmOB2f-I.js +61 -0
  54. package/dist/docs-g4IPmtZr.d.ts +48 -0
  55. package/dist/docs-z3fl2eW-.d.ts +48 -0
  56. package/dist/go-COaHV3Hc.js +303 -0
  57. package/dist/http-fOPCX17A.js +389 -0
  58. package/dist/icons-BYKn5X8E.js +885 -0
  59. package/dist/index-B8Zys1C2.d.ts +347 -0
  60. package/dist/index-C5Zmb2CI.d.ts +16 -0
  61. package/dist/index-CwjGm9zX.d.ts +1722 -0
  62. package/dist/index-D7PkxNgB.d.ts +16 -0
  63. package/dist/index-DIaM6Ync.d.ts +347 -0
  64. package/dist/index.d.ts +20 -0
  65. package/dist/index.js +32 -7542
  66. package/dist/java-CxGSJVvv.js +403 -0
  67. package/dist/languages/cli.d.ts +12 -0
  68. package/dist/languages/cli.js +21 -0
  69. package/dist/languages/csharp.d.ts +12 -0
  70. package/dist/languages/csharp.js +9 -0
  71. package/dist/languages/go.d.ts +12 -0
  72. package/dist/languages/go.js +9 -0
  73. package/dist/languages/http.d.ts +12 -0
  74. package/dist/languages/http.js +20 -0
  75. package/dist/languages/index.d.ts +12 -0
  76. package/dist/languages/index.js +29 -0
  77. package/dist/languages/java.d.ts +12 -0
  78. package/dist/languages/java.js +9 -0
  79. package/dist/languages/python.d.ts +12 -0
  80. package/dist/languages/python.js +9 -0
  81. package/dist/languages/ruby.d.ts +12 -0
  82. package/dist/languages/ruby.js +9 -0
  83. package/dist/languages/terraform.d.ts +12 -0
  84. package/dist/languages/terraform.js +9 -0
  85. package/dist/languages/typescript.d.ts +12 -0
  86. package/dist/languages/typescript.js +9 -0
  87. package/dist/languages-B6eap2M6.js +30 -0
  88. package/dist/markdown/index.d.ts +12 -0
  89. package/dist/markdown/index.js +107 -0
  90. package/dist/markdown/md.d.ts +15 -0
  91. package/dist/markdown/md.js +41 -0
  92. package/dist/markdown/printer.d.ts +13 -0
  93. package/dist/markdown/printer.js +100 -0
  94. package/dist/markdown/utils.d.ts +21 -0
  95. package/dist/markdown/utils.js +31 -0
  96. package/dist/markdown-CTKHMLVr.js +49 -0
  97. package/dist/markdown-Cdh0TSHp.d.ts +22 -0
  98. package/dist/markdown-Cibv9fDR.d.ts +22 -0
  99. package/dist/method-630cPKDl.d.ts +59 -0
  100. package/dist/method-BPDUyBlD.js +96 -0
  101. package/dist/method-BzkPRXGL.d.ts +59 -0
  102. package/dist/navigation-BW-SBvb4.d.ts +29 -0
  103. package/dist/navigation-DWYqC_HX.d.ts +29 -0
  104. package/dist/navigation-aoYZ_tl4.js +24 -0
  105. package/dist/overview-Cui1XtuC.d.ts +39 -0
  106. package/dist/overview-DFwfIK6k.js +138 -0
  107. package/dist/overview-RXc9iPzz.d.ts +39 -0
  108. package/dist/primitives-DJEqe_r1.js +250 -0
  109. package/dist/primitives-DhGxFYx6.d.ts +105 -0
  110. package/dist/primitives-MsH-h0bU.d.ts +105 -0
  111. package/dist/properties-BnbBKd5a.js +132 -0
  112. package/dist/properties-Bynmj9_H.d.ts +54 -0
  113. package/dist/properties-C9W4QJ_F.d.ts +54 -0
  114. package/dist/python-DsTuWCKE.js +269 -0
  115. package/dist/routing-C64k4fmX.js +205 -0
  116. package/dist/routing-Cm_9XJiQ.d.ts +61 -0
  117. package/dist/routing-utiR5mY3.d.ts +61 -0
  118. package/dist/routing.d.ts +2 -0
  119. package/dist/routing.js +3 -180
  120. package/dist/ruby-BncKp6hd.js +387 -0
  121. package/dist/sdk-BvZeXpsj.d.ts +122 -0
  122. package/dist/sdk-Bw99eXxA.js +399 -0
  123. package/dist/sdk-GMOw94wL.d.ts +122 -0
  124. package/dist/sdk-sidebar-NCBSWuUW.d.ts +15 -0
  125. package/dist/sdk-sidebar-VNY2-O1Y.d.ts +15 -0
  126. package/dist/sdk-sidebar-V_MTkVw8.js +50 -0
  127. package/dist/snippets-BehbU3rt.js +164 -0
  128. package/dist/snippets-Bj7Ey56K.d.ts +53 -0
  129. package/dist/snippets-CQQSDvg2.d.ts +53 -0
  130. package/dist/spec.d.ts +65 -0
  131. package/dist/spec.js +167 -0
  132. package/dist/stl-sidebar-CXzs_shz.d.ts +58 -0
  133. package/dist/stl-sidebar-DSkUHwcU.d.ts +58 -0
  134. package/dist/stl-sidebar-WtimNrk1.js +106 -0
  135. package/dist/style-HpXpcJ9v.js +172 -0
  136. package/dist/style.d.ts +171 -0
  137. package/dist/style.js +3 -0
  138. package/dist/styles/main.css +744 -754
  139. package/dist/styles/main.js +0 -0
  140. package/dist/styles/primitives.css +327 -458
  141. package/dist/styles/primitives.js +0 -0
  142. package/dist/styles/resets.css +32 -41
  143. package/dist/styles/resets.js +0 -0
  144. package/dist/styles/search.css +192 -270
  145. package/dist/styles/search.js +0 -0
  146. package/dist/styles/sidebar.css +170 -69
  147. package/dist/styles/sidebar.js +0 -0
  148. package/dist/styles/variables.css +26 -89
  149. package/dist/styles/variables.js +0 -0
  150. package/dist/styles.css +3273 -0
  151. package/dist/styles.mjs +1 -0
  152. package/dist/terraform-B95X4rNK.js +243 -0
  153. package/dist/typescript-n46M9OtL.js +449 -0
  154. package/dist/use-components-BUz3GbO4.js +7 -0
  155. package/dist/utils-DPbkW1Tz.js +54 -0
  156. package/dist/utils.d.ts +20 -0
  157. package/dist/utils.js +3 -0
  158. package/package.json +74 -22
  159. package/dist/mcp.js +0 -16003
  160. package/dist/styles/snippets.css +0 -132
  161. package/src/components/breadcrumbs.tsx +0 -94
  162. package/src/components/chat.tsx +0 -154
  163. package/src/components/dropdown.tsx +0 -91
  164. package/src/components/icons.tsx +0 -584
  165. package/src/components/index.ts +0 -9
  166. package/src/components/method.tsx +0 -144
  167. package/src/components/overview.tsx +0 -159
  168. package/src/components/primitives.tsx +0 -284
  169. package/src/components/properties.tsx +0 -130
  170. package/src/components/scripts/dropdown.ts +0 -78
  171. package/src/components/sdk.tsx +0 -402
  172. package/src/components/sidebar.tsx +0 -99
  173. package/src/components/snippets.tsx +0 -179
  174. package/src/contexts/component-generics.tsx +0 -48
  175. package/src/contexts/component-types.tsx +0 -5
  176. package/src/contexts/component.tsx +0 -32
  177. package/src/contexts/docs.tsx +0 -75
  178. package/src/contexts/index.tsx +0 -17
  179. package/src/contexts/markdown.tsx +0 -43
  180. package/src/contexts/navigation.tsx +0 -44
  181. package/src/contexts/search.tsx +0 -28
  182. package/src/contexts/use-components.tsx +0 -4
  183. package/src/index.ts +0 -6
  184. package/src/languages/go.tsx +0 -281
  185. package/src/languages/http.tsx +0 -321
  186. package/src/languages/index.ts +0 -26
  187. package/src/languages/java.tsx +0 -358
  188. package/src/languages/python.tsx +0 -255
  189. package/src/languages/ruby.tsx +0 -320
  190. package/src/languages/typescript.tsx +0 -393
  191. package/src/markdown/index.ts +0 -107
  192. package/src/markdown/md.ts +0 -45
  193. package/src/markdown/utils.ts +0 -49
  194. package/src/routing.ts +0 -238
  195. package/src/search/form.tsx +0 -127
  196. package/src/search/index.tsx +0 -1
  197. package/src/search/indexer.ts +0 -246
  198. package/src/search/mcp.ts +0 -61
  199. package/src/search/printer.tsx +0 -86
  200. package/src/search/providers/algolia.ts +0 -88
  201. package/src/search/providers/fuse.ts +0 -19
  202. package/src/search/providers/pagefind.ts +0 -17
  203. package/src/search/providers/walker.ts +0 -30
  204. package/src/search/results.tsx +0 -181
  205. package/src/search/state.ts +0 -64
  206. package/src/search/types.ts +0 -116
  207. package/src/style.ts +0 -197
  208. package/src/styles/main.css +0 -993
  209. package/src/styles/primitives.css +0 -572
  210. package/src/styles/resets.css +0 -47
  211. package/src/styles/search.css +0 -342
  212. package/src/styles/sidebar.css +0 -87
  213. package/src/styles/snippets.css +0 -132
  214. package/src/styles/variables.css +0 -90
  215. 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
- }