@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,86 +0,0 @@
1
- import * as React from 'react';
2
- import { renderToStaticMarkup } from 'react-dom/server';
3
- import type * as SDKJSON from '~/lib/json-spec-v2/types';
4
- import type { DocsLanguage } from '../routing';
5
-
6
- import { DocsProvider, useLanguageComponents } from '../contexts';
7
-
8
- import style from '../style';
9
- import { ComponentProvider } from '../contexts/component';
10
-
11
- type ProvidersProps = {
12
- language: DocsLanguage;
13
- children: React.ReactNode;
14
- };
15
-
16
- function Providers({ language, children }: ProvidersProps) {
17
- return (
18
- <DocsProvider spec={null} language={language}>
19
- <ComponentProvider
20
- components={{
21
- SDKReference({ stainlessPath, children }) {
22
- if (!stainlessPath) return children;
23
- return <span className={style.TypeReference}>{children}</span>;
24
- },
25
- }}
26
- >
27
- {children}
28
- </ComponentProvider>
29
- </DocsProvider>
30
- );
31
- }
32
-
33
- function RenderType({ type, full }: { type: SDKJSON.Type; full?: boolean }) {
34
- const { Type, TypeName } = useLanguageComponents();
35
- return full ? <Type type={type} /> : <TypeName type={type} />;
36
- }
37
-
38
- export function typeName(language: DocsLanguage, type: SDKJSON.Type) {
39
- const component = (
40
- <Providers language={language}>
41
- <RenderType type={type} />
42
- </Providers>
43
- );
44
-
45
- return renderToStaticMarkup(component);
46
- }
47
-
48
- export function type(language: DocsLanguage, type: SDKJSON.Type) {
49
- const component = (
50
- <Providers language={language}>
51
- <RenderType type={type} full={true} />
52
- </Providers>
53
- );
54
-
55
- return renderToStaticMarkup(component);
56
- }
57
-
58
- function RenderDeclaration({ decl }: { decl: SDKJSON.DeclarationNode }) {
59
- const { Declaration } = useLanguageComponents();
60
- return <Declaration decl={decl} />;
61
- }
62
-
63
- export function declaration(language: DocsLanguage, decl: SDKJSON.DeclarationNode) {
64
- const component = (
65
- <Providers language={language}>
66
- <RenderDeclaration decl={decl} />
67
- </Providers>
68
- );
69
-
70
- return renderToStaticMarkup(component);
71
- }
72
-
73
- function RenderMethod({ method }: { method: SDKJSON.DeclarationNode }) {
74
- const { MethodSignature } = useLanguageComponents();
75
- return <MethodSignature decl={method} />;
76
- }
77
-
78
- export function methodSignature(language: DocsLanguage, decl: SDKJSON.DeclarationNode) {
79
- const component = (
80
- <Providers language={language}>
81
- <RenderMethod method={decl} />
82
- </Providers>
83
- );
84
-
85
- return renderToStaticMarkup(component);
86
- }
@@ -1,88 +0,0 @@
1
- import { searchClient } from '@algolia/client-search';
2
- import { generateChatIndex, generateIndex } from '../indexer';
3
- import { SearchableAttributes, SearchableAttributesChat } from '../types';
4
- import type * as SDKJSON from '~/lib/json-spec-v2/types';
5
- import type { ResultRecordType, SearchSettings, SearchParams, ResultType } from '../types';
6
-
7
- export async function buildIndex(
8
- appId: string,
9
- indexName: string,
10
- writeKey: string,
11
- spec: SDKJSON.Spec,
12
- renderMarkdown: (string?) => string | null,
13
- ): Promise<void> {
14
- if (!appId || !indexName || !writeKey) return;
15
- const objects = Array.from(generateIndex(spec, renderMarkdown));
16
- const client = searchClient(appId, writeKey);
17
-
18
- await client.setSettings({
19
- indexName,
20
- indexSettings: {
21
- highlightPreTag: '<mark>',
22
- highlightPostTag: '</mark>',
23
- customRanking: ['asc(priority)'],
24
- attributesForFaceting: ['language', 'kind'],
25
- searchableAttributes: SearchableAttributes,
26
- },
27
- });
28
-
29
- await client.replaceAllObjects({ indexName, objects });
30
- }
31
-
32
- export async function buildChatIndex(
33
- appId: string,
34
- indexName: string,
35
- writeKey: string,
36
- spec: SDKJSON.Spec,
37
- ): Promise<void> {
38
- if (!appId || !indexName || !writeKey) return;
39
- const objects = Array.from(generateChatIndex(spec));
40
- const client = searchClient(appId, writeKey);
41
-
42
- await client.setSettings({
43
- indexName,
44
- indexSettings: {
45
- attributesForFaceting: ['language'],
46
- attributeForDistinct: 'stainlessPath',
47
- searchableAttributes: SearchableAttributesChat,
48
- },
49
- });
50
-
51
- await client.replaceAllObjects({ indexName, objects });
52
- }
53
-
54
- export async function search({
55
- settings: { appId, indexName, searchKey },
56
- params: { query, language, kind },
57
- }: {
58
- params: SearchParams;
59
- settings: SearchSettings;
60
- }): Promise<ResultType | undefined> {
61
- const client = searchClient(appId, searchKey);
62
- const filters = language ? `language:${language}` : undefined;
63
- const facetFilters = kind ? [`kind:${kind}`] : undefined;
64
- const { results } = await client.search<ResultRecordType>({
65
- requests: [
66
- {
67
- query,
68
- indexName,
69
- filters,
70
- hitsPerPage: 5,
71
- facets: ['kind'],
72
- },
73
- {
74
- query,
75
- indexName,
76
- filters,
77
- facetFilters,
78
- facets: ['kind'],
79
- hitsPerPage: 50,
80
- },
81
- ],
82
- });
83
-
84
- if ('hits' in results[0] && 'hits' in results[1]) {
85
- const [{ nbHits, facets }, { hits }] = results;
86
- return { hits, nbHits, facets };
87
- }
88
- }
@@ -1,19 +0,0 @@
1
- import Fuse, { FuseIndex } from 'fuse.js';
2
- import { DocsLanguage } from '../../routing';
3
- import { generateIndex } from '../indexer';
4
- import { IndexEntry, SearchableAttributes } from '../types';
5
- import type * as SDKJSON from '~/lib/json-spec-v2/types';
6
-
7
- export type FuseIndexData = { content: IndexEntry[]; index: FuseIndex<IndexEntry> };
8
-
9
- export function buildIndex(spec: SDKJSON.Spec, language?: DocsLanguage): FuseIndexData {
10
- const idx = Array.from(generateIndex(spec, null, false));
11
- const content = language ? idx.filter((entry) => entry.language === language) : idx;
12
- const index = Fuse.createIndex(SearchableAttributes, content);
13
- return { content, index };
14
- }
15
-
16
- export function search({ content, index }: FuseIndexData, query: string, limit: number = 100) {
17
- const fuse = new Fuse(content, { keys: SearchableAttributes }, index);
18
- return fuse.search(query).slice(0, limit);
19
- }
@@ -1,17 +0,0 @@
1
- import type { GuideResultType } from '../types';
2
-
3
- async function loadPagefind(path: string) {
4
- const url = new URL(path, import.meta.url).href;
5
- return await import(/* @vite-ignore */ url);
6
- }
7
-
8
- export async function guideSearch(
9
- loadPath: string,
10
- query: string,
11
- limit?: number,
12
- ): Promise<GuideResultType[]> {
13
- const index = await loadPagefind(loadPath);
14
- const response = await index.search(query);
15
- const items = limit ? response.results.slice(0, limit) : response.results;
16
- return Promise.all(items.map((result) => result.data().then((data) => ({ ...result, data }))));
17
- }
@@ -1,30 +0,0 @@
1
- import { DocsLanguage } from '../../routing';
2
- import { generateIndex } from '../indexer';
3
- import { IndexEntry, SearchableAttributes } from '../types';
4
- import type * as SDKJSON from '~/lib/json-spec-v2/types';
5
-
6
- export function buildIndex(spec: SDKJSON.Spec) {
7
- return generateIndex(spec, null, false);
8
- }
9
-
10
- function* findEntryInIndex(index: Generator<IndexEntry>, language: string, query: string) {
11
- for (const entry of index) {
12
- if (entry.language !== language) continue;
13
- for (const attr of SearchableAttributes) {
14
- if (entry[attr] && typeof entry[attr] === 'string' && entry[attr].includes(query)) yield entry;
15
- }
16
- }
17
- }
18
-
19
- export function search(
20
- index: Generator<IndexEntry>,
21
- language: DocsLanguage,
22
- query: string,
23
- limit: number = 100,
24
- ) {
25
- const results = findEntryInIndex(index, language, query);
26
- const sorted = Array.from(results)
27
- .sort((a, b) => a.priority - b.priority)
28
- .slice(0, limit);
29
- return sorted;
30
- }
@@ -1,181 +0,0 @@
1
- import { Folder, Box, Code, Wrench, BookOpenText, Search } from 'lucide-react';
2
- import { useLanguage } from '../contexts';
3
- import { useComponents } from '../contexts/use-components';
4
- import { GuideResultType, QueryKindsType, ResultRecordType, SearchAttributeNames } from './types';
5
-
6
- import style from '../style';
7
-
8
- export const QueryKindDisplay: Record<QueryKindsType, { name: string; icon: typeof Folder }> = {
9
- all: { name: 'Results', icon: Search },
10
- resource: { name: 'Resources', icon: Folder },
11
- http_method: { name: 'Methods', icon: Box },
12
- model: { name: 'Types', icon: Code },
13
- property: { name: 'Properties', icon: Wrench },
14
- guide: { name: 'Guide', icon: BookOpenText },
15
- };
16
-
17
- export type HighlightProps = {
18
- result: ResultRecordType;
19
- name: SearchAttributeNames;
20
- };
21
-
22
- export function Highlight({ result, name }: HighlightProps) {
23
- const value = result._highlightResult[name]?.value;
24
- if (value) return <span dangerouslySetInnerHTML={{ __html: value }} />;
25
- }
26
-
27
- export type SearchResultProps = {
28
- result: ResultRecordType;
29
- };
30
-
31
- export function SearchResultBreadcrumb({ result }: SearchResultProps) {
32
- const Docs = useComponents();
33
- const Icon = QueryKindDisplay[result.kind].icon;
34
- const items = result.crumbs?.map((crumb) => (
35
- <span key={crumb} className={style.SearchBreadcrumbItem}>
36
- {crumb}
37
- </span>
38
- ));
39
-
40
- return (
41
- <div className={style.SearchBreadcrumb}>
42
- <Icon className={style.Icon} size={14} />
43
- {Array.isArray(result.crumbs) && (
44
- <Docs.Join items={items}>
45
- <span className={style.SearchBreadcrumbDivider}>{'›'}</span>
46
- </Docs.Join>
47
- )}
48
- </div>
49
- );
50
- }
51
-
52
- export function SearchResult({ result }: SearchResultProps) {
53
- return (
54
- <div className={style.SearchResult} data-stldocs-search-result={result.kind}>
55
- <SearchResultBreadcrumb result={result} />
56
- <SearchResultContent result={result} />
57
- </div>
58
- );
59
- }
60
-
61
- export type GuideResultProps = {
62
- result: GuideResultType;
63
- };
64
-
65
- export function GuideResult({ result }: GuideResultProps) {
66
- const Docs = useComponents();
67
- const Icon = QueryKindDisplay['guide'].icon;
68
- const path = result.data.url
69
- .slice(1, -1)
70
- .split('/')
71
- .map((crumb) => (
72
- <span className={style.SearchBreadcrumbItem} key={crumb}>
73
- {crumb}
74
- </span>
75
- ));
76
-
77
- const crumbs =
78
- path.length > 1
79
- ? path
80
- : [
81
- <span className={style.SearchBreadcrumbItem} key="overview">
82
- Overview
83
- </span>,
84
- ];
85
-
86
- return (
87
- <div className={style.SearchResult} data-stldocs-search-result="guide">
88
- <div className={style.SearchBreadcrumb}>
89
- <Icon className={style.Icon} size={14} />
90
- <Docs.Join items={crumbs}>
91
- <span className={style.SearchBreadcrumbDivider}>{'›'}</span>
92
- </Docs.Join>
93
- </div>
94
- <h3 className={style.SearchResultGuideTitle}>{result.data.meta.title}</h3>
95
- <div
96
- className={style.SearchResultGuideExcerpt}
97
- dangerouslySetInnerHTML={{ __html: result.data.excerpt }}
98
- />
99
- </div>
100
- );
101
- }
102
-
103
- export function SearchResultContent({ result }: SearchResultProps) {
104
- const Docs = useComponents();
105
- const language = useLanguage();
106
-
107
- switch (result.kind) {
108
- case 'http_method':
109
- return (
110
- <>
111
- <Docs.MethodHeader
112
- title={<Highlight result={result} name={result.summary ? 'summary' : 'title'} />}
113
- signature={result['qualified'] && <Highlight result={result} name={'qualified'} />}
114
- >
115
- <Docs.MethodRoute
116
- httpMethod={result.httpMethod}
117
- endpoint={<Highlight result={result} name="endpoint" />}
118
- />
119
- </Docs.MethodHeader>
120
- <div className={style.MethodDescription}>
121
- <Highlight result={result} name="description" />
122
- </div>
123
- </>
124
- );
125
-
126
- case 'model': {
127
- const properties = result.children.map((child, index) => (
128
- <span key={index} className={style.TextIdentifier}>
129
- {child}
130
- </span>
131
- ));
132
-
133
- return (
134
- <div className={style.Property} data-stldocs-language={language}>
135
- <div className={style.PropertyHeader}>
136
- <span className={style.PropertyName}>
137
- <Highlight result={result} name={result.title ? 'title' : 'name'} />
138
- </span>
139
- </div>
140
- <span className={style.PropertyDeclaration}>
141
- <Highlight result={result} name="ident" />:{' '}
142
- <Docs.Join items={properties} limit={3}>
143
- <span className={style.TextPunctuation}>, </span>
144
- </Docs.Join>
145
- </span>
146
- </div>
147
- );
148
- }
149
-
150
- case 'resource':
151
- return (
152
- <div className={style.SearchResultResourceInfo}>
153
- <span className={style.SearchResultResourceTitle}>
154
- <Highlight result={result} name="title" />
155
- </span>
156
- <span className={style.SearchResultResourcePath}>
157
- <Highlight result={result} name="QualifiedName" />
158
- </span>
159
- </div>
160
- );
161
-
162
- case 'property':
163
- return (
164
- <div className={style.Property} data-stldocs-language={language}>
165
- <div className={style.PropertyHeader}>
166
- <span className={style.PropertyName}>
167
- <Highlight result={result} name="name" />
168
- </span>
169
- <span className={style.PropertyTypeName}>
170
- <span dangerouslySetInnerHTML={{ __html: result.type }} />
171
- </span>
172
- </div>
173
- {result.docstring && (
174
- <span className={style.PropertyDescription}>
175
- <Highlight result={result} name="docstring" />
176
- </span>
177
- )}
178
- </div>
179
- );
180
- }
181
- }
@@ -1,64 +0,0 @@
1
- import { useReducer } from 'react';
2
- import { QueryKindsType, ResultRecordType } from './types';
3
-
4
- export type SearchReducerState = {
5
- results: ResultRecordType[];
6
- resultsCount: number;
7
- filterKind?: QueryKindsType;
8
- filterKindCount?: Record<QueryKindsType, number>;
9
- keyboardSelection?: number;
10
- selectedIndex: number;
11
- searchQuery: string;
12
- };
13
-
14
- export type SearchReducerAction =
15
- | { action: 'DecrementSelection' }
16
- | { action: 'IncrementSelection' }
17
- | { action: 'SetSelectedIndex'; selectedIndex: number }
18
- | { action: 'SetFilterKind'; filterKind: QueryKindsType }
19
- | { action: 'UpdateQuery'; searchQuery: string }
20
- | ({ action: 'UpdateResults' } & Pick<SearchReducerState, 'results' | 'resultsCount' | 'filterKindCount'>);
21
-
22
- export const SearchReducerDefaults: SearchReducerState = {
23
- results: [],
24
- resultsCount: 0,
25
- selectedIndex: 0,
26
- searchQuery: '',
27
- };
28
-
29
- export function searchReducer(state: SearchReducerState, op: SearchReducerAction): SearchReducerState {
30
- switch (op.action) {
31
- case 'IncrementSelection': {
32
- const value = Math.min(state.resultsCount, state.selectedIndex + 1);
33
- return { ...state, selectedIndex: value, keyboardSelection: value };
34
- }
35
-
36
- case 'DecrementSelection': {
37
- const value = Math.max(0, state.selectedIndex - 1);
38
- return { ...state, selectedIndex: value, keyboardSelection: value };
39
- }
40
-
41
- case 'SetSelectedIndex':
42
- return { ...state, selectedIndex: op.selectedIndex };
43
-
44
- case 'SetFilterKind':
45
- return { ...state, filterKind: op.filterKind };
46
-
47
- case 'UpdateQuery':
48
- return { ...state, searchQuery: op.searchQuery };
49
-
50
- case 'UpdateResults':
51
- return {
52
- ...state,
53
- results: op.results,
54
- resultsCount: op.resultsCount,
55
- filterKindCount: op.filterKindCount,
56
- keyboardSelection: undefined,
57
- selectedIndex: 0,
58
- };
59
- }
60
- }
61
-
62
- export function useSearchReducer() {
63
- return useReducer(searchReducer, SearchReducerDefaults);
64
- }
@@ -1,116 +0,0 @@
1
- import type * as SDKJSON from '~/lib/json-spec-v2/types';
2
- import { DocsLanguage } from '../routing';
3
-
4
- export type SearchSettings = {
5
- appId: string;
6
- searchKey: string;
7
- indexName: string;
8
- assistant?: string;
9
- };
10
-
11
- export type SearchParams = {
12
- query: string;
13
- language?: DocsLanguage | null;
14
- kind?: QueryKindsType | null;
15
- };
16
-
17
- export const QueryKinds = ['all', 'resource', 'http_method', 'model', 'property', 'guide'] as const;
18
-
19
- export type QueryKindsType = (typeof QueryKinds)[number];
20
-
21
- export type IndexModel = {
22
- kind: 'model';
23
- title: string;
24
- children?: string[];
25
- ident?: string;
26
- };
27
-
28
- export type IndexProperty = {
29
- kind: 'property';
30
- docstring?: string;
31
- type?: string;
32
- };
33
-
34
- export type IndexResource = {
35
- kind: 'resource';
36
- title: string;
37
- Name: string;
38
- QualifiedName: string;
39
- };
40
-
41
- export type IndexMethod = Pick<
42
- SDKJSON.Method,
43
- 'kind' | 'summary' | 'description' | 'endpoint' | 'httpMethod'
44
- > & {
45
- title: string;
46
- qualified?: string;
47
- ident?: string;
48
- };
49
-
50
- export const SearchableAttributes = [
51
- 'name',
52
- 'title',
53
- 'ident',
54
- 'Name',
55
- 'qualified',
56
- 'QualifiedName',
57
- 'endpoint',
58
- 'summary',
59
- 'description',
60
- 'docstring',
61
- ];
62
-
63
- export const SearchableAttributesChat = [
64
- 'title',
65
- 'name',
66
- 'endpoint',
67
- 'summary',
68
- 'description',
69
- 'qualified',
70
- 'ident',
71
- 'content',
72
- ];
73
-
74
- export type SearchAttributeNames = (typeof SearchableAttributes)[number];
75
-
76
- export type RoutableJsonNode = SDKJSON.Method | SDKJSON.Model | SDKJSON.Resource;
77
-
78
- export type IndexEntry = Pick<RoutableJsonNode, 'name' | 'stainlessPath'> &
79
- (IndexProperty | IndexModel | IndexResource | IndexMethod) & {
80
- language: DocsLanguage;
81
- priority: number;
82
- crumbs: string[];
83
- };
84
-
85
- export type ResultRecordType = IndexEntry & {
86
- objectID: string;
87
- _highlightResult: Record<SearchAttributeNames, { value: string }>;
88
- };
89
-
90
- export type ResultType = {
91
- hits: ResultRecordType[];
92
- facets?: Record<string, Record<string, number>>;
93
- nbHits: number;
94
- };
95
-
96
- export type GuideResultType = {
97
- id: string;
98
- score: number;
99
- words: number[];
100
- data: {
101
- excerpt: string;
102
- url: string;
103
- word_count: number;
104
- meta: { title: string };
105
- sub_results: {
106
- url: string;
107
- title: string;
108
- excerpt: string;
109
- }[];
110
- };
111
- };
112
-
113
- export type ResultData = {
114
- items: Array<ResultRecordType | GuideResultType>;
115
- counts: Partial<Record<QueryKindsType, number>>;
116
- };