@vueuse/head
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -29,2 +29,3 @@ import { UnwrapRef, App, Ref } from 'vue'; | ||
removeHeadTags: (tags: HeadTag[]) => void; | ||
updateHeadTags: (oldTags: HeadTag[], newTags: HeadTag[]) => void; | ||
updateDOM: (document?: Document) => void; | ||
@@ -31,0 +32,0 @@ }; |
@@ -177,3 +177,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/index.ts | ||
var createHead = () => { | ||
const headTags = []; | ||
let allHeadTags = []; | ||
const head = { | ||
@@ -184,36 +184,47 @@ install(app) { | ||
}, | ||
headTags, | ||
addHeadTags(tags) { | ||
tags.forEach((tag) => { | ||
if (tag.tag === "meta" || tag.tag === "base") { | ||
const key = getTagKey(tag.props); | ||
if (key) { | ||
let index = -1; | ||
for (let i = 0; i < headTags.length; i++) { | ||
const prev = headTags[i]; | ||
const prevValue = prev.props[key.name]; | ||
const nextValue = tag.props[key.name]; | ||
if (prev.tag === tag.tag && prevValue === nextValue) { | ||
index = i; | ||
break; | ||
get headTags() { | ||
const deduped = []; | ||
allHeadTags.forEach((tags) => { | ||
tags.forEach((tag) => { | ||
if (tag.tag === "meta" || tag.tag === "base") { | ||
const key = getTagKey(tag.props); | ||
if (key) { | ||
let index = -1; | ||
for (let i = 0; i < deduped.length; i++) { | ||
const prev = deduped[i]; | ||
const prevValue = prev.props[key.name]; | ||
const nextValue = tag.props[key.name]; | ||
if (prev.tag === tag.tag && prevValue === nextValue) { | ||
index = i; | ||
break; | ||
} | ||
} | ||
if (index !== -1) { | ||
deduped.splice(index, 1); | ||
} | ||
} | ||
if (index !== -1) { | ||
headTags.splice(index, 1); | ||
} | ||
} | ||
deduped.push(tag); | ||
}); | ||
}); | ||
return deduped; | ||
}, | ||
addHeadTags(tags) { | ||
allHeadTags.push(tags); | ||
}, | ||
updateHeadTags(oldTags, newTags) { | ||
allHeadTags = allHeadTags.map((v) => { | ||
if (v === oldTags) { | ||
return newTags; | ||
} | ||
headTags.push(tag); | ||
return v; | ||
}); | ||
}, | ||
removeHeadTags(tags) { | ||
tags.forEach((tag) => { | ||
const index = headTags.indexOf(tag); | ||
if (index !== -1) { | ||
headTags.splice(index, 1); | ||
} | ||
allHeadTags = allHeadTags.filter((v) => { | ||
return tags !== v; | ||
}); | ||
}, | ||
updateDOM(document) { | ||
insertTags(headTags, document); | ||
insertTags(head.headTags, document); | ||
} | ||
@@ -229,13 +240,16 @@ }; | ||
let tags; | ||
let oldTags; | ||
_vue.watchEffect.call(void 0, () => { | ||
if (tags) { | ||
head.removeHeadTags(tags); | ||
tags = headObjToTags(headObj.value); | ||
if (oldTags) { | ||
head.updateHeadTags(oldTags, tags); | ||
} else { | ||
head.addHeadTags(tags); | ||
} | ||
tags = headObjToTags(headObj.value); | ||
head.addHeadTags(tags); | ||
oldTags = tags; | ||
head.updateDOM(); | ||
}); | ||
_vue.onBeforeUnmount.call(void 0, () => { | ||
if (tags) { | ||
head.removeHeadTags(tags); | ||
if (oldTags) { | ||
head.removeHeadTags(oldTags); | ||
head.updateDOM(); | ||
@@ -242,0 +256,0 @@ } |
{ | ||
"name": "@vueuse/head", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"license": "MIT", | ||
@@ -23,6 +23,6 @@ "description": "Document head manager for Vue 3. SSR ready.", | ||
"scripts": { | ||
"test": "start-server-and-test example http://localhost:3000 test:e2e", | ||
"test": "node -r esbuild-register scripts/run-test.ts", | ||
"example": "vite example", | ||
"release": "shipjs prepare", | ||
"build": "tsup src/index.ts --format esm,cjs --external vue --dts", | ||
"build": "tsup src/index.ts --format esm,cjs && tsc && dtsup types/index.d.ts", | ||
"prepublishOnly": "npm run build", | ||
@@ -54,3 +54,3 @@ "test:e2e": "ava" | ||
"lint-staged": { | ||
"*.ts": [ | ||
"*.{ts,tsx}": [ | ||
"prettier --write" | ||
@@ -62,14 +62,18 @@ ] | ||
"@egoist/prettier-config": "^0.1.0", | ||
"@types/node-fetch": "^2.5.8", | ||
"@vitejs/plugin-vue-jsx": "^1.0.2", | ||
"@vue/server-renderer": "^3.0.5", | ||
"ava": "^3.15.0", | ||
"esbuild-register": "^1.2.1", | ||
"chrome-location": "^1.2.1", | ||
"dtsup": "^1.0.1", | ||
"esbuild-register": "^2.1.0", | ||
"execa": "^5.0.0", | ||
"husky": "^4.3.8", | ||
"lint-staged": "^10.5.3", | ||
"playwright-chromium": "^1.8.0", | ||
"node-fetch": "^2.6.1", | ||
"playwright-core": "^1.9.1", | ||
"prettier": "^2.2.1", | ||
"start-server-and-test": "^1.11.7", | ||
"tsup": "^3.11.0", | ||
"typescript": "^4.1.3", | ||
"vite": "^2.0.0-beta.30", | ||
"tsup": "^4.6.1", | ||
"typescript": "^4.2.2", | ||
"vite": "^2.0.5", | ||
"vue": "^3.0.5", | ||
@@ -76,0 +80,0 @@ "vue-router": "^4.0.3" |
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
23747
637
19