Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-to-print

Package Overview
Dependencies
Maintainers
1
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-to-print - npm Package Compare versions

Comparing version 2.0.0-alpha-2 to 2.0.0-alpha-3

2

lib/index.js

@@ -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 r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),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,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)},ReactToPrint=function(e){function t(){var e,r,n,o;classCallCheck(this,t);for(var a=arguments.length,i=Array(a),l=0;l<a;l++)i[l]=arguments[l];return r=n=possibleConstructorReturn(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(i))),n.handlePrint=function(){var e=n.props,t=e.bodyClass,r=e.content,o=e.copyStyles,a=e.pageStyle,i=(e.onAfterPrint,r());if(void 0===i)return console.error("Refs are not available stateless components. For 'react-to-print' to work only Class based components can be printed"),!1;var l=document.createElement("iframe");l.style.position="absolute",l.style.top="-1000px",l.style.left="-1000px";var c=reactDom.findDOMNode(i),s=document.querySelectorAll('link[rel="stylesheet"]');n.linkTotal=s.length||0,n.linkLoaded=0;var u=function(e){n.linkLoaded++,n.linkLoaded===n.linkTotal&&n.triggerPrint(l)};l.onload=function(){var e=l.contentDocument||l.contentWindow.document,r=[].concat(toConsumableArray(c.querySelectorAll("canvas")));e.open(),e.write(c.outerHTML),e.close();var i=void 0===a?"@page { size: auto; margin: 0mm; } @media print { body { -webkit-print-color-adjust: exact; } }":a,s=e.createElement("style");s.appendChild(e.createTextNode(i)),e.head.appendChild(s),t.length&&e.body.classList.add(t);var p=e.querySelectorAll("canvas");if([].concat(toConsumableArray(p)).forEach(function(e,t){e.getContext("2d").drawImage(r[t],0,0)}),!1!==o){var f=document.querySelectorAll('style, link[rel="stylesheet"]');[].concat(toConsumableArray(f)).forEach(function(t,r){var n=e.createElement(t.tagName),o="";if("STYLE"===t.tagName){if(t.sheet){for(var a=0;a<t.sheet.cssRules.length;a++)o+=t.sheet.cssRules[a].cssText+"\r\n";n.setAttribute("id","react-to-print-"+r),n.appendChild(e.createTextNode(o))}}else{[].concat(toConsumableArray(t.attributes)).forEach(function(e){n.setAttribute(e.nodeName,e.nodeValue)}),n.onload=u.bind(null,"link"),n.onerror=u.bind(null,"link")}e.head.appendChild(n)})}0!==n.linkTotal&&!1!==o||n.triggerPrint(l)},document.body.appendChild(l)},o=r,possibleConstructorReturn(n,o)}return inherits(t,e),createClass(t,[{key:"triggerPrint",value:function(e){var t=this,r=this.props,n=r.onBeforePrint,o=r.onAfterPrint;n&&n(),setTimeout(function(){e.contentWindow.focus(),e.contentWindow.print(),t.removeWindow(e),o&&o()},500)}},{key:"removeWindow",value:function(e){setTimeout(function(){e.parentNode.removeChild(e)},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:""},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 r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),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,r,o;classCallCheck(this,t);for(var a=arguments.length,i=Array(a),l=0;l<a;l++)i[l]=arguments[l];return n=r=possibleConstructorReturn(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(i))),r.handlePrint=function(){var e=r.props,t=e.bodyClass,n=e.content,o=e.copyStyles,a=e.pageStyle,i=(e.onAfterPrint,n());if(void 0===i)return console.error("Refs are not available stateless components. For 'react-to-print' to work only Class based components can be printed"),!1;var l=document.createElement("iframe");l.style.position="absolute",l.style.top="-1000px",l.style.left="-1000px";var c=reactDom.findDOMNode(i),s=document.querySelectorAll('link[rel="stylesheet"]');r.linkTotal=s.length||0,r.linkLoaded=0;var u=function(e){r.linkLoaded++,r.linkLoaded===r.linkTotal&&r.triggerPrint(l)};l.onload=function(){window.navigator&&window.navigator.userAgent.includes("Trident/7.0")&&(l.onload=null);var e=l.contentDocument||l.contentWindow.document,n=[].concat(toConsumableArray(c.querySelectorAll("canvas")));e.open(),e.write(c.outerHTML),e.close();var i=void 0===a?"@page { size: auto; margin: 0mm; } @media print { body { -webkit-print-color-adjust: exact; } }":a,s=e.createElement("style");s.appendChild(e.createTextNode(i)),e.head.appendChild(s),t.length&&e.body.classList.add(t);var p=e.querySelectorAll("canvas");if([].concat(toConsumableArray(p)).forEach(function(e,t){e.getContext("2d").drawImage(n[t],0,0)}),!1!==o){var d=document.querySelectorAll('style, link[rel="stylesheet"]');[].concat(toConsumableArray(d)).forEach(function(t,n){var r=e.createElement(t.tagName),o="";if("STYLE"===t.tagName){if(t.sheet){for(var a=0;a<t.sheet.cssRules.length;a++)o+=t.sheet.cssRules[a].cssText+"\r\n";r.setAttribute("id","react-to-print-"+n),r.appendChild(e.createTextNode(o))}}else{[].concat(toConsumableArray(t.attributes)).forEach(function(e){r.setAttribute(e.nodeName,e.nodeValue)}),r.onload=u.bind(null,"link"),r.onerror=u.bind(null,"link")}e.head.appendChild(r)})}0!==r.linkTotal&&!1!==o||r.triggerPrint(l)},document.body.appendChild(l)},o=n,possibleConstructorReturn(r,o)}return inherits(t,e),createClass(t,[{key:"triggerPrint",value:function(e){var t=this,n=this.props,r=n.onBeforePrint,o=n.onAfterPrint;r&&r(),setTimeout(function(){e.contentWindow.focus(),e.contentWindow.print(),t.removeWindow(e),o&&o()},500)}},{key:"removeWindow",value:function(e){setTimeout(function(){e.parentNode.removeChild(e)},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:""},module.exports=ReactToPrint;
//# sourceMappingURL=index.js.map
{
"name": "react-to-print",
"version": "2.0.0-alpha-2",
"version": "2.0.0-alpha-3",
"description": "Print React components in the browser",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc