From 1b214b712bcf08336a5002b4c840bae1c920cd61 Mon Sep 17 00:00:00 2001 From: Apperside Date: Fri, 19 Nov 2021 12:13:36 +0100 Subject: [PATCH 1/5] add callback after the file is generated --- src/ExcelPlugin/components/ExcelFile.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ExcelPlugin/components/ExcelFile.js b/src/ExcelPlugin/components/ExcelFile.js index 753a257b..ee8d03ee 100644 --- a/src/ExcelPlugin/components/ExcelFile.js +++ b/src/ExcelPlugin/components/ExcelFile.js @@ -15,6 +15,7 @@ class ExcelFile extends React.Component { filename: PropTypes.string, fileExtension: PropTypes.string, element: PropTypes.any, + onFileGenerated:PropTypes.function, children: function (props, propName, componentName) { React.Children.forEach(props[propName], child => { if (child.type !== ExcelSheet) { @@ -82,6 +83,10 @@ class ExcelFile extends React.Component { const wbout = XLSX.write(wb, {bookType: fileExtension, bookSST: true, type: 'binary'}); saveAs(new Blob([strToArrBuffer(wbout)], {type: "application/octet-stream"}), fileName); + + if(this.props.onFileGenerated){ + this.props.onFileGenerated() + } } getFileName() { From bbebb549dd28463063ec69c15b6d6298b2809bf2 Mon Sep 17 00:00:00 2001 From: Simone G Date: Fri, 19 Nov 2021 12:38:04 +0100 Subject: [PATCH 2/5] chore: add new dist folder --- dist/ExcelPlugin/components/ExcelFile.js | 5 +++++ src/ExcelPlugin/components/ExcelFile.js | 16 ++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/dist/ExcelPlugin/components/ExcelFile.js b/dist/ExcelPlugin/components/ExcelFile.js index ae7d84ba..92b5dc45 100644 --- a/dist/ExcelPlugin/components/ExcelFile.js +++ b/dist/ExcelPlugin/components/ExcelFile.js @@ -104,6 +104,10 @@ var ExcelFile = function (_React$Component) { var wbout = _tempaXlsx2.default.write(wb, { bookType: fileExtension, bookSST: true, type: 'binary' }); (0, _fileSaver.saveAs)(new Blob([(0, _DataUtil.strToArrBuffer)(wbout)], { type: "application/octet-stream" }), fileName); + + if (this.props.onFileGenerated) { + this.props.onFileGenerated(); + } } }, { key: "getFileName", @@ -165,6 +169,7 @@ ExcelFile.props = { filename: _propTypes2.default.string, fileExtension: _propTypes2.default.string, element: _propTypes2.default.any, + onFileGenerated: _propTypes2.default.function, children: function children(props, propName, componentName) { _react2.default.Children.forEach(props[propName], function (child) { if (child.type !== _ExcelSheet2.default) { diff --git a/src/ExcelPlugin/components/ExcelFile.js b/src/ExcelPlugin/components/ExcelFile.js index ee8d03ee..ff9433e0 100644 --- a/src/ExcelPlugin/components/ExcelFile.js +++ b/src/ExcelPlugin/components/ExcelFile.js @@ -1,21 +1,21 @@ import React from "react"; import PropTypes from "prop-types"; -import {saveAs} from "file-saver"; +import { saveAs } from "file-saver"; import XLSX from "tempa-xlsx"; import ExcelSheet from "../elements/ExcelSheet"; -import {strToArrBuffer, excelSheetFromAoA, excelSheetFromDataSet} from "../utils/DataUtil"; +import { strToArrBuffer, excelSheetFromAoA, excelSheetFromDataSet } from "../utils/DataUtil"; class ExcelFile extends React.Component { fileExtensions = ['xlsx', 'xls', 'csv', 'txt', 'html']; defaultFileExtension = 'xlsx'; - static props = { + static props = { hideElement: PropTypes.bool, filename: PropTypes.string, fileExtension: PropTypes.string, element: PropTypes.any, - onFileGenerated:PropTypes.function, + onFileGenerated: PropTypes.function, children: function (props, propName, componentName) { React.Children.forEach(props[propName], child => { if (child.type !== ExcelSheet) { @@ -80,11 +80,11 @@ class ExcelFile extends React.Component { const fileExtension = this.getFileExtension(); const fileName = this.getFileName(); - const wbout = XLSX.write(wb, {bookType: fileExtension, bookSST: true, type: 'binary'}); + const wbout = XLSX.write(wb, { bookType: fileExtension, bookSST: true, type: 'binary' }); - saveAs(new Blob([strToArrBuffer(wbout)], {type: "application/octet-stream"}), fileName); + saveAs(new Blob([strToArrBuffer(wbout)], { type: "application/octet-stream" }), fileName); - if(this.props.onFileGenerated){ + if (this.props.onFileGenerated) { this.props.onFileGenerated() } } @@ -126,7 +126,7 @@ class ExcelFile extends React.Component { } else { return ({element}); } - + } } From 56a1805d6f0f4ff253d53fca5c57fe05718f4eb3 Mon Sep 17 00:00:00 2001 From: Simone G Date: Fri, 19 Nov 2021 12:57:03 +0100 Subject: [PATCH 3/5] feat: add callback for file generation start --- dist/ExcelPlugin/components/ExcelFile.js | 4 ++++ src/ExcelPlugin/components/ExcelFile.js | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dist/ExcelPlugin/components/ExcelFile.js b/dist/ExcelPlugin/components/ExcelFile.js index 92b5dc45..4dd627c4 100644 --- a/dist/ExcelPlugin/components/ExcelFile.js +++ b/dist/ExcelPlugin/components/ExcelFile.js @@ -84,6 +84,9 @@ var ExcelFile = function (_React$Component) { value: function download() { var _this2 = this; + if (this.props.onGenerationStart) { + this.props.onGenerationStart(); + } var wb = { SheetNames: _react2.default.Children.map(this.props.children, function (sheet) { return sheet.props.name; @@ -170,6 +173,7 @@ ExcelFile.props = { fileExtension: _propTypes2.default.string, element: _propTypes2.default.any, onFileGenerated: _propTypes2.default.function, + onGenerationStart: _propTypes2.default.function, children: function children(props, propName, componentName) { _react2.default.Children.forEach(props[propName], function (child) { if (child.type !== _ExcelSheet2.default) { diff --git a/src/ExcelPlugin/components/ExcelFile.js b/src/ExcelPlugin/components/ExcelFile.js index ff9433e0..1a6198c9 100644 --- a/src/ExcelPlugin/components/ExcelFile.js +++ b/src/ExcelPlugin/components/ExcelFile.js @@ -16,6 +16,7 @@ class ExcelFile extends React.Component { fileExtension: PropTypes.string, element: PropTypes.any, onFileGenerated: PropTypes.function, + onGenerationStart: PropTypes.function, children: function (props, propName, componentName) { React.Children.forEach(props[propName], child => { if (child.type !== ExcelSheet) { @@ -65,6 +66,9 @@ class ExcelFile extends React.Component { } download() { + if (this.props.onGenerationStart) { + this.props.onGenerationStart(); + } const wb = { SheetNames: React.Children.map(this.props.children, sheet => sheet.props.name), Sheets: {} @@ -85,7 +89,7 @@ class ExcelFile extends React.Component { saveAs(new Blob([strToArrBuffer(wbout)], { type: "application/octet-stream" }), fileName); if (this.props.onFileGenerated) { - this.props.onFileGenerated() + this.props.onFileGenerated(); } } From 55ece870715dab969ec5cddce6b88ec6af8b1bb9 Mon Sep 17 00:00:00 2001 From: Simone G Date: Fri, 19 Nov 2021 13:53:42 +0100 Subject: [PATCH 4/5] chore: add typings --- types/index.d.ts | 59 +++++++++++++++--------------------------------- 1 file changed, 18 insertions(+), 41 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 1ee4149a..ffe8cc32 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,32 +1,29 @@ -/* index.d.ts (C) react-data-export */ - -// TypeScript Version: 2.2 -declare module 'react-data-export' { - import * as React from 'react' - +declare module "react-data-export" { export interface ExcelFileProps { filename?: string; + onFileGenerated?: () => void; + onGenerationStart?: () => void; fileExtension?: string; - element?: any; //Download Element - children?: Array | React.ReactChild; // Array; + element?: any; + children?: any } export interface ExcelSheetProps { name: string; - data?: Array; - dataSet?: Array; - value?: Array | Function; - children?: Array | React.ReactChild; // Array + data?: () => any | any[]; + dataSet?: any; + value?: string[] | Function; + children?: any } export interface ExcelSheetData { xSteps?: number; ySteps?: number; columns: Array; - data: Array; + data: any } - export type ExcelCellData = ExcelValue | ExcelCell | Array; + export type ExcelCellData = ExcelValue | ExcelCell; export type ExcelValue = string | number | Date | boolean; export interface ExcelCell { @@ -96,7 +93,7 @@ declare module 'react-data-export' { export type ExcelTextRotation = 0 | 45 | 90 | 135 | 180 | 255; - export enum ExcelReadingOrder { LeftToRight = 1, RightToLeft} + enum ExcelReadingOrder { LeftToRight = 1, RightToLeft } export type ExcelAlignmentType = "bottom" | "center" | "top"; @@ -106,32 +103,12 @@ declare module 'react-data-export' { color: ExcelColorSpec; } - export type ExcelBorderStyle = - "thin" - | "medium" - | "thick" - | "dotted" - | "hair" - | "dashed" - | "mediumDashed" - | "dashDot" - | "mediumDashDot" - | "dashDotDot" - | "mediumDashDotDot" - | "slantDashDot"; - - export class ExcelColumn extends React.Component { - } - - export class ExcelSheet extends React.Component { - } - - export class ExcelFile extends React.Component { - } + export type ExcelBorderStyle = "thin" | "medium" | "thick" | "dotted" | "hair" | "dashed" | "mediumDashed" | "dashDot" | "mediumDashDot" | "dashDotDot" | "mediumDashDotDot" | "slantDashDot"; - export namespace ReactExport { - export class ExcelFile extends React.Component { - } + declare class ExcelFile extends React.Component { + static ExcelSheet: typeof ExcelSheet + static ExcelColumn: typeof ExcelColumn } - export default ReactExport + declare class ExcelSheet extends React.Component { } + declare class ExcelColumn extends React.Component { } } From de1a8b798af5c162aceb16cb23e3d7b4278959da Mon Sep 17 00:00:00 2001 From: Simone G Date: Sat, 20 Nov 2021 13:13:42 +0100 Subject: [PATCH 5/5] chore: version bump --- .vscode/settings.json | 5 +++++ package.json | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..ab5b6a80 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "workbench.colorCustomizations": { + "editorIndentGuide.activeBackground": "#20e20e9e" + } +} \ No newline at end of file diff --git a/package.json b/package.json index 6313f869..258cb296 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-data-export", - "version": "0.6.0", + "version": "0.6.1", "main": "dist/index.js", "types": "types/index.d.ts", "description": "A set of tools to export dataset from react to different formats.", @@ -73,4 +73,4 @@ "@commitlint/config-conventional" ] } -} +} \ No newline at end of file