@brillout/docpress 0.6.21-commit-e35fa3b → 0.6.21-commit-05759d2

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.
@@ -1,6 +1,5 @@
1
1
  export { initMobileNavigation }
2
-
3
- hideNavigationOnLinkClick()
2
+ export { hideMobileNavigation }
4
3
 
5
4
  function initMobileNavigation() {
6
5
  activateMobileShowNavigationToggle()
@@ -16,27 +15,9 @@ function activateMobileNavigationMask() {
16
15
  navigationMask.onclick = toggleNavigation
17
16
  }
18
17
 
19
- function hideNavigationOnLinkClick() {
20
- document.addEventListener('click', (ev) => {
21
- const linkTag = findLinkTag(ev.target as HTMLElement)
22
- if (!linkTag) return
23
- hideNavigation()
24
- })
25
- }
26
- function findLinkTag(target: HTMLElement): null | HTMLElement {
27
- while (target.tagName !== 'A') {
28
- const { parentNode } = target
29
- if (!parentNode) {
30
- return null
31
- }
32
- target = parentNode as HTMLElement
33
- }
34
- return target
35
- }
36
-
37
18
  function toggleNavigation() {
38
19
  document.body.classList.toggle('mobile-show-navigation')
39
20
  }
40
- function hideNavigation() {
21
+ function hideMobileNavigation() {
41
22
  document.body.classList.remove('mobile-show-navigation')
42
23
  }
@@ -1,14 +1,12 @@
1
1
  export { initNavigationFullscreen }
2
+ export { hideNavigationFullScreen }
2
3
 
3
4
  import { assert } from '../../utils/client'
4
-
5
5
  let scrollPositionBeforeToggle: number = 0
6
+ initOnce()
6
7
 
7
- function initNavigationFullscreen() {
8
- updateColumnWidth()
8
+ function initOnce() {
9
9
  window.addEventListener('resize', updateColumnWidth, { passive: true })
10
- document.getElementById('navigation-fullscreen-button')!.onclick = toggleNavExpend
11
- document.getElementById('navigation-fullscreen-close')!.onclick = toggleNavExpend
12
10
  document.addEventListener(
13
11
  // We don't use keydown to not interfere with user pressing `<Esc>` for closing the browser's `<Ctrl-F>` search diablog, see https://stackoverflow.com/questions/66595035/how-to-detect-escape-key-if-search-bar-of-browser-is-open
14
12
  'keydown',
@@ -19,6 +17,11 @@ function initNavigationFullscreen() {
19
17
  false,
20
18
  )
21
19
  }
20
+ function initNavigationFullscreen() {
21
+ document.getElementById('navigation-fullscreen-button')!.onclick = toggleNavExpend
22
+ document.getElementById('navigation-fullscreen-close')!.onclick = toggleNavExpend
23
+ updateColumnWidth()
24
+ }
22
25
 
23
26
  function toggleNavExpend() {
24
27
  const navContainer = document.getElementById('navigation-container')!
@@ -29,6 +32,10 @@ function toggleNavExpend() {
29
32
  }
30
33
  scrollPositionBeforeToggle = scrollPos
31
34
  }
35
+ function hideNavigationFullScreen() {
36
+ if (!document.documentElement.classList.contains('navigation-fullscreen')) return
37
+ toggleNavExpend()
38
+ }
32
39
 
33
40
  function updateColumnWidth() {
34
41
  const navMinWidth = 299
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/docpress",
3
- "version": "0.6.21-commit-e35fa3b",
3
+ "version": "0.6.21-commit-05759d2",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "// Build vite.config.ts and +config.ts": "",
@@ -5,14 +5,19 @@ import type { PageContextClient } from 'vike/types'
5
5
  import ReactDOM from 'react-dom/client'
6
6
  import { PageContextResolved } from '../config/resolvePageContext'
7
7
  import { getPageElement } from './getPageElement'
8
- import { initNavigationFullscreen } from '../navigation/navigation-fullscreen/initNavigationFullscreen'
9
- import { initMobileNavigation } from '../navigation/initMobileNavigation'
8
+ import {
9
+ hideNavigationFullScreen,
10
+ initNavigationFullscreen,
11
+ } from '../navigation/navigation-fullscreen/initNavigationFullscreen'
12
+ import { hideMobileNavigation, initMobileNavigation } from '../navigation/initMobileNavigation'
10
13
  import { initPressKit } from '../navigation/initPressKit'
11
14
  import '../css/index.css'
12
15
  import { autoScrollNav } from '../autoScrollNav'
13
16
  import { installSectionUrlHashs } from '../installSectionUrlHashs'
14
17
  import { addFeatureClickHandlers, addTwitterWidgets } from '../components/FeatureList/FeatureList.client'
15
18
 
19
+ initOnLinkClick()
20
+
16
21
  let root: ReactDOM.Root
17
22
  function onRenderClient(pageContext: PageContextClient) {
18
23
  const pageContextResolved: PageContextResolved = (pageContext as any).pageContextResolved
@@ -45,6 +50,27 @@ function OnRenderDoneHook({ children }: { children: React.ReactNode }) {
45
50
  return children
46
51
  }
47
52
 
53
+ function initOnLinkClick() {
54
+ document.addEventListener('click', (ev) => {
55
+ const linkTag = findLinkTag(ev.target as HTMLElement)
56
+ if (!linkTag) return
57
+ const url = linkTag.getAttribute('href')
58
+ if (!url) return
59
+ hideMobileNavigation()
60
+ hideNavigationFullScreen()
61
+ })
62
+ }
63
+ function findLinkTag(target: HTMLElement): null | HTMLElement {
64
+ while (target.tagName !== 'A') {
65
+ const { parentNode } = target
66
+ if (!parentNode) {
67
+ return null
68
+ }
69
+ target = parentNode as HTMLElement
70
+ }
71
+ return target
72
+ }
73
+
48
74
  function setHydrationIsFinished() {
49
75
  // Used by:
50
76
  // - https://github.com/vikejs/vike/blob/9d67f3dd4bdfb38c835186b8147251e0e3b06657/docs/.testRun.ts#L22