ngx-link-preview
Version:
The Open Graph link preview component for Angular 6+
111 lines (110 loc) • 5.29 kB
TypeScript
import { EventEmitter, OnChanges, OnDestroy, SimpleChanges } from '@angular/core';
import { OpenGraphMetaData } from '../../interfaces/open-graph-meta-data';
import { NgxLinkPreviewCacheService } from '../../services/ngx-link-preview-cache.service';
import { Observable } from 'rxjs';
import { DomSanitizer } from '@angular/platform-browser';
import * as i0 from "@angular/core";
type HtmlLinkTarget = '_blank' | '_self' | '_parent' | '_top' | FrameName;
type FrameName = string;
export declare class NgxLinkPreviewComponent implements OnChanges, OnDestroy {
private sanitizer;
private cacheSvc;
/** Plain links string array */
links: string[];
/** Input string to parse for links */
parseForLinksStr: string;
/** Method that does the API request, provide as class member arrow function from parent */
getApiEndpoint$: (requestUrl: string) => Observable<any>;
/** API route where to get the meta data from, component will build the full request url
* Schema: api.example.com/api/get-meta-data?url=d3d3LmV4YW1wbGUuY29t
*/
apiRoute: string;
/** Target url will be attached as encodeURI(btoa(url)), so it must be decoded on the server */
queryParamName: string;
/** boolean: show image in preview */
showImage: boolean;
/** boolean: show site name in preview */
showSiteName: boolean;
/** boolean: show title in preview */
showTitle: boolean;
/** boolean: show description in preview */
showDescription: boolean;
/** boolean: show link url in preview */
showLinkUrl: boolean;
/** boolean: use cache to display previews faster on next rendering */
useCache: boolean;
/** number: max age the data cache of a link preview should be used */
maxCacheAgeMs: number;
/** boolean: show loading indicator */
showLoadingIndicator: boolean;
/**
* boolean: whether the <a href="..."></a> link should be clickable.
* This is a question of context security. Otherwise use (previewClick) event.
*/
useHtmlLinkDefaultClickEvent: boolean;
/**
* HtmlLinkTarget: where the HTML link should be opened on click.
* Only has an effect if [useHtmlLinkDefaultClickEvent]="true"
*/
htmlLinkTarget: HtmlLinkTarget;
/** Event emitter: on click to handle the click event, emits the clicked URL */
previewClicked: EventEmitter<string>;
/** Scanned links[] from @Input() links & @Input() parseForLinks */
private scannedLinks;
/** Array of metadata objects where the preview is rendered from */
previews: OpenGraphMetaData[];
private loadingMgr;
loadingSpinner: import("@angular/platform-browser").SafeHtml;
showLoadingSpinner: boolean;
private subscriptions;
constructor(sanitizer: DomSanitizer, cacheSvc: NgxLinkPreviewCacheService);
ngOnDestroy(): void;
/**
* Preview will be refreshed every time a change is recognized
*/
ngOnChanges(changes: SimpleChanges): void;
/**
* Subscribe to loading manager has jobs stream
*/
private subscribeLoadingMgrHasJobs;
/**
* Unsubscribe all subscriptions
*/
private unsubscribeAll;
/**
* Init preview
*/
private init;
/**
* Load cache or get from api
*/
private loadCacheOrGet;
/**
* Check if cache item is outdated by max-cache-age
*/
private isCacheOutdated;
/**
* On link click emit to EventEmitter
*/
onLinkClick(url: string): void;
disableDefaultLink(event: MouseEvent): void;
/**
* Encode string url safe
*/
private encodeUrlSafe;
/**
* Check required input parameters
*/
private checkInputParameters;
/**
* Parse string for links
*/
private parseStringForLinks;
/**
* Get sanitized image url due data often contains url errors
*/
getSanitizedImageUrl(p: OpenGraphMetaData): string;
static ɵfac: i0.ɵɵFactoryDeclaration<NgxLinkPreviewComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<NgxLinkPreviewComponent, "ngx-link-preview", never, { "links": { "alias": "links"; "required": false; }; "parseForLinksStr": { "alias": "parseForLinksStr"; "required": false; }; "getApiEndpoint$": { "alias": "getApiEndpoint$"; "required": false; }; "apiRoute": { "alias": "apiRoute"; "required": false; }; "queryParamName": { "alias": "queryParamName"; "required": false; }; "showImage": { "alias": "showImage"; "required": false; }; "showSiteName": { "alias": "showSiteName"; "required": false; }; "showTitle": { "alias": "showTitle"; "required": false; }; "showDescription": { "alias": "showDescription"; "required": false; }; "showLinkUrl": { "alias": "showLinkUrl"; "required": false; }; "useCache": { "alias": "useCache"; "required": false; }; "maxCacheAgeMs": { "alias": "maxCacheAgeMs"; "required": false; }; "showLoadingIndicator": { "alias": "showLoadingIndicator"; "required": false; }; "useHtmlLinkDefaultClickEvent": { "alias": "useHtmlLinkDefaultClickEvent"; "required": false; }; "htmlLinkTarget": { "alias": "htmlLinkTarget"; "required": false; }; }, { "previewClicked": "previewClicked"; }, never, ["*"], false, never>;
}
export {};