@stainless-api/docs-ui 0.1.0-beta.4 → 0.1.0-beta.40

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 (188) hide show
  1. package/dist/breadcrumbs-CZg0Fk4V.d.ts +20 -0
  2. package/dist/chunk-Bf_Gc_jT.js +18 -0
  3. package/dist/component-generics-BLXXX1dz.d.ts +30 -0
  4. package/dist/component-generics-D3ybuN5r.js +45 -0
  5. package/dist/components/breadcrumbs.d.ts +2 -0
  6. package/dist/components/breadcrumbs.js +15 -0
  7. package/dist/components/icons.d.ts +50 -0
  8. package/dist/components/icons.js +3 -0
  9. package/dist/components/index.d.ts +11 -0
  10. package/dist/components/index.js +15 -0
  11. package/dist/components/method.d.ts +2 -0
  12. package/dist/components/method.js +15 -0
  13. package/dist/components/overview.d.ts +2 -0
  14. package/dist/components/overview.js +15 -0
  15. package/dist/components/primitives.d.ts +2 -0
  16. package/dist/components/primitives.js +15 -0
  17. package/dist/components/properties.d.ts +2 -0
  18. package/dist/components/properties.js +15 -0
  19. package/dist/components/sdk.d.ts +3 -0
  20. package/dist/components/sdk.js +15 -0
  21. package/dist/components/sidebar.d.ts +2 -0
  22. package/dist/components/sidebar.js +15 -0
  23. package/dist/components/snippets.d.ts +4 -0
  24. package/dist/components/snippets.js +15 -0
  25. package/dist/contexts/component-generics.d.ts +2 -0
  26. package/dist/contexts/component-generics.js +3 -0
  27. package/dist/contexts/component-types.d.ts +17 -0
  28. package/dist/contexts/component-types.js +0 -0
  29. package/dist/contexts/component.d.ts +30 -0
  30. package/dist/contexts/component.js +15 -0
  31. package/dist/contexts/docs.d.ts +2 -0
  32. package/dist/contexts/docs.js +3 -0
  33. package/dist/contexts/index.d.ts +19 -0
  34. package/dist/contexts/index.js +15 -0
  35. package/dist/contexts/markdown.d.ts +2 -0
  36. package/dist/contexts/markdown.js +4 -0
  37. package/dist/contexts/navigation.d.ts +3 -0
  38. package/dist/contexts/navigation.js +3 -0
  39. package/dist/contexts/search.d.ts +4 -0
  40. package/dist/contexts/search.js +15 -0
  41. package/dist/contexts/use-components.d.ts +15 -0
  42. package/dist/contexts/use-components.js +4 -0
  43. package/dist/contexts-B-OYzYpz.js +3837 -0
  44. package/dist/docs-BeJaKOCE.d.ts +46 -0
  45. package/dist/docs-CopwX9a7.js +54 -0
  46. package/dist/icons-yb-Jhkmg.js +753 -0
  47. package/dist/index-CBi59jcw.d.ts +240 -0
  48. package/dist/index-DT1wzg21.d.ts +15 -0
  49. package/dist/index-DteYqCJO.d.ts +14 -0
  50. package/dist/index.d.ts +21 -0
  51. package/dist/index.js +15 -7542
  52. package/dist/languages/go.d.ts +12 -0
  53. package/dist/languages/go.js +15 -0
  54. package/dist/languages/http.d.ts +12 -0
  55. package/dist/languages/http.js +15 -0
  56. package/dist/languages/index.d.ts +12 -0
  57. package/dist/languages/index.js +15 -0
  58. package/dist/languages/java.d.ts +12 -0
  59. package/dist/languages/java.js +15 -0
  60. package/dist/languages/python.d.ts +12 -0
  61. package/dist/languages/python.js +15 -0
  62. package/dist/languages/ruby.d.ts +12 -0
  63. package/dist/languages/ruby.js +15 -0
  64. package/dist/languages/typescript.d.ts +12 -0
  65. package/dist/languages/typescript.js +15 -0
  66. package/dist/markdown/index.d.ts +12 -0
  67. package/dist/markdown/index.js +15 -0
  68. package/dist/markdown/md.d.ts +15 -0
  69. package/dist/markdown/md.js +3 -0
  70. package/dist/markdown/utils.d.ts +4 -0
  71. package/dist/markdown/utils.js +3 -0
  72. package/dist/markdown-DTVxnxGP.d.ts +22 -0
  73. package/dist/markdown-Diyg-eof.js +48 -0
  74. package/dist/md-DxiV1_vy.js +41 -0
  75. package/dist/method-DHjDGGA_.d.ts +71 -0
  76. package/dist/navigation-CGr5_w6z.js +24 -0
  77. package/dist/navigation-rt_B_1lt.d.ts +29 -0
  78. package/dist/overview-CKJV2xUO.d.ts +39 -0
  79. package/dist/pagefind-BaK1krMe.js +15 -0
  80. package/dist/primitives-CiVFjnRA.d.ts +99 -0
  81. package/dist/properties-Z45x-uLZ.d.ts +46 -0
  82. package/dist/routing-DNN8R6bZ.d.ts +54 -0
  83. package/dist/routing-qs2YNG9o.js +189 -0
  84. package/dist/routing.d.ts +2 -0
  85. package/dist/routing.js +3 -180
  86. package/dist/sdk-DDWWoPPD.d.ts +119 -0
  87. package/dist/search/index.d.ts +26 -0
  88. package/dist/search/index.js +334 -0
  89. package/dist/search/providers/algolia.d.ts +24 -0
  90. package/dist/search/providers/algolia.js +15 -0
  91. package/dist/search/providers/fuse.d.ts +18 -0
  92. package/dist/search/providers/fuse.js +30 -0
  93. package/dist/search/providers/pagefind.d.ts +7 -0
  94. package/dist/search/providers/pagefind.js +3 -0
  95. package/dist/search/providers/walker.d.ts +9 -0
  96. package/dist/search/providers/walker.js +34 -0
  97. package/dist/search/types.d.ts +3 -0
  98. package/dist/search/types.js +3 -0
  99. package/dist/search-CCDWCiAd.d.ts +21 -0
  100. package/dist/sidebar-DrtsF85U.d.ts +36 -0
  101. package/dist/snippets-B2EEG7AK.d.ts +46 -0
  102. package/dist/spec.d.ts +65 -0
  103. package/dist/spec.js +167 -0
  104. package/dist/style-BhhgPVF6.js +165 -0
  105. package/dist/style-p4qTfnmO.d.ts +164 -0
  106. package/dist/style.d.ts +2 -0
  107. package/dist/style.js +3 -0
  108. package/dist/styles/main.css +724 -754
  109. package/dist/styles/main.js +0 -0
  110. package/dist/styles/primitives.css +287 -466
  111. package/dist/styles/primitives.js +0 -0
  112. package/dist/styles/resets.css +31 -41
  113. package/dist/styles/resets.js +0 -0
  114. package/dist/styles/search.css +175 -274
  115. package/dist/styles/search.js +0 -0
  116. package/dist/styles/sidebar.css +59 -60
  117. package/dist/styles/sidebar.js +0 -0
  118. package/dist/styles/variables.css +26 -89
  119. package/dist/styles/variables.js +0 -0
  120. package/dist/styles.css +1753 -0
  121. package/dist/styles.mjs +1 -0
  122. package/dist/types-DNSz4kuM.d.ts +83 -0
  123. package/dist/types-__XoFvJ_.js +34 -0
  124. package/dist/use-components-BHEwm0mE.js +7 -0
  125. package/dist/utils-CA3mYNaX.d.ts +21 -0
  126. package/dist/utils-D43p_yTd.d.ts +14 -0
  127. package/dist/utils-FnJ4tyuN.js +32 -0
  128. package/dist/utils-Jo_o4DX9.js +31 -0
  129. package/dist/utils.d.ts +2 -0
  130. package/dist/utils.js +4 -0
  131. package/package.json +84 -19
  132. package/dist/mcp.js +0 -16003
  133. package/dist/styles/snippets.css +0 -132
  134. package/src/components/breadcrumbs.tsx +0 -94
  135. package/src/components/chat.tsx +0 -154
  136. package/src/components/dropdown.tsx +0 -91
  137. package/src/components/icons.tsx +0 -584
  138. package/src/components/index.ts +0 -9
  139. package/src/components/method.tsx +0 -144
  140. package/src/components/overview.tsx +0 -159
  141. package/src/components/primitives.tsx +0 -284
  142. package/src/components/properties.tsx +0 -130
  143. package/src/components/scripts/dropdown.ts +0 -78
  144. package/src/components/sdk.tsx +0 -402
  145. package/src/components/sidebar.tsx +0 -99
  146. package/src/components/snippets.tsx +0 -179
  147. package/src/contexts/component-generics.tsx +0 -48
  148. package/src/contexts/component-types.tsx +0 -5
  149. package/src/contexts/component.tsx +0 -32
  150. package/src/contexts/docs.tsx +0 -75
  151. package/src/contexts/index.tsx +0 -17
  152. package/src/contexts/markdown.tsx +0 -43
  153. package/src/contexts/navigation.tsx +0 -44
  154. package/src/contexts/search.tsx +0 -28
  155. package/src/contexts/use-components.tsx +0 -4
  156. package/src/index.ts +0 -6
  157. package/src/languages/go.tsx +0 -281
  158. package/src/languages/http.tsx +0 -321
  159. package/src/languages/index.ts +0 -26
  160. package/src/languages/java.tsx +0 -358
  161. package/src/languages/python.tsx +0 -255
  162. package/src/languages/ruby.tsx +0 -320
  163. package/src/languages/typescript.tsx +0 -393
  164. package/src/markdown/index.ts +0 -107
  165. package/src/markdown/md.ts +0 -45
  166. package/src/markdown/utils.ts +0 -49
  167. package/src/routing.ts +0 -238
  168. package/src/search/form.tsx +0 -127
  169. package/src/search/index.tsx +0 -1
  170. package/src/search/indexer.ts +0 -246
  171. package/src/search/mcp.ts +0 -61
  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 -30
  177. package/src/search/results.tsx +0 -181
  178. package/src/search/state.ts +0 -64
  179. package/src/search/types.ts +0 -116
  180. package/src/style.ts +0 -197
  181. package/src/styles/main.css +0 -993
  182. package/src/styles/primitives.css +0 -572
  183. package/src/styles/resets.css +0 -47
  184. package/src/styles/search.css +0 -342
  185. package/src/styles/sidebar.css +0 -87
  186. package/src/styles/snippets.css +0 -132
  187. package/src/styles/variables.css +0 -90
  188. 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';