@vuepress/client 2.0.0-rc.2 → 2.0.0-rc.21

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/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  ## Documentation
7
7
 
8
- https://v2.vuepress.vuejs.org
8
+ https://vuepress.vuejs.org
9
9
 
10
10
  ## License
11
11
 
package/dist/app.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as CreateVueAppFunction } from './createVueAppFunction-YNGNKfE3.js';
1
+ import { C as CreateVueAppFunction } from './createVueAppFunction-onJTVJru.js';
2
2
  import 'vue';
3
3
  import 'vue-router';
4
4
 
package/dist/app.js CHANGED
@@ -1,114 +1,75 @@
1
1
  import {
2
2
  ClientOnly,
3
3
  Content,
4
- layoutsSymbol,
5
- pageDataSymbol,
6
- pageFrontmatterSymbol,
7
- pageHeadSymbol,
8
- pageHeadTitleSymbol,
9
- pageLangSymbol,
10
- pageLayoutSymbol,
11
- pagesData,
4
+ RouteLink,
5
+ clientDataSymbol,
6
+ redirects,
7
+ resolveRoute,
12
8
  resolvers,
13
- routeLocaleSymbol,
14
- siteData,
15
- siteLocaleDataSymbol,
9
+ routes,
16
10
  updateHeadSymbol,
17
11
  usePageHead,
18
12
  usePageLang,
19
13
  usePageLayout,
20
14
  withBase
21
- } from "./chunk-PEQEPZ75.js";
15
+ } from "./chunk-XDHI2EHH.js";
16
+ import "./chunk-MLKGABMK.js";
22
17
 
23
18
  // src/app.ts
24
19
  import { clientConfigs } from "@internal/clientConfigs";
25
- import { createApp, createSSRApp, h as h2 } from "vue";
26
- import { RouterView } from "vue-router";
20
+ import { createApp, createSSRApp, h } from "vue";
27
21
 
28
- // src/router.ts
29
- import { pagesComponents } from "@internal/pagesComponents";
22
+ // src/internal/siteData.ts
23
+ import { siteData as siteDataRaw } from "@internal/siteData";
24
+ import { shallowRef } from "vue";
25
+ var siteData = shallowRef(siteDataRaw);
26
+ if (__VUEPRESS_DEV__ && (import.meta.webpackHot || import.meta.hot)) {
27
+ __VUE_HMR_RUNTIME__.updateSiteData = (data) => {
28
+ siteData.value = data;
29
+ };
30
+ }
31
+
32
+ // src/router/createVueRouter.ts
30
33
  import { removeEndingSlash } from "@vuepress/shared";
31
34
  import {
35
+ START_LOCATION,
32
36
  createMemoryHistory,
33
37
  createRouter,
34
- createWebHistory,
35
- START_LOCATION
38
+ createWebHistory
36
39
  } 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
40
  var historyCreator = __VUEPRESS_SSR__ ? createMemoryHistory : createWebHistory;
92
41
  var createVueRouter = () => {
93
42
  const router = createRouter({
94
43
  // it might be an issue of vue-router that have to remove the ending slash
95
44
  history: historyCreator(removeEndingSlash(__VUEPRESS_BASE__)),
96
- routes: createRoutes(),
97
- scrollBehavior: (to, from, savedPosition) => {
98
- if (savedPosition)
99
- return savedPosition;
100
- if (to.hash)
101
- return { el: to.hash };
45
+ routes: [
46
+ {
47
+ name: "vuepress-route",
48
+ path: "/:catchAll(.*)",
49
+ components: {}
50
+ }
51
+ ],
52
+ scrollBehavior: (to, _from, savedPosition) => {
53
+ if (savedPosition) return savedPosition;
54
+ if (to.hash) return { el: to.hash };
102
55
  return { top: 0 };
103
56
  }
104
57
  });
105
58
  router.beforeResolve(async (to, from) => {
106
59
  if (to.path !== from.path || from === START_LOCATION) {
107
- ;
108
- [to.meta._data] = await Promise.all([
109
- resolvers.resolvePageData(to.name),
110
- pagesComponents[to.name]?.__asyncLoader()
111
- ]);
60
+ const route = resolveRoute(to.fullPath);
61
+ if (route.path !== to.fullPath) {
62
+ return route.path;
63
+ }
64
+ const pageChunk = await route.loader();
65
+ to.meta = {
66
+ // attach route meta
67
+ ...route.meta,
68
+ // attach page chunk route meta
69
+ _pageChunk: pageChunk
70
+ };
71
+ } else if (to.path === from.path) {
72
+ to.meta = from.meta;
112
73
  }
113
74
  });
114
75
  return router;
@@ -118,23 +79,30 @@ var createVueRouter = () => {
118
79
  var setupGlobalComponents = (app) => {
119
80
  app.component("ClientOnly", ClientOnly);
120
81
  app.component("Content", Content);
82
+ app.component("RouteLink", RouteLink);
121
83
  };
122
84
 
123
85
  // src/setupGlobalComputed.ts
124
- import { computedWithControl } from "@vueuse/core";
125
- import { computed } from "vue";
86
+ import { computed, customRef } from "vue";
126
87
  var setupGlobalComputed = (app, router, clientConfigs2) => {
127
88
  const routePath = computed(() => router.currentRoute.value.path);
128
- const pageData = computedWithControl(
129
- routePath,
130
- () => router.currentRoute.value.meta._data
131
- );
89
+ const pageChunk = customRef((track, trigger) => ({
90
+ get() {
91
+ track();
92
+ return router.currentRoute.value.meta._pageChunk;
93
+ },
94
+ set(value) {
95
+ router.currentRoute.value.meta._pageChunk = value;
96
+ trigger();
97
+ }
98
+ }));
132
99
  if (__VUEPRESS_DEV__ && (import.meta.webpackHot || import.meta.hot)) {
133
- __VUE_HMR_RUNTIME__.updatePageData = (data) => {
134
- pagesData.value[data.key] = () => Promise.resolve(data);
135
- if (data.key === router.currentRoute.value.meta._data?.key) {
136
- router.currentRoute.value.meta._data = data;
137
- pageData.trigger();
100
+ __VUE_HMR_RUNTIME__.updatePageData = async (newPageData) => {
101
+ const oldPageChunk = await routes.value[newPageData.path].loader();
102
+ const newPageChunk = { comp: oldPageChunk.comp, data: newPageData };
103
+ routes.value[newPageData.path].loader = async () => Promise.resolve(newPageChunk);
104
+ if (newPageData.path === router.currentRoute.value.meta._pageChunk?.data.path) {
105
+ pageChunk.value = newPageChunk;
138
106
  }
139
107
  };
140
108
  }
@@ -145,9 +113,9 @@ var setupGlobalComputed = (app, router, clientConfigs2) => {
145
113
  const siteLocaleData = computed(
146
114
  () => resolvers.resolveSiteLocaleData(siteData.value, routeLocale.value)
147
115
  );
148
- const pageFrontmatter = computed(
149
- () => resolvers.resolvePageFrontmatter(pageData.value)
150
- );
116
+ const pageComponent = computed(() => pageChunk.value.comp);
117
+ const pageData = computed(() => pageChunk.value.data);
118
+ const pageFrontmatter = computed(() => pageData.value.frontmatter);
151
119
  const pageHeadTitle = computed(
152
120
  () => resolvers.resolvePageHeadTitle(pageData.value, siteLocaleData.value)
153
121
  );
@@ -164,43 +132,86 @@ var setupGlobalComputed = (app, router, clientConfigs2) => {
164
132
  const pageLayout = computed(
165
133
  () => resolvers.resolvePageLayout(pageData.value, layouts.value)
166
134
  );
167
- app.provide(layoutsSymbol, layouts);
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 {
135
+ const clientData = {
188
136
  layouts,
189
137
  pageData,
138
+ pageComponent,
190
139
  pageFrontmatter,
191
140
  pageHead,
192
141
  pageHeadTitle,
193
142
  pageLang,
194
143
  pageLayout,
144
+ redirects,
195
145
  routeLocale,
146
+ routePath,
147
+ routes,
196
148
  siteData,
197
149
  siteLocaleData
198
150
  };
151
+ app.provide(clientDataSymbol, clientData);
152
+ Object.defineProperties(app.config.globalProperties, {
153
+ $frontmatter: { get: () => pageFrontmatter.value },
154
+ $head: { get: () => pageHead.value },
155
+ $headTitle: { get: () => pageHeadTitle.value },
156
+ $lang: { get: () => pageLang.value },
157
+ $page: { get: () => pageData.value },
158
+ $routeLocale: { get: () => routeLocale.value },
159
+ $site: { get: () => siteData.value },
160
+ $siteLocale: { get: () => siteLocaleData.value },
161
+ $withBase: { get: () => withBase }
162
+ });
163
+ return clientData;
199
164
  };
200
165
 
201
166
  // src/setupUpdateHead.ts
202
167
  import { isPlainObject, isString } from "@vuepress/shared";
203
168
  import { onMounted, provide, useSSRContext, watch } from "vue";
169
+ var queryHeadElement = ([
170
+ tagName,
171
+ attrs,
172
+ content = ""
173
+ ]) => {
174
+ const attrsSelector = Object.entries(attrs).map(([key, value]) => {
175
+ if (isString(value)) {
176
+ return `[${key}=${JSON.stringify(value)}]`;
177
+ }
178
+ if (value) {
179
+ return `[${key}]`;
180
+ }
181
+ return "";
182
+ }).join("");
183
+ const selector = `head > ${tagName}${attrsSelector}`;
184
+ const headElements = Array.from(
185
+ document.querySelectorAll(selector)
186
+ );
187
+ const matchedHeadElement = headElements.find(
188
+ (item) => item.innerText === content
189
+ );
190
+ return matchedHeadElement ?? null;
191
+ };
192
+ var createHeadElement = ([
193
+ tagName,
194
+ attrs,
195
+ content
196
+ ]) => {
197
+ if (!isString(tagName)) {
198
+ return null;
199
+ }
200
+ const headElement = document.createElement(tagName);
201
+ if (isPlainObject(attrs)) {
202
+ Object.entries(attrs).forEach(([key, value]) => {
203
+ if (isString(value)) {
204
+ headElement.setAttribute(key, value);
205
+ } else if (value) {
206
+ headElement.setAttribute(key, "");
207
+ }
208
+ });
209
+ }
210
+ if (isString(content)) {
211
+ headElement.appendChild(document.createTextNode(content));
212
+ }
213
+ return headElement;
214
+ };
204
215
  var setupUpdateHead = () => {
205
216
  const head = usePageHead();
206
217
  const lang = usePageLang();
@@ -260,76 +271,29 @@ var setupUpdateHead = () => {
260
271
  watch(head, updateHead, { immediate: __VUEPRESS_DEV__ });
261
272
  });
262
273
  };
263
- var queryHeadElement = ([
264
- tagName,
265
- attrs,
266
- content = ""
267
- ]) => {
268
- const attrsSelector = Object.entries(attrs).map(([key, value]) => {
269
- if (isString(value)) {
270
- return `[${key}=${JSON.stringify(value)}]`;
271
- }
272
- if (value === true) {
273
- return `[${key}]`;
274
- }
275
- return "";
276
- }).join("");
277
- const selector = `head > ${tagName}${attrsSelector}`;
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;
285
- };
286
- var createHeadElement = ([
287
- tagName,
288
- attrs,
289
- content
290
- ]) => {
291
- if (!isString(tagName)) {
292
- return null;
293
- }
294
- const headElement = document.createElement(tagName);
295
- if (isPlainObject(attrs)) {
296
- Object.entries(attrs).forEach(([key, value]) => {
297
- if (isString(value)) {
298
- headElement.setAttribute(key, value);
299
- } else if (value === true) {
300
- headElement.setAttribute(key, "");
301
- }
302
- });
303
- }
304
- if (isString(content)) {
305
- headElement.appendChild(document.createTextNode(content));
306
- }
307
- return headElement;
308
- };
309
274
 
310
275
  // src/app.ts
311
276
  var appCreator = __VUEPRESS_DEV__ ? createApp : createSSRApp;
312
277
  var createVueApp = async () => {
313
278
  const app = appCreator({
314
- name: "VuepressApp",
279
+ name: "Vuepress",
315
280
  setup() {
316
281
  setupUpdateHead();
317
282
  for (const clientConfig of clientConfigs) {
318
283
  clientConfig.setup?.();
319
284
  }
320
- return () => [
321
- h2(RouterView),
322
- ...clientConfigs.flatMap(
323
- ({ rootComponents = [] }) => rootComponents.map((component) => h2(component))
324
- )
325
- ];
285
+ const clientRootComponents = clientConfigs.flatMap(
286
+ ({ rootComponents = [] }) => rootComponents.map((component) => h(component))
287
+ );
288
+ const pageLayout = usePageLayout();
289
+ return () => [h(pageLayout.value), clientRootComponents];
326
290
  }
327
291
  });
328
292
  const router = createVueRouter();
329
293
  setupGlobalComponents(app);
330
294
  const globalComputed = setupGlobalComputed(app, router, clientConfigs);
331
295
  if (__VUEPRESS_DEV__ || __VUE_PROD_DEVTOOLS__) {
332
- const { setupDevtools } = await import("./setupDevtools-X4YFRK4B.js");
296
+ const { setupDevtools } = await import("./setupDevtools-QXEOFQJV.js");
333
297
  setupDevtools(app, globalComputed);
334
298
  }
335
299
  for (const clientConfig of clientConfigs) {
@@ -342,8 +306,8 @@ var createVueApp = async () => {
342
306
  };
343
307
  };
344
308
  if (!__VUEPRESS_SSR__) {
345
- createVueApp().then(({ app, router }) => {
346
- router.isReady().then(() => {
309
+ void createVueApp().then(({ app, router }) => {
310
+ void router.isReady().then(() => {
347
311
  app.mount("#app");
348
312
  });
349
313
  });
@@ -0,0 +1,9 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export {
8
+ __export
9
+ };