@brillout/docpress 0.16.47-commit-cd5aa01 → 0.16.47-commit-e262d2a

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/Layout.tsx CHANGED
@@ -69,7 +69,8 @@ const whitespaceBuster2: React.CSSProperties = {
69
69
 
70
70
  function Layout({ children }: { children: React.ReactNode }) {
71
71
  const pageContext = usePageContext()
72
- const { isLandingPage } = pageContext.resolved
72
+ const { isLandingPage, pageDesign } = pageContext.resolved
73
+ const isTopNavSticky = !isLandingPage && (pageDesign?.topNavSticky ?? true)
73
74
 
74
75
  let content: React.JSX.Element
75
76
  if (isLandingPage) {
@@ -86,6 +87,8 @@ function Layout({ children }: { children: React.ReactNode }) {
86
87
  ['--block-margin']: `${blockMargin}px`,
87
88
  // ['--nav-head-height']: `${isLandingPage ? 70 : 63}px`,
88
89
  ['--nav-head-height']: `63px`,
90
+ // The offset that sticky elements (top nav, <NavLeft>) sit below. Zero when the top nav scrolls away.
91
+ ['--nav-head-sticky-offset']: isTopNavSticky ? 'var(--nav-head-height)' : '0px',
89
92
  ['--main-view-padding']: `${mainViewPadding}px`,
90
93
  // We don't add `container` to `body` nor `html` beacuse in Firefox it breaks the `position: fixed` of <MenuModal>
91
94
  // https://stackoverflow.com/questions/74601420/css-container-inline-size-and-fixed-child
@@ -95,7 +98,7 @@ function Layout({ children }: { children: React.ReactNode }) {
95
98
  }}
96
99
  >
97
100
  <div className={isLandingPage ? 'landing-page' : 'doc-page'} style={whitespaceBuster1}>
98
- <div style={{ position: isLandingPage ? 'relative' : 'sticky', top: 0, zIndex: 100 }}>
101
+ <div style={{ position: isTopNavSticky ? 'sticky' : 'relative', top: 0, zIndex: 100 }}>
99
102
  <NavHead />
100
103
  {/* <MenuModal> is inside here because `container-type` on the page wrapper traps `position: fixed` — https://github.com/brillout/docpress/pull/177 */}
101
104
  <MenuModal isNavLeftAlwaysHidden_={isNavLeftAlwaysHidden_} />
@@ -223,8 +226,8 @@ function NavLeft() {
223
226
  <div
224
227
  style={{
225
228
  position: 'sticky',
226
- // Sit below the sticky top nav
227
- top: 'var(--nav-head-height)',
229
+ // Sit below the sticky top nav (or at the very top when the top nav scrolls away)
230
+ top: 'var(--nav-head-sticky-offset)',
228
231
  }}
229
232
  >
230
233
  <div
@@ -236,7 +239,7 @@ function NavLeft() {
236
239
  id="navigation-container"
237
240
  style={{
238
241
  top: 0,
239
- height: `calc(100vh - var(--nav-head-height) - var(--block-margin))`,
242
+ height: `calc(100vh - var(--nav-head-sticky-offset) - var(--block-margin))`,
240
243
  overflowY: 'auto',
241
244
  overscrollBehavior: 'contain',
242
245
  paddingBottom: 40,
@@ -1,11 +1,8 @@
1
1
  export * from '../utils/Emoji/index.js'
2
2
  export * from './Link.js'
3
3
  export * from './RepoLink.js'
4
- export * from './P.js'
5
4
  export * from './Note.js'
6
5
  export * from './ImportMeta.js'
7
- export * from './HorizontalLine.js'
8
6
  export * from './CodeBlockTransformer.js'
9
- export * from './Comment.js'
10
7
  export * from './FileRemoved.js'
11
8
  export * from '../code-blocks/components/Tabs.js'
package/css/heading.css CHANGED
@@ -13,9 +13,9 @@ h3 {
13
13
  margin-bottom: 20px;
14
14
  }
15
15
 
16
- /* Offset headings below the sticky top nav. */
16
+ /* Offset headings below the sticky top nav (no offset when the top nav scrolls away). */
17
17
  .doc-page :is(h1, h2, h3, h4, h5, h6) {
18
- scroll-margin-top: calc(var(--nav-head-height) + 16px);
18
+ scroll-margin-top: calc(var(--nav-head-sticky-offset) + 16px);
19
19
  }
20
20
 
21
21
  .doc-page h2,
@@ -1,11 +1,8 @@
1
1
  export * from '../utils/Emoji/index.js';
2
2
  export * from './Link.js';
3
3
  export * from './RepoLink.js';
4
- export * from './P.js';
5
4
  export * from './Note.js';
6
5
  export * from './ImportMeta.js';
7
- export * from './HorizontalLine.js';
8
6
  export * from './CodeBlockTransformer.js';
9
- export * from './Comment.js';
10
7
  export * from './FileRemoved.js';
11
8
  export * from '../code-blocks/components/Tabs.js';
@@ -1,11 +1,8 @@
1
1
  export * from '../utils/Emoji/index.js';
2
2
  export * from './Link.js';
3
3
  export * from './RepoLink.js';
4
- export * from './P.js';
5
4
  export * from './Note.js';
6
5
  export * from './ImportMeta.js';
7
- export * from './HorizontalLine.js';
8
6
  export * from './CodeBlockTransformer.js';
9
- export * from './Comment.js';
10
7
  export * from './FileRemoved.js';
11
8
  export * from '../code-blocks/components/Tabs.js';
@@ -1,23 +1,7 @@
1
1
  export { PageContextProvider };
2
2
  export { usePageContext };
3
- export { usePageContextLegacy };
4
3
  import React from 'react';
5
4
  import type { PageContext } from 'vike/types';
6
- declare function usePageContextLegacy(): {
7
- navItemsAll: import("../NavItemComponent.js").NavItem[];
8
- navItemsDetached: import("../NavItemComponent.js").NavItem[] | undefined;
9
- pageDesign: {
10
- hideTitle?: true;
11
- hideMenuLeft?: true;
12
- contentMaxWidth?: number;
13
- } | undefined;
14
- linksAll: import("../components/Link.js").LinkData[];
15
- isLandingPage: boolean;
16
- pageTitle: string | null;
17
- documentTitle: string;
18
- activeCategoryName: string;
19
- choices: import("../code-blocks/utils/resolveChoices.js").ResolvedChoices | undefined;
20
- };
21
5
  declare function usePageContext(): PageContext;
22
6
  declare function PageContextProvider({ pageContext, children, }: {
23
7
  pageContext: PageContext;
@@ -1,16 +1,10 @@
1
1
  export { PageContextProvider };
2
2
  export { usePageContext };
3
- export { usePageContextLegacy };
4
3
  import React, { useContext } from 'react';
5
4
  import { getGlobalObject } from '../utils/getGlobalObject.js';
6
5
  const globalObject = getGlobalObject('usePageContext.ts', {
7
6
  Ctx: React.createContext(undefined),
8
7
  });
9
- function usePageContextLegacy() {
10
- const { Ctx } = globalObject;
11
- const pageContext = useContext(Ctx);
12
- return pageContext.resolved;
13
- }
14
8
  function usePageContext() {
15
9
  const pageContext = useContext(globalObject.Ctx);
16
10
  return pageContext;
@@ -10,6 +10,7 @@ declare function resolvePageContext(pageContext: PageContextServer): {
10
10
  hideTitle?: true;
11
11
  hideMenuLeft?: true;
12
12
  contentMaxWidth?: number;
13
+ topNavSticky?: boolean;
13
14
  } | undefined;
14
15
  linksAll: LinkData[];
15
16
  isLandingPage: boolean;
@@ -24,6 +24,12 @@ type PageDesign = {
24
24
  hideTitle?: true;
25
25
  hideMenuLeft?: true;
26
26
  contentMaxWidth?: number;
27
+ /**
28
+ * Whether the top navigation sticks to the top of the viewport while scrolling.
29
+ *
30
+ * @default true
31
+ */
32
+ topNavSticky?: boolean;
27
33
  };
28
34
  type HeadingDetachedResolved = Omit<HeadingResolved, 'level' | 'linkBreadcrumb'> & {
29
35
  level: 2;
@@ -1,7 +1,5 @@
1
1
  export * from './client.js';
2
2
  export * from './isBrowser.js';
3
- export * from './filter.js';
4
3
  export * from './determineSectionUrlHash.js';
5
4
  export * from './jsxToTextContent.js';
6
- export * from './objectAssign.js';
7
5
  export * from './Emoji/index.js';
@@ -1,7 +1,5 @@
1
1
  export * from './client.js';
2
2
  export * from './isBrowser.js';
3
- export * from './filter.js';
4
3
  export * from './determineSectionUrlHash.js';
5
4
  export * from './jsxToTextContent.js';
6
- export * from './objectAssign.js';
7
5
  export * from './Emoji/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/docpress",
3
- "version": "0.16.47-commit-cd5aa01",
3
+ "version": "0.16.47-commit-e262d2a",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@brillout/picocolors": "^1.0.10",
@@ -1,6 +1,5 @@
1
1
  export { PageContextProvider }
2
2
  export { usePageContext }
3
- export { usePageContextLegacy }
4
3
 
5
4
  import React, { useContext } from 'react'
6
5
  import type { PageContext } from 'vike/types'
@@ -10,12 +9,6 @@ const globalObject = getGlobalObject('usePageContext.ts', {
10
9
  Ctx: React.createContext<PageContext>(undefined as any),
11
10
  })
12
11
 
13
- function usePageContextLegacy() {
14
- const { Ctx } = globalObject
15
- const pageContext = useContext(Ctx)
16
- return pageContext.resolved
17
- }
18
-
19
12
  function usePageContext(): PageContext {
20
13
  const pageContext = useContext(globalObject.Ctx)
21
14
  return pageContext
package/types/Heading.ts CHANGED
@@ -28,6 +28,12 @@ type PageDesign = {
28
28
  hideTitle?: true
29
29
  hideMenuLeft?: true
30
30
  contentMaxWidth?: number
31
+ /**
32
+ * Whether the top navigation sticks to the top of the viewport while scrolling.
33
+ *
34
+ * @default true
35
+ */
36
+ topNavSticky?: boolean
31
37
  }
32
38
 
33
39
  type HeadingDetachedResolved = Omit<HeadingResolved, 'level' | 'linkBreadcrumb'> & {
package/utils/server.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  export * from './client.js'
2
2
  export * from './isBrowser.js'
3
- export * from './filter.js'
4
3
  export * from './determineSectionUrlHash.js'
5
4
  export * from './jsxToTextContent.js'
6
- export * from './objectAssign.js'
7
5
  export * from './Emoji/index.js'
@@ -1,7 +0,0 @@
1
- export { Comment }
2
-
3
- import React from 'react'
4
-
5
- function Comment() {
6
- return <></>
7
- }
@@ -1,22 +0,0 @@
1
- export { HorizontalLine }
2
-
3
- import React from 'react'
4
- import { cls } from '../utils/cls.js'
5
-
6
- function HorizontalLine({ primary }: { primary?: true }) {
7
- return (
8
- <div className={cls(primary && 'primary')} style={{ textAlign: 'center' }}>
9
- <hr
10
- style={{
11
- display: 'inline-block',
12
- margin: 0,
13
- border: 0,
14
- // Same as `.doc-page h2::after`
15
- borderTop: '1px solid var(--color-border, rgba(0, 0, 0, 0.1))',
16
- maxWidth: 500,
17
- width: '80%',
18
- }}
19
- />
20
- </div>
21
- )
22
- }
package/components/P.css DELETED
@@ -1,8 +0,0 @@
1
- /* Copied from Chrome's user agent stylesheet */
2
- div.paragraph {
3
- display: block;
4
- margin-block-start: 1em;
5
- margin-block-end: 1em;
6
- margin-inline-start: 0px;
7
- margin-inline-end: 0px;
8
- }
package/components/P.tsx DELETED
@@ -1,8 +0,0 @@
1
- import React from 'react'
2
- import './P.css'
3
-
4
- export { P }
5
-
6
- function P(props: React.HTMLProps<HTMLDivElement>) {
7
- return <div {...props} className={'paragraph'} />
8
- }
@@ -1,3 +0,0 @@
1
- export { Comment };
2
- import React from 'react';
3
- declare function Comment(): React.JSX.Element;
@@ -1,5 +0,0 @@
1
- export { Comment };
2
- import React from 'react';
3
- function Comment() {
4
- return React.createElement(React.Fragment, null);
5
- }
@@ -1,5 +0,0 @@
1
- export { HorizontalLine };
2
- import React from 'react';
3
- declare function HorizontalLine({ primary }: {
4
- primary?: true;
5
- }): React.JSX.Element;
@@ -1,15 +0,0 @@
1
- export { HorizontalLine };
2
- import React from 'react';
3
- import { cls } from '../utils/cls.js';
4
- function HorizontalLine({ primary }) {
5
- return (React.createElement("div", { className: cls(primary && 'primary'), style: { textAlign: 'center' } },
6
- React.createElement("hr", { style: {
7
- display: 'inline-block',
8
- margin: 0,
9
- border: 0,
10
- // Same as `.doc-page h2::after`
11
- borderTop: '1px solid var(--color-border, rgba(0, 0, 0, 0.1))',
12
- maxWidth: 500,
13
- width: '80%',
14
- } })));
15
- }
@@ -1,4 +0,0 @@
1
- import React from 'react';
2
- import './P.css';
3
- export { P };
4
- declare function P(props: React.HTMLProps<HTMLDivElement>): React.JSX.Element;
@@ -1,6 +0,0 @@
1
- import React from 'react';
2
- import './P.css';
3
- export { P };
4
- function P(props) {
5
- return React.createElement("div", { ...props, className: 'paragraph' });
6
- }
@@ -1,3 +0,0 @@
1
- export { cls };
2
- type Class = string | boolean | undefined;
3
- declare function cls(className: Class | Class[]): string;
package/dist/utils/cls.js DELETED
@@ -1,5 +0,0 @@
1
- export { cls };
2
- function cls(className) {
3
- const classNames = Array.isArray(className) ? className : [className];
4
- return classNames.filter(Boolean).join(' ');
5
- }
@@ -1,2 +0,0 @@
1
- export { filter };
2
- declare function filter<T extends object>(obj: T, predicate: <K extends keyof T>(value: T[K], key: K) => boolean): T;
@@ -1,11 +0,0 @@
1
- export { filter };
2
- // https://stackoverflow.com/questions/66341757/typescript-how-to-filter-the-object
3
- function filter(obj, predicate) {
4
- const result = {};
5
- Object.keys(obj).forEach((name) => {
6
- if (predicate(obj[name], name)) {
7
- result[name] = obj[name];
8
- }
9
- });
10
- return result;
11
- }
@@ -1,2 +0,0 @@
1
- export { objectAssign };
2
- declare function objectAssign<Obj extends Object, ObjAddendum>(obj: Obj, objAddendum: ObjAddendum): asserts obj is Obj & ObjAddendum;
@@ -1,5 +0,0 @@
1
- export { objectAssign };
2
- // Same as `Object.assign()` but with type inference
3
- function objectAssign(obj, objAddendum) {
4
- Object.assign(obj, objAddendum);
5
- }
@@ -1,7 +0,0 @@
1
- export { PassThrough }
2
-
3
- import React from 'react'
4
-
5
- function PassThrough({ children }: any) {
6
- return <>{children}</>
7
- }
@@ -1,42 +0,0 @@
1
- export { toPosixPath }
2
- export { assertPosixPath }
3
- export { toSystemPath }
4
-
5
- import assert from 'assert'
6
-
7
- const sepPosix = '/'
8
- const sepWin32 = '\\'
9
-
10
- function toPosixPath(path: string) {
11
- if (isPosix()) {
12
- assertPosixPath(path)
13
- return path
14
- }
15
- if (isWin32()) {
16
- const pathPosix = path.split(sepWin32).join(sepPosix)
17
- assertPosixPath(pathPosix)
18
- return pathPosix
19
- }
20
- assert(false)
21
- }
22
-
23
- function assertPosixPath(path: string) {
24
- assert(path && !path.includes(sepWin32), `Wrongly formatted path: ${path}`)
25
- }
26
-
27
- function toSystemPath(path: string) {
28
- if (isPosix()) {
29
- return toPosixPath(path)
30
- }
31
- if (isWin32()) {
32
- return path.split(sepPosix).join(sepWin32)
33
- }
34
- assert(false)
35
- }
36
-
37
- function isWin32() {
38
- return process.platform === 'win32'
39
- }
40
- function isPosix() {
41
- return !isWin32()
42
- }
package/utils/filter.ts DELETED
@@ -1,12 +0,0 @@
1
- export { filter }
2
-
3
- // https://stackoverflow.com/questions/66341757/typescript-how-to-filter-the-object
4
- function filter<T extends object>(obj: T, predicate: <K extends keyof T>(value: T[K], key: K) => boolean): T {
5
- const result: { [K in keyof T]?: T[K] } = {}
6
- ;(Object.keys(obj) as Array<keyof T>).forEach((name) => {
7
- if (predicate(obj[name], name)) {
8
- result[name] = obj[name]
9
- }
10
- })
11
- return result as T
12
- }
@@ -1,9 +0,0 @@
1
- export { objectAssign }
2
-
3
- // Same as `Object.assign()` but with type inference
4
- function objectAssign<Obj extends Object, ObjAddendum>(
5
- obj: Obj,
6
- objAddendum: ObjAddendum,
7
- ): asserts obj is Obj & ObjAddendum {
8
- Object.assign(obj, objAddendum)
9
- }