{"filename":"react-formengine-ai-form-builder-cursorrules-prompt-file.mdc","content":"---\ndescription: \"Cursor rules for generating React forms from screenshots, PDFs, HTML, or text descriptions with validated FormEngine JSON schema. Renders through RSuite, Material UI, or Mantine.\"\nglobs: **/*\nalwaysApply: false\n---\n# FormEngine — AI Form Builder for React\n\nGenerate production-ready React forms from a screenshot, PDF, HTML, or\ntext description. The output is a validated FormEngine JSON schema plus\na runnable App.tsx — portable data, not throwaway JSX.\n\nDefault target: FormEngine Core (MIT, free) via `@react-form-builder/core`\n+ `@react-form-builder/components-rsuite` (or Material UI / Mantine).\n\nSource repo: https://github.com/lukinov/ai-form-builder\n\n## What you produce — every time\n\n1. `form.json` — a normalized FormEngine schema, validated against the\n   real list of component types from the target UI library.\n2. `App.tsx` — a runnable React file that imports the schema and renders\n   it through `<FormViewer>`.\n3. A short validation report (Screen root, unique keys, layout-only\n   `css`, no smuggled HTML markup, valid validation rule keys).\n4. Install command + a link to the free Online FormBuilder\n   (https://formbuilder.formengine.io) so the user can tweak visually.\n\n## Hard rules — never violate\n\n### Schema invariants\n\n- Root is `type: \"Screen\"` (NOT `\"Form\"`).\n- Every component node has `key` (unique within the tree), `type` (must\n  exist in the chosen library), and usually `props`.\n- **Every prop value is wrapped:** `\"label\": { \"value\": \"Email\" }` —\n  never `\"label\": \"Email\"`.\n- Validations live under `schema.validations` on the field component\n  that owns the data — never on the Screen root.\n- Use the correct tooltip/error types:\n  - RSuite: `RsTooltip` / `RsErrorMessage`\n  - MUI: `MuiTooltip` / `MuiErrorWrapper`\n  - Mantine: `MtTooltip` / `MtErrorWrapper`\n\n### Layout vs. styling\n\n- `css` and `wrapperCss` are **layout-only** — flex, grid, box-model,\n  margin, padding, gap, width/height, alignment. **Never** color, font,\n  background, border, shadow, radius, opacity, transform.\n- Visual styling belongs in the UI library's theme provider in\n  `App.tsx` (`<CustomProvider>` / `<ThemeProvider>` / `<MantineProvider>`).\n- The legacy `style` field is **forbidden** — use `css` / `wrapperCss`.\n- The shape is `{ \"any\": { \"object\": { \"<layout-key>\": \"<value>\" } } }`,\n  never a plain CSS string.\n- No companion `.css` file alongside `App.tsx`. No root `className`. No\n  `<style>` blocks. No `styled-components`.\n\n### Plain-text strings only\n\nEvery string inside any prop is plain text. **No HTML markup of any\nkind**, anywhere — no `<h1>`, `<p>`, `<strong>`, `<small>`, `<br>`, no\n`style=\"...\"`, no `class=\"...\"`, no `<style>` block. Express section\nheadings and structure with components (`RsCard` with `header` prop,\n`RsHeader`, `RsDivider`) — not embedded HTML.\n\n### Validation rule keys — Zod set only\n\nValid keys: `required`, `nonEmpty`, `min`, `max`, `length`, `email`,\n`url`, `uuid`, `ip`, `datetime`, `regex`, `includes`, `startsWith`,\n`endsWith`, `lessThan`, `moreThan`, `integer`, `multipleOf`, `truthy`,\n`falsy`. There is **no `minLength` / `maxLength`** — use `min` / `max`\nwith `args.limit`.\n\n## UI library defaults\n\n- **Default to RSuite.** Reference library; widest component set\n  including `RsWizard` for multi-step forms.\n- **Material UI** when the user mentions MUI, Material, or their project\n  is on MUI.\n- **Mantine** when the user mentions Mantine or needs a component that's\n  Mantine-only (color picker, rich date pickers, segmented control).\n\nState the choice explicitly in the first sentence of the response.\n\n## Common renames — always emit the right name\n\n| Wrong | Right |\n|---|---|\n| `Form` | `Screen` |\n| `RsForm` | `RsCard` or `RsContainer` |\n| `RsSelectPicker` | `RsDropdown` |\n| `RsRadio` | `RsRadioGroup` |\n| `RsTextarea` | `RsTextArea` (capital A) |\n| `RsInputNumber` | `RsNumberFormat` |\n| `RsUpload` | `RsUploader` |\n| `MtDatePickerSingle` | `MtDatePicker` |\n| `MtTextField` | `MtTextInput` |\n\n## Side-by-side fields\n\nUse `RsContainer` with `display: flex` and children with\n`wrapperCss.any.object.flex: \"1\"`. RSuite has no FlexboxGrid/Stack\nadapter — flex on `RsContainer` is the mechanism.\n\n## Section headings\n\nUse `RsCard` with the `header` prop, or `RsHeader` — never `<h1>` /\n`<h2>` embedded in `RsStaticContent` `content` strings.\n\n## Conditional rendering\n\nUse `renderWhen: { \"jsCode\": \"data.X === Y\" }` and pair with\n`validateWhen` if validations should also be conditional.\n\n## App.tsx — minimal starter\n\nImport only the library's stylesheet. Theme via the library's provider.\nNo companion CSS. No root className. Layout-level inline styles\n(`maxWidth`, `margin`, `padding`) on the wrapping `<div>` are fine.\n\n```tsx\nimport \"rsuite/dist/rsuite.min.css\";\nimport { FormViewer, BiDi } from \"@react-form-builder/core\";\nimport { view } from \"@react-form-builder/components-rsuite\";\nimport formJson from \"./form.json\";\n\nconst getForm = () => JSON.stringify(formJson);\n\nexport default function App() {\n  return (\n    <div style={{ maxWidth: 720, margin: \"40px auto\", padding: 16 }}>\n      <FormViewer\n        view={view}\n        getForm={getForm}\n        onFormDataChange={(d) => console.log(d)}\n        biDi={BiDi.LTR}\n      />\n    </div>\n  );\n}\n```\n\n## Free vs. commercial — stay on the MIT side\n\nFormEngine **Core** is MIT and free. The Designer and some Premium\ncomponents (Signature, DataGrid, Rich Text, QR Code, Google Maps) are\ncommercial. Don't emit Premium component types unless the user\nexplicitly asks. Direct people to the free Online FormBuilder\n(https://formbuilder.formengine.io) for visual editing.\n\n## Response shape\n\nLead paragraph (library + field count) → `form.json` → `App.tsx` →\nvalidation checklist → install command → \"tweak visually in the Online\nFormBuilder\" link → 3 next-step doc links into FormEngine Core docs.\n\n## Reference\n\n- FormEngine Core docs: https://formengine.io/documentation/formengine-core/\n- Forms JSON reference: https://formengine.io/documentation/formengine-core/forms-json/\n- Validation: https://formengine.io/documentation/formengine-core/validation/\n- Conditional rendering: https://formengine.io/documentation/formengine-core/conditional-rendering/\n- Online FormBuilder: https://formbuilder.formengine.io\n- llms-full.txt (full machine-readable docs): https://formengine.io/documentation/llms-full.txt\n- Source repo for this rule: https://github.com/lukinov/ai-form-builder\n"}