@brillout/docpress 0.15.10-commit-ef0b9a0 → 0.15.10-commit-e9efbd3

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.
@@ -52,7 +52,11 @@ function CodeSnippet({
52
52
 
53
53
  return (
54
54
  <div style={{ ...style, position: 'relative' }}>
55
- <button type="button" style={{ position: 'absolute', top: '10px', right: '10px' }} onClick={copyToClipboard}>
55
+ <button
56
+ type="button"
57
+ style={{ position: 'absolute', top: '10px', right: '10px', zIndex: 3 }}
58
+ onClick={copyToClipboard}
59
+ >
56
60
  Copy
57
61
  </button>
58
62
  {children}
package/detypePlugin.ts CHANGED
@@ -16,48 +16,60 @@ function detypePlugin(): PluginOption {
16
16
  return
17
17
  }
18
18
  const codeNew = await transformCode(code)
19
+
19
20
  return codeNew
20
21
  },
21
22
  }
22
23
  }
23
24
 
24
- const tsBlockRegex = /```(tsx?|vue)(\s+ts-only)?([\s\S]*?)```/g
25
+ const codeBlockRE = /^([ \t]{0,3}>?[ \t]?)```(tsx?|vue)[^\n]*\n([\s\S]*?)```/gm
26
+ const prettierOptions = {
27
+ semi: false,
28
+ singleQuote: true,
29
+ printWidth: 100,
30
+ }
25
31
 
26
32
  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
-
33
+ const matches = Array.from(code.matchAll(codeBlockRE))
32
34
  if (matches.length === 0) {
33
35
  return code
34
36
  }
35
37
 
38
+ let codeNew = `import { CodeSnippets, CodeSnippet } from '@brillout/docpress';\n\n`
39
+ let lastIndex = 0
40
+
36
41
  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
42
+ let [fullMatch, startsWith, lang, tsCode] = match
43
+ const tsOpeningCode = fullMatch.split('\n')[0].slice(startsWith.length)
39
44
 
40
45
  const blockStart = match.index
41
- const blockEnd = blockStart + tsCodeBlock.length
46
+ const blockEnd = blockStart + fullMatch.length
42
47
 
43
48
  codeNew += code.slice(lastIndex, blockStart)
44
49
 
45
- if (tsOnly) {
46
- codeNew += `\n<CodeSnippet language={'ts'} tsOnly={'true'}>\n${tsCodeBlock}\n</CodeSnippet>\n`
50
+ if (startsWith.length > 0) {
51
+ tsCode = stripStarts(tsCode, startsWith)
52
+ }
53
+
54
+ if (tsOpeningCode.includes('ts-only')) {
55
+ codeNew += `${startsWith}<CodeSnippet language={'ts'} tsOnly={'true'}>\n${fullMatch}\n${startsWith}</CodeSnippet>`
47
56
  } else {
48
- const jsCode = await transform(tsCode.trim().replaceAll('.ts', '.js'), `tsCode.${lang}`, {
57
+ const jsCode = await transform(tsCode.replaceAll('.ts', '.js'), `tsCode.${lang}`, {
49
58
  removeTsComments: true,
50
- prettierOptions: {
51
- semi: false,
52
- singleQuote: true,
53
- },
59
+ prettierOptions,
54
60
  })
61
+ const jsLang = lang === 'vue' ? 'vue' : lang.replace('t', 'j') // ts => js | tsx => jsx
62
+ const jsOpeningCode = tsOpeningCode.replace(lang, jsLang)
63
+ const closing = `\`\`\``
55
64
 
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`
65
+ const jsCodeSnippet = `<CodeSnippet language={'js'}>\n${jsOpeningCode}\n${jsCode}${closing}\n</CodeSnippet>`
66
+ const tsCodeSnippet = `<CodeSnippet language={'ts'}>\n${tsOpeningCode}\n${tsCode}${closing}\n</CodeSnippet>`
67
+ const codeSnippets = putBackStarts(
68
+ `<CodeSnippets>\n${tsCodeSnippet}\n${jsCodeSnippet}\n</CodeSnippets>`,
69
+ startsWith,
70
+ )
59
71
 
60
- codeNew += `<CodeSnippets>${jsCodeSnippet}${tsCodeSnippet}</CodeSnippets>`
72
+ codeNew += codeSnippets
61
73
  }
62
74
 
63
75
  lastIndex = blockEnd
@@ -66,3 +78,20 @@ async function transformCode(code: string) {
66
78
 
67
79
  return codeNew
68
80
  }
81
+
82
+ function stripStarts(code: string, startsWith: string) {
83
+ return code
84
+ .split('\n')
85
+ .map((line) => line.slice(startsWith.length))
86
+ .join('\n')
87
+ }
88
+
89
+ function putBackStarts(code: string, startsWith: string) {
90
+ if (!startsWith.length) {
91
+ return code
92
+ }
93
+ return code
94
+ .split('\n')
95
+ .map((line) => `${startsWith}${line}`)
96
+ .join('\n')
97
+ }
package/dist/+config.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export { config as default };
2
2
  import { viteConfig } from './vite.config.js';
3
- const config = {
3
+ var config = {
4
4
  name: '@brillout/docpress',
5
5
  require: { vike: '>=0.4.234' },
6
6
  vite: viteConfig,
@@ -1,39 +1,53 @@
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
+ };
1
12
  export { NavItemComponent };
2
13
  export { getNavItemsWithComputed };
3
14
  import React from 'react';
4
15
  import { assert, assertWarning, jsxToTextContent } from './utils/server';
5
16
  import './NavItemComponent.css';
6
17
  import { parseMarkdownMini } from './parseMarkdownMini';
7
- function NavItemComponent({ navItem, onClick, }) {
18
+ function NavItemComponent(_a) {
19
+ var _b;
20
+ var _c;
21
+ var navItem = _a.navItem, onClick = _a.onClick;
8
22
  assert([1, 2, 3, 4].includes(navItem.level), navItem);
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 } }));
23
+ var titleJsx = parseMarkdownMini(navItem.title);
24
+ var titleInNavJsx = parseMarkdownMini(navItem.titleInNav);
25
+ var iconSize = 25;
26
+ var icon = navItem.titleIcon && (React.createElement("img", { src: navItem.titleIcon, style: __assign({ height: iconSize, width: iconSize, marginRight: 8, marginLeft: 4 }, navItem.titleIconStyle) }));
13
27
  if (navItem.level === 1 || navItem.level === 4) {
14
28
  assert(navItem.url === undefined);
15
29
  }
16
30
  else {
17
- const sectionTitle = jsxToTextContent(titleJsx);
31
+ var sectionTitle = jsxToTextContent(titleJsx);
18
32
  assertWarning(navItem.url, [
19
- `${jsxToTextContent(titleInNavJsx)} is missing a URL hash.`,
20
- `Add a URL hash with: \`## ${sectionTitle}{#some-hash}\`.`,
33
+ "".concat(jsxToTextContent(titleInNavJsx), " is missing a URL hash."),
34
+ "Add a URL hash with: `## ".concat(sectionTitle, "{#some-hash}`."),
21
35
  /* TO-DO/eventually: not implemented yet.
22
36
  `Use \`<h2 id="url-hash">${sectionTitle}</h2>\` instead of \`## ${sectionTitle}\`.`,
23
37
  */
24
38
  ].join(' '));
25
39
  }
26
- let children = titleInNavJsx;
40
+ var children = titleInNavJsx;
27
41
  if (navItem.level === 1) {
28
42
  children = (React.createElement(React.Fragment, null,
29
43
  icon,
30
44
  children,
31
45
  React.createElement(Chevron, { className: "collapsible-icon", height: 9 })));
32
46
  }
33
- const props = {
34
- href: navItem.url ?? undefined,
35
- children,
36
- onClick,
47
+ var props = {
48
+ href: (_c = navItem.url) !== null && _c !== void 0 ? _c : undefined,
49
+ children: children,
50
+ onClick: onClick,
37
51
  className: [
38
52
  'nav-item',
39
53
  'nav-item-level-' + navItem.level,
@@ -45,51 +59,45 @@ function NavItemComponent({ navItem, onClick, }) {
45
59
  .join(' '),
46
60
  };
47
61
  if (navItem.level === 1) {
48
- props.style = {
49
- ['--category-color']: navItem.color,
50
- };
62
+ props.style = (_b = {},
63
+ _b['--category-color'] = navItem.color,
64
+ _b);
51
65
  }
52
66
  if (navItem.level === 2 || navItem.level === 3) {
53
- return React.createElement("a", { ...props });
67
+ return React.createElement("a", __assign({}, props));
54
68
  }
55
69
  else {
56
- return React.createElement("span", { ...props });
70
+ return React.createElement("span", __assign({}, props));
57
71
  }
58
72
  }
59
73
  function getNavItemsWithComputed(navItems, currentUrl) {
60
- let navItemIdx;
61
- const navItemsWithComputed = navItems.map((navItem, i) => {
74
+ var navItemIdx;
75
+ var navItemsWithComputed = navItems.map(function (navItem, i) {
62
76
  assert([1, 2, 3, 4].includes(navItem.level), navItem);
63
- const navItemPrevious = navItems[i - 1];
64
- const navItemNext = navItems[i + 1];
65
- let isActive = false;
77
+ var navItemPrevious = navItems[i - 1];
78
+ var navItemNext = navItems[i + 1];
79
+ var isActive = false;
66
80
  if (navItem.url === currentUrl) {
67
- assert(navItem.level === 2, { currentUrl });
81
+ assert(navItem.level === 2, { currentUrl: currentUrl });
68
82
  assert(navItemIdx === undefined);
69
83
  navItemIdx = i;
70
84
  isActive = true;
71
85
  }
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
- };
86
+ var isFirstOfItsKind = navItem.level !== (navItemPrevious === null || navItemPrevious === void 0 ? void 0 : navItemPrevious.level);
87
+ var isLastOfItsKind = navItem.level !== (navItemNext === null || navItemNext === void 0 ? void 0 : navItemNext.level);
88
+ var navItemComputed = __assign(__assign({}, navItem), { isActive: isActive, isRelevant: false, isFirstOfItsKind: isFirstOfItsKind, isLastOfItsKind: isLastOfItsKind });
81
89
  return navItemComputed;
82
90
  });
83
91
  // Set `isRelevant`
84
92
  if (navItemIdx !== undefined) {
85
- for (let i = navItemIdx; i >= 0; i--) {
86
- const navItem = navItemsWithComputed[i];
93
+ for (var i = navItemIdx; i >= 0; i--) {
94
+ var navItem = navItemsWithComputed[i];
87
95
  navItem.isRelevant = true;
88
96
  if (navItem.level === 1)
89
97
  break;
90
98
  }
91
- for (let i = navItemIdx; i < navItemsWithComputed.length; i++) {
92
- const navItem = navItemsWithComputed[i];
99
+ for (var i = navItemIdx; i < navItemsWithComputed.length; i++) {
100
+ var navItem = navItemsWithComputed[i];
93
101
  if (navItem.level === 1)
94
102
  break;
95
103
  navItem.isRelevant = true;
@@ -98,6 +106,6 @@ function getNavItemsWithComputed(navItems, currentUrl) {
98
106
  return navItemsWithComputed;
99
107
  }
100
108
  function Chevron(props) {
101
- return (React.createElement("svg", { viewBox: "0 0 512 292.52", xmlns: "http://www.w3.org/2000/svg", ...props },
109
+ return (React.createElement("svg", __assign({ viewBox: "0 0 512 292.52", xmlns: "http://www.w3.org/2000/svg" }, props),
102
110
  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" })));
103
111
  }
@@ -2,8 +2,9 @@ export { CodeBlockTransformer };
2
2
  import React from 'react';
3
3
  import { assert } from '../utils/server';
4
4
  import './CodeBlockTransformer.css';
5
- function CodeBlockTransformer({ children, lineBreak }) {
5
+ function CodeBlockTransformer(_a) {
6
+ var children = _a.children, lineBreak = _a.lineBreak;
6
7
  assert(lineBreak === 'white-space' || lineBreak === 'break-word', '`lineBreak` is currently the only use case for <CodeBlockTransformer>');
7
- const className = `with-line-break_${lineBreak}`;
8
+ var className = "with-line-break_".concat(lineBreak);
8
9
  return React.createElement("div", { className: className }, children);
9
10
  }
@@ -1,9 +1,57 @@
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
+ };
1
48
  export { CodeSnippets, CodeSnippet, TypescriptOnly };
2
49
  import React from 'react';
3
50
  import { useSelectedLanguage } from '../utils/useSelectedLanguage';
4
- function CodeSnippets({ children }) {
5
- const [selectedLang, setSelectedLang] = useSelectedLanguage();
6
- const handleOnChange = (e) => {
51
+ function CodeSnippets(_a) {
52
+ var children = _a.children;
53
+ var _b = useSelectedLanguage(), selectedLang = _b[0], setSelectedLang = _b[1];
54
+ var handleOnChange = function (e) {
7
55
  setSelectedLang(e.target.value);
8
56
  };
9
57
  return (React.createElement("div", null,
@@ -13,27 +61,41 @@ function CodeSnippets({ children }) {
13
61
  React.createElement("option", { value: "ts" }, "Typescript"))),
14
62
  children));
15
63
  }
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!');
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*/];
25
89
  }
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"),
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"),
33
94
  children));
34
95
  }
35
96
  // Show/hide TypeScript sections (code and/or plain)
36
- function TypescriptOnly({ children }) {
37
- const [selectedLang] = useSelectedLanguage();
97
+ function TypescriptOnly(_a) {
98
+ var children = _a.children;
99
+ var selectedLang = useSelectedLanguage()[0];
38
100
  return React.createElement("div", { style: { display: selectedLang === 'ts' ? 'block' : 'none' } }, children);
39
101
  }
@@ -1,5 +1,6 @@
1
1
  export { Comment };
2
2
  import React from 'react';
3
- function Comment({ children }) {
3
+ function Comment(_a) {
4
+ var children = _a.children;
4
5
  return React.createElement(React.Fragment, null);
5
6
  }
@@ -2,23 +2,25 @@ export { FileRemoved };
2
2
  export { FileAdded };
3
3
  import React from 'react';
4
4
  // Styling defined in src/css/code/diff.css
5
- const classRemoved = [
5
+ var classRemoved = [
6
6
  //
7
7
  'diff-entire-file',
8
8
  'diff-entire-file-removed',
9
9
  ].join(' ');
10
- const classAdded = [
10
+ var classAdded = [
11
11
  //
12
12
  'diff-entire-file',
13
13
  'diff-entire-file-added',
14
14
  ].join(' ');
15
- function FileRemoved({ children }) {
15
+ function FileRemoved(_a) {
16
+ var children = _a.children;
16
17
  return React.createElement("div", { className: classRemoved },
17
18
  " ",
18
19
  children,
19
20
  " ");
20
21
  }
21
- function FileAdded({ children }) {
22
+ function FileAdded(_a) {
23
+ var children = _a.children;
22
24
  return React.createElement("div", { className: classAdded },
23
25
  " ",
24
26
  children,
@@ -1,7 +1,8 @@
1
1
  export { HorizontalLine };
2
2
  import React from 'react';
3
3
  import { cls } from '../utils/cls';
4
- function HorizontalLine({ primary }) {
4
+ function HorizontalLine(_a) {
5
+ var primary = _a.primary;
5
6
  return (React.createElement("div", { className: cls(primary && 'primary'), style: { textAlign: 'center' } },
6
7
  React.createElement("hr", { style: {
7
8
  display: 'inline-block',
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
2
  import { assert } from '../utils/server';
3
3
  export { ImportMeta };
4
- function ImportMeta({ prop }) {
4
+ function ImportMeta(_a) {
5
+ var prop = _a.prop;
5
6
  assert(!prop.startsWith('import'));
6
7
  assert(!prop.startsWith('.'));
7
- const text = 'imp' + 'ort.meta.' + prop;
8
+ var text = 'imp' + 'ort.meta.' + prop;
8
9
  return React.createElement("code", null, text);
9
10
  }
@@ -1,22 +1,31 @@
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
+ };
1
12
  export { Link };
2
13
  import React from 'react';
3
14
  import { usePageContext } from '../renderer/usePageContext';
4
15
  import { assert, assertUsage, assertWarning, determineSectionTitle, determineSectionUrlHash } from '../utils/server';
5
16
  import { parseMarkdownMini } from '../parseMarkdownMini';
6
17
  import pc from '@brillout/picocolors';
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 '#'`);
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 '#'"));
10
22
  assertUsage(!text || !children, 'Cannot use both `text` or `children`');
11
23
  // assertWarning(!text, 'prop `text` is deprecated')
12
- text = text ?? children;
13
- const linkTextData = getLinkTextData({ href, pageContext, doNotInferSectionTitle, noWarning });
24
+ text = text !== null && text !== void 0 ? text : children;
25
+ var linkTextData = getLinkTextData({ href: href, pageContext: pageContext, doNotInferSectionTitle: doNotInferSectionTitle, noWarning: noWarning });
14
26
  if (!text) {
15
27
  if (linkTextData) {
16
- text = getLinkText({
17
- noBreadcrumb,
18
- ...linkTextData,
19
- });
28
+ text = getLinkText(__assign({ noBreadcrumb: noBreadcrumb }, linkTextData));
20
29
  }
21
30
  else {
22
31
  text = 'LINK-TARGET-NOT-FOUND';
@@ -24,10 +33,12 @@ function Link({ href, text, noBreadcrumb, doNotInferSectionTitle, noWarning, chi
24
33
  }
25
34
  return React.createElement("a", { href: href }, text);
26
35
  }
27
- function getLinkText({ noBreadcrumb, linkData, sectionTitle, isLinkOnSamePage, }) {
28
- const breadcrumbParts = [];
36
+ function getLinkText(_a) {
37
+ var _b;
38
+ var noBreadcrumb = _a.noBreadcrumb, linkData = _a.linkData, sectionTitle = _a.sectionTitle, isLinkOnSamePage = _a.isLinkOnSamePage;
39
+ var breadcrumbParts = [];
29
40
  if (linkData.linkBreadcrumb) {
30
- breadcrumbParts.push(...(linkData.linkBreadcrumb ?? []).slice().reverse().map(parseMarkdownMini));
41
+ breadcrumbParts.push.apply(breadcrumbParts, ((_b = linkData.linkBreadcrumb) !== null && _b !== void 0 ? _b : []).slice().reverse().map(parseMarkdownMini));
31
42
  }
32
43
  breadcrumbParts.push(parseMarkdownMini(linkData.title));
33
44
  if (sectionTitle)
@@ -35,32 +46,33 @@ function getLinkText({ noBreadcrumb, linkData, sectionTitle, isLinkOnSamePage, }
35
46
  if (noBreadcrumb || isLinkOnSamePage) {
36
47
  return breadcrumbParts[breadcrumbParts.length - 1];
37
48
  }
38
- return (React.createElement(React.Fragment, null, breadcrumbParts.map((title, i) => {
39
- const seperator = i === 0 ? React.createElement(React.Fragment, null) : ' > ';
49
+ return (React.createElement(React.Fragment, null, breadcrumbParts.map(function (title, i) {
50
+ var seperator = i === 0 ? React.createElement(React.Fragment, null) : ' > ';
40
51
  return (React.createElement(React.Fragment, { key: i },
41
52
  seperator,
42
53
  title));
43
54
  })));
44
55
  }
45
- function getLinkTextData({ href, pageContext, doNotInferSectionTitle, noWarning, }) {
46
- const { hrefPathname, hrefHash } = parseHref(href);
47
- const linkData = findLinkData(hrefPathname || pageContext.urlPathname, { pageContext, noWarning });
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 });
48
60
  if (!linkData)
49
61
  return null;
50
- const isLinkOnSamePage = linkData.url === pageContext.urlPathname;
62
+ var isLinkOnSamePage = linkData.url === pageContext.urlPathname;
51
63
  if (!hrefPathname)
52
64
  assert(isLinkOnSamePage);
53
- let sectionTitle = null;
65
+ var sectionTitle = null;
54
66
  if (hrefHash) {
55
67
  assert(!hrefHash.startsWith('#'));
56
68
  if (isLinkOnSamePage) {
57
- const linkDataPageSection = findLinkData(`#${hrefHash}`, { pageContext, noWarning });
69
+ var linkDataPageSection = findLinkData("#".concat(hrefHash), { pageContext: pageContext, noWarning: noWarning });
58
70
  if (!linkDataPageSection)
59
71
  return null;
60
72
  sectionTitle = parseMarkdownMini(linkDataPageSection.title);
61
73
  }
62
74
  else if ('sectionTitles' in linkData && linkData.sectionTitles) {
63
- linkData.sectionTitles.forEach((title) => {
75
+ linkData.sectionTitles.forEach(function (title) {
64
76
  if (determineSectionUrlHash(title) === hrefHash) {
65
77
  sectionTitle = parseMarkdownMini(title);
66
78
  }
@@ -68,28 +80,32 @@ function getLinkTextData({ href, pageContext, doNotInferSectionTitle, noWarning,
68
80
  }
69
81
  if (!sectionTitle) {
70
82
  if (doNotInferSectionTitle) {
71
- assertWarning(false, `Page section title not found for <Link href="\`${href}\`" doNotInferSectionTitle={true} />.`);
83
+ assertWarning(false, "Page section title not found for <Link href=\"`".concat(href, "`\" doNotInferSectionTitle={true} />."));
72
84
  return null;
73
85
  }
74
86
  sectionTitle = React.createElement(React.Fragment, null, determineSectionTitle(href));
75
87
  }
76
88
  }
77
- return { linkData, sectionTitle, isLinkOnSamePage };
89
+ return { linkData: linkData, sectionTitle: sectionTitle, isLinkOnSamePage: isLinkOnSamePage };
78
90
  }
79
- function findLinkData(href, { pageContext, noWarning }) {
91
+ function findLinkData(href, _a) {
92
+ var pageContext = _a.pageContext, noWarning = _a.noWarning;
80
93
  assert(href.startsWith('/') || href.startsWith('#'));
81
- const { linksAll } = pageContext.resolved;
82
- const linkData = linksAll.find(({ url }) => href === url);
94
+ var linksAll = pageContext.resolved.linksAll;
95
+ var linkData = linksAll.find(function (_a) {
96
+ var url = _a.url;
97
+ return href === url;
98
+ });
83
99
  if (href.startsWith('#')) {
84
100
  if (!noWarning) {
85
- assertWarning(linkData, `Couldn't find ${href} in ${pageContext.urlPathname}, does it exist?`);
101
+ assertWarning(linkData, "Couldn't find ".concat(href, " in ").concat(pageContext.urlPathname, ", does it exist?"));
86
102
  }
87
103
  }
88
104
  else {
89
105
  if (!noWarning) {
90
106
  assertWarning(linkData, [
91
- `Couldn't find page with URL ${pc.bold(href)}`,
92
- `— did you define it in`,
107
+ "Couldn't find page with URL ".concat(pc.bold(href)),
108
+ "\u2014 did you define it in",
93
109
  [
94
110
  pc.cyan('docpress.config.js'),
95
111
  pc.dim('#{'),
@@ -102,16 +118,16 @@ function findLinkData(href, { pageContext, noWarning }) {
102
118
  ].join(' '));
103
119
  }
104
120
  }
105
- return linkData ?? null;
121
+ return linkData !== null && linkData !== void 0 ? linkData : null;
106
122
  }
107
123
  function parseHref(href) {
108
- let hrefHash = null;
109
- let hrefPathname = null;
124
+ var hrefHash = null;
125
+ var hrefPathname = null;
110
126
  if (!href.includes('#')) {
111
127
  hrefPathname = href;
112
128
  }
113
129
  else {
114
- const [partsFirst, ...partsRest] = href.split('#');
130
+ var _a = href.split('#'), partsFirst = _a[0], partsRest = _a.slice(1);
115
131
  if (partsFirst) {
116
132
  hrefPathname = partsFirst;
117
133
  }
@@ -122,5 +138,5 @@ function parseHref(href) {
122
138
  // Text highlight links e,g. #metadata:~:text=global%20or%20local.-,Global%20metadata,-.
123
139
  if (hrefHash)
124
140
  hrefHash = hrefHash.split(':~:text')[0];
125
- return { hrefPathname, hrefHash };
141
+ return { hrefPathname: hrefPathname, hrefHash: hrefHash };
126
142
  }