@vuepress/client 2.0.0-rc.0 → 2.0.0-rc.2
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/LICENSE +1 -1
- package/README.md +12 -0
- package/dist/app.d.ts +7 -0
- package/dist/app.js +56 -36
- package/dist/{chunk-DHNSDB55.js → chunk-PEQEPZ75.js} +9 -8
- package/dist/createVueAppFunction-YNGNKfE3.d.ts +9 -0
- package/dist/index.d.ts +64 -68
- package/dist/index.js +1 -1
- package/package.json +10 -7
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2018-present,
|
|
3
|
+
Copyright (c) 2018-present, VuePress Community
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @vuepress/client
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@vuepress/client)
|
|
4
|
+
[](https://github.com/vuepress/core/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
## Documentation
|
|
7
|
+
|
|
8
|
+
https://v2.vuepress.vuejs.org
|
|
9
|
+
|
|
10
|
+
## License
|
|
11
|
+
|
|
12
|
+
[MIT](https://github.com/vuepress/core/blob/main/LICENSE)
|
package/dist/app.d.ts
ADDED
package/dist/app.js
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
usePageLang,
|
|
19
19
|
usePageLayout,
|
|
20
20
|
withBase
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-PEQEPZ75.js";
|
|
22
22
|
|
|
23
23
|
// src/app.ts
|
|
24
24
|
import { clientConfigs } from "@internal/clientConfigs";
|
|
@@ -121,13 +121,10 @@ var setupGlobalComponents = (app) => {
|
|
|
121
121
|
};
|
|
122
122
|
|
|
123
123
|
// src/setupGlobalComputed.ts
|
|
124
|
-
import {
|
|
124
|
+
import { computedWithControl } from "@vueuse/core";
|
|
125
125
|
import { computed } from "vue";
|
|
126
126
|
var setupGlobalComputed = (app, router, clientConfigs2) => {
|
|
127
|
-
const routePath =
|
|
128
|
-
const routeLocale = computedEager(
|
|
129
|
-
() => resolvers.resolveRouteLocale(siteData.value.locales, routePath.value)
|
|
130
|
-
);
|
|
127
|
+
const routePath = computed(() => router.currentRoute.value.path);
|
|
131
128
|
const pageData = computedWithControl(
|
|
132
129
|
routePath,
|
|
133
130
|
() => router.currentRoute.value.meta._data
|
|
@@ -142,6 +139,9 @@ var setupGlobalComputed = (app, router, clientConfigs2) => {
|
|
|
142
139
|
};
|
|
143
140
|
}
|
|
144
141
|
const layouts = computed(() => resolvers.resolveLayouts(clientConfigs2));
|
|
142
|
+
const routeLocale = computed(
|
|
143
|
+
() => resolvers.resolveRouteLocale(siteData.value.locales, routePath.value)
|
|
144
|
+
);
|
|
145
145
|
const siteLocaleData = computed(
|
|
146
146
|
() => resolvers.resolveSiteLocaleData(siteData.value, routeLocale.value)
|
|
147
147
|
);
|
|
@@ -200,7 +200,7 @@ var setupGlobalComputed = (app, router, clientConfigs2) => {
|
|
|
200
200
|
|
|
201
201
|
// src/setupUpdateHead.ts
|
|
202
202
|
import { isPlainObject, isString } from "@vuepress/shared";
|
|
203
|
-
import { onMounted, provide,
|
|
203
|
+
import { onMounted, provide, useSSRContext, watch } from "vue";
|
|
204
204
|
var setupUpdateHead = () => {
|
|
205
205
|
const head = usePageHead();
|
|
206
206
|
const lang = usePageLang();
|
|
@@ -212,39 +212,55 @@ var setupUpdateHead = () => {
|
|
|
212
212
|
}
|
|
213
213
|
return;
|
|
214
214
|
}
|
|
215
|
-
|
|
216
|
-
const
|
|
215
|
+
let managedHeadElements = [];
|
|
216
|
+
const takeOverHeadElements = () => {
|
|
217
217
|
head.value.forEach((item) => {
|
|
218
|
-
const
|
|
219
|
-
if (
|
|
220
|
-
|
|
218
|
+
const headElement = queryHeadElement(item);
|
|
219
|
+
if (headElement) {
|
|
220
|
+
managedHeadElements.push(headElement);
|
|
221
221
|
}
|
|
222
222
|
});
|
|
223
223
|
};
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
224
|
+
const generateHeadElements = () => {
|
|
225
|
+
const result = [];
|
|
226
|
+
head.value.forEach((item) => {
|
|
227
|
+
const headElement = createHeadElement(item);
|
|
228
|
+
if (headElement) {
|
|
229
|
+
result.push(headElement);
|
|
229
230
|
}
|
|
230
231
|
});
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
232
|
+
return result;
|
|
233
|
+
};
|
|
234
|
+
const updateHead = () => {
|
|
235
|
+
document.documentElement.lang = lang.value;
|
|
236
|
+
const newHeadElements = generateHeadElements();
|
|
237
|
+
managedHeadElements.forEach((oldEl, oldIndex) => {
|
|
238
|
+
const matchedIndex = newHeadElements.findIndex(
|
|
239
|
+
(newEl) => oldEl.isEqualNode(newEl)
|
|
240
|
+
);
|
|
241
|
+
if (matchedIndex === -1) {
|
|
242
|
+
oldEl.remove();
|
|
243
|
+
delete managedHeadElements[oldIndex];
|
|
244
|
+
} else {
|
|
245
|
+
newHeadElements.splice(matchedIndex, 1);
|
|
237
246
|
}
|
|
238
247
|
});
|
|
248
|
+
newHeadElements.forEach((el) => document.head.appendChild(el));
|
|
249
|
+
managedHeadElements = [
|
|
250
|
+
// filter out empty deleted items
|
|
251
|
+
...managedHeadElements.filter((item) => !!item),
|
|
252
|
+
...newHeadElements
|
|
253
|
+
];
|
|
239
254
|
};
|
|
240
255
|
provide(updateHeadSymbol, updateHead);
|
|
241
256
|
onMounted(() => {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
257
|
+
if (!__VUEPRESS_DEV__) {
|
|
258
|
+
takeOverHeadElements();
|
|
259
|
+
}
|
|
260
|
+
watch(head, updateHead, { immediate: __VUEPRESS_DEV__ });
|
|
245
261
|
});
|
|
246
262
|
};
|
|
247
|
-
var
|
|
263
|
+
var queryHeadElement = ([
|
|
248
264
|
tagName,
|
|
249
265
|
attrs,
|
|
250
266
|
content = ""
|
|
@@ -259,11 +275,15 @@ var queryHeadTag = ([
|
|
|
259
275
|
return "";
|
|
260
276
|
}).join("");
|
|
261
277
|
const selector = `head > ${tagName}${attrsSelector}`;
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
278
|
+
const headElements = Array.from(
|
|
279
|
+
document.querySelectorAll(selector)
|
|
280
|
+
);
|
|
281
|
+
const matchedHeadElement = headElements.find(
|
|
282
|
+
(item) => item.innerText === content
|
|
283
|
+
);
|
|
284
|
+
return matchedHeadElement || null;
|
|
265
285
|
};
|
|
266
|
-
var
|
|
286
|
+
var createHeadElement = ([
|
|
267
287
|
tagName,
|
|
268
288
|
attrs,
|
|
269
289
|
content
|
|
@@ -271,20 +291,20 @@ var createHeadTag = ([
|
|
|
271
291
|
if (!isString(tagName)) {
|
|
272
292
|
return null;
|
|
273
293
|
}
|
|
274
|
-
const
|
|
294
|
+
const headElement = document.createElement(tagName);
|
|
275
295
|
if (isPlainObject(attrs)) {
|
|
276
296
|
Object.entries(attrs).forEach(([key, value]) => {
|
|
277
297
|
if (isString(value)) {
|
|
278
|
-
|
|
298
|
+
headElement.setAttribute(key, value);
|
|
279
299
|
} else if (value === true) {
|
|
280
|
-
|
|
300
|
+
headElement.setAttribute(key, "");
|
|
281
301
|
}
|
|
282
302
|
});
|
|
283
303
|
}
|
|
284
304
|
if (isString(content)) {
|
|
285
|
-
|
|
305
|
+
headElement.appendChild(document.createTextNode(content));
|
|
286
306
|
}
|
|
287
|
-
return
|
|
307
|
+
return headElement;
|
|
288
308
|
};
|
|
289
309
|
|
|
290
310
|
// src/app.ts
|
|
@@ -154,12 +154,7 @@ var useUpdateHead = () => {
|
|
|
154
154
|
};
|
|
155
155
|
|
|
156
156
|
// src/resolvers.ts
|
|
157
|
-
import {
|
|
158
|
-
dedupeHead,
|
|
159
|
-
isArray,
|
|
160
|
-
isString,
|
|
161
|
-
resolveLocalePath
|
|
162
|
-
} from "@vuepress/shared";
|
|
157
|
+
import { dedupeHead, isString, resolveLocalePath } from "@vuepress/shared";
|
|
163
158
|
import { reactive } from "vue";
|
|
164
159
|
|
|
165
160
|
// src/constants.ts
|
|
@@ -198,7 +193,7 @@ var resolvers = reactive({
|
|
|
198
193
|
resolvePageHead: (headTitle, frontmatter, siteLocale) => {
|
|
199
194
|
const description = isString(frontmatter.description) ? frontmatter.description : siteLocale.description;
|
|
200
195
|
const head = [
|
|
201
|
-
...isArray(frontmatter.head) ? frontmatter.head : [],
|
|
196
|
+
...Array.isArray(frontmatter.head) ? frontmatter.head : [],
|
|
202
197
|
...siteLocale.head,
|
|
203
198
|
["title", {}, headTitle],
|
|
204
199
|
["meta", { name: "description", content: description }]
|
|
@@ -245,7 +240,13 @@ var resolvers = reactive({
|
|
|
245
240
|
*/
|
|
246
241
|
resolveSiteLocaleData: (site, routeLocale) => ({
|
|
247
242
|
...site,
|
|
248
|
-
...site.locales[routeLocale]
|
|
243
|
+
...site.locales[routeLocale],
|
|
244
|
+
head: [
|
|
245
|
+
// when merging head, the locales head should be placed before root head
|
|
246
|
+
// to get higher priority
|
|
247
|
+
...site.locales[routeLocale]?.head ?? [],
|
|
248
|
+
...site.head ?? []
|
|
249
|
+
]
|
|
249
250
|
})
|
|
250
251
|
});
|
|
251
252
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,74 +1,9 @@
|
|
|
1
1
|
import { PageData, PageFrontmatter, HeadConfig, SiteData } from '@vuepress/shared';
|
|
2
2
|
export { PageData, PageFrontmatter, PageHeader, SiteData } from '@vuepress/shared';
|
|
3
3
|
import * as vue from 'vue';
|
|
4
|
-
import {
|
|
4
|
+
import { ComputedRef, InjectionKey, Ref, Component, App } from 'vue';
|
|
5
5
|
import { Router, RouteMeta } from 'vue-router';
|
|
6
|
-
|
|
7
|
-
declare const ClientOnly: vue.DefineComponent<{}, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
8
|
-
[key: string]: any;
|
|
9
|
-
}>[] | null | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.VNodeProps & vue.AllowedComponentProps & vue.ComponentCustomProps, Readonly<vue.ExtractPropTypes<{}>>, {}, {}>;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Markdown rendered content
|
|
13
|
-
*/
|
|
14
|
-
declare const Content: vue.DefineComponent<{
|
|
15
|
-
pageKey: {
|
|
16
|
-
type: StringConstructor;
|
|
17
|
-
required: false;
|
|
18
|
-
default: string;
|
|
19
|
-
};
|
|
20
|
-
}, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
21
|
-
[key: string]: any;
|
|
22
|
-
}>, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.VNodeProps & vue.AllowedComponentProps & vue.ComponentCustomProps, Readonly<vue.ExtractPropTypes<{
|
|
23
|
-
pageKey: {
|
|
24
|
-
type: StringConstructor;
|
|
25
|
-
required: false;
|
|
26
|
-
default: string;
|
|
27
|
-
};
|
|
28
|
-
}>>, {
|
|
29
|
-
pageKey: string;
|
|
30
|
-
}, {}>;
|
|
31
|
-
|
|
32
|
-
type Layouts = Record<string, Component>;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Configure vuepress client
|
|
36
|
-
*/
|
|
37
|
-
interface ClientConfig {
|
|
38
|
-
/**
|
|
39
|
-
* An enhance function to be called after vue app instance and
|
|
40
|
-
* vue-router instance has been created
|
|
41
|
-
*/
|
|
42
|
-
enhance?: (context: {
|
|
43
|
-
app: App;
|
|
44
|
-
router: Router;
|
|
45
|
-
siteData: SiteDataRef;
|
|
46
|
-
}) => void | Promise<void>;
|
|
47
|
-
/**
|
|
48
|
-
* A function to be called inside the setup function of vue app
|
|
49
|
-
*/
|
|
50
|
-
setup?: () => void;
|
|
51
|
-
/**
|
|
52
|
-
* Layout components
|
|
53
|
-
*/
|
|
54
|
-
layouts?: Layouts;
|
|
55
|
-
/**
|
|
56
|
-
* Components to be placed directly into the root node of vue app
|
|
57
|
-
*/
|
|
58
|
-
rootComponents?: Component[];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
type CreateVueAppFunction = () => Promise<{
|
|
62
|
-
app: App;
|
|
63
|
-
router: Router;
|
|
64
|
-
}>;
|
|
65
|
-
|
|
66
|
-
type PageRouteItem = [
|
|
67
|
-
name: string,
|
|
68
|
-
path: string,
|
|
69
|
-
meta: RouteMeta,
|
|
70
|
-
redirects: string[]
|
|
71
|
-
];
|
|
6
|
+
export { C as CreateVueAppFunction } from './createVueAppFunction-YNGNKfE3.js';
|
|
72
7
|
|
|
73
8
|
/**
|
|
74
9
|
* Ref wrapper of `Layouts`
|
|
@@ -257,6 +192,67 @@ declare const updateHeadSymbol: InjectionKey<UpdateHead>;
|
|
|
257
192
|
*/
|
|
258
193
|
declare const useUpdateHead: () => UpdateHead;
|
|
259
194
|
|
|
195
|
+
type Layouts = Record<string, Component>;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Configure vuepress client
|
|
199
|
+
*/
|
|
200
|
+
interface ClientConfig {
|
|
201
|
+
/**
|
|
202
|
+
* An enhance function to be called after vue app instance and
|
|
203
|
+
* vue-router instance has been created
|
|
204
|
+
*/
|
|
205
|
+
enhance?: (context: {
|
|
206
|
+
app: App;
|
|
207
|
+
router: Router;
|
|
208
|
+
siteData: SiteDataRef;
|
|
209
|
+
}) => void | Promise<void>;
|
|
210
|
+
/**
|
|
211
|
+
* A function to be called inside the setup function of vue app
|
|
212
|
+
*/
|
|
213
|
+
setup?: () => void;
|
|
214
|
+
/**
|
|
215
|
+
* Layout components
|
|
216
|
+
*/
|
|
217
|
+
layouts?: Layouts;
|
|
218
|
+
/**
|
|
219
|
+
* Components to be placed directly into the root node of vue app
|
|
220
|
+
*/
|
|
221
|
+
rootComponents?: Component[];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
type PageRouteItem = [
|
|
225
|
+
name: string,
|
|
226
|
+
path: string,
|
|
227
|
+
meta: RouteMeta,
|
|
228
|
+
redirects: string[]
|
|
229
|
+
];
|
|
230
|
+
|
|
231
|
+
declare const ClientOnly: vue.DefineComponent<{}, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
232
|
+
[key: string]: any;
|
|
233
|
+
}>[] | null | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{}>>, {}, {}>;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Markdown rendered content
|
|
237
|
+
*/
|
|
238
|
+
declare const Content: vue.DefineComponent<{
|
|
239
|
+
pageKey: {
|
|
240
|
+
type: StringConstructor;
|
|
241
|
+
required: false;
|
|
242
|
+
default: string;
|
|
243
|
+
};
|
|
244
|
+
}, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
245
|
+
[key: string]: any;
|
|
246
|
+
}>, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
247
|
+
pageKey: {
|
|
248
|
+
type: StringConstructor;
|
|
249
|
+
required: false;
|
|
250
|
+
default: string;
|
|
251
|
+
};
|
|
252
|
+
}>>, {
|
|
253
|
+
pageKey: string;
|
|
254
|
+
}, {}>;
|
|
255
|
+
|
|
260
256
|
/**
|
|
261
257
|
* A helper function to help you define vuepress client config file
|
|
262
258
|
*/
|
|
@@ -284,4 +280,4 @@ declare const resolvers: {
|
|
|
284
280
|
resolveSiteLocaleData: (site: SiteData, routeLocale: RouteLocale) => SiteLocaleData;
|
|
285
281
|
};
|
|
286
282
|
|
|
287
|
-
export { ClientConfig, ClientOnly, Content,
|
|
283
|
+
export { type ClientConfig, ClientOnly, Content, type Layouts, type LayoutsRef, type PageDataRef, type PageFrontmatterRef, type PageHead, type PageHeadRef, type PageHeadTitle, type PageHeadTitleRef, type PageLang, type PageLangRef, type PageLayoutRef, type PageRouteItem, type PagesData, type PagesDataRef, type RouteLocale, type RouteLocaleRef, type SiteDataRef, type SiteLocaleData, type SiteLocaleDataRef, type UpdateHead, defineClientConfig, layoutsSymbol, pageDataEmpty, pageDataSymbol, pageFrontmatterSymbol, pageHeadSymbol, pageHeadTitleSymbol, pageLangSymbol, pageLayoutSymbol, pagesData, resolvers, routeLocaleSymbol, siteData, siteLocaleDataSymbol, updateHeadSymbol, useLayouts, usePageData, usePageFrontmatter, usePageHead, usePageHeadTitle, usePageLang, usePageLayout, usePagesData, useRouteLocale, useSiteData, useSiteLocaleData, useUpdateHead, withBase };
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress/client",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.2",
|
|
4
4
|
"description": "Client package of VuePress",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress",
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
],
|
|
9
9
|
"homepage": "https://github.com/vuepress",
|
|
10
10
|
"bugs": {
|
|
11
|
-
"url": "https://github.com/vuepress/
|
|
11
|
+
"url": "https://github.com/vuepress/core/issues"
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
|
-
"url": "git+https://github.com/vuepress/
|
|
15
|
+
"url": "git+https://github.com/vuepress/core.git"
|
|
16
16
|
},
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"author": "meteorlxy",
|
|
@@ -34,17 +34,20 @@
|
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@vue/devtools-api": "^6.5.1",
|
|
37
|
-
"@vueuse/core": "^10.
|
|
38
|
-
"vue": "^3.
|
|
37
|
+
"@vueuse/core": "^10.7.2",
|
|
38
|
+
"vue": "^3.4.15",
|
|
39
39
|
"vue-router": "^4.2.5",
|
|
40
|
-
"@vuepress/shared": "2.0.0-rc.
|
|
40
|
+
"@vuepress/shared": "2.0.0-rc.2"
|
|
41
41
|
},
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
45
|
"tsup": {
|
|
46
46
|
"clean": true,
|
|
47
|
-
"dts":
|
|
47
|
+
"dts": [
|
|
48
|
+
"./src/app.ts",
|
|
49
|
+
"./src/index.ts"
|
|
50
|
+
],
|
|
48
51
|
"entry": [
|
|
49
52
|
"./src/app.ts",
|
|
50
53
|
"./src/index.ts"
|