@vuepress/client 2.0.0-beta.50-pre → 2.0.0-beta.51

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.js ADDED
@@ -0,0 +1,286 @@
1
+ import {
2
+ ClientOnly,
3
+ Content,
4
+ Vuepress,
5
+ pageData,
6
+ pageFrontmatterSymbol,
7
+ pageHeadSymbol,
8
+ pageHeadTitleSymbol,
9
+ pageLangSymbol,
10
+ resolvers,
11
+ routeLocaleSymbol,
12
+ siteData,
13
+ siteLocaleDataSymbol,
14
+ updateHeadSymbol,
15
+ usePageHead,
16
+ usePageLang,
17
+ withBase
18
+ } from "./chunk-O5XLV5GU.js";
19
+
20
+ // src/app.ts
21
+ import { clientConfigs } from "@internal/clientConfigs";
22
+ import { createApp, createSSRApp, h } from "vue";
23
+ import { RouterView } from "vue-router";
24
+
25
+ // src/router.ts
26
+ import { pagesComponents } from "@internal/pagesComponents";
27
+ import { removeEndingSlash } from "@vuepress/shared";
28
+ import {
29
+ createMemoryHistory,
30
+ createRouter,
31
+ createWebHistory,
32
+ START_LOCATION
33
+ } from "vue-router";
34
+
35
+ // src/routes.ts
36
+ import { pagesRoutes } from "@internal/pagesRoutes";
37
+ var createRoutes = () => pagesRoutes.reduce(
38
+ (result, [name, path, meta, redirects]) => {
39
+ result.push(
40
+ {
41
+ name,
42
+ path,
43
+ component: Vuepress,
44
+ meta
45
+ },
46
+ ...redirects.map((item) => ({
47
+ path: item,
48
+ redirect: path
49
+ }))
50
+ );
51
+ return result;
52
+ },
53
+ [
54
+ {
55
+ name: "404",
56
+ path: "/:catchAll(.*)",
57
+ component: Vuepress
58
+ }
59
+ ]
60
+ );
61
+
62
+ // src/router.ts
63
+ var historyCreator = __VUEPRESS_SSR__ ? createMemoryHistory : createWebHistory;
64
+ var createVueRouter = () => {
65
+ const router = createRouter({
66
+ history: historyCreator(removeEndingSlash(siteData.value.base)),
67
+ routes: createRoutes(),
68
+ scrollBehavior: (to, from, savedPosition) => {
69
+ if (savedPosition)
70
+ return savedPosition;
71
+ if (to.hash)
72
+ return { el: to.hash };
73
+ return { top: 0 };
74
+ }
75
+ });
76
+ router.beforeResolve(async (to, from) => {
77
+ if (to.path !== from.path || from === START_LOCATION) {
78
+ ;
79
+ [pageData.value] = await Promise.all([
80
+ resolvers.resolvePageData(to.name),
81
+ pagesComponents[to.name]?.__asyncLoader()
82
+ ]);
83
+ }
84
+ });
85
+ return router;
86
+ };
87
+
88
+ // src/setupGlobalComponents.ts
89
+ var setupGlobalComponents = (app) => {
90
+ app.component("ClientOnly", ClientOnly);
91
+ app.component("Content", Content);
92
+ };
93
+
94
+ // src/setupGlobalComputed.ts
95
+ import { computed } from "vue";
96
+ var setupGlobalComputed = (app, router) => {
97
+ const routeLocale = computed(
98
+ () => resolvers.resolveRouteLocale(
99
+ siteData.value.locales,
100
+ router.currentRoute.value.path
101
+ )
102
+ );
103
+ const siteLocaleData = computed(
104
+ () => resolvers.resolveSiteLocaleData(siteData.value, routeLocale.value)
105
+ );
106
+ const pageFrontmatter = computed(
107
+ () => resolvers.resolvePageFrontmatter(pageData.value)
108
+ );
109
+ const pageHeadTitle = computed(
110
+ () => resolvers.resolvePageHeadTitle(pageData.value, siteLocaleData.value)
111
+ );
112
+ const pageHead = computed(
113
+ () => resolvers.resolvePageHead(
114
+ pageHeadTitle.value,
115
+ pageFrontmatter.value,
116
+ siteLocaleData.value
117
+ )
118
+ );
119
+ const pageLang = computed(() => resolvers.resolvePageLang(pageData.value));
120
+ app.provide(routeLocaleSymbol, routeLocale);
121
+ app.provide(siteLocaleDataSymbol, siteLocaleData);
122
+ app.provide(pageFrontmatterSymbol, pageFrontmatter);
123
+ app.provide(pageHeadTitleSymbol, pageHeadTitle);
124
+ app.provide(pageHeadSymbol, pageHead);
125
+ app.provide(pageLangSymbol, pageLang);
126
+ Object.defineProperties(app.config.globalProperties, {
127
+ $frontmatter: { get: () => pageFrontmatter.value },
128
+ $head: { get: () => pageHead.value },
129
+ $headTitle: { get: () => pageHeadTitle.value },
130
+ $lang: { get: () => pageLang.value },
131
+ $page: { get: () => pageData.value },
132
+ $routeLocale: { get: () => routeLocale.value },
133
+ $site: { get: () => siteData.value },
134
+ $siteLocale: { get: () => siteLocaleData.value },
135
+ $withBase: { get: () => withBase }
136
+ });
137
+ return {
138
+ pageData,
139
+ pageFrontmatter,
140
+ pageHead,
141
+ pageHeadTitle,
142
+ pageLang,
143
+ routeLocale,
144
+ siteData,
145
+ siteLocaleData
146
+ };
147
+ };
148
+
149
+ // src/setupUpdateHead.ts
150
+ import { isPlainObject, isString } from "@vuepress/shared";
151
+ import { onMounted, provide, ref, useSSRContext, watch } from "vue";
152
+ import { useRoute } from "vue-router";
153
+ var setupUpdateHead = () => {
154
+ const route = useRoute();
155
+ const head = usePageHead();
156
+ const lang = usePageLang();
157
+ if (__VUEPRESS_SSR__) {
158
+ const ssrContext = useSSRContext();
159
+ if (ssrContext) {
160
+ ssrContext.head = head.value;
161
+ ssrContext.lang = lang.value;
162
+ }
163
+ return;
164
+ }
165
+ const headTags = ref([]);
166
+ const loadHead = () => {
167
+ head.value.forEach((item) => {
168
+ const tag = queryHeadTag(item);
169
+ if (tag) {
170
+ headTags.value.push(tag);
171
+ }
172
+ });
173
+ };
174
+ const updateHead = () => {
175
+ document.documentElement.lang = lang.value;
176
+ headTags.value.forEach((item) => {
177
+ if (item.parentNode === document.head) {
178
+ document.head.removeChild(item);
179
+ }
180
+ });
181
+ headTags.value.splice(0, headTags.value.length);
182
+ head.value.forEach((item) => {
183
+ const tag = createHeadTag(item);
184
+ if (tag !== null) {
185
+ document.head.appendChild(tag);
186
+ headTags.value.push(tag);
187
+ }
188
+ });
189
+ };
190
+ provide(updateHeadSymbol, updateHead);
191
+ onMounted(() => {
192
+ loadHead();
193
+ updateHead();
194
+ watch(
195
+ () => __VUEPRESS_DEV__ ? head.value : route.path,
196
+ () => updateHead()
197
+ );
198
+ });
199
+ };
200
+ var queryHeadTag = ([
201
+ tagName,
202
+ attrs,
203
+ content = ""
204
+ ]) => {
205
+ const attrsSelector = Object.entries(attrs).map(([key, value]) => {
206
+ if (isString(value)) {
207
+ return `[${key}="${value}"]`;
208
+ }
209
+ if (value === true) {
210
+ return `[${key}]`;
211
+ }
212
+ return "";
213
+ }).join("");
214
+ const selector = `head > ${tagName}${attrsSelector}`;
215
+ const tags = Array.from(document.querySelectorAll(selector));
216
+ const matchedTag = tags.find((item) => item.innerText === content);
217
+ return matchedTag || null;
218
+ };
219
+ var createHeadTag = ([
220
+ tagName,
221
+ attrs,
222
+ content
223
+ ]) => {
224
+ if (!isString(tagName)) {
225
+ return null;
226
+ }
227
+ const tag = document.createElement(tagName);
228
+ if (isPlainObject(attrs)) {
229
+ Object.entries(attrs).forEach(([key, value]) => {
230
+ if (isString(value)) {
231
+ tag.setAttribute(key, value);
232
+ } else if (value === true) {
233
+ tag.setAttribute(key, "");
234
+ }
235
+ });
236
+ }
237
+ if (isString(content)) {
238
+ tag.appendChild(document.createTextNode(content));
239
+ }
240
+ return tag;
241
+ };
242
+
243
+ // src/app.ts
244
+ var appCreator = __VUEPRESS_DEV__ ? createApp : createSSRApp;
245
+ var createVueApp = async () => {
246
+ const app = appCreator({
247
+ name: "VuepressApp",
248
+ setup() {
249
+ setupUpdateHead();
250
+ for (const clientConfig of clientConfigs) {
251
+ clientConfig.setup?.();
252
+ }
253
+ return () => [
254
+ h(RouterView),
255
+ ...clientConfigs.flatMap(
256
+ ({ rootComponents = [] }) => rootComponents.map((component) => h(component))
257
+ )
258
+ ];
259
+ }
260
+ });
261
+ const router = createVueRouter();
262
+ setupGlobalComponents(app);
263
+ const globalComputed = setupGlobalComputed(app, router);
264
+ if (__VUEPRESS_DEV__ || __VUE_PROD_DEVTOOLS__) {
265
+ const { setupDevtools } = await import("./setupDevtools-EXVHPMXB.js");
266
+ setupDevtools(app, globalComputed);
267
+ }
268
+ for (const clientConfig of clientConfigs) {
269
+ await clientConfig.enhance?.({ app, router, siteData });
270
+ }
271
+ app.use(router);
272
+ return {
273
+ app,
274
+ router
275
+ };
276
+ };
277
+ if (!__VUEPRESS_SSR__) {
278
+ createVueApp().then(({ app, router }) => {
279
+ router.isReady().then(() => {
280
+ app.mount("#app");
281
+ });
282
+ });
283
+ }
284
+ export {
285
+ createVueApp
286
+ };
@@ -0,0 +1,273 @@
1
+ // src/composables/pagesData.ts
2
+ import { pagesData as pagesDataRaw } from "@internal/pagesData";
3
+ import { ref } from "vue";
4
+ var pagesData = ref(pagesDataRaw);
5
+ var usePagesData = () => pagesData;
6
+
7
+ // src/composables/pageData.ts
8
+ import { readonly, ref as ref2 } from "vue";
9
+ var pageDataEmpty = readonly({
10
+ key: "",
11
+ path: "",
12
+ title: "",
13
+ lang: "",
14
+ frontmatter: {},
15
+ excerpt: "",
16
+ headers: []
17
+ });
18
+ var pageData = ref2(pageDataEmpty);
19
+ var usePageData = () => pageData;
20
+ if (import.meta.webpackHot || import.meta.hot) {
21
+ __VUE_HMR_RUNTIME__.updatePageData = (data) => {
22
+ pagesData.value[data.key] = () => Promise.resolve(data);
23
+ if (data.key === pageData.value.key) {
24
+ pageData.value = data;
25
+ }
26
+ };
27
+ }
28
+
29
+ // src/composables/pageFrontmatter.ts
30
+ import { inject } from "vue";
31
+ var pageFrontmatterSymbol = Symbol(
32
+ __VUEPRESS_DEV__ ? "pageFrontmatter" : ""
33
+ );
34
+ var usePageFrontmatter = () => {
35
+ const pageFrontmatter = inject(pageFrontmatterSymbol);
36
+ if (!pageFrontmatter) {
37
+ throw new Error("usePageFrontmatter() is called without provider.");
38
+ }
39
+ return pageFrontmatter;
40
+ };
41
+
42
+ // src/composables/pageHead.ts
43
+ import { inject as inject2 } from "vue";
44
+ var pageHeadSymbol = Symbol(
45
+ __VUEPRESS_DEV__ ? "pageHead" : ""
46
+ );
47
+ var usePageHead = () => {
48
+ const pageHead = inject2(pageHeadSymbol);
49
+ if (!pageHead) {
50
+ throw new Error("usePageHead() is called without provider.");
51
+ }
52
+ return pageHead;
53
+ };
54
+
55
+ // src/composables/pageHeadTitle.ts
56
+ import { inject as inject3 } from "vue";
57
+ var pageHeadTitleSymbol = Symbol(
58
+ __VUEPRESS_DEV__ ? "pageHeadTitle" : ""
59
+ );
60
+ var usePageHeadTitle = () => {
61
+ const pageHeadTitle = inject3(pageHeadTitleSymbol);
62
+ if (!pageHeadTitle) {
63
+ throw new Error("usePageHeadTitle() is called without provider.");
64
+ }
65
+ return pageHeadTitle;
66
+ };
67
+
68
+ // src/composables/pageLang.ts
69
+ import { inject as inject4 } from "vue";
70
+ var pageLangSymbol = Symbol(
71
+ __VUEPRESS_DEV__ ? "pageLang" : ""
72
+ );
73
+ var usePageLang = () => {
74
+ const pageLang = inject4(pageLangSymbol);
75
+ if (!pageLang) {
76
+ throw new Error("usePageLang() is called without provider.");
77
+ }
78
+ return pageLang;
79
+ };
80
+
81
+ // src/composables/routeLocale.ts
82
+ import { inject as inject5 } from "vue";
83
+ var routeLocaleSymbol = Symbol(
84
+ __VUEPRESS_DEV__ ? "routeLocale" : ""
85
+ );
86
+ var useRouteLocale = () => {
87
+ const routeLocale = inject5(routeLocaleSymbol);
88
+ if (!routeLocale) {
89
+ throw new Error("useRouteLocale() is called without provider.");
90
+ }
91
+ return routeLocale;
92
+ };
93
+
94
+ // src/composables/siteData.ts
95
+ import { siteData as siteDataRaw } from "@internal/siteData";
96
+ import { ref as ref3 } from "vue";
97
+ var siteData = ref3(siteDataRaw);
98
+ var useSiteData = () => siteData;
99
+ if (import.meta.webpackHot || import.meta.hot) {
100
+ __VUE_HMR_RUNTIME__.updateSiteData = (data) => {
101
+ siteData.value = data;
102
+ };
103
+ }
104
+
105
+ // src/composables/siteLocaleData.ts
106
+ import { inject as inject6 } from "vue";
107
+ var siteLocaleDataSymbol = Symbol(
108
+ __VUEPRESS_DEV__ ? "siteLocaleData" : ""
109
+ );
110
+ var useSiteLocaleData = () => {
111
+ const siteLocaleData = inject6(siteLocaleDataSymbol);
112
+ if (!siteLocaleData) {
113
+ throw new Error("useSiteLocaleData() is called without provider.");
114
+ }
115
+ return siteLocaleData;
116
+ };
117
+
118
+ // src/composables/updateHead.ts
119
+ import { inject as inject7 } from "vue";
120
+ var updateHeadSymbol = Symbol(
121
+ __VUEPRESS_DEV__ ? "updateHead" : ""
122
+ );
123
+ var useUpdateHead = () => {
124
+ const updateHead = inject7(updateHeadSymbol);
125
+ if (!updateHead) {
126
+ throw new Error("useUpdateHead() is called without provider.");
127
+ }
128
+ return updateHead;
129
+ };
130
+
131
+ // src/resolvers.ts
132
+ import {
133
+ dedupeHead,
134
+ isArray,
135
+ isString,
136
+ resolveLocalePath
137
+ } from "@vuepress/shared";
138
+ import { reactive } from "vue";
139
+ var resolvers = reactive({
140
+ resolvePageData: async (pageKey) => {
141
+ const pageDataResolver = pagesData.value[pageKey];
142
+ const pageData2 = await pageDataResolver?.();
143
+ return pageData2 ?? pageDataEmpty;
144
+ },
145
+ resolvePageFrontmatter: (pageData2) => pageData2.frontmatter,
146
+ resolvePageHead: (headTitle, frontmatter, siteLocale) => {
147
+ const description = isString(frontmatter.description) ? frontmatter.description : siteLocale.description;
148
+ const head = [
149
+ ...isArray(frontmatter.head) ? frontmatter.head : [],
150
+ ...siteLocale.head,
151
+ ["title", {}, headTitle],
152
+ ["meta", { name: "description", content: description }]
153
+ ];
154
+ return dedupeHead(head);
155
+ },
156
+ resolvePageHeadTitle: (page, siteLocale) => `${page.title ? `${page.title} | ` : ``}${siteLocale.title}`,
157
+ resolvePageLang: (pageData2) => pageData2.lang || "en",
158
+ resolveRouteLocale: (locales, routePath) => resolveLocalePath(locales, routePath),
159
+ resolveSiteLocaleData: (site, routeLocale) => ({
160
+ ...site,
161
+ ...site.locales[routeLocale]
162
+ })
163
+ });
164
+
165
+ // src/components/ClientOnly.ts
166
+ import { defineComponent, onMounted, ref as ref4 } from "vue";
167
+ var ClientOnly = defineComponent({
168
+ name: "ClientOnly",
169
+ setup(_, ctx) {
170
+ const isMounted = ref4(false);
171
+ onMounted(() => {
172
+ isMounted.value = true;
173
+ });
174
+ return () => isMounted.value ? ctx.slots.default?.() : null;
175
+ }
176
+ });
177
+
178
+ // src/components/Content.ts
179
+ import { pagesComponents } from "@internal/pagesComponents";
180
+ import { computed, defineComponent as defineComponent2, h } from "vue";
181
+ var Content = defineComponent2({
182
+ name: "Content",
183
+ props: {
184
+ pageKey: {
185
+ type: String,
186
+ required: false,
187
+ default: ""
188
+ }
189
+ },
190
+ setup(props) {
191
+ const page = usePageData();
192
+ const pageComponent = computed(
193
+ () => pagesComponents[props.pageKey || page.value.key]
194
+ );
195
+ return () => pageComponent.value ? h(pageComponent.value) : h(
196
+ "div",
197
+ __VUEPRESS_DEV__ ? "Page does not exist. This is a fallback content." : "404 Not Found"
198
+ );
199
+ }
200
+ });
201
+
202
+ // src/components/Vuepress.ts
203
+ import { clientConfigs } from "@internal/clientConfigs";
204
+ import { isString as isString2 } from "@vuepress/shared";
205
+ import { computed as computed2, defineComponent as defineComponent3, h as h2 } from "vue";
206
+ var LAYOUT_NAME_DEFAULT = "Layout";
207
+ var LAYOUT_NAME_NOT_FOUND = "NotFound";
208
+ var layouts = clientConfigs.reduce(
209
+ (prev, item) => ({
210
+ ...prev,
211
+ ...item.layouts
212
+ }),
213
+ {}
214
+ );
215
+ var Vuepress = defineComponent3({
216
+ name: "Vuepress",
217
+ setup() {
218
+ const page = usePageData();
219
+ const layoutComponent = computed2(() => {
220
+ let layoutName;
221
+ if (page.value.path) {
222
+ const frontmatterLayout = page.value.frontmatter.layout;
223
+ if (isString2(frontmatterLayout)) {
224
+ layoutName = frontmatterLayout;
225
+ } else {
226
+ layoutName = LAYOUT_NAME_DEFAULT;
227
+ }
228
+ } else {
229
+ layoutName = LAYOUT_NAME_NOT_FOUND;
230
+ }
231
+ return layouts[layoutName];
232
+ });
233
+ return () => h2(layoutComponent.value);
234
+ }
235
+ });
236
+
237
+ // src/withBase.ts
238
+ import { isLinkHttp, removeLeadingSlash } from "@vuepress/shared";
239
+ var withBase = (url) => {
240
+ if (isLinkHttp(url))
241
+ return url;
242
+ const base = useSiteData().value.base;
243
+ return `${base}${removeLeadingSlash(url)}`;
244
+ };
245
+
246
+ export {
247
+ pagesData,
248
+ usePagesData,
249
+ pageDataEmpty,
250
+ pageData,
251
+ usePageData,
252
+ pageFrontmatterSymbol,
253
+ usePageFrontmatter,
254
+ pageHeadSymbol,
255
+ usePageHead,
256
+ pageHeadTitleSymbol,
257
+ usePageHeadTitle,
258
+ pageLangSymbol,
259
+ usePageLang,
260
+ routeLocaleSymbol,
261
+ useRouteLocale,
262
+ siteData,
263
+ useSiteData,
264
+ siteLocaleDataSymbol,
265
+ useSiteLocaleData,
266
+ updateHeadSymbol,
267
+ useUpdateHead,
268
+ resolvers,
269
+ ClientOnly,
270
+ Content,
271
+ Vuepress,
272
+ withBase
273
+ };
@@ -0,0 +1,264 @@
1
+ import { PageData, PageFrontmatter, HeadConfig, SiteData } from '@vuepress/shared';
2
+ export { PageData, PageFrontmatter, PageHeader, SiteData } from '@vuepress/shared';
3
+ import * as vue from 'vue';
4
+ import { Ref, ComputedRef, InjectionKey, App, Component } from 'vue';
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, vue.EmitsOptions, 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, Record<string, any>, 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
+ /**
33
+ * Global Layout
34
+ */
35
+ declare const Vuepress: vue.DefineComponent<{}, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
36
+ [key: string]: any;
37
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, vue.EmitsOptions, string, vue.VNodeProps & vue.AllowedComponentProps & vue.ComponentCustomProps, Readonly<vue.ExtractPropTypes<{}>>, {}>;
38
+
39
+ /**
40
+ * Ref wrapper of `PageData`
41
+ */
42
+ declare type PageDataRef<T extends Record<any, any> = Record<never, never>> = Ref<PageData<T>>;
43
+ /**
44
+ * Empty page data to be used as the fallback value
45
+ */
46
+ declare const pageDataEmpty: PageData<Record<never, never>, Record<string, unknown>>;
47
+ /**
48
+ * Global page data ref
49
+ */
50
+ declare const pageData: PageDataRef;
51
+ /**
52
+ * Returns the ref of the data of current page
53
+ */
54
+ declare const usePageData: <T extends Record<any, any> = Record<never, never>>() => PageDataRef<T>;
55
+
56
+ /**
57
+ * Ref wrapper of `PageFrontmatter`
58
+ */
59
+ declare type PageFrontmatterRef<T extends Record<any, any> = Record<string, unknown>> = ComputedRef<PageFrontmatter<T>>;
60
+ /**
61
+ * Injection key for page frontmatter
62
+ */
63
+ declare const pageFrontmatterSymbol: InjectionKey<PageFrontmatterRef>;
64
+ /**
65
+ * Returns the ref of the frontmatter of current page
66
+ */
67
+ declare const usePageFrontmatter: <T extends Record<any, any> = Record<string, unknown>>() => PageFrontmatterRef<T>;
68
+
69
+ /**
70
+ * Page head config, which would be used for generate html tags in `<head>`
71
+ */
72
+ declare type PageHead = HeadConfig[];
73
+ /**
74
+ * Ref wrapper of `PageHead`
75
+ */
76
+ declare type PageHeadRef = ComputedRef<PageHead>;
77
+ /**
78
+ * Injection key for page head
79
+ */
80
+ declare const pageHeadSymbol: InjectionKey<PageHeadRef>;
81
+ /**
82
+ * Returns the ref of the head config of current page
83
+ */
84
+ declare const usePageHead: () => PageHeadRef;
85
+
86
+ /**
87
+ * Page head title, which would be used as the content of `head > title` tag
88
+ */
89
+ declare type PageHeadTitle = string;
90
+ /**
91
+ * Ref wrapper of `PageHeadTitle`
92
+ */
93
+ declare type PageHeadTitleRef = ComputedRef<PageHeadTitle>;
94
+ /**
95
+ * Injection key for page head title
96
+ */
97
+ declare const pageHeadTitleSymbol: InjectionKey<PageHeadTitleRef>;
98
+ /**
99
+ * Returns the ref of the head title of current page
100
+ */
101
+ declare const usePageHeadTitle: () => PageHeadTitleRef;
102
+
103
+ /**
104
+ * Page language
105
+ */
106
+ declare type PageLang = string;
107
+ /**
108
+ * Ref wrapper of `PageLang`
109
+ */
110
+ declare type PageLangRef = ComputedRef<PageLang>;
111
+ /**
112
+ * Injection key for page language
113
+ */
114
+ declare const pageLangSymbol: InjectionKey<PageLangRef>;
115
+ /**
116
+ * Returns the ref of the language of current page
117
+ */
118
+ declare const usePageLang: () => PageLangRef;
119
+
120
+ /**
121
+ * Data resolvers of all pages
122
+ *
123
+ * The key is page key, and the value is an async function that
124
+ * returns the page data
125
+ */
126
+ declare type PagesData = Record<string, (() => Promise<PageData>) | undefined>;
127
+ /**
128
+ * Ref wrapper of `PagesData`
129
+ */
130
+ declare type PagesDataRef = Ref<PagesData>;
131
+ /**
132
+ * Global pages data ref
133
+ */
134
+ declare const pagesData: PagesDataRef;
135
+ /**
136
+ * Returns the ref of data resolvers of all pages
137
+ */
138
+ declare const usePagesData: () => PagesDataRef;
139
+
140
+ /**
141
+ * Route locale path
142
+ */
143
+ declare type RouteLocale = string;
144
+ /**
145
+ * Ref wrapper of `RouteLocale`
146
+ */
147
+ declare type RouteLocaleRef = ComputedRef<RouteLocale>;
148
+ /**
149
+ * Injection key for page route locale path
150
+ */
151
+ declare const routeLocaleSymbol: InjectionKey<RouteLocaleRef>;
152
+ /**
153
+ * Returns the ref of the route locale path of current page
154
+ */
155
+ declare const useRouteLocale: () => RouteLocaleRef;
156
+
157
+ /**
158
+ * Ref wrapper of `SiteData`
159
+ */
160
+ declare type SiteDataRef = Ref<SiteData>;
161
+ /**
162
+ * Global site data ref
163
+ */
164
+ declare const siteData: SiteDataRef;
165
+ /**
166
+ * Returns the ref of the site data
167
+ */
168
+ declare const useSiteData: () => SiteDataRef;
169
+
170
+ /**
171
+ * Site data of current locale
172
+ */
173
+ declare type SiteLocaleData = SiteData;
174
+ /**
175
+ * Ref wrapper of `SiteLocaleData`
176
+ */
177
+ declare type SiteLocaleDataRef = ComputedRef<SiteLocaleData>;
178
+ /**
179
+ * Injection key for site locale data
180
+ */
181
+ declare const siteLocaleDataSymbol: InjectionKey<SiteLocaleDataRef>;
182
+ /**
183
+ * Returns the ref of the site data of current locale
184
+ */
185
+ declare const useSiteLocaleData: () => SiteLocaleDataRef;
186
+
187
+ /**
188
+ * A util function to force update `<head>` of current page
189
+ */
190
+ declare type UpdateHead = () => void;
191
+ /**
192
+ * Injection key for `updateHead` util
193
+ */
194
+ declare const updateHeadSymbol: InjectionKey<UpdateHead>;
195
+ /**
196
+ * Returns the `updateHead` util
197
+ */
198
+ declare const useUpdateHead: () => UpdateHead;
199
+
200
+ /**
201
+ * Configure vuepress client
202
+ */
203
+ interface ClientConfig {
204
+ /**
205
+ * An enhance function to be called after vue app instance and
206
+ * vue-router instance has been created
207
+ */
208
+ enhance?: (context: {
209
+ app: App;
210
+ router: Router;
211
+ siteData: SiteDataRef;
212
+ }) => void | Promise<void>;
213
+ /**
214
+ * A function to be called inside the setup function of vue app
215
+ */
216
+ setup?: () => void;
217
+ /**
218
+ * Layout components
219
+ */
220
+ layouts?: Record<string, Component>;
221
+ /**
222
+ * Components to be placed directly into the root node of vue app
223
+ */
224
+ rootComponents?: Component[];
225
+ }
226
+
227
+ declare type CreateVueAppFunction = () => Promise<{
228
+ app: App;
229
+ router: Router;
230
+ }>;
231
+
232
+ declare type PageRouteItem = [
233
+ name: string,
234
+ path: string,
235
+ meta: RouteMeta,
236
+ redirects: string[]
237
+ ];
238
+
239
+ /**
240
+ * A helper function to help you define vuepress client config file
241
+ */
242
+ declare const defineClientConfig: (clientConfig?: ClientConfig) => ClientConfig;
243
+
244
+ /**
245
+ * Resolver methods to get global computed
246
+ *
247
+ * Users can override corresponding method for advanced customization
248
+ */
249
+ declare const resolvers: {
250
+ resolvePageData: (pageKey: string) => Promise<PageData>;
251
+ resolvePageFrontmatter: (pageData: PageData) => PageFrontmatter;
252
+ resolvePageHead: (headTitle: PageHeadTitle, frontmatter: PageFrontmatter, siteLocale: SiteLocaleData) => PageHead;
253
+ resolvePageHeadTitle: (page: PageData, siteLocale: SiteLocaleData) => PageHeadTitle;
254
+ resolvePageLang: (pageData: PageData) => PageLang;
255
+ resolveRouteLocale: (locales: SiteData['locales'], routePath: string) => RouteLocale;
256
+ resolveSiteLocaleData: (site: SiteData, routeLocale: RouteLocale) => SiteLocaleData;
257
+ };
258
+
259
+ /**
260
+ * Prefix url with site base
261
+ */
262
+ declare const withBase: (url: string) => string;
263
+
264
+ export { ClientConfig, ClientOnly, Content, CreateVueAppFunction, PageDataRef, PageFrontmatterRef, PageHead, PageHeadRef, PageHeadTitle, PageHeadTitleRef, PageLang, PageLangRef, PageRouteItem, PagesData, PagesDataRef, RouteLocale, RouteLocaleRef, SiteDataRef, SiteLocaleData, SiteLocaleDataRef, UpdateHead, Vuepress, defineClientConfig, pageData, pageDataEmpty, pageFrontmatterSymbol, pageHeadSymbol, pageHeadTitleSymbol, pageLangSymbol, pagesData, resolvers, routeLocaleSymbol, siteData, siteLocaleDataSymbol, updateHeadSymbol, usePageData, usePageFrontmatter, usePageHead, usePageHeadTitle, usePageLang, usePagesData, useRouteLocale, useSiteData, useSiteLocaleData, useUpdateHead, withBase };
package/dist/index.js ADDED
@@ -0,0 +1,60 @@
1
+ import {
2
+ ClientOnly,
3
+ Content,
4
+ Vuepress,
5
+ pageData,
6
+ pageDataEmpty,
7
+ pageFrontmatterSymbol,
8
+ pageHeadSymbol,
9
+ pageHeadTitleSymbol,
10
+ pageLangSymbol,
11
+ pagesData,
12
+ resolvers,
13
+ routeLocaleSymbol,
14
+ siteData,
15
+ siteLocaleDataSymbol,
16
+ updateHeadSymbol,
17
+ usePageData,
18
+ usePageFrontmatter,
19
+ usePageHead,
20
+ usePageHeadTitle,
21
+ usePageLang,
22
+ usePagesData,
23
+ useRouteLocale,
24
+ useSiteData,
25
+ useSiteLocaleData,
26
+ useUpdateHead,
27
+ withBase
28
+ } from "./chunk-O5XLV5GU.js";
29
+
30
+ // src/helpers/defineClientConfig.ts
31
+ var defineClientConfig = (clientConfig = {}) => clientConfig;
32
+ export {
33
+ ClientOnly,
34
+ Content,
35
+ Vuepress,
36
+ defineClientConfig,
37
+ pageData,
38
+ pageDataEmpty,
39
+ pageFrontmatterSymbol,
40
+ pageHeadSymbol,
41
+ pageHeadTitleSymbol,
42
+ pageLangSymbol,
43
+ pagesData,
44
+ resolvers,
45
+ routeLocaleSymbol,
46
+ siteData,
47
+ siteLocaleDataSymbol,
48
+ updateHeadSymbol,
49
+ usePageData,
50
+ usePageFrontmatter,
51
+ usePageHead,
52
+ usePageHeadTitle,
53
+ usePageLang,
54
+ usePagesData,
55
+ useRouteLocale,
56
+ useSiteData,
57
+ useSiteLocaleData,
58
+ useUpdateHead,
59
+ withBase
60
+ };
@@ -0,0 +1,88 @@
1
+ // src/setupDevtools.ts
2
+ import { setupDevtoolsPlugin } from "@vue/devtools-api";
3
+ import { watch } from "vue";
4
+ var PLUGIN_ID = "org.vuejs.vuepress";
5
+ var PLUGIN_LABEL = "VuePress";
6
+ var PLUGIN_COMPONENT_STATE_TYPE = PLUGIN_LABEL;
7
+ var INSPECTOR_ID = PLUGIN_ID;
8
+ var INSPECTOR_LABEL = PLUGIN_LABEL;
9
+ var INSPECTOR_GLOBAL_COMPUTED_ID = "global-computed";
10
+ var INSPECTOR_GLOBAL_COMPUTED_LABEL = "Global Computed";
11
+ var setupDevtools = (app, globalComputed) => {
12
+ setupDevtoolsPlugin(
13
+ {
14
+ app,
15
+ id: PLUGIN_ID,
16
+ label: PLUGIN_LABEL,
17
+ packageName: "@vuepress/client",
18
+ homepage: "https://v2.vuepress.vuejs.org",
19
+ logo: "https://v2.vuepress.vuejs.org/images/hero.png",
20
+ componentStateTypes: [PLUGIN_COMPONENT_STATE_TYPE]
21
+ },
22
+ (api) => {
23
+ const globalComputedEntries = Object.entries(globalComputed);
24
+ const globalComputedKeys = Object.keys(globalComputed);
25
+ const globalComputedValues = Object.values(globalComputed);
26
+ api.on.inspectComponent((payload) => {
27
+ payload.instanceData.state.push(
28
+ ...globalComputedEntries.map(([name, item]) => ({
29
+ type: PLUGIN_COMPONENT_STATE_TYPE,
30
+ editable: false,
31
+ key: name,
32
+ value: item.value
33
+ }))
34
+ );
35
+ });
36
+ api.addInspector({
37
+ id: INSPECTOR_ID,
38
+ label: INSPECTOR_LABEL,
39
+ icon: "article"
40
+ });
41
+ api.on.getInspectorTree((payload) => {
42
+ if (payload.inspectorId !== INSPECTOR_ID)
43
+ return;
44
+ payload.rootNodes = [
45
+ {
46
+ id: INSPECTOR_GLOBAL_COMPUTED_ID,
47
+ label: INSPECTOR_GLOBAL_COMPUTED_LABEL,
48
+ children: globalComputedKeys.map((name) => ({
49
+ id: name,
50
+ label: name
51
+ }))
52
+ }
53
+ ];
54
+ });
55
+ api.on.getInspectorState((payload) => {
56
+ if (payload.inspectorId !== INSPECTOR_ID)
57
+ return;
58
+ if (payload.nodeId === INSPECTOR_GLOBAL_COMPUTED_ID) {
59
+ payload.state = {
60
+ [INSPECTOR_GLOBAL_COMPUTED_LABEL]: globalComputedEntries.map(
61
+ ([name, item]) => ({
62
+ key: name,
63
+ value: item.value
64
+ })
65
+ )
66
+ };
67
+ }
68
+ if (globalComputedKeys.includes(payload.nodeId)) {
69
+ payload.state = {
70
+ [INSPECTOR_GLOBAL_COMPUTED_LABEL]: [
71
+ {
72
+ key: payload.nodeId,
73
+ value: globalComputed[payload.nodeId].value
74
+ }
75
+ ]
76
+ };
77
+ }
78
+ });
79
+ watch(globalComputedValues, () => {
80
+ api.notifyComponentUpdate();
81
+ api.sendInspectorState(INSPECTOR_ID);
82
+ });
83
+ }
84
+ );
85
+ };
86
+ export {
87
+ setupDevtools
88
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/client",
3
- "version": "2.0.0-beta.50-pre",
3
+ "version": "2.0.0-beta.51",
4
4
  "description": "Client package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -28,15 +28,15 @@
28
28
  "module": "./dist/index.js",
29
29
  "types": "./dist/index.d.ts",
30
30
  "files": [
31
- "./dist",
32
- "./templates",
33
- "./types.d.ts"
31
+ "dist",
32
+ "templates",
33
+ "types.d.ts"
34
34
  ],
35
35
  "dependencies": {
36
36
  "@vue/devtools-api": "^6.2.1",
37
- "@vuepress/shared": "2.0.0-beta.50-pre",
37
+ "@vuepress/shared": "2.0.0-beta.51",
38
38
  "vue": "^3.2.37",
39
- "vue-router": "^4.1.3"
39
+ "vue-router": "^4.1.4"
40
40
  },
41
41
  "publishConfig": {
42
42
  "access": "public"
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html lang="{{ lang }}">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <meta name="generator" content="VuePress {{ version }}">
7
+ <!--vuepress-ssr-head-->
8
+ <!--vuepress-ssr-resources-->
9
+ <!--vuepress-ssr-styles-->
10
+ </head>
11
+ <body>
12
+ <div id="app"><!--vuepress-ssr-app--></div>
13
+ <!--vuepress-ssr-scripts-->
14
+ </body>
15
+ </html>
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ </head>
7
+ <body>
8
+ <div id="app"></div>
9
+ </body>
10
+ </html>
package/types.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ declare const __VUEPRESS_VERSION__: string
2
+ declare const __VUEPRESS_DEV__: boolean
3
+ declare const __VUEPRESS_SSR__: boolean
4
+ declare const __VUE_HMR_RUNTIME__: Record<string, any>
5
+ declare const __VUE_OPTIONS_API__: boolean
6
+ declare const __VUE_PROD_DEVTOOLS__: boolean