# Formula Builder (Vue 3)

Visual formula builder shown in the **Cost Calculator** tab of the Contact Form 7 editor.

## Build

```bash
cd formula-builder
npm install
npm run build
```

The build writes `../assets/admin/formula-builder/formula-builder.js` and `formula-builder.css`
(Vue is bundled in, one IIFE file — no module loader needed). `inc/admin.php` enqueues them
only on CF7 editor screens. Ship the built files with the plugin; `node_modules` is not needed.

## Develop

```bash
npm run dev
```

Opens `index.html`, which fakes the CF7 form textarea (`#wpcf7-form`) and `window.cf7ccBuilder`,
so you can work on the UI without WordPress. Edit the demo form template to see fields update.

## How it fits together

| Piece | Where |
|---|---|
| Fields list | Parsed from the CF7 form template (`src/lib/fields.js`), re-read every 1.5 s and on input |
| Formula ↔ tokens | `src/lib/formula.js` — parse, serialize, safe evaluator (no `eval`) |
| State | `src/store.js` |
| Saving | Hidden inputs `cf7cc_formulas[<name>]` are posted with the CF7 **Save** button (`wpcf7_save_contact_form`), and the **Save formula** button saves via AJAX (`cf7cc_save_formulas`, nonce `cf7cc_formula_builder`) |
| Storage | Post meta `_cf7cc_<calculated field name>` — the format `assets/frontend/frontend.js` reads |

Formula format: `quantity * unit_price + shipping`, with `( )` and
`Math.round/ceil/floor/abs/min/max(...)`.
