@brillout/docpress 0.8.14 → 0.8.16
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/Layout.tsx +256 -179
- package/MenuModal.tsx +54 -46
- package/{Links.tsx → NavSecondaryContent.tsx} +5 -8
- package/components/HorizontalLine.tsx +4 -3
- package/components/Note.tsx +6 -2
- package/config/resolveHeadingsData.ts +7 -10
- package/css/code/block.css +5 -5
- package/css/code/inline.css +1 -1
- package/css/colorize-on-hover.css +2 -2
- package/dist/Layout.d.ts +10 -6
- package/dist/Layout.js +167 -122
- package/dist/MenuModal.d.ts +2 -0
- package/dist/MenuModal.js +46 -46
- package/dist/{Links.d.ts → NavSecondaryContent.d.ts} +3 -2
- package/dist/{Links.js → NavSecondaryContent.js} +5 -7
- package/dist/components/HorizontalLine.d.ts +1 -1
- package/dist/components/HorizontalLine.js +3 -2
- package/dist/components/Note.js +4 -3
- package/dist/config/resolveHeadingsData.d.ts +3 -4
- package/dist/config/resolveHeadingsData.js +5 -8
- package/dist/config/resolvePageContext.d.ts +2 -3
- package/dist/docsearch/SearchLink.js +1 -1
- package/dist/navigation/Collapsible.d.ts +10 -0
- package/dist/navigation/Collapsible.js +35 -0
- package/dist/navigation/Navigation.d.ts +0 -3
- package/dist/navigation/Navigation.js +106 -55
- package/dist/renderer/determineNavItemsColumnLayout.d.ts +3 -0
- package/dist/renderer/{determineColumnEntries.js → determineNavItemsColumnLayout.js} +34 -28
- package/dist/renderer/usePageContext.d.ts +2 -2
- package/dist/renderer/usePageContext.js +2 -4
- package/dist/utils/Style.d.ts +5 -0
- package/dist/utils/Style.js +6 -0
- package/dist/utils/cls.d.ts +3 -0
- package/dist/utils/cls.js +5 -0
- package/dist/utils/throttle.d.ts +1 -0
- package/dist/utils/throttle.js +14 -0
- package/docsearch/SearchLink.tsx +1 -1
- package/global.d.ts +1 -1
- package/navigation/Collapsible.css +11 -0
- package/navigation/Collapsible.tsx +64 -0
- package/navigation/Navigation.css +12 -6
- package/navigation/Navigation.tsx +191 -80
- package/package.json +1 -1
- package/renderer/{determineColumnEntries.ts → determineNavItemsColumnLayout.ts} +35 -29
- package/renderer/initOnNavigation.ts +37 -0
- package/renderer/onRenderClient.tsx +2 -0
- package/renderer/usePageContext.tsx +2 -5
- package/utils/Style.tsx +7 -0
- package/utils/cls.ts +8 -0
- package/utils/throttle.ts +10 -0
- package/dist/renderer/determineColumnEntries.d.ts +0 -3
package/MenuModal.tsx
CHANGED
|
@@ -2,30 +2,38 @@ export { MenuModal }
|
|
|
2
2
|
export { toggleMenuModal }
|
|
3
3
|
export { openMenuModal }
|
|
4
4
|
export { closeMenuModal }
|
|
5
|
+
export { closeMenuModalWithDelay }
|
|
5
6
|
|
|
6
7
|
import React from 'react'
|
|
7
8
|
import { usePageContext } from './renderer/usePageContext'
|
|
8
9
|
import { NavigationContent } from './navigation/Navigation'
|
|
9
10
|
import { css } from './utils/css'
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { isBrowser } from './utils/isBrowser'
|
|
11
|
+
import { containerQueryMobileLayout, containerQueryMobileMenu } from './Layout'
|
|
12
|
+
import { NavSecondaryContent } from './NavSecondaryContent'
|
|
13
13
|
import { getViewportWidth } from './utils/getViewportWidth'
|
|
14
|
+
import { Style } from './utils/Style'
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
let closeMenuModalPending: NodeJS.Timeout
|
|
16
17
|
|
|
17
18
|
function MenuModal({ isTopNav }: { isTopNav: boolean }) {
|
|
18
19
|
return (
|
|
19
20
|
<>
|
|
20
|
-
<
|
|
21
|
+
<Style>{getStyle()}</Style>
|
|
21
22
|
<div
|
|
22
23
|
id="menu-modal"
|
|
23
24
|
className="link-hover-animation add-transition"
|
|
24
25
|
style={{
|
|
25
26
|
position: isTopNav ? 'absolute' : 'fixed',
|
|
26
27
|
width: '100%',
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
/* Firefox doesn't support `dvh` yet: https://caniuse.com/?search=dvh
|
|
29
|
+
* - Always use `dvh` instead of `vh` once Firefox supports it.
|
|
30
|
+
* - We use dvh because of mobile: https://stackoverflow.com/questions/37112218/css3-100vh-not-constant-in-mobile-browser/72245072#72245072
|
|
31
|
+
height: 'calc(100dvh - var(--nav-head-height))',
|
|
32
|
+
/*/
|
|
33
|
+
height: 'calc(100vh - var(--nav-head-height))',
|
|
34
|
+
maxHeight: 'calc(100dvh - var(--nav-head-height))',
|
|
35
|
+
//*/
|
|
36
|
+
top: 'var(--nav-head-height)',
|
|
29
37
|
left: 0,
|
|
30
38
|
zIndex: 9999,
|
|
31
39
|
overflow: 'scroll',
|
|
@@ -40,20 +48,16 @@ function MenuModal({ isTopNav }: { isTopNav: boolean }) {
|
|
|
40
48
|
// Place <LinksBottom /> to the bottom
|
|
41
49
|
display: 'flex',
|
|
42
50
|
flexDirection: 'column',
|
|
43
|
-
minHeight: 'calc(
|
|
51
|
+
minHeight: 'calc(100dvh - var(--nav-head-height))',
|
|
44
52
|
justifyContent: 'space-between',
|
|
45
53
|
// We don't set `container` to parent beacuse of a Chrome bug (showing a blank <MenuModal>)
|
|
46
|
-
|
|
54
|
+
container: 'container-viewport / inline-size',
|
|
47
55
|
}}
|
|
48
56
|
>
|
|
49
57
|
<Nav />
|
|
50
|
-
|
|
51
|
-
<LinksBottom />
|
|
52
|
-
*/}
|
|
58
|
+
<NavSecondary className="show-only-for-mobile" />
|
|
53
59
|
</div>
|
|
54
|
-
|
|
55
|
-
<CloseButton />
|
|
56
|
-
*/}
|
|
60
|
+
<CloseButton className="show-only-for-mobile" />
|
|
57
61
|
</div>
|
|
58
62
|
</>
|
|
59
63
|
)
|
|
@@ -63,15 +67,17 @@ function Nav() {
|
|
|
63
67
|
const navItems = pageContext.navItemsAll
|
|
64
68
|
return <NavigationContent columnLayout={true} navItems={navItems} />
|
|
65
69
|
}
|
|
66
|
-
function
|
|
70
|
+
function NavSecondary({ className }: { className: string }) {
|
|
67
71
|
return (
|
|
68
72
|
<div
|
|
73
|
+
className={className}
|
|
69
74
|
style={{
|
|
70
75
|
display: 'flex',
|
|
71
76
|
justifyContent: 'center',
|
|
77
|
+
marginTop: 20,
|
|
72
78
|
}}
|
|
73
79
|
>
|
|
74
|
-
<
|
|
80
|
+
<NavSecondaryContent style={{ height: 70 }} />
|
|
75
81
|
</div>
|
|
76
82
|
)
|
|
77
83
|
}
|
|
@@ -86,17 +92,28 @@ html:not(.menu-modal-show) #menu-modal {
|
|
|
86
92
|
html.menu-modal-show {
|
|
87
93
|
overflow: hidden !important;
|
|
88
94
|
}
|
|
89
|
-
@container(min-width: ${
|
|
95
|
+
@container container-viewport (min-width: ${containerQueryMobileLayout}px) {
|
|
90
96
|
#menu-modal .nav-item-level-3 {
|
|
91
97
|
display: none;
|
|
92
98
|
}
|
|
93
99
|
}
|
|
100
|
+
@media(max-width: ${containerQueryMobileMenu}px) {
|
|
101
|
+
#menu-modal {
|
|
102
|
+
--nav-head-height: 0px !important;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
@media(min-width: ${containerQueryMobileMenu + 1}px) {
|
|
106
|
+
.show-only-for-mobile {
|
|
107
|
+
display: none !important;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
94
110
|
`
|
|
95
111
|
}
|
|
96
112
|
|
|
97
|
-
function CloseButton() {
|
|
113
|
+
function CloseButton({ className }: { className: string }) {
|
|
98
114
|
return (
|
|
99
115
|
<div
|
|
116
|
+
className={className}
|
|
100
117
|
onClick={toggleMenuModal}
|
|
101
118
|
style={{ position: 'fixed', top: 0, right: 0, zIndex: 10, padding: 11, cursor: 'pointer' }}
|
|
102
119
|
aria-label={'Escape\nCtrl\xa0+\xa0M'}
|
|
@@ -128,7 +145,10 @@ function CloseButton() {
|
|
|
128
145
|
|
|
129
146
|
function toggleMenuModal() {
|
|
130
147
|
document.documentElement.classList.toggle('menu-modal-show')
|
|
131
|
-
if (
|
|
148
|
+
if (
|
|
149
|
+
document.documentElement.classList.contains('menu-modal-show') &&
|
|
150
|
+
getViewportWidth() < containerQueryMobileLayout
|
|
151
|
+
) {
|
|
132
152
|
autoScroll()
|
|
133
153
|
}
|
|
134
154
|
}
|
|
@@ -136,43 +156,31 @@ function autoScroll() {
|
|
|
136
156
|
const nav = document.querySelector('#menu-modal .navigation-content')!
|
|
137
157
|
const href = window.location.pathname
|
|
138
158
|
const navLinks = Array.from(nav.querySelectorAll(`a[href="${href}"]`))
|
|
139
|
-
const navLink = navLinks[0]
|
|
159
|
+
const navLink = navLinks[0] as HTMLElement | undefined
|
|
140
160
|
if (!navLink) return
|
|
161
|
+
// None of the following seemes to be working: https://stackoverflow.com/questions/19669786/check-if-element-is-visible-in-dom
|
|
162
|
+
if (findCollapsibleEl(navLink)!.classList.contains('collapsible-collapsed')) return
|
|
141
163
|
navLink.scrollIntoView({
|
|
142
164
|
behavior: 'instant',
|
|
143
165
|
block: 'center',
|
|
144
166
|
inline: 'start',
|
|
145
167
|
})
|
|
146
168
|
}
|
|
169
|
+
function findCollapsibleEl(navLink: HTMLElement | undefined) {
|
|
170
|
+
let parentEl: HTMLElement | null | undefined = navLink
|
|
171
|
+
while (parentEl) {
|
|
172
|
+
if (parentEl.classList.contains('collapsible')) return parentEl
|
|
173
|
+
parentEl = parentEl.parentElement
|
|
174
|
+
}
|
|
175
|
+
return null
|
|
176
|
+
}
|
|
147
177
|
function openMenuModal() {
|
|
178
|
+
clearTimeout(closeMenuModalPending)
|
|
148
179
|
document.documentElement.classList.add('menu-modal-show')
|
|
149
180
|
}
|
|
150
181
|
function closeMenuModal() {
|
|
151
182
|
document.documentElement.classList.remove('menu-modal-show')
|
|
152
183
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (!isBrowser()) return
|
|
156
|
-
document.addEventListener('click', onLinkClick)
|
|
157
|
-
// It's redundant (and onLinkClick() is enough), but just to be sure.
|
|
158
|
-
addEventListener('hashchange', closeMenuModal)
|
|
159
|
-
}
|
|
160
|
-
function onLinkClick(ev: MouseEvent) {
|
|
161
|
-
if (ev.altKey || ev.ctrlKey || ev.metaKey || ev.shiftKey) return
|
|
162
|
-
const linkTag = findLinkTag(ev.target as HTMLElement)
|
|
163
|
-
if (!linkTag) return
|
|
164
|
-
const href = linkTag.getAttribute('href')
|
|
165
|
-
if (!href) return
|
|
166
|
-
if (!href.startsWith('/') && !href.startsWith('#')) return
|
|
167
|
-
closeMenuModal()
|
|
168
|
-
}
|
|
169
|
-
function findLinkTag(target: HTMLElement): null | HTMLElement {
|
|
170
|
-
while (target.tagName !== 'A') {
|
|
171
|
-
const { parentNode } = target
|
|
172
|
-
if (!parentNode) {
|
|
173
|
-
return null
|
|
174
|
-
}
|
|
175
|
-
target = parentNode as HTMLElement
|
|
176
|
-
}
|
|
177
|
-
return target
|
|
184
|
+
function closeMenuModalWithDelay(delay: number) {
|
|
185
|
+
closeMenuModalPending = setTimeout(closeMenuModal, delay)
|
|
178
186
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export { Links }
|
|
1
|
+
export { NavSecondaryContent }
|
|
3
2
|
|
|
4
3
|
import React from 'react'
|
|
5
4
|
import iconGithub from './icons/github.svg'
|
|
@@ -10,7 +9,7 @@ import iconLanguages from './icons/languages.svg'
|
|
|
10
9
|
import { usePageContext } from './renderer/usePageContext'
|
|
11
10
|
import '@docsearch/css'
|
|
12
11
|
|
|
13
|
-
function
|
|
12
|
+
function NavSecondaryContent(props: { style?: React.CSSProperties; className?: string }) {
|
|
14
13
|
const pageContext = usePageContext()
|
|
15
14
|
const { projectInfo, i18n } = pageContext.config
|
|
16
15
|
const iconI18n = !i18n ? null : (
|
|
@@ -23,13 +22,11 @@ function Links({ style }: { style?: React.CSSProperties }) {
|
|
|
23
22
|
)
|
|
24
23
|
return (
|
|
25
24
|
<div
|
|
25
|
+
{...props}
|
|
26
26
|
style={{
|
|
27
27
|
display: 'flex',
|
|
28
28
|
alignItems: 'center',
|
|
29
|
-
|
|
30
|
-
justifyContent: 'left',
|
|
31
|
-
height: '100%',
|
|
32
|
-
...style,
|
|
29
|
+
...props.style,
|
|
33
30
|
}}
|
|
34
31
|
>
|
|
35
32
|
{iconI18n}
|
|
@@ -53,7 +50,7 @@ function ChangelogButton() {
|
|
|
53
50
|
style={{
|
|
54
51
|
display: 'flex',
|
|
55
52
|
alignItems: 'center',
|
|
56
|
-
padding:
|
|
53
|
+
padding: '0 5px',
|
|
57
54
|
height: '100%',
|
|
58
55
|
}}
|
|
59
56
|
>
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
|
|
3
1
|
export { HorizontalLine }
|
|
4
2
|
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { cls } from '../utils/cls'
|
|
5
|
+
|
|
5
6
|
function HorizontalLine({ primary }: { primary?: true }) {
|
|
6
7
|
return (
|
|
7
|
-
<div className={
|
|
8
|
+
<div className={cls(primary && 'primary')} style={{ textAlign: 'center' }}>
|
|
8
9
|
<hr
|
|
9
10
|
style={{
|
|
10
11
|
display: 'inline-block',
|
package/components/Note.tsx
CHANGED
|
@@ -93,8 +93,12 @@ function NoteGeneric({
|
|
|
93
93
|
return (
|
|
94
94
|
<blockquote className={className} style={style}>
|
|
95
95
|
<div style={{ marginBottom: 20 }} />
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
{icon && (
|
|
97
|
+
<>
|
|
98
|
+
<span style={{ fontFamily: 'emoji' }}>{icon}</span>
|
|
99
|
+
<span style={{ width: iconMargin ?? undefined, display: 'inline-block' }}></span>{' '}
|
|
100
|
+
</>
|
|
101
|
+
)}
|
|
98
102
|
<div className="blockquote-content">{children}</div>
|
|
99
103
|
<div style={{ marginTop: 20 }} />
|
|
100
104
|
</blockquote>
|
|
@@ -9,12 +9,12 @@ import type {
|
|
|
9
9
|
} from '../types/Heading'
|
|
10
10
|
import type { Config } from '../types/Config'
|
|
11
11
|
import { getConfig } from './getConfig'
|
|
12
|
-
import type { NavItem
|
|
12
|
+
import type { NavItem } from '../navigation/Navigation'
|
|
13
13
|
import type { LinkData } from '../components'
|
|
14
14
|
import type { Exports, PageContextOriginal } from './resolvePageContext'
|
|
15
15
|
import pc from '@brillout/picocolors'
|
|
16
16
|
import { parseTitle } from '../parseTitle'
|
|
17
|
-
import {
|
|
17
|
+
import { determineNavItemsColumnLayout } from '../renderer/determineNavItemsColumnLayout'
|
|
18
18
|
assert(!isBrowser())
|
|
19
19
|
|
|
20
20
|
type PageSectionResolved = {
|
|
@@ -53,19 +53,17 @@ function resolveHeadingsData(pageContext: PageContextOriginal) {
|
|
|
53
53
|
...headingsDetachedResolved.map(headingToLinkData),
|
|
54
54
|
]
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
let
|
|
58
|
-
let navItemsAll: NavItemAll[]
|
|
56
|
+
let navItemsAll: NavItem[]
|
|
57
|
+
let navItemsDetached: NavItem[] | undefined
|
|
59
58
|
{
|
|
60
59
|
const navItemsPageSections = pageSectionsResolved
|
|
61
60
|
.filter((pageSection) => pageSection.pageSectionLevel === 2)
|
|
62
61
|
.map(pageSectionToNavItem)
|
|
63
62
|
navItemsAll = headingsResolved.map(headingToNavItem)
|
|
64
|
-
|
|
63
|
+
determineNavItemsColumnLayout(navItemsAll)
|
|
65
64
|
if (isDetachedPage) {
|
|
66
|
-
|
|
65
|
+
navItemsDetached = [headingToNavItem(activeHeading), ...navItemsPageSections]
|
|
67
66
|
} else {
|
|
68
|
-
navItems = navItemsAll
|
|
69
67
|
const activeHeadingIndex = navItemsAll.findIndex((navItem) => navItem.url === pageContext.urlPathname)
|
|
70
68
|
assert(activeHeadingIndex >= 0)
|
|
71
69
|
navItemsPageSections.forEach((navItem, i) => {
|
|
@@ -75,9 +73,8 @@ function resolveHeadingsData(pageContext: PageContextOriginal) {
|
|
|
75
73
|
}
|
|
76
74
|
|
|
77
75
|
const pageContextAddendum = {
|
|
78
|
-
isDetachedPage,
|
|
79
|
-
navItems,
|
|
80
76
|
navItemsAll,
|
|
77
|
+
navItemsDetached,
|
|
81
78
|
linksAll,
|
|
82
79
|
isLandingPage,
|
|
83
80
|
pageTitle,
|
package/css/code/block.css
CHANGED
|
@@ -22,27 +22,27 @@ figure[data-rehype-pretty-code-figure] {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/* 821px screen width => the width of code blocks isn't shrinked anymore => no need to reduce the font-size of code blocks */
|
|
25
|
-
@container(max-width: 820px) {
|
|
25
|
+
@container container-viewport (max-width: 820px) {
|
|
26
26
|
pre > code {
|
|
27
27
|
font-size: 0.9em !important;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
@container(max-width: 720px) {
|
|
30
|
+
@container container-viewport (max-width: 720px) {
|
|
31
31
|
pre > code {
|
|
32
32
|
font-size: 0.8em !important;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
@container(max-width: 620px) {
|
|
35
|
+
@container container-viewport (max-width: 620px) {
|
|
36
36
|
pre > code {
|
|
37
37
|
font-size: 0.7em !important;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
@container(max-width: 550px) {
|
|
40
|
+
@container container-viewport (max-width: 550px) {
|
|
41
41
|
pre > code {
|
|
42
42
|
font-size: 0.6em !important;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
@container(max-width: 450px) {
|
|
45
|
+
@container container-viewport (max-width: 450px) {
|
|
46
46
|
pre > code {
|
|
47
47
|
font-size: 0.5em !important;
|
|
48
48
|
}
|
package/css/code/inline.css
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
.link-hover-animation a,
|
|
23
23
|
.link-hover-animation .menu-toggle,
|
|
24
24
|
.add-transition {
|
|
25
|
-
transition:
|
|
25
|
+
transition: none 0.4s ease-in-out;
|
|
26
26
|
}
|
|
27
27
|
[class^='decolorize-'],
|
|
28
28
|
[class*=' decolorize-'] {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
}
|
|
31
31
|
.link-hover-animation a,
|
|
32
32
|
.menu-toggle {
|
|
33
|
-
transition-property: color, background-color;
|
|
33
|
+
transition-property: color, background-color !important;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
.decolorize-7 {
|
package/dist/Layout.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
export { Layout };
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
2
|
+
export { containerQueryMobileLayout };
|
|
3
|
+
export { containerQueryMobileMenu };
|
|
4
|
+
export { navLeftWidthMin };
|
|
5
|
+
export { navLeftWidthMax };
|
|
6
|
+
export { unexpandNav };
|
|
5
7
|
import React from 'react';
|
|
6
|
-
declare const
|
|
7
|
-
declare const
|
|
8
|
-
declare const
|
|
8
|
+
declare const navLeftWidthMax = 370;
|
|
9
|
+
declare const navLeftWidthMin = 300;
|
|
10
|
+
declare const containerQueryMobileMenu = 1000;
|
|
11
|
+
declare const containerQueryMobileLayout: number;
|
|
9
12
|
declare function Layout({ children }: {
|
|
10
13
|
children: React.ReactNode;
|
|
11
14
|
}): React.JSX.Element;
|
|
15
|
+
declare function unexpandNav(): void;
|