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-5 to 2.0.0-alpha-6

lib/index.d.ts

2

lib/index.js

@@ -1,2 +0,2 @@

"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(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)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),e}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _inherits(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&&_setPrototypeOf(e,t)}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _possibleConstructorReturn(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?_assertThisInitialized(e):t}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_nonIterableSpread()}function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t<e.length;t++)r[t]=e[t];return r}}function _iterableToArray(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}var React=_interopDefault(require("react")),reactDom=require("react-dom"),propTypes=_interopDefault(require("prop-types")),ReactToPrint=function(e){function t(){var e,r;_classCallCheck(this,t);for(var n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];return r=_possibleConstructorReturn(this,(e=_getPrototypeOf(t)).call.apply(e,[this].concat(o))),_defineProperty(_assertThisInitialized(_assertThisInitialized(r)),"removeWindow",function(e){setTimeout(function(){e.parentNode.removeChild(e)},500)}),_defineProperty(_assertThisInitialized(_assertThisInitialized(r)),"triggerPrint",function(e){var t=r.props,n=t.onBeforePrint,o=t.onAfterPrint;n&&n(),setTimeout(function(){e.contentWindow.focus(),e.contentWindow.print(),r.removeWindow(e),o&&o()},500)}),_defineProperty(_assertThisInitialized(_assertThisInitialized(r)),"handlePrint",function(){var e=r.props,t=e.bodyClass,n=e.content,o=e.copyStyles,i=e.pageStyle,a=n();if(void 0!==a){var l=document.createElement("iframe");l.style.position="absolute",l.style.top="-1000px",l.style.left="-1000px";var s=reactDom.findDOMNode(a),c=document.querySelectorAll('link[rel="stylesheet"]');r.linkTotal=c.length||0,r.linksLoaded=[],r.linksErrored=[];var u=function(e,t){t?r.linksLoaded.push(e):(console.error("'react-to-print' was unable to load a link. It may be invalid. 'react-to-print' will continue attempting to print the page. The link the errored was:",e),r.linksErrored.push(e)),r.linksLoaded.length+r.linksErrored.length===r.linkTotal&&r.triggerPrint(l)};l.onload=function(){window.navigator&&window.navigator.userAgent.indexOf("Trident/7.0")>-1&&(l.onload=null);var e=l.contentDocument||l.contentWindow.document,n=_toConsumableArray(s.querySelectorAll("canvas"));e.open(),e.write(s.outerHTML),e.close();var a=void 0===i?"@page { size: auto; margin: 0mm; } @media print { body { -webkit-print-color-adjust: exact; } }":i,c=e.createElement("style");c.appendChild(e.createTextNode(a)),e.head.appendChild(c),t.length&&e.body.classList.add(t);if(_toConsumableArray(e.querySelectorAll("canvas")).forEach(function(e,t){e.getContext("2d").drawImage(n[t],0,0)}),!1!==o){_toConsumableArray(document.querySelectorAll('style, link[rel="stylesheet"]')).forEach(function(t,r){if("STYLE"===t.tagName){var n=e.createElement(t.tagName);if(t.sheet){for(var o="",i=0;i<t.sheet.cssRules.length;i++)o+="".concat(t.sheet.cssRules[i].cssText,"\r\n");n.setAttribute("id","react-to-print-".concat(r)),n.appendChild(e.createTextNode(o)),e.head.appendChild(n)}}else{var a=_toConsumableArray(t.attributes),l=a.filter(function(e){return"href"===e.nodeName});if(!!l.length&&!!l[0].nodeValue){var s=e.createElement(t.tagName);a.forEach(function(e){s.setAttribute(e.nodeName,e.nodeValue)}),s.onload=u.bind(null,s,!0),s.onerror=u.bind(null,s,!1),e.head.appendChild(s)}else console.warn("'react-to-print' encountered a <link> tag with an empty 'href' attribute. In addition to being invalid HTML, this can cause problems in many browsers, and so the <link> was not loaded. The <link> is:",t),u(t,!0)}})}0!==r.linkTotal&&!1!==o||r.triggerPrint(l)},document.body.appendChild(l)}else console.error("Refs are not available for stateless components. For 'react-to-print' to work only Class based components can be printed")}),_defineProperty(_assertThisInitialized(_assertThisInitialized(r)),"setRef",function(e){r.triggerRef=e}),r}return _inherits(t,React.Component),_createClass(t,[{key:"render",value:function(){var e=this.props.trigger;return React.cloneElement(e(),{onClick:this.handlePrint,ref:this.setRef})}}]),t}();_defineProperty(ReactToPrint,"defaultProps",{bodyClass:"",copyStyles:!0,onAfterPrint:!1,onBeforePrint:!1,pageStyle:void 0}),module.exports=ReactToPrint;
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(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)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),e}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _inherits(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&&_setPrototypeOf(e,t)}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _possibleConstructorReturn(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?_assertThisInitialized(e):t}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_nonIterableSpread()}function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t<e.length;t++)r[t]=e[t];return r}}function _iterableToArray(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}var React=_interopDefault(require("react")),reactDom=require("react-dom"),propTypes=_interopDefault(require("prop-types")),ReactToPrint=function(e){function t(){var e,r;_classCallCheck(this,t);for(var n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];return r=_possibleConstructorReturn(this,(e=_getPrototypeOf(t)).call.apply(e,[this].concat(o))),_defineProperty(_assertThisInitialized(_assertThisInitialized(r)),"removeWindow",function(e){setTimeout(function(){e.parentNode.removeChild(e)},500)}),_defineProperty(_assertThisInitialized(_assertThisInitialized(r)),"triggerPrint",function(e){var t=r.props,n=t.onBeforePrint,o=t.onAfterPrint;n&&n(),setTimeout(function(){e.contentWindow.focus(),e.contentWindow.print(),r.removeWindow(e),o&&o()},500)}),_defineProperty(_assertThisInitialized(_assertThisInitialized(r)),"handlePrint",function(){var e=r.props,t=e.bodyClass,n=e.content,o=e.copyStyles,i=e.pageStyle,a=n();if(void 0!==a){var l=document.createElement("iframe");l.style.position="absolute",l.style.top="-1000px",l.style.left="-1000px";var s=reactDom.findDOMNode(a),c=document.querySelectorAll('link[rel="stylesheet"]');r.linkTotal=c.length||0,r.linksLoaded=[],r.linksErrored=[];var u=function(e,t){t?r.linksLoaded.push(e):(console.error("'react-to-print' was unable to load a link. It may be invalid. 'react-to-print' will continue attempting to print the page. The link the errored was:",e),r.linksErrored.push(e)),r.linksLoaded.length+r.linksErrored.length===r.linkTotal&&r.triggerPrint(l)};l.onload=function(){window.navigator&&window.navigator.userAgent.indexOf("Trident/7.0")>-1&&(l.onload=null);var e=l.contentDocument||l.contentWindow.document,n=_toConsumableArray(s.querySelectorAll("canvas"));e.open(),e.write(s.outerHTML),e.close();var a=void 0===i?"@page { size: auto; margin: 0mm; } @media print { body { -webkit-print-color-adjust: exact; } }":i,c=e.createElement("style");c.appendChild(e.createTextNode(a)),e.head.appendChild(c),t.length&&e.body.classList.add(t);if(_toConsumableArray(e.querySelectorAll("canvas")).forEach(function(e,t){e.getContext("2d").drawImage(n[t],0,0)}),!1!==o){_toConsumableArray(document.querySelectorAll('style, link[rel="stylesheet"]')).forEach(function(t,r){if("STYLE"===t.tagName){var n=e.createElement(t.tagName);if(t.sheet){for(var o="",i=0;i<t.sheet.cssRules.length;i++)o+="".concat(t.sheet.cssRules[i].cssText,"\r\n");n.setAttribute("id","react-to-print-".concat(r)),n.appendChild(e.createTextNode(o)),e.head.appendChild(n)}}else{var a=_toConsumableArray(t.attributes),l=a.filter(function(e){return"href"===e.nodeName});if(!!l.length&&!!l[0].nodeValue){var s=e.createElement(t.tagName);a.forEach(function(e){s.setAttribute(e.nodeName,e.nodeValue)}),s.onload=u.bind(null,s,!0),s.onerror=u.bind(null,s,!1),e.head.appendChild(s)}else console.warn("'react-to-print' encountered a <link> tag with an empty 'href' attribute. In addition to being invalid HTML, this can cause problems in many browsers, and so the <link> was not loaded. The <link> is:",t),u(t,!0)}})}0!==r.linkTotal&&!1!==o||r.triggerPrint(l)},document.body.appendChild(l)}else console.error("Refs are not available for stateless components. For 'react-to-print' to work only Class based components can be printed")}),_defineProperty(_assertThisInitialized(_assertThisInitialized(r)),"setRef",function(e){r.triggerRef=e}),r}return _inherits(t,React.Component),_createClass(t,[{key:"render",value:function(){var e=this.props.trigger;return React.cloneElement(e(),{onClick:this.handlePrint,ref:this.setRef})}}]),t}();_defineProperty(ReactToPrint,"defaultProps",{bodyClass:"",copyStyles:!0,onAfterPrint:void 0,onBeforePrint:void 0,pageStyle:void 0}),module.exports=ReactToPrint;
//# sourceMappingURL=index.js.map
{
"name": "react-to-print",
"version": "2.0.0-alpha-5",
"version": "2.0.0-alpha-6",
"description": "Print React components in the browser",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [

@@ -11,2 +12,3 @@ "lib"

"build": "rollup -c",
"build:ts": "tsc -p .",
"lint": "eslint . --color",

@@ -46,2 +48,5 @@ "webpack": "webpack --progress",

"@babel/preset-react": "^7.0.0",
"@types/prop-types": "^15.5.8",
"@types/react": "^16.7.18",
"@types/react-dom": "^16.0.11",
"babel-eslint": "^10.0.1",

@@ -60,4 +65,6 @@ "babel-loader": "^8.0.4",

"rollup-plugin-commonjs": "^8.2.6",
"rollup-plugin-copy": "~0.2.0",
"rollup-plugin-replace": "^2.1.0",
"rollup-plugin-uglify": "^2.0.1",
"typescript": "^3.0.0",
"webpack": "^3.9.1",

@@ -64,0 +71,0 @@ "webpack-dev-server": "^2.9.5"

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