@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.
- package/+config.ts +2 -2
- package/EditLink.tsx +3 -3
- package/ExternalLinks.tsx +1 -1
- package/Layout.tsx +15 -14
- package/MenuModal/Collapsible.tsx +1 -1
- package/MenuModal/NavigationWithColumnLayout.tsx +11 -11
- package/MenuModal/toggleMenuModal.ts +4 -4
- package/MenuModal.tsx +12 -8
- package/NavItemComponent.tsx +4 -3
- package/code-blocks/components/ChoiceGroup.css +6 -11
- package/code-blocks/components/ChoiceGroup.tsx +18 -19
- package/code-blocks/components/Pre.tsx +1 -1
- package/code-blocks/hooks/useSelectedChoice.ts +1 -1
- package/code-blocks/remarkChoiceGroup.ts +3 -5
- package/code-blocks/remarkDetype.ts +2 -3
- package/code-blocks/remarkPkgManager.ts +3 -1
- package/code-blocks/shikiTransformerAutoLinks.ts +2 -2
- package/code-blocks/utils/generateChoiceGroupCode.ts +40 -21
- package/components/Algolia/Hit.tsx +3 -3
- package/components/CodeBlockTransformer.tsx +1 -1
- package/components/Comment.tsx +1 -1
- package/components/HorizontalLine.tsx +1 -1
- package/components/ImportMeta.tsx +1 -1
- package/components/Link.tsx +5 -5
- package/components/Note.tsx +1 -1
- package/components/RepoLink.tsx +1 -1
- package/components/index.ts +10 -10
- package/css/index.css +1 -1
- package/determineNavItemsColumnLayout.spec.ts +2 -2
- package/determineNavItemsColumnLayout.ts +6 -6
- package/dist/+config.d.ts +2 -2
- package/dist/NavItemComponent.js +2 -2
- package/dist/code-blocks/rehypeMetaToProps.js +1 -1
- package/dist/code-blocks/remarkChoiceGroup.js +4 -6
- package/dist/code-blocks/remarkDetype.js +3 -3
- package/dist/code-blocks/remarkPkgManager.js +4 -2
- package/dist/code-blocks/utils/generateChoiceGroupCode.d.ts +2 -2
- package/dist/code-blocks/utils/generateChoiceGroupCode.js +35 -18
- package/dist/components/CodeBlockTransformer.js +1 -1
- package/dist/components/Comment.d.ts +1 -3
- package/dist/components/Comment.js +1 -1
- package/dist/components/HorizontalLine.js +1 -1
- package/dist/components/ImportMeta.js +1 -1
- package/dist/components/Link.d.ts +1 -1
- package/dist/components/Link.js +3 -3
- package/dist/components/Note.js +2 -2
- package/dist/components/RepoLink.js +1 -1
- package/dist/components/index.d.ts +10 -10
- package/dist/components/index.js +10 -10
- package/dist/determineNavItemsColumnLayout.d.ts +1 -1
- package/dist/determineNavItemsColumnLayout.js +3 -2
- package/dist/renderer/usePageContext.d.ts +3 -3
- package/dist/renderer/usePageContext.js +1 -1
- package/dist/resolvePageContext.d.ts +2 -2
- package/dist/resolvePageContext.js +5 -5
- package/dist/types/Config.d.ts +1 -1
- package/dist/utils/Emoji/Emoji.js +2 -2
- package/dist/utils/Emoji/index.d.ts +1 -1
- package/dist/utils/Emoji/index.js +1 -1
- package/dist/utils/client.d.ts +3 -3
- package/dist/utils/client.js +3 -3
- package/dist/utils/jsxToTextContent.js +1 -1
- package/dist/utils/server.d.ts +7 -7
- package/dist/utils/server.js +7 -7
- package/docsearch/DocSearchInstall.tsx +3 -3
- package/docsearch/SearchLink.tsx +2 -2
- package/docsearch/toggleDocsearchModal.ts +1 -1
- package/index.ts +10 -10
- package/initKeyBindings.ts +2 -2
- package/installSectionUrlHashs.ts +1 -1
- package/package.json +1 -1
- package/parsePageSections.ts +2 -2
- package/renderer/getHydrationPromise.ts +2 -2
- package/renderer/getPageElement.tsx +3 -3
- package/renderer/initOnNavigation.ts +3 -3
- package/renderer/onCreatePageContext.ts +1 -1
- package/renderer/onRenderClient.tsx +9 -9
- package/renderer/onRenderHtml.tsx +3 -3
- package/renderer/usePageContext.tsx +1 -1
- package/resolvePageContext.ts +10 -10
- package/tsconfig.json +20 -12
- package/types/Config.ts +1 -1
- package/utils/Emoji/Emoji.ts +2 -2
- package/utils/Emoji/index.ts +1 -1
- package/utils/addScript.ts +1 -1
- package/utils/client.ts +3 -3
- package/utils/determineSectionUrlHash.ts +2 -2
- package/utils/jsxToTextContent.ts +1 -1
- 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,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 {
|
|
11
|
-
|
|
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 (
|
package/NavItemComponent.tsx
CHANGED
|
@@ -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
|
-
|
|
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-
|
|
14
|
-
--
|
|
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
|
|
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
|
|
30
|
-
const
|
|
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 || !
|
|
33
|
+
const isHidden = choices.length === 1 || !choices.includes(selectedChoice) || hide
|
|
36
34
|
|
|
37
35
|
return (
|
|
38
|
-
<div
|
|
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',
|
|
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={!
|
|
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]
|
|
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]
|
|
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
|
|
|
@@ -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
|
|
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
|
|
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:
|
|
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
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
package/components/Comment.tsx
CHANGED
package/components/Link.tsx
CHANGED
|
@@ -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
|
<>
|
package/components/Note.tsx
CHANGED
package/components/RepoLink.tsx
CHANGED
|
@@ -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
|