export class Formsmd { /** * Google reCAPTCHA attributes. * * @typedef {Object} RecaptchaType * @property {string} [siteKey] Google reCAPTCHA site key. * @property {string} [action] The action name. Default is `"submit"`. * @property {"bottomleft"|"bottomright"|"inline"} [badgePosition] The position of the reCAPTCHA badge. Default is `"bottomleft"`. * @property {boolean} [hideBadge] Whether to hide the reCAPTCHA badge. Default is `false`. */ /** * Theme for the page or form. * * @typedef {Object} ThemeType * @property {string} [accent] The primary color (must be HTML name, hex code, or RGB) used on buttons, form fields, etc. * @property {string} [accentForeground] The text color (must be HTML name, hex code, or RGB) used on `accent` background, for example, the text on buttons. * @property {string} [backgroundColor] The `background-color` of the page (must be HTML name, hex code, or RGB). * @property {string} [color] The `color` of the text on the page (must be HTML name, hex code, or RGB). */ /** * Options for the page or form. * * @typedef {Object} OptionsType * @property {"light"|"dark"} [colorScheme] The default or initial color scheme of the page. Default is `"light"`. * @property {string} [errorFieldKey] The key used to identify the field in error objects. Default is `"field"`. * @property {string} [errorMessageKey] The key used to identify the error message in error objects. Default is `"message"`. * @property {"hide"|"show"} [footer] Controls visibility of the footer. * @property {"hide"|"show"} [formsmdBranding] Controls visibility of the Forms.md branding. * @property {Object} [getHeaders] Headers for GET requests. * @property {boolean} [isFullPage] Whether to render in full page mode. Default is `false`. * @property {number} [paddingInlineBottom] Padding bottom for inline pages or forms. Default is `20`. * @property {number} [paddingInlineHorizontal] Horizontal padding for inline pages or forms. Default is `0`. * @property {number} [paddingInlineTop] Padding top for inline pages or forms. Default is `20`. * @property {"hide"|"show"|"decorative"} [pageProgress] Controls visibility and function of the page progress. * @property {Object} [postData] Extra data sent with POST requests. * @property {Object} [postHeaders] Headers for POST requests. * @property {boolean} [prioritizeURLFormData] Whether to prioritize URL form data. Default is `false`. * @property {RecaptchaType} [recaptcha] The Google reCAPTCHA attributes. * @property {boolean} [sanitize] Whether to sanitize template. Default is `true`. * @property {boolean} [saveState] Whether to save form data in local storage. Default is `true`. * @property {boolean} [sendFilesAsBase64] Whether to send files as base64. Default is `false`. * @property {boolean} [setColorSchemeAttrsAgain] Whether to set color scheme attributes again. * @property {"hide"|"show"} [slideControls] Controls visibility of next and previous buttons. * @property {number} [startSlide] The index of the first slide to make active. Default is `0`. * @property {ThemeType} [themeDark] Dark theme. * @property {ThemeType} [themeLight] Light theme. */ /** * Create an instance of the class. * * @param {string} template * @param {Document|HTMLElement|Element} container * @param {OptionsType} options */ constructor( template: string, container: Document | HTMLElement | Element, options: { /** * The default or initial color scheme of the page. Default is `"light"`. */ colorScheme?: "light" | "dark"; /** * The key used to identify the field in error objects. Default is `"field"`. */ errorFieldKey?: string; /** * The key used to identify the error message in error objects. Default is `"message"`. */ errorMessageKey?: string; /** * Controls visibility of the footer. */ footer?: "hide" | "show"; /** * Controls visibility of the Forms.md branding. */ formsmdBranding?: "hide" | "show"; /** * Headers for GET requests. */ getHeaders?: any; /** * Whether to render in full page mode. Default is `false`. */ isFullPage?: boolean; /** * Padding bottom for inline pages or forms. Default is `20`. */ paddingInlineBottom?: number; /** * Horizontal padding for inline pages or forms. Default is `0`. */ paddingInlineHorizontal?: number; /** * Padding top for inline pages or forms. Default is `20`. */ paddingInlineTop?: number; /** * Controls visibility and function of the page progress. */ pageProgress?: "hide" | "show" | "decorative"; /** * Extra data sent with POST requests. */ postData?: any; /** * Headers for POST requests. */ postHeaders?: any; /** * Whether to prioritize URL form data. Default is `false`. */ prioritizeURLFormData?: boolean; /** * The Google reCAPTCHA attributes. */ recaptcha?: { /** * Google reCAPTCHA site key. */ siteKey?: string; /** * The action name. Default is `"submit"`. */ action?: string; /** * The position of the reCAPTCHA badge. Default is `"bottomleft"`. */ badgePosition?: "bottomleft" | "bottomright" | "inline"; /** * Whether to hide the reCAPTCHA badge. Default is `false`. */ hideBadge?: boolean; }; /** * Whether to sanitize template. Default is `true`. */ sanitize?: boolean; /** * Whether to save form data in local storage. Default is `true`. */ saveState?: boolean; /** * Whether to send files as base64. Default is `false`. */ sendFilesAsBase64?: boolean; /** * Whether to set color scheme attributes again. */ setColorSchemeAttrsAgain?: boolean; /** * Controls visibility of next and previous buttons. */ slideControls?: "hide" | "show"; /** * The index of the first slide to make active. Default is `0`. */ startSlide?: number; /** * Dark theme. */ themeDark?: { /** * The primary color (must be HTML name, hex code, or RGB) used on buttons, form fields, etc. */ accent?: string; /** * The text color (must be HTML name, hex code, or RGB) used on `accent` background, for example, the text on buttons. */ accentForeground?: string; /** * The `background-color` of the page (must be HTML name, hex code, or RGB). */ backgroundColor?: string; /** * The `color` of the text on the page (must be HTML name, hex code, or RGB). */ color?: string; }; /** * Light theme. */ themeLight?: { /** * The primary color (must be HTML name, hex code, or RGB) used on buttons, form fields, etc. */ accent?: string; /** * The text color (must be HTML name, hex code, or RGB) used on `accent` background, for example, the text on buttons. */ accentForeground?: string; /** * The `background-color` of the page (must be HTML name, hex code, or RGB). */ backgroundColor?: string; /** * The `color` of the text on the page (must be HTML name, hex code, or RGB). */ color?: string; }; }, ); options: { colorScheme: string; errorFieldKey: string; errorMessageKey: string; footer: string; formsmdBranding: string; getHeaders: {}; isFullPage: boolean; paddingInlineBottom: number; paddingInlineHorizontal: number; paddingInlineTop: number; pageProgress: string; postData: {}; postHeaders: {}; prioritizeURLFormData: boolean; recaptcha: { siteKey: string; action: string; badgePosition: string; hideBadge: boolean; }; sanitize: boolean; saveState: boolean; sendFilesAsBase64: boolean; setColorSchemeAttrsAgain: boolean; slideControls: string; startSlide: number; themeDark: { accent: string; accentForeground: string; backgroundColor: string; color: string; }; themeLight: { accent: string; accentForeground: string; backgroundColor: string; color: string; }; }; container: Element | Document | HTMLElement; _template: string; /** * Set the state to defaults. */ setStateToDefaults: () => void; state: { bindDivTemplates: {}; data: {}; fieldTypes: {}; formData: {}; settings: any; slideData: { currentIndex: number; }; }; /** * Add a single attribute value to an HTML element. * * @param {HTMLElement} elem * @param {string} name * @param {string} value */ setSingleAttribute: (elem: HTMLElement, name: string, value: string) => void; /** * Remove a single attribute value from an HTML element. * * @param {HTMLElement} elem * @param {string} name * @param {string} value */ removeSingleAttribute: ( elem: HTMLElement, name: string, value: string, ) => void; /** * Get the prefix for the page/form id. * * @returns {string} */ getIdPrefix: () => string; /** * Set the preferred color scheme (if one is found in the local storage). * Depending on the preference from settings, either the domain-wide or the * page-specific value is used. */ setPreferredColorScheme: () => void; /** * Toggle color scheme. If the preferred color scheme (from settings) is set * to "isolate", the preference is saved (and used) only for that page. * Otherwise, it is saved (and used) domain-wide. * * @param {MouseEvent} e */ toggleColorScheme: (e: MouseEvent) => void; /** * Create a random 32 characters id separated by dashes. * * @returns {string} */ createRandomId: () => string; /** * Get or create response id. This uniquely identifies one single form * response. The id is created on initialization (unless one already * exists), and it is removed when the user reaches the end slide. * * @returns {string} */ getOrCreateResponseId: () => string; /** * Remove response id. This is called when the user reaches the end slide. */ removeResponseId: () => void; /** * Save form field value in local storage. * * @param {string} name * @param {*} value */ saveFieldValue: (name: string, value: any) => void; /** * Remove form data from local storage. This is called when the user reaches * the end slide. */ removeSavedFormData: () => void; /** * Re-render the bind
and elements. * * @param {string} name */ reRenderBindElems: (name: string) => void; /** * Get value of a set of radio buttons or checkboxes. * * @param {string} name * @param {string} inputClass * @param {"radio"|"checkbox"} type * @returns {string|Array.} */ getRadioCheckboxValue: ( name: string, inputClass: string, type: "radio" | "checkbox", ) => string | Array; /** * Set value of a set of radio buttons or checkboxes. * * @param {string} name * @param {string} inputClass * @param {"radio"|"checkbox"} type * @param {string|Array.} value */ setRadioCheckboxValue: ( name: string, inputClass: string, type: "radio" | "checkbox", value: string | Array, ) => void; /** * Given a country calling code