From 8acd3871b952fcc6c70828084907090d7238810c Mon Sep 17 00:00:00 2001 From: Zandor Smith <info@zsinfo.nl> Date: Wed, 26 Oct 2022 12:03:38 +0200 Subject: [PATCH] fix: Remove dist and lib folders from Git repository. --- .gitignore | 2 + dist/react-meta-tags.es.js | 320 ---------------------------------- dist/react-meta-tags.js | 332 ------------------------------------ dist/react-meta-tags.min.js | 8 - lib/index.js | 35 ---- lib/meta_tags.js | 165 ------------------ lib/meta_tags_context.js | 61 ------- lib/meta_tags_server.js | 53 ------ lib/react_title.js | 57 ------- lib/utils.js | 143 ---------------- 10 files changed, 2 insertions(+), 1174 deletions(-) delete mode 100644 dist/react-meta-tags.es.js delete mode 100644 dist/react-meta-tags.js delete mode 100644 dist/react-meta-tags.min.js delete mode 100644 lib/index.js delete mode 100644 lib/meta_tags.js delete mode 100644 lib/meta_tags_context.js delete mode 100644 lib/meta_tags_server.js delete mode 100644 lib/react_title.js delete mode 100644 lib/utils.js diff --git a/.gitignore b/.gitignore index 6f4809d..8a3bf24 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ node_modules/**/* *.swp *.log .DS_Store +lib/ +dist/ diff --git a/dist/react-meta-tags.es.js b/dist/react-meta-tags.es.js deleted file mode 100644 index ccfb8b4..0000000 --- a/dist/react-meta-tags.es.js +++ /dev/null @@ -1,320 +0,0 @@ -/** - * react-meta-tags - 1.0.1 - * Author : Sudhanshu Yadav - * Copyright (c) 2016, 2020 to Sudhanshu Yadav, released under the MIT license. - * https://github.com/s-yadav/react-meta-tags - */ - -import React, { Component, Children, createContext } from 'react'; -import ReactDOM from 'react-dom'; - -function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } -} - -function _defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } -} - -function _createClass(Constructor, protoProps, staticProps) { - if (protoProps) _defineProperties(Constructor.prototype, protoProps); - if (staticProps) _defineProperties(Constructor, staticProps); - return Constructor; -} - -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 _inherits(subClass, superClass) { - if (typeof superClass !== "function" && superClass !== null) { - throw new TypeError("Super expression must either be null or a function"); - } - - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - writable: true, - configurable: true - } - }); - if (superClass) _setPrototypeOf(subClass, superClass); -} - -function _getPrototypeOf(o) { - _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { - return o.__proto__ || Object.getPrototypeOf(o); - }; - return _getPrototypeOf(o); -} - -function _setPrototypeOf(o, p) { - _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { - o.__proto__ = p; - return o; - }; - - return _setPrototypeOf(o, p); -} - -function _assertThisInitialized(self) { - if (self === void 0) { - throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - } - - return self; -} - -function _possibleConstructorReturn(self, call) { - if (call && (typeof call === "object" || typeof call === "function")) { - return call; - } - - return _assertThisInitialized(self); -} - -var MetaContext = createContext({}); -/** context class which passes extract fuunction to MetaTags Component **/ - -var MetaContextProviderWrapper = -/*#__PURE__*/ -function (_Component) { - _inherits(MetaContextProviderWrapper, _Component); - - function MetaContextProviderWrapper() { - _classCallCheck(this, MetaContextProviderWrapper); - - return _possibleConstructorReturn(this, _getPrototypeOf(MetaContextProviderWrapper).apply(this, arguments)); - } - - _createClass(MetaContextProviderWrapper, [{ - key: "render", - value: function render() { - return React.createElement(MetaContext.Provider, { - value: { - extract: this.props.extract - } - }, Children.only(this.props.children)); - } - }]); - - return MetaContextProviderWrapper; -}(Component); - -var uniqueIdentifiersI = ['property', 'name', 'itemprop']; -/** - Note: - 1. In server side we will add meta tags and title at last after fitering - 2. In client we will match and replace meta tagString - 3. For now we will not support link and other tags properly, they can be added but we will not check for uniqueness and will not decide placement -**/ - -function filterOutMetaWithId(metas) { - metas = Array.prototype.slice.call(metas || []); - return metas.filter(function (meta) { - return !meta.id; - }); -} - -function getDuplicateTitle() { - return document.head.querySelectorAll('title'); -} -function getDuplicateCanonical() { - return document.head.querySelectorAll('link[rel="canonical"]'); -} -function getDuplicateElementById(_ref) { - var id = _ref.id; - return id && document.head.querySelector("#".concat(id)); -} -function getDuplicateMeta(meta) { - var head = document.head; //for any other unique identifier check if metas already available with same identifier which doesn't have id - - return uniqueIdentifiersI.reduce(function (duplicates, identifier) { - var identifierValue = meta.getAttribute(identifier); - return identifierValue ? duplicates.concat(filterOutMetaWithId(head.querySelectorAll("[".concat(identifier, " = \"").concat(identifierValue, "\"]")))) : duplicates; - }, []); -} //function to append childrens on a parent - -function appendChild(parent, childrens) { - if (childrens.length === undefined) childrens = [childrens]; - var docFrag = document.createDocumentFragment(); //we used for loop instead of forEach because childrens can be array like object - - for (var i = 0, ln = childrens.length; i < ln; i++) { - docFrag.appendChild(childrens[i]); - } - - parent.appendChild(docFrag); -} -function removeChild(parent, childrens) { - if (childrens.length === undefined) childrens = [childrens]; - - for (var i = 0, ln = childrens.length; i < ln; i++) { - parent.removeChild(childrens[i]); - } -} - -/** An wrapper component to wrap element which need to shifted to head **/ - -var MetaTags = -/*#__PURE__*/ -function (_Component) { - _inherits(MetaTags, _Component); - - function MetaTags() { - _classCallCheck(this, MetaTags); - - return _possibleConstructorReturn(this, _getPrototypeOf(MetaTags).apply(this, arguments)); - } - - _createClass(MetaTags, [{ - key: "componentDidMount", - value: function componentDidMount() { - this.temporaryElement = document.createElement('div'); - this.handleChildrens(); - } - }, { - key: "componentDidUpdate", - value: function componentDidUpdate(oldProps) { - if (oldProps.children !== this.props.children) { - this.handleChildrens(); - } - } - }, { - key: "componentWillUnmount", - value: function componentWillUnmount() { - if (this.temporaryElement) { - ReactDOM.unmountComponentAtNode(this.temporaryElement); - } - } - }, { - key: "extractChildren", - value: function extractChildren() { - var extract = this.context.extract; - var children = this.props.children; - - if (!children) { - return; - } - - if (extract) { - extract(children); - } - } - }, { - key: "handleChildrens", - value: function handleChildrens() { - var _this = this; - - var children = this.props.children; - - if (this.context.extract || !children) { - return; - } - - var headComponent = React.createElement("div", { - className: "react-head-temp" - }, children); - ReactDOM.render(headComponent, this.temporaryElement, function () { - var childStr = _this.temporaryElement.innerHTML; //if html is not changed return - - if (_this.lastChildStr === childStr) { - return; - } - - _this.lastChildStr = childStr; - - var tempHead = _this.temporaryElement.querySelector('.react-head-temp'); // .react-head-temp might not exist when triggered from async action - - - if (tempHead === null) { - return; - } - - var childNodes = Array.prototype.slice.call(tempHead.children); - var head = document.head; - var headHtml = head.innerHTML; //filter children remove if children has not been changed - - childNodes = childNodes.filter(function (child) { - return headHtml.indexOf(child.outerHTML) === -1; - }); //create clone of childNodes - - childNodes = childNodes.map(function (child) { - return child.cloneNode(true); - }); //remove duplicate title and meta from head - - childNodes.forEach(function (child) { - var tag = child.tagName.toLowerCase(); - - if (tag === 'title') { - var title = getDuplicateTitle(); - if (title) removeChild(head, title); - } else if (child.id) { - // if the element has id defined remove the existing element with that id - var elm = getDuplicateElementById(child); - if (elm) removeChild(head, elm); - } else if (tag === 'meta') { - var meta = getDuplicateMeta(child); - if (meta) removeChild(head, meta); - } else if (tag === 'link' && child.rel === 'canonical') { - var link = getDuplicateCanonical(child); - if (link) removeChild(head, link); - } - }); - appendChild(document.head, childNodes); - }); - } - }, { - key: "render", - value: function render() { - this.extractChildren(); - return null; - } - }]); - - return MetaTags; -}(Component); - -_defineProperty(MetaTags, "contextType", MetaContext); - -var ReactTitle = -/*#__PURE__*/ -function (_Component) { - _inherits(ReactTitle, _Component); - - function ReactTitle() { - _classCallCheck(this, ReactTitle); - - return _possibleConstructorReturn(this, _getPrototypeOf(ReactTitle).apply(this, arguments)); - } - - _createClass(ReactTitle, [{ - key: "render", - value: function render() { - return React.createElement(MetaTags, null, React.createElement("title", null, this.props.title)); - } - }]); - - return ReactTitle; -}(Component); - -export default MetaTags; -export { MetaTags, MetaContextProviderWrapper as MetaTagsContext, ReactTitle }; diff --git a/dist/react-meta-tags.js b/dist/react-meta-tags.js deleted file mode 100644 index 6bb525c..0000000 --- a/dist/react-meta-tags.js +++ /dev/null @@ -1,332 +0,0 @@ -/** - * react-meta-tags - 1.0.1 - * Author : Sudhanshu Yadav - * Copyright (c) 2016, 2020 to Sudhanshu Yadav, released under the MIT license. - * https://github.com/s-yadav/react-meta-tags - */ - -(function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('react-dom')) : - typeof define === 'function' && define.amd ? define(['exports', 'react', 'react-dom'], factory) : - (factory((global.MetaTags = {}),global.React,global.ReactDOM)); -}(this, (function (exports,React,ReactDOM) { 'use strict'; - - var React__default = 'default' in React ? React['default'] : React; - ReactDOM = ReactDOM && ReactDOM.hasOwnProperty('default') ? ReactDOM['default'] : ReactDOM; - - function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } - } - - function _defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } - } - - function _createClass(Constructor, protoProps, staticProps) { - if (protoProps) _defineProperties(Constructor.prototype, protoProps); - if (staticProps) _defineProperties(Constructor, staticProps); - return Constructor; - } - - 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 _inherits(subClass, superClass) { - if (typeof superClass !== "function" && superClass !== null) { - throw new TypeError("Super expression must either be null or a function"); - } - - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - writable: true, - configurable: true - } - }); - if (superClass) _setPrototypeOf(subClass, superClass); - } - - function _getPrototypeOf(o) { - _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { - return o.__proto__ || Object.getPrototypeOf(o); - }; - return _getPrototypeOf(o); - } - - function _setPrototypeOf(o, p) { - _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { - o.__proto__ = p; - return o; - }; - - return _setPrototypeOf(o, p); - } - - function _assertThisInitialized(self) { - if (self === void 0) { - throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - } - - return self; - } - - function _possibleConstructorReturn(self, call) { - if (call && (typeof call === "object" || typeof call === "function")) { - return call; - } - - return _assertThisInitialized(self); - } - - var MetaContext = React.createContext({}); - /** context class which passes extract fuunction to MetaTags Component **/ - - var MetaContextProviderWrapper = - /*#__PURE__*/ - function (_Component) { - _inherits(MetaContextProviderWrapper, _Component); - - function MetaContextProviderWrapper() { - _classCallCheck(this, MetaContextProviderWrapper); - - return _possibleConstructorReturn(this, _getPrototypeOf(MetaContextProviderWrapper).apply(this, arguments)); - } - - _createClass(MetaContextProviderWrapper, [{ - key: "render", - value: function render() { - return React__default.createElement(MetaContext.Provider, { - value: { - extract: this.props.extract - } - }, React.Children.only(this.props.children)); - } - }]); - - return MetaContextProviderWrapper; - }(React.Component); - - var uniqueIdentifiersI = ['property', 'name', 'itemprop']; - /** - Note: - 1. In server side we will add meta tags and title at last after fitering - 2. In client we will match and replace meta tagString - 3. For now we will not support link and other tags properly, they can be added but we will not check for uniqueness and will not decide placement - **/ - - function filterOutMetaWithId(metas) { - metas = Array.prototype.slice.call(metas || []); - return metas.filter(function (meta) { - return !meta.id; - }); - } - - function getDuplicateTitle() { - return document.head.querySelectorAll('title'); - } - function getDuplicateCanonical() { - return document.head.querySelectorAll('link[rel="canonical"]'); - } - function getDuplicateElementById(_ref) { - var id = _ref.id; - return id && document.head.querySelector("#".concat(id)); - } - function getDuplicateMeta(meta) { - var head = document.head; //for any other unique identifier check if metas already available with same identifier which doesn't have id - - return uniqueIdentifiersI.reduce(function (duplicates, identifier) { - var identifierValue = meta.getAttribute(identifier); - return identifierValue ? duplicates.concat(filterOutMetaWithId(head.querySelectorAll("[".concat(identifier, " = \"").concat(identifierValue, "\"]")))) : duplicates; - }, []); - } //function to append childrens on a parent - - function appendChild(parent, childrens) { - if (childrens.length === undefined) childrens = [childrens]; - var docFrag = document.createDocumentFragment(); //we used for loop instead of forEach because childrens can be array like object - - for (var i = 0, ln = childrens.length; i < ln; i++) { - docFrag.appendChild(childrens[i]); - } - - parent.appendChild(docFrag); - } - function removeChild(parent, childrens) { - if (childrens.length === undefined) childrens = [childrens]; - - for (var i = 0, ln = childrens.length; i < ln; i++) { - parent.removeChild(childrens[i]); - } - } - - /** An wrapper component to wrap element which need to shifted to head **/ - - var MetaTags = - /*#__PURE__*/ - function (_Component) { - _inherits(MetaTags, _Component); - - function MetaTags() { - _classCallCheck(this, MetaTags); - - return _possibleConstructorReturn(this, _getPrototypeOf(MetaTags).apply(this, arguments)); - } - - _createClass(MetaTags, [{ - key: "componentDidMount", - value: function componentDidMount() { - this.temporaryElement = document.createElement('div'); - this.handleChildrens(); - } - }, { - key: "componentDidUpdate", - value: function componentDidUpdate(oldProps) { - if (oldProps.children !== this.props.children) { - this.handleChildrens(); - } - } - }, { - key: "componentWillUnmount", - value: function componentWillUnmount() { - if (this.temporaryElement) { - ReactDOM.unmountComponentAtNode(this.temporaryElement); - } - } - }, { - key: "extractChildren", - value: function extractChildren() { - var extract = this.context.extract; - var children = this.props.children; - - if (!children) { - return; - } - - if (extract) { - extract(children); - } - } - }, { - key: "handleChildrens", - value: function handleChildrens() { - var _this = this; - - var children = this.props.children; - - if (this.context.extract || !children) { - return; - } - - var headComponent = React__default.createElement("div", { - className: "react-head-temp" - }, children); - ReactDOM.render(headComponent, this.temporaryElement, function () { - var childStr = _this.temporaryElement.innerHTML; //if html is not changed return - - if (_this.lastChildStr === childStr) { - return; - } - - _this.lastChildStr = childStr; - - var tempHead = _this.temporaryElement.querySelector('.react-head-temp'); // .react-head-temp might not exist when triggered from async action - - - if (tempHead === null) { - return; - } - - var childNodes = Array.prototype.slice.call(tempHead.children); - var head = document.head; - var headHtml = head.innerHTML; //filter children remove if children has not been changed - - childNodes = childNodes.filter(function (child) { - return headHtml.indexOf(child.outerHTML) === -1; - }); //create clone of childNodes - - childNodes = childNodes.map(function (child) { - return child.cloneNode(true); - }); //remove duplicate title and meta from head - - childNodes.forEach(function (child) { - var tag = child.tagName.toLowerCase(); - - if (tag === 'title') { - var title = getDuplicateTitle(); - if (title) removeChild(head, title); - } else if (child.id) { - // if the element has id defined remove the existing element with that id - var elm = getDuplicateElementById(child); - if (elm) removeChild(head, elm); - } else if (tag === 'meta') { - var meta = getDuplicateMeta(child); - if (meta) removeChild(head, meta); - } else if (tag === 'link' && child.rel === 'canonical') { - var link = getDuplicateCanonical(child); - if (link) removeChild(head, link); - } - }); - appendChild(document.head, childNodes); - }); - } - }, { - key: "render", - value: function render() { - this.extractChildren(); - return null; - } - }]); - - return MetaTags; - }(React.Component); - - _defineProperty(MetaTags, "contextType", MetaContext); - - var ReactTitle = - /*#__PURE__*/ - function (_Component) { - _inherits(ReactTitle, _Component); - - function ReactTitle() { - _classCallCheck(this, ReactTitle); - - return _possibleConstructorReturn(this, _getPrototypeOf(ReactTitle).apply(this, arguments)); - } - - _createClass(ReactTitle, [{ - key: "render", - value: function render() { - return React__default.createElement(MetaTags, null, React__default.createElement("title", null, this.props.title)); - } - }]); - - return ReactTitle; - }(React.Component); - - exports.default = MetaTags; - exports.MetaTags = MetaTags; - exports.MetaTagsContext = MetaContextProviderWrapper; - exports.ReactTitle = ReactTitle; - - Object.defineProperty(exports, '__esModule', { value: true }); - -}))); diff --git a/dist/react-meta-tags.min.js b/dist/react-meta-tags.min.js deleted file mode 100644 index bf9c5b4..0000000 --- a/dist/react-meta-tags.min.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * react-meta-tags - 1.0.1 - * Author : Sudhanshu Yadav - * Copyright (c) 2016, 2020 to Sudhanshu Yadav, released under the MIT license. - * https://github.com/s-yadav/react-meta-tags - */ - -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","react","react-dom"],t):t(e.MetaTags={},e.React,e.ReactDOM)}(this,function(e,n,r){"use strict";var i="default"in n?n.default:n;function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function c(e,t,n){return t&&a(e.prototype,t),n&&a(e,n),e}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&f(e,t)}function u(e){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function f(e,t){return(f=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function d(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}r=r&&r.hasOwnProperty("default")?r.default:r;var p=n.createContext({}),t=function(e){function t(){return o(this,t),d(this,u(t).apply(this,arguments))}return l(t,n.Component),c(t,[{key:"render",value:function(){return i.createElement(p.Provider,{value:{extract:this.props.extract}},n.Children.only(this.props.children))}}]),t}(),s=["property","name","itemprop"];function h(o){var i=document.head;return s.reduce(function(e,t){var n,r=o.getAttribute(t);return r?e.concat((n=i.querySelectorAll("[".concat(t,' = "').concat(r,'"]')),(n=Array.prototype.slice.call(n||[])).filter(function(e){return!e.id}))):e},[])}function m(e,t){void 0===t.length&&(t=[t]);for(var n=0,r=t.length;n<r;n++)e.removeChild(t[n])}var y,v,b,C=function(e){function t(){return o(this,t),d(this,u(t).apply(this,arguments))}return l(t,n.Component),c(t,[{key:"componentDidMount",value:function(){this.temporaryElement=document.createElement("div"),this.handleChildrens()}},{key:"componentDidUpdate",value:function(e){e.children!==this.props.children&&this.handleChildrens()}},{key:"componentWillUnmount",value:function(){this.temporaryElement&&r.unmountComponentAtNode(this.temporaryElement)}},{key:"extractChildren",value:function(){var e=this.context.extract,t=this.props.children;t&&e&&e(t)}},{key:"handleChildrens",value:function(){var o=this,e=this.props.children;if(!this.context.extract&&e){var t=i.createElement("div",{className:"react-head-temp"},e);r.render(t,this.temporaryElement,function(){var e=o.temporaryElement.innerHTML;if(o.lastChildStr!==e){o.lastChildStr=e;var t=o.temporaryElement.querySelector(".react-head-temp");if(null!==t){var n=Array.prototype.slice.call(t.children),c=document.head,r=c.innerHTML;(n=(n=n.filter(function(e){return-1===r.indexOf(e.outerHTML)})).map(function(e){return e.cloneNode(!0)})).forEach(function(e){var t,n=e.tagName.toLowerCase();if("title"===n){var r=document.head.querySelectorAll("title");r&&m(c,r)}else if(e.id){var o=(t=e.id)&&document.head.querySelector("#".concat(t));o&&m(c,o)}else if("meta"===n){var i=h(e);i&&m(c,i)}else if("link"===n&&"canonical"===e.rel){var a=document.head.querySelectorAll('link[rel="canonical"]');a&&m(c,a)}}),function(e,t){void 0===t.length&&(t=[t]);for(var n=document.createDocumentFragment(),r=0,o=t.length;r<o;r++)n.appendChild(t[r]);e.appendChild(n)}(document.head,n)}}})}}},{key:"render",value:function(){return this.extractChildren(),null}}]),t}();b=p,(v="contextType")in(y=C)?Object.defineProperty(y,v,{value:b,enumerable:!0,configurable:!0,writable:!0}):y[v]=b;var g=function(e){function t(){return o(this,t),d(this,u(t).apply(this,arguments))}return l(t,n.Component),c(t,[{key:"render",value:function(){return i.createElement(C,null,i.createElement("title",null,this.props.title))}}]),t}();e.default=C,e.MetaTags=C,e.MetaTagsContext=t,e.ReactTitle=g,Object.defineProperty(e,"__esModule",{value:!0})}); diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 89b95b6..0000000 --- a/lib/index.js +++ /dev/null @@ -1,35 +0,0 @@ -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -Object.defineProperty(exports, "MetaTagsContext", { - enumerable: true, - get: function get() { - return _meta_tags_context.default; - } -}); -Object.defineProperty(exports, "MetaTags", { - enumerable: true, - get: function get() { - return _meta_tags.default; - } -}); -Object.defineProperty(exports, "ReactTitle", { - enumerable: true, - get: function get() { - return _react_title.default; - } -}); -exports.default = void 0; - -var _meta_tags_context = _interopRequireDefault(require("./meta_tags_context")); - -var _meta_tags = _interopRequireDefault(require("./meta_tags")); - -var _react_title = _interopRequireDefault(require("./react_title")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -var _default = _meta_tags.default; -exports.default = _default; \ No newline at end of file diff --git a/lib/meta_tags.js b/lib/meta_tags.js deleted file mode 100644 index 1c0d3e1..0000000 --- a/lib/meta_tags.js +++ /dev/null @@ -1,165 +0,0 @@ -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _react = _interopRequireWildcard(require("react")); - -var _reactDom = _interopRequireDefault(require("react-dom")); - -var _utils = require("./utils"); - -var _meta_tags_context = require("./meta_tags_context"); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } - -function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -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; } - -/** An wrapper component to wrap element which need to shifted to head **/ -var MetaTags = -/*#__PURE__*/ -function (_Component) { - _inherits(MetaTags, _Component); - - function MetaTags() { - _classCallCheck(this, MetaTags); - - return _possibleConstructorReturn(this, _getPrototypeOf(MetaTags).apply(this, arguments)); - } - - _createClass(MetaTags, [{ - key: "componentDidMount", - value: function componentDidMount() { - this.temporaryElement = document.createElement('div'); - this.handleChildrens(); - } - }, { - key: "componentDidUpdate", - value: function componentDidUpdate(oldProps) { - if (oldProps.children !== this.props.children) { - this.handleChildrens(); - } - } - }, { - key: "componentWillUnmount", - value: function componentWillUnmount() { - if (this.temporaryElement) { - _reactDom.default.unmountComponentAtNode(this.temporaryElement); - } - } - }, { - key: "extractChildren", - value: function extractChildren() { - var extract = this.context.extract; - var children = this.props.children; - - if (!children) { - return; - } - - if (extract) { - extract(children); - } - } - }, { - key: "handleChildrens", - value: function handleChildrens() { - var _this = this; - - var children = this.props.children; - - if (this.context.extract || !children) { - return; - } - - var headComponent = _react.default.createElement("div", { - className: "react-head-temp" - }, children); - - _reactDom.default.render(headComponent, this.temporaryElement, function () { - var childStr = _this.temporaryElement.innerHTML; //if html is not changed return - - if (_this.lastChildStr === childStr) { - return; - } - - _this.lastChildStr = childStr; - - var tempHead = _this.temporaryElement.querySelector('.react-head-temp'); // .react-head-temp might not exist when triggered from async action - - - if (tempHead === null) { - return; - } - - var childNodes = Array.prototype.slice.call(tempHead.children); - var head = document.head; - var headHtml = head.innerHTML; //filter children remove if children has not been changed - - childNodes = childNodes.filter(function (child) { - return headHtml.indexOf(child.outerHTML) === -1; - }); //create clone of childNodes - - childNodes = childNodes.map(function (child) { - return child.cloneNode(true); - }); //remove duplicate title and meta from head - - childNodes.forEach(function (child) { - var tag = child.tagName.toLowerCase(); - - if (tag === 'title') { - var title = (0, _utils.getDuplicateTitle)(); - if (title) (0, _utils.removeChild)(head, title); - } else if (child.id) { - // if the element has id defined remove the existing element with that id - var elm = (0, _utils.getDuplicateElementById)(child); - if (elm) (0, _utils.removeChild)(head, elm); - } else if (tag === 'meta') { - var meta = (0, _utils.getDuplicateMeta)(child); - if (meta) (0, _utils.removeChild)(head, meta); - } else if (tag === 'link' && child.rel === 'canonical') { - var link = (0, _utils.getDuplicateCanonical)(child); - if (link) (0, _utils.removeChild)(head, link); - } - }); - (0, _utils.appendChild)(document.head, childNodes); - }); - } - }, { - key: "render", - value: function render() { - this.extractChildren(); - return null; - } - }]); - - return MetaTags; -}(_react.Component); - -_defineProperty(MetaTags, "contextType", _meta_tags_context.MetaContext); - -var _default = MetaTags; -exports.default = _default; -module.exports = exports.default; \ No newline at end of file diff --git a/lib/meta_tags_context.js b/lib/meta_tags_context.js deleted file mode 100644 index 9b2f247..0000000 --- a/lib/meta_tags_context.js +++ /dev/null @@ -1,61 +0,0 @@ -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = exports.MetaContext = void 0; - -var _react = _interopRequireWildcard(require("react")); - -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } - -function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -var MetaContext = (0, _react.createContext)({}); -/** context class which passes extract fuunction to MetaTags Component **/ - -exports.MetaContext = MetaContext; - -var MetaContextProviderWrapper = -/*#__PURE__*/ -function (_Component) { - _inherits(MetaContextProviderWrapper, _Component); - - function MetaContextProviderWrapper() { - _classCallCheck(this, MetaContextProviderWrapper); - - return _possibleConstructorReturn(this, _getPrototypeOf(MetaContextProviderWrapper).apply(this, arguments)); - } - - _createClass(MetaContextProviderWrapper, [{ - key: "render", - value: function render() { - return _react.default.createElement(MetaContext.Provider, { - value: { - extract: this.props.extract - } - }, _react.Children.only(this.props.children)); - } - }]); - - return MetaContextProviderWrapper; -}(_react.Component); - -var _default = MetaContextProviderWrapper; -exports.default = _default; \ No newline at end of file diff --git a/lib/meta_tags_server.js b/lib/meta_tags_server.js deleted file mode 100644 index c1a8c26..0000000 --- a/lib/meta_tags_server.js +++ /dev/null @@ -1,53 +0,0 @@ -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _react = _interopRequireDefault(require("react")); - -var _server = _interopRequireDefault(require("react-dom/server")); - -var _utils = require("./utils"); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function MetaTagsServer() { - var headElms = []; - return { - extract: function extract(elms) { - if (!(elms instanceof Array)) { - elms = [elms]; - } //filter out null nodes - - - elms = elms.filter(function (elm) { - return !!elm; - }); - headElms = headElms.concat(elms); - }, - renderToString: function renderToString() { - var filteredElms = (0, _utils.filterAndArrangeTags)(headElms); - - var headComponent = _react.default.createElement("div", { - className: "react-head-temp" - }, filteredElms); - - var componentStr = _server.default.renderToStaticMarkup(headComponent); //remove wrapper div from string - - - componentStr = componentStr.replace(/^<div[^<>]*class="react-head-temp"[^<>]*>(.*)<\/div>$/, function ($1, $2) { - return $2; - }); - return componentStr; - }, - getTags: function getTags() { - return (0, _utils.filterAndArrangeTags)(headElms); - } - }; -} - -var _default = MetaTagsServer; -exports.default = _default; -module.exports = exports.default; \ No newline at end of file diff --git a/lib/react_title.js b/lib/react_title.js deleted file mode 100644 index 46fb28f..0000000 --- a/lib/react_title.js +++ /dev/null @@ -1,57 +0,0 @@ -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _react = _interopRequireWildcard(require("react")); - -var _meta_tags = _interopRequireDefault(require("./meta_tags")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } - -function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -var ReactTitle = -/*#__PURE__*/ -function (_Component) { - _inherits(ReactTitle, _Component); - - function ReactTitle() { - _classCallCheck(this, ReactTitle); - - return _possibleConstructorReturn(this, _getPrototypeOf(ReactTitle).apply(this, arguments)); - } - - _createClass(ReactTitle, [{ - key: "render", - value: function render() { - return _react.default.createElement(_meta_tags.default, null, _react.default.createElement("title", null, this.props.title)); - } - }]); - - return ReactTitle; -}(_react.Component); - -var _default = ReactTitle; -exports.default = _default; -module.exports = exports.default; \ No newline at end of file diff --git a/lib/utils.js b/lib/utils.js deleted file mode 100644 index 0df181b..0000000 --- a/lib/utils.js +++ /dev/null @@ -1,143 +0,0 @@ -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.filterAndArrangeTags = filterAndArrangeTags; -exports.getDuplicateTitle = getDuplicateTitle; -exports.getDuplicateCanonical = getDuplicateCanonical; -exports.getDuplicateElementById = getDuplicateElementById; -exports.getDuplicateMeta = getDuplicateMeta; -exports.appendChild = appendChild; -exports.removeChild = removeChild; - -function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } - -function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } - -function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } - -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; } } - -var camelCaseProps = ['itemProp']; -var uniqueIdentifiersI = ['property', 'name', 'itemprop']; -var uniqueIdentifiers = uniqueIdentifiersI.concat(camelCaseProps); //case sensitive props is defined in case anyone defined the lowercase prop - -var uniqueIdentifiersAll = uniqueIdentifiers.concat(['id']); -/** - Note: - 1. In server side we will add meta tags and title at last after fitering - 2. In client we will match and replace meta tagString - 3. For now we will not support link and other tags properly, they can be added but we will not check for uniqueness and will not decide placement -**/ - -function filterOutMetaWithId(metas) { - metas = Array.prototype.slice.call(metas || []); - return metas.filter(function (meta) { - return !meta.id; - }); -} - -function filterAndArrangeTags(headElms) { - var title = null; - var canonicalLink = null; - var metas = []; - var rest = []; - headElms.forEach(function (elm) { - var type = elm.type, - props = elm.props; - - if (type === 'title') { - title = elm; - } else if (type === 'link' && props.rel === 'canonical') { - canonicalLink = elm; - } else if (type === 'meta') { - metas.push(elm); - } else { - rest.push(elm); - } - }); - return [title].concat(_toConsumableArray(removeDuplicateMetas(metas)), [canonicalLink], rest); -} - -function removeDuplicateMetas(metas) { - var addedMeta = {}; //initialize all the identifiers with empty array - - uniqueIdentifiersAll.forEach(function (identifier) { - addedMeta[identifier] = []; - }); - var filteredMetas = []; - - var _loop = function _loop(i) { - var meta = metas[i]; - var id = meta.props.id; - var addMeta = false; //if has id and element with id is not present than always add meta - - if (id) { - addMeta = !addedMeta.id[id]; //for any other unique identifier check if meta already available with same identifier which doesn't have id - } else { - addMeta = uniqueIdentifiers.filter(function (identifier) { - var identifierValue = meta.props[identifier]; - var existing = addedMeta[identifier][identifierValue]; - return existing && !existing.props.id; - }).length === 0; - } - - if (addMeta) { - filteredMetas.unshift(meta); //add meta as added - - uniqueIdentifiersAll.forEach(function (identifier) { - var identifierValue = meta.props[identifier]; - if (identifierValue) addedMeta[identifier][identifierValue] = meta; - }); - } - }; - - for (var i = metas.length - 1; i >= 0; i--) { - _loop(i); - } - - return filteredMetas; -} - -function getDuplicateTitle() { - return document.head.querySelectorAll('title'); -} - -function getDuplicateCanonical() { - return document.head.querySelectorAll('link[rel="canonical"]'); -} - -function getDuplicateElementById(_ref) { - var id = _ref.id; - return id && document.head.querySelector("#".concat(id)); -} - -function getDuplicateMeta(meta) { - var head = document.head; //for any other unique identifier check if metas already available with same identifier which doesn't have id - - return uniqueIdentifiersI.reduce(function (duplicates, identifier) { - var identifierValue = meta.getAttribute(identifier); - return identifierValue ? duplicates.concat(filterOutMetaWithId(head.querySelectorAll("[".concat(identifier, " = \"").concat(identifierValue, "\"]")))) : duplicates; - }, []); -} //function to append childrens on a parent - - -function appendChild(parent, childrens) { - if (childrens.length === undefined) childrens = [childrens]; - var docFrag = document.createDocumentFragment(); //we used for loop instead of forEach because childrens can be array like object - - for (var i = 0, ln = childrens.length; i < ln; i++) { - docFrag.appendChild(childrens[i]); - } - - parent.appendChild(docFrag); -} - -function removeChild(parent, childrens) { - if (childrens.length === undefined) childrens = [childrens]; - - for (var i = 0, ln = childrens.length; i < ln; i++) { - parent.removeChild(childrens[i]); - } -} \ No newline at end of file -- GitLab