@vuepress/client 2.0.0-rc.3 → 2.0.0-rc.31

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.
@@ -1,394 +0,0 @@
1
- // src/composables/layouts.ts
2
- import { inject } from "vue";
3
- var layoutsSymbol = Symbol(
4
- __VUEPRESS_DEV__ ? "layouts" : ""
5
- );
6
- var useLayouts = () => {
7
- const layouts = inject(layoutsSymbol);
8
- if (!layouts) {
9
- throw new Error("useLayouts() is called without provider.");
10
- }
11
- return layouts;
12
- };
13
-
14
- // src/composables/pageData.ts
15
- import { inject as inject2 } from "vue";
16
- var pageDataSymbol = Symbol(
17
- __VUEPRESS_DEV__ ? "pageData" : ""
18
- );
19
- var usePageData = () => {
20
- const pageData = inject2(pageDataSymbol);
21
- if (!pageData) {
22
- throw new Error("pageData() is called without provider.");
23
- }
24
- return pageData;
25
- };
26
-
27
- // src/composables/pageFrontmatter.ts
28
- import { inject as inject3 } from "vue";
29
- var pageFrontmatterSymbol = Symbol(
30
- __VUEPRESS_DEV__ ? "pageFrontmatter" : ""
31
- );
32
- var usePageFrontmatter = () => {
33
- const pageFrontmatter = inject3(pageFrontmatterSymbol);
34
- if (!pageFrontmatter) {
35
- throw new Error("usePageFrontmatter() is called without provider.");
36
- }
37
- return pageFrontmatter;
38
- };
39
-
40
- // src/composables/pageHead.ts
41
- import { inject as inject4 } from "vue";
42
- var pageHeadSymbol = Symbol(
43
- __VUEPRESS_DEV__ ? "pageHead" : ""
44
- );
45
- var usePageHead = () => {
46
- const pageHead = inject4(pageHeadSymbol);
47
- if (!pageHead) {
48
- throw new Error("usePageHead() is called without provider.");
49
- }
50
- return pageHead;
51
- };
52
-
53
- // src/composables/pageHeadTitle.ts
54
- import { inject as inject5 } from "vue";
55
- var pageHeadTitleSymbol = Symbol(
56
- __VUEPRESS_DEV__ ? "pageHeadTitle" : ""
57
- );
58
- var usePageHeadTitle = () => {
59
- const pageHeadTitle = inject5(pageHeadTitleSymbol);
60
- if (!pageHeadTitle) {
61
- throw new Error("usePageHeadTitle() is called without provider.");
62
- }
63
- return pageHeadTitle;
64
- };
65
-
66
- // src/composables/pageLang.ts
67
- import { inject as inject6 } from "vue";
68
- var pageLangSymbol = Symbol(
69
- __VUEPRESS_DEV__ ? "pageLang" : ""
70
- );
71
- var usePageLang = () => {
72
- const pageLang = inject6(pageLangSymbol);
73
- if (!pageLang) {
74
- throw new Error("usePageLang() is called without provider.");
75
- }
76
- return pageLang;
77
- };
78
-
79
- // src/composables/pageLayout.ts
80
- import { inject as inject7 } from "vue";
81
- var pageLayoutSymbol = Symbol(
82
- __VUEPRESS_DEV__ ? "pageLayout" : ""
83
- );
84
- var usePageLayout = () => {
85
- const pageLayout = inject7(pageLayoutSymbol);
86
- if (!pageLayout) {
87
- throw new Error("usePageLayout() is called without provider.");
88
- }
89
- return pageLayout;
90
- };
91
-
92
- // src/composables/routeLocale.ts
93
- import { inject as inject8 } from "vue";
94
- var routeLocaleSymbol = Symbol(
95
- __VUEPRESS_DEV__ ? "routeLocale" : ""
96
- );
97
- var useRouteLocale = () => {
98
- const routeLocale = inject8(routeLocaleSymbol);
99
- if (!routeLocale) {
100
- throw new Error("useRouteLocale() is called without provider.");
101
- }
102
- return routeLocale;
103
- };
104
-
105
- // src/router/routes.ts
106
- import {
107
- redirects as redirectsRaw,
108
- routes as routesRaw
109
- } from "@internal/routes";
110
- import { shallowRef } from "vue";
111
- var redirects = shallowRef(redirectsRaw);
112
- var routes = shallowRef(routesRaw);
113
- if (__VUEPRESS_DEV__ && (import.meta.webpackHot || import.meta.hot)) {
114
- __VUE_HMR_RUNTIME__.updateRoutes = (data) => {
115
- routes.value = data;
116
- };
117
- __VUE_HMR_RUNTIME__.updateRedirects = (data) => {
118
- redirects.value = data;
119
- };
120
- }
121
-
122
- // src/router/resolveRoutePath.ts
123
- import { normalizeRoutePath } from "@vuepress/shared";
124
- var resolveRoutePath = (path) => {
125
- const normalizedPath = normalizeRoutePath(path);
126
- if (routes.value[normalizedPath])
127
- return normalizedPath;
128
- const encodedPath = encodeURI(normalizedPath);
129
- if (routes.value[encodedPath])
130
- return encodedPath;
131
- return redirects.value[normalizedPath] || normalizedPath;
132
- };
133
-
134
- // src/router/resolveRoute.ts
135
- var resolveRoute = (path) => {
136
- const routePath = resolveRoutePath(path);
137
- const route = routes.value[routePath] ?? {
138
- ...routes.value["/404.html"],
139
- notFound: true
140
- };
141
- return {
142
- path: routePath,
143
- notFound: false,
144
- ...route
145
- };
146
- };
147
-
148
- // src/composables/routes.ts
149
- var useRedirects = () => redirects;
150
- var useRoutes = () => routes;
151
-
152
- // src/composables/siteData.ts
153
- import { siteData as siteDataRaw } from "@internal/siteData";
154
- import { shallowRef as shallowRef2 } from "vue";
155
- var siteData = shallowRef2(siteDataRaw);
156
- var useSiteData = () => siteData;
157
- if (__VUEPRESS_DEV__ && (import.meta.webpackHot || import.meta.hot)) {
158
- __VUE_HMR_RUNTIME__.updateSiteData = (data) => {
159
- siteData.value = data;
160
- };
161
- }
162
-
163
- // src/composables/siteLocaleData.ts
164
- import { inject as inject9 } from "vue";
165
- var siteLocaleDataSymbol = Symbol(
166
- __VUEPRESS_DEV__ ? "siteLocaleData" : ""
167
- );
168
- var useSiteLocaleData = () => {
169
- const siteLocaleData = inject9(siteLocaleDataSymbol);
170
- if (!siteLocaleData) {
171
- throw new Error("useSiteLocaleData() is called without provider.");
172
- }
173
- return siteLocaleData;
174
- };
175
-
176
- // src/composables/updateHead.ts
177
- import { inject as inject10 } from "vue";
178
- var updateHeadSymbol = Symbol(
179
- __VUEPRESS_DEV__ ? "updateHead" : ""
180
- );
181
- var useUpdateHead = () => {
182
- const updateHead = inject10(updateHeadSymbol);
183
- if (!updateHead) {
184
- throw new Error("useUpdateHead() is called without provider.");
185
- }
186
- return updateHead;
187
- };
188
-
189
- // src/components/ClientOnly.ts
190
- import { defineComponent, onMounted, ref } from "vue";
191
- var ClientOnly = defineComponent({
192
- name: "ClientOnly",
193
- setup(_, ctx) {
194
- const isMounted = ref(false);
195
- onMounted(() => {
196
- isMounted.value = true;
197
- });
198
- return () => isMounted.value ? ctx.slots.default?.() : null;
199
- }
200
- });
201
-
202
- // src/components/Content.ts
203
- import { computed, defineAsyncComponent, defineComponent as defineComponent2, h } from "vue";
204
- var Content = defineComponent2({
205
- // eslint-disable-next-line vue/no-reserved-component-names
206
- name: "Content",
207
- props: {
208
- path: {
209
- type: String,
210
- required: false,
211
- default: ""
212
- }
213
- },
214
- setup(props) {
215
- const pageData = usePageData();
216
- const pageComponent = computed(() => {
217
- const route = resolveRoute(props.path || pageData.value.path);
218
- return defineAsyncComponent(() => route.loader().then(({ comp }) => comp));
219
- });
220
- return () => h(pageComponent.value);
221
- }
222
- });
223
-
224
- // src/helpers/defineClientConfig.ts
225
- var defineClientConfig = (clientConfig = {}) => clientConfig;
226
-
227
- // src/helpers/withBase.ts
228
- import { isLinkHttp, removeLeadingSlash } from "@vuepress/shared";
229
- var withBase = (url) => {
230
- if (isLinkHttp(url))
231
- return url;
232
- return `${__VUEPRESS_BASE__}${removeLeadingSlash(url)}`;
233
- };
234
-
235
- // src/components/VPLink.ts
236
- import { h as h2 } from "vue";
237
- import { useRouter } from "vue-router";
238
- var guardEvent = (event) => {
239
- if (event.metaKey || event.altKey || event.ctrlKey || event.shiftKey)
240
- return;
241
- if (event.defaultPrevented)
242
- return;
243
- if (event.button !== void 0 && event.button !== 0)
244
- return;
245
- if (event.currentTarget) {
246
- const target = event.currentTarget.getAttribute("target");
247
- if (target?.match(/\b_blank\b/i))
248
- return;
249
- }
250
- event.preventDefault();
251
- return true;
252
- };
253
- var VPLink = ({ to = "" }, { slots }) => {
254
- const router = useRouter();
255
- const path = withBase(resolveRoutePath(to));
256
- return h2(
257
- "a",
258
- {
259
- class: "vp-link",
260
- href: path,
261
- onClick: (event = {}) => {
262
- guardEvent(event) ? router.push(to).catch() : Promise.resolve();
263
- }
264
- },
265
- slots.default?.()
266
- );
267
- };
268
- VPLink.displayName = "VPLink";
269
-
270
- // src/resolvers.ts
271
- import { dedupeHead, isString, resolveLocalePath } from "@vuepress/shared";
272
- import { reactive } from "vue";
273
-
274
- // src/constants.ts
275
- var LAYOUT_NAME_DEFAULT = "Layout";
276
- var LAYOUT_NAME_NOT_FOUND = "NotFound";
277
-
278
- // src/resolvers.ts
279
- var resolvers = reactive({
280
- /**
281
- * Resolve layouts component map
282
- */
283
- resolveLayouts: (clientConfigs) => clientConfigs.reduce(
284
- (prev, item) => ({
285
- ...prev,
286
- ...item.layouts
287
- }),
288
- {}
289
- ),
290
- /**
291
- * Resolve page frontmatter from page data
292
- */
293
- resolvePageFrontmatter: (pageData) => pageData.frontmatter,
294
- /**
295
- * Merge the head config in frontmatter and site locale
296
- *
297
- * Frontmatter should take priority over site locale
298
- */
299
- resolvePageHead: (headTitle, frontmatter, siteLocale) => {
300
- const description = isString(frontmatter.description) ? frontmatter.description : siteLocale.description;
301
- const head = [
302
- ...Array.isArray(frontmatter.head) ? frontmatter.head : [],
303
- ...siteLocale.head,
304
- ["title", {}, headTitle],
305
- ["meta", { name: "description", content: description }]
306
- ];
307
- return dedupeHead(head);
308
- },
309
- /**
310
- * Resolve the content of page head title
311
- *
312
- * It would be used as the content of the `<title>` tag
313
- */
314
- resolvePageHeadTitle: (page, siteLocale) => [page.title, siteLocale.title].filter((item) => !!item).join(" | "),
315
- /**
316
- * Resolve page language from page data
317
- *
318
- * It would be used as the `lang` attribute of `<html>` tag
319
- */
320
- resolvePageLang: (page, siteLocale) => page.lang || siteLocale.lang || "en-US",
321
- /**
322
- * Resolve layout component of current page
323
- */
324
- resolvePageLayout: (page, layouts) => {
325
- let layoutName;
326
- if (page.path) {
327
- const frontmatterLayout = page.frontmatter.layout;
328
- if (isString(frontmatterLayout)) {
329
- layoutName = frontmatterLayout;
330
- } else {
331
- layoutName = LAYOUT_NAME_DEFAULT;
332
- }
333
- } else {
334
- layoutName = LAYOUT_NAME_NOT_FOUND;
335
- }
336
- return layouts[layoutName];
337
- },
338
- /**
339
- * Resolve locale path according to route path and locales config
340
- */
341
- resolveRouteLocale: (locales, routePath) => resolveLocalePath(locales, routePath),
342
- /**
343
- * Resolve site data for specific locale
344
- *
345
- * It would merge the locales fields to the root fields
346
- */
347
- resolveSiteLocaleData: (site, routeLocale) => ({
348
- ...site,
349
- ...site.locales[routeLocale],
350
- head: [
351
- // when merging head, the locales head should be placed before root head
352
- // to get higher priority
353
- ...site.locales[routeLocale]?.head ?? [],
354
- ...site.head ?? []
355
- ]
356
- })
357
- });
358
-
359
- export {
360
- layoutsSymbol,
361
- useLayouts,
362
- pageDataSymbol,
363
- usePageData,
364
- pageFrontmatterSymbol,
365
- usePageFrontmatter,
366
- pageHeadSymbol,
367
- usePageHead,
368
- pageHeadTitleSymbol,
369
- usePageHeadTitle,
370
- pageLangSymbol,
371
- usePageLang,
372
- pageLayoutSymbol,
373
- usePageLayout,
374
- routeLocaleSymbol,
375
- useRouteLocale,
376
- redirects,
377
- routes,
378
- resolveRoutePath,
379
- resolveRoute,
380
- useRedirects,
381
- useRoutes,
382
- siteData,
383
- useSiteData,
384
- siteLocaleDataSymbol,
385
- useSiteLocaleData,
386
- updateHeadSymbol,
387
- useUpdateHead,
388
- ClientOnly,
389
- Content,
390
- defineClientConfig,
391
- withBase,
392
- VPLink,
393
- resolvers
394
- };
@@ -1,9 +0,0 @@
1
- import { App } from 'vue';
2
- import { Router } from 'vue-router';
3
-
4
- type CreateVueAppFunction = () => Promise<{
5
- app: App;
6
- router: Router;
7
- }>;
8
-
9
- export type { CreateVueAppFunction as C };
@@ -1,89 +0,0 @@
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
- // fix recursive reference
15
- app,
16
- id: PLUGIN_ID,
17
- label: PLUGIN_LABEL,
18
- packageName: "@vuepress/client",
19
- homepage: "https://v2.vuepress.vuejs.org",
20
- logo: "https://v2.vuepress.vuejs.org/images/hero.png",
21
- componentStateTypes: [PLUGIN_COMPONENT_STATE_TYPE]
22
- },
23
- (api) => {
24
- const globalComputedEntries = Object.entries(globalComputed);
25
- const globalComputedKeys = Object.keys(globalComputed);
26
- const globalComputedValues = Object.values(globalComputed);
27
- api.on.inspectComponent((payload) => {
28
- payload.instanceData.state.push(
29
- ...globalComputedEntries.map(([name, item]) => ({
30
- type: PLUGIN_COMPONENT_STATE_TYPE,
31
- editable: false,
32
- key: name,
33
- value: item.value
34
- }))
35
- );
36
- });
37
- api.addInspector({
38
- id: INSPECTOR_ID,
39
- label: INSPECTOR_LABEL,
40
- icon: "article"
41
- });
42
- api.on.getInspectorTree((payload) => {
43
- if (payload.inspectorId !== INSPECTOR_ID)
44
- return;
45
- payload.rootNodes = [
46
- {
47
- id: INSPECTOR_GLOBAL_COMPUTED_ID,
48
- label: INSPECTOR_GLOBAL_COMPUTED_LABEL,
49
- children: globalComputedKeys.map((name) => ({
50
- id: name,
51
- label: name
52
- }))
53
- }
54
- ];
55
- });
56
- api.on.getInspectorState((payload) => {
57
- if (payload.inspectorId !== INSPECTOR_ID)
58
- return;
59
- if (payload.nodeId === INSPECTOR_GLOBAL_COMPUTED_ID) {
60
- payload.state = {
61
- [INSPECTOR_GLOBAL_COMPUTED_LABEL]: globalComputedEntries.map(
62
- ([name, item]) => ({
63
- key: name,
64
- value: item.value
65
- })
66
- )
67
- };
68
- }
69
- if (globalComputedKeys.includes(payload.nodeId)) {
70
- payload.state = {
71
- [INSPECTOR_GLOBAL_COMPUTED_LABEL]: [
72
- {
73
- key: payload.nodeId,
74
- value: globalComputed[payload.nodeId].value
75
- }
76
- ]
77
- };
78
- }
79
- });
80
- watch(globalComputedValues, () => {
81
- api.notifyComponentUpdate();
82
- api.sendInspectorState(INSPECTOR_ID);
83
- });
84
- }
85
- );
86
- };
87
- export {
88
- setupDevtools
89
- };