1
1
import algoliasearch from 'algoliasearch/lite' ;
2
2
import { createRoot } from 'react-dom/client' ;
3
3
import docsStyle from './docs.css' ;
4
+ import DocumentOutline from '@spectrum-icons/workflow/DocumentOutline' ;
4
5
import DOMPurify from 'dompurify' ;
6
+ import { Icon } from '@react-spectrum/icon' ;
5
7
import { Item , SearchAutocomplete , Section } from '@react-spectrum/autocomplete' ;
6
- import Link from '@spectrum-icons/workflow/Link' ;
7
8
import News from '@spectrum-icons/workflow/News' ;
8
9
import React , { useRef , useState } from 'react' ;
9
10
import { Text , VisuallyHidden } from '@adobe/react-spectrum' ;
10
11
import { ThemeProvider } from './ThemeSwitcher' ;
11
- import WebPage from '@spectrum-icons/workflow/WebPage' ;
12
12
13
13
export default function DocSearch ( ) {
14
14
const client = algoliasearch ( '1V1Q59JVTR' , '44a7e2e7508ff185f25ac64c0a675f98' ) ;
@@ -89,6 +89,13 @@ export default function DocSearch() {
89
89
groupedHits . map ( ( hit ) => {
90
90
const hierarchy = hit . hierarchy ;
91
91
const objectID = hit . objectID ;
92
+ const docsearchParent = hit . type !== 'lvl1' &&
93
+ groupedHits . find (
94
+ ( siblingItem ) =>
95
+ siblingItem . type === 'lvl1' &&
96
+ siblingItem . hierarchy . lvl1 ===
97
+ hit . hierarchy . lvl1
98
+ ) ;
92
99
93
100
return (
94
101
< Item key = { objectID } textValue = { hit . type === 'content' ? hit [ hit . type ] : hierarchy [ hit . type ] } >
@@ -99,7 +106,7 @@ export default function DocSearch() {
99
106
{
100
107
title === 'Blog' || title === 'Releases' ?
101
108
< News aria-label = "news" /> :
102
- < WebPage aria-label = "web page" />
109
+ < DocumentOutline aria-label = "web page" />
103
110
}
104
111
< Text >
105
112
< Snippet
@@ -129,7 +136,9 @@ export default function DocSearch() {
129
136
hit . type === 'lvl6'
130
137
) && (
131
138
< >
132
- < Link aria-label = "in-page link" />
139
+ < Hash
140
+ UNSAFE_className = { docsearchParent ? docsStyle . docSearchItemIndent : undefined }
141
+ aria-label = "in-page link" />
133
142
< Text >
134
143
< Snippet
135
144
className = "DocSearch-Hit-title"
@@ -149,7 +158,9 @@ export default function DocSearch() {
149
158
{
150
159
hit . type === 'content' && (
151
160
< >
152
- < Link aria-label = "in-page link" />
161
+ < Hash
162
+ UNSAFE_className = { docsearchParent ? docsStyle . docSearchItemIndent : undefined }
163
+ aria-label = "in-page link" />
153
164
< Text >
154
165
< Snippet
155
166
className = "DocSearch-Hit-title"
@@ -172,48 +183,6 @@ export default function DocSearch() {
172
183
173
184
sections . push ( { title, items} ) ;
174
185
}
175
- /*
176
- hits.forEach(prediction => {
177
- let hierarchy = prediction.hierarchy;
178
- let objectID = prediction.objectID;
179
- let url = prediction.url;
180
- let sectionTitle;
181
- for (const [path, title] of Object.entries(sectionTitles)) {
182
- let regexp = new RegExp('^.+//.+/' + path + '[/.].+$', 'i');
183
- if (url.match(regexp)) {
184
- sectionTitle = title;
185
- break;
186
- }
187
- }
188
- if (!sectionTitle) {
189
- sectionTitle = 'Documentation';
190
- }
191
- let section = sections.find(section => section.title === sectionTitle);
192
- if (!section) {
193
- section = {title: sectionTitle, items: []};
194
- sections.push(section);
195
- }
196
- let text = [];
197
- let textValue = [];
198
- for (let i = 1; i < 6; i++) {
199
- if (hierarchy[`lvl${i}`]) {
200
- text.push(prediction._highlightResult.hierarchy[`lvl${i}`].value);
201
- textValue.push(hierarchy[`lvl${i}`]);
202
- }
203
- }
204
- section.items.push(
205
- <Item key={objectID} textValue={textValue.join(' | ')}>
206
- <Text><span dangerouslySetInnerHTML={{__html: DOMPurify.sanitize(text.join(' | '))}} /></Text>
207
- {
208
- prediction.content &&
209
- <Text slot="description">
210
- <span dangerouslySetInnerHTML={{__html: DOMPurify.sanitize(prediction._snippetResult.content.value)}} />
211
- </Text>
212
- }
213
- </Item>
214
- );
215
- });
216
- */
217
186
let titles = Object . values ( sectionTitles ) ;
218
187
sections = sections . sort ( ( a , b ) => titles . indexOf ( a . title ) < titles . indexOf ( b . title ) ? - 1 : 1 ) ;
219
188
let suggestions = sections . map ( ( section , index ) => < Section key = { `${ index } -${ section . title } ` } title = { section . title } > { section . items } </ Section > ) ;
@@ -287,6 +256,16 @@ export default function DocSearch() {
287
256
) ;
288
257
}
289
258
259
+ function Hash ( props ) {
260
+ return (
261
+ < Icon { ...props } >
262
+ < svg viewBox = "0 0 20 20" >
263
+ < path d = "M13 13h4-4V8H7v5h6v4-4H7V8H3h4V3v5h6V3v5h4-4v5zm-6 0v4-4H3h4z" stroke = "currentColor" fill = "none" fillRule = "evenodd" strokeLinecap = "round" strokeLinejoin = "round" />
264
+ </ svg >
265
+ </ Icon >
266
+ ) ;
267
+ }
268
+
290
269
const AlgoliaSearchLogo = (
291
270
< div className = { docsStyle . docSearchLogo } >
292
271
< a href = "https://www.algolia.com/ref/docsearch/?utm_source=react-spectrum.adobe.com&utm_medium=referral&utm_content=powered_by&utm_campaign=docsearch" target = "_blank" rel = "noopener noreferrer" >
@@ -346,3 +325,4 @@ function Snippet({
346
325
} ) ;
347
326
}
348
327
328
+
0 commit comments