UNPKG

@xapp/chat-widget

Version:
66 lines (65 loc) 2.48 kB
import 'rollup-plugin-inject-process-env'; /*! Copyright (c) 2024, XAPPmedia */ /** * Options that can be passed when opening the form widget */ export interface OpenFormOptions { /** * Label of a chip to auto-select after the form loads. * If the first step of the form contains chips, the form will * automatically click the chip matching this label. */ preselectChipLabel?: string; } declare global { interface Window { xafwControl?: { openForm: (options?: OpenFormOptions) => void; formStatus: string; }; } } /** * Builds the form-widget script URL with the provided key */ export declare function getFormWidgetScriptUrl(key: string): string; /** * Checks if the form-widget script is already loaded on the page. * Checks both by ID and by src URL to handle various installation methods. */ export declare function isFormWidgetScriptLoaded(key?: string): boolean; /** * Injects the form-widget script into the page with retry logic. * Returns a promise that resolves when the script is loaded. * Does nothing if the script is already loaded. * * @param key The form widget key * @param maxRetries Maximum number of retry attempts (default: 3) * @param retryDelayMs Delay between retries in milliseconds (default: 1000) */ export declare function loadFormWidgetScript(key: string, maxRetries?: number, retryDelayMs?: number): Promise<void>; /** * Pre-loads the form-widget script if a key is provided. * This is a fire-and-forget operation - errors are logged but not thrown. */ export declare function preloadFormWidgetScript(key?: string): void; /** * Checks if the form-widget control API is available */ export declare function isFormWidgetReady(): boolean; /** * Opens the form widget if it's available. * Returns true if the form was opened, false otherwise. * * @param options Optional configuration for opening the form */ export declare function openFormWidget(options?: OpenFormOptions): boolean; /** * Attempts to open the form widget, waiting for it to be ready if necessary. * Useful when the script is still loading. * * @param options Optional configuration for opening the form * @param maxAttempts Maximum number of attempts to check for readiness * @param intervalMs Time between attempts in milliseconds */ export declare function openFormWidgetWhenReady(options?: OpenFormOptions, maxAttempts?: number, intervalMs?: number): Promise<boolean>;