@vuepress/client
Advanced tools
Comparing version 2.0.0-rc.0 to 2.0.0-rc.1
@@ -21,3 +21,3 @@ import { | ||
withBase | ||
} from "./chunk-DHNSDB55.js"; | ||
} from "./chunk-PEQEPZ75.js"; | ||
@@ -125,9 +125,6 @@ // src/app.ts | ||
// src/setupGlobalComputed.ts | ||
import { computedEager, computedWithControl } from "@vueuse/core"; | ||
import { computedWithControl } from "@vueuse/core"; | ||
import { computed } from "vue"; | ||
var setupGlobalComputed = (app, router, clientConfigs2) => { | ||
const routePath = computedEager(() => router.currentRoute.value.path); | ||
const routeLocale = computedEager( | ||
() => resolvers.resolveRouteLocale(siteData.value.locales, routePath.value) | ||
); | ||
const routePath = computed(() => router.currentRoute.value.path); | ||
const pageData = computedWithControl( | ||
@@ -147,2 +144,5 @@ routePath, | ||
const layouts = computed(() => resolvers.resolveLayouts(clientConfigs2)); | ||
const routeLocale = computed( | ||
() => resolvers.resolveRouteLocale(siteData.value.locales, routePath.value) | ||
); | ||
const siteLocaleData = computed( | ||
@@ -206,3 +206,3 @@ () => resolvers.resolveSiteLocaleData(siteData.value, routeLocale.value) | ||
import { isPlainObject, isString } from "@vuepress/shared"; | ||
import { onMounted, provide, ref, useSSRContext, watch } from "vue"; | ||
import { onMounted, provide, useSSRContext, watch } from "vue"; | ||
var setupUpdateHead = () => { | ||
@@ -219,35 +219,51 @@ const head = usePageHead(); | ||
} | ||
const headTags = ref([]); | ||
const loadHead = () => { | ||
let managedHeadElements = []; | ||
const takeOverHeadElements = () => { | ||
head.value.forEach((item) => { | ||
const tag = queryHeadTag(item); | ||
if (tag) { | ||
headTags.value.push(tag); | ||
const headElement = queryHeadElement(item); | ||
if (headElement) { | ||
managedHeadElements.push(headElement); | ||
} | ||
}); | ||
}; | ||
const generateHeadElements = () => { | ||
const result = []; | ||
head.value.forEach((item) => { | ||
const headElement = createHeadElement(item); | ||
if (headElement) { | ||
result.push(headElement); | ||
} | ||
}); | ||
return result; | ||
}; | ||
const updateHead = () => { | ||
document.documentElement.lang = lang.value; | ||
headTags.value.forEach((item) => { | ||
if (item.parentNode === document.head) { | ||
document.head.removeChild(item); | ||
const newHeadElements = generateHeadElements(); | ||
managedHeadElements.forEach((oldEl, oldIndex) => { | ||
const matchedIndex = newHeadElements.findIndex( | ||
(newEl) => oldEl.isEqualNode(newEl) | ||
); | ||
if (matchedIndex === -1) { | ||
oldEl.remove(); | ||
delete managedHeadElements[oldIndex]; | ||
} else { | ||
newHeadElements.splice(matchedIndex, 1); | ||
} | ||
}); | ||
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); | ||
} | ||
}); | ||
newHeadElements.forEach((el) => document.head.appendChild(el)); | ||
managedHeadElements = [ | ||
// filter out empty deleted items | ||
...managedHeadElements.filter((item) => !!item), | ||
...newHeadElements | ||
]; | ||
}; | ||
provide(updateHeadSymbol, updateHead); | ||
onMounted(() => { | ||
loadHead(); | ||
updateHead(); | ||
watch(() => head.value, updateHead); | ||
if (!__VUEPRESS_DEV__) { | ||
takeOverHeadElements(); | ||
} | ||
watch(head, updateHead, { immediate: __VUEPRESS_DEV__ }); | ||
}); | ||
}; | ||
var queryHeadTag = ([ | ||
var queryHeadElement = ([ | ||
tagName, | ||
@@ -267,7 +283,11 @@ attrs, | ||
const selector = `head > ${tagName}${attrsSelector}`; | ||
const tags = Array.from(document.querySelectorAll(selector)); | ||
const matchedTag = tags.find((item) => item.innerText === content); | ||
return matchedTag || null; | ||
const headElements = Array.from( | ||
document.querySelectorAll(selector) | ||
); | ||
const matchedHeadElement = headElements.find( | ||
(item) => item.innerText === content | ||
); | ||
return matchedHeadElement || null; | ||
}; | ||
var createHeadTag = ([ | ||
var createHeadElement = ([ | ||
tagName, | ||
@@ -280,9 +300,9 @@ attrs, | ||
} | ||
const tag = document.createElement(tagName); | ||
const headElement = document.createElement(tagName); | ||
if (isPlainObject(attrs)) { | ||
Object.entries(attrs).forEach(([key, value]) => { | ||
if (isString(value)) { | ||
tag.setAttribute(key, value); | ||
headElement.setAttribute(key, value); | ||
} else if (value === true) { | ||
tag.setAttribute(key, ""); | ||
headElement.setAttribute(key, ""); | ||
} | ||
@@ -292,5 +312,5 @@ }); | ||
if (isString(content)) { | ||
tag.appendChild(document.createTextNode(content)); | ||
headElement.appendChild(document.createTextNode(content)); | ||
} | ||
return tag; | ||
return headElement; | ||
}; | ||
@@ -297,0 +317,0 @@ |
import { PageData, PageFrontmatter, HeadConfig, SiteData } from '@vuepress/shared'; | ||
export { PageData, PageFrontmatter, PageHeader, SiteData } from '@vuepress/shared'; | ||
import * as vue from 'vue'; | ||
import { Component, App, ComputedRef, InjectionKey, Ref } from 'vue'; | ||
import { ComputedRef, InjectionKey, Ref, Component, App } from 'vue'; | ||
import { Router, RouteMeta } from 'vue-router'; | ||
export { C as CreateVueAppFunction } from './createVueAppFunction-YNGNKfE3.js'; | ||
declare const ClientOnly: vue.DefineComponent<{}, () => vue.VNode<vue.RendererNode, vue.RendererElement, { | ||
[key: string]: any; | ||
}>[] | null | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.VNodeProps & vue.AllowedComponentProps & vue.ComponentCustomProps, Readonly<vue.ExtractPropTypes<{}>>, {}, {}>; | ||
/** | ||
* Markdown rendered content | ||
*/ | ||
declare const Content: vue.DefineComponent<{ | ||
pageKey: { | ||
type: StringConstructor; | ||
required: false; | ||
default: string; | ||
}; | ||
}, () => vue.VNode<vue.RendererNode, vue.RendererElement, { | ||
[key: string]: any; | ||
}>, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.VNodeProps & vue.AllowedComponentProps & vue.ComponentCustomProps, Readonly<vue.ExtractPropTypes<{ | ||
pageKey: { | ||
type: StringConstructor; | ||
required: false; | ||
default: string; | ||
}; | ||
}>>, { | ||
pageKey: string; | ||
}, {}>; | ||
type Layouts = Record<string, Component>; | ||
/** | ||
* Configure vuepress client | ||
*/ | ||
interface ClientConfig { | ||
/** | ||
* An enhance function to be called after vue app instance and | ||
* vue-router instance has been created | ||
*/ | ||
enhance?: (context: { | ||
app: App; | ||
router: Router; | ||
siteData: SiteDataRef; | ||
}) => void | Promise<void>; | ||
/** | ||
* A function to be called inside the setup function of vue app | ||
*/ | ||
setup?: () => void; | ||
/** | ||
* Layout components | ||
*/ | ||
layouts?: Layouts; | ||
/** | ||
* Components to be placed directly into the root node of vue app | ||
*/ | ||
rootComponents?: Component[]; | ||
} | ||
type CreateVueAppFunction = () => Promise<{ | ||
app: App; | ||
router: Router; | ||
}>; | ||
type PageRouteItem = [ | ||
name: string, | ||
path: string, | ||
meta: RouteMeta, | ||
redirects: string[] | ||
]; | ||
/** | ||
* Ref wrapper of `Layouts` | ||
@@ -260,3 +195,64 @@ */ | ||
type Layouts = Record<string, Component>; | ||
/** | ||
* Configure vuepress client | ||
*/ | ||
interface ClientConfig { | ||
/** | ||
* An enhance function to be called after vue app instance and | ||
* vue-router instance has been created | ||
*/ | ||
enhance?: (context: { | ||
app: App; | ||
router: Router; | ||
siteData: SiteDataRef; | ||
}) => void | Promise<void>; | ||
/** | ||
* A function to be called inside the setup function of vue app | ||
*/ | ||
setup?: () => void; | ||
/** | ||
* Layout components | ||
*/ | ||
layouts?: Layouts; | ||
/** | ||
* Components to be placed directly into the root node of vue app | ||
*/ | ||
rootComponents?: Component[]; | ||
} | ||
type PageRouteItem = [ | ||
name: string, | ||
path: string, | ||
meta: RouteMeta, | ||
redirects: string[] | ||
]; | ||
declare const ClientOnly: vue.DefineComponent<{}, () => vue.VNode<vue.RendererNode, vue.RendererElement, { | ||
[key: string]: any; | ||
}>[] | null | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{}>>, {}, {}>; | ||
/** | ||
* Markdown rendered content | ||
*/ | ||
declare const Content: vue.DefineComponent<{ | ||
pageKey: { | ||
type: StringConstructor; | ||
required: false; | ||
default: string; | ||
}; | ||
}, () => vue.VNode<vue.RendererNode, vue.RendererElement, { | ||
[key: string]: any; | ||
}>, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{ | ||
pageKey: { | ||
type: StringConstructor; | ||
required: false; | ||
default: string; | ||
}; | ||
}>>, { | ||
pageKey: string; | ||
}, {}>; | ||
/** | ||
* A helper function to help you define vuepress client config file | ||
@@ -288,2 +284,2 @@ */ | ||
export { ClientConfig, ClientOnly, Content, CreateVueAppFunction, Layouts, LayoutsRef, PageDataRef, PageFrontmatterRef, PageHead, PageHeadRef, PageHeadTitle, PageHeadTitleRef, PageLang, PageLangRef, PageLayoutRef, PageRouteItem, PagesData, PagesDataRef, RouteLocale, RouteLocaleRef, SiteDataRef, SiteLocaleData, SiteLocaleDataRef, UpdateHead, defineClientConfig, layoutsSymbol, pageDataEmpty, pageDataSymbol, pageFrontmatterSymbol, pageHeadSymbol, pageHeadTitleSymbol, pageLangSymbol, pageLayoutSymbol, pagesData, resolvers, routeLocaleSymbol, siteData, siteLocaleDataSymbol, updateHeadSymbol, useLayouts, usePageData, usePageFrontmatter, usePageHead, usePageHeadTitle, usePageLang, usePageLayout, usePagesData, useRouteLocale, useSiteData, useSiteLocaleData, useUpdateHead, withBase }; | ||
export { type ClientConfig, ClientOnly, Content, type Layouts, type LayoutsRef, type PageDataRef, type PageFrontmatterRef, type PageHead, type PageHeadRef, type PageHeadTitle, type PageHeadTitleRef, type PageLang, type PageLangRef, type PageLayoutRef, type PageRouteItem, type PagesData, type PagesDataRef, type RouteLocale, type RouteLocaleRef, type SiteDataRef, type SiteLocaleData, type SiteLocaleDataRef, type UpdateHead, defineClientConfig, layoutsSymbol, pageDataEmpty, pageDataSymbol, pageFrontmatterSymbol, pageHeadSymbol, pageHeadTitleSymbol, pageLangSymbol, pageLayoutSymbol, pagesData, resolvers, routeLocaleSymbol, siteData, siteLocaleDataSymbol, updateHeadSymbol, useLayouts, usePageData, usePageFrontmatter, usePageHead, usePageHeadTitle, usePageLang, usePageLayout, usePagesData, useRouteLocale, useSiteData, useSiteLocaleData, useUpdateHead, withBase }; |
@@ -32,3 +32,3 @@ import { | ||
withBase | ||
} from "./chunk-DHNSDB55.js"; | ||
} from "./chunk-PEQEPZ75.js"; | ||
export { | ||
@@ -35,0 +35,0 @@ ClientOnly, |
{ | ||
"name": "@vuepress/client", | ||
"version": "2.0.0-rc.0", | ||
"version": "2.0.0-rc.1", | ||
"description": "Client package of VuePress", | ||
@@ -11,7 +11,7 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/vuepress/vuepress-next/issues" | ||
"url": "https://github.com/vuepress/core/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/vuepress/vuepress-next.git" | ||
"url": "git+https://github.com/vuepress/core.git" | ||
}, | ||
@@ -38,6 +38,6 @@ "license": "MIT", | ||
"@vue/devtools-api": "^6.5.1", | ||
"@vueuse/core": "^10.6.1", | ||
"vue": "^3.3.8", | ||
"@vueuse/core": "^10.7.2", | ||
"vue": "^3.4.15", | ||
"vue-router": "^4.2.5", | ||
"@vuepress/shared": "2.0.0-rc.0" | ||
"@vuepress/shared": "2.0.0-rc.1" | ||
}, | ||
@@ -49,3 +49,6 @@ "publishConfig": { | ||
"clean": true, | ||
"dts": "./src/index.ts", | ||
"dts": [ | ||
"./src/app.ts", | ||
"./src/index.ts" | ||
], | ||
"entry": [ | ||
@@ -52,0 +55,0 @@ "./src/app.ts", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
35265
13
1100
0
13
0
+ Added@mdit-vue/types@2.1.0(transitive)
+ Added@vuepress/shared@2.0.0-rc.1(transitive)
- Removed@mdit-vue/types@1.0.0(transitive)
- Removed@vuepress/shared@2.0.0-rc.0(transitive)
Updated@vuepress/shared@2.0.0-rc.1
Updated@vueuse/core@^10.7.2
Updatedvue@^3.4.15