@stoplight/elements-dev-portal 3.0.12-beta-0.1 → 3.0.13

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 (107) hide show
  1. package/{dist/index.esm.js → index.esm.js} +2 -2
  2. package/{dist/index.js → index.js} +2 -2
  3. package/{dist/index.mjs → index.mjs} +2 -2
  4. package/package.json +17 -71
  5. package/{dist/types.d.ts → types.d.ts} +0 -1
  6. package/version.d.ts +1 -0
  7. package/{dist/web-components.min.js → web-components.min.js} +1 -1
  8. package/.storybook/main.js +0 -6
  9. package/.storybook/manager.js +0 -1
  10. package/.storybook/preview.jsx +0 -46
  11. package/dist/LICENSE +0 -190
  12. package/dist/README.md +0 -22
  13. package/dist/package.json +0 -51
  14. package/dist/version.d.ts +0 -1
  15. package/jest.config.js +0 -10
  16. package/src/__fixtures__/branches.json +0 -28
  17. package/src/__fixtures__/node-content.json +0 -257
  18. package/src/__fixtures__/table-of-contents.json +0 -144
  19. package/src/components/BranchSelector/BranchSelector.spec.tsx +0 -61
  20. package/src/components/BranchSelector/BranchSelector.stories.tsx +0 -41
  21. package/src/components/BranchSelector/BranchSelector.tsx +0 -50
  22. package/src/components/BranchSelector/index.tsx +0 -1
  23. package/src/components/DevPortalProvider/index.tsx +0 -25
  24. package/src/components/Forbidden.tsx +0 -11
  25. package/src/components/Loading.tsx +0 -9
  26. package/src/components/NodeContent/NodeContent.spec.tsx +0 -128
  27. package/src/components/NodeContent/NodeContent.stories.tsx +0 -60
  28. package/src/components/NodeContent/NodeContent.tsx +0 -235
  29. package/src/components/NodeContent/index.tsx +0 -1
  30. package/src/components/NotFound.tsx +0 -11
  31. package/src/components/Search/Search.stories.tsx +0 -151
  32. package/src/components/Search/Search.tsx +0 -161
  33. package/src/components/Search/SearchOverlay.tsx +0 -88
  34. package/src/components/Search/index.tsx +0 -1
  35. package/src/components/TableOfContents/TableOfContents.stories.tsx +0 -68
  36. package/src/components/TableOfContents/TableOfContents.tsx +0 -54
  37. package/src/components/TableOfContents/index.tsx +0 -1
  38. package/src/components/UpgradeToStarter.tsx +0 -22
  39. package/src/consts.ts +0 -32
  40. package/src/containers/StoplightProject.spec.tsx +0 -78
  41. package/src/containers/StoplightProject.stories.tsx +0 -28
  42. package/src/containers/StoplightProject.tsx +0 -269
  43. package/src/handlers/__tests__/getBranches.test.ts +0 -30
  44. package/src/handlers/__tests__/getNodeContent.test.ts +0 -35
  45. package/src/handlers/__tests__/getNodes.test.ts +0 -38
  46. package/src/handlers/__tests__/getTableOfContents.test.ts +0 -34
  47. package/src/handlers/__tests__/getWorkspace.test.ts +0 -30
  48. package/src/handlers/getBranches.ts +0 -27
  49. package/src/handlers/getNodeContent.ts +0 -53
  50. package/src/handlers/getNodes.ts +0 -69
  51. package/src/handlers/getTableOfContents.ts +0 -30
  52. package/src/handlers/getWorkspace.ts +0 -27
  53. package/src/hooks/__tests__/dataFetching.spec.tsx +0 -42
  54. package/src/hooks/useGetBranches.ts +0 -17
  55. package/src/hooks/useGetNodeContent.ts +0 -24
  56. package/src/hooks/useGetNodes.ts +0 -34
  57. package/src/hooks/useGetTableOfContents.ts +0 -17
  58. package/src/hooks/useGetWorkspace.tsx +0 -13
  59. package/src/index.ts +0 -25
  60. package/src/styles.css +0 -1
  61. package/src/types.ts +0 -85
  62. package/src/version.ts +0 -2
  63. package/src/web-components/__stories__/StoplightProject.stories.tsx +0 -33
  64. package/src/web-components/components.ts +0 -19
  65. package/src/web-components/index.ts +0 -3
  66. package/tsconfig.build.json +0 -18
  67. package/tsconfig.json +0 -7
  68. package/web-components.config.js +0 -1
  69. /package/{dist/components → components}/BranchSelector/BranchSelector.d.ts +0 -0
  70. /package/{dist/components → components}/BranchSelector/BranchSelector.spec.d.ts +0 -0
  71. /package/{dist/components → components}/BranchSelector/BranchSelector.stories.d.ts +0 -0
  72. /package/{dist/components → components}/BranchSelector/index.d.ts +0 -0
  73. /package/{dist/components → components}/DevPortalProvider/index.d.ts +0 -0
  74. /package/{dist/components → components}/Forbidden.d.ts +0 -0
  75. /package/{dist/components → components}/Loading.d.ts +0 -0
  76. /package/{dist/components → components}/NodeContent/NodeContent.d.ts +0 -0
  77. /package/{dist/components → components}/NodeContent/NodeContent.spec.d.ts +0 -0
  78. /package/{dist/components → components}/NodeContent/NodeContent.stories.d.ts +0 -0
  79. /package/{dist/components → components}/NodeContent/index.d.ts +0 -0
  80. /package/{dist/components → components}/NotFound.d.ts +0 -0
  81. /package/{dist/components → components}/Search/Search.d.ts +0 -0
  82. /package/{dist/components → components}/Search/Search.stories.d.ts +0 -0
  83. /package/{dist/components → components}/Search/SearchOverlay.d.ts +0 -0
  84. /package/{dist/components → components}/Search/index.d.ts +0 -0
  85. /package/{dist/components → components}/TableOfContents/TableOfContents.d.ts +0 -0
  86. /package/{dist/components → components}/TableOfContents/TableOfContents.stories.d.ts +0 -0
  87. /package/{dist/components → components}/TableOfContents/index.d.ts +0 -0
  88. /package/{dist/components → components}/UpgradeToStarter.d.ts +0 -0
  89. /package/{dist/consts.d.ts → consts.d.ts} +0 -0
  90. /package/{dist/containers → containers}/StoplightProject.d.ts +0 -0
  91. /package/{dist/containers → containers}/StoplightProject.spec.d.ts +0 -0
  92. /package/{dist/containers → containers}/StoplightProject.stories.d.ts +0 -0
  93. /package/{dist/handlers → handlers}/getBranches.d.ts +0 -0
  94. /package/{dist/handlers → handlers}/getNodeContent.d.ts +0 -0
  95. /package/{dist/handlers → handlers}/getNodes.d.ts +0 -0
  96. /package/{dist/handlers → handlers}/getTableOfContents.d.ts +0 -0
  97. /package/{dist/handlers → handlers}/getWorkspace.d.ts +0 -0
  98. /package/{dist/hooks → hooks}/useGetBranches.d.ts +0 -0
  99. /package/{dist/hooks → hooks}/useGetNodeContent.d.ts +0 -0
  100. /package/{dist/hooks → hooks}/useGetNodes.d.ts +0 -0
  101. /package/{dist/hooks → hooks}/useGetTableOfContents.d.ts +0 -0
  102. /package/{dist/hooks → hooks}/useGetWorkspace.d.ts +0 -0
  103. /package/{dist/index.d.ts → index.d.ts} +0 -0
  104. /package/{dist/styles.min.css → styles.min.css} +0 -0
  105. /package/{dist/web-components → web-components}/components.d.ts +0 -0
  106. /package/{dist/web-components → web-components}/index.d.ts +0 -0
  107. /package/{dist/web-components.min.js.LICENSE.txt → web-components.min.js.LICENSE.txt} +0 -0
@@ -1,235 +0,0 @@
1
- import {
2
- CustomLinkComponent,
3
- Docs,
4
- DocsProps,
5
- LinkHeading,
6
- MarkdownComponentsProvider,
7
- MockingProvider,
8
- ReferenceResolver,
9
- RouterTypeContext,
10
- } from '@stoplight/elements-core';
11
- import { CustomComponentMapping } from '@stoplight/markdown-viewer';
12
- import { dirname, resolve } from '@stoplight/path';
13
- import { NodeType } from '@stoplight/types';
14
- import * as React from 'react';
15
- import { useLocation } from 'react-router-dom';
16
-
17
- import { Node } from '../../types';
18
-
19
- // Props shared with elements-core Docs component
20
- type DocsBaseProps = Pick<
21
- DocsProps,
22
- 'tryItCorsProxy' | 'tryItCredentialsPolicy' | 'nodeHasChanged' | 'nodeUnsupported'
23
- >;
24
- type DocsLayoutProps = Pick<
25
- Required<DocsProps>['layoutOptions'],
26
- 'compact' | 'hideTryIt' | 'hideTryItPanel' | 'hideSamples' | 'hideExport' | 'hideSecurityInfo' | 'hideServerInfo'
27
- >;
28
-
29
- export type NodeContentProps = {
30
- node: Node;
31
- Link: CustomLinkComponent;
32
-
33
- /**
34
- * Allows to hide mocking button
35
- */
36
- hideMocking?: boolean;
37
-
38
- /**
39
- * Support for custom reference resolver
40
- */
41
- refResolver?: ReferenceResolver;
42
-
43
- maxRefDepth?: number;
44
-
45
- onExportRequest?: (type: 'original' | 'bundled') => void;
46
- } & DocsBaseProps &
47
- DocsLayoutProps;
48
-
49
- export const NodeContent = ({
50
- node,
51
- Link,
52
- hideMocking,
53
- refResolver,
54
- maxRefDepth,
55
-
56
- // Docs base props
57
- tryItCorsProxy,
58
- tryItCredentialsPolicy,
59
- nodeHasChanged,
60
- nodeUnsupported,
61
-
62
- // Docs layout props
63
- compact,
64
- hideTryIt,
65
- hideSamples,
66
- hideTryItPanel,
67
- hideSecurityInfo,
68
- hideServerInfo,
69
-
70
- // Exporting
71
- hideExport,
72
- onExportRequest,
73
- }: NodeContentProps) => {
74
- return (
75
- <NodeLinkContext.Provider value={[node, Link]}>
76
- <MarkdownComponentsProvider
77
- value={{
78
- a: LinkComponent,
79
- // These override the default markdown-viewer components and modifies the
80
- // rendering of hash routing hrefs for headings in elements-core for the BaseArticleComponent
81
- h2: ({ color, ...props }) => <LinkHeading size={2} {...props} />,
82
- h3: ({ color, ...props }) => <LinkHeading size={3} {...props} />,
83
- h4: ({ color, ...props }) => <LinkHeading size={4} {...props} />,
84
- }}
85
- >
86
- <MockingProvider mockUrl={node.links.mock_url} hideMocking={hideMocking}>
87
- <Docs
88
- nodeType={node.type as NodeType}
89
- nodeData={node.data}
90
- nodeTitle={node.title}
91
- disableProps={node?.disableProps}
92
- layoutOptions={{
93
- compact,
94
- hideTryIt: hideTryIt,
95
- hideTryItPanel: hideTryItPanel,
96
- hideSamples,
97
- hideSecurityInfo: hideSecurityInfo,
98
- hideServerInfo: hideServerInfo,
99
- hideExport:
100
- hideExport ||
101
- (node.links.export_url ?? node.links.export_original_file_url ?? node.links.export_bundled_file_url) ===
102
- undefined,
103
- }}
104
- useNodeForRefResolving
105
- refResolver={refResolver}
106
- maxRefDepth={maxRefDepth}
107
- tryItCorsProxy={tryItCorsProxy}
108
- exportProps={
109
- [NodeType.HttpService, NodeType.Model].includes(node.type as NodeType)
110
- ? {
111
- original: onExportRequest
112
- ? { onPress: () => onExportRequest('original') }
113
- : { href: node.links.export_original_file_url ?? node.links.export_url },
114
- bundled: onExportRequest
115
- ? { onPress: () => onExportRequest('bundled') }
116
- : { href: node.links.export_bundled_file_url ?? getBundledUrl(node.links.export_url) },
117
- }
118
- : undefined
119
- }
120
- tryItCredentialsPolicy={tryItCredentialsPolicy}
121
- nodeHasChanged={nodeHasChanged}
122
- nodeUnsupported={nodeUnsupported}
123
- />
124
- </MockingProvider>
125
- </MarkdownComponentsProvider>
126
- </NodeLinkContext.Provider>
127
- );
128
- };
129
-
130
- const NodeLinkContext = React.createContext<[Node, CustomLinkComponent] | undefined>(undefined);
131
-
132
- const externalRegex = new RegExp('^(?:[a-z]+:)?//', 'i');
133
- const LinkComponent: CustomComponentMapping['a'] = ({ children, href, title }) => {
134
- console.log('LinkComponent href-----', href);
135
- const ctx = React.useContext(NodeLinkContext);
136
- const routerKind = React.useContext(RouterTypeContext);
137
-
138
- const { pathname } = useLocation();
139
- const route = pathname.split('#')[0];
140
-
141
- try {
142
- if (href && externalRegex.test(href)) {
143
- const baseURL = window.location.host;
144
- const hrefURL = new URL(href).host;
145
-
146
- if (baseURL === hrefURL) {
147
- // Open URL in same tab if domain match
148
- return (
149
- <a href={href} title={title ? title : undefined}>
150
- {children}
151
- </a>
152
- );
153
- }
154
- return (
155
- <a href={href} target="_blank" rel="noreferrer" title={title ? title : undefined}>
156
- {children}
157
- </a>
158
- );
159
- }
160
- } catch (error) {
161
- console.error(error);
162
- }
163
-
164
- if (href && ctx) {
165
- const [node, Link] = ctx;
166
- console.log('LinkComponent node-----', node);
167
-
168
- // Resolve relative file URI with
169
- const { fileUri } = getNodeUriParts(node.uri);
170
- const { fileUri: hrefFileUri } = getNodeUriParts(href);
171
-
172
- let resolvedUri;
173
- if (hrefFileUri) {
174
- // if the href is targeting another file, resolve it against the dir path of current file
175
- resolvedUri = resolve(dirname(fileUri), href);
176
- } else {
177
- // If the href does not include a file, resolve it relative to the current file
178
- resolvedUri = resolve(fileUri, href);
179
- }
180
-
181
- const [resolvedUriWithoutAnchor, hash] = resolvedUri.split('#');
182
- const decodedUrl = decodeURIComponent(href);
183
- const decodedResolvedUriWithoutAnchor = decodeURIComponent(resolvedUriWithoutAnchor);
184
- const [pagePathWithoutHash] = pathname.split('#');
185
-
186
- let edge = node.outbound_edges.find(
187
- edge => edge.uri === decodedUrl || edge.uri === decodedResolvedUriWithoutAnchor,
188
- );
189
-
190
- if (!edge) {
191
- edge = node.outbound_edges.find(edge => pagePathWithoutHash === `/${edge.slug}`);
192
- }
193
-
194
- if (edge) {
195
- const slug = routerKind === 'hash' ? `#${route.replace(node.slug, edge.slug)}` : edge.slug;
196
- return <Link to={`${slug}${hash ? `#${hash}` : ''}`}>{children}</Link>;
197
- }
198
- }
199
-
200
- const fullHref = routerKind === 'hash' ? `#${route}${href}` : href;
201
- return <a href={fullHref}>{children}</a>;
202
- };
203
-
204
- function getBundledUrl(url: string | undefined) {
205
- if (url === undefined) return undefined;
206
- const bundledUrl = new URL(url);
207
- const searchParams = new URLSearchParams(bundledUrl.search);
208
- searchParams.append('deref', 'optimizedBundle');
209
- bundledUrl.search = searchParams.toString();
210
- return bundledUrl.toString();
211
- }
212
-
213
- // Extract out just the file portion of the node URI
214
- // This handles cases such as links to http_operation node uris, which include both the file + encoded pointer, e.g.
215
- //
216
- // /reference/openapi.json/paths/~1v2~1contact~1last_change/post#heading-anchor
217
- // fileUri = /reference/openapi.json
218
- // pointer = /paths/~1v2~1contact~1last_change/post#heading-anchor
219
- export const getNodeUriParts = (uri: string): { fileUri: string; pointer: string } => {
220
- // Check: added console for debugging purpose
221
- console.log('getNodeUriParts uri-----', uri, 'typeof uri:', typeof uri);
222
- // Guard against undefined or non-string input
223
- if (!uri || typeof uri !== 'string') return { fileUri: '', pointer: '' };
224
- const parts = uri.split(/(\.yaml|\.yml|\.json|\.md)/);
225
- if (parts === undefined || void 0) {
226
- return { fileUri: '', pointer: '' };
227
- }
228
- if (!parts || parts.length === 1) {
229
- return { fileUri: '', pointer: parts[0] || '' };
230
- }
231
-
232
- const fileUri = `${parts[0] || ''}${parts[1] || ''}`;
233
-
234
- return { fileUri, pointer: parts[2] || '' };
235
- };
@@ -1 +0,0 @@
1
- export * from './NodeContent';
@@ -1,11 +0,0 @@
1
- import { Box, Flex, Heading, VStack } from '@stoplight/mosaic';
2
- import React from 'react';
3
-
4
- export const NotFound = () => (
5
- <Flex align="center" justify="center" flexGrow>
6
- <VStack spacing={4} align="center">
7
- <Heading size={1}>Not Found</Heading>
8
- <Box as="p">Could not find what you are looking for</Box>
9
- </VStack>
10
- </Flex>
11
- );
@@ -1,151 +0,0 @@
1
- import { faSearch, faSpinner } from '@fortawesome/free-solid-svg-icons';
2
- import { Box, Icon, Input, useModalState } from '@stoplight/mosaic';
3
- import { Story } from '@storybook/react';
4
- import * as React from 'react';
5
-
6
- import { useGetNodes } from '../../hooks/useGetNodes';
7
- import { useGetTableOfContents } from '../../hooks/useGetTableOfContents';
8
- import { useGetWorkspace } from '../../hooks/useGetWorkspace';
9
- import { NodeSearchResult } from '../../types';
10
- import { TableOfContents } from '../TableOfContents';
11
- import { Search, SearchResults } from './';
12
-
13
- type SearchWrapperProps = { projectIds: string[]; workspaceId: string; isInResponsiveMode?: boolean };
14
- // Wrapper to show how to use the node content hook
15
- const SearchWrapper = ({ projectIds, workspaceId }: SearchWrapperProps) => {
16
- const { isOpen, open, close } = useModalState();
17
- const [search, setSearch] = React.useState('');
18
- const { data, isFetching } = useGetNodes({
19
- search,
20
- projectIds,
21
- workspaceId,
22
- });
23
-
24
- const { data: workspace } = useGetWorkspace({
25
- projectIds,
26
- });
27
-
28
- const handleClose = () => {
29
- close();
30
- setSearch('');
31
- };
32
-
33
- const handleClick = (searchResult: NodeSearchResult) => {
34
- console.log('Search clicked', searchResult);
35
- window.open(
36
- `https://${workspace?.workspace.slug}.stoplight.io/docs/${searchResult.project_slug}${searchResult.uri}`,
37
- '_blank',
38
- );
39
-
40
- handleClose();
41
- };
42
-
43
- return (
44
- <>
45
- <Input placeholder="Search..." onClick={open} />
46
- <Search
47
- isLoading={isFetching}
48
- search={search}
49
- searchResults={data}
50
- onSearch={setSearch}
51
- isOpen={isOpen}
52
- onClose={handleClose}
53
- onClick={handleClick}
54
- />
55
- </>
56
- );
57
- };
58
-
59
- const EmbeddedSearchWrapper = ({ projectIds, workspaceId, isInResponsiveMode }: SearchWrapperProps) => {
60
- const [search, setSearch] = React.useState('');
61
- const { data, isFetching } = useGetNodes({
62
- search,
63
- projectIds,
64
- workspaceId,
65
- });
66
-
67
- const { data: workspace } = useGetWorkspace({
68
- projectIds,
69
- });
70
- const { data: tableOfContents } = useGetTableOfContents({ projectId: projectIds[0], branchSlug: '' });
71
-
72
- const handleClick = (searchResult: NodeSearchResult) => {
73
- console.log('Search clicked', searchResult);
74
- window.open(
75
- `https://${workspace?.workspace.slug}.stoplight.io/docs/${searchResult.project_slug}${searchResult.uri}`,
76
- '_blank',
77
- );
78
- };
79
-
80
- return (
81
- <>
82
- <Box bg="canvas" pos="sticky" style={{ top: 0 }}>
83
- <Box bg="canvas" w="full" pt={3}>
84
- <Input
85
- appearance="minimal"
86
- border
87
- icon={<Box as={Icon} ml={1} icon={isFetching ? faSpinner : faSearch} spin={isFetching} />}
88
- autoFocus
89
- placeholder="Search..."
90
- value={search}
91
- onChange={e => {
92
- setSearch(e.currentTarget.value);
93
- }}
94
- type="search"
95
- />
96
- </Box>
97
- </Box>
98
- <Box>
99
- {isInResponsiveMode && !search && tableOfContents ? (
100
- <TableOfContents
101
- isInResponsiveMode={isInResponsiveMode}
102
- tableOfContents={tableOfContents}
103
- activeId="b3A6MTE0"
104
- Link={({ children, ...props }) => {
105
- return (
106
- <a
107
- onClick={() => {
108
- console.log('Link clicked!', props);
109
- }}
110
- >
111
- {children}
112
- </a>
113
- );
114
- }}
115
- />
116
- ) : (
117
- !search && isInResponsiveMode && <>Loading...</>
118
- )}
119
- {/* show search results first if not in responsive mode */}
120
- {!isInResponsiveMode || (isInResponsiveMode && search) ? (
121
- <Box p={5}>
122
- <SearchResults searchResults={data} onClick={handleClick} isEmbedded={true} />
123
- </Box>
124
- ) : null}
125
- </Box>
126
- </>
127
- );
128
- };
129
- export default {
130
- title: 'Public/Search',
131
- component: SearchWrapper,
132
- argTypes: {
133
- workspaceId: { table: { category: 'Input' } },
134
- projectIds: { table: { category: 'Input' } },
135
- platformUrl: { table: { category: 'Input' } },
136
- isInResponsiveMode: { table: { category: 'Input' } },
137
- },
138
- args: {
139
- projectIds: ['cHJqOjYwNjYx'],
140
- workspaceId: 'd2s6NDE1NTU',
141
- platformUrl: 'https://stoplight.io',
142
- isInResponsiveMode: false,
143
- },
144
- };
145
-
146
- export const Playground: Story<SearchWrapperProps> = args => <SearchWrapper {...args} />;
147
- export const EmbeddedSearch: Story<SearchWrapperProps> = args => <EmbeddedSearchWrapper {...args} />;
148
-
149
- Playground.storyName = 'Studio Demo';
150
-
151
- EmbeddedSearch.storyName = 'Embedded Search';
@@ -1,161 +0,0 @@
1
- import { faSearch, faSpinner } from '@fortawesome/free-solid-svg-icons';
2
- import {
3
- NodeTypeColors,
4
- NodeTypeIconDefs,
5
- withMosaicProvider,
6
- withPersistenceBoundary,
7
- withQueryClientProvider,
8
- withStyles,
9
- } from '@stoplight/elements-core';
10
- import { Box, Flex, Icon, Input, ListBox, ListBoxItem, Modal, ModalProps } from '@stoplight/mosaic';
11
- import { flow } from 'lodash';
12
- import * as React from 'react';
13
-
14
- import { NodeSearchResult } from '../../types';
15
-
16
- export type SearchProps = {
17
- isLoading?: boolean;
18
- search?: string;
19
- searchResults?: NodeSearchResult[];
20
- onSearch: (search: string) => void;
21
- onClick: (result: NodeSearchResult) => void;
22
- isOpen?: boolean;
23
- onClose: ModalProps['onClose'];
24
- };
25
-
26
- export type SearchResultsListProps = {
27
- searchResults?: NodeSearchResult[];
28
- isEmbedded?: boolean;
29
- showDivider?: boolean;
30
- onClick: (result: NodeSearchResult) => void;
31
- };
32
-
33
- const SearchImpl = ({ isLoading, search, searchResults, isOpen, onClose, onClick, onSearch }: SearchProps) => {
34
- const listBoxRef = React.useRef<HTMLDivElement>(null);
35
-
36
- const onChange = React.useCallback(e => onSearch(e.currentTarget.value), [onSearch]);
37
-
38
- const onKeyDown = React.useCallback(e => {
39
- // Focus the search results on arrow down
40
- if (e.key === 'ArrowDown') {
41
- e.preventDefault();
42
- listBoxRef.current?.focus();
43
- }
44
- }, []);
45
-
46
- return (
47
- <Modal
48
- renderHeader={() => (
49
- <Input
50
- appearance="minimal"
51
- borderB
52
- size="lg"
53
- icon={<Box as={Icon} ml={1} icon={isLoading ? faSpinner : faSearch} spin={isLoading} />}
54
- autoFocus
55
- placeholder="Search..."
56
- value={search}
57
- onChange={onChange}
58
- onKeyDown={onKeyDown}
59
- />
60
- )}
61
- isOpen={!!isOpen}
62
- onClose={onClose}
63
- >
64
- <SearchResultsList searchResults={searchResults} onClick={onClick} />
65
- </Modal>
66
- );
67
- };
68
-
69
- export const SearchResultsList = ({
70
- searchResults,
71
- onClick,
72
- isEmbedded,
73
- showDivider = true,
74
- }: SearchResultsListProps) => {
75
- const listBoxRef = React.useRef<HTMLDivElement>(null);
76
- const onSelectionChange = React.useCallback(
77
- keys => {
78
- const selectedId = keys.values().next().value;
79
- const selectedResult = searchResults?.find(
80
- searchResult => `${searchResult.id}-${searchResult.project_id}` === selectedId,
81
- );
82
- if (selectedResult) {
83
- onClick(selectedResult);
84
- }
85
- },
86
- [searchResults, onClick],
87
- );
88
-
89
- return (
90
- <>
91
- {searchResults && searchResults.length > 0 ? (
92
- <ListBox
93
- ref={listBoxRef}
94
- aria-label="Search"
95
- overflowY="auto"
96
- h={isEmbedded ? undefined : 80}
97
- m={-5}
98
- items={searchResults}
99
- selectionMode="single"
100
- onSelectionChange={onSelectionChange}
101
- >
102
- {(searchResult: NodeSearchResult) => {
103
- return (
104
- <ListBoxItem key={`${searchResult.id}-${searchResult.project_id}`} textValue={searchResult.title}>
105
- <Box p={3} borderB={!showDivider ? undefined : true}>
106
- <Flex align="center">
107
- <Box
108
- as={Icon}
109
- w={4}
110
- icon={NodeTypeIconDefs[searchResult.type as keyof typeof NodeTypeIconDefs]}
111
- style={{ color: NodeTypeColors[searchResult.type as keyof typeof NodeTypeIconDefs] }}
112
- />
113
-
114
- <Box
115
- flex={1}
116
- fontSize="lg"
117
- dangerouslySetInnerHTML={{ __html: searchResult.highlighted.name ?? '' }}
118
- fontWeight="medium"
119
- textOverflow="overflow-ellipsis"
120
- mx={2}
121
- />
122
-
123
- <Box fontSize="sm" color="muted">
124
- {searchResult.project_name}
125
- </Box>
126
- </Flex>
127
-
128
- <Box
129
- dangerouslySetInnerHTML={{ __html: searchResult.highlighted.summary ?? '' }}
130
- color="muted"
131
- fontSize="sm"
132
- mt={1}
133
- ml={6}
134
- />
135
- </Box>
136
- </ListBoxItem>
137
- );
138
- }}
139
- </ListBox>
140
- ) : (
141
- <Flex w="full" h={80} align="center" justify="center" m={-5}>
142
- No search results
143
- </Flex>
144
- )}
145
- </>
146
- );
147
- };
148
-
149
- export const SearchResults = flow(
150
- withStyles,
151
- withPersistenceBoundary,
152
- withMosaicProvider,
153
- withQueryClientProvider,
154
- )(SearchResultsList);
155
-
156
- export const Search = flow(
157
- withStyles,
158
- withPersistenceBoundary,
159
- withMosaicProvider,
160
- withQueryClientProvider,
161
- )(SearchImpl);
@@ -1,88 +0,0 @@
1
- import { faSearch, faSpinner } from '@fortawesome/free-solid-svg-icons';
2
- import type { CustomLinkComponent } from '@stoplight/elements-core';
3
- import { Box, Button, Flex, Icon, Input, Modal } from '@stoplight/mosaic';
4
- import * as React from 'react';
5
- import { Link } from 'react-router-dom';
6
-
7
- import { NodeSearchResult, ProjectTableOfContents } from '../../types';
8
- import { TableOfContents } from '../TableOfContents';
9
- import { SearchResults } from './Search';
10
-
11
- type SearchOverlayProps = {
12
- isFetching: boolean;
13
- search: string;
14
- setSearch: (search: string) => void;
15
- data?: NodeSearchResult[];
16
- toc?: ProjectTableOfContents;
17
- nodeSlug?: string;
18
- projectSlug?: string;
19
- branchSlug?: string;
20
- isSearchShowing: boolean;
21
- onClose: () => void;
22
- onClick: (item?: NodeSearchResult) => void;
23
- };
24
-
25
- export const SearchOverlay = ({
26
- isFetching,
27
- search,
28
- setSearch,
29
- data,
30
- toc,
31
- nodeSlug,
32
- projectSlug,
33
- branchSlug,
34
- isSearchShowing,
35
- onClose,
36
- onClick,
37
- }: SearchOverlayProps) => {
38
- return (
39
- <Modal isOpen={isSearchShowing} onClose={onClose}>
40
- <Box className="sl-overlay" bg="canvas" overflowY="scroll" data-test="search-overlay">
41
- <Flex alignItems="center" h="3xl" px={7} bg="canvas" borderB pos="sticky" zIndex={20}>
42
- <Flex w="full">
43
- <Box pt={1} pr={2}>
44
- <Button
45
- appearance="minimal"
46
- onClick={() => {
47
- onClose();
48
- }}
49
- data-test="search-overlay-back-button"
50
- >
51
- <Icon icon={['fas', 'arrow-left']} color="gray" size="lg" />
52
- </Button>
53
- </Box>
54
- <Input
55
- border
56
- data-test="docs-search-input"
57
- display="inline-block"
58
- appearance="minimal"
59
- icon={<Box as={Icon} ml={1} icon={isFetching ? faSpinner : faSearch} spin={isFetching} />}
60
- autoFocus
61
- placeholder={projectSlug ? 'Search within the project' : 'Search...'}
62
- value={search}
63
- onChange={e => {
64
- setSearch(e.currentTarget.value);
65
- }}
66
- type="search"
67
- w="full"
68
- size="lg"
69
- />
70
- </Flex>
71
- </Flex>
72
- <Box px={5} py={toc && !search ? 0 : 5} data-test="responsive-project-toc">
73
- {toc && !search && projectSlug && (
74
- <TableOfContents
75
- tableOfContents={{ ...toc, hide_powered_by: true }}
76
- activeId={nodeSlug || ''}
77
- Link={Link as CustomLinkComponent}
78
- onLinkClick={onClick}
79
- />
80
- )}
81
- {search && (
82
- <SearchResults searchResults={data} onClick={item => onClick(item)} isEmbedded={true} showDivider={false} />
83
- )}
84
- </Box>
85
- </Box>
86
- </Modal>
87
- );
88
- };
@@ -1 +0,0 @@
1
- export * from './Search';