@brillout/docpress 0.7.2 → 0.7.4
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 +10 -1
- package/LICENSE.md +9 -0
- package/{PageLayout.css → Layout.css} +21 -0
- package/Layout.tsx +92 -0
- package/algolia/DocSearch.css +2 -5
- package/components/Algolia/Hit.tsx +67 -0
- package/components/Algolia/README.md +21 -0
- package/components/Algolia/SelectIcon.tsx +12 -0
- package/components/Algolia/Snippet.tsx +32 -0
- package/components/Algolia/SourceIcon.tsx +55 -0
- package/components/Algolia/types.ts +86 -0
- package/config/resolveHeadingsData.ts +11 -3
- package/dist/+config.d.ts +13 -0
- package/dist/+config.js +8 -0
- package/dist/components/Algolia/Hit.d.ts +4 -0
- package/dist/components/Algolia/Hit.js +30 -0
- package/dist/components/Algolia/SelectIcon.d.ts +2 -0
- package/dist/components/Algolia/SelectIcon.js +7 -0
- package/dist/components/Algolia/Snippet.d.ts +13 -0
- package/dist/components/Algolia/Snippet.js +37 -0
- package/dist/components/Algolia/SourceIcon.d.ts +4 -0
- package/dist/components/Algolia/SourceIcon.js +23 -0
- package/dist/components/Algolia/types.d.ts +79 -0
- package/dist/components/Algolia/types.js +1 -0
- package/dist/config/resolveHeadingsData.d.ts +5 -0
- package/dist/config/resolveHeadingsData.js +13 -6
- package/dist/config/resolvePageContext.d.ts +5 -0
- package/dist/navigation/Navigation.js +8 -8
- package/dist/navigation/NavigationHeader.d.ts +4 -0
- package/dist/navigation/NavigationHeader.js +9 -19
- package/dist/types/Heading.d.ts +10 -4
- package/dist/utils/assert.js +6 -10
- package/icons/twitter.svg +1 -16
- package/navigation/Navigation-items.css +1 -1
- package/navigation/Navigation-layout.css +1 -1
- package/navigation/Navigation.tsx +10 -11
- package/navigation/NavigationHeader.tsx +10 -21
- package/navigation/navigation-fullscreen/initNavigationFullscreen.ts +32 -8
- package/package.json +22 -18
- package/renderer/getPageElement.tsx +15 -4
- package/renderer/onRenderClient.tsx +16 -2
- package/types/Heading.ts +11 -6
- package/utils/assert.ts +5 -10
- package/PageLayout.tsx +0 -48
package/package.json
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brillout/docpress",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"======== Build": "",
|
|
7
|
-
"// Build vite.config.ts and +config.ts (other files don't need to be built as @brillout/docpress is noExternal)": "",
|
|
8
|
-
"build": "rm -rf dist/ && tsc --project tsconfig.config.json",
|
|
9
|
-
"======== Develop": "",
|
|
10
|
-
"dev": "tsc --watch --project tsconfig.config.json",
|
|
11
|
-
"// Check types of all source files while developing": "",
|
|
12
|
-
"typecheck": "tsc --noEmit --watch",
|
|
13
|
-
"========= Release": "",
|
|
14
|
-
"release": "release-me patch",
|
|
15
|
-
"release:minor": "release-me minor",
|
|
16
|
-
"release:commit": "release-me commit"
|
|
17
|
-
},
|
|
18
5
|
"dependencies": {
|
|
19
6
|
"@brillout/picocolors": "^1.0.10",
|
|
20
7
|
"@docsearch/css": "^3.6.1",
|
|
@@ -37,13 +24,14 @@
|
|
|
37
24
|
"react": ">=18.0.0",
|
|
38
25
|
"react-dom": ">=18.0.0",
|
|
39
26
|
"typescript": "*",
|
|
40
|
-
"vike": ">=0.4.
|
|
27
|
+
"vike": ">=0.4.198",
|
|
41
28
|
"vite": ">=5.2.0"
|
|
42
29
|
},
|
|
43
30
|
"exports": {
|
|
44
31
|
"./renderer/onRenderHtml": "./renderer/onRenderHtml.tsx",
|
|
45
32
|
"./renderer/onRenderClient": "./renderer/onRenderClient.tsx",
|
|
46
33
|
"./renderer/onBeforeRender": "./renderer/onBeforeRender.ts",
|
|
34
|
+
"./Layout": "./Layout.tsx",
|
|
47
35
|
".": "./index.ts",
|
|
48
36
|
"./FeatureList/FeatureList": "./components/FeatureList/FeatureList.tsx",
|
|
49
37
|
"./FeatureList/FeatureList.client": {
|
|
@@ -51,7 +39,10 @@
|
|
|
51
39
|
},
|
|
52
40
|
"./vite-config": "./dist/vite.config.js",
|
|
53
41
|
"./config": "./dist/+config.js",
|
|
54
|
-
"./style": "./css/index.css"
|
|
42
|
+
"./style": "./css/index.css",
|
|
43
|
+
"./types": {
|
|
44
|
+
"types": "./types.d.ts"
|
|
45
|
+
}
|
|
55
46
|
},
|
|
56
47
|
"typesVersions": {
|
|
57
48
|
"*": {
|
|
@@ -73,7 +64,7 @@
|
|
|
73
64
|
}
|
|
74
65
|
},
|
|
75
66
|
"devDependencies": {
|
|
76
|
-
"@brillout/release-me": "^0.
|
|
67
|
+
"@brillout/release-me": "^0.4.2",
|
|
77
68
|
"@types/node": "link:../demo/node_modules/@types/node/",
|
|
78
69
|
"@types/react": "link:../demo/node_modules/@types/react/",
|
|
79
70
|
"@types/react-dom": "link:../demo/node_modules/@types/react-dom/",
|
|
@@ -87,5 +78,18 @@
|
|
|
87
78
|
"license": "MIT",
|
|
88
79
|
"publishConfig": {
|
|
89
80
|
"access": "public"
|
|
81
|
+
},
|
|
82
|
+
"scripts": {
|
|
83
|
+
"======== Build": "",
|
|
84
|
+
"// Build vite.config.ts and +config.ts (other files don't need to be built as @brillout/docpress is noExternal)": "",
|
|
85
|
+
"build": "rm -rf dist/ && tsc --project tsconfig.config.json",
|
|
86
|
+
"======== Develop": "",
|
|
87
|
+
"dev": "tsc --watch --project tsconfig.config.json",
|
|
88
|
+
"// Check types of all source files while developing": "",
|
|
89
|
+
"typecheck": "tsc --noEmit --watch",
|
|
90
|
+
"========= Release": "",
|
|
91
|
+
"release": "release-me patch",
|
|
92
|
+
"release:minor": "release-me minor",
|
|
93
|
+
"release:commit": "release-me commit"
|
|
90
94
|
}
|
|
91
|
-
}
|
|
95
|
+
}
|
|
@@ -2,15 +2,26 @@ export { getPageElement }
|
|
|
2
2
|
|
|
3
3
|
import type { PageContext } from 'vike/types'
|
|
4
4
|
import type { PageContextResolved } from '../config/resolvePageContext'
|
|
5
|
-
import {
|
|
5
|
+
import { PageContextProvider, PageContextProvider2 } from './usePageContext'
|
|
6
6
|
import React from 'react'
|
|
7
7
|
|
|
8
8
|
function getPageElement(pageContext: PageContext, pageContextResolved: PageContextResolved) {
|
|
9
9
|
const { Page } = pageContext
|
|
10
|
+
const { Layout = PassThrough } = pageContext.config
|
|
10
11
|
const page = (
|
|
11
|
-
<
|
|
12
|
-
<
|
|
13
|
-
|
|
12
|
+
<React.StrictMode>
|
|
13
|
+
<PageContextProvider2 pageContext={pageContext}>
|
|
14
|
+
<PageContextProvider pageContext={pageContextResolved}>
|
|
15
|
+
<Layout pageContext={pageContextResolved} pageContext2={pageContext}>
|
|
16
|
+
<Page />
|
|
17
|
+
</Layout>
|
|
18
|
+
</PageContextProvider>
|
|
19
|
+
</PageContextProvider2>
|
|
20
|
+
</React.StrictMode>
|
|
14
21
|
)
|
|
15
22
|
return page
|
|
16
23
|
}
|
|
24
|
+
|
|
25
|
+
function PassThrough({ children }: any) {
|
|
26
|
+
return <>{children}</>
|
|
27
|
+
}
|
|
@@ -8,6 +8,7 @@ import { getPageElement } from './getPageElement'
|
|
|
8
8
|
import {
|
|
9
9
|
hideNavigationFullScreen,
|
|
10
10
|
initNavigationFullscreen,
|
|
11
|
+
initNavigationFullscreenOnce,
|
|
11
12
|
} from '../navigation/navigation-fullscreen/initNavigationFullscreen'
|
|
12
13
|
import { hideMobileNavigation, initMobileNavigation } from '../navigation/initMobileNavigation'
|
|
13
14
|
import { initPressKit } from '../navigation/initPressKit'
|
|
@@ -16,12 +17,18 @@ import { autoScrollNav } from '../autoScrollNav'
|
|
|
16
17
|
import { installSectionUrlHashs } from '../installSectionUrlHashs'
|
|
17
18
|
import { addFeatureClickHandlers, addTwitterWidgets } from '../components/FeatureList/FeatureList.client'
|
|
18
19
|
|
|
20
|
+
addEcosystemStamp()
|
|
19
21
|
initOnLinkClick()
|
|
22
|
+
initNavigationFullscreenOnce()
|
|
20
23
|
|
|
21
24
|
let root: ReactDOM.Root
|
|
22
|
-
|
|
25
|
+
let renderPromiseResolve: () => void
|
|
26
|
+
async function onRenderClient(pageContext: PageContextClient) {
|
|
23
27
|
// TODO: stop using any
|
|
24
28
|
const pageContextResolved: PageContextResolved = (pageContext as any).pageContextResolved
|
|
29
|
+
const renderPromise = new Promise<void>((r) => {
|
|
30
|
+
renderPromiseResolve = r
|
|
31
|
+
})
|
|
25
32
|
let page = getPageElement(pageContext, pageContextResolved)
|
|
26
33
|
page = <OnRenderDoneHook>{page}</OnRenderDoneHook>
|
|
27
34
|
const container = document.getElementById('page-view')!
|
|
@@ -33,10 +40,10 @@ function onRenderClient(pageContext: PageContextClient) {
|
|
|
33
40
|
}
|
|
34
41
|
root.render(page)
|
|
35
42
|
}
|
|
36
|
-
|
|
37
43
|
if (!pageContext.isHydration) {
|
|
38
44
|
applyHead(pageContext)
|
|
39
45
|
}
|
|
46
|
+
await renderPromise
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
function applyHead(pageContext: PageContextClient) {
|
|
@@ -54,6 +61,7 @@ function onRenderDone() {
|
|
|
54
61
|
addFeatureClickHandlers()
|
|
55
62
|
addTwitterWidgets()
|
|
56
63
|
setHydrationIsFinished()
|
|
64
|
+
renderPromiseResolve()
|
|
57
65
|
}
|
|
58
66
|
|
|
59
67
|
function OnRenderDoneHook({ children }: { children: React.ReactNode }) {
|
|
@@ -88,3 +96,9 @@ function setHydrationIsFinished() {
|
|
|
88
96
|
// - https://github.com/brillout/telefunc/blob/57c942c15b7795cfda96b5106acc9e098aa509aa/docs/.testRun.ts#L26
|
|
89
97
|
;(window as any).__docpress_hydrationFinished = true
|
|
90
98
|
}
|
|
99
|
+
|
|
100
|
+
// Used by:
|
|
101
|
+
// - https://github.com/vikejs/vike/blob/87cca54f30b3c7e71867763d5723493d7eef37ab/vike/client/client-routing-runtime/prefetch.ts#L309-L312
|
|
102
|
+
function addEcosystemStamp() {
|
|
103
|
+
;(window as any)._isBrilloutDocpress = true
|
|
104
|
+
}
|
package/types/Heading.ts
CHANGED
|
@@ -3,13 +3,13 @@ export { HeadingDetachedResolved }
|
|
|
3
3
|
export { HeadingDetachedDefinition }
|
|
4
4
|
export { HeadingDefinition }
|
|
5
5
|
|
|
6
|
-
import type { EmojiName } from '../utils/server'
|
|
7
|
-
|
|
8
6
|
type HeadingResolved = {
|
|
9
7
|
url?: null | string
|
|
10
8
|
level: number
|
|
11
9
|
title: string
|
|
12
10
|
titleInNav: string
|
|
11
|
+
noSideNavigation?: true
|
|
12
|
+
topNavigation?: true | string
|
|
13
13
|
linkBreadcrumb: string[]
|
|
14
14
|
sectionTitles?: string[]
|
|
15
15
|
} & Tmp
|
|
@@ -19,22 +19,27 @@ type HeadingDetachedResolved = Omit<HeadingResolved, 'level' | 'linkBreadcrumb'>
|
|
|
19
19
|
linkBreadcrumb: null
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
type
|
|
23
|
-
url: string
|
|
22
|
+
type HeadingDefinitionCommon = {
|
|
24
23
|
title: string
|
|
24
|
+
topNavigation?: true | string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type HeadingDetachedDefinition = HeadingDefinitionCommon & {
|
|
28
|
+
url: string
|
|
25
29
|
sectionTitles?: string[]
|
|
26
30
|
}
|
|
27
31
|
|
|
28
|
-
type HeadingDefinition = {
|
|
32
|
+
type HeadingDefinition = HeadingDefinitionCommon & {
|
|
29
33
|
url?: null | string
|
|
30
|
-
title: string
|
|
31
34
|
titleInNav?: string
|
|
35
|
+
noSideNavigation?: true
|
|
32
36
|
} & HeadingDefinitionLevel &
|
|
33
37
|
Tmp
|
|
34
38
|
type IsCategory = {
|
|
35
39
|
url?: undefined
|
|
36
40
|
titleDocument?: undefined
|
|
37
41
|
titleInNav?: undefined
|
|
42
|
+
noSideNavigation?: undefined
|
|
38
43
|
}
|
|
39
44
|
type HeadingDefinitionLevel =
|
|
40
45
|
| ({ level: 1 } & IsCategory)
|
package/utils/assert.ts
CHANGED
|
@@ -10,14 +10,14 @@ if (isBrowser()) {
|
|
|
10
10
|
[
|
|
11
11
|
'[@brillout/docpress] DEV MODE',
|
|
12
12
|
isDevMode() ? 'enabled' : 'disabled',
|
|
13
|
-
!isLocalhost() && 'run window.toggleDevMode() to toggle DEV MODE',
|
|
13
|
+
!isLocalhost() && '— run window.toggleDevMode() to toggle DEV MODE',
|
|
14
14
|
]
|
|
15
15
|
.filter(Boolean)
|
|
16
16
|
.join(' '),
|
|
17
17
|
)
|
|
18
18
|
if (isDevMode()) {
|
|
19
19
|
window.onerror = (err) => {
|
|
20
|
-
alert(err)
|
|
20
|
+
window.alert(err)
|
|
21
21
|
window.onerror = null
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -39,9 +39,6 @@ function assert(condition: unknown, debugInfo?: unknown): asserts condition {
|
|
|
39
39
|
errMsg += ' Debug info: ' + String(debugInfo)
|
|
40
40
|
}
|
|
41
41
|
const err = new Error(errMsg)
|
|
42
|
-
if (isBrowser() && isDevMode()) {
|
|
43
|
-
window.alert(err.stack)
|
|
44
|
-
}
|
|
45
42
|
throw err
|
|
46
43
|
}
|
|
47
44
|
|
|
@@ -50,9 +47,6 @@ function assertUsage(condition: unknown, msg: string): asserts condition {
|
|
|
50
47
|
return
|
|
51
48
|
}
|
|
52
49
|
const err = new Error('[DocPress][Wrong Usage] ' + msg)
|
|
53
|
-
if (isBrowser() && isDevMode()) {
|
|
54
|
-
window.alert(err.stack)
|
|
55
|
-
}
|
|
56
50
|
throw err
|
|
57
51
|
}
|
|
58
52
|
|
|
@@ -81,8 +75,9 @@ function assertWarning(condition: unknown, msg: string): asserts condition {
|
|
|
81
75
|
return
|
|
82
76
|
}
|
|
83
77
|
msg = '[DocPress][Warning] ' + msg
|
|
84
|
-
console.warn(msg)
|
|
85
78
|
if (isBrowser() && isDevMode()) {
|
|
86
|
-
|
|
79
|
+
throw new Error(msg)
|
|
80
|
+
} else {
|
|
81
|
+
console.warn(msg)
|
|
87
82
|
}
|
|
88
83
|
}
|
package/PageLayout.tsx
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { Navigation, NavigationMask } from './navigation/Navigation'
|
|
3
|
-
import type { PageContextResolved } from './config/resolvePageContext'
|
|
4
|
-
import { MobileHeader } from './MobileHeader'
|
|
5
|
-
import { EditPageNote } from './components/EditPageNote'
|
|
6
|
-
import { PageContextProvider, PageContextProvider2 } from './renderer/usePageContext'
|
|
7
|
-
import './PageLayout.css'
|
|
8
|
-
import { NavigationFullscreenButton } from './navigation/navigation-fullscreen/NavigationFullscreenButton'
|
|
9
|
-
import type { PageContext } from 'vike/types'
|
|
10
|
-
import { parseTitle } from './parseTitle'
|
|
11
|
-
|
|
12
|
-
export { PageLayout }
|
|
13
|
-
|
|
14
|
-
function PageLayout({
|
|
15
|
-
pageContext,
|
|
16
|
-
children,
|
|
17
|
-
pageContext2,
|
|
18
|
-
}: { pageContext: PageContextResolved; children: React.ReactNode; pageContext2: PageContext }) {
|
|
19
|
-
const { isLandingPage, pageTitle, navigationData } = pageContext
|
|
20
|
-
const pageTitleParsed = pageTitle && parseTitle(pageTitle)
|
|
21
|
-
const { globalNote } = pageContext.config
|
|
22
|
-
return (
|
|
23
|
-
<React.StrictMode>
|
|
24
|
-
<PageContextProvider2 pageContext={pageContext2}>
|
|
25
|
-
<PageContextProvider pageContext={pageContext}>
|
|
26
|
-
<div className={`page-layout ${isLandingPage ? 'landing-page' : 'doc-page'}`}>
|
|
27
|
-
<div id="navigation-wrapper">
|
|
28
|
-
<Navigation {...pageContext.navigationData} />
|
|
29
|
-
</div>
|
|
30
|
-
<NavigationFullscreenButton />
|
|
31
|
-
<div className="page-wrapper">
|
|
32
|
-
<div className="page-container">
|
|
33
|
-
<MobileHeader />
|
|
34
|
-
<div className="page-content">
|
|
35
|
-
{globalNote}
|
|
36
|
-
{pageTitleParsed && <h1 id={`${navigationData.currentUrl.replace('/', '')}`}>{pageTitleParsed}</h1>}
|
|
37
|
-
{children}
|
|
38
|
-
{!isLandingPage && <EditPageNote pageContext={pageContext} />}
|
|
39
|
-
</div>
|
|
40
|
-
</div>
|
|
41
|
-
<NavigationMask />
|
|
42
|
-
</div>
|
|
43
|
-
</div>
|
|
44
|
-
</PageContextProvider>
|
|
45
|
-
</PageContextProvider2>
|
|
46
|
-
</React.StrictMode>
|
|
47
|
-
)
|
|
48
|
-
}
|