diff --git a/CHANGELOG.md b/CHANGELOG.md index eaa31327..c1604259 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ 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. +### [2.3.3](https://github.com/nuxt/vue-meta/compare/v2.3.2...v2.3.3) (2020-02-26) + + +### Bug Fixes + +* memory leak, use hook events (thanks [#522](https://github.com/nuxt/vue-meta/issues/522)) ([21621e1](https://github.com/nuxt/vue-meta/commit/21621e13f53f45eeef5d75c76ed01c7703ad78b9)) +* support once (with skip) client side (fix [#498](https://github.com/nuxt/vue-meta/issues/498)) ([c74c645](https://github.com/nuxt/vue-meta/commit/c74c645d1881e22569a2ea7ac0c903a4f6ee2243)) + ### [2.3.2](https://github.com/nuxt/vue-meta/compare/v2.3.1...v2.3.2) (2020-01-12) diff --git a/dist/vue-meta.common.js b/dist/vue-meta.common.js index 6c56dafb..148b34a6 100644 --- a/dist/vue-meta.common.js +++ b/dist/vue-meta.common.js @@ -1,5 +1,5 @@ /** - * vue-meta v2.3.2 + * vue-meta v2.3.3 * (c) 2020 * - Declan de Wet * - Sébastien Chopin (@Atinux) @@ -14,9 +14,11 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau var deepmerge = _interopDefault(require('deepmerge')); -var version = "2.3.2"; +var version = "2.3.3"; function _typeof(obj) { + "@babel/helpers - typeof"; + if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function (obj) { return typeof obj; @@ -220,7 +222,7 @@ var tagsWithoutEndTag = ['base', 'meta', 'link']; // HTML elements which can hav var tagsWithInnerContent = ['noscript', 'script', 'style']; // Attributes which are inserted as childNodes instead of HTMLAttribute var tagAttributeAsInnerContent = ['innerHTML', 'cssText', 'json']; -var tagProperties = ['once', 'template']; // Attributes which should be added with data- prefix +var tagProperties = ['once', 'skip', 'template']; // Attributes which should be added with data- prefix var commonDataAttributes = ['body', 'pbody']; // from: https://github.com/kangax/html-minifier/blob/gh-pages/src/htmlminifier.js#L202 @@ -325,22 +327,6 @@ function includes(array, value) { return array.includes(value); } -function ensureIsArray(arg, key) { - if (!key || !isObject(arg)) { - return isArray(arg) ? arg : []; - } - - if (!isArray(arg[key])) { - arg[key] = []; - } - - return arg; -} -function ensuredPush(object, key, el) { - ensureIsArray(object, key); - object[key].push(el); -} - function hasMetaInfo(vm) { vm = vm || this; return vm && (vm[rootConfigKey] === true || isObject(vm[rootConfigKey])); @@ -397,6 +383,8 @@ function createMixin(Vue, options) { return { beforeCreate: function beforeCreate() { + var _this2 = this; + var rootKey = '$root'; var $root = this[rootKey]; var $options = this.$options; @@ -466,7 +454,7 @@ function createMixin(Vue, options) { // if computed $metaInfo exists, watch it for updates & trigger a refresh // when it changes (i.e. automatically handle async actions that affect metaInfo) // credit for this suggestion goes to [Sébastien Chopin](https://github.com/Atinux) - ensuredPush($options, 'created', function () { + this.$on('hook:created', function () { this.$watch('$metaInfo', function () { triggerUpdate(options, this[rootKey], 'watcher'); }); @@ -484,7 +472,7 @@ function createMixin(Vue, options) { if (!$root[rootConfigKey].initialized) { if (!$root[rootConfigKey].initializedSsr) { $root[rootConfigKey].initializedSsr = true; - ensuredPush($options, 'beforeMount', function () { + this.$on('hook:beforeMount', function () { var $root = this; // if this Vue-app was server rendered, set the appId to 'ssr' // only one SSR app per page is supported @@ -495,7 +483,7 @@ function createMixin(Vue, options) { } // we use the mounted hook here as on page load - ensuredPush($options, 'mounted', function () { + this.$on('hook:mounted', function () { var $root = this[rootKey]; if (!$root[rootConfigKey].initialized) { @@ -535,8 +523,38 @@ function createMixin(Vue, options) { addNavGuards($root); } } - } // do not trigger refresh on the server side + } + + this.$on('hook:destroyed', function () { + var _this = this; + + // do not trigger refresh: + // - when user configured to not wait for transitions on destroyed + // - when the component doesnt have a parent + // - doesnt have metaInfo defined + if (!this.$parent || !hasMetaInfo(this)) { + return; + } + delete this._hasMetaInfo; + this.$nextTick(function () { + if (!options.waitOnDestroyed || !_this.$el || !_this.$el.offsetParent) { + triggerUpdate(options, _this.$root, 'destroyed'); + return; + } // Wait that element is hidden before refreshing meta tags (to support animations) + + + var interval = setInterval(function () { + if (_this.$el && _this.$el.offsetParent !== null) { + /* istanbul ignore next line */ + return; + } + + clearInterval(interval); + triggerUpdate(options, _this.$root, 'destroyed'); + }, 50); + }); + }); // do not trigger refresh on the server side if (this.$isServer) { /* istanbul ignore next */ @@ -545,41 +563,10 @@ function createMixin(Vue, options) { updateOnLifecycleHook.forEach(function (lifecycleHook) { - ensuredPush($options, lifecycleHook, function () { + _this2.$on("hook:".concat(lifecycleHook), function () { triggerUpdate(options, this[rootKey], lifecycleHook); }); }); - }, - // TODO: move back into beforeCreate when Vue issue is resolved - destroyed: function destroyed() { - var _this = this; - - // do not trigger refresh: - // - when user configured to not wait for transitions on destroyed - // - when the component doesnt have a parent - // - doesnt have metaInfo defined - if (!this.$parent || !hasMetaInfo(this)) { - return; - } - - delete this._hasMetaInfo; - this.$nextTick(function () { - if (!options.waitOnDestroyed || !_this.$el || !_this.$el.offsetParent) { - triggerUpdate(options, _this.$root, 'destroyed'); - return; - } // Wait that element is hidden before refreshing meta tags (to support animations) - - - var interval = setInterval(function () { - if (_this.$el && _this.$el.offsetParent !== null) { - /* istanbul ignore next line */ - return; - } - - clearInterval(interval); - triggerUpdate(options, _this.$root, 'destroyed'); - }, 50); - }); } }; } @@ -617,6 +604,18 @@ function getOptions(options) { return optionsCopy; } +function ensureIsArray(arg, key) { + if (!key || !isObject(arg)) { + return isArray(arg) ? arg : []; + } + + if (!isArray(arg[key])) { + arg[key] = []; + } + + return arg; +} + var serverSequences = [[/&/g, '&'], [//g, '>'], [/"/g, '"'], [/'/g, ''']]; var clientSequences = [[/&/g, "&"], [//g, ">"], [/"/g, "\""], [/'/g, "'"]]; // sanitizes potentially dangerous characters @@ -1196,7 +1195,11 @@ function updateTag(appId, options, type, tags, head, body) { } var newElement = document.createElement(type); - newElement.setAttribute(attribute, appId); + + if (!tag.once) { + newElement.setAttribute(attribute, appId); + } + Object.keys(tag).forEach(function (attr) { /* istanbul ignore next */ if (includes(tagProperties, attr)) { diff --git a/dist/vue-meta.esm.browser.js b/dist/vue-meta.esm.browser.js index b6c04aec..59e1acb5 100644 --- a/dist/vue-meta.esm.browser.js +++ b/dist/vue-meta.esm.browser.js @@ -1,5 +1,5 @@ /** - * vue-meta v2.3.2 + * vue-meta v2.3.3 * (c) 2020 * - Declan de Wet * - Sébastien Chopin (@Atinux) @@ -10,9 +10,11 @@ import deepmerge from 'deepmerge'; -var version = "2.3.2"; +var version = "2.3.3"; function _typeof(obj) { + "@babel/helpers - typeof"; + if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function (obj) { return typeof obj; @@ -143,7 +145,7 @@ var metaInfoOptionKeys = [defaultInfoKeys[1], defaultInfoKeys[2], 'changed'].con var metaInfoAttributeKeys = [defaultInfoKeys[3], defaultInfoKeys[4], defaultInfoKeys[5]]; // HTML elements which support the onload event var tagsSupportingOnload = ['link', 'style', 'script']; // HTML elements which dont have a head tag (shortened to our needs) -var tagProperties = ['once', 'template']; // Attributes which should be added with data- prefix +var tagProperties = ['once', 'skip', 'template']; // Attributes which should be added with data- prefix var commonDataAttributes = ['body', 'pbody']; // from: https://github.com/kangax/html-minifier/blob/gh-pages/src/htmlminifier.js#L202 @@ -248,22 +250,6 @@ function includes(array, value) { return array.includes(value); } -function ensureIsArray(arg, key) { - if (!key || !isObject(arg)) { - return isArray(arg) ? arg : []; - } - - if (!isArray(arg[key])) { - arg[key] = []; - } - - return arg; -} -function ensuredPush(object, key, el) { - ensureIsArray(object, key); - object[key].push(el); -} - function hasMetaInfo(vm) { vm = vm || this; return vm && (vm[rootConfigKey] === true || isObject(vm[rootConfigKey])); @@ -320,6 +306,8 @@ function createMixin(Vue, options) { return { beforeCreate: function beforeCreate() { + var _this2 = this; + var rootKey = '$root'; var $root = this[rootKey]; var $options = this.$options; @@ -389,7 +377,7 @@ function createMixin(Vue, options) { // if computed $metaInfo exists, watch it for updates & trigger a refresh // when it changes (i.e. automatically handle async actions that affect metaInfo) // credit for this suggestion goes to [Sébastien Chopin](https://github.com/Atinux) - ensuredPush($options, 'created', function () { + this.$on('hook:created', function () { this.$watch('$metaInfo', function () { triggerUpdate(options, this[rootKey], 'watcher'); }); @@ -407,7 +395,7 @@ function createMixin(Vue, options) { if (!$root[rootConfigKey].initialized) { if (!$root[rootConfigKey].initializedSsr) { $root[rootConfigKey].initializedSsr = true; - ensuredPush($options, 'beforeMount', function () { + this.$on('hook:beforeMount', function () { var $root = this; // if this Vue-app was server rendered, set the appId to 'ssr' // only one SSR app per page is supported @@ -418,7 +406,7 @@ function createMixin(Vue, options) { } // we use the mounted hook here as on page load - ensuredPush($options, 'mounted', function () { + this.$on('hook:mounted', function () { var $root = this[rootKey]; if (!$root[rootConfigKey].initialized) { @@ -458,8 +446,38 @@ function createMixin(Vue, options) { addNavGuards($root); } } - } // do not trigger refresh on the server side + } + + this.$on('hook:destroyed', function () { + var _this = this; + + // do not trigger refresh: + // - when user configured to not wait for transitions on destroyed + // - when the component doesnt have a parent + // - doesnt have metaInfo defined + if (!this.$parent || !hasMetaInfo(this)) { + return; + } + delete this._hasMetaInfo; + this.$nextTick(function () { + if (!options.waitOnDestroyed || !_this.$el || !_this.$el.offsetParent) { + triggerUpdate(options, _this.$root, 'destroyed'); + return; + } // Wait that element is hidden before refreshing meta tags (to support animations) + + + var interval = setInterval(function () { + if (_this.$el && _this.$el.offsetParent !== null) { + /* istanbul ignore next line */ + return; + } + + clearInterval(interval); + triggerUpdate(options, _this.$root, 'destroyed'); + }, 50); + }); + }); // do not trigger refresh on the server side if (this.$isServer) { /* istanbul ignore next */ @@ -468,41 +486,10 @@ function createMixin(Vue, options) { updateOnLifecycleHook.forEach(function (lifecycleHook) { - ensuredPush($options, lifecycleHook, function () { + _this2.$on("hook:".concat(lifecycleHook), function () { triggerUpdate(options, this[rootKey], lifecycleHook); }); }); - }, - // TODO: move back into beforeCreate when Vue issue is resolved - destroyed: function destroyed() { - var _this = this; - - // do not trigger refresh: - // - when user configured to not wait for transitions on destroyed - // - when the component doesnt have a parent - // - doesnt have metaInfo defined - if (!this.$parent || !hasMetaInfo(this)) { - return; - } - - delete this._hasMetaInfo; - this.$nextTick(function () { - if (!options.waitOnDestroyed || !_this.$el || !_this.$el.offsetParent) { - triggerUpdate(options, _this.$root, 'destroyed'); - return; - } // Wait that element is hidden before refreshing meta tags (to support animations) - - - var interval = setInterval(function () { - if (_this.$el && _this.$el.offsetParent !== null) { - /* istanbul ignore next line */ - return; - } - - clearInterval(interval); - triggerUpdate(options, _this.$root, 'destroyed'); - }, 50); - }); } }; } @@ -540,6 +527,18 @@ function getOptions(options) { return optionsCopy; } +function ensureIsArray(arg, key) { + if (!key || !isObject(arg)) { + return isArray(arg) ? arg : []; + } + + if (!isArray(arg[key])) { + arg[key] = []; + } + + return arg; +} + var clientSequences = [[/&/g, "&"], [//g, ">"], [/"/g, "\""], [/'/g, "'"]]; // sanitizes potentially dangerous characters function escape(info, options, escapeOptions, escapeKeys) { @@ -1118,7 +1117,11 @@ function updateTag(appId, options, type, tags, head, body) { } var newElement = document.createElement(type); - newElement.setAttribute(attribute, appId); + + if (!tag.once) { + newElement.setAttribute(attribute, appId); + } + Object.keys(tag).forEach(function (attr) { /* istanbul ignore next */ if (includes(tagProperties, attr)) { diff --git a/dist/vue-meta.esm.browser.min.js b/dist/vue-meta.esm.browser.min.js index d7212ba0..f5690e33 100644 --- a/dist/vue-meta.esm.browser.min.js +++ b/dist/vue-meta.esm.browser.min.js @@ -1,5 +1,5 @@ /** - * vue-meta v2.3.2 + * vue-meta v2.3.3 * (c) 2020 * - Declan de Wet * - Sébastien Chopin (@Atinux) @@ -7,4 +7,4 @@ * - All the amazing contributors * @license MIT */ -import n from"deepmerge";function e(n){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(n)}function t(n){return Array.isArray(n)}function r(n){return void 0===n}function i(n){return"object"===e(n)}function o(n){return"object"===e(n)&&null!==n}function a(n){return"function"==typeof n}var u=(function(){try{return!r(window)}catch(n){return!1}}()?window:global).console||{};function f(n){u&&u.warn&&u.warn(n)}var c=function(n){return f("".concat(n," is not supported in browser builds"))},s={title:void 0,titleChunk:"",titleTemplate:"%s",htmlAttrs:{},bodyAttrs:{},headAttrs:{},base:[],link:[],meta:[],style:[],script:[],noscript:[],__dangerouslyDisableSanitizers:[],__dangerouslyDisableSanitizersByTagID:{}},d="metaInfo",l="data-vue-meta",v="data-vue-meta-server-rendered",m="vmid",p="content",y="template",h=!0,b=10,g="ssr",I=Object.keys(s),A=[I[12],I[13]],N=[I[1],I[2],"changed"].concat(A),T=[I[3],I[4],I[5]],w=["link","style","script"],O=["once","template"],M=["body","pbody"],S=["allowfullscreen","amp","async","autofocus","autoplay","checked","compact","controls","declare","default","defaultchecked","defaultmuted","defaultselected","defer","disabled","enabled","formnovalidate","hidden","indeterminate","inert","ismap","itemscope","loop","multiple","muted","nohref","noresize","noshade","novalidate","nowrap","open","pauseonexit","readonly","required","reversed","scoped","seamless","selected","sortable","truespeed","typemustmatch","visible"],j=null;function K(n,e,t){var r=n.t;e._vueMeta.i||!e._vueMeta.o&&"watcher"!==t||(e._vueMeta.i=null),e._vueMeta.i&&!e._vueMeta.u&&function(n,e){if(!(e=void 0===e?10:e))return void n();clearTimeout(j),j=setTimeout((function(){n()}),e)}((function(){e.$meta().refresh()}),r)}function _(n,e,t){if(!Array.prototype.findIndex){for(var r=0;r/g,">"],[/"/g,'"'],[/'/g,"'"]];function P(n,e,r){r=r||[];var i={A:function(n){return r.reduce((function(n,e){return n.replace(e[0],e[1])}),n)}};return A.forEach((function(n,t){if(0===t)x(e,n);else if(1===t)for(var r in e[n])x(e[n],r);i[n]=e[n]})),function n(e,r,i,a){var u=r.j,f=i.A,c=void 0===f?function(n){return n}:f,s={};for(var d in e){var l=e[d];if(k(N,d))s[d]=l;else{var v=A[0];if(i[v]&&k(i[v],d))s[d]=l;else{var m=e[u];if(m&&(v=A[1],i[v]&&i[v][m]&&k(i[v][m],d)))s[d]=l;else if("string"==typeof l?s[d]=c(l):t(l)?s[d]=l.map((function(e){return o(e)?n(e,r,i,!0):c(e)})):o(l)?s[d]=n(l,r,i,!0):s[d]=l,a){var p=c(d);d!==p&&(s[p]=s[d],delete s[d])}}}}return s}(e,n,i)}function R(n,e,t,i){var o=n.component,u=n.N,f=n.T;return!0!==t&&!0!==e[u]&&(r(t)&&e[u]&&(t=e[u],e[u]=!0),t?(r(i)&&(i=e[f]),e[f]=a(t)?t.call(o,i):t.replace(/%s/g,i),!0):(delete e[u],!1))}var $=!1;function q(e,t,r){return r=r||{},void 0===t.title&&delete t.title,T.forEach((function(n){if(t[n])for(var e in t[n])e in t[n]&&void 0===t[n][e]&&(k(S,e)&&!$&&(f("VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details"),$=!0),delete t[n][e])})),n(e,t,{O:function(n,e){return function(n,e,t){var r=n.component,i=n.j,o=n.N,a=n.T,u=[];return e.length||t.length?(e.forEach((function(n,e){if(n[i]){var f=_(t,(function(e){return e[i]===n[i]})),c=t[f];if(-1!==f){if(a in c&&void 0===c[a]||"innerHTML"in c&&void 0===c.innerHTML)return u.push(n),void t.splice(f,1);if(null!==c[a]&&null!==c.innerHTML){var s=n[o];if(s){if(!c[o])return R({component:r,N:o,T:a},c,s),void(c.template=!0);c[a]||R({component:r,N:o,T:a},c,void 0,n[a])}}else t.splice(f,1)}else u.push(n)}else u.push(n)})),u.concat(t)):u}(r,n,e)}})}function E(n,e){return function n(e,t,o){if(o=o||{},t._inactive)return o;var a=(e=e||{}).v,u=t.$metaInfo,f=t.$options,c=t.$children;if(f[a]){var s=u||f[a];i(s)&&(o=q(o,s,e))}c.length&&c.forEach((function(t){(function(n){return(n=n||this)&&!r(n._vueMeta)})(t)&&(o=n(e,t,o))}));return o}(n||{},e,s)}var U=function(n,e){return(e||document).querySelectorAll(n)};function F(n,e){return n[e]||(n[e]=document.getElementsByTagName(e)[0]),n[e]}function G(n,e,t){var r=e.m,i=e.M,o=e.type,a=e.j;t=t||{};var u=["".concat(o,"[").concat(i,'="').concat(r,'"]'),"".concat(o,"[data-").concat(a,"]")].map((function(n){for(var e in t){var r=t[e],i=r&&!0!==r?'="'.concat(r,'"'):"";n+="[data-".concat(e).concat(i,"]")}return n}));return D(U(u.join(", "),n))}function Q(n,e){n.removeAttribute(e)}var X=[];function Y(n,e,t,r){var i=n.j,o=!1;return t.forEach((function(n){n[i]&&n.callback&&(o=!0,function(n,e){1===arguments.length&&(e=n,n=""),X.push([n,e])}("".concat(e,"[data-").concat(i,'="').concat(n[i],'"]'),n.callback))})),r&&o?Z():o}function Z(){var n;"complete"!==(n||document).readyState?document.onreadystatechange=function(){nn()}:nn()}function nn(n){X.forEach((function(e){var t=e[0],r=e[1],i="".concat(t,'[onload="this.__vm_l=1"]'),o=[];n||(o=D(U(i))),n&&n.matches(i)&&(o=[n]),o.forEach((function(n){if(!n.__vm_cb){var e=function(){n.__vm_cb=!0,Q(n,"onload"),r(n)};n.__vm_l?e():n.__vm_ev||(n.__vm_ev=!0,n.addEventListener("load",e))}}))}))}var en,tn={};function rn(n,e,t,r,i){var o=(e||{}).M,a=i.getAttribute(o);a&&(tn[t]=JSON.parse(decodeURI(a)),Q(i,o));var u=tn[t]||{},f=[];for(var c in u)u[c]&&n in u[c]&&(f.push(c),r[c]||delete u[c][n]);for(var s in r){var d=u[s];d&&d[n]===r[s]||(f.push(s),r[s]&&(u[s]=u[s]||{},u[s][n]=r[s]))}for(var l=0,v=f;l1){var v=[];r=r.filter((function(n){var e=JSON.stringify(n),t=!k(v,e);return v.push(e),t}))}r.forEach((function(e){if(!e.skip){var r=document.createElement(t);r.setAttribute(u,n),Object.keys(e).forEach((function(n){if(!k(O,n))if("innerHTML"!==n)if("json"!==n)if("cssText"!==n)if("callback"!==n){var t=k(c,n)?"data-".concat(n):n,i=k(S,n);if(!i||e[n]){var o=i?"":e[n];r.setAttribute(t,o)}}else r.onload=function(){return e[n](r)};else r.styleSheet?r.styleSheet.cssText=e.cssText:r.appendChild(document.createTextNode(e.cssText));else r.innerHTML=JSON.stringify(e.json);else r.innerHTML=e.innerHTML}));var i,o=l[function(n){var e=n.body,t=n.pbody;return e?"body":t?"pbody":"head"}(e)];o.some((function(n,e){return i=e,r.isEqualNode(n)}))&&(i||0===i)?o.splice(i,1):s.push(r)}}));var m=[];for(var p in l)Array.prototype.push.apply(m,l[p]);return m.forEach((function(n){n.parentNode.removeChild(n)})),s.forEach((function(n){n.hasAttribute("data-body")?o.appendChild(n):n.hasAttribute("data-pbody")?o.insertBefore(n,o.firstChild):i.appendChild(n)})),{oldTags:m,newTags:s}}function an(n,e,r){var i=e=e||{},o=i.S,a=i.p,u={},f=F(u,"html");if(n===a&&f.hasAttribute(o)){Q(f,o);var c=!1;return w.forEach((function(n){r[n]&&Y(e,n,r[n])&&(c=!0)})),c&&Z(),!1}var s,d={},l={};for(var v in r)if(!k(N,v))if("title"!==v){if(k(T,v)){var m=v.substr(0,4);rn(n,e,v,r[v],F(u,m))}else if(t(r[v])){var p=on(n,e,v,r[v],F(u,"head"),F(u,"body")),y=p.oldTags,h=p.newTags;h.length&&(d[v]=h,l[v]=y)}}else((s=r.title)||""===s)&&(document.title=s);return{D:d,K:l}}function un(n,e,t){return{set:function(r){return function(n,e,t,r){if(n&&n.$el)return an(e,t,r);(en=en||{})[e]=r}(n,e,t,r)},remove:function(){return function(n,e,t){if(n&&n.$el){var r={},i=!0,o=!1,a=void 0;try{for(var u,f=T[Symbol.iterator]();!(i=(u=f.next()).done);i=!0){var c=u.value,s=c.substr(0,4);rn(e,t,c,{},F(r,s))}}catch(n){o=!0,a=n}finally{try{i||null==f.return||f.return()}finally{if(o)throw a}}return function(n,e){var t=n.M;D(U("[".concat(t,'="').concat(e,'"]'))).map((function(n){return n.remove()}))}(t,e)}en[e]&&(delete en[e],cn())}(n,e,t)}}}function fn(){return en}function cn(n){!n&&Object.keys(en).length||(en=void 0)}function sn(n,e){if(e=e||{},!n._vueMeta)return f("This vue app/component has no vue-meta configuration"),{};var t=function(n,e,t,r){t=t||[];var i=(n=n||{}).j;return e.title&&(e.titleChunk=e.title),e.titleTemplate&&"%s"!==e.titleTemplate&&R({component:r,T:"title"},e,e.titleTemplate,e.titleChunk||""),e.base&&(e.base=Object.keys(e.base).length?[e.base]:[]),e.meta&&(e.meta=e.meta.filter((function(n,e,t){return!n[i]||e===_(t,(function(e){return e[i]===n[i]}))})),e.meta.forEach((function(e){return R(n,e)}))),P(n,e,t)}(e,E(e,n),L,n),r=an(n._vueMeta.m,e,t);r&&a(t.changed)&&(t.changed(t,r.D,r.K),r={addedTags:r.D,removedTags:r.K});var i=fn();if(i){for(var o in i)an(o,e,i[o]),delete i[o];cn(!0)}return{vm:n,metaInfo:t,tags:r}}function dn(n){n=n||{};var e=this.$root;return{getOptions:function(){return function(n){var e={};for(var t in n)e[t]=n[t];return e}(n)},setOptions:function(t){t&&t.h&&(n.h=!!t.h,W(e));if(t&&"debounceWait"in t){var r=parseInt(t.t);isNaN(r)||(n.t=r)}t&&"waitOnDestroyed"in t&&(n.g=!!t.g)},refresh:function(){return sn(e,n)},inject:function(){return c("inject")},pause:function(){return B(e)},resume:function(){return J(e)},addApp:function(t){return un(e,t,n)}}}var ln={version:"2.3.2",install:function(n,e){n.__vuemeta_installed||(n.__vuemeta_installed=!0,e=function(n){return{v:(n=i(n)?n:{}).keyName||d,M:n.attribute||l,S:n.ssrAttribute||v,j:n.tagIDKeyName||m,T:n.contentKeyName||p,N:n.metaTemplateKeyName||y,t:r(n.debounceWait)?b:n.debounceWait,g:r(n.waitOnDestroyed)?h:n.waitOnDestroyed,p:n.ssrAppId||g,h:!!n.refreshOnceOnNavigation}}(e),n.prototype.$meta=function(){return dn.call(this,e)},n.mixin(H(n,e)))},generate:function(n,e){return c("generate")},hasMetaInfo:z};export default ln; +import n from"deepmerge";function t(n){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(n)}function e(n){return Array.isArray(n)}function r(n){return void 0===n}function i(n){return"object"===t(n)}function o(n){return"object"===t(n)&&null!==n}function a(n){return"function"==typeof n}var u=(function(){try{return!r(window)}catch(n){return!1}}()?window:global).console||{};function f(n){u&&u.warn&&u.warn(n)}var c=function(n){return f("".concat(n," is not supported in browser builds"))},s={title:void 0,titleChunk:"",titleTemplate:"%s",htmlAttrs:{},bodyAttrs:{},headAttrs:{},base:[],link:[],meta:[],style:[],script:[],noscript:[],__dangerouslyDisableSanitizers:[],__dangerouslyDisableSanitizersByTagID:{}},d="metaInfo",l="data-vue-meta",v="data-vue-meta-server-rendered",m="vmid",h="content",p="template",y=!0,b=10,g="ssr",I=Object.keys(s),A=[I[12],I[13]],N=[I[1],I[2],"changed"].concat(A),T=[I[3],I[4],I[5]],w=["link","style","script"],O=["once","skip","template"],k=["body","pbody"],M=["allowfullscreen","amp","async","autofocus","autoplay","checked","compact","controls","declare","default","defaultchecked","defaultmuted","defaultselected","defer","disabled","enabled","formnovalidate","hidden","indeterminate","inert","ismap","itemscope","loop","multiple","muted","nohref","noresize","noshade","novalidate","nowrap","open","pauseonexit","readonly","required","reversed","scoped","seamless","selected","sortable","truespeed","typemustmatch","visible"],S=null;function j(n,t,e){var r=n.t;t._vueMeta.i||!t._vueMeta.o&&"watcher"!==e||(t._vueMeta.i=null),t._vueMeta.i&&!t._vueMeta.u&&function(n,t){if(!(t=void 0===t?10:t))return void n();clearTimeout(S),S=setTimeout((function(){n()}),t)}((function(){t.$meta().refresh()}),r)}function K(n,t,e){if(!Array.prototype.findIndex){for(var r=0;r/g,">"],[/"/g,'"'],[/'/g,"'"]];function L(n,t,r){r=r||[];var i={A:function(n){return r.reduce((function(n,t){return n.replace(t[0],t[1])}),n)}};return A.forEach((function(n,e){if(0===e)C(t,n);else if(1===e)for(var r in t[n])C(t[n],r);i[n]=t[n]})),function n(t,r,i,a){var u=r.j,f=i.A,c=void 0===f?function(n){return n}:f,s={};for(var d in t){var l=t[d];if(D(N,d))s[d]=l;else{var v=A[0];if(i[v]&&D(i[v],d))s[d]=l;else{var m=t[u];if(m&&(v=A[1],i[v]&&i[v][m]&&D(i[v][m],d)))s[d]=l;else if("string"==typeof l?s[d]=c(l):e(l)?s[d]=l.map((function(t){return o(t)?n(t,r,i,!0):c(t)})):o(l)?s[d]=n(l,r,i,!0):s[d]=l,a){var h=c(d);d!==h&&(s[h]=s[d],delete s[d])}}}}return s}(t,n,i)}function P(n,t,e,i){var o=n.component,u=n.N,f=n.T;return!0!==e&&!0!==t[u]&&(r(e)&&t[u]&&(e=t[u],t[u]=!0),e?(r(i)&&(i=t[f]),t[f]=a(e)?e.call(o,i):e.replace(/%s/g,i),!0):(delete t[u],!1))}var R=!1;function $(t,e,r){return r=r||{},void 0===e.title&&delete e.title,T.forEach((function(n){if(e[n])for(var t in e[n])t in e[n]&&void 0===e[n][t]&&(D(M,t)&&!R&&(f("VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details"),R=!0),delete e[n][t])})),n(t,e,{O:function(n,t){return function(n,t,e){var r=n.component,i=n.j,o=n.N,a=n.T,u=[];return t.length||e.length?(t.forEach((function(n,t){if(n[i]){var f=K(e,(function(t){return t[i]===n[i]})),c=e[f];if(-1!==f){if(a in c&&void 0===c[a]||"innerHTML"in c&&void 0===c.innerHTML)return u.push(n),void e.splice(f,1);if(null!==c[a]&&null!==c.innerHTML){var s=n[o];if(s){if(!c[o])return P({component:r,N:o,T:a},c,s),void(c.template=!0);c[a]||P({component:r,N:o,T:a},c,void 0,n[a])}}else e.splice(f,1)}else u.push(n)}else u.push(n)})),u.concat(e)):u}(r,n,t)}})}function q(n,t){return function n(t,e,o){if(o=o||{},e._inactive)return o;var a=(t=t||{}).v,u=e.$metaInfo,f=e.$options,c=e.$children;if(f[a]){var s=u||f[a];i(s)&&(o=$(o,s,t))}c.length&&c.forEach((function(e){(function(n){return(n=n||this)&&!r(n._vueMeta)})(e)&&(o=n(t,e,o))}));return o}(n||{},t,s)}var E=function(n,t){return(t||document).querySelectorAll(n)};function U(n,t){return n[t]||(n[t]=document.getElementsByTagName(t)[0]),n[t]}function F(n,t,e){var r=t.m,i=t.k,o=t.type,a=t.j;e=e||{};var u=["".concat(o,"[").concat(i,'="').concat(r,'"]'),"".concat(o,"[data-").concat(a,"]")].map((function(n){for(var t in e){var r=e[t],i=r&&!0!==r?'="'.concat(r,'"'):"";n+="[data-".concat(t).concat(i,"]")}return n}));return _(E(u.join(", "),n))}function G(n,t){n.removeAttribute(t)}var Q=[];function X(n,t,e,r){var i=n.j,o=!1;return e.forEach((function(n){n[i]&&n.callback&&(o=!0,function(n,t){1===arguments.length&&(t=n,n=""),Q.push([n,t])}("".concat(t,"[data-").concat(i,'="').concat(n[i],'"]'),n.callback))})),r&&o?Y():o}function Y(){var n;"complete"!==(n||document).readyState?document.onreadystatechange=function(){Z()}:Z()}function Z(n){Q.forEach((function(t){var e=t[0],r=t[1],i="".concat(e,'[onload="this.__vm_l=1"]'),o=[];n||(o=_(E(i))),n&&n.matches(i)&&(o=[n]),o.forEach((function(n){if(!n.__vm_cb){var t=function(){n.__vm_cb=!0,G(n,"onload"),r(n)};n.__vm_l?t():n.__vm_ev||(n.__vm_ev=!0,n.addEventListener("load",t))}}))}))}var nn,tn={};function en(n,t,e,r,i){var o=(t||{}).k,a=i.getAttribute(o);a&&(tn[e]=JSON.parse(decodeURI(a)),G(i,o));var u=tn[e]||{},f=[];for(var c in u)u[c]&&n in u[c]&&(f.push(c),r[c]||delete u[c][n]);for(var s in r){var d=u[s];d&&d[n]===r[s]||(f.push(s),r[s]&&(u[s]=u[s]||{},u[s][n]=r[s]))}for(var l=0,v=f;l1){var v=[];r=r.filter((function(n){var t=JSON.stringify(n),e=!D(v,t);return v.push(t),e}))}r.forEach((function(t){if(!t.skip){var r=document.createElement(e);t.once||r.setAttribute(u,n),Object.keys(t).forEach((function(n){if(!D(O,n))if("innerHTML"!==n)if("json"!==n)if("cssText"!==n)if("callback"!==n){var e=D(c,n)?"data-".concat(n):n,i=D(M,n);if(!i||t[n]){var o=i?"":t[n];r.setAttribute(e,o)}}else r.onload=function(){return t[n](r)};else r.styleSheet?r.styleSheet.cssText=t.cssText:r.appendChild(document.createTextNode(t.cssText));else r.innerHTML=JSON.stringify(t.json);else r.innerHTML=t.innerHTML}));var i,o=l[function(n){var t=n.body,e=n.pbody;return t?"body":e?"pbody":"head"}(t)];o.some((function(n,t){return i=t,r.isEqualNode(n)}))&&(i||0===i)?o.splice(i,1):s.push(r)}}));var m=[];for(var h in l)Array.prototype.push.apply(m,l[h]);return m.forEach((function(n){n.parentNode.removeChild(n)})),s.forEach((function(n){n.hasAttribute("data-body")?o.appendChild(n):n.hasAttribute("data-pbody")?o.insertBefore(n,o.firstChild):i.appendChild(n)})),{oldTags:m,newTags:s}}function on(n,t,r){var i=t=t||{},o=i.M,a=i.h,u={},f=U(u,"html");if(n===a&&f.hasAttribute(o)){G(f,o);var c=!1;return w.forEach((function(n){r[n]&&X(t,n,r[n])&&(c=!0)})),c&&Y(),!1}var s,d={},l={};for(var v in r)if(!D(N,v))if("title"!==v){if(D(T,v)){var m=v.substr(0,4);en(n,t,v,r[v],U(u,m))}else if(e(r[v])){var h=rn(n,t,v,r[v],U(u,"head"),U(u,"body")),p=h.oldTags,y=h.newTags;y.length&&(d[v]=y,l[v]=p)}}else((s=r.title)||""===s)&&(document.title=s);return{S:d,D:l}}function an(n,t,e){return{set:function(r){return function(n,t,e,r){if(n&&n.$el)return on(t,e,r);(nn=nn||{})[t]=r}(n,t,e,r)},remove:function(){return function(n,t,e){if(n&&n.$el){var r={},i=!0,o=!1,a=void 0;try{for(var u,f=T[Symbol.iterator]();!(i=(u=f.next()).done);i=!0){var c=u.value,s=c.substr(0,4);en(t,e,c,{},U(r,s))}}catch(n){o=!0,a=n}finally{try{i||null==f.return||f.return()}finally{if(o)throw a}}return function(n,t){var e=n.k;_(E("[".concat(e,'="').concat(t,'"]'))).map((function(n){return n.remove()}))}(e,t)}nn[t]&&(delete nn[t],fn())}(n,t,e)}}}function un(){return nn}function fn(n){!n&&Object.keys(nn).length||(nn=void 0)}function cn(n,t){if(t=t||{},!n._vueMeta)return f("This vue app/component has no vue-meta configuration"),{};var e=function(n,t,e,r){e=e||[];var i=(n=n||{}).j;return t.title&&(t.titleChunk=t.title),t.titleTemplate&&"%s"!==t.titleTemplate&&P({component:r,T:"title"},t,t.titleTemplate,t.titleChunk||""),t.base&&(t.base=Object.keys(t.base).length?[t.base]:[]),t.meta&&(t.meta=t.meta.filter((function(n,t,e){return!n[i]||t===K(e,(function(t){return t[i]===n[i]}))})),t.meta.forEach((function(t){return P(n,t)}))),L(n,t,e)}(t,q(t,n),H,n),r=on(n._vueMeta.m,t,e);r&&a(e.changed)&&(e.changed(e,r.S,r.D),r={addedTags:r.S,removedTags:r.D});var i=un();if(i){for(var o in i)on(o,t,i[o]),delete i[o];fn(!0)}return{vm:n,metaInfo:e,tags:r}}function sn(n){n=n||{};var t=this.$root;return{getOptions:function(){return function(n){var t={};for(var e in n)t[e]=n[e];return t}(n)},setOptions:function(e){e&&e.p&&(n.p=!!e.p,B(t));if(e&&"debounceWait"in e){var r=parseInt(e.t);isNaN(r)||(n.t=r)}e&&"waitOnDestroyed"in e&&(n.g=!!e.g)},refresh:function(){return cn(t,n)},inject:function(){return c("inject")},pause:function(){return V(t)},resume:function(){return z(t)},addApp:function(e){return an(t,e,n)}}}var dn={version:"2.3.3",install:function(n,t){n.__vuemeta_installed||(n.__vuemeta_installed=!0,t=function(n){return{v:(n=i(n)?n:{}).keyName||d,k:n.attribute||l,M:n.ssrAttribute||v,j:n.tagIDKeyName||m,T:n.contentKeyName||h,N:n.metaTemplateKeyName||p,t:r(n.debounceWait)?b:n.debounceWait,g:r(n.waitOnDestroyed)?y:n.waitOnDestroyed,h:n.ssrAppId||g,p:!!n.refreshOnceOnNavigation}}(t),n.prototype.$meta=function(){return sn.call(this,t)},n.mixin(W(n,t)))},generate:function(n,t){return c("generate")},hasMetaInfo:x};export default dn; diff --git a/dist/vue-meta.esm.js b/dist/vue-meta.esm.js index 3a336f46..7b242029 100644 --- a/dist/vue-meta.esm.js +++ b/dist/vue-meta.esm.js @@ -1,5 +1,5 @@ /** - * vue-meta v2.3.2 + * vue-meta v2.3.3 * (c) 2020 * - Declan de Wet * - Sébastien Chopin (@Atinux) @@ -10,9 +10,11 @@ import deepmerge from 'deepmerge'; -var version = "2.3.2"; +var version = "2.3.3"; function _typeof(obj) { + "@babel/helpers - typeof"; + if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function (obj) { return typeof obj; @@ -216,7 +218,7 @@ var tagsWithoutEndTag = ['base', 'meta', 'link']; // HTML elements which can hav var tagsWithInnerContent = ['noscript', 'script', 'style']; // Attributes which are inserted as childNodes instead of HTMLAttribute var tagAttributeAsInnerContent = ['innerHTML', 'cssText', 'json']; -var tagProperties = ['once', 'template']; // Attributes which should be added with data- prefix +var tagProperties = ['once', 'skip', 'template']; // Attributes which should be added with data- prefix var commonDataAttributes = ['body', 'pbody']; // from: https://github.com/kangax/html-minifier/blob/gh-pages/src/htmlminifier.js#L202 @@ -321,22 +323,6 @@ function includes(array, value) { return array.includes(value); } -function ensureIsArray(arg, key) { - if (!key || !isObject(arg)) { - return isArray(arg) ? arg : []; - } - - if (!isArray(arg[key])) { - arg[key] = []; - } - - return arg; -} -function ensuredPush(object, key, el) { - ensureIsArray(object, key); - object[key].push(el); -} - function hasMetaInfo(vm) { vm = vm || this; return vm && (vm[rootConfigKey] === true || isObject(vm[rootConfigKey])); @@ -393,6 +379,8 @@ function createMixin(Vue, options) { return { beforeCreate: function beforeCreate() { + var _this2 = this; + var rootKey = '$root'; var $root = this[rootKey]; var $options = this.$options; @@ -462,7 +450,7 @@ function createMixin(Vue, options) { // if computed $metaInfo exists, watch it for updates & trigger a refresh // when it changes (i.e. automatically handle async actions that affect metaInfo) // credit for this suggestion goes to [Sébastien Chopin](https://github.com/Atinux) - ensuredPush($options, 'created', function () { + this.$on('hook:created', function () { this.$watch('$metaInfo', function () { triggerUpdate(options, this[rootKey], 'watcher'); }); @@ -480,7 +468,7 @@ function createMixin(Vue, options) { if (!$root[rootConfigKey].initialized) { if (!$root[rootConfigKey].initializedSsr) { $root[rootConfigKey].initializedSsr = true; - ensuredPush($options, 'beforeMount', function () { + this.$on('hook:beforeMount', function () { var $root = this; // if this Vue-app was server rendered, set the appId to 'ssr' // only one SSR app per page is supported @@ -491,7 +479,7 @@ function createMixin(Vue, options) { } // we use the mounted hook here as on page load - ensuredPush($options, 'mounted', function () { + this.$on('hook:mounted', function () { var $root = this[rootKey]; if (!$root[rootConfigKey].initialized) { @@ -531,8 +519,38 @@ function createMixin(Vue, options) { addNavGuards($root); } } - } // do not trigger refresh on the server side + } + + this.$on('hook:destroyed', function () { + var _this = this; + + // do not trigger refresh: + // - when user configured to not wait for transitions on destroyed + // - when the component doesnt have a parent + // - doesnt have metaInfo defined + if (!this.$parent || !hasMetaInfo(this)) { + return; + } + delete this._hasMetaInfo; + this.$nextTick(function () { + if (!options.waitOnDestroyed || !_this.$el || !_this.$el.offsetParent) { + triggerUpdate(options, _this.$root, 'destroyed'); + return; + } // Wait that element is hidden before refreshing meta tags (to support animations) + + + var interval = setInterval(function () { + if (_this.$el && _this.$el.offsetParent !== null) { + /* istanbul ignore next line */ + return; + } + + clearInterval(interval); + triggerUpdate(options, _this.$root, 'destroyed'); + }, 50); + }); + }); // do not trigger refresh on the server side if (this.$isServer) { /* istanbul ignore next */ @@ -541,41 +559,10 @@ function createMixin(Vue, options) { updateOnLifecycleHook.forEach(function (lifecycleHook) { - ensuredPush($options, lifecycleHook, function () { + _this2.$on("hook:".concat(lifecycleHook), function () { triggerUpdate(options, this[rootKey], lifecycleHook); }); }); - }, - // TODO: move back into beforeCreate when Vue issue is resolved - destroyed: function destroyed() { - var _this = this; - - // do not trigger refresh: - // - when user configured to not wait for transitions on destroyed - // - when the component doesnt have a parent - // - doesnt have metaInfo defined - if (!this.$parent || !hasMetaInfo(this)) { - return; - } - - delete this._hasMetaInfo; - this.$nextTick(function () { - if (!options.waitOnDestroyed || !_this.$el || !_this.$el.offsetParent) { - triggerUpdate(options, _this.$root, 'destroyed'); - return; - } // Wait that element is hidden before refreshing meta tags (to support animations) - - - var interval = setInterval(function () { - if (_this.$el && _this.$el.offsetParent !== null) { - /* istanbul ignore next line */ - return; - } - - clearInterval(interval); - triggerUpdate(options, _this.$root, 'destroyed'); - }, 50); - }); } }; } @@ -613,6 +600,18 @@ function getOptions(options) { return optionsCopy; } +function ensureIsArray(arg, key) { + if (!key || !isObject(arg)) { + return isArray(arg) ? arg : []; + } + + if (!isArray(arg[key])) { + arg[key] = []; + } + + return arg; +} + var serverSequences = [[/&/g, '&'], [//g, '>'], [/"/g, '"'], [/'/g, ''']]; var clientSequences = [[/&/g, "&"], [//g, ">"], [/"/g, "\""], [/'/g, "'"]]; // sanitizes potentially dangerous characters @@ -1192,7 +1191,11 @@ function updateTag(appId, options, type, tags, head, body) { } var newElement = document.createElement(type); - newElement.setAttribute(attribute, appId); + + if (!tag.once) { + newElement.setAttribute(attribute, appId); + } + Object.keys(tag).forEach(function (attr) { /* istanbul ignore next */ if (includes(tagProperties, attr)) { diff --git a/dist/vue-meta.js b/dist/vue-meta.js index a8199f08..f5683305 100644 --- a/dist/vue-meta.js +++ b/dist/vue-meta.js @@ -1,5 +1,5 @@ /** - * vue-meta v2.3.2 + * vue-meta v2.3.3 * (c) 2020 * - Declan de Wet * - Sébastien Chopin (@Atinux) @@ -14,9 +14,11 @@ (global = global || self, global.VueMeta = factory()); }(this, (function () { 'use strict'; - var version = "2.3.2"; + var version = "2.3.3"; function _typeof(obj) { + "@babel/helpers - typeof"; + if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function (obj) { return typeof obj; @@ -147,7 +149,7 @@ var metaInfoAttributeKeys = [defaultInfoKeys[3], defaultInfoKeys[4], defaultInfoKeys[5]]; // HTML elements which support the onload event var tagsSupportingOnload = ['link', 'style', 'script']; // HTML elements which dont have a head tag (shortened to our needs) - var tagProperties = ['once', 'template']; // Attributes which should be added with data- prefix + var tagProperties = ['once', 'skip', 'template']; // Attributes which should be added with data- prefix var commonDataAttributes = ['body', 'pbody']; // from: https://github.com/kangax/html-minifier/blob/gh-pages/src/htmlminifier.js#L202 @@ -252,22 +254,6 @@ return array.includes(value); } - function ensureIsArray(arg, key) { - if (!key || !isObject(arg)) { - return isArray(arg) ? arg : []; - } - - if (!isArray(arg[key])) { - arg[key] = []; - } - - return arg; - } - function ensuredPush(object, key, el) { - ensureIsArray(object, key); - object[key].push(el); - } - function hasMetaInfo(vm) { vm = vm || this; return vm && (vm[rootConfigKey] === true || isObject(vm[rootConfigKey])); @@ -324,6 +310,8 @@ return { beforeCreate: function beforeCreate() { + var _this2 = this; + var rootKey = '$root'; var $root = this[rootKey]; var $options = this.$options; @@ -393,7 +381,7 @@ // if computed $metaInfo exists, watch it for updates & trigger a refresh // when it changes (i.e. automatically handle async actions that affect metaInfo) // credit for this suggestion goes to [Sébastien Chopin](https://github.com/Atinux) - ensuredPush($options, 'created', function () { + this.$on('hook:created', function () { this.$watch('$metaInfo', function () { triggerUpdate(options, this[rootKey], 'watcher'); }); @@ -411,7 +399,7 @@ if (!$root[rootConfigKey].initialized) { if (!$root[rootConfigKey].initializedSsr) { $root[rootConfigKey].initializedSsr = true; - ensuredPush($options, 'beforeMount', function () { + this.$on('hook:beforeMount', function () { var $root = this; // if this Vue-app was server rendered, set the appId to 'ssr' // only one SSR app per page is supported @@ -422,7 +410,7 @@ } // we use the mounted hook here as on page load - ensuredPush($options, 'mounted', function () { + this.$on('hook:mounted', function () { var $root = this[rootKey]; if (!$root[rootConfigKey].initialized) { @@ -462,8 +450,38 @@ addNavGuards($root); } } - } // do not trigger refresh on the server side + } + + this.$on('hook:destroyed', function () { + var _this = this; + + // do not trigger refresh: + // - when user configured to not wait for transitions on destroyed + // - when the component doesnt have a parent + // - doesnt have metaInfo defined + if (!this.$parent || !hasMetaInfo(this)) { + return; + } + delete this._hasMetaInfo; + this.$nextTick(function () { + if (!options.waitOnDestroyed || !_this.$el || !_this.$el.offsetParent) { + triggerUpdate(options, _this.$root, 'destroyed'); + return; + } // Wait that element is hidden before refreshing meta tags (to support animations) + + + var interval = setInterval(function () { + if (_this.$el && _this.$el.offsetParent !== null) { + /* istanbul ignore next line */ + return; + } + + clearInterval(interval); + triggerUpdate(options, _this.$root, 'destroyed'); + }, 50); + }); + }); // do not trigger refresh on the server side if (this.$isServer) { /* istanbul ignore next */ @@ -472,41 +490,10 @@ updateOnLifecycleHook.forEach(function (lifecycleHook) { - ensuredPush($options, lifecycleHook, function () { + _this2.$on("hook:".concat(lifecycleHook), function () { triggerUpdate(options, this[rootKey], lifecycleHook); }); }); - }, - // TODO: move back into beforeCreate when Vue issue is resolved - destroyed: function destroyed() { - var _this = this; - - // do not trigger refresh: - // - when user configured to not wait for transitions on destroyed - // - when the component doesnt have a parent - // - doesnt have metaInfo defined - if (!this.$parent || !hasMetaInfo(this)) { - return; - } - - delete this._hasMetaInfo; - this.$nextTick(function () { - if (!options.waitOnDestroyed || !_this.$el || !_this.$el.offsetParent) { - triggerUpdate(options, _this.$root, 'destroyed'); - return; - } // Wait that element is hidden before refreshing meta tags (to support animations) - - - var interval = setInterval(function () { - if (_this.$el && _this.$el.offsetParent !== null) { - /* istanbul ignore next line */ - return; - } - - clearInterval(interval); - triggerUpdate(options, _this.$root, 'destroyed'); - }, 50); - }); } }; } @@ -544,6 +531,18 @@ return optionsCopy; } + function ensureIsArray(arg, key) { + if (!key || !isObject(arg)) { + return isArray(arg) ? arg : []; + } + + if (!isArray(arg[key])) { + arg[key] = []; + } + + return arg; + } + var clientSequences = [[/&/g, "&"], [//g, ">"], [/"/g, "\""], [/'/g, "'"]]; // sanitizes potentially dangerous characters function escape(info, options, escapeOptions, escapeKeys) { @@ -1209,7 +1208,11 @@ } var newElement = document.createElement(type); - newElement.setAttribute(attribute, appId); + + if (!tag.once) { + newElement.setAttribute(attribute, appId); + } + Object.keys(tag).forEach(function (attr) { /* istanbul ignore next */ if (includes(tagProperties, attr)) { diff --git a/dist/vue-meta.min.js b/dist/vue-meta.min.js index 3073febe..eca9c49c 100644 --- a/dist/vue-meta.min.js +++ b/dist/vue-meta.min.js @@ -1,5 +1,5 @@ /** - * vue-meta v2.3.2 + * vue-meta v2.3.3 * (c) 2020 * - Declan de Wet * - Sébastien Chopin (@Atinux) @@ -7,4 +7,4 @@ * - All the amazing contributors * @license MIT */ -!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(n=n||self).VueMeta=t()}(this,(function(){"use strict";function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(t)}function t(n){return Array.isArray(n)}function e(n){return void 0===n}function r(t){return"object"===n(t)}function i(t){return"object"===n(t)&&null!==t}function o(n){return"function"==typeof n}var u=(function(){try{return!e(window)}catch(n){return!1}}()?window:global).console||{};function a(n){u&&u.warn&&u.warn(n)}var f=function(n){return a("".concat(n," is not supported in browser builds"))},c={title:void 0,titleChunk:"",titleTemplate:"%s",htmlAttrs:{},bodyAttrs:{},headAttrs:{},base:[],link:[],meta:[],style:[],script:[],noscript:[],__dangerouslyDisableSanitizers:[],__dangerouslyDisableSanitizersByTagID:{}},s="metaInfo",d="data-vue-meta",l="data-vue-meta-server-rendered",v="vmid",m="content",y="template",p=!0,h=10,b="ssr",g=Object.keys(c),A=[g[12],g[13]],j=[g[1],g[2],"changed"].concat(A),I=[g[3],g[4],g[5]],O=["link","style","script"],N=["once","template"],T=["body","pbody"],w=["allowfullscreen","amp","async","autofocus","autoplay","checked","compact","controls","declare","default","defaultchecked","defaultmuted","defaultselected","defer","disabled","enabled","formnovalidate","hidden","indeterminate","inert","ismap","itemscope","loop","multiple","muted","nohref","noresize","noshade","novalidate","nowrap","open","pauseonexit","readonly","required","reversed","scoped","seamless","selected","sortable","truespeed","typemustmatch","visible"],M=null;function S(n,t,e){var r=n.t;t._vueMeta.i||!t._vueMeta.o&&"watcher"!==e||(t._vueMeta.i=null),t._vueMeta.i&&!t._vueMeta.u&&function(n,t){if(!(t=void 0===t?10:t))return void n();clearTimeout(M),M=setTimeout((function(){n()}),t)}((function(){t.$meta().refresh()}),r)}function D(n,t,e){if(!Array.prototype.findIndex){for(var r=0;r/g,">"],[/"/g,'"'],[/'/g,"'"]];function E(n,e,r){r=r||[];var o={A:function(n){return r.reduce((function(n,t){return n.replace(t[0],t[1])}),n)}};return A.forEach((function(n,t){if(0===t)k(e,n);else if(1===t)for(var r in e[n])k(e[n],r);o[n]=e[n]})),function n(e,r,o,u){var a=r.j,f=o.A,c=void 0===f?function(n){return n}:f,s={};for(var d in e){var l=e[d];if(_(j,d))s[d]=l;else{var v=A[0];if(o[v]&&_(o[v],d))s[d]=l;else{var m=e[a];if(m&&(v=A[1],o[v]&&o[v][m]&&_(o[v][m],d)))s[d]=l;else if("string"==typeof l?s[d]=c(l):t(l)?s[d]=l.map((function(t){return i(t)?n(t,r,o,!0):c(t)})):i(l)?s[d]=n(l,r,o,!0):s[d]=l,u){var y=c(d);d!==y&&(s[y]=s[d],delete s[d])}}}}return s}(e,n,o)}var H=function(t){return function(t){return!!t&&"object"===n(t)}(t)&&!function(n){var t=Object.prototype.toString.call(n);return"[object RegExp]"===t||"[object Date]"===t||!1}(t)};function L(n,t){return n}function P(n){return Object.keys(n)}function $(n,t){try{return t in n}catch(n){return!1}}function q(n,t,e){var r={};return e.I(n)&&P(n).forEach((function(t){r[t]=L(n[t])})),P(t).forEach((function(i){(function(n,t){return $(n,t)&&!(Object.hasOwnProperty.call(n,t)&&Object.propertyIsEnumerable.call(n,t))})(n,i)||($(n,i)&&e.I(t[i])?r[i]=U(n[i],t[i],e):r[i]=L(t[i]))})),r}function U(n,t,e){(e=e||{}).O=e.O,e.I=e.I||H,e.cloneUnlessOtherwiseSpecified=L;var r=Array.isArray(t);return r===Array.isArray(n)?r?e.O(n,t,e):q(n,t,e):L(t)}var F=U;function G(n,t,r,i){var u=n.component,a=n.N,f=n.T;return!0!==r&&!0!==t[a]&&(e(r)&&t[a]&&(r=t[a],t[a]=!0),r?(e(i)&&(i=t[f]),t[f]=o(r)?r.call(u,i):r.replace(/%s/g,i),!0):(delete t[a],!1))}var Q=!1;function X(n,t,e){return e=e||{},void 0===t.title&&delete t.title,I.forEach((function(n){if(t[n])for(var e in t[n])e in t[n]&&void 0===t[n][e]&&(_(w,e)&&!Q&&(a("VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details"),Q=!0),delete t[n][e])})),F(n,t,{O:function(n,t){return function(n,t,e){var r=n.component,i=n.j,o=n.N,u=n.T,a=[];return t.length||e.length?(t.forEach((function(n,t){if(n[i]){var f=D(e,(function(t){return t[i]===n[i]})),c=e[f];if(-1!==f){if(u in c&&void 0===c[u]||"innerHTML"in c&&void 0===c.innerHTML)return a.push(n),void e.splice(f,1);if(null!==c[u]&&null!==c.innerHTML){var s=n[o];if(s){if(!c[o])return G({component:r,N:o,T:u},c,s),void(c.template=!0);c[u]||G({component:r,N:o,T:u},c,void 0,n[u])}}else e.splice(f,1)}else a.push(n)}else a.push(n)})),a.concat(e)):a}(e,n,t)}})}function Y(n,t){return function n(t,i,o){if(o=o||{},i._inactive)return o;var u=(t=t||{}).v,a=i.$metaInfo,f=i.$options,c=i.$children;if(f[u]){var s=a||f[u];r(s)&&(o=X(o,s,t))}c.length&&c.forEach((function(r){(function(n){return(n=n||this)&&!e(n._vueMeta)})(r)&&(o=n(t,r,o))}));return o}(n||{},t,c)}var Z=function(n,t){return(t||document).querySelectorAll(n)};function nn(n,t){return n[t]||(n[t]=document.getElementsByTagName(t)[0]),n[t]}function tn(n,t,e){var r=t.m,i=t.M,o=t.type,u=t.j;e=e||{};var a=["".concat(o,"[").concat(i,'="').concat(r,'"]'),"".concat(o,"[data-").concat(u,"]")].map((function(n){for(var t in e){var r=e[t],i=r&&!0!==r?'="'.concat(r,'"'):"";n+="[data-".concat(t).concat(i,"]")}return n}));return K(Z(a.join(", "),n))}function en(n,t){n.removeAttribute(t)}var rn=[];function on(n,t,e,r){var i=n.j,o=!1;return e.forEach((function(n){n[i]&&n.callback&&(o=!0,function(n,t){1===arguments.length&&(t=n,n=""),rn.push([n,t])}("".concat(t,"[data-").concat(i,'="').concat(n[i],'"]'),n.callback))})),r&&o?un():o}function un(){var n;"complete"!==(n||document).readyState?document.onreadystatechange=function(){an()}:an()}function an(n){rn.forEach((function(t){var e=t[0],r=t[1],i="".concat(e,'[onload="this.__vm_l=1"]'),o=[];n||(o=K(Z(i))),n&&n.matches(i)&&(o=[n]),o.forEach((function(n){if(!n.__vm_cb){var t=function(){n.__vm_cb=!0,en(n,"onload"),r(n)};n.__vm_l?t():n.__vm_ev||(n.__vm_ev=!0,n.addEventListener("load",t))}}))}))}var fn,cn={};function sn(n,t,e,r,i){var o=(t||{}).M,u=i.getAttribute(o);u&&(cn[e]=JSON.parse(decodeURI(u)),en(i,o));var a=cn[e]||{},f=[];for(var c in a)a[c]&&n in a[c]&&(f.push(c),r[c]||delete a[c][n]);for(var s in r){var d=a[s];d&&d[n]===r[s]||(f.push(s),r[s]&&(a[s]=a[s]||{},a[s][n]=r[s]))}for(var l=0,v=f;l1){var v=[];r=r.filter((function(n){var t=JSON.stringify(n),e=!_(v,t);return v.push(t),e}))}r.forEach((function(t){if(!t.skip){var r=document.createElement(e);r.setAttribute(a,n),Object.keys(t).forEach((function(n){if(!_(N,n))if("innerHTML"!==n)if("json"!==n)if("cssText"!==n)if("callback"!==n){var e=_(c,n)?"data-".concat(n):n,i=_(w,n);if(!i||t[n]){var o=i?"":t[n];r.setAttribute(e,o)}}else r.onload=function(){return t[n](r)};else r.styleSheet?r.styleSheet.cssText=t.cssText:r.appendChild(document.createTextNode(t.cssText));else r.innerHTML=JSON.stringify(t.json);else r.innerHTML=t.innerHTML}));var i,o=l[function(n){var t=n.body,e=n.pbody;return t?"body":e?"pbody":"head"}(t)];o.some((function(n,t){return i=t,r.isEqualNode(n)}))&&(i||0===i)?o.splice(i,1):s.push(r)}}));var m=[];for(var y in l)Array.prototype.push.apply(m,l[y]);return m.forEach((function(n){n.parentNode.removeChild(n)})),s.forEach((function(n){n.hasAttribute("data-body")?o.appendChild(n):n.hasAttribute("data-pbody")?o.insertBefore(n,o.firstChild):i.appendChild(n)})),{oldTags:m,newTags:s}}function ln(n,e,r){var i=e=e||{},o=i.S,u=i.p,a={},f=nn(a,"html");if(n===u&&f.hasAttribute(o)){en(f,o);var c=!1;return O.forEach((function(n){r[n]&&on(e,n,r[n])&&(c=!0)})),c&&un(),!1}var s,d={},l={};for(var v in r)if(!_(j,v))if("title"!==v){if(_(I,v)){var m=v.substr(0,4);sn(n,e,v,r[v],nn(a,m))}else if(t(r[v])){var y=dn(n,e,v,r[v],nn(a,"head"),nn(a,"body")),p=y.oldTags,h=y.newTags;h.length&&(d[v]=h,l[v]=p)}}else((s=r.title)||""===s)&&(document.title=s);return{D:d,K:l}}function vn(n,t,e){return{set:function(r){return function(n,t,e,r){if(n&&n.$el)return ln(t,e,r);(fn=fn||{})[t]=r}(n,t,e,r)},remove:function(){return function(n,t,e){if(n&&n.$el){var r={},i=!0,o=!1,u=void 0;try{for(var a,f=I[Symbol.iterator]();!(i=(a=f.next()).done);i=!0){var c=a.value,s=c.substr(0,4);sn(t,e,c,{},nn(r,s))}}catch(n){o=!0,u=n}finally{try{i||null==f.return||f.return()}finally{if(o)throw u}}return function(n,t){var e=n.M;K(Z("[".concat(e,'="').concat(t,'"]'))).map((function(n){return n.remove()}))}(e,t)}fn[t]&&(delete fn[t],yn())}(n,t,e)}}}function mn(){return fn}function yn(n){!n&&Object.keys(fn).length||(fn=void 0)}function pn(n,t){if(t=t||{},!n._vueMeta)return a("This vue app/component has no vue-meta configuration"),{};var e=function(n,t,e,r){e=e||[];var i=(n=n||{}).j;return t.title&&(t.titleChunk=t.title),t.titleTemplate&&"%s"!==t.titleTemplate&&G({component:r,T:"title"},t,t.titleTemplate,t.titleChunk||""),t.base&&(t.base=Object.keys(t.base).length?[t.base]:[]),t.meta&&(t.meta=t.meta.filter((function(n,t,e){return!n[i]||t===D(e,(function(t){return t[i]===n[i]}))})),t.meta.forEach((function(t){return G(n,t)}))),E(n,t,e)}(t,Y(t,n),C,n),r=ln(n._vueMeta.m,t,e);r&&o(e.changed)&&(e.changed(e,r.D,r.K),r={addedTags:r.D,removedTags:r.K});var i=mn();if(i){for(var u in i)ln(u,t,i[u]),delete i[u];yn(!0)}return{vm:n,metaInfo:e,tags:r}}function hn(n){n=n||{};var t=this.$root;return{getOptions:function(){return function(n){var t={};for(var e in n)t[e]=n[e];return t}(n)},setOptions:function(e){e&&e.h&&(n.h=!!e.h,J(t));if(e&&"debounceWait"in e){var r=parseInt(e.t);isNaN(r)||(n.t=r)}e&&"waitOnDestroyed"in e&&(n.g=!!e.g)},refresh:function(){return pn(t,n)},inject:function(){return f("inject")},pause:function(){return z(t)},resume:function(){return B(t)},addApp:function(e){return vn(t,e,n)}}}return{version:"2.3.2",install:function(n,t){n.__vuemeta_installed||(n.__vuemeta_installed=!0,t=function(n){return{v:(n=r(n)?n:{}).keyName||s,M:n.attribute||d,S:n.ssrAttribute||l,j:n.tagIDKeyName||v,T:n.contentKeyName||m,N:n.metaTemplateKeyName||y,t:e(n.debounceWait)?h:n.debounceWait,g:e(n.waitOnDestroyed)?p:n.waitOnDestroyed,p:n.ssrAppId||b,h:!!n.refreshOnceOnNavigation}}(t),n.prototype.$meta=function(){return hn.call(this,t)},n.mixin(W(n,t)))},generate:function(n,t){return f("generate")},hasMetaInfo:V}})); +!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(n=n||self).VueMeta=t()}(this,(function(){"use strict";function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(t)}function t(n){return Array.isArray(n)}function e(n){return void 0===n}function r(t){return"object"===n(t)}function i(t){return"object"===n(t)&&null!==t}function o(n){return"function"==typeof n}var u=(function(){try{return!e(window)}catch(n){return!1}}()?window:global).console||{};function a(n){u&&u.warn&&u.warn(n)}var f=function(n){return a("".concat(n," is not supported in browser builds"))},c={title:void 0,titleChunk:"",titleTemplate:"%s",htmlAttrs:{},bodyAttrs:{},headAttrs:{},base:[],link:[],meta:[],style:[],script:[],noscript:[],__dangerouslyDisableSanitizers:[],__dangerouslyDisableSanitizersByTagID:{}},s="metaInfo",d="data-vue-meta",l="data-vue-meta-server-rendered",v="vmid",m="content",h="template",y=!0,p=10,b="ssr",g=Object.keys(c),A=[g[12],g[13]],j=[g[1],g[2],"changed"].concat(A),I=[g[3],g[4],g[5]],O=["link","style","script"],N=["once","skip","template"],T=["body","pbody"],w=["allowfullscreen","amp","async","autofocus","autoplay","checked","compact","controls","declare","default","defaultchecked","defaultmuted","defaultselected","defer","disabled","enabled","formnovalidate","hidden","indeterminate","inert","ismap","itemscope","loop","multiple","muted","nohref","noresize","noshade","novalidate","nowrap","open","pauseonexit","readonly","required","reversed","scoped","seamless","selected","sortable","truespeed","typemustmatch","visible"],k=null;function M(n,t,e){var r=n.t;t._vueMeta.i||!t._vueMeta.o&&"watcher"!==e||(t._vueMeta.i=null),t._vueMeta.i&&!t._vueMeta.u&&function(n,t){if(!(t=void 0===t?10:t))return void n();clearTimeout(k),k=setTimeout((function(){n()}),t)}((function(){t.$meta().refresh()}),r)}function S(n,t,e){if(!Array.prototype.findIndex){for(var r=0;r/g,">"],[/"/g,'"'],[/'/g,"'"]];function C(n,e,r){r=r||[];var o={A:function(n){return r.reduce((function(n,t){return n.replace(t[0],t[1])}),n)}};return A.forEach((function(n,t){if(0===t)R(e,n);else if(1===t)for(var r in e[n])R(e[n],r);o[n]=e[n]})),function n(e,r,o,u){var a=r.j,f=o.A,c=void 0===f?function(n){return n}:f,s={};for(var d in e){var l=e[d];if(K(j,d))s[d]=l;else{var v=A[0];if(o[v]&&K(o[v],d))s[d]=l;else{var m=e[a];if(m&&(v=A[1],o[v]&&o[v][m]&&K(o[v][m],d)))s[d]=l;else if("string"==typeof l?s[d]=c(l):t(l)?s[d]=l.map((function(t){return i(t)?n(t,r,o,!0):c(t)})):i(l)?s[d]=n(l,r,o,!0):s[d]=l,u){var h=c(d);d!==h&&(s[h]=s[d],delete s[d])}}}}return s}(e,n,o)}var E=function(t){return function(t){return!!t&&"object"===n(t)}(t)&&!function(n){var t=Object.prototype.toString.call(n);return"[object RegExp]"===t||"[object Date]"===t||!1}(t)};function H(n,t){return n}function L(n){return Object.keys(n)}function P(n,t){try{return t in n}catch(n){return!1}}function $(n,t,e){var r={};return e.I(n)&&L(n).forEach((function(t){r[t]=H(n[t])})),L(t).forEach((function(i){(function(n,t){return P(n,t)&&!(Object.hasOwnProperty.call(n,t)&&Object.propertyIsEnumerable.call(n,t))})(n,i)||(P(n,i)&&e.I(t[i])?r[i]=q(n[i],t[i],e):r[i]=H(t[i]))})),r}function q(n,t,e){(e=e||{}).O=e.O,e.I=e.I||E,e.cloneUnlessOtherwiseSpecified=H;var r=Array.isArray(t);return r===Array.isArray(n)?r?e.O(n,t,e):$(n,t,e):H(t)}var U=q;function F(n,t,r,i){var u=n.component,a=n.N,f=n.T;return!0!==r&&!0!==t[a]&&(e(r)&&t[a]&&(r=t[a],t[a]=!0),r?(e(i)&&(i=t[f]),t[f]=o(r)?r.call(u,i):r.replace(/%s/g,i),!0):(delete t[a],!1))}var G=!1;function Q(n,t,e){return e=e||{},void 0===t.title&&delete t.title,I.forEach((function(n){if(t[n])for(var e in t[n])e in t[n]&&void 0===t[n][e]&&(K(w,e)&&!G&&(a("VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details"),G=!0),delete t[n][e])})),U(n,t,{O:function(n,t){return function(n,t,e){var r=n.component,i=n.j,o=n.N,u=n.T,a=[];return t.length||e.length?(t.forEach((function(n,t){if(n[i]){var f=S(e,(function(t){return t[i]===n[i]})),c=e[f];if(-1!==f){if(u in c&&void 0===c[u]||"innerHTML"in c&&void 0===c.innerHTML)return a.push(n),void e.splice(f,1);if(null!==c[u]&&null!==c.innerHTML){var s=n[o];if(s){if(!c[o])return F({component:r,N:o,T:u},c,s),void(c.template=!0);c[u]||F({component:r,N:o,T:u},c,void 0,n[u])}}else e.splice(f,1)}else a.push(n)}else a.push(n)})),a.concat(e)):a}(e,n,t)}})}function X(n,t){return function n(t,i,o){if(o=o||{},i._inactive)return o;var u=(t=t||{}).v,a=i.$metaInfo,f=i.$options,c=i.$children;if(f[u]){var s=a||f[u];r(s)&&(o=Q(o,s,t))}c.length&&c.forEach((function(r){(function(n){return(n=n||this)&&!e(n._vueMeta)})(r)&&(o=n(t,r,o))}));return o}(n||{},t,c)}var Y=function(n,t){return(t||document).querySelectorAll(n)};function Z(n,t){return n[t]||(n[t]=document.getElementsByTagName(t)[0]),n[t]}function nn(n,t,e){var r=t.m,i=t.k,o=t.type,u=t.j;e=e||{};var a=["".concat(o,"[").concat(i,'="').concat(r,'"]'),"".concat(o,"[data-").concat(u,"]")].map((function(n){for(var t in e){var r=e[t],i=r&&!0!==r?'="'.concat(r,'"'):"";n+="[data-".concat(t).concat(i,"]")}return n}));return D(Y(a.join(", "),n))}function tn(n,t){n.removeAttribute(t)}var en=[];function rn(n,t,e,r){var i=n.j,o=!1;return e.forEach((function(n){n[i]&&n.callback&&(o=!0,function(n,t){1===arguments.length&&(t=n,n=""),en.push([n,t])}("".concat(t,"[data-").concat(i,'="').concat(n[i],'"]'),n.callback))})),r&&o?on():o}function on(){var n;"complete"!==(n||document).readyState?document.onreadystatechange=function(){un()}:un()}function un(n){en.forEach((function(t){var e=t[0],r=t[1],i="".concat(e,'[onload="this.__vm_l=1"]'),o=[];n||(o=D(Y(i))),n&&n.matches(i)&&(o=[n]),o.forEach((function(n){if(!n.__vm_cb){var t=function(){n.__vm_cb=!0,tn(n,"onload"),r(n)};n.__vm_l?t():n.__vm_ev||(n.__vm_ev=!0,n.addEventListener("load",t))}}))}))}var an,fn={};function cn(n,t,e,r,i){var o=(t||{}).k,u=i.getAttribute(o);u&&(fn[e]=JSON.parse(decodeURI(u)),tn(i,o));var a=fn[e]||{},f=[];for(var c in a)a[c]&&n in a[c]&&(f.push(c),r[c]||delete a[c][n]);for(var s in r){var d=a[s];d&&d[n]===r[s]||(f.push(s),r[s]&&(a[s]=a[s]||{},a[s][n]=r[s]))}for(var l=0,v=f;l1){var v=[];r=r.filter((function(n){var t=JSON.stringify(n),e=!K(v,t);return v.push(t),e}))}r.forEach((function(t){if(!t.skip){var r=document.createElement(e);t.once||r.setAttribute(a,n),Object.keys(t).forEach((function(n){if(!K(N,n))if("innerHTML"!==n)if("json"!==n)if("cssText"!==n)if("callback"!==n){var e=K(c,n)?"data-".concat(n):n,i=K(w,n);if(!i||t[n]){var o=i?"":t[n];r.setAttribute(e,o)}}else r.onload=function(){return t[n](r)};else r.styleSheet?r.styleSheet.cssText=t.cssText:r.appendChild(document.createTextNode(t.cssText));else r.innerHTML=JSON.stringify(t.json);else r.innerHTML=t.innerHTML}));var i,o=l[function(n){var t=n.body,e=n.pbody;return t?"body":e?"pbody":"head"}(t)];o.some((function(n,t){return i=t,r.isEqualNode(n)}))&&(i||0===i)?o.splice(i,1):s.push(r)}}));var m=[];for(var h in l)Array.prototype.push.apply(m,l[h]);return m.forEach((function(n){n.parentNode.removeChild(n)})),s.forEach((function(n){n.hasAttribute("data-body")?o.appendChild(n):n.hasAttribute("data-pbody")?o.insertBefore(n,o.firstChild):i.appendChild(n)})),{oldTags:m,newTags:s}}function dn(n,e,r){var i=e=e||{},o=i.M,u=i.h,a={},f=Z(a,"html");if(n===u&&f.hasAttribute(o)){tn(f,o);var c=!1;return O.forEach((function(n){r[n]&&rn(e,n,r[n])&&(c=!0)})),c&&on(),!1}var s,d={},l={};for(var v in r)if(!K(j,v))if("title"!==v){if(K(I,v)){var m=v.substr(0,4);cn(n,e,v,r[v],Z(a,m))}else if(t(r[v])){var h=sn(n,e,v,r[v],Z(a,"head"),Z(a,"body")),y=h.oldTags,p=h.newTags;p.length&&(d[v]=p,l[v]=y)}}else((s=r.title)||""===s)&&(document.title=s);return{S:d,D:l}}function ln(n,t,e){return{set:function(r){return function(n,t,e,r){if(n&&n.$el)return dn(t,e,r);(an=an||{})[t]=r}(n,t,e,r)},remove:function(){return function(n,t,e){if(n&&n.$el){var r={},i=!0,o=!1,u=void 0;try{for(var a,f=I[Symbol.iterator]();!(i=(a=f.next()).done);i=!0){var c=a.value,s=c.substr(0,4);cn(t,e,c,{},Z(r,s))}}catch(n){o=!0,u=n}finally{try{i||null==f.return||f.return()}finally{if(o)throw u}}return function(n,t){var e=n.k;D(Y("[".concat(e,'="').concat(t,'"]'))).map((function(n){return n.remove()}))}(e,t)}an[t]&&(delete an[t],mn())}(n,t,e)}}}function vn(){return an}function mn(n){!n&&Object.keys(an).length||(an=void 0)}function hn(n,t){if(t=t||{},!n._vueMeta)return a("This vue app/component has no vue-meta configuration"),{};var e=function(n,t,e,r){e=e||[];var i=(n=n||{}).j;return t.title&&(t.titleChunk=t.title),t.titleTemplate&&"%s"!==t.titleTemplate&&F({component:r,T:"title"},t,t.titleTemplate,t.titleChunk||""),t.base&&(t.base=Object.keys(t.base).length?[t.base]:[]),t.meta&&(t.meta=t.meta.filter((function(n,t,e){return!n[i]||t===S(e,(function(t){return t[i]===n[i]}))})),t.meta.forEach((function(t){return F(n,t)}))),C(n,t,e)}(t,X(t,n),W,n),r=dn(n._vueMeta.m,t,e);r&&o(e.changed)&&(e.changed(e,r.S,r.D),r={addedTags:r.S,removedTags:r.D});var i=vn();if(i){for(var u in i)dn(u,t,i[u]),delete i[u];mn(!0)}return{vm:n,metaInfo:e,tags:r}}function yn(n){n=n||{};var t=this.$root;return{getOptions:function(){return function(n){var t={};for(var e in n)t[e]=n[e];return t}(n)},setOptions:function(e){e&&e.p&&(n.p=!!e.p,z(t));if(e&&"debounceWait"in e){var r=parseInt(e.t);isNaN(r)||(n.t=r)}e&&"waitOnDestroyed"in e&&(n.g=!!e.g)},refresh:function(){return hn(t,n)},inject:function(){return f("inject")},pause:function(){return x(t)},resume:function(){return V(t)},addApp:function(e){return ln(t,e,n)}}}return{version:"2.3.3",install:function(n,t){n.__vuemeta_installed||(n.__vuemeta_installed=!0,t=function(n){return{v:(n=r(n)?n:{}).keyName||s,k:n.attribute||d,M:n.ssrAttribute||l,j:n.tagIDKeyName||v,T:n.contentKeyName||m,N:n.metaTemplateKeyName||h,t:e(n.debounceWait)?p:n.debounceWait,g:e(n.waitOnDestroyed)?y:n.waitOnDestroyed,h:n.ssrAppId||b,p:!!n.refreshOnceOnNavigation}}(t),n.prototype.$meta=function(){return yn.call(this,t)},n.mixin(J(n,t)))},generate:function(n,t){return f("generate")},hasMetaInfo:_}})); diff --git a/package.json b/package.json index 6c8fdbfc..906369e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-meta", - "version": "2.3.2", + "version": "2.3.3", "description": "Manage HTML metadata in Vue.js components with ssr support", "keywords": [ "attribute",