import * as actions from './actions'; import { PiralPlugin } from 'piral-core'; import { withForm } from './withForm'; import { withFormHandler } from './withFormHandler'; import type { PiletFormsApi } from './types'; /** * Available configuration options for the forms plugin. */ export interface FormsConfig {} /** * Creates new Pilet API extensions for enhancing forms. */ export function createFormsApi(config: FormsConfig = {}): PiralPlugin { return (context) => { context.defineActions(actions); context.dispatch((state) => ({ ...state, forms: {}, })); return { createForm(options) { return (component, config) => { const hoc = config?.skipForm ? withFormHandler : withForm; return hoc(component, options); }; }, }; }; }