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