@angulartoolsdr/cdk-table-exporter
Version:
Abstract CdkTable Exporter
251 lines (231 loc) • 9.82 kB
TypeScript
import * as i0 from '@angular/core';
import { Injector, EventEmitter, InjectionToken } from '@angular/core';
import * as i1 from '@angular/cdk/table';
import { DataRowOutlet } from '@angular/cdk/table';
import { Observable } from 'rxjs';
import * as XLSX from 'xlsx';
import { WritingOptions, WorkSheet } from 'xlsx';
declare class CdkTableExporterModule {
static ɵfac: i0.ɵɵFactoryDeclaration<CdkTableExporterModule, never>;
static ɵmod: i0.ɵɵNgModuleDeclaration<CdkTableExporterModule, never, [typeof i1.CdkTableModule], never>;
static ɵinj: i0.ɵɵInjectorDeclaration<CdkTableExporterModule>;
}
declare enum ExportType {
XLS = "xls",
XLSX = "xlsx",
CSV = "csv",
TXT = "txt",
JSON = "json",
OTHER = "other"
}
interface Options {
fileName?: string;
}
interface TxtOptions extends Options {
delimiter?: string;
}
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
interface ExcelOptions extends Options, Omit<WritingOptions, 'bookType'> {
columnWidths: Array<number>;
}
declare class DataExtractorService {
constructor();
extractRows(cdkTable: any, hiddenColumns?: Array<any>, outlet?: DataRowOutlet): Array<any>;
private getRowsAsJsonArray;
private getRenderedRows;
private convertToJsonArray;
private convertRow;
private shouldHide;
private createExcelItem;
static ɵfac: i0.ɵɵFactoryDeclaration<DataExtractorService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<DataExtractorService>;
}
interface Exporter<T extends Options> {
export(rows: Array<any>, options?: T): void;
}
declare class ServiceLocatorService {
private injector;
constructor(injector: Injector);
getService(exportType: ExportType | 'xls' | 'xlsx' | 'csv' | 'txt' | 'json' | 'other', customExporter?: Exporter<Options>): Exporter<Options>;
static ɵfac: i0.ɵɵFactoryDeclaration<ServiceLocatorService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<ServiceLocatorService>;
}
/**
* Exporter class for CdkTable. Abstracts the varying behaviors among different CdkTable implementations.
*/
declare abstract class CdkTableExporter {
private serviceLocator;
private dataExtractor;
protected _cdkTable: any;
private _exporterService;
hiddenColumns?: Array<number>;
exporter?: Exporter<Options>;
exportCompleted: EventEmitter<void>;
exportStarted: EventEmitter<void>;
/**
* Data array which is extracted from nativeTable
*/
private _data;
private _isIterating;
private _initialPageIndex;
private _isExporting;
private _subscription;
private _options?;
private _selectedRows;
constructor(serviceLocator: ServiceLocatorService, dataExtractor: DataExtractorService, _cdkTable: any);
/**
* Must return the number of pages of the table
*/
abstract getPageCount(): number;
/**
* Must return the number of items to display on a page
*/
abstract getPageSize(): number;
/**
* Must return the index of the current page that's displayed
*/
abstract getCurrentPageIndex(): number;
/**
* Must return the total number of items in the table
*/
abstract getTotalItemsCount(): number;
/**
* When called, the CdkTable should render the rows inside the page whose index given as parameter
* @param index page index
*/
abstract goToPage(index: number): void;
/**
* Must return an observable that notifies the subscribers about page changes
*/
abstract getPageChangeObservable(): Observable<any> | undefined;
/**
* Triggers page event chain thus extracting and exporting all the rows in nativetables in pages
*/
exportTable(exportType?: ExportType | 'xls' | 'xlsx' | 'csv' | 'txt' | 'json' | 'other', options?: Options | ExcelOptions | TxtOptions): void;
toggleRow(index: number): void;
/**
* This event will clear rows selection done using toggleRow functionality
*/
resetToggleRows(): void;
private toggleOn;
private toggleOff;
private isToggleOn;
private loadExporter;
private exportWithPagination;
private exportSinglePage;
private extractDataOnCurrentPage;
private getSelectedRows;
private isSelectiveExport;
private isMasterToggleOn;
private isMasterToggleOff;
private compareSelectedRowCount;
private initPageHandler;
private exportExtractedData;
private extractSpecialRows;
private extractTableHeader;
private extractTableFooter;
private hasNextPage;
private nextPage;
private getPaginatedRowIndex;
static ɵfac: i0.ɵɵFactoryDeclaration<CdkTableExporter, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<CdkTableExporter, never, never, { "hiddenColumns": { "alias": "hiddenColumns"; "required": false; }; "exporter": { "alias": "exporter"; "required": false; }; }, { "exportCompleted": "exportCompleted"; "exportStarted": "exportStarted"; }, never, never, true, never>;
}
declare class Mime {
extension: string;
contentTypeHeader: string;
constructor(extension: string, contentTypeHeader: string);
}
declare abstract class FileExporter<T extends Options> implements Exporter<T> {
constructor();
export(rows: Array<any>, options?: T): void;
abstract createContent(rows: Array<any>, options?: T): Promise<any>;
abstract getMimeType(): Mime;
}
declare class JsonExporterService extends FileExporter<Options> {
constructor();
createContent(rows: any[], options?: Options): Promise<any>;
getMimeType(): Mime;
static ɵfac: i0.ɵɵFactoryDeclaration<JsonExporterService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<JsonExporterService>;
}
declare class TxtExporterService extends FileExporter<TxtOptions> {
constructor();
createContent(rows: any[], options?: TxtOptions): Promise<any>;
getMimeType(): Mime;
private getDelimiter;
static ɵfac: i0.ɵɵFactoryDeclaration<TxtExporterService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<TxtExporterService>;
}
declare class SheetjsHelperService {
private xlsxLightweight;
constructor(xlsxLightweight: boolean);
getXlsx(): Promise<typeof XLSX>;
static ɵfac: i0.ɵɵFactoryDeclaration<SheetjsHelperService, [{ optional: true; }]>;
static ɵprov: i0.ɵɵInjectableDeclaration<SheetjsHelperService>;
}
/**
* An angular service class that is used to create files out of json object arrays.
*/
declare abstract class WorksheetExporter<T extends Options> extends FileExporter<T> {
protected sheetJsHelper: SheetjsHelperService;
constructor(sheetJsHelper: SheetjsHelperService);
createContent(rows: Array<any>, options?: T): Promise<any>;
abstract workSheetToContent(workSheet: WorkSheet, options?: T): Promise<any>;
abstract getMimeType(): Mime;
}
declare class XlsExporterService extends WorksheetExporter<ExcelOptions> {
constructor(sheetJsHelper: SheetjsHelperService);
workSheetToContent(worksheet: WorkSheet, options?: ExcelOptions): Promise<any>;
getMimeType(): Mime;
private correctTypes;
private convertToWch;
static ɵfac: i0.ɵɵFactoryDeclaration<XlsExporterService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<XlsExporterService>;
}
declare class XlsxExporterService extends XlsExporterService {
constructor(sheetJsHelper: SheetjsHelperService);
getMimeType(): Mime;
static ɵfac: i0.ɵɵFactoryDeclaration<XlsxExporterService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<XlsxExporterService>;
}
declare class CsvExporterService extends WorksheetExporter<TxtOptions> {
constructor(sheetJsHelper: SheetjsHelperService);
workSheetToContent(worksheet: WorkSheet, options?: TxtOptions): Promise<any>;
getMimeType(): Mime;
static ɵfac: i0.ɵɵFactoryDeclaration<CsvExporterService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<CsvExporterService>;
}
declare const MAT_TABLE_EXPORTER = "mat-table-exporter";
declare const TYPE_ARRAY = "array";
declare const CHAR_SET_UTF = ";charset=utf-";
declare const CHAR_SET_UTF_8: string;
declare const CONTENT_TYPE_TEXT: string;
declare const CONTENT_TYPE_APPLICATION = "application/";
declare const CONTENT_TYPE_EXCEL: string;
declare const DOT = ".";
declare const COMMA = ",";
declare const EXTENSION_XLS: string;
declare const EXTENSION_XLSX: string;
declare const EXTENSION_CSV: string;
declare const EXTENSION_JSON: string;
declare const EXTENSION_TEXT: string;
declare const MIME_EXCEL_XLS: Mime;
declare const MIME_EXCEL_XLSX: Mime;
declare const MIME_JSON: Mime;
declare const MIME_TXT: Mime;
declare const MIME_CSV: Mime;
declare const REF = "!ref";
declare const XLS_REGEX: string;
declare const RETURN = "\n";
declare const TAB = "\t";
declare const XLSX_COLS = "!cols";
declare const BOM = "\uFEFF";
declare const XLSX_LIGHTWEIGHT: InjectionToken<boolean>;
declare class FileUtil {
static save(content: string, mime: Mime, options?: Options): void;
static isXls(fileName: string): boolean;
static identifyExportType(fileName?: string): ExportType;
static removeExtension(options?: Options): void;
}
export { BOM, CHAR_SET_UTF, CHAR_SET_UTF_8, COMMA, CONTENT_TYPE_APPLICATION, CONTENT_TYPE_EXCEL, CONTENT_TYPE_TEXT, CdkTableExporter, CdkTableExporterModule, CsvExporterService, DOT, DataExtractorService, EXTENSION_CSV, EXTENSION_JSON, EXTENSION_TEXT, EXTENSION_XLS, EXTENSION_XLSX, ExportType, FileExporter, FileUtil, JsonExporterService, MAT_TABLE_EXPORTER, MIME_CSV, MIME_EXCEL_XLS, MIME_EXCEL_XLSX, MIME_JSON, MIME_TXT, Mime, REF, RETURN, ServiceLocatorService, TAB, TYPE_ARRAY, TxtExporterService, WorksheetExporter, XLSX_COLS, XLSX_LIGHTWEIGHT, XLS_REGEX, XlsExporterService, XlsxExporterService };
export type { ExcelOptions, Exporter, Options };