@stainless-api/docs-ui 0.1.0-beta.5 → 0.1.0-beta.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/dist/breadcrumbs-C6pTTw_o.d.ts +20 -0
  2. package/dist/breadcrumbs-DEyC9k79.d.ts +20 -0
  3. package/dist/breadcrumbs-nSFZO5Gf.js +63 -0
  4. package/dist/chunk-DRcLgZ1e.js +18 -0
  5. package/dist/component-DRO8kQSp.js +23 -0
  6. package/dist/component-generics-B6Fn47Mz.js +45 -0
  7. package/dist/component-generics-D_yxZT6v.d.ts +30 -0
  8. package/dist/component-generics-DxN-MaP2.d.ts +30 -0
  9. package/dist/components/MaskedInput.d.ts +14 -0
  10. package/dist/components/MaskedInput.js +76 -0
  11. package/dist/components/breadcrumbs.d.ts +2 -0
  12. package/dist/components/breadcrumbs.js +9 -0
  13. package/dist/components/icons.d.ts +55 -0
  14. package/dist/components/icons.js +3 -0
  15. package/dist/components/index.d.ts +10 -0
  16. package/dist/components/index.js +18 -0
  17. package/dist/components/method.d.ts +2 -0
  18. package/dist/components/method.js +10 -0
  19. package/dist/components/overview.d.ts +2 -0
  20. package/dist/components/overview.js +11 -0
  21. package/dist/components/primitives.d.ts +2 -0
  22. package/dist/components/primitives.js +8 -0
  23. package/dist/components/properties.d.ts +2 -0
  24. package/dist/components/properties.js +9 -0
  25. package/dist/components/sdk.d.ts +2 -0
  26. package/dist/components/sdk.js +10 -0
  27. package/dist/components/sidebar.d.ts +2 -0
  28. package/dist/components/sidebar.js +11 -0
  29. package/dist/components/snippets.d.ts +3 -0
  30. package/dist/components/snippets.js +9 -0
  31. package/dist/components-D7M-BwNI.js +71 -0
  32. package/dist/contexts/component-generics.d.ts +2 -0
  33. package/dist/contexts/component-generics.js +3 -0
  34. package/dist/contexts/component-types.d.ts +16 -0
  35. package/dist/contexts/component-types.js +0 -0
  36. package/dist/contexts/component.d.ts +29 -0
  37. package/dist/contexts/component.js +27 -0
  38. package/dist/contexts/docs.d.ts +2 -0
  39. package/dist/contexts/docs.js +3 -0
  40. package/dist/contexts/index.d.ts +16 -0
  41. package/dist/contexts/index.js +7 -0
  42. package/dist/contexts/markdown.d.ts +2 -0
  43. package/dist/contexts/markdown.js +4 -0
  44. package/dist/contexts/navigation.d.ts +2 -0
  45. package/dist/contexts/navigation.js +3 -0
  46. package/dist/contexts/use-components.d.ts +14 -0
  47. package/dist/contexts/use-components.js +4 -0
  48. package/dist/contexts-p3rRZDlM.js +39 -0
  49. package/dist/csharp-CDSxfCZE.js +283 -0
  50. package/dist/docs-CXqi26jB.js +54 -0
  51. package/dist/docs-dNFWvk6w.d.ts +47 -0
  52. package/dist/docs-mMDqYdkf.d.ts +47 -0
  53. package/dist/go-1c3S5ETL.js +303 -0
  54. package/dist/http-2QNWXH9t.js +330 -0
  55. package/dist/icons-Ckod9aod.js +869 -0
  56. package/dist/index-0imEqwWy.d.ts +15 -0
  57. package/dist/index-BJR7MT73.d.ts +13 -0
  58. package/dist/index-DGWbX2x8.d.ts +13 -0
  59. package/dist/index-DJO7hQAU.d.ts +274 -0
  60. package/dist/index-DMFZJxNb.d.ts +15 -0
  61. package/dist/index-tw6MEWKp.d.ts +274 -0
  62. package/dist/index.d.ts +19 -0
  63. package/dist/index.js +29 -7542
  64. package/dist/java-BbjF_oUI.js +403 -0
  65. package/dist/languages/csharp.d.ts +11 -0
  66. package/dist/languages/csharp.js +9 -0
  67. package/dist/languages/go.d.ts +11 -0
  68. package/dist/languages/go.js +9 -0
  69. package/dist/languages/http.d.ts +11 -0
  70. package/dist/languages/http.js +19 -0
  71. package/dist/languages/index.d.ts +11 -0
  72. package/dist/languages/index.js +26 -0
  73. package/dist/languages/java.d.ts +11 -0
  74. package/dist/languages/java.js +9 -0
  75. package/dist/languages/python.d.ts +11 -0
  76. package/dist/languages/python.js +9 -0
  77. package/dist/languages/ruby.d.ts +11 -0
  78. package/dist/languages/ruby.js +9 -0
  79. package/dist/languages/typescript.d.ts +11 -0
  80. package/dist/languages/typescript.js +9 -0
  81. package/dist/languages-BCYZjzuS.js +26 -0
  82. package/dist/markdown/index.d.ts +12 -0
  83. package/dist/markdown/index.js +104 -0
  84. package/dist/markdown/md.d.ts +15 -0
  85. package/dist/markdown/md.js +3 -0
  86. package/dist/markdown/printer.d.ts +2 -0
  87. package/dist/markdown/printer.js +28 -0
  88. package/dist/markdown/utils.d.ts +3 -0
  89. package/dist/markdown/utils.js +3 -0
  90. package/dist/markdown-CxdeWgjV.js +48 -0
  91. package/dist/markdown-DeSSIANr.d.ts +22 -0
  92. package/dist/markdown-OuUthjwK.d.ts +22 -0
  93. package/dist/md-oM2tUaCA.js +41 -0
  94. package/dist/method-BiXJltKa.d.ts +71 -0
  95. package/dist/method-CE08mUME.js +115 -0
  96. package/dist/method-DQ3lDoTM.d.ts +71 -0
  97. package/dist/navigation-BX8nuda9.d.ts +29 -0
  98. package/dist/navigation-C5TN0SgC.js +24 -0
  99. package/dist/navigation-CWDfzVoR.d.ts +29 -0
  100. package/dist/overview-B43BuZbK.d.ts +39 -0
  101. package/dist/overview-MTDgZ7Xr.d.ts +39 -0
  102. package/dist/overview-S2hUqPXA.js +139 -0
  103. package/dist/primitives-1lB1L0is.d.ts +97 -0
  104. package/dist/primitives-BIWfwN5L.js +258 -0
  105. package/dist/primitives-DLv4uMoz.d.ts +97 -0
  106. package/dist/printer-DBw4S_Jn.d.ts +13 -0
  107. package/dist/printer-bNxiG6UB.js +74 -0
  108. package/dist/properties-B-giMW4K.d.ts +54 -0
  109. package/dist/properties-BvP2WAjP.d.ts +54 -0
  110. package/dist/properties-jlGW3USi.js +131 -0
  111. package/dist/python-USOwFDv_.js +279 -0
  112. package/dist/routing-CMqh1cTZ.d.ts +54 -0
  113. package/dist/routing-Wbb7YECB.js +194 -0
  114. package/dist/routing.d.ts +2 -0
  115. package/dist/routing.js +3 -180
  116. package/dist/ruby-CSvGbSLe.js +387 -0
  117. package/dist/sdk-BwXeHS3_.d.ts +118 -0
  118. package/dist/sdk-CSCbbn3O.js +336 -0
  119. package/dist/sdk-DXdNszcC.d.ts +118 -0
  120. package/dist/sidebar-CWyvCrJ0.js +81 -0
  121. package/dist/sidebar-DGGt5gik.d.ts +36 -0
  122. package/dist/sidebar-DfS6SWQz.d.ts +36 -0
  123. package/dist/snippets-BQLXEIf6.js +161 -0
  124. package/dist/snippets-BRs_4F1I.d.ts +51 -0
  125. package/dist/snippets-DxSMK50g.d.ts +51 -0
  126. package/dist/spec.d.ts +65 -0
  127. package/dist/spec.js +167 -0
  128. package/dist/style-D7RO5ymE.d.ts +168 -0
  129. package/dist/style-gnVEeXFj.js +169 -0
  130. package/dist/style.d.ts +2 -0
  131. package/dist/style.js +3 -0
  132. package/dist/styles/main.css +727 -754
  133. package/dist/styles/main.js +0 -0
  134. package/dist/styles/primitives.css +317 -461
  135. package/dist/styles/primitives.js +0 -0
  136. package/dist/styles/resets.css +32 -41
  137. package/dist/styles/resets.js +0 -0
  138. package/dist/styles/search.css +175 -274
  139. package/dist/styles/search.js +0 -0
  140. package/dist/styles/sidebar.css +59 -60
  141. package/dist/styles/sidebar.js +0 -0
  142. package/dist/styles/variables.css +26 -89
  143. package/dist/styles/variables.js +0 -0
  144. package/dist/styles.css +2910 -0
  145. package/dist/styles.mjs +1 -0
  146. package/dist/typescript-DXG9psK3.js +449 -0
  147. package/dist/use-components-RWQbviGq.js +7 -0
  148. package/dist/utils-BaLi5Bed.d.ts +21 -0
  149. package/dist/utils-CqnL9Fc3.js +31 -0
  150. package/dist/utils-D_1AWSRX.js +32 -0
  151. package/dist/utils-_AEBNJhG.d.ts +21 -0
  152. package/dist/utils-d8paVwKN.d.ts +14 -0
  153. package/dist/utils.d.ts +2 -0
  154. package/dist/utils.js +3 -0
  155. package/package.json +73 -21
  156. package/dist/mcp.js +0 -16003
  157. package/dist/styles/snippets.css +0 -132
  158. package/src/components/breadcrumbs.tsx +0 -94
  159. package/src/components/chat.tsx +0 -154
  160. package/src/components/dropdown.tsx +0 -91
  161. package/src/components/icons.tsx +0 -584
  162. package/src/components/index.ts +0 -9
  163. package/src/components/method.tsx +0 -144
  164. package/src/components/overview.tsx +0 -159
  165. package/src/components/primitives.tsx +0 -284
  166. package/src/components/properties.tsx +0 -130
  167. package/src/components/scripts/dropdown.ts +0 -78
  168. package/src/components/sdk.tsx +0 -402
  169. package/src/components/sidebar.tsx +0 -99
  170. package/src/components/snippets.tsx +0 -179
  171. package/src/contexts/component-generics.tsx +0 -48
  172. package/src/contexts/component-types.tsx +0 -5
  173. package/src/contexts/component.tsx +0 -32
  174. package/src/contexts/docs.tsx +0 -75
  175. package/src/contexts/index.tsx +0 -17
  176. package/src/contexts/markdown.tsx +0 -43
  177. package/src/contexts/navigation.tsx +0 -44
  178. package/src/contexts/search.tsx +0 -28
  179. package/src/contexts/use-components.tsx +0 -4
  180. package/src/index.ts +0 -6
  181. package/src/languages/go.tsx +0 -281
  182. package/src/languages/http.tsx +0 -321
  183. package/src/languages/index.ts +0 -26
  184. package/src/languages/java.tsx +0 -358
  185. package/src/languages/python.tsx +0 -255
  186. package/src/languages/ruby.tsx +0 -320
  187. package/src/languages/typescript.tsx +0 -393
  188. package/src/markdown/index.ts +0 -107
  189. package/src/markdown/md.ts +0 -45
  190. package/src/markdown/utils.ts +0 -49
  191. package/src/routing.ts +0 -238
  192. package/src/search/form.tsx +0 -127
  193. package/src/search/index.tsx +0 -1
  194. package/src/search/indexer.ts +0 -246
  195. package/src/search/mcp.ts +0 -61
  196. package/src/search/printer.tsx +0 -86
  197. package/src/search/providers/algolia.ts +0 -88
  198. package/src/search/providers/fuse.ts +0 -19
  199. package/src/search/providers/pagefind.ts +0 -17
  200. package/src/search/providers/walker.ts +0 -30
  201. package/src/search/results.tsx +0 -181
  202. package/src/search/state.ts +0 -64
  203. package/src/search/types.ts +0 -116
  204. package/src/style.ts +0 -197
  205. package/src/styles/main.css +0 -993
  206. package/src/styles/primitives.css +0 -573
  207. package/src/styles/resets.css +0 -47
  208. package/src/styles/search.css +0 -342
  209. package/src/styles/sidebar.css +0 -87
  210. package/src/styles/snippets.css +0 -132
  211. package/src/styles/variables.css +0 -90
  212. package/src/utils.ts +0 -41
@@ -1,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';