UNPKG

@progress/kendo-react-pdf

Version:

React PDF Processing enables you to export single- and multi-page content in PDF. KendoReact PDF Processing package

133 lines (132 loc) 4.35 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import * as r from "react"; import e from "prop-types"; import { getPageMargin as m } from "../getPageMargin.mjs"; import { savePDF as h } from "../savePDF.mjs"; import { provideSaveGridPDF as g } from "./provideSaveGridPDF.mjs"; import { createPortal as c } from "react-dom"; import { validatePackage as d, WatermarkOverlay as u } from "@progress/kendo-react-common"; import { packageMetadata as f } from "../package-metadata.mjs"; const o = class o extends r.Component { constructor(t) { super(t), this.state = { show: !1 }, this.showLicenseWatermark = !1, this.showLicenseWatermark = !d(f, { component: "GridPDFExport" }), this.saveGridPDF = g(this.getSavePDF()), this.gridInnerWrapperRef = r.createRef(); } /** * @hidden */ componentDidUpdate(t, s) { this.state.show && this.state.show !== s.show && this.saveGridPDF( this.gridInnerWrapperRef.current, Object.assign({}, this.props, { margin: m(this.props) }), this.callback ); } /** * @hidden */ render() { return /* @__PURE__ */ r.createElement(r.Fragment, null, this.state.show && c( /* @__PURE__ */ r.createElement( "div", { style: { position: "absolute", left: "-5000px", top: "0px" } }, /* @__PURE__ */ r.createElement("div", { ref: this.gridInnerWrapperRef }, this.prepareRawGridForExport(this.data)) ), document.body ), this.showLicenseWatermark && /* @__PURE__ */ r.createElement(u, null)); } /* eslint-disable max-len */ /** * Saves the content of the Grid as a PDF file. * * @param data - The data can be different from the currently displayed data in the Grid. Can be used to export all Grid pages. * @param callback - The callback that will be executed after the PDF is saved. */ // tslint:enable:max-line-length save(t, s) { this.grid = this.getGrid(), this.columns = this.getCustomColumns(), this.data = t, this.callback = () => { this.setState({ show: !1 }), s && s(); }, this.setState({ show: !0 }); } getSavePDF() { return h; } getGrid() { return r.Children.toArray(this.props.children).find( (t) => t && t.type.displayName === "KendoReactGrid" ); } getCustomColumns() { return r.Children.toArray(this.props.children).filter( (t) => t && t.type.displayName === "KendoReactGridColumn" ); } prepareRawGridForExport(t) { const s = t && { data: t, total: t.length, pageSize: t.length, skip: 0 }, a = { style: Object.assign({}, this.grid.props.style, { width: "1000px" }) }, p = { scrollable: this.grid.props === "none" ? "none" : "scrollable" }, i = Object.assign({}, s, a, p); if (this.columns && this.columns.length > 0) { const l = this.getGridNotColumnChildren(this.grid); return r.cloneElement(this.grid, i, this.columns.concat(l)); } return r.cloneElement(this.grid, i); } getGridNotColumnChildren(t) { return r.Children.toArray(t.props.children).filter( (s) => s && s.type && s.type.displayName !== "KendoReactGridColumn" ); } }; o.propTypes = { author: e.string, avoidLinks: e.oneOfType([e.bool, e.string]), forcePageBreak: e.string, keepTogether: e.string, creator: e.string, date: e.instanceOf(Date), imageResolution: e.number, fileName: e.string, forceProxy: e.bool, keywords: e.string, landscape: e.bool, margin: e.oneOfType([ e.string, e.number, e.shape({ left: e.oneOfType([e.number, e.string]), top: e.oneOfType([e.number, e.string]), right: e.oneOfType([e.number, e.string]), bottom: e.oneOfType([e.number, e.string]) }) ]), pageTemplate: e.any, paperSize: e.any, repeatHeaders: e.bool, scale: e.number, proxyData: e.any, proxyURL: e.string, proxyTarget: e.string, producer: e.string, subject: e.string, title: e.string }; let n = o; export { n as GridPDFExport };