@brillout/docpress 0.15.10-commit-e9efbd3 → 0.15.10-commit-af2d9bc
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/components/CodeSnippets/useSelectCodeLang.ts +61 -0
- package/components/CodeSnippets.css +47 -0
- package/components/CodeSnippets.tsx +80 -45
- package/css/tooltip.css +10 -2
- package/detypePlugin.ts +73 -48
- package/dist/+config.js +1 -1
- package/dist/NavItemComponent.js +38 -46
- package/dist/components/CodeBlockTransformer.js +2 -3
- package/dist/components/CodeSnippets/useSelectCodeLang.d.ts +7 -0
- package/dist/components/CodeSnippets/useSelectCodeLang.js +51 -0
- package/dist/components/CodeSnippets.d.ts +10 -6
- package/dist/components/CodeSnippets.js +66 -94
- 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/determineNavItemsColumnLayout.js +48 -63
- package/dist/detypePlugin.js +84 -120
- 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/vite.config.js +7 -7
- package/package.json +1 -1
- package/tsconfig.json +2 -1
- package/dist/utils/useSelectedLanguage.d.ts +0 -7
- package/dist/utils/useSelectedLanguage.js +0 -49
- package/utils/useSelectedLanguage.ts +0 -61
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export { useSelectCodeLang };
|
|
2
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
3
|
+
import { assertWarning } from '../../utils/assert';
|
|
4
|
+
const storageKey = 'docpress:code-lang';
|
|
5
|
+
const codeLangDefaultSsr = 'ts';
|
|
6
|
+
const codeLangDefaultClient = 'js';
|
|
7
|
+
function useSelectCodeLang() {
|
|
8
|
+
const [codeLangSelected, setCodeLangSelected] = useState(codeLangDefaultSsr);
|
|
9
|
+
const updateState = () => {
|
|
10
|
+
setCodeLangSelected(getCodeLangStorage());
|
|
11
|
+
};
|
|
12
|
+
const updateStateOnStorageEvent = (event) => {
|
|
13
|
+
if (event.key === storageKey)
|
|
14
|
+
return;
|
|
15
|
+
updateState();
|
|
16
|
+
};
|
|
17
|
+
const getCodeLangStorage = () => {
|
|
18
|
+
try {
|
|
19
|
+
return window.localStorage.getItem(storageKey) ?? codeLangDefaultClient;
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error(error);
|
|
23
|
+
assertWarning(false, 'Error reading from localStorage');
|
|
24
|
+
return codeLangDefaultClient;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const selectCodeLang = useCallback((value) => {
|
|
28
|
+
try {
|
|
29
|
+
window.localStorage.setItem(storageKey, value);
|
|
30
|
+
setCodeLangSelected(value);
|
|
31
|
+
window.dispatchEvent(new CustomEvent('code-lang-storage'));
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.error(error);
|
|
35
|
+
assertWarning(false, 'Error setting localStorage');
|
|
36
|
+
}
|
|
37
|
+
}, []);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
// Initial load from localStorage
|
|
40
|
+
updateState();
|
|
41
|
+
// Update code lang in current tab
|
|
42
|
+
window.addEventListener('code-lang-storage', updateState);
|
|
43
|
+
// Update code lang if changed in another tab
|
|
44
|
+
window.addEventListener('storage', updateStateOnStorageEvent);
|
|
45
|
+
return () => {
|
|
46
|
+
window.removeEventListener('code-lang-storage', updateState);
|
|
47
|
+
window.removeEventListener('storage', updateStateOnStorageEvent);
|
|
48
|
+
};
|
|
49
|
+
}, []);
|
|
50
|
+
return [codeLangSelected, selectCodeLang];
|
|
51
|
+
}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { TypescriptOnly };
|
|
2
|
+
export { CodeSnippets };
|
|
3
|
+
export { CodeSnippet };
|
|
2
4
|
import React from 'react';
|
|
3
|
-
|
|
5
|
+
import './CodeSnippets.css';
|
|
6
|
+
/** Only show if TypeScript is selected */
|
|
7
|
+
declare function TypescriptOnly({ children }: {
|
|
4
8
|
children: React.ReactNode;
|
|
5
9
|
}): React.JSX.Element;
|
|
6
|
-
declare function
|
|
10
|
+
declare function CodeSnippets({ children }: {
|
|
7
11
|
children: React.ReactNode;
|
|
8
|
-
language: string;
|
|
9
|
-
tsOnly: boolean;
|
|
10
12
|
}): React.JSX.Element;
|
|
11
|
-
declare function
|
|
13
|
+
declare function CodeSnippet({ children, codeLang, tsOnly, }: {
|
|
12
14
|
children: React.ReactNode;
|
|
15
|
+
codeLang: string;
|
|
16
|
+
tsOnly: boolean;
|
|
13
17
|
}): React.JSX.Element;
|
|
@@ -1,101 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
23
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
export { CodeSnippets, CodeSnippet, TypescriptOnly };
|
|
49
|
-
import React from 'react';
|
|
50
|
-
import { useSelectedLanguage } from '../utils/useSelectedLanguage';
|
|
51
|
-
function CodeSnippets(_a) {
|
|
52
|
-
var children = _a.children;
|
|
53
|
-
var _b = useSelectedLanguage(), selectedLang = _b[0], setSelectedLang = _b[1];
|
|
54
|
-
var handleOnChange = function (e) {
|
|
55
|
-
setSelectedLang(e.target.value);
|
|
56
|
-
};
|
|
1
|
+
// Public
|
|
2
|
+
export { TypescriptOnly };
|
|
3
|
+
// Internal
|
|
4
|
+
export { CodeSnippets };
|
|
5
|
+
export { CodeSnippet };
|
|
6
|
+
import React, { useState } from 'react';
|
|
7
|
+
import { useSelectCodeLang } from './CodeSnippets/useSelectCodeLang';
|
|
8
|
+
import './CodeSnippets.css';
|
|
9
|
+
/** Only show if TypeScript is selected */
|
|
10
|
+
function TypescriptOnly({ children }) {
|
|
11
|
+
const [codeLangSelected] = useSelectCodeLang();
|
|
12
|
+
return React.createElement("div", { style: { display: codeLangSelected === 'ts' ? 'block' : 'none' } }, children);
|
|
13
|
+
}
|
|
14
|
+
function CodeSnippets({ children }) {
|
|
15
|
+
const [codeLangSelected, selectCodeLang] = useSelectCodeLang();
|
|
57
16
|
return (React.createElement("div", null,
|
|
58
17
|
React.createElement("form", { style: { position: 'relative' } },
|
|
59
|
-
React.createElement("select", {
|
|
60
|
-
React.createElement("option", { value: "js" }, "
|
|
61
|
-
React.createElement("option", { value: "ts" }, "
|
|
18
|
+
React.createElement("select", { className: "code-lang-select", onChange: onChange, value: codeLangSelected },
|
|
19
|
+
React.createElement("option", { value: "js" }, "JavaScript"),
|
|
20
|
+
React.createElement("option", { value: "ts" }, "TypeScript"))),
|
|
62
21
|
children));
|
|
22
|
+
function onChange(e) {
|
|
23
|
+
selectCodeLang(e.target.value);
|
|
24
|
+
}
|
|
63
25
|
}
|
|
64
|
-
function CodeSnippet(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
var copyToClipboard = function (e) { return __awaiter(_this, void 0, void 0, function () {
|
|
70
|
-
var figureEl, error_1;
|
|
71
|
-
var _a;
|
|
72
|
-
return __generator(this, function (_b) {
|
|
73
|
-
switch (_b.label) {
|
|
74
|
-
case 0:
|
|
75
|
-
_b.trys.push([0, 3, , 4]);
|
|
76
|
-
figureEl = e.currentTarget.nextElementSibling;
|
|
77
|
-
if (!((figureEl === null || figureEl === void 0 ? void 0 : figureEl.tagName) === 'FIGURE')) return [3 /*break*/, 2];
|
|
78
|
-
return [4 /*yield*/, navigator.clipboard.writeText((_a = figureEl.textContent) !== null && _a !== void 0 ? _a : '')];
|
|
79
|
-
case 1:
|
|
80
|
-
_b.sent();
|
|
81
|
-
console.log('Copied to clipboard!');
|
|
82
|
-
_b.label = 2;
|
|
83
|
-
case 2: return [3 /*break*/, 4];
|
|
84
|
-
case 3:
|
|
85
|
-
error_1 = _b.sent();
|
|
86
|
-
console.warn('Copy failed', error_1);
|
|
87
|
-
return [3 /*break*/, 4];
|
|
88
|
-
case 4: return [2 /*return*/];
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}); };
|
|
92
|
-
return (React.createElement("div", { style: __assign(__assign({}, style), { position: 'relative' }) },
|
|
93
|
-
React.createElement("button", { type: "button", style: { position: 'absolute', top: '10px', right: '10px', zIndex: 3 }, onClick: copyToClipboard }, "Copy"),
|
|
26
|
+
function CodeSnippet({ children, codeLang, tsOnly = false, }) {
|
|
27
|
+
const [codeLangSelected] = useSelectCodeLang();
|
|
28
|
+
const displayStyle = tsOnly ? {} : { display: codeLangSelected === codeLang ? 'block' : 'none' };
|
|
29
|
+
return (React.createElement("div", { style: { ...displayStyle, position: 'relative' } },
|
|
30
|
+
React.createElement(CopyButton, null),
|
|
94
31
|
children));
|
|
95
32
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
33
|
+
function CopyButton() {
|
|
34
|
+
const [isSuccess, setIsSuccess] = useState(null);
|
|
35
|
+
const onCopy = (success) => {
|
|
36
|
+
setIsSuccess(success);
|
|
37
|
+
setTimeout(() => {
|
|
38
|
+
setIsSuccess(null);
|
|
39
|
+
}, 900);
|
|
40
|
+
};
|
|
41
|
+
const tooltip = isSuccess === null ? 'Copy to clipboard' : isSuccess ? 'Copied' : 'Failed';
|
|
42
|
+
const text = isSuccess === null ? (React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: "2" },
|
|
43
|
+
React.createElement("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2", ry: "2" }),
|
|
44
|
+
React.createElement("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" }))) : isSuccess ? (React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", stroke: "#28a745", strokeWidth: "3" },
|
|
45
|
+
React.createElement("polyline", { points: "20 6 9 17 4 12" }))) : ('❌');
|
|
46
|
+
return (React.createElement("button", { className: "copy-button", "aria-label": tooltip, "data-label-position": "top", type: "button", onClick: onClick }, text));
|
|
47
|
+
async function onClick(e) {
|
|
48
|
+
let success;
|
|
49
|
+
try {
|
|
50
|
+
await copyToClipboard(e);
|
|
51
|
+
success = true;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error(error);
|
|
55
|
+
success = false;
|
|
56
|
+
}
|
|
57
|
+
onCopy(success);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async function copyToClipboard(e) {
|
|
61
|
+
const figureEl = e.currentTarget.nextElementSibling;
|
|
62
|
+
if (figureEl?.tagName === 'FIGURE') {
|
|
63
|
+
let text = figureEl.textContent ?? '';
|
|
64
|
+
text = removeTrailingWhitespaces(text);
|
|
65
|
+
await navigator.clipboard.writeText(text);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function removeTrailingWhitespaces(text) {
|
|
69
|
+
return text
|
|
70
|
+
.split('\n')
|
|
71
|
+
.map((line) => line.trimEnd())
|
|
72
|
+
.join('\n');
|
|
101
73
|
}
|
|
@@ -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
|
}
|
package/dist/components/Note.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
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 { Warning };
|
|
13
2
|
export { Advanced };
|
|
14
3
|
export { Construction };
|
|
@@ -27,39 +16,38 @@ import React from 'react';
|
|
|
27
16
|
import { assert } from '../utils/assert';
|
|
28
17
|
import './Note.css';
|
|
29
18
|
function Warning(props) {
|
|
30
|
-
return React.createElement(NoteGeneric,
|
|
19
|
+
return React.createElement(NoteGeneric, { type: "warning", ...props });
|
|
31
20
|
}
|
|
32
21
|
function Advanced(props) {
|
|
33
|
-
return React.createElement(NoteGeneric,
|
|
22
|
+
return React.createElement(NoteGeneric, { type: "advanced", ...props });
|
|
34
23
|
}
|
|
35
24
|
function Construction(props) {
|
|
36
|
-
return React.createElement(NoteGeneric,
|
|
25
|
+
return React.createElement(NoteGeneric, { type: "construction", ...props });
|
|
37
26
|
}
|
|
38
27
|
function Contribution(props) {
|
|
39
|
-
return React.createElement(NoteGeneric,
|
|
28
|
+
return React.createElement(NoteGeneric, { type: "contribution", ...props });
|
|
40
29
|
}
|
|
41
30
|
function Danger(props) {
|
|
42
|
-
return React.createElement(NoteGeneric,
|
|
31
|
+
return React.createElement(NoteGeneric, { type: "danger", ...props });
|
|
43
32
|
}
|
|
44
33
|
function NoteWithoutIcon(props) {
|
|
45
|
-
return React.createElement(NoteGeneric,
|
|
34
|
+
return React.createElement(NoteGeneric, { icon: null, ...props });
|
|
46
35
|
}
|
|
47
36
|
function NoteWithCustomIcon(props) {
|
|
48
|
-
|
|
37
|
+
const { icon } = props;
|
|
49
38
|
if (!icon)
|
|
50
|
-
throw new Error(
|
|
51
|
-
return React.createElement(NoteGeneric,
|
|
39
|
+
throw new Error(`<NoteWithCustomIcon icon={/*...*/}> property 'icon' is \`${icon}\` which is forbidden`);
|
|
40
|
+
return React.createElement(NoteGeneric, { ...props });
|
|
52
41
|
}
|
|
53
|
-
function NoteGeneric(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
var className = 'custom-icon';
|
|
42
|
+
function NoteGeneric({ type, icon, iconMargin, children, style, }) {
|
|
43
|
+
assert(icon === null || icon || type, { icon, type });
|
|
44
|
+
iconMargin ??= 2;
|
|
45
|
+
let className = 'custom-icon';
|
|
58
46
|
if (type) {
|
|
59
|
-
className =
|
|
47
|
+
className = `${className} type-${type}`;
|
|
60
48
|
}
|
|
61
49
|
if (!icon && type) {
|
|
62
|
-
|
|
50
|
+
let classColor = '';
|
|
63
51
|
if (type === 'danger') {
|
|
64
52
|
icon = '⛔';
|
|
65
53
|
classColor = 'note-color-red';
|
|
@@ -82,13 +70,13 @@ function NoteGeneric(_a) {
|
|
|
82
70
|
}
|
|
83
71
|
assert(icon);
|
|
84
72
|
assert(classColor);
|
|
85
|
-
className =
|
|
73
|
+
className = `${className} ${classColor}`;
|
|
86
74
|
}
|
|
87
75
|
return (React.createElement("blockquote", { className: className, style: style },
|
|
88
76
|
React.createElement("div", { style: { marginBottom: 20 } }),
|
|
89
77
|
icon && (React.createElement(React.Fragment, null,
|
|
90
78
|
React.createElement("span", { style: { fontFamily: 'emoji' } }, icon),
|
|
91
|
-
React.createElement("span", { style: { width: iconMargin
|
|
79
|
+
React.createElement("span", { style: { width: iconMargin ?? undefined, display: 'inline-block' } }),
|
|
92
80
|
' ')),
|
|
93
81
|
React.createElement("div", { className: "blockquote-content" }, children),
|
|
94
82
|
React.createElement("div", { style: { marginTop: 20 } })));
|
package/dist/components/P.js
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
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
|
import React from 'react';
|
|
13
2
|
import './P.css';
|
|
14
3
|
export { P };
|
|
15
4
|
function P(props) {
|
|
16
|
-
return React.createElement("div",
|
|
5
|
+
return React.createElement("div", { ...props, className: 'paragraph' });
|
|
17
6
|
}
|
|
@@ -2,21 +2,19 @@ export { RepoLink };
|
|
|
2
2
|
export { getRepoHref };
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { usePageContext } from '../renderer/usePageContext';
|
|
5
|
-
function RepoLink(
|
|
6
|
-
var path = _a.path, text = _a.text;
|
|
5
|
+
function RepoLink({ path, text }) {
|
|
7
6
|
text = text || path;
|
|
8
|
-
|
|
7
|
+
const href = getRepoHref(path);
|
|
9
8
|
return React.createElement("a", { href: href }, text);
|
|
10
9
|
}
|
|
11
|
-
function getRepoHref(path, editMode) {
|
|
12
|
-
|
|
13
|
-
var pageContext = usePageContext();
|
|
10
|
+
function getRepoHref(path, editMode = false) {
|
|
11
|
+
const pageContext = usePageContext();
|
|
14
12
|
if (!path.startsWith('/')) {
|
|
15
13
|
path = '/' + path;
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
const viewMode = path.endsWith('/') && !editMode ? 'tree' : 'blob';
|
|
16
|
+
const { github } = pageContext.globalContext.config.docpress;
|
|
17
|
+
let href = `${github}/${viewMode}/main${path}`;
|
|
20
18
|
if (editMode)
|
|
21
19
|
href += '?plain=1';
|
|
22
20
|
return href;
|