@vuepress/client 2.0.0-rc.1 → 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/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,32 +1,34 @@
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-GA5RAHE7.js";
22
16
 
23
17
  // src/app.ts
24
18
  import { clientConfigs } from "@internal/clientConfigs";
25
- import { createApp, createSSRApp, h as h2 } from "vue";
26
- import { RouterView } from "vue-router";
19
+ import { createApp, createSSRApp, h } from "vue";
27
20
 
28
- // src/router.ts
29
- import { pagesComponents } from "@internal/pagesComponents";
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: createRoutes(),
97
- scrollBehavior: (to, from, savedPosition) => {
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
- [to.meta._data] = await Promise.all([
109
- resolvers.resolvePageData(to.name),
110
- pagesComponents[to.name]?.__asyncLoader()
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,23 +80,30 @@ 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 { computedWithControl } from "@vueuse/core";
125
- import { computed } from "vue";
87
+ import { computed, customRef } from "vue";
126
88
  var setupGlobalComputed = (app, router, clientConfigs2) => {
127
89
  const routePath = computed(() => router.currentRoute.value.path);
128
- const pageData = computedWithControl(
129
- routePath,
130
- () => router.currentRoute.value.meta._data
131
- );
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
+ }));
132
100
  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();
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;
138
107
  }
139
108
  };
140
109
  }
@@ -145,9 +114,9 @@ var setupGlobalComputed = (app, router, clientConfigs2) => {
145
114
  const siteLocaleData = computed(
146
115
  () => resolvers.resolveSiteLocaleData(siteData.value, routeLocale.value)
147
116
  );
148
- const pageFrontmatter = computed(
149
- () => resolvers.resolvePageFrontmatter(pageData.value)
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,38 +133,35 @@ var setupGlobalComputed = (app, router, clientConfigs2) => {
164
133
  const pageLayout = computed(
165
134
  () => resolvers.resolvePageLayout(pageData.value, layouts.value)
166
135
  );
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 {
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
@@ -311,25 +277,24 @@ var createHeadElement = ([
311
277
  var appCreator = __VUEPRESS_DEV__ ? createApp : createSSRApp;
312
278
  var createVueApp = async () => {
313
279
  const app = appCreator({
314
- name: "VuepressApp",
280
+ name: "Vuepress",
315
281
  setup() {
316
282
  setupUpdateHead();
317
283
  for (const clientConfig of clientConfigs) {
318
284
  clientConfig.setup?.();
319
285
  }
320
- return () => [
321
- h2(RouterView),
322
- ...clientConfigs.flatMap(
323
- ({ rootComponents = [] }) => rootComponents.map((component) => h2(component))
324
- )
325
- ];
286
+ const rootComponents = clientConfigs.flatMap(
287
+ ({ rootComponents: rootComponents2 = [] }) => rootComponents2.map((component) => h(component))
288
+ );
289
+ const pageLayout = usePageLayout();
290
+ return () => [h(pageLayout.value), rootComponents];
326
291
  }
327
292
  });
328
293
  const router = createVueRouter();
329
294
  setupGlobalComponents(app);
330
295
  const globalComputed = setupGlobalComputed(app, router, clientConfigs);
331
296
  if (__VUEPRESS_DEV__ || __VUE_PROD_DEVTOOLS__) {
332
- const { setupDevtools } = await import("./setupDevtools-X4YFRK4B.js");
297
+ const { setupDevtools } = await import("./setupDevtools-H6KAGBNI.js");
333
298
  setupDevtools(app, globalComputed);
334
299
  }
335
300
  for (const clientConfig of clientConfigs) {