@vuepress/client 2.0.0-rc.0 → 2.0.0-rc.10
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 +139 -154
- package/dist/chunk-GA5RAHE7.js +432 -0
- package/dist/createVueAppFunction-onJTVJru.d.ts +9 -0
- package/dist/index.d.ts +344 -204
- package/dist/index.js +25 -29
- package/dist/{setupDevtools-X4YFRK4B.js → setupDevtools-H6KAGBNI.js} +16 -16
- package/package.json +12 -13
- package/dist/chunk-DHNSDB55.js +0 -338
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
|
@@ -1,32 +1,34 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ClientOnly,
|
|
3
3
|
Content,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
pageHeadTitleSymbol,
|
|
9
|
-
pageLangSymbol,
|
|
10
|
-
pageLayoutSymbol,
|
|
11
|
-
pagesData,
|
|
4
|
+
RouteLink,
|
|
5
|
+
clientDataSymbol,
|
|
6
|
+
redirects,
|
|
7
|
+
resolveRoute,
|
|
12
8
|
resolvers,
|
|
13
|
-
|
|
14
|
-
siteData,
|
|
15
|
-
siteLocaleDataSymbol,
|
|
9
|
+
routes,
|
|
16
10
|
updateHeadSymbol,
|
|
17
11
|
usePageHead,
|
|
18
12
|
usePageLang,
|
|
19
13
|
usePageLayout,
|
|
20
14
|
withBase
|
|
21
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-GA5RAHE7.js";
|
|
22
16
|
|
|
23
17
|
// src/app.ts
|
|
24
18
|
import { clientConfigs } from "@internal/clientConfigs";
|
|
25
|
-
import { createApp, createSSRApp, h
|
|
26
|
-
import { RouterView } from "vue-router";
|
|
19
|
+
import { createApp, createSSRApp, h } from "vue";
|
|
27
20
|
|
|
28
|
-
// src/
|
|
29
|
-
import {
|
|
21
|
+
// src/internal/siteData.ts
|
|
22
|
+
import { siteData as siteDataRaw } from "@internal/siteData";
|
|
23
|
+
import { shallowRef } from "vue";
|
|
24
|
+
var siteData = shallowRef(siteDataRaw);
|
|
25
|
+
if (__VUEPRESS_DEV__ && (import.meta.webpackHot || import.meta.hot)) {
|
|
26
|
+
__VUE_HMR_RUNTIME__.updateSiteData = (data) => {
|
|
27
|
+
siteData.value = data;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/router/createVueRouter.ts
|
|
30
32
|
import { removeEndingSlash } from "@vuepress/shared";
|
|
31
33
|
import {
|
|
32
34
|
createMemoryHistory,
|
|
@@ -34,67 +36,19 @@ import {
|
|
|
34
36
|
createWebHistory,
|
|
35
37
|
START_LOCATION
|
|
36
38
|
} from "vue-router";
|
|
37
|
-
|
|
38
|
-
// src/routes.ts
|
|
39
|
-
import { pagesRoutes } from "@internal/pagesRoutes";
|
|
40
|
-
|
|
41
|
-
// src/components/Vuepress.ts
|
|
42
|
-
import { defineComponent, h } from "vue";
|
|
43
|
-
var Vuepress = defineComponent({
|
|
44
|
-
name: "Vuepress",
|
|
45
|
-
setup() {
|
|
46
|
-
const layout = usePageLayout();
|
|
47
|
-
return () => h(layout.value);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
// src/routes.ts
|
|
52
|
-
var createRoutes = () => pagesRoutes.reduce(
|
|
53
|
-
(result, [name, path, meta, redirects]) => {
|
|
54
|
-
result.push(
|
|
55
|
-
{
|
|
56
|
-
name,
|
|
57
|
-
path,
|
|
58
|
-
component: Vuepress,
|
|
59
|
-
meta
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
path: path.endsWith("/") ? (
|
|
63
|
-
// redirect from `/index.html` to `/`
|
|
64
|
-
path + "index.html"
|
|
65
|
-
) : (
|
|
66
|
-
// redirect from `/foo` to `/foo.html`
|
|
67
|
-
path.substring(0, path.length - 5)
|
|
68
|
-
),
|
|
69
|
-
redirect: path
|
|
70
|
-
},
|
|
71
|
-
...redirects.map((item) => ({
|
|
72
|
-
path: item === ":md" ? (
|
|
73
|
-
// redirect from `/foo.md` to `/foo.html`
|
|
74
|
-
path.substring(0, path.length - 5) + ".md"
|
|
75
|
-
) : item,
|
|
76
|
-
redirect: path
|
|
77
|
-
}))
|
|
78
|
-
);
|
|
79
|
-
return result;
|
|
80
|
-
},
|
|
81
|
-
[
|
|
82
|
-
{
|
|
83
|
-
name: "404",
|
|
84
|
-
path: "/:catchAll(.*)",
|
|
85
|
-
component: Vuepress
|
|
86
|
-
}
|
|
87
|
-
]
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
// src/router.ts
|
|
91
39
|
var historyCreator = __VUEPRESS_SSR__ ? createMemoryHistory : createWebHistory;
|
|
92
40
|
var createVueRouter = () => {
|
|
93
41
|
const router = createRouter({
|
|
94
42
|
// it might be an issue of vue-router that have to remove the ending slash
|
|
95
43
|
history: historyCreator(removeEndingSlash(__VUEPRESS_BASE__)),
|
|
96
|
-
routes:
|
|
97
|
-
|
|
44
|
+
routes: [
|
|
45
|
+
{
|
|
46
|
+
name: "vuepress-route",
|
|
47
|
+
path: "/:catchAll(.*)",
|
|
48
|
+
components: {}
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
scrollBehavior: (to, _from, savedPosition) => {
|
|
98
52
|
if (savedPosition)
|
|
99
53
|
return savedPosition;
|
|
100
54
|
if (to.hash)
|
|
@@ -104,11 +58,19 @@ var createVueRouter = () => {
|
|
|
104
58
|
});
|
|
105
59
|
router.beforeResolve(async (to, from) => {
|
|
106
60
|
if (to.path !== from.path || from === START_LOCATION) {
|
|
107
|
-
;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
61
|
+
const route = resolveRoute(to.fullPath);
|
|
62
|
+
if (route.path !== to.fullPath) {
|
|
63
|
+
return route.path;
|
|
64
|
+
}
|
|
65
|
+
const pageChunk = await route.loader();
|
|
66
|
+
to.meta = {
|
|
67
|
+
// attach route meta
|
|
68
|
+
...route.meta,
|
|
69
|
+
// attach page chunk route meta
|
|
70
|
+
_pageChunk: pageChunk
|
|
71
|
+
};
|
|
72
|
+
} else if (to.path === from.path) {
|
|
73
|
+
to.meta = from.meta;
|
|
112
74
|
}
|
|
113
75
|
});
|
|
114
76
|
return router;
|
|
@@ -118,36 +80,43 @@ var createVueRouter = () => {
|
|
|
118
80
|
var setupGlobalComponents = (app) => {
|
|
119
81
|
app.component("ClientOnly", ClientOnly);
|
|
120
82
|
app.component("Content", Content);
|
|
83
|
+
app.component("RouteLink", RouteLink);
|
|
121
84
|
};
|
|
122
85
|
|
|
123
86
|
// src/setupGlobalComputed.ts
|
|
124
|
-
import {
|
|
125
|
-
import { computed } from "vue";
|
|
87
|
+
import { computed, customRef } from "vue";
|
|
126
88
|
var setupGlobalComputed = (app, router, clientConfigs2) => {
|
|
127
|
-
const routePath =
|
|
128
|
-
const
|
|
129
|
-
()
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
()
|
|
134
|
-
|
|
89
|
+
const routePath = computed(() => router.currentRoute.value.path);
|
|
90
|
+
const pageChunk = customRef((track, trigger) => ({
|
|
91
|
+
get() {
|
|
92
|
+
track();
|
|
93
|
+
return router.currentRoute.value.meta._pageChunk;
|
|
94
|
+
},
|
|
95
|
+
set(value) {
|
|
96
|
+
router.currentRoute.value.meta._pageChunk = value;
|
|
97
|
+
trigger();
|
|
98
|
+
}
|
|
99
|
+
}));
|
|
135
100
|
if (__VUEPRESS_DEV__ && (import.meta.webpackHot || import.meta.hot)) {
|
|
136
|
-
__VUE_HMR_RUNTIME__.updatePageData = (
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
101
|
+
__VUE_HMR_RUNTIME__.updatePageData = async (newPageData) => {
|
|
102
|
+
const oldPageChunk = await routes.value[newPageData.path].loader();
|
|
103
|
+
const newPageChunk = { comp: oldPageChunk.comp, data: newPageData };
|
|
104
|
+
routes.value[newPageData.path].loader = () => Promise.resolve(newPageChunk);
|
|
105
|
+
if (newPageData.path === router.currentRoute.value.meta._pageChunk?.data.path) {
|
|
106
|
+
pageChunk.value = newPageChunk;
|
|
141
107
|
}
|
|
142
108
|
};
|
|
143
109
|
}
|
|
144
110
|
const layouts = computed(() => resolvers.resolveLayouts(clientConfigs2));
|
|
111
|
+
const routeLocale = computed(
|
|
112
|
+
() => resolvers.resolveRouteLocale(siteData.value.locales, routePath.value)
|
|
113
|
+
);
|
|
145
114
|
const siteLocaleData = computed(
|
|
146
115
|
() => resolvers.resolveSiteLocaleData(siteData.value, routeLocale.value)
|
|
147
116
|
);
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
);
|
|
117
|
+
const pageComponent = computed(() => pageChunk.value.comp);
|
|
118
|
+
const pageData = computed(() => pageChunk.value.data);
|
|
119
|
+
const pageFrontmatter = computed(() => pageData.value.frontmatter);
|
|
151
120
|
const pageHeadTitle = computed(
|
|
152
121
|
() => resolvers.resolvePageHeadTitle(pageData.value, siteLocaleData.value)
|
|
153
122
|
);
|
|
@@ -164,43 +133,40 @@ var setupGlobalComputed = (app, router, clientConfigs2) => {
|
|
|
164
133
|
const pageLayout = computed(
|
|
165
134
|
() => resolvers.resolvePageLayout(pageData.value, layouts.value)
|
|
166
135
|
);
|
|
167
|
-
|
|
168
|
-
app.provide(pageDataSymbol, pageData);
|
|
169
|
-
app.provide(pageFrontmatterSymbol, pageFrontmatter);
|
|
170
|
-
app.provide(pageHeadTitleSymbol, pageHeadTitle);
|
|
171
|
-
app.provide(pageHeadSymbol, pageHead);
|
|
172
|
-
app.provide(pageLangSymbol, pageLang);
|
|
173
|
-
app.provide(pageLayoutSymbol, pageLayout);
|
|
174
|
-
app.provide(routeLocaleSymbol, routeLocale);
|
|
175
|
-
app.provide(siteLocaleDataSymbol, siteLocaleData);
|
|
176
|
-
Object.defineProperties(app.config.globalProperties, {
|
|
177
|
-
$frontmatter: { get: () => pageFrontmatter.value },
|
|
178
|
-
$head: { get: () => pageHead.value },
|
|
179
|
-
$headTitle: { get: () => pageHeadTitle.value },
|
|
180
|
-
$lang: { get: () => pageLang.value },
|
|
181
|
-
$page: { get: () => pageData.value },
|
|
182
|
-
$routeLocale: { get: () => routeLocale.value },
|
|
183
|
-
$site: { get: () => siteData.value },
|
|
184
|
-
$siteLocale: { get: () => siteLocaleData.value },
|
|
185
|
-
$withBase: { get: () => withBase }
|
|
186
|
-
});
|
|
187
|
-
return {
|
|
136
|
+
const clientData = {
|
|
188
137
|
layouts,
|
|
189
138
|
pageData,
|
|
139
|
+
pageComponent,
|
|
190
140
|
pageFrontmatter,
|
|
191
141
|
pageHead,
|
|
192
142
|
pageHeadTitle,
|
|
193
143
|
pageLang,
|
|
194
144
|
pageLayout,
|
|
145
|
+
redirects,
|
|
195
146
|
routeLocale,
|
|
147
|
+
routePath,
|
|
148
|
+
routes,
|
|
196
149
|
siteData,
|
|
197
150
|
siteLocaleData
|
|
198
151
|
};
|
|
152
|
+
app.provide(clientDataSymbol, clientData);
|
|
153
|
+
Object.defineProperties(app.config.globalProperties, {
|
|
154
|
+
$frontmatter: { get: () => pageFrontmatter.value },
|
|
155
|
+
$head: { get: () => pageHead.value },
|
|
156
|
+
$headTitle: { get: () => pageHeadTitle.value },
|
|
157
|
+
$lang: { get: () => pageLang.value },
|
|
158
|
+
$page: { get: () => pageData.value },
|
|
159
|
+
$routeLocale: { get: () => routeLocale.value },
|
|
160
|
+
$site: { get: () => siteData.value },
|
|
161
|
+
$siteLocale: { get: () => siteLocaleData.value },
|
|
162
|
+
$withBase: { get: () => withBase }
|
|
163
|
+
});
|
|
164
|
+
return clientData;
|
|
199
165
|
};
|
|
200
166
|
|
|
201
167
|
// src/setupUpdateHead.ts
|
|
202
168
|
import { isPlainObject, isString } from "@vuepress/shared";
|
|
203
|
-
import { onMounted, provide,
|
|
169
|
+
import { onMounted, provide, useSSRContext, watch } from "vue";
|
|
204
170
|
var setupUpdateHead = () => {
|
|
205
171
|
const head = usePageHead();
|
|
206
172
|
const lang = usePageLang();
|
|
@@ -212,39 +178,55 @@ var setupUpdateHead = () => {
|
|
|
212
178
|
}
|
|
213
179
|
return;
|
|
214
180
|
}
|
|
215
|
-
|
|
216
|
-
const
|
|
181
|
+
let managedHeadElements = [];
|
|
182
|
+
const takeOverHeadElements = () => {
|
|
217
183
|
head.value.forEach((item) => {
|
|
218
|
-
const
|
|
219
|
-
if (
|
|
220
|
-
|
|
184
|
+
const headElement = queryHeadElement(item);
|
|
185
|
+
if (headElement) {
|
|
186
|
+
managedHeadElements.push(headElement);
|
|
221
187
|
}
|
|
222
188
|
});
|
|
223
189
|
};
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
190
|
+
const generateHeadElements = () => {
|
|
191
|
+
const result = [];
|
|
192
|
+
head.value.forEach((item) => {
|
|
193
|
+
const headElement = createHeadElement(item);
|
|
194
|
+
if (headElement) {
|
|
195
|
+
result.push(headElement);
|
|
229
196
|
}
|
|
230
197
|
});
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
198
|
+
return result;
|
|
199
|
+
};
|
|
200
|
+
const updateHead = () => {
|
|
201
|
+
document.documentElement.lang = lang.value;
|
|
202
|
+
const newHeadElements = generateHeadElements();
|
|
203
|
+
managedHeadElements.forEach((oldEl, oldIndex) => {
|
|
204
|
+
const matchedIndex = newHeadElements.findIndex(
|
|
205
|
+
(newEl) => oldEl.isEqualNode(newEl)
|
|
206
|
+
);
|
|
207
|
+
if (matchedIndex === -1) {
|
|
208
|
+
oldEl.remove();
|
|
209
|
+
delete managedHeadElements[oldIndex];
|
|
210
|
+
} else {
|
|
211
|
+
newHeadElements.splice(matchedIndex, 1);
|
|
237
212
|
}
|
|
238
213
|
});
|
|
214
|
+
newHeadElements.forEach((el) => document.head.appendChild(el));
|
|
215
|
+
managedHeadElements = [
|
|
216
|
+
// filter out empty deleted items
|
|
217
|
+
...managedHeadElements.filter((item) => !!item),
|
|
218
|
+
...newHeadElements
|
|
219
|
+
];
|
|
239
220
|
};
|
|
240
221
|
provide(updateHeadSymbol, updateHead);
|
|
241
222
|
onMounted(() => {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
223
|
+
if (!__VUEPRESS_DEV__) {
|
|
224
|
+
takeOverHeadElements();
|
|
225
|
+
}
|
|
226
|
+
watch(head, updateHead, { immediate: __VUEPRESS_DEV__ });
|
|
245
227
|
});
|
|
246
228
|
};
|
|
247
|
-
var
|
|
229
|
+
var queryHeadElement = ([
|
|
248
230
|
tagName,
|
|
249
231
|
attrs,
|
|
250
232
|
content = ""
|
|
@@ -259,11 +241,15 @@ var queryHeadTag = ([
|
|
|
259
241
|
return "";
|
|
260
242
|
}).join("");
|
|
261
243
|
const selector = `head > ${tagName}${attrsSelector}`;
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
244
|
+
const headElements = Array.from(
|
|
245
|
+
document.querySelectorAll(selector)
|
|
246
|
+
);
|
|
247
|
+
const matchedHeadElement = headElements.find(
|
|
248
|
+
(item) => item.innerText === content
|
|
249
|
+
);
|
|
250
|
+
return matchedHeadElement || null;
|
|
265
251
|
};
|
|
266
|
-
var
|
|
252
|
+
var createHeadElement = ([
|
|
267
253
|
tagName,
|
|
268
254
|
attrs,
|
|
269
255
|
content
|
|
@@ -271,45 +257,44 @@ var createHeadTag = ([
|
|
|
271
257
|
if (!isString(tagName)) {
|
|
272
258
|
return null;
|
|
273
259
|
}
|
|
274
|
-
const
|
|
260
|
+
const headElement = document.createElement(tagName);
|
|
275
261
|
if (isPlainObject(attrs)) {
|
|
276
262
|
Object.entries(attrs).forEach(([key, value]) => {
|
|
277
263
|
if (isString(value)) {
|
|
278
|
-
|
|
264
|
+
headElement.setAttribute(key, value);
|
|
279
265
|
} else if (value === true) {
|
|
280
|
-
|
|
266
|
+
headElement.setAttribute(key, "");
|
|
281
267
|
}
|
|
282
268
|
});
|
|
283
269
|
}
|
|
284
270
|
if (isString(content)) {
|
|
285
|
-
|
|
271
|
+
headElement.appendChild(document.createTextNode(content));
|
|
286
272
|
}
|
|
287
|
-
return
|
|
273
|
+
return headElement;
|
|
288
274
|
};
|
|
289
275
|
|
|
290
276
|
// src/app.ts
|
|
291
277
|
var appCreator = __VUEPRESS_DEV__ ? createApp : createSSRApp;
|
|
292
278
|
var createVueApp = async () => {
|
|
293
279
|
const app = appCreator({
|
|
294
|
-
name: "
|
|
280
|
+
name: "Vuepress",
|
|
295
281
|
setup() {
|
|
296
282
|
setupUpdateHead();
|
|
297
283
|
for (const clientConfig of clientConfigs) {
|
|
298
284
|
clientConfig.setup?.();
|
|
299
285
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
];
|
|
286
|
+
const rootComponents = clientConfigs.flatMap(
|
|
287
|
+
({ rootComponents: rootComponents2 = [] }) => rootComponents2.map((component) => h(component))
|
|
288
|
+
);
|
|
289
|
+
const pageLayout = usePageLayout();
|
|
290
|
+
return () => [h(pageLayout.value), rootComponents];
|
|
306
291
|
}
|
|
307
292
|
});
|
|
308
293
|
const router = createVueRouter();
|
|
309
294
|
setupGlobalComponents(app);
|
|
310
295
|
const globalComputed = setupGlobalComputed(app, router, clientConfigs);
|
|
311
296
|
if (__VUEPRESS_DEV__ || __VUE_PROD_DEVTOOLS__) {
|
|
312
|
-
const { setupDevtools } = await import("./setupDevtools-
|
|
297
|
+
const { setupDevtools } = await import("./setupDevtools-H6KAGBNI.js");
|
|
313
298
|
setupDevtools(app, globalComputed);
|
|
314
299
|
}
|
|
315
300
|
for (const clientConfig of clientConfigs) {
|