@brillout/docpress 0.15.12 → 0.15.13-commit-03246ec

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.
@@ -3,7 +3,7 @@ export { NavigationWithColumnLayout }
3
3
  import React, { useEffect, useState } from 'react'
4
4
  import { assert } from '../utils/server'
5
5
  import { getViewportWidth } from '../utils/getViewportWidth'
6
- import { containerQueryMobileMenu, navLeftWidthMax, navLeftWidthMin } from '../Layout'
6
+ import { viewTablet, navLeftWidthMax, navLeftWidthMin } from '../Layout'
7
7
  import { throttle } from '../utils/throttle'
8
8
  import { Collapsible } from './Collapsible'
9
9
  import { ColumnMap, getNavItemsWithComputed, NavItem, NavItemComponent, NavItemComputed } from '../NavItemComponent'
@@ -23,6 +23,16 @@ function NavigationWithColumnLayout(props: { navItems: NavItem[] }) {
23
23
  window.addEventListener('resize', throttle(updateviewportwidth, 300), { passive: true })
24
24
  })
25
25
  const navItemsByColumnLayouts = getNavItemsByColumnLayouts(navItemsWithComputed, viewportWidth)
26
+ const columnWidthBase = navLeftWidthMax + 20
27
+ const maxColumns = Math.max(...navItemsByColumnLayouts.map((layout) => layout.columns.length), 1)
28
+ const widthMax = maxColumns * columnWidthBase
29
+ const getColumnsWrapperStyle = (columnLayout: NavItemsByColumnLayout) => {
30
+ const widthColumn = columnLayout.columns.length * columnWidthBase
31
+ return {
32
+ width: Math.max(700, widthColumn),
33
+ maxWidth: `min(100%, ${widthMax}px)`,
34
+ }
35
+ }
26
36
  return (
27
37
  <>
28
38
  <Style>{getStyle()}</Style>
@@ -40,10 +50,10 @@ function NavigationWithColumnLayout(props: { navItems: NavItem[] }) {
40
50
  >
41
51
  {columnLayout.isFullWidthCategory ? (
42
52
  <div style={{ marginTop: 0 }}>
43
- <ColumnsWrapper numberOfColumns={columnLayout.columns.length}>
53
+ <ColumnsWrapper style={getColumnsWrapperStyle(columnLayout)}>
44
54
  <Collapsible
45
55
  head={(onClick) => <NavItemComponent navItem={columnLayout.navItemLevel1} onClick={onClick} />}
46
- disabled={columnLayout.columns.length > 1}
56
+ disabled={maxColumns > 1}
47
57
  collapsedInit={!columnLayout.navItemLevel1.isRelevant}
48
58
  marginBottomOnExpand={marginBottomOnExpand}
49
59
  >
@@ -61,7 +71,7 @@ function NavigationWithColumnLayout(props: { navItems: NavItem[] }) {
61
71
  </ColumnsWrapper>
62
72
  </div>
63
73
  ) : (
64
- <ColumnsWrapper numberOfColumns={columnLayout.columns.length}>
74
+ <ColumnsWrapper style={getColumnsWrapperStyle(columnLayout)}>
65
75
  <ColumnsLayout>
66
76
  {columnLayout.columns.map((column, j) => (
67
77
  <Column key={j}>
@@ -69,7 +79,7 @@ function NavigationWithColumnLayout(props: { navItems: NavItem[] }) {
69
79
  <div key={k} style={{ marginBottom: 0 }}>
70
80
  <Collapsible
71
81
  head={(onClick) => <NavItemComponent navItem={category.navItemLevel1} onClick={onClick} />}
72
- disabled={columnLayout.columns.length > 1}
82
+ disabled={maxColumns > 1}
73
83
  collapsedInit={!category.navItemLevel1.isRelevant}
74
84
  marginBottomOnExpand={marginBottomOnExpand}
75
85
  >
@@ -93,7 +103,7 @@ function NavigationWithColumnLayout(props: { navItems: NavItem[] }) {
93
103
 
94
104
  function getStyle() {
95
105
  const style = css`
96
- @media(min-width: ${containerQueryMobileMenu + 1}px) {
106
+ @media(min-width: ${viewTablet + 1}px) {
97
107
  .menu-navigation-content {
98
108
  position: absolute;
99
109
  width: 100%;
@@ -165,14 +175,14 @@ function Column({ children }: { children: React.ReactNode }) {
165
175
  </div>
166
176
  )
167
177
  }
168
- function ColumnsWrapper({ children, numberOfColumns }: { children: React.ReactNode; numberOfColumns: number }) {
178
+ function ColumnsWrapper({ children, style }: { children: React.ReactNode; style: React.CSSProperties }) {
169
179
  return (
170
180
  <div
181
+ className="columns-wrapper"
171
182
  style={{
172
- width: numberOfColumns * (navLeftWidthMax + 20),
173
- maxWidth: '100%',
174
183
  paddingLeft: 3,
175
184
  margin: 'auto',
185
+ ...style,
176
186
  }}
177
187
  >
178
188
  {children}
@@ -269,17 +279,23 @@ function getNavItemsByColumnEntries(navItems: NavItemComputed[]): NavItemsByColu
269
279
  let isFullWidthCategory: boolean | undefined
270
280
  navItems.forEach((navItem) => {
271
281
  if (navItem.level === 1) {
272
- const isFullWidthCategoryPrevious = isFullWidthCategory
273
- isFullWidthCategory = !!navItem.menuModalFullWidth
274
- if (isFullWidthCategoryPrevious !== undefined && isFullWidthCategoryPrevious !== isFullWidthCategory) {
282
+ if (isFullWidthCategory) {
283
+ assert(navItem.menuModalFullWidth)
284
+ }
285
+ const isFullWidthCategoryPrevious = !!isFullWidthCategory
286
+ if (navItem.menuModalFullWidth) {
287
+ isFullWidthCategory = true
288
+ // Flush
275
289
  navItemsByColumnEntries.push({ columnEntries, isFullWidthCategory: isFullWidthCategoryPrevious })
276
290
  columnEntries = []
291
+ } else {
292
+ isFullWidthCategory = false
277
293
  }
278
294
  }
279
295
  assert(isFullWidthCategory !== undefined)
280
- if (navItem.isColumnEntry) {
296
+ if (navItem.isPotentialColumn) {
281
297
  assert(navItem.level === 1 || navItem.level === 4)
282
- columnEntry = { navItems: [navItem], columnMap: navItem.isColumnEntry }
298
+ columnEntry = { navItems: [navItem], columnMap: navItem.isPotentialColumn }
283
299
  columnEntries.push(columnEntry)
284
300
  } else {
285
301
  assert(navItem.level !== 1)
@@ -4,7 +4,7 @@ export { keepMenuModalOpen }
4
4
  export { closeMenuModal }
5
5
  export { coseMenuModalOnMouseLeave }
6
6
 
7
- import { containerQueryMobileMenu } from '../Layout'
7
+ import { viewTablet } from '../Layout'
8
8
  import { getHydrationPromise } from '../renderer/getHydrationPromise'
9
9
  import { getViewportWidth } from '../utils/getViewportWidth'
10
10
  import { isBrowser } from '../utils/isBrowser'
@@ -111,7 +111,7 @@ function toggleMenuModal(menuId: number) {
111
111
  closeMenuModal()
112
112
  } else {
113
113
  openMenuModal(menuId)
114
- if (getViewportWidth() < containerQueryMobileMenu) autoScroll()
114
+ if (getViewportWidth() < viewTablet) autoScroll()
115
115
  }
116
116
  }
117
117
 
package/MenuModal.tsx CHANGED
@@ -3,7 +3,7 @@ export { MenuModal }
3
3
  import React from 'react'
4
4
  import { usePageContext } from './renderer/usePageContext'
5
5
  import { css } from './utils/css'
6
- import { containerQueryMobileLayout, containerQueryMobileMenu } from './Layout'
6
+ import { viewDesktop, viewTablet } from './Layout'
7
7
  import { ExternalLinks } from './ExternalLinks'
8
8
  import { Style } from './utils/Style'
9
9
  import { NavigationWithColumnLayout } from './MenuModal/NavigationWithColumnLayout'
@@ -79,7 +79,7 @@ function Nav() {
79
79
 
80
80
  function getStyle() {
81
81
  return css`
82
- @media(min-width: ${containerQueryMobileMenu + 1}px) {
82
+ @media(min-width: ${viewTablet + 1}px) {
83
83
  #menu-modal-scroll-container {
84
84
  max-height: calc(100vh - var(--nav-head-height) - var(--block-margin));
85
85
  ${/* https://github.com/brillout/docpress/issues/23 */ ''}
@@ -99,7 +99,7 @@ function getStyle() {
99
99
  display: none !important;
100
100
  }
101
101
  }
102
- @media(max-width: ${containerQueryMobileMenu}px) {
102
+ @media(max-width: ${viewTablet}px) {
103
103
  #menu-modal-scroll-container {
104
104
  ${/* Fallback for Firefox: it doesn't support `dvh` yet: https://caniuse.com/?search=dvh */ ''}
105
105
  ${/* Let's always and systematically use `dvh` instead of `vh` once Firefox supports it */ ''}
@@ -132,10 +132,13 @@ function getStyle() {
132
132
  .show-only-on-desktop {
133
133
  display: none !important;
134
134
  }
135
+ .columns-wrapper {
136
+ width: 100% !important;
137
+ }
135
138
  }
136
139
 
137
140
  ${/* Hide same-page headings navigation */ ''}
138
- @container container-viewport (min-width: ${containerQueryMobileLayout}px) {
141
+ @container container-viewport (min-width: ${viewDesktop}px) {
139
142
  #menu-modal-wrapper .nav-item-level-3 {
140
143
  display: none;
141
144
  }
@@ -31,8 +31,22 @@ type NavItem = {
31
31
  title: string
32
32
  titleInNav: string
33
33
  menuModalFullWidth?: true
34
- isColumnEntry?: ColumnMap
34
+ /**
35
+ * Maps viewport column counts to column indices.
36
+ * Indicates this nav item is a "column entry" (a level-1 or level-4 heading that starts a new column section).
37
+ * Example: `{ 1: 0, 2: 1, 3: 0 }` means:
38
+ * - When there's 1 column, put this item in column 0
39
+ * - When there are 2 columns, put it in column 1
40
+ * - When there are 3 columns, put it in column 0
41
+ */
42
+ isPotentialColumn?: ColumnMap
35
43
  }
44
+ /**
45
+ * A mapping of viewport column counts to column indices.
46
+ * Used to determine which column a nav item should be placed in for different viewport widths.
47
+ * Key: number of columns in the viewport
48
+ * Value: the column index (0-based) where this item should be placed
49
+ */
36
50
  type ColumnMap = Record<number, number>
37
51
 
38
52
  type PropsNavItem = PropsAnchor & PropsSpan