@stainless-api/docs-ui 0.1.0-beta.5 → 0.1.0-beta.51
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.
- package/dist/breadcrumbs-BdYnaHA8.d.ts +20 -0
- package/dist/breadcrumbs-CA7GmW_8.d.ts +20 -0
- package/dist/breadcrumbs-nSFZO5Gf.js +63 -0
- package/dist/chunk-DRcLgZ1e.js +18 -0
- package/dist/component-DRO8kQSp.js +23 -0
- package/dist/component-generics-B6Fn47Mz.js +45 -0
- package/dist/component-generics-BHFUK06s.d.ts +30 -0
- package/dist/component-generics-BJSyydZ-.d.ts +30 -0
- package/dist/components/MaskedInput.d.ts +14 -0
- package/dist/components/MaskedInput.js +76 -0
- package/dist/components/breadcrumbs.d.ts +2 -0
- package/dist/components/breadcrumbs.js +9 -0
- package/dist/components/icons.d.ts +55 -0
- package/dist/components/icons.js +3 -0
- package/dist/components/index.d.ts +10 -0
- package/dist/components/index.js +18 -0
- package/dist/components/method.d.ts +2 -0
- package/dist/components/method.js +10 -0
- package/dist/components/overview.d.ts +2 -0
- package/dist/components/overview.js +11 -0
- package/dist/components/primitives.d.ts +2 -0
- package/dist/components/primitives.js +8 -0
- package/dist/components/properties.d.ts +2 -0
- package/dist/components/properties.js +9 -0
- package/dist/components/sdk.d.ts +2 -0
- package/dist/components/sdk.js +10 -0
- package/dist/components/sidebar.d.ts +2 -0
- package/dist/components/sidebar.js +11 -0
- package/dist/components/snippets.d.ts +3 -0
- package/dist/components/snippets.js +9 -0
- package/dist/components-D7M-BwNI.js +71 -0
- package/dist/contexts/component-generics.d.ts +2 -0
- package/dist/contexts/component-generics.js +3 -0
- package/dist/contexts/component-types.d.ts +16 -0
- package/dist/contexts/component-types.js +0 -0
- package/dist/contexts/component.d.ts +29 -0
- package/dist/contexts/component.js +27 -0
- package/dist/contexts/docs.d.ts +2 -0
- package/dist/contexts/docs.js +3 -0
- package/dist/contexts/index.d.ts +16 -0
- package/dist/contexts/index.js +7 -0
- package/dist/contexts/markdown.d.ts +2 -0
- package/dist/contexts/markdown.js +4 -0
- package/dist/contexts/navigation.d.ts +2 -0
- package/dist/contexts/navigation.js +3 -0
- package/dist/contexts/use-components.d.ts +14 -0
- package/dist/contexts/use-components.js +4 -0
- package/dist/contexts-p3rRZDlM.js +39 -0
- package/dist/csharp-CDSxfCZE.js +283 -0
- package/dist/docs-BUS__I1m.d.ts +47 -0
- package/dist/docs-CXqi26jB.js +54 -0
- package/dist/docs-fKyo35eI.d.ts +47 -0
- package/dist/go-1c3S5ETL.js +303 -0
- package/dist/http-2QNWXH9t.js +330 -0
- package/dist/icons-Ckod9aod.js +869 -0
- package/dist/index-5Yl-BBg3.d.ts +15 -0
- package/dist/index-9LRO8R1a.d.ts +274 -0
- package/dist/index-CBIJwoyp.d.ts +13 -0
- package/dist/index-ClCZKGcw.d.ts +274 -0
- package/dist/index-pMKpm2Jk.d.ts +13 -0
- package/dist/index-q3bZhNWj.d.ts +15 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +29 -7542
- package/dist/java-BbjF_oUI.js +403 -0
- package/dist/languages/csharp.d.ts +11 -0
- package/dist/languages/csharp.js +9 -0
- package/dist/languages/go.d.ts +11 -0
- package/dist/languages/go.js +9 -0
- package/dist/languages/http.d.ts +11 -0
- package/dist/languages/http.js +19 -0
- package/dist/languages/index.d.ts +11 -0
- package/dist/languages/index.js +26 -0
- package/dist/languages/java.d.ts +11 -0
- package/dist/languages/java.js +9 -0
- package/dist/languages/python.d.ts +11 -0
- package/dist/languages/python.js +9 -0
- package/dist/languages/ruby.d.ts +11 -0
- package/dist/languages/ruby.js +9 -0
- package/dist/languages/typescript.d.ts +11 -0
- package/dist/languages/typescript.js +9 -0
- package/dist/languages-BCYZjzuS.js +26 -0
- package/dist/markdown/index.d.ts +12 -0
- package/dist/markdown/index.js +104 -0
- package/dist/markdown/md.d.ts +15 -0
- package/dist/markdown/md.js +3 -0
- package/dist/markdown/printer.d.ts +2 -0
- package/dist/markdown/printer.js +28 -0
- package/dist/markdown/utils.d.ts +3 -0
- package/dist/markdown/utils.js +3 -0
- package/dist/markdown-C8o8WrwG.d.ts +22 -0
- package/dist/markdown-CqJohZei.d.ts +22 -0
- package/dist/markdown-CxdeWgjV.js +48 -0
- package/dist/md-oM2tUaCA.js +41 -0
- package/dist/method-CE08mUME.js +115 -0
- package/dist/method-CMt6uyix.d.ts +71 -0
- package/dist/method-r5UAB40b.d.ts +71 -0
- package/dist/navigation-9_4wRkcT.d.ts +29 -0
- package/dist/navigation-C5TN0SgC.js +24 -0
- package/dist/navigation-zuoWsXzh.d.ts +29 -0
- package/dist/overview-DXmLmmr7.d.ts +39 -0
- package/dist/overview-S2hUqPXA.js +139 -0
- package/dist/overview-ixhAhHj8.d.ts +39 -0
- package/dist/primitives-BIWfwN5L.js +258 -0
- package/dist/primitives-BVXfSSiS.d.ts +97 -0
- package/dist/primitives-Bl0wzAGo.d.ts +97 -0
- package/dist/printer-DBw4S_Jn.d.ts +13 -0
- package/dist/printer-bNxiG6UB.js +74 -0
- package/dist/properties-C-NU_ghj.d.ts +54 -0
- package/dist/properties-GT9ixNTg.d.ts +54 -0
- package/dist/properties-jlGW3USi.js +131 -0
- package/dist/python-USOwFDv_.js +279 -0
- package/dist/routing-CMqh1cTZ.d.ts +54 -0
- package/dist/routing-Wbb7YECB.js +194 -0
- package/dist/routing.d.ts +2 -0
- package/dist/routing.js +3 -180
- package/dist/ruby-CSvGbSLe.js +387 -0
- package/dist/sdk-B5W3VipN.d.ts +118 -0
- package/dist/sdk-CS6A3HW3.d.ts +118 -0
- package/dist/sdk-CSCbbn3O.js +336 -0
- package/dist/sidebar-C3fZrgmP.d.ts +36 -0
- package/dist/sidebar-CWyvCrJ0.js +81 -0
- package/dist/sidebar-CbCLUteD.d.ts +36 -0
- package/dist/snippets-BQLXEIf6.js +161 -0
- package/dist/snippets-C72s2IwS.d.ts +51 -0
- package/dist/snippets-DcFph7ir.d.ts +51 -0
- package/dist/spec.d.ts +65 -0
- package/dist/spec.js +167 -0
- package/dist/style-D7RO5ymE.d.ts +168 -0
- package/dist/style-gnVEeXFj.js +169 -0
- package/dist/style.d.ts +2 -0
- package/dist/style.js +3 -0
- package/dist/styles/main.css +727 -754
- package/dist/styles/main.js +0 -0
- package/dist/styles/primitives.css +317 -461
- package/dist/styles/primitives.js +0 -0
- package/dist/styles/resets.css +32 -41
- package/dist/styles/resets.js +0 -0
- package/dist/styles/search.css +175 -274
- package/dist/styles/search.js +0 -0
- package/dist/styles/sidebar.css +59 -60
- package/dist/styles/sidebar.js +0 -0
- package/dist/styles/variables.css +26 -89
- package/dist/styles/variables.js +0 -0
- package/dist/styles.css +2910 -0
- package/dist/styles.mjs +1 -0
- package/dist/typescript-DXG9psK3.js +449 -0
- package/dist/use-components-RWQbviGq.js +7 -0
- package/dist/utils-CqnL9Fc3.js +31 -0
- package/dist/utils-DGnJ6mcU.d.ts +21 -0
- package/dist/utils-D_1AWSRX.js +32 -0
- package/dist/utils-d8paVwKN.d.ts +14 -0
- package/dist/utils-uQbtk0-_.d.ts +21 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +3 -0
- package/package.json +73 -21
- package/dist/mcp.js +0 -16003
- package/dist/styles/snippets.css +0 -132
- package/src/components/breadcrumbs.tsx +0 -94
- package/src/components/chat.tsx +0 -154
- package/src/components/dropdown.tsx +0 -91
- package/src/components/icons.tsx +0 -584
- package/src/components/index.ts +0 -9
- package/src/components/method.tsx +0 -144
- package/src/components/overview.tsx +0 -159
- package/src/components/primitives.tsx +0 -284
- package/src/components/properties.tsx +0 -130
- package/src/components/scripts/dropdown.ts +0 -78
- package/src/components/sdk.tsx +0 -402
- package/src/components/sidebar.tsx +0 -99
- package/src/components/snippets.tsx +0 -179
- package/src/contexts/component-generics.tsx +0 -48
- package/src/contexts/component-types.tsx +0 -5
- package/src/contexts/component.tsx +0 -32
- package/src/contexts/docs.tsx +0 -75
- package/src/contexts/index.tsx +0 -17
- package/src/contexts/markdown.tsx +0 -43
- package/src/contexts/navigation.tsx +0 -44
- package/src/contexts/search.tsx +0 -28
- package/src/contexts/use-components.tsx +0 -4
- package/src/index.ts +0 -6
- package/src/languages/go.tsx +0 -281
- package/src/languages/http.tsx +0 -321
- package/src/languages/index.ts +0 -26
- package/src/languages/java.tsx +0 -358
- package/src/languages/python.tsx +0 -255
- package/src/languages/ruby.tsx +0 -320
- package/src/languages/typescript.tsx +0 -393
- package/src/markdown/index.ts +0 -107
- package/src/markdown/md.ts +0 -45
- package/src/markdown/utils.ts +0 -49
- package/src/routing.ts +0 -238
- package/src/search/form.tsx +0 -127
- package/src/search/index.tsx +0 -1
- package/src/search/indexer.ts +0 -246
- package/src/search/mcp.ts +0 -61
- package/src/search/printer.tsx +0 -86
- package/src/search/providers/algolia.ts +0 -88
- package/src/search/providers/fuse.ts +0 -19
- package/src/search/providers/pagefind.ts +0 -17
- package/src/search/providers/walker.ts +0 -30
- package/src/search/results.tsx +0 -181
- package/src/search/state.ts +0 -64
- package/src/search/types.ts +0 -116
- package/src/style.ts +0 -197
- package/src/styles/main.css +0 -993
- package/src/styles/primitives.css +0 -573
- package/src/styles/resets.css +0 -47
- package/src/styles/search.css +0 -342
- package/src/styles/sidebar.css +0 -87
- package/src/styles/snippets.css +0 -132
- package/src/styles/variables.css +0 -90
- package/src/utils.ts +0 -41
package/src/search/printer.tsx
DELETED
|
@@ -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
|
-
}
|
package/src/search/results.tsx
DELETED
|
@@ -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
|
-
}
|
package/src/search/state.ts
DELETED
|
@@ -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
|
-
}
|
package/src/search/types.ts
DELETED
|
@@ -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
|
-
};
|