From b802766eb683a0676b834b09bbd2d74cd0ccdb92 Mon Sep 17 00:00:00 2001 From: pimlie Date: Sun, 23 May 2021 22:36:11 +0000 Subject: [PATCH] chore(release): 3.0.0-alpha.7 --- CHANGELOG.md | 12 +++++++++++ dist/vue-meta.cjs.js | 34 +++++++++++++++++++++--------- dist/vue-meta.cjs.prod.js | 34 +++++++++++++++++++++--------- dist/vue-meta.d.ts | 6 ++++-- dist/vue-meta.esm-browser.js | 36 ++++++++++++++++++++++---------- dist/vue-meta.esm-browser.min.js | 4 ++-- dist/vue-meta.esm-bundler.js | 36 ++++++++++++++++++++++---------- dist/vue-meta.global.js | 34 +++++++++++++++++++++--------- dist/vue-meta.global.min.js | 4 ++-- package.json | 2 +- 10 files changed, 143 insertions(+), 59 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4611992..a328b0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [3.0.0-alpha.7](https://github.com/nuxt/vue-meta/compare/v3.0.0-alpha.6...v3.0.0-alpha.7) (2021-05-23) + + +### Bug Fixes + +* check if DOM is still loading before cleanup ([1785d4f](https://github.com/nuxt/vue-meta/commit/1785d4fef6b2c2adaa645e44419c3da883863562)) +* export ssr type declarion into ssr folder ([01e4aed](https://github.com/nuxt/vue-meta/commit/01e4aed34034984e5a523d77db9bd79e66418678)) +* get keyAttribute _either_ from section or tag config ([e551fe4](https://github.com/nuxt/vue-meta/commit/e551fe46fe6f81726f6f6ce9734aedccdc0753df)) +* get keyAttribute either from section or tag config ([3b3d3f4](https://github.com/nuxt/vue-meta/commit/3b3d3f4397eb83003c5d1dd69ec862b39c9fbf37)) +* SSR active, dont use global active var due to runInNewContext: false ([#668](https://github.com/nuxt/vue-meta/issues/668)) ([6593e92](https://github.com/nuxt/vue-meta/commit/6593e9272dea7585cb72b925beafad2020c623db)) +* use document.title to update title on the client ([88d57e7](https://github.com/nuxt/vue-meta/commit/88d57e71993bab8866cc9de22534b39ca01dbf33)) + ## [3.0.0-alpha.6](https://github.com/nuxt/vue-meta/compare/v3.0.0-alpha.5...v3.0.0-alpha.6) (2021-05-17) diff --git a/dist/vue-meta.cjs.js b/dist/vue-meta.cjs.js index 72cb0f5..7fda686 100644 --- a/dist/vue-meta.cjs.js +++ b/dist/vue-meta.cjs.js @@ -1,5 +1,5 @@ /** - * vue-meta v3.0.0-alpha.6 + * vue-meta v3.0.0-alpha.7 * (c) 2021 * - Pim (@pimlie) * - All the amazing contributors @@ -518,6 +518,7 @@ function renderGroup(context, key, data, config) { } return renderTag(context, key, data[childKey], config, groupConfig); }) + .filter(Boolean) .flat(); } function renderTag(context, key, data, config = {}, groupConfig) { @@ -529,6 +530,7 @@ function renderTag(context, key, data, config = {}, groupConfig) { .map((child) => { return renderTag(context, key, child, config, groupConfig); }) + .filter(Boolean) .flat(); } const { tag = config.tag || key } = data; @@ -545,7 +547,7 @@ function renderTag(context, key, data, config = {}, groupConfig) { if (isArray(data)) { return data.map(({ vnode }) => vnode); } - return data.vnode; + return data && data.vnode; }); } else { @@ -594,8 +596,9 @@ function renderTag(context, key, data, config = {}, groupConfig) { content = getSlotContent(context, slotName, content, data); } else { - const { nameless, keyAttribute } = config; + const { nameless } = config; if (!nameless) { + const keyAttribute = config.keyAttribute || getTagConfig('keyAttribute'); if (keyAttribute) { attributes[keyAttribute] = fullName; } @@ -607,6 +610,10 @@ function renderTag(context, key, data, config = {}, groupConfig) { const finalTag = groupConfig && groupConfig.tagNamespace ? `${groupConfig.tagNamespace}:${tag}` : tag; + if (finalTag === 'title' && !context.isSSR) { + document.title = content; + return; + } // console.info('FINAL TAG', finalTag) // console.log(' ATTRIBUTES', attributes) // console.log(' CONTENT', content) @@ -766,7 +773,6 @@ const MetainfoImpl = vue.defineComponent({ const Metainfo = MetainfoImpl; const ssrAttribute = 'data-vm-ssr'; -const active = vue.reactive({}); function addVnode(isSSR, teleports, to, vnodes) { const nodes = (isArray(vnodes) ? vnodes : [vnodes]); if (!isSSR) { @@ -806,7 +812,7 @@ class MetaManager { install(app) { app.component('Metainfo', Metainfo); app.config.globalProperties.$metaManager = this; - app.provide(metaActiveKey, active); + app.provide(metaActiveKey, this.target.context.active); } addMeta(metadata, vm) { if (!vm) { @@ -865,20 +871,27 @@ class MetaManager { } } render({ slots } = {}) { + const active = this.target.context.active; // TODO: clean this method const { isSSR } = this; // cleanup ssr tags if not yet done if (!isSSR && !this.ssrCleanedUp) { this.ssrCleanedUp = true; - // Listen for DOM loaded because tags in the body couldnt - // have loaded yet once the manager does it first render - // (preferable there should only be one meta render on hydration) - window.addEventListener('DOMContentLoaded', () => { + const cleanUpSSR = () => { const ssrTags = document.querySelectorAll(`[${ssrAttribute}]`); if (ssrTags && ssrTags.length) { ssrTags.forEach(el => el.parentNode && el.parentNode.removeChild(el)); } - }, { once: true }); + }; + if (document.readyState === 'loading') { + // Listen for DOM loaded because tags in the body couldnt + // have loaded yet once the manager does it first render + // (preferable there should only be one meta render on hydration) + window.addEventListener('DOMContentLoaded', cleanUpSSR, { once: true }); + } + else { + cleanUpSSR(); + } } const teleports = {}; for (const key in active) { @@ -927,6 +940,7 @@ MetaManager.create = (isSSR, config, resolver) => { } return resolver.resolve(options, contexts, active, key, pathSegments); }; + const active = vue.reactive({}); const mergedObject = createMergedObject(resolve, active); // TODO: validate resolver const manager = new MetaManager(isSSR, config, mergedObject, resolver); diff --git a/dist/vue-meta.cjs.prod.js b/dist/vue-meta.cjs.prod.js index 11bd941..970ad99 100644 --- a/dist/vue-meta.cjs.prod.js +++ b/dist/vue-meta.cjs.prod.js @@ -1,5 +1,5 @@ /** - * vue-meta v3.0.0-alpha.6 + * vue-meta v3.0.0-alpha.7 * (c) 2021 * - Pim (@pimlie) * - All the amazing contributors @@ -507,6 +507,7 @@ function renderGroup(context, key, data, config) { } return renderTag(context, key, data[childKey], config, groupConfig); }) + .filter(Boolean) .flat(); } function renderTag(context, key, data, config = {}, groupConfig) { @@ -518,6 +519,7 @@ function renderTag(context, key, data, config = {}, groupConfig) { .map((child) => { return renderTag(context, key, child, config, groupConfig); }) + .filter(Boolean) .flat(); } const { tag = config.tag || key } = data; @@ -534,7 +536,7 @@ function renderTag(context, key, data, config = {}, groupConfig) { if (isArray(data)) { return data.map(({ vnode }) => vnode); } - return data.vnode; + return data && data.vnode; }); } else { @@ -583,8 +585,9 @@ function renderTag(context, key, data, config = {}, groupConfig) { content = getSlotContent(context, slotName, content, data); } else { - const { nameless, keyAttribute } = config; + const { nameless } = config; if (!nameless) { + const keyAttribute = config.keyAttribute || getTagConfig('keyAttribute'); if (keyAttribute) { attributes[keyAttribute] = fullName; } @@ -596,6 +599,10 @@ function renderTag(context, key, data, config = {}, groupConfig) { const finalTag = groupConfig && groupConfig.tagNamespace ? `${groupConfig.tagNamespace}:${tag}` : tag; + if (finalTag === 'title' && !context.isSSR) { + document.title = content; + return; + } // console.info('FINAL TAG', finalTag) // console.log(' ATTRIBUTES', attributes) // console.log(' CONTENT', content) @@ -746,7 +753,6 @@ const MetainfoImpl = vue.defineComponent({ const Metainfo = MetainfoImpl; const ssrAttribute = 'data-vm-ssr'; -const active = vue.reactive({}); function addVnode(isSSR, teleports, to, vnodes) { const nodes = (isArray(vnodes) ? vnodes : [vnodes]); if (!isSSR) { @@ -786,7 +792,7 @@ class MetaManager { install(app) { app.component('Metainfo', Metainfo); app.config.globalProperties.$metaManager = this; - app.provide(metaActiveKey, active); + app.provide(metaActiveKey, this.target.context.active); } addMeta(metadata, vm) { if (!vm) { @@ -845,20 +851,27 @@ class MetaManager { } } render({ slots } = {}) { + const active = this.target.context.active; // TODO: clean this method const { isSSR } = this; // cleanup ssr tags if not yet done if (!isSSR && !this.ssrCleanedUp) { this.ssrCleanedUp = true; - // Listen for DOM loaded because tags in the body couldnt - // have loaded yet once the manager does it first render - // (preferable there should only be one meta render on hydration) - window.addEventListener('DOMContentLoaded', () => { + const cleanUpSSR = () => { const ssrTags = document.querySelectorAll(`[${ssrAttribute}]`); if (ssrTags && ssrTags.length) { ssrTags.forEach(el => el.parentNode && el.parentNode.removeChild(el)); } - }, { once: true }); + }; + if (document.readyState === 'loading') { + // Listen for DOM loaded because tags in the body couldnt + // have loaded yet once the manager does it first render + // (preferable there should only be one meta render on hydration) + window.addEventListener('DOMContentLoaded', cleanUpSSR, { once: true }); + } + else { + cleanUpSSR(); + } } const teleports = {}; for (const key in active) { @@ -907,6 +920,7 @@ MetaManager.create = (isSSR, config, resolver) => { } return resolver.resolve(options, contexts, active, key, pathSegments); }; + const active = vue.reactive({}); const mergedObject = createMergedObject(resolve, active); // TODO: validate resolver const manager = new MetaManager(isSSR, config, mergedObject, resolver); diff --git a/dist/vue-meta.d.ts b/dist/vue-meta.d.ts index 2874f49..78e813e 100644 --- a/dist/vue-meta.d.ts +++ b/dist/vue-meta.d.ts @@ -1,5 +1,5 @@ /** - * vue-meta v3.0.0-alpha.6 + * vue-meta v3.0.0-alpha.7 * (c) 2021 * - Pim (@pimlie) * - All the amazing contributors @@ -96,6 +96,8 @@ declare type MetaTagsConfig = { }; declare type Modify = Omit & R; +declare type Truthy = T extends undefined | void | null | false | 0 | '' ? never : T; +declare type ExcludesFalsy = (x: T) => x is Truthy; declare type TODO = any; /** * Proxied meta source for tracking changes and updating the active meta daa @@ -214,4 +216,4 @@ declare function getCurrentManager(vm?: ComponentInternalInstance): MetaManager declare function useMeta(source: MetaSource, manager?: MetaManager): MetaProxy; declare function useActiveMeta(): MetaActive; -export { MetaActive, MetaConfig, MetaConfigSection, MetaConfigSectionAttribute, MetaConfigSectionGroup, MetaConfigSectionKey, MetaConfigSectionTag, MetaGroupConfig, MetaGuardRemoved, MetaGuards, MetaProxy, MetaRenderContext, MetaRendered, MetaRenderedNode, MetaResolveContext, MetaResolveSetup, MetaResolver, MetaResolverSetup, MetaSource, MetaSourceProxy, MetaTagConfig, MetaTagConfigKey, MetaTagName, MetaTagsConfig, MetaTeleports, Modify, SlotScopeProperties, TODO, createMetaManager, deepest_d as deepestResolver, defaultConfig, getCurrentManager, resolveOption, useActiveMeta, useMeta }; +export { ExcludesFalsy, MetaActive, MetaConfig, MetaConfigSection, MetaConfigSectionAttribute, MetaConfigSectionGroup, MetaConfigSectionKey, MetaConfigSectionTag, MetaGroupConfig, MetaGuardRemoved, MetaGuards, MetaProxy, MetaRenderContext, MetaRendered, MetaRenderedNode, MetaResolveContext, MetaResolveSetup, MetaResolver, MetaResolverSetup, MetaSource, MetaSourceProxy, MetaTagConfig, MetaTagConfigKey, MetaTagName, MetaTagsConfig, MetaTeleports, Modify, SlotScopeProperties, TODO, Truthy, createMetaManager, deepest_d as deepestResolver, defaultConfig, getCurrentManager, resolveOption, useActiveMeta, useMeta }; diff --git a/dist/vue-meta.esm-browser.js b/dist/vue-meta.esm-browser.js index 0b9b23e..1899820 100644 --- a/dist/vue-meta.esm-browser.js +++ b/dist/vue-meta.esm-browser.js @@ -1,12 +1,12 @@ /** - * vue-meta v3.0.0-alpha.6 + * vue-meta v3.0.0-alpha.7 * (c) 2021 * - Pim (@pimlie) * - All the amazing contributors * @license MIT */ -import { markRaw, h, getCurrentInstance, isProxy, watch, inject, defineComponent, reactive, onUnmounted, Teleport, Comment } from 'vue'; +import { markRaw, h, getCurrentInstance, isProxy, watch, inject, defineComponent, onUnmounted, Teleport, reactive, Comment } from 'vue'; const resolveOption = (predicament, initialValue) => (options, contexts) => { let resolvedIndex = -1; @@ -514,6 +514,7 @@ function renderGroup(context, key, data, config) { } return renderTag(context, key, data[childKey], config, groupConfig); }) + .filter(Boolean) .flat(); } function renderTag(context, key, data, config = {}, groupConfig) { @@ -525,6 +526,7 @@ function renderTag(context, key, data, config = {}, groupConfig) { .map((child) => { return renderTag(context, key, child, config, groupConfig); }) + .filter(Boolean) .flat(); } const { tag = config.tag || key } = data; @@ -541,7 +543,7 @@ function renderTag(context, key, data, config = {}, groupConfig) { if (isArray(data)) { return data.map(({ vnode }) => vnode); } - return data.vnode; + return data && data.vnode; }); } else { @@ -590,8 +592,9 @@ function renderTag(context, key, data, config = {}, groupConfig) { content = getSlotContent(context, slotName, content, data); } else { - const { nameless, keyAttribute } = config; + const { nameless } = config; if (!nameless) { + const keyAttribute = config.keyAttribute || getTagConfig('keyAttribute'); if (keyAttribute) { attributes[keyAttribute] = fullName; } @@ -603,6 +606,10 @@ function renderTag(context, key, data, config = {}, groupConfig) { const finalTag = groupConfig && groupConfig.tagNamespace ? `${groupConfig.tagNamespace}:${tag}` : tag; + if (finalTag === 'title' && !context.isSSR) { + document.title = content; + return; + } // console.info('FINAL TAG', finalTag) // console.log(' ATTRIBUTES', attributes) // console.log(' CONTENT', content) @@ -762,7 +769,6 @@ const MetainfoImpl = defineComponent({ const Metainfo = MetainfoImpl; const ssrAttribute = 'data-vm-ssr'; -const active = reactive({}); function addVnode(isSSR, teleports, to, vnodes) { const nodes = (isArray(vnodes) ? vnodes : [vnodes]); if (!isSSR) { @@ -802,7 +808,7 @@ class MetaManager { install(app) { app.component('Metainfo', Metainfo); app.config.globalProperties.$metaManager = this; - app.provide(metaActiveKey, active); + app.provide(metaActiveKey, this.target.context.active); } addMeta(metadata, vm) { if (!vm) { @@ -861,20 +867,27 @@ class MetaManager { } } render({ slots } = {}) { + const active = this.target.context.active; // TODO: clean this method const { isSSR } = this; // cleanup ssr tags if not yet done if (!isSSR && !this.ssrCleanedUp) { this.ssrCleanedUp = true; - // Listen for DOM loaded because tags in the body couldnt - // have loaded yet once the manager does it first render - // (preferable there should only be one meta render on hydration) - window.addEventListener('DOMContentLoaded', () => { + const cleanUpSSR = () => { const ssrTags = document.querySelectorAll(`[${ssrAttribute}]`); if (ssrTags && ssrTags.length) { ssrTags.forEach(el => el.parentNode && el.parentNode.removeChild(el)); } - }, { once: true }); + }; + if (document.readyState === 'loading') { + // Listen for DOM loaded because tags in the body couldnt + // have loaded yet once the manager does it first render + // (preferable there should only be one meta render on hydration) + window.addEventListener('DOMContentLoaded', cleanUpSSR, { once: true }); + } + else { + cleanUpSSR(); + } } const teleports = {}; for (const key in active) { @@ -923,6 +936,7 @@ MetaManager.create = (isSSR, config, resolver) => { } return resolver.resolve(options, contexts, active, key, pathSegments); }; + const active = reactive({}); const mergedObject = createMergedObject(resolve, active); // TODO: validate resolver const manager = new MetaManager(isSSR, config, mergedObject, resolver); diff --git a/dist/vue-meta.esm-browser.min.js b/dist/vue-meta.esm-browser.min.js index 1502d9c..3dd35be 100644 --- a/dist/vue-meta.esm-browser.min.js +++ b/dist/vue-meta.esm-browser.min.js @@ -1,8 +1,8 @@ /** - * vue-meta v3.0.0-alpha.6 + * vue-meta v3.0.0-alpha.7 * (c) 2021 * - Pim (@pimlie) * - All the amazing contributors * @license MIT */ -import{markRaw as t,h as e,getCurrentInstance as o,isProxy as r,watch as n,inject as s,defineComponent as i,reactive as c,onUnmounted as a,Teleport as u,Comment as l}from"vue";const f=(t,e)=>(o,r)=>{let n=-1;if(r.reduce(((e,o,r)=>{const s=t(e,o);return s!==e?(n=r,s):e}),e),n>-1)return o[n]},d=f(((t,e)=>{const{depth:o}=e;return!t||o>t?o:t}));var p=Object.freeze({__proto__:null,setup:t=>{let e=0;if(t.vm){let{vm:o}=t;do{o.parent&&(e++,o=o.parent)}while(o&&o.parent&&o!==o.root)}t.depth=e},resolve:d});const m={body:{tag:"script",to:"body"},base:{valueAttribute:"href"},charset:{tag:"meta",nameless:!0,valueAttribute:"charset"},description:{tag:"meta"},og:{group:!0,namespacedAttribute:!0,tag:"meta",keyAttribute:"property"},twitter:{group:!0,namespacedAttribute:!0,tag:"meta"},htmlAttrs:{attributesFor:"html"},headAttrs:{attributesFor:"head"},bodyAttrs:{attributesFor:"body"}},h={title:{attributes:!1},base:{contentAsAttribute:!0,attributes:["href","target"]},meta:{contentAsAttribute:!0,keyAttribute:"name",attributes:["content","name","http-equiv","charset"]},link:{contentAsAttribute:!0,attributes:["href","crossorigin","rel","media","integrity","hreflang","type","referrerpolicy","sizes","imagesrcset","imagesizes","as","color"]},style:{attributes:["media"]},script:{attributes:["src","type","nomodule","async","defer","crossorigin","integrity","referrerpolicy"]},noscript:{attributes:!1}};Object.freeze({}),Object.freeze([]);const b=Array.isArray,g=t=>"function"==typeof t,y=t=>"string"==typeof t,v=t=>null!==t&&"object"==typeof t,S=Object.prototype.toString,A=t=>"[object Object]"===S.call(t),k=Symbol("kIsProxy"),j=Symbol("kProxySources"),w=Symbol("kProxyTarget"),R=Symbol("kResolveContext");function N(t){if(b(t))return t.map(N);if(v(t)){const e={};for(const o in t)e[o]="context"===o?t[o]:N(t[o]);return e}return t}const $=(t,e,o)=>{const r=[];for(const n of t)n&&e in n&&(r.push(n[e]),o&&o(n));return r},O=(t,e=[],o,r)=>{if(!o&&!r&&(({active:o,sources:r}=t),e.length))for(let t=0;tt[n])).filter(Boolean)}if(!o||!r)return;const n=((t,...e)=>{const o=t?Object.keys(t):[];if(e)for(const t of e)if(t&&v(t))for(const e in t)o.includes(e)||o.push(e);return o})(...r),s=Object.keys(o);for(const t of s)n.includes(t)||delete o[t];for(const s of n){let n=!1;for(let t=0;ti.push(t[R])));let a=t.resolve(c,i,o[s],s,e);A(a)&&(a=N(a)),o[s]=a}},x=(e,o,r,n=[])=>{const s=P(e,r,n),i=t(new Proxy(o,s));return!n.length&&e.sources&&e.sources.push(i),i},P=(t,e,o=[])=>({get:(r,n,s)=>{if(n===k)return!0;if(n===j)return t.sources;if(n===w)return r;if(n===R)return e;let i=Reflect.get(r,n,s);if(!v(i))return i;if(!i[k]){const s=[...o,n];i=x(t,i,e,s),Reflect.set(r,n,i)}return i},set:(e,r,n)=>{const s=Reflect.set(e,r,n);if(s){const i=b(e);let c,a=!1,{sources:u,active:l}=t,f=0;for(const t of o){if(u=$(u,t),i&&f===o.length-1){c=t;break}b(l)&&(a=!0),l=l[t],f++}if(a)return O(t),s;if(A(n))return O(t,o),s;let d,p=[];i?(d=u,p=u.map((t=>t[R]))):d=$(u,r,(t=>p.push(t[R])));let m=t.resolve(d,p,l,r,o);A(m)&&(m=N(m)),i&&c?l[c]=m:l[r]=m}return s},deleteProperty:(e,r)=>{const n=Reflect.deleteProperty(e,r);if(n){const n=b(e);let s,i=t.sources,c=t.active,a=0;for(const t of o){if(i=i.map((e=>e&&e[t])),n&&a===o.length-1){s=t;break}c=c[t],a++}if(i.some((t=>t&&r in t))){let e,a=[];n?(e=i,a=i.map((t=>t[R]))):e=$(i,r,(t=>a.push(t[R])));let u=t.resolve(e,a,c,r,o);A(u)&&(u=N(u)),n&&s?c[s]=u:c[r]=u}else delete c[r]}return n}}),C={};function M(t,o,r,n){return"attributesFor"in n?function(t,o,r,n){const{attributesFor:s}=n;if(!s||!r)return;if(t.isSSR)return{to:"",vnode:e(`ssr-${s}`,r)};if(!C[s]){const[t,e]=Array.from(document.querySelectorAll(s));if(!t)return void console.error("Could not find element for selector",s,", won't render attributes");e&&console.warn("Found multiple elements for selector",s),C[s]={el:t,attrs:[]}}const{el:i,attrs:c}=C[s];for(const e in r){let n=E(t,`${o}(${e})`,r[e],r);b(n)&&(n=n.join(",")),i.setAttribute(e,n||""),c.includes(e)||c.push(e)}const a=c.filter((t=>!r[t]));for(const t of a)i.removeAttribute(t)}(t,o,r,n):"group"in n?function(t,e,o,r){if(b(o))return console.warn("Specifying an array for group properties isnt supported"),[];return Object.keys(o).map((n=>{const s={group:e,data:o};if(r.namespaced)s.tagNamespace=!0===r.namespaced?e:r.namespaced;else if(r.namespacedAttribute){const t=!0===r.namespacedAttribute?e:r.namespacedAttribute;s.fullName=`${t}:${n}`,s.slotName=`${t}(${n})`}return F(t,e,o[n],r,s)})).flat()}(t,o,r,n):F(t,o,r,n)}function F(t,o,r,n={},s){const i=["content","json","rawContent"],c=t=>function(t,e){for(const o of t){const t=h[o];if(o&&t)return t[e]}}([a,n.tag],t);if(b(r))return r.map((e=>F(t,o,e,n,s))).flat();const{tag:a=n.tag||o}=r;let u="",l=!1,f=!1;if(y(r))u=r;else if(r.children&&b(r.children))l=!0,u=r.children.map((e=>{const r=F(t,o,e,n,s);return b(r)?r.map((({vnode:t})=>t)):r.vnode}));else{let t=0;for(const e of i){if(!u&&r[e]){u=1===t?JSON.stringify(r[e]):r[e],f=t>1;break}t++}}const d=s&&s.fullName||o,p=s&&s.slotName||o;let{attrs:m}=r;if(m||"object"!=typeof r)m||(m={});else{m={...r},delete m.tag,delete m.children,delete m.to;for(const t of i)delete m[t]}if(l)u=E(t,p,u,r);else{const e=!!c("contentAsAttribute");let{valueAttribute:o}=n;if(!o&&e){const[t]=c("attributes");o=y(e)?e:t}if(o){const{nameless:e,keyAttribute:r}=n;e||r&&(m[r]=d),m[o]=E(t,p,m[o]||u,s),u=""}else u=E(t,p,u,r)}const g=s&&s.tagNamespace?`${s.tagNamespace}:${a}`:a;f&&u&&(m.innerHTML=u);const v=e(g,m,u||void 0);return{to:r.to,vnode:v}}function E({metainfo:t,slots:e},o,r,n){const s=e&&e[o];if(!s||!g(s))return r;const i={content:r,metainfo:t};if(n&&n.group){const{group:t,data:e}=n;i[t]=e}const c=s(i);if(c&&c.length){const{children:t}=c[0];return t?t.toString():""}return r}const U="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag,z=(t=>U?Symbol("[vue-meta]: "+t):"[vue-meta]: "+t)("meta_active");function _(t,e,o){for(const r in e)r in o?v(t[r])?_(t[r],e[r],o[r]):e[r]!==o[r]&&(t[r]=e[r]):t[r]=e[r];for(const r in o)e&&r in e||delete t[r]}function L(t){if(t||(t=o()||void 0),t)return t.appContext.config.globalProperties.$metaManager}function q(t,e){const s=o()||void 0;if(!e&&s&&(e=L(s)),!e)throw new Error("No manager or current instance");r(t)&&(n(t,((t,e)=>{_(i.meta,t,e)})),t=t.value);const i=e.addMeta(t,s);return i}function T(){return s(z)}const I=i({name:"Metainfo",inheritAttrs:!1,setup:(t,{slots:e})=>()=>{const t=L();if(t)return t.render({slots:e})}}),B=c({});function D(t,e,o,r){const n=b(r)?r:[r];t?o.endsWith("Attrs")||n.forEach((t=>{t.props||(t.props={}),t.props["data-vm-ssr"]=!0})):n.forEach(((t,e)=>{t.type===l&&n.splice(e,1)})),e[o]||(e[o]=[]),e[o].push(...n)}const H=(t=!1,e,o)=>J.create(t,e||m,o||p);class J{constructor(t,e,o,r){this.isSSR=!1,this.ssrCleanedUp=!1,this.isSSR=t,this.config=e,this.target=o,r&&"setup"in r&&g(r.setup)&&(this.resolver=r)}install(t){t.component("Metainfo",I),t.config.globalProperties.$metaManager=this,t.provide(z,B)}addMeta(t,e){e||(e=o()||void 0);const r={removed:[]},n={vm:e},{resolver:s}=this;s&&s.setup&&s.setup(n);const i=this.target.addSource(t,n,!0),c=t=>this.unmount(!!t,i,r,e);return e&&a(c),{meta:i,onRemoved:t=>r.removed.push(t),unmount:c}}unmount(t,e,o,r){if(r){const{$el:n}=r.proxy;if(n&&n.offsetParent){let r=new MutationObserver((s=>{for(const{removedNodes:i}of s)i&&i.forEach((s=>{s===n&&r&&(r.disconnect(),r=void 0,this.reallyUnmount(t,e,o))}))}));return void r.observe(n.parentNode,{childList:!0})}}this.reallyUnmount(t,e,o)}async reallyUnmount(t,e,o){this.target.delSource(e),!t&&o&&await Promise.all(o.removed.map((t=>t())))}render({slots:t}={}){const{isSSR:o}=this;o||this.ssrCleanedUp||(this.ssrCleanedUp=!0,window.addEventListener("DOMContentLoaded",(()=>{const t=document.querySelectorAll("[data-vm-ssr]");t&&t.length&&t.forEach((t=>t.parentNode&&t.parentNode.removeChild(t)))}),{once:!0}));const r={};for(const e in B){const n=this.config[e]||{};let s=M({isSSR:o,metainfo:B,slots:t},e,B[e],n);if(!s)continue;b(s)||(s=[s]);let i="base"!==e&&B[e].to;!i&&"to"in n&&(i=n.to),!i&&"attributesFor"in n&&(i=e);for(const{to:t,vnode:e}of s)D(this.isSSR,r,t||i||"head",e)}if(t)for(const e in t){const o="default"===e?"head":e;if("head"!==o&&"body"!==o)continue;const n=t[e];g(n)&&D(this.isSSR,r,o,n({metainfo:B}))}return Object.keys(r).map((t=>e(u,{to:t},r[t])))}}J.create=(t,e,o)=>{const r=((t,e)=>{const o=[],r={active:e,resolve:t,sources:o},n=()=>O(r);return{context:r,compute:n,addSource:(t,e,o=!1)=>{const s=x(r,t,e||{});return o&&n(),s},delSource:(t,e=!0)=>{const r=o.findIndex((e=>e===t||e[w]===t));return r>-1&&(o.splice(r,1),e&&n(),!0)}}})(((t,e,r,n,s)=>g(o)?o(t,e,r,n,s):o.resolve(t,e,r,n,s)),B);return new J(t,e,r,o)};export{H as createMetaManager,p as deepestResolver,m as defaultConfig,L as getCurrentManager,f as resolveOption,T as useActiveMeta,q as useMeta}; +import{markRaw as t,h as e,getCurrentInstance as o,isProxy as r,watch as n,inject as s,defineComponent as i,onUnmounted as c,Teleport as a,reactive as u,Comment as l}from"vue";const f=(t,e)=>(o,r)=>{let n=-1;if(r.reduce(((e,o,r)=>{const s=t(e,o);return s!==e?(n=r,s):e}),e),n>-1)return o[n]},d=f(((t,e)=>{const{depth:o}=e;return!t||o>t?o:t}));var p=Object.freeze({__proto__:null,setup:t=>{let e=0;if(t.vm){let{vm:o}=t;do{o.parent&&(e++,o=o.parent)}while(o&&o.parent&&o!==o.root)}t.depth=e},resolve:d});const m={body:{tag:"script",to:"body"},base:{valueAttribute:"href"},charset:{tag:"meta",nameless:!0,valueAttribute:"charset"},description:{tag:"meta"},og:{group:!0,namespacedAttribute:!0,tag:"meta",keyAttribute:"property"},twitter:{group:!0,namespacedAttribute:!0,tag:"meta"},htmlAttrs:{attributesFor:"html"},headAttrs:{attributesFor:"head"},bodyAttrs:{attributesFor:"body"}},h={title:{attributes:!1},base:{contentAsAttribute:!0,attributes:["href","target"]},meta:{contentAsAttribute:!0,keyAttribute:"name",attributes:["content","name","http-equiv","charset"]},link:{contentAsAttribute:!0,attributes:["href","crossorigin","rel","media","integrity","hreflang","type","referrerpolicy","sizes","imagesrcset","imagesizes","as","color"]},style:{attributes:["media"]},script:{attributes:["src","type","nomodule","async","defer","crossorigin","integrity","referrerpolicy"]},noscript:{attributes:!1}};Object.freeze({}),Object.freeze([]);const b=Array.isArray,g=t=>"function"==typeof t,y=t=>"string"==typeof t,v=t=>null!==t&&"object"==typeof t,S=Object.prototype.toString,A=t=>"[object Object]"===S.call(t),k=Symbol("kIsProxy"),R=Symbol("kProxySources"),j=Symbol("kProxyTarget"),w=Symbol("kResolveContext");function x(t){if(b(t))return t.map(x);if(v(t)){const e={};for(const o in t)e[o]="context"===o?t[o]:x(t[o]);return e}return t}const N=(t,e,o)=>{const r=[];for(const n of t)n&&e in n&&(r.push(n[e]),o&&o(n));return r},$=(t,e=[],o,r)=>{if(!o&&!r&&(({active:o,sources:r}=t),e.length))for(let t=0;tt[n])).filter(Boolean)}if(!o||!r)return;const n=((t,...e)=>{const o=t?Object.keys(t):[];if(e)for(const t of e)if(t&&v(t))for(const e in t)o.includes(e)||o.push(e);return o})(...r),s=Object.keys(o);for(const t of s)n.includes(t)||delete o[t];for(const s of n){let n=!1;for(let t=0;ti.push(t[w])));let a=t.resolve(c,i,o[s],s,e);A(a)&&(a=x(a)),o[s]=a}},O=(e,o,r,n=[])=>{const s=P(e,r,n),i=t(new Proxy(o,s));return!n.length&&e.sources&&e.sources.push(i),i},P=(t,e,o=[])=>({get:(r,n,s)=>{if(n===k)return!0;if(n===R)return t.sources;if(n===j)return r;if(n===w)return e;let i=Reflect.get(r,n,s);if(!v(i))return i;if(!i[k]){const s=[...o,n];i=O(t,i,e,s),Reflect.set(r,n,i)}return i},set:(e,r,n)=>{const s=Reflect.set(e,r,n);if(s){const i=b(e);let c,a=!1,{sources:u,active:l}=t,f=0;for(const t of o){if(u=N(u,t),i&&f===o.length-1){c=t;break}b(l)&&(a=!0),l=l[t],f++}if(a)return $(t),s;if(A(n))return $(t,o),s;let d,p=[];i?(d=u,p=u.map((t=>t[w]))):d=N(u,r,(t=>p.push(t[w])));let m=t.resolve(d,p,l,r,o);A(m)&&(m=x(m)),i&&c?l[c]=m:l[r]=m}return s},deleteProperty:(e,r)=>{const n=Reflect.deleteProperty(e,r);if(n){const n=b(e);let s,i=t.sources,c=t.active,a=0;for(const t of o){if(i=i.map((e=>e&&e[t])),n&&a===o.length-1){s=t;break}c=c[t],a++}if(i.some((t=>t&&r in t))){let e,a=[];n?(e=i,a=i.map((t=>t[w]))):e=N(i,r,(t=>a.push(t[w])));let u=t.resolve(e,a,c,r,o);A(u)&&(u=x(u)),n&&s?c[s]=u:c[r]=u}else delete c[r]}return n}}),C={};function M(t,o,r,n){return"attributesFor"in n?function(t,o,r,n){const{attributesFor:s}=n;if(!s||!r)return;if(t.isSSR)return{to:"",vnode:e(`ssr-${s}`,r)};if(!C[s]){const[t,e]=Array.from(document.querySelectorAll(s));if(!t)return void console.error("Could not find element for selector",s,", won't render attributes");e&&console.warn("Found multiple elements for selector",s),C[s]={el:t,attrs:[]}}const{el:i,attrs:c}=C[s];for(const e in r){let n=E(t,`${o}(${e})`,r[e],r);b(n)&&(n=n.join(",")),i.setAttribute(e,n||""),c.includes(e)||c.push(e)}const a=c.filter((t=>!r[t]));for(const t of a)i.removeAttribute(t)}(t,o,r,n):"group"in n?function(t,e,o,r){if(b(o))return console.warn("Specifying an array for group properties isnt supported"),[];return Object.keys(o).map((n=>{const s={group:e,data:o};if(r.namespaced)s.tagNamespace=!0===r.namespaced?e:r.namespaced;else if(r.namespacedAttribute){const t=!0===r.namespacedAttribute?e:r.namespacedAttribute;s.fullName=`${t}:${n}`,s.slotName=`${t}(${n})`}return F(t,e,o[n],r,s)})).filter(Boolean).flat()}(t,o,r,n):F(t,o,r,n)}function F(t,o,r,n={},s){const i=["content","json","rawContent"],c=t=>function(t,e){for(const o of t){const t=h[o];if(o&&t)return t[e]}}([a,n.tag],t);if(b(r))return r.map((e=>F(t,o,e,n,s))).filter(Boolean).flat();const{tag:a=n.tag||o}=r;let u="",l=!1,f=!1;if(y(r))u=r;else if(r.children&&b(r.children))l=!0,u=r.children.map((e=>{const r=F(t,o,e,n,s);return b(r)?r.map((({vnode:t})=>t)):r&&r.vnode}));else{let t=0;for(const e of i){if(!u&&r[e]){u=1===t?JSON.stringify(r[e]):r[e],f=t>1;break}t++}}const d=s&&s.fullName||o,p=s&&s.slotName||o;let{attrs:m}=r;if(m||"object"!=typeof r)m||(m={});else{m={...r},delete m.tag,delete m.children,delete m.to;for(const t of i)delete m[t]}if(l)u=E(t,p,u,r);else{const e=!!c("contentAsAttribute");let{valueAttribute:o}=n;if(!o&&e){const[t]=c("attributes");o=y(e)?e:t}if(o){const{nameless:e}=n;if(!e){const t=n.keyAttribute||c("keyAttribute");t&&(m[t]=d)}m[o]=E(t,p,m[o]||u,s),u=""}else u=E(t,p,u,r)}const g=s&&s.tagNamespace?`${s.tagNamespace}:${a}`:a;if("title"===g&&!t.isSSR)return void(document.title=u);f&&u&&(m.innerHTML=u);const v=e(g,m,u||void 0);return{to:r.to,vnode:v}}function E({metainfo:t,slots:e},o,r,n){const s=e&&e[o];if(!s||!g(s))return r;const i={content:r,metainfo:t};if(n&&n.group){const{group:t,data:e}=n;i[t]=e}const c=s(i);if(c&&c.length){const{children:t}=c[0];return t?t.toString():""}return r}const U="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag,z=(t=>U?Symbol("[vue-meta]: "+t):"[vue-meta]: "+t)("meta_active");function _(t,e,o){for(const r in e)r in o?v(t[r])?_(t[r],e[r],o[r]):e[r]!==o[r]&&(t[r]=e[r]):t[r]=e[r];for(const r in o)e&&r in e||delete t[r]}function L(t){if(t||(t=o()||void 0),t)return t.appContext.config.globalProperties.$metaManager}function q(t,e){const s=o()||void 0;if(!e&&s&&(e=L(s)),!e)throw new Error("No manager or current instance");r(t)&&(n(t,((t,e)=>{_(i.meta,t,e)})),t=t.value);const i=e.addMeta(t,s);return i}function B(){return s(z)}const T=i({name:"Metainfo",inheritAttrs:!1,setup:(t,{slots:e})=>()=>{const t=L();if(t)return t.render({slots:e})}});function I(t,e,o,r){const n=b(r)?r:[r];t?o.endsWith("Attrs")||n.forEach((t=>{t.props||(t.props={}),t.props["data-vm-ssr"]=!0})):n.forEach(((t,e)=>{t.type===l&&n.splice(e,1)})),e[o]||(e[o]=[]),e[o].push(...n)}const D=(t=!1,e,o)=>H.create(t,e||m,o||p);class H{constructor(t,e,o,r){this.isSSR=!1,this.ssrCleanedUp=!1,this.isSSR=t,this.config=e,this.target=o,r&&"setup"in r&&g(r.setup)&&(this.resolver=r)}install(t){t.component("Metainfo",T),t.config.globalProperties.$metaManager=this,t.provide(z,this.target.context.active)}addMeta(t,e){e||(e=o()||void 0);const r={removed:[]},n={vm:e},{resolver:s}=this;s&&s.setup&&s.setup(n);const i=this.target.addSource(t,n,!0),a=t=>this.unmount(!!t,i,r,e);return e&&c(a),{meta:i,onRemoved:t=>r.removed.push(t),unmount:a}}unmount(t,e,o,r){if(r){const{$el:n}=r.proxy;if(n&&n.offsetParent){let r=new MutationObserver((s=>{for(const{removedNodes:i}of s)i&&i.forEach((s=>{s===n&&r&&(r.disconnect(),r=void 0,this.reallyUnmount(t,e,o))}))}));return void r.observe(n.parentNode,{childList:!0})}}this.reallyUnmount(t,e,o)}async reallyUnmount(t,e,o){this.target.delSource(e),!t&&o&&await Promise.all(o.removed.map((t=>t())))}render({slots:t}={}){const o=this.target.context.active,{isSSR:r}=this;if(!r&&!this.ssrCleanedUp){this.ssrCleanedUp=!0;const t=()=>{const t=document.querySelectorAll("[data-vm-ssr]");t&&t.length&&t.forEach((t=>t.parentNode&&t.parentNode.removeChild(t)))};"loading"===document.readyState?window.addEventListener("DOMContentLoaded",t,{once:!0}):t()}const n={};for(const e in o){const s=this.config[e]||{};let i=M({isSSR:r,metainfo:o,slots:t},e,o[e],s);if(!i)continue;b(i)||(i=[i]);let c="base"!==e&&o[e].to;!c&&"to"in s&&(c=s.to),!c&&"attributesFor"in s&&(c=e);for(const{to:t,vnode:e}of i)I(this.isSSR,n,t||c||"head",e)}if(t)for(const e in t){const r="default"===e?"head":e;if("head"!==r&&"body"!==r)continue;const s=t[e];g(s)&&I(this.isSSR,n,r,s({metainfo:o}))}return Object.keys(n).map((t=>e(a,{to:t},n[t])))}}H.create=(t,e,o)=>{const r=((t,e)=>{const o=[],r={active:e,resolve:t,sources:o},n=()=>$(r);return{context:r,compute:n,addSource:(t,e,o=!1)=>{const s=O(r,t,e||{});return o&&n(),s},delSource:(t,e=!0)=>{const r=o.findIndex((e=>e===t||e[j]===t));return r>-1&&(o.splice(r,1),e&&n(),!0)}}})(((t,e,r,n,s)=>g(o)?o(t,e,r,n,s):o.resolve(t,e,r,n,s)),u({}));return new H(t,e,r,o)};export{D as createMetaManager,p as deepestResolver,m as defaultConfig,L as getCurrentManager,f as resolveOption,B as useActiveMeta,q as useMeta}; diff --git a/dist/vue-meta.esm-bundler.js b/dist/vue-meta.esm-bundler.js index 2bcf19c..62354d4 100644 --- a/dist/vue-meta.esm-bundler.js +++ b/dist/vue-meta.esm-bundler.js @@ -1,12 +1,12 @@ /** - * vue-meta v3.0.0-alpha.6 + * vue-meta v3.0.0-alpha.7 * (c) 2021 * - Pim (@pimlie) * - All the amazing contributors * @license MIT */ -import { markRaw, h, getCurrentInstance, isProxy, watch, inject, defineComponent, reactive, onUnmounted, Teleport, Comment } from 'vue'; +import { markRaw, h, getCurrentInstance, isProxy, watch, inject, defineComponent, onUnmounted, Teleport, reactive, Comment } from 'vue'; const resolveOption = (predicament, initialValue) => (options, contexts) => { let resolvedIndex = -1; @@ -514,6 +514,7 @@ function renderGroup(context, key, data, config) { } return renderTag(context, key, data[childKey], config, groupConfig); }) + .filter(Boolean) .flat(); } function renderTag(context, key, data, config = {}, groupConfig) { @@ -525,6 +526,7 @@ function renderTag(context, key, data, config = {}, groupConfig) { .map((child) => { return renderTag(context, key, child, config, groupConfig); }) + .filter(Boolean) .flat(); } const { tag = config.tag || key } = data; @@ -541,7 +543,7 @@ function renderTag(context, key, data, config = {}, groupConfig) { if (isArray(data)) { return data.map(({ vnode }) => vnode); } - return data.vnode; + return data && data.vnode; }); } else { @@ -590,8 +592,9 @@ function renderTag(context, key, data, config = {}, groupConfig) { content = getSlotContent(context, slotName, content, data); } else { - const { nameless, keyAttribute } = config; + const { nameless } = config; if (!nameless) { + const keyAttribute = config.keyAttribute || getTagConfig('keyAttribute'); if (keyAttribute) { attributes[keyAttribute] = fullName; } @@ -603,6 +606,10 @@ function renderTag(context, key, data, config = {}, groupConfig) { const finalTag = groupConfig && groupConfig.tagNamespace ? `${groupConfig.tagNamespace}:${tag}` : tag; + if (finalTag === 'title' && !context.isSSR) { + document.title = content; + return; + } // console.info('FINAL TAG', finalTag) // console.log(' ATTRIBUTES', attributes) // console.log(' CONTENT', content) @@ -762,7 +769,6 @@ const MetainfoImpl = defineComponent({ const Metainfo = MetainfoImpl; const ssrAttribute = 'data-vm-ssr'; -const active = reactive({}); function addVnode(isSSR, teleports, to, vnodes) { const nodes = (isArray(vnodes) ? vnodes : [vnodes]); if (!isSSR) { @@ -802,7 +808,7 @@ class MetaManager { install(app) { app.component('Metainfo', Metainfo); app.config.globalProperties.$metaManager = this; - app.provide(metaActiveKey, active); + app.provide(metaActiveKey, this.target.context.active); } addMeta(metadata, vm) { if (!vm) { @@ -861,20 +867,27 @@ class MetaManager { } } render({ slots } = {}) { + const active = this.target.context.active; // TODO: clean this method const { isSSR } = this; // cleanup ssr tags if not yet done if (!isSSR && !this.ssrCleanedUp) { this.ssrCleanedUp = true; - // Listen for DOM loaded because tags in the body couldnt - // have loaded yet once the manager does it first render - // (preferable there should only be one meta render on hydration) - window.addEventListener('DOMContentLoaded', () => { + const cleanUpSSR = () => { const ssrTags = document.querySelectorAll(`[${ssrAttribute}]`); if (ssrTags && ssrTags.length) { ssrTags.forEach(el => el.parentNode && el.parentNode.removeChild(el)); } - }, { once: true }); + }; + if (document.readyState === 'loading') { + // Listen for DOM loaded because tags in the body couldnt + // have loaded yet once the manager does it first render + // (preferable there should only be one meta render on hydration) + window.addEventListener('DOMContentLoaded', cleanUpSSR, { once: true }); + } + else { + cleanUpSSR(); + } } const teleports = {}; for (const key in active) { @@ -923,6 +936,7 @@ MetaManager.create = (isSSR, config, resolver) => { } return resolver.resolve(options, contexts, active, key, pathSegments); }; + const active = reactive({}); const mergedObject = createMergedObject(resolve, active); // TODO: validate resolver const manager = new MetaManager(isSSR, config, mergedObject, resolver); diff --git a/dist/vue-meta.global.js b/dist/vue-meta.global.js index d48d7ba..7b892b7 100644 --- a/dist/vue-meta.global.js +++ b/dist/vue-meta.global.js @@ -1,5 +1,5 @@ /** - * vue-meta v3.0.0-alpha.6 + * vue-meta v3.0.0-alpha.7 * (c) 2021 * - Pim (@pimlie) * - All the amazing contributors @@ -515,6 +515,7 @@ var VueMeta = (function (exports, vue) { } return renderTag(context, key, data[childKey], config, groupConfig); }) + .filter(Boolean) .flat(); } function renderTag(context, key, data, config = {}, groupConfig) { @@ -526,6 +527,7 @@ var VueMeta = (function (exports, vue) { .map((child) => { return renderTag(context, key, child, config, groupConfig); }) + .filter(Boolean) .flat(); } const { tag = config.tag || key } = data; @@ -542,7 +544,7 @@ var VueMeta = (function (exports, vue) { if (isArray(data)) { return data.map(({ vnode }) => vnode); } - return data.vnode; + return data && data.vnode; }); } else { @@ -591,8 +593,9 @@ var VueMeta = (function (exports, vue) { content = getSlotContent(context, slotName, content, data); } else { - const { nameless, keyAttribute } = config; + const { nameless } = config; if (!nameless) { + const keyAttribute = config.keyAttribute || getTagConfig('keyAttribute'); if (keyAttribute) { attributes[keyAttribute] = fullName; } @@ -604,6 +607,10 @@ var VueMeta = (function (exports, vue) { const finalTag = groupConfig && groupConfig.tagNamespace ? `${groupConfig.tagNamespace}:${tag}` : tag; + if (finalTag === 'title' && !context.isSSR) { + document.title = content; + return; + } // console.info('FINAL TAG', finalTag) // console.log(' ATTRIBUTES', attributes) // console.log(' CONTENT', content) @@ -763,7 +770,6 @@ var VueMeta = (function (exports, vue) { const Metainfo = MetainfoImpl; const ssrAttribute = 'data-vm-ssr'; - const active = vue.reactive({}); function addVnode(isSSR, teleports, to, vnodes) { const nodes = (isArray(vnodes) ? vnodes : [vnodes]); if (!isSSR) { @@ -803,7 +809,7 @@ var VueMeta = (function (exports, vue) { install(app) { app.component('Metainfo', Metainfo); app.config.globalProperties.$metaManager = this; - app.provide(metaActiveKey, active); + app.provide(metaActiveKey, this.target.context.active); } addMeta(metadata, vm) { if (!vm) { @@ -862,20 +868,27 @@ var VueMeta = (function (exports, vue) { } } render({ slots } = {}) { + const active = this.target.context.active; // TODO: clean this method const { isSSR } = this; // cleanup ssr tags if not yet done if (!isSSR && !this.ssrCleanedUp) { this.ssrCleanedUp = true; - // Listen for DOM loaded because tags in the body couldnt - // have loaded yet once the manager does it first render - // (preferable there should only be one meta render on hydration) - window.addEventListener('DOMContentLoaded', () => { + const cleanUpSSR = () => { const ssrTags = document.querySelectorAll(`[${ssrAttribute}]`); if (ssrTags && ssrTags.length) { ssrTags.forEach(el => el.parentNode && el.parentNode.removeChild(el)); } - }, { once: true }); + }; + if (document.readyState === 'loading') { + // Listen for DOM loaded because tags in the body couldnt + // have loaded yet once the manager does it first render + // (preferable there should only be one meta render on hydration) + window.addEventListener('DOMContentLoaded', cleanUpSSR, { once: true }); + } + else { + cleanUpSSR(); + } } const teleports = {}; for (const key in active) { @@ -924,6 +937,7 @@ var VueMeta = (function (exports, vue) { } return resolver.resolve(options, contexts, active, key, pathSegments); }; + const active = vue.reactive({}); const mergedObject = createMergedObject(resolve, active); // TODO: validate resolver const manager = new MetaManager(isSSR, config, mergedObject, resolver); diff --git a/dist/vue-meta.global.min.js b/dist/vue-meta.global.min.js index d7087c1..e020dd9 100644 --- a/dist/vue-meta.global.min.js +++ b/dist/vue-meta.global.min.js @@ -1,8 +1,8 @@ /** - * vue-meta v3.0.0-alpha.6 + * vue-meta v3.0.0-alpha.7 * (c) 2021 * - Pim (@pimlie) * - All the amazing contributors * @license MIT */ -var VueMeta=function(t,e){"use strict";const r=(t,e)=>(r,o)=>{let n=-1;if(o.reduce(((e,r,o)=>{const s=t(e,r);return s!==e?(n=o,s):e}),e),n>-1)return r[n]},o=r(((t,e)=>{const{depth:r}=e;return!t||r>t?r:t}));var n=Object.freeze({__proto__:null,setup:t=>{let e=0;if(t.vm){let{vm:r}=t;do{r.parent&&(e++,r=r.parent)}while(r&&r.parent&&r!==r.root)}t.depth=e},resolve:o});const s={body:{tag:"script",to:"body"},base:{valueAttribute:"href"},charset:{tag:"meta",nameless:!0,valueAttribute:"charset"},description:{tag:"meta"},og:{group:!0,namespacedAttribute:!0,tag:"meta",keyAttribute:"property"},twitter:{group:!0,namespacedAttribute:!0,tag:"meta"},htmlAttrs:{attributesFor:"html"},headAttrs:{attributesFor:"head"},bodyAttrs:{attributesFor:"body"}},i={title:{attributes:!1},base:{contentAsAttribute:!0,attributes:["href","target"]},meta:{contentAsAttribute:!0,keyAttribute:"name",attributes:["content","name","http-equiv","charset"]},link:{contentAsAttribute:!0,attributes:["href","crossorigin","rel","media","integrity","hreflang","type","referrerpolicy","sizes","imagesrcset","imagesizes","as","color"]},style:{attributes:["media"]},script:{attributes:["src","type","nomodule","async","defer","crossorigin","integrity","referrerpolicy"]},noscript:{attributes:!1}};Object.freeze({}),Object.freeze([]);const c=Array.isArray,a=t=>"function"==typeof t,u=t=>"string"==typeof t,l=t=>null!==t&&"object"==typeof t,f=Object.prototype.toString,d=t=>"[object Object]"===f.call(t),p=Symbol("kIsProxy"),m=Symbol("kProxySources"),h=Symbol("kProxyTarget"),b=Symbol("kResolveContext");function g(t){if(c(t))return t.map(g);if(l(t)){const e={};for(const r in t)e[r]="context"===r?t[r]:g(t[r]);return e}return t}const v=(t,e,r)=>{const o=[];for(const n of t)n&&e in n&&(o.push(n[e]),r&&r(n));return o},y=(t,e=[],r,o)=>{if(!r&&!o&&(({active:r,sources:o}=t),e.length))for(let t=0;tt[n])).filter(Boolean)}if(!r||!o)return;const n=((t,...e)=>{const r=t?Object.keys(t):[];if(e)for(const t of e)if(t&&l(t))for(const e in t)r.includes(e)||r.push(e);return r})(...o),s=Object.keys(r);for(const t of s)n.includes(t)||delete r[t];for(const s of n){let n=!1;for(let t=0;ti.push(t[b])));let u=t.resolve(a,i,r[s],s,e);d(u)&&(u=g(u)),r[s]=u}},S=(t,r,o,n=[])=>{const s=A(t,o,n),i=e.markRaw(new Proxy(r,s));return!n.length&&t.sources&&t.sources.push(i),i},A=(t,e,r=[])=>({get:(o,n,s)=>{if(n===p)return!0;if(n===m)return t.sources;if(n===h)return o;if(n===b)return e;let i=Reflect.get(o,n,s);if(!l(i))return i;if(!i[p]){const s=[...r,n];i=S(t,i,e,s),Reflect.set(o,n,i)}return i},set:(e,o,n)=>{const s=Reflect.set(e,o,n);if(s){const i=c(e);let a,u=!1,{sources:l,active:f}=t,p=0;for(const t of r){if(l=v(l,t),i&&p===r.length-1){a=t;break}c(f)&&(u=!0),f=f[t],p++}if(u)return y(t),s;if(d(n))return y(t,r),s;let m,h=[];i?(m=l,h=l.map((t=>t[b]))):m=v(l,o,(t=>h.push(t[b])));let S=t.resolve(m,h,f,o,r);d(S)&&(S=g(S)),i&&a?f[a]=S:f[o]=S}return s},deleteProperty:(e,o)=>{const n=Reflect.deleteProperty(e,o);if(n){const n=c(e);let s,i=t.sources,a=t.active,u=0;for(const t of r){if(i=i.map((e=>e&&e[t])),n&&u===r.length-1){s=t;break}a=a[t],u++}if(i.some((t=>t&&o in t))){let e,c=[];n?(e=i,c=i.map((t=>t[b]))):e=v(i,o,(t=>c.push(t[b])));let u=t.resolve(e,c,a,o,r);d(u)&&(u=g(u)),n&&s?a[s]=u:a[o]=u}else delete a[o]}return n}}),k={};function j(t,r,o,n){return"attributesFor"in n?function(t,r,o,n){const{attributesFor:s}=n;if(!s||!o)return;if(t.isSSR)return{to:"",vnode:e.h(`ssr-${s}`,o)};if(!k[s]){const[t,e]=Array.from(document.querySelectorAll(s));if(!t)return void console.error("Could not find element for selector",s,", won't render attributes");e&&console.warn("Found multiple elements for selector",s),k[s]={el:t,attrs:[]}}const{el:i,attrs:a}=k[s];for(const e in o){let n=C(t,`${r}(${e})`,o[e],o);c(n)&&(n=n.join(",")),i.setAttribute(e,n||""),a.includes(e)||a.push(e)}const u=a.filter((t=>!o[t]));for(const t of u)i.removeAttribute(t)}(t,r,o,n):"group"in n?function(t,e,r,o){if(c(r))return console.warn("Specifying an array for group properties isnt supported"),[];return Object.keys(r).map((n=>{const s={group:e,data:r};if(o.namespaced)s.tagNamespace=!0===o.namespaced?e:o.namespaced;else if(o.namespacedAttribute){const t=!0===o.namespacedAttribute?e:o.namespacedAttribute;s.fullName=`${t}:${n}`,s.slotName=`${t}(${n})`}return w(t,e,r[n],o,s)})).flat()}(t,r,o,n):w(t,r,o,n)}function w(t,r,o,n={},s){const a=["content","json","rawContent"],l=t=>function(t,e){for(const r of t){const t=i[r];if(r&&t)return t[e]}}([f,n.tag],t);if(c(o))return o.map((e=>w(t,r,e,n,s))).flat();const{tag:f=n.tag||r}=o;let d="",p=!1,m=!1;if(u(o))d=o;else if(o.children&&c(o.children))p=!0,d=o.children.map((e=>{const o=w(t,r,e,n,s);return c(o)?o.map((({vnode:t})=>t)):o.vnode}));else{let t=0;for(const e of a){if(!d&&o[e]){d=1===t?JSON.stringify(o[e]):o[e],m=t>1;break}t++}}const h=s&&s.fullName||r,b=s&&s.slotName||r;let{attrs:g}=o;if(g||"object"!=typeof o)g||(g={});else{g={...o},delete g.tag,delete g.children,delete g.to;for(const t of a)delete g[t]}if(p)d=C(t,b,d,o);else{const e=!!l("contentAsAttribute");let{valueAttribute:r}=n;if(!r&&e){const[t]=l("attributes");r=u(e)?e:t}if(r){const{nameless:e,keyAttribute:o}=n;e||o&&(g[o]=h),g[r]=C(t,b,g[r]||d,s),d=""}else d=C(t,b,d,o)}const v=s&&s.tagNamespace?`${s.tagNamespace}:${f}`:f;m&&d&&(g.innerHTML=d);const y=e.h(v,g,d||void 0);return{to:o.to,vnode:y}}function C({metainfo:t,slots:e},r,o,n){const s=e&&e[r];if(!s||!a(s))return o;const i={content:o,metainfo:t};if(n&&n.group){const{group:t,data:e}=n;i[t]=e}const c=s(i);if(c&&c.length){const{children:t}=c[0];return t?t.toString():""}return o}const M="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag,R=(t=>M?Symbol("[vue-meta]: "+t):"[vue-meta]: "+t)("meta_active");function O(t,e,r){for(const o in e)o in r?l(t[o])?O(t[o],e[o],r[o]):e[o]!==r[o]&&(t[o]=e[o]):t[o]=e[o];for(const o in r)e&&o in e||delete t[o]}function N(t){if(t||(t=e.getCurrentInstance()||void 0),t)return t.appContext.config.globalProperties.$metaManager}const $=e.defineComponent({name:"Metainfo",inheritAttrs:!1,setup:(t,{slots:e})=>()=>{const t=N();if(t)return t.render({slots:e})}}),P="data-vm-ssr",x=e.reactive({});function F(t,r,o,n){const s=c(n)?n:[n];t?o.endsWith("Attrs")||s.forEach((t=>{t.props||(t.props={}),t.props[P]=!0})):s.forEach(((t,r)=>{t.type===e.Comment&&s.splice(r,1)})),r[o]||(r[o]=[]),r[o].push(...s)}class U{constructor(t,e,r,o){this.isSSR=!1,this.ssrCleanedUp=!1,this.isSSR=t,this.config=e,this.target=r,o&&"setup"in o&&a(o.setup)&&(this.resolver=o)}install(t){t.component("Metainfo",$),t.config.globalProperties.$metaManager=this,t.provide(R,x)}addMeta(t,r){r||(r=e.getCurrentInstance()||void 0);const o={removed:[]},n={vm:r},{resolver:s}=this;s&&s.setup&&s.setup(n);const i=this.target.addSource(t,n,!0),c=t=>this.unmount(!!t,i,o,r);return r&&e.onUnmounted(c),{meta:i,onRemoved:t=>o.removed.push(t),unmount:c}}unmount(t,e,r,o){if(o){const{$el:n}=o.proxy;if(n&&n.offsetParent){let o=new MutationObserver((s=>{for(const{removedNodes:i}of s)i&&i.forEach((s=>{s===n&&o&&(o.disconnect(),o=void 0,this.reallyUnmount(t,e,r))}))}));return void o.observe(n.parentNode,{childList:!0})}}this.reallyUnmount(t,e,r)}async reallyUnmount(t,e,r){this.target.delSource(e),!t&&r&&await Promise.all(r.removed.map((t=>t())))}render({slots:t}={}){const{isSSR:r}=this;r||this.ssrCleanedUp||(this.ssrCleanedUp=!0,window.addEventListener("DOMContentLoaded",(()=>{const t=document.querySelectorAll("[data-vm-ssr]");t&&t.length&&t.forEach((t=>t.parentNode&&t.parentNode.removeChild(t)))}),{once:!0}));const o={};for(const e in x){const n=this.config[e]||{};let s=j({isSSR:r,metainfo:x,slots:t},e,x[e],n);if(!s)continue;c(s)||(s=[s]);let i="base"!==e&&x[e].to;!i&&"to"in n&&(i=n.to),!i&&"attributesFor"in n&&(i=e);for(const{to:t,vnode:e}of s)F(this.isSSR,o,t||i||"head",e)}if(t)for(const e in t){const r="default"===e?"head":e;if("head"!==r&&"body"!==r)continue;const n=t[e];a(n)&&F(this.isSSR,o,r,n({metainfo:x}))}return Object.keys(o).map((t=>e.h(e.Teleport,{to:t},o[t])))}}return U.create=(t,e,r)=>{const o=((t,e)=>{const r=[],o={active:e,resolve:t,sources:r},n=()=>y(o);return{context:o,compute:n,addSource:(t,e,r=!1)=>{const s=S(o,t,e||{});return r&&n(),s},delSource:(t,e=!0)=>{const o=r.findIndex((e=>e===t||e[h]===t));return o>-1&&(r.splice(o,1),e&&n(),!0)}}})(((t,e,o,n,s)=>a(r)?r(t,e,o,n,s):r.resolve(t,e,o,n,s)),x);return new U(t,e,o,r)},t.createMetaManager=(t=!1,e,r)=>U.create(t,e||s,r||n),t.deepestResolver=n,t.defaultConfig=s,t.getCurrentManager=N,t.resolveOption=r,t.useActiveMeta=function(){return e.inject(R)},t.useMeta=function(t,r){const o=e.getCurrentInstance()||void 0;if(!r&&o&&(r=N(o)),!r)throw new Error("No manager or current instance");e.isProxy(t)&&(e.watch(t,((t,e)=>{O(n.meta,t,e)})),t=t.value);const n=r.addMeta(t,o);return n},Object.defineProperty(t,"__esModule",{value:!0}),t}({},Vue); +var VueMeta=function(t,e){"use strict";const r=(t,e)=>(r,o)=>{let n=-1;if(o.reduce(((e,r,o)=>{const s=t(e,r);return s!==e?(n=o,s):e}),e),n>-1)return r[n]},o=r(((t,e)=>{const{depth:r}=e;return!t||r>t?r:t}));var n=Object.freeze({__proto__:null,setup:t=>{let e=0;if(t.vm){let{vm:r}=t;do{r.parent&&(e++,r=r.parent)}while(r&&r.parent&&r!==r.root)}t.depth=e},resolve:o});const s={body:{tag:"script",to:"body"},base:{valueAttribute:"href"},charset:{tag:"meta",nameless:!0,valueAttribute:"charset"},description:{tag:"meta"},og:{group:!0,namespacedAttribute:!0,tag:"meta",keyAttribute:"property"},twitter:{group:!0,namespacedAttribute:!0,tag:"meta"},htmlAttrs:{attributesFor:"html"},headAttrs:{attributesFor:"head"},bodyAttrs:{attributesFor:"body"}},i={title:{attributes:!1},base:{contentAsAttribute:!0,attributes:["href","target"]},meta:{contentAsAttribute:!0,keyAttribute:"name",attributes:["content","name","http-equiv","charset"]},link:{contentAsAttribute:!0,attributes:["href","crossorigin","rel","media","integrity","hreflang","type","referrerpolicy","sizes","imagesrcset","imagesizes","as","color"]},style:{attributes:["media"]},script:{attributes:["src","type","nomodule","async","defer","crossorigin","integrity","referrerpolicy"]},noscript:{attributes:!1}};Object.freeze({}),Object.freeze([]);const c=Array.isArray,a=t=>"function"==typeof t,u=t=>"string"==typeof t,l=t=>null!==t&&"object"==typeof t,f=Object.prototype.toString,d=t=>"[object Object]"===f.call(t),p=Symbol("kIsProxy"),m=Symbol("kProxySources"),h=Symbol("kProxyTarget"),b=Symbol("kResolveContext");function g(t){if(c(t))return t.map(g);if(l(t)){const e={};for(const r in t)e[r]="context"===r?t[r]:g(t[r]);return e}return t}const v=(t,e,r)=>{const o=[];for(const n of t)n&&e in n&&(o.push(n[e]),r&&r(n));return o},y=(t,e=[],r,o)=>{if(!r&&!o&&(({active:r,sources:o}=t),e.length))for(let t=0;tt[n])).filter(Boolean)}if(!r||!o)return;const n=((t,...e)=>{const r=t?Object.keys(t):[];if(e)for(const t of e)if(t&&l(t))for(const e in t)r.includes(e)||r.push(e);return r})(...o),s=Object.keys(r);for(const t of s)n.includes(t)||delete r[t];for(const s of n){let n=!1;for(let t=0;ti.push(t[b])));let u=t.resolve(a,i,r[s],s,e);d(u)&&(u=g(u)),r[s]=u}},S=(t,r,o,n=[])=>{const s=A(t,o,n),i=e.markRaw(new Proxy(r,s));return!n.length&&t.sources&&t.sources.push(i),i},A=(t,e,r=[])=>({get:(o,n,s)=>{if(n===p)return!0;if(n===m)return t.sources;if(n===h)return o;if(n===b)return e;let i=Reflect.get(o,n,s);if(!l(i))return i;if(!i[p]){const s=[...r,n];i=S(t,i,e,s),Reflect.set(o,n,i)}return i},set:(e,o,n)=>{const s=Reflect.set(e,o,n);if(s){const i=c(e);let a,u=!1,{sources:l,active:f}=t,p=0;for(const t of r){if(l=v(l,t),i&&p===r.length-1){a=t;break}c(f)&&(u=!0),f=f[t],p++}if(u)return y(t),s;if(d(n))return y(t,r),s;let m,h=[];i?(m=l,h=l.map((t=>t[b]))):m=v(l,o,(t=>h.push(t[b])));let S=t.resolve(m,h,f,o,r);d(S)&&(S=g(S)),i&&a?f[a]=S:f[o]=S}return s},deleteProperty:(e,o)=>{const n=Reflect.deleteProperty(e,o);if(n){const n=c(e);let s,i=t.sources,a=t.active,u=0;for(const t of r){if(i=i.map((e=>e&&e[t])),n&&u===r.length-1){s=t;break}a=a[t],u++}if(i.some((t=>t&&o in t))){let e,c=[];n?(e=i,c=i.map((t=>t[b]))):e=v(i,o,(t=>c.push(t[b])));let u=t.resolve(e,c,a,o,r);d(u)&&(u=g(u)),n&&s?a[s]=u:a[o]=u}else delete a[o]}return n}}),k={};function j(t,r,o,n){return"attributesFor"in n?function(t,r,o,n){const{attributesFor:s}=n;if(!s||!o)return;if(t.isSSR)return{to:"",vnode:e.h(`ssr-${s}`,o)};if(!k[s]){const[t,e]=Array.from(document.querySelectorAll(s));if(!t)return void console.error("Could not find element for selector",s,", won't render attributes");e&&console.warn("Found multiple elements for selector",s),k[s]={el:t,attrs:[]}}const{el:i,attrs:a}=k[s];for(const e in o){let n=C(t,`${r}(${e})`,o[e],o);c(n)&&(n=n.join(",")),i.setAttribute(e,n||""),a.includes(e)||a.push(e)}const u=a.filter((t=>!o[t]));for(const t of u)i.removeAttribute(t)}(t,r,o,n):"group"in n?function(t,e,r,o){if(c(r))return console.warn("Specifying an array for group properties isnt supported"),[];return Object.keys(r).map((n=>{const s={group:e,data:r};if(o.namespaced)s.tagNamespace=!0===o.namespaced?e:o.namespaced;else if(o.namespacedAttribute){const t=!0===o.namespacedAttribute?e:o.namespacedAttribute;s.fullName=`${t}:${n}`,s.slotName=`${t}(${n})`}return w(t,e,r[n],o,s)})).filter(Boolean).flat()}(t,r,o,n):w(t,r,o,n)}function w(t,r,o,n={},s){const a=["content","json","rawContent"],l=t=>function(t,e){for(const r of t){const t=i[r];if(r&&t)return t[e]}}([f,n.tag],t);if(c(o))return o.map((e=>w(t,r,e,n,s))).filter(Boolean).flat();const{tag:f=n.tag||r}=o;let d="",p=!1,m=!1;if(u(o))d=o;else if(o.children&&c(o.children))p=!0,d=o.children.map((e=>{const o=w(t,r,e,n,s);return c(o)?o.map((({vnode:t})=>t)):o&&o.vnode}));else{let t=0;for(const e of a){if(!d&&o[e]){d=1===t?JSON.stringify(o[e]):o[e],m=t>1;break}t++}}const h=s&&s.fullName||r,b=s&&s.slotName||r;let{attrs:g}=o;if(g||"object"!=typeof o)g||(g={});else{g={...o},delete g.tag,delete g.children,delete g.to;for(const t of a)delete g[t]}if(p)d=C(t,b,d,o);else{const e=!!l("contentAsAttribute");let{valueAttribute:r}=n;if(!r&&e){const[t]=l("attributes");r=u(e)?e:t}if(r){const{nameless:e}=n;if(!e){const t=n.keyAttribute||l("keyAttribute");t&&(g[t]=h)}g[r]=C(t,b,g[r]||d,s),d=""}else d=C(t,b,d,o)}const v=s&&s.tagNamespace?`${s.tagNamespace}:${f}`:f;if("title"===v&&!t.isSSR)return void(document.title=d);m&&d&&(g.innerHTML=d);const y=e.h(v,g,d||void 0);return{to:o.to,vnode:y}}function C({metainfo:t,slots:e},r,o,n){const s=e&&e[r];if(!s||!a(s))return o;const i={content:o,metainfo:t};if(n&&n.group){const{group:t,data:e}=n;i[t]=e}const c=s(i);if(c&&c.length){const{children:t}=c[0];return t?t.toString():""}return o}const M="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag,R=(t=>M?Symbol("[vue-meta]: "+t):"[vue-meta]: "+t)("meta_active");function O(t,e,r){for(const o in e)o in r?l(t[o])?O(t[o],e[o],r[o]):e[o]!==r[o]&&(t[o]=e[o]):t[o]=e[o];for(const o in r)e&&o in e||delete t[o]}function x(t){if(t||(t=e.getCurrentInstance()||void 0),t)return t.appContext.config.globalProperties.$metaManager}const N=e.defineComponent({name:"Metainfo",inheritAttrs:!1,setup:(t,{slots:e})=>()=>{const t=x();if(t)return t.render({slots:e})}}),$="data-vm-ssr";function P(t,r,o,n){const s=c(n)?n:[n];t?o.endsWith("Attrs")||s.forEach((t=>{t.props||(t.props={}),t.props[$]=!0})):s.forEach(((t,r)=>{t.type===e.Comment&&s.splice(r,1)})),r[o]||(r[o]=[]),r[o].push(...s)}class F{constructor(t,e,r,o){this.isSSR=!1,this.ssrCleanedUp=!1,this.isSSR=t,this.config=e,this.target=r,o&&"setup"in o&&a(o.setup)&&(this.resolver=o)}install(t){t.component("Metainfo",N),t.config.globalProperties.$metaManager=this,t.provide(R,this.target.context.active)}addMeta(t,r){r||(r=e.getCurrentInstance()||void 0);const o={removed:[]},n={vm:r},{resolver:s}=this;s&&s.setup&&s.setup(n);const i=this.target.addSource(t,n,!0),c=t=>this.unmount(!!t,i,o,r);return r&&e.onUnmounted(c),{meta:i,onRemoved:t=>o.removed.push(t),unmount:c}}unmount(t,e,r,o){if(o){const{$el:n}=o.proxy;if(n&&n.offsetParent){let o=new MutationObserver((s=>{for(const{removedNodes:i}of s)i&&i.forEach((s=>{s===n&&o&&(o.disconnect(),o=void 0,this.reallyUnmount(t,e,r))}))}));return void o.observe(n.parentNode,{childList:!0})}}this.reallyUnmount(t,e,r)}async reallyUnmount(t,e,r){this.target.delSource(e),!t&&r&&await Promise.all(r.removed.map((t=>t())))}render({slots:t}={}){const r=this.target.context.active,{isSSR:o}=this;if(!o&&!this.ssrCleanedUp){this.ssrCleanedUp=!0;const t=()=>{const t=document.querySelectorAll("[data-vm-ssr]");t&&t.length&&t.forEach((t=>t.parentNode&&t.parentNode.removeChild(t)))};"loading"===document.readyState?window.addEventListener("DOMContentLoaded",t,{once:!0}):t()}const n={};for(const e in r){const s=this.config[e]||{};let i=j({isSSR:o,metainfo:r,slots:t},e,r[e],s);if(!i)continue;c(i)||(i=[i]);let a="base"!==e&&r[e].to;!a&&"to"in s&&(a=s.to),!a&&"attributesFor"in s&&(a=e);for(const{to:t,vnode:e}of i)P(this.isSSR,n,t||a||"head",e)}if(t)for(const e in t){const o="default"===e?"head":e;if("head"!==o&&"body"!==o)continue;const s=t[e];a(s)&&P(this.isSSR,n,o,s({metainfo:r}))}return Object.keys(n).map((t=>e.h(e.Teleport,{to:t},n[t])))}}return F.create=(t,r,o)=>{const n=((t,e)=>{const r=[],o={active:e,resolve:t,sources:r},n=()=>y(o);return{context:o,compute:n,addSource:(t,e,r=!1)=>{const s=S(o,t,e||{});return r&&n(),s},delSource:(t,e=!0)=>{const o=r.findIndex((e=>e===t||e[h]===t));return o>-1&&(r.splice(o,1),e&&n(),!0)}}})(((t,e,r,n,s)=>a(o)?o(t,e,r,n,s):o.resolve(t,e,r,n,s)),e.reactive({}));return new F(t,r,n,o)},t.createMetaManager=(t=!1,e,r)=>F.create(t,e||s,r||n),t.deepestResolver=n,t.defaultConfig=s,t.getCurrentManager=x,t.resolveOption=r,t.useActiveMeta=function(){return e.inject(R)},t.useMeta=function(t,r){const o=e.getCurrentInstance()||void 0;if(!r&&o&&(r=x(o)),!r)throw new Error("No manager or current instance");e.isProxy(t)&&(e.watch(t,((t,e)=>{O(n.meta,t,e)})),t=t.value);const n=r.addMeta(t,o);return n},Object.defineProperty(t,"__esModule",{value:!0}),t}({},Vue); diff --git a/package.json b/package.json index 88a33fc..9d5f821 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-meta", - "version": "3.0.0-alpha.6", + "version": "3.0.0-alpha.7", "description": "Manage HTML metadata in Vue.js components with SSR support", "main": "dist/vue-meta.cjs.js", "browser": "dist/vue-meta.esm-browser.min.js",