diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9e288c9..d6e0bde 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,37 @@
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.1.1](https://github.com/nuxt/vue-meta/compare/v2.0.3...v2.1.1) (2019-07-26)
+
+
+### Bug Fixes
+
+* add warning for v1 boolean attribute syntax ([bfeab17](https://github.com/nuxt/vue-meta/commit/bfeab17))
+* also use ssrAppId for client update ([50c0509](https://github.com/nuxt/vue-meta/commit/50c0509))
+* babel config for rollup ([71b2d52](https://github.com/nuxt/vue-meta/commit/71b2d52))
+* don't generate
tag if metaInfo.title is null or false ([#409](https://github.com/nuxt/vue-meta/issues/409)) ([39ef287](https://github.com/nuxt/vue-meta/commit/39ef287))
+* dont change title when value is undefined (fix [#396](https://github.com/nuxt/vue-meta/issues/396)) ([90f9710](https://github.com/nuxt/vue-meta/commit/90f9710))
+* dont update title on client with falsy value except empty string ([6efcdf1](https://github.com/nuxt/vue-meta/commit/6efcdf1))
+* ensure hasAttribute exists on $root.$el ([f1511ac](https://github.com/nuxt/vue-meta/commit/f1511ac))
+* only show boolean attrs with truthy value ([1d9072a](https://github.com/nuxt/vue-meta/commit/1d9072a))
+
+
+### Features
+
+* add option for prepending (no)script to body ([#410](https://github.com/nuxt/vue-meta/issues/410)) ([05163a7](https://github.com/nuxt/vue-meta/commit/05163a7))
+* auto add ssrAttribute to htmlAttrs ([9cf6d32](https://github.com/nuxt/vue-meta/commit/9cf6d32))
+* enable onload callbacks ([#414](https://github.com/nuxt/vue-meta/issues/414)) ([fc71e1f](https://github.com/nuxt/vue-meta/commit/fc71e1f))
+* make ssr app id configurable ([b0c85e5](https://github.com/nuxt/vue-meta/commit/b0c85e5))
+* support json content (without disabling sanitizers) ([#415](https://github.com/nuxt/vue-meta/issues/415)) ([51fe6ea](https://github.com/nuxt/vue-meta/commit/51fe6ea))
+
+
+### Tests
+
+* enable all getMetaInfo tests again ([24d7fee](https://github.com/nuxt/vue-meta/commit/24d7fee))
+* update browser config ([8c35863](https://github.com/nuxt/vue-meta/commit/8c35863))
+
+
+
## [2.1.0](https://github.com/nuxt/vue-meta/compare/v2.0.3...v2.1.0) (2019-07-24)
diff --git a/dist/vue-meta.common.js b/dist/vue-meta.common.js
index f92adca..03d5e07 100644
--- a/dist/vue-meta.common.js
+++ b/dist/vue-meta.common.js
@@ -1,5 +1,5 @@
/**
- * vue-meta v2.1.0
+ * vue-meta v2.1.1
* (c) 2019
* - Declan de Wet
* - Sébastien Chopin (@Atinux)
@@ -13,10 +13,10 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
var deepmerge = _interopDefault(require('deepmerge'));
-var version = "2.1.0";
+var version = "2.1.1";
// store an id to keep track of DOM updates
-let batchId = null;
+var batchId = null;
function triggerUpdate(vm, hookName) {
// if an update was triggered during initialization or when an update was triggered by the
// metaInfo watcher, set initialized to null
@@ -27,7 +27,9 @@ function triggerUpdate(vm, hookName) {
if (vm.$root._vueMeta.initialized && !vm.$root._vueMeta.paused) {
// batch potential DOM updates to prevent extraneous re-rendering
- batchUpdate(() => vm.$meta().refresh());
+ batchUpdate(function () {
+ return vm.$meta().refresh();
+ });
}
}
/**
@@ -38,14 +40,136 @@ function triggerUpdate(vm, hookName) {
* @return {Number} id - a new ID
*/
-function batchUpdate(callback, timeout = 10) {
+function batchUpdate(callback) {
+ var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
clearTimeout(batchId);
- batchId = setTimeout(() => {
+ batchId = setTimeout(function () {
callback();
}, timeout);
return batchId;
}
+function _typeof(obj) {
+ if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
+ _typeof = function (obj) {
+ return typeof obj;
+ };
+ } else {
+ _typeof = function (obj) {
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
+ };
+ }
+
+ return _typeof(obj);
+}
+
+function _defineProperty(obj, key, value) {
+ if (key in obj) {
+ Object.defineProperty(obj, key, {
+ value: value,
+ enumerable: true,
+ configurable: true,
+ writable: true
+ });
+ } else {
+ obj[key] = value;
+ }
+
+ return obj;
+}
+
+function ownKeys(object, enumerableOnly) {
+ var keys = Object.keys(object);
+
+ if (Object.getOwnPropertySymbols) {
+ var symbols = Object.getOwnPropertySymbols(object);
+ if (enumerableOnly) symbols = symbols.filter(function (sym) {
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
+ });
+ keys.push.apply(keys, symbols);
+ }
+
+ return keys;
+}
+
+function _objectSpread2(target) {
+ for (var i = 1; i < arguments.length; i++) {
+ var source = arguments[i] != null ? arguments[i] : {};
+
+ if (i % 2) {
+ ownKeys(source, true).forEach(function (key) {
+ _defineProperty(target, key, source[key]);
+ });
+ } else if (Object.getOwnPropertyDescriptors) {
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
+ } else {
+ ownKeys(source).forEach(function (key) {
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
+ });
+ }
+ }
+
+ return target;
+}
+
+function _slicedToArray(arr, i) {
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
+}
+
+function _toConsumableArray(arr) {
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
+}
+
+function _arrayWithoutHoles(arr) {
+ if (Array.isArray(arr)) {
+ for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
+
+ return arr2;
+ }
+}
+
+function _arrayWithHoles(arr) {
+ if (Array.isArray(arr)) return arr;
+}
+
+function _iterableToArray(iter) {
+ if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
+}
+
+function _iterableToArrayLimit(arr, i) {
+ var _arr = [];
+ var _n = true;
+ var _d = false;
+ var _e = undefined;
+
+ try {
+ for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
+ _arr.push(_s.value);
+
+ if (i && _arr.length === i) break;
+ }
+ } catch (err) {
+ _d = true;
+ _e = err;
+ } finally {
+ try {
+ if (!_n && _i["return"] != null) _i["return"]();
+ } finally {
+ if (_d) throw _e;
+ }
+ }
+
+ return _arr;
+}
+
+function _nonIterableSpread() {
+ throw new TypeError("Invalid attempt to spread non-iterable instance");
+}
+
+function _nonIterableRest() {
+ throw new TypeError("Invalid attempt to destructure non-iterable instance");
+}
+
/**
* checks if passed argument is an array
* @param {any} arg - the object to check
@@ -58,10 +182,10 @@ function isUndefined(arg) {
return typeof arg === 'undefined';
}
function isObject(arg) {
- return typeof arg === 'object';
+ return _typeof(arg) === 'object';
}
function isPureObject(arg) {
- return typeof arg === 'object' && arg !== null;
+ return _typeof(arg) === 'object' && arg !== null;
}
function isFunction(arg) {
return typeof arg === 'function';
@@ -86,11 +210,13 @@ function ensuredPush(object, key, el) {
object[key].push(el);
}
-function hasMetaInfo(vm = this) {
+function hasMetaInfo() {
+ var vm = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this;
return vm && (vm._vueMeta === true || isObject(vm._vueMeta));
} // a component is in a metaInfo branch when itself has meta info or one of its (grand-)children has
-function inMetaInfoBranch(vm = this) {
+function inMetaInfoBranch() {
+ var vm = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this;
return vm && !isUndefined(vm._vueMeta);
}
@@ -102,16 +228,15 @@ function addNavGuards(vm) {
}
vm.$root._vueMeta.navGuards = true;
- const $router = vm.$root.$router;
- const $meta = vm.$root.$meta();
- $router.beforeEach((to, from, next) => {
+ var $router = vm.$root.$router;
+ var $meta = vm.$root.$meta();
+ $router.beforeEach(function (to, from, next) {
$meta.pause();
next();
});
- $router.afterEach(() => {
- const {
- metaInfo
- } = $meta.resume();
+ $router.afterEach(function () {
+ var _$meta$resume = $meta.resume(),
+ metaInfo = _$meta$resume.metaInfo;
if (metaInfo && metaInfo.afterNavigation && isFunction(metaInfo.afterNavigation)) {
metaInfo.afterNavigation(metaInfo);
@@ -126,31 +251,32 @@ function hasGlobalWindowFn() {
return false;
}
}
-const hasGlobalWindow = hasGlobalWindowFn();
+var hasGlobalWindow = hasGlobalWindowFn();
-const _global = hasGlobalWindow ? window : global;
+var _global = hasGlobalWindow ? window : global;
-const console = _global.console = _global.console || {};
-function warn(...args) {
+var console = _global.console = _global.console || {};
+function warn() {
/* istanbul ignore next */
if (!console || !console.warn) {
return;
}
- console.warn(...args);
+ console.warn.apply(console, arguments);
}
-let appId = 1;
+var appId = 1;
function createMixin(Vue, options) {
// for which Vue lifecycle hooks should the metaInfo be refreshed
- const updateOnLifecycleHook = ['activated', 'deactivated', 'beforeMount']; // watch for client side component updates
+ var updateOnLifecycleHook = ['activated', 'deactivated', 'beforeMount']; // watch for client side component updates
return {
- beforeCreate() {
+ beforeCreate: function beforeCreate() {
+ var _this = this;
+
Object.defineProperty(this, '_hasMetaInfo', {
configurable: true,
-
- get() {
+ get: function get() {
// Show deprecation warning once when devtools enabled
if (Vue.config.devtools && !this.$root._vueMeta.hasMetaInfoDeprecationWarningShown) {
warn('VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead');
@@ -159,7 +285,6 @@ function createMixin(Vue, options) {
return hasMetaInfo(this);
}
-
}); // Add a marker to know if it uses metaInfo
// _vnode is used to know that it's attached to a real component
// useful if we use some mixin to add some meta tags (like nuxt-i18n)
@@ -167,7 +292,7 @@ function createMixin(Vue, options) {
if (!isUndefined(this.$options[options.keyName]) && this.$options[options.keyName] !== null) {
if (!this.$root._vueMeta) {
this.$root._vueMeta = {
- appId
+ appId: appId
};
appId++;
} // to speed up updates we keep track of branches which have a component with vue-meta info defined
@@ -176,7 +301,7 @@ function createMixin(Vue, options) {
if (!this._vueMeta) {
this._vueMeta = true;
- let p = this.$parent;
+ var p = this.$parent;
while (p && p !== this.$root) {
if (isUndefined(p._vueMeta)) {
@@ -200,8 +325,8 @@ 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(this.$options, 'created', () => {
- this.$watch('$metaInfo', function () {
+ ensuredPush(this.$options, 'created', function () {
+ _this.$watch('$metaInfo', function () {
triggerUpdate(this, 'watcher');
});
});
@@ -216,33 +341,37 @@ function createMixin(Vue, options) {
this.$root._vueMeta.initialized = this.$isServer;
if (!this.$root._vueMeta.initialized) {
- ensuredPush(this.$options, 'beforeMount', () => {
+ ensuredPush(this.$options, 'beforeMount', function () {
// if this Vue-app was server rendered, set the appId to 'ssr'
// only one SSR app per page is supported
- if (this.$root.$el && this.$root.$el.hasAttribute && this.$root.$el.hasAttribute('data-server-rendered')) {
- this.$root._vueMeta.appId = options.ssrAppId;
+ if (_this.$root.$el && _this.$root.$el.hasAttribute && _this.$root.$el.hasAttribute('data-server-rendered')) {
+ _this.$root._vueMeta.appId = options.ssrAppId;
}
}); // we use the mounted hook here as on page load
- ensuredPush(this.$options, 'mounted', () => {
- if (!this.$root._vueMeta.initialized) {
+ ensuredPush(this.$options, 'mounted', function () {
+ if (!_this.$root._vueMeta.initialized) {
// used in triggerUpdate to check if a change was triggered
// during initialization
- this.$root._vueMeta.initializing = true; // refresh meta in nextTick so all child components have loaded
+ _this.$root._vueMeta.initializing = true; // refresh meta in nextTick so all child components have loaded
- this.$nextTick(function () {
- const {
- tags,
- metaInfo
- } = this.$root.$meta().refresh(); // After ssr hydration (identifier by tags === false) check
+ _this.$nextTick(function () {
+ var _this2 = this;
+
+ var _this$$root$$meta$ref = this.$root.$meta().refresh(),
+ tags = _this$$root$$meta$ref.tags,
+ metaInfo = _this$$root$$meta$ref.metaInfo; // After ssr hydration (identifier by tags === false) check
// if initialized was set to null in triggerUpdate. That'd mean
// that during initilazation changes where triggered which need
// to be applied OR a metaInfo watcher was triggered before the
// current hook was called
// (during initialization all changes are blocked)
+
if (tags === false && this.$root._vueMeta.initialized === null) {
- this.$nextTick(() => triggerUpdate(this, 'initializing'));
+ this.$nextTick(function () {
+ return triggerUpdate(_this2, 'initializing');
+ });
}
this.$root._vueMeta.initialized = true;
@@ -265,32 +394,33 @@ function createMixin(Vue, options) {
if (!this.$isServer) {
// no need to add this hooks on server side
- updateOnLifecycleHook.forEach(lifecycleHook => {
- ensuredPush(this.$options, lifecycleHook, () => triggerUpdate(this, lifecycleHook));
+ updateOnLifecycleHook.forEach(function (lifecycleHook) {
+ ensuredPush(_this.$options, lifecycleHook, function () {
+ return triggerUpdate(_this, lifecycleHook);
+ });
}); // re-render meta data when returning from a child component to parent
- ensuredPush(this.$options, 'destroyed', () => {
+ ensuredPush(this.$options, 'destroyed', function () {
// Wait that element is hidden before refreshing meta tags (to support animations)
- const interval = setInterval(() => {
- if (this.$el && this.$el.offsetParent !== null) {
+ var interval = setInterval(function () {
+ if (_this.$el && _this.$el.offsetParent !== null) {
/* istanbul ignore next line */
return;
}
clearInterval(interval);
- if (!this.$parent) {
+ if (!_this.$parent) {
/* istanbul ignore next line */
return;
}
- triggerUpdate(this, 'destroyed');
+ triggerUpdate(_this, 'destroyed');
}, 50);
});
}
}
}
-
};
}
@@ -298,7 +428,7 @@ function createMixin(Vue, options) {
* These are constant variables used throughout the application.
*/
// set some sane defaults
-const defaultInfo = {
+var defaultInfo = {
title: undefined,
titleChunk: '',
titleTemplate: '%s',
@@ -316,58 +446,58 @@ const defaultInfo = {
// gets converted to the various meta tags & attributes for the page.
};
-const keyName = 'metaInfo'; // This is the attribute vue-meta arguments on elements to know which it should
+var keyName = 'metaInfo'; // This is the attribute vue-meta arguments on elements to know which it should
// manage and which it should ignore.
-const attribute = 'data-vue-meta'; // This is the attribute that goes on the `html` tag to inform `vue-meta`
+var attribute = 'data-vue-meta'; // This is the attribute that goes on the `html` tag to inform `vue-meta`
// that the server has already generated the meta tags for the initial render.
-const ssrAttribute = 'data-vue-meta-server-rendered'; // This is the property that tells vue-meta to overwrite (instead of append)
+var ssrAttribute = 'data-vue-meta-server-rendered'; // This is the property that tells vue-meta to overwrite (instead of append)
// an item in a tag list. For example, if you have two `meta` tag list items
// that both have `vmid` of "description", then vue-meta will overwrite the
// shallowest one with the deepest one.
-const tagIDKeyName = 'vmid'; // This is the key name for possible meta templates
+var tagIDKeyName = 'vmid'; // This is the key name for possible meta templates
-const metaTemplateKeyName = 'template'; // This is the key name for the content-holding property
+var metaTemplateKeyName = 'template'; // This is the key name for the content-holding property
-const contentKeyName = 'content'; // The id used for the ssr app
+var contentKeyName = 'content'; // The id used for the ssr app
-const ssrAppId = 'ssr';
-const defaultOptions = {
- keyName,
- attribute,
- ssrAttribute,
- tagIDKeyName,
- contentKeyName,
- metaTemplateKeyName,
- ssrAppId // List of metaInfo property keys which are configuration options (and dont generate html)
+var ssrAppId = 'ssr';
+var defaultOptions = {
+ keyName: keyName,
+ attribute: attribute,
+ ssrAttribute: ssrAttribute,
+ tagIDKeyName: tagIDKeyName,
+ contentKeyName: contentKeyName,
+ metaTemplateKeyName: metaTemplateKeyName,
+ ssrAppId: ssrAppId // List of metaInfo property keys which are configuration options (and dont generate html)
};
-const metaInfoOptionKeys = ['titleChunk', 'titleTemplate', 'changed', '__dangerouslyDisableSanitizers', '__dangerouslyDisableSanitizersByTagID']; // The metaInfo property keys which are used to disable escaping
+var metaInfoOptionKeys = ['titleChunk', 'titleTemplate', 'changed', '__dangerouslyDisableSanitizers', '__dangerouslyDisableSanitizersByTagID']; // The metaInfo property keys which are used to disable escaping
-const disableOptionKeys = ['__dangerouslyDisableSanitizers', '__dangerouslyDisableSanitizersByTagID']; // List of metaInfo property keys which only generates attributes and no tags
+var disableOptionKeys = ['__dangerouslyDisableSanitizers', '__dangerouslyDisableSanitizersByTagID']; // List of metaInfo property keys which only generates attributes and no tags
-const metaInfoAttributeKeys = ['htmlAttrs', 'headAttrs', 'bodyAttrs']; // HTML elements which support the onload event
+var metaInfoAttributeKeys = ['htmlAttrs', 'headAttrs', 'bodyAttrs']; // HTML elements which support the onload event
-const tagsSupportingOnload = ['link', 'style', 'script']; // HTML elements which dont have a head tag (shortened to our needs)
+var tagsSupportingOnload = ['link', 'style', 'script']; // HTML elements which dont have a head tag (shortened to our needs)
// see: https://www.w3.org/TR/html52/document-metadata.html
-const tagsWithoutEndTag = ['base', 'meta', 'link']; // HTML elements which can have inner content (shortened to our needs)
+var tagsWithoutEndTag = ['base', 'meta', 'link']; // HTML elements which can have inner content (shortened to our needs)
-const tagsWithInnerContent = ['noscript', 'script', 'style']; // Attributes which are inserted as childNodes instead of HTMLAttribute
+var tagsWithInnerContent = ['noscript', 'script', 'style']; // Attributes which are inserted as childNodes instead of HTMLAttribute
-const tagAttributeAsInnerContent = ['innerHTML', 'cssText', 'json']; // Attributes which should be added with data- prefix
+var tagAttributeAsInnerContent = ['innerHTML', 'cssText', 'json']; // Attributes which should be added with data- prefix
-const commonDataAttributes = ['body', 'pbody']; // from: https://github.com/kangax/html-minifier/blob/gh-pages/src/htmlminifier.js#L202
+var commonDataAttributes = ['body', 'pbody']; // from: https://github.com/kangax/html-minifier/blob/gh-pages/src/htmlminifier.js#L202
-const booleanHtmlAttributes = ['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'];
+var booleanHtmlAttributes = ['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'];
function setOptions(options) {
// combine options
options = isObject(options) ? options : {};
- for (const key in defaultOptions) {
+ for (var key in defaultOptions) {
if (!options[key]) {
options[key] = defaultOptions[key];
}
@@ -376,20 +506,24 @@ function setOptions(options) {
return options;
}
function getOptions(options) {
- const optionsCopy = {};
+ var optionsCopy = {};
- for (const key in options) {
+ for (var key in options) {
optionsCopy[key] = options[key];
}
return optionsCopy;
}
-function pause(refresh = true) {
+function pause() {
+ var refresh = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
this.$root._vueMeta.paused = true;
- return () => resume(refresh);
+ return function () {
+ return resume(refresh);
+ };
}
-function resume(refresh = true) {
+function resume() {
+ var refresh = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
this.$root._vueMeta.paused = false;
if (refresh) {
@@ -397,11 +531,11 @@ function resume(refresh = true) {
}
}
-function applyTemplate({
- component,
- metaTemplateKeyName,
- contentKeyName
-}, headObject, template, chunk) {
+function applyTemplate(_ref, headObject, template, chunk) {
+ var component = _ref.component,
+ metaTemplateKeyName = _ref.metaTemplateKeyName,
+ contentKeyName = _ref.contentKeyName;
+
if (isUndefined(template)) {
template = headObject[metaTemplateKeyName];
delete headObject[metaTemplateKeyName];
@@ -429,62 +563,40 @@ function applyTemplate({
* files in server/ still use normal js function
*/
function findIndex(array, predicate) {
- if ( !Array.prototype.findIndex) {
- // idx needs to be a Number, for..in returns string
- for (let idx = 0; idx < array.length; idx++) {
- if (predicate.call(arguments[2], array[idx], idx, array)) {
- return idx;
- }
- }
-
- return -1;
- }
return array.findIndex(predicate, arguments[2]);
}
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 (const idx in array) {
- if (array[idx] === value) {
- return true;
- }
- }
-
- return false;
- }
return array.includes(value);
}
-const serverSequences = [[/&/g, '&'], [//g, '>'], [/"/g, '"'], [/'/g, ''']];
-const clientSequences = [[/&/g, '\u0026'], [//g, '\u003E'], [/"/g, '\u0022'], [/'/g, '\u0027']]; // sanitizes potentially dangerous characters
+var serverSequences = [[/&/g, '&'], [//g, '>'], [/"/g, '"'], [/'/g, ''']];
+var clientSequences = [[/&/g, "&"], [//g, ">"], [/"/g, "\""], [/'/g, "'"]]; // sanitizes potentially dangerous characters
function escape(info, options, escapeOptions) {
- const {
- tagIDKeyName
- } = options;
- const {
- doEscape = v => v,
- escapeKeys
- } = escapeOptions;
- const escaped = {};
+ var tagIDKeyName = options.tagIDKeyName;
+ var _escapeOptions$doEsca = escapeOptions.doEscape,
+ doEscape = _escapeOptions$doEsca === void 0 ? function (v) {
+ return v;
+ } : _escapeOptions$doEsca,
+ escapeKeys = escapeOptions.escapeKeys;
+ var escaped = {};
- for (const key in info) {
- const value = info[key]; // no need to escape configuration options
+ for (var key in info) {
+ var value = info[key]; // no need to escape configuration options
if (includes(metaInfoOptionKeys, key)) {
escaped[key] = value;
continue;
}
- let [disableKey] = disableOptionKeys;
+ var _disableOptionKeys = _slicedToArray(disableOptionKeys, 1),
+ disableKey = _disableOptionKeys[0];
if (escapeOptions[disableKey] && includes(escapeOptions[disableKey], key)) {
// this info[key] doesnt need to escaped if the option is listed in __dangerouslyDisableSanitizers
@@ -492,7 +604,7 @@ function escape(info, options, escapeOptions) {
continue;
}
- const tagId = info[tagIDKeyName];
+ var tagId = info[tagIDKeyName];
if (tagId) {
disableKey = disableOptionKeys[1]; // keys which are listed in __dangerouslyDisableSanitizersByTagID for the current vmid do not need to be escaped
@@ -506,25 +618,25 @@ function escape(info, options, escapeOptions) {
if (isString(value)) {
escaped[key] = doEscape(value);
} else if (isArray(value)) {
- escaped[key] = value.map(v => {
+ escaped[key] = value.map(function (v) {
if (isPureObject(v)) {
- return escape(v, options, { ...escapeOptions,
+ return escape(v, options, _objectSpread2({}, escapeOptions, {
escapeKeys: true
- });
+ }));
}
return doEscape(v);
});
} else if (isPureObject(value)) {
- escaped[key] = escape(value, options, { ...escapeOptions,
+ escaped[key] = escape(value, options, _objectSpread2({}, escapeOptions, {
escapeKeys: true
- });
+ }));
} else {
escaped[key] = value;
}
if (escapeKeys) {
- const escapedKey = doEscape(key);
+ var escapedKey = doEscape(key);
if (key !== escapedKey) {
escaped[escapedKey] = escaped[key];
@@ -536,25 +648,26 @@ function escape(info, options, escapeOptions) {
return escaped;
}
-function arrayMerge({
- component,
- tagIDKeyName,
- metaTemplateKeyName,
- contentKeyName
-}, target, source) {
+function _arrayMerge(_ref, target, source) {
+ var component = _ref.component,
+ tagIDKeyName = _ref.tagIDKeyName,
+ metaTemplateKeyName = _ref.metaTemplateKeyName,
+ contentKeyName = _ref.contentKeyName;
// we concat the arrays without merging objects contained in,
// but we check for a `vmid` property on each object in the array
// using an O(1) lookup associative array exploit
- const destination = [];
- target.forEach((targetItem, targetIndex) => {
+ var destination = [];
+ target.forEach(function (targetItem, targetIndex) {
// no tagID so no need to check for duplicity
if (!targetItem[tagIDKeyName]) {
destination.push(targetItem);
return;
}
- const sourceIndex = findIndex(source, item => item[tagIDKeyName] === targetItem[tagIDKeyName]);
- const sourceItem = source[sourceIndex]; // source doesnt contain any duplicate vmid's, we can keep targetItem
+ var sourceIndex = findIndex(source, function (item) {
+ return item[tagIDKeyName] === targetItem[tagIDKeyName];
+ });
+ var sourceItem = source[sourceIndex]; // source doesnt contain any duplicate vmid's, we can keep targetItem
if (sourceIndex === -1) {
destination.push(targetItem);
@@ -580,33 +693,35 @@ function arrayMerge({
} // now we only need to check if the target has a template to combine it with the source
- const targetTemplate = targetItem[metaTemplateKeyName];
+ var targetTemplate = targetItem[metaTemplateKeyName];
if (!targetTemplate) {
return;
}
- const sourceTemplate = sourceItem[metaTemplateKeyName];
+ var sourceTemplate = sourceItem[metaTemplateKeyName];
if (!sourceTemplate) {
// use parent template and child content
applyTemplate({
- component,
- metaTemplateKeyName,
- contentKeyName
+ component: component,
+ metaTemplateKeyName: metaTemplateKeyName,
+ contentKeyName: contentKeyName
}, sourceItem, targetTemplate);
} else if (!sourceItem[contentKeyName]) {
// use child template and parent content
applyTemplate({
- component,
- metaTemplateKeyName,
- contentKeyName
+ component: component,
+ metaTemplateKeyName: metaTemplateKeyName,
+ contentKeyName: contentKeyName
}, sourceItem, undefined, targetItem[contentKeyName]);
}
});
return destination.concat(source);
}
-function merge(target, source, options = {}) {
+function merge(target, source) {
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
+
// remove properties explicitly set to false so child components can
// optionally _not_ overwrite the parents content
// (for array properties this is checked in arrayMerge)
@@ -614,12 +729,12 @@ function merge(target, source, options = {}) {
delete source.title;
}
- metaInfoAttributeKeys.forEach(attrKey => {
+ metaInfoAttributeKeys.forEach(function (attrKey) {
if (!source[attrKey]) {
return;
}
- for (const key in source[attrKey]) {
+ for (var key in source[attrKey]) {
if (source[attrKey].hasOwnProperty(key) && source[attrKey][key] === undefined) {
if (includes(booleanHtmlAttributes, key)) {
warn('VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details');
@@ -630,7 +745,9 @@ function merge(target, source, options = {}) {
}
});
return deepmerge(target, source, {
- arrayMerge: (t, s) => arrayMerge(options, t, s)
+ arrayMerge: function arrayMerge(t, s) {
+ return _arrayMerge(options, t, s);
+ }
});
}
@@ -649,16 +766,15 @@ function merge(target, source, options = {}) {
* @return {Object} result - final aggregated result
*/
-function getComponentOption(options = {}, component, result = {}) {
- const {
- keyName,
- metaTemplateKeyName,
- tagIDKeyName
- } = options;
- const {
- $options,
- $children
- } = component;
+function getComponentOption() {
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
+ var component = arguments.length > 1 ? arguments[1] : undefined;
+ var result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
+ var keyName = options.keyName,
+ metaTemplateKeyName = options.metaTemplateKeyName,
+ tagIDKeyName = options.tagIDKeyName;
+ var $options = component.$options,
+ $children = component.$children;
if (component._inactive) {
return result;
@@ -666,7 +782,7 @@ function getComponentOption(options = {}, component, result = {}) {
if ($options[keyName]) {
- let data = $options[keyName]; // if option is a function, replace it with it's result
+ var data = $options[keyName]; // if option is a function, replace it with it's result
if (isFunction(data)) {
data = data.call(component);
@@ -683,7 +799,7 @@ function getComponentOption(options = {}, component, result = {}) {
if ($children.length) {
- $children.forEach(childComponent => {
+ $children.forEach(function (childComponent) {
// check if the childComponent is in a branch
// return otherwise so we dont walk all component branches unnecessarily
if (!inMetaInfoBranch(childComponent)) {
@@ -696,12 +812,16 @@ function getComponentOption(options = {}, component, result = {}) {
if (metaTemplateKeyName && result.meta) {
// apply templates if needed
- result.meta.forEach(metaObject => applyTemplate(options, metaObject)); // remove meta items with duplicate vmid's
+ result.meta.forEach(function (metaObject) {
+ return applyTemplate(options, metaObject);
+ }); // remove meta items with duplicate vmid's
- result.meta = result.meta.filter((metaItem, index, arr) => {
+ result.meta = result.meta.filter(function (metaItem, index, arr) {
return (// keep meta item if it doesnt has a vmid
!metaItem.hasOwnProperty(tagIDKeyName) || // or if it's the first item in the array with this vmid
- index === findIndex(arr, item => item[tagIDKeyName] === metaItem[tagIDKeyName])
+ index === findIndex(arr, function (item) {
+ return item[tagIDKeyName] === metaItem[tagIDKeyName];
+ })
);
});
}
@@ -717,9 +837,12 @@ function getComponentOption(options = {}, component, result = {}) {
* @return {Object} - returned meta info
*/
-function getMetaInfo(options = {}, component, escapeSequences = []) {
+function getMetaInfo() {
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
+ var component = arguments.length > 1 ? arguments[1] : undefined;
+ var escapeSequences = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
// collect & aggregate all metaInfo $options
- let info = getComponentOption(options, component, defaultInfo); // Remove all "template" tags from meta
+ var info = getComponentOption(options, component, defaultInfo); // Remove all "template" tags from meta
// backup the title chunk in case user wants access to it
if (info.title) {
@@ -729,7 +852,7 @@ function getMetaInfo(options = {}, component, escapeSequences = []) {
if (info.titleTemplate && info.titleTemplate !== '%s') {
applyTemplate({
- component,
+ component: component,
contentKeyName: 'title'
}, info, info.titleTemplate, info.titleChunk || '');
} // convert base tag to an array so it can be handled the same way
@@ -740,14 +863,22 @@ function getMetaInfo(options = {}, component, escapeSequences = []) {
info.base = Object.keys(info.base).length ? [info.base] : [];
}
- const escapeOptions = {
- doEscape: value => escapeSequences.reduce((val, [v, r]) => val.replace(v, r), value)
+ var escapeOptions = {
+ doEscape: function doEscape(value) {
+ return escapeSequences.reduce(function (val, _ref) {
+ var _ref2 = _slicedToArray(_ref, 2),
+ v = _ref2[0],
+ r = _ref2[1];
+
+ return val.replace(v, r);
+ }, value);
+ }
};
- disableOptionKeys.forEach((disableKey, index) => {
+ disableOptionKeys.forEach(function (disableKey, index) {
if (index === 0) {
ensureIsArray(info, disableKey);
} else if (index === 1) {
- for (const key in info[disableKey]) {
+ for (var key in info[disableKey]) {
ensureIsArray(info[disableKey], key);
}
}
@@ -766,23 +897,22 @@ function getTag(tags, tag) {
return tags[tag];
}
-function getElementsKey({
- body,
- pbody
-}) {
+function getElementsKey(_ref) {
+ var body = _ref.body,
+ pbody = _ref.pbody;
return body ? 'body' : pbody ? 'pbody' : 'head';
}
-function queryElements(parentNode, {
- appId,
- attribute,
- type,
- tagIDKeyName
-}, attributes = {}) {
- const queries = [`${type}[${attribute}="${appId}"]`, `${type}[data-${tagIDKeyName}]`].map(query => {
- for (const key in attributes) {
- const val = attributes[key];
- const attributeValue = val && val !== true ? `="${val}"` : '';
- query += `[data-${key}${attributeValue}]`;
+function queryElements(parentNode, _ref2) {
+ var appId = _ref2.appId,
+ attribute = _ref2.attribute,
+ type = _ref2.type,
+ tagIDKeyName = _ref2.tagIDKeyName;
+ var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
+ var queries = ["".concat(type, "[").concat(attribute, "=\"").concat(appId, "\"]"), "".concat(type, "[data-").concat(tagIDKeyName, "]")].map(function (query) {
+ for (var key in attributes) {
+ var val = attributes[key];
+ var attributeValue = val && val !== true ? "=\"".concat(val, "\"") : '';
+ query += "[data-".concat(key).concat(attributeValue, "]");
}
return query;
@@ -790,8 +920,9 @@ function queryElements(parentNode, {
return toArray(parentNode.querySelectorAll(queries.join(', ')));
}
-const callbacks = [];
-function isDOMComplete(d = document) {
+var callbacks = [];
+function isDOMComplete() {
+ var d = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
return d.readyState === 'complete';
}
function addCallback(query, callback) {
@@ -802,18 +933,37 @@ function addCallback(query, callback) {
callbacks.push([query, callback]);
}
-function addCallbacks({
- tagIDKeyName
-}, type, tags, autoAddListeners) {
- let hasAsyncCallback = false;
+function addCallbacks(_ref, type, tags, autoAddListeners) {
+ var tagIDKeyName = _ref.tagIDKeyName;
+ var hasAsyncCallback = false;
+ var _iteratorNormalCompletion = true;
+ var _didIteratorError = false;
+ var _iteratorError = undefined;
- for (const tag of tags) {
- if (!tag[tagIDKeyName] || !tag.callback) {
- continue;
+ try {
+ for (var _iterator = tags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
+ var tag = _step.value;
+
+ if (!tag[tagIDKeyName] || !tag.callback) {
+ continue;
+ }
+
+ hasAsyncCallback = true;
+ addCallback("".concat(type, "[data-").concat(tagIDKeyName, "=\"").concat(tag[tagIDKeyName], "\"]"), tag.callback);
+ }
+ } catch (err) {
+ _didIteratorError = true;
+ _iteratorError = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
+ _iterator.return();
+ }
+ } finally {
+ if (_didIteratorError) {
+ throw _iteratorError;
+ }
}
-
- hasAsyncCallback = true;
- addCallback(`${type}[data-${tagIDKeyName}="${tag[tagIDKeyName]}"]`, tag.callback);
}
if (!autoAddListeners || !hasAsyncCallback) {
@@ -831,14 +981,18 @@ function addListeners() {
/* istanbul ignore next */
- document.onreadystatechange = () => {
+ document.onreadystatechange = function () {
applyCallbacks();
};
}
function applyCallbacks(matchElement) {
- for (const [query, callback] of callbacks) {
- const selector = `${query}[onload="this.__vm_l=1"]`;
- let elements = [];
+ var _loop = function _loop() {
+ var _callbacks$_i = _slicedToArray(_callbacks[_i], 2),
+ query = _callbacks$_i[0],
+ callback = _callbacks$_i[1];
+
+ var selector = "".concat(query, "[onload=\"this.__vm_l=1\"]");
+ var elements = [];
if (!matchElement) {
elements = toArray(document.querySelectorAll(selector));
@@ -848,47 +1002,78 @@ function applyCallbacks(matchElement) {
elements = [matchElement];
}
- for (const element of elements) {
- /* __vm_cb: whether the load callback has been called
- * __vm_l: set by onload attribute, whether the element was loaded
- * __vm_ev: whether the event listener was added or not
- */
- if (element.__vm_cb) {
- continue;
- }
+ var _iteratorNormalCompletion2 = true;
+ var _didIteratorError2 = false;
+ var _iteratorError2 = undefined;
- const onload = () => {
- /* Mark that the callback for this element has already been called,
- * this prevents the callback to run twice in some (rare) conditions
+ try {
+ var _loop2 = function _loop2() {
+ var element = _step2.value;
+
+ /* __vm_cb: whether the load callback has been called
+ * __vm_l: set by onload attribute, whether the element was loaded
+ * __vm_ev: whether the event listener was added or not
*/
- element.__vm_cb = true;
- /* onload needs to be removed because we only need the
- * attribute after ssr and if we dont remove it the node
- * will fail isEqualNode on the client
+ if (element.__vm_cb) {
+ return "continue";
+ }
+
+ var onload = function onload() {
+ /* Mark that the callback for this element has already been called,
+ * this prevents the callback to run twice in some (rare) conditions
+ */
+ element.__vm_cb = true;
+ /* onload needs to be removed because we only need the
+ * attribute after ssr and if we dont remove it the node
+ * will fail isEqualNode on the client
+ */
+
+ element.removeAttribute('onload');
+ callback(element);
+ };
+ /* IE9 doesnt seem to load scripts synchronously,
+ * causing a script sometimes/often already to be loaded
+ * when we add the event listener below (thus adding an onload event
+ * listener has no use because it will never be triggered).
+ * Therefore we add the onload attribute during ssr, and
+ * check here if it was already loaded or not
*/
- element.removeAttribute('onload');
- callback(element);
+
+ if (element.__vm_l) {
+ onload();
+ return "continue";
+ }
+
+ if (!element.__vm_ev) {
+ element.__vm_ev = true;
+ element.addEventListener('load', onload);
+ }
};
- /* IE9 doesnt seem to load scripts synchronously,
- * causing a script sometimes/often already to be loaded
- * when we add the event listener below (thus adding an onload event
- * listener has no use because it will never be triggered).
- * Therefore we add the onload attribute during ssr, and
- * check here if it was already loaded or not
- */
+ for (var _iterator2 = elements[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
+ var _ret = _loop2();
- if (element.__vm_l) {
- onload();
- continue;
+ if (_ret === "continue") continue;
}
-
- if (!element.__vm_ev) {
- element.__vm_ev = true;
- element.addEventListener('load', onload);
+ } catch (err) {
+ _didIteratorError2 = true;
+ _iteratorError2 = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
+ _iterator2.return();
+ }
+ } finally {
+ if (_didIteratorError2) {
+ throw _iteratorError2;
+ }
}
}
+ };
+
+ for (var _i = 0, _callbacks = callbacks; _i < _callbacks.length; _i++) {
+ _loop();
}
}
@@ -899,17 +1084,20 @@ function applyCallbacks(matchElement) {
* @param {HTMLElement} tag - the HTMLElement tag to update with new attrs
*/
-function updateAttribute({
- attribute
-} = {}, attrs, tag) {
- const vueMetaAttrString = tag.getAttribute(attribute);
- const vueMetaAttrs = vueMetaAttrString ? vueMetaAttrString.split(',') : [];
- const toRemove = toArray(vueMetaAttrs);
- const keepIndexes = [];
+function updateAttribute() {
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
+ attribute = _ref.attribute;
- for (const attr in attrs) {
+ var attrs = arguments.length > 1 ? arguments[1] : undefined;
+ var tag = arguments.length > 2 ? arguments[2] : undefined;
+ var vueMetaAttrString = tag.getAttribute(attribute);
+ var vueMetaAttrs = vueMetaAttrString ? vueMetaAttrString.split(',') : [];
+ var toRemove = toArray(vueMetaAttrs);
+ var keepIndexes = [];
+
+ for (var attr in attrs) {
if (attrs.hasOwnProperty(attr)) {
- const value = includes(booleanHtmlAttributes, attr) ? '' : isArray(attrs[attr]) ? attrs[attr].join(' ') : attrs[attr];
+ var value = includes(booleanHtmlAttributes, attr) ? '' : isArray(attrs[attr]) ? attrs[attr].join(' ') : attrs[attr];
tag.setAttribute(attr, value || '');
if (!includes(vueMetaAttrs, attr)) {
@@ -921,7 +1109,9 @@ function updateAttribute({
}
}
- const removedAttributesCount = toRemove.filter((el, index) => !includes(keepIndexes, index)).reduce((acc, attr) => {
+ var removedAttributesCount = toRemove.filter(function (el, index) {
+ return !includes(keepIndexes, index);
+ }).reduce(function (acc, attr) {
tag.removeAttribute(attr);
return acc + 1;
}, 0);
@@ -955,20 +1145,23 @@ function updateTitle(title) {
* @return {Object} - a representation of what tags changed
*/
-function updateTag(appId, options = {}, type, tags, head, body) {
- const {
- attribute,
- tagIDKeyName
- } = options;
- const dataAttributes = [tagIDKeyName, ...commonDataAttributes];
- const newElements = [];
- const queryOptions = {
- appId,
- attribute,
- type,
- tagIDKeyName
+function updateTag(appId) {
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+ var type = arguments.length > 2 ? arguments[2] : undefined;
+ var tags = arguments.length > 3 ? arguments[3] : undefined;
+ var head = arguments.length > 4 ? arguments[4] : undefined;
+ var body = arguments.length > 5 ? arguments[5] : undefined;
+ var attribute = options.attribute,
+ tagIDKeyName = options.tagIDKeyName;
+ var dataAttributes = [tagIDKeyName].concat(_toConsumableArray(commonDataAttributes));
+ var newElements = [];
+ var queryOptions = {
+ appId: appId,
+ attribute: attribute,
+ type: type,
+ tagIDKeyName: tagIDKeyName
};
- const currentElements = {
+ var currentElements = {
head: queryElements(head, queryOptions),
pbody: queryElements(body, queryOptions, {
pbody: true
@@ -982,109 +1175,148 @@ function updateTag(appId, options = {}, type, tags, head, body) {
// remove duplicates that could have been found by merging tags
// which include a mixin with metaInfo and that mixin is used
// by multiple components on the same page
- const found = [];
- tags = tags.filter(x => {
- const k = JSON.stringify(x);
- const res = !includes(found, k);
+ var found = [];
+ tags = tags.filter(function (x) {
+ var k = JSON.stringify(x);
+ var res = !includes(found, k);
found.push(k);
return res;
});
}
if (tags.length) {
- for (const tag of tags) {
- if (tag.skip) {
- continue;
- }
+ var _iteratorNormalCompletion = true;
+ var _didIteratorError = false;
+ var _iteratorError = undefined;
- const newElement = document.createElement(type);
- newElement.setAttribute(attribute, appId);
+ try {
+ var _loop = function _loop() {
+ var tag = _step.value;
- for (const attr in tag) {
- /* istanbul ignore next */
- if (!tag.hasOwnProperty(attr)) {
- continue;
+ if (tag.skip) {
+ return "continue";
}
- if (attr === 'innerHTML') {
- newElement.innerHTML = tag.innerHTML;
- continue;
- }
+ var newElement = document.createElement(type);
+ newElement.setAttribute(attribute, appId);
- if (attr === 'json') {
- newElement.innerHTML = JSON.stringify(tag.json);
- continue;
- }
-
- if (attr === 'cssText') {
- if (newElement.styleSheet) {
- /* istanbul ignore next */
- newElement.styleSheet.cssText = tag.cssText;
- } else {
- newElement.appendChild(document.createTextNode(tag.cssText));
+ var _loop2 = function _loop2(attr) {
+ /* istanbul ignore next */
+ if (!tag.hasOwnProperty(attr)) {
+ return "continue";
}
- continue;
+ if (attr === 'innerHTML') {
+ newElement.innerHTML = tag.innerHTML;
+ return "continue";
+ }
+
+ if (attr === 'json') {
+ newElement.innerHTML = JSON.stringify(tag.json);
+ return "continue";
+ }
+
+ if (attr === 'cssText') {
+ if (newElement.styleSheet) {
+ /* istanbul ignore next */
+ newElement.styleSheet.cssText = tag.cssText;
+ } else {
+ newElement.appendChild(document.createTextNode(tag.cssText));
+ }
+
+ return "continue";
+ }
+
+ if (attr === 'callback') {
+ newElement.onload = function () {
+ return tag[attr](newElement);
+ };
+
+ return "continue";
+ }
+
+ var _attr = includes(dataAttributes, attr) ? "data-".concat(attr) : attr;
+
+ var isBooleanAttribute = includes(booleanHtmlAttributes, attr);
+
+ if (isBooleanAttribute && !tag[attr]) {
+ return "continue";
+ }
+
+ var value = isBooleanAttribute ? '' : tag[attr];
+ newElement.setAttribute(_attr, value);
+ };
+
+ for (var attr in tag) {
+ var _ret2 = _loop2(attr);
+
+ if (_ret2 === "continue") continue;
}
- if (attr === 'callback') {
- newElement.onload = () => tag[attr](newElement);
+ var oldElements = currentElements[getElementsKey(tag)]; // Remove a duplicate tag from domTagstoRemove, so it isn't cleared.
- continue;
+ var indexToDelete = void 0;
+ var hasEqualElement = oldElements.some(function (existingTag, index) {
+ indexToDelete = index;
+ return newElement.isEqualNode(existingTag);
+ });
+
+ if (hasEqualElement && (indexToDelete || indexToDelete === 0)) {
+ oldElements.splice(indexToDelete, 1);
+ } else {
+ newElements.push(newElement);
}
+ };
- const _attr = includes(dataAttributes, attr) ? `data-${attr}` : attr;
+ for (var _iterator = tags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
+ var _ret = _loop();
- const isBooleanAttribute = includes(booleanHtmlAttributes, attr);
-
- if (isBooleanAttribute && !tag[attr]) {
- continue;
- }
-
- const value = isBooleanAttribute ? '' : tag[attr];
- newElement.setAttribute(_attr, value);
+ if (_ret === "continue") continue;
}
-
- const oldElements = currentElements[getElementsKey(tag)]; // Remove a duplicate tag from domTagstoRemove, so it isn't cleared.
-
- let indexToDelete;
- const hasEqualElement = oldElements.some((existingTag, index) => {
- indexToDelete = index;
- return newElement.isEqualNode(existingTag);
- });
-
- if (hasEqualElement && (indexToDelete || indexToDelete === 0)) {
- oldElements.splice(indexToDelete, 1);
- } else {
- newElements.push(newElement);
+ } catch (err) {
+ _didIteratorError = true;
+ _iteratorError = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
+ _iterator.return();
+ }
+ } finally {
+ if (_didIteratorError) {
+ throw _iteratorError;
+ }
}
}
}
- let oldElements = [];
+ var oldElements = [];
- for (const current of Object.values(currentElements)) {
- oldElements = [...oldElements, ...current];
+ for (var _i = 0, _Object$values = Object.values(currentElements); _i < _Object$values.length; _i++) {
+ var current = _Object$values[_i];
+ oldElements = [].concat(_toConsumableArray(oldElements), _toConsumableArray(current));
} // remove old elements
- for (const element of oldElements) {
+ for (var _i2 = 0, _oldElements = oldElements; _i2 < _oldElements.length; _i2++) {
+ var element = _oldElements[_i2];
element.parentNode.removeChild(element);
} // insert new elements
- for (const element of newElements) {
- if (element.hasAttribute('data-body')) {
- body.appendChild(element);
+ for (var _i3 = 0, _newElements = newElements; _i3 < _newElements.length; _i3++) {
+ var _element = _newElements[_i3];
+
+ if (_element.hasAttribute('data-body')) {
+ body.appendChild(_element);
continue;
}
- if (element.hasAttribute('data-pbody')) {
- body.insertBefore(element, body.firstChild);
+ if (_element.hasAttribute('data-pbody')) {
+ body.insertBefore(_element, body.firstChild);
continue;
}
- head.appendChild(element);
+ head.appendChild(_element);
}
return {
@@ -1099,24 +1331,44 @@ function updateTag(appId, options = {}, type, tags, head, body) {
* @param {Object} newInfo - the meta info to update to
*/
-function updateClientMetaInfo(appId, options = {}, newInfo) {
- const {
- ssrAttribute,
- ssrAppId
- } = options; // only cache tags for current update
+function updateClientMetaInfo(appId) {
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+ var newInfo = arguments.length > 2 ? arguments[2] : undefined;
+ var ssrAttribute = options.ssrAttribute,
+ ssrAppId = options.ssrAppId; // only cache tags for current update
- const tags = {};
- const htmlTag = getTag(tags, 'html'); // if this is a server render, then dont update
+ var tags = {};
+ var htmlTag = getTag(tags, 'html'); // if this is a server render, then dont update
if (appId === ssrAppId && htmlTag.hasAttribute(ssrAttribute)) {
// remove the server render attribute so we can update on (next) changes
htmlTag.removeAttribute(ssrAttribute); // add load callbacks if the
- let addLoadListeners = false;
+ var addLoadListeners = false;
+ var _iteratorNormalCompletion = true;
+ var _didIteratorError = false;
+ var _iteratorError = undefined;
- for (const type of tagsSupportingOnload) {
- if (newInfo[type] && addCallbacks(options, type, newInfo[type])) {
- addLoadListeners = true;
+ try {
+ for (var _iterator = tagsSupportingOnload[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
+ var type = _step.value;
+
+ if (newInfo[type] && addCallbacks(options, type, newInfo[type])) {
+ addLoadListeners = true;
+ }
+ }
+ } catch (err) {
+ _didIteratorError = true;
+ _iteratorError = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
+ _iterator.return();
+ }
+ } finally {
+ if (_didIteratorError) {
+ throw _iteratorError;
+ }
}
}
@@ -1128,50 +1380,52 @@ function updateClientMetaInfo(appId, options = {}, newInfo) {
} // initialize tracked changes
- const addedTags = {};
- const removedTags = {};
+ var addedTags = {};
+ var removedTags = {};
- for (const type in newInfo) {
+ for (var _type in newInfo) {
// ignore these
- if (includes(metaInfoOptionKeys, type)) {
+ if (includes(metaInfoOptionKeys, _type)) {
continue;
}
- if (type === 'title') {
+ if (_type === 'title') {
// update the title
updateTitle(newInfo.title);
continue;
}
- if (includes(metaInfoAttributeKeys, type)) {
- const tagName = type.substr(0, 4);
- updateAttribute(options, newInfo[type], getTag(tags, tagName));
+ if (includes(metaInfoAttributeKeys, _type)) {
+ var tagName = _type.substr(0, 4);
+
+ updateAttribute(options, newInfo[_type], getTag(tags, tagName));
continue;
} // tags should always be an array, ignore if it isnt
- if (!isArray(newInfo[type])) {
+ if (!isArray(newInfo[_type])) {
continue;
}
- const {
- oldTags,
- newTags
- } = updateTag(appId, options, type, newInfo[type], getTag(tags, 'head'), getTag(tags, 'body'));
+ var _updateTag = updateTag(appId, options, _type, newInfo[_type], getTag(tags, 'head'), getTag(tags, 'body')),
+ oldTags = _updateTag.oldTags,
+ newTags = _updateTag.newTags;
if (newTags.length) {
- addedTags[type] = newTags;
- removedTags[type] = oldTags;
+ addedTags[_type] = newTags;
+ removedTags[_type] = oldTags;
}
}
return {
- addedTags,
- removedTags
+ addedTags: addedTags,
+ removedTags: removedTags
};
}
-function _refresh(options = {}) {
+function _refresh() {
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
+
/**
* When called, will update the current meta info with new meta info.
* Useful when updating meta info as the result of an asynchronous
@@ -1183,9 +1437,9 @@ function _refresh(options = {}) {
* @return {Object} - new meta info
*/
return function refresh() {
- const metaInfo = getMetaInfo(options, this.$root, clientSequences);
- const appId = this.$root._vueMeta.appId;
- const tags = updateClientMetaInfo(appId, options, metaInfo); // emit "event" with new info
+ var metaInfo = getMetaInfo(options, this.$root, clientSequences);
+ var appId = this.$root._vueMeta.appId;
+ var tags = updateClientMetaInfo(appId, options, metaInfo); // emit "event" with new info
if (tags && isFunction(metaInfo.changed)) {
metaInfo.changed(metaInfo, tags.addedTags, tags.removedTags);
@@ -1193,8 +1447,8 @@ function _refresh(options = {}) {
return {
vm: this,
- metaInfo,
- tags
+ metaInfo: metaInfo,
+ tags: tags
};
};
}
@@ -1207,34 +1461,36 @@ function _refresh(options = {}) {
* @return {Object} - the attribute generator
*/
-function attributeGenerator({
- attribute,
- ssrAttribute
-} = {}, type, data) {
- return {
- text(addSrrAttribute) {
- let attributeStr = '';
- const watchedAttrs = [];
+function attributeGenerator() {
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
+ attribute = _ref.attribute,
+ ssrAttribute = _ref.ssrAttribute;
- for (const attr in data) {
+ var type = arguments.length > 1 ? arguments[1] : undefined;
+ var data = arguments.length > 2 ? arguments[2] : undefined;
+ return {
+ text: function text(addSrrAttribute) {
+ var attributeStr = '';
+ var watchedAttrs = [];
+
+ for (var attr in data) {
if (data.hasOwnProperty(attr)) {
watchedAttrs.push(attr);
- attributeStr += isUndefined(data[attr]) || booleanHtmlAttributes.includes(attr) ? attr : `${attr}="${isArray(data[attr]) ? data[attr].join(' ') : data[attr]}"`;
+ attributeStr += isUndefined(data[attr]) || booleanHtmlAttributes.includes(attr) ? attr : "".concat(attr, "=\"").concat(isArray(data[attr]) ? data[attr].join(' ') : data[attr], "\"");
attributeStr += ' ';
}
}
if (attributeStr) {
- attributeStr += `${attribute}="${watchedAttrs.sort().join(',')}"`;
+ attributeStr += "".concat(attribute, "=\"").concat(watchedAttrs.sort().join(','), "\"");
}
if (type === 'htmlAttrs' && addSrrAttribute) {
- return `${ssrAttribute}${attributeStr ? ' ' : ''}${attributeStr}`;
+ return "".concat(ssrAttribute).concat(attributeStr ? ' ' : '').concat(attributeStr);
}
return attributeStr;
}
-
};
}
@@ -1245,18 +1501,20 @@ function attributeGenerator({
* @param {String} data - the title text
* @return {Object} - the title generator
*/
-function titleGenerator({
- attribute
-} = {}, type, data) {
+function titleGenerator() {
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
+ attribute = _ref.attribute;
+
+ var type = arguments.length > 1 ? arguments[1] : undefined;
+ var data = arguments.length > 2 ? arguments[2] : undefined;
return {
- text() {
+ text: function text() {
if (!data) {
return '';
}
- return `<${type}>${data}${type}>`;
+ return "<".concat(type, ">").concat(data, "").concat(type, ">");
}
-
};
}
@@ -1268,24 +1526,30 @@ function titleGenerator({
* @return {Object} - the tag generator
*/
-function tagGenerator({
- ssrAppId,
- attribute,
- tagIDKeyName
-} = {}, type, tags) {
- const dataAttributes = [tagIDKeyName, 'callback', ...commonDataAttributes];
+function tagGenerator() {
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
+ ssrAppId = _ref.ssrAppId,
+ attribute = _ref.attribute,
+ tagIDKeyName = _ref.tagIDKeyName;
+
+ var type = arguments.length > 1 ? arguments[1] : undefined;
+ var tags = arguments.length > 2 ? arguments[2] : undefined;
+ var dataAttributes = [tagIDKeyName, 'callback'].concat(_toConsumableArray(commonDataAttributes));
return {
- text({
- body = false,
- pbody = false
- } = {}) {
+ text: function text() {
+ var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
+ _ref2$body = _ref2.body,
+ body = _ref2$body === void 0 ? false : _ref2$body,
+ _ref2$pbody = _ref2.pbody,
+ pbody = _ref2$pbody === void 0 ? false : _ref2$pbody;
+
// build a string containing all tags of this type
- return tags.reduce((tagsStr, tag) => {
+ return tags.reduce(function (tagsStr, tag) {
if (tag.skip) {
return tagsStr;
}
- const tagKeys = Object.keys(tag);
+ var tagKeys = Object.keys(tag);
if (tagKeys.length === 0) {
return tagsStr; // Bail on empty tag object
@@ -1295,53 +1559,52 @@ function tagGenerator({
return tagsStr;
}
- let attrs = tag.once ? '' : ` ${attribute}="${ssrAppId}"`; // build a string containing all attributes of this tag
+ var attrs = tag.once ? '' : " ".concat(attribute, "=\"").concat(ssrAppId, "\""); // build a string containing all attributes of this tag
- for (const attr in tag) {
+ for (var attr in tag) {
// these attributes are treated as children on the tag
if (tagAttributeAsInnerContent.includes(attr) || attr === 'once') {
continue;
} // these form the attribute list for this tag
- let prefix = '';
+ var prefix = '';
if (dataAttributes.includes(attr)) {
prefix = 'data-';
}
if (attr === 'callback') {
- attrs += ` onload="this.__vm_l=1"`;
+ attrs += " onload=\"this.__vm_l=1\"";
continue;
}
- const isBooleanAttr = !prefix && booleanHtmlAttributes.includes(attr);
+ var isBooleanAttr = !prefix && booleanHtmlAttributes.includes(attr);
if (isBooleanAttr && !tag[attr]) {
continue;
}
- attrs += ` ${prefix}${attr}` + (isBooleanAttr ? '' : `="${tag[attr]}"`);
+ attrs += " ".concat(prefix).concat(attr) + (isBooleanAttr ? '' : "=\"".concat(tag[attr], "\""));
}
- let json = '';
+ var json = '';
if (tag.json) {
json = JSON.stringify(tag.json);
} // grab child content from one of these attributes, if possible
- const content = tag.innerHTML || tag.cssText || json; // generate tag exactly without any other redundant attribute
+ var content = tag.innerHTML || tag.cssText || json; // generate tag exactly without any other redundant attribute
// these tags have no end tag
- const hasEndTag = !tagsWithoutEndTag.includes(type); // these tag types will have content inserted
+ var hasEndTag = !tagsWithoutEndTag.includes(type); // these tag types will have content inserted
- const hasContent = hasEndTag && tagsWithInnerContent.includes(type); // the final string for this specific tag
+ var hasContent = hasEndTag && tagsWithInnerContent.includes(type); // the final string for this specific tag
- return `${tagsStr}<${type}${attrs}${!hasContent && hasEndTag ? '/' : ''}>` + (hasContent ? `${content}${type}>` : '');
+ return "".concat(tagsStr, "<").concat(type).concat(attrs).concat(!hasContent && hasEndTag ? '/' : '', ">") + (hasContent ? "".concat(content, "").concat(type, ">") : '');
}, '');
}
-
};
}
@@ -1365,7 +1628,9 @@ function generateServerInjector(options, type, data) {
return tagGenerator(options, type, data);
}
-function _inject(options = {}) {
+function _inject() {
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
+
/**
* Converts the state of the meta info object such that each item
* can be compiled to a tag string on the server
@@ -1375,9 +1640,9 @@ function _inject(options = {}) {
*/
return function inject() {
// get meta info with sensible defaults
- const metaInfo = getMetaInfo(options, this.$root, serverSequences); // generate server injectors
+ var metaInfo = getMetaInfo(options, this.$root, serverSequences); // generate server injectors
- for (const key in metaInfo) {
+ for (var key in metaInfo) {
if (!metaInfoOptionKeys.includes(key) && metaInfo.hasOwnProperty(key)) {
metaInfo[key] = generateServerInjector(options, key, metaInfo[key]);
}
@@ -1387,10 +1652,12 @@ function _inject(options = {}) {
};
}
-function _$meta(options = {}) {
- const _refresh$1 = _refresh(options);
+function _$meta() {
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- const _inject$1 = _inject(options);
+ var _refresh$1 = _refresh(options);
+
+ var _inject$1 = _inject(options);
/**
* Returns an injector for server-side rendering.
* @this {Object} - the Vue instance (a root component)
@@ -1400,7 +1667,9 @@ function _$meta(options = {}) {
return function $meta() {
return {
- getOptions: () => getOptions(options),
+ getOptions: function getOptions$1() {
+ return getOptions(options);
+ },
refresh: _refresh$1.bind(this),
inject: _inject$1.bind(this),
pause: pause.bind(this),
@@ -1414,7 +1683,9 @@ function _$meta(options = {}) {
* @param {Function} Vue - the Vue constructor.
*/
-function install(Vue, options = {}) {
+function install(Vue) {
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+
if (Vue.__vuemeta_installed) {
return;
}
@@ -1426,9 +1697,9 @@ function install(Vue, options = {}) {
}
var index = {
- version,
- install,
- hasMetaInfo
+ version: version,
+ install: install,
+ hasMetaInfo: hasMetaInfo
};
module.exports = index;
diff --git a/dist/vue-meta.esm.browser.js b/dist/vue-meta.esm.browser.js
index 09d4d9a..6116f55 100644
--- a/dist/vue-meta.esm.browser.js
+++ b/dist/vue-meta.esm.browser.js
@@ -1,5 +1,5 @@
/**
- * vue-meta v2.1.0
+ * vue-meta v2.1.1
* (c) 2019
* - Declan de Wet
* - Sébastien Chopin (@Atinux)
@@ -9,12 +9,11 @@
import deepmerge from 'deepmerge';
-var version = "2.1.0";
+var version = "2.1.1";
// store an id to keep track of DOM updates
-let batchId = null;
-
-function triggerUpdate (vm, hookName) {
+var batchId = null;
+function triggerUpdate(vm, hookName) {
// if an update was triggered during initialization or when an update was triggered by the
// metaInfo watcher, set initialized to null
// then we keep falsy value but know we need to run a triggerUpdate after initialization
@@ -24,10 +23,11 @@ function triggerUpdate (vm, hookName) {
if (vm.$root._vueMeta.initialized && !vm.$root._vueMeta.paused) {
// batch potential DOM updates to prevent extraneous re-rendering
- batchUpdate(() => vm.$meta().refresh());
+ batchUpdate(function () {
+ return vm.$meta().refresh();
+ });
}
}
-
/**
* Performs a batched update.
*
@@ -35,14 +35,135 @@ function triggerUpdate (vm, hookName) {
* @param {Function} callback - the update to perform
* @return {Number} id - a new ID
*/
-function batchUpdate (callback, timeout = 10) {
- clearTimeout(batchId);
- batchId = setTimeout(() => {
+function batchUpdate(callback) {
+ var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
+ clearTimeout(batchId);
+ batchId = setTimeout(function () {
callback();
}, timeout);
+ return batchId;
+}
- return batchId
+function _typeof(obj) {
+ if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
+ _typeof = function (obj) {
+ return typeof obj;
+ };
+ } else {
+ _typeof = function (obj) {
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
+ };
+ }
+
+ return _typeof(obj);
+}
+
+function _defineProperty(obj, key, value) {
+ if (key in obj) {
+ Object.defineProperty(obj, key, {
+ value: value,
+ enumerable: true,
+ configurable: true,
+ writable: true
+ });
+ } else {
+ obj[key] = value;
+ }
+
+ return obj;
+}
+
+function ownKeys(object, enumerableOnly) {
+ var keys = Object.keys(object);
+
+ if (Object.getOwnPropertySymbols) {
+ var symbols = Object.getOwnPropertySymbols(object);
+ if (enumerableOnly) symbols = symbols.filter(function (sym) {
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
+ });
+ keys.push.apply(keys, symbols);
+ }
+
+ return keys;
+}
+
+function _objectSpread2(target) {
+ for (var i = 1; i < arguments.length; i++) {
+ var source = arguments[i] != null ? arguments[i] : {};
+
+ if (i % 2) {
+ ownKeys(source, true).forEach(function (key) {
+ _defineProperty(target, key, source[key]);
+ });
+ } else if (Object.getOwnPropertyDescriptors) {
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
+ } else {
+ ownKeys(source).forEach(function (key) {
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
+ });
+ }
+ }
+
+ return target;
+}
+
+function _slicedToArray(arr, i) {
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
+}
+
+function _toConsumableArray(arr) {
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
+}
+
+function _arrayWithoutHoles(arr) {
+ if (Array.isArray(arr)) {
+ for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
+
+ return arr2;
+ }
+}
+
+function _arrayWithHoles(arr) {
+ if (Array.isArray(arr)) return arr;
+}
+
+function _iterableToArray(iter) {
+ if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
+}
+
+function _iterableToArrayLimit(arr, i) {
+ var _arr = [];
+ var _n = true;
+ var _d = false;
+ var _e = undefined;
+
+ try {
+ for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
+ _arr.push(_s.value);
+
+ if (i && _arr.length === i) break;
+ }
+ } catch (err) {
+ _d = true;
+ _e = err;
+ } finally {
+ try {
+ if (!_n && _i["return"] != null) _i["return"]();
+ } finally {
+ if (_d) throw _e;
+ }
+ }
+
+ return _arr;
+}
+
+function _nonIterableSpread() {
+ throw new TypeError("Invalid attempt to spread non-iterable instance");
+}
+
+function _nonIterableRest() {
+ throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
/**
@@ -50,265 +171,263 @@ function batchUpdate (callback, timeout = 10) {
* @param {any} arg - the object to check
* @return {Boolean} - true if `arg` is an array
*/
-function isArray (arg) {
- return Array.isArray(arg)
+function isArray(arg) {
+ return Array.isArray(arg);
+}
+function isUndefined(arg) {
+ return typeof arg === 'undefined';
+}
+function isObject(arg) {
+ return _typeof(arg) === 'object';
+}
+function isPureObject(arg) {
+ return _typeof(arg) === 'object' && arg !== null;
+}
+function isFunction(arg) {
+ return typeof arg === 'function';
+}
+function isString(arg) {
+ return typeof arg === 'string';
}
-function isUndefined (arg) {
- return typeof arg === 'undefined'
-}
-
-function isObject (arg) {
- return typeof arg === 'object'
-}
-
-function isPureObject (arg) {
- return typeof arg === 'object' && arg !== null
-}
-
-function isFunction (arg) {
- return typeof arg === 'function'
-}
-
-function isString (arg) {
- return typeof arg === 'string'
-}
-
-function ensureIsArray (arg, key) {
+function ensureIsArray(arg, key) {
if (!key || !isObject(arg)) {
- return isArray(arg) ? arg : []
+ return isArray(arg) ? arg : [];
}
if (!isArray(arg[key])) {
arg[key] = [];
}
- return arg
+
+ return arg;
}
-
-function ensuredPush (object, key, el) {
+function ensuredPush(object, key, el) {
ensureIsArray(object, key);
-
object[key].push(el);
}
-// Vue $root instance has a _vueMeta object property, otherwise its a boolean true
-function hasMetaInfo (vm = this) {
- return vm && (vm._vueMeta === true || isObject(vm._vueMeta))
+function hasMetaInfo() {
+ var vm = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this;
+ return vm && (vm._vueMeta === true || isObject(vm._vueMeta));
+} // a component is in a metaInfo branch when itself has meta info or one of its (grand-)children has
+
+function inMetaInfoBranch() {
+ var vm = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this;
+ return vm && !isUndefined(vm._vueMeta);
}
-// a component is in a metaInfo branch when itself has meta info or one of its (grand-)children has
-function inMetaInfoBranch (vm = this) {
- return vm && !isUndefined(vm._vueMeta)
-}
-
-function addNavGuards (vm) {
+function addNavGuards(vm) {
// return when nav guards already added or no router exists
if (vm.$root._vueMeta.navGuards || !vm.$root.$router) {
/* istanbul ignore next */
- return
+ return;
}
vm.$root._vueMeta.navGuards = true;
-
- const $router = vm.$root.$router;
- const $meta = vm.$root.$meta();
-
- $router.beforeEach((to, from, next) => {
+ var $router = vm.$root.$router;
+ var $meta = vm.$root.$meta();
+ $router.beforeEach(function (to, from, next) {
$meta.pause();
next();
});
+ $router.afterEach(function () {
+ var _$meta$resume = $meta.resume(),
+ metaInfo = _$meta$resume.metaInfo;
- $router.afterEach(() => {
- const { metaInfo } = $meta.resume();
if (metaInfo && metaInfo.afterNavigation && isFunction(metaInfo.afterNavigation)) {
metaInfo.afterNavigation(metaInfo);
}
});
}
-function hasGlobalWindowFn () {
+function hasGlobalWindowFn() {
try {
- return !isUndefined(window)
+ return !isUndefined(window);
} catch (e) {
- return false
+ return false;
}
}
+var hasGlobalWindow = hasGlobalWindowFn();
-const hasGlobalWindow = hasGlobalWindowFn();
+var _global = hasGlobalWindow ? window : global;
-const _global = hasGlobalWindow ? window : global;
-
-const console = (_global.console = _global.console || {});
-
-function warn (...args) {
+var console = _global.console = _global.console || {};
+function warn() {
/* istanbul ignore next */
if (!console || !console.warn) {
- return
+ return;
}
- console.warn(...args);
+ console.warn.apply(console, arguments);
}
+var showWarningNotSupported = function showWarningNotSupported() {
+ return warn('This vue app/component has no vue-meta configuration');
+};
-const showWarningNotSupported = () => warn('This vue app/component has no vue-meta configuration');
-
-let appId = 1;
-
-function createMixin (Vue, options) {
+var appId = 1;
+function createMixin(Vue, options) {
// for which Vue lifecycle hooks should the metaInfo be refreshed
- const updateOnLifecycleHook = ['activated', 'deactivated', 'beforeMount'];
+ var updateOnLifecycleHook = ['activated', 'deactivated', 'beforeMount']; // watch for client side component updates
- // watch for client side component updates
return {
- beforeCreate () {
+ beforeCreate: function beforeCreate() {
+ var _this = this;
+
Object.defineProperty(this, '_hasMetaInfo', {
configurable: true,
- get () {
+ get: function get() {
// Show deprecation warning once when devtools enabled
if (Vue.config.devtools && !this.$root._vueMeta.hasMetaInfoDeprecationWarningShown) {
warn('VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead');
this.$root._vueMeta.hasMetaInfoDeprecationWarningShown = true;
}
- return hasMetaInfo(this)
- }
- });
- // Add a marker to know if it uses metaInfo
+ return hasMetaInfo(this);
+ }
+ }); // Add a marker to know if it uses metaInfo
// _vnode is used to know that it's attached to a real component
// useful if we use some mixin to add some meta tags (like nuxt-i18n)
+
if (!isUndefined(this.$options[options.keyName]) && this.$options[options.keyName] !== null) {
if (!this.$root._vueMeta) {
- this.$root._vueMeta = { appId };
+ this.$root._vueMeta = {
+ appId: appId
+ };
appId++;
- }
-
- // to speed up updates we keep track of branches which have a component with vue-meta info defined
+ } // 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
+
+
if (!this._vueMeta) {
this._vueMeta = true;
+ var p = this.$parent;
- let p = this.$parent;
while (p && p !== this.$root) {
if (isUndefined(p._vueMeta)) {
p._vueMeta = false;
}
+
p = p.$parent;
}
- }
-
- // coerce function-style metaInfo to a computed prop so we can observe
+ } // coerce function-style metaInfo to a computed prop so we can observe
// it on creation
+
+
if (isFunction(this.$options[options.keyName])) {
if (!this.$options.computed) {
this.$options.computed = {};
}
+
this.$options.computed.$metaInfo = this.$options[options.keyName];
if (!this.$isServer) {
// 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(this.$options, 'created', () => {
- this.$watch('$metaInfo', function () {
+ ensuredPush(this.$options, 'created', function () {
+ _this.$watch('$metaInfo', function () {
triggerUpdate(this, 'watcher');
});
});
}
- }
-
- // force an initial refresh on page load and prevent other lifecycleHooks
+ } // force an initial refresh on page load and prevent other lifecycleHooks
// to triggerUpdate until this initial refresh is finished
// this is to make sure that when a page is opened in an inactive tab which
// has throttled rAF/timers we still immediately set the page title
+
+
if (isUndefined(this.$root._vueMeta.initialized)) {
this.$root._vueMeta.initialized = this.$isServer;
if (!this.$root._vueMeta.initialized) {
- ensuredPush(this.$options, 'beforeMount', () => {
+ ensuredPush(this.$options, 'beforeMount', function () {
// if this Vue-app was server rendered, set the appId to 'ssr'
// only one SSR app per page is supported
- if (this.$root.$el && this.$root.$el.hasAttribute && this.$root.$el.hasAttribute('data-server-rendered')) {
- this.$root._vueMeta.appId = options.ssrAppId;
+ if (_this.$root.$el && _this.$root.$el.hasAttribute && _this.$root.$el.hasAttribute('data-server-rendered')) {
+ _this.$root._vueMeta.appId = options.ssrAppId;
}
- });
+ }); // we use the mounted hook here as on page load
- // we use the mounted hook here as on page load
- ensuredPush(this.$options, 'mounted', () => {
- if (!this.$root._vueMeta.initialized) {
+ ensuredPush(this.$options, 'mounted', function () {
+ if (!_this.$root._vueMeta.initialized) {
// used in triggerUpdate to check if a change was triggered
// during initialization
- this.$root._vueMeta.initializing = true;
+ _this.$root._vueMeta.initializing = true; // refresh meta in nextTick so all child components have loaded
- // refresh meta in nextTick so all child components have loaded
- this.$nextTick(function () {
- const { tags, metaInfo } = this.$root.$meta().refresh();
+ _this.$nextTick(function () {
+ var _this2 = this;
- // After ssr hydration (identifier by tags === false) check
+ var _this$$root$$meta$ref = this.$root.$meta().refresh(),
+ tags = _this$$root$$meta$ref.tags,
+ metaInfo = _this$$root$$meta$ref.metaInfo; // After ssr hydration (identifier by tags === false) check
// if initialized was set to null in triggerUpdate. That'd mean
// that during initilazation changes where triggered which need
// to be applied OR a metaInfo watcher was triggered before the
// current hook was called
// (during initialization all changes are blocked)
+
+
if (tags === false && this.$root._vueMeta.initialized === null) {
- this.$nextTick(() => triggerUpdate(this, 'initializing'));
+ this.$nextTick(function () {
+ return triggerUpdate(_this2, 'initializing');
+ });
}
this.$root._vueMeta.initialized = true;
- delete this.$root._vueMeta.initializing;
-
- // add the navigation guards if they havent been added yet
+ delete this.$root._vueMeta.initializing; // add the navigation guards if they havent been added yet
// they are needed for the afterNavigation callback
+
if (!options.refreshOnceOnNavigation && metaInfo.afterNavigation) {
addNavGuards(this);
}
});
}
- });
+ }); // add the navigation guards if requested
- // add the navigation guards if requested
if (options.refreshOnceOnNavigation) {
addNavGuards(this);
}
}
- }
+ } // do not trigger refresh on the server side
+
- // do not trigger refresh on the server side
if (!this.$isServer) {
// no need to add this hooks on server side
- updateOnLifecycleHook.forEach((lifecycleHook) => {
- ensuredPush(this.$options, lifecycleHook, () => triggerUpdate(this, lifecycleHook));
- });
+ updateOnLifecycleHook.forEach(function (lifecycleHook) {
+ ensuredPush(_this.$options, lifecycleHook, function () {
+ return triggerUpdate(_this, lifecycleHook);
+ });
+ }); // re-render meta data when returning from a child component to parent
- // re-render meta data when returning from a child component to parent
- ensuredPush(this.$options, 'destroyed', () => {
+ ensuredPush(this.$options, 'destroyed', function () {
// Wait that element is hidden before refreshing meta tags (to support animations)
- const interval = setInterval(() => {
- if (this.$el && this.$el.offsetParent !== null) {
+ var interval = setInterval(function () {
+ if (_this.$el && _this.$el.offsetParent !== null) {
/* istanbul ignore next line */
- return
+ return;
}
clearInterval(interval);
- if (!this.$parent) {
+ if (!_this.$parent) {
/* istanbul ignore next line */
- return
+ return;
}
- triggerUpdate(this, 'destroyed');
+ triggerUpdate(_this, 'destroyed');
}, 50);
});
}
}
}
- }
+ };
}
/**
* These are constant variables used throughout the application.
*/
-
// set some sane defaults
-const defaultInfo = {
+var defaultInfo = {
title: undefined,
titleChunk: '',
titleTemplate: '%s',
@@ -322,175 +441,109 @@ const defaultInfo = {
script: [],
noscript: [],
__dangerouslyDisableSanitizers: [],
- __dangerouslyDisableSanitizersByTagID: {}
+ __dangerouslyDisableSanitizersByTagID: {} // This is the name of the component option that contains all the information that
+ // gets converted to the various meta tags & attributes for the page.
+
};
-
-// This is the name of the component option that contains all the information that
-// gets converted to the various meta tags & attributes for the page.
-const keyName = 'metaInfo';
-
-// This is the attribute vue-meta arguments on elements to know which it should
+var keyName = 'metaInfo'; // This is the attribute vue-meta arguments on elements to know which it should
// manage and which it should ignore.
-const attribute = 'data-vue-meta';
-// This is the attribute that goes on the `html` tag to inform `vue-meta`
+var attribute = 'data-vue-meta'; // This is the attribute that goes on the `html` tag to inform `vue-meta`
// that the server has already generated the meta tags for the initial render.
-const ssrAttribute = 'data-vue-meta-server-rendered';
-// This is the property that tells vue-meta to overwrite (instead of append)
+var ssrAttribute = 'data-vue-meta-server-rendered'; // This is the property that tells vue-meta to overwrite (instead of append)
// an item in a tag list. For example, if you have two `meta` tag list items
// that both have `vmid` of "description", then vue-meta will overwrite the
// shallowest one with the deepest one.
-const tagIDKeyName = 'vmid';
-// This is the key name for possible meta templates
-const metaTemplateKeyName = 'template';
+var tagIDKeyName = 'vmid'; // This is the key name for possible meta templates
-// This is the key name for the content-holding property
-const contentKeyName = 'content';
+var metaTemplateKeyName = 'template'; // This is the key name for the content-holding property
-// The id used for the ssr app
-const ssrAppId = 'ssr';
+var contentKeyName = 'content'; // The id used for the ssr app
+
+var ssrAppId = 'ssr';
+var defaultOptions = {
+ keyName: keyName,
+ attribute: attribute,
+ ssrAttribute: ssrAttribute,
+ tagIDKeyName: tagIDKeyName,
+ contentKeyName: contentKeyName,
+ metaTemplateKeyName: metaTemplateKeyName,
+ ssrAppId: ssrAppId // List of metaInfo property keys which are configuration options (and dont generate html)
-const defaultOptions = {
- keyName,
- attribute,
- ssrAttribute,
- tagIDKeyName,
- contentKeyName,
- metaTemplateKeyName,
- ssrAppId
};
+var metaInfoOptionKeys = ['titleChunk', 'titleTemplate', 'changed', '__dangerouslyDisableSanitizers', '__dangerouslyDisableSanitizersByTagID']; // The metaInfo property keys which are used to disable escaping
-// List of metaInfo property keys which are configuration options (and dont generate html)
-const metaInfoOptionKeys = [
- 'titleChunk',
- 'titleTemplate',
- 'changed',
- '__dangerouslyDisableSanitizers',
- '__dangerouslyDisableSanitizersByTagID'
-];
+var disableOptionKeys = ['__dangerouslyDisableSanitizers', '__dangerouslyDisableSanitizersByTagID']; // List of metaInfo property keys which only generates attributes and no tags
-// The metaInfo property keys which are used to disable escaping
-const disableOptionKeys = [
- '__dangerouslyDisableSanitizers',
- '__dangerouslyDisableSanitizersByTagID'
-];
+var metaInfoAttributeKeys = ['htmlAttrs', 'headAttrs', 'bodyAttrs']; // HTML elements which support the onload event
-// List of metaInfo property keys which only generates attributes and no tags
-const metaInfoAttributeKeys = [
- 'htmlAttrs',
- 'headAttrs',
- 'bodyAttrs'
-];
+var tagsSupportingOnload = ['link', 'style', 'script']; // HTML elements which dont have a head tag (shortened to our needs)
-// HTML elements which support the onload event
-const tagsSupportingOnload = ['link', 'style', 'script'];
+var commonDataAttributes = ['body', 'pbody']; // from: https://github.com/kangax/html-minifier/blob/gh-pages/src/htmlminifier.js#L202
-// Attributes which should be added with data- prefix
-const commonDataAttributes = ['body', 'pbody'];
+var booleanHtmlAttributes = ['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'];
-// from: https://github.com/kangax/html-minifier/blob/gh-pages/src/htmlminifier.js#L202
-const booleanHtmlAttributes = [
- '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'
-];
-
-function setOptions (options) {
+function setOptions(options) {
// combine options
options = isObject(options) ? options : {};
- for (const key in defaultOptions) {
+ for (var key in defaultOptions) {
if (!options[key]) {
options[key] = defaultOptions[key];
}
}
- return options
+ return options;
}
+function getOptions(options) {
+ var optionsCopy = {};
-function getOptions (options) {
- const optionsCopy = {};
- for (const key in options) {
+ for (var key in options) {
optionsCopy[key] = options[key];
}
- return optionsCopy
+
+ return optionsCopy;
}
-function pause (refresh = true) {
+function pause() {
+ var refresh = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
this.$root._vueMeta.paused = true;
-
- return () => resume(refresh)
+ return function () {
+ return resume(refresh);
+ };
}
-
-function resume (refresh = true) {
+function resume() {
+ var refresh = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
this.$root._vueMeta.paused = false;
if (refresh) {
- return this.$root.$meta().refresh()
+ return this.$root.$meta().refresh();
}
}
-function applyTemplate ({ component, metaTemplateKeyName, contentKeyName }, headObject, template, chunk) {
+function applyTemplate(_ref, headObject, template, chunk) {
+ var component = _ref.component,
+ metaTemplateKeyName = _ref.metaTemplateKeyName,
+ contentKeyName = _ref.contentKeyName;
+
if (isUndefined(template)) {
template = headObject[metaTemplateKeyName];
delete headObject[metaTemplateKeyName];
- }
+ } // return early if no template defined
+
- // return early if no template defined
if (!template) {
- return false
+ return false;
}
if (isUndefined(chunk)) {
chunk = headObject[contentKeyName];
}
- headObject[contentKeyName] = isFunction(template)
- ? template.call(component, chunk)
- : template.replace(/%s/g, chunk);
-
- return true
+ headObject[contentKeyName] = isFunction(template) ? template.call(component, chunk) : template.replace(/%s/g, chunk);
+ return true;
}
/*
@@ -501,78 +554,81 @@ function applyTemplate ({ component, metaTemplateKeyName, contentKeyName }, head
* Also, only files in client/ & shared/ should use these functions
* files in server/ still use normal js function
*/
+function findIndex(array, predicate) {
-function findIndex (array, predicate) {
- return array.findIndex(predicate, arguments[2])
+ return array.findIndex(predicate, arguments[2]);
+}
+function toArray(arg) {
+
+ return Array.from(arg);
+}
+function includes(array, value) {
+
+ return array.includes(value);
}
-function toArray (arg) {
- return Array.from(arg)
-}
+var clientSequences = [[/&/g, "&"], [//g, ">"], [/"/g, "\""], [/'/g, "'"]]; // sanitizes potentially dangerous characters
-function includes (array, value) {
- return array.includes(value)
-}
+function escape(info, options, escapeOptions) {
+ var tagIDKeyName = options.tagIDKeyName;
+ var _escapeOptions$doEsca = escapeOptions.doEscape,
+ doEscape = _escapeOptions$doEsca === void 0 ? function (v) {
+ return v;
+ } : _escapeOptions$doEsca,
+ escapeKeys = escapeOptions.escapeKeys;
+ var escaped = {};
-const clientSequences = [
- [/&/g, '\u0026'],
- [//g, '\u003E'],
- [/"/g, '\u0022'],
- [/'/g, '\u0027']
-];
+ for (var key in info) {
+ var value = info[key]; // no need to escape configuration options
-// sanitizes potentially dangerous characters
-function escape (info, options, escapeOptions) {
- const { tagIDKeyName } = options;
- const { doEscape = v => v, escapeKeys } = escapeOptions;
- const escaped = {};
-
- for (const key in info) {
- const value = info[key];
-
- // no need to escape configuration options
if (includes(metaInfoOptionKeys, key)) {
escaped[key] = value;
- continue
+ continue;
}
- let [ disableKey ] = disableOptionKeys;
+ var _disableOptionKeys = _slicedToArray(disableOptionKeys, 1),
+ disableKey = _disableOptionKeys[0];
+
if (escapeOptions[disableKey] && includes(escapeOptions[disableKey], key)) {
// this info[key] doesnt need to escaped if the option is listed in __dangerouslyDisableSanitizers
escaped[key] = value;
- continue
+ continue;
}
- const tagId = info[tagIDKeyName];
+ var tagId = info[tagIDKeyName];
+
if (tagId) {
- disableKey = disableOptionKeys[1];
+ disableKey = disableOptionKeys[1]; // keys which are listed in __dangerouslyDisableSanitizersByTagID for the current vmid do not need to be escaped
- // keys which are listed in __dangerouslyDisableSanitizersByTagID for the current vmid do not need to be escaped
if (escapeOptions[disableKey] && escapeOptions[disableKey][tagId] && includes(escapeOptions[disableKey][tagId], key)) {
escaped[key] = value;
- continue
+ continue;
}
}
if (isString(value)) {
escaped[key] = doEscape(value);
} else if (isArray(value)) {
- escaped[key] = value.map((v) => {
+ escaped[key] = value.map(function (v) {
if (isPureObject(v)) {
- return escape(v, options, { ...escapeOptions, escapeKeys: true })
+ return escape(v, options, _objectSpread2({}, escapeOptions, {
+ escapeKeys: true
+ }));
}
- return doEscape(v)
+ return doEscape(v);
});
} else if (isPureObject(value)) {
- escaped[key] = escape(value, options, { ...escapeOptions, escapeKeys: true });
+ escaped[key] = escape(value, options, _objectSpread2({}, escapeOptions, {
+ escapeKeys: true
+ }));
} else {
escaped[key] = value;
}
if (escapeKeys) {
- const escapedKey = doEscape(key);
+ var escapedKey = doEscape(key);
+
if (key !== escapedKey) {
escaped[escapedKey] = escaped[key];
delete escaped[key];
@@ -580,72 +636,83 @@ function escape (info, options, escapeOptions) {
}
}
- return escaped
+ return escaped;
}
-function arrayMerge ({ component, tagIDKeyName, metaTemplateKeyName, contentKeyName }, target, source) {
+function _arrayMerge(_ref, target, source) {
+ var component = _ref.component,
+ tagIDKeyName = _ref.tagIDKeyName,
+ metaTemplateKeyName = _ref.metaTemplateKeyName,
+ contentKeyName = _ref.contentKeyName;
// we concat the arrays without merging objects contained in,
// but we check for a `vmid` property on each object in the array
// using an O(1) lookup associative array exploit
- const destination = [];
-
- target.forEach((targetItem, targetIndex) => {
+ var destination = [];
+ target.forEach(function (targetItem, targetIndex) {
// no tagID so no need to check for duplicity
if (!targetItem[tagIDKeyName]) {
destination.push(targetItem);
- return
+ return;
}
- const sourceIndex = findIndex(source, item => item[tagIDKeyName] === targetItem[tagIDKeyName]);
- const sourceItem = source[sourceIndex];
+ var sourceIndex = findIndex(source, function (item) {
+ return item[tagIDKeyName] === targetItem[tagIDKeyName];
+ });
+ var sourceItem = source[sourceIndex]; // source doesnt contain any duplicate vmid's, we can keep targetItem
- // source doesnt contain any duplicate vmid's, we can keep targetItem
if (sourceIndex === -1) {
destination.push(targetItem);
- return
- }
-
- // when sourceItem explictly defines contentKeyName or innerHTML as undefined, its
+ return;
+ } // when sourceItem explictly defines contentKeyName or innerHTML as undefined, its
// an indication that we need to skip the default behaviour or child has preference over parent
// which means we keep the targetItem and ignore/remove the sourceItem
- if ((sourceItem.hasOwnProperty(contentKeyName) && sourceItem[contentKeyName] === undefined) ||
- (sourceItem.hasOwnProperty('innerHTML') && sourceItem.innerHTML === undefined)) {
- destination.push(targetItem);
- // remove current index from source array so its not concatenated to destination below
+
+
+ if (sourceItem.hasOwnProperty(contentKeyName) && sourceItem[contentKeyName] === undefined || sourceItem.hasOwnProperty('innerHTML') && sourceItem.innerHTML === undefined) {
+ destination.push(targetItem); // remove current index from source array so its not concatenated to destination below
+
source.splice(sourceIndex, 1);
- return
- }
-
- // we now know that targetItem is a duplicate and we should ignore it in favor of sourceItem
-
+ return;
+ } // we now know that targetItem is a duplicate and we should ignore it in favor of sourceItem
// if source specifies null as content then ignore both the target as the source
+
+
if (sourceItem[contentKeyName] === null || sourceItem.innerHTML === null) {
// remove current index from source array so its not concatenated to destination below
source.splice(sourceIndex, 1);
- return
- }
+ return;
+ } // now we only need to check if the target has a template to combine it with the source
+
+
+ var targetTemplate = targetItem[metaTemplateKeyName];
- // now we only need to check if the target has a template to combine it with the source
- const targetTemplate = targetItem[metaTemplateKeyName];
if (!targetTemplate) {
- return
+ return;
}
- const sourceTemplate = sourceItem[metaTemplateKeyName];
+ var sourceTemplate = sourceItem[metaTemplateKeyName];
if (!sourceTemplate) {
// use parent template and child content
- applyTemplate({ component, metaTemplateKeyName, contentKeyName }, sourceItem, targetTemplate);
+ applyTemplate({
+ component: component,
+ metaTemplateKeyName: metaTemplateKeyName,
+ contentKeyName: contentKeyName
+ }, sourceItem, targetTemplate);
} else if (!sourceItem[contentKeyName]) {
// use child template and parent content
- applyTemplate({ component, metaTemplateKeyName, contentKeyName }, sourceItem, undefined, targetItem[contentKeyName]);
+ applyTemplate({
+ component: component,
+ metaTemplateKeyName: metaTemplateKeyName,
+ contentKeyName: contentKeyName
+ }, sourceItem, undefined, targetItem[contentKeyName]);
}
});
-
- return destination.concat(source)
+ return destination.concat(source);
}
+function merge(target, source) {
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
-function merge (target, source, options = {}) {
// remove properties explicitly set to false so child components can
// optionally _not_ overwrite the parents content
// (for array properties this is checked in arrayMerge)
@@ -653,24 +720,26 @@ function merge (target, source, options = {}) {
delete source.title;
}
- metaInfoAttributeKeys.forEach((attrKey) => {
+ metaInfoAttributeKeys.forEach(function (attrKey) {
if (!source[attrKey]) {
- return
+ return;
}
- for (const key in source[attrKey]) {
+ for (var key in source[attrKey]) {
if (source[attrKey].hasOwnProperty(key) && source[attrKey][key] === undefined) {
if (includes(booleanHtmlAttributes, key)) {
warn('VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details');
}
+
delete source[attrKey][key];
}
}
});
-
return deepmerge(target, source, {
- arrayMerge: (t, s) => arrayMerge(options, t, s)
- })
+ arrayMerge: function arrayMerge(t, s) {
+ return _arrayMerge(options, t, s);
+ }
+ });
}
/**
@@ -687,39 +756,45 @@ function merge (target, source, options = {}) {
* @param {Object} [result={}] - result so far
* @return {Object} result - final aggregated result
*/
-function getComponentOption (options = {}, component, result = {}) {
- const { keyName, metaTemplateKeyName, tagIDKeyName } = options;
- const { $options, $children } = component;
+
+function getComponentOption() {
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
+ var component = arguments.length > 1 ? arguments[1] : undefined;
+ var result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
+ var keyName = options.keyName,
+ metaTemplateKeyName = options.metaTemplateKeyName,
+ tagIDKeyName = options.tagIDKeyName;
+ var $options = component.$options,
+ $children = component.$children;
if (component._inactive) {
- return result
- }
+ return result;
+ } // only collect option data if it exists
+
- // only collect option data if it exists
if ($options[keyName]) {
- let data = $options[keyName];
+ var data = $options[keyName]; // if option is a function, replace it with it's result
- // if option is a function, replace it with it's result
if (isFunction(data)) {
data = data.call(component);
- }
+ } // ignore data if its not an object, then we keep our previous result
+
- // ignore data if its not an object, then we keep our previous result
if (!isObject(data)) {
- return result
- }
+ return result;
+ } // merge with existing options
+
- // merge with existing options
result = merge(result, data, options);
- }
+ } // collect & aggregate child options if deep = true
+
- // collect & aggregate child options if deep = true
if ($children.length) {
- $children.forEach((childComponent) => {
+ $children.forEach(function (childComponent) {
// check if the childComponent is in a branch
// return otherwise so we dont walk all component branches unnecessarily
if (!inMetaInfoBranch(childComponent)) {
- return
+ return;
}
result = getComponentOption(options, childComponent, result);
@@ -728,20 +803,21 @@ function getComponentOption (options = {}, component, result = {}) {
if (metaTemplateKeyName && result.meta) {
// apply templates if needed
- result.meta.forEach(metaObject => applyTemplate(options, metaObject));
+ result.meta.forEach(function (metaObject) {
+ return applyTemplate(options, metaObject);
+ }); // remove meta items with duplicate vmid's
- // remove meta items with duplicate vmid's
- result.meta = result.meta.filter((metaItem, index, arr) => {
- return (
- // keep meta item if it doesnt has a vmid
- !metaItem.hasOwnProperty(tagIDKeyName) ||
- // or if it's the first item in the array with this vmid
- index === findIndex(arr, item => item[tagIDKeyName] === metaItem[tagIDKeyName])
- )
+ result.meta = result.meta.filter(function (metaItem, index, arr) {
+ return (// keep meta item if it doesnt has a vmid
+ !metaItem.hasOwnProperty(tagIDKeyName) || // or if it's the first item in the array with this vmid
+ index === findIndex(arr, function (item) {
+ return item[tagIDKeyName] === metaItem[tagIDKeyName];
+ })
+ );
});
}
- return result
+ return result;
}
/**
@@ -751,132 +827,164 @@ function getComponentOption (options = {}, component, result = {}) {
* @param {Object} component - the Vue instance to get meta info from
* @return {Object} - returned meta info
*/
-function getMetaInfo (options = {}, component, escapeSequences = []) {
+
+function getMetaInfo() {
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
+ var component = arguments.length > 1 ? arguments[1] : undefined;
+ var escapeSequences = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
// collect & aggregate all metaInfo $options
- let info = getComponentOption(options, component, defaultInfo);
-
- // Remove all "template" tags from meta
-
+ var info = getComponentOption(options, component, defaultInfo); // Remove all "template" tags from meta
// backup the title chunk in case user wants access to it
+
if (info.title) {
info.titleChunk = info.title;
- }
+ } // replace title with populated template
+
- // replace title with populated template
if (info.titleTemplate && info.titleTemplate !== '%s') {
- applyTemplate({ component, contentKeyName: 'title' }, info, info.titleTemplate, info.titleChunk || '');
- }
-
- // convert base tag to an array so it can be handled the same way
+ applyTemplate({
+ component: component,
+ contentKeyName: 'title'
+ }, info, info.titleTemplate, info.titleChunk || '');
+ } // convert base tag to an array so it can be handled the same way
// as the other tags
+
+
if (info.base) {
info.base = Object.keys(info.base).length ? [info.base] : [];
}
- const escapeOptions = {
- doEscape: value => escapeSequences.reduce((val, [v, r]) => val.replace(v, r), value)
- };
+ var escapeOptions = {
+ doEscape: function doEscape(value) {
+ return escapeSequences.reduce(function (val, _ref) {
+ var _ref2 = _slicedToArray(_ref, 2),
+ v = _ref2[0],
+ r = _ref2[1];
- disableOptionKeys.forEach((disableKey, index) => {
+ return val.replace(v, r);
+ }, value);
+ }
+ };
+ disableOptionKeys.forEach(function (disableKey, index) {
if (index === 0) {
ensureIsArray(info, disableKey);
} else if (index === 1) {
- for (const key in info[disableKey]) {
+ for (var key in info[disableKey]) {
ensureIsArray(info[disableKey], key);
}
}
escapeOptions[disableKey] = info[disableKey];
- });
+ }); // begin sanitization
- // begin sanitization
info = escape(info, options, escapeOptions);
-
- return info
+ return info;
}
-function getTag (tags, tag) {
+function getTag(tags, tag) {
if (!tags[tag]) {
tags[tag] = document.getElementsByTagName(tag)[0];
}
- return tags[tag]
+ return tags[tag];
}
-
-function getElementsKey ({ body, pbody }) {
- return body
- ? 'body'
- : (pbody ? 'pbody' : 'head')
+function getElementsKey(_ref) {
+ var body = _ref.body,
+ pbody = _ref.pbody;
+ return body ? 'body' : pbody ? 'pbody' : 'head';
}
-
-function queryElements (parentNode, { appId, attribute, type, tagIDKeyName }, attributes = {}) {
- const queries = [
- `${type}[${attribute}="${appId}"]`,
- `${type}[data-${tagIDKeyName}]`
- ].map((query) => {
- for (const key in attributes) {
- const val = attributes[key];
- const attributeValue = val && val !== true ? `="${val}"` : '';
- query += `[data-${key}${attributeValue}]`;
+function queryElements(parentNode, _ref2) {
+ var appId = _ref2.appId,
+ attribute = _ref2.attribute,
+ type = _ref2.type,
+ tagIDKeyName = _ref2.tagIDKeyName;
+ var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
+ var queries = ["".concat(type, "[").concat(attribute, "=\"").concat(appId, "\"]"), "".concat(type, "[data-").concat(tagIDKeyName, "]")].map(function (query) {
+ for (var key in attributes) {
+ var val = attributes[key];
+ var attributeValue = val && val !== true ? "=\"".concat(val, "\"") : '';
+ query += "[data-".concat(key).concat(attributeValue, "]");
}
- return query
+
+ return query;
});
-
- return toArray(parentNode.querySelectorAll(queries.join(', ')))
+ return toArray(parentNode.querySelectorAll(queries.join(', ')));
}
-const callbacks = [];
-
-function isDOMComplete (d = document) {
- return d.readyState === 'complete'
+var callbacks = [];
+function isDOMComplete() {
+ var d = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
+ return d.readyState === 'complete';
}
-
-function addCallback (query, callback) {
+function addCallback(query, callback) {
if (arguments.length === 1) {
callback = query;
query = '';
}
- callbacks.push([ query, callback ]);
+ callbacks.push([query, callback]);
}
+function addCallbacks(_ref, type, tags, autoAddListeners) {
+ var tagIDKeyName = _ref.tagIDKeyName;
+ var hasAsyncCallback = false;
+ var _iteratorNormalCompletion = true;
+ var _didIteratorError = false;
+ var _iteratorError = undefined;
-function addCallbacks ({ tagIDKeyName }, type, tags, autoAddListeners) {
- let hasAsyncCallback = false;
+ try {
+ for (var _iterator = tags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
+ var tag = _step.value;
- for (const tag of tags) {
- if (!tag[tagIDKeyName] || !tag.callback) {
- continue
+ if (!tag[tagIDKeyName] || !tag.callback) {
+ continue;
+ }
+
+ hasAsyncCallback = true;
+ addCallback("".concat(type, "[data-").concat(tagIDKeyName, "=\"").concat(tag[tagIDKeyName], "\"]"), tag.callback);
+ }
+ } catch (err) {
+ _didIteratorError = true;
+ _iteratorError = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
+ _iterator.return();
+ }
+ } finally {
+ if (_didIteratorError) {
+ throw _iteratorError;
+ }
}
-
- hasAsyncCallback = true;
- addCallback(`${type}[data-${tagIDKeyName}="${tag[tagIDKeyName]}"]`, tag.callback);
}
if (!autoAddListeners || !hasAsyncCallback) {
- return hasAsyncCallback
+ return hasAsyncCallback;
}
- return addListeners()
+ return addListeners();
}
-
-function addListeners () {
+function addListeners() {
if (isDOMComplete()) {
applyCallbacks();
- return
- }
+ return;
+ } // Instead of using a MutationObserver, we just apply
- // Instead of using a MutationObserver, we just apply
/* istanbul ignore next */
- document.onreadystatechange = () => {
+
+
+ document.onreadystatechange = function () {
applyCallbacks();
};
}
+function applyCallbacks(matchElement) {
+ var _loop = function _loop() {
+ var _callbacks$_i = _slicedToArray(_callbacks[_i], 2),
+ query = _callbacks$_i[0],
+ callback = _callbacks$_i[1];
-function applyCallbacks (matchElement) {
- for (const [query, callback] of callbacks) {
- const selector = `${query}[onload="this.__vm_l=1"]`;
+ var selector = "".concat(query, "[onload=\"this.__vm_l=1\"]");
+ var elements = [];
- let elements = [];
if (!matchElement) {
elements = toArray(document.querySelectorAll(selector));
}
@@ -885,48 +993,78 @@ function applyCallbacks (matchElement) {
elements = [matchElement];
}
- for (const element of elements) {
- /* __vm_cb: whether the load callback has been called
- * __vm_l: set by onload attribute, whether the element was loaded
- * __vm_ev: whether the event listener was added or not
- */
- if (element.__vm_cb) {
- continue
- }
+ var _iteratorNormalCompletion2 = true;
+ var _didIteratorError2 = false;
+ var _iteratorError2 = undefined;
- const onload = () => {
- /* Mark that the callback for this element has already been called,
- * this prevents the callback to run twice in some (rare) conditions
+ try {
+ var _loop2 = function _loop2() {
+ var element = _step2.value;
+
+ /* __vm_cb: whether the load callback has been called
+ * __vm_l: set by onload attribute, whether the element was loaded
+ * __vm_ev: whether the event listener was added or not
*/
- element.__vm_cb = true;
+ if (element.__vm_cb) {
+ return "continue";
+ }
- /* onload needs to be removed because we only need the
- * attribute after ssr and if we dont remove it the node
- * will fail isEqualNode on the client
+ var onload = function onload() {
+ /* Mark that the callback for this element has already been called,
+ * this prevents the callback to run twice in some (rare) conditions
+ */
+ element.__vm_cb = true;
+ /* onload needs to be removed because we only need the
+ * attribute after ssr and if we dont remove it the node
+ * will fail isEqualNode on the client
+ */
+
+ element.removeAttribute('onload');
+ callback(element);
+ };
+ /* IE9 doesnt seem to load scripts synchronously,
+ * causing a script sometimes/often already to be loaded
+ * when we add the event listener below (thus adding an onload event
+ * listener has no use because it will never be triggered).
+ * Therefore we add the onload attribute during ssr, and
+ * check here if it was already loaded or not
*/
- element.removeAttribute('onload');
- callback(element);
+
+ if (element.__vm_l) {
+ onload();
+ return "continue";
+ }
+
+ if (!element.__vm_ev) {
+ element.__vm_ev = true;
+ element.addEventListener('load', onload);
+ }
};
- /* IE9 doesnt seem to load scripts synchronously,
- * causing a script sometimes/often already to be loaded
- * when we add the event listener below (thus adding an onload event
- * listener has no use because it will never be triggered).
- * Therefore we add the onload attribute during ssr, and
- * check here if it was already loaded or not
- */
- if (element.__vm_l) {
- onload();
- continue
+ for (var _iterator2 = elements[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
+ var _ret = _loop2();
+
+ if (_ret === "continue") continue;
}
-
- if (!element.__vm_ev) {
- element.__vm_ev = true;
-
- element.addEventListener('load', onload);
+ } catch (err) {
+ _didIteratorError2 = true;
+ _iteratorError2 = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
+ _iterator2.return();
+ }
+ } finally {
+ if (_didIteratorError2) {
+ throw _iteratorError2;
+ }
}
}
+ };
+
+ for (var _i = 0, _callbacks = callbacks; _i < _callbacks.length; _i++) {
+ _loop();
}
}
@@ -936,40 +1074,43 @@ function applyCallbacks (matchElement) {
* @param {Object} attrs - the new document html attributes
* @param {HTMLElement} tag - the HTMLElement tag to update with new attrs
*/
-function updateAttribute ({ attribute } = {}, attrs, tag) {
- const vueMetaAttrString = tag.getAttribute(attribute);
- const vueMetaAttrs = vueMetaAttrString ? vueMetaAttrString.split(',') : [];
- const toRemove = toArray(vueMetaAttrs);
- const keepIndexes = [];
- for (const attr in attrs) {
+function updateAttribute() {
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
+ attribute = _ref.attribute;
+
+ var attrs = arguments.length > 1 ? arguments[1] : undefined;
+ var tag = arguments.length > 2 ? arguments[2] : undefined;
+ var vueMetaAttrString = tag.getAttribute(attribute);
+ var vueMetaAttrs = vueMetaAttrString ? vueMetaAttrString.split(',') : [];
+ var toRemove = toArray(vueMetaAttrs);
+ var keepIndexes = [];
+
+ for (var attr in attrs) {
if (attrs.hasOwnProperty(attr)) {
- const value = includes(booleanHtmlAttributes, attr)
- ? ''
- : isArray(attrs[attr]) ? attrs[attr].join(' ') : attrs[attr];
-
+ var value = includes(booleanHtmlAttributes, attr) ? '' : isArray(attrs[attr]) ? attrs[attr].join(' ') : attrs[attr];
tag.setAttribute(attr, value || '');
if (!includes(vueMetaAttrs, attr)) {
vueMetaAttrs.push(attr);
- }
+ } // filter below wont ever check -1
+
- // filter below wont ever check -1
keepIndexes.push(toRemove.indexOf(attr));
}
}
- const removedAttributesCount = toRemove
- .filter((el, index) => !includes(keepIndexes, index))
- .reduce((acc, attr) => {
- tag.removeAttribute(attr);
- return acc + 1
- }, 0);
+ var removedAttributesCount = toRemove.filter(function (el, index) {
+ return !includes(keepIndexes, index);
+ }).reduce(function (acc, attr) {
+ tag.removeAttribute(attr);
+ return acc + 1;
+ }, 0);
if (vueMetaAttrs.length === removedAttributesCount) {
tag.removeAttribute(attribute);
} else {
- tag.setAttribute(attribute, (vueMetaAttrs.sort()).join(','));
+ tag.setAttribute(attribute, vueMetaAttrs.sort().join(','));
}
}
@@ -978,9 +1119,9 @@ function updateAttribute ({ attribute } = {}, attrs, tag) {
*
* @param {String} title - the new title of the document
*/
-function updateTitle (title) {
+function updateTitle(title) {
if (!title && title !== '') {
- return
+ return;
}
document.title = title;
@@ -994,134 +1135,185 @@ function updateTitle (title) {
* @param {(Array