vitepress 2.0.0-alpha.5 → 2.0.0-alpha.7
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/dist/client/app/composables/copyCode.js +8 -6
- package/dist/client/app/router.js +9 -4
- package/dist/client/index.d.ts +1 -0
- package/dist/client/shared.js +1 -1
- package/dist/client/theme-default/components/VPLocalSearchBox.vue +4 -0
- package/dist/client/theme-default/components/VPNavBarSearch.vue +1 -1
- package/dist/client/theme-default/styles/components/vp-doc.css +2 -0
- package/dist/node/{chunk-CJIxUApD.js → chunk-CWIFpuXB.js} +1798 -1887
- package/dist/node/cli.js +3 -2
- package/dist/node/index.d.ts +25 -26
- package/dist/node/index.js +26 -37
- package/package.json +38 -33
- package/types/shared.d.ts +1 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { inBrowser } from 'vitepress';
|
|
2
|
+
const shellRE = /language-(shellscript|shell|bash|sh|zsh)/;
|
|
3
|
+
const ignoredNodes = ['.vp-copy-ignore', '.diff.remove'].join(', ');
|
|
2
4
|
export function useCopyCode() {
|
|
3
5
|
if (inBrowser) {
|
|
4
6
|
const timeoutIdMap = new WeakMap();
|
|
@@ -6,17 +8,17 @@ export function useCopyCode() {
|
|
|
6
8
|
const el = e.target;
|
|
7
9
|
if (el.matches('div[class*="language-"] > button.copy')) {
|
|
8
10
|
const parent = el.parentElement;
|
|
9
|
-
const sibling = el.nextElementSibling?.nextElementSibling;
|
|
11
|
+
const sibling = el.nextElementSibling?.nextElementSibling; // <pre> tag
|
|
10
12
|
if (!parent || !sibling) {
|
|
11
13
|
return;
|
|
12
14
|
}
|
|
13
|
-
const isShell =
|
|
14
|
-
const ignoredNodes = ['.vp-copy-ignore', '.diff.remove'];
|
|
15
|
+
const isShell = shellRE.test(parent.className);
|
|
15
16
|
// Clone the node and remove the ignored nodes
|
|
16
17
|
const clone = sibling.cloneNode(true);
|
|
17
|
-
clone
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
clone.querySelectorAll(ignoredNodes).forEach((node) => node.remove());
|
|
19
|
+
// remove extra newlines left after removing ignored nodes (affecting textContent because it is inside `<pre>`)
|
|
20
|
+
// doesn't affect the newlines already in the code because they are rendered as `\n<span class="line"></span>`
|
|
21
|
+
clone.innerHTML = clone.innerHTML.replace(/\n+/g, '\n');
|
|
20
22
|
let text = clone.textContent || '';
|
|
21
23
|
if (isShell) {
|
|
22
24
|
text = text.replace(/^ *(\$|>) /gm, '').trim();
|
|
@@ -222,7 +222,7 @@ function normalizeHref(href) {
|
|
|
222
222
|
}
|
|
223
223
|
return url.pathname + url.search + url.hash;
|
|
224
224
|
}
|
|
225
|
-
async function changeRoute(href, { smoothScroll = false, initialLoad = false } = {}) {
|
|
225
|
+
async function changeRoute(href, { smoothScroll = false, initialLoad = false, replace = false } = {}) {
|
|
226
226
|
const loc = normalizeHref(location.href);
|
|
227
227
|
const nextUrl = new URL(href, location.origin);
|
|
228
228
|
const currentUrl = new URL(loc, location.origin);
|
|
@@ -233,9 +233,14 @@ async function changeRoute(href, { smoothScroll = false, initialLoad = false } =
|
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
235
|
else {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
236
|
+
if (replace) {
|
|
237
|
+
history.replaceState({}, '', href);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
// save scroll position before changing URL
|
|
241
|
+
history.replaceState({ scrollPosition: window.scrollY }, '');
|
|
242
|
+
history.pushState({}, '', href);
|
|
243
|
+
}
|
|
239
244
|
if (nextUrl.pathname === currentUrl.pathname) {
|
|
240
245
|
// scroll between hash anchors on the same page, avoid duplicate entries
|
|
241
246
|
if (nextUrl.hash !== currentUrl.hash) {
|
package/dist/client/index.d.ts
CHANGED
package/dist/client/shared.js
CHANGED
|
@@ -171,7 +171,7 @@ function resolveAdditionalConfig({ additionalConfig }, path) {
|
|
|
171
171
|
if (additionalConfig === undefined)
|
|
172
172
|
return [];
|
|
173
173
|
if (typeof additionalConfig === 'function')
|
|
174
|
-
return additionalConfig(path);
|
|
174
|
+
return additionalConfig(path) ?? [];
|
|
175
175
|
const configs = [];
|
|
176
176
|
const segments = path.split('/').slice(0, -1); // remove file name
|
|
177
177
|
while (segments.length) {
|
|
@@ -53,7 +53,7 @@ onMounted(() => {
|
|
|
53
53
|
|
|
54
54
|
const handleSearchHotKey = (event: KeyboardEvent) => {
|
|
55
55
|
if (
|
|
56
|
-
(event.key
|
|
56
|
+
(event.key?.toLowerCase() === 'k' && (event.metaKey || event.ctrlKey)) ||
|
|
57
57
|
(!isEditingContent(event) && event.key === '/')
|
|
58
58
|
) {
|
|
59
59
|
event.preventDefault()
|