react-to-print
Advanced tools
Comparing version 2.11.0 to 2.12.0
# CHANGELOG | ||
## 2.12.0 (November 27th, 2020) | ||
- CHORE: added React/ReactDOM ^17 to allowed peerDependencies. Library still supports React >= 15, though expect a major release in the near-future that drops React 15 support, which will clear the way to removing the restriction that the top-level component being printed must be a class component | ||
- CHORE: upgraded all devDependencies. Big changes here include updating Typescript from 3 -> 4 and Webpack from 4 -> 5. While upgrading Webpack the minifier was changed from UglifyJS to Terser, resulting in a 5.7% reduced file size (14.1kb -> 13.3kb) | ||
- CHORE: Use Node ^14 for CLI tests | ||
- DOCUMENTATION: small improvements to the examples, including renaming them from `example` -> `examples` | ||
- DOCUMENTATION: added a note about finding the [`examples`](https://github.com/gregnb/react-to-print/tree/master/examples) folder | ||
- DOCUMENTATION [311](https://github.com/gregnb/react-to-print/issues/311): small type fix, thanks [nealeu](https://github.com/nealeu) | ||
- DOCUMENTATION: added a "Common Pitfalls" section to the README, starting with a note on using the library with a component wrapped in `connect` from `react-redux` | ||
## 2.11.0 (October 30th, 2020) | ||
@@ -4,0 +14,0 @@ |
@@ -1,1 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define("lib",["react","react-dom"],t):"object"==typeof exports?exports.lib=t(require("react"),require("react-dom")):e.lib=t(e.react,e["react-dom"])}("undefined"!=typeof self?self:this,function(n,r){return a={},o.m=i=[function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.useReactToPrint=t.PrintContextConsumer=void 0;var L=n(1),i=n(2),a=n(3),r=Object.prototype.hasOwnProperty.call(i,"createContext"),o=Object.prototype.hasOwnProperty.call(i,"useMemo")&&Object.prototype.hasOwnProperty.call(i,"useCallback"),l=r?i.createContext({}):null;t.PrintContextConsumer=l?l.Consumer:function(){return null};var c,u={copyStyles:!0,pageStyle:"@page { size: auto; margin: 0mm; } @media print { body { -webkit-print-color-adjust: exact; } }",removeAfterPrint:!1,suppressErrors:!1},s=(c=i.Component,L.__extends(f,c),f.prototype.render=function(){var e=this.props,t=e.children,n=e.suppressErrors,r=e.trigger;if(r)return i.cloneElement(r(),{onClick:this.handleClick});var o={handlePrint:this.handleClick};return l?l?i.createElement(l.Provider,{value:o},t):i.createElement("h2",null,"lorem"):(n||console.error('"react-to-print" requires React ^16.3.0 to be able to use "PrintContext"'),null)},f.defaultProps=u,f);function f(){var W=null!==c&&c.apply(this,arguments)||this;return W.startPrint=function(t){var e=W.props,n=e.onAfterPrint,r=e.onPrintError,o=e.print,i=e.suppressErrors,a=e.documentTitle;setTimeout(function(){if(t.contentWindow){if(t.contentWindow.focus(),o)o(t).then(W.handleRemoveIframe).catch(function(e){r?r("print",e):i||console.error("An error was thrown by the specified `print` function",e)});else if(t.contentWindow.print){var e=document.title;a&&(document.title=a),t.contentWindow.print(),a&&(document.title=e),n&&n()}else i||console.error("Printing for this browser is not currently possible: the browser does not have a `print` method available for iframes.");W.handleRemoveIframe()}else i||console.error("Printing failed because the `contentWindow` of the print iframe did not load. This is possibly an error with `react-to-print`. Please file an issue: https://github.com/gregnb/react-to-print/issues/")},500)},W.triggerPrint=function(e){var t=W.props,n=t.onBeforePrint,r=t.onPrintError;if(n){var o=n();o&&"function"==typeof o.then?o.then(function(){W.startPrint(e)}).catch(function(e){r&&r("onBeforePrint",e)}):W.startPrint(e)}else W.startPrint(e)},W.handleClick=function(){var e=W.props,t=e.onBeforeGetContent,n=e.onPrintError;if(t){var r=t();r&&"function"==typeof r.then?r.then(W.handlePrint).catch(function(e){n&&n("onBeforeGetContent",e)}):W.handlePrint()}else W.handlePrint()},W.handlePrint=function(){var e=W.props,j=e.bodyClass,t=e.content,E=e.copyStyles,T=e.fonts,C=e.pageStyle,A=e.suppressErrors,n=t();if(void 0!==n)if(null!==n){var I=document.createElement("iframe");I.style.position="absolute",I.style.top="-1000px",I.style.left="-1000px",I.id="printWindow",I.title="Print Window";var R=a.findDOMNode(n);if(R){var r=document.querySelectorAll("link[rel='stylesheet']"),q=R.querySelectorAll("img");W.linkTotal=r.length+q.length,W.linksLoaded=[],W.linksErrored=[],W.fontsLoaded=[],W.fontsErrored=[];var M=function(e,t){t?W.linksLoaded.push(e):(A||console.error('"react-to-print" was unable to load a linked node. It may be invalid. "react-to-print" will continue attempting to print the page. The linked node that errored was:',e),W.linksErrored.push(e)),W.linksLoaded.length+W.linksErrored.length+W.fontsLoaded.length+W.fontsErrored.length===W.linkTotal&&W.triggerPrint(I)};I.onload=function(){var e,t,n,r;I.onload=null;var o=I.contentDocument||(null===(t=I.contentWindow)||void 0===t?void 0:t.document),i=R.querySelectorAll("canvas");if(o){o.open(),o.write(R.outerHTML),o.close(),T&&(null!==(n=I.contentDocument)&&void 0!==n&&n.fonts&&null!==(r=I.contentWindow)&&void 0!==r&&r.FontFace?T.forEach(function(e){var t=new FontFace(e.family,e.source);I.contentDocument.fonts.add(t),t.loaded.then(function(e){W.fontsLoaded.push(e)}).catch(function(e){W.fontsErrored.push(t),A||console.error('"react-to-print" was unable to load a font. "react-to-print" will continue attempting to print the page. The font that failed to load is:',t,"The error from loading the font is:",e)})}):A||console.error('"react-to-print" is not able to load custom fonts because the browser does not support the FontFace API'));var a="function"==typeof C?C():C,l=o.createElement("style");l.appendChild(o.createTextNode(a)),o.head.appendChild(l),j&&(e=o.body.classList).add.apply(e,L.__spread(j.split(" ")));for(var c=o.querySelectorAll("canvas"),u=0,s=c.length;u<s;++u){var f=(g=c[u]).getContext("2d");f&&f.drawImage(i[u],0,0)}for(u=0;u<q.length;u++){var d=q[u],p=d.getAttribute("src");if(p){var h=new Image;h.onload=M.bind(null,d,!0),h.onerror=M.bind(null,d,!1),h.src=p}else A||console.warn('"react-to-print" encountered an <img> tag with an empty "src" attribute. It will not attempt to pre-load it. The <img> is:',d)}var y=R.querySelectorAll("input[type=checkbox]"),b=o.querySelectorAll("input[type=checkbox]");for(u=0;u<y.length;u++)b[u].checked=y[u].checked;if(E)for(var m=document.querySelectorAll("style, link[rel='stylesheet']"),v=(u=0,m.length);u<v;++u){var g;if("STYLE"===(g=m[u]).tagName){var w=o.createElement(g.tagName),_=g.sheet;if(_){for(var P="",x=0,O=_.cssRules.length;x<O;++x)"string"==typeof _.cssRules[x].cssText&&(P+=_.cssRules[x].cssText+"\r\n");w.setAttribute("id","react-to-print-"+u),w.appendChild(o.createTextNode(P)),o.head.appendChild(w)}}else if(g.getAttribute("href")){w=o.createElement(g.tagName),x=0;for(var S=g.attributes.length;x<S;++x){var k=g.attributes[x];k&&w.setAttribute(k.nodeName,k.nodeValue||"")}w.onload=M.bind(null,w,!0),w.onerror=M.bind(null,w,!1),o.head.appendChild(w)}else A||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:',g),M(g,!0)}}0!==W.linkTotal&&E||W.triggerPrint(I)};var o=document.getElementById("printWindow");o&&document.body.removeChild(o),document.body.appendChild(I)}else A||console.error('"react-to-print" could not locate the DOM node corresponding with the `content` prop')}else A||console.error('There is nothing to print because the "content" prop returned "null". Please ensure "content" is renderable before allowing "react-to-print" to be called.');else A||console.error('For "react-to-print" to work only Class based components can be printed.')},W.handleRemoveIframe=function(){if(W.props.removeAfterPrint){var e=document.getElementById("printWindow");e&&document.body.removeChild(e)}},W}t.default=s,t.useReactToPrint=o?function(e){var t=i.useMemo(function(){return new s(L.__assign(L.__assign({},u),e))},[e]);return i.useCallback(function(){return t.handleClick()},[t])}:function(e){e.suppressErrors||console.warn('"react-to-print" requires React ^16.8.0 to be able to use "useReactToPrint"')}},function(e,t,n){"use strict";n.r(t),n.d(t,"__extends",function(){return o}),n.d(t,"__assign",function(){return i}),n.d(t,"__rest",function(){return a}),n.d(t,"__decorate",function(){return l}),n.d(t,"__param",function(){return c}),n.d(t,"__metadata",function(){return u}),n.d(t,"__awaiter",function(){return s}),n.d(t,"__generator",function(){return f}),n.d(t,"__exportStar",function(){return d}),n.d(t,"__values",function(){return p}),n.d(t,"__read",function(){return h}),n.d(t,"__spread",function(){return y}),n.d(t,"__spreadArrays",function(){return b}),n.d(t,"__await",function(){return m}),n.d(t,"__asyncGenerator",function(){return v}),n.d(t,"__asyncDelegator",function(){return g}),n.d(t,"__asyncValues",function(){return w}),n.d(t,"__makeTemplateObject",function(){return _}),n.d(t,"__importStar",function(){return P}),n.d(t,"__importDefault",function(){return x}),n.d(t,"__classPrivateFieldGet",function(){return O}),n.d(t,"__classPrivateFieldSet",function(){return S});var r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function o(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var i=function(){return(i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function a(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function l(e,t,n,r){var o,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var l=e.length-1;0<=l;l--)(o=e[l])&&(a=(i<3?o(a):3<i?o(t,n,a):o(t,n))||a);return 3<i&&a&&Object.defineProperty(t,n,a),a}function c(n,r){return function(e,t){r(e,t,n)}}function u(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function s(e,a,l,c){return new(l=l||Promise)(function(n,t){function r(e){try{i(c.next(e))}catch(e){t(e)}}function o(e){try{i(c.throw(e))}catch(e){t(e)}}function i(e){var t;e.done?n(e.value):((t=e.value)instanceof l?t:new l(function(e){e(t)})).then(r,o)}i((c=c.apply(e,a||[])).next())})}function f(n,r){var o,i,a,e,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return e={next:t(0),throw:t(1),return:t(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(t){return function(e){return function(t){if(o)throw new TypeError("Generator is already executing.");for(;l;)try{if(o=1,i&&(a=2&t[0]?i.return:t[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,t[1])).done)return a;switch(i=0,a&&(t=[2&t[0],a.value]),t[0]){case 0:case 1:a=t;break;case 4:return l.label++,{value:t[1],done:!1};case 5:l.label++,i=t[1],t=[0];continue;case 7:t=l.ops.pop(),l.trys.pop();continue;default:if(!(a=0<(a=l.trys).length&&a[a.length-1])&&(6===t[0]||2===t[0])){l=0;continue}if(3===t[0]&&(!a||t[1]>a[0]&&t[1]<a[3])){l.label=t[1];break}if(6===t[0]&&l.label<a[1]){l.label=a[1],a=t;break}if(a&&l.label<a[2]){l.label=a[2],l.ops.push(t);break}a[2]&&l.ops.pop(),l.trys.pop();continue}t=r.call(n,l)}catch(e){t=[6,e],i=0}finally{o=a=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}}function d(e,t){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}function p(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function h(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||0<t--)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a}function y(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(h(arguments[t]));return e}function b(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var i=arguments[t],a=0,l=i.length;a<l;a++,o++)r[o]=i[a];return r}function m(e){return this instanceof m?(this.v=e,this):new m(e)}function v(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,i=n.apply(e,t||[]),a=[];return o={},r("next"),r("throw"),r("return"),o[Symbol.asyncIterator]=function(){return this},o;function r(r){i[r]&&(o[r]=function(n){return new Promise(function(e,t){1<a.push([r,n,e,t])||l(r,n)})})}function l(e,t){try{(n=i[e](t)).value instanceof m?Promise.resolve(n.value.v).then(c,u):s(a[0][2],n)}catch(e){s(a[0][3],e)}var n}function c(e){l("next",e)}function u(e){l("throw",e)}function s(e,t){e(t),a.shift(),a.length&&l(a[0][0],a[0][1])}}function g(r){var e,o;return e={},t("next"),t("throw",function(e){throw e}),t("return"),e[Symbol.iterator]=function(){return this},e;function t(t,n){e[t]=r[t]?function(e){return(o=!o)?{value:m(r[t](e)),done:"return"===t}:n?n(e):e}:n}}function w(c){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,t=c[Symbol.asyncIterator];return t?t.call(c):(c=p(c),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(l){e[l]=c[l]&&function(a){return new Promise(function(e,t){var n,r,o,i;a=c[l](a),n=e,r=t,o=a.done,i=a.value,Promise.resolve(i).then(function(e){n({value:e,done:o})},r)})}}}function _(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}function P(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function x(e){return e&&e.__esModule?e:{default:e}}function O(e,t){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return t.get(e)}function S(e,t,n){if(!t.has(e))throw new TypeError("attempted to set private field on non-instance");return t.set(e,n),n}},function(e,t){e.exports=n},function(e,t){e.exports=r}],o.c=a,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)o.d(n,r,function(e){return t[e]}.bind(null,r));return n},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=0);function o(e){if(a[e])return a[e].exports;var t=a[e]={i:e,l:!1,exports:{}};return i[e].call(t.exports,t,t.exports,o),t.l=!0,t.exports}var i,a}); | ||
/*! For license information please see index.js.LICENSE.txt */ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define("lib",["react","react-dom"],t):"object"==typeof exports?exports.lib=t(require("react"),require("react-dom")):e.lib=t(e.react,e["react-dom"])}("undefined"!=typeof self?self:this,(function(e,t){return(()=>{"use strict";var n={629:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.useReactToPrint=t.PrintContextConsumer=void 0;var r=n(655),o=n(297),i=n(268),a=Object.prototype.hasOwnProperty.call(o,"createContext"),l=Object.prototype.hasOwnProperty.call(o,"useMemo")&&Object.prototype.hasOwnProperty.call(o,"useCallback"),c=a?o.createContext({}):null;t.PrintContextConsumer=c?c.Consumer:function(){return null};var s={copyStyles:!0,pageStyle:"@page { size: auto; margin: 0mm; } @media print { body { -webkit-print-color-adjust: exact; } }",removeAfterPrint:!1,suppressErrors:!1},u=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.startPrint=function(e){var n=t.props,r=n.onAfterPrint,o=n.onPrintError,i=n.print,a=n.suppressErrors,l=n.documentTitle;setTimeout((function(){if(e.contentWindow){if(e.contentWindow.focus(),i)i(e).then(t.handleRemoveIframe).catch((function(e){o?o("print",e):a||console.error("An error was thrown by the specified `print` function",e)}));else if(e.contentWindow.print){var n=document.title;l&&(document.title=l),e.contentWindow.print(),l&&(document.title=n),r&&r()}else a||console.error("Printing for this browser is not currently possible: the browser does not have a `print` method available for iframes.");t.handleRemoveIframe()}else a||console.error("Printing failed because the `contentWindow` of the print iframe did not load. This is possibly an error with `react-to-print`. Please file an issue: https://github.com/gregnb/react-to-print/issues/")}),500)},t.triggerPrint=function(e){var n=t.props,r=n.onBeforePrint,o=n.onPrintError;if(r){var i=r();i&&"function"==typeof i.then?i.then((function(){t.startPrint(e)})).catch((function(e){o&&o("onBeforePrint",e)})):t.startPrint(e)}else t.startPrint(e)},t.handleClick=function(){var e=t.props,n=e.onBeforeGetContent,r=e.onPrintError;if(n){var o=n();o&&"function"==typeof o.then?o.then(t.handlePrint).catch((function(e){r&&r("onBeforeGetContent",e)})):t.handlePrint()}else t.handlePrint()},t.handlePrint=function(){var e=t.props,n=e.bodyClass,o=e.content,a=e.copyStyles,l=e.fonts,c=e.pageStyle,s=e.suppressErrors,u=o();if(void 0!==u)if(null!==u){var f=document.createElement("iframe");f.style.position="absolute",f.style.top="-1000px",f.style.left="-1000px",f.id="printWindow",f.title="Print Window";var d=i.findDOMNode(u);if(d){var p=document.querySelectorAll("link[rel='stylesheet']"),h=d.querySelectorAll("img");t.linkTotal=p.length+h.length,t.linksLoaded=[],t.linksErrored=[],t.fontsLoaded=[],t.fontsErrored=[];var y=function(e,n){n?t.linksLoaded.push(e):(s||console.error('"react-to-print" was unable to load a linked node. It may be invalid. "react-to-print" will continue attempting to print the page. The linked node that errored was:',e),t.linksErrored.push(e)),t.linksLoaded.length+t.linksErrored.length+t.fontsLoaded.length+t.fontsErrored.length===t.linkTotal&&t.triggerPrint(f)};f.onload=function(){var e,o,i,u;f.onload=null;var p=f.contentDocument||(null===(o=f.contentWindow)||void 0===o?void 0:o.document),b=d.querySelectorAll("canvas");if(p){p.open(),p.write(d.outerHTML),p.close(),l&&((null===(i=f.contentDocument)||void 0===i?void 0:i.fonts)&&(null===(u=f.contentWindow)||void 0===u?void 0:u.FontFace)?l.forEach((function(e){var n=new FontFace(e.family,e.source);f.contentDocument.fonts.add(n),n.loaded.then((function(e){t.fontsLoaded.push(e)})).catch((function(e){t.fontsErrored.push(n),s||console.error('"react-to-print" was unable to load a font. "react-to-print" will continue attempting to print the page. The font that failed to load is:',n,"The error from loading the font is:",e)}))})):s||console.error('"react-to-print" is not able to load custom fonts because the browser does not support the FontFace API'));var m="function"==typeof c?c():c,v=p.createElement("style");v.appendChild(p.createTextNode(m)),p.head.appendChild(v),n&&(e=p.body.classList).add.apply(e,r.__spread(n.split(" ")));for(var w=p.querySelectorAll("canvas"),g=0,_=w.length;g<_;++g){var P=(C=w[g]).getContext("2d");P&&P.drawImage(b[g],0,0)}for(g=0;g<h.length;g++){var x=h[g],O=x.getAttribute("src");if(O){var S=new Image;S.onload=y.bind(null,x,!0),S.onerror=y.bind(null,x,!1),S.src=O}else s||console.warn('"react-to-print" encountered an <img> tag with an empty "src" attribute. It will not attempt to pre-load it. The <img> is:',x)}var k=d.querySelectorAll("input[type=checkbox]"),E=p.querySelectorAll("input[type=checkbox]");for(g=0;g<k.length;g++)E[g].checked=k[g].checked;if(a)for(var T=document.querySelectorAll("style, link[rel='stylesheet']"),j=(g=0,T.length);g<j;++g){var C;if("STYLE"===(C=T[g]).tagName){var A=p.createElement(C.tagName),I=C.sheet;if(I){for(var R="",q=0,M=I.cssRules.length;q<M;++q)"string"==typeof I.cssRules[q].cssText&&(R+=I.cssRules[q].cssText+"\r\n");A.setAttribute("id","react-to-print-"+g),A.appendChild(p.createTextNode(R)),p.head.appendChild(A)}}else if(C.getAttribute("href")){A=p.createElement(C.tagName),q=0;for(var W=C.attributes.length;q<W;++q){var L=C.attributes[q];L&&A.setAttribute(L.nodeName,L.nodeValue||"")}A.onload=y.bind(null,A,!0),A.onerror=y.bind(null,A,!1),p.head.appendChild(A)}else s||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:',C),y(C,!0)}}0!==t.linkTotal&&a||t.triggerPrint(f)};var b=document.getElementById("printWindow");b&&document.body.removeChild(b),document.body.appendChild(f)}else s||console.error('"react-to-print" could not locate the DOM node corresponding with the `content` prop')}else s||console.error('There is nothing to print because the "content" prop returned "null". Please ensure "content" is renderable before allowing "react-to-print" to be called.');else s||console.error('For "react-to-print" to work only Class based components can be printed.')},t.handleRemoveIframe=function(){if(t.props.removeAfterPrint){var e=document.getElementById("printWindow");e&&document.body.removeChild(e)}},t}return r.__extends(t,e),t.prototype.render=function(){var e=this.props,t=e.children,n=e.suppressErrors,r=e.trigger;if(r)return o.cloneElement(r(),{onClick:this.handleClick});var i={handlePrint:this.handleClick};return c?c?o.createElement(c.Provider,{value:i},t):o.createElement("h2",null,"lorem"):(n||console.error('"react-to-print" requires React ^16.3.0 to be able to use "PrintContext"'),null)},t.defaultProps=s,t}(o.Component);t.default=u,t.useReactToPrint=l?function(e){var t=o.useMemo((function(){return new u(r.__assign(r.__assign({},s),e))}),[e]);return o.useCallback((function(){return t.handleClick()}),[t])}:function(e){e.suppressErrors||console.warn('"react-to-print" requires React ^16.8.0 to be able to use "useReactToPrint"')}},655:(e,t,n)=>{n.r(t),n.d(t,{__extends:()=>o,__assign:()=>i,__rest:()=>a,__decorate:()=>l,__param:()=>c,__metadata:()=>s,__awaiter:()=>u,__generator:()=>f,__exportStar:()=>d,__values:()=>p,__read:()=>h,__spread:()=>y,__spreadArrays:()=>b,__await:()=>m,__asyncGenerator:()=>v,__asyncDelegator:()=>w,__asyncValues:()=>g,__makeTemplateObject:()=>_,__importStar:()=>P,__importDefault:()=>x,__classPrivateFieldGet:()=>O,__classPrivateFieldSet:()=>S});var r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function o(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var i=function(){return(i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function a(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function l(e,t,n,r){var o,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var l=e.length-1;l>=0;l--)(o=e[l])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function c(e,t){return function(n,r){t(n,r,e)}}function s(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function u(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function l(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}c((r=r.apply(e,t||[])).next())}))}function f(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function l(i){return function(l){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,l])}}}function d(e,t){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}function p(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function h(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a}function y(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(h(arguments[t]));return e}function b(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var i=arguments[t],a=0,l=i.length;a<l;a++,o++)r[o]=i[a];return r}function m(e){return this instanceof m?(this.v=e,this):new m(e)}function v(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,o=n.apply(e,t||[]),i=[];return r={},a("next"),a("throw"),a("return"),r[Symbol.asyncIterator]=function(){return this},r;function a(e){o[e]&&(r[e]=function(t){return new Promise((function(n,r){i.push([e,t,n,r])>1||l(e,t)}))})}function l(e,t){try{(n=o[e](t)).value instanceof m?Promise.resolve(n.value.v).then(c,s):u(i[0][2],n)}catch(e){u(i[0][3],e)}var n}function c(e){l("next",e)}function s(e){l("throw",e)}function u(e,t){e(t),i.shift(),i.length&&l(i[0][0],i[0][1])}}function w(e){var t,n;return t={},r("next"),r("throw",(function(e){throw e})),r("return"),t[Symbol.iterator]=function(){return this},t;function r(r,o){t[r]=e[r]?function(t){return(n=!n)?{value:m(e[r](t)),done:"return"===r}:o?o(t):t}:o}}function g(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e=p(e),t={},r("next"),r("throw"),r("return"),t[Symbol.asyncIterator]=function(){return this},t);function r(n){t[n]=e[n]&&function(t){return new Promise((function(r,o){!function(e,t,n,r){Promise.resolve(r).then((function(t){e({value:t,done:n})}),t)}(r,o,(t=e[n](t)).done,t.value)}))}}}function _(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}function P(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function x(e){return e&&e.__esModule?e:{default:e}}function O(e,t){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return t.get(e)}function S(e,t,n){if(!t.has(e))throw new TypeError("attempted to set private field on non-instance");return t.set(e,n),n}},297:t=>{t.exports=e},268:e=>{e.exports=t}},r={};function o(e){if(r[e])return r[e].exports;var t=r[e]={exports:{}};return n[e](t,t.exports,o),t.exports}return o.d=(e,t)=>{for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o(629)})()})); |
{ | ||
"name": "react-to-print", | ||
"version": "2.11.0", | ||
"version": "2.12.0", | ||
"description": "Print React components in the browser", | ||
@@ -11,4 +11,4 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"start": "webpack-dev-server --env.development --progress --colors --hot --open", | ||
"build": "webpack --env.production --progress", | ||
"start": "NODE_ENV=development webpack serve", | ||
"build": "NODE_ENV=production webpack --progress", | ||
"prepare": "npm run build", | ||
@@ -37,4 +37,4 @@ "lint": "eslint src/**/*.{ts,tsx}" | ||
"peerDependencies": { | ||
"react": "^15.0.0 || ^16.0.0", | ||
"react-dom": "^15.0.0 || ^16.0.0" | ||
"react": "^15.0.0 || ^16.0.0 || ^17.0.0", | ||
"react-dom": "^15.0.0 || ^16.0.0 || ^17.0.0" | ||
}, | ||
@@ -45,21 +45,21 @@ "dependencies": { | ||
"devDependencies": { | ||
"@types/react": "^16.9.55", | ||
"@types/react-dom": "^16.9.9", | ||
"@typescript-eslint/eslint-plugin": "^3.9.1", | ||
"@typescript-eslint/parser": "^3.9.1", | ||
"acorn": "^7.2.0", | ||
"@types/react": "^17.0.0", | ||
"@types/react-dom": "^17.0.0", | ||
"@typescript-eslint/eslint-plugin": "^4.8.2", | ||
"@typescript-eslint/parser": "^4.8.2", | ||
"acorn": "^8.0.4", | ||
"clean-webpack-plugin": "^3.0.0", | ||
"css-loader": "^3.5.3", | ||
"eslint": "^7.12.1", | ||
"css-loader": "^5.0.1", | ||
"eslint": "^7.14.0", | ||
"html-webpack-plugin": "^4.5.0", | ||
"husky": "^4.3.0", | ||
"lint-staged": "^10.5.0", | ||
"react": "^16.8.4", | ||
"react-dom": "^16.8.4", | ||
"style-loader": "^1.2.1", | ||
"ts-loader": "^7.0.5", | ||
"typescript": "^3.9.3", | ||
"uglifyjs-webpack-plugin": "^2.2.0", | ||
"webpack": "^4.44.1", | ||
"webpack-cli": "^3.3.12", | ||
"lint-staged": "^10.5.2", | ||
"react": "^17.0.1", | ||
"react-dom": "^17.0.1", | ||
"style-loader": "^2.0.0", | ||
"ts-loader": "^8.0.11", | ||
"typescript": "^4.1.2", | ||
"url-loader": "^4.1.1", | ||
"webpack": "^5.8.0", | ||
"webpack-cli": "^4.2.0", | ||
"webpack-dev-server": "^3.11.0" | ||
@@ -66,0 +66,0 @@ }, |
@@ -1,4 +0,4 @@ | ||
<div align="center"> | ||
<img src="https://user-images.githubusercontent.com/19170080/33672781-14f1b03e-da79-11e7-95fe-4ce15f170230.png" /> | ||
</div> | ||
<p align="center"> | ||
<img width="300" height="300" src="./logo.png" alt="react-to-print logo"> | ||
</p> | ||
@@ -67,2 +67,4 @@ # ReactToPrint - Print React components in the browser | ||
For full examples please see the [`examples`](https://github.com/gregnb/react-to-print/tree/master/examples) folder. | ||
```jsx | ||
@@ -190,5 +192,9 @@ export class ComponentToPrint extends React.PureComponent { | ||
## Common Pitfalls | ||
- The `connect` method from `react-redux` returns a functional component that cannot be assigned a reference to be used within the `content` props' callback in `react-to-print`. To use a component wrapped in `connect` within `content` create an intermediate class component that simply renders your component wrapped in `connect`. See [280](https://github.com/gregnb/react-to-print/issues/280) for more. | ||
## Running locally | ||
*NOTE*: Node ^10 is required to build the library locally. We use Node ^10 for our CLI checks. | ||
*NOTE*: Node >=10 is required to build the library locally. We use Node ^14 for our CLI checks. | ||
@@ -195,0 +201,0 @@ ## FAQ |
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
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
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
44099
7
52
299
2
80