@brillout/docpress 0.15.8 → 0.15.10-commit-ef0b9a0
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/NavItemComponent.tsx +11 -0
- package/components/CodeSnippets.tsx +68 -0
- package/components/index.ts +1 -0
- package/detypePlugin.ts +68 -0
- package/dist/+config.js +1 -1
- package/dist/NavItemComponent.d.ts +0 -1
- package/dist/NavItemComponent.js +38 -47
- package/dist/components/CodeBlockTransformer.js +2 -3
- package/dist/components/CodeSnippets.d.ts +13 -0
- package/dist/components/CodeSnippets.js +39 -0
- package/dist/components/Comment.js +1 -2
- package/dist/components/FileRemoved.js +4 -6
- package/dist/components/HorizontalLine.js +1 -2
- package/dist/components/ImportMeta.js +2 -3
- package/dist/components/Link.js +34 -50
- package/dist/components/Note.js +17 -29
- package/dist/components/P.js +1 -12
- package/dist/components/RepoLink.js +7 -9
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/determineNavItemsColumnLayout.js +48 -62
- package/dist/detypePlugin.d.ts +3 -0
- package/dist/detypePlugin.js +53 -0
- package/dist/parseMarkdownMini.js +5 -17
- package/dist/parsePageSections.js +41 -82
- package/dist/renderer/usePageContext.js +6 -7
- package/dist/resolvePageContext.js +91 -103
- package/dist/utils/Emoji/Emoji.js +13 -21
- package/dist/utils/assert.js +14 -16
- package/dist/utils/cls.js +1 -1
- package/dist/utils/determineSectionUrlHash.js +5 -5
- package/dist/utils/filter.js +2 -2
- package/dist/utils/getGlobalObject.js +3 -3
- package/dist/utils/useSelectedLanguage.d.ts +7 -0
- package/dist/utils/useSelectedLanguage.js +48 -0
- package/dist/vite.config.js +9 -7
- package/global.d.ts +3 -1
- package/index.ts +3 -0
- package/package.json +2 -1
- package/tsconfig.config.json +1 -1
- package/tsconfig.json +1 -0
- package/utils/useSelectedLanguage.ts +61 -0
- package/vite.config.ts +2 -0
package/NavItemComponent.tsx
CHANGED
|
@@ -8,7 +8,18 @@ import React from 'react'
|
|
|
8
8
|
import { assert, assertWarning, jsxToTextContent } from './utils/server'
|
|
9
9
|
import './NavItemComponent.css'
|
|
10
10
|
import { parseMarkdownMini } from './parseMarkdownMini'
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
// We cannot do that: we must use `import type` otherwise Vite will transpile global.d.ts and throw:
|
|
14
|
+
// ```console
|
|
15
|
+
// [11:55:47.528][/docs/.test-dev.test.ts][pnpm run dev][stderr] 11:55:47 AM [vite] Failed to transpile /home/runner/work/telefunc/telefunc/node_modules/.pnpm/@brillout+docpress@0.15.7_@algolia+client-search@5.31.0_@types+react@19.1.8_@vitejs+plugin-re_lcm3fspejcg3ebrmr3gvb5i3se/node_modules/@brillout/docpress/global.d.ts because:
|
|
16
|
+
// x `declare` modifier not allowed for code already in an ambient context
|
|
17
|
+
// ```
|
|
11
18
|
import './global.d.ts'
|
|
19
|
+
/*/
|
|
20
|
+
// The only purpose of `FakeExport` is to be able to use `import type`
|
|
21
|
+
import type { FakeExport } from './global.d.ts'
|
|
22
|
+
//*/
|
|
12
23
|
|
|
13
24
|
type NavItemComputed = ReturnType<typeof getNavItemsWithComputed>[number]
|
|
14
25
|
type NavItem = {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export { CodeSnippets, CodeSnippet, TypescriptOnly }
|
|
2
|
+
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { useSelectedLanguage } from '../utils/useSelectedLanguage'
|
|
5
|
+
|
|
6
|
+
function CodeSnippets({ children }: { children: React.ReactNode }) {
|
|
7
|
+
const [selectedLang, setSelectedLang] = useSelectedLanguage()
|
|
8
|
+
|
|
9
|
+
const handleOnChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
|
10
|
+
setSelectedLang(e.target.value)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<div>
|
|
15
|
+
<form style={{ position: 'relative' }}>
|
|
16
|
+
<select
|
|
17
|
+
name="language"
|
|
18
|
+
id="language"
|
|
19
|
+
onChange={handleOnChange}
|
|
20
|
+
value={selectedLang}
|
|
21
|
+
style={{ position: 'absolute', top: '10px', right: '60px', zIndex: 3 }}
|
|
22
|
+
>
|
|
23
|
+
<option value="js">Javascript</option>
|
|
24
|
+
<option value="ts">Typescript</option>
|
|
25
|
+
</select>
|
|
26
|
+
</form>
|
|
27
|
+
{children}
|
|
28
|
+
</div>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function CodeSnippet({
|
|
33
|
+
children,
|
|
34
|
+
language,
|
|
35
|
+
tsOnly = false,
|
|
36
|
+
}: { children: React.ReactNode; language: string; tsOnly: boolean }) {
|
|
37
|
+
const [selectedLang] = useSelectedLanguage()
|
|
38
|
+
|
|
39
|
+
const style = tsOnly ? {} : { display: selectedLang === language ? 'block' : 'none' }
|
|
40
|
+
|
|
41
|
+
const copyToClipboard = async (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
42
|
+
try {
|
|
43
|
+
const figureEl = e.currentTarget.nextElementSibling
|
|
44
|
+
if (figureEl?.tagName === 'FIGURE') {
|
|
45
|
+
await navigator.clipboard.writeText(figureEl.textContent ?? '')
|
|
46
|
+
console.log('Copied to clipboard!')
|
|
47
|
+
}
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.warn('Copy failed', error)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<div style={{ ...style, position: 'relative' }}>
|
|
55
|
+
<button type="button" style={{ position: 'absolute', top: '10px', right: '10px' }} onClick={copyToClipboard}>
|
|
56
|
+
Copy
|
|
57
|
+
</button>
|
|
58
|
+
{children}
|
|
59
|
+
</div>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Show/hide TypeScript sections (code and/or plain)
|
|
64
|
+
function TypescriptOnly({ children }: { children: React.ReactNode }) {
|
|
65
|
+
const [selectedLang] = useSelectedLanguage()
|
|
66
|
+
|
|
67
|
+
return <div style={{ display: selectedLang === 'ts' ? 'block' : 'none' }}>{children}</div>
|
|
68
|
+
}
|
package/components/index.ts
CHANGED
package/detypePlugin.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export { detypePlugin }
|
|
2
|
+
|
|
3
|
+
import type { PluginOption } from 'vite'
|
|
4
|
+
import module from 'node:module'
|
|
5
|
+
|
|
6
|
+
// Cannot use `import { transform } from 'detype'` as it results in errors,
|
|
7
|
+
// and the package has no default export. Using `module.createRequire` instead.
|
|
8
|
+
const { transform } = module.createRequire(import.meta.url)('detype') as typeof import('detype')
|
|
9
|
+
|
|
10
|
+
function detypePlugin(): PluginOption {
|
|
11
|
+
return {
|
|
12
|
+
name: '@brillout/docpress:detypePlugin',
|
|
13
|
+
enforce: 'pre',
|
|
14
|
+
transform: async (code: string, id: string) => {
|
|
15
|
+
if (!id.endsWith('+Page.mdx')) {
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
const codeNew = await transformCode(code)
|
|
19
|
+
return codeNew
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const tsBlockRegex = /```(tsx?|vue)(\s+ts-only)?([\s\S]*?)```/g
|
|
25
|
+
|
|
26
|
+
async function transformCode(code: string) {
|
|
27
|
+
let codeNew = `import { CodeSnippets, CodeSnippet } from '@brillout/docpress';\n`
|
|
28
|
+
let lastIndex = 0
|
|
29
|
+
|
|
30
|
+
const matches = [...code.matchAll(tsBlockRegex)]
|
|
31
|
+
|
|
32
|
+
if (matches.length === 0) {
|
|
33
|
+
return code
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
for (const match of matches) {
|
|
37
|
+
const [tsCodeBlock, lang, tsOnly, tsCode] = match // lang = ts | tsx | vue
|
|
38
|
+
const type = lang === 'vue' ? 'vue' : lang.replace('t', 'j') // ts => js | tsx => jsx
|
|
39
|
+
|
|
40
|
+
const blockStart = match.index
|
|
41
|
+
const blockEnd = blockStart + tsCodeBlock.length
|
|
42
|
+
|
|
43
|
+
codeNew += code.slice(lastIndex, blockStart)
|
|
44
|
+
|
|
45
|
+
if (tsOnly) {
|
|
46
|
+
codeNew += `\n<CodeSnippet language={'ts'} tsOnly={'true'}>\n${tsCodeBlock}\n</CodeSnippet>\n`
|
|
47
|
+
} else {
|
|
48
|
+
const jsCode = await transform(tsCode.trim().replaceAll('.ts', '.js'), `tsCode.${lang}`, {
|
|
49
|
+
removeTsComments: true,
|
|
50
|
+
prettierOptions: {
|
|
51
|
+
semi: false,
|
|
52
|
+
singleQuote: true,
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const jsCodeBlock = `\`\`\`${type}\n${jsCode}\`\`\``
|
|
57
|
+
const jsCodeSnippet = `\n<CodeSnippet language={'js'}>\n${jsCodeBlock}\n</CodeSnippet>\n`
|
|
58
|
+
const tsCodeSnippet = `\n<CodeSnippet language={'ts'}>\n${tsCodeBlock}\n</CodeSnippet>\n`
|
|
59
|
+
|
|
60
|
+
codeNew += `<CodeSnippets>${jsCodeSnippet}${tsCodeSnippet}</CodeSnippets>`
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
lastIndex = blockEnd
|
|
64
|
+
}
|
|
65
|
+
codeNew += code.slice(lastIndex)
|
|
66
|
+
|
|
67
|
+
return codeNew
|
|
68
|
+
}
|
package/dist/+config.js
CHANGED
package/dist/NavItemComponent.js
CHANGED
|
@@ -1,54 +1,39 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
export { NavItemComponent };
|
|
13
2
|
export { getNavItemsWithComputed };
|
|
14
3
|
import React from 'react';
|
|
15
4
|
import { assert, assertWarning, jsxToTextContent } from './utils/server';
|
|
16
5
|
import './NavItemComponent.css';
|
|
17
6
|
import { parseMarkdownMini } from './parseMarkdownMini';
|
|
18
|
-
|
|
19
|
-
function NavItemComponent(_a) {
|
|
20
|
-
var _b;
|
|
21
|
-
var _c;
|
|
22
|
-
var navItem = _a.navItem, onClick = _a.onClick;
|
|
7
|
+
function NavItemComponent({ navItem, onClick, }) {
|
|
23
8
|
assert([1, 2, 3, 4].includes(navItem.level), navItem);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
9
|
+
const titleJsx = parseMarkdownMini(navItem.title);
|
|
10
|
+
const titleInNavJsx = parseMarkdownMini(navItem.titleInNav);
|
|
11
|
+
const iconSize = 25;
|
|
12
|
+
const icon = navItem.titleIcon && (React.createElement("img", { src: navItem.titleIcon, style: { height: iconSize, width: iconSize, marginRight: 8, marginLeft: 4, ...navItem.titleIconStyle } }));
|
|
28
13
|
if (navItem.level === 1 || navItem.level === 4) {
|
|
29
14
|
assert(navItem.url === undefined);
|
|
30
15
|
}
|
|
31
16
|
else {
|
|
32
|
-
|
|
17
|
+
const sectionTitle = jsxToTextContent(titleJsx);
|
|
33
18
|
assertWarning(navItem.url, [
|
|
34
|
-
|
|
35
|
-
|
|
19
|
+
`${jsxToTextContent(titleInNavJsx)} is missing a URL hash.`,
|
|
20
|
+
`Add a URL hash with: \`## ${sectionTitle}{#some-hash}\`.`,
|
|
36
21
|
/* TO-DO/eventually: not implemented yet.
|
|
37
22
|
`Use \`<h2 id="url-hash">${sectionTitle}</h2>\` instead of \`## ${sectionTitle}\`.`,
|
|
38
23
|
*/
|
|
39
24
|
].join(' '));
|
|
40
25
|
}
|
|
41
|
-
|
|
26
|
+
let children = titleInNavJsx;
|
|
42
27
|
if (navItem.level === 1) {
|
|
43
28
|
children = (React.createElement(React.Fragment, null,
|
|
44
29
|
icon,
|
|
45
30
|
children,
|
|
46
31
|
React.createElement(Chevron, { className: "collapsible-icon", height: 9 })));
|
|
47
32
|
}
|
|
48
|
-
|
|
49
|
-
href:
|
|
50
|
-
children
|
|
51
|
-
onClick
|
|
33
|
+
const props = {
|
|
34
|
+
href: navItem.url ?? undefined,
|
|
35
|
+
children,
|
|
36
|
+
onClick,
|
|
52
37
|
className: [
|
|
53
38
|
'nav-item',
|
|
54
39
|
'nav-item-level-' + navItem.level,
|
|
@@ -60,45 +45,51 @@ function NavItemComponent(_a) {
|
|
|
60
45
|
.join(' '),
|
|
61
46
|
};
|
|
62
47
|
if (navItem.level === 1) {
|
|
63
|
-
props.style =
|
|
64
|
-
|
|
65
|
-
|
|
48
|
+
props.style = {
|
|
49
|
+
['--category-color']: navItem.color,
|
|
50
|
+
};
|
|
66
51
|
}
|
|
67
52
|
if (navItem.level === 2 || navItem.level === 3) {
|
|
68
|
-
return React.createElement("a",
|
|
53
|
+
return React.createElement("a", { ...props });
|
|
69
54
|
}
|
|
70
55
|
else {
|
|
71
|
-
return React.createElement("span",
|
|
56
|
+
return React.createElement("span", { ...props });
|
|
72
57
|
}
|
|
73
58
|
}
|
|
74
59
|
function getNavItemsWithComputed(navItems, currentUrl) {
|
|
75
|
-
|
|
76
|
-
|
|
60
|
+
let navItemIdx;
|
|
61
|
+
const navItemsWithComputed = navItems.map((navItem, i) => {
|
|
77
62
|
assert([1, 2, 3, 4].includes(navItem.level), navItem);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
63
|
+
const navItemPrevious = navItems[i - 1];
|
|
64
|
+
const navItemNext = navItems[i + 1];
|
|
65
|
+
let isActive = false;
|
|
81
66
|
if (navItem.url === currentUrl) {
|
|
82
|
-
assert(navItem.level === 2, { currentUrl
|
|
67
|
+
assert(navItem.level === 2, { currentUrl });
|
|
83
68
|
assert(navItemIdx === undefined);
|
|
84
69
|
navItemIdx = i;
|
|
85
70
|
isActive = true;
|
|
86
71
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
72
|
+
const isFirstOfItsKind = navItem.level !== navItemPrevious?.level;
|
|
73
|
+
const isLastOfItsKind = navItem.level !== navItemNext?.level;
|
|
74
|
+
const navItemComputed = {
|
|
75
|
+
...navItem,
|
|
76
|
+
isActive,
|
|
77
|
+
isRelevant: false,
|
|
78
|
+
isFirstOfItsKind,
|
|
79
|
+
isLastOfItsKind,
|
|
80
|
+
};
|
|
90
81
|
return navItemComputed;
|
|
91
82
|
});
|
|
92
83
|
// Set `isRelevant`
|
|
93
84
|
if (navItemIdx !== undefined) {
|
|
94
|
-
for (
|
|
95
|
-
|
|
85
|
+
for (let i = navItemIdx; i >= 0; i--) {
|
|
86
|
+
const navItem = navItemsWithComputed[i];
|
|
96
87
|
navItem.isRelevant = true;
|
|
97
88
|
if (navItem.level === 1)
|
|
98
89
|
break;
|
|
99
90
|
}
|
|
100
|
-
for (
|
|
101
|
-
|
|
91
|
+
for (let i = navItemIdx; i < navItemsWithComputed.length; i++) {
|
|
92
|
+
const navItem = navItemsWithComputed[i];
|
|
102
93
|
if (navItem.level === 1)
|
|
103
94
|
break;
|
|
104
95
|
navItem.isRelevant = true;
|
|
@@ -107,6 +98,6 @@ function getNavItemsWithComputed(navItems, currentUrl) {
|
|
|
107
98
|
return navItemsWithComputed;
|
|
108
99
|
}
|
|
109
100
|
function Chevron(props) {
|
|
110
|
-
return (React.createElement("svg",
|
|
101
|
+
return (React.createElement("svg", { viewBox: "0 0 512 292.52", xmlns: "http://www.w3.org/2000/svg", ...props },
|
|
111
102
|
React.createElement("path", { fill: "#aaa", d: "M10.725 82.42L230.125 261.82c6.8 6.8 16.2 10.7 25.9 10.7s19.1-3.9 25.9-10.7l219.4-179.4c14.3-14.3 14.3-37.4 0-51.7s-37.4-14.3-51.7 0l-193.6 153.6-193.6-153.6c-14.3-14.3-37.4-14.3-51.7 0s-14.3 37.5 0 51.7z" })));
|
|
112
103
|
}
|
|
@@ -2,9 +2,8 @@ export { CodeBlockTransformer };
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { assert } from '../utils/server';
|
|
4
4
|
import './CodeBlockTransformer.css';
|
|
5
|
-
function CodeBlockTransformer(
|
|
6
|
-
var children = _a.children, lineBreak = _a.lineBreak;
|
|
5
|
+
function CodeBlockTransformer({ children, lineBreak }) {
|
|
7
6
|
assert(lineBreak === 'white-space' || lineBreak === 'break-word', '`lineBreak` is currently the only use case for <CodeBlockTransformer>');
|
|
8
|
-
|
|
7
|
+
const className = `with-line-break_${lineBreak}`;
|
|
9
8
|
return React.createElement("div", { className: className }, children);
|
|
10
9
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { CodeSnippets, CodeSnippet, TypescriptOnly };
|
|
2
|
+
import React from 'react';
|
|
3
|
+
declare function CodeSnippets({ children }: {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
}): React.JSX.Element;
|
|
6
|
+
declare function CodeSnippet({ children, language, tsOnly, }: {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
language: string;
|
|
9
|
+
tsOnly: boolean;
|
|
10
|
+
}): React.JSX.Element;
|
|
11
|
+
declare function TypescriptOnly({ children }: {
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export { CodeSnippets, CodeSnippet, TypescriptOnly };
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useSelectedLanguage } from '../utils/useSelectedLanguage';
|
|
4
|
+
function CodeSnippets({ children }) {
|
|
5
|
+
const [selectedLang, setSelectedLang] = useSelectedLanguage();
|
|
6
|
+
const handleOnChange = (e) => {
|
|
7
|
+
setSelectedLang(e.target.value);
|
|
8
|
+
};
|
|
9
|
+
return (React.createElement("div", null,
|
|
10
|
+
React.createElement("form", { style: { position: 'relative' } },
|
|
11
|
+
React.createElement("select", { name: "language", id: "language", onChange: handleOnChange, value: selectedLang, style: { position: 'absolute', top: '10px', right: '60px', zIndex: 3 } },
|
|
12
|
+
React.createElement("option", { value: "js" }, "Javascript"),
|
|
13
|
+
React.createElement("option", { value: "ts" }, "Typescript"))),
|
|
14
|
+
children));
|
|
15
|
+
}
|
|
16
|
+
function CodeSnippet({ children, language, tsOnly = false, }) {
|
|
17
|
+
const [selectedLang] = useSelectedLanguage();
|
|
18
|
+
const style = tsOnly ? {} : { display: selectedLang === language ? 'block' : 'none' };
|
|
19
|
+
const copyToClipboard = async (e) => {
|
|
20
|
+
try {
|
|
21
|
+
const figureEl = e.currentTarget.nextElementSibling;
|
|
22
|
+
if (figureEl?.tagName === 'FIGURE') {
|
|
23
|
+
await navigator.clipboard.writeText(figureEl.textContent ?? '');
|
|
24
|
+
console.log('Copied to clipboard!');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
console.warn('Copy failed', error);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return (React.createElement("div", { style: { ...style, position: 'relative' } },
|
|
32
|
+
React.createElement("button", { type: "button", style: { position: 'absolute', top: '10px', right: '10px' }, onClick: copyToClipboard }, "Copy"),
|
|
33
|
+
children));
|
|
34
|
+
}
|
|
35
|
+
// Show/hide TypeScript sections (code and/or plain)
|
|
36
|
+
function TypescriptOnly({ children }) {
|
|
37
|
+
const [selectedLang] = useSelectedLanguage();
|
|
38
|
+
return React.createElement("div", { style: { display: selectedLang === 'ts' ? 'block' : 'none' } }, children);
|
|
39
|
+
}
|
|
@@ -2,25 +2,23 @@ export { FileRemoved };
|
|
|
2
2
|
export { FileAdded };
|
|
3
3
|
import React from 'react';
|
|
4
4
|
// Styling defined in src/css/code/diff.css
|
|
5
|
-
|
|
5
|
+
const classRemoved = [
|
|
6
6
|
//
|
|
7
7
|
'diff-entire-file',
|
|
8
8
|
'diff-entire-file-removed',
|
|
9
9
|
].join(' ');
|
|
10
|
-
|
|
10
|
+
const classAdded = [
|
|
11
11
|
//
|
|
12
12
|
'diff-entire-file',
|
|
13
13
|
'diff-entire-file-added',
|
|
14
14
|
].join(' ');
|
|
15
|
-
function FileRemoved(
|
|
16
|
-
var children = _a.children;
|
|
15
|
+
function FileRemoved({ children }) {
|
|
17
16
|
return React.createElement("div", { className: classRemoved },
|
|
18
17
|
" ",
|
|
19
18
|
children,
|
|
20
19
|
" ");
|
|
21
20
|
}
|
|
22
|
-
function FileAdded(
|
|
23
|
-
var children = _a.children;
|
|
21
|
+
function FileAdded({ children }) {
|
|
24
22
|
return React.createElement("div", { className: classAdded },
|
|
25
23
|
" ",
|
|
26
24
|
children,
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export { HorizontalLine };
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { cls } from '../utils/cls';
|
|
4
|
-
function HorizontalLine(
|
|
5
|
-
var primary = _a.primary;
|
|
4
|
+
function HorizontalLine({ primary }) {
|
|
6
5
|
return (React.createElement("div", { className: cls(primary && 'primary'), style: { textAlign: 'center' } },
|
|
7
6
|
React.createElement("hr", { style: {
|
|
8
7
|
display: 'inline-block',
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { assert } from '../utils/server';
|
|
3
3
|
export { ImportMeta };
|
|
4
|
-
function ImportMeta(
|
|
5
|
-
var prop = _a.prop;
|
|
4
|
+
function ImportMeta({ prop }) {
|
|
6
5
|
assert(!prop.startsWith('import'));
|
|
7
6
|
assert(!prop.startsWith('.'));
|
|
8
|
-
|
|
7
|
+
const text = 'imp' + 'ort.meta.' + prop;
|
|
9
8
|
return React.createElement("code", null, text);
|
|
10
9
|
}
|
package/dist/components/Link.js
CHANGED
|
@@ -1,31 +1,22 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
export { Link };
|
|
13
2
|
import React from 'react';
|
|
14
3
|
import { usePageContext } from '../renderer/usePageContext';
|
|
15
4
|
import { assert, assertUsage, assertWarning, determineSectionTitle, determineSectionUrlHash } from '../utils/server';
|
|
16
5
|
import { parseMarkdownMini } from '../parseMarkdownMini';
|
|
17
6
|
import pc from '@brillout/picocolors';
|
|
18
|
-
function Link(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
assertUsage(href.startsWith('/') || href.startsWith('#'), "<Link href /> prop `href==='".concat(href, "'` but should start with '/' or '#'"));
|
|
7
|
+
function Link({ href, text, noBreadcrumb, doNotInferSectionTitle, noWarning, children, }) {
|
|
8
|
+
const pageContext = usePageContext();
|
|
9
|
+
assertUsage(href.startsWith('/') || href.startsWith('#'), `<Link href /> prop \`href==='${href}'\` but should start with '/' or '#'`);
|
|
22
10
|
assertUsage(!text || !children, 'Cannot use both `text` or `children`');
|
|
23
11
|
// assertWarning(!text, 'prop `text` is deprecated')
|
|
24
|
-
text = text
|
|
25
|
-
|
|
12
|
+
text = text ?? children;
|
|
13
|
+
const linkTextData = getLinkTextData({ href, pageContext, doNotInferSectionTitle, noWarning });
|
|
26
14
|
if (!text) {
|
|
27
15
|
if (linkTextData) {
|
|
28
|
-
text = getLinkText(
|
|
16
|
+
text = getLinkText({
|
|
17
|
+
noBreadcrumb,
|
|
18
|
+
...linkTextData,
|
|
19
|
+
});
|
|
29
20
|
}
|
|
30
21
|
else {
|
|
31
22
|
text = 'LINK-TARGET-NOT-FOUND';
|
|
@@ -33,12 +24,10 @@ function Link(_a) {
|
|
|
33
24
|
}
|
|
34
25
|
return React.createElement("a", { href: href }, text);
|
|
35
26
|
}
|
|
36
|
-
function getLinkText(
|
|
37
|
-
|
|
38
|
-
var noBreadcrumb = _a.noBreadcrumb, linkData = _a.linkData, sectionTitle = _a.sectionTitle, isLinkOnSamePage = _a.isLinkOnSamePage;
|
|
39
|
-
var breadcrumbParts = [];
|
|
27
|
+
function getLinkText({ noBreadcrumb, linkData, sectionTitle, isLinkOnSamePage, }) {
|
|
28
|
+
const breadcrumbParts = [];
|
|
40
29
|
if (linkData.linkBreadcrumb) {
|
|
41
|
-
breadcrumbParts.push
|
|
30
|
+
breadcrumbParts.push(...(linkData.linkBreadcrumb ?? []).slice().reverse().map(parseMarkdownMini));
|
|
42
31
|
}
|
|
43
32
|
breadcrumbParts.push(parseMarkdownMini(linkData.title));
|
|
44
33
|
if (sectionTitle)
|
|
@@ -46,33 +35,32 @@ function getLinkText(_a) {
|
|
|
46
35
|
if (noBreadcrumb || isLinkOnSamePage) {
|
|
47
36
|
return breadcrumbParts[breadcrumbParts.length - 1];
|
|
48
37
|
}
|
|
49
|
-
return (React.createElement(React.Fragment, null, breadcrumbParts.map(
|
|
50
|
-
|
|
38
|
+
return (React.createElement(React.Fragment, null, breadcrumbParts.map((title, i) => {
|
|
39
|
+
const seperator = i === 0 ? React.createElement(React.Fragment, null) : ' > ';
|
|
51
40
|
return (React.createElement(React.Fragment, { key: i },
|
|
52
41
|
seperator,
|
|
53
42
|
title));
|
|
54
43
|
})));
|
|
55
44
|
}
|
|
56
|
-
function getLinkTextData(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
var linkData = findLinkData(hrefPathname || pageContext.urlPathname, { pageContext: pageContext, noWarning: noWarning });
|
|
45
|
+
function getLinkTextData({ href, pageContext, doNotInferSectionTitle, noWarning, }) {
|
|
46
|
+
const { hrefPathname, hrefHash } = parseHref(href);
|
|
47
|
+
const linkData = findLinkData(hrefPathname || pageContext.urlPathname, { pageContext, noWarning });
|
|
60
48
|
if (!linkData)
|
|
61
49
|
return null;
|
|
62
|
-
|
|
50
|
+
const isLinkOnSamePage = linkData.url === pageContext.urlPathname;
|
|
63
51
|
if (!hrefPathname)
|
|
64
52
|
assert(isLinkOnSamePage);
|
|
65
|
-
|
|
53
|
+
let sectionTitle = null;
|
|
66
54
|
if (hrefHash) {
|
|
67
55
|
assert(!hrefHash.startsWith('#'));
|
|
68
56
|
if (isLinkOnSamePage) {
|
|
69
|
-
|
|
57
|
+
const linkDataPageSection = findLinkData(`#${hrefHash}`, { pageContext, noWarning });
|
|
70
58
|
if (!linkDataPageSection)
|
|
71
59
|
return null;
|
|
72
60
|
sectionTitle = parseMarkdownMini(linkDataPageSection.title);
|
|
73
61
|
}
|
|
74
62
|
else if ('sectionTitles' in linkData && linkData.sectionTitles) {
|
|
75
|
-
linkData.sectionTitles.forEach(
|
|
63
|
+
linkData.sectionTitles.forEach((title) => {
|
|
76
64
|
if (determineSectionUrlHash(title) === hrefHash) {
|
|
77
65
|
sectionTitle = parseMarkdownMini(title);
|
|
78
66
|
}
|
|
@@ -80,32 +68,28 @@ function getLinkTextData(_a) {
|
|
|
80
68
|
}
|
|
81
69
|
if (!sectionTitle) {
|
|
82
70
|
if (doNotInferSectionTitle) {
|
|
83
|
-
assertWarning(false,
|
|
71
|
+
assertWarning(false, `Page section title not found for <Link href="\`${href}\`" doNotInferSectionTitle={true} />.`);
|
|
84
72
|
return null;
|
|
85
73
|
}
|
|
86
74
|
sectionTitle = React.createElement(React.Fragment, null, determineSectionTitle(href));
|
|
87
75
|
}
|
|
88
76
|
}
|
|
89
|
-
return { linkData
|
|
77
|
+
return { linkData, sectionTitle, isLinkOnSamePage };
|
|
90
78
|
}
|
|
91
|
-
function findLinkData(href,
|
|
92
|
-
var pageContext = _a.pageContext, noWarning = _a.noWarning;
|
|
79
|
+
function findLinkData(href, { pageContext, noWarning }) {
|
|
93
80
|
assert(href.startsWith('/') || href.startsWith('#'));
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
var url = _a.url;
|
|
97
|
-
return href === url;
|
|
98
|
-
});
|
|
81
|
+
const { linksAll } = pageContext.resolved;
|
|
82
|
+
const linkData = linksAll.find(({ url }) => href === url);
|
|
99
83
|
if (href.startsWith('#')) {
|
|
100
84
|
if (!noWarning) {
|
|
101
|
-
assertWarning(linkData,
|
|
85
|
+
assertWarning(linkData, `Couldn't find ${href} in ${pageContext.urlPathname}, does it exist?`);
|
|
102
86
|
}
|
|
103
87
|
}
|
|
104
88
|
else {
|
|
105
89
|
if (!noWarning) {
|
|
106
90
|
assertWarning(linkData, [
|
|
107
|
-
|
|
108
|
-
|
|
91
|
+
`Couldn't find page with URL ${pc.bold(href)}`,
|
|
92
|
+
`— did you define it in`,
|
|
109
93
|
[
|
|
110
94
|
pc.cyan('docpress.config.js'),
|
|
111
95
|
pc.dim('#{'),
|
|
@@ -118,16 +102,16 @@ function findLinkData(href, _a) {
|
|
|
118
102
|
].join(' '));
|
|
119
103
|
}
|
|
120
104
|
}
|
|
121
|
-
return linkData
|
|
105
|
+
return linkData ?? null;
|
|
122
106
|
}
|
|
123
107
|
function parseHref(href) {
|
|
124
|
-
|
|
125
|
-
|
|
108
|
+
let hrefHash = null;
|
|
109
|
+
let hrefPathname = null;
|
|
126
110
|
if (!href.includes('#')) {
|
|
127
111
|
hrefPathname = href;
|
|
128
112
|
}
|
|
129
113
|
else {
|
|
130
|
-
|
|
114
|
+
const [partsFirst, ...partsRest] = href.split('#');
|
|
131
115
|
if (partsFirst) {
|
|
132
116
|
hrefPathname = partsFirst;
|
|
133
117
|
}
|
|
@@ -138,5 +122,5 @@ function parseHref(href) {
|
|
|
138
122
|
// Text highlight links e,g. #metadata:~:text=global%20or%20local.-,Global%20metadata,-.
|
|
139
123
|
if (hrefHash)
|
|
140
124
|
hrefHash = hrefHash.split(':~:text')[0];
|
|
141
|
-
return { hrefPathname
|
|
125
|
+
return { hrefPathname, hrefHash };
|
|
142
126
|
}
|