@vueuse/head
Advanced tools
Comparing version 0.3.2 to 0.4.0
@@ -27,5 +27,4 @@ import { UnwrapRef, App, Ref } from 'vue'; | ||
headTags: HeadTag[]; | ||
addHeadTags: (tags: HeadTag[]) => void; | ||
removeHeadTags: (tags: HeadTag[]) => void; | ||
updateHeadTags: (oldTags: HeadTag[], newTags: HeadTag[]) => void; | ||
addHeadObjs: (objs: Ref<HeadObjectPlain>) => void; | ||
removeHeadObjs: (objs: Ref<HeadObjectPlain>) => void; | ||
updateDOM: (document?: Document) => void; | ||
@@ -44,5 +43,5 @@ }; | ||
declare const createHead: () => Head; | ||
declare const useHead: (obj: HeadObject | Ref<HeadObject> | (() => HeadObject)) => void; | ||
declare const useHead: (obj: HeadObject | Ref<HeadObject>) => void; | ||
declare const renderHeadToString: (head: Head) => HTMLResult; | ||
export { HTMLResult, Head, HeadAttrs, HeadObject, HeadObjectPlain, HeadTag, createHead, injectHead, renderHeadToString, useHead }; |
@@ -7,3 +7,2 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/index.ts | ||
var _vue = require('vue'); | ||
@@ -178,3 +177,3 @@ | ||
var createHead = () => { | ||
let allHeadTags = []; | ||
let allHeadObjs = []; | ||
const head = { | ||
@@ -187,3 +186,4 @@ install(app) { | ||
const deduped = []; | ||
allHeadTags.forEach((tags) => { | ||
allHeadObjs.forEach((objs) => { | ||
const tags = headObjToTags(objs.value); | ||
tags.forEach((tag) => { | ||
@@ -213,18 +213,8 @@ if (tag.tag === "meta" || tag.tag === "base") { | ||
}, | ||
addHeadTags(tags) { | ||
allHeadTags.push(tags); | ||
addHeadObjs(objs) { | ||
allHeadObjs.push(objs); | ||
}, | ||
updateHeadTags(oldTags, newTags) { | ||
allHeadTags = allHeadTags.map((v) => { | ||
if (v === oldTags) { | ||
return newTags; | ||
} | ||
return v; | ||
}); | ||
removeHeadObjs(objs) { | ||
allHeadObjs = allHeadObjs.filter((_objs) => _objs !== objs); | ||
}, | ||
removeHeadTags(tags) { | ||
allHeadTags = allHeadTags.filter((v) => { | ||
return tags !== v; | ||
}); | ||
}, | ||
updateDOM(document) { | ||
@@ -238,25 +228,13 @@ insertTags(head.headTags, document); | ||
var useHead = (obj) => { | ||
const headObj = typeof obj === "function" ? _vue.computed.call(void 0, obj) : _vue.ref.call(void 0, obj); | ||
const headObj = _vue.ref.call(void 0, obj); | ||
const head = injectHead(); | ||
head.addHeadObjs(headObj); | ||
if (IS_BROWSER) { | ||
let tags; | ||
let oldTags; | ||
_vue.watchEffect.call(void 0, () => { | ||
tags = headObjToTags(headObj.value); | ||
if (oldTags) { | ||
head.updateHeadTags(oldTags, tags); | ||
} else { | ||
head.addHeadTags(tags); | ||
} | ||
oldTags = tags; | ||
head.updateDOM(); | ||
}); | ||
_vue.onBeforeUnmount.call(void 0, () => { | ||
if (oldTags) { | ||
head.removeHeadTags(oldTags); | ||
head.updateDOM(); | ||
} | ||
head.removeHeadObjs(headObj); | ||
head.updateDOM(); | ||
}); | ||
} else { | ||
head.addHeadTags(headObjToTags(headObj.value)); | ||
} | ||
@@ -263,0 +241,0 @@ }; |
{ | ||
"name": "@vueuse/head", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Document head manager for Vue 3. SSR ready.", |
@@ -5,3 +5,3 @@ # @vueuse/head | ||
`@vueuse/head` is a [Vue composition API](https://v3.vuejs.org/guide/composition-api-introduction.html) that helps you manage `<title>`, `<meta>` and other elements inside document head, it has no dependencies and we always try to keep it as slim as possible. | ||
`@vueuse/head` is a [Vue composition API](https://v3.vuejs.org/guide/composition-api-introduction.html) that helps you manage `<title>`, `<meta>` and other elements inside document head, it has no dependencies and we always try to keep it as slim as possible. | ||
@@ -97,3 +97,3 @@ [![NPM version](https://img.shields.io/npm/v/@vueuse/head?color=a1b858)](https://www.npmjs.com/package/@vueuse/head) | ||
### `useHead(head: HeadObject | Ref<HeadObject> | (() => HeadObject))` | ||
### `useHead(head: HeadObject | Ref<HeadObject>)` | ||
@@ -100,0 +100,0 @@ ```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
22663
593