@brillout/docpress 0.7.9 → 0.7.10-commit-776b1fc
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/+config.ts +2 -10
- package/Layout.tsx +397 -67
- package/{navigation/NavigationHeader.tsx → Links.tsx} +6 -57
- package/MenuModal.tsx +146 -0
- package/autoScrollNav.ts +4 -5
- package/components/CodeBlockTransformer.tsx +0 -2
- package/components/Note.css +4 -4
- package/components/Note.tsx +0 -2
- package/components/Supporters.tsx +1 -0
- package/config/resolveHeadingsData.ts +20 -23
- package/config/resolvePageContext.ts +11 -1
- package/css/code/block.css +5 -5
- package/css/code/inline.css +1 -1
- package/css/code.css +9 -5
- package/css/index.css +0 -4
- package/css/reset.css +0 -6
- package/dist/+config.d.ts +1 -13
- package/dist/+config.js +0 -3
- package/dist/components/CodeBlockTransformer.d.ts +1 -0
- package/dist/components/CodeBlockTransformer.js +1 -0
- package/dist/components/Note.d.ts +1 -0
- package/dist/components/Note.js +1 -0
- package/dist/components/Supporters.js +1 -0
- package/dist/config/resolveHeadingsData.d.ts +5 -8
- package/dist/config/resolveHeadingsData.js +20 -22
- package/dist/config/resolvePageContext.d.ts +5 -7
- package/dist/config/resolvePageContext.js +2 -1
- package/dist/navigation/Navigation.d.ts +12 -11
- package/dist/navigation/Navigation.js +75 -73
- package/dist/renderer/getStyleColumnLayout.d.ts +7 -0
- package/dist/renderer/getStyleColumnLayout.js +167 -0
- package/dist/types/Heading.d.ts +2 -4
- package/dist/utils/client.d.ts +1 -0
- package/dist/utils/client.js +1 -0
- package/dist/utils/css.d.ts +1 -0
- package/dist/utils/css.js +27 -0
- package/dist/utils/getGlobalObject.d.ts +1 -0
- package/dist/utils/getGlobalObject.js +9 -0
- package/docsearch/DocSearchInstall.tsx +23 -0
- package/docsearch/SearchLink.tsx +48 -0
- package/docsearch/closeDocsearchModal.ts +29 -0
- package/initKeyBindings.ts +41 -0
- package/installSectionUrlHashs.ts +6 -5
- package/navigation/Navigation.css +101 -3
- package/navigation/Navigation.tsx +109 -124
- package/package.json +1 -8
- package/renderer/getPageContextCurrent.ts +16 -0
- package/renderer/getPageElement.tsx +19 -7
- package/renderer/getStyleColumnLayout.ts +187 -0
- package/renderer/onRenderClient.tsx +20 -24
- package/renderer/onRenderHtml.tsx +4 -0
- package/types/Heading.ts +2 -5
- package/types.d.ts +8 -0
- package/utils/client.ts +1 -0
- package/utils/css.ts +26 -0
- package/utils/getGlobalObject.ts +11 -0
- package/Layout.css +0 -63
- package/MobileHeader.tsx +0 -70
- package/algolia/DocSearch.css +0 -28
- package/components/FeatureList/FeatureList.client.ts +0 -60
- package/components/FeatureList/FeatureList.css +0 -119
- package/components/FeatureList/FeatureList.tsx +0 -114
- package/components/FeatureList/chevron.svg +0 -7
- package/css/block-design.css +0 -4
- package/dist/autoScrollNav.d.ts +0 -3
- package/dist/autoScrollNav.js +0 -36
- package/dist/components/Algolia/Hit.d.ts +0 -4
- package/dist/components/Algolia/Hit.js +0 -30
- package/dist/components/Algolia/SelectIcon.d.ts +0 -2
- package/dist/components/Algolia/SelectIcon.js +0 -7
- package/dist/components/Algolia/Snippet.d.ts +0 -13
- package/dist/components/Algolia/Snippet.js +0 -37
- package/dist/components/Algolia/SourceIcon.d.ts +0 -4
- package/dist/components/Algolia/SourceIcon.js +0 -23
- package/dist/components/Algolia/types.d.ts +0 -79
- package/dist/components/Algolia/types.js +0 -1
- package/dist/navigation/NavigationHeader.d.ts +0 -8
- package/dist/navigation/NavigationHeader.js +0 -75
- package/dist/navigation/navigation-fullscreen/NavigationFullscreenButton.d.ts +0 -6
- package/dist/navigation/navigation-fullscreen/NavigationFullscreenButton.js +0 -23
- package/dist/navigation/navigation-fullscreen/hotkeyLabel.d.ts +0 -1
- package/dist/navigation/navigation-fullscreen/hotkeyLabel.js +0 -1
- package/navigation/Navigation-highlight.css +0 -41
- package/navigation/Navigation-items.css +0 -119
- package/navigation/Navigation-layout.css +0 -127
- package/navigation/initMobileNavigation.ts +0 -23
- package/navigation/initPressKit.ts +0 -19
- package/navigation/navigation-fullscreen/NavigationFullscreenButton.css +0 -32
- package/navigation/navigation-fullscreen/NavigationFullscreenButton.tsx +0 -47
- package/navigation/navigation-fullscreen/chevron.svg +0 -1
- package/navigation/navigation-fullscreen/close.svg +0 -4
- package/navigation/navigation-fullscreen/hotkeyLabel.ts +0 -1
- package/navigation/navigation-fullscreen/initNavigationFullscreen.ts +0 -147
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export { initKeyBindings }
|
|
2
|
+
|
|
3
|
+
import { closeDocsearchModal } from './docsearch/closeDocsearchModal'
|
|
4
|
+
import { closeMenuModal, toggleMenuModal } from './MenuModal'
|
|
5
|
+
|
|
6
|
+
function initKeyBindings() {
|
|
7
|
+
window.addEventListener(
|
|
8
|
+
// Cannot use `keyup`: https://stackoverflow.com/questions/66595035/how-to-detect-escape-key-if-search-bar-of-browser-is-open/66600548#66600548
|
|
9
|
+
'keydown',
|
|
10
|
+
(ev) => {
|
|
11
|
+
if (ev.key === 'Escape') {
|
|
12
|
+
closeDocsearchModal()
|
|
13
|
+
closeMenuModal()
|
|
14
|
+
return
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const key = (ev.key || '').toLowerCase()
|
|
18
|
+
const isCtrl = ev.metaKey || ev.ctrlKey
|
|
19
|
+
if (isCtrl && key === 'm') {
|
|
20
|
+
ev.preventDefault()
|
|
21
|
+
closeDocsearchModal()
|
|
22
|
+
toggleMenuModal()
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Replicate https://github.com/algolia/docsearch/blob/90f3c6aabbc324fe49e9a1dfe0906fcd4d90f27b/packages/docsearch-react/src/useDocSearchKeyboardEvents.ts#L45-L49
|
|
27
|
+
if ((isCtrl && key === 'k') || (key === '/' && !isEditingContent(ev))) {
|
|
28
|
+
ev.preventDefault()
|
|
29
|
+
closeMenuModal()
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
false,
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
function isEditingContent(event: KeyboardEvent): boolean {
|
|
37
|
+
const element = event.target as HTMLElement
|
|
38
|
+
const tagName = element.tagName
|
|
39
|
+
|
|
40
|
+
return element.isContentEditable || tagName === 'INPUT' || tagName === 'SELECT' || tagName === 'TEXTAREA'
|
|
41
|
+
}
|
|
@@ -3,10 +3,11 @@ export { installSectionUrlHashs }
|
|
|
3
3
|
import { assert } from './utils/client'
|
|
4
4
|
|
|
5
5
|
function installSectionUrlHashs() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
{
|
|
7
|
+
const isLandingPage = window.location.pathname === '/'
|
|
8
|
+
const isDocPage = !!document.querySelector('.doc-page')
|
|
9
|
+
assert(isLandingPage !== isDocPage)
|
|
10
|
+
if (!isDocPage) return
|
|
10
11
|
}
|
|
11
12
|
const headings = [...Array.from(document.querySelectorAll('h2')), ...Array.from(document.querySelectorAll('h3'))]
|
|
12
13
|
headings.forEach((heading) => {
|
|
@@ -26,7 +27,7 @@ function installSectionUrlHashs() {
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
function assertNavLink(urlHash: string, heading: HTMLHeadingElement) {
|
|
29
|
-
const navigationEl = document.querySelector('#navigation-
|
|
30
|
+
const navigationEl = document.querySelector('#nav-left .navigation-content')!
|
|
30
31
|
{
|
|
31
32
|
const { pathname } = window.location
|
|
32
33
|
const parentNavLinkMatch = Array.from(navigationEl.querySelectorAll(`a[href="${pathname}"]`))
|
|
@@ -1,3 +1,101 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
.nav-item {
|
|
2
|
+
display: block;
|
|
3
|
+
white-space: nowrap;
|
|
4
|
+
overflow-x: hidden;
|
|
5
|
+
--padding-left-global: 9px;
|
|
6
|
+
--padding-left-additional: 0px;
|
|
7
|
+
}
|
|
8
|
+
.nav-item code {
|
|
9
|
+
font-size: 0.9em;
|
|
10
|
+
}
|
|
11
|
+
.nav-item-level-1 + .nav-item-level-4 {
|
|
12
|
+
margin-top: -2px;
|
|
13
|
+
}
|
|
14
|
+
.nav-item-level-4 {
|
|
15
|
+
margin-top: 14px;
|
|
16
|
+
margin-bottom: -1px;
|
|
17
|
+
color: #999;
|
|
18
|
+
font-size: 12px;
|
|
19
|
+
font-weight: 400;
|
|
20
|
+
letter-spacing: 0.15ch;
|
|
21
|
+
padding-left: var(--padding-left-global);
|
|
22
|
+
padding-right: 4px;
|
|
23
|
+
text-decoration: none;
|
|
24
|
+
}
|
|
25
|
+
.nav-item-level-1 {
|
|
26
|
+
font-size: 15.4px;
|
|
27
|
+
text-transform: uppercase;
|
|
28
|
+
font-weight: 600;
|
|
29
|
+
letter-spacing: 0.15ch;
|
|
30
|
+
color: var(--color-text);
|
|
31
|
+
padding: 12px 0;
|
|
32
|
+
padding-left: calc(var(--padding-left-global) - 2px);
|
|
33
|
+
padding-right: 4px;
|
|
34
|
+
text-decoration: none;
|
|
35
|
+
}
|
|
36
|
+
.nav-item-level-2 {
|
|
37
|
+
text-decoration: none;
|
|
38
|
+
font-size: 14.4px;
|
|
39
|
+
font-weight: 400;
|
|
40
|
+
letter-spacing: 0.15ch;
|
|
41
|
+
color: var(--color-text);
|
|
42
|
+
padding-left: var(--padding-left-global);
|
|
43
|
+
padding-right: 0;
|
|
44
|
+
--padding: 4px;
|
|
45
|
+
padding-top: var(--padding);
|
|
46
|
+
padding-bottom: var(--padding);
|
|
47
|
+
}
|
|
48
|
+
.nav-item-level-3 {
|
|
49
|
+
font-size: 12px;
|
|
50
|
+
font-weight: 400;
|
|
51
|
+
letter-spacing: 0.15ch;
|
|
52
|
+
color: var(--color-text);
|
|
53
|
+
text-decoration: none;
|
|
54
|
+
--padding: 5px;
|
|
55
|
+
|
|
56
|
+
/* #ededed === rgb(237, 237, 237)
|
|
57
|
+
* #f5f5f5 === rgb(245, 245, 245)
|
|
58
|
+
* 1 - (237 / 245) === 0.03265306122
|
|
59
|
+
background-color: #ededed;
|
|
60
|
+
*/
|
|
61
|
+
background-color: rgba(0,0,0, 0.03265306122);
|
|
62
|
+
padding: var(--padding) 0;
|
|
63
|
+
padding-left: calc(var(--padding-left-global) + var(--padding-left-additional));
|
|
64
|
+
}
|
|
65
|
+
#menu-modal .nav-item-level-3 {
|
|
66
|
+
border-right: 4px solid #eee;
|
|
67
|
+
}
|
|
68
|
+
.nav-item {
|
|
69
|
+
/*
|
|
70
|
+
--shadow-size: 14px;
|
|
71
|
+
--shadow-color: rgba(0, 0, 0, 0.09);
|
|
72
|
+
*/
|
|
73
|
+
--shadow-size: 7px;
|
|
74
|
+
--shadow-color: rgba(0, 0, 0, 0.11);
|
|
75
|
+
--shadow-size-minus: calc(-1 * var(--shadow-size));
|
|
76
|
+
--shadow-top: inset 0px var(--shadow-size) var(--shadow-size) var(--shadow-size-minus) var(--shadow-color);
|
|
77
|
+
--shadow-bottom: inset 0px var(--shadow-size-minus) var(--shadow-size) var(--shadow-size-minus) var(--shadow-color);
|
|
78
|
+
--box-shadow-top: 0 0;
|
|
79
|
+
--box-shadow-bottom: 0 0;
|
|
80
|
+
box-shadow: var(--box-shadow-top), var(--box-shadow-bottom);
|
|
81
|
+
}
|
|
82
|
+
.nav-item-level-3.nav-item-first-of-its-kind {
|
|
83
|
+
padding-top: calc(var(--padding) * 1.8);
|
|
84
|
+
--box-shadow-top: var(--shadow-top);
|
|
85
|
+
}
|
|
86
|
+
.nav-item-level-3.nav-item-last-of-its-kind {
|
|
87
|
+
padding-bottom: calc(var(--padding) * 1.8);
|
|
88
|
+
--box-shadow-bottom: var(--shadow-bottom);
|
|
89
|
+
}
|
|
90
|
+
.nav-item-level-2,
|
|
91
|
+
.nav-item-level-3 {
|
|
92
|
+
position: relative;
|
|
93
|
+
}
|
|
94
|
+
.nav-item-level-2.is-active {
|
|
95
|
+
/* #ededed === rgb(237, 237, 237)
|
|
96
|
+
* #f5f5f5 === rgb(245, 245, 245)
|
|
97
|
+
* 1 - (237 / 245) === 0.03265306122
|
|
98
|
+
background-color: #ededed;
|
|
99
|
+
*/
|
|
100
|
+
background-color: rgba(0,0,0, 0.03265306122);
|
|
101
|
+
}
|
|
@@ -1,90 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
1
|
+
// TODO/refactor: rename file and/or component
|
|
2
|
+
export { NavigationContent }
|
|
3
|
+
// TODO/refactor: do this only on the server side?
|
|
4
4
|
export type { NavItem }
|
|
5
|
+
export type { NavItemAll }
|
|
5
6
|
|
|
6
7
|
import React from 'react'
|
|
7
|
-
import {
|
|
8
|
-
import { assert, Emoji, assertWarning, jsxToTextContent } from '../utils/server'
|
|
8
|
+
import { assert, assertWarning, jsxToTextContent } from '../utils/server'
|
|
9
9
|
import './Navigation.css'
|
|
10
|
-
import { NavigationFullscreenClose } from './navigation-fullscreen/NavigationFullscreenButton'
|
|
11
10
|
import { parseTitle } from '../parseTitle'
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
type NavigationData = Parameters<typeof Navigation>[0]
|
|
15
|
-
|
|
16
|
-
function Navigation({
|
|
17
|
-
navItems,
|
|
18
|
-
navItemsAll,
|
|
19
|
-
currentUrl,
|
|
20
|
-
isDetachedPage,
|
|
21
|
-
}: {
|
|
22
|
-
navItems: NavItem[]
|
|
23
|
-
navItemsAll: NavItem[]
|
|
24
|
-
currentUrl: string
|
|
25
|
-
isDetachedPage: boolean
|
|
26
|
-
}) {
|
|
27
|
-
return (
|
|
28
|
-
<>
|
|
29
|
-
<div id="navigation-container">
|
|
30
|
-
<NavigationHeader />
|
|
31
|
-
<div id="navigation-body">
|
|
32
|
-
{isDetachedPage && (
|
|
33
|
-
<>
|
|
34
|
-
{navItems.length > 1 && (
|
|
35
|
-
<NavigationContent id="navigation-content-detached" navItems={navItems} currentUrl={currentUrl} />
|
|
36
|
-
)}
|
|
37
|
-
<DetachedPageNote />
|
|
38
|
-
</>
|
|
39
|
-
)}
|
|
40
|
-
<NavigationContent id="navigation-content-main" navItems={navItemsAll} currentUrl={currentUrl} />
|
|
41
|
-
<NavigationFullscreenClose />
|
|
42
|
-
</div>
|
|
43
|
-
</div>
|
|
44
|
-
{/* Early scrolling, to avoid flashing */}
|
|
45
|
-
<script dangerouslySetInnerHTML={{ __html: autoScrollNav_SSR }}></script>
|
|
46
|
-
</>
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function NavigationMask() {
|
|
51
|
-
return <div id="mobile-navigation-mask" />
|
|
52
|
-
}
|
|
11
|
+
import { usePageContext } from '../renderer/usePageContext'
|
|
12
|
+
import '@docsearch/css'
|
|
53
13
|
|
|
54
14
|
type NavItem = {
|
|
55
15
|
level: number
|
|
56
16
|
url?: string | null
|
|
57
17
|
title: string
|
|
58
18
|
titleInNav: string
|
|
19
|
+
menuModalFullWidth?: true
|
|
59
20
|
}
|
|
60
|
-
type
|
|
61
|
-
|
|
62
|
-
isActiveFirst: boolean
|
|
63
|
-
isActiveLast: boolean
|
|
64
|
-
isFirstOfItsKind: boolean
|
|
65
|
-
isLastOfItsKind: boolean
|
|
21
|
+
type NavItemAll = NavItem & {
|
|
22
|
+
columnLayoutEntry?: true
|
|
66
23
|
}
|
|
67
|
-
|
|
68
24
|
function NavigationContent(props: {
|
|
69
|
-
id: 'navigation-content-main' | 'navigation-content-detached'
|
|
70
25
|
navItems: NavItem[]
|
|
71
|
-
|
|
26
|
+
showOnlyRelevant?: true
|
|
27
|
+
columnLayout?: true
|
|
72
28
|
}) {
|
|
73
|
-
const
|
|
74
|
-
const
|
|
29
|
+
const pageContext = usePageContext()
|
|
30
|
+
const navItemsWithComputed = getNavItemsWithComputed(props.navItems, pageContext.urlPathname)
|
|
75
31
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
32
|
+
let navContent: React.ReactNode
|
|
33
|
+
if (!props.columnLayout) {
|
|
34
|
+
navContent = navItemsWithComputed
|
|
35
|
+
.filter((navItemGroup) => !props.showOnlyRelevant || navItemGroup.isRelevant)
|
|
36
|
+
.map((navItem, i) => <NavItemComponent navItem={navItem} key={i} />)
|
|
37
|
+
} else {
|
|
38
|
+
assert(!props.showOnlyRelevant)
|
|
39
|
+
const navItemsColumnLayout = groupByColumns(navItemsWithComputed)
|
|
40
|
+
navContent = (
|
|
41
|
+
<>
|
|
42
|
+
{navItemsColumnLayout.map((columns, i) => (
|
|
43
|
+
<div
|
|
44
|
+
key={i}
|
|
45
|
+
style={{
|
|
46
|
+
display: 'flex',
|
|
47
|
+
justifyContent: 'center',
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
<div
|
|
51
|
+
className={`column-layout-${i}`}
|
|
52
|
+
style={{
|
|
53
|
+
flexGrow: 1,
|
|
54
|
+
columnGap: 20,
|
|
55
|
+
}}
|
|
56
|
+
>
|
|
57
|
+
{columns.map((navItemColumnEntry, k) => (
|
|
58
|
+
<div
|
|
59
|
+
key={k}
|
|
60
|
+
className="column-layout-entry"
|
|
61
|
+
style={{
|
|
62
|
+
breakInside: 'avoid',
|
|
63
|
+
marginBottom: !navItemColumnEntry.isFullWidth ? 35 : undefined,
|
|
64
|
+
width: '100%',
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
<NavItemComponent navItem={navItemColumnEntry} />
|
|
68
|
+
{navItemColumnEntry.navItemChilds.map((navItem, k) => (
|
|
69
|
+
<NavItemComponent navItem={navItem} key={k} />
|
|
70
|
+
))}
|
|
71
|
+
</div>
|
|
72
|
+
))}
|
|
73
|
+
</div>
|
|
85
74
|
</div>
|
|
86
75
|
))}
|
|
87
|
-
|
|
76
|
+
</>
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<div className="navigation-content" style={{ marginTop: 10 }}>
|
|
82
|
+
{navContent}
|
|
88
83
|
</div>
|
|
89
84
|
)
|
|
90
85
|
}
|
|
@@ -118,8 +113,6 @@ function NavItemComponent({
|
|
|
118
113
|
'nav-item',
|
|
119
114
|
'nav-item-level-' + navItem.level,
|
|
120
115
|
navItem.url && navItem.isActive && ' is-active',
|
|
121
|
-
navItem.url && navItem.isActiveFirst && ' is-active-first',
|
|
122
|
-
navItem.url && navItem.isActiveLast && ' is-active-last',
|
|
123
116
|
navItem.isFirstOfItsKind && 'nav-item-first-of-its-kind',
|
|
124
117
|
navItem.isLastOfItsKind && 'nav-item-last-of-its-kind',
|
|
125
118
|
]
|
|
@@ -133,85 +126,77 @@ function NavItemComponent({
|
|
|
133
126
|
)
|
|
134
127
|
}
|
|
135
128
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const
|
|
129
|
+
type NavItemsColumnEntry = NavItemComputed & { navItemChilds: NavItemComputed[]; isFullWidth: boolean }
|
|
130
|
+
function groupByColumns(navItems: NavItemComputed[]) {
|
|
131
|
+
const navItemsColumnLayout: NavItemsColumnEntry[][] = []
|
|
132
|
+
let navItemsColumnEntries: NavItemsColumnEntry[] = []
|
|
133
|
+
let isFullWidth: boolean | undefined
|
|
139
134
|
navItems.forEach((navItem) => {
|
|
140
|
-
if (navItem.level ===
|
|
141
|
-
|
|
135
|
+
if (navItem.level === 1) {
|
|
136
|
+
const isFullWidthPrevious = isFullWidth
|
|
137
|
+
isFullWidth = !!navItem.menuModalFullWidth
|
|
138
|
+
if (isFullWidthPrevious !== undefined && isFullWidthPrevious !== isFullWidth) {
|
|
139
|
+
navItemsColumnLayout.push(navItemsColumnEntries)
|
|
140
|
+
navItemsColumnEntries = []
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
assert(isFullWidth !== undefined)
|
|
144
|
+
if (navItem.columnLayoutEntry) {
|
|
145
|
+
assert(navItem.level === 1 || navItem.level === 4)
|
|
146
|
+
const navItemColumnEntry = { ...navItem, navItemChilds: [], isFullWidth }
|
|
147
|
+
navItemsColumnEntries.push(navItemColumnEntry)
|
|
142
148
|
} else {
|
|
143
|
-
|
|
149
|
+
assert(navItem.level !== 1)
|
|
150
|
+
navItemsColumnEntries[navItemsColumnEntries.length - 1].navItemChilds.push(navItem)
|
|
144
151
|
}
|
|
145
152
|
})
|
|
146
|
-
|
|
153
|
+
navItemsColumnLayout.push(navItemsColumnEntries)
|
|
154
|
+
return navItemsColumnLayout
|
|
147
155
|
}
|
|
148
156
|
|
|
149
|
-
|
|
150
|
-
|
|
157
|
+
type NavItemComputed = ReturnType<typeof getNavItemsWithComputed>[number]
|
|
158
|
+
function getNavItemsWithComputed(navItems: NavItemAll[], currentUrl: string) {
|
|
159
|
+
let navItemIdx: number | undefined
|
|
160
|
+
const navItemsWithComputed = navItems.map((navItem, i) => {
|
|
151
161
|
assert([1, 2, 3, 4].includes(navItem.level), navItem)
|
|
152
162
|
|
|
153
163
|
const navItemPrevious = navItems[i - 1]
|
|
154
164
|
const navItemNext = navItems[i + 1]
|
|
155
165
|
|
|
156
|
-
let isActiveFirst = false
|
|
157
|
-
let isActiveLast = false
|
|
158
166
|
let isActive = false
|
|
159
167
|
if (navItem.url === currentUrl) {
|
|
160
168
|
assert(navItem.level === 2, { currentUrl })
|
|
169
|
+
assert(navItemIdx === undefined)
|
|
170
|
+
navItemIdx = i
|
|
161
171
|
isActive = true
|
|
162
|
-
isActiveFirst = true
|
|
163
|
-
if (navItemNext?.level !== 3) {
|
|
164
|
-
isActiveLast = true
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
if (navItem.level === 3) {
|
|
168
|
-
isActive = true
|
|
169
|
-
if (navItemNext?.level !== 3) {
|
|
170
|
-
isActiveLast = true
|
|
171
|
-
}
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
const isFirstOfItsKind = navItem.level !== navItemPrevious?.level
|
|
175
175
|
const isLastOfItsKind = navItem.level !== navItemNext?.level
|
|
176
176
|
|
|
177
|
-
|
|
177
|
+
const navItemComputed = {
|
|
178
178
|
...navItem,
|
|
179
179
|
isActive,
|
|
180
|
-
|
|
181
|
-
isActiveLast,
|
|
180
|
+
isRelevant: false,
|
|
182
181
|
isFirstOfItsKind,
|
|
183
182
|
isLastOfItsKind,
|
|
184
183
|
}
|
|
184
|
+
|
|
185
|
+
return navItemComputed
|
|
185
186
|
})
|
|
186
|
-
}
|
|
187
187
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
>
|
|
203
|
-
<Emoji name="info" />{' '}
|
|
204
|
-
<b>
|
|
205
|
-
<em>Detached</em>
|
|
206
|
-
</b>
|
|
207
|
-
<span
|
|
208
|
-
style={{
|
|
209
|
-
opacity: 0.8,
|
|
210
|
-
}}
|
|
211
|
-
>
|
|
212
|
-
{' '}
|
|
213
|
-
— this page isn't listed in the navigation below.
|
|
214
|
-
</span>
|
|
215
|
-
</div>
|
|
216
|
-
)
|
|
188
|
+
// Set `isRelevant`
|
|
189
|
+
assert(navItemIdx !== undefined)
|
|
190
|
+
for (let i = navItemIdx; i >= 0; i--) {
|
|
191
|
+
const navItem = navItemsWithComputed[i]!
|
|
192
|
+
navItem.isRelevant = true
|
|
193
|
+
if (navItem.level === 1) break
|
|
194
|
+
}
|
|
195
|
+
for (let i = navItemIdx; i < navItemsWithComputed.length; i++) {
|
|
196
|
+
const navItem = navItemsWithComputed[i]!
|
|
197
|
+
if (navItem.level === 1) break
|
|
198
|
+
navItem.isRelevant = true
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return navItemsWithComputed
|
|
217
202
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brillout/docpress",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.10-commit-776b1fc",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@brillout/picocolors": "^1.0.10",
|
|
@@ -33,10 +33,6 @@
|
|
|
33
33
|
"./renderer/onBeforeRender": "./renderer/onBeforeRender.ts",
|
|
34
34
|
"./Layout": "./Layout.tsx",
|
|
35
35
|
".": "./index.ts",
|
|
36
|
-
"./FeatureList/FeatureList": "./components/FeatureList/FeatureList.tsx",
|
|
37
|
-
"./FeatureList/FeatureList.client": {
|
|
38
|
-
"browser": "./components/FeatureList/FeatureList.client.ts"
|
|
39
|
-
},
|
|
40
36
|
"./vite-config": "./dist/vite.config.js",
|
|
41
37
|
"./config": "./dist/+config.js",
|
|
42
38
|
"./style": "./css/index.css",
|
|
@@ -57,9 +53,6 @@
|
|
|
57
53
|
],
|
|
58
54
|
"config": [
|
|
59
55
|
"./dist/+config.d.ts"
|
|
60
|
-
],
|
|
61
|
-
"FeatureList/*": [
|
|
62
|
-
"./components/FeatureList/*"
|
|
63
56
|
]
|
|
64
57
|
}
|
|
65
58
|
},
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { getpageContextCurrent }
|
|
2
|
+
export { setpageContextCurrent }
|
|
3
|
+
|
|
4
|
+
import { PageContextClient } from 'vike/types'
|
|
5
|
+
import { getGlobalObject } from '../utils/getGlobalObject'
|
|
6
|
+
|
|
7
|
+
const globalObject = getGlobalObject<{
|
|
8
|
+
pageContextCurrent?: PageContextClient
|
|
9
|
+
}>('onRenderClient.ts', {})
|
|
10
|
+
|
|
11
|
+
function getpageContextCurrent(): undefined | PageContextClient {
|
|
12
|
+
return globalObject.pageContextCurrent
|
|
13
|
+
}
|
|
14
|
+
function setpageContextCurrent(pageContext: PageContextClient): void {
|
|
15
|
+
globalObject.pageContextCurrent = pageContext
|
|
16
|
+
}
|
|
@@ -4,22 +4,34 @@ import type { PageContext } from 'vike/types'
|
|
|
4
4
|
import type { PageContextResolved } from '../config/resolvePageContext'
|
|
5
5
|
import { PageContextProvider, PageContextProvider2 } from './usePageContext'
|
|
6
6
|
import React from 'react'
|
|
7
|
+
import { DocSearchInstall } from '../docsearch/DocSearchInstall'
|
|
7
8
|
|
|
8
9
|
function getPageElement(pageContext: PageContext, pageContextResolved: PageContextResolved) {
|
|
9
10
|
const { Page } = pageContext
|
|
10
|
-
const
|
|
11
|
+
const Layout = pageContext.config.Layout || PassThrough
|
|
11
12
|
const page = (
|
|
13
|
+
<Wrapper {...{ pageContext, pageContextResolved }}>
|
|
14
|
+
<Layout pageContext={pageContextResolved} pageContext2={pageContext}>
|
|
15
|
+
<Page />
|
|
16
|
+
</Layout>
|
|
17
|
+
<DocSearchInstall />
|
|
18
|
+
</Wrapper>
|
|
19
|
+
)
|
|
20
|
+
return page
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function Wrapper({
|
|
24
|
+
children,
|
|
25
|
+
pageContext,
|
|
26
|
+
pageContextResolved,
|
|
27
|
+
}: { children: React.ReactNode; pageContext: PageContext; pageContextResolved: PageContextResolved }) {
|
|
28
|
+
return (
|
|
12
29
|
<React.StrictMode>
|
|
13
30
|
<PageContextProvider2 pageContext={pageContext}>
|
|
14
|
-
<PageContextProvider pageContext={pageContextResolved}>
|
|
15
|
-
<Layout pageContext={pageContextResolved} pageContext2={pageContext}>
|
|
16
|
-
<Page />
|
|
17
|
-
</Layout>
|
|
18
|
-
</PageContextProvider>
|
|
31
|
+
<PageContextProvider pageContext={pageContextResolved}>{children}</PageContextProvider>
|
|
19
32
|
</PageContextProvider2>
|
|
20
33
|
</React.StrictMode>
|
|
21
34
|
)
|
|
22
|
-
return page
|
|
23
35
|
}
|
|
24
36
|
|
|
25
37
|
function PassThrough({ children }: any) {
|