@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,179 +0,0 @@
1
- import * as React from 'react';
2
- import { CheckIcon, CircleAlertIcon, CopyIcon, LucideIcon } from 'lucide-react';
3
- import { useDeclaration, useHighlight, useLanguage, useSnippet } from '../contexts';
4
- import { useComponents } from '../contexts/use-components';
5
- import style from '../style';
6
- import clsx from 'clsx';
7
- import type * as SDKJSON from '~/lib/json-spec-v2/types';
8
- import type { TransformRequestSnippetFn } from './sdk';
9
-
10
- export type SnippetCodeProps = {
11
- content: string;
12
- signature?: string;
13
- language?: string;
14
- };
15
-
16
- export function SnippetCode({ content, language }: SnippetCodeProps) {
17
- const lang = useLanguage();
18
- const highlighted = useHighlight(content, language || lang);
19
-
20
- return (
21
- <div className={style.SnippetCode}>
22
- <pre className={style.SnippetCodeContent} data-stldocs-copy-content>
23
- <code
24
- className={(language as string) === 'json' ? 'snippet-json' : 'snippet'}
25
- dangerouslySetInnerHTML={{ __html: highlighted }}
26
- />
27
- </pre>
28
- </div>
29
- );
30
- }
31
-
32
- export type SnippetProps = {
33
- method: SDKJSON.Method;
34
- requestTitle?: React.ReactNode;
35
- transformRequestSnippet?: TransformRequestSnippetFn;
36
- };
37
-
38
- export type SnippetContainerProps = {
39
- children: React.ReactNode;
40
- signature?: string;
41
- };
42
-
43
- export function SnippetContainer({ children }: SnippetContainerProps) {
44
- return <div className={clsx(style.Snippet)}>{children}</div>;
45
- }
46
-
47
- export type SnippetRequestContainerProps = {
48
- children?: React.ReactNode;
49
- signature?: string;
50
- };
51
-
52
- export function SnippetRequestContainer({ children }: SnippetRequestContainerProps) {
53
- return <div>{children}</div>;
54
- }
55
-
56
- export function Snippet({ requestTitle, method, transformRequestSnippet }: SnippetProps) {
57
- const Docs = useComponents();
58
- const language = useLanguage();
59
- const [CopyButtonIcon, setCopyIcon] = React.useState<LucideIcon>(CopyIcon);
60
-
61
- let snippet = useSnippet(method.stainlessPath, null, language === 'http' ? 'curl' : 'default');
62
- const decl = useDeclaration(method.stainlessPath);
63
-
64
- const signature = 'qualified' in decl ? decl.qualified : undefined;
65
- const responses = method.exampleResponses;
66
-
67
- if (transformRequestSnippet) {
68
- snippet = transformRequestSnippet({ snippet, language });
69
- }
70
-
71
- async function handleCopy() {
72
- try {
73
- await navigator.clipboard.writeText(snippet);
74
- setCopyIcon(CheckIcon);
75
- } catch {
76
- setCopyIcon(CircleAlertIcon);
77
- }
78
-
79
- setTimeout(() => setCopyIcon(CopyIcon), 1000);
80
- }
81
-
82
- return (
83
- <Docs.SnippetContainer signature={signature}>
84
- {snippet && (
85
- <Docs.SnippetRequestContainer signature={signature}>
86
- <div className={style.SnippetRequest} data-stldocs-copy-parent>
87
- <div className={style.SnippetRequestTitle}>
88
- <div className={style.SnippetRequestTitleMethod}>
89
- <Docs.MethodRoute httpMethod={method.httpMethod} iconOnly />
90
- <h5>{method.summary}</h5>
91
- </div>
92
- <div className={style.SnippetRequestTitleContent}>{requestTitle}</div>
93
- <button data-stldocs-snippet-copy className={style.SnippetRequestTitleCopyButton}>
94
- <CopyButtonIcon size={16} className={style.Icon} onClick={handleCopy} />
95
- </button>
96
- </div>
97
- <Docs.SnippetCode content={snippet} signature={signature} />
98
- </div>
99
- </Docs.SnippetRequestContainer>
100
- )}
101
- {responses && <Docs.SnippetResponse responses={responses} />}
102
- </Docs.SnippetContainer>
103
- );
104
- }
105
-
106
- export function SnippetResponse({ responses }: { responses: SDKJSON.Method['exampleResponses'] }) {
107
- const { SnippetCode } = useComponents();
108
-
109
- if (!responses) {
110
- return null;
111
- }
112
-
113
- const mappedResponses = Object.keys(responses)
114
- .map((key) => {
115
- // Get the first response type ie application/json or text/plain
116
- const responseType = Object.keys(responses[key])[0];
117
- const response = responses[key][responseType];
118
-
119
- const examples = response?.examples;
120
-
121
- if (!examples) return null;
122
-
123
- // Get the first example type, ie Example or html
124
- const exampleType = Object.keys(examples)[0];
125
- let value = examples[exampleType]?.value;
126
-
127
- if (!value) return null;
128
-
129
- if (responseType === 'application/json') {
130
- value = JSON.stringify(value, null, 2);
131
- }
132
-
133
- return {
134
- responseCode: key,
135
- content: value,
136
- };
137
- })
138
- .filter(Boolean);
139
-
140
- if (mappedResponses.length === 0) return null;
141
-
142
- return (
143
- <div className={style.SnippetMultiResponse}>
144
- <div className={clsx(style.Snippet)}>
145
- <div
146
- className={clsx(
147
- style.SnippetResponseTab,
148
- mappedResponses.length === 1 && style.SnippetResponseTabSingleReturn,
149
- )}
150
- >
151
- {mappedResponses.map(({ responseCode }, index) => (
152
- <button
153
- className={clsx(
154
- style.SnippetResponseTabItem,
155
- index === 0 && style.SnippetResponseTabItemActive,
156
- )}
157
- key={`snippet-response-tab-item-${responseCode}-${index}`}
158
- data-snippet-response-tab-id={`snippet-response-tab-${responseCode}-${index}`}
159
- disabled={mappedResponses.length === 1}
160
- >
161
- {responseCode} example
162
- </button>
163
- ))}
164
- </div>
165
- {mappedResponses.map(({ responseCode, content }, index) => {
166
- return (
167
- <div
168
- className={clsx(style.SnippetResponsePane, index === 0 && style.SnippetResponsePaneActive)}
169
- key={`snippet-response-${responseCode}-${index}`}
170
- data-snippet-response-pane-id={`snippet-response-tab-${responseCode}-${index}`}
171
- >
172
- <SnippetCode content={content} language="json" />
173
- </div>
174
- );
175
- })}
176
- </div>
177
- </div>
178
- );
179
- }
@@ -1,48 +0,0 @@
1
- // This file should never import from ../components or ../languages to avoid circular dependencies
2
-
3
- import * as React from 'react';
4
-
5
- type DeepPartialMap<L> = { [K in keyof L]?: Partial<L[K]> };
6
-
7
- export type ComponentsContextType<C, L> = {
8
- components: C;
9
- language: L;
10
- };
11
-
12
- const ComponentContext = React.createContext<ComponentsContextType<any, any> | null>(null);
13
- ComponentContext.displayName = 'ComponentContext';
14
-
15
- export function useComponents<C = unknown>() {
16
- const ctx = React.useContext(ComponentContext);
17
- if (!ctx) throw new Error('useComponents must be used within a ComponentContext.Provider');
18
- return ctx.components as C;
19
- }
20
-
21
- export function customizeComponents<C, L>(
22
- defaults: { components: C; language: L },
23
- overrides: { components?: Partial<C>; language?: DeepPartialMap<L> } = {},
24
- ): { components: C; language: L } {
25
- const mergedComponents = { ...defaults.components, ...(overrides.components ?? {}) } as C;
26
-
27
- const mergedLanguage = Object.keys(defaults.language as Record<string, unknown>).reduce(
28
- (acc, key) => {
29
- acc[key] = { ...(defaults.language as any)[key], ...(overrides.language?.[key] ?? {}) };
30
- return acc;
31
- },
32
- {} as any as L,
33
- );
34
-
35
- return { components: mergedComponents, language: mergedLanguage };
36
- }
37
-
38
- export function ComponentProvider<C, L>({
39
- value,
40
- children,
41
- }: {
42
- value: ComponentsContextType<C, L>;
43
- children: React.ReactNode;
44
- }) {
45
- return <ComponentContext.Provider value={value}>{children}</ComponentContext.Provider>;
46
- }
47
-
48
- export { ComponentContext };
@@ -1,5 +0,0 @@
1
- import type * as DefaultComponents from '../components';
2
- import type * as DefaultLanguage from '../languages';
3
-
4
- export type AppComponents = typeof DefaultComponents;
5
- export type AppLanguage = typeof DefaultLanguage;
@@ -1,32 +0,0 @@
1
- import React from 'react';
2
- import * as DefaultComponents from '../components';
3
- import * as DefaultLanguage from '../languages';
4
- import {
5
- ComponentProvider as GenericComponentProvider,
6
- customizeComponents,
7
- type ComponentsContextType,
8
- } from './component-generics';
9
-
10
- export type AppComponents = typeof DefaultComponents;
11
- export type AppLanguage = typeof DefaultLanguage;
12
-
13
- export const defaultContextValue: ComponentsContextType<AppComponents, AppLanguage> = {
14
- components: DefaultComponents,
15
- language: DefaultLanguage,
16
- };
17
-
18
- export function ComponentProvider({
19
- components,
20
- language,
21
- children,
22
- }: {
23
- components?: Partial<AppComponents>;
24
- language?: { [K in keyof AppLanguage]?: Partial<AppLanguage[K]> };
25
- children: React.ReactNode;
26
- }) {
27
- const value = React.useMemo(
28
- () => customizeComponents(defaultContextValue, { components, language }),
29
- [components, language],
30
- );
31
- return <GenericComponentProvider value={value}>{children}</GenericComponentProvider>;
32
- }
@@ -1,75 +0,0 @@
1
- import * as React from 'react';
2
- import type { Spec, SpecLanguage } from '~/lib/json-spec-v2/types';
3
-
4
- export type ContentPanelLayout = 'double-pane' | 'single-pane';
5
- export type PropertySettingsType = {
6
- types?: 'simple' | 'rich';
7
- includeModelProperties?: boolean;
8
- collapseDescription?: boolean;
9
- expandDepth?: number;
10
- };
11
-
12
- export type DocsContextType = {
13
- language: SpecLanguage;
14
- spec: Spec | null;
15
- settings?: {
16
- properties?: PropertySettingsType;
17
- contentPanelLayout?: ContentPanelLayout;
18
- virtualExpanders?: boolean;
19
- };
20
- };
21
-
22
- const DocsContextDefaults: DocsContextType = {
23
- settings: {},
24
- language: 'node',
25
- spec: null,
26
- };
27
-
28
- const DocsContext = React.createContext<DocsContextType>(DocsContextDefaults);
29
-
30
- export function useDocs() {
31
- return React.useContext(DocsContext);
32
- }
33
-
34
- export function useSpec() {
35
- return useDocs().spec;
36
- }
37
-
38
- export function useSettings() {
39
- return useDocs().settings;
40
- }
41
-
42
- export function useSnippet(stainlessPath: string, language?: SpecLanguage, variant?: string) {
43
- const snippetLanguage = [language ?? useLanguage(), variant ?? 'default'].join('.');
44
-
45
- return useSpec()?.snippets?.[snippetLanguage]?.[stainlessPath];
46
- }
47
-
48
- export function useDeclaration(stainlessPath: string, language?: SpecLanguage) {
49
- return useSpec()?.decls?.[language ?? useLanguage()]?.[stainlessPath];
50
- }
51
-
52
- export function useResource(name: string) {
53
- return useSpec()?.resources?.[name];
54
- }
55
-
56
- export function useLanguage() {
57
- return useDocs().language;
58
- }
59
-
60
- export function useContentPanelLayout() {
61
- return useDocs().settings?.contentPanelLayout ?? 'double-pane';
62
- }
63
-
64
- export type DocsProviderProps = DocsContextType & { children: React.ReactNode };
65
-
66
- export function DocsProvider({ spec, language, settings, children }: DocsProviderProps) {
67
- const value = {
68
- ...DocsContextDefaults,
69
- spec,
70
- settings: settings ?? DocsContextDefaults.settings,
71
- language: language ?? DocsContextDefaults.language,
72
- };
73
-
74
- return <DocsContext.Provider value={value}>{children}</DocsContext.Provider>;
75
- }
@@ -1,17 +0,0 @@
1
- import * as React from 'react';
2
- import { ComponentContext } from './component-generics';
3
- import { useLanguage } from './docs';
4
- import { LanguageComponentDefinition } from '../languages';
5
-
6
- // DO NOT re-export component contexts from here. Only export generics.
7
- export * from './navigation';
8
- export * from './markdown';
9
- export * from './component-generics';
10
- export * from './search';
11
- export * from './docs';
12
-
13
- export function useLanguageComponents() {
14
- const language = useLanguage();
15
- const context = React.useContext(ComponentContext);
16
- return context.language[language] as LanguageComponentDefinition;
17
- }
@@ -1,43 +0,0 @@
1
- import * as React from 'react';
2
- import { useLanguage } from './docs';
3
-
4
- const HighlightLanguageMappings = {
5
- node: 'typescript',
6
- http: 'bash',
7
- };
8
-
9
- export type MarkdownContext = {
10
- highlight?: (content: string, language?: string) => string | Promise<string>;
11
- render?: (content: string) => string;
12
- };
13
-
14
- export const MarkdownContext = React.createContext<MarkdownContext>({
15
- highlight: (content) => content,
16
- render: (content) => content,
17
- });
18
-
19
- export const useMarkdownContext = () => React.useContext(MarkdownContext);
20
-
21
- export function useRenderMarkdown(content?: string) {
22
- const { render } = React.useContext(MarkdownContext);
23
- return React.useMemo(() => (content ? render(content) : undefined), [content, render]);
24
- }
25
-
26
- export function useHighlight(content?: string, language?: string) {
27
- const { highlight } = React.useContext(MarkdownContext);
28
- const lang = language ?? useLanguage();
29
-
30
- return React.useMemo(() => {
31
- const highlightLanguage = HighlightLanguageMappings[lang] ?? lang;
32
- const rendered = highlight(content, highlightLanguage);
33
- return typeof rendered === 'string' ? rendered : React.use(rendered);
34
- }, [content, language, highlight]);
35
- }
36
-
37
- export type MarkdownProviderProps = MarkdownContext & {
38
- children: React.ReactNode;
39
- };
40
-
41
- export function MarkdownProvider({ render, highlight, children }: MarkdownProviderProps) {
42
- return <MarkdownContext.Provider value={{ render, highlight }}>{children}</MarkdownContext.Provider>;
43
- }
@@ -1,44 +0,0 @@
1
- import * as React from 'react';
2
- import { DocsLanguage } from '../routing';
3
-
4
- export type NavigationHandler = (
5
- ev: React.MouseEvent | null,
6
- opts: {
7
- href: string;
8
- language: DocsLanguage;
9
- stainlessPath: string;
10
- scroll: boolean;
11
- },
12
- ) => void;
13
-
14
- export type NavigationContextType = {
15
- basePath?: string;
16
- selectedPath?: string;
17
- navigationPath?: string[];
18
- onNavigate?: NavigationHandler;
19
- };
20
-
21
- const Defaults: NavigationContextType = {
22
- basePath: '/',
23
- };
24
-
25
- const NavigationContext = React.createContext<NavigationContextType>(Defaults);
26
-
27
- export function useNavigation() {
28
- return React.useContext(NavigationContext);
29
- }
30
-
31
- export type NavigationProviderProps = NavigationContextType & {
32
- children: React.ReactNode;
33
- };
34
-
35
- export function NavigationProvider({
36
- basePath,
37
- selectedPath,
38
- onNavigate,
39
- children,
40
- }: NavigationProviderProps) {
41
- const value = { ...Defaults, onNavigate, basePath, selectedPath };
42
-
43
- return <NavigationContext.Provider value={value}>{children}</NavigationContext.Provider>;
44
- }
@@ -1,28 +0,0 @@
1
- import * as React from 'react';
2
- import { search } from '../search/providers/algolia';
3
- import { SearchParams, SearchSettings } from '../search/types';
4
-
5
- export type SearchContextType = {
6
- settings: SearchSettings;
7
- onSelect?: (stainlessPath: string) => void;
8
- pageFind?: string;
9
- };
10
-
11
- const SearchContext = React.createContext<SearchContextType>(null);
12
-
13
- export function useSearchContext() {
14
- return React.useContext(SearchContext);
15
- }
16
-
17
- export function useSearch() {
18
- const { settings } = useSearchContext();
19
- return (params: SearchParams) => search({ settings, params });
20
- }
21
-
22
- export type SearchProviderProps = SearchContextType & {
23
- children: React.ReactNode;
24
- };
25
-
26
- export function SearchProvider({ children, ...props }: SearchProviderProps) {
27
- return <SearchContext value={props}>{children}</SearchContext>;
28
- }
@@ -1,4 +0,0 @@
1
- import { useComponents as base } from './component-generics';
2
- import type { AppComponents } from './component-types';
3
-
4
- export const useComponents = () => base<AppComponents>();
package/src/index.ts DELETED
@@ -1,6 +0,0 @@
1
- export * as contexts from './contexts';
2
- export * as components from './components';
3
- export * as languages from './languages';
4
- export * as routing from './routing';
5
- export * as utils from './utils';
6
- export { default as style } from './style';