@brillout/docpress 0.7.8 → 0.7.9
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 +1 -1
- package/autoScrollNav.ts +20 -20
- package/dist/autoScrollNav.d.ts +3 -0
- package/dist/autoScrollNav.js +36 -0
- package/dist/navigation/Navigation.js +3 -1
- package/dist/navigation/navigation-fullscreen/NavigationFullscreenButton.js +2 -2
- package/navigation/Navigation.tsx +3 -0
- package/navigation/navigation-fullscreen/NavigationFullscreenButton.tsx +2 -0
- package/navigation/navigation-fullscreen/initNavigationFullscreen.ts +1 -1
- package/package.json +1 -1
- package/renderer/onRenderClient.tsx +7 -22
package/Layout.tsx
CHANGED
|
@@ -42,7 +42,7 @@ function Layout({ children }: { children: React.ReactNode }) {
|
|
|
42
42
|
</a>
|
|
43
43
|
)}
|
|
44
44
|
<div style={{ display: 'flex', alignItems: 'center' }}>
|
|
45
|
-
<TopNavigationLink id="doclink" aria-label={hotkeyLabel} data-balloon-pos="left">
|
|
45
|
+
<TopNavigationLink id="doclink" aria-label={hotkeyLabel} data-balloon-pos="left" data-balloon-blunt>
|
|
46
46
|
Documentation
|
|
47
47
|
</TopNavigationLink>
|
|
48
48
|
{topNavigationList.map(({ title, url }) => (
|
package/autoScrollNav.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
export { autoScrollNav }
|
|
2
|
+
export const autoScrollNav_SSR = `autoScrollNav();${autoScrollNav.toString()}`
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
// - We cannot use TypeScript syntax because of autoScrollNav_SSR
|
|
5
|
+
// - We have to save & restore `dodocument.documentElement.scrollTop` because scrollIntoView() scrolls the main view. (I don't know why).
|
|
6
|
+
// - Failed alternatives:
|
|
7
|
+
// - scrollIntoViewIfNeeded() (https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded) would work (it doesn't scroll the main view) but Firefox doesn't support it.
|
|
8
|
+
// - Doesn't work: the scrolling is off by hundreds of px (I guess because this function runs too early while the page is still rendering).
|
|
9
|
+
// ```js
|
|
10
|
+
// const navigationContainerEl = document.getElementById("navigation-container")
|
|
11
|
+
// const offset = navLink.offsetTop - (window.innerHeight / 2)
|
|
12
|
+
// navigationContainerEl.scrollTop = offset
|
|
13
|
+
// ```
|
|
14
|
+
// - Doesn't work: scrollIntoView() still scrolls the main view
|
|
15
|
+
// ```js
|
|
16
|
+
// const overflowOriginal = document.documentElement.style.overflow
|
|
17
|
+
// document.documentElement.style.overflow = 'hidden'
|
|
18
|
+
// // ...
|
|
19
|
+
// document.documentElement.style.overflow = overflowOriginal
|
|
20
|
+
// ```
|
|
4
21
|
|
|
5
22
|
function autoScrollNav() {
|
|
6
23
|
const navigationEl = document.getElementById('navigation-content-main')
|
|
7
|
-
|
|
24
|
+
if (!navigationEl) return
|
|
8
25
|
const href = window.location.pathname
|
|
9
|
-
const navLinks
|
|
10
|
-
assert(navLinks.length <= 1, { navLinks, href })
|
|
26
|
+
const navLinks = Array.from(navigationEl.querySelectorAll(`a[href="${href}"]`))
|
|
11
27
|
const navLink = navLinks[0]
|
|
12
28
|
if (!navLink) return
|
|
13
29
|
|
|
14
|
-
/* Doesn't work: the scrolling is off by hundreds of px (I guess because this function runs too early while the page is still rendering)
|
|
15
|
-
const navigationContainerEl = document.getElementById("navigation-container")
|
|
16
|
-
const offset = navLink.offsetTop - (window.innerHeight / 2)
|
|
17
|
-
navigationContainerEl.scrollTop = offset
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/* Doesn't work: scrollIntoView() still scrolls the main view
|
|
21
|
-
const overflowOriginal = document.documentElement.style.overflow
|
|
22
|
-
document.documentElement.style.overflow = 'hidden'
|
|
23
|
-
...
|
|
24
|
-
document.documentElement.style.overflow = overflowOriginal
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
30
|
const scrollTopOriginal = document.documentElement.scrollTop
|
|
28
31
|
navLink.scrollIntoView({
|
|
29
|
-
// @ts-ignore https://github.com/microsoft/TypeScript/issues/46654
|
|
30
32
|
behavior: 'instant',
|
|
31
33
|
block: 'center',
|
|
32
34
|
inline: 'start',
|
|
33
35
|
})
|
|
34
|
-
// Avoid scrollIntoView() from scrolling the main view.
|
|
35
|
-
// - Alternatively scrollIntoViewIfNeeded() (https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded) would work (it doesn't scroll the main view) but Firefox doesn't support it.
|
|
36
36
|
document.documentElement.scrollTop = scrollTopOriginal
|
|
37
37
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export { autoScrollNav };
|
|
2
|
+
export var autoScrollNav_SSR = "autoScrollNav();".concat(autoScrollNav.toString());
|
|
3
|
+
// - We cannot use TypeScript syntax because of autoScrollNav_SSR
|
|
4
|
+
// - We have to save & restore `dodocument.documentElement.scrollTop` because scrollIntoView() scrolls the main view. (I don't know why).
|
|
5
|
+
// - Failed alternatives:
|
|
6
|
+
// - scrollIntoViewIfNeeded() (https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded) would work (it doesn't scroll the main view) but Firefox doesn't support it.
|
|
7
|
+
// - Doesn't work: the scrolling is off by hundreds of px (I guess because this function runs too early while the page is still rendering).
|
|
8
|
+
// ```js
|
|
9
|
+
// const navigationContainerEl = document.getElementById("navigation-container")
|
|
10
|
+
// const offset = navLink.offsetTop - (window.innerHeight / 2)
|
|
11
|
+
// navigationContainerEl.scrollTop = offset
|
|
12
|
+
// ```
|
|
13
|
+
// - Doesn't work: scrollIntoView() still scrolls the main view
|
|
14
|
+
// ```js
|
|
15
|
+
// const overflowOriginal = document.documentElement.style.overflow
|
|
16
|
+
// document.documentElement.style.overflow = 'hidden'
|
|
17
|
+
// // ...
|
|
18
|
+
// document.documentElement.style.overflow = overflowOriginal
|
|
19
|
+
// ```
|
|
20
|
+
function autoScrollNav() {
|
|
21
|
+
var navigationEl = document.getElementById('navigation-content-main');
|
|
22
|
+
if (!navigationEl)
|
|
23
|
+
return;
|
|
24
|
+
var href = window.location.pathname;
|
|
25
|
+
var navLinks = Array.from(navigationEl.querySelectorAll("a[href=\"".concat(href, "\"]")));
|
|
26
|
+
var navLink = navLinks[0];
|
|
27
|
+
if (!navLink)
|
|
28
|
+
return;
|
|
29
|
+
var scrollTopOriginal = document.documentElement.scrollTop;
|
|
30
|
+
navLink.scrollIntoView({
|
|
31
|
+
behavior: 'instant',
|
|
32
|
+
block: 'center',
|
|
33
|
+
inline: 'start',
|
|
34
|
+
});
|
|
35
|
+
document.documentElement.scrollTop = scrollTopOriginal;
|
|
36
|
+
}
|
|
@@ -17,6 +17,7 @@ import { assert, Emoji, assertWarning, jsxToTextContent } from '../utils/server'
|
|
|
17
17
|
import './Navigation.css';
|
|
18
18
|
import { NavigationFullscreenClose } from './navigation-fullscreen/NavigationFullscreenButton';
|
|
19
19
|
import { parseTitle } from '../parseTitle';
|
|
20
|
+
import { autoScrollNav_SSR } from '../autoScrollNav';
|
|
20
21
|
function Navigation(_a) {
|
|
21
22
|
var navItems = _a.navItems, navItemsAll = _a.navItemsAll, currentUrl = _a.currentUrl, isDetachedPage = _a.isDetachedPage;
|
|
22
23
|
return (React.createElement(React.Fragment, null,
|
|
@@ -27,7 +28,8 @@ function Navigation(_a) {
|
|
|
27
28
|
navItems.length > 1 && (React.createElement(NavigationContent, { id: "navigation-content-detached", navItems: navItems, currentUrl: currentUrl })),
|
|
28
29
|
React.createElement(DetachedPageNote, null))),
|
|
29
30
|
React.createElement(NavigationContent, { id: "navigation-content-main", navItems: navItemsAll, currentUrl: currentUrl }),
|
|
30
|
-
React.createElement(NavigationFullscreenClose, null)))
|
|
31
|
+
React.createElement(NavigationFullscreenClose, null))),
|
|
32
|
+
React.createElement("script", { dangerouslySetInnerHTML: { __html: autoScrollNav_SSR } })));
|
|
31
33
|
}
|
|
32
34
|
function NavigationMask() {
|
|
33
35
|
return React.createElement("div", { id: "mobile-navigation-mask" });
|
|
@@ -15,9 +15,9 @@ function NavigationFullscreenButton() {
|
|
|
15
15
|
overflow: 'hidden',
|
|
16
16
|
} },
|
|
17
17
|
React.createElement("div", null)),
|
|
18
|
-
React.createElement("div", { style: { position: 'fixed', height: '100vh', width: 20 }, "aria-label": hotkeyLabel, "data-balloon-pos": "right" }))));
|
|
18
|
+
React.createElement("div", { style: { position: 'fixed', height: '100vh', width: 20 }, "aria-label": hotkeyLabel, "data-balloon-pos": "right", "data-balloon-blunt": true }))));
|
|
19
19
|
}
|
|
20
20
|
function NavigationFullscreenClose() {
|
|
21
|
-
return (React.createElement("a", { id: "navigation-fullscreen-close", style: { position: 'absolute', top: 11, right: 11, zIndex: 10 }, "aria-label": hotkeyLabel, "data-balloon-pos": "left" },
|
|
21
|
+
return (React.createElement("a", { id: "navigation-fullscreen-close", style: { position: 'absolute', top: 11, right: 11, zIndex: 10 }, "aria-label": hotkeyLabel, "data-balloon-pos": "left", "data-balloon-blunt": true },
|
|
22
22
|
React.createElement("img", { src: closeIcon, height: 50, width: 50, style: { display: 'block' } })));
|
|
23
23
|
}
|
|
@@ -9,6 +9,7 @@ import { assert, Emoji, assertWarning, jsxToTextContent } from '../utils/server'
|
|
|
9
9
|
import './Navigation.css'
|
|
10
10
|
import { NavigationFullscreenClose } from './navigation-fullscreen/NavigationFullscreenButton'
|
|
11
11
|
import { parseTitle } from '../parseTitle'
|
|
12
|
+
import { autoScrollNav_SSR } from '../autoScrollNav'
|
|
12
13
|
|
|
13
14
|
type NavigationData = Parameters<typeof Navigation>[0]
|
|
14
15
|
|
|
@@ -40,6 +41,8 @@ function Navigation({
|
|
|
40
41
|
<NavigationFullscreenClose />
|
|
41
42
|
</div>
|
|
42
43
|
</div>
|
|
44
|
+
{/* Early scrolling, to avoid flashing */}
|
|
45
|
+
<script dangerouslySetInnerHTML={{ __html: autoScrollNav_SSR }}></script>
|
|
43
46
|
</>
|
|
44
47
|
)
|
|
45
48
|
}
|
|
@@ -25,6 +25,7 @@ function NavigationFullscreenButton() {
|
|
|
25
25
|
style={{ position: 'fixed', height: '100vh', width: 20 }}
|
|
26
26
|
aria-label={hotkeyLabel}
|
|
27
27
|
data-balloon-pos="right"
|
|
28
|
+
data-balloon-blunt
|
|
28
29
|
></div>
|
|
29
30
|
</a>
|
|
30
31
|
</>
|
|
@@ -38,6 +39,7 @@ function NavigationFullscreenClose() {
|
|
|
38
39
|
style={{ position: 'absolute', top: 11, right: 11, zIndex: 10 }}
|
|
39
40
|
aria-label={hotkeyLabel}
|
|
40
41
|
data-balloon-pos="left"
|
|
42
|
+
data-balloon-blunt
|
|
41
43
|
>
|
|
42
44
|
<img src={closeIcon} height={50} width={50} style={{ display: 'block' }} />
|
|
43
45
|
</a>
|
|
@@ -7,7 +7,7 @@ import { assert } from '../../utils/client'
|
|
|
7
7
|
let scrollPositionBeforeToggle: number
|
|
8
8
|
|
|
9
9
|
function initNavigationFullscreenOnce() {
|
|
10
|
-
scrollPositionBeforeToggle = 0
|
|
10
|
+
scrollPositionBeforeToggle = 0 // Initial scroll of fullscreen navigation is 0
|
|
11
11
|
initKeyBindings()
|
|
12
12
|
}
|
|
13
13
|
function initKeyBindings() {
|
package/package.json
CHANGED
|
@@ -18,12 +18,13 @@ import { installSectionUrlHashs } from '../installSectionUrlHashs'
|
|
|
18
18
|
import { addFeatureClickHandlers, addTwitterWidgets } from '../components/FeatureList/FeatureList.client'
|
|
19
19
|
|
|
20
20
|
addEcosystemStamp()
|
|
21
|
-
initOnLinkClick()
|
|
22
21
|
initNavigationFullscreenOnce()
|
|
23
22
|
|
|
24
23
|
let root: ReactDOM.Root
|
|
25
24
|
let renderPromiseResolve: () => void
|
|
26
25
|
async function onRenderClient(pageContext: PageContextClient) {
|
|
26
|
+
onRenderStart()
|
|
27
|
+
|
|
27
28
|
// TODO: stop using any
|
|
28
29
|
const pageContextResolved: PageContextResolved = (pageContext as any).pageContextResolved
|
|
29
30
|
const renderPromise = new Promise<void>((r) => {
|
|
@@ -52,6 +53,11 @@ function applyHead(pageContext: PageContextClient) {
|
|
|
52
53
|
document.title = pageContextResolved.documentTitle
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
function onRenderStart() {
|
|
57
|
+
hideMobileNavigation()
|
|
58
|
+
hideNavigationFullScreen()
|
|
59
|
+
}
|
|
60
|
+
|
|
55
61
|
function onRenderDone() {
|
|
56
62
|
autoScrollNav()
|
|
57
63
|
installSectionUrlHashs()
|
|
@@ -69,27 +75,6 @@ function OnRenderDoneHook({ children }: { children: React.ReactNode }) {
|
|
|
69
75
|
return children
|
|
70
76
|
}
|
|
71
77
|
|
|
72
|
-
function initOnLinkClick() {
|
|
73
|
-
document.addEventListener('click', (ev) => {
|
|
74
|
-
const linkTag = findLinkTag(ev.target as HTMLElement)
|
|
75
|
-
if (!linkTag) return
|
|
76
|
-
const url = linkTag.getAttribute('href')
|
|
77
|
-
if (!url) return
|
|
78
|
-
hideMobileNavigation()
|
|
79
|
-
hideNavigationFullScreen()
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
function findLinkTag(target: HTMLElement): null | HTMLElement {
|
|
83
|
-
while (target.tagName !== 'A') {
|
|
84
|
-
const { parentNode } = target
|
|
85
|
-
if (!parentNode) {
|
|
86
|
-
return null
|
|
87
|
-
}
|
|
88
|
-
target = parentNode as HTMLElement
|
|
89
|
-
}
|
|
90
|
-
return target
|
|
91
|
-
}
|
|
92
|
-
|
|
93
78
|
function setHydrationIsFinished() {
|
|
94
79
|
// Used by:
|
|
95
80
|
// - https://github.com/vikejs/vike/blob/9d67f3dd4bdfb38c835186b8147251e0e3b06657/docs/.testRun.ts#L22
|