react-to-print
Advanced tools
Comparing version 2.2.1 to 2.3.0
# CHANGELOG | ||
## 2.3.0 (July 30th, 2019) | ||
- FEATURE [152](https://github.com/gregnb/react-to-print/pull/152): Previously, this library used a window rather than an `iframe` to handle printing. That was changed some time ago, however, the `closeAfterPrint` prop was never removed from the documentation (though it was removed from the code). This release restores similar functionality, in a new `removeAfterPrint` prop. Passing this prop will ensure that `react-to-print` removes the `iframe` it uses to print from the DOM after printing (something that it currently does not do). NOTE: the `iframe` is removed after the call to `onAfterPrint` (if provided) has completed. We will likely make this the default functionality in version 3, but are keeping it like this for now to ensure anyone relying on the `iframe` does not face issues. Thanks [aviklai](https://github.com/aviklai) | ||
## 2.2.1 (July 22nd, 2019) | ||
@@ -4,0 +8,0 @@ |
@@ -14,2 +14,3 @@ import * as React from "react"; | ||
bodyClass?: string; | ||
removeAfterPrint?: boolean; | ||
} | ||
@@ -16,0 +17,0 @@ export default class ReactToPrint extends React.Component<IReactToPrintProps> { |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define("lib",["react","react-dom"],e):"object"==typeof exports?exports.lib=e(require("react"),require("react-dom")):t.lib=e(t.react,t["react-dom"])}("undefined"!=typeof self?self:this,function(t,e){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(1),o=n(2),i=n(3),a=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.startPrint=function(t,e){setTimeout(function(){t.contentWindow.focus(),t.contentWindow.print(),e&&e()},500)},e.triggerPrint=function(t){var n=e.props,r=n.onBeforePrint,o=n.onAfterPrint;if(r){var i=r();i&&"function"==typeof i.then?i.then(function(){e.startPrint(t,o)}):e.startPrint(t,o)}else e.startPrint(t,o)},e.handlePrint=function(){var t=e.props,n=t.bodyClass,r=void 0===n?"":n,o=t.content,a=t.copyStyles,u=void 0===a||a,c=t.pageStyle,l=o();if(void 0!==l){var f=document.createElement("iframe");f.style.position="absolute",f.style.top="-1000px",f.style.left="-1000px",f.id="printWindow";var s=i.findDOMNode(l),d=document.querySelectorAll("link[rel='stylesheet']");e.linkTotal=d.length||0,e.linksLoaded=[],e.linksErrored=[];var p=function(t,n){n?e.linksLoaded.push(t):(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:',t),e.linksErrored.push(t)),e.linksLoaded.length+e.linksErrored.length===e.linkTotal&&e.triggerPrint(f)};f.onload=function(){window.navigator&&window.navigator.userAgent.indexOf("Trident/7.0")>-1&&(f.onload=null);var t=f.contentDocument||f.contentWindow.document,n=s.querySelectorAll("canvas");t.open(),t.write(s.outerHTML),t.close();var o=void 0===c?"@page { size: auto; margin: 0mm; } @media print { body { -webkit-print-color-adjust: exact; } }":c,i=t.createElement("style");i.appendChild(t.createTextNode(o)),t.head.appendChild(i),r.length&&t.body.classList.add(r);for(var a=t.querySelectorAll("canvas"),l=0,d=a.length;l<d;++l){(h=a[l]).getContext("2d").drawImage(n[l],0,0)}if(!1!==u){var y=document.querySelectorAll("style, link[rel='stylesheet']");for(l=0,d=y.length;l<d;++l){var h;if("STYLE"===(h=y[l]).tagName){var b=t.createElement(h.tagName),v=h.sheet;if(v){for(var m="",g=0;g<v.cssRules.length;g++)"string"==typeof v.cssRules[g].cssText&&(m+=v.cssRules[g].cssText+"\r\n");b.setAttribute("id","react-to-print-"+l),b.appendChild(t.createTextNode(m)),t.head.appendChild(b)}}else if(h.hasAttribute("href")&&h.getAttribute("href")){b=t.createElement(h.tagName),g=0;for(var _=h.attributes.length;g<_;++g){var w=h.attributes[g];b.setAttribute(w.nodeName,w.nodeValue)}b.onload=p.bind(null,b,!0),b.onerror=p.bind(null,b,!1),t.head.appendChild(b)}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:',h),p(h,!0)}}0!==e.linkTotal&&!1!==u||e.triggerPrint(f)},document.getElementById("printWindow")&&document.body.removeChild(document.getElementById("printWindow")),document.body.appendChild(f)}else console.error('Refs are not available for stateless components. For "react-to-print" to work only Class based components can be printed')},e.setRef=function(t){e.triggerRef=t},e}return r.__extends(e,t),e.prototype.render=function(){var t=this.props.trigger;return o.cloneElement(t(),{onClick:this.handlePrint,ref:this.setRef})},e}(o.Component);e.default=a},function(t,e,n){"use strict";n.r(e),n.d(e,"__extends",function(){return o}),n.d(e,"__assign",function(){return i}),n.d(e,"__rest",function(){return a}),n.d(e,"__decorate",function(){return u}),n.d(e,"__param",function(){return c}),n.d(e,"__metadata",function(){return l}),n.d(e,"__awaiter",function(){return f}),n.d(e,"__generator",function(){return s}),n.d(e,"__exportStar",function(){return d}),n.d(e,"__values",function(){return p}),n.d(e,"__read",function(){return y}),n.d(e,"__spread",function(){return h}),n.d(e,"__await",function(){return b}),n.d(e,"__asyncGenerator",function(){return v}),n.d(e,"__asyncDelegator",function(){return m}),n.d(e,"__asyncValues",function(){return g}),n.d(e,"__makeTemplateObject",function(){return _}),n.d(e,"__importStar",function(){return w}),n.d(e,"__importDefault",function(){return x}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define("lib",["react","react-dom"],e):"object"==typeof exports?exports.lib=e(require("react"),require("react-dom")):t.lib=e(t.react,t["react-dom"])}("undefined"!=typeof self?self:this,function(t,e){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(1),o=n(2),i=n(3),a=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.startPrint=function(t,n){setTimeout(function(){t.contentWindow.focus(),t.contentWindow.print(),n&&n(),e.props.removeAfterPrint&&t.remove()},500)},e.triggerPrint=function(t){var n=e.props,r=n.onBeforePrint,o=n.onAfterPrint;if(r){var i=r();i&&"function"==typeof i.then?i.then(function(){e.startPrint(t,o)}):e.startPrint(t,o)}else e.startPrint(t,o)},e.handlePrint=function(){var t=e.props,n=t.bodyClass,r=void 0===n?"":n,o=t.content,a=t.copyStyles,u=void 0===a||a,c=t.pageStyle,l=o();if(void 0!==l){var f=document.createElement("iframe");f.style.position="absolute",f.style.top="-1000px",f.style.left="-1000px",f.id="printWindow";var s=i.findDOMNode(l),d=document.querySelectorAll("link[rel='stylesheet']");e.linkTotal=d.length||0,e.linksLoaded=[],e.linksErrored=[];var p=function(t,n){n?e.linksLoaded.push(t):(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:',t),e.linksErrored.push(t)),e.linksLoaded.length+e.linksErrored.length===e.linkTotal&&e.triggerPrint(f)};f.onload=function(){window.navigator&&window.navigator.userAgent.indexOf("Trident/7.0")>-1&&(f.onload=null);var t=f.contentDocument||f.contentWindow.document,n=s.querySelectorAll("canvas");t.open(),t.write(s.outerHTML),t.close();var o=void 0===c?"@page { size: auto; margin: 0mm; } @media print { body { -webkit-print-color-adjust: exact; } }":c,i=t.createElement("style");i.appendChild(t.createTextNode(o)),t.head.appendChild(i),r.length&&t.body.classList.add(r);for(var a=t.querySelectorAll("canvas"),l=0,d=a.length;l<d;++l){(h=a[l]).getContext("2d").drawImage(n[l],0,0)}if(!1!==u){var y=document.querySelectorAll("style, link[rel='stylesheet']");for(l=0,d=y.length;l<d;++l){var h;if("STYLE"===(h=y[l]).tagName){var b=t.createElement(h.tagName),v=h.sheet;if(v){for(var m="",g=0;g<v.cssRules.length;g++)"string"==typeof v.cssRules[g].cssText&&(m+=v.cssRules[g].cssText+"\r\n");b.setAttribute("id","react-to-print-"+l),b.appendChild(t.createTextNode(m)),t.head.appendChild(b)}}else if(h.hasAttribute("href")&&h.getAttribute("href")){b=t.createElement(h.tagName),g=0;for(var _=h.attributes.length;g<_;++g){var w=h.attributes[g];b.setAttribute(w.nodeName,w.nodeValue)}b.onload=p.bind(null,b,!0),b.onerror=p.bind(null,b,!1),t.head.appendChild(b)}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:',h),p(h,!0)}}0!==e.linkTotal&&!1!==u||e.triggerPrint(f)},document.getElementById("printWindow")&&document.body.removeChild(document.getElementById("printWindow")),document.body.appendChild(f)}else console.error('Refs are not available for stateless components. For "react-to-print" to work only Class based components can be printed')},e.setRef=function(t){e.triggerRef=t},e}return r.__extends(e,t),e.prototype.render=function(){var t=this.props.trigger;return o.cloneElement(t(),{onClick:this.handlePrint,ref:this.setRef})},e}(o.Component);e.default=a},function(t,e,n){"use strict";n.r(e),n.d(e,"__extends",function(){return o}),n.d(e,"__assign",function(){return i}),n.d(e,"__rest",function(){return a}),n.d(e,"__decorate",function(){return u}),n.d(e,"__param",function(){return c}),n.d(e,"__metadata",function(){return l}),n.d(e,"__awaiter",function(){return f}),n.d(e,"__generator",function(){return s}),n.d(e,"__exportStar",function(){return d}),n.d(e,"__values",function(){return p}),n.d(e,"__read",function(){return y}),n.d(e,"__spread",function(){return h}),n.d(e,"__await",function(){return b}),n.d(e,"__asyncGenerator",function(){return v}),n.d(e,"__asyncDelegator",function(){return m}),n.d(e,"__asyncValues",function(){return g}),n.d(e,"__makeTemplateObject",function(){return _}),n.d(e,"__importStar",function(){return w}),n.d(e,"__importDefault",function(){return x}); | ||
/*! ***************************************************************************** | ||
@@ -3,0 +3,0 @@ Copyright (c) Microsoft Corporation. All rights reserved. |
{ | ||
"name": "react-to-print", | ||
"version": "2.2.1", | ||
"version": "2.3.0", | ||
"description": "Print React components in the browser", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -138,5 +138,5 @@ <div align="center"> | ||
| **`copyStyles`** | boolean | Copies all <style> and <link type="stylesheet" /> from <head> inside the parent window into the print window. (default: true) | | ||
| **`onBeforePrint`** | function | A callback function that triggers before print. Either returns void or a Promise. If the function returns a Promise the content will be printed when the Promise is resolved. Users are responsible for catching the Promise rejecting. | | ||
| **`onAfterPrint`** | function | A callback function that triggers after print | | ||
| **`closeAfterPrint`** | boolean | Close the print window after action | | ||
| **`onBeforePrint`** | function | Optional callback function that triggers before print. Either returns void or a Promise. If the function returns a Promise the content will be printed when the Promise is resolved. Users are responsible for catching the Promise rejecting. | | ||
| **`onAfterPrint`** | function | Optional callback function that triggers after print | | ||
| **`removeAfterPrint`** | boolean | Remove the print iframe after action. Defaults to `false`. | | ||
| **`pageStyle`** | string | Override default print window styling | | ||
@@ -143,0 +143,0 @@ | **`bodyClass`** | string | Optional class to pass to the print window body | |
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
22735
59