Socket
Socket
Sign inDemoInstall

@vuepress/client

Package Overview
Dependencies
Maintainers
7
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vuepress/client - npm Package Compare versions

Comparing version 2.0.0-beta.34 to 2.0.0-beta.35

lib/helpers/defineClientAppEnhance.d.ts

48

lib/app.js
import { clientAppEnhances } from '@internal/clientAppEnhances';
import { clientAppRootComponents } from '@internal/clientAppRootComponents';
import { clientAppSetups } from '@internal/clientAppSetups';
import { pagesComponents } from '@internal/pagesComponents';
import { pagesRoutes } from '@internal/pagesRoutes';
import { removeEndingSlash } from '@vuepress/shared';
import { createApp, createSSRApp, h } from 'vue';
import { createMemoryHistory, createRouter, createWebHistory, RouterView, START_LOCATION, } from 'vue-router';
import { pageData, resolvePageData, setupUpdateHead, siteData, } from './composables';
import { provideGlobalComputed } from './provideGlobalComputed';
import { registerGlobalComponents } from './registerGlobalComponents';
import { RouterView } from 'vue-router';
import { siteData } from './composables';
import { createVueRouter } from './router';
import { setupDevtools } from './setupDevtools';
import { setupGlobalComponents } from './setupGlobalComponents';
import { setupGlobalComputed } from './setupGlobalComputed';
import { setupUpdateHead } from './setupUpdateHead';
/**

@@ -18,7 +17,2 @@ * - use `createApp` in dev mode

const appCreator = __VUEPRESS_DEV__ ? createApp : createSSRApp;
/**
* - use `createWebHistory` in dev mode and build mode client bundle
* - use `createMemoryHistory` in build mode server bundle
*/
const historyCreator = __VUEPRESS_SSR__ ? createMemoryHistory : createWebHistory;
export const createVueApp = async () => {

@@ -41,29 +35,7 @@ // create vue app

});
// create vue-router
const router = createRouter({
// TODO: it might be an issue of vue-router that have to remove the ending slash
history: historyCreator(removeEndingSlash(siteData.value.base)),
routes: pagesRoutes,
scrollBehavior: (to, from, savedPosition) => {
if (savedPosition)
return savedPosition;
if (to.hash)
return { el: to.hash };
return { top: 0 };
},
});
router.beforeResolve(async (to, from) => {
var _a;
if (to.path !== from.path || from === START_LOCATION) {
// ensure page data and page component have been loaded
;
[pageData.value] = await Promise.all([
resolvePageData(to.name),
(_a = pagesComponents[to.name]) === null || _a === void 0 ? void 0 : _a.__asyncLoader(),
]);
}
});
// create vue-router instance
const router = createVueRouter();
// global components and computed
registerGlobalComponents(app);
const globalComputed = provideGlobalComputed(app, router);
setupGlobalComponents(app);
const globalComputed = setupGlobalComputed(app, router);
// setup devtools in dev mode

@@ -70,0 +42,0 @@ if (__VUEPRESS_DEV__ || __VUE_PROD_DEVTOOLS__) {

export declare const ClientOnly: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}>[] | null | undefined, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{} & {} & {}>, {}>;
}>[] | null | undefined, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}>;

@@ -6,2 +6,2 @@ /**

[key: string]: any;
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{} & {} & {}>, {}>;
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}>;

@@ -9,2 +9,6 @@ import type { PageData } from '@vuepress/shared';

/**
* Empty page data to be used as the fallback value
*/
export declare const pageDataEmpty: PageData<Record<never, never>>;
/**
* Global page data ref

@@ -17,5 +21,1 @@ */

export declare const usePageData: <T extends Record<any, any> = Record<never, never>>() => PageDataRef<T>;
/**
* Resolve page data according to page key
*/
export declare const resolvePageData: (pageKey: string) => Promise<PageData>;

@@ -6,3 +6,3 @@ import { readonly, ref } from 'vue';

*/
const pageDataEmpty = readonly({
export const pageDataEmpty = readonly({
key: '',

@@ -24,13 +24,2 @@ path: '',

export const usePageData = () => pageData;
/**
* Resolve page data according to page key
*/
export const resolvePageData = async (pageKey) => {
const pageDataResolver = pagesData.value[pageKey];
if (!pageDataResolver) {
return pageDataEmpty;
}
const pageData = await pageDataResolver();
return pageData !== null && pageData !== void 0 ? pageData : pageDataEmpty;
};
if (import.meta.webpackHot || import.meta.hot) {

@@ -37,0 +26,0 @@ // reuse vue HMR runtime

@@ -1,2 +0,2 @@

import type { PageData, PageFrontmatter } from '@vuepress/shared';
import type { PageFrontmatter } from '@vuepress/shared';
import type { ComputedRef, InjectionKey } from 'vue';

@@ -16,5 +16,1 @@ export type { PageFrontmatter };

export declare const usePageFrontmatter: <T extends Record<any, any> = Record<string, unknown>>() => PageFrontmatterRef<T>;
/**
* Resolve page frontmatter from page data
*/
export declare const resolvePageFrontmatter: (pageData: PageData) => PageFrontmatter;

@@ -16,5 +16,1 @@ import { inject } from 'vue';

};
/**
* Resolve page frontmatter from page data
*/
export const resolvePageFrontmatter = (pageData) => pageData.frontmatter;
import type { HeadConfig } from '@vuepress/shared';
import type { ComputedRef, InjectionKey } from 'vue';
import type { PageFrontmatter } from './pageFrontmatter';
import type { PageHeadTitle } from './pageHeadTitle';
import type { SiteLocaleData } from './siteLocaleData';
/**

@@ -22,7 +19,1 @@ * Page head config, which would be used for generate html tags in `<head>`

export declare const usePageHead: () => PageHeadRef;
/**
* Merge the head config in frontmatter and site locale
*
* Frontmatter should take priority over site locale
*/
export declare const resolvePageHead: (headTitle: PageHeadTitle, frontmatter: PageFrontmatter, siteLocale: SiteLocaleData) => HeadConfig[];

@@ -1,2 +0,1 @@

import { dedupeHead, isArray, isString } from '@vuepress/shared';
import { inject } from 'vue';

@@ -17,18 +16,1 @@ /**

};
/**
* Merge the head config in frontmatter and site locale
*
* Frontmatter should take priority over site locale
*/
export const resolvePageHead = (headTitle, frontmatter, siteLocale) => {
const description = isString(frontmatter.description)
? frontmatter.description
: siteLocale.description;
const head = [
...(isArray(frontmatter.head) ? frontmatter.head : []),
...siteLocale.head,
['title', {}, headTitle],
['meta', { name: 'description', content: description }],
];
return dedupeHead(head);
};
import type { ComputedRef, InjectionKey } from 'vue';
import type { PageData } from './pageData';
import type { SiteLocaleData } from './siteLocaleData';
/**

@@ -20,7 +18,1 @@ * Page head title, which would be used as the content of `head > title` tag

export declare const usePageHeadTitle: () => PageHeadTitleRef;
/**
* Resolve the content of page head title
*
* It would be used as the content of the `<title>` tag
*/
export declare const resolvePageHeadTitle: (page: PageData, siteLocale: SiteLocaleData) => PageHeadTitle;

@@ -16,7 +16,1 @@ import { inject } from 'vue';

};
/**
* Resolve the content of page head title
*
* It would be used as the content of the `<title>` tag
*/
export const resolvePageHeadTitle = (page, siteLocale) => `${page.title ? `${page.title} | ` : ``}${siteLocale.title}`;

@@ -1,2 +0,1 @@

import type { PageData } from '@vuepress/shared';
import type { ComputedRef, InjectionKey } from 'vue';

@@ -19,7 +18,1 @@ /**

export declare const usePageLang: () => PageLangRef;
/**
* Resolve page language from page data
*
* It would be used as the `lang` attribute of `<html>` tag
*/
export declare const resolvePageLang: (pageData: PageData) => PageLang;

@@ -16,7 +16,1 @@ import { inject } from 'vue';

};
/**
* Resolve page language from page data
*
* It would be used as the `lang` attribute of `<html>` tag
*/
export const resolvePageLang = (pageData) => pageData.lang || 'en';

@@ -9,3 +9,3 @@ import type { PageData } from '@vuepress/shared';

*/
export declare type PagesData = Record<string, () => Promise<PageData>>;
export declare type PagesData = Record<string, (() => Promise<PageData>) | undefined>;
/**

@@ -12,0 +12,0 @@ * Ref wrapper of `PagesData`

@@ -1,2 +0,1 @@

import type { SiteData } from '@vuepress/shared';
import type { ComputedRef, InjectionKey } from 'vue';

@@ -19,5 +18,1 @@ /**

export declare const useRouteLocale: () => RouteLocaleRef;
/**
* Resolve locale path according to route path and locales config
*/
export declare const resolveRouteLocale: (locales: SiteData['locales'], routePath: string) => RouteLocale;

@@ -1,2 +0,1 @@

import { resolveLocalePath } from '@vuepress/shared';
import { inject } from 'vue';

@@ -17,5 +16,1 @@ /**

};
/**
* Resolve locale path according to route path and locales config
*/
export const resolveRouteLocale = (locales, routePath) => resolveLocalePath(locales, routePath);
import type { SiteData } from '@vuepress/shared';
import type { ComputedRef, InjectionKey } from 'vue';
import type { RouteLocale } from './routeLocale';
/**

@@ -20,7 +19,1 @@ * Site data of current locale

export declare const useSiteLocaleData: () => SiteLocaleDataRef;
/**
* Resolve site data for specific locale
*
* It would merge the locales fields to the root fields
*/
export declare const resolveSiteLocaleData: (site: SiteData, routeLocale: RouteLocale) => SiteLocaleData;

@@ -16,10 +16,1 @@ import { inject } from 'vue';

};
/**
* Resolve site data for specific locale
*
* It would merge the locales fields to the root fields
*/
export const resolveSiteLocaleData = (site, routeLocale) => ({
...site,
...site.locales[routeLocale],
});

@@ -1,2 +0,1 @@

import type { HeadConfig } from '@vuepress/shared';
import type { InjectionKey } from 'vue';

@@ -15,13 +14,1 @@ /**

export declare const useUpdateHead: () => UpdateHead;
/**
* Auto update head and provide as global util in setup
*/
export declare const setupUpdateHead: () => void;
/**
* Query the matched head tag of head config
*/
export declare const queryHeadTag: ([tagName, attrs, content,]: HeadConfig) => HTMLElement | null;
/**
* Create head tag from head config
*/
export declare const createHeadTag: ([tagName, attrs, content,]: HeadConfig) => HTMLElement | null;

@@ -1,6 +0,2 @@

import { isPlainObject, isString } from '@vuepress/shared';
import { inject, onMounted, provide, ref, useSSRContext, watch } from 'vue';
import { useRoute } from 'vue-router';
import { usePageHead } from './pageHead';
import { usePageLang } from './pageLang';
import { inject } from 'vue';
/**

@@ -20,98 +16,1 @@ * Injection key for `updateHead` util

};
/**
* Auto update head and provide as global util in setup
*/
export const setupUpdateHead = () => {
const route = useRoute();
const head = usePageHead();
const lang = usePageLang();
// ssr-only, extract page meta info to ssrContext
if (__VUEPRESS_SSR__) {
const ssrContext = useSSRContext();
if (ssrContext) {
ssrContext.head = head.value;
ssrContext.lang = lang.value;
}
return;
}
const headTags = ref([]);
// load current head tags from DOM
const loadHead = () => {
head.value.forEach((item) => {
const tag = queryHeadTag(item);
if (tag) {
headTags.value.push(tag);
}
});
};
// update html lang attribute and head tags to DOM
const updateHead = () => {
document.documentElement.lang = lang.value;
headTags.value.forEach((item) => {
if (item.parentNode === document.head) {
document.head.removeChild(item);
}
});
headTags.value.splice(0, headTags.value.length);
head.value.forEach((item) => {
const tag = createHeadTag(item);
if (tag !== null) {
document.head.appendChild(tag);
headTags.value.push(tag);
}
});
};
provide(updateHeadSymbol, updateHead);
onMounted(() => {
loadHead();
updateHead();
// only update head on route change
watch(() => route.path, () => updateHead());
});
};
/**
* Query the matched head tag of head config
*/
export const queryHeadTag = ([tagName, attrs, content = '',]) => {
const attrsSelector = Object.entries(attrs)
.map(([key, value]) => {
if (isString(value)) {
return `[${key}="${value}"]`;
}
if (value === true) {
return `[${key}]`;
}
return '';
})
.join('');
const selector = `head > ${tagName}${attrsSelector}`;
const tags = Array.from(document.querySelectorAll(selector));
const matchedTag = tags.find((item) => item.innerText === content);
return matchedTag || null;
};
/**
* Create head tag from head config
*/
export const createHeadTag = ([tagName, attrs, content,]) => {
if (!isString(tagName)) {
return null;
}
// create element
const tag = document.createElement(tagName);
// set attributes
if (isPlainObject(attrs)) {
Object.entries(attrs).forEach(([key, value]) => {
if (isString(value)) {
tag.setAttribute(key, value);
}
else if (value === true) {
tag.setAttribute(key, '');
}
});
}
// set content
if (isString(content)) {
tag.appendChild(document.createTextNode(content));
}
return tag;
};
export type { PageHeader } from '@vuepress/shared';
export { useRoute, useRouter } from 'vue-router';
export * from './app';
export { RouterLink, useRoute, useRouter } from 'vue-router';
export * from './components';
export * from './composables';
export * from './helpers';
export * from './types';
export * from './utils';
export * from './app';
export * from './resolvers';

@@ -1,6 +0,7 @@

export { useRoute, useRouter } from 'vue-router';
export * from './app';
export { RouterLink, useRoute, useRouter } from 'vue-router';
export * from './components';
export * from './composables';
export * from './helpers';
export * from './types';
export * from './utils';
export * from './app';
export * from './resolvers';
import type { App } from 'vue';
import type { GlobalComputed } from './provideGlobalComputed';
import type { GlobalComputed } from './setupGlobalComputed';
export declare const setupDevtools: (app: App, globalComputed: GlobalComputed) => void;
export * from './clientAppEnhance';
export * from './clientAppSetup';
declare module 'vue-router' {
interface RouteMeta {
title?: string;
}
}
{
"name": "@vuepress/client",
"version": "2.0.0-beta.34",
"version": "2.0.0-beta.35",
"description": "Client package of VuePress",

@@ -33,4 +33,4 @@ "keywords": [

"@vue/devtools-api": "^6.0.0-beta.21.1",
"@vuepress/shared": "2.0.0-beta.33",
"vue": "^3.2.26",
"@vuepress/shared": "2.0.0-beta.35",
"vue": "^3.2.28",
"vue-router": "^4.0.12"

@@ -40,3 +40,3 @@ },

"@types/webpack-env": "^1.16.3",
"vite": "^2.7.10"
"vite": "^2.7.13"
},

@@ -46,3 +46,3 @@ "publishConfig": {

},
"gitHead": "aba907994697f4d0a691f2e3668dad4bea388f20"
"gitHead": "4bf1c55b6fb863c9251aa80178d5bc6475f5b315"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc