@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.
Files changed (38) hide show
  1. package/components/CodeSnippets/useSelectCodeLang.ts +61 -0
  2. package/components/CodeSnippets.css +47 -0
  3. package/components/CodeSnippets.tsx +80 -45
  4. package/css/tooltip.css +10 -2
  5. package/detypePlugin.ts +73 -48
  6. package/dist/+config.js +1 -1
  7. package/dist/NavItemComponent.js +38 -46
  8. package/dist/components/CodeBlockTransformer.js +2 -3
  9. package/dist/components/CodeSnippets/useSelectCodeLang.d.ts +7 -0
  10. package/dist/components/CodeSnippets/useSelectCodeLang.js +51 -0
  11. package/dist/components/CodeSnippets.d.ts +10 -6
  12. package/dist/components/CodeSnippets.js +66 -94
  13. package/dist/components/Comment.js +1 -2
  14. package/dist/components/FileRemoved.js +4 -6
  15. package/dist/components/HorizontalLine.js +1 -2
  16. package/dist/components/ImportMeta.js +2 -3
  17. package/dist/components/Link.js +34 -50
  18. package/dist/components/Note.js +17 -29
  19. package/dist/components/P.js +1 -12
  20. package/dist/components/RepoLink.js +7 -9
  21. package/dist/determineNavItemsColumnLayout.js +48 -63
  22. package/dist/detypePlugin.js +84 -120
  23. package/dist/parseMarkdownMini.js +5 -17
  24. package/dist/parsePageSections.js +41 -82
  25. package/dist/renderer/usePageContext.js +6 -7
  26. package/dist/resolvePageContext.js +91 -103
  27. package/dist/utils/Emoji/Emoji.js +13 -21
  28. package/dist/utils/assert.js +14 -16
  29. package/dist/utils/cls.js +1 -1
  30. package/dist/utils/determineSectionUrlHash.js +5 -5
  31. package/dist/utils/filter.js +2 -2
  32. package/dist/utils/getGlobalObject.js +3 -3
  33. package/dist/vite.config.js +7 -7
  34. package/package.json +1 -1
  35. package/tsconfig.json +2 -1
  36. package/dist/utils/useSelectedLanguage.d.ts +0 -7
  37. package/dist/utils/useSelectedLanguage.js +0 -49
  38. 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 { CodeSnippets, CodeSnippet, TypescriptOnly };
1
+ export { TypescriptOnly };
2
+ export { CodeSnippets };
3
+ export { CodeSnippet };
2
4
  import React from 'react';
3
- declare function CodeSnippets({ children }: {
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 CodeSnippet({ children, language, tsOnly, }: {
10
+ declare function CodeSnippets({ children }: {
7
11
  children: React.ReactNode;
8
- language: string;
9
- tsOnly: boolean;
10
12
  }): React.JSX.Element;
11
- declare function TypescriptOnly({ children }: {
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
- 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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
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", { name: "language", id: "language", onChange: handleOnChange, value: selectedLang, style: { position: 'absolute', top: '10px', right: '60px', zIndex: 3 } },
60
- React.createElement("option", { value: "js" }, "Javascript"),
61
- React.createElement("option", { value: "ts" }, "Typescript"))),
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(_a) {
65
- var _this = this;
66
- var children = _a.children, language = _a.language, _b = _a.tsOnly, tsOnly = _b === void 0 ? false : _b;
67
- var selectedLang = useSelectedLanguage()[0];
68
- var style = tsOnly ? {} : { display: selectedLang === language ? 'block' : 'none' };
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
- // Show/hide TypeScript sections (code and/or plain)
97
- function TypescriptOnly(_a) {
98
- var children = _a.children;
99
- var selectedLang = useSelectedLanguage()[0];
100
- return React.createElement("div", { style: { display: selectedLang === 'ts' ? 'block' : 'none' } }, children);
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
  }
@@ -1,6 +1,5 @@
1
1
  export { Comment };
2
2
  import React from 'react';
3
- function Comment(_a) {
4
- var children = _a.children;
3
+ function Comment({ children }) {
5
4
  return React.createElement(React.Fragment, null);
6
5
  }
@@ -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
- var classRemoved = [
5
+ const classRemoved = [
6
6
  //
7
7
  'diff-entire-file',
8
8
  'diff-entire-file-removed',
9
9
  ].join(' ');
10
- var classAdded = [
10
+ const classAdded = [
11
11
  //
12
12
  'diff-entire-file',
13
13
  'diff-entire-file-added',
14
14
  ].join(' ');
15
- function FileRemoved(_a) {
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(_a) {
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(_a) {
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(_a) {
5
- var prop = _a.prop;
4
+ function ImportMeta({ prop }) {
6
5
  assert(!prop.startsWith('import'));
7
6
  assert(!prop.startsWith('.'));
8
- var text = 'imp' + 'ort.meta.' + prop;
7
+ const text = 'imp' + 'ort.meta.' + prop;
9
8
  return React.createElement("code", null, text);
10
9
  }
@@ -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(_a) {
19
- var href = _a.href, text = _a.text, noBreadcrumb = _a.noBreadcrumb, doNotInferSectionTitle = _a.doNotInferSectionTitle, noWarning = _a.noWarning, children = _a.children;
20
- var pageContext = usePageContext();
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 !== null && text !== void 0 ? text : children;
25
- var linkTextData = getLinkTextData({ href: href, pageContext: pageContext, doNotInferSectionTitle: doNotInferSectionTitle, noWarning: noWarning });
12
+ text = text ?? children;
13
+ const linkTextData = getLinkTextData({ href, pageContext, doNotInferSectionTitle, noWarning });
26
14
  if (!text) {
27
15
  if (linkTextData) {
28
- text = getLinkText(__assign({ noBreadcrumb: noBreadcrumb }, linkTextData));
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(_a) {
37
- var _b;
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.apply(breadcrumbParts, ((_b = linkData.linkBreadcrumb) !== null && _b !== void 0 ? _b : []).slice().reverse().map(parseMarkdownMini));
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(function (title, i) {
50
- var seperator = i === 0 ? React.createElement(React.Fragment, null) : ' > ';
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(_a) {
57
- var href = _a.href, pageContext = _a.pageContext, doNotInferSectionTitle = _a.doNotInferSectionTitle, noWarning = _a.noWarning;
58
- var _b = parseHref(href), hrefPathname = _b.hrefPathname, hrefHash = _b.hrefHash;
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
- var isLinkOnSamePage = linkData.url === pageContext.urlPathname;
50
+ const isLinkOnSamePage = linkData.url === pageContext.urlPathname;
63
51
  if (!hrefPathname)
64
52
  assert(isLinkOnSamePage);
65
- var sectionTitle = null;
53
+ let sectionTitle = null;
66
54
  if (hrefHash) {
67
55
  assert(!hrefHash.startsWith('#'));
68
56
  if (isLinkOnSamePage) {
69
- var linkDataPageSection = findLinkData("#".concat(hrefHash), { pageContext: pageContext, noWarning: noWarning });
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(function (title) {
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, "Page section title not found for <Link href=\"`".concat(href, "`\" doNotInferSectionTitle={true} />."));
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: linkData, sectionTitle: sectionTitle, isLinkOnSamePage: isLinkOnSamePage };
77
+ return { linkData, sectionTitle, isLinkOnSamePage };
90
78
  }
91
- function findLinkData(href, _a) {
92
- var pageContext = _a.pageContext, noWarning = _a.noWarning;
79
+ function findLinkData(href, { pageContext, noWarning }) {
93
80
  assert(href.startsWith('/') || href.startsWith('#'));
94
- var linksAll = pageContext.resolved.linksAll;
95
- var linkData = linksAll.find(function (_a) {
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, "Couldn't find ".concat(href, " in ").concat(pageContext.urlPathname, ", does it exist?"));
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
- "Couldn't find page with URL ".concat(pc.bold(href)),
108
- "\u2014 did you define it in",
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 !== null && linkData !== void 0 ? linkData : null;
105
+ return linkData ?? null;
122
106
  }
123
107
  function parseHref(href) {
124
- var hrefHash = null;
125
- var hrefPathname = null;
108
+ let hrefHash = null;
109
+ let hrefPathname = null;
126
110
  if (!href.includes('#')) {
127
111
  hrefPathname = href;
128
112
  }
129
113
  else {
130
- var _a = href.split('#'), partsFirst = _a[0], partsRest = _a.slice(1);
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: hrefPathname, hrefHash: hrefHash };
125
+ return { hrefPathname, hrefHash };
142
126
  }
@@ -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, __assign({ type: "warning" }, props));
19
+ return React.createElement(NoteGeneric, { type: "warning", ...props });
31
20
  }
32
21
  function Advanced(props) {
33
- return React.createElement(NoteGeneric, __assign({ type: "advanced" }, props));
22
+ return React.createElement(NoteGeneric, { type: "advanced", ...props });
34
23
  }
35
24
  function Construction(props) {
36
- return React.createElement(NoteGeneric, __assign({ type: "construction" }, props));
25
+ return React.createElement(NoteGeneric, { type: "construction", ...props });
37
26
  }
38
27
  function Contribution(props) {
39
- return React.createElement(NoteGeneric, __assign({ type: "contribution" }, props));
28
+ return React.createElement(NoteGeneric, { type: "contribution", ...props });
40
29
  }
41
30
  function Danger(props) {
42
- return React.createElement(NoteGeneric, __assign({ type: "danger" }, props));
31
+ return React.createElement(NoteGeneric, { type: "danger", ...props });
43
32
  }
44
33
  function NoteWithoutIcon(props) {
45
- return React.createElement(NoteGeneric, __assign({ icon: null }, props));
34
+ return React.createElement(NoteGeneric, { icon: null, ...props });
46
35
  }
47
36
  function NoteWithCustomIcon(props) {
48
- var icon = props.icon;
37
+ const { icon } = props;
49
38
  if (!icon)
50
- throw new Error("<NoteWithCustomIcon icon={/*...*/}> property 'icon' is `".concat(icon, "` which is forbidden"));
51
- return React.createElement(NoteGeneric, __assign({}, props));
39
+ throw new Error(`<NoteWithCustomIcon icon={/*...*/}> property 'icon' is \`${icon}\` which is forbidden`);
40
+ return React.createElement(NoteGeneric, { ...props });
52
41
  }
53
- function NoteGeneric(_a) {
54
- var type = _a.type, icon = _a.icon, iconMargin = _a.iconMargin, children = _a.children, style = _a.style;
55
- assert(icon === null || icon || type, { icon: icon, type: type });
56
- iconMargin !== null && iconMargin !== void 0 ? iconMargin : (iconMargin = 2);
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 = "".concat(className, " type-").concat(type);
47
+ className = `${className} type-${type}`;
60
48
  }
61
49
  if (!icon && type) {
62
- var classColor = '';
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 = "".concat(className, " ").concat(classColor);
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 !== null && iconMargin !== void 0 ? iconMargin : undefined, display: 'inline-block' } }),
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 } })));
@@ -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", __assign({}, props, { className: 'paragraph' }));
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(_a) {
6
- var path = _a.path, text = _a.text;
5
+ function RepoLink({ path, text }) {
7
6
  text = text || path;
8
- var href = getRepoHref(path);
7
+ const href = getRepoHref(path);
9
8
  return React.createElement("a", { href: href }, text);
10
9
  }
11
- function getRepoHref(path, editMode) {
12
- if (editMode === void 0) { editMode = false; }
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
- var viewMode = path.endsWith('/') && !editMode ? 'tree' : 'blob';
18
- var github = pageContext.globalContext.config.docpress.github;
19
- var href = "".concat(github, "/").concat(viewMode, "/main").concat(path);
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;