@c8y/ngx-components
Version:
Angular modules for Cumulocity IoT applications
114 lines (108 loc) • 4.9 kB
TypeScript
import * as i0 from '@angular/core';
import { OnInit, OnDestroy, TemplateRef } from '@angular/core';
import { FilesService, AlertService, AppStateService, OnBeforeSave } from '@c8y/ngx-components';
import { FormGroup, FormControl, FormBuilder, NgForm } from '@angular/forms';
import { InventoryService, InventoryBinaryService, FetchClient } from '@c8y/client';
import { TranslateService } from '@ngx-translate/core';
import { BehaviorSubject } from 'rxjs';
interface MarkdownWidgetConfig {
markdownBinaryId: string | null;
contentUrl: string | null;
markdownContent: string | null;
}
declare const MarkdownSourceType: {
readonly WRITE: "writeMarkdown";
readonly UPLOAD: "uploadBinary";
readonly URL: "uploadUrl";
};
type MarkdownSourceType = (typeof MarkdownSourceType)[keyof typeof MarkdownSourceType];
interface DroppedFileItem {
file: File;
name: string;
}
type MarkdownWidgetFormGroup = FormGroup<{
contentUrl: FormControl<string>;
droppedFile: FormControl<DroppedFileItem[] | null>;
uploadChoice: FormControl<MarkdownSourceType>;
}>;
declare class MarkdownWidgetService {
private fileService;
private inventory;
private binary;
private alert;
private translate;
private fetchClient;
private appStateService;
private readonly headers;
constructor(fileService: FilesService, inventory: InventoryService, binary: InventoryBinaryService, alert: AlertService, translate: TranslateService, fetchClient: FetchClient, appStateService: AppStateService);
/**
* Retrieves a markdown file from the inventory by its binary ID.
* @param markdownBinaryId - The ID of the binary managed object.
* @returns The file if found, otherwise null.
*/
getFile(markdownBinaryId: string | null): Promise<File>;
/**
* Uploads a markdown file to the inventory as a binary.
* @param file - The file to upload.
* @returns The ID of the created binary managed object.
*/
uploadFile(file: File): Promise<string>;
/**
* Fetches markdown content from a URL.
* For internal URLs (e.g., `/readme.md`), uses FetchClient with the app's context path.
* For external URLs, uses XMLHttpRequest to avoid CORS issues with auth headers.
* @param url - The URL to fetch content from.
* @returns The markdown content as a string, or empty string on error.
*/
getContentFromUrl(url: string): Promise<string>;
private getContentFromInternalUrl;
private getContentFromExternalUrl;
static ɵfac: i0.ɵɵFactoryDeclaration<MarkdownWidgetService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<MarkdownWidgetService>;
}
declare class MarkdownWidgetConfigComponent implements OnInit, OnDestroy, OnBeforeSave {
private formBuilder;
private form;
private alert;
private markdownService;
config: MarkdownWidgetConfig;
set markdownPreviewTemplate(template: TemplateRef<any>);
readonly MarkdownSourceType: {
readonly WRITE: "writeMarkdown";
readonly UPLOAD: "uploadBinary";
readonly URL: "uploadUrl";
};
formGroup: MarkdownWidgetFormGroup;
fileFromConfig: File;
uploadChoice: MarkdownSourceType;
previewMarkdown$: BehaviorSubject<string>;
editorContent: string;
private widgetConfigService;
private destroy$;
constructor(formBuilder: FormBuilder, form: NgForm, alert: AlertService, markdownService: MarkdownWidgetService);
onBeforeSave(config?: MarkdownWidgetConfig): Promise<boolean>;
ngOnInit(): Promise<void>;
ngOnDestroy(): void;
onChange(value: MarkdownSourceType): void;
onEditorChange(content: string): void;
private updatePreview;
private updatePreviewFromFile;
private getFileFromFormValue;
private initForm;
private requireValidSource;
private clearRequiredError;
static ɵfac: i0.ɵɵFactoryDeclaration<MarkdownWidgetConfigComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<MarkdownWidgetConfigComponent, "c8y-markdown-widget-config", never, { "config": { "alias": "config"; "required": false; }; }, {}, never, never, true, never>;
}
declare class MarkdownWidgetViewComponent implements OnInit {
private markdownWidgetService;
config: MarkdownWidgetConfig;
markdown: string;
constructor(markdownWidgetService: MarkdownWidgetService);
ngOnInit(): Promise<void>;
static ɵfac: i0.ɵɵFactoryDeclaration<MarkdownWidgetViewComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<MarkdownWidgetViewComponent, "c8y-markdown-widget-view", never, { "config": { "alias": "config"; "required": false; }; }, {}, never, never, true, never>;
}
export { MarkdownSourceType, MarkdownWidgetConfigComponent, MarkdownWidgetService, MarkdownWidgetViewComponent };
export type { DroppedFileItem, MarkdownWidgetConfig, MarkdownWidgetFormGroup };
//# sourceMappingURL=index.d.ts.map