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

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.
@@ -0,0 +1,448 @@
1
+ // src/composables/clientData.ts
2
+ import { inject } from "vue";
3
+ var clientDataSymbol = Symbol(
4
+ __VUEPRESS_DEV__ ? "clientData" : ""
5
+ );
6
+ var useClientData = () => {
7
+ const clientData = inject(clientDataSymbol);
8
+ if (!clientData) {
9
+ throw new Error("useClientData() is called without provider.");
10
+ }
11
+ return clientData;
12
+ };
13
+
14
+ // src/composables/clientDataUtils.ts
15
+ var useLayouts = () => useClientData().layouts;
16
+ var usePageComponent = () => useClientData().pageComponent;
17
+ var usePageData = () => useClientData().pageData;
18
+ var usePageFrontmatter = () => useClientData().pageFrontmatter;
19
+ var usePageHead = () => useClientData().pageHead;
20
+ var usePageLang = () => useClientData().pageLang;
21
+ var usePageLayout = () => useClientData().pageLayout;
22
+ var useRedirects = () => useClientData().redirects;
23
+ var useRouteLocale = () => useClientData().routeLocale;
24
+ var useRoutePath = () => useClientData().routePath;
25
+ var useRoutes = () => useClientData().routes;
26
+ var useSiteData = () => useClientData().siteData;
27
+ var useSiteLocaleData = () => useClientData().siteLocaleData;
28
+
29
+ // src/composables/onContentUpdated.ts
30
+ import { onUnmounted } from "vue";
31
+
32
+ // src/internal/contentUpdatedCallbacks.ts
33
+ import { shallowRef } from "vue";
34
+ var contentUpdatedCallbacks = shallowRef([]);
35
+
36
+ // src/composables/onContentUpdated.ts
37
+ var onContentUpdated = (fn) => {
38
+ contentUpdatedCallbacks.value.push(fn);
39
+ onUnmounted(() => {
40
+ contentUpdatedCallbacks.value = contentUpdatedCallbacks.value.filter(
41
+ (f) => f !== fn
42
+ );
43
+ });
44
+ };
45
+
46
+ // src/composables/updateHead.ts
47
+ import { inject as inject2 } from "vue";
48
+ var updateHeadSymbol = Symbol(
49
+ __VUEPRESS_DEV__ ? "updateHead" : ""
50
+ );
51
+ var useUpdateHead = () => {
52
+ const updateHead = inject2(updateHeadSymbol);
53
+ if (!updateHead) {
54
+ throw new Error("useUpdateHead() is called without provider.");
55
+ }
56
+ return updateHead;
57
+ };
58
+
59
+ // src/router/resolveRoutePath.ts
60
+ import { normalizeRoutePath } from "@vuepress/shared";
61
+
62
+ // src/internal/routes.ts
63
+ import {
64
+ redirects as redirectsRaw,
65
+ routes as routesRaw
66
+ } from "@internal/routes";
67
+ import { shallowRef as shallowRef2 } from "vue";
68
+ var redirects = shallowRef2(redirectsRaw);
69
+ var routes = shallowRef2(routesRaw);
70
+ if (__VUEPRESS_DEV__ && (import.meta.webpackHot || import.meta.hot)) {
71
+ __VUE_HMR_RUNTIME__.updateRedirects = (data) => {
72
+ redirects.value = data;
73
+ };
74
+ __VUE_HMR_RUNTIME__.updateRoutes = (data) => {
75
+ routes.value = data;
76
+ };
77
+ }
78
+
79
+ // src/router/resolveRoutePath.ts
80
+ var resolveRoutePath = (pathname, currentPath) => {
81
+ const normalizedRoutePath = normalizeRoutePath(pathname, currentPath);
82
+ if (routes.value[normalizedRoutePath]) return normalizedRoutePath;
83
+ const encodedRoutePath = encodeURI(normalizedRoutePath);
84
+ if (routes.value[encodedRoutePath]) {
85
+ return encodedRoutePath;
86
+ }
87
+ const redirectedRoutePath = redirects.value[normalizedRoutePath] || redirects.value[encodedRoutePath];
88
+ if (redirectedRoutePath) {
89
+ return redirectedRoutePath;
90
+ }
91
+ return normalizedRoutePath;
92
+ };
93
+
94
+ // src/router/resolveRoute.ts
95
+ import { splitPath } from "@vuepress/shared";
96
+ var resolveRoute = (path, currentPath) => {
97
+ const { pathname, hashAndQueries } = splitPath(path);
98
+ const routePath = resolveRoutePath(pathname, currentPath);
99
+ const routeFullPath = routePath + hashAndQueries;
100
+ if (!routes.value[routePath]) {
101
+ return {
102
+ ...routes.value["/404.html"],
103
+ path: routeFullPath,
104
+ notFound: true
105
+ };
106
+ }
107
+ return {
108
+ ...routes.value[routePath],
109
+ path: routeFullPath,
110
+ notFound: false
111
+ };
112
+ };
113
+
114
+ // src/router/resolveRouteFullPath.ts
115
+ import { splitPath as splitPath2 } from "@vuepress/shared";
116
+ var resolveRouteFullPath = (path, currentPath) => {
117
+ const { pathname, hashAndQueries } = splitPath2(path);
118
+ return resolveRoutePath(pathname, currentPath) + hashAndQueries;
119
+ };
120
+
121
+ // src/router/index.ts
122
+ import { useRoute, useRouter } from "vue-router";
123
+
124
+ // src/components/RouteLink.ts
125
+ import { computed, defineComponent, h } from "vue";
126
+ import { useRoute as useRoute2, useRouter as useRouter2 } from "vue-router";
127
+ var guardEvent = (event) => {
128
+ if (event.metaKey || event.altKey || event.ctrlKey || event.shiftKey) return;
129
+ if (event.defaultPrevented) return;
130
+ if (event.button !== void 0 && event.button !== 0) return;
131
+ if (event.currentTarget) {
132
+ const target = event.currentTarget.getAttribute("target");
133
+ if (target?.match(/\b_blank\b/i)) return;
134
+ }
135
+ event.preventDefault();
136
+ return true;
137
+ };
138
+ var RouteLink = defineComponent({
139
+ name: "RouteLink",
140
+ props: {
141
+ /**
142
+ * The route path to link to
143
+ */
144
+ to: {
145
+ type: String,
146
+ required: true
147
+ },
148
+ /**
149
+ * Whether the link is active to have an active class
150
+ *
151
+ * Notice that the active status is not automatically determined according to the current route.
152
+ */
153
+ active: Boolean,
154
+ /**
155
+ * The class to add when the link is active
156
+ */
157
+ activeClass: {
158
+ type: String,
159
+ default: "route-link-active"
160
+ }
161
+ },
162
+ slots: Object,
163
+ setup(props, { slots }) {
164
+ const router = useRouter2();
165
+ const route = useRoute2();
166
+ const path = computed(
167
+ () => props.to.startsWith("#") || props.to.startsWith("?") ? props.to : `${__VUEPRESS_BASE__}${resolveRouteFullPath(props.to, route.path).substring(1)}`
168
+ );
169
+ return () => h(
170
+ "a",
171
+ {
172
+ class: ["route-link", { [props.activeClass]: props.active }],
173
+ href: path.value,
174
+ onClick: (event = {}) => {
175
+ if (guardEvent(event)) {
176
+ void router.push(props.to).catch();
177
+ }
178
+ }
179
+ },
180
+ slots.default()
181
+ );
182
+ }
183
+ });
184
+
185
+ // src/components/AutoLink.ts
186
+ import { isLinkWithProtocol } from "@vuepress/shared";
187
+ import { computed as computed2, defineComponent as defineComponent2, h as h2, toRef } from "vue";
188
+ import { useRoute as useRoute3 } from "vue-router";
189
+ var AutoLink = defineComponent2({
190
+ name: "AutoLink",
191
+ props: {
192
+ config: {
193
+ type: Object,
194
+ required: true
195
+ }
196
+ },
197
+ slots: Object,
198
+ setup(props, { slots }) {
199
+ const config = toRef(props, "config");
200
+ const route = useRoute3();
201
+ const siteData = useSiteData();
202
+ const withProtocol = computed2(() => isLinkWithProtocol(config.value.link));
203
+ const linkTarget = computed2(
204
+ () => config.value.target || (withProtocol.value ? "_blank" : void 0)
205
+ );
206
+ const isBlankTarget = computed2(() => linkTarget.value === "_blank");
207
+ const isInternal = computed2(
208
+ () => !withProtocol.value && !isBlankTarget.value
209
+ );
210
+ const linkRel = computed2(
211
+ () => config.value.rel || (isBlankTarget.value ? "noopener noreferrer" : null)
212
+ );
213
+ const linkAriaLabel = computed2(
214
+ () => config.value.ariaLabel ?? config.value.text
215
+ );
216
+ const shouldBeActiveInSubpath = computed2(() => {
217
+ if (config.value.exact) return false;
218
+ const localePaths = Object.keys(siteData.value.locales);
219
+ return localePaths.length ? (
220
+ // Check all the locales
221
+ localePaths.every((key) => key !== config.value.link)
222
+ ) : (
223
+ // Check root
224
+ config.value.link !== "/"
225
+ );
226
+ });
227
+ const isActive = computed2(() => {
228
+ if (!isInternal.value) return false;
229
+ if (config.value.activeMatch) {
230
+ return (config.value.activeMatch instanceof RegExp ? config.value.activeMatch : new RegExp(config.value.activeMatch, "u")).test(route.path);
231
+ }
232
+ if (shouldBeActiveInSubpath.value) {
233
+ return route.path.startsWith(config.value.link);
234
+ }
235
+ return route.path === config.value.link;
236
+ });
237
+ return () => {
238
+ const { before, after, default: defaultSlot } = slots;
239
+ const content = defaultSlot?.(config.value) ?? [
240
+ before?.(config.value),
241
+ config.value.text,
242
+ after?.(config.value)
243
+ ];
244
+ return isInternal.value ? h2(
245
+ RouteLink,
246
+ {
247
+ "class": "auto-link",
248
+ "to": config.value.link,
249
+ "active": isActive.value,
250
+ "aria-label": linkAriaLabel.value
251
+ },
252
+ () => content
253
+ ) : h2(
254
+ "a",
255
+ {
256
+ "class": "auto-link external-link",
257
+ "href": config.value.link,
258
+ "aria-label": linkAriaLabel.value,
259
+ "rel": linkRel.value,
260
+ "target": linkTarget.value
261
+ },
262
+ content
263
+ );
264
+ };
265
+ }
266
+ });
267
+
268
+ // src/components/ClientOnly.ts
269
+ import { defineComponent as defineComponent3, onMounted, ref } from "vue";
270
+ var ClientOnly = defineComponent3({
271
+ name: "ClientOnly",
272
+ setup(_, ctx) {
273
+ const isMounted = ref(false);
274
+ onMounted(() => {
275
+ isMounted.value = true;
276
+ });
277
+ return () => isMounted.value ? ctx.slots.default?.() : null;
278
+ }
279
+ });
280
+
281
+ // src/components/Content.ts
282
+ import { computed as computed3, defineAsyncComponent, defineComponent as defineComponent4, h as h3, watch } from "vue";
283
+ var runContentUpdatedCallbacks = (reason) => {
284
+ contentUpdatedCallbacks.value.forEach((fn) => fn(reason));
285
+ };
286
+ var Content = defineComponent4({
287
+ name: "Content",
288
+ props: {
289
+ path: {
290
+ type: String,
291
+ required: false,
292
+ default: ""
293
+ }
294
+ },
295
+ setup(props) {
296
+ const pageComponent = usePageComponent();
297
+ const ContentComponent = computed3(() => {
298
+ if (!props.path) return pageComponent.value;
299
+ const route = resolveRoute(props.path);
300
+ return defineAsyncComponent(
301
+ async () => route.loader().then(({ comp }) => comp)
302
+ );
303
+ });
304
+ const frontmatter = usePageFrontmatter();
305
+ watch(
306
+ frontmatter,
307
+ () => {
308
+ runContentUpdatedCallbacks("updated");
309
+ },
310
+ { deep: true, flush: "post" }
311
+ );
312
+ return () => h3(ContentComponent.value, {
313
+ onVnodeMounted: () => {
314
+ runContentUpdatedCallbacks("mounted");
315
+ },
316
+ onVnodeUpdated: () => {
317
+ runContentUpdatedCallbacks("updated");
318
+ },
319
+ onVnodeBeforeUnmount: () => {
320
+ runContentUpdatedCallbacks("beforeUnmount");
321
+ }
322
+ });
323
+ }
324
+ });
325
+
326
+ // src/resolvers.ts
327
+ import { dedupeHead, isString, resolveLocalePath } from "@vuepress/shared";
328
+ import { reactive } from "vue";
329
+
330
+ // src/constants.ts
331
+ var LAYOUT_NAME_DEFAULT = "Layout";
332
+ var LANG_DEFAULT = "en-US";
333
+
334
+ // src/resolvers.ts
335
+ var resolvers = reactive({
336
+ /**
337
+ * Resolve layouts component map
338
+ */
339
+ resolveLayouts: (clientConfigs) => clientConfigs.reduce(
340
+ (prev, item) => ({
341
+ ...prev,
342
+ ...item.layouts
343
+ }),
344
+ {}
345
+ ),
346
+ /**
347
+ * Merge the head config in frontmatter and site locale
348
+ *
349
+ * Frontmatter should take priority over site locale
350
+ */
351
+ resolvePageHead: (pageHeadTitle, pageFrontmatter, siteLocaleDate) => {
352
+ const description = isString(pageFrontmatter.description) ? pageFrontmatter.description : siteLocaleDate.description;
353
+ const head = [
354
+ ...Array.isArray(pageFrontmatter.head) ? pageFrontmatter.head : [],
355
+ ...siteLocaleDate.head,
356
+ ["title", {}, pageHeadTitle],
357
+ ["meta", { name: "description", content: description }]
358
+ ];
359
+ return dedupeHead(head);
360
+ },
361
+ /**
362
+ * Resolve the content of page head title
363
+ *
364
+ * It would be used as the content of the `<title>` tag
365
+ */
366
+ resolvePageHeadTitle: (pageData, siteLocaleDate) => [pageData.title, siteLocaleDate.title].filter((item) => !!item).join(" | "),
367
+ /**
368
+ * Resolve page language from page data
369
+ *
370
+ * It would be used as the `lang` attribute of `<html>` tag
371
+ */
372
+ resolvePageLang: (pageData, siteLocaleData) => pageData.lang || siteLocaleData.lang || LANG_DEFAULT,
373
+ /**
374
+ * Resolve layout component of current page
375
+ */
376
+ resolvePageLayout: (pageData, layouts) => {
377
+ const layoutName = isString(pageData.frontmatter.layout) ? pageData.frontmatter.layout : LAYOUT_NAME_DEFAULT;
378
+ if (!layouts[layoutName]) {
379
+ throw new Error(`[vuepress] Cannot resolve layout: ${layoutName}`);
380
+ }
381
+ return layouts[layoutName];
382
+ },
383
+ /**
384
+ * Resolve locale path according to route path and locales config
385
+ */
386
+ resolveRouteLocale: (locales, routePath) => resolveLocalePath(locales, decodeURI(routePath)),
387
+ /**
388
+ * Resolve site data for specific locale
389
+ *
390
+ * It would merge the locales fields to the root fields
391
+ */
392
+ resolveSiteLocaleData: ({ base, locales, ...siteData }, routeLocale) => ({
393
+ ...siteData,
394
+ ...locales[routeLocale],
395
+ head: [
396
+ // when merging head, the locales head should be placed before root head
397
+ // to get higher priority
398
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- unsafe indexed access
399
+ ...locales[routeLocale]?.head ?? [],
400
+ ...siteData.head
401
+ ]
402
+ })
403
+ });
404
+
405
+ // src/utils/defineClientConfig.ts
406
+ var defineClientConfig = (clientConfig = {}) => clientConfig;
407
+
408
+ // src/utils/withBase.ts
409
+ import { isLinkHttp, removeLeadingSlash } from "@vuepress/shared";
410
+ var withBase = (url) => {
411
+ if (isLinkHttp(url)) return url;
412
+ return `${__VUEPRESS_BASE__}${removeLeadingSlash(url)}`;
413
+ };
414
+
415
+ export {
416
+ clientDataSymbol,
417
+ useClientData,
418
+ useLayouts,
419
+ usePageComponent,
420
+ usePageData,
421
+ usePageFrontmatter,
422
+ usePageHead,
423
+ usePageLang,
424
+ usePageLayout,
425
+ useRedirects,
426
+ useRouteLocale,
427
+ useRoutePath,
428
+ useRoutes,
429
+ useSiteData,
430
+ useSiteLocaleData,
431
+ onContentUpdated,
432
+ updateHeadSymbol,
433
+ useUpdateHead,
434
+ redirects,
435
+ routes,
436
+ resolveRoutePath,
437
+ resolveRoute,
438
+ resolveRouteFullPath,
439
+ useRoute,
440
+ useRouter,
441
+ RouteLink,
442
+ AutoLink,
443
+ ClientOnly,
444
+ Content,
445
+ resolvers,
446
+ defineClientConfig,
447
+ withBase
448
+ };
@@ -0,0 +1,66 @@
1
+ import {
2
+ __export
3
+ } from "./chunk-MLKGABMK.js";
4
+
5
+ // src/devtools/constants.ts
6
+ var constants_exports = {};
7
+ __export(constants_exports, {
8
+ COMPONENT_STATE_TYPE: () => COMPONENT_STATE_TYPE,
9
+ INSPECTOR_ID: () => INSPECTOR_ID,
10
+ INSPECTOR_LABEL: () => INSPECTOR_LABEL,
11
+ INSPECTOR_NODES: () => INSPECTOR_NODES,
12
+ INSPECTOR_STATE_SECTION_NAME: () => INSPECTOR_STATE_SECTION_NAME,
13
+ PLUGIN_ID: () => PLUGIN_ID,
14
+ PLUGIN_LABEL: () => PLUGIN_LABEL
15
+ });
16
+ var PLUGIN_ID = "org.vuejs.vuepress";
17
+ var PLUGIN_LABEL = "VuePress";
18
+ var COMPONENT_STATE_TYPE = PLUGIN_LABEL;
19
+ var INSPECTOR_ID = PLUGIN_ID;
20
+ var INSPECTOR_LABEL = PLUGIN_LABEL;
21
+ var INSPECTOR_NODE_INTERNAL = {
22
+ id: "INTERNAL",
23
+ label: "Internal",
24
+ keys: ["layouts", "routes", "redirects"]
25
+ };
26
+ var INSPECTOR_NODE_SITE = {
27
+ id: "SITE",
28
+ label: "Site",
29
+ keys: ["siteData", "siteLocaleData"]
30
+ };
31
+ var INSPECTOR_NODE_ROUTE = {
32
+ id: "ROUTE",
33
+ label: "Route",
34
+ keys: ["routePath", "routeLocale"]
35
+ };
36
+ var INSPECTOR_NODE_PAGE = {
37
+ id: "PAGE",
38
+ label: "Page",
39
+ keys: [
40
+ "pageData",
41
+ "pageFrontmatter",
42
+ "pageLang",
43
+ "pageHead",
44
+ "pageHeadTitle",
45
+ "pageLayout",
46
+ "pageComponent"
47
+ ]
48
+ };
49
+ var INSPECTOR_NODES = {
50
+ [INSPECTOR_NODE_INTERNAL.id]: INSPECTOR_NODE_INTERNAL,
51
+ [INSPECTOR_NODE_SITE.id]: INSPECTOR_NODE_SITE,
52
+ [INSPECTOR_NODE_ROUTE.id]: INSPECTOR_NODE_ROUTE,
53
+ [INSPECTOR_NODE_PAGE.id]: INSPECTOR_NODE_PAGE
54
+ };
55
+ var INSPECTOR_STATE_SECTION_NAME = "State";
56
+
57
+ export {
58
+ PLUGIN_ID,
59
+ PLUGIN_LABEL,
60
+ COMPONENT_STATE_TYPE,
61
+ INSPECTOR_ID,
62
+ INSPECTOR_LABEL,
63
+ INSPECTOR_NODES,
64
+ INSPECTOR_STATE_SECTION_NAME,
65
+ constants_exports
66
+ };