import { default as AnalyticsApi } from '../../api/AnalyticsApi'; import { default as WidgetApi } from '../../api/WidgetApi'; import { DeclarativeConfigOptions } from '../../types'; import { default as EmbedWidget } from '../EmbedWidget'; import { default as PopupWidget } from '../PopupWidget'; /** * Abstract class for building web-components that render SaaSquatch widgets to the DOM * @abstract * @example * class TestWidgetElement extends DeclarativeWidget {} * const testWidget = new TestWidgetElement() * testWidget.widgetType = 'w/widget-type' * testWidget.type = 'EMBED' * testWidget.renderWidget() */ export default abstract class DeclarativeWidget extends HTMLElement { /** * Configuration overrides * @default window.squatchConfig */ config: DeclarativeConfigOptions | undefined; /** * Signed JWT containing user information * @default window.squatchToken */ token: string | undefined; /** * Tenant alias of SaaSquatch tenant * @default window.squatchTenant */ tenant: string | undefined; /** * widgetType of widget to load */ widgetType: string | undefined; /** * Locale to render the widget in */ locale: string | undefined; /** * Instance of {@link WidgetApi} */ widgetApi: WidgetApi; /** * Instance of {@link AnalyticsApi} */ analyticsApi: AnalyticsApi; /** * Instance of {@link EmbedWidget} or {@link PopupWidget} */ widgetInstance: EmbedWidget | PopupWidget; /** * Determines whether to render the widget as an embedding widget or popup widget */ type: "EMBED" | "POPUP"; /** * Container element to contain the widget iframe * @default this */ container: string | HTMLElement | undefined | null; element: HTMLElement | undefined; /** * Flag for if the component has been loaded or not * @hidden */ loaded: boolean; constructor(); private _setupApis; private renderPasswordlessVariant; private renderUserUpsertVariant; private _setWidget; /** * Fetches widget content from SaaSquatch and builds a Widget instance to support rendering the widget in the DOM * @returns Instance of either {@link EmbedWidget} or {@link PopupWidget} depending on `this.type` * @throws Throws an Error if `widgetType` is undefined */ getWidgetInstance(): Promise; /** * Calls {@link getWidgetInstance} to build the Widget instance and loads the widget iframe into the DOM */ renderWidget(): Promise; /** * Builds a Widget instance for the default error widget * @returns Instance of either {@link EmbedWidget} or {@link PopupWidget} depending on `this.type` */ setErrorWidget: (e: Error) => EmbedWidget | PopupWidget; /** * Calls `open` method of `widgetInstance` * @throws Throws an Error if called before the widget has loaded */ open(): void; /** * Calls `close` method of `widgetInstance` * @throws Throws an Error if called before the widget has loaded */ close(): void; reload: () => Promise; show: () => void; hide: () => void; }