@brillout/docpress 0.6.20 → 0.6.21-commit-74553e7

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 (105) hide show
  1. package/+config.ts +26 -7
  2. package/MobileHeader.tsx +5 -3
  3. package/PageLayout.css +11 -11
  4. package/PageLayout.tsx +27 -20
  5. package/algolia/DocSearch.css +6 -9
  6. package/autoScrollNav.ts +4 -3
  7. package/components/FeatureList/FeatureList.client.ts +6 -11
  8. package/components/Link.tsx +9 -9
  9. package/config/getConfig.ts +2 -1
  10. package/config/resolveHeadingsData.ts +22 -30
  11. package/config/resolvePageContext.ts +4 -6
  12. package/dist/+config.d.ts +25 -8
  13. package/dist/+config.js +7 -7
  14. package/dist/components/CodeBlockTransformer.d.ts +7 -0
  15. package/dist/components/CodeBlockTransformer.js +9 -0
  16. package/dist/components/Comment.d.ts +5 -0
  17. package/dist/components/Comment.js +6 -0
  18. package/dist/components/Consulting.d.ts +4 -0
  19. package/dist/components/Consulting.js +39 -0
  20. package/dist/components/Contributors.d.ts +7 -0
  21. package/dist/components/Contributors.js +74 -0
  22. package/dist/components/FileRemoved.d.ts +9 -0
  23. package/dist/components/FileRemoved.js +28 -0
  24. package/dist/components/HorizontalLine.d.ts +5 -0
  25. package/dist/components/HorizontalLine.js +15 -0
  26. package/dist/components/ImportMeta.d.ts +5 -0
  27. package/dist/components/ImportMeta.js +10 -0
  28. package/dist/components/Link.d.ts +16 -0
  29. package/dist/components/Link.js +108 -0
  30. package/dist/components/Note.d.ts +22 -0
  31. package/dist/components/Note.js +93 -0
  32. package/dist/components/P.d.ts +4 -0
  33. package/dist/components/P.js +17 -0
  34. package/dist/components/ReadingRecommendation.d.ts +6 -0
  35. package/dist/components/ReadingRecommendation.js +40 -0
  36. package/dist/components/RepoLink.d.ts +9 -0
  37. package/dist/components/RepoLink.js +22 -0
  38. package/dist/components/Sponsors.d.ts +22 -0
  39. package/dist/components/Sponsors.js +161 -0
  40. package/dist/components/Supporters.d.ts +32 -0
  41. package/dist/components/Supporters.js +80 -0
  42. package/dist/components/index.d.ts +15 -0
  43. package/dist/components/index.js +15 -0
  44. package/dist/config/getConfig.d.ts +3 -0
  45. package/dist/config/getConfig.js +14 -0
  46. package/dist/config/resolveHeadingsData.d.ts +16 -0
  47. package/dist/config/resolveHeadingsData.js +223 -0
  48. package/dist/config/resolvePageContext.d.ts +38 -0
  49. package/dist/config/resolvePageContext.js +23 -0
  50. package/dist/data/maintainersList.d.ts +9 -0
  51. package/dist/data/maintainersList.js +83 -0
  52. package/dist/data/sponsorsList.d.ts +3 -0
  53. package/dist/data/sponsorsList.js +151 -0
  54. package/dist/navigation/Navigation.d.ts +20 -0
  55. package/dist/navigation/Navigation.js +127 -0
  56. package/dist/navigation/NavigationHeader.d.ts +4 -0
  57. package/dist/navigation/NavigationHeader.js +85 -0
  58. package/dist/navigation/navigation-fullscreen/NavigationFullscreenButton.d.ts +6 -0
  59. package/dist/navigation/navigation-fullscreen/NavigationFullscreenButton.js +22 -0
  60. package/dist/parsePageSections.js +2 -2
  61. package/dist/parseTitle.d.ts +5 -0
  62. package/dist/parseTitle.js +52 -0
  63. package/dist/renderer/usePageContext.d.ts +17 -0
  64. package/dist/renderer/usePageContext.js +26 -0
  65. package/dist/types/Config.d.ts +30 -0
  66. package/dist/types/Config.js +1 -0
  67. package/dist/types/Heading.d.ts +45 -0
  68. package/dist/types/Heading.js +1 -0
  69. package/dist/utils/Emoji/Emoji.d.ts +8 -0
  70. package/dist/utils/Emoji/Emoji.js +191 -0
  71. package/dist/utils/Emoji/assets.d.ts +6 -0
  72. package/dist/utils/Emoji/assets.js +7 -0
  73. package/dist/utils/Emoji/index.d.ts +1 -0
  74. package/dist/utils/Emoji/index.js +1 -0
  75. package/dist/utils/client.d.ts +2 -0
  76. package/dist/utils/client.js +2 -0
  77. package/dist/utils/filter.d.ts +2 -0
  78. package/dist/utils/filter.js +11 -0
  79. package/dist/utils/isBrowser.d.ts +2 -0
  80. package/dist/utils/isBrowser.js +4 -0
  81. package/dist/utils/jsxToTextContent.d.ts +2 -0
  82. package/dist/utils/jsxToTextContent.js +12 -0
  83. package/dist/utils/objectAssign.d.ts +2 -0
  84. package/dist/utils/objectAssign.js +5 -0
  85. package/dist/utils/server.d.ts +7 -0
  86. package/dist/utils/server.js +7 -0
  87. package/dist/vite.config.js +7 -2
  88. package/installSectionUrlHashs.ts +7 -6
  89. package/navigation/Navigation-layout.css +2 -2
  90. package/navigation/Navigation.tsx +9 -6
  91. package/navigation/NavigationHeader.tsx +33 -4
  92. package/navigation/initPressKit.ts +2 -1
  93. package/package.json +17 -13
  94. package/renderer/getPageElement.tsx +16 -0
  95. package/renderer/onBeforeRender.ts +12 -0
  96. package/renderer/onRenderClient.tsx +53 -0
  97. package/renderer/onRenderHtml.tsx +7 -22
  98. package/renderer/usePageContext.tsx +20 -0
  99. package/tsconfig.json +1 -1
  100. package/types/Config.ts +6 -20
  101. package/types/Heading.ts +4 -4
  102. package/vite.config.ts +7 -2
  103. package/algolia/DocSearch.ts +0 -62
  104. package/navigation/Navigation.client.ts +0 -7
  105. package/renderer/client.ts +0 -4
@@ -0,0 +1,12 @@
1
+ export { onBeforeRender }
2
+
3
+ import { resolvePageContext, type PageContextOriginal, type PageContextResolved } from '../config/resolvePageContext'
4
+
5
+ function onBeforeRender(pageContextOriginal: PageContextOriginal) {
6
+ const pageContextResolved = resolvePageContext(pageContextOriginal)
7
+ return {
8
+ pageContext: {
9
+ pageContextResolved,
10
+ },
11
+ }
12
+ }
@@ -0,0 +1,53 @@
1
+ export { onRenderClient }
2
+
3
+ import React, { useEffect } from 'react'
4
+ import type { PageContextClient } from 'vike/types'
5
+ import ReactDOM from 'react-dom/client'
6
+ import { PageContextResolved } from '../config/resolvePageContext'
7
+ import { getPageElement } from './getPageElement'
8
+ import { initNavigationFullscreen } from '../navigation/navigation-fullscreen/initNavigationFullscreen'
9
+ import { initMobileNavigation } from '../navigation/initMobileNavigation'
10
+ import { initPressKit } from '../navigation/initPressKit'
11
+ import '../css/index.css'
12
+ import { autoScrollNav } from '../autoScrollNav'
13
+ import { installSectionUrlHashs } from '../installSectionUrlHashs'
14
+ import { addFeatureClickHandlers, addTwitterWidgets } from '../components/FeatureList/FeatureList.client'
15
+
16
+ let root: ReactDOM.Root
17
+ function onRenderClient(pageContext: PageContextClient) {
18
+ const pageContextResolved: PageContextResolved = (pageContext as any).pageContextResolved
19
+ let page = getPageElement(pageContext, pageContextResolved)
20
+ page = <OnRenderDoneHook>{page}</OnRenderDoneHook>
21
+ const container = document.getElementById('page-view')!
22
+ if (pageContext.isHydration) {
23
+ root = ReactDOM.hydrateRoot(container, page)
24
+ } else {
25
+ if (!root) {
26
+ root = ReactDOM.createRoot(container)
27
+ }
28
+ root.render(page)
29
+ }
30
+ }
31
+
32
+ function onRenderDone() {
33
+ autoScrollNav()
34
+ installSectionUrlHashs()
35
+ initNavigationFullscreen()
36
+ initMobileNavigation()
37
+ initPressKit()
38
+ addFeatureClickHandlers()
39
+ addTwitterWidgets()
40
+ setHydrationIsFinished()
41
+ }
42
+
43
+ function OnRenderDoneHook({ children }: { children: React.ReactNode }) {
44
+ useEffect(onRenderDone)
45
+ return children
46
+ }
47
+
48
+ function setHydrationIsFinished() {
49
+ // Used by:
50
+ // - https://github.com/vikejs/vike/blob/9d67f3dd4bdfb38c835186b8147251e0e3b06657/docs/.testRun.ts#L22
51
+ // - https://github.com/brillout/telefunc/blob/57c942c15b7795cfda96b5106acc9e098aa509aa/docs/.testRun.ts#L26
52
+ ;(window as any).__docpress_hydrationFinished = true
53
+ }
@@ -1,30 +1,21 @@
1
1
  export { onRenderHtml }
2
2
 
3
3
  import ReactDOMServer from 'react-dom/server'
4
- import React from 'react'
5
4
  import { escapeInject, dangerouslySkipEscape } from 'vike/server'
6
- import { PageLayout } from '../PageLayout'
7
- import { resolvePageContext, PageContextOriginal } from '../config/resolvePageContext'
8
- import { getDocSearchJS, getDocSearchCSS } from '../algolia/DocSearch'
9
5
  import { assert } from '../utils/server'
6
+ import type { PageContextServer } from 'vike/types'
7
+ import type { PageContextResolved } from '../config/resolvePageContext'
8
+ import { getPageElement } from './getPageElement'
10
9
 
11
- async function onRenderHtml(pageContextOriginal: PageContextOriginal) {
12
- const { Page } = pageContextOriginal
13
- const pageContextResolved = resolvePageContext(pageContextOriginal)
10
+ async function onRenderHtml(pageContext: PageContextServer) {
11
+ const pageContextResolved: PageContextResolved = (pageContext as any).pageContextResolved
14
12
 
15
- const page = (
16
- <PageLayout pageContext={pageContextResolved}>
17
- <Page />
18
- </PageLayout>
19
- )
13
+ const page = getPageElement(pageContext, pageContextResolved)
20
14
 
21
15
  const descriptionTag = pageContextResolved.isLandingPage
22
16
  ? dangerouslySkipEscape(`<meta name="description" content="${pageContextResolved.meta.tagline}" />`)
23
17
  : ''
24
18
 
25
- const docSearchJS = getDocSearchJS(pageContextResolved)
26
- const docSearchCSS = getDocSearchCSS(pageContextResolved)
27
-
28
19
  const pageHtml = ReactDOMServer.renderToString(page)
29
20
 
30
21
  return escapeInject`<!DOCTYPE html>
@@ -35,16 +26,10 @@ async function onRenderHtml(pageContextOriginal: PageContextOriginal) {
35
26
  <title>${pageContextResolved.documentTitle}</title>
36
27
  ${descriptionTag}
37
28
  <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
38
- ${docSearchCSS}
39
- ${getOpenGraphTags(
40
- pageContextOriginal.urlPathname,
41
- pageContextResolved.documentTitle,
42
- pageContextResolved.meta,
43
- )}
29
+ ${getOpenGraphTags(pageContext.urlPathname, pageContextResolved.documentTitle, pageContextResolved.meta)}
44
30
  </head>
45
31
  <body>
46
32
  <div id="page-view">${dangerouslySkipEscape(pageHtml)}</div>
47
- ${docSearchJS}
48
33
  </body>
49
34
  </html>`
50
35
  }
@@ -3,6 +3,7 @@
3
3
 
4
4
  import React, { useContext } from 'react'
5
5
  import type { PageContextResolved } from '../config/resolvePageContext'
6
+ import type { PageContext } from 'vike/types'
6
7
 
7
8
  export { PageContextProvider }
8
9
  export { usePageContext }
@@ -23,3 +24,22 @@ function usePageContext(): PageContextResolved {
23
24
  const pageContext = useContext(Context)
24
25
  return pageContext
25
26
  }
27
+
28
+ export { PageContextProvider2 }
29
+ // TODO/refactor: rename to usePageContext and remove old implementation
30
+ export { usePageContext2 }
31
+
32
+ const Context2 = React.createContext<PageContext>(undefined as any)
33
+ function usePageContext2(): PageContext {
34
+ const pageContext = useContext(Context2)
35
+ return pageContext
36
+ }
37
+ function PageContextProvider2({
38
+ pageContext,
39
+ children,
40
+ }: {
41
+ pageContext: PageContext
42
+ children: React.ReactNode
43
+ }) {
44
+ return <Context2.Provider value={pageContext}>{children}</Context2.Provider>
45
+ }
package/tsconfig.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "compilerOptions": {
3
3
  "jsx": "react",
4
4
  "module": "ES2020",
5
- "moduleResolution": "Node",
5
+ "moduleResolution": "Bundler",
6
6
  "lib": ["DOM", "DOM.Iterable", "ESNext"],
7
7
  "types": ["vite/client"],
8
8
  "esModuleInterop": true,
package/types/Config.ts CHANGED
@@ -13,28 +13,14 @@ type Config = {
13
13
  twitterProfile: string
14
14
  }
15
15
  faviconUrl: string
16
- algolia:
17
- | null
18
- | ({
19
- PENDING_APPROVAL?: true
20
- } & (
21
- | {
22
- appId?: undefined
23
- apiKey?: undefined
24
- indexName?: undefined
25
- }
26
- | {
27
- appId: string
28
- apiKey: string
29
- indexName: string
30
- }
31
- ))
16
+ algolia: null | {
17
+ appId: string
18
+ apiKey: string
19
+ indexName: string
20
+ }
32
21
  headings: HeadingDefinition[]
33
22
  headingsDetached: HeadingDetachedDefinition[]
34
- navHeaderMobile: React.ReactNode
35
- navHeaderMobileWrapperStyle?: React.CSSProperties
36
- navHeader: React.ReactNode
37
- navHeaderWrapperStyle?: React.CSSProperties
23
+
38
24
  /** Sets `<meta name="description" content="${tagline}" />` */
39
25
  tagline: string
40
26
  websiteUrl: string
package/types/Heading.ts CHANGED
@@ -8,9 +8,9 @@ import type { EmojiName } from '../utils/server'
8
8
  type HeadingResolved = {
9
9
  url?: null | string
10
10
  level: number
11
- title: JSX.Element
12
- titleInNav: JSX.Element
13
- linkBreadcrumb: JSX.Element[]
11
+ title: string
12
+ titleInNav: string
13
+ linkBreadcrumb: string[]
14
14
  sectionTitles?: string[]
15
15
  } & Tmp
16
16
 
@@ -21,7 +21,7 @@ type HeadingDetachedResolved = Omit<HeadingResolved, 'level' | 'linkBreadcrumb'>
21
21
 
22
22
  type HeadingDetachedDefinition = {
23
23
  url: string
24
- title: string | JSX.Element
24
+ title: string
25
25
  sectionTitles?: string[]
26
26
  }
27
27
 
package/vite.config.ts CHANGED
@@ -6,6 +6,7 @@ import { parsePageSections } from './parsePageSections.js'
6
6
  import rehypePrettyCode from 'rehype-pretty-code'
7
7
  import remarkGfm from 'remark-gfm'
8
8
  import { transformerNotationDiff } from '@shikijs/transformers'
9
+ import { cjsInterop } from 'vite-plugin-cjs-interop'
9
10
 
10
11
  const root = process.cwd()
11
12
  const prettyCode = [rehypePrettyCode, { theme: 'github-light', transformers: [transformerNotationDiff()] }]
@@ -25,9 +26,13 @@ const config: UserConfig = {
25
26
  },
26
27
  includeAssetsImportedByServer: true,
27
28
  }),
29
+ cjsInterop({
30
+ dependencies: ['@docsearch/react'],
31
+ }),
28
32
  ],
29
- optimizeDeps: { include: ['@brillout/docpress', 'react-dom'] },
30
- // @ts-ignore
33
+ optimizeDeps: {
34
+ include: ['react-dom/client', '@docsearch/react'],
35
+ },
31
36
  ssr: {
32
37
  noExternal: ['@brillout/docpress'],
33
38
  },
@@ -1,62 +0,0 @@
1
- export { getDocSearchCSS }
2
- export { getDocSearchJS }
3
-
4
- import { dangerouslySkipEscape, escapeInject } from 'vike/server'
5
- import { PageContextResolved } from '../config/resolvePageContext'
6
- /* Imorted in /src/css/index.css instead
7
- import './DocSearch.css'
8
- */
9
-
10
- function getDocSearchCSS(pageContext: PageContextResolved) {
11
- const docSearchCSS = !pageContext.meta.algolia
12
- ? ''
13
- : escapeInject`
14
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@docsearch/css@alpha" />
15
- `
16
- return docSearchCSS
17
- }
18
-
19
- function getDocSearchJS(pageContext: PageContextResolved) {
20
- const { algolia } = pageContext.meta
21
- // If the docpress website doesn't use algolia => we don't inject the algolia assets => the search icon wrapper stays empty
22
- // If algolia is PENDING_APPROVAL => we fill a FAKE API key so that the algolia popup shows (while no results are shown).
23
- // - We show an alert warning users that there aren't any results until algolia's approval is pending (see below).
24
- let docSearchJS = !algolia
25
- ? ''
26
- : escapeInject`
27
- <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@docsearch/js@alpha"></script>
28
- <script type="text/javascript">
29
- const appId = '${algolia.appId || 'FAKE'}';
30
- const apiKey = '${algolia.apiKey || 'FAKE'}';
31
- const indexName = '${algolia.indexName || 'FAKE'}';
32
- const transformItems = ${dangerouslySkipEscape(getTransformItems())};
33
- docsearch({
34
- container: '#docsearch-desktop',
35
- appId, apiKey, indexName, transformItems,
36
- insights: true,
37
- });
38
- </script>
39
- `
40
- if (algolia?.PENDING_APPROVAL) {
41
- docSearchJS = escapeInject`
42
- ${docSearchJS}
43
- <script>document.getElementById('docsearch-desktop').addEventListener('click', () => window.alert("Algolia approval is pending: the search results may be empty until the approval process is completed."))</script>
44
- `
45
- }
46
- return docSearchJS
47
- }
48
-
49
- // Remove superfluous hash '#page-content' from URLs pointing to whole pages
50
- // - https://github.com/algolia/docsearch/issues/1801
51
- // - https://discourse.algolia.com/t/how-to-avoid-hash-in-search-result-url/6486
52
- // - https://discourse.algolia.com/t/docsearchs-transformdata-function-cannot-remove-hashes-from-result-urls/8487
53
- function getTransformItems() {
54
- return `function(hits) {
55
- hits.map(hit => {
56
- if (hit.url.indexOf('#page-content') > 0) {
57
- hit.url = hit.url.replace('#page-content', '');
58
- }
59
- });
60
- return hits;
61
- }`
62
- }
@@ -1,7 +0,0 @@
1
- import { initNavigationFullscreen } from './navigation-fullscreen/initNavigationFullscreen'
2
- import { initMobileNavigation } from './initMobileNavigation'
3
- import { initPressKit } from './initPressKit'
4
-
5
- initNavigationFullscreen()
6
- initMobileNavigation()
7
- initPressKit()
@@ -1,4 +0,0 @@
1
- import '../css/index.css'
2
- import '../autoScrollNav'
3
- import '../installSectionUrlHashs'
4
- import '../navigation/Navigation.client'