react-to-print
Advanced tools
Comparing version 1.0.20 to 1.0.21
@@ -1,2 +0,2 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var React=_interopDefault(require("react")),reactDom=require("react-dom"),propTypes=_interopDefault(require("prop-types")),classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},toConsumableArray=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)},ReactToPrint=function(e){function t(){var e,n,o,r;classCallCheck(this,t);for(var a=arguments.length,i=Array(a),l=0;l<a;l++)i[l]=arguments[l];return n=o=possibleConstructorReturn(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(i))),o.handlePrint=function(){var e=o.props,t=e.content,n=e.copyStyles,r=e.onAfterPrint,a=window.open("","Print","status=no, toolbar=no, scrollbars=yes","false");r&&(a.onbeforeunload=r);var i=t(),l=reactDom.findDOMNode(i),c=[].concat(toConsumableArray(l.getElementsByTagName("img"))),s=document.querySelectorAll('link[rel="stylesheet"]');o.imageTotal=c.length,o.imageLoaded=0,o.linkTotal=s.length,o.linkLoaded=0;var u=function(e){"image"===e?o.imageLoaded++:"link"===e&&o.linkLoaded++,o.imageLoaded===o.imageTotal&&o.linkLoaded===o.linkTotal&&o.triggerPrint(a)};if([].concat(toConsumableArray(c)).forEach(function(e){/^data:/.test(e.src)&&(e.crossOrigin="anonymous"),e.setAttribute("src",e.src),e.onload=u.bind(null,"image"),e.onerror=u.bind(null,"image"),e.crossOrigin="use-credentials"}),!1!==n){var d=document.querySelectorAll('style, link[rel="stylesheet"]');[].concat(toConsumableArray(d)).forEach(function(e){var t=(a.contentDocument||a.document).createElement(e.tagName);e.textContent?t.textContent=e.textContent:e.innerText&&(t.innerText=e.innerText);[].concat(toConsumableArray(e.attributes)).forEach(function(e){var n=e.nodeValue;if("href"===e.nodeName&&!1===/^https?:\/\//.test(e.nodeValue)&&!1===/^blob:/.test(e.nodeValue)){var o="../"===e.nodeValue.substr(0,3)?document.location.pathname.replace(/[^/]*$/,""):"/";n=n.replace(/\/+/,""),n=document.location.protocol+"//"+document.location.host+o+n}t.setAttribute(e.nodeName,n)}),"LINK"===e.tagName&&(t.onload=u.bind(null,"link"),t.onerror=u.bind(null,"link")),a.document.head.appendChild(t)})}if(document.body.className){document.body.className.split(" ").filter(function(e){return e}).map(function(e){return a.document.body.classList.add(e)})}o.props.bodyClass.length&&a.document.body.classList.add(o.props.bodyClass);var p=a.document.createElement("style");p.appendChild(a.document.createTextNode("@page { size: auto; margin: 0mm; } @media print { body { -webkit-print-color-adjust: exact; } }")),a.document.head.appendChild(p),a.document.body.innerHTML=l.outerHTML,0!==o.imageTotal&&!1!==n||o.triggerPrint(a),o.props.debug&&(console.log("** DEBUG MODE **"),console.log(a.document))},r=n,possibleConstructorReturn(o,r)}return inherits(t,e),createClass(t,[{key:"triggerPrint",value:function(e){var t=this;this.props.onBeforePrint&&this.props.onBeforePrint(),setTimeout(function(){t.props.debug||(e.print(),t.props.closeAfterPrint&&e.close())},500)}},{key:"render",value:function(){var e=this;return React.cloneElement(this.props.trigger(),{ref:function(t){return e.triggerRef=t},onClick:this.handlePrint})}}]),t}(React.Component);ReactToPrint.defaultProps={copyStyles:!0,closeAfterPrint:!0,bodyClass:"",debug:!1},module.exports=ReactToPrint; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var React=_interopDefault(require("react")),reactDom=require("react-dom"),propTypes=_interopDefault(require("prop-types")),classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},toConsumableArray=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)},ReactToPrint=function(e){function t(){var e,n,o,r;classCallCheck(this,t);for(var a=arguments.length,i=Array(a),l=0;l<a;l++)i[l]=arguments[l];return n=o=possibleConstructorReturn(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(i))),o.handlePrint=function(){var e=o.props,t=e.content,n=e.copyStyles,r=e.onAfterPrint,a=e.pageStyle;console.log(a);var i=window.open("","Print","status=no, toolbar=no, scrollbars=yes","false");r&&(i.onbeforeunload=r);var l=t(),c=reactDom.findDOMNode(l),s=[].concat(toConsumableArray(c.getElementsByTagName("img"))),u=document.querySelectorAll('link[rel="stylesheet"]');o.imageTotal=s.length,o.imageLoaded=0,o.linkTotal=u.length,o.linkLoaded=0;var d=function(e){"image"===e?o.imageLoaded++:"link"===e&&o.linkLoaded++,o.imageLoaded===o.imageTotal&&o.linkLoaded===o.linkTotal&&o.triggerPrint(i)};if([].concat(toConsumableArray(s)).forEach(function(e){/^data:/.test(e.src)&&(e.crossOrigin="anonymous"),e.setAttribute("src",e.src),e.onload=d.bind(null,"image"),e.onerror=d.bind(null,"image"),e.crossOrigin="use-credentials"}),!1!==n){var p=document.querySelectorAll('style, link[rel="stylesheet"]');[].concat(toConsumableArray(p)).forEach(function(e){var t=(i.contentDocument||i.document).createElement(e.tagName);e.textContent?t.textContent=e.textContent:e.innerText&&(t.innerText=e.innerText);[].concat(toConsumableArray(e.attributes)).forEach(function(e){var n=e.nodeValue;if("href"===e.nodeName&&!1===/^https?:\/\//.test(e.nodeValue)&&!1===/^blob:/.test(e.nodeValue)){var o="../"===e.nodeValue.substr(0,3)?document.location.pathname.replace(/[^/]*$/,""):"/";n=n.replace(/\/+/,""),n=document.location.protocol+"//"+document.location.host+o+n}t.setAttribute(e.nodeName,n)}),"LINK"===e.tagName&&(t.onload=d.bind(null,"link"),t.onerror=d.bind(null,"link")),i.document.head.appendChild(t)})}if(document.body.className){document.body.className.split(" ").filter(function(e){return e}).map(function(e){return i.document.body.classList.add(e)})}o.props.bodyClass.length&&i.document.body.classList.add(o.props.bodyClass);var f=void 0===a?"@page { size: auto; margin: 0mm; } @media print { body { -webkit-print-color-adjust: exact; } }":a,m=i.document.createElement("style");m.appendChild(i.document.createTextNode(f)),i.document.head.appendChild(m),i.document.body.innerHTML=c.outerHTML,0!==o.imageTotal&&!1!==n||o.triggerPrint(i),o.props.debug&&(console.log("** DEBUG MODE **"),console.log(i.document))},r=n,possibleConstructorReturn(o,r)}return inherits(t,e),createClass(t,[{key:"triggerPrint",value:function(e){var t=this;this.props.onBeforePrint&&this.props.onBeforePrint(),setTimeout(function(){t.props.debug||(e.print(),t.props.closeAfterPrint&&e.close())},500)}},{key:"render",value:function(){var e=this;return React.cloneElement(this.props.trigger(),{ref:function(t){return e.triggerRef=t},onClick:this.handlePrint})}}]),t}(React.Component);ReactToPrint.defaultProps={copyStyles:!0,closeAfterPrint:!0,bodyClass:"",debug:!1},module.exports=ReactToPrint; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "react-to-print", | ||
"version": "1.0.20", | ||
"version": "1.0.21", | ||
"description": "Print React components in the browser", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -92,2 +92,3 @@ <div align="center"> | ||
|**`closeAfterPrint`**|boolean|Close the print window after action | ||
|**`pageStyle`**|string|Override default print window styling | ||
|**`bodyClass`**|string|Optional class to pass to the print window body |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18689
18
94