From 06295bf9fb11527d22a1441ffa8ca56574dcd25c Mon Sep 17 00:00:00 2001 From: pimlie Date: Wed, 9 Oct 2019 10:10:33 +0000 Subject: [PATCH] chore(release): 2.3.1 --- CHANGELOG.md | 9 ++ dist/vue-meta.common.js | 158 +++++++++++++++++++------------ dist/vue-meta.esm.browser.js | 156 ++++++++++++++++++------------ dist/vue-meta.esm.browser.min.js | 2 +- dist/vue-meta.esm.js | 158 +++++++++++++++++++------------ dist/vue-meta.js | 156 ++++++++++++++++++------------ dist/vue-meta.min.js | 2 +- package.json | 2 +- 8 files changed, 394 insertions(+), 249 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19704c62..d71adbc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ 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.1](https://github.com/nuxt/vue-meta/compare/v2.3.0...v2.3.1) (2019-10-09) + + +### Bug Fixes + +* accept and pass options as second arg for generate ([2ce5177](https://github.com/nuxt/vue-meta/commit/2ce5177)) +* still traverse children when metainfo doesnt return object ([#469](https://github.com/nuxt/vue-meta/issues/469)) ([35b7099](https://github.com/nuxt/vue-meta/commit/35b7099)) +* try to detect global mixins adding meta info ([#467](https://github.com/nuxt/vue-meta/issues/467)) ([2231ec1](https://github.com/nuxt/vue-meta/commit/2231ec1)) + ## [2.3.0](https://github.com/nuxt/vue-meta/compare/v2.3.0-beta.0...v2.3.0) (2019-10-03) ## [2.3.0-beta.0](https://github.com/nuxt/vue-meta/compare/v2.2.2...v2.3.0-beta.0) (2019-09-17) diff --git a/dist/vue-meta.common.js b/dist/vue-meta.common.js index d00f9867..a8000121 100644 --- a/dist/vue-meta.common.js +++ b/dist/vue-meta.common.js @@ -1,5 +1,5 @@ /** - * vue-meta v2.3.0 + * vue-meta v2.3.1 * (c) 2019 * - Declan de Wet * - Sébastien Chopin (@Atinux) @@ -14,7 +14,7 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau var deepmerge = _interopDefault(require('deepmerge')); -var version = "2.3.0"; +var version = "2.3.1"; function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { @@ -233,6 +233,63 @@ function batchUpdate(callback, timeout) { return batchId; } +/* + * To reduce build size, this file provides simple polyfills without + * overly excessive type checking and without modifying + * the global Array.prototype + * The polyfills are automatically removed in the commonjs build + * Also, only files in client/ & shared/ should use these functions + * files in server/ still use normal js function + */ +function find(array, predicate, thisArg) { + if ( !Array.prototype.find) { + // idx needs to be a Number, for..in returns string + for (var idx = 0; idx < array.length; idx++) { + if (predicate.call(thisArg, array[idx], idx, array)) { + return array[idx]; + } + } + + return; + } + + return array.find(predicate, thisArg); +} +function findIndex(array, predicate, thisArg) { + if ( !Array.prototype.findIndex) { + // idx needs to be a Number, for..in returns string + for (var idx = 0; idx < array.length; idx++) { + if (predicate.call(thisArg, array[idx], idx, array)) { + return idx; + } + } + + return -1; + } + + return array.findIndex(predicate, thisArg); +} +function toArray(arg) { + if ( !Array.from) { + return Array.prototype.slice.call(arg); + } + + return Array.from(arg); +} +function includes(array, value) { + if ( !Array.prototype.includes) { + for (var idx in array) { + if (array[idx] === value) { + return true; + } + } + + return false; + } + + return array.includes(value); +} + function ensureIsArray(arg, key) { if (!key || !isObject(arg)) { return isArray(arg) ? arg : []; @@ -306,11 +363,12 @@ function createMixin(Vue, options) { var rootKey = '$root'; var $root = this[rootKey]; var $options = this.$options; + var devtoolsEnabled = Vue.config.devtools; Object.defineProperty(this, '_hasMetaInfo', { configurable: true, get: function get() { // Show deprecation warning once when devtools enabled - if (Vue.config.devtools && !$root[rootConfigKey].deprecationWarningShown) { + if (devtoolsEnabled && !$root[rootConfigKey].deprecationWarningShown) { warn('VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead'); $root[rootConfigKey].deprecationWarningShown = true; } @@ -330,6 +388,20 @@ function createMixin(Vue, options) { appId: appId }; appId++; + + if (devtoolsEnabled && $root.$options[options.keyName]) { + // use nextTick so the children should be added to $root + this.$nextTick(function () { + // find the first child that lists fnOptions + var child = find($root.$children, function (c) { + return c.$vnode && c.$vnode.fnOptions; + }); + + if (child && child.$vnode.fnOptions[options.keyName]) { + warn("VueMeta has detected a possible global mixin which adds a ".concat(options.keyName, " property to all Vue components on the page. This could cause severe performance issues. If possible, use $meta().addApp to add meta information instead")); + } + }); + } } // to speed up updates we keep track of branches which have a component with vue-meta info defined // if _vueMeta = true it has info, if _vueMeta = false a child has info @@ -373,14 +445,18 @@ function createMixin(Vue, options) { $root[rootConfigKey].initialized = this.$isServer; if (!$root[rootConfigKey].initialized) { - ensuredPush($options, 'beforeMount', function () { - var $root = this[rootKey]; // if this Vue-app was server rendered, set the appId to 'ssr' - // only one SSR app per page is supported + if (!$root[rootConfigKey].initializedSsr) { + $root[rootConfigKey].initializedSsr = true; + ensuredPush($options, '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 + + if ($root.$el && $root.$el.nodeType === 1 && $root.$el.hasAttribute('data-server-rendered')) { + $root[rootConfigKey].appId = options.ssrAppId; + } + }); + } // we use the mounted hook here as on page load - if ($root.$el && $root.$el.nodeType === 1 && $root.$el.hasAttribute('data-server-rendered')) { - $root[rootConfigKey].appId = options.ssrAppId; - } - }); // we use the mounted hook here as on page load ensuredPush($options, 'mounted', function () { var $root = this[rootKey]; @@ -426,6 +502,7 @@ function createMixin(Vue, options) { if (this.$isServer) { + /* istanbul ignore next */ return; } // no need to add this hooks on server side @@ -448,6 +525,7 @@ function createMixin(Vue, options) { return; } + delete this._hasMetaInfo; this.$nextTick(function () { if (!options.waitOnDestroyed || !_this.$el || !_this.$el.offsetParent) { triggerUpdate(options, _this.$root, 'destroyed'); @@ -502,49 +580,6 @@ function getOptions(options) { return optionsCopy; } -/* - * To reduce build size, this file provides simple polyfills without - * overly excessive type checking and without modifying - * the global Array.prototype - * The polyfills are automatically removed in the commonjs build - * Also, only files in client/ & shared/ should use these functions - * files in server/ still use normal js function - */ -function findIndex(array, predicate, thisArg) { - if ( !Array.prototype.findIndex) { - // idx needs to be a Number, for..in returns string - for (var idx = 0; idx < array.length; idx++) { - if (predicate.call(thisArg, array[idx], idx, array)) { - return idx; - } - } - - return -1; - } - - return array.findIndex(predicate, thisArg); -} -function toArray(arg) { - if ( !Array.from) { - return Array.prototype.slice.call(arg); - } - - return Array.from(arg); -} -function includes(array, value) { - if ( !Array.prototype.includes) { - for (var idx in array) { - if (array[idx] === value) { - return true; - } - } - - return false; - } - - return array.includes(value); -} - var serverSequences = [[/&/g, '&'], [//g, '>'], [/"/g, '"'], [/'/g, ''']]; var clientSequences = [[/&/g, "&"], [//g, ">"], [/"/g, "\""], [/'/g, "'"]]; // sanitizes potentially dangerous characters @@ -820,14 +855,13 @@ function getComponentOption(options, component, result) { // and set to the computed prop $metaInfo in the mixin // using the computed prop should be a small performance increase // because Vue caches those internally - var data = $metaInfo || $options[keyName]; // ignore data if its not an object, then we keep our previous result + var data = $metaInfo || $options[keyName]; // only merge data with result when its an object + // eg it could be a function when metaInfo() returns undefined + // dueo to the or statement above - if (!isObject(data)) { - return result; - } // merge with existing options - - - result = merge(result, data, options); + if (isObject(data)) { + result = merge(result, data, options); + } } // collect & aggregate child options if deep = true @@ -1819,8 +1853,8 @@ function install(Vue, options) { var index = { version: version, install: install, - generate: function generate$1(metaInfo) { - return generate(metaInfo) ; + generate: function generate$1(metaInfo, options) { + return generate(metaInfo, options) ; }, hasMetaInfo: hasMetaInfo }; diff --git a/dist/vue-meta.esm.browser.js b/dist/vue-meta.esm.browser.js index 89a6ecfe..5a00648a 100644 --- a/dist/vue-meta.esm.browser.js +++ b/dist/vue-meta.esm.browser.js @@ -1,5 +1,5 @@ /** - * vue-meta v2.3.0 + * vue-meta v2.3.1 * (c) 2019 * - Declan de Wet * - Sébastien Chopin (@Atinux) @@ -10,7 +10,7 @@ import deepmerge from 'deepmerge'; -var version = "2.3.0"; +var version = "2.3.1"; function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { @@ -190,6 +190,63 @@ function batchUpdate(callback, timeout) { return batchId; } +/* + * To reduce build size, this file provides simple polyfills without + * overly excessive type checking and without modifying + * the global Array.prototype + * The polyfills are automatically removed in the commonjs build + * Also, only files in client/ & shared/ should use these functions + * files in server/ still use normal js function + */ +function find(array, predicate, thisArg) { + if ( !Array.prototype.find) { + // idx needs to be a Number, for..in returns string + for (var idx = 0; idx < array.length; idx++) { + if (predicate.call(thisArg, array[idx], idx, array)) { + return array[idx]; + } + } + + return; + } + + return array.find(predicate, thisArg); +} +function findIndex(array, predicate, thisArg) { + if ( !Array.prototype.findIndex) { + // idx needs to be a Number, for..in returns string + for (var idx = 0; idx < array.length; idx++) { + if (predicate.call(thisArg, array[idx], idx, array)) { + return idx; + } + } + + return -1; + } + + return array.findIndex(predicate, thisArg); +} +function toArray(arg) { + if ( !Array.from) { + return Array.prototype.slice.call(arg); + } + + return Array.from(arg); +} +function includes(array, value) { + if ( !Array.prototype.includes) { + for (var idx in array) { + if (array[idx] === value) { + return true; + } + } + + return false; + } + + return array.includes(value); +} + function ensureIsArray(arg, key) { if (!key || !isObject(arg)) { return isArray(arg) ? arg : []; @@ -263,11 +320,12 @@ function createMixin(Vue, options) { var rootKey = '$root'; var $root = this[rootKey]; var $options = this.$options; + var devtoolsEnabled = Vue.config.devtools; Object.defineProperty(this, '_hasMetaInfo', { configurable: true, get: function get() { // Show deprecation warning once when devtools enabled - if (Vue.config.devtools && !$root[rootConfigKey].deprecationWarningShown) { + if (devtoolsEnabled && !$root[rootConfigKey].deprecationWarningShown) { warn('VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead'); $root[rootConfigKey].deprecationWarningShown = true; } @@ -287,6 +345,20 @@ function createMixin(Vue, options) { appId: appId }; appId++; + + if (devtoolsEnabled && $root.$options[options.keyName]) { + // use nextTick so the children should be added to $root + this.$nextTick(function () { + // find the first child that lists fnOptions + var child = find($root.$children, function (c) { + return c.$vnode && c.$vnode.fnOptions; + }); + + if (child && child.$vnode.fnOptions[options.keyName]) { + warn("VueMeta has detected a possible global mixin which adds a ".concat(options.keyName, " property to all Vue components on the page. This could cause severe performance issues. If possible, use $meta().addApp to add meta information instead")); + } + }); + } } // to speed up updates we keep track of branches which have a component with vue-meta info defined // if _vueMeta = true it has info, if _vueMeta = false a child has info @@ -330,14 +402,18 @@ function createMixin(Vue, options) { $root[rootConfigKey].initialized = this.$isServer; if (!$root[rootConfigKey].initialized) { - ensuredPush($options, 'beforeMount', function () { - var $root = this[rootKey]; // if this Vue-app was server rendered, set the appId to 'ssr' - // only one SSR app per page is supported + if (!$root[rootConfigKey].initializedSsr) { + $root[rootConfigKey].initializedSsr = true; + ensuredPush($options, '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 + + if ($root.$el && $root.$el.nodeType === 1 && $root.$el.hasAttribute('data-server-rendered')) { + $root[rootConfigKey].appId = options.ssrAppId; + } + }); + } // we use the mounted hook here as on page load - if ($root.$el && $root.$el.nodeType === 1 && $root.$el.hasAttribute('data-server-rendered')) { - $root[rootConfigKey].appId = options.ssrAppId; - } - }); // we use the mounted hook here as on page load ensuredPush($options, 'mounted', function () { var $root = this[rootKey]; @@ -383,6 +459,7 @@ function createMixin(Vue, options) { if (this.$isServer) { + /* istanbul ignore next */ return; } // no need to add this hooks on server side @@ -405,6 +482,7 @@ function createMixin(Vue, options) { return; } + delete this._hasMetaInfo; this.$nextTick(function () { if (!options.waitOnDestroyed || !_this.$el || !_this.$el.offsetParent) { triggerUpdate(options, _this.$root, 'destroyed'); @@ -459,49 +537,6 @@ function getOptions(options) { return optionsCopy; } -/* - * To reduce build size, this file provides simple polyfills without - * overly excessive type checking and without modifying - * the global Array.prototype - * The polyfills are automatically removed in the commonjs build - * Also, only files in client/ & shared/ should use these functions - * files in server/ still use normal js function - */ -function findIndex(array, predicate, thisArg) { - if ( !Array.prototype.findIndex) { - // idx needs to be a Number, for..in returns string - for (var idx = 0; idx < array.length; idx++) { - if (predicate.call(thisArg, array[idx], idx, array)) { - return idx; - } - } - - return -1; - } - - return array.findIndex(predicate, thisArg); -} -function toArray(arg) { - if ( !Array.from) { - return Array.prototype.slice.call(arg); - } - - return Array.from(arg); -} -function includes(array, value) { - if ( !Array.prototype.includes) { - for (var idx in array) { - if (array[idx] === value) { - return true; - } - } - - return false; - } - - return array.includes(value); -} - var clientSequences = [[/&/g, "&"], [//g, ">"], [/"/g, "\""], [/'/g, "'"]]; // sanitizes potentially dangerous characters function escape(info, options, escapeOptions, escapeKeys) { @@ -776,14 +811,13 @@ function getComponentOption(options, component, result) { // and set to the computed prop $metaInfo in the mixin // using the computed prop should be a small performance increase // because Vue caches those internally - var data = $metaInfo || $options[keyName]; // ignore data if its not an object, then we keep our previous result + var data = $metaInfo || $options[keyName]; // only merge data with result when its an object + // eg it could be a function when metaInfo() returns undefined + // dueo to the or statement above - if (!isObject(data)) { - return result; - } // merge with existing options - - - result = merge(result, data, options); + if (isObject(data)) { + result = merge(result, data, options); + } } // collect & aggregate child options if deep = true @@ -1501,7 +1535,7 @@ function install(Vue, options) { var index = { version: version, install: install, - generate: function generate(metaInfo) { + generate: function generate(metaInfo, options) { return showWarningNotSupportedInBrowserBundle('generate'); }, hasMetaInfo: hasMetaInfo diff --git a/dist/vue-meta.esm.browser.min.js b/dist/vue-meta.esm.browser.min.js index af32de6e..43428cd8 100644 --- a/dist/vue-meta.esm.browser.min.js +++ b/dist/vue-meta.esm.browser.min.js @@ -1 +1 @@ -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=function(){return f("This vue app/component has no vue-meta configuration")},d={title:void 0,titleChunk:"",titleTemplate:"%s",htmlAttrs:{},bodyAttrs:{},headAttrs:{},base:[],link:[],meta:[],style:[],script:[],noscript:[],__dangerouslyDisableSanitizers:[],__dangerouslyDisableSanitizersByTagID:{}},l="_vueMeta",v={t:"metaInfo",i:"data-vue-meta",o:"data-vue-meta-server-rendered",u:"vmid",s:"content",l:"template",v:!0,m:10,p:"ssr"},m=Object.keys(d),y=[m[12],m[13]],p=[m[1],m[2],"changed"].concat(y),h=[m[3],m[4],m[5]],b=["link","style","script"],g=["once","template"],N=["body","pbody"],I=["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"],A=null;function T(n,e,t){var r=n.m;e[l].h||!e[l].g&&"watcher"!==t||(e[l].h=null),e[l].h&&!e[l].N&&function(n,e){if(!(e=void 0===e?10:e))return void n();clearTimeout(A),A=setTimeout((function(){n()}),e)}((function(){e.$meta().refresh()}),r)}function w(n,e){return e&&i(n)?(t(n[e])||(n[e]=[]),n):t(n)?n:[]}function O(n,e,t){w(n,e),n[e].push(t)}function K(n){return(n=n||this)&&(!0===n[l]||i(n[l]))}function M(n,e){return n[l].N=!0,function(){return S(n,e)}}function S(n,e){if(n[l].N=!1,e||void 0===e)return n.$meta().refresh()}function j(n){var e=n.$router;!n[l].I&&e&&(n[l].I=!0,e.beforeEach((function(e,t,r){M(n),r()})),e.afterEach((function(){var e=S(n).metaInfo;e&&a(e.afterNavigation)&&e.afterNavigation(e)})))}var D=1;function _(n,e,t){if(!Array.prototype.findIndex){for(var r=0;r/g,">"],[/"/g,'"'],[/'/g,"'"]];function z(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 y.forEach((function(n,t){if(0===t)w(e,n);else if(1===t)for(var r in e[n])w(e[n],r);i[n]=e[n]})),function n(e,r,i,a){var u=r.u,f=i.A,c=void 0===f?function(n){return n}:f,s={};for(var d in e){var l=e[d];if(W(p,d))s[d]=l;else{var v=y[0];if(i[v]&&W(i[v],d))s[d]=l;else{var m=e[u];if(m&&(v=y[1],i[v]&&i[v][m]&&W(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 h=c(d);d!==h&&(s[h]=s[d],delete s[d])}}}}return s}(e,n,i)}function B(n,e,t,i){var o=n.component,u=n.l,f=n.s;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 J=!1;function C(e,t,r){return r=r||{},void 0===t.title&&delete t.title,h.forEach((function(n){if(t[n])for(var e in t[n])e in t[n]&&void 0===t[n][e]&&(W(I,e)&&!J&&(f("VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details"),J=!0),delete t[n][e])})),n(e,t,{T:function(n,e){return function(n,e,t){var r=n.component,i=n.u,o=n.l,a=n.s,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 B({component:r,l:o,s:a},c,s),void(c.template=!0);c[a]||B({component:r,l:o,s: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 H(n,e){return function n(e,t,o){o=o||{};if(t._inactive)return o;e=e||{};var a=e,u=a.t;var f=t.$metaInfo,c=t.$options,s=t.$children;if(c[u]){var d=f||c[u];if(!i(d))return o;o=C(o,d,e)}s.length&&s.forEach((function(t){(function(n){return(n=n||this)&&!r(n[l])})(t)&&(o=n(e,t,o))}));return o}(n||{},e,d)}var L=function(n,e){return(e||document).querySelectorAll(n)};function P(n,e){return n[e]||(n[e]=document.getElementsByTagName(e)[0]),n[e]}function R(n,e,t){var r=e.O,i=e.i,o=e.type,a=e.u;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 k(L(u.join(", "),n))}function V(n,e){n.removeAttribute(e)}var q=[];function E(n,e,t,r){var i=n.u,o=!1;return t.forEach((function(n){n[i]&&n.callback&&(o=!0,function(n,e){1===arguments.length&&(e=n,n=""),q.push([n,e])}("".concat(e,"[data-").concat(i,'="').concat(n[i],'"]'),n.callback))})),r&&o?U():o}function U(){var n;"complete"!==(n||document).readyState?document.onreadystatechange=function(){$()}:$()}function $(n){q.forEach((function(e){var t=e[0],r=e[1],i="".concat(t,'[onload="this.__vm_l=1"]'),o=[];n||(o=k(L(i))),n&&n.matches(i)&&(o=[n]),o.forEach((function(n){if(!n.__vm_cb){var e=function(){n.__vm_cb=!0,V(n,"onload"),r(n)};n.__vm_l?e():n.__vm_ev||(n.__vm_ev=!0,n.addEventListener("load",e))}}))}))}var F,G={};function Q(n,e,t,r,i){var o=(e||{}).i,a=i.getAttribute(o);a&&(G[t]=JSON.parse(decodeURI(a)),V(i,o));var u=G[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=!W(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(!W(g,n))if("innerHTML"!==n)if("json"!==n)if("cssText"!==n)if("callback"!==n){var t=W(c,n)?"data-".concat(n):n,i=W(I,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 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 Y(n,e,r){var i=e=e||{},o=i.o,a=i.p,u={},f=P(u,"html");if(n===a&&f.hasAttribute(o)){V(f,o);var c=!1;return b.forEach((function(n){r[n]&&E(e,n,r[n])&&(c=!0)})),c&&U(),!1}var s,d={},l={};for(var v in r)if(!W(p,v))if("title"!==v){if(W(h,v)){var m=v.substr(0,4);Q(n,e,v,r[v],P(u,m))}else if(t(r[v])){var y=X(n,e,v,r[v],P(u,"head"),P(u,"body")),g=y.oldTags,N=y.newTags;N.length&&(d[v]=N,l[v]=g)}}else((s=r.title)||""===s)&&(document.title=s);return{K:d,M:l}}function Z(n,e,t){return{set:function(r){return function(n,e,t,r){if(n&&n.$el)return Y(e,t,r);(F=F||{})[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=h[Symbol.iterator]();!(i=(u=f.next()).done);i=!0){var c=u.value,s=c.substr(0,4);Q(e,t,c,{},P(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.i;k(L("[".concat(t,'="').concat(e,'"]'))).map((function(n){return n.remove()}))}(t,e)}F[e]&&(delete F[e],en())}(n,e,t)}}}function nn(){return F}function en(n){!n&&Object.keys(F).length||(F=void 0)}function tn(n,e){if(e=e||{},!n[l])return s(),{};var t=function(n,e,t,r){t=t||[];var i=(n=n||{}).u;return e.title&&(e.titleChunk=e.title),e.titleTemplate&&"%s"!==e.titleTemplate&&B({component:r,s:"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 B(n,e)}))),z(n,e,t)}(e,H(e,n),x,n),r=Y(n[l].O,e,t);r&&a(t.changed)&&(t.changed(t,r.K,r.M),r={addedTags:r.K,removedTags:r.M});var i=nn();if(i){for(var o in i)Y(o,e,i[o]),delete i[o];en(!0)}return{vm:n,metaInfo:t,tags:r}}function rn(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.S&&(n.S=!!t.S,j(e));if(t&&"debounceWait"in t){var r=parseInt(t.m);isNaN(r)||(n.m=r)}t&&"waitOnDestroyed"in t&&(n.v=!!t.v)},refresh:function(){return tn(e,n)},inject:function(){return c("inject")},pause:function(){return M(e)},resume:function(){return S(e)},addApp:function(t){return Z(e,t,n)}}}var on={version:"2.3.0",install:function(n,e){n.__vuemeta_installed||(n.__vuemeta_installed=!0,e=function(n){return{t:(n=i(n)?n:{}).keyName||v.t,i:n.attribute||v.i,o:n.ssrAttribute||v.o,u:n.tagIDKeyName||v.u,s:n.contentKeyName||v.s,l:n.metaTemplateKeyName||v.l,m:r(n.debounceWait)?v.m:n.debounceWait,v:r(n.waitOnDestroyed)?v.v:n.waitOnDestroyed,p:n.ssrAppId||v.p,S:!!n.refreshOnceOnNavigation}}(e),n.prototype.$meta=function(){return rn.call(this,e)},n.mixin(function(n,e){var t=["activated","deactivated","beforeMount"];return{beforeCreate:function(){var i=this.$root,o=this.$options;if(Object.defineProperty(this,"_hasMetaInfo",{configurable:!0,get:function(){return n.config.devtools&&!i[l].j&&(f("VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead"),i[l].j=!0),K(this)}}),!r(o[e.t])&&null!==o[e.t]){if(i[l]||(i[l]={O:D},D++),!this[l]){this[l]=!0;for(var u=this.$parent;u&&u!==i;)r(u[l])&&(u[l]=!1),u=u.$parent}a(o[e.t])&&(o.computed=o.computed||{},o.computed.$metaInfo=o[e.t],this.$isServer||O(o,"created",(function(){this.$watch("$metaInfo",(function(){T(e,this.$root,"watcher")}))}))),r(i[l].h)&&(i[l].h=this.$isServer,i[l].h||(O(o,"beforeMount",(function(){var n=this.$root;n.$el&&1===n.$el.nodeType&&n.$el.hasAttribute("data-server-rendered")&&(n[l].O=e.p)})),O(o,"mounted",(function(){var n=this.$root;n[l].h||(n[l].g=!0,this.$nextTick((function(){var t=n.$meta().refresh(),r=t.tags,i=t.metaInfo;!1===r&&null===n[l].h&&this.$nextTick((function(){return T(e,n,"init")})),n[l].h=!0,delete n[l].g,!e.S&&i.afterNavigation&&j(n)})))})),e.S&&j(i))),this.$isServer||t.forEach((function(n){O(o,n,(function(){T(e,this.$root,n)}))}))}},destroyed:function(){var n=this;this.$parent&&K(this)&&this.$nextTick((function(){if(e.v&&n.$el&&n.$el.offsetParent)var t=setInterval((function(){n.$el&&null!==n.$el.offsetParent||(clearInterval(t),T(e,n.$root,"destroyed"))}),50);else T(e,n.$root,"destroyed")}))}}}(n,e)))},generate:function(n){return c("generate")},hasMetaInfo:K};export default on; +import e from"deepmerge";function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function t(e){return Array.isArray(e)}function r(e){return void 0===e}function i(e){return"object"===n(e)}function o(e){return"object"===n(e)&&null!==e}function a(e){return"function"==typeof e}var u=(function(){try{return!r(window)}catch(e){return!1}}()?window:global).console||{};function f(e){u&&u.warn&&u.warn(e)}var c=function(e){return f("".concat(e," is not supported in browser builds"))},s=function(){return f("This vue app/component has no vue-meta configuration")},d={title:void 0,titleChunk:"",titleTemplate:"%s",htmlAttrs:{},bodyAttrs:{},headAttrs:{},base:[],link:[],meta:[],style:[],script:[],noscript:[],__dangerouslyDisableSanitizers:[],__dangerouslyDisableSanitizersByTagID:{}},l="_vueMeta",v={t:"metaInfo",i:"data-vue-meta",o:"data-vue-meta-server-rendered",u:"vmid",s:"content",l:"template",v:!0,m:10,p:"ssr"},m=Object.keys(d),p=[m[12],m[13]],y=[m[1],m[2],"changed"].concat(p),h=[m[3],m[4],m[5]],b=["link","style","script"],g=["once","template"],I=["body","pbody"],N=["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"],A=null;function T(e,n,t){var r=e.m;n[l].h||!n[l].g&&"watcher"!==t||(n[l].h=null),n[l].h&&!n[l].I&&function(e,n){if(!(n=void 0===n?10:n))return void e();clearTimeout(A),A=setTimeout((function(){e()}),n)}((function(){n.$meta().refresh()}),r)}function w(e,n,t){if(!Array.prototype.findIndex){for(var r=0;r/g,">"],[/"/g,'"'],[/'/g,"'"]];function z(e,n,r){r=r||[];var i={M:function(e){return r.reduce((function(e,n){return e.replace(n[0],n[1])}),e)}};return p.forEach((function(e,t){if(0===t)K(n,e);else if(1===t)for(var r in n[e])K(n[e],r);i[e]=n[e]})),function e(n,r,i,a){var u=r.u,f=i.M,c=void 0===f?function(e){return e}:f,s={};for(var d in n){var l=n[d];if(M(y,d))s[d]=l;else{var v=p[0];if(i[v]&&M(i[v],d))s[d]=l;else{var m=n[u];if(m&&(v=p[1],i[v]&&i[v][m]&&M(i[v][m],d)))s[d]=l;else if("string"==typeof l?s[d]=c(l):t(l)?s[d]=l.map((function(n){return o(n)?e(n,r,i,!0):c(n)})):o(l)?s[d]=e(l,r,i,!0):s[d]=l,a){var h=c(d);d!==h&&(s[h]=s[d],delete s[d])}}}}return s}(n,e,i)}function B(e,n,t,i){var o=e.component,u=e.l,f=e.s;return!0!==t&&!0!==n[u]&&(r(t)&&n[u]&&(t=n[u],n[u]=!0),t?(r(i)&&(i=n[f]),n[f]=a(t)?t.call(o,i):t.replace(/%s/g,i),!0):(delete n[u],!1))}var J=!1;function C(n,t,r){return r=r||{},void 0===t.title&&delete t.title,h.forEach((function(e){if(t[e])for(var n in t[e])n in t[e]&&void 0===t[e][n]&&(M(N,n)&&!J&&(f("VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details"),J=!0),delete t[e][n])})),e(n,t,{K:function(e,n){return function(e,n,t){var r=e.component,i=e.u,o=e.l,a=e.s,u=[];return n.length||t.length?(n.forEach((function(e,n){if(e[i]){var f=w(t,(function(n){return n[i]===e[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(e),void t.splice(f,1);if(null!==c[a]&&null!==c.innerHTML){var s=e[o];if(s){if(!c[o])return B({component:r,l:o,s:a},c,s),void(c.template=!0);c[a]||B({component:r,l:o,s:a},c,void 0,e[a])}}else t.splice(f,1)}else u.push(e)}else u.push(e)})),u.concat(t)):u}(r,e,n)}})}function H(e,n){return function e(n,t,o){o=o||{};if(t._inactive)return o;n=n||{};var a=n,u=a.t;var f=t.$metaInfo,c=t.$options,s=t.$children;if(c[u]){var d=f||c[u];i(d)&&(o=C(o,d,n))}s.length&&s.forEach((function(t){(function(e){return(e=e||this)&&!r(e[l])})(t)&&(o=e(n,t,o))}));return o}(e||{},n,d)}var L=function(e,n){return(n||document).querySelectorAll(e)};function P(e,n){return e[n]||(e[n]=document.getElementsByTagName(n)[0]),e[n]}function R(e,n,t){var r=n.T,i=n.i,o=n.type,a=n.u;t=t||{};var u=["".concat(o,"[").concat(i,'="').concat(r,'"]'),"".concat(o,"[data-").concat(a,"]")].map((function(e){for(var n in t){var r=t[n],i=r&&!0!==r?'="'.concat(r,'"'):"";e+="[data-".concat(n).concat(i,"]")}return e}));return O(L(u.join(", "),e))}function $(e,n){e.removeAttribute(n)}var q=[];function E(e,n,t,r){var i=e.u,o=!1;return t.forEach((function(e){e[i]&&e.callback&&(o=!0,function(e,n){1===arguments.length&&(n=e,e=""),q.push([e,n])}("".concat(n,"[data-").concat(i,'="').concat(e[i],'"]'),e.callback))})),r&&o?U():o}function U(){var e;"complete"!==(e||document).readyState?document.onreadystatechange=function(){F()}:F()}function F(e){q.forEach((function(n){var t=n[0],r=n[1],i="".concat(t,'[onload="this.__vm_l=1"]'),o=[];e||(o=O(L(i))),e&&e.matches(i)&&(o=[e]),o.forEach((function(e){if(!e.__vm_cb){var n=function(){e.__vm_cb=!0,$(e,"onload"),r(e)};e.__vm_l?n():e.__vm_ev||(e.__vm_ev=!0,e.addEventListener("load",n))}}))}))}var G,Q={};function X(e,n,t,r,i){var o=(n||{}).i,a=i.getAttribute(o);a&&(Q[t]=JSON.parse(decodeURI(a)),$(i,o));var u=Q[t]||{},f=[];for(var c in u)u[c]&&e in u[c]&&(f.push(c),r[c]||delete u[c][e]);for(var s in r){var d=u[s];d&&d[e]===r[s]||(f.push(s),r[s]&&(u[s]=u[s]||{},u[s][e]=r[s]))}for(var l=0,v=f;l1){var v=[];r=r.filter((function(e){var n=JSON.stringify(e),t=!M(v,n);return v.push(n),t}))}r.forEach((function(n){if(!n.skip){var r=document.createElement(t);r.setAttribute(u,e),Object.keys(n).forEach((function(e){if(!M(g,e))if("innerHTML"!==e)if("json"!==e)if("cssText"!==e)if("callback"!==e){var t=M(c,e)?"data-".concat(e):e,i=M(N,e);if(!i||n[e]){var o=i?"":n[e];r.setAttribute(t,o)}}else r.onload=function(){return n[e](r)};else r.styleSheet?r.styleSheet.cssText=n.cssText:r.appendChild(document.createTextNode(n.cssText));else r.innerHTML=JSON.stringify(n.json);else r.innerHTML=n.innerHTML}));var i,o=l[function(e){var n=e.body,t=e.pbody;return n?"body":t?"pbody":"head"}(n)];o.some((function(e,n){return i=n,r.isEqualNode(e)}))&&(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(e){e.parentNode.removeChild(e)})),s.forEach((function(e){e.hasAttribute("data-body")?o.appendChild(e):e.hasAttribute("data-pbody")?o.insertBefore(e,o.firstChild):i.appendChild(e)})),{oldTags:m,newTags:s}}function Z(e,n,r){var i=n=n||{},o=i.o,a=i.p,u={},f=P(u,"html");if(e===a&&f.hasAttribute(o)){$(f,o);var c=!1;return b.forEach((function(e){r[e]&&E(n,e,r[e])&&(c=!0)})),c&&U(),!1}var s,d={},l={};for(var v in r)if(!M(y,v))if("title"!==v){if(M(h,v)){var m=v.substr(0,4);X(e,n,v,r[v],P(u,m))}else if(t(r[v])){var p=Y(e,n,v,r[v],P(u,"head"),P(u,"body")),g=p.oldTags,I=p.newTags;I.length&&(d[v]=I,l[v]=g)}}else((s=r.title)||""===s)&&(document.title=s);return{S:d,j:l}}function ee(e,n,t){return{set:function(r){return function(e,n,t,r){if(e&&e.$el)return Z(n,t,r);(G=G||{})[n]=r}(e,n,t,r)},remove:function(){return function(e,n,t){if(e&&e.$el){var r={},i=!0,o=!1,a=void 0;try{for(var u,f=h[Symbol.iterator]();!(i=(u=f.next()).done);i=!0){var c=u.value,s=c.substr(0,4);X(n,t,c,{},P(r,s))}}catch(e){o=!0,a=e}finally{try{i||null==f.return||f.return()}finally{if(o)throw a}}return function(e,n){var t=e.i;O(L("[".concat(t,'="').concat(n,'"]'))).map((function(e){return e.remove()}))}(t,n)}G[n]&&(delete G[n],te())}(e,n,t)}}}function ne(){return G}function te(e){!e&&Object.keys(G).length||(G=void 0)}function re(e,n){if(n=n||{},!e[l])return s(),{};var t=function(e,n,t,r){t=t||[];var i=(e=e||{}).u;return n.title&&(n.titleChunk=n.title),n.titleTemplate&&"%s"!==n.titleTemplate&&B({component:r,s:"title"},n,n.titleTemplate,n.titleChunk||""),n.base&&(n.base=Object.keys(n.base).length?[n.base]:[]),n.meta&&(n.meta=n.meta.filter((function(e,n,t){return!e[i]||n===w(t,(function(n){return n[i]===e[i]}))})),n.meta.forEach((function(n){return B(e,n)}))),z(e,n,t)}(n,H(n,e),W,e),r=Z(e[l].T,n,t);r&&a(t.changed)&&(t.changed(t,r.S,r.j),r={addedTags:r.S,removedTags:r.j});var i=ne();if(i){for(var o in i)Z(o,n,i[o]),delete i[o];te(!0)}return{vm:e,metaInfo:t,tags:r}}function ie(e){e=e||{};var n=this.$root;return{getOptions:function(){return function(e){var n={};for(var t in e)n[t]=e[t];return n}(e)},setOptions:function(t){t&&t.O&&(e.O=!!t.O,k(n));if(t&&"debounceWait"in t){var r=parseInt(t.m);isNaN(r)||(e.m=r)}t&&"waitOnDestroyed"in t&&(e.v=!!t.v)},refresh:function(){return re(n,e)},inject:function(){return c("inject")},pause:function(){return D(n)},resume:function(){return _(n)},addApp:function(t){return ee(n,t,e)}}}var oe={version:"2.3.1",install:function(e,n){e.__vuemeta_installed||(e.__vuemeta_installed=!0,n=function(e){return{t:(e=i(e)?e:{}).keyName||v.t,i:e.attribute||v.i,o:e.ssrAttribute||v.o,u:e.tagIDKeyName||v.u,s:e.contentKeyName||v.s,l:e.metaTemplateKeyName||v.l,m:r(e.debounceWait)?v.m:e.debounceWait,v:r(e.waitOnDestroyed)?v.v:e.waitOnDestroyed,p:e.ssrAppId||v.p,O:!!e.refreshOnceOnNavigation}}(n),e.prototype.$meta=function(){return ie.call(this,n)},e.mixin(V(e,n)))},generate:function(e,n){return c("generate")},hasMetaInfo:j};export default oe; diff --git a/dist/vue-meta.esm.js b/dist/vue-meta.esm.js index 18627450..f1164980 100644 --- a/dist/vue-meta.esm.js +++ b/dist/vue-meta.esm.js @@ -1,5 +1,5 @@ /** - * vue-meta v2.3.0 + * vue-meta v2.3.1 * (c) 2019 * - Declan de Wet * - Sébastien Chopin (@Atinux) @@ -10,7 +10,7 @@ import deepmerge from 'deepmerge'; -var version = "2.3.0"; +var version = "2.3.1"; function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { @@ -229,6 +229,63 @@ function batchUpdate(callback, timeout) { return batchId; } +/* + * To reduce build size, this file provides simple polyfills without + * overly excessive type checking and without modifying + * the global Array.prototype + * The polyfills are automatically removed in the commonjs build + * Also, only files in client/ & shared/ should use these functions + * files in server/ still use normal js function + */ +function find(array, predicate, thisArg) { + if ( !Array.prototype.find) { + // idx needs to be a Number, for..in returns string + for (var idx = 0; idx < array.length; idx++) { + if (predicate.call(thisArg, array[idx], idx, array)) { + return array[idx]; + } + } + + return; + } + + return array.find(predicate, thisArg); +} +function findIndex(array, predicate, thisArg) { + if ( !Array.prototype.findIndex) { + // idx needs to be a Number, for..in returns string + for (var idx = 0; idx < array.length; idx++) { + if (predicate.call(thisArg, array[idx], idx, array)) { + return idx; + } + } + + return -1; + } + + return array.findIndex(predicate, thisArg); +} +function toArray(arg) { + if ( !Array.from) { + return Array.prototype.slice.call(arg); + } + + return Array.from(arg); +} +function includes(array, value) { + if ( !Array.prototype.includes) { + for (var idx in array) { + if (array[idx] === value) { + return true; + } + } + + return false; + } + + return array.includes(value); +} + function ensureIsArray(arg, key) { if (!key || !isObject(arg)) { return isArray(arg) ? arg : []; @@ -302,11 +359,12 @@ function createMixin(Vue, options) { var rootKey = '$root'; var $root = this[rootKey]; var $options = this.$options; + var devtoolsEnabled = Vue.config.devtools; Object.defineProperty(this, '_hasMetaInfo', { configurable: true, get: function get() { // Show deprecation warning once when devtools enabled - if (Vue.config.devtools && !$root[rootConfigKey].deprecationWarningShown) { + if (devtoolsEnabled && !$root[rootConfigKey].deprecationWarningShown) { warn('VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead'); $root[rootConfigKey].deprecationWarningShown = true; } @@ -326,6 +384,20 @@ function createMixin(Vue, options) { appId: appId }; appId++; + + if (devtoolsEnabled && $root.$options[options.keyName]) { + // use nextTick so the children should be added to $root + this.$nextTick(function () { + // find the first child that lists fnOptions + var child = find($root.$children, function (c) { + return c.$vnode && c.$vnode.fnOptions; + }); + + if (child && child.$vnode.fnOptions[options.keyName]) { + warn("VueMeta has detected a possible global mixin which adds a ".concat(options.keyName, " property to all Vue components on the page. This could cause severe performance issues. If possible, use $meta().addApp to add meta information instead")); + } + }); + } } // to speed up updates we keep track of branches which have a component with vue-meta info defined // if _vueMeta = true it has info, if _vueMeta = false a child has info @@ -369,14 +441,18 @@ function createMixin(Vue, options) { $root[rootConfigKey].initialized = this.$isServer; if (!$root[rootConfigKey].initialized) { - ensuredPush($options, 'beforeMount', function () { - var $root = this[rootKey]; // if this Vue-app was server rendered, set the appId to 'ssr' - // only one SSR app per page is supported + if (!$root[rootConfigKey].initializedSsr) { + $root[rootConfigKey].initializedSsr = true; + ensuredPush($options, '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 + + if ($root.$el && $root.$el.nodeType === 1 && $root.$el.hasAttribute('data-server-rendered')) { + $root[rootConfigKey].appId = options.ssrAppId; + } + }); + } // we use the mounted hook here as on page load - if ($root.$el && $root.$el.nodeType === 1 && $root.$el.hasAttribute('data-server-rendered')) { - $root[rootConfigKey].appId = options.ssrAppId; - } - }); // we use the mounted hook here as on page load ensuredPush($options, 'mounted', function () { var $root = this[rootKey]; @@ -422,6 +498,7 @@ function createMixin(Vue, options) { if (this.$isServer) { + /* istanbul ignore next */ return; } // no need to add this hooks on server side @@ -444,6 +521,7 @@ function createMixin(Vue, options) { return; } + delete this._hasMetaInfo; this.$nextTick(function () { if (!options.waitOnDestroyed || !_this.$el || !_this.$el.offsetParent) { triggerUpdate(options, _this.$root, 'destroyed'); @@ -498,49 +576,6 @@ function getOptions(options) { return optionsCopy; } -/* - * To reduce build size, this file provides simple polyfills without - * overly excessive type checking and without modifying - * the global Array.prototype - * The polyfills are automatically removed in the commonjs build - * Also, only files in client/ & shared/ should use these functions - * files in server/ still use normal js function - */ -function findIndex(array, predicate, thisArg) { - if ( !Array.prototype.findIndex) { - // idx needs to be a Number, for..in returns string - for (var idx = 0; idx < array.length; idx++) { - if (predicate.call(thisArg, array[idx], idx, array)) { - return idx; - } - } - - return -1; - } - - return array.findIndex(predicate, thisArg); -} -function toArray(arg) { - if ( !Array.from) { - return Array.prototype.slice.call(arg); - } - - return Array.from(arg); -} -function includes(array, value) { - if ( !Array.prototype.includes) { - for (var idx in array) { - if (array[idx] === value) { - return true; - } - } - - return false; - } - - return array.includes(value); -} - var serverSequences = [[/&/g, '&'], [//g, '>'], [/"/g, '"'], [/'/g, ''']]; var clientSequences = [[/&/g, "&"], [//g, ">"], [/"/g, "\""], [/'/g, "'"]]; // sanitizes potentially dangerous characters @@ -816,14 +851,13 @@ function getComponentOption(options, component, result) { // and set to the computed prop $metaInfo in the mixin // using the computed prop should be a small performance increase // because Vue caches those internally - var data = $metaInfo || $options[keyName]; // ignore data if its not an object, then we keep our previous result + var data = $metaInfo || $options[keyName]; // only merge data with result when its an object + // eg it could be a function when metaInfo() returns undefined + // dueo to the or statement above - if (!isObject(data)) { - return result; - } // merge with existing options - - - result = merge(result, data, options); + if (isObject(data)) { + result = merge(result, data, options); + } } // collect & aggregate child options if deep = true @@ -1815,8 +1849,8 @@ function install(Vue, options) { var index = { version: version, install: install, - generate: function generate$1(metaInfo) { - return generate(metaInfo) ; + generate: function generate$1(metaInfo, options) { + return generate(metaInfo, options) ; }, hasMetaInfo: hasMetaInfo }; diff --git a/dist/vue-meta.js b/dist/vue-meta.js index 31763572..b42d3594 100644 --- a/dist/vue-meta.js +++ b/dist/vue-meta.js @@ -1,5 +1,5 @@ /** - * vue-meta v2.3.0 + * vue-meta v2.3.1 * (c) 2019 * - Declan de Wet * - Sébastien Chopin (@Atinux) @@ -14,7 +14,7 @@ (global = global || self, global.VueMeta = factory()); }(this, function () { 'use strict'; - var version = "2.3.0"; + var version = "2.3.1"; function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { @@ -194,6 +194,63 @@ return batchId; } + /* + * To reduce build size, this file provides simple polyfills without + * overly excessive type checking and without modifying + * the global Array.prototype + * The polyfills are automatically removed in the commonjs build + * Also, only files in client/ & shared/ should use these functions + * files in server/ still use normal js function + */ + function find(array, predicate, thisArg) { + if ( !Array.prototype.find) { + // idx needs to be a Number, for..in returns string + for (var idx = 0; idx < array.length; idx++) { + if (predicate.call(thisArg, array[idx], idx, array)) { + return array[idx]; + } + } + + return; + } + + return array.find(predicate, thisArg); + } + function findIndex(array, predicate, thisArg) { + if ( !Array.prototype.findIndex) { + // idx needs to be a Number, for..in returns string + for (var idx = 0; idx < array.length; idx++) { + if (predicate.call(thisArg, array[idx], idx, array)) { + return idx; + } + } + + return -1; + } + + return array.findIndex(predicate, thisArg); + } + function toArray(arg) { + if ( !Array.from) { + return Array.prototype.slice.call(arg); + } + + return Array.from(arg); + } + function includes(array, value) { + if ( !Array.prototype.includes) { + for (var idx in array) { + if (array[idx] === value) { + return true; + } + } + + return false; + } + + return array.includes(value); + } + function ensureIsArray(arg, key) { if (!key || !isObject(arg)) { return isArray(arg) ? arg : []; @@ -267,11 +324,12 @@ var rootKey = '$root'; var $root = this[rootKey]; var $options = this.$options; + var devtoolsEnabled = Vue.config.devtools; Object.defineProperty(this, '_hasMetaInfo', { configurable: true, get: function get() { // Show deprecation warning once when devtools enabled - if (Vue.config.devtools && !$root[rootConfigKey].deprecationWarningShown) { + if (devtoolsEnabled && !$root[rootConfigKey].deprecationWarningShown) { warn('VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead'); $root[rootConfigKey].deprecationWarningShown = true; } @@ -291,6 +349,20 @@ appId: appId }; appId++; + + if (devtoolsEnabled && $root.$options[options.keyName]) { + // use nextTick so the children should be added to $root + this.$nextTick(function () { + // find the first child that lists fnOptions + var child = find($root.$children, function (c) { + return c.$vnode && c.$vnode.fnOptions; + }); + + if (child && child.$vnode.fnOptions[options.keyName]) { + warn("VueMeta has detected a possible global mixin which adds a ".concat(options.keyName, " property to all Vue components on the page. This could cause severe performance issues. If possible, use $meta().addApp to add meta information instead")); + } + }); + } } // to speed up updates we keep track of branches which have a component with vue-meta info defined // if _vueMeta = true it has info, if _vueMeta = false a child has info @@ -334,14 +406,18 @@ $root[rootConfigKey].initialized = this.$isServer; if (!$root[rootConfigKey].initialized) { - ensuredPush($options, 'beforeMount', function () { - var $root = this[rootKey]; // if this Vue-app was server rendered, set the appId to 'ssr' - // only one SSR app per page is supported + if (!$root[rootConfigKey].initializedSsr) { + $root[rootConfigKey].initializedSsr = true; + ensuredPush($options, '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 + + if ($root.$el && $root.$el.nodeType === 1 && $root.$el.hasAttribute('data-server-rendered')) { + $root[rootConfigKey].appId = options.ssrAppId; + } + }); + } // we use the mounted hook here as on page load - if ($root.$el && $root.$el.nodeType === 1 && $root.$el.hasAttribute('data-server-rendered')) { - $root[rootConfigKey].appId = options.ssrAppId; - } - }); // we use the mounted hook here as on page load ensuredPush($options, 'mounted', function () { var $root = this[rootKey]; @@ -387,6 +463,7 @@ if (this.$isServer) { + /* istanbul ignore next */ return; } // no need to add this hooks on server side @@ -409,6 +486,7 @@ return; } + delete this._hasMetaInfo; this.$nextTick(function () { if (!options.waitOnDestroyed || !_this.$el || !_this.$el.offsetParent) { triggerUpdate(options, _this.$root, 'destroyed'); @@ -463,49 +541,6 @@ return optionsCopy; } - /* - * To reduce build size, this file provides simple polyfills without - * overly excessive type checking and without modifying - * the global Array.prototype - * The polyfills are automatically removed in the commonjs build - * Also, only files in client/ & shared/ should use these functions - * files in server/ still use normal js function - */ - function findIndex(array, predicate, thisArg) { - if ( !Array.prototype.findIndex) { - // idx needs to be a Number, for..in returns string - for (var idx = 0; idx < array.length; idx++) { - if (predicate.call(thisArg, array[idx], idx, array)) { - return idx; - } - } - - return -1; - } - - return array.findIndex(predicate, thisArg); - } - function toArray(arg) { - if ( !Array.from) { - return Array.prototype.slice.call(arg); - } - - return Array.from(arg); - } - function includes(array, value) { - if ( !Array.prototype.includes) { - for (var idx in array) { - if (array[idx] === value) { - return true; - } - } - - return false; - } - - return array.includes(value); - } - var clientSequences = [[/&/g, "&"], [//g, ">"], [/"/g, "\""], [/'/g, "'"]]; // sanitizes potentially dangerous characters function escape(info, options, escapeOptions, escapeKeys) { @@ -848,14 +883,13 @@ // and set to the computed prop $metaInfo in the mixin // using the computed prop should be a small performance increase // because Vue caches those internally - var data = $metaInfo || $options[keyName]; // ignore data if its not an object, then we keep our previous result + var data = $metaInfo || $options[keyName]; // only merge data with result when its an object + // eg it could be a function when metaInfo() returns undefined + // dueo to the or statement above - if (!isObject(data)) { - return result; - } // merge with existing options - - - result = merge(result, data, options); + if (isObject(data)) { + result = merge(result, data, options); + } } // collect & aggregate child options if deep = true @@ -1573,7 +1607,7 @@ var index = { version: version, install: install, - generate: function generate(metaInfo) { + generate: function generate(metaInfo, options) { return showWarningNotSupportedInBrowserBundle('generate'); }, hasMetaInfo: hasMetaInfo diff --git a/dist/vue-meta.min.js b/dist/vue-meta.min.js index a28af6ce..0574fae7 100644 --- a/dist/vue-meta.min.js +++ b/dist/vue-meta.min.js @@ -1 +1 @@ -!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=function(){return a("This vue app/component has no vue-meta configuration")},s={title:void 0,titleChunk:"",titleTemplate:"%s",htmlAttrs:{},bodyAttrs:{},headAttrs:{},base:[],link:[],meta:[],style:[],script:[],noscript:[],__dangerouslyDisableSanitizers:[],__dangerouslyDisableSanitizersByTagID:{}},d="_vueMeta",v={t:"metaInfo",i:"data-vue-meta",o:"data-vue-meta-server-rendered",u:"vmid",s:"content",v:"template",l:!0,m:10,p:"ssr"},l=Object.keys(s),m=[l[12],l[13]],y=[l[1],l[2],"changed"].concat(m),p=[l[3],l[4],l[5]],b=["link","style","script"],h=["once","template"],g=["body","pbody"],N=["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"],A=null;function I(n,t,e){var r=n.m;t[d].h||!t[d].g&&"watcher"!==e||(t[d].h=null),t[d].h&&!t[d].N&&function(n,t){if(!(t=void 0===t?10:t))return void n();clearTimeout(A),A=setTimeout((function(){n()}),t)}((function(){t.$meta().refresh()}),r)}function O(n,e){return e&&r(n)?(t(n[e])||(n[e]=[]),n):t(n)?n:[]}function j(n,t,e){O(n,t),n[t].push(e)}function T(n){return(n=n||this)&&(!0===n[d]||r(n[d]))}function w(n,t){return n[d].N=!0,function(){return K(n,t)}}function K(n,t){if(n[d].N=!1,t||void 0===t)return n.$meta().refresh()}function M(n){var t=n.$router;!n[d].A&&t&&(n[d].A=!0,t.beforeEach((function(t,e,r){w(n),r()})),t.afterEach((function(){var t=K(n).metaInfo;t&&o(t.afterNavigation)&&t.afterNavigation(t)})))}var D=1;function S(n,t,e){if(!Array.prototype.findIndex){for(var r=0;r/g,">"],[/"/g,'"'],[/'/g,"'"]];function W(n,e,r){r=r||[];var o={I:function(n){return r.reduce((function(n,t){return n.replace(t[0],t[1])}),n)}};return m.forEach((function(n,t){if(0===t)O(e,n);else if(1===t)for(var r in e[n])O(e[n],r);o[n]=e[n]})),function n(e,r,o,u){var a=r.u,f=o.I,c=void 0===f?function(n){return n}:f,s={};for(var d in e){var v=e[d];if(k(y,d))s[d]=v;else{var l=m[0];if(o[l]&&k(o[l],d))s[d]=v;else{var p=e[a];if(p&&(l=m[1],o[l]&&o[l][p]&&k(o[l][p],d)))s[d]=v;else if("string"==typeof v?s[d]=c(v):t(v)?s[d]=v.map((function(t){return i(t)?n(t,r,o,!0):c(t)})):i(v)?s[d]=n(v,r,o,!0):s[d]=v,u){var b=c(d);d!==b&&(s[b]=s[d],delete s[d])}}}}return s}(e,n,o)}var z=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 B(n,t){return n}function J(n){return Object.keys(n)}function R(n,t,e){var r={};return e.O(n)&&J(n).forEach((function(t){r[t]=B(n[t])})),J(t).forEach((function(i){e.O(t[i])&&n[i]?r[i]=C(n[i],t[i],e):r[i]=B(t[i])})),r}function C(n,t,e){(e=e||{}).j=e.j,e.O=e.O||z;var r=Array.isArray(t);return r===Array.isArray(n)?r?e.j(n,t,e):R(n,t,e):B(t)}var E=C;function H(n,t,r,i){var u=n.component,a=n.v,f=n.s;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 L=!1;function P(n,t,e){return e=e||{},void 0===t.title&&delete t.title,p.forEach((function(n){if(t[n])for(var e in t[n])e in t[n]&&void 0===t[n][e]&&(k(N,e)&&!L&&(a("VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details"),L=!0),delete t[n][e])})),E(n,t,{j:function(n,t){return function(n,t,e){var r=n.component,i=n.u,o=n.v,u=n.s,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 H({component:r,v:o,s:u},c,s),void(c.template=!0);c[u]||H({component:r,v:o,s: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 V(n,t){return function n(t,i,o){o=o||{};if(i._inactive)return o;t=t||{};var u=t,a=u.t;var f=i.$metaInfo,c=i.$options,s=i.$children;if(c[a]){var v=f||c[a];if(!r(v))return o;o=P(o,v,t)}s.length&&s.forEach((function(r){(function(n){return(n=n||this)&&!e(n[d])})(r)&&(o=n(t,r,o))}));return o}(n||{},t,s)}var q=function(n,t){return(t||document).querySelectorAll(n)};function U(n,t){return n[t]||(n[t]=document.getElementsByTagName(t)[0]),n[t]}function $(n,t,e){var r=t.T,i=t.i,o=t.type,u=t.u;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 _(q(a.join(", "),n))}function F(n,t){n.removeAttribute(t)}var G=[];function Q(n,t,e,r){var i=n.u,o=!1;return e.forEach((function(n){n[i]&&n.callback&&(o=!0,function(n,t){1===arguments.length&&(t=n,n=""),G.push([n,t])}("".concat(t,"[data-").concat(i,'="').concat(n[i],'"]'),n.callback))})),r&&o?X():o}function X(){var n;"complete"!==(n||document).readyState?document.onreadystatechange=function(){Y()}:Y()}function Y(n){G.forEach((function(t){var e=t[0],r=t[1],i="".concat(e,'[onload="this.__vm_l=1"]'),o=[];n||(o=_(q(i))),n&&n.matches(i)&&(o=[n]),o.forEach((function(n){if(!n.__vm_cb){var t=function(){n.__vm_cb=!0,F(n,"onload"),r(n)};n.__vm_l?t():n.__vm_ev||(n.__vm_ev=!0,n.addEventListener("load",t))}}))}))}var Z,nn={};function tn(n,t,e,r,i){var o=(t||{}).i,u=i.getAttribute(o);u&&(nn[e]=JSON.parse(decodeURI(u)),F(i,o));var a=nn[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 v=0,l=f;v1){var l=[];r=r.filter((function(n){var t=JSON.stringify(n),e=!k(l,t);return l.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(!k(h,n))if("innerHTML"!==n)if("json"!==n)if("cssText"!==n)if("callback"!==n){var e=k(c,n)?"data-".concat(n):n,i=k(N,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=v[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 v)Array.prototype.push.apply(m,v[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 rn(n,e,r){var i=e=e||{},o=i.o,u=i.p,a={},f=U(a,"html");if(n===u&&f.hasAttribute(o)){F(f,o);var c=!1;return b.forEach((function(n){r[n]&&Q(e,n,r[n])&&(c=!0)})),c&&X(),!1}var s,d={},v={};for(var l in r)if(!k(y,l))if("title"!==l){if(k(p,l)){var m=l.substr(0,4);tn(n,e,l,r[l],U(a,m))}else if(t(r[l])){var h=en(n,e,l,r[l],U(a,"head"),U(a,"body")),g=h.oldTags,N=h.newTags;N.length&&(d[l]=N,v[l]=g)}}else((s=r.title)||""===s)&&(document.title=s);return{K:d,M:v}}function on(n,t,e){return{set:function(r){return function(n,t,e,r){if(n&&n.$el)return rn(t,e,r);(Z=Z||{})[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=p[Symbol.iterator]();!(i=(a=f.next()).done);i=!0){var c=a.value,s=c.substr(0,4);tn(t,e,c,{},U(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.i;_(q("[".concat(e,'="').concat(t,'"]'))).map((function(n){return n.remove()}))}(e,t)}Z[t]&&(delete Z[t],an())}(n,t,e)}}}function un(){return Z}function an(n){!n&&Object.keys(Z).length||(Z=void 0)}function fn(n,t){if(t=t||{},!n[d])return c(),{};var e=function(n,t,e,r){e=e||[];var i=(n=n||{}).u;return t.title&&(t.titleChunk=t.title),t.titleTemplate&&"%s"!==t.titleTemplate&&H({component:r,s:"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 H(n,t)}))),W(n,t,e)}(t,V(t,n),x,n),r=rn(n[d].T,t,e);r&&o(e.changed)&&(e.changed(e,r.K,r.M),r={addedTags:r.K,removedTags:r.M});var i=un();if(i){for(var u in i)rn(u,t,i[u]),delete i[u];an(!0)}return{vm:n,metaInfo:e,tags:r}}function cn(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.D&&(n.D=!!e.D,M(t));if(e&&"debounceWait"in e){var r=parseInt(e.m);isNaN(r)||(n.m=r)}e&&"waitOnDestroyed"in e&&(n.l=!!e.l)},refresh:function(){return fn(t,n)},inject:function(){return f("inject")},pause:function(){return w(t)},resume:function(){return K(t)},addApp:function(e){return on(t,e,n)}}}return{version:"2.3.0",install:function(n,t){n.__vuemeta_installed||(n.__vuemeta_installed=!0,t=function(n){return{t:(n=r(n)?n:{}).keyName||v.t,i:n.attribute||v.i,o:n.ssrAttribute||v.o,u:n.tagIDKeyName||v.u,s:n.contentKeyName||v.s,v:n.metaTemplateKeyName||v.v,m:e(n.debounceWait)?v.m:n.debounceWait,l:e(n.waitOnDestroyed)?v.l:n.waitOnDestroyed,p:n.ssrAppId||v.p,D:!!n.refreshOnceOnNavigation}}(t),n.prototype.$meta=function(){return cn.call(this,t)},n.mixin(function(n,t){var r=["activated","deactivated","beforeMount"];return{beforeCreate:function(){var i=this.$root,u=this.$options;if(Object.defineProperty(this,"_hasMetaInfo",{configurable:!0,get:function(){return n.config.devtools&&!i[d].S&&(a("VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead"),i[d].S=!0),T(this)}}),!e(u[t.t])&&null!==u[t.t]){if(i[d]||(i[d]={T:D},D++),!this[d]){this[d]=!0;for(var f=this.$parent;f&&f!==i;)e(f[d])&&(f[d]=!1),f=f.$parent}o(u[t.t])&&(u.computed=u.computed||{},u.computed.$metaInfo=u[t.t],this.$isServer||j(u,"created",(function(){this.$watch("$metaInfo",(function(){I(t,this.$root,"watcher")}))}))),e(i[d].h)&&(i[d].h=this.$isServer,i[d].h||(j(u,"beforeMount",(function(){var n=this.$root;n.$el&&1===n.$el.nodeType&&n.$el.hasAttribute("data-server-rendered")&&(n[d].T=t.p)})),j(u,"mounted",(function(){var n=this.$root;n[d].h||(n[d].g=!0,this.$nextTick((function(){var e=n.$meta().refresh(),r=e.tags,i=e.metaInfo;!1===r&&null===n[d].h&&this.$nextTick((function(){return I(t,n,"init")})),n[d].h=!0,delete n[d].g,!t.D&&i.afterNavigation&&M(n)})))})),t.D&&M(i))),this.$isServer||r.forEach((function(n){j(u,n,(function(){I(t,this.$root,n)}))}))}},destroyed:function(){var n=this;this.$parent&&T(this)&&this.$nextTick((function(){if(t.l&&n.$el&&n.$el.offsetParent)var e=setInterval((function(){n.$el&&null!==n.$el.offsetParent||(clearInterval(e),I(t,n.$root,"destroyed"))}),50);else I(t,n.$root,"destroyed")}))}}}(n,t)))},generate:function(n){return f("generate")},hasMetaInfo:T}})); +!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(n=n||self).VueMeta=e()}(this,(function(){"use strict";function n(e){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})(e)}function e(n){return Array.isArray(n)}function t(n){return void 0===n}function r(e){return"object"===n(e)}function i(e){return"object"===n(e)&&null!==e}function o(n){return"function"==typeof n}var u=(function(){try{return!t(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=function(){return a("This vue app/component has no vue-meta configuration")},s={title:void 0,titleChunk:"",titleTemplate:"%s",htmlAttrs:{},bodyAttrs:{},headAttrs:{},base:[],link:[],meta:[],style:[],script:[],noscript:[],__dangerouslyDisableSanitizers:[],__dangerouslyDisableSanitizersByTagID:{}},d="_vueMeta",l={t:"metaInfo",i:"data-vue-meta",o:"data-vue-meta-server-rendered",u:"vmid",s:"content",l:"template",v:!0,m:10,p:"ssr"},v=Object.keys(s),m=[v[12],v[13]],y=[v[1],v[2],"changed"].concat(m),p=[v[3],v[4],v[5]],h=["link","style","script"],b=["once","template"],g=["body","pbody"],A=["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"],I=null;function N(n,e,t){var r=n.m;e[d].h||!e[d].g&&"watcher"!==t||(e[d].h=null),e[d].h&&!e[d].A&&function(n,e){if(!(e=void 0===e?10:e))return void n();clearTimeout(I),I=setTimeout((function(){n()}),e)}((function(){e.$meta().refresh()}),r)}function O(n,e,t){if(!Array.prototype.findIndex){for(var r=0;r/g,">"],[/"/g,'"'],[/'/g,"'"]];function W(n,t,r){r=r||[];var o={j:function(n){return r.reduce((function(n,e){return n.replace(e[0],e[1])}),n)}};return m.forEach((function(n,e){if(0===e)w(t,n);else if(1===e)for(var r in t[n])w(t[n],r);o[n]=t[n]})),function n(t,r,o,u){var a=r.u,f=o.j,c=void 0===f?function(n){return n}:f,s={};for(var d in t){var l=t[d];if(j(y,d))s[d]=l;else{var v=m[0];if(o[v]&&j(o[v],d))s[d]=l;else{var p=t[a];if(p&&(v=m[1],o[v]&&o[v][p]&&j(o[v][p],d)))s[d]=l;else if("string"==typeof l?s[d]=c(l):e(l)?s[d]=l.map((function(e){return i(e)?n(e,r,o,!0):c(e)})):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}(t,n,o)}var z=function(e){return function(e){return!!e&&"object"===n(e)}(e)&&!function(n){var e=Object.prototype.toString.call(n);return"[object RegExp]"===e||"[object Date]"===e||!1}(e)};function B(n,e){return n}function J(n){return Object.keys(n)}function R(n,e,t){var r={};return t.M(n)&&J(n).forEach((function(e){r[e]=B(n[e])})),J(e).forEach((function(i){t.M(e[i])&&n[i]?r[i]=C(n[i],e[i],t):r[i]=B(e[i])})),r}function C(n,e,t){(t=t||{}).K=t.K,t.M=t.M||z;var r=Array.isArray(e);return r===Array.isArray(n)?r?t.K(n,e,t):R(n,e,t):B(e)}var E=C;function H(n,e,r,i){var u=n.component,a=n.l,f=n.s;return!0!==r&&!0!==e[a]&&(t(r)&&e[a]&&(r=e[a],e[a]=!0),r?(t(i)&&(i=e[f]),e[f]=o(r)?r.call(u,i):r.replace(/%s/g,i),!0):(delete e[a],!1))}var L=!1;function P(n,e,t){return t=t||{},void 0===e.title&&delete e.title,p.forEach((function(n){if(e[n])for(var t in e[n])t in e[n]&&void 0===e[n][t]&&(j(A,t)&&!L&&(a("VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details"),L=!0),delete e[n][t])})),E(n,e,{K:function(n,e){return function(n,e,t){var r=n.component,i=n.u,o=n.l,u=n.s,a=[];return e.length||t.length?(e.forEach((function(n,e){if(n[i]){var f=O(t,(function(e){return e[i]===n[i]})),c=t[f];if(-1!==f){if(u in c&&void 0===c[u]||"innerHTML"in c&&void 0===c.innerHTML)return a.push(n),void t.splice(f,1);if(null!==c[u]&&null!==c.innerHTML){var s=n[o];if(s){if(!c[o])return H({component:r,l:o,s:u},c,s),void(c.template=!0);c[u]||H({component:r,l:o,s:u},c,void 0,n[u])}}else t.splice(f,1)}else a.push(n)}else a.push(n)})),a.concat(t)):a}(t,n,e)}})}function $(n,e){return function n(e,i,o){o=o||{};if(i._inactive)return o;e=e||{};var u=e,a=u.t;var f=i.$metaInfo,c=i.$options,s=i.$children;if(c[a]){var l=f||c[a];r(l)&&(o=P(o,l,e))}s.length&&s.forEach((function(r){(function(n){return(n=n||this)&&!t(n[d])})(r)&&(o=n(e,r,o))}));return o}(n||{},e,s)}var q=function(n,e){return(e||document).querySelectorAll(n)};function U(n,e){return n[e]||(n[e]=document.getElementsByTagName(e)[0]),n[e]}function F(n,e,t){var r=e.O,i=e.i,o=e.type,u=e.u;t=t||{};var a=["".concat(o,"[").concat(i,'="').concat(r,'"]'),"".concat(o,"[data-").concat(u,"]")].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 T(q(a.join(", "),n))}function G(n,e){n.removeAttribute(e)}var Q=[];function X(n,e,t,r){var i=n.u,o=!1;return t.forEach((function(n){n[i]&&n.callback&&(o=!0,function(n,e){1===arguments.length&&(e=n,n=""),Q.push([n,e])}("".concat(e,"[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(e){var t=e[0],r=e[1],i="".concat(t,'[onload="this.__vm_l=1"]'),o=[];n||(o=T(q(i))),n&&n.matches(i)&&(o=[n]),o.forEach((function(n){if(!n.__vm_cb){var e=function(){n.__vm_cb=!0,G(n,"onload"),r(n)};n.__vm_l?e():n.__vm_ev||(n.__vm_ev=!0,n.addEventListener("load",e))}}))}))}var nn,en={};function tn(n,e,t,r,i){var o=(e||{}).i,u=i.getAttribute(o);u&&(en[t]=JSON.parse(decodeURI(u)),G(i,o));var a=en[t]||{},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 e=JSON.stringify(n),t=!j(v,e);return v.push(e),t}))}r.forEach((function(e){if(!e.skip){var r=document.createElement(t);r.setAttribute(a,n),Object.keys(e).forEach((function(n){if(!j(b,n))if("innerHTML"!==n)if("json"!==n)if("cssText"!==n)if("callback"!==n){var t=j(c,n)?"data-".concat(n):n,i=j(A,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 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 on(n,t,r){var i=t=t||{},o=i.o,u=i.p,a={},f=U(a,"html");if(n===u&&f.hasAttribute(o)){G(f,o);var c=!1;return h.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(!j(y,v))if("title"!==v){if(j(p,v)){var m=v.substr(0,4);tn(n,t,v,r[v],U(a,m))}else if(e(r[v])){var b=rn(n,t,v,r[v],U(a,"head"),U(a,"body")),g=b.oldTags,A=b.newTags;A.length&&(d[v]=A,l[v]=g)}}else((s=r.title)||""===s)&&(document.title=s);return{D:d,S:l}}function un(n,e,t){return{set:function(r){return function(n,e,t,r){if(n&&n.$el)return on(e,t,r);(nn=nn||{})[e]=r}(n,e,t,r)},remove:function(){return function(n,e,t){if(n&&n.$el){var r={},i=!0,o=!1,u=void 0;try{for(var a,f=p[Symbol.iterator]();!(i=(a=f.next()).done);i=!0){var c=a.value,s=c.substr(0,4);tn(e,t,c,{},U(r,s))}}catch(n){o=!0,u=n}finally{try{i||null==f.return||f.return()}finally{if(o)throw u}}return function(n,e){var t=n.i;T(q("[".concat(t,'="').concat(e,'"]'))).map((function(n){return n.remove()}))}(t,e)}nn[e]&&(delete nn[e],fn())}(n,e,t)}}}function an(){return nn}function fn(n){!n&&Object.keys(nn).length||(nn=void 0)}function cn(n,e){if(e=e||{},!n[d])return c(),{};var t=function(n,e,t,r){t=t||[];var i=(n=n||{}).u;return e.title&&(e.titleChunk=e.title),e.titleTemplate&&"%s"!==e.titleTemplate&&H({component:r,s:"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===O(t,(function(e){return e[i]===n[i]}))})),e.meta.forEach((function(e){return H(n,e)}))),W(n,e,t)}(e,$(e,n),V,n),r=on(n[d].O,e,t);r&&o(t.changed)&&(t.changed(t,r.D,r.S),r={addedTags:r.D,removedTags:r.S});var i=an();if(i){for(var u in i)on(u,e,i[u]),delete i[u];fn(!0)}return{vm:n,metaInfo:t,tags:r}}function sn(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.T&&(n.T=!!t.T,_(e));if(t&&"debounceWait"in t){var r=parseInt(t.m);isNaN(r)||(n.m=r)}t&&"waitOnDestroyed"in t&&(n.v=!!t.v)},refresh:function(){return cn(e,n)},inject:function(){return f("inject")},pause:function(){return D(e)},resume:function(){return S(e)},addApp:function(t){return un(e,t,n)}}}return{version:"2.3.1",install:function(n,e){n.__vuemeta_installed||(n.__vuemeta_installed=!0,e=function(n){return{t:(n=r(n)?n:{}).keyName||l.t,i:n.attribute||l.i,o:n.ssrAttribute||l.o,u:n.tagIDKeyName||l.u,s:n.contentKeyName||l.s,l:n.metaTemplateKeyName||l.l,m:t(n.debounceWait)?l.m:n.debounceWait,v:t(n.waitOnDestroyed)?l.v:n.waitOnDestroyed,p:n.ssrAppId||l.p,T:!!n.refreshOnceOnNavigation}}(e),n.prototype.$meta=function(){return sn.call(this,e)},n.mixin(x(n,e)))},generate:function(n,e){return f("generate")},hasMetaInfo:K}})); diff --git a/package.json b/package.json index 47009dd6..9de914a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-meta", - "version": "2.3.0", + "version": "2.3.1", "description": "Manage HTML metadata in Vue.js components with ssr support", "keywords": [ "attribute",