From 66d98ee17022f4c6c0abf1012ae580fc49145117 Mon Sep 17 00:00:00 2001 From: pimlie Date: Sun, 28 Jul 2019 15:08:10 +0000 Subject: [PATCH] chore(release): 2.2.0 --- CHANGELOG.md | 33 ++ dist/vue-meta.common.js | 656 +++++++++++++------------------ dist/vue-meta.esm.browser.js | 611 +++++++++++----------------- dist/vue-meta.esm.browser.min.js | 2 +- dist/vue-meta.esm.js | 656 +++++++++++++------------------ dist/vue-meta.js | 611 +++++++++++----------------- dist/vue-meta.min.js | 2 +- package.json | 2 +- 8 files changed, 1038 insertions(+), 1535 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6e0bde..c511d47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,39 @@ 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.2.0](https://github.com/nuxt/vue-meta/compare/v2.0.3...v2.2.0) (2019-07-28) + + +### 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 generating tags directly from metaInfo object ([cb2758e](https://github.com/nuxt/vue-meta/commit/cb2758e)) +* 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)) +* use build/dist for e2e testing ([#421](https://github.com/nuxt/vue-meta/issues/421)) ([0bf0ceb](https://github.com/nuxt/vue-meta/commit/0bf0ceb)) + + + ### [2.1.1](https://github.com/nuxt/vue-meta/compare/v2.0.3...v2.1.1) (2019-07-26) diff --git a/dist/vue-meta.common.js b/dist/vue-meta.common.js index 03d5e07..7563490 100644 --- a/dist/vue-meta.common.js +++ b/dist/vue-meta.common.js @@ -1,5 +1,5 @@ /** - * vue-meta v2.1.1 + * vue-meta v2.2.0 * (c) 2019 * - Declan de Wet * - Sébastien Chopin (@Atinux) @@ -13,7 +13,7 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau var deepmerge = _interopDefault(require('deepmerge')); -var version = "2.1.1"; +var version = "2.2.0"; // store an id to keep track of DOM updates var batchId = null; @@ -63,55 +63,6 @@ function _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(); } @@ -256,13 +207,13 @@ var hasGlobalWindow = hasGlobalWindowFn(); var _global = hasGlobalWindow ? window : global; var console = _global.console = _global.console || {}; -function warn() { +function warn(str) { /* istanbul ignore next */ if (!console || !console.warn) { return; } - console.warn.apply(console, arguments); + console.warn(str); } var appId = 1; @@ -531,29 +482,6 @@ function resume() { } } -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 - - - if (!template) { - return false; - } - - if (isUndefined(chunk)) { - chunk = headObject[contentKeyName]; - } - - headObject[contentKeyName] = isFunction(template) ? template.call(component, chunk) : template.replace(/%s/g, chunk); - return true; -} - /* * To reduce build size, this file provides simple polyfills without * overly excessive type checking and without modifying @@ -563,14 +491,36 @@ function applyTemplate(_ref, headObject, template, chunk) { * 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 (var 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 (var idx in array) { + if (array[idx] === value) { + return true; + } + } + + return false; + } return array.includes(value); } @@ -578,13 +528,12 @@ function includes(array, value) { var serverSequences = [[/&/g, '&'], [/</g, '<'], [/>/g, '>'], [/"/g, '"'], [/'/g, ''']]; var clientSequences = [[/&/g, "&"], [/</g, "<"], [/>/g, ">"], [/"/g, "\""], [/'/g, "'"]]; // sanitizes potentially dangerous characters -function escape(info, options, escapeOptions) { +function escape(info, options, escapeOptions, escapeKeys) { var tagIDKeyName = options.tagIDKeyName; var _escapeOptions$doEsca = escapeOptions.doEscape, doEscape = _escapeOptions$doEsca === void 0 ? function (v) { return v; - } : _escapeOptions$doEsca, - escapeKeys = escapeOptions.escapeKeys; + } : _escapeOptions$doEsca; var escaped = {}; for (var key in info) { @@ -620,17 +569,13 @@ function escape(info, options, escapeOptions) { } else if (isArray(value)) { escaped[key] = value.map(function (v) { if (isPureObject(v)) { - return escape(v, options, _objectSpread2({}, escapeOptions, { - escapeKeys: true - })); + return escape(v, options, escapeOptions, true); } return doEscape(v); }); } else if (isPureObject(value)) { - escaped[key] = escape(value, options, _objectSpread2({}, escapeOptions, { - escapeKeys: true - })); + escaped[key] = escape(value, options, escapeOptions, true); } else { escaped[key] = value; } @@ -647,6 +592,56 @@ function escape(info, options, escapeOptions) { return escaped; } +function escapeMetaInfo(options, info) { + var escapeSequences = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; + 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(function (disableKey, index) { + if (index === 0) { + ensureIsArray(info, disableKey); + } else if (index === 1) { + for (var key in info[disableKey]) { + ensureIsArray(info[disableKey], key); + } + } + + escapeOptions[disableKey] = info[disableKey]; + }); // begin sanitization + + return escape(info, options, escapeOptions); +} + +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 + + + if (!template) { + return false; + } + + if (isUndefined(chunk)) { + chunk = headObject[contentKeyName]; + } + + headObject[contentKeyName] = isFunction(template) ? template.call(component, chunk) : template.replace(/%s/g, chunk); + return true; +} function _arrayMerge(_ref, target, source) { var component = _ref.component, @@ -751,6 +746,11 @@ function merge(target, source) { }); } +function getComponentMetaInfo() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var component = arguments.length > 1 ? arguments[1] : undefined; + return getComponentOption(options, component, defaultInfo); +} /** * Returns the `opts.option` $option value of the given `opts.component`. * If methods are encountered, they will be bound to the component context. @@ -839,12 +839,12 @@ function getComponentOption() { function getMetaInfo() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - var component = arguments.length > 1 ? arguments[1] : undefined; + var info = arguments.length > 1 ? arguments[1] : undefined; var escapeSequences = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; - // collect & aggregate all metaInfo $options - var info = getComponentOption(options, component, defaultInfo); // Remove all "template" tags from meta - // backup the title chunk in case user wants access to it + var component = arguments.length > 3 ? arguments[3] : undefined; + // 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 @@ -863,31 +863,7 @@ function getMetaInfo() { info.base = Object.keys(info.base).length ? [info.base] : []; } - 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(function (disableKey, index) { - if (index === 0) { - ensureIsArray(info, disableKey); - } else if (index === 1) { - for (var key in info[disableKey]) { - ensureIsArray(info[disableKey], key); - } - } - - escapeOptions[disableKey] = info[disableKey]; - }); // begin sanitization - - info = escape(info, options, escapeOptions); - return info; + return escapeMetaInfo(options, info, escapeSequences); } function getTag(tags, tag) { @@ -936,35 +912,14 @@ function addCallback(query, callback) { function addCallbacks(_ref, type, tags, autoAddListeners) { var tagIDKeyName = _ref.tagIDKeyName; var hasAsyncCallback = false; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - 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); + tags.forEach(function (tag) { + if (!tag[tagIDKeyName] || !tag.callback) { + return; } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } + + hasAsyncCallback = true; + addCallback("".concat(type, "[data-").concat(tagIDKeyName, "=\"").concat(tag[tagIDKeyName], "\"]"), tag.callback); + }); if (!autoAddListeners || !hasAsyncCallback) { return hasAsyncCallback; @@ -986,10 +941,10 @@ function addListeners() { }; } function applyCallbacks(matchElement) { - var _loop = function _loop() { - var _callbacks$_i = _slicedToArray(_callbacks[_i], 2), - query = _callbacks$_i[0], - callback = _callbacks$_i[1]; + callbacks.forEach(function (_ref2) { + var _ref3 = _slicedToArray(_ref2, 2), + query = _ref3[0], + callback = _ref3[1]; var selector = "".concat(query, "[onload=\"this.__vm_l=1\"]"); var elements = []; @@ -1002,79 +957,48 @@ function applyCallbacks(matchElement) { elements = [matchElement]; } - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; + elements.forEach(function (element) { + /* __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) { + return; + } - 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 + 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 */ - 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.__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_l) { - onload(); - return "continue"; - } - - if (!element.__vm_ev) { - element.__vm_ev = true; - element.addEventListener('load', onload); - } + 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 + */ - for (var _iterator2 = elements[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var _ret = _loop2(); - if (_ret === "continue") continue; + if (element.__vm_l) { + onload(); + return; } - } 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(); - } + if (!element.__vm_ev) { + element.__vm_ev = true; + element.addEventListener('load', onload); + } + }); + }); } /** @@ -1153,7 +1077,8 @@ function updateTag(appId) { var body = arguments.length > 5 ? arguments[5] : undefined; var attribute = options.attribute, tagIDKeyName = options.tagIDKeyName; - var dataAttributes = [tagIDKeyName].concat(_toConsumableArray(commonDataAttributes)); + var dataAttributes = commonDataAttributes.slice(); + dataAttributes.push(tagIDKeyName); var newElements = []; var queryOptions = { appId: appId, @@ -1184,141 +1109,105 @@ function updateTag(appId) { }); } - if (tags.length) { - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; + tags.forEach(function (tag) { + if (tag.skip) { + return; + } - try { - var _loop = function _loop() { - var tag = _step.value; + var newElement = document.createElement(type); + newElement.setAttribute(attribute, appId); - if (tag.skip) { - return "continue"; + var _loop = function _loop(attr) { + /* istanbul ignore next */ + if (!tag.hasOwnProperty(attr)) { + return "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)); } - var newElement = document.createElement(type); - newElement.setAttribute(attribute, appId); + return "continue"; + } - var _loop2 = function _loop2(attr) { - /* istanbul ignore next */ - if (!tag.hasOwnProperty(attr)) { - return "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); + if (attr === 'callback') { + newElement.onload = function () { + return tag[attr](newElement); }; - for (var attr in tag) { - var _ret2 = _loop2(attr); - - if (_ret2 === "continue") continue; - } - - var oldElements = currentElements[getElementsKey(tag)]; // Remove a duplicate tag from domTagstoRemove, so it isn't cleared. - - 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); - } - }; - - for (var _iterator = tags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var _ret = _loop(); - - if (_ret === "continue") continue; + return "continue"; } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } + + 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 _ret = _loop(attr); + + if (_ret === "continue") continue; } - } + var oldElements = currentElements[getElementsKey(tag)]; // Remove a duplicate tag from domTagstoRemove, so it isn't cleared. + + var indexToDelete; + 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); + } + }); var oldElements = []; - 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)); + for (var _type in currentElements) { + Array.prototype.push.apply(oldElements, currentElements[_type]); } // remove old elements - for (var _i2 = 0, _oldElements = oldElements; _i2 < _oldElements.length; _i2++) { - var element = _oldElements[_i2]; + oldElements.forEach(function (element) { element.parentNode.removeChild(element); - } // insert new elements + }); // insert new elements - - for (var _i3 = 0, _newElements = newElements; _i3 < _newElements.length; _i3++) { - var _element = _newElements[_i3]; - - if (_element.hasAttribute('data-body')) { - body.appendChild(_element); - continue; + newElements.forEach(function (element) { + if (element.hasAttribute('data-body')) { + body.appendChild(element); + return; } - if (_element.hasAttribute('data-pbody')) { - body.insertBefore(_element, body.firstChild); - continue; + if (element.hasAttribute('data-pbody')) { + body.insertBefore(element, body.firstChild); + return; } - head.appendChild(_element); - } - + head.appendChild(element); + }); return { oldTags: oldElements, newTags: newElements @@ -1345,32 +1234,11 @@ function updateClientMetaInfo(appId) { htmlTag.removeAttribute(ssrAttribute); // add load callbacks if the var addLoadListeners = false; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - 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; - } + tagsSupportingOnload.forEach(function (type) { + 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; - } - } - } + }); if (addLoadListeners) { addListeners(); @@ -1383,37 +1251,36 @@ function updateClientMetaInfo(appId) { var addedTags = {}; var removedTags = {}; - for (var _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)) { - var 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; } - var _updateTag = 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; } } @@ -1437,7 +1304,9 @@ function _refresh() { * @return {Object} - new meta info */ return function refresh() { - var metaInfo = getMetaInfo(options, this.$root, clientSequences); + // collect & aggregate all metaInfo $options + var rawInfo = getComponentMetaInfo(options, this.$root); + var metaInfo = getMetaInfo(options, rawInfo, clientSequences, this.$root); var appId = this.$root._vueMeta.appId; var tags = updateClientMetaInfo(appId, options, metaInfo); // emit "event" with new info @@ -1534,7 +1403,7 @@ function tagGenerator() { var type = arguments.length > 1 ? arguments[1] : undefined; var tags = arguments.length > 2 ? arguments[2] : undefined; - var dataAttributes = [tagIDKeyName, 'callback'].concat(_toConsumableArray(commonDataAttributes)); + var dataAttributes = [tagIDKeyName].concat(_toConsumableArray(commonDataAttributes)); return { text: function text() { var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, @@ -1543,7 +1412,11 @@ function tagGenerator() { _ref2$pbody = _ref2.pbody, pbody = _ref2$pbody === void 0 ? false : _ref2$pbody; - // build a string containing all tags of this type + if (!tags || !tags.length) { + return ''; + } // build a string containing all tags of this type + + return tags.reduce(function (tagsStr, tag) { if (tag.skip) { return tagsStr; @@ -1565,6 +1438,11 @@ function tagGenerator() { // these attributes are treated as children on the tag if (tagAttributeAsInnerContent.includes(attr) || attr === 'once') { continue; + } + + if (attr === 'callback') { + attrs += " onload=\"this.__vm_l=1\""; + continue; } // these form the attribute list for this tag @@ -1574,11 +1452,6 @@ function tagGenerator() { prefix = 'data-'; } - if (attr === 'callback') { - attrs += " onload=\"this.__vm_l=1\""; - continue; - } - var isBooleanAttr = !prefix && booleanHtmlAttributes.includes(attr); if (isBooleanAttr && !tag[attr]) { @@ -1616,16 +1489,26 @@ function tagGenerator() { * @return {Object} - the new injector */ -function generateServerInjector(options, type, data) { - if (type === 'title') { - return titleGenerator(options, type, data); +function generateServerInjector(options, newInfo) { + for (var type in defaultInfo) { + if (metaInfoOptionKeys.includes(type)) { + continue; + } + + if (type === 'title') { + newInfo[type] = titleGenerator(options, type, newInfo[type]); + continue; + } + + if (metaInfoAttributeKeys.includes(type)) { + newInfo[type] = attributeGenerator(options, type, newInfo[type]); + continue; + } + + newInfo[type] = tagGenerator(options, type, newInfo[type]); } - if (metaInfoAttributeKeys.includes(type)) { - return attributeGenerator(options, type, data); - } - - return tagGenerator(options, type, data); + return newInfo; } function _inject() { @@ -1639,15 +1522,11 @@ function _inject() { * @return {Object} - server meta info with `toString` methods */ return function inject() { - // get meta info with sensible defaults - var metaInfo = getMetaInfo(options, this.$root, serverSequences); // generate server injectors - - for (var key in metaInfo) { - if (!metaInfoOptionKeys.includes(key) && metaInfo.hasOwnProperty(key)) { - metaInfo[key] = generateServerInjector(options, key, metaInfo[key]); - } - } + // collect & aggregate all metaInfo $options + var rawInfo = getComponentMetaInfo(options, this.$root); + var metaInfo = getMetaInfo(options, rawInfo, serverSequences, this.$root); // generate server injectors + generateServerInjector(options, metaInfo); return metaInfo; }; } @@ -1678,6 +1557,12 @@ function _$meta() { }; } +function generate(rawInfo) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var metaInfo = getMetaInfo(setOptions(options), rawInfo, serverSequences); + return generateServerInjector(options, metaInfo); +} + /** * Plugin install function. * @param {Function} Vue - the Vue constructor. @@ -1699,7 +1584,8 @@ function install(Vue) { var index = { version: version, install: install, - hasMetaInfo: hasMetaInfo + hasMetaInfo: hasMetaInfo, + generate: generate }; module.exports = index; diff --git a/dist/vue-meta.esm.browser.js b/dist/vue-meta.esm.browser.js index 6116f55..441131c 100644 --- a/dist/vue-meta.esm.browser.js +++ b/dist/vue-meta.esm.browser.js @@ -1,5 +1,5 @@ /** - * vue-meta v2.1.1 + * vue-meta v2.2.0 * (c) 2019 * - Declan de Wet * - Sébastien Chopin (@Atinux) @@ -9,7 +9,7 @@ import deepmerge from 'deepmerge'; -var version = "2.1.1"; +var version = "2.2.0"; // store an id to keep track of DOM updates var batchId = null; @@ -59,79 +59,14 @@ function _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; @@ -158,10 +93,6 @@ function _iterableToArrayLimit(arr, i) { 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"); } @@ -252,13 +183,13 @@ var hasGlobalWindow = hasGlobalWindowFn(); var _global = hasGlobalWindow ? window : global; var console = _global.console = _global.console || {}; -function warn() { +function warn(str) { /* istanbul ignore next */ if (!console || !console.warn) { return; } - console.warn.apply(console, arguments); + console.warn(str); } var showWarningNotSupported = function showWarningNotSupported() { return warn('This vue app/component has no vue-meta configuration'); @@ -523,29 +454,6 @@ function resume() { } } -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 - - - if (!template) { - return false; - } - - if (isUndefined(chunk)) { - chunk = headObject[contentKeyName]; - } - - headObject[contentKeyName] = isFunction(template) ? template.call(component, chunk) : template.replace(/%s/g, chunk); - return true; -} - /* * To reduce build size, this file provides simple polyfills without * overly excessive type checking and without modifying @@ -555,27 +463,48 @@ function applyTemplate(_ref, headObject, template, chunk) { * 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 (var 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 (var idx in array) { + if (array[idx] === value) { + return true; + } + } + + return false; + } return array.includes(value); } var clientSequences = [[/&/g, "&"], [/</g, "<"], [/>/g, ">"], [/"/g, "\""], [/'/g, "'"]]; // sanitizes potentially dangerous characters -function escape(info, options, escapeOptions) { +function escape(info, options, escapeOptions, escapeKeys) { var tagIDKeyName = options.tagIDKeyName; var _escapeOptions$doEsca = escapeOptions.doEscape, doEscape = _escapeOptions$doEsca === void 0 ? function (v) { return v; - } : _escapeOptions$doEsca, - escapeKeys = escapeOptions.escapeKeys; + } : _escapeOptions$doEsca; var escaped = {}; for (var key in info) { @@ -611,17 +540,13 @@ function escape(info, options, escapeOptions) { } else if (isArray(value)) { escaped[key] = value.map(function (v) { if (isPureObject(v)) { - return escape(v, options, _objectSpread2({}, escapeOptions, { - escapeKeys: true - })); + return escape(v, options, escapeOptions, true); } return doEscape(v); }); } else if (isPureObject(value)) { - escaped[key] = escape(value, options, _objectSpread2({}, escapeOptions, { - escapeKeys: true - })); + escaped[key] = escape(value, options, escapeOptions, true); } else { escaped[key] = value; } @@ -638,6 +563,56 @@ function escape(info, options, escapeOptions) { return escaped; } +function escapeMetaInfo(options, info) { + var escapeSequences = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; + 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(function (disableKey, index) { + if (index === 0) { + ensureIsArray(info, disableKey); + } else if (index === 1) { + for (var key in info[disableKey]) { + ensureIsArray(info[disableKey], key); + } + } + + escapeOptions[disableKey] = info[disableKey]; + }); // begin sanitization + + return escape(info, options, escapeOptions); +} + +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 + + + if (!template) { + return false; + } + + if (isUndefined(chunk)) { + chunk = headObject[contentKeyName]; + } + + headObject[contentKeyName] = isFunction(template) ? template.call(component, chunk) : template.replace(/%s/g, chunk); + return true; +} function _arrayMerge(_ref, target, source) { var component = _ref.component, @@ -742,6 +717,11 @@ function merge(target, source) { }); } +function getComponentMetaInfo() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var component = arguments.length > 1 ? arguments[1] : undefined; + return getComponentOption(options, component, defaultInfo); +} /** * Returns the `opts.option` $option value of the given `opts.component`. * If methods are encountered, they will be bound to the component context. @@ -830,12 +810,12 @@ function getComponentOption() { function getMetaInfo() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - var component = arguments.length > 1 ? arguments[1] : undefined; + var info = arguments.length > 1 ? arguments[1] : undefined; var escapeSequences = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; - // collect & aggregate all metaInfo $options - var info = getComponentOption(options, component, defaultInfo); // Remove all "template" tags from meta - // backup the title chunk in case user wants access to it + var component = arguments.length > 3 ? arguments[3] : undefined; + // 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 @@ -854,31 +834,7 @@ function getMetaInfo() { info.base = Object.keys(info.base).length ? [info.base] : []; } - 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(function (disableKey, index) { - if (index === 0) { - ensureIsArray(info, disableKey); - } else if (index === 1) { - for (var key in info[disableKey]) { - ensureIsArray(info[disableKey], key); - } - } - - escapeOptions[disableKey] = info[disableKey]; - }); // begin sanitization - - info = escape(info, options, escapeOptions); - return info; + return escapeMetaInfo(options, info, escapeSequences); } function getTag(tags, tag) { @@ -927,35 +883,14 @@ function addCallback(query, callback) { function addCallbacks(_ref, type, tags, autoAddListeners) { var tagIDKeyName = _ref.tagIDKeyName; var hasAsyncCallback = false; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - 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); + tags.forEach(function (tag) { + if (!tag[tagIDKeyName] || !tag.callback) { + return; } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } + + hasAsyncCallback = true; + addCallback("".concat(type, "[data-").concat(tagIDKeyName, "=\"").concat(tag[tagIDKeyName], "\"]"), tag.callback); + }); if (!autoAddListeners || !hasAsyncCallback) { return hasAsyncCallback; @@ -977,10 +912,10 @@ function addListeners() { }; } function applyCallbacks(matchElement) { - var _loop = function _loop() { - var _callbacks$_i = _slicedToArray(_callbacks[_i], 2), - query = _callbacks$_i[0], - callback = _callbacks$_i[1]; + callbacks.forEach(function (_ref2) { + var _ref3 = _slicedToArray(_ref2, 2), + query = _ref3[0], + callback = _ref3[1]; var selector = "".concat(query, "[onload=\"this.__vm_l=1\"]"); var elements = []; @@ -993,79 +928,48 @@ function applyCallbacks(matchElement) { elements = [matchElement]; } - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; + elements.forEach(function (element) { + /* __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) { + return; + } - 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 + 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 */ - 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.__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_l) { - onload(); - return "continue"; - } - - if (!element.__vm_ev) { - element.__vm_ev = true; - element.addEventListener('load', onload); - } + 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 + */ - for (var _iterator2 = elements[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var _ret = _loop2(); - if (_ret === "continue") continue; + if (element.__vm_l) { + onload(); + return; } - } 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(); - } + if (!element.__vm_ev) { + element.__vm_ev = true; + element.addEventListener('load', onload); + } + }); + }); } /** @@ -1144,7 +1048,8 @@ function updateTag(appId) { var body = arguments.length > 5 ? arguments[5] : undefined; var attribute = options.attribute, tagIDKeyName = options.tagIDKeyName; - var dataAttributes = [tagIDKeyName].concat(_toConsumableArray(commonDataAttributes)); + var dataAttributes = commonDataAttributes.slice(); + dataAttributes.push(tagIDKeyName); var newElements = []; var queryOptions = { appId: appId, @@ -1175,141 +1080,105 @@ function updateTag(appId) { }); } - if (tags.length) { - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; + tags.forEach(function (tag) { + if (tag.skip) { + return; + } - try { - var _loop = function _loop() { - var tag = _step.value; + var newElement = document.createElement(type); + newElement.setAttribute(attribute, appId); - if (tag.skip) { - return "continue"; + var _loop = function _loop(attr) { + /* istanbul ignore next */ + if (!tag.hasOwnProperty(attr)) { + return "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)); } - var newElement = document.createElement(type); - newElement.setAttribute(attribute, appId); + return "continue"; + } - var _loop2 = function _loop2(attr) { - /* istanbul ignore next */ - if (!tag.hasOwnProperty(attr)) { - return "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); + if (attr === 'callback') { + newElement.onload = function () { + return tag[attr](newElement); }; - for (var attr in tag) { - var _ret2 = _loop2(attr); - - if (_ret2 === "continue") continue; - } - - var oldElements = currentElements[getElementsKey(tag)]; // Remove a duplicate tag from domTagstoRemove, so it isn't cleared. - - 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); - } - }; - - for (var _iterator = tags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var _ret = _loop(); - - if (_ret === "continue") continue; + return "continue"; } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } + + 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 _ret = _loop(attr); + + if (_ret === "continue") continue; } - } + var oldElements = currentElements[getElementsKey(tag)]; // Remove a duplicate tag from domTagstoRemove, so it isn't cleared. + + var indexToDelete; + 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); + } + }); var oldElements = []; - 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)); + for (var _type in currentElements) { + Array.prototype.push.apply(oldElements, currentElements[_type]); } // remove old elements - for (var _i2 = 0, _oldElements = oldElements; _i2 < _oldElements.length; _i2++) { - var element = _oldElements[_i2]; + oldElements.forEach(function (element) { element.parentNode.removeChild(element); - } // insert new elements + }); // insert new elements - - for (var _i3 = 0, _newElements = newElements; _i3 < _newElements.length; _i3++) { - var _element = _newElements[_i3]; - - if (_element.hasAttribute('data-body')) { - body.appendChild(_element); - continue; + newElements.forEach(function (element) { + if (element.hasAttribute('data-body')) { + body.appendChild(element); + return; } - if (_element.hasAttribute('data-pbody')) { - body.insertBefore(_element, body.firstChild); - continue; + if (element.hasAttribute('data-pbody')) { + body.insertBefore(element, body.firstChild); + return; } - head.appendChild(_element); - } - + head.appendChild(element); + }); return { oldTags: oldElements, newTags: newElements @@ -1336,32 +1205,11 @@ function updateClientMetaInfo(appId) { htmlTag.removeAttribute(ssrAttribute); // add load callbacks if the var addLoadListeners = false; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - 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; - } + tagsSupportingOnload.forEach(function (type) { + 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; - } - } - } + }); if (addLoadListeners) { addListeners(); @@ -1374,37 +1222,36 @@ function updateClientMetaInfo(appId) { var addedTags = {}; var removedTags = {}; - for (var _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)) { - var 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; } - var _updateTag = 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; } } @@ -1428,7 +1275,9 @@ function _refresh() { * @return {Object} - new meta info */ return function refresh() { - var metaInfo = getMetaInfo(options, this.$root, clientSequences); + // collect & aggregate all metaInfo $options + var rawInfo = getComponentMetaInfo(options, this.$root); + var metaInfo = getMetaInfo(options, rawInfo, clientSequences, this.$root); var appId = this.$root._vueMeta.appId; var tags = updateClientMetaInfo(appId, options, metaInfo); // emit "event" with new info diff --git a/dist/vue-meta.esm.browser.min.js b/dist/vue-meta.esm.browser.min.js index c7cb2fa..9f41f17 100644 --- a/dist/vue-meta.esm.browser.min.js +++ b/dist/vue-meta.esm.browser.min.js @@ -1 +1 @@ -import t from"deepmerge";var e=null;function n(t,n){t.$root._vueMeta.initialized||!t.$root._vueMeta.initializing&&"watcher"!==n||(t.$root._vueMeta.initialized=null),t.$root._vueMeta.initialized&&!t.$root._vueMeta.paused&&function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10;clearTimeout(e),e=setTimeout(function(){t()},n)}(function(){return t.$meta().refresh()})}function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function i(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)}return n}function a(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?i(n,!0).forEach(function(e){o(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):i(n).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function u(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=[],r=!0,o=!1,i=void 0;try{for(var a,u=t[Symbol.iterator]();!(r=(a=u.next()).done)&&(n.push(a.value),!e||n.length!==e);r=!0);}catch(t){o=!0,i=t}finally{try{r||null==u.return||u.return()}finally{if(o)throw i}}return n}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function c(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function l(t){return Array.isArray(t)}function s(t){return void 0===t}function f(t){return"object"===r(t)}function d(t){return"object"===r(t)&&null!==t}function v(t){return"function"==typeof t}function h(t,e){return e&&f(t)?(l(t[e])||(t[e]=[]),t):l(t)?t:[]}function p(t,e,n){h(t,e),t[e].push(n)}function m(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this;return t&&(!0===t._vueMeta||f(t._vueMeta))}function y(t){if(!t.$root._vueMeta.navGuards&&t.$root.$router){t.$root._vueMeta.navGuards=!0;var e=t.$root.$router,n=t.$root.$meta();e.beforeEach(function(t,e,r){n.pause(),r()}),e.afterEach(function(){var t=n.resume().metaInfo;t&&t.afterNavigation&&v(t.afterNavigation)&&t.afterNavigation(t)})}}var g=function(){try{return!s(window)}catch(t){return!1}}()?window:global,b=g.console=g.console||{};function $(){b&&b.warn&&b.warn.apply(b,arguments)}var _=function(){return $("This vue app/component has no vue-meta configuration")},M=1;var w={title:void 0,titleChunk:"",titleTemplate:"%s",htmlAttrs:{},bodyAttrs:{},headAttrs:{},base:[],link:[],meta:[],style:[],script:[],noscript:[],__dangerouslyDisableSanitizers:[],__dangerouslyDisableSanitizersByTagID:{}},T={keyName:"metaInfo",attribute:"data-vue-meta",ssrAttribute:"data-vue-meta-server-rendered",tagIDKeyName:"vmid",contentKeyName:"content",metaTemplateKeyName:"template",ssrAppId:"ssr"},N=["titleChunk","titleTemplate","changed","__dangerouslyDisableSanitizers","__dangerouslyDisableSanitizersByTagID"],A=["__dangerouslyDisableSanitizers","__dangerouslyDisableSanitizersByTagID"],O=["htmlAttrs","headAttrs","bodyAttrs"],I=["link","style","script"],S=["body","pbody"],j=["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 D(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this.$root._vueMeta.paused=!0,function(){return K(t)}}function K(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];if(this.$root._vueMeta.paused=!1,t)return this.$root.$meta().refresh()}function k(t,e,n,r){var o=t.component,i=t.metaTemplateKeyName,a=t.contentKeyName;return s(n)&&(n=e[i],delete e[i]),!!n&&(s(r)&&(r=e[a]),e[a]=v(n)?n.call(o,r):n.replace(/%s/g,r),!0)}function z(t,e){return t.findIndex(e,arguments[2])}function P(t){return Array.from(t)}function E(t,e){return t.includes(e)}var x=[[/&/g,"&"],[/</g,"<"],[/>/g,">"],[/"/g,'"'],[/'/g,"'"]];function C(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.hasOwnProperty("title")&&void 0===n.title&&delete n.title,O.forEach(function(t){if(n[t])for(var e in n[t])n[t].hasOwnProperty(e)&&void 0===n[t][e]&&(E(j,e)&&$("VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details"),delete n[t][e])}),t(e,n,{arrayMerge:function(t,e){return function(t,e,n){var r=t.component,o=t.tagIDKeyName,i=t.metaTemplateKeyName,a=t.contentKeyName,u=[];return e.forEach(function(t,e){if(t[o]){var c=z(n,function(e){return e[o]===t[o]}),l=n[c];if(-1!==c){if(l.hasOwnProperty(a)&&void 0===l[a]||l.hasOwnProperty("innerHTML")&&void 0===l.innerHTML)return u.push(t),void n.splice(c,1);if(null!==l[a]&&null!==l.innerHTML){var s=t[i];s&&(l[i]?l[a]||k({component:r,metaTemplateKeyName:i,contentKeyName:a},l,void 0,t[a]):k({component:r,metaTemplateKeyName:i,contentKeyName:a},l,s))}else n.splice(c,1)}else u.push(t)}else u.push(t)}),u.concat(n)}(r,t,e)}})}function L(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=t.keyName,o=t.metaTemplateKeyName,i=t.tagIDKeyName,a=e.$options,u=e.$children;if(e._inactive)return n;if(a[r]){var c=a[r];if(v(c)&&(c=c.call(e)),!f(c))return n;n=C(n,c,t)}return u.length&&u.forEach(function(e){(function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this;return t&&!s(t._vueMeta)})(e)&&(n=L(t,e,n))}),o&&n.meta&&(n.meta.forEach(function(e){return k(t,e)}),n.meta=n.meta.filter(function(t,e,n){return!t.hasOwnProperty(i)||e===z(n,function(e){return e[i]===t[i]})})),n}function H(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=L(t,e,w);r.title&&(r.titleChunk=r.title),r.titleTemplate&&"%s"!==r.titleTemplate&&k({component:e,contentKeyName:"title"},r,r.titleTemplate,r.titleChunk||""),r.base&&(r.base=Object.keys(r.base).length?[r.base]:[]);var o={doEscape:function(t){return n.reduce(function(t,e){var n=u(e,2),r=n[0],o=n[1];return t.replace(r,o)},t)}};return A.forEach(function(t,e){if(0===e)h(r,t);else if(1===e)for(var n in r[t])h(r[t],n);o[t]=r[t]}),r=function t(e,n,r){var o=n.tagIDKeyName,i=r.doEscape,c=void 0===i?function(t){return t}:i,s=r.escapeKeys,f={};for(var v in e){var h=e[v];if(E(N,v))f[v]=h;else{var p=u(A,1)[0];if(r[p]&&E(r[p],v))f[v]=h;else{var m=e[o];if(m&&(p=A[1],r[p]&&r[p][m]&&E(r[p][m],v)))f[v]=h;else if("string"==typeof h?f[v]=c(h):l(h)?f[v]=h.map(function(e){return d(e)?t(e,n,a({},r,{escapeKeys:!0})):c(e)}):d(h)?f[v]=t(h,n,a({},r,{escapeKeys:!0})):f[v]=h,s){var y=c(v);v!==y&&(f[y]=f[v],delete f[v])}}}}return f}(r,t,o)}function B(t,e){return t[e]||(t[e]=document.getElementsByTagName(e)[0]),t[e]}function q(t,e){var n=e.appId,r=e.attribute,o=e.type,i=e.tagIDKeyName,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},u=["".concat(o,"[").concat(r,'="').concat(n,'"]'),"".concat(o,"[data-").concat(i,"]")].map(function(t){for(var e in a){var n=a[e],r=n&&!0!==n?'="'.concat(n,'"'):"";t+="[data-".concat(e).concat(r,"]")}return t});return P(t.querySelectorAll(u.join(", ")))}var V=[];function W(t,e){1===arguments.length&&(e=t,t=""),V.push([t,e])}function G(t,e,n,r){var o=t.tagIDKeyName,i=!1,a=!0,u=!1,c=void 0;try{for(var l,s=n[Symbol.iterator]();!(a=(l=s.next()).done);a=!0){var f=l.value;f[o]&&f.callback&&(i=!0,W("".concat(e,"[data-").concat(o,'="').concat(f[o],'"]'),f.callback))}}catch(t){u=!0,c=t}finally{try{a||null==s.return||s.return()}finally{if(u)throw c}}return r&&i?J():i}function J(){!function(){return"complete"===(arguments.length>0&&void 0!==arguments[0]?arguments[0]:document).readyState}()?document.onreadystatechange=function(){F()}:F()}function F(t){for(var e=function(){var e=u(r[n],2),o=e[0],i=e[1],a="".concat(o,'[onload="this.__vm_l=1"]'),c=[];t||(c=P(document.querySelectorAll(a))),t&&t.matches(a)&&(c=[t]);var l=!0,s=!1,f=void 0;try{for(var d,v=function(){var t=d.value;if(t.__vm_cb)return"continue";var e=function(){t.__vm_cb=!0,t.removeAttribute("onload"),i(t)};if(t.__vm_l)return e(),"continue";t.__vm_ev||(t.__vm_ev=!0,t.addEventListener("load",e))},h=c[Symbol.iterator]();!(l=(d=h.next()).done);l=!0)v()}catch(t){s=!0,f=t}finally{try{l||null==h.return||h.return()}finally{if(s)throw f}}},n=0,r=V;n<r.length;n++)e()}function Q(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).attribute,e=arguments.length>1?arguments[1]:void 0,n=arguments.length>2?arguments[2]:void 0,r=n.getAttribute(t),o=r?r.split(","):[],i=P(o),a=[];for(var u in e)if(e.hasOwnProperty(u)){var c=E(j,u)?"":l(e[u])?e[u].join(" "):e[u];n.setAttribute(u,c||""),E(o,u)||o.push(u),a.push(i.indexOf(u))}var s=i.filter(function(t,e){return!E(a,e)}).reduce(function(t,e){return n.removeAttribute(e),t+1},0);o.length===s?n.removeAttribute(t):n.setAttribute(t,o.sort().join(","))}function R(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,o=arguments.length>4?arguments[4]:void 0,i=arguments.length>5?arguments[5]:void 0,a=e.attribute,u=e.tagIDKeyName,l=[u].concat(c(S)),s=[],f={appId:t,attribute:a,type:n,tagIDKeyName:u},d={head:q(o,f),pbody:q(i,f,{pbody:!0}),body:q(i,f,{body:!0})};if(r.length>1){var v=[];r=r.filter(function(t){var e=JSON.stringify(t),n=!E(v,e);return v.push(e),n})}if(r.length){var h=!0,p=!1,m=void 0;try{for(var y,g=function(){var e=y.value;if(e.skip)return"continue";var r=document.createElement(n);r.setAttribute(a,t);var o=function(t){if(!e.hasOwnProperty(t))return"continue";if("innerHTML"===t)return r.innerHTML=e.innerHTML,"continue";if("json"===t)return r.innerHTML=JSON.stringify(e.json),"continue";if("cssText"===t)return r.styleSheet?r.styleSheet.cssText=e.cssText:r.appendChild(document.createTextNode(e.cssText)),"continue";if("callback"===t)return r.onload=function(){return e[t](r)},"continue";var n=E(l,t)?"data-".concat(t):t,o=E(j,t);if(o&&!e[t])return"continue";var i=o?"":e[t];r.setAttribute(n,i)};for(var i in e)o(i);var u=d[function(t){var e=t.body,n=t.pbody;return e?"body":n?"pbody":"head"}(e)],c=void 0;u.some(function(t,e){return c=e,r.isEqualNode(t)})&&(c||0===c)?u.splice(c,1):s.push(r)},b=r[Symbol.iterator]();!(h=(y=b.next()).done);h=!0)g()}catch(t){p=!0,m=t}finally{try{h||null==b.return||b.return()}finally{if(p)throw m}}}for(var $=[],_=0,M=Object.values(d);_<M.length;_++){var w=M[_];$=[].concat(c($),c(w))}for(var T=0,N=$;T<N.length;T++){var A=N[T];A.parentNode.removeChild(A)}for(var O=0,I=s;O<I.length;O++){var D=I[O];D.hasAttribute("data-body")?i.appendChild(D):D.hasAttribute("data-pbody")?i.insertBefore(D,i.firstChild):o.appendChild(D)}return{oldTags:$,newTags:s}}function U(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(){var e=H(t,this.$root,x),n=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,r=e.ssrAttribute,o=e.ssrAppId,i={},a=B(i,"html");if(t===o&&a.hasAttribute(r)){a.removeAttribute(r);var u=!1,c=!0,s=!1,f=void 0;try{for(var d,v=I[Symbol.iterator]();!(c=(d=v.next()).done);c=!0){var h=d.value;n[h]&&G(e,h,n[h])&&(u=!0)}}catch(t){s=!0,f=t}finally{try{c||null==v.return||v.return()}finally{if(s)throw f}}return u&&J(),!1}var p,m={},y={};for(var g in n)if(!E(N,g))if("title"!==g){if(E(O,g)){var b=g.substr(0,4);Q(e,n[g],B(i,b))}else if(l(n[g])){var $=R(t,e,g,n[g],B(i,"head"),B(i,"body")),_=$.oldTags,M=$.newTags;M.length&&(m[g]=M,y[g]=_)}}else((p=n.title)||""===p)&&(document.title=p);return{addedTags:m,removedTags:y}}(this.$root._vueMeta.appId,t,e);return n&&v(e.changed)&&e.changed(e,n.addedTags,n.removedTags),{vm:this,metaInfo:e,tags:n}}}function X(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t.__vuemeta_installed||(t.__vuemeta_installed=!0,e=function(t){for(var e in t=f(t)?t:{},T)t[e]||(t[e]=T[e]);return t}(e),t.prototype.$meta=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=U(t),n=function(){};return function(){return this.$root._vueMeta?{getOptions:function(){return function(t){var e={};for(var n in t)e[n]=t[n];return e}(t)},refresh:e.bind(this),inject:n,pause:D.bind(this),resume:K.bind(this)}:{getOptions:_,refresh:_,inject:_,pause:_,resume:_}}}(e),t.mixin(function(t,e){var r=["activated","deactivated","beforeMount"];return{beforeCreate:function(){var o=this;if(Object.defineProperty(this,"_hasMetaInfo",{configurable:!0,get:function(){return t.config.devtools&&!this.$root._vueMeta.hasMetaInfoDeprecationWarningShown&&($("VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead"),this.$root._vueMeta.hasMetaInfoDeprecationWarningShown=!0),m(this)}}),!s(this.$options[e.keyName])&&null!==this.$options[e.keyName]){if(this.$root._vueMeta||(this.$root._vueMeta={appId:M},M++),!this._vueMeta){this._vueMeta=!0;for(var i=this.$parent;i&&i!==this.$root;)s(i._vueMeta)&&(i._vueMeta=!1),i=i.$parent}v(this.$options[e.keyName])&&(this.$options.computed||(this.$options.computed={}),this.$options.computed.$metaInfo=this.$options[e.keyName],this.$isServer||p(this.$options,"created",function(){o.$watch("$metaInfo",function(){n(this,"watcher")})})),s(this.$root._vueMeta.initialized)&&(this.$root._vueMeta.initialized=this.$isServer,this.$root._vueMeta.initialized||(p(this.$options,"beforeMount",function(){o.$root.$el&&o.$root.$el.hasAttribute&&o.$root.$el.hasAttribute("data-server-rendered")&&(o.$root._vueMeta.appId=e.ssrAppId)}),p(this.$options,"mounted",function(){o.$root._vueMeta.initialized||(o.$root._vueMeta.initializing=!0,o.$nextTick(function(){var t=this,r=this.$root.$meta().refresh(),o=r.tags,i=r.metaInfo;!1===o&&null===this.$root._vueMeta.initialized&&this.$nextTick(function(){return n(t,"initializing")}),this.$root._vueMeta.initialized=!0,delete this.$root._vueMeta.initializing,!e.refreshOnceOnNavigation&&i.afterNavigation&&y(this)}))}),e.refreshOnceOnNavigation&&y(this))),this.$isServer||(r.forEach(function(t){p(o.$options,t,function(){return n(o,t)})}),p(this.$options,"destroyed",function(){var t=setInterval(function(){o.$el&&null!==o.$el.offsetParent||(clearInterval(t),o.$parent&&n(o,"destroyed"))},50)}))}}}}(t,e)))}s(window)||s(window.Vue)||X(window.Vue);var Y={version:"2.1.1",install:X,hasMetaInfo:m};export default Y; +import t from"deepmerge";var e=null;function n(t,n){t.$root._vueMeta.initialized||!t.$root._vueMeta.initializing&&"watcher"!==n||(t.$root._vueMeta.initialized=null),t.$root._vueMeta.initialized&&!t.$root._vueMeta.paused&&function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10;clearTimeout(e),e=setTimeout(function(){t()},n)}(function(){return t.$meta().refresh()})}function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=[],r=!0,i=!1,o=void 0;try{for(var a,u=t[Symbol.iterator]();!(r=(a=u.next()).done)&&(n.push(a.value),!e||n.length!==e);r=!0);}catch(t){i=!0,o=t}finally{try{r||null==u.return||u.return()}finally{if(i)throw o}}return n}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function o(t){return Array.isArray(t)}function a(t){return void 0===t}function u(t){return"object"===r(t)}function s(t){return"object"===r(t)&&null!==t}function c(t){return"function"==typeof t}function l(t,e){return e&&u(t)?(o(t[e])||(t[e]=[]),t):o(t)?t:[]}function f(t,e,n){l(t,e),t[e].push(n)}function d(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this;return t&&(!0===t._vueMeta||u(t._vueMeta))}function v(t){if(!t.$root._vueMeta.navGuards&&t.$root.$router){t.$root._vueMeta.navGuards=!0;var e=t.$root.$router,n=t.$root.$meta();e.beforeEach(function(t,e,r){n.pause(),r()}),e.afterEach(function(){var t=n.resume().metaInfo;t&&t.afterNavigation&&c(t.afterNavigation)&&t.afterNavigation(t)})}}var h=function(){try{return!a(window)}catch(t){return!1}}()?window:global,p=h.console=h.console||{};function m(t){p&&p.warn&&p.warn(t)}var y=function(){return m("This vue app/component has no vue-meta configuration")},g=1;var b={title:void 0,titleChunk:"",titleTemplate:"%s",htmlAttrs:{},bodyAttrs:{},headAttrs:{},base:[],link:[],meta:[],style:[],script:[],noscript:[],__dangerouslyDisableSanitizers:[],__dangerouslyDisableSanitizersByTagID:{}},$={keyName:"metaInfo",attribute:"data-vue-meta",ssrAttribute:"data-vue-meta-server-rendered",tagIDKeyName:"vmid",contentKeyName:"content",metaTemplateKeyName:"template",ssrAppId:"ssr"},_=["titleChunk","titleTemplate","changed","__dangerouslyDisableSanitizers","__dangerouslyDisableSanitizersByTagID"],M=["__dangerouslyDisableSanitizers","__dangerouslyDisableSanitizersByTagID"],T=["htmlAttrs","headAttrs","bodyAttrs"],N=["link","style","script"],A=["body","pbody"],I=["allowfullscreen","amp","async","autofocus","autoplay","checked","compact","controls","declare","default","defaultchecked","defaultmuted","defaultselected","defer","disabled","enabled","formnovalidate","hidden","indeterminate","inert","ismap","itemscope","loop","multiple","muted","nohref","noresize","noshade","novalidate","nowrap","open","pauseonexit","readonly","required","reversed","scoped","seamless","selected","sortable","truespeed","typemustmatch","visible"];function w(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this.$root._vueMeta.paused=!0,function(){return S(t)}}function S(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];if(this.$root._vueMeta.paused=!1,t)return this.$root.$meta().refresh()}function E(t,e){if(!Array.prototype.findIndex){for(var n=0;n<t.length;n++)if(e.call(arguments[2],t[n],n,t))return n;return-1}return t.findIndex(e,arguments[2])}function k(t){return Array.from?Array.from(t):Array.prototype.slice.call(t)}function z(t,e){if(!Array.prototype.includes){for(var n in t)if(t[n]===e)return!0;return!1}return t.includes(e)}var D=[[/&/g,"&"],[/</g,"<"],[/>/g,">"],[/"/g,'"'],[/'/g,"'"]];function K(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r={doEscape:function(t){return n.reduce(function(t,e){var n=i(e,2),r=n[0],o=n[1];return t.replace(r,o)},t)}};return M.forEach(function(t,n){if(0===n)l(e,t);else if(1===n)for(var i in e[t])l(e[t],i);r[t]=e[t]}),function t(e,n,r,a){var u=n.tagIDKeyName,c=r.doEscape,l=void 0===c?function(t){return t}:c,f={};for(var d in e){var v=e[d];if(z(_,d))f[d]=v;else{var h=i(M,1)[0];if(r[h]&&z(r[h],d))f[d]=v;else{var p=e[u];if(p&&(h=M[1],r[h]&&r[h][p]&&z(r[h][p],d)))f[d]=v;else if("string"==typeof v?f[d]=l(v):o(v)?f[d]=v.map(function(e){return s(e)?t(e,n,r,!0):l(e)}):s(v)?f[d]=t(v,n,r,!0):f[d]=v,a){var m=l(d);d!==m&&(f[m]=f[d],delete f[d])}}}}return f}(e,t,r)}function O(t,e,n,r){var i=t.component,o=t.metaTemplateKeyName,u=t.contentKeyName;return a(n)&&(n=e[o],delete e[o]),!!n&&(a(r)&&(r=e[u]),e[u]=c(n)?n.call(i,r):n.replace(/%s/g,r),!0)}function x(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.hasOwnProperty("title")&&void 0===n.title&&delete n.title,T.forEach(function(t){if(n[t])for(var e in n[t])n[t].hasOwnProperty(e)&&void 0===n[t][e]&&(z(I,e)&&m("VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details"),delete n[t][e])}),t(e,n,{arrayMerge:function(t,e){return function(t,e,n){var r=t.component,i=t.tagIDKeyName,o=t.metaTemplateKeyName,a=t.contentKeyName,u=[];return e.forEach(function(t,e){if(t[i]){var s=E(n,function(e){return e[i]===t[i]}),c=n[s];if(-1!==s){if(c.hasOwnProperty(a)&&void 0===c[a]||c.hasOwnProperty("innerHTML")&&void 0===c.innerHTML)return u.push(t),void n.splice(s,1);if(null!==c[a]&&null!==c.innerHTML){var l=t[o];l&&(c[o]?c[a]||O({component:r,metaTemplateKeyName:o,contentKeyName:a},c,void 0,t[a]):O({component:r,metaTemplateKeyName:o,contentKeyName:a},c,l))}else n.splice(s,1)}else u.push(t)}else u.push(t)}),u.concat(n)}(r,t,e)}})}function j(){return function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};var n=arguments.length>1?arguments[1]:void 0;var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};var i=e.keyName,o=e.metaTemplateKeyName,s=e.tagIDKeyName;var l=n.$options,f=n.$children;if(n._inactive)return r;if(l[i]){var d=l[i];if(c(d)&&(d=d.call(n)),!u(d))return r;r=x(r,d,e)}f.length&&f.forEach(function(n){(function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this;return t&&!a(t._vueMeta)})(n)&&(r=t(e,n,r))});o&&r.meta&&(r.meta.forEach(function(t){return O(e,t)}),r.meta=r.meta.filter(function(t,e,n){return!t.hasOwnProperty(s)||e===E(n,function(e){return e[s]===t[s]})}));return r}(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},arguments.length>1?arguments[1]:void 0,b)}function P(t,e){return t[e]||(t[e]=document.getElementsByTagName(e)[0]),t[e]}function C(t,e){var n=e.appId,r=e.attribute,i=e.type,o=e.tagIDKeyName,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},u=["".concat(i,"[").concat(r,'="').concat(n,'"]'),"".concat(i,"[data-").concat(o,"]")].map(function(t){for(var e in a){var n=a[e],r=n&&!0!==n?'="'.concat(n,'"'):"";t+="[data-".concat(e).concat(r,"]")}return t});return k(t.querySelectorAll(u.join(", ")))}var L=[];function H(t,e,n,r){var i=t.tagIDKeyName,o=!1;return n.forEach(function(t){t[i]&&t.callback&&(o=!0,function(t,e){1===arguments.length&&(e=t,t=""),L.push([t,e])}("".concat(e,"[data-").concat(i,'="').concat(t[i],'"]'),t.callback))}),r&&o?B():o}function B(){!function(){return"complete"===(arguments.length>0&&void 0!==arguments[0]?arguments[0]:document).readyState}()?document.onreadystatechange=function(){q()}:q()}function q(t){L.forEach(function(e){var n=i(e,2),r=n[0],o=n[1],a="".concat(r,'[onload="this.__vm_l=1"]'),u=[];t||(u=k(document.querySelectorAll(a))),t&&t.matches(a)&&(u=[t]),u.forEach(function(t){if(!t.__vm_cb){var e=function(){t.__vm_cb=!0,t.removeAttribute("onload"),o(t)};t.__vm_l?e():t.__vm_ev||(t.__vm_ev=!0,t.addEventListener("load",e))}})})}function V(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).attribute,e=arguments.length>1?arguments[1]:void 0,n=arguments.length>2?arguments[2]:void 0,r=n.getAttribute(t),i=r?r.split(","):[],a=k(i),u=[];for(var s in e)if(e.hasOwnProperty(s)){var c=z(I,s)?"":o(e[s])?e[s].join(" "):e[s];n.setAttribute(s,c||""),z(i,s)||i.push(s),u.push(a.indexOf(s))}var l=a.filter(function(t,e){return!z(u,e)}).reduce(function(t,e){return n.removeAttribute(e),t+1},0);i.length===l?n.removeAttribute(t):n.setAttribute(t,i.sort().join(","))}function W(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,i=arguments.length>4?arguments[4]:void 0,o=arguments.length>5?arguments[5]:void 0,a=e.attribute,u=e.tagIDKeyName,s=A.slice();s.push(u);var c=[],l={appId:t,attribute:a,type:n,tagIDKeyName:u},f={head:C(i,l),pbody:C(o,l,{pbody:!0}),body:C(o,l,{body:!0})};if(r.length>1){var d=[];r=r.filter(function(t){var e=JSON.stringify(t),n=!z(d,e);return d.push(e),n})}r.forEach(function(e){if(!e.skip){var r=document.createElement(n);r.setAttribute(a,t);var i=function(t){if(!e.hasOwnProperty(t))return"continue";if("innerHTML"===t)return r.innerHTML=e.innerHTML,"continue";if("json"===t)return r.innerHTML=JSON.stringify(e.json),"continue";if("cssText"===t)return r.styleSheet?r.styleSheet.cssText=e.cssText:r.appendChild(document.createTextNode(e.cssText)),"continue";if("callback"===t)return r.onload=function(){return e[t](r)},"continue";var n=z(s,t)?"data-".concat(t):t,i=z(I,t);if(i&&!e[t])return"continue";var o=i?"":e[t];r.setAttribute(n,o)};for(var o in e)i(o);var u,l=f[function(t){var e=t.body,n=t.pbody;return e?"body":n?"pbody":"head"}(e)];l.some(function(t,e){return u=e,r.isEqualNode(t)})&&(u||0===u)?l.splice(u,1):c.push(r)}});var v=[];for(var h in f)Array.prototype.push.apply(v,f[h]);return v.forEach(function(t){t.parentNode.removeChild(t)}),c.forEach(function(t){t.hasAttribute("data-body")?o.appendChild(t):t.hasAttribute("data-pbody")?o.insertBefore(t,o.firstChild):i.appendChild(t)}),{oldTags:v,newTags:c}}function G(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(){var e=j(t,this.$root),n=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=arguments.length>3?arguments[3]:void 0;return e.title&&(e.titleChunk=e.title),e.titleTemplate&&"%s"!==e.titleTemplate&&O({component:r,contentKeyName:"title"},e,e.titleTemplate,e.titleChunk||""),e.base&&(e.base=Object.keys(e.base).length?[e.base]:[]),K(t,e,n)}(t,e,D,this.$root),r=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,r=e.ssrAttribute,i=e.ssrAppId,a={},u=P(a,"html");if(t===i&&u.hasAttribute(r)){u.removeAttribute(r);var s=!1;return N.forEach(function(t){n[t]&&H(e,t,n[t])&&(s=!0)}),s&&B(),!1}var c,l={},f={};for(var d in n)if(!z(_,d))if("title"!==d){if(z(T,d)){var v=d.substr(0,4);V(e,n[d],P(a,v))}else if(o(n[d])){var h=W(t,e,d,n[d],P(a,"head"),P(a,"body")),p=h.oldTags,m=h.newTags;m.length&&(l[d]=m,f[d]=p)}}else((c=n.title)||""===c)&&(document.title=c);return{addedTags:l,removedTags:f}}(this.$root._vueMeta.appId,t,n);return r&&c(n.changed)&&n.changed(n,r.addedTags,r.removedTags),{vm:this,metaInfo:n,tags:r}}}function J(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t.__vuemeta_installed||(t.__vuemeta_installed=!0,e=function(t){for(var e in t=u(t)?t:{},$)t[e]||(t[e]=$[e]);return t}(e),t.prototype.$meta=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=G(t),n=function(){};return function(){return this.$root._vueMeta?{getOptions:function(){return function(t){var e={};for(var n in t)e[n]=t[n];return e}(t)},refresh:e.bind(this),inject:n,pause:w.bind(this),resume:S.bind(this)}:{getOptions:y,refresh:y,inject:y,pause:y,resume:y}}}(e),t.mixin(function(t,e){var r=["activated","deactivated","beforeMount"];return{beforeCreate:function(){var i=this;if(Object.defineProperty(this,"_hasMetaInfo",{configurable:!0,get:function(){return t.config.devtools&&!this.$root._vueMeta.hasMetaInfoDeprecationWarningShown&&(m("VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead"),this.$root._vueMeta.hasMetaInfoDeprecationWarningShown=!0),d(this)}}),!a(this.$options[e.keyName])&&null!==this.$options[e.keyName]){if(this.$root._vueMeta||(this.$root._vueMeta={appId:g},g++),!this._vueMeta){this._vueMeta=!0;for(var o=this.$parent;o&&o!==this.$root;)a(o._vueMeta)&&(o._vueMeta=!1),o=o.$parent}c(this.$options[e.keyName])&&(this.$options.computed||(this.$options.computed={}),this.$options.computed.$metaInfo=this.$options[e.keyName],this.$isServer||f(this.$options,"created",function(){i.$watch("$metaInfo",function(){n(this,"watcher")})})),a(this.$root._vueMeta.initialized)&&(this.$root._vueMeta.initialized=this.$isServer,this.$root._vueMeta.initialized||(f(this.$options,"beforeMount",function(){i.$root.$el&&i.$root.$el.hasAttribute&&i.$root.$el.hasAttribute("data-server-rendered")&&(i.$root._vueMeta.appId=e.ssrAppId)}),f(this.$options,"mounted",function(){i.$root._vueMeta.initialized||(i.$root._vueMeta.initializing=!0,i.$nextTick(function(){var t=this,r=this.$root.$meta().refresh(),i=r.tags,o=r.metaInfo;!1===i&&null===this.$root._vueMeta.initialized&&this.$nextTick(function(){return n(t,"initializing")}),this.$root._vueMeta.initialized=!0,delete this.$root._vueMeta.initializing,!e.refreshOnceOnNavigation&&o.afterNavigation&&v(this)}))}),e.refreshOnceOnNavigation&&v(this))),this.$isServer||(r.forEach(function(t){f(i.$options,t,function(){return n(i,t)})}),f(this.$options,"destroyed",function(){var t=setInterval(function(){i.$el&&null!==i.$el.offsetParent||(clearInterval(t),i.$parent&&n(i,"destroyed"))},50)}))}}}}(t,e)))}a(window)||a(window.Vue)||J(window.Vue);var F={version:"2.2.0",install:J,hasMetaInfo:d};export default F; diff --git a/dist/vue-meta.esm.js b/dist/vue-meta.esm.js index dd6884f..722ef11 100644 --- a/dist/vue-meta.esm.js +++ b/dist/vue-meta.esm.js @@ -1,5 +1,5 @@ /** - * vue-meta v2.1.1 + * vue-meta v2.2.0 * (c) 2019 * - Declan de Wet * - Sébastien Chopin (@Atinux) @@ -9,7 +9,7 @@ import deepmerge from 'deepmerge'; -var version = "2.1.1"; +var version = "2.2.0"; // store an id to keep track of DOM updates var batchId = null; @@ -59,55 +59,6 @@ function _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(); } @@ -252,13 +203,13 @@ var hasGlobalWindow = hasGlobalWindowFn(); var _global = hasGlobalWindow ? window : global; var console = _global.console = _global.console || {}; -function warn() { +function warn(str) { /* istanbul ignore next */ if (!console || !console.warn) { return; } - console.warn.apply(console, arguments); + console.warn(str); } var appId = 1; @@ -527,29 +478,6 @@ function resume() { } } -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 - - - if (!template) { - return false; - } - - if (isUndefined(chunk)) { - chunk = headObject[contentKeyName]; - } - - headObject[contentKeyName] = isFunction(template) ? template.call(component, chunk) : template.replace(/%s/g, chunk); - return true; -} - /* * To reduce build size, this file provides simple polyfills without * overly excessive type checking and without modifying @@ -559,14 +487,36 @@ function applyTemplate(_ref, headObject, template, chunk) { * 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 (var 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 (var idx in array) { + if (array[idx] === value) { + return true; + } + } + + return false; + } return array.includes(value); } @@ -574,13 +524,12 @@ function includes(array, value) { var serverSequences = [[/&/g, '&'], [/</g, '<'], [/>/g, '>'], [/"/g, '"'], [/'/g, ''']]; var clientSequences = [[/&/g, "&"], [/</g, "<"], [/>/g, ">"], [/"/g, "\""], [/'/g, "'"]]; // sanitizes potentially dangerous characters -function escape(info, options, escapeOptions) { +function escape(info, options, escapeOptions, escapeKeys) { var tagIDKeyName = options.tagIDKeyName; var _escapeOptions$doEsca = escapeOptions.doEscape, doEscape = _escapeOptions$doEsca === void 0 ? function (v) { return v; - } : _escapeOptions$doEsca, - escapeKeys = escapeOptions.escapeKeys; + } : _escapeOptions$doEsca; var escaped = {}; for (var key in info) { @@ -616,17 +565,13 @@ function escape(info, options, escapeOptions) { } else if (isArray(value)) { escaped[key] = value.map(function (v) { if (isPureObject(v)) { - return escape(v, options, _objectSpread2({}, escapeOptions, { - escapeKeys: true - })); + return escape(v, options, escapeOptions, true); } return doEscape(v); }); } else if (isPureObject(value)) { - escaped[key] = escape(value, options, _objectSpread2({}, escapeOptions, { - escapeKeys: true - })); + escaped[key] = escape(value, options, escapeOptions, true); } else { escaped[key] = value; } @@ -643,6 +588,56 @@ function escape(info, options, escapeOptions) { return escaped; } +function escapeMetaInfo(options, info) { + var escapeSequences = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; + 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(function (disableKey, index) { + if (index === 0) { + ensureIsArray(info, disableKey); + } else if (index === 1) { + for (var key in info[disableKey]) { + ensureIsArray(info[disableKey], key); + } + } + + escapeOptions[disableKey] = info[disableKey]; + }); // begin sanitization + + return escape(info, options, escapeOptions); +} + +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 + + + if (!template) { + return false; + } + + if (isUndefined(chunk)) { + chunk = headObject[contentKeyName]; + } + + headObject[contentKeyName] = isFunction(template) ? template.call(component, chunk) : template.replace(/%s/g, chunk); + return true; +} function _arrayMerge(_ref, target, source) { var component = _ref.component, @@ -747,6 +742,11 @@ function merge(target, source) { }); } +function getComponentMetaInfo() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var component = arguments.length > 1 ? arguments[1] : undefined; + return getComponentOption(options, component, defaultInfo); +} /** * Returns the `opts.option` $option value of the given `opts.component`. * If methods are encountered, they will be bound to the component context. @@ -835,12 +835,12 @@ function getComponentOption() { function getMetaInfo() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - var component = arguments.length > 1 ? arguments[1] : undefined; + var info = arguments.length > 1 ? arguments[1] : undefined; var escapeSequences = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; - // collect & aggregate all metaInfo $options - var info = getComponentOption(options, component, defaultInfo); // Remove all "template" tags from meta - // backup the title chunk in case user wants access to it + var component = arguments.length > 3 ? arguments[3] : undefined; + // 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 @@ -859,31 +859,7 @@ function getMetaInfo() { info.base = Object.keys(info.base).length ? [info.base] : []; } - 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(function (disableKey, index) { - if (index === 0) { - ensureIsArray(info, disableKey); - } else if (index === 1) { - for (var key in info[disableKey]) { - ensureIsArray(info[disableKey], key); - } - } - - escapeOptions[disableKey] = info[disableKey]; - }); // begin sanitization - - info = escape(info, options, escapeOptions); - return info; + return escapeMetaInfo(options, info, escapeSequences); } function getTag(tags, tag) { @@ -932,35 +908,14 @@ function addCallback(query, callback) { function addCallbacks(_ref, type, tags, autoAddListeners) { var tagIDKeyName = _ref.tagIDKeyName; var hasAsyncCallback = false; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - 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); + tags.forEach(function (tag) { + if (!tag[tagIDKeyName] || !tag.callback) { + return; } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } + + hasAsyncCallback = true; + addCallback("".concat(type, "[data-").concat(tagIDKeyName, "=\"").concat(tag[tagIDKeyName], "\"]"), tag.callback); + }); if (!autoAddListeners || !hasAsyncCallback) { return hasAsyncCallback; @@ -982,10 +937,10 @@ function addListeners() { }; } function applyCallbacks(matchElement) { - var _loop = function _loop() { - var _callbacks$_i = _slicedToArray(_callbacks[_i], 2), - query = _callbacks$_i[0], - callback = _callbacks$_i[1]; + callbacks.forEach(function (_ref2) { + var _ref3 = _slicedToArray(_ref2, 2), + query = _ref3[0], + callback = _ref3[1]; var selector = "".concat(query, "[onload=\"this.__vm_l=1\"]"); var elements = []; @@ -998,79 +953,48 @@ function applyCallbacks(matchElement) { elements = [matchElement]; } - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; + elements.forEach(function (element) { + /* __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) { + return; + } - 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 + 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 */ - 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.__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_l) { - onload(); - return "continue"; - } - - if (!element.__vm_ev) { - element.__vm_ev = true; - element.addEventListener('load', onload); - } + 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 + */ - for (var _iterator2 = elements[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var _ret = _loop2(); - if (_ret === "continue") continue; + if (element.__vm_l) { + onload(); + return; } - } 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(); - } + if (!element.__vm_ev) { + element.__vm_ev = true; + element.addEventListener('load', onload); + } + }); + }); } /** @@ -1149,7 +1073,8 @@ function updateTag(appId) { var body = arguments.length > 5 ? arguments[5] : undefined; var attribute = options.attribute, tagIDKeyName = options.tagIDKeyName; - var dataAttributes = [tagIDKeyName].concat(_toConsumableArray(commonDataAttributes)); + var dataAttributes = commonDataAttributes.slice(); + dataAttributes.push(tagIDKeyName); var newElements = []; var queryOptions = { appId: appId, @@ -1180,141 +1105,105 @@ function updateTag(appId) { }); } - if (tags.length) { - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; + tags.forEach(function (tag) { + if (tag.skip) { + return; + } - try { - var _loop = function _loop() { - var tag = _step.value; + var newElement = document.createElement(type); + newElement.setAttribute(attribute, appId); - if (tag.skip) { - return "continue"; + var _loop = function _loop(attr) { + /* istanbul ignore next */ + if (!tag.hasOwnProperty(attr)) { + return "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)); } - var newElement = document.createElement(type); - newElement.setAttribute(attribute, appId); + return "continue"; + } - var _loop2 = function _loop2(attr) { - /* istanbul ignore next */ - if (!tag.hasOwnProperty(attr)) { - return "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); + if (attr === 'callback') { + newElement.onload = function () { + return tag[attr](newElement); }; - for (var attr in tag) { - var _ret2 = _loop2(attr); - - if (_ret2 === "continue") continue; - } - - var oldElements = currentElements[getElementsKey(tag)]; // Remove a duplicate tag from domTagstoRemove, so it isn't cleared. - - 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); - } - }; - - for (var _iterator = tags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var _ret = _loop(); - - if (_ret === "continue") continue; + return "continue"; } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } + + 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 _ret = _loop(attr); + + if (_ret === "continue") continue; } - } + var oldElements = currentElements[getElementsKey(tag)]; // Remove a duplicate tag from domTagstoRemove, so it isn't cleared. + + var indexToDelete; + 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); + } + }); var oldElements = []; - 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)); + for (var _type in currentElements) { + Array.prototype.push.apply(oldElements, currentElements[_type]); } // remove old elements - for (var _i2 = 0, _oldElements = oldElements; _i2 < _oldElements.length; _i2++) { - var element = _oldElements[_i2]; + oldElements.forEach(function (element) { element.parentNode.removeChild(element); - } // insert new elements + }); // insert new elements - - for (var _i3 = 0, _newElements = newElements; _i3 < _newElements.length; _i3++) { - var _element = _newElements[_i3]; - - if (_element.hasAttribute('data-body')) { - body.appendChild(_element); - continue; + newElements.forEach(function (element) { + if (element.hasAttribute('data-body')) { + body.appendChild(element); + return; } - if (_element.hasAttribute('data-pbody')) { - body.insertBefore(_element, body.firstChild); - continue; + if (element.hasAttribute('data-pbody')) { + body.insertBefore(element, body.firstChild); + return; } - head.appendChild(_element); - } - + head.appendChild(element); + }); return { oldTags: oldElements, newTags: newElements @@ -1341,32 +1230,11 @@ function updateClientMetaInfo(appId) { htmlTag.removeAttribute(ssrAttribute); // add load callbacks if the var addLoadListeners = false; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - 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; - } + tagsSupportingOnload.forEach(function (type) { + 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; - } - } - } + }); if (addLoadListeners) { addListeners(); @@ -1379,37 +1247,36 @@ function updateClientMetaInfo(appId) { var addedTags = {}; var removedTags = {}; - for (var _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)) { - var 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; } - var _updateTag = 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; } } @@ -1433,7 +1300,9 @@ function _refresh() { * @return {Object} - new meta info */ return function refresh() { - var metaInfo = getMetaInfo(options, this.$root, clientSequences); + // collect & aggregate all metaInfo $options + var rawInfo = getComponentMetaInfo(options, this.$root); + var metaInfo = getMetaInfo(options, rawInfo, clientSequences, this.$root); var appId = this.$root._vueMeta.appId; var tags = updateClientMetaInfo(appId, options, metaInfo); // emit "event" with new info @@ -1530,7 +1399,7 @@ function tagGenerator() { var type = arguments.length > 1 ? arguments[1] : undefined; var tags = arguments.length > 2 ? arguments[2] : undefined; - var dataAttributes = [tagIDKeyName, 'callback'].concat(_toConsumableArray(commonDataAttributes)); + var dataAttributes = [tagIDKeyName].concat(_toConsumableArray(commonDataAttributes)); return { text: function text() { var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, @@ -1539,7 +1408,11 @@ function tagGenerator() { _ref2$pbody = _ref2.pbody, pbody = _ref2$pbody === void 0 ? false : _ref2$pbody; - // build a string containing all tags of this type + if (!tags || !tags.length) { + return ''; + } // build a string containing all tags of this type + + return tags.reduce(function (tagsStr, tag) { if (tag.skip) { return tagsStr; @@ -1561,6 +1434,11 @@ function tagGenerator() { // these attributes are treated as children on the tag if (tagAttributeAsInnerContent.includes(attr) || attr === 'once') { continue; + } + + if (attr === 'callback') { + attrs += " onload=\"this.__vm_l=1\""; + continue; } // these form the attribute list for this tag @@ -1570,11 +1448,6 @@ function tagGenerator() { prefix = 'data-'; } - if (attr === 'callback') { - attrs += " onload=\"this.__vm_l=1\""; - continue; - } - var isBooleanAttr = !prefix && booleanHtmlAttributes.includes(attr); if (isBooleanAttr && !tag[attr]) { @@ -1612,16 +1485,26 @@ function tagGenerator() { * @return {Object} - the new injector */ -function generateServerInjector(options, type, data) { - if (type === 'title') { - return titleGenerator(options, type, data); +function generateServerInjector(options, newInfo) { + for (var type in defaultInfo) { + if (metaInfoOptionKeys.includes(type)) { + continue; + } + + if (type === 'title') { + newInfo[type] = titleGenerator(options, type, newInfo[type]); + continue; + } + + if (metaInfoAttributeKeys.includes(type)) { + newInfo[type] = attributeGenerator(options, type, newInfo[type]); + continue; + } + + newInfo[type] = tagGenerator(options, type, newInfo[type]); } - if (metaInfoAttributeKeys.includes(type)) { - return attributeGenerator(options, type, data); - } - - return tagGenerator(options, type, data); + return newInfo; } function _inject() { @@ -1635,15 +1518,11 @@ function _inject() { * @return {Object} - server meta info with `toString` methods */ return function inject() { - // get meta info with sensible defaults - var metaInfo = getMetaInfo(options, this.$root, serverSequences); // generate server injectors - - for (var key in metaInfo) { - if (!metaInfoOptionKeys.includes(key) && metaInfo.hasOwnProperty(key)) { - metaInfo[key] = generateServerInjector(options, key, metaInfo[key]); - } - } + // collect & aggregate all metaInfo $options + var rawInfo = getComponentMetaInfo(options, this.$root); + var metaInfo = getMetaInfo(options, rawInfo, serverSequences, this.$root); // generate server injectors + generateServerInjector(options, metaInfo); return metaInfo; }; } @@ -1674,6 +1553,12 @@ function _$meta() { }; } +function generate(rawInfo) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var metaInfo = getMetaInfo(setOptions(options), rawInfo, serverSequences); + return generateServerInjector(options, metaInfo); +} + /** * Plugin install function. * @param {Function} Vue - the Vue constructor. @@ -1695,7 +1580,8 @@ function install(Vue) { var index = { version: version, install: install, - hasMetaInfo: hasMetaInfo + hasMetaInfo: hasMetaInfo, + generate: generate }; export default index; diff --git a/dist/vue-meta.js b/dist/vue-meta.js index 98b5e1f..f869e7d 100644 --- a/dist/vue-meta.js +++ b/dist/vue-meta.js @@ -1,5 +1,5 @@ /** - * vue-meta v2.1.1 + * vue-meta v2.2.0 * (c) 2019 * - Declan de Wet * - Sébastien Chopin (@Atinux) @@ -13,7 +13,7 @@ (global = global || self, global.VueMeta = factory()); }(this, function () { 'use strict'; - var version = "2.1.1"; + var version = "2.2.0"; // store an id to keep track of DOM updates var batchId = null; @@ -63,79 +63,14 @@ 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; @@ -162,10 +97,6 @@ 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"); } @@ -256,13 +187,13 @@ var _global = hasGlobalWindow ? window : global; var console = _global.console = _global.console || {}; - function warn() { + function warn(str) { /* istanbul ignore next */ if (!console || !console.warn) { return; } - console.warn.apply(console, arguments); + console.warn(str); } var showWarningNotSupported = function showWarningNotSupported() { return warn('This vue app/component has no vue-meta configuration'); @@ -527,29 +458,6 @@ } } - 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 - - - if (!template) { - return false; - } - - if (isUndefined(chunk)) { - chunk = headObject[contentKeyName]; - } - - headObject[contentKeyName] = isFunction(template) ? template.call(component, chunk) : template.replace(/%s/g, chunk); - return true; - } - /* * To reduce build size, this file provides simple polyfills without * overly excessive type checking and without modifying @@ -559,27 +467,48 @@ * 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 (var 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 (var idx in array) { + if (array[idx] === value) { + return true; + } + } + + return false; + } return array.includes(value); } var clientSequences = [[/&/g, "&"], [/</g, "<"], [/>/g, ">"], [/"/g, "\""], [/'/g, "'"]]; // sanitizes potentially dangerous characters - function escape(info, options, escapeOptions) { + function escape(info, options, escapeOptions, escapeKeys) { var tagIDKeyName = options.tagIDKeyName; var _escapeOptions$doEsca = escapeOptions.doEscape, doEscape = _escapeOptions$doEsca === void 0 ? function (v) { return v; - } : _escapeOptions$doEsca, - escapeKeys = escapeOptions.escapeKeys; + } : _escapeOptions$doEsca; var escaped = {}; for (var key in info) { @@ -615,17 +544,13 @@ } else if (isArray(value)) { escaped[key] = value.map(function (v) { if (isPureObject(v)) { - return escape(v, options, _objectSpread2({}, escapeOptions, { - escapeKeys: true - })); + return escape(v, options, escapeOptions, true); } return doEscape(v); }); } else if (isPureObject(value)) { - escaped[key] = escape(value, options, _objectSpread2({}, escapeOptions, { - escapeKeys: true - })); + escaped[key] = escape(value, options, escapeOptions, true); } else { escaped[key] = value; } @@ -642,6 +567,33 @@ return escaped; } + function escapeMetaInfo(options, info) { + var escapeSequences = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; + 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(function (disableKey, index) { + if (index === 0) { + ensureIsArray(info, disableKey); + } else if (index === 1) { + for (var key in info[disableKey]) { + ensureIsArray(info[disableKey], key); + } + } + + escapeOptions[disableKey] = info[disableKey]; + }); // begin sanitization + + return escape(info, options, escapeOptions); + } var isMergeableObject = function isMergeableObject(value) { return isNonNullObject(value) && !isSpecial(value); @@ -746,6 +698,29 @@ var deepmerge_1 = deepmerge; var cjs = deepmerge_1; + 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 + + + if (!template) { + return false; + } + + if (isUndefined(chunk)) { + chunk = headObject[contentKeyName]; + } + + headObject[contentKeyName] = isFunction(template) ? template.call(component, chunk) : template.replace(/%s/g, chunk); + return true; + } + function _arrayMerge(_ref, target, source) { var component = _ref.component, tagIDKeyName = _ref.tagIDKeyName, @@ -849,6 +824,11 @@ }); } + function getComponentMetaInfo() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var component = arguments.length > 1 ? arguments[1] : undefined; + return getComponentOption(options, component, defaultInfo); + } /** * Returns the `opts.option` $option value of the given `opts.component`. * If methods are encountered, they will be bound to the component context. @@ -937,12 +917,12 @@ function getMetaInfo() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - var component = arguments.length > 1 ? arguments[1] : undefined; + var info = arguments.length > 1 ? arguments[1] : undefined; var escapeSequences = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; - // collect & aggregate all metaInfo $options - var info = getComponentOption(options, component, defaultInfo); // Remove all "template" tags from meta - // backup the title chunk in case user wants access to it + var component = arguments.length > 3 ? arguments[3] : undefined; + // 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 @@ -961,31 +941,7 @@ info.base = Object.keys(info.base).length ? [info.base] : []; } - 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(function (disableKey, index) { - if (index === 0) { - ensureIsArray(info, disableKey); - } else if (index === 1) { - for (var key in info[disableKey]) { - ensureIsArray(info[disableKey], key); - } - } - - escapeOptions[disableKey] = info[disableKey]; - }); // begin sanitization - - info = escape(info, options, escapeOptions); - return info; + return escapeMetaInfo(options, info, escapeSequences); } function getTag(tags, tag) { @@ -1034,35 +990,14 @@ function addCallbacks(_ref, type, tags, autoAddListeners) { var tagIDKeyName = _ref.tagIDKeyName; var hasAsyncCallback = false; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - 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); + tags.forEach(function (tag) { + if (!tag[tagIDKeyName] || !tag.callback) { + return; } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } + + hasAsyncCallback = true; + addCallback("".concat(type, "[data-").concat(tagIDKeyName, "=\"").concat(tag[tagIDKeyName], "\"]"), tag.callback); + }); if (!autoAddListeners || !hasAsyncCallback) { return hasAsyncCallback; @@ -1084,10 +1019,10 @@ }; } function applyCallbacks(matchElement) { - var _loop = function _loop() { - var _callbacks$_i = _slicedToArray(_callbacks[_i], 2), - query = _callbacks$_i[0], - callback = _callbacks$_i[1]; + callbacks.forEach(function (_ref2) { + var _ref3 = _slicedToArray(_ref2, 2), + query = _ref3[0], + callback = _ref3[1]; var selector = "".concat(query, "[onload=\"this.__vm_l=1\"]"); var elements = []; @@ -1100,79 +1035,48 @@ elements = [matchElement]; } - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; + elements.forEach(function (element) { + /* __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) { + return; + } - 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 + 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 */ - 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.__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_l) { - onload(); - return "continue"; - } - - if (!element.__vm_ev) { - element.__vm_ev = true; - element.addEventListener('load', onload); - } + 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 + */ - for (var _iterator2 = elements[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var _ret = _loop2(); - if (_ret === "continue") continue; + if (element.__vm_l) { + onload(); + return; } - } 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(); - } + if (!element.__vm_ev) { + element.__vm_ev = true; + element.addEventListener('load', onload); + } + }); + }); } /** @@ -1251,7 +1155,8 @@ var body = arguments.length > 5 ? arguments[5] : undefined; var attribute = options.attribute, tagIDKeyName = options.tagIDKeyName; - var dataAttributes = [tagIDKeyName].concat(_toConsumableArray(commonDataAttributes)); + var dataAttributes = commonDataAttributes.slice(); + dataAttributes.push(tagIDKeyName); var newElements = []; var queryOptions = { appId: appId, @@ -1282,141 +1187,105 @@ }); } - if (tags.length) { - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; + tags.forEach(function (tag) { + if (tag.skip) { + return; + } - try { - var _loop = function _loop() { - var tag = _step.value; + var newElement = document.createElement(type); + newElement.setAttribute(attribute, appId); - if (tag.skip) { - return "continue"; + var _loop = function _loop(attr) { + /* istanbul ignore next */ + if (!tag.hasOwnProperty(attr)) { + return "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)); } - var newElement = document.createElement(type); - newElement.setAttribute(attribute, appId); + return "continue"; + } - var _loop2 = function _loop2(attr) { - /* istanbul ignore next */ - if (!tag.hasOwnProperty(attr)) { - return "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); + if (attr === 'callback') { + newElement.onload = function () { + return tag[attr](newElement); }; - for (var attr in tag) { - var _ret2 = _loop2(attr); - - if (_ret2 === "continue") continue; - } - - var oldElements = currentElements[getElementsKey(tag)]; // Remove a duplicate tag from domTagstoRemove, so it isn't cleared. - - 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); - } - }; - - for (var _iterator = tags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var _ret = _loop(); - - if (_ret === "continue") continue; + return "continue"; } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } + + 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 _ret = _loop(attr); + + if (_ret === "continue") continue; } - } + var oldElements = currentElements[getElementsKey(tag)]; // Remove a duplicate tag from domTagstoRemove, so it isn't cleared. + + var indexToDelete; + 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); + } + }); var oldElements = []; - 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)); + for (var _type in currentElements) { + Array.prototype.push.apply(oldElements, currentElements[_type]); } // remove old elements - for (var _i2 = 0, _oldElements = oldElements; _i2 < _oldElements.length; _i2++) { - var element = _oldElements[_i2]; + oldElements.forEach(function (element) { element.parentNode.removeChild(element); - } // insert new elements + }); // insert new elements - - for (var _i3 = 0, _newElements = newElements; _i3 < _newElements.length; _i3++) { - var _element = _newElements[_i3]; - - if (_element.hasAttribute('data-body')) { - body.appendChild(_element); - continue; + newElements.forEach(function (element) { + if (element.hasAttribute('data-body')) { + body.appendChild(element); + return; } - if (_element.hasAttribute('data-pbody')) { - body.insertBefore(_element, body.firstChild); - continue; + if (element.hasAttribute('data-pbody')) { + body.insertBefore(element, body.firstChild); + return; } - head.appendChild(_element); - } - + head.appendChild(element); + }); return { oldTags: oldElements, newTags: newElements @@ -1443,32 +1312,11 @@ htmlTag.removeAttribute(ssrAttribute); // add load callbacks if the var addLoadListeners = false; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - 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; - } + tagsSupportingOnload.forEach(function (type) { + 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; - } - } - } + }); if (addLoadListeners) { addListeners(); @@ -1481,37 +1329,36 @@ var addedTags = {}; var removedTags = {}; - for (var _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)) { - var 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; } - var _updateTag = 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; } } @@ -1535,7 +1382,9 @@ * @return {Object} - new meta info */ return function refresh() { - var metaInfo = getMetaInfo(options, this.$root, clientSequences); + // collect & aggregate all metaInfo $options + var rawInfo = getComponentMetaInfo(options, this.$root); + var metaInfo = getMetaInfo(options, rawInfo, clientSequences, this.$root); var appId = this.$root._vueMeta.appId; var tags = updateClientMetaInfo(appId, options, metaInfo); // emit "event" with new info diff --git a/dist/vue-meta.min.js b/dist/vue-meta.min.js index 538d736..0730c0a 100644 --- a/dist/vue-meta.min.js +++ b/dist/vue-meta.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).VueMeta=t()}(this,function(){"use strict";var e=null;function t(t,n){t.$root._vueMeta.initialized||!t.$root._vueMeta.initializing&&"watcher"!==n||(t.$root._vueMeta.initialized=null),t.$root._vueMeta.initialized&&!t.$root._vueMeta.paused&&function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10;clearTimeout(e),e=setTimeout(function(){t()},n)}(function(){return t.$meta().refresh()})}function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(n,!0).forEach(function(t){r(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(n).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function a(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],r=!0,o=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(r=(a=u.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{r||null==u.return||u.return()}finally{if(o)throw i}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function u(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function c(e){return Array.isArray(e)}function l(e){return void 0===e}function s(e){return"object"===n(e)}function f(e){return"object"===n(e)&&null!==e}function d(e){return"function"==typeof e}function v(e,t){return t&&s(e)?(c(e[t])||(e[t]=[]),e):c(e)?e:[]}function h(e,t,n){v(e,t),e[t].push(n)}function p(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this;return e&&(!0===e._vueMeta||s(e._vueMeta))}function y(e){if(!e.$root._vueMeta.navGuards&&e.$root.$router){e.$root._vueMeta.navGuards=!0;var t=e.$root.$router,n=e.$root.$meta();t.beforeEach(function(e,t,r){n.pause(),r()}),t.afterEach(function(){var e=n.resume().metaInfo;e&&e.afterNavigation&&d(e.afterNavigation)&&e.afterNavigation(e)})}}var m=function(){try{return!l(window)}catch(e){return!1}}()?window:global,b=m.console=m.console||{};function g(){b&&b.warn&&b.warn.apply(b,arguments)}var $=function(){return g("This vue app/component has no vue-meta configuration")},_=1;var M={title:void 0,titleChunk:"",titleTemplate:"%s",htmlAttrs:{},bodyAttrs:{},headAttrs:{},base:[],link:[],meta:[],style:[],script:[],noscript:[],__dangerouslyDisableSanitizers:[],__dangerouslyDisableSanitizersByTagID:{}},w={keyName:"metaInfo",attribute:"data-vue-meta",ssrAttribute:"data-vue-meta-server-rendered",tagIDKeyName:"vmid",contentKeyName:"content",metaTemplateKeyName:"template",ssrAppId:"ssr"},O=["titleChunk","titleTemplate","changed","__dangerouslyDisableSanitizers","__dangerouslyDisableSanitizersByTagID"],A=["__dangerouslyDisableSanitizers","__dangerouslyDisableSanitizersByTagID"],T=["htmlAttrs","headAttrs","bodyAttrs"],j=["link","style","script"],N=["body","pbody"],S=["allowfullscreen","amp","async","autofocus","autoplay","checked","compact","controls","declare","default","defaultchecked","defaultmuted","defaultselected","defer","disabled","enabled","formnovalidate","hidden","indeterminate","inert","ismap","itemscope","loop","multiple","muted","nohref","noresize","noshade","novalidate","nowrap","open","pauseonexit","readonly","required","reversed","scoped","seamless","selected","sortable","truespeed","typemustmatch","visible"];function I(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this.$root._vueMeta.paused=!0,function(){return D(e)}}function D(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];if(this.$root._vueMeta.paused=!1,e)return this.$root.$meta().refresh()}function k(e,t,n,r){var o=e.component,i=e.metaTemplateKeyName,a=e.contentKeyName;return l(n)&&(n=t[i],delete t[i]),!!n&&(l(r)&&(r=t[a]),t[a]=d(n)?n.call(o,r):n.replace(/%s/g,r),!0)}function E(e,t){return e.findIndex(t,arguments[2])}function K(e){return Array.from(e)}function P(e,t){return e.includes(t)}var z=[[/&/g,"&"],[/</g,"<"],[/>/g,">"],[/"/g,'"'],[/'/g,"'"]];var x=function(e){return function(e){return!!e&&"object"===n(e)}(e)&&!function(e){var t=Object.prototype.toString.call(e);return"[object RegExp]"===t||"[object Date]"===t||function(e){return e.$$typeof===C}(e)}(e)};var C="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function L(e,t){return!1!==t.clone&&t.isMergeableObject(e)?q((n=e,Array.isArray(n)?[]:{}),e,t):e;var n}function H(e,t,n){return e.concat(t).map(function(e){return L(e,n)})}function B(e){return Object.keys(e).concat(function(e){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter(function(t){return e.propertyIsEnumerable(t)}):[]}(e))}function V(e,t,n){var r={};return n.isMergeableObject(e)&&B(e).forEach(function(t){r[t]=L(e[t],n)}),B(t).forEach(function(o){n.isMergeableObject(t[o])&&e[o]?r[o]=function(e,t){if(!t.customMerge)return q;var n=t.customMerge(e);return"function"==typeof n?n:q}(o,n)(e[o],t[o],n):r[o]=L(t[o],n)}),r}function q(e,t,n){(n=n||{}).arrayMerge=n.arrayMerge||H,n.isMergeableObject=n.isMergeableObject||x;var r=Array.isArray(t);return r===Array.isArray(e)?r?n.arrayMerge(e,t,n):V(e,t,n):L(t,n)}q.all=function(e,t){if(!Array.isArray(e))throw new Error("first argument should be an array");return e.reduce(function(e,n){return q(e,n,t)},{})};var W=q;function G(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return t.hasOwnProperty("title")&&void 0===t.title&&delete t.title,T.forEach(function(e){if(t[e])for(var n in t[e])t[e].hasOwnProperty(n)&&void 0===t[e][n]&&(P(S,n)&&g("VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details"),delete t[e][n])}),W(e,t,{arrayMerge:function(e,t){return function(e,t,n){var r=e.component,o=e.tagIDKeyName,i=e.metaTemplateKeyName,a=e.contentKeyName,u=[];return t.forEach(function(e,t){if(e[o]){var c=E(n,function(t){return t[o]===e[o]}),l=n[c];if(-1!==c){if(l.hasOwnProperty(a)&&void 0===l[a]||l.hasOwnProperty("innerHTML")&&void 0===l.innerHTML)return u.push(e),void n.splice(c,1);if(null!==l[a]&&null!==l.innerHTML){var s=e[i];s&&(l[i]?l[a]||k({component:r,metaTemplateKeyName:i,contentKeyName:a},l,void 0,e[a]):k({component:r,metaTemplateKeyName:i,contentKeyName:a},l,s))}else n.splice(c,1)}else u.push(e)}else u.push(e)}),u.concat(n)}(n,e,t)}})}function J(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=e.keyName,o=e.metaTemplateKeyName,i=e.tagIDKeyName,a=t.$options,u=t.$children;if(t._inactive)return n;if(a[r]){var c=a[r];if(d(c)&&(c=c.call(t)),!s(c))return n;n=G(n,c,e)}return u.length&&u.forEach(function(t){(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this;return e&&!l(e._vueMeta)})(t)&&(n=J(e,t,n))}),o&&n.meta&&(n.meta.forEach(function(t){return k(e,t)}),n.meta=n.meta.filter(function(e,t,n){return!e.hasOwnProperty(i)||t===E(n,function(t){return t[i]===e[i]})})),n}function R(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=J(e,t,M);r.title&&(r.titleChunk=r.title),r.titleTemplate&&"%s"!==r.titleTemplate&&k({component:t,contentKeyName:"title"},r,r.titleTemplate,r.titleChunk||""),r.base&&(r.base=Object.keys(r.base).length?[r.base]:[]);var o={doEscape:function(e){return n.reduce(function(e,t){var n=a(t,2),r=n[0],o=n[1];return e.replace(r,o)},e)}};return A.forEach(function(e,t){if(0===t)v(r,e);else if(1===t)for(var n in r[e])v(r[e],n);o[e]=r[e]}),r=function e(t,n,r){var o=n.tagIDKeyName,u=r.doEscape,l=void 0===u?function(e){return e}:u,s=r.escapeKeys,d={};for(var v in t){var h=t[v];if(P(O,v))d[v]=h;else{var p=a(A,1)[0];if(r[p]&&P(r[p],v))d[v]=h;else{var y=t[o];if(y&&(p=A[1],r[p]&&r[p][y]&&P(r[p][y],v)))d[v]=h;else if("string"==typeof h?d[v]=l(h):c(h)?d[v]=h.map(function(t){return f(t)?e(t,n,i({},r,{escapeKeys:!0})):l(t)}):f(h)?d[v]=e(h,n,i({},r,{escapeKeys:!0})):d[v]=h,s){var m=l(v);v!==m&&(d[m]=d[v],delete d[v])}}}}return d}(r,e,o)}function F(e,t){return e[t]||(e[t]=document.getElementsByTagName(t)[0]),e[t]}function Q(e,t){var n=t.appId,r=t.attribute,o=t.type,i=t.tagIDKeyName,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},u=["".concat(o,"[").concat(r,'="').concat(n,'"]'),"".concat(o,"[data-").concat(i,"]")].map(function(e){for(var t in a){var n=a[t],r=n&&!0!==n?'="'.concat(n,'"'):"";e+="[data-".concat(t).concat(r,"]")}return e});return K(e.querySelectorAll(u.join(", ")))}var U=[];function X(e,t){1===arguments.length&&(t=e,e=""),U.push([e,t])}function Y(e,t,n,r){var o=e.tagIDKeyName,i=!1,a=!0,u=!1,c=void 0;try{for(var l,s=n[Symbol.iterator]();!(a=(l=s.next()).done);a=!0){var f=l.value;f[o]&&f.callback&&(i=!0,X("".concat(t,"[data-").concat(o,'="').concat(f[o],'"]'),f.callback))}}catch(e){u=!0,c=e}finally{try{a||null==s.return||s.return()}finally{if(u)throw c}}return r&&i?Z():i}function Z(){!function(){return"complete"===(arguments.length>0&&void 0!==arguments[0]?arguments[0]:document).readyState}()?document.onreadystatechange=function(){ee()}:ee()}function ee(e){for(var t=function(){var t=a(r[n],2),o=t[0],i=t[1],u="".concat(o,'[onload="this.__vm_l=1"]'),c=[];e||(c=K(document.querySelectorAll(u))),e&&e.matches(u)&&(c=[e]);var l=!0,s=!1,f=void 0;try{for(var d,v=function(){var e=d.value;if(e.__vm_cb)return"continue";var t=function(){e.__vm_cb=!0,e.removeAttribute("onload"),i(e)};if(e.__vm_l)return t(),"continue";e.__vm_ev||(e.__vm_ev=!0,e.addEventListener("load",t))},h=c[Symbol.iterator]();!(l=(d=h.next()).done);l=!0)v()}catch(e){s=!0,f=e}finally{try{l||null==h.return||h.return()}finally{if(s)throw f}}},n=0,r=U;n<r.length;n++)t()}function te(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).attribute,t=arguments.length>1?arguments[1]:void 0,n=arguments.length>2?arguments[2]:void 0,r=n.getAttribute(e),o=r?r.split(","):[],i=K(o),a=[];for(var u in t)if(t.hasOwnProperty(u)){var l=P(S,u)?"":c(t[u])?t[u].join(" "):t[u];n.setAttribute(u,l||""),P(o,u)||o.push(u),a.push(i.indexOf(u))}var s=i.filter(function(e,t){return!P(a,t)}).reduce(function(e,t){return n.removeAttribute(t),e+1},0);o.length===s?n.removeAttribute(e):n.setAttribute(e,o.sort().join(","))}function ne(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,o=arguments.length>4?arguments[4]:void 0,i=arguments.length>5?arguments[5]:void 0,a=t.attribute,c=t.tagIDKeyName,l=[c].concat(u(N)),s=[],f={appId:e,attribute:a,type:n,tagIDKeyName:c},d={head:Q(o,f),pbody:Q(i,f,{pbody:!0}),body:Q(i,f,{body:!0})};if(r.length>1){var v=[];r=r.filter(function(e){var t=JSON.stringify(e),n=!P(v,t);return v.push(t),n})}if(r.length){var h=!0,p=!1,y=void 0;try{for(var m,b=function(){var t=m.value;if(t.skip)return"continue";var r=document.createElement(n);r.setAttribute(a,e);var o=function(e){if(!t.hasOwnProperty(e))return"continue";if("innerHTML"===e)return r.innerHTML=t.innerHTML,"continue";if("json"===e)return r.innerHTML=JSON.stringify(t.json),"continue";if("cssText"===e)return r.styleSheet?r.styleSheet.cssText=t.cssText:r.appendChild(document.createTextNode(t.cssText)),"continue";if("callback"===e)return r.onload=function(){return t[e](r)},"continue";var n=P(l,e)?"data-".concat(e):e,o=P(S,e);if(o&&!t[e])return"continue";var i=o?"":t[e];r.setAttribute(n,i)};for(var i in t)o(i);var u=d[function(e){var t=e.body,n=e.pbody;return t?"body":n?"pbody":"head"}(t)],c=void 0;u.some(function(e,t){return c=t,r.isEqualNode(e)})&&(c||0===c)?u.splice(c,1):s.push(r)},g=r[Symbol.iterator]();!(h=(m=g.next()).done);h=!0)b()}catch(e){p=!0,y=e}finally{try{h||null==g.return||g.return()}finally{if(p)throw y}}}for(var $=[],_=0,M=Object.values(d);_<M.length;_++){var w=M[_];$=[].concat(u($),u(w))}for(var O=0,A=$;O<A.length;O++){var T=A[O];T.parentNode.removeChild(T)}for(var j=0,I=s;j<I.length;j++){var D=I[j];D.hasAttribute("data-body")?i.appendChild(D):D.hasAttribute("data-pbody")?i.insertBefore(D,i.firstChild):o.appendChild(D)}return{oldTags:$,newTags:s}}function re(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(){var t=R(e,this.$root,z),n=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,r=t.ssrAttribute,o=t.ssrAppId,i={},a=F(i,"html");if(e===o&&a.hasAttribute(r)){a.removeAttribute(r);var u=!1,l=!0,s=!1,f=void 0;try{for(var d,v=j[Symbol.iterator]();!(l=(d=v.next()).done);l=!0){var h=d.value;n[h]&&Y(t,h,n[h])&&(u=!0)}}catch(e){s=!0,f=e}finally{try{l||null==v.return||v.return()}finally{if(s)throw f}}return u&&Z(),!1}var p,y={},m={};for(var b in n)if(!P(O,b))if("title"!==b){if(P(T,b)){var g=b.substr(0,4);te(t,n[b],F(i,g))}else if(c(n[b])){var $=ne(e,t,b,n[b],F(i,"head"),F(i,"body")),_=$.oldTags,M=$.newTags;M.length&&(y[b]=M,m[b]=_)}}else((p=n.title)||""===p)&&(document.title=p);return{addedTags:y,removedTags:m}}(this.$root._vueMeta.appId,e,t);return n&&d(t.changed)&&t.changed(t,n.addedTags,n.removedTags),{vm:this,metaInfo:t,tags:n}}}function oe(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e.__vuemeta_installed||(e.__vuemeta_installed=!0,n=function(e){for(var t in e=s(e)?e:{},w)e[t]||(e[t]=w[t]);return e}(n),e.prototype.$meta=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=re(e),n=function(){};return function(){return this.$root._vueMeta?{getOptions:function(){return function(e){var t={};for(var n in e)t[n]=e[n];return t}(e)},refresh:t.bind(this),inject:n,pause:I.bind(this),resume:D.bind(this)}:{getOptions:$,refresh:$,inject:$,pause:$,resume:$}}}(n),e.mixin(function(e,n){var r=["activated","deactivated","beforeMount"];return{beforeCreate:function(){var o=this;if(Object.defineProperty(this,"_hasMetaInfo",{configurable:!0,get:function(){return e.config.devtools&&!this.$root._vueMeta.hasMetaInfoDeprecationWarningShown&&(g("VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead"),this.$root._vueMeta.hasMetaInfoDeprecationWarningShown=!0),p(this)}}),!l(this.$options[n.keyName])&&null!==this.$options[n.keyName]){if(this.$root._vueMeta||(this.$root._vueMeta={appId:_},_++),!this._vueMeta){this._vueMeta=!0;for(var i=this.$parent;i&&i!==this.$root;)l(i._vueMeta)&&(i._vueMeta=!1),i=i.$parent}d(this.$options[n.keyName])&&(this.$options.computed||(this.$options.computed={}),this.$options.computed.$metaInfo=this.$options[n.keyName],this.$isServer||h(this.$options,"created",function(){o.$watch("$metaInfo",function(){t(this,"watcher")})})),l(this.$root._vueMeta.initialized)&&(this.$root._vueMeta.initialized=this.$isServer,this.$root._vueMeta.initialized||(h(this.$options,"beforeMount",function(){o.$root.$el&&o.$root.$el.hasAttribute&&o.$root.$el.hasAttribute("data-server-rendered")&&(o.$root._vueMeta.appId=n.ssrAppId)}),h(this.$options,"mounted",function(){o.$root._vueMeta.initialized||(o.$root._vueMeta.initializing=!0,o.$nextTick(function(){var e=this,r=this.$root.$meta().refresh(),o=r.tags,i=r.metaInfo;!1===o&&null===this.$root._vueMeta.initialized&&this.$nextTick(function(){return t(e,"initializing")}),this.$root._vueMeta.initialized=!0,delete this.$root._vueMeta.initializing,!n.refreshOnceOnNavigation&&i.afterNavigation&&y(this)}))}),n.refreshOnceOnNavigation&&y(this))),this.$isServer||(r.forEach(function(e){h(o.$options,e,function(){return t(o,e)})}),h(this.$options,"destroyed",function(){var e=setInterval(function(){o.$el&&null!==o.$el.offsetParent||(clearInterval(e),o.$parent&&t(o,"destroyed"))},50)}))}}}}(e,n)))}return l(window)||l(window.Vue)||oe(window.Vue),{version:"2.1.1",install:oe,hasMetaInfo:p}}); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).VueMeta=t()}(this,function(){"use strict";var e=null;function t(t,n){t.$root._vueMeta.initialized||!t.$root._vueMeta.initializing&&"watcher"!==n||(t.$root._vueMeta.initialized=null),t.$root._vueMeta.initialized&&!t.$root._vueMeta.paused&&function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10;clearTimeout(e),e=setTimeout(function(){t()},n)}(function(){return t.$meta().refresh()})}function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function r(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],r=!0,o=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(r=(a=u.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{r||null==u.return||u.return()}finally{if(o)throw i}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function o(e){return Array.isArray(e)}function i(e){return void 0===e}function a(e){return"object"===n(e)}function u(e){return"object"===n(e)&&null!==e}function c(e){return"function"==typeof e}function s(e,t){return t&&a(e)?(o(e[t])||(e[t]=[]),e):o(e)?e:[]}function f(e,t,n){s(e,t),e[t].push(n)}function l(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this;return e&&(!0===e._vueMeta||a(e._vueMeta))}function d(e){if(!e.$root._vueMeta.navGuards&&e.$root.$router){e.$root._vueMeta.navGuards=!0;var t=e.$root.$router,n=e.$root.$meta();t.beforeEach(function(e,t,r){n.pause(),r()}),t.afterEach(function(){var e=n.resume().metaInfo;e&&e.afterNavigation&&c(e.afterNavigation)&&e.afterNavigation(e)})}}var v=function(){try{return!i(window)}catch(e){return!1}}()?window:global,h=v.console=v.console||{};function p(e){h&&h.warn&&h.warn(e)}var m=function(){return p("This vue app/component has no vue-meta configuration")},y=1;var g={title:void 0,titleChunk:"",titleTemplate:"%s",htmlAttrs:{},bodyAttrs:{},headAttrs:{},base:[],link:[],meta:[],style:[],script:[],noscript:[],__dangerouslyDisableSanitizers:[],__dangerouslyDisableSanitizersByTagID:{}},b={keyName:"metaInfo",attribute:"data-vue-meta",ssrAttribute:"data-vue-meta-server-rendered",tagIDKeyName:"vmid",contentKeyName:"content",metaTemplateKeyName:"template",ssrAppId:"ssr"},$=["titleChunk","titleTemplate","changed","__dangerouslyDisableSanitizers","__dangerouslyDisableSanitizersByTagID"],_=["__dangerouslyDisableSanitizers","__dangerouslyDisableSanitizersByTagID"],M=["htmlAttrs","headAttrs","bodyAttrs"],A=["link","style","script"],T=["body","pbody"],N=["allowfullscreen","amp","async","autofocus","autoplay","checked","compact","controls","declare","default","defaultchecked","defaultmuted","defaultselected","defer","disabled","enabled","formnovalidate","hidden","indeterminate","inert","ismap","itemscope","loop","multiple","muted","nohref","noresize","noshade","novalidate","nowrap","open","pauseonexit","readonly","required","reversed","scoped","seamless","selected","sortable","truespeed","typemustmatch","visible"];function I(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this.$root._vueMeta.paused=!0,function(){return w(e)}}function w(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];if(this.$root._vueMeta.paused=!1,e)return this.$root.$meta().refresh()}function S(e,t){if(!Array.prototype.findIndex){for(var n=0;n<e.length;n++)if(t.call(arguments[2],e[n],n,e))return n;return-1}return e.findIndex(t,arguments[2])}function O(e){return Array.from?Array.from(e):Array.prototype.slice.call(e)}function E(e,t){if(!Array.prototype.includes){for(var n in e)if(e[n]===t)return!0;return!1}return e.includes(t)}var j=[[/&/g,"&"],[/</g,"<"],[/>/g,">"],[/"/g,'"'],[/'/g,"'"]];function k(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],i={doEscape:function(e){return n.reduce(function(e,t){var n=r(t,2),o=n[0],i=n[1];return e.replace(o,i)},e)}};return _.forEach(function(e,n){if(0===n)s(t,e);else if(1===n)for(var r in t[e])s(t[e],r);i[e]=t[e]}),function e(t,n,i,a){var c=n.tagIDKeyName,s=i.doEscape,f=void 0===s?function(e){return e}:s,l={};for(var d in t){var v=t[d];if(E($,d))l[d]=v;else{var h=r(_,1)[0];if(i[h]&&E(i[h],d))l[d]=v;else{var p=t[c];if(p&&(h=_[1],i[h]&&i[h][p]&&E(i[h][p],d)))l[d]=v;else if("string"==typeof v?l[d]=f(v):o(v)?l[d]=v.map(function(t){return u(t)?e(t,n,i,!0):f(t)}):u(v)?l[d]=e(v,n,i,!0):l[d]=v,a){var m=f(d);d!==m&&(l[m]=l[d],delete l[d])}}}}return l}(t,e,i)}var D=function(e){return function(e){return!!e&&"object"===n(e)}(e)&&!function(e){var t=Object.prototype.toString.call(e);return"[object RegExp]"===t||"[object Date]"===t||function(e){return e.$$typeof===z}(e)}(e)};var z="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function K(e,t){return!1!==t.clone&&t.isMergeableObject(e)?L((n=e,Array.isArray(n)?[]:{}),e,t):e;var n}function x(e,t,n){return e.concat(t).map(function(e){return K(e,n)})}function P(e){return Object.keys(e).concat(function(e){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter(function(t){return e.propertyIsEnumerable(t)}):[]}(e))}function C(e,t,n){var r={};return n.isMergeableObject(e)&&P(e).forEach(function(t){r[t]=K(e[t],n)}),P(t).forEach(function(o){n.isMergeableObject(t[o])&&e[o]?r[o]=function(e,t){if(!t.customMerge)return L;var n=t.customMerge(e);return"function"==typeof n?n:L}(o,n)(e[o],t[o],n):r[o]=K(t[o],n)}),r}function L(e,t,n){(n=n||{}).arrayMerge=n.arrayMerge||x,n.isMergeableObject=n.isMergeableObject||D;var r=Array.isArray(t);return r===Array.isArray(e)?r?n.arrayMerge(e,t,n):C(e,t,n):K(t,n)}L.all=function(e,t){if(!Array.isArray(e))throw new Error("first argument should be an array");return e.reduce(function(e,n){return L(e,n,t)},{})};var H=L;function B(e,t,n,r){var o=e.component,a=e.metaTemplateKeyName,u=e.contentKeyName;return i(n)&&(n=t[a],delete t[a]),!!n&&(i(r)&&(r=t[u]),t[u]=c(n)?n.call(o,r):n.replace(/%s/g,r),!0)}function V(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return t.hasOwnProperty("title")&&void 0===t.title&&delete t.title,M.forEach(function(e){if(t[e])for(var n in t[e])t[e].hasOwnProperty(n)&&void 0===t[e][n]&&(E(N,n)&&p("VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details"),delete t[e][n])}),H(e,t,{arrayMerge:function(e,t){return function(e,t,n){var r=e.component,o=e.tagIDKeyName,i=e.metaTemplateKeyName,a=e.contentKeyName,u=[];return t.forEach(function(e,t){if(e[o]){var c=S(n,function(t){return t[o]===e[o]}),s=n[c];if(-1!==c){if(s.hasOwnProperty(a)&&void 0===s[a]||s.hasOwnProperty("innerHTML")&&void 0===s.innerHTML)return u.push(e),void n.splice(c,1);if(null!==s[a]&&null!==s.innerHTML){var f=e[i];f&&(s[i]?s[a]||B({component:r,metaTemplateKeyName:i,contentKeyName:a},s,void 0,e[a]):B({component:r,metaTemplateKeyName:i,contentKeyName:a},s,f))}else n.splice(c,1)}else u.push(e)}else u.push(e)}),u.concat(n)}(n,e,t)}})}function q(){return function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};var n=arguments.length>1?arguments[1]:void 0;var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};var o=t.keyName,u=t.metaTemplateKeyName,s=t.tagIDKeyName;var f=n.$options,l=n.$children;if(n._inactive)return r;if(f[o]){var d=f[o];if(c(d)&&(d=d.call(n)),!a(d))return r;r=V(r,d,t)}l.length&&l.forEach(function(n){(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this;return e&&!i(e._vueMeta)})(n)&&(r=e(t,n,r))});u&&r.meta&&(r.meta.forEach(function(e){return B(t,e)}),r.meta=r.meta.filter(function(e,t,n){return!e.hasOwnProperty(s)||t===S(n,function(t){return t[s]===e[s]})}));return r}(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},arguments.length>1?arguments[1]:void 0,g)}function W(e,t){return e[t]||(e[t]=document.getElementsByTagName(t)[0]),e[t]}function G(e,t){var n=t.appId,r=t.attribute,o=t.type,i=t.tagIDKeyName,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},u=["".concat(o,"[").concat(r,'="').concat(n,'"]'),"".concat(o,"[data-").concat(i,"]")].map(function(e){for(var t in a){var n=a[t],r=n&&!0!==n?'="'.concat(n,'"'):"";e+="[data-".concat(t).concat(r,"]")}return e});return O(e.querySelectorAll(u.join(", ")))}var J=[];function R(e,t,n,r){var o=e.tagIDKeyName,i=!1;return n.forEach(function(e){e[o]&&e.callback&&(i=!0,function(e,t){1===arguments.length&&(t=e,e=""),J.push([e,t])}("".concat(t,"[data-").concat(o,'="').concat(e[o],'"]'),e.callback))}),r&&i?F():i}function F(){!function(){return"complete"===(arguments.length>0&&void 0!==arguments[0]?arguments[0]:document).readyState}()?document.onreadystatechange=function(){Q()}:Q()}function Q(e){J.forEach(function(t){var n=r(t,2),o=n[0],i=n[1],a="".concat(o,'[onload="this.__vm_l=1"]'),u=[];e||(u=O(document.querySelectorAll(a))),e&&e.matches(a)&&(u=[e]),u.forEach(function(e){if(!e.__vm_cb){var t=function(){e.__vm_cb=!0,e.removeAttribute("onload"),i(e)};e.__vm_l?t():e.__vm_ev||(e.__vm_ev=!0,e.addEventListener("load",t))}})})}function U(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).attribute,t=arguments.length>1?arguments[1]:void 0,n=arguments.length>2?arguments[2]:void 0,r=n.getAttribute(e),i=r?r.split(","):[],a=O(i),u=[];for(var c in t)if(t.hasOwnProperty(c)){var s=E(N,c)?"":o(t[c])?t[c].join(" "):t[c];n.setAttribute(c,s||""),E(i,c)||i.push(c),u.push(a.indexOf(c))}var f=a.filter(function(e,t){return!E(u,t)}).reduce(function(e,t){return n.removeAttribute(t),e+1},0);i.length===f?n.removeAttribute(e):n.setAttribute(e,i.sort().join(","))}function X(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,o=arguments.length>4?arguments[4]:void 0,i=arguments.length>5?arguments[5]:void 0,a=t.attribute,u=t.tagIDKeyName,c=T.slice();c.push(u);var s=[],f={appId:e,attribute:a,type:n,tagIDKeyName:u},l={head:G(o,f),pbody:G(i,f,{pbody:!0}),body:G(i,f,{body:!0})};if(r.length>1){var d=[];r=r.filter(function(e){var t=JSON.stringify(e),n=!E(d,t);return d.push(t),n})}r.forEach(function(t){if(!t.skip){var r=document.createElement(n);r.setAttribute(a,e);var o=function(e){if(!t.hasOwnProperty(e))return"continue";if("innerHTML"===e)return r.innerHTML=t.innerHTML,"continue";if("json"===e)return r.innerHTML=JSON.stringify(t.json),"continue";if("cssText"===e)return r.styleSheet?r.styleSheet.cssText=t.cssText:r.appendChild(document.createTextNode(t.cssText)),"continue";if("callback"===e)return r.onload=function(){return t[e](r)},"continue";var n=E(c,e)?"data-".concat(e):e,o=E(N,e);if(o&&!t[e])return"continue";var i=o?"":t[e];r.setAttribute(n,i)};for(var i in t)o(i);var u,f=l[function(e){var t=e.body,n=e.pbody;return t?"body":n?"pbody":"head"}(t)];f.some(function(e,t){return u=t,r.isEqualNode(e)})&&(u||0===u)?f.splice(u,1):s.push(r)}});var v=[];for(var h in l)Array.prototype.push.apply(v,l[h]);return v.forEach(function(e){e.parentNode.removeChild(e)}),s.forEach(function(e){e.hasAttribute("data-body")?i.appendChild(e):e.hasAttribute("data-pbody")?i.insertBefore(e,i.firstChild):o.appendChild(e)}),{oldTags:v,newTags:s}}function Y(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(){var t=q(e,this.$root),n=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=arguments.length>3?arguments[3]:void 0;return t.title&&(t.titleChunk=t.title),t.titleTemplate&&"%s"!==t.titleTemplate&&B({component:r,contentKeyName:"title"},t,t.titleTemplate,t.titleChunk||""),t.base&&(t.base=Object.keys(t.base).length?[t.base]:[]),k(e,t,n)}(e,t,j,this.$root),r=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,r=t.ssrAttribute,i=t.ssrAppId,a={},u=W(a,"html");if(e===i&&u.hasAttribute(r)){u.removeAttribute(r);var c=!1;return A.forEach(function(e){n[e]&&R(t,e,n[e])&&(c=!0)}),c&&F(),!1}var s,f={},l={};for(var d in n)if(!E($,d))if("title"!==d){if(E(M,d)){var v=d.substr(0,4);U(t,n[d],W(a,v))}else if(o(n[d])){var h=X(e,t,d,n[d],W(a,"head"),W(a,"body")),p=h.oldTags,m=h.newTags;m.length&&(f[d]=m,l[d]=p)}}else((s=n.title)||""===s)&&(document.title=s);return{addedTags:f,removedTags:l}}(this.$root._vueMeta.appId,e,n);return r&&c(n.changed)&&n.changed(n,r.addedTags,r.removedTags),{vm:this,metaInfo:n,tags:r}}}function Z(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e.__vuemeta_installed||(e.__vuemeta_installed=!0,n=function(e){for(var t in e=a(e)?e:{},b)e[t]||(e[t]=b[t]);return e}(n),e.prototype.$meta=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=Y(e),n=function(){};return function(){return this.$root._vueMeta?{getOptions:function(){return function(e){var t={};for(var n in e)t[n]=e[n];return t}(e)},refresh:t.bind(this),inject:n,pause:I.bind(this),resume:w.bind(this)}:{getOptions:m,refresh:m,inject:m,pause:m,resume:m}}}(n),e.mixin(function(e,n){var r=["activated","deactivated","beforeMount"];return{beforeCreate:function(){var o=this;if(Object.defineProperty(this,"_hasMetaInfo",{configurable:!0,get:function(){return e.config.devtools&&!this.$root._vueMeta.hasMetaInfoDeprecationWarningShown&&(p("VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead"),this.$root._vueMeta.hasMetaInfoDeprecationWarningShown=!0),l(this)}}),!i(this.$options[n.keyName])&&null!==this.$options[n.keyName]){if(this.$root._vueMeta||(this.$root._vueMeta={appId:y},y++),!this._vueMeta){this._vueMeta=!0;for(var a=this.$parent;a&&a!==this.$root;)i(a._vueMeta)&&(a._vueMeta=!1),a=a.$parent}c(this.$options[n.keyName])&&(this.$options.computed||(this.$options.computed={}),this.$options.computed.$metaInfo=this.$options[n.keyName],this.$isServer||f(this.$options,"created",function(){o.$watch("$metaInfo",function(){t(this,"watcher")})})),i(this.$root._vueMeta.initialized)&&(this.$root._vueMeta.initialized=this.$isServer,this.$root._vueMeta.initialized||(f(this.$options,"beforeMount",function(){o.$root.$el&&o.$root.$el.hasAttribute&&o.$root.$el.hasAttribute("data-server-rendered")&&(o.$root._vueMeta.appId=n.ssrAppId)}),f(this.$options,"mounted",function(){o.$root._vueMeta.initialized||(o.$root._vueMeta.initializing=!0,o.$nextTick(function(){var e=this,r=this.$root.$meta().refresh(),o=r.tags,i=r.metaInfo;!1===o&&null===this.$root._vueMeta.initialized&&this.$nextTick(function(){return t(e,"initializing")}),this.$root._vueMeta.initialized=!0,delete this.$root._vueMeta.initializing,!n.refreshOnceOnNavigation&&i.afterNavigation&&d(this)}))}),n.refreshOnceOnNavigation&&d(this))),this.$isServer||(r.forEach(function(e){f(o.$options,e,function(){return t(o,e)})}),f(this.$options,"destroyed",function(){var e=setInterval(function(){o.$el&&null!==o.$el.offsetParent||(clearInterval(e),o.$parent&&t(o,"destroyed"))},50)}))}}}}(e,n)))}return i(window)||i(window.Vue)||Z(window.Vue),{version:"2.2.0",install:Z,hasMetaInfo:l}}); diff --git a/package.json b/package.json index 29aae89..208bc8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-meta", - "version": "2.1.1", + "version": "2.2.0", "description": "Manage HTML metadata in Vue.js components with ssr support", "keywords": [ "attribute",