@brillout/docpress 0.15.10 → 0.15.11
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 +60 -0
- package/components/CodeSnippets.css +78 -0
- package/components/CodeSnippets.tsx +50 -0
- package/components/Pre.css +51 -0
- package/components/Pre.tsx +72 -0
- package/components/index.ts +1 -0
- package/components/useMDXComponents.tsx +13 -0
- package/css/button.css +23 -0
- package/css/code.css +3 -21
- package/css/index.css +1 -0
- package/css/tooltip.css +10 -2
- 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 +50 -0
- package/dist/components/CodeSnippets.d.ts +11 -0
- package/dist/components/CodeSnippets.js +35 -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 -63
- package/dist/parseMarkdownMini.js +5 -17
- package/dist/parsePageSections.js +41 -82
- package/dist/rehypeMetaToProps.d.ts +19 -0
- package/dist/rehypeMetaToProps.js +62 -0
- package/dist/remarkDetype.d.ts +4 -0
- package/dist/remarkDetype.js +146 -0
- package/dist/renderer/usePageContext.js +6 -7
- package/dist/resolvePageContext.js +103 -110
- 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 +12 -7
- package/index.ts +15 -5
- package/package.json +5 -1
- package/rehypeMetaToProps.ts +69 -0
- package/remarkDetype.ts +172 -0
- package/resolvePageContext.ts +19 -15
- package/tsconfig.json +2 -1
- package/vite.config.ts +9 -4
|
@@ -1,75 +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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
-
if (ar || !(i in from)) {
|
|
15
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
-
ar[i] = from[i];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
-
};
|
|
21
1
|
export { resolvePageContext };
|
|
22
|
-
import { assert } from './utils/assert';
|
|
2
|
+
import { assert, assertUsage } from './utils/assert';
|
|
23
3
|
import { jsxToTextContent } from './utils/jsxToTextContent';
|
|
24
4
|
import pc from '@brillout/picocolors';
|
|
25
5
|
import { parseMarkdownMini } from './parseMarkdownMini';
|
|
26
6
|
import { determineNavItemsColumnLayout } from './determineNavItemsColumnLayout';
|
|
27
7
|
function resolvePageContext(pageContext) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var pageSections = (_a = pageContext.config.pageSectionsExport) !== null && _a !== void 0 ? _a : [];
|
|
8
|
+
const config = pageContext.globalContext.config.docpress;
|
|
9
|
+
const { urlPathname } = pageContext;
|
|
10
|
+
const pageSections = pageContext.config.pageSectionsExport ?? [];
|
|
32
11
|
{
|
|
33
|
-
|
|
34
|
-
assertHeadingsDefinition(
|
|
12
|
+
const { headings, headingsDetached } = config;
|
|
13
|
+
assertHeadingsDefinition([...headings, ...headingsDetached]);
|
|
35
14
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
15
|
+
const ret = getHeadingsResolved(config);
|
|
16
|
+
const { headingsDetachedResolved } = ret;
|
|
17
|
+
let { headingsResolved } = ret;
|
|
18
|
+
const { activeHeading, isDetachedPage, activeCategoryName } = getActiveHeading(headingsResolved, headingsDetachedResolved, urlPathname);
|
|
19
|
+
const { documentTitle, isLandingPage, pageTitle } = getTitles(activeHeading, urlPathname, config);
|
|
20
|
+
const pageSectionsResolved = getPageSectionsResolved(pageSections, activeHeading);
|
|
21
|
+
const linksGlobal = [
|
|
22
|
+
...headingsResolved.map(headingToLinkData),
|
|
23
|
+
...headingsDetachedResolved.map(headingToLinkData),
|
|
24
|
+
];
|
|
25
|
+
const linksPage = pageSectionsResolved.map(pageSectionToLinkData);
|
|
26
|
+
const linksAll = [...linksPage, ...linksGlobal];
|
|
27
|
+
let navItemsAll;
|
|
28
|
+
let navItemsDetached;
|
|
47
29
|
{
|
|
48
|
-
|
|
49
|
-
.filter(
|
|
30
|
+
const navItemsPageSections = pageSectionsResolved
|
|
31
|
+
.filter((pageSection) => pageSection.pageSectionLevel === 2)
|
|
50
32
|
.map(pageSectionToNavItem);
|
|
51
33
|
navItemsAll = headingsResolved.map(headingToNavItem);
|
|
52
34
|
determineNavItemsColumnLayout(navItemsAll);
|
|
53
35
|
if (isDetachedPage) {
|
|
54
|
-
navItemsDetached =
|
|
36
|
+
navItemsDetached = [headingToNavItem(activeHeading), ...navItemsPageSections];
|
|
55
37
|
}
|
|
56
38
|
else {
|
|
57
|
-
|
|
58
|
-
assert(
|
|
59
|
-
navItemsPageSections.forEach(
|
|
60
|
-
navItemsAll.splice(
|
|
39
|
+
const activeHeadingIndex = navItemsAll.findIndex((navItem) => navItem.url === urlPathname);
|
|
40
|
+
assert(activeHeadingIndex >= 0);
|
|
41
|
+
navItemsPageSections.forEach((navItem, i) => {
|
|
42
|
+
navItemsAll.splice(activeHeadingIndex + 1 + i, 0, navItem);
|
|
61
43
|
});
|
|
62
44
|
}
|
|
63
45
|
}
|
|
64
|
-
|
|
65
|
-
navItemsAll
|
|
66
|
-
navItemsDetached
|
|
46
|
+
const resolved = {
|
|
47
|
+
navItemsAll,
|
|
48
|
+
navItemsDetached,
|
|
67
49
|
pageDesign: activeHeading.pageDesign,
|
|
68
|
-
linksAll
|
|
69
|
-
isLandingPage
|
|
70
|
-
pageTitle
|
|
71
|
-
documentTitle
|
|
72
|
-
activeCategoryName
|
|
50
|
+
linksAll,
|
|
51
|
+
isLandingPage,
|
|
52
|
+
pageTitle,
|
|
53
|
+
documentTitle,
|
|
54
|
+
activeCategoryName,
|
|
73
55
|
};
|
|
74
56
|
return resolved;
|
|
75
57
|
}
|
|
@@ -109,106 +91,117 @@ function pageSectionToLinkData(pageSection) {
|
|
|
109
91
|
};
|
|
110
92
|
}
|
|
111
93
|
function getTitles(activeHeading, urlPathname, config) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
94
|
+
const isLandingPage = urlPathname === '/';
|
|
95
|
+
const { title } = activeHeading;
|
|
96
|
+
let pageTitle = isLandingPage ? null : title;
|
|
97
|
+
let documentTitle = activeHeading.titleDocument || jsxToTextContent(parseMarkdownMini(title));
|
|
116
98
|
if (!isLandingPage) {
|
|
117
99
|
documentTitle += ' | ' + config.name;
|
|
118
100
|
}
|
|
119
101
|
if (isLandingPage) {
|
|
120
102
|
pageTitle = null;
|
|
121
103
|
}
|
|
122
|
-
return { documentTitle
|
|
104
|
+
return { documentTitle, isLandingPage, pageTitle };
|
|
123
105
|
}
|
|
124
106
|
function getActiveHeading(headingsResolved, headingsDetachedResolved, urlPathname) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
107
|
+
const URLs = '\n' +
|
|
108
|
+
[...headingsResolved, ...headingsDetachedResolved]
|
|
109
|
+
.filter(Boolean)
|
|
110
|
+
.map((h) => h.url)
|
|
111
|
+
.sort()
|
|
112
|
+
.map((url) => ` ${url}`)
|
|
113
|
+
.join('\n');
|
|
114
|
+
const errNotFound = `URL ${pc.bold(urlPathname)} not found in following URLs:${URLs}`;
|
|
115
|
+
const errFoundTwice = `URL ${pc.bold(urlPathname)} found twice in following URLs:${URLs}`;
|
|
116
|
+
let activeHeading = null;
|
|
117
|
+
let activeCategoryName = 'Miscellaneous';
|
|
118
|
+
let headingCategory;
|
|
129
119
|
assert(urlPathname);
|
|
130
|
-
for (
|
|
131
|
-
var heading = headingsResolved_1[_i];
|
|
120
|
+
for (const heading of headingsResolved) {
|
|
132
121
|
if (heading.level === 1) {
|
|
133
122
|
headingCategory = heading.title;
|
|
134
123
|
}
|
|
135
124
|
if (heading.url === urlPathname) {
|
|
125
|
+
assertUsage(!activeHeading, errFoundTwice);
|
|
136
126
|
activeHeading = heading;
|
|
137
127
|
assert(headingCategory);
|
|
138
128
|
activeCategoryName = headingCategory;
|
|
139
|
-
assert(heading.level === 2, { pageUrl: urlPathname, heading
|
|
129
|
+
assert(heading.level === 2, { pageUrl: urlPathname, heading });
|
|
140
130
|
break;
|
|
141
131
|
}
|
|
142
132
|
}
|
|
143
|
-
|
|
144
|
-
if (!activeHeading) {
|
|
145
|
-
activeHeading = (_a = headingsDetachedResolved.find(function (_a) {
|
|
146
|
-
var url = _a.url;
|
|
147
|
-
return urlPathname === url;
|
|
148
|
-
})) !== null && _a !== void 0 ? _a : null;
|
|
149
|
-
}
|
|
133
|
+
const isDetachedPage = !activeHeading;
|
|
150
134
|
if (!activeHeading) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
.join('\n'),
|
|
158
|
-
].join('\n'));
|
|
135
|
+
const found = headingsDetachedResolved.filter(({ url }) => urlPathname === url);
|
|
136
|
+
if (found.length > 0) {
|
|
137
|
+
assertUsage(found.length === 1, errFoundTwice);
|
|
138
|
+
assertUsage(!activeHeading, errFoundTwice);
|
|
139
|
+
activeHeading = found[0];
|
|
140
|
+
}
|
|
159
141
|
}
|
|
142
|
+
assertUsage(activeHeading, errNotFound);
|
|
160
143
|
if (activeHeading.category)
|
|
161
144
|
activeCategoryName = activeHeading.category;
|
|
162
|
-
return { activeHeading
|
|
145
|
+
return { activeHeading, isDetachedPage, activeCategoryName };
|
|
163
146
|
}
|
|
164
147
|
function getPageSectionsResolved(pageSections, activeHeading) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
url: url,
|
|
148
|
+
const pageSectionsResolved = pageSections.map((pageSection) => {
|
|
149
|
+
const { pageSectionTitle } = pageSection;
|
|
150
|
+
const url = pageSection.pageSectionId === null ? null : '#' + pageSection.pageSectionId;
|
|
151
|
+
const pageSectionResolved = {
|
|
152
|
+
url,
|
|
171
153
|
title: pageSectionTitle,
|
|
172
|
-
linkBreadcrumb:
|
|
154
|
+
linkBreadcrumb: [activeHeading.title, ...(activeHeading.linkBreadcrumb ?? [])],
|
|
173
155
|
titleInNav: pageSectionTitle,
|
|
174
156
|
pageSectionLevel: pageSection.pageSectionLevel,
|
|
175
157
|
};
|
|
176
158
|
return pageSectionResolved;
|
|
177
159
|
});
|
|
178
|
-
if (activeHeading
|
|
179
|
-
activeHeading.sectionTitles.forEach(
|
|
180
|
-
|
|
181
|
-
assert(pageSectionTitles.includes(sectionTitle), { pageHeadingTitles: pageSectionTitles, sectionTitle
|
|
160
|
+
if (activeHeading?.sectionTitles) {
|
|
161
|
+
activeHeading.sectionTitles.forEach((sectionTitle) => {
|
|
162
|
+
const pageSectionTitles = pageSections.map((h) => h.pageSectionTitle);
|
|
163
|
+
assert(pageSectionTitles.includes(sectionTitle), { pageHeadingTitles: pageSectionTitles, sectionTitle });
|
|
182
164
|
});
|
|
183
165
|
}
|
|
184
166
|
return pageSectionsResolved;
|
|
185
167
|
}
|
|
186
168
|
function getHeadingsResolved(config) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
169
|
+
const headingsWithoutBreadcrumb = config.headings.map((heading) => {
|
|
170
|
+
const titleInNav = heading.titleInNav || heading.title;
|
|
171
|
+
const headingResolved = {
|
|
172
|
+
...heading,
|
|
173
|
+
titleInNav,
|
|
174
|
+
};
|
|
190
175
|
return headingResolved;
|
|
191
176
|
});
|
|
192
|
-
|
|
193
|
-
headingsWithoutBreadcrumb.forEach(
|
|
194
|
-
|
|
195
|
-
headingsResolved.push(
|
|
177
|
+
const headingsResolved = [];
|
|
178
|
+
headingsWithoutBreadcrumb.forEach((heading) => {
|
|
179
|
+
const linkBreadcrumb = getHeadingsBreadcrumb(heading, headingsResolved);
|
|
180
|
+
headingsResolved.push({
|
|
181
|
+
...heading,
|
|
182
|
+
linkBreadcrumb,
|
|
183
|
+
});
|
|
196
184
|
});
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
assert(headingsResolved.find(
|
|
200
|
-
return
|
|
185
|
+
const headingsDetachedResolved = config.headingsDetached.map((headingsDetached) => {
|
|
186
|
+
const { url } = headingsDetached;
|
|
187
|
+
assert(headingsResolved.find((heading) => heading.url === url) === undefined, `remove ${headingsDetached.url} from headingsDetached`);
|
|
188
|
+
return {
|
|
189
|
+
...headingsDetached,
|
|
190
|
+
level: 2,
|
|
191
|
+
titleInNav: headingsDetached.title,
|
|
192
|
+
linkBreadcrumb: null,
|
|
193
|
+
};
|
|
201
194
|
});
|
|
202
|
-
return { headingsResolved
|
|
195
|
+
return { headingsResolved, headingsDetachedResolved };
|
|
203
196
|
}
|
|
204
197
|
function getHeadingsBreadcrumb(heading, headings) {
|
|
205
|
-
|
|
206
|
-
|
|
198
|
+
const linkBreadcrumb = [];
|
|
199
|
+
let levelCurrent = heading.level;
|
|
207
200
|
headings
|
|
208
201
|
.slice()
|
|
209
202
|
.reverse()
|
|
210
|
-
.forEach(
|
|
211
|
-
|
|
203
|
+
.forEach((parentCandidate) => {
|
|
204
|
+
const isParent = parentCandidate.level < levelCurrent;
|
|
212
205
|
if (isParent) {
|
|
213
206
|
levelCurrent = parentCandidate.level;
|
|
214
207
|
linkBreadcrumb.push(parentCandidate.title);
|
|
@@ -217,9 +210,9 @@ function getHeadingsBreadcrumb(heading, headings) {
|
|
|
217
210
|
return linkBreadcrumb;
|
|
218
211
|
}
|
|
219
212
|
function assertHeadingsDefinition(headings) {
|
|
220
|
-
headings.forEach(
|
|
213
|
+
headings.forEach((heading) => {
|
|
221
214
|
if (heading.url) {
|
|
222
|
-
|
|
215
|
+
const { url } = heading;
|
|
223
216
|
assert(url.startsWith('/'));
|
|
224
217
|
}
|
|
225
218
|
});
|
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
// Let's eventually remove this. Telefunc is still using this as of 2024-12.
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
import React from 'react';
|
|
14
3
|
import { assert } from '../assert';
|
|
15
4
|
import { iconMechanicalArm, iconShield, iconTypescript, iconEngine } from './assets';
|
|
16
5
|
export { Emoji };
|
|
17
|
-
function Emoji(
|
|
18
|
-
|
|
19
|
-
var emoji =
|
|
6
|
+
function Emoji({ name, style }) {
|
|
7
|
+
const emoji =
|
|
20
8
|
// ***
|
|
21
9
|
// U+26A0
|
|
22
10
|
// https://emojipedia.org/warning/
|
|
@@ -165,22 +153,26 @@ function Emoji(_a) {
|
|
|
165
153
|
(name === 'left-right-arrow' && Unicode(0xFE0F)) ||
|
|
166
154
|
(name === 'left-right-arrow' && Unicode(0xFE0F, { fontFamily: 'reset' })) ||
|
|
167
155
|
======================== */
|
|
168
|
-
assert(emoji, { name
|
|
156
|
+
assert(emoji, { name });
|
|
169
157
|
return emoji;
|
|
170
158
|
function Unicode(codePoint, styleAddendum) {
|
|
171
|
-
|
|
159
|
+
const text = String.fromCodePoint(codePoint);
|
|
172
160
|
if (style || styleAddendum) {
|
|
173
|
-
return React.createElement('span', { style:
|
|
161
|
+
return React.createElement('span', { style: { ...style, ...styleAddendum } }, text);
|
|
174
162
|
}
|
|
175
163
|
else {
|
|
176
164
|
return React.createElement(React.Fragment, null, text);
|
|
177
165
|
}
|
|
178
166
|
}
|
|
179
|
-
function Img(imgSrc, width) {
|
|
180
|
-
|
|
181
|
-
var props = {
|
|
167
|
+
function Img(imgSrc, width = '1.15em') {
|
|
168
|
+
const props = {
|
|
182
169
|
src: imgSrc,
|
|
183
|
-
style:
|
|
170
|
+
style: {
|
|
171
|
+
verticalAlign: 'text-top',
|
|
172
|
+
fontSize: '1em',
|
|
173
|
+
width,
|
|
174
|
+
...style,
|
|
175
|
+
},
|
|
184
176
|
};
|
|
185
177
|
return React.createElement('img', props);
|
|
186
178
|
}
|
package/dist/utils/assert.js
CHANGED
|
@@ -2,8 +2,8 @@ export { assert };
|
|
|
2
2
|
export { assertUsage };
|
|
3
3
|
export { assertWarning };
|
|
4
4
|
import { getGlobalObject } from './getGlobalObject.js';
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const devModeKey = '__docpress_dev_mode';
|
|
6
|
+
const globalObject = getGlobalObject('utils/assert.ts', {
|
|
7
7
|
alreadyLogged: new Set(),
|
|
8
8
|
});
|
|
9
9
|
if (isBrowser()) {
|
|
@@ -18,7 +18,7 @@ if (isBrowser()) {
|
|
|
18
18
|
.join(' '));
|
|
19
19
|
}
|
|
20
20
|
if (isDevMode()) {
|
|
21
|
-
window.onerror =
|
|
21
|
+
window.onerror = (err) => {
|
|
22
22
|
window.alert(err);
|
|
23
23
|
window.onerror = null;
|
|
24
24
|
};
|
|
@@ -27,25 +27,25 @@ function assert(condition, debugInfo) {
|
|
|
27
27
|
if (condition) {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
const hasDebugInfo = debugInfo !== undefined;
|
|
31
31
|
if (hasDebugInfo) {
|
|
32
32
|
console.log(debugInfo);
|
|
33
33
|
if (typeof debugInfo === 'object') {
|
|
34
34
|
debugInfo = JSON.stringify(debugInfo);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
let errMsg = '[DocPress] Bug. Contact DocPress maintainer.';
|
|
38
38
|
if (hasDebugInfo) {
|
|
39
39
|
errMsg += ' Debug info: ' + String(debugInfo);
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
const err = new Error(errMsg);
|
|
42
42
|
throw err;
|
|
43
43
|
}
|
|
44
44
|
function assertUsage(condition, msg) {
|
|
45
45
|
if (condition) {
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
const err = new Error('[DocPress][Wrong Usage] ' + msg);
|
|
49
49
|
throw err;
|
|
50
50
|
}
|
|
51
51
|
function isBrowser() {
|
|
@@ -55,34 +55,32 @@ function isDevMode() {
|
|
|
55
55
|
return isBrowser() && (!!window.localStorage[devModeKey] || isLocalhost());
|
|
56
56
|
}
|
|
57
57
|
function isLocalhost() {
|
|
58
|
-
|
|
59
|
-
return ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.port) !== '';
|
|
58
|
+
return window?.location?.port !== '';
|
|
60
59
|
}
|
|
61
60
|
function toggleDevMode() {
|
|
62
61
|
if (isLocalhost())
|
|
63
62
|
throw new Error('On localhost DEV MODE is always on.');
|
|
64
|
-
|
|
63
|
+
const isEnabled = () => window.localStorage[devModeKey];
|
|
65
64
|
if (!isEnabled()) {
|
|
66
65
|
window.localStorage[devModeKey] = 'true';
|
|
67
66
|
}
|
|
68
67
|
else {
|
|
69
68
|
delete window.localStorage[devModeKey];
|
|
70
69
|
}
|
|
71
|
-
console.log(
|
|
70
|
+
console.log(`DEV MODE ${isEnabled() ? 'enabled' : 'disabled'}`);
|
|
72
71
|
}
|
|
73
|
-
function assertWarning(condition, msg,
|
|
74
|
-
var _b = _a === void 0 ? {} : _a, _c = _b.onlyOnce, onlyOnce = _c === void 0 ? true : _c, showStackTrace = _b.showStackTrace;
|
|
72
|
+
function assertWarning(condition, msg, { onlyOnce = true, showStackTrace } = {}) {
|
|
75
73
|
if (condition) {
|
|
76
74
|
return;
|
|
77
75
|
}
|
|
78
|
-
|
|
76
|
+
const err = new Error(msg);
|
|
79
77
|
if (!import.meta.env.DEV) {
|
|
80
78
|
throw err;
|
|
81
79
|
}
|
|
82
80
|
else {
|
|
83
81
|
if (onlyOnce) {
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
const { alreadyLogged } = globalObject;
|
|
83
|
+
const key = onlyOnce === true ? msg : onlyOnce;
|
|
86
84
|
if (alreadyLogged.has(key))
|
|
87
85
|
return;
|
|
88
86
|
alreadyLogged.add(key);
|
package/dist/utils/cls.js
CHANGED
|
@@ -4,7 +4,7 @@ export { determineSectionTitle };
|
|
|
4
4
|
function determineSectionUrlHash(title) {
|
|
5
5
|
title = title.toLowerCase();
|
|
6
6
|
title = removeAccentsAndDiacritics(title);
|
|
7
|
-
|
|
7
|
+
const urlHash = title
|
|
8
8
|
// \u4E00-\u9FA5 are chinese characters, see https://github.com/brillout/docpress/pull/2
|
|
9
9
|
.split(/[^a-z0-9\u4E00-\u9FA5]+/)
|
|
10
10
|
.filter(Boolean)
|
|
@@ -20,11 +20,11 @@ function removeAccentsAndDiacritics(str) {
|
|
|
20
20
|
return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
|
21
21
|
}
|
|
22
22
|
function determineSectionTitle(urlWithHash) {
|
|
23
|
-
assert(urlWithHash.includes('#'), { urlWithHash
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
assert(urlWithHash.includes('#'), { urlWithHash });
|
|
24
|
+
const urlHash = urlWithHash.split('#')[1];
|
|
25
|
+
const title = urlHash
|
|
26
26
|
.split('-')
|
|
27
|
-
.map(
|
|
27
|
+
.map((word, i) => {
|
|
28
28
|
if (i === 0) {
|
|
29
29
|
return capitalizeFirstLetter(word);
|
|
30
30
|
}
|
package/dist/utils/filter.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { filter };
|
|
2
2
|
// https://stackoverflow.com/questions/66341757/typescript-how-to-filter-the-object
|
|
3
3
|
function filter(obj, predicate) {
|
|
4
|
-
|
|
5
|
-
Object.keys(obj).forEach(
|
|
4
|
+
const result = {};
|
|
5
|
+
Object.keys(obj).forEach((name) => {
|
|
6
6
|
if (predicate(obj[name], name)) {
|
|
7
7
|
result[name] = obj[name];
|
|
8
8
|
}
|
|
@@ -2,8 +2,8 @@ export function getGlobalObject(
|
|
|
2
2
|
// We use the filename as key; each `getGlobalObject()` call should live inside a file with a unique filename.
|
|
3
3
|
key, defaultValue) {
|
|
4
4
|
// @ts-ignore
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const globalObjectsAll = (globalThis[projectKey] = globalThis[projectKey] || {});
|
|
6
|
+
const globalObject = (globalObjectsAll[key] = globalObjectsAll[key] || defaultValue);
|
|
7
7
|
return globalObject;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
const projectKey = '_docpress';
|
package/dist/vite.config.js
CHANGED
|
@@ -5,15 +5,20 @@ import { parsePageSections } from './parsePageSections.js';
|
|
|
5
5
|
import rehypePrettyCode from 'rehype-pretty-code';
|
|
6
6
|
import remarkGfm from 'remark-gfm';
|
|
7
7
|
import { transformerNotationDiff } from '@shikijs/transformers';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
import { remarkDetype } from './remarkDetype.js';
|
|
9
|
+
import { rehypeMetaToProps } from './rehypeMetaToProps.js';
|
|
10
|
+
const root = process.cwd();
|
|
11
|
+
const prettyCode = [
|
|
12
|
+
rehypePrettyCode,
|
|
13
|
+
{ theme: 'github-light', keepBackground: false, transformers: [transformerNotationDiff()] },
|
|
14
|
+
];
|
|
15
|
+
const rehypePlugins = [prettyCode, [rehypeMetaToProps]];
|
|
16
|
+
const remarkPlugins = [remarkGfm, remarkDetype];
|
|
17
|
+
const config = {
|
|
18
|
+
root,
|
|
14
19
|
plugins: [
|
|
15
20
|
parsePageSections(),
|
|
16
|
-
mdx({ rehypePlugins
|
|
21
|
+
mdx({ rehypePlugins, remarkPlugins, providerImportSource: '@brillout/docpress' }),
|
|
17
22
|
// @vitejs/plugin-react-swc needs to be added *after* the mdx plugins
|
|
18
23
|
react(),
|
|
19
24
|
],
|
package/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**********/
|
|
2
|
+
/* PUBLIC */
|
|
3
|
+
/**********/
|
|
1
4
|
export {
|
|
2
5
|
CodeBlockTransformer,
|
|
3
6
|
Link,
|
|
@@ -6,16 +9,23 @@ export {
|
|
|
6
9
|
FileRemoved,
|
|
7
10
|
ImportMeta,
|
|
8
11
|
Emoji,
|
|
12
|
+
TypescriptOnly,
|
|
9
13
|
} from './components'
|
|
10
14
|
export { MenuToggle } from './Layout'
|
|
11
|
-
|
|
12
|
-
// The only place usePageContext() is used at:
|
|
13
|
-
// https://github.com/vikejs/vike/blob/0b1b109f64aafbed23a1c2ac2630e6146a270ec0/packages/vike.dev/components/CommunityNote.tsx#L4
|
|
14
|
-
export { usePageContext } from './renderer/usePageContext'
|
|
15
|
-
|
|
16
15
|
export * from './components/Note'
|
|
17
16
|
export * from './icons/index'
|
|
18
17
|
export { assert } from './utils/assert'
|
|
19
18
|
export { parseMarkdownMini } from './parseMarkdownMini'
|
|
20
19
|
export type { Config } from './types/Config'
|
|
21
20
|
export type { HeadingDefinition, HeadingDetachedDefinition } from './types/Heading'
|
|
21
|
+
// The only place usePageContext() is used at:
|
|
22
|
+
// https://github.com/vikejs/vike/blob/0b1b109f64aafbed23a1c2ac2630e6146a270ec0/packages/vike.dev/components/CommunityNote.tsx#L4
|
|
23
|
+
export { usePageContext } from './renderer/usePageContext'
|
|
24
|
+
|
|
25
|
+
// The following are used internally by DocPress — users (should) never use these exports
|
|
26
|
+
/************/
|
|
27
|
+
/* INTERNAL */
|
|
28
|
+
/************/
|
|
29
|
+
// We provide our own `useMDXComponents()` to enable MDX component injection by setting `providerImportSource` to '@brillout/docpress'.
|
|
30
|
+
// https://mdxjs.com/guides/injecting-components/
|
|
31
|
+
export { useMDXComponents } from './components/useMDXComponents'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brillout/docpress",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@brillout/picocolors": "^1.0.10",
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
"@mdx-js/rollup": "3.0.1",
|
|
12
12
|
"@shikijs/transformers": "1.2.0",
|
|
13
13
|
"@vitejs/plugin-react-swc": "^3.10.2",
|
|
14
|
+
"detype": "^1.1.3",
|
|
14
15
|
"rehype-pretty-code": "0.13.0",
|
|
15
16
|
"remark-gfm": "4.0.0",
|
|
16
17
|
"shiki": "1.2.0",
|
|
18
|
+
"unist-util-visit": "^5.0.0",
|
|
17
19
|
"vite": "^6.3.5"
|
|
18
20
|
},
|
|
19
21
|
"peerDependencies": {
|
|
@@ -58,6 +60,8 @@
|
|
|
58
60
|
},
|
|
59
61
|
"devDependencies": {
|
|
60
62
|
"@brillout/release-me": "^0.4.8",
|
|
63
|
+
"@types/hast": "^3.0.4",
|
|
64
|
+
"@types/mdast": "^4.0.4",
|
|
61
65
|
"@types/node": "^22.5.5",
|
|
62
66
|
"@types/react": "^18.3.8",
|
|
63
67
|
"@types/react-dom": "^18.3.0"
|