import * as i0 from '@angular/core'; import { EventEmitter, ElementRef } from '@angular/core'; import { SafeUrl, DomSanitizer } from '@angular/platform-browser'; import * as i2 from '@angular/common'; interface FileHandle { file: File; url: SafeUrl; } interface DragHandle { files: FileHandle[]; evt: DragEvent; } declare class DragAndDropDirective { private readonly sanitizer; private readonly elementRef; /** * Change background color */ background: string; /** * highlight when drag over */ highlightColor: i0.InputSignal; /** * leave color */ leaveColor: i0.InputSignal; /** * Emit DragHandle class object */ files: EventEmitter; constructor(sanitizer: DomSanitizer, elementRef: ElementRef); onMouseEnter(): void; onMouseLeave(): void; private highlight; onDragOver(evt: DragEvent): void; onDragLeave(evt: DragEvent): void; onDrop(evt: DragEvent): void; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵdir: i0.ɵɵDirectiveDeclaration; } declare class FilesModule { static ɵfac: i0.ɵɵFactoryDeclaration; static ɵmod: i0.ɵɵNgModuleDeclaration; static ɵinj: i0.ɵɵInjectorDeclaration; } type TextType = 'text/css' | 'text/csv' | 'text/json' | 'text/html' | 'text/javascript' | 'application/javascript' | 'application/json' | 'text/plain' | 'text/html' | 'image/svg+xml' | 'text/*'; declare class OblFileService { private readonly document; constructor(document: Document); readTextFile(): Promise; readFileAsDataUrl(): Promise; readFileAsArrayBuffer(): Promise; loadJsonFile(url: string): Promise; /** * Let you save text file on user device * @param text - text to save * @param textType - default text/plain */ saveTextFile(text: string, fileName: string, textType?: TextType): void; /** * Svg save file * @param svgContent * @param fileName */ saveSvgFile(svgContent: string, fileName: string): void; /** * saving blob file */ saveBlobFile(blob: Blob, fileName: string): void; /** * Create HTMLImageElement with loaded image as Promise */ getImageFromUrl(url: string): Promise; /** * Reading file from user device * @param type - file type * @returns file */ protected readFile(type: 'text' | 'DataURL' | 'ArrayBuffer'): Promise; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } type SystemResourceType = 'file' | 'folder'; interface SystemResource { type: SystemResourceType; path: string; name: string; data?: Object; appName?: string; x: number; y: number; } declare class JsonFileSystemService { /** * Maximum size of file as json string */ protected maxSize: number; /** * field name */ protected readonly resourcesField = "systemResources"; /** * Table of folders/files recovered from localeStorage */ systemResources: SystemResource[]; constructor(); /** * Saving to localStorage */ protected save(): void; /** * Check if resource can be added * @param name name of resource file or folder * @param path path to resource * @param type type of resource: {@link SystemResourceType} * @param data data storage in resource required for files * @returns true if can be added, false if can't */ checkResource(name: string, path?: string, type?: SystemResourceType, data?: Object): boolean; /** * Adding folder resource and update localStorage * @param name name of folder * @param path path to folder that contains resource * @param params external params * @returns true if added, or false fail */ addFolder(name: string, path?: string, params?: { x?: number; y?: number; }): boolean; /** * Adding the file to system and update localStorage * @param name name of file * @param data required data of file * @param appName name of app that will open this file * @param path path to folder * @param params optional parameters * @returns true if added, false other way */ addFile(name: string, data: Object, appName: string, path?: string, params?: { x?: number; y?: number; }): boolean; /** * Return all resources in chosen path * @param path path to resources folder * @returns return resources storage in folder */ getResources(path?: string): SystemResource[]; /** * Return folder from specific path */ getFolder(path: string): false | SystemResource; /** * Check if resource can be updated and if so update it * @param resource resource to update */ update(resource: SystemResource, newName?: string): void; /** * Check if folder path exist */ pathFolderExist(path: string): boolean; /** * Delete */ delete(resource: SystemResource, saving?: boolean): void; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } declare class Csv { hasHeaders: boolean; separator: string; /** * Static constructor that create Csv object from array * @param array array to convert to Csv object * @returns Csv object */ static fromArray(array: (number | string | { [key: string]: any; })[][], headers?: (number | string)[]): Csv; /** * Map object of columns containing array of values. * * By default system is parsing values to number or live as string. You can use columnParse field * to parse to any type you wanted (data, pare by JSON, or any other object) */ table: Map; /** * errors to throw: * columns - if true throw error if number of columns is not equal in every row * headerNotAString - throw error when one of headers fields is not a string * empty - throw error when file contain empty string * columnParse - error when column contain improper format * * @example * * const file = await this.file.readTextFile(); * * const csv = new Csv(); * * csv.throwing.columnsParse['age'] = (value: string) => { * if (!ElementaryMath.isNumeric(value, true)) { * throw new Error(`Some value in "col 2" is not a number: "${value}"`); * } * }; * * csv.throwing.columnsParse['zip'] = (value: string) => { * if (!ElementaryMath.isNumeric(value, true)) { * throw new Error(`Some value in "zip" is not a number: "${value}"`); * } * * if (!/^[0-9]{5,5}$/.test(value)) { * throw new Error(`Some value in "zip" have not 5 digits: "${value}"`); * } * } * * csv.parse(file, true); * * console.log(csv.table); */ throwing: { columns?: boolean; headerNotAString?: boolean; empty?: boolean; columnsParse: { [key: string]: ((value: string) => void); }; }; /** * let you parse column however you want by adding key name corresponding to column name and parsing function * * @example * * const file = await this.file.readTextFile(); * * const csv = new Csv(); * * csv.columnsParse['zip'] = (value: string) => value.substring(0, 2) + '-' + value.substring(2); * csv.columnsParse['date'] = (value: string) => new Date(value); * * csv.parse(file, true); * * console.log(csv.table); */ columnsParse: { [key: string | number]: ((value: string) => any); }; /** * let you prepare column to export to CSV clear format by using key name of column with method * that revers parsing method * * WARNING! If you use columnsParse you probably want to use this one as reverse process to CSV */ columnsPrepare: { [key: string | number]: ((value: any) => string); }; /** * Default so call do nothing parsing string global method to override * * You can use parsing string static method from @obliczeniowo/elementary/parse call ParseString * or use totally own one * * @value - parsed string value */ parseString: (value: string) => string; /** * Reverse method of parseString used to export back to CSV */ prepareString: (value: any) => string; constructor(hasHeaders?: boolean, separator?: string); headers(): (string | number)[]; getRawRow(index: number): (string | number | any)[]; getJsonRow(index: number): { [key: string]: (string | number | any); }; getColumn(name: string): T; parse(csvText: string, hasColumns?: boolean, separator?: string): void; prepare(): string; toJson(): { [key: string]: string; }[]; } export { Csv, DragAndDropDirective, FilesModule, JsonFileSystemService, OblFileService }; export type { DragHandle, FileHandle, SystemResource, SystemResourceType, TextType };