@brillout/docpress 0.16.12 → 0.16.13

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 (89) hide show
  1. package/+config.ts +2 -2
  2. package/EditLink.tsx +3 -3
  3. package/ExternalLinks.tsx +1 -1
  4. package/Layout.tsx +15 -14
  5. package/MenuModal/Collapsible.tsx +1 -1
  6. package/MenuModal/NavigationWithColumnLayout.tsx +11 -11
  7. package/MenuModal/toggleMenuModal.ts +4 -4
  8. package/MenuModal.tsx +12 -8
  9. package/NavItemComponent.tsx +4 -3
  10. package/code-blocks/components/ChoiceGroup.css +6 -11
  11. package/code-blocks/components/ChoiceGroup.tsx +18 -19
  12. package/code-blocks/components/Pre.tsx +1 -1
  13. package/code-blocks/hooks/useSelectedChoice.ts +1 -1
  14. package/code-blocks/remarkChoiceGroup.ts +3 -5
  15. package/code-blocks/remarkDetype.ts +2 -3
  16. package/code-blocks/remarkPkgManager.ts +3 -1
  17. package/code-blocks/shikiTransformerAutoLinks.ts +2 -2
  18. package/code-blocks/utils/generateChoiceGroupCode.ts +40 -21
  19. package/components/Algolia/Hit.tsx +3 -3
  20. package/components/CodeBlockTransformer.tsx +1 -1
  21. package/components/Comment.tsx +1 -1
  22. package/components/HorizontalLine.tsx +1 -1
  23. package/components/ImportMeta.tsx +1 -1
  24. package/components/Link.tsx +5 -5
  25. package/components/Note.tsx +1 -1
  26. package/components/RepoLink.tsx +1 -1
  27. package/components/index.ts +10 -10
  28. package/css/index.css +1 -1
  29. package/determineNavItemsColumnLayout.spec.ts +2 -2
  30. package/determineNavItemsColumnLayout.ts +6 -6
  31. package/dist/+config.d.ts +2 -2
  32. package/dist/NavItemComponent.js +2 -2
  33. package/dist/code-blocks/rehypeMetaToProps.js +1 -1
  34. package/dist/code-blocks/remarkChoiceGroup.js +4 -6
  35. package/dist/code-blocks/remarkDetype.js +3 -3
  36. package/dist/code-blocks/remarkPkgManager.js +4 -2
  37. package/dist/code-blocks/utils/generateChoiceGroupCode.d.ts +2 -2
  38. package/dist/code-blocks/utils/generateChoiceGroupCode.js +35 -18
  39. package/dist/components/CodeBlockTransformer.js +1 -1
  40. package/dist/components/Comment.d.ts +1 -3
  41. package/dist/components/Comment.js +1 -1
  42. package/dist/components/HorizontalLine.js +1 -1
  43. package/dist/components/ImportMeta.js +1 -1
  44. package/dist/components/Link.d.ts +1 -1
  45. package/dist/components/Link.js +3 -3
  46. package/dist/components/Note.js +2 -2
  47. package/dist/components/RepoLink.js +1 -1
  48. package/dist/components/index.d.ts +10 -10
  49. package/dist/components/index.js +10 -10
  50. package/dist/determineNavItemsColumnLayout.d.ts +1 -1
  51. package/dist/determineNavItemsColumnLayout.js +3 -2
  52. package/dist/renderer/usePageContext.d.ts +3 -3
  53. package/dist/renderer/usePageContext.js +1 -1
  54. package/dist/resolvePageContext.d.ts +2 -2
  55. package/dist/resolvePageContext.js +5 -5
  56. package/dist/types/Config.d.ts +1 -1
  57. package/dist/utils/Emoji/Emoji.js +2 -2
  58. package/dist/utils/Emoji/index.d.ts +1 -1
  59. package/dist/utils/Emoji/index.js +1 -1
  60. package/dist/utils/client.d.ts +3 -3
  61. package/dist/utils/client.js +3 -3
  62. package/dist/utils/jsxToTextContent.js +1 -1
  63. package/dist/utils/server.d.ts +7 -7
  64. package/dist/utils/server.js +7 -7
  65. package/docsearch/DocSearchInstall.tsx +3 -3
  66. package/docsearch/SearchLink.tsx +2 -2
  67. package/docsearch/toggleDocsearchModal.ts +1 -1
  68. package/index.ts +10 -10
  69. package/initKeyBindings.ts +2 -2
  70. package/installSectionUrlHashs.ts +1 -1
  71. package/package.json +1 -1
  72. package/parsePageSections.ts +2 -2
  73. package/renderer/getHydrationPromise.ts +2 -2
  74. package/renderer/getPageElement.tsx +3 -3
  75. package/renderer/initOnNavigation.ts +3 -3
  76. package/renderer/onCreatePageContext.ts +1 -1
  77. package/renderer/onRenderClient.tsx +9 -9
  78. package/renderer/onRenderHtml.tsx +3 -3
  79. package/renderer/usePageContext.tsx +1 -1
  80. package/resolvePageContext.ts +10 -10
  81. package/tsconfig.json +20 -12
  82. package/types/Config.ts +1 -1
  83. package/utils/Emoji/Emoji.ts +2 -2
  84. package/utils/Emoji/index.ts +1 -1
  85. package/utils/addScript.ts +1 -1
  86. package/utils/client.ts +3 -3
  87. package/utils/determineSectionUrlHash.ts +2 -2
  88. package/utils/jsxToTextContent.ts +1 -1
  89. package/utils/server.ts +7 -7
package/+config.ts CHANGED
@@ -2,8 +2,8 @@ export { config as default }
2
2
 
3
3
  import type { Config } from 'vike/types'
4
4
  import { viteConfig } from './vite.config.js'
5
- import type { Config as DocpressConfig } from './types/Config'
6
- import type { PageSection } from './parsePageSections'
5
+ import type { Config as DocpressConfig } from './types/Config.js'
6
+ import type { PageSection } from './parsePageSections.js'
7
7
  import type { Resolved } from './resolvePageContext.js'
8
8
 
9
9
  const config = {
package/EditLink.tsx CHANGED
@@ -1,9 +1,9 @@
1
1
  export { EditLink }
2
2
 
3
3
  import React from 'react'
4
- import { usePageContext } from './renderer/usePageContext'
5
- import { iconPencil } from './icons'
6
- import { getRepoHref } from './components'
4
+ import { usePageContext } from './renderer/usePageContext.js'
5
+ import { iconPencil } from './icons/index.js'
6
+ import { getRepoHref } from './components/index.js'
7
7
 
8
8
  function EditLink({
9
9
  className,
package/ExternalLinks.tsx CHANGED
@@ -8,7 +8,7 @@ import iconBluesky from './icons/bluesky.svg'
8
8
  import iconLinkedin from './icons/linkedin.svg'
9
9
  import iconChangelog from './icons/changelog.svg'
10
10
  import iconLanguages from './icons/languages.svg'
11
- import { usePageContext } from './renderer/usePageContext'
11
+ import { usePageContext } from './renderer/usePageContext.js'
12
12
  import '@docsearch/css'
13
13
 
14
14
  function ExternalLinks(props: { style?: React.CSSProperties }) {
package/Layout.tsx CHANGED
@@ -15,26 +15,26 @@ export { scrollFadeMask }
15
15
  // - We use --padding-side because we cannot set a fixed max-width on the <NavHead> container .nav-head-content — DocPress doesn't know how many extra <NavHead> elements the user adds using the +docpress.topNavigation setting.
16
16
 
17
17
  import React from 'react'
18
- import { getNavItemsWithComputed, NavItem, NavItemComponent } from './NavItemComponent'
19
- import { parseMarkdownMini } from './parseMarkdownMini'
20
- import { usePageContext } from './renderer/usePageContext'
21
- import { ExternalLinks } from './ExternalLinks'
18
+ import { getNavItemsWithComputed, NavItem, NavItemComponent } from './NavItemComponent.js'
19
+ import { parseMarkdownMini } from './parseMarkdownMini.js'
20
+ import { usePageContext } from './renderer/usePageContext.js'
21
+ import { ExternalLinks } from './ExternalLinks.js'
22
22
  import {
23
23
  closeMenuModalOnMouseLeaveToggle,
24
24
  ignoreHoverOnTouchStart,
25
25
  openMenuModalOnMouseEnter,
26
26
  toggleMenuModal,
27
- } from './MenuModal/toggleMenuModal'
28
- import { MenuModal } from './MenuModal'
29
- import { autoScrollNav_SSR } from './autoScrollNav'
30
- import { initializeChoiceGroup_SSR } from './code-blocks/hooks/useSelectedChoice'
31
- import { SearchLink } from './docsearch/SearchLink'
27
+ } from './MenuModal/toggleMenuModal.js'
28
+ import { MenuModal } from './MenuModal.js'
29
+ import { autoScrollNav_SSR } from './autoScrollNav.js'
30
+ import { initializeChoiceGroup_SSR } from './code-blocks/hooks/useSelectedChoice.js'
31
+ import { SearchLink } from './docsearch/SearchLink.js'
32
32
  import { navigate } from 'vike/client/router'
33
- import { css } from './utils/css'
34
- import { Style } from './utils/Style'
35
- import { cls } from './utils/cls'
36
- import { iconBooks } from './icons'
37
- import { EditLink } from './EditLink'
33
+ import { css } from './utils/css.js'
34
+ import { Style } from './utils/Style.js'
35
+ import { cls } from './utils/cls.js'
36
+ import { iconBooks } from './icons/index.js'
37
+ import { EditLink } from './EditLink.js'
38
38
  import './Layout.css'
39
39
 
40
40
  const blockMargin = 4
@@ -604,6 +604,7 @@ function NavHeadLogo({ isNavLeft }: { isNavLeft?: true }) {
604
604
  if (!pageContext.globalContext.config.docpress.pressKit) return // no /press page
605
605
  if (window.location.pathname === '/press') return
606
606
  ev.preventDefault()
607
+ // @ts-expect-error Will be fixed in the next Vike version — remove this @ts-expect-error then.
607
608
  navigate('/press#logo')
608
609
  }
609
610
  }
@@ -1,7 +1,7 @@
1
1
  export { Collapsible }
2
2
 
3
3
  import React, { useRef, useState } from 'react'
4
- import { cls } from '../utils/cls'
4
+ import { cls } from '../utils/cls.js'
5
5
  import './Collapsible.css'
6
6
 
7
7
  function Collapsible({
@@ -1,16 +1,16 @@
1
1
  export { NavigationWithColumnLayout }
2
2
 
3
3
  import React, { useEffect, useState } from 'react'
4
- import { assert } from '../utils/server'
5
- import { getViewportWidth } from '../utils/getViewportWidth'
6
- import { viewTablet, navLeftWidthMax, navLeftWidthMin, bodyMaxWidth } from '../Layout'
7
- import { throttle } from '../utils/throttle'
8
- import { Collapsible } from './Collapsible'
9
- import { ColumnMap, getNavItemsWithComputed, NavItem, NavItemComponent, NavItemComputed } from '../NavItemComponent'
10
- import { usePageContext } from '../renderer/usePageContext'
4
+ import { assert } from '../utils/server.js'
5
+ import { getViewportWidth } from '../utils/getViewportWidth.js'
6
+ import { viewTablet, navLeftWidthMax, navLeftWidthMin, bodyMaxWidth } from '../Layout.js'
7
+ import { throttle } from '../utils/throttle.js'
8
+ import { Collapsible } from './Collapsible.js'
9
+ import { ColumnMap, getNavItemsWithComputed, NavItem, NavItemComponent, NavItemComputed } from '../NavItemComponent.js'
10
+ import { usePageContext } from '../renderer/usePageContext.js'
11
11
  import './NavigationWithColumnLayout.css'
12
- import { Style } from '../utils/Style'
13
- import { css } from '../utils/css'
12
+ import { Style } from '../utils/Style.js'
13
+ import { css } from '../utils/css.js'
14
14
 
15
15
  const marginBottomOnExpand = 15
16
16
  function NavigationWithColumnLayout(props: { navItems: NavItem[] }) {
@@ -240,7 +240,7 @@ function getNavItemsByColumnLayouts(navItems: NavItemComputed[], availableWidth:
240
240
  const idx = numberOfColumns === 1 ? 0 : columnEntry.columnMap[numberOfColumns]!
241
241
  assert(idx >= 0)
242
242
  columns[idx] ??= { categories: [] }
243
- const navItemLevel1 = columnEntry.navItems[0]
243
+ const navItemLevel1 = columnEntry.navItems[0]!
244
244
  const navItems = columnEntry.navItems.slice(1)
245
245
  columns[idx].categories.push({ navItemLevel1, navItems })
246
246
  })
@@ -255,7 +255,7 @@ function getNavItemsByColumnLayouts(navItems: NavItemComputed[], availableWidth:
255
255
  columns[idx] ??= { navItems: [] }
256
256
  let { navItems } = columnEntry
257
257
  if (i === 0) {
258
- navItemLevel1 = navItems[0]
258
+ navItemLevel1 = navItems[0]!
259
259
  navItems = navItems.slice(1)
260
260
  }
261
261
  columns[idx].navItems.push(...navItems)
@@ -7,10 +7,10 @@ export { keepMenuModalOpenOnMouseOver }
7
7
  export { closeMenuModalOnMouseLeave }
8
8
  export { closeMenuModalOnMouseLeaveToggle }
9
9
 
10
- import { viewTablet } from '../Layout'
11
- import { getHydrationPromise } from '../renderer/getHydrationPromise'
12
- import { getViewportWidth } from '../utils/getViewportWidth'
13
- import { isBrowser } from '../utils/isBrowser'
10
+ import { viewTablet } from '../Layout.js'
11
+ import { getHydrationPromise } from '../renderer/getHydrationPromise.js'
12
+ import { getViewportWidth } from '../utils/getViewportWidth.js'
13
+ import { isBrowser } from '../utils/isBrowser.js'
14
14
 
15
15
  initScrollListener()
16
16
 
package/MenuModal.tsx CHANGED
@@ -1,14 +1,18 @@
1
1
  export { MenuModal }
2
2
 
3
3
  import React from 'react'
4
- import { usePageContext } from './renderer/usePageContext'
5
- import { css } from './utils/css'
6
- import { bodyMaxWidth, viewDesktop, viewTablet, scrollFadeMask } from './Layout'
7
- import { ExternalLinks } from './ExternalLinks'
8
- import { Style } from './utils/Style'
9
- import { NavigationWithColumnLayout } from './MenuModal/NavigationWithColumnLayout'
10
- import { closeMenuModal, closeMenuModalOnMouseLeave, keepMenuModalOpenOnMouseOver } from './MenuModal/toggleMenuModal'
11
- import { EditLink } from './EditLink'
4
+ import { usePageContext } from './renderer/usePageContext.js'
5
+ import { css } from './utils/css.js'
6
+ import { bodyMaxWidth, viewDesktop, viewTablet, scrollFadeMask } from './Layout.js'
7
+ import { ExternalLinks } from './ExternalLinks.js'
8
+ import { Style } from './utils/Style.js'
9
+ import { NavigationWithColumnLayout } from './MenuModal/NavigationWithColumnLayout.js'
10
+ import {
11
+ closeMenuModal,
12
+ closeMenuModalOnMouseLeave,
13
+ keepMenuModalOpenOnMouseOver,
14
+ } from './MenuModal/toggleMenuModal.js'
15
+ import { EditLink } from './EditLink.js'
12
16
 
13
17
  function MenuModal({ isTopNav, isNavLeftAlwaysHidden_ }: { isTopNav: boolean; isNavLeftAlwaysHidden_: boolean }) {
14
18
  return (
@@ -5,9 +5,9 @@ export type { NavItemComputed }
5
5
  export type { ColumnMap }
6
6
 
7
7
  import React from 'react'
8
- import { assert, assertWarning, jsxToTextContent } from './utils/server'
8
+ import { assert, assertWarning, jsxToTextContent } from './utils/server.js'
9
9
  import './NavItemComponent.css'
10
- import { parseMarkdownMini } from './parseMarkdownMini'
10
+ import { parseMarkdownMini } from './parseMarkdownMini.js'
11
11
 
12
12
  /*
13
13
  // We cannot do that: we must use `import type` otherwise Vite will transpile global.d.ts and throw:
@@ -18,7 +18,8 @@ import { parseMarkdownMini } from './parseMarkdownMini'
18
18
  import './global.d.ts'
19
19
  /*/
20
20
  // The only purpose of `FakeExport` is to be able to use `import type`
21
- import type { FakeExport } from './global.d.ts'
21
+ // @ts-expect-error
22
+ import type { FakeExport } from './global.js'
22
23
  //*/
23
24
 
24
25
  type NavItemComputed = ReturnType<typeof getNavItemsWithComputed>[number]
@@ -8,35 +8,30 @@
8
8
  }
9
9
  }
10
10
 
11
+ /* layout */
11
12
  --select-width: 85px;
12
13
  --select-top-position: 10px;
13
- --select-right-position: 42px;
14
- --show-js-dropdown-right-position: calc(var(--select-right-position) + var(--select-width) + 2px);
14
+ --select-right-base: 42px;
15
+ --select-gap: 2px;
15
16
 
17
+ /* each select increments the level */
16
18
  .select-choice {
17
19
  position: absolute;
18
20
  z-index: 3;
19
21
  height: 25px;
20
22
  top: var(--select-top-position);
21
- right: var(--select-right-position);
22
23
  width: var(--select-width);
24
+ right: calc(var(--select-right-base) + (var(--lvl) * (var(--select-width) + var(--select-gap))));
23
25
 
24
26
  opacity: 0;
25
27
  transition: opacity 0.5s ease-in-out, background-color 0.4s ease-in-out;
26
-
27
- &.show-js-dropdown {
28
- --select-right-position: var(--show-js-dropdown-right-position);
29
- }
30
-
31
- &:has(+ .choice > .choice-group:not([data-choice-group='codeLang'])) {
32
- right: calc(var(--select-width) + var(--select-right-position) + 2px);
33
- }
34
28
  }
35
29
 
36
30
  .hidden {
37
31
  display: none !important;
38
32
  }
39
33
 
34
+ /* choice visibility logic */
40
35
  select:has(option:nth-of-type(1):not(:checked)) ~ .choice:nth-of-type(1),
41
36
  select:has(option:nth-of-type(2):not(:checked)) ~ .choice:nth-of-type(2),
42
37
  select:has(option:nth-of-type(3):not(:checked)) ~ .choice:nth-of-type(3),
@@ -1,11 +1,11 @@
1
1
  export { ChoiceGroup }
2
2
 
3
- import React, { useRef } from 'react'
4
- import { usePageContext } from '../../renderer/usePageContext'
5
- import { useSelectedChoice } from '../hooks/useSelectedChoice'
6
- import { useRestoreScroll } from '../hooks/useRestoreScroll'
7
- import { assertUsage } from '../../utils/assert'
8
- import { cls } from '../../utils/cls'
3
+ import React from 'react'
4
+ import { usePageContext } from '../../renderer/usePageContext.js'
5
+ import { useSelectedChoice } from '../hooks/useSelectedChoice.js'
6
+ import { useRestoreScroll } from '../hooks/useRestoreScroll.js'
7
+ import { assertUsage } from '../../utils/assert.js'
8
+ import { cls } from '../../utils/cls.js'
9
9
  import type { PageContext } from 'vike/types'
10
10
  import './ChoiceGroup.css'
11
11
 
@@ -23,27 +23,26 @@ const CHOICES_BUILT_IN: Record<string, { choices: string[]; default: string }> =
23
23
  function ChoiceGroup({
24
24
  children,
25
25
  choices,
26
+ lvl,
26
27
  hide = false,
27
- }: { children: React.ReactNode; choices: string[]; hide: boolean }) {
28
+ }: { children: React.ReactNode; choices: string[]; lvl: number; hide: boolean }) {
28
29
  const pageContext = usePageContext()
29
- const cleanChoices = choices.map((c) => c.split(':')[0])
30
- const choiceGroup = findChoiceGroup(pageContext, cleanChoices)
31
- const [selectedChoice, setSelectedChoice] = useSelectedChoice(choiceGroup.name, choiceGroup.default)
32
- const isJsDropdownVisible = choices.indexOf(`${selectedChoice}:jsDropdown`) !== -1
33
- const choiceGroupRef = useRef<HTMLDivElement>(null)
30
+ const choiceGroup = findChoiceGroup(pageContext, choices)
31
+ const [selectedChoice, setSelectedChoice] = useSelectedChoice(choiceGroup.name, choiceGroup.default!)
34
32
  const prevPositionRef = useRestoreScroll([selectedChoice])
35
- const isHidden = choices.length === 1 || !cleanChoices.includes(selectedChoice) || hide
33
+ const isHidden = choices.length === 1 || !choices.includes(selectedChoice) || hide
36
34
 
37
35
  return (
38
- <div ref={choiceGroupRef} data-choice-group={choiceGroup.name} className="choice-group">
36
+ <div data-choice-group={choiceGroup.name} className="choice-group">
39
37
  <select
40
38
  name={`choicesFor-${choiceGroup.name}`}
41
39
  value={selectedChoice}
42
40
  onChange={onChange}
43
- className={cls(['select-choice', isJsDropdownVisible && 'show-js-dropdown', isHidden && 'hidden'])}
41
+ className={cls(['select-choice', isHidden && 'hidden'])}
42
+ style={{ '--lvl': lvl }}
44
43
  >
45
44
  {choiceGroup.choices.map((choice, i) => (
46
- <option key={i} value={choice} disabled={!cleanChoices.includes(choice)}>
45
+ <option key={i} value={choice} disabled={!choices.includes(choice)}>
47
46
  {choice}
48
47
  </option>
49
48
  ))}
@@ -65,7 +64,7 @@ function findChoiceGroup(pageContext: PageContext, choices: string[]) {
65
64
 
66
65
  const groupName = Object.keys(choicesAll).find((key) => {
67
66
  // get only the values that exist in both choices and choicesAll[key].choices
68
- const relevantChoices = choicesAll[key].choices.filter((choice) => choices.includes(choice))
67
+ const relevantChoices = choicesAll[key]!.choices.filter((choice) => choices.includes(choice))
69
68
  // if nothing exists, skip this key
70
69
  if (relevantChoices.length === 0) return false
71
70
 
@@ -83,11 +82,11 @@ function findChoiceGroup(pageContext: PageContext, choices: string[]) {
83
82
  })
84
83
  assertUsage(groupName, `Missing group name for [${choices}]. Define it in +docpress.choices.`)
85
84
 
86
- const mergedChoices = [...new Set([...choices, ...choicesAll[groupName].choices])]
85
+ const mergedChoices = [...new Set([...choices, ...choicesAll[groupName]!.choices])]
87
86
 
88
87
  const choiceGroup = {
89
88
  name: groupName,
90
- ...choicesAll[groupName],
89
+ ...choicesAll[groupName]!,
91
90
  choices: mergedChoices,
92
91
  }
93
92
 
@@ -1,7 +1,7 @@
1
1
  export { Pre }
2
2
 
3
3
  import React, { useState } from 'react'
4
- import { cls } from '../../utils/cls'
4
+ import { cls } from '../../utils/cls.js'
5
5
  import './Pre.css'
6
6
 
7
7
  // Styling defined in src/css/code/diff.css
@@ -1,7 +1,7 @@
1
1
  export { useSelectedChoice }
2
2
  export { initializeChoiceGroup_SSR }
3
3
 
4
- import { useLocalStorage } from './useLocalStorage'
4
+ import { useLocalStorage } from './useLocalStorage.js'
5
5
 
6
6
  const keyPrefix = 'docpress'
7
7
 
@@ -31,7 +31,6 @@ function remarkChoiceGroup() {
31
31
  const replaced = new WeakSet()
32
32
  visit(tree, (node) => {
33
33
  if (!('children' in node) || replaced.has(node)) return 'skip'
34
- if (node.type === 'mdxJsxFlowElement') return 'skip'
35
34
 
36
35
  let start = -1
37
36
  let end = 0
@@ -43,11 +42,10 @@ function remarkChoiceGroup() {
43
42
  const replacements: MdxJsxFlowElement[] = []
44
43
 
45
44
  for (const choiceNodes of choiceNodesFiltered) {
46
- const replacement = generateChoiceGroupCode(choiceNodes)
47
-
45
+ const replacement = generateChoiceGroupCode(choiceNodes, node)
48
46
  replacements.push(replacement)
49
- replaced.add(replacement)
50
47
  }
48
+ replaced.add(replacements)
51
49
 
52
50
  node.children.splice(start, end - start, ...replacements)
53
51
 
@@ -56,7 +54,7 @@ function remarkChoiceGroup() {
56
54
  }
57
55
 
58
56
  for (; end < node.children.length; end++) {
59
- const child = node.children[end]
57
+ const child = node.children[end]!
60
58
 
61
59
  if (!['code', 'mdxJsxFlowElement', 'containerDirective'].includes(child.type)) {
62
60
  process()
@@ -1,7 +1,6 @@
1
1
  export { remarkDetype }
2
2
 
3
3
  import type { Root, Parent, Code } from 'mdast'
4
- import type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx'
5
4
  import type { VFile } from '@mdx-js/mdx/internal-create-format-aware-processors'
6
5
  import { visit } from 'unist-util-visit'
7
6
  import { assertUsage } from '../utils/assert.js'
@@ -175,9 +174,9 @@ function processMagicComments(code: string) {
175
174
 
176
175
  if (matches.length) {
177
176
  for (let i = matches.length - 1; i >= 0; i--) {
178
- const match = matches[i]
177
+ const match = matches[i]!
179
178
  const [fullMatch, renameFrom, renameTo] = match
180
- code = code.split(fullMatch).join('').replaceAll(renameFrom, renameTo)
179
+ code = code.split(fullMatch).join('').replaceAll(renameFrom!, renameTo!)
181
180
  }
182
181
  }
183
182
  code = code.replaceAll('// @docpress-uncomment ', '')
@@ -2,9 +2,11 @@ export { remarkPkgManager }
2
2
 
3
3
  import type { Code, Root } from 'mdast'
4
4
  import { visit } from 'unist-util-visit'
5
- import convert from 'npm-to-yarn'
5
+ import convert_ from 'npm-to-yarn'
6
6
  import { parseMetaString } from './rehypeMetaToProps.js'
7
7
  import { generateChoiceGroupCode } from './utils/generateChoiceGroupCode.js'
8
+ // @ts-expect-error The type of npm-to-yarn doesn't work with `"moduleResolution": "Node16"`
9
+ const convert: (str: string, to: 'npm' | 'yarn' | 'pnpm' | 'bun') => string = convert_
8
10
 
9
11
  const PKG_MANAGERS = ['pnpm', 'Bun', 'Yarn'] as const
10
12
 
@@ -14,7 +14,7 @@ function shikiTransformerAutoLinks(): ShikiTransformer {
14
14
  name: 'docpress-shiki-autolinks',
15
15
  span(span) {
16
16
  if (span.children.length !== 1) return
17
- let child = span.children[0]
17
+ let child = span.children[0]!
18
18
  if (child.type !== 'text') return
19
19
 
20
20
  const links: { href: string; index: number }[] = []
@@ -26,7 +26,7 @@ function shikiTransformerAutoLinks(): ShikiTransformer {
26
26
 
27
27
  for (const match of filtered) {
28
28
  const [href] = match
29
- links.unshift({ href, index: match.index })
29
+ links.unshift({ href, index: match.index! })
30
30
  }
31
31
 
32
32
  const newChildren: typeof span.children = []
@@ -1,7 +1,7 @@
1
1
  export { generateChoiceGroupCode }
2
2
  export type { ChoiceNode }
3
3
 
4
- import type { BlockContent, DefinitionContent } from 'mdast'
4
+ import type { BlockContent, DefinitionContent, Parent } from 'mdast'
5
5
  import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx-jsx'
6
6
 
7
7
  type ChoiceNode = {
@@ -9,17 +9,10 @@ type ChoiceNode = {
9
9
  children: (BlockContent | DefinitionContent)[]
10
10
  }
11
11
 
12
- function generateChoiceGroupCode(choiceNodes: ChoiceNode[]): MdxJsxFlowElement {
12
+ function generateChoiceGroupCode(choiceNodes: ChoiceNode[], parent?: Parent): MdxJsxFlowElement {
13
13
  const attributes: MdxJsxAttribute[] = []
14
14
  const children: MdxJsxFlowElement[] = []
15
15
 
16
- const elements = choiceNodes.map((choiceNode) => ({
17
- type: 'Literal',
18
- value: findVisibleJsDropdown(choiceNode.children[0])
19
- ? `${choiceNode.choiceValue}:jsDropdown`
20
- : choiceNode.choiceValue,
21
- }))
22
-
23
16
  attributes.push({
24
17
  type: 'mdxJsxAttribute',
25
18
  name: 'choices',
@@ -37,7 +30,10 @@ function generateChoiceGroupCode(choiceNodes: ChoiceNode[]): MdxJsxFlowElement {
37
30
  expression: {
38
31
  type: 'ArrayExpression',
39
32
  // @ts-ignore: Missing properties in type definition
40
- elements,
33
+ elements: choiceNodes.map((choiceNode) => ({
34
+ type: 'Literal',
35
+ value: choiceNode.choiceValue,
36
+ })),
41
37
  },
42
38
  },
43
39
  ],
@@ -46,7 +42,32 @@ function generateChoiceGroupCode(choiceNodes: ChoiceNode[]): MdxJsxFlowElement {
46
42
  },
47
43
  })
48
44
 
45
+ let initLvl: number
46
+
47
+ switch (parent?.type) {
48
+ case 'root':
49
+ initLvl = 0
50
+ break
51
+ case 'mdxJsxFlowElement':
52
+ initLvl = 1
53
+ break
54
+
55
+ default:
56
+ initLvl = 0
57
+ break
58
+ }
59
+
60
+ attributes.push({ type: 'mdxJsxAttribute', name: 'lvl', value: `${initLvl}` })
61
+
49
62
  for (const choiceNode of choiceNodes) {
63
+ const choiceChildren: (BlockContent | DefinitionContent)[] = []
64
+ if (choiceNode.children.every((node) => node.type === 'containerDirective')) {
65
+ choiceChildren.push(...choiceNode.children.flatMap((node) => [...node.children]))
66
+ } else {
67
+ choiceChildren.push(...choiceNode.children)
68
+ }
69
+ for (const child of choiceChildren) increaseLvl(child)
70
+
50
71
  children.push({
51
72
  type: 'mdxJsxFlowElement',
52
73
  name: 'div',
@@ -54,9 +75,7 @@ function generateChoiceGroupCode(choiceNodes: ChoiceNode[]): MdxJsxFlowElement {
54
75
  { type: 'mdxJsxAttribute', name: 'data-choice-value', value: choiceNode.choiceValue },
55
76
  { type: 'mdxJsxAttribute', name: 'className', value: 'choice' },
56
77
  ],
57
- children: choiceNode.children.every((node) => node.type === 'containerDirective')
58
- ? choiceNode.children.flatMap((node) => [...node.children])
59
- : choiceNode.children,
78
+ children: choiceChildren,
60
79
  })
61
80
  }
62
81
 
@@ -68,12 +87,12 @@ function generateChoiceGroupCode(choiceNodes: ChoiceNode[]): MdxJsxFlowElement {
68
87
  }
69
88
  }
70
89
 
71
- function findVisibleJsDropdown(node: BlockContent | DefinitionContent) {
72
- let currentNode = node
73
- if (node.type === 'containerDirective' && node.name === 'Choice') currentNode = node.children[0]
74
- return (
75
- currentNode.type === 'mdxJsxFlowElement' &&
76
- currentNode.data?.customDataFilter === 'codeLang' &&
77
- currentNode.attributes.every((attribute) => attribute.type !== 'mdxJsxAttribute' || attribute.name !== 'hide')
78
- )
90
+ function increaseLvl(node: BlockContent | DefinitionContent) {
91
+ if (node.type === 'mdxJsxFlowElement' && node.name === 'ChoiceGroup') {
92
+ const attribute = node.attributes.find(
93
+ (attribute) => attribute.type === 'mdxJsxAttribute' && attribute.name === 'lvl',
94
+ )
95
+ const lvlValue = attribute?.value
96
+ if (lvlValue) attribute.value = `${Number(lvlValue) + 1}`
97
+ }
79
98
  }
@@ -2,9 +2,9 @@ export { Hit }
2
2
 
3
3
  import React from 'react'
4
4
  import type { DocSearchHit, InternalDocSearchHit, StoredDocSearchHit } from '@docsearch/react'
5
- import { Snippet } from './Snippet'
6
- import { SourceIcon } from './SourceIcon'
7
- import { SelectIcon } from './SelectIcon'
5
+ import { Snippet } from './Snippet.js'
6
+ import { SourceIcon } from './SourceIcon.js'
7
+ import { SelectIcon } from './SelectIcon.js'
8
8
 
9
9
  type HitProps = {
10
10
  hit: InternalDocSearchHit | StoredDocSearchHit
@@ -1,7 +1,7 @@
1
1
  export { CodeBlockTransformer }
2
2
 
3
3
  import React from 'react'
4
- import { assert } from '../utils/server'
4
+ import { assert } from '../utils/server.js'
5
5
  import './CodeBlockTransformer.css'
6
6
 
7
7
  type LineBreak = 'white-space' | 'break-word'
@@ -2,6 +2,6 @@ export { Comment }
2
2
 
3
3
  import React from 'react'
4
4
 
5
- function Comment({ children }: { children: React.ReactNode }) {
5
+ function Comment() {
6
6
  return <></>
7
7
  }
@@ -1,7 +1,7 @@
1
1
  export { HorizontalLine }
2
2
 
3
3
  import React from 'react'
4
- import { cls } from '../utils/cls'
4
+ import { cls } from '../utils/cls.js'
5
5
 
6
6
  function HorizontalLine({ primary }: { primary?: true }) {
7
7
  return (
@@ -1,5 +1,5 @@
1
1
  import React from 'react'
2
- import { assert } from '../utils/server'
2
+ import { assert } from '../utils/server.js'
3
3
 
4
4
  export { ImportMeta }
5
5
 
@@ -2,12 +2,12 @@ export { Link }
2
2
  export type { LinkData }
3
3
 
4
4
  import React from 'react'
5
- import { usePageContext } from '../renderer/usePageContext'
6
- import { assert, assertUsage, assertWarning, determineSectionTitle, determineSectionUrlHash } from '../utils/server'
7
- import { parseMarkdownMini } from '../parseMarkdownMini'
5
+ import { usePageContext } from '../renderer/usePageContext.js'
6
+ import { assert, assertUsage, assertWarning, determineSectionTitle, determineSectionUrlHash } from '../utils/server.js'
7
+ import { parseMarkdownMini } from '../parseMarkdownMini.js'
8
8
  import pc from '@brillout/picocolors'
9
9
  import type { PageContext } from 'vike/types'
10
- import type { StringArray } from '../types/Heading'
10
+ import type { StringArray } from '../types/Heading.js'
11
11
 
12
12
  function Link({
13
13
  href,
@@ -67,7 +67,7 @@ function getLinkText({
67
67
  if (sectionTitle) breadcrumbParts.push(sectionTitle)
68
68
 
69
69
  if (noBreadcrumb || isLinkOnSamePage) {
70
- return breadcrumbParts[breadcrumbParts.length - 1]
70
+ return breadcrumbParts[breadcrumbParts.length - 1]!
71
71
  }
72
72
  return (
73
73
  <>
@@ -14,7 +14,7 @@ export { Note }
14
14
  */
15
15
 
16
16
  import React from 'react'
17
- import { assert } from '../utils/assert'
17
+ import { assert } from '../utils/assert.js'
18
18
  import './Note.css'
19
19
 
20
20
  type Props = {
@@ -2,7 +2,7 @@ export { RepoLink }
2
2
  export { getRepoHref }
3
3
 
4
4
  import React from 'react'
5
- import { usePageContext } from '../renderer/usePageContext'
5
+ import { usePageContext } from '../renderer/usePageContext.js'
6
6
 
7
7
  function RepoLink({ path, text }: { path: string; text?: string | React.ReactNode }) {
8
8
  text = text || path