@brillout/docpress 0.7.2 → 0.7.4

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 (44) hide show
  1. package/+config.ts +10 -1
  2. package/LICENSE.md +9 -0
  3. package/{PageLayout.css → Layout.css} +21 -0
  4. package/Layout.tsx +92 -0
  5. package/algolia/DocSearch.css +2 -5
  6. package/components/Algolia/Hit.tsx +67 -0
  7. package/components/Algolia/README.md +21 -0
  8. package/components/Algolia/SelectIcon.tsx +12 -0
  9. package/components/Algolia/Snippet.tsx +32 -0
  10. package/components/Algolia/SourceIcon.tsx +55 -0
  11. package/components/Algolia/types.ts +86 -0
  12. package/config/resolveHeadingsData.ts +11 -3
  13. package/dist/+config.d.ts +13 -0
  14. package/dist/+config.js +8 -0
  15. package/dist/components/Algolia/Hit.d.ts +4 -0
  16. package/dist/components/Algolia/Hit.js +30 -0
  17. package/dist/components/Algolia/SelectIcon.d.ts +2 -0
  18. package/dist/components/Algolia/SelectIcon.js +7 -0
  19. package/dist/components/Algolia/Snippet.d.ts +13 -0
  20. package/dist/components/Algolia/Snippet.js +37 -0
  21. package/dist/components/Algolia/SourceIcon.d.ts +4 -0
  22. package/dist/components/Algolia/SourceIcon.js +23 -0
  23. package/dist/components/Algolia/types.d.ts +79 -0
  24. package/dist/components/Algolia/types.js +1 -0
  25. package/dist/config/resolveHeadingsData.d.ts +5 -0
  26. package/dist/config/resolveHeadingsData.js +13 -6
  27. package/dist/config/resolvePageContext.d.ts +5 -0
  28. package/dist/navigation/Navigation.js +8 -8
  29. package/dist/navigation/NavigationHeader.d.ts +4 -0
  30. package/dist/navigation/NavigationHeader.js +9 -19
  31. package/dist/types/Heading.d.ts +10 -4
  32. package/dist/utils/assert.js +6 -10
  33. package/icons/twitter.svg +1 -16
  34. package/navigation/Navigation-items.css +1 -1
  35. package/navigation/Navigation-layout.css +1 -1
  36. package/navigation/Navigation.tsx +10 -11
  37. package/navigation/NavigationHeader.tsx +10 -21
  38. package/navigation/navigation-fullscreen/initNavigationFullscreen.ts +32 -8
  39. package/package.json +22 -18
  40. package/renderer/getPageElement.tsx +15 -4
  41. package/renderer/onRenderClient.tsx +16 -2
  42. package/types/Heading.ts +11 -6
  43. package/utils/assert.ts +5 -10
  44. package/PageLayout.tsx +0 -48
package/+config.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Config } from 'vike/types'
1
+ import type { Config, ImportString } from 'vike/types'
2
2
  import type { Exports } from './config/resolvePageContext'
3
3
 
4
4
  export default {
@@ -7,6 +7,7 @@ export default {
7
7
  onRenderHtml: 'import:@brillout/docpress/renderer/onRenderHtml:onRenderHtml',
8
8
  onRenderClient: 'import:@brillout/docpress/renderer/onRenderClient:onRenderClient',
9
9
  onBeforeRender: 'import:@brillout/docpress/renderer/onBeforeRender:onBeforeRender',
10
+ Layout: 'import:@brillout/docpress/Layout:Layout',
10
11
  clientRouting: true,
11
12
  hydrationCanBeAborted: true,
12
13
  passToClient: ['pageContextResolved'],
@@ -14,6 +15,13 @@ export default {
14
15
  NavHeader: {
15
16
  env: { client: true, server: true },
16
17
  },
18
+ Layout: {
19
+ env: { client: true, server: true },
20
+ },
21
+ },
22
+ prefetch: {
23
+ staticAssets: 'hover',
24
+ pageContext: Infinity,
17
25
  },
18
26
  } satisfies Config
19
27
 
@@ -25,6 +33,7 @@ declare global {
25
33
  exports: Exports
26
34
  }
27
35
  interface Config {
36
+ Layout: ReactComponent | ImportString
28
37
  NavHeader?: {
29
38
  NavHeader: ReactComponent
30
39
  navHeaderWrapperStyle?: React.CSSProperties
package/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020-present Romuald Brillout
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -40,3 +40,24 @@
40
40
  --main-view-padding: 10px;
41
41
  }
42
42
  }
43
+
44
+
45
+ /* === noSideNavigation === */
46
+ .page-layout:not(.noSideNavigation) #top-navigation {
47
+ display: none !important;
48
+ }
49
+ @media screen and (max-width: 1139px) {
50
+ #top-navigation {
51
+ display: none !important;
52
+ }
53
+ }
54
+ @media screen and (min-width: 1140px) {
55
+ html:not(.navigation-fullscreen) .page-layout.noSideNavigation #navigation-wrapper,
56
+ html:not(.navigation-fullscreen) .page-layout.noSideNavigation #navigation-fullscreen-button {
57
+ display: none !important;
58
+ }
59
+ .noSideNavigation .page-wrapper {
60
+ /* Maybe we can remove this after we remove the vertical fullscreen navigation toggler? */
61
+ margin-left: 0 !important;
62
+ }
63
+ }
package/Layout.tsx ADDED
@@ -0,0 +1,92 @@
1
+ export { Layout }
2
+
3
+ import React from 'react'
4
+ import { Navigation, NavigationMask } from './navigation/Navigation'
5
+ import { MobileHeader } from './MobileHeader'
6
+ import { EditPageNote } from './components/EditPageNote'
7
+ import './Layout.css'
8
+ import { NavigationFullscreenButton } from './navigation/navigation-fullscreen/NavigationFullscreenButton'
9
+ import { parseTitle } from './parseTitle'
10
+ import { usePageContext, usePageContext2 } from './renderer/usePageContext'
11
+ import { Links } from './navigation/NavigationHeader'
12
+
13
+ function Layout({ children }: { children: React.ReactNode }) {
14
+ const pageContext = usePageContext()
15
+ const pageContext2 = usePageContext2()
16
+ const { isLandingPage, pageTitle, navigationData, noSideNavigation, topNavigationList } = pageContext
17
+ const pageTitleParsed = pageTitle && parseTitle(pageTitle)
18
+ const { globalNote } = pageContext.config
19
+ const { NavHeader } = pageContext2.config.NavHeader!
20
+ return (
21
+ <>
22
+ {noSideNavigation && (
23
+ <div
24
+ id="top-navigation"
25
+ style={{
26
+ position: 'relative',
27
+ display: 'flex',
28
+ color: 'inherit',
29
+ alignItems: 'center',
30
+ justifyContent: 'space-between',
31
+ textDecoration: 'none',
32
+ maxWidth: 1024,
33
+ margin: 'auto',
34
+ }}
35
+ >
36
+ <a href="/" style={{ display: 'flex', alignItems: 'center', color: 'inherit' }}>
37
+ <NavHeader />
38
+ </a>
39
+ <div style={{ display: 'flex', alignItems: 'center' }}>
40
+ <TopNavigationLink id="doclink">Documentation</TopNavigationLink>
41
+ {topNavigationList.map(({ title, url }) => (
42
+ <TopNavigationLink href={url!} key={url}>
43
+ {title}
44
+ </TopNavigationLink>
45
+ ))}
46
+ <Links style={{ display: 'inline-flex', marginLeft: 10 }} />
47
+ </div>
48
+ </div>
49
+ )}
50
+ <div
51
+ className={['page-layout', isLandingPage ? 'landing-page' : 'doc-page', noSideNavigation && 'noSideNavigation']
52
+ .filter(Boolean)
53
+ .join(' ')}
54
+ >
55
+ <div id="navigation-wrapper">
56
+ <Navigation {...pageContext.navigationData} />
57
+ </div>
58
+ <NavigationFullscreenButton />
59
+ <div className="page-wrapper">
60
+ <div className="page-container">
61
+ <MobileHeader />
62
+ <div className="page-content">
63
+ {globalNote}
64
+ {pageTitleParsed && <h1 id={`${navigationData.currentUrl.replace('/', '')}`}>{pageTitleParsed}</h1>}
65
+ {children}
66
+ {!isLandingPage && <EditPageNote pageContext={pageContext} />}
67
+ </div>
68
+ </div>
69
+ <NavigationMask />
70
+ </div>
71
+ </div>
72
+ </>
73
+ )
74
+ }
75
+
76
+ function TopNavigationLink(props: React.AnchorHTMLAttributes<HTMLAnchorElement>) {
77
+ return (
78
+ <a
79
+ style={{
80
+ height: '100%',
81
+ display: 'inline-flex',
82
+ alignItems: 'center',
83
+ justifyContent: 'center',
84
+ padding: '20px 10px',
85
+ cursor: 'pointer',
86
+ color: '#666',
87
+ fontSize: '1.06em',
88
+ }}
89
+ {...props}
90
+ />
91
+ )
92
+ }
@@ -14,9 +14,7 @@
14
14
  }
15
15
  .DocSearch-Button {
16
16
  background: transparent !important;
17
- padding: 0 !important;
18
- position: relative;
19
- top: -1px;
17
+ padding: 3px !important;
20
18
  outline: none !important;
21
19
  border: none !important;
22
20
  box-shadow: none !important;
@@ -26,6 +24,5 @@
26
24
  width: 21px !important;
27
25
  }
28
26
  .DocSearch-Button {
29
- margin-right: 3px !important;
30
- margin-left: 1px !important;
27
+ margin: 0 !important;
31
28
  }
@@ -0,0 +1,67 @@
1
+ export { Hit }
2
+
3
+ import React from 'react'
4
+ import { DocSearch } from '@docsearch/react'
5
+ import type { InternalDocSearchHit } from './types'
6
+ import { Snippet } from './Snippet'
7
+ import { SourceIcon } from './SourceIcon'
8
+ import { SelectIcon } from './SelectIcon'
9
+
10
+ type HitProps = Parameters<typeof DocSearch>[0]['hitComponent']
11
+ type ContentType = 'lvl0' | 'lvl1' | 'lvl2' | 'lvl3' | 'lvl4' | 'lvl5' | 'lvl6'
12
+
13
+ const Hit: HitProps = ({ hit }) => {
14
+ return (
15
+ <a href={hit.url}>
16
+ <div className="DocSearch-Hit-Container">
17
+ {(hit as InternalDocSearchHit).__docsearch_parent && (
18
+ <svg className="DocSearch-Hit-Tree" viewBox="0 0 24 54">
19
+ <g stroke="currentColor" fill="none" fillRule="evenodd" strokeLinecap="round" strokeLinejoin="round">
20
+ {!(hit as InternalDocSearchHit).__docsearch_parent ? (
21
+ <path d="M8 6v21M20 27H8.3" />
22
+ ) : (
23
+ <path d="M8 6v42M20 27H8.3" />
24
+ )}
25
+ </g>
26
+ </svg>
27
+ )}
28
+
29
+ <div className="DocSearch-Hit-icon">
30
+ <SourceIcon type={hit.type} />
31
+ </div>
32
+ {hit.hierarchy[hit.type as ContentType] && hit.type === 'lvl1' && (
33
+ <div className="DocSearch-Hit-content-wrapper">
34
+ <Snippet className="DocSearch-Hit-title" hit={hit} attribute="hierarchy.lvl1" />
35
+ {hit.content && <Snippet className="DocSearch-Hit-path" hit={hit} attribute="content" />}
36
+ </div>
37
+ )}
38
+
39
+ {hit.hierarchy[hit.type as ContentType] &&
40
+ (hit.type === 'lvl2' ||
41
+ hit.type === 'lvl3' ||
42
+ hit.type === 'lvl4' ||
43
+ hit.type === 'lvl5' ||
44
+ hit.type === 'lvl6') && (
45
+ <div className="DocSearch-Hit-content-wrapper">
46
+ <Snippet className="DocSearch-Hit-title" hit={hit} attribute={`hierarchy.${hit.type}`} />
47
+ <Snippet
48
+ className="DocSearch-Hit-path"
49
+ hit={hit}
50
+ attribute={hit.content ? 'content' : 'hierarchy.lvl1'}
51
+ />
52
+ </div>
53
+ )}
54
+
55
+ {hit.type === 'content' && (
56
+ <div className="DocSearch-Hit-content-wrapper">
57
+ <Snippet className="DocSearch-Hit-title" hit={hit} attribute="content" />
58
+ <Snippet className="DocSearch-Hit-path" hit={hit} attribute="hierarchy.lvl1" />
59
+ </div>
60
+ )}
61
+ <div className="DocSearch-Hit-action">
62
+ <SelectIcon />
63
+ </div>
64
+ </div>
65
+ </a>
66
+ )
67
+ }
@@ -0,0 +1,21 @@
1
+ # Components: Algolia
2
+
3
+ ## Overview
4
+
5
+ This directory contains a custom components for integrating Algolia's search functionality into our application. The components here are tailored to meet our specific requirements, ensuring a seamless user experience.
6
+
7
+ ## Creation Process
8
+
9
+ The `components/Algolia/` directory was created to address our need for a custom search implementation using Algolia Docsearch. Here’s a brief overview of how this directory was created:
10
+
11
+ 1. **Source Files**:
12
+ We sourced most of the files from [Algolia's DocSearch repository](https://github.com/algolia/docsearch/tree/9733ba9a503e18a27d5fef3470fde8b3bb54ec79/packages/docsearch-react/src), specifically extracting the base for our `<Hit>` component from their [Results.tsx](https://github.com/algolia/docsearch/blob/9733ba9a503e18a27d5fef3470fde8b3bb54ec79/packages/docsearch-react/src/Results.tsx#L113-L169) file, which includes the core rendering logic and styles.
13
+
14
+ 1. **Customization**:
15
+ - The components were modified to fit our needs. This included changing specific functionalities and adapting styles to match our application's design.
16
+ - Most notably, we created a custom `<Hit>` component to tailor the display of search results.
17
+
18
+ 2. **Removal of Unused Code**: We eliminated unnecessary parts of the original codebase that were not required and were incompatible with our implementation.
19
+
20
+ 3. **Minor adaptation**:
21
+ - While copying the original source code, we encountered issues with types that were not exported, requiring additional modifications to the components to ensure compatibility.
@@ -0,0 +1,12 @@
1
+ import React from 'react'
2
+
3
+ export function SelectIcon() {
4
+ return (
5
+ <svg className="DocSearch-Hit-Select-Icon" width="20" height="20" viewBox="0 0 20 20">
6
+ <g stroke="currentColor" fill="none" fillRule="evenodd" strokeLinecap="round" strokeLinejoin="round">
7
+ <path d="M18 3v4c0 2-2 4-4 4H2" />
8
+ <path d="M8 17l-6-6 6-6" />
9
+ </g>
10
+ </svg>
11
+ )
12
+ }
@@ -0,0 +1,32 @@
1
+ import { createElement } from 'react'
2
+ import { StoredDocSearchHit } from './types'
3
+
4
+ function getPropertyByPath(object: Record<string, any>, path: string): any {
5
+ const parts = path.split('.')
6
+
7
+ return parts.reduce((prev, current) => {
8
+ if (prev?.[current]) return prev[current]
9
+ return null
10
+ }, object)
11
+ }
12
+
13
+ interface SnippetProps<TItem> {
14
+ hit: TItem
15
+ attribute: string
16
+ tagName?: string
17
+ [prop: string]: unknown
18
+ }
19
+
20
+ export function Snippet<TItem extends StoredDocSearchHit>({
21
+ hit,
22
+ attribute,
23
+ tagName = 'span',
24
+ ...rest
25
+ }: SnippetProps<TItem>) {
26
+ return createElement(tagName, {
27
+ ...rest,
28
+ dangerouslySetInnerHTML: {
29
+ __html: getPropertyByPath(hit, `_snippetResult.${attribute}.value`) || getPropertyByPath(hit, attribute),
30
+ },
31
+ })
32
+ }
@@ -0,0 +1,55 @@
1
+ import React from 'react'
2
+
3
+ const LvlIcon: React.FC = () => {
4
+ return (
5
+ <svg width="20" height="20" viewBox="0 0 20 20">
6
+ <path
7
+ d="M17 6v12c0 .52-.2 1-1 1H4c-.7 0-1-.33-1-1V2c0-.55.42-1 1-1h8l5 5zM14 8h-3.13c-.51 0-.87-.34-.87-.87V4"
8
+ stroke="currentColor"
9
+ fill="none"
10
+ fillRule="evenodd"
11
+ strokeLinejoin="round"
12
+ />
13
+ </svg>
14
+ )
15
+ }
16
+
17
+ export function SourceIcon(props: { type: string }) {
18
+ switch (props.type) {
19
+ case 'lvl1':
20
+ return <LvlIcon />
21
+ case 'content':
22
+ return <ContentIcon />
23
+ default:
24
+ return <AnchorIcon />
25
+ }
26
+ }
27
+
28
+ function AnchorIcon() {
29
+ return (
30
+ <svg width="20" height="20" viewBox="0 0 20 20">
31
+ <path
32
+ d="M13 13h4-4V8H7v5h6v4-4H7V8H3h4V3v5h6V3v5h4-4v5zm-6 0v4-4H3h4z"
33
+ stroke="currentColor"
34
+ fill="none"
35
+ fillRule="evenodd"
36
+ strokeLinecap="round"
37
+ strokeLinejoin="round"
38
+ />
39
+ </svg>
40
+ )
41
+ }
42
+
43
+ function ContentIcon() {
44
+ return (
45
+ <svg width="20" height="20" viewBox="0 0 20 20">
46
+ <path
47
+ d="M17 5H3h14zm0 5H3h14zm0 5H3h14z"
48
+ stroke="currentColor"
49
+ fill="none"
50
+ fillRule="evenodd"
51
+ strokeLinejoin="round"
52
+ />
53
+ </svg>
54
+ )
55
+ }
@@ -0,0 +1,86 @@
1
+ export type InternalDocSearchHit = DocSearchHit & {
2
+ __docsearch_parent: InternalDocSearchHit | null
3
+ }
4
+
5
+ export type StoredDocSearchHit = Omit<DocSearchHit, '_highlightResult' | '_snippetResult'>
6
+
7
+ type ContentType = 'content' | 'lvl0' | 'lvl1' | 'lvl2' | 'lvl3' | 'lvl4' | 'lvl5' | 'lvl6'
8
+
9
+ interface DocSearchHitAttributeHighlightResult {
10
+ value: string
11
+ matchLevel: 'full' | 'none' | 'partial'
12
+ matchedWords: string[]
13
+ fullyHighlighted?: boolean
14
+ }
15
+
16
+ interface DocSearchHitHighlightResultHierarchy {
17
+ lvl0: DocSearchHitAttributeHighlightResult
18
+ lvl1: DocSearchHitAttributeHighlightResult
19
+ lvl2: DocSearchHitAttributeHighlightResult
20
+ lvl3: DocSearchHitAttributeHighlightResult
21
+ lvl4: DocSearchHitAttributeHighlightResult
22
+ lvl5: DocSearchHitAttributeHighlightResult
23
+ lvl6: DocSearchHitAttributeHighlightResult
24
+ }
25
+
26
+ interface DocSearchHitHighlightResult {
27
+ content: DocSearchHitAttributeHighlightResult
28
+ hierarchy: DocSearchHitHighlightResultHierarchy
29
+ hierarchy_camel: DocSearchHitHighlightResultHierarchy[]
30
+ }
31
+
32
+ interface DocSearchHitAttributeSnippetResult {
33
+ value: string
34
+ matchLevel: 'full' | 'none' | 'partial'
35
+ }
36
+
37
+ interface DocSearchHitSnippetResult {
38
+ content: DocSearchHitAttributeSnippetResult
39
+ hierarchy: DocSearchHitHighlightResultHierarchy
40
+ hierarchy_camel: DocSearchHitHighlightResultHierarchy[]
41
+ }
42
+
43
+ export declare type DocSearchHit = {
44
+ objectID: string
45
+ content: string | null
46
+ url: string
47
+ url_without_anchor: string
48
+ type: ContentType
49
+ anchor: string | null
50
+ hierarchy: {
51
+ lvl0: string
52
+ lvl1: string
53
+ lvl2: string | null
54
+ lvl3: string | null
55
+ lvl4: string | null
56
+ lvl5: string | null
57
+ lvl6: string | null
58
+ }
59
+ _highlightResult: DocSearchHitHighlightResult
60
+ _snippetResult: DocSearchHitSnippetResult
61
+ _rankingInfo?: {
62
+ promoted: boolean
63
+ nbTypos: number
64
+ firstMatchedWord: number
65
+ proximityDistance?: number
66
+ geoDistance: number
67
+ geoPrecision?: number
68
+ nbExactWords: number
69
+ words: number
70
+ filters: number
71
+ userScore: number
72
+ matchedGeoLocation?: {
73
+ lat: number
74
+ lng: number
75
+ distance: number
76
+ }
77
+ }
78
+ _distinctSeqID?: number
79
+ __autocomplete_indexName?: string
80
+ __autocomplete_queryID?: string
81
+ __autocomplete_algoliaCredentials?: {
82
+ appId: string
83
+ apiKey: string
84
+ }
85
+ __autocomplete_id?: number
86
+ }
@@ -79,12 +79,18 @@ function resolveHeadingsData(pageContext: PageContextOriginal) {
79
79
  }
80
80
  }
81
81
 
82
+ const topNavigationList = headingsResolved
83
+ .filter((heading) => heading.topNavigation)
84
+ .map((h) => ({ title: typeof h.topNavigation === 'string' ? h.topNavigation : h.title, url: h.url }))
85
+
82
86
  const pageContextAddendum = {
83
87
  navigationData,
84
88
  linksAll,
85
89
  isLandingPage,
86
90
  pageTitle,
87
91
  documentTitle,
92
+ noSideNavigation: activeHeading.noSideNavigation,
93
+ topNavigationList,
88
94
  }
89
95
  return pageContextAddendum
90
96
  }
@@ -166,10 +172,12 @@ function getActiveHeading(
166
172
  throw new Error(
167
173
  [
168
174
  `URL ${pc.bold(urlPathname)} not found in following URLs:`,
169
- ...headingsResolved
170
- .map((h) => ` ${h.url}`)
175
+ [...headingsResolved, ...headingsDetachedResolved]
171
176
  .filter(Boolean)
172
- .sort(),
177
+ .map((h) => h.url)
178
+ .sort()
179
+ .map((url) => ` ${url}`)
180
+ .join('\n'),
173
181
  ].join('\n'),
174
182
  )
175
183
  }
package/dist/+config.d.ts CHANGED
@@ -1,9 +1,11 @@
1
+ import type { ImportString } from 'vike/types';
1
2
  import type { Exports } from './config/resolvePageContext';
2
3
  declare const _default: {
3
4
  name: string;
4
5
  onRenderHtml: "import:@brillout/docpress/renderer/onRenderHtml:onRenderHtml";
5
6
  onRenderClient: "import:@brillout/docpress/renderer/onRenderClient:onRenderClient";
6
7
  onBeforeRender: "import:@brillout/docpress/renderer/onBeforeRender:onBeforeRender";
8
+ Layout: "import:@brillout/docpress/Layout:Layout";
7
9
  clientRouting: true;
8
10
  hydrationCanBeAborted: true;
9
11
  passToClient: string[];
@@ -14,6 +16,16 @@ declare const _default: {
14
16
  server: true;
15
17
  };
16
18
  };
19
+ Layout: {
20
+ env: {
21
+ client: true;
22
+ server: true;
23
+ };
24
+ };
25
+ };
26
+ prefetch: {
27
+ staticAssets: "hover";
28
+ pageContext: number;
17
29
  };
18
30
  };
19
31
  export default _default;
@@ -25,6 +37,7 @@ declare global {
25
37
  exports: Exports;
26
38
  }
27
39
  interface Config {
40
+ Layout: ReactComponent | ImportString;
28
41
  NavHeader?: {
29
42
  NavHeader: ReactComponent;
30
43
  navHeaderWrapperStyle?: React.CSSProperties;
package/dist/+config.js CHANGED
@@ -4,6 +4,7 @@ export default {
4
4
  onRenderHtml: 'import:@brillout/docpress/renderer/onRenderHtml:onRenderHtml',
5
5
  onRenderClient: 'import:@brillout/docpress/renderer/onRenderClient:onRenderClient',
6
6
  onBeforeRender: 'import:@brillout/docpress/renderer/onBeforeRender:onBeforeRender',
7
+ Layout: 'import:@brillout/docpress/Layout:Layout',
7
8
  clientRouting: true,
8
9
  hydrationCanBeAborted: true,
9
10
  passToClient: ['pageContextResolved'],
@@ -11,5 +12,12 @@ export default {
11
12
  NavHeader: {
12
13
  env: { client: true, server: true },
13
14
  },
15
+ Layout: {
16
+ env: { client: true, server: true },
17
+ },
18
+ },
19
+ prefetch: {
20
+ staticAssets: 'hover',
21
+ pageContext: Infinity,
14
22
  },
15
23
  };
@@ -0,0 +1,4 @@
1
+ export { Hit };
2
+ import { DocSearch } from '@docsearch/react';
3
+ type HitProps = Parameters<typeof DocSearch>[0]['hitComponent'];
4
+ declare const Hit: HitProps;
@@ -0,0 +1,30 @@
1
+ export { Hit };
2
+ import React from 'react';
3
+ import { Snippet } from './Snippet';
4
+ import { SourceIcon } from './SourceIcon';
5
+ import { SelectIcon } from './SelectIcon';
6
+ var Hit = function (_a) {
7
+ var hit = _a.hit;
8
+ return (React.createElement("a", { href: hit.url },
9
+ React.createElement("div", { className: "DocSearch-Hit-Container" },
10
+ hit.__docsearch_parent && (React.createElement("svg", { className: "DocSearch-Hit-Tree", viewBox: "0 0 24 54" },
11
+ React.createElement("g", { stroke: "currentColor", fill: "none", fillRule: "evenodd", strokeLinecap: "round", strokeLinejoin: "round" }, !hit.__docsearch_parent ? (React.createElement("path", { d: "M8 6v21M20 27H8.3" })) : (React.createElement("path", { d: "M8 6v42M20 27H8.3" }))))),
12
+ React.createElement("div", { className: "DocSearch-Hit-icon" },
13
+ React.createElement(SourceIcon, { type: hit.type })),
14
+ hit.hierarchy[hit.type] && hit.type === 'lvl1' && (React.createElement("div", { className: "DocSearch-Hit-content-wrapper" },
15
+ React.createElement(Snippet, { className: "DocSearch-Hit-title", hit: hit, attribute: "hierarchy.lvl1" }),
16
+ hit.content && React.createElement(Snippet, { className: "DocSearch-Hit-path", hit: hit, attribute: "content" }))),
17
+ hit.hierarchy[hit.type] &&
18
+ (hit.type === 'lvl2' ||
19
+ hit.type === 'lvl3' ||
20
+ hit.type === 'lvl4' ||
21
+ hit.type === 'lvl5' ||
22
+ hit.type === 'lvl6') && (React.createElement("div", { className: "DocSearch-Hit-content-wrapper" },
23
+ React.createElement(Snippet, { className: "DocSearch-Hit-title", hit: hit, attribute: "hierarchy.".concat(hit.type) }),
24
+ React.createElement(Snippet, { className: "DocSearch-Hit-path", hit: hit, attribute: hit.content ? 'content' : 'hierarchy.lvl1' }))),
25
+ hit.type === 'content' && (React.createElement("div", { className: "DocSearch-Hit-content-wrapper" },
26
+ React.createElement(Snippet, { className: "DocSearch-Hit-title", hit: hit, attribute: "content" }),
27
+ React.createElement(Snippet, { className: "DocSearch-Hit-path", hit: hit, attribute: "hierarchy.lvl1" }))),
28
+ React.createElement("div", { className: "DocSearch-Hit-action" },
29
+ React.createElement(SelectIcon, null)))));
30
+ };
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare function SelectIcon(): React.JSX.Element;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ export function SelectIcon() {
3
+ return (React.createElement("svg", { className: "DocSearch-Hit-Select-Icon", width: "20", height: "20", viewBox: "0 0 20 20" },
4
+ React.createElement("g", { stroke: "currentColor", fill: "none", fillRule: "evenodd", strokeLinecap: "round", strokeLinejoin: "round" },
5
+ React.createElement("path", { d: "M18 3v4c0 2-2 4-4 4H2" }),
6
+ React.createElement("path", { d: "M8 17l-6-6 6-6" }))));
7
+ }
@@ -0,0 +1,13 @@
1
+ import { StoredDocSearchHit } from './types';
2
+ interface SnippetProps<TItem> {
3
+ hit: TItem;
4
+ attribute: string;
5
+ tagName?: string;
6
+ [prop: string]: unknown;
7
+ }
8
+ export declare function Snippet<TItem extends StoredDocSearchHit>({ hit, attribute, tagName, ...rest }: SnippetProps<TItem>): import("react").DOMElement<{
9
+ dangerouslySetInnerHTML: {
10
+ __html: any;
11
+ };
12
+ }, Element>;
13
+ export {};
@@ -0,0 +1,37 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import { createElement } from 'react';
24
+ function getPropertyByPath(object, path) {
25
+ var parts = path.split('.');
26
+ return parts.reduce(function (prev, current) {
27
+ if (prev === null || prev === void 0 ? void 0 : prev[current])
28
+ return prev[current];
29
+ return null;
30
+ }, object);
31
+ }
32
+ export function Snippet(_a) {
33
+ var hit = _a.hit, attribute = _a.attribute, _b = _a.tagName, tagName = _b === void 0 ? 'span' : _b, rest = __rest(_a, ["hit", "attribute", "tagName"]);
34
+ return createElement(tagName, __assign(__assign({}, rest), { dangerouslySetInnerHTML: {
35
+ __html: getPropertyByPath(hit, "_snippetResult.".concat(attribute, ".value")) || getPropertyByPath(hit, attribute),
36
+ } }));
37
+ }
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export declare function SourceIcon(props: {
3
+ type: string;
4
+ }): React.JSX.Element;