UNPKG

@progress/kendo-react-pdf

Version:

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

116 lines (115 loc) 4.11 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 s from "react"; import e from "prop-types"; import { getPageMargin as n } from "../getPageMargin.mjs"; import { savePDF as p } from "../savePDF.mjs"; import { provideSaveTreeListPDF as h } from "./provideSaveTreeListPDF.mjs"; import { createPortal as m } from "react-dom"; import { packageMetadata as l } from "../package-metadata.mjs"; import { validatePackage as c, WatermarkOverlay as g } from "@progress/kendo-react-common"; const o = class o extends s.Component { constructor(t) { super(t), this.state = { show: !1 }, this.showLicenseWatermark = !1, this.showLicenseWatermark = !c(l, { component: "TreeListPDFExport" }), this.saveTreeListPDF = h(this.getSavePDF()), this.treeListInnerWrapperRef = s.createRef(); } /** * @hidden */ componentDidUpdate(t, r) { this.state.show && this.state.show !== r.show && this.saveTreeListPDF( this.treeListInnerWrapperRef.current, Object.assign({}, this.props, { margin: n(this.props) }), this.callback ); } /** * @hidden */ render() { return /* @__PURE__ */ s.createElement(s.Fragment, null, this.state.show && m( /* @__PURE__ */ s.createElement( "div", { style: { position: "absolute", left: "-5000px", top: "0px" } }, /* @__PURE__ */ s.createElement("div", { ref: this.treeListInnerWrapperRef }, this.prepareRawTreeListForExport()) ), document.body ), this.showLicenseWatermark && /* @__PURE__ */ s.createElement(g, null)); } /* eslint-disable max-len */ /** * Saves the content of the TreeList as a PDF file. * * @param data - The data that will be exported to the PDF. The data can be different from the currently displayed data in the TreeList. * @param columns - The columns that will be exported to the PDF. The columns collection can be different from the currently displayed in the TreeList. * @param callback - The callback that will be executed after the PDF is saved. */ // tslint:enable:max-line-length save(t, r, i) { this.treeList = this.getTreeList(), this.columns = r || [], this.data = t, this.callback = () => { this.setState({ show: !1 }), i && i(); }, this.setState({ show: !0 }); } getSavePDF() { return p; } getTreeList() { const t = this.props.children; if (t && t.props.data && t.props.columns) return this.props.children; } prepareRawTreeListForExport() { const t = this.props.allPages && this.data ? { data: this.data, take: Number.MAX_VALUE, skip: 0 } : {}, r = { style: Object.assign({}, this.treeList.props.style, { width: "1000px" }) }, i = Object.assign({}, t, r); return this.columns && this.columns.length > 0 ? s.cloneElement(this.treeList, Object.assign({}, i, { columns: this.columns })) : s.cloneElement(this.treeList, i); } }; 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, allPages: e.bool }; let a = o; export { a as TreeListPDFExport };