import { forms } from '@wix/forms'; import { type ReadOnlySignal } from '@wix/services-definitions/core-services/signals'; import { FormValues } from '../react/types.js'; import { type SiteConfig } from './utils/index.js'; /** * Response type for form submission operations. * Represents the different states a form submission can be in. */ export type SubmitResponse = { type: 'success'; message?: string; } | { type: 'error'; message: string; } | { type: 'idle'; } | { type: 'loading'; }; /** * API interface for the Form service, providing reactive form data management. * This service handles loading and managing form data, loading state, errors, and submissions. * It supports both pre-loaded form data and lazy loading with form IDs. * * @interface FormServiceAPI */ export interface FormServiceAPI { /** Reactive signal containing the current form data */ formSignal: ReadOnlySignal; /** Reactive signal containing the address templates */ addressTemplatesSignal: ReadOnlySignal; /** Reactive signal containing the site configuration */ siteConfigSignal: ReadOnlySignal; /** Reactive signal indicating if a form is currently being loaded */ isLoadingSignal: ReadOnlySignal; /** Reactive signal containing any error message, or null if no error */ errorSignal: ReadOnlySignal; /** Reactive signal containing submission response state */ submitResponseSignal: ReadOnlySignal; /** Reactive signal that contains all actual formValues */ formValuesSignal: ReadOnlySignal; /** Function to submit form with current values */ submitForm: () => Promise; /** Function to handle changed form with new values */ handleForm: (formValues: FormValues) => Promise; } /** * Service definition for the Form service. * This defines the contract that the FormService must implement. * * @constant */ export declare const FormServiceDefinition: string & { __api: FormServiceAPI; __config: {}; isServiceDefinition?: boolean; } & FormServiceAPI; type OnSubmit = (formId: string, formValues: FormValues) => Promise; /** * Configuration type for the Form service. * Supports two distinct patterns for providing form data: * - Pre-loaded form data (SSR/SSG scenarios) * - Lazy loading with form ID (client-side routing) * * Optionally accepts a custom submission handler to override default behavior. * * @type {FormServiceConfig} */ export type FormServiceConfig = { formId: string; onSubmit?: OnSubmit; namespace?: string; additionalMetadata?: Record; } | { form: forms.Form; onSubmit?: OnSubmit; addressTemplates?: any[]; siteConfig?: SiteConfig; }; /** * Implementation of the Form service that manages reactive form data and submissions. * This service provides signals for form data, loading state, error handling, and submission state. * It supports both pre-loaded form data and lazy loading with form IDs. * Consumers can provide a custom submission handler via config. * * @example * ```tsx * // Pre-loaded form data (SSR/SSG) * const formService = FormService.withConfig({ form: formData }); * * // Lazy loading with form ID (client-side) * const formService = FormService.withConfig({ formId: 'form-123' }); * * // With custom submission handler * const formService = FormService.withConfig({ * formId: 'form-123', * onSubmit: async (formId, formValues) => { * // Custom submission logic * await fetch('/api/submit', { method: 'POST', body: JSON.stringify({ formId, ...formValues }) }); * return { type: 'success', message: 'Form submitted!' }; * } * }); * ``` */ export declare const FormService: import("@wix/services-definitions").ServiceFactory; /** * Loads form service configuration from the Wix Forms API for SSR initialization. * This function is designed to be used during Server-Side Rendering (SSR) to preload * a specific form by ID that will be used to configure the FormService. * * @param {string} formId - The unique identifier of the form to load * @param {string} [namespace] - Optional namespace for the form * @param {Record} [additionalMetadata] - Optional additional metadata to pass to the API * @returns {Promise} Configuration object with pre-loaded form data * @throws {Error} When the form cannot be loaded * * @example * ```tsx * // In your SSR/SSG setup * const formConfig = await loadFormServiceConfig('form-123'); * const formService = FormService.withConfig(formConfig); * ``` */ export declare function loadFormServiceConfig(formId: string, namespace?: string, additionalMetadata?: Record): Promise; export {};