@brillout/docpress 0.8.14 → 0.8.15

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 (48) hide show
  1. package/Layout.tsx +254 -177
  2. package/MenuModal.tsx +42 -48
  3. package/{Links.tsx → NavSecondaryContent.tsx} +5 -8
  4. package/components/HorizontalLine.tsx +4 -3
  5. package/config/resolveHeadingsData.ts +7 -10
  6. package/css/code/block.css +5 -5
  7. package/css/code/inline.css +1 -1
  8. package/css/colorize-on-hover.css +2 -2
  9. package/dist/Layout.d.ts +10 -6
  10. package/dist/Layout.js +165 -120
  11. package/dist/MenuModal.js +34 -47
  12. package/dist/{Links.d.ts → NavSecondaryContent.d.ts} +3 -2
  13. package/dist/{Links.js → NavSecondaryContent.js} +5 -7
  14. package/dist/components/HorizontalLine.d.ts +1 -1
  15. package/dist/components/HorizontalLine.js +3 -2
  16. package/dist/config/resolveHeadingsData.d.ts +3 -4
  17. package/dist/config/resolveHeadingsData.js +5 -8
  18. package/dist/config/resolvePageContext.d.ts +2 -3
  19. package/dist/docsearch/SearchLink.js +1 -1
  20. package/dist/navigation/Collapsible.d.ts +10 -0
  21. package/dist/navigation/Collapsible.js +35 -0
  22. package/dist/navigation/Navigation.d.ts +0 -3
  23. package/dist/navigation/Navigation.js +106 -55
  24. package/dist/renderer/determineNavItemsColumnLayout.d.ts +3 -0
  25. package/dist/renderer/{determineColumnEntries.js → determineNavItemsColumnLayout.js} +34 -28
  26. package/dist/renderer/usePageContext.d.ts +2 -2
  27. package/dist/renderer/usePageContext.js +2 -4
  28. package/dist/utils/Style.d.ts +5 -0
  29. package/dist/utils/Style.js +6 -0
  30. package/dist/utils/cls.d.ts +3 -0
  31. package/dist/utils/cls.js +5 -0
  32. package/dist/utils/throttle.d.ts +1 -0
  33. package/dist/utils/throttle.js +14 -0
  34. package/docsearch/SearchLink.tsx +1 -1
  35. package/global.d.ts +1 -1
  36. package/navigation/Collapsible.css +11 -0
  37. package/navigation/Collapsible.tsx +64 -0
  38. package/navigation/Navigation.css +12 -6
  39. package/navigation/Navigation.tsx +191 -80
  40. package/package.json +1 -1
  41. package/renderer/{determineColumnEntries.ts → determineNavItemsColumnLayout.ts} +35 -29
  42. package/renderer/initOnNavigation.ts +37 -0
  43. package/renderer/onRenderClient.tsx +2 -0
  44. package/renderer/usePageContext.tsx +2 -5
  45. package/utils/Style.tsx +7 -0
  46. package/utils/cls.ts +8 -0
  47. package/utils/throttle.ts +10 -0
  48. package/dist/renderer/determineColumnEntries.d.ts +0 -3
package/MenuModal.tsx CHANGED
@@ -7,25 +7,23 @@ import React from 'react'
7
7
  import { usePageContext } from './renderer/usePageContext'
8
8
  import { NavigationContent } from './navigation/Navigation'
9
9
  import { css } from './utils/css'
10
- import { containerQueryMobile } from './Layout'
11
- import { Links } from './Links'
12
- import { isBrowser } from './utils/isBrowser'
10
+ import { containerQueryMobileLayout, containerQueryMobileMenu } from './Layout'
11
+ import { NavSecondaryContent } from './NavSecondaryContent'
13
12
  import { getViewportWidth } from './utils/getViewportWidth'
14
-
15
- initCloseListeners()
13
+ import { Style } from './utils/Style'
16
14
 
17
15
  function MenuModal({ isTopNav }: { isTopNav: boolean }) {
18
16
  return (
19
17
  <>
20
- <style>{getStyle()}</style>
18
+ <Style>{getStyle()}</Style>
21
19
  <div
22
20
  id="menu-modal"
23
21
  className="link-hover-animation add-transition"
24
22
  style={{
25
23
  position: isTopNav ? 'absolute' : 'fixed',
26
24
  width: '100%',
27
- height: 'calc(100vh - var(--top-nav-height))',
28
- top: 'var(--top-nav-height)',
25
+ height: 'calc(100vh - var(--nav-head-height))',
26
+ top: 'var(--nav-head-height)',
29
27
  left: 0,
30
28
  zIndex: 9999,
31
29
  overflow: 'scroll',
@@ -40,20 +38,16 @@ function MenuModal({ isTopNav }: { isTopNav: boolean }) {
40
38
  // Place <LinksBottom /> to the bottom
41
39
  display: 'flex',
42
40
  flexDirection: 'column',
43
- minHeight: 'calc(100vh - var(--top-nav-height))',
41
+ minHeight: 'calc(100vh - var(--nav-head-height))',
44
42
  justifyContent: 'space-between',
45
43
  // We don't set `container` to parent beacuse of a Chrome bug (showing a blank <MenuModal>)
46
- containerType: 'inline-size',
44
+ container: 'container-viewport / inline-size',
47
45
  }}
48
46
  >
49
47
  <Nav />
50
- {/* TODO/now: use for mobile
51
- <LinksBottom />
52
- */}
48
+ <NavSecondary className="show-only-for-mobile" />
53
49
  </div>
54
- {/* TODO/now: use for mobile
55
- <CloseButton />
56
- */}
50
+ <CloseButton className="show-only-for-mobile" />
57
51
  </div>
58
52
  </>
59
53
  )
@@ -63,15 +57,17 @@ function Nav() {
63
57
  const navItems = pageContext.navItemsAll
64
58
  return <NavigationContent columnLayout={true} navItems={navItems} />
65
59
  }
66
- function LinksBottom() {
60
+ function NavSecondary({ className }: { className: string }) {
67
61
  return (
68
62
  <div
63
+ className={className}
69
64
  style={{
70
65
  display: 'flex',
71
66
  justifyContent: 'center',
67
+ marginTop: 20,
72
68
  }}
73
69
  >
74
- <Links style={{ height: 70 }} />
70
+ <NavSecondaryContent style={{ height: 70 }} />
75
71
  </div>
76
72
  )
77
73
  }
@@ -86,17 +82,28 @@ html:not(.menu-modal-show) #menu-modal {
86
82
  html.menu-modal-show {
87
83
  overflow: hidden !important;
88
84
  }
89
- @container(min-width: ${containerQueryMobile}px) {
85
+ @container container-viewport (min-width: ${containerQueryMobileLayout}px) {
90
86
  #menu-modal .nav-item-level-3 {
91
87
  display: none;
92
88
  }
93
89
  }
90
+ @media(max-width: ${containerQueryMobileMenu}px) {
91
+ #menu-modal {
92
+ --nav-head-height: 0px !important;
93
+ }
94
+ }
95
+ @media(min-width: ${containerQueryMobileMenu + 1}px) {
96
+ .show-only-for-mobile {
97
+ display: none !important;
98
+ }
99
+ }
94
100
  `
95
101
  }
96
102
 
97
- function CloseButton() {
103
+ function CloseButton({ className }: { className: string }) {
98
104
  return (
99
105
  <div
106
+ className={className}
100
107
  onClick={toggleMenuModal}
101
108
  style={{ position: 'fixed', top: 0, right: 0, zIndex: 10, padding: 11, cursor: 'pointer' }}
102
109
  aria-label={'Escape\nCtrl\xa0+\xa0M'}
@@ -128,7 +135,10 @@ function CloseButton() {
128
135
 
129
136
  function toggleMenuModal() {
130
137
  document.documentElement.classList.toggle('menu-modal-show')
131
- if (document.documentElement.classList.contains('menu-modal-show') && getViewportWidth() < containerQueryMobile) {
138
+ if (
139
+ document.documentElement.classList.contains('menu-modal-show') &&
140
+ getViewportWidth() < containerQueryMobileLayout
141
+ ) {
132
142
  autoScroll()
133
143
  }
134
144
  }
@@ -136,43 +146,27 @@ function autoScroll() {
136
146
  const nav = document.querySelector('#menu-modal .navigation-content')!
137
147
  const href = window.location.pathname
138
148
  const navLinks = Array.from(nav.querySelectorAll(`a[href="${href}"]`))
139
- const navLink = navLinks[0]
149
+ const navLink = navLinks[0] as HTMLElement | undefined
140
150
  if (!navLink) return
151
+ // None of the following seemes to be working: https://stackoverflow.com/questions/19669786/check-if-element-is-visible-in-dom
152
+ if (findCollapsibleEl(navLink)!.classList.contains('collapsible-collapsed')) return
141
153
  navLink.scrollIntoView({
142
154
  behavior: 'instant',
143
155
  block: 'center',
144
156
  inline: 'start',
145
157
  })
146
158
  }
159
+ function findCollapsibleEl(navLink: HTMLElement | undefined) {
160
+ let parentEl: HTMLElement | null | undefined = navLink
161
+ while (parentEl) {
162
+ if (parentEl.classList.contains('collapsible')) return parentEl
163
+ parentEl = parentEl.parentElement
164
+ }
165
+ return null
166
+ }
147
167
  function openMenuModal() {
148
168
  document.documentElement.classList.add('menu-modal-show')
149
169
  }
150
170
  function closeMenuModal() {
151
171
  document.documentElement.classList.remove('menu-modal-show')
152
172
  }
153
-
154
- function initCloseListeners() {
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
178
- }
@@ -1,5 +1,4 @@
1
- // TODO/refactor: rename
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 Links({ style }: { style?: React.CSSProperties }) {
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
- paddingTop: 0,
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: 10,
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={'header-separator-line ' + (primary ? 'primary' : '')} style={{ textAlign: 'center' }}>
8
+ <div className={cls(primary && 'primary')} style={{ textAlign: 'center' }}>
8
9
  <hr
9
10
  style={{
10
11
  display: 'inline-block',
@@ -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, NavItemAll } from '../navigation/Navigation'
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 { determineColumnEntries } from '../renderer/determineColumnEntries'
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
- // TODO/refactor: remove navItems
57
- let navItems: NavItem[]
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
- determineColumnEntries(navItemsAll)
63
+ determineNavItemsColumnLayout(navItemsAll)
65
64
  if (isDetachedPage) {
66
- navItems = [headingToNavItem(activeHeading), ...navItemsPageSections]
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,
@@ -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
  }
@@ -8,7 +8,7 @@ code {
8
8
  * - Allow them on mobile
9
9
  * - Allow them for `<code long>`
10
10
  */
11
- @container(max-width: 500px) {
11
+ @container container-viewport (max-width: 500px) {
12
12
  code {
13
13
  word-break: break-word;
14
14
  }
@@ -22,7 +22,7 @@
22
22
  .link-hover-animation a,
23
23
  .link-hover-animation .menu-toggle,
24
24
  .add-transition {
25
- transition: all 0.4s ease-in-out;
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 { containerQueryMobile };
3
- export { navWidthMin };
4
- export { navWidthMax };
2
+ export { containerQueryMobileLayout };
3
+ export { containerQueryMobileMenu };
4
+ export { navLeftWidthMin };
5
+ export { navLeftWidthMax };
6
+ export { unexpandNav };
5
7
  import React from 'react';
6
- declare const navWidthMax = 370;
7
- declare const navWidthMin = 300;
8
- declare const containerQueryMobile: number;
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;