@vergelijkdirect/comparison-forms 2.0.0-rc.8 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -109
- package/dist/vue/comparison-forms.css +1 -1
- package/dist/vue/comparison-forms.d.ts +91 -73
- package/dist/vue/comparison-forms.js +772 -755
- package/dist/wc/comparison-forms.css +1 -1
- package/dist/wc/comparison-forms.js +3328 -3277
- package/dist/wc-forms/VdInput-CQMUZonZ.cjs +1 -0
- package/dist/wc-forms/VdPopover-B7iU4v7L.cjs +1 -0
- package/dist/wc-forms/VdRadioGroup-CliXOc0N.cjs +1 -0
- package/dist/wc-forms/VdSearchableSelect-BOOYo1Cc.cjs +3 -0
- package/dist/wc-forms/VdSelect-BsnfIWYl.cjs +1 -0
- package/dist/wc-forms/bike.cjs +1 -0
- package/dist/wc-forms/birthdate.schema-C-y732mA.cjs +1 -0
- package/dist/wc-forms/business-car.cjs +1 -0
- package/dist/wc-forms/business-liability.cjs +1 -0
- package/dist/wc-forms/car.cjs +1 -0
- package/dist/wc-forms/caravan.cjs +1 -0
- package/dist/wc-forms/company.schema-Dhzxphqu.cjs +1 -0
- package/dist/wc-forms/date.util-DoOLYSV4.cjs +1 -0
- package/dist/wc-forms/familyComposition.schema-gvSnx-ea.cjs +1 -0
- package/dist/wc-forms/floating-ui.dom-QFQ2zVcn.cjs +1 -0
- package/dist/wc-forms/house.cjs +1 -0
- package/dist/wc-forms/houseOwnedBuilding.model-G9AqKTZo.cjs +1 -0
- package/dist/wc-forms/legal.cjs +1 -0
- package/dist/wc-forms/liability.cjs +1 -0
- package/dist/wc-forms/loan.cjs +1 -0
- package/dist/wc-forms/messages-CX8jVyEo.cjs +1 -0
- package/dist/wc-forms/moped.cjs +1 -0
- package/dist/wc-forms/motor.cjs +1 -0
- package/dist/wc-forms/package.cjs +1 -0
- package/dist/wc-forms/pet.cjs +1 -0
- package/dist/wc-forms/rolldown-runtime-Dbss1pSk.cjs +1 -0
- package/dist/wc-forms/rules-GF6hc_di.cjs +1 -0
- package/dist/wc-forms/services-BmRVYKgg.cjs +1 -0
- package/dist/wc-forms/travel.cjs +1 -0
- package/dist/wc-forms/useAddress-CNccyKT4.cjs +1 -0
- package/dist/wc-forms/useLicensePlate-Ct8T-GYB.cjs +1 -0
- package/dist/wc-forms/useValidator-C2pny0oV.cjs +3 -0
- package/dist/wc-forms/yesNo-DgihWhwI.cjs +1 -0
- package/dist/wc-noitc/comparison-forms.css +2 -13
- package/dist/wc-noitc/comparison-forms.umd.cjs +5 -0
- package/package.json +14 -10
- package/dist/wc-noitc/comparison-forms.js +0 -35
package/README.md
CHANGED
|
@@ -1,136 +1,172 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vergelijkdirect/comparison-forms — Vue 3 library (`2.x`)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Headless comparison forms for vergelijkdirect, consumable two ways:
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
- **Vue 3 hosts** — npm package export `@vergelijkdirect/comparison-forms/vue`
|
|
6
|
+
- **Vue 2.7 / non-Vue hosts** — self-contained Web Component `@vergelijkdirect/comparison-forms/wc`
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
The library is the whole of `src/`. The legacy Vue 2.7 app it replaced was migrated form by form
|
|
9
|
+
and has since been removed — its `<embedded-comparison-forms>` plugin API does not exist here
|
|
10
|
+
(see the migration table below). If you still need `1.x`, it lives on the **`v1`** branch, in
|
|
11
|
+
maintenance mode: bugfixes and security only, no new forms or features.
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
## Install & prerequisites
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
| title | Specify forms title | &title=Motorverzekering vergelijken |
|
|
16
|
-
| full-form-width | Specify, should form has 100% width of parent component, or should has strong standard borders | &full-form-width=true |
|
|
15
|
+
The ITC client (`@vergelijkdirect/insurance-transmission-client`) is **your** peer dependency:
|
|
16
|
+
the library never creates or exports it for Vue hosts. You install and initialize it yourself,
|
|
17
|
+
once, before mounting any form — the library's forms/flow lazily pull the already-initialized
|
|
18
|
+
services (see `preview/main.ts` for a working bootstrap example).
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
```bash
|
|
21
|
+
npm i @vergelijkdirect/comparison-forms
|
|
22
|
+
```
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
Load the styles once per page:
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
```ts
|
|
27
|
+
import '@vergelijkdirect/comparison-forms/vue/styles';
|
|
28
|
+
```
|
|
23
29
|
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
### 1. Drop-in (recommended) — the form handles everything
|
|
33
|
+
|
|
34
|
+
```vue
|
|
35
|
+
<script setup>
|
|
36
|
+
import { ComparisonFormFlow } from '@vergelijkdirect/comparison-forms/vue';
|
|
37
|
+
// ITC must already be initialized (see "Install & prerequisites" above)
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<template>
|
|
41
|
+
<ComparisonFormFlow
|
|
42
|
+
form="bike"
|
|
43
|
+
link="https://www.vergelijkdirect.com/fietsverzekering/"
|
|
44
|
+
layout="horizontal"
|
|
45
|
+
@submitted="(url) => track(url)"
|
|
46
|
+
@error="showFallbackLead"
|
|
47
|
+
/>
|
|
48
|
+
</template>
|
|
24
49
|
```
|
|
25
|
-
|
|
50
|
+
|
|
51
|
+
Fills the form → creates the comparison via ITC → appends the comparison route (`#/<id>/…`)
|
|
52
|
+
to the base `link` → redirects.
|
|
53
|
+
On failure it emits `error(error, payload)` and does nothing else — the fallback-lead UI is
|
|
54
|
+
yours to wire, with the user's data available in `payload.user`.
|
|
55
|
+
|
|
56
|
+
### 2. Headless — you own the submit
|
|
57
|
+
|
|
58
|
+
```vue
|
|
59
|
+
<script setup>
|
|
60
|
+
import {
|
|
61
|
+
BikeForm,
|
|
62
|
+
bikePresenter,
|
|
63
|
+
useComparisonSubmit,
|
|
64
|
+
} from '@vergelijkdirect/comparison-forms/vue';
|
|
65
|
+
|
|
66
|
+
const { submit, isSubmitting } = useComparisonSubmit({
|
|
67
|
+
link: 'https://…/fietsverzekering/funnel/',
|
|
68
|
+
onError: showFallbackLead,
|
|
69
|
+
});
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
<template>
|
|
73
|
+
<BikeForm @submitted="(data) => submit(bikePresenter(data))" />
|
|
74
|
+
</template>
|
|
26
75
|
```
|
|
27
76
|
|
|
28
|
-
|
|
29
|
-
3.In entry js file (for example vd-partner.ts in partner-front) import comparisonFormsPlugin
|
|
77
|
+
Or skip the flow entirely (result-page edit, custom persistence):
|
|
30
78
|
|
|
79
|
+
```vue
|
|
80
|
+
<BikeForm :initial-data="savedBike" @submitted="updateMyComparison" />
|
|
31
81
|
```
|
|
32
|
-
import comparisonFormsPlugin from '@vergelijkdirect/comparison-forms';
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
4.Make Vue use plugin
|
|
36
82
|
|
|
83
|
+
`initialData` is read once on mount — remount with `:key` when it arrives async.
|
|
84
|
+
|
|
85
|
+
### 3. Web Component (Vue 2.7 / plain HTML hosts)
|
|
86
|
+
|
|
87
|
+
```html
|
|
88
|
+
<script
|
|
89
|
+
type="module"
|
|
90
|
+
src=".../comparison-forms/wc"
|
|
91
|
+
></script>
|
|
92
|
+
<link
|
|
93
|
+
rel="stylesheet"
|
|
94
|
+
href=".../comparison-forms/wc/styles"
|
|
95
|
+
/>
|
|
96
|
+
|
|
97
|
+
<vd-comparison-form
|
|
98
|
+
form="bike"
|
|
99
|
+
link="https://…/fietsverzekering/funnel/"
|
|
100
|
+
api-url="https://api.vergelijkdirect.com"
|
|
101
|
+
></vd-comparison-form>
|
|
102
|
+
|
|
103
|
+
<script>
|
|
104
|
+
document
|
|
105
|
+
.querySelector('vd-comparison-form')
|
|
106
|
+
.addEventListener('error', (e) => console.error(e.detail[0]));
|
|
107
|
+
</script>
|
|
37
108
|
```
|
|
38
|
-
|
|
109
|
+
|
|
110
|
+
The element initializes the shared ITC client from the url attributes — it is its own consumer,
|
|
111
|
+
no host-side setup needed. Events are native `CustomEvent`s (`submitted`, `error`) with the
|
|
112
|
+
emit arguments in `detail` — `error` carries the error in `detail[0]` and, when the failure
|
|
113
|
+
happened on submit, the `ComparisonPayload` in `detail[1]` (client-init failures have no
|
|
114
|
+
payload). `initial-data` accepts either a JSON-string attribute (`initial-data='{"kind":1}'`, for
|
|
115
|
+
plain HTML) or an object set as a DOM property (`el.initialData = {…}`); other complex props are
|
|
116
|
+
DOM properties only.
|
|
117
|
+
|
|
118
|
+
## Migrating from the 1.x `<embedded-comparison-forms>` events
|
|
119
|
+
|
|
120
|
+
The 2.x event contract is a deliberate break. How each legacy event maps:
|
|
121
|
+
|
|
122
|
+
| Legacy (1.x) | When it fired | 2.x equivalent |
|
|
123
|
+
| ------------------------------------------------------- | ------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
124
|
+
| `@change` | result/coverage page — "update, don't create" | headless `@submitted` with typed form data; run it through the form's presenter and `payload.user` carries the fields hosts wrote back (`zipCode`, `birthdate`, `houseNumber`, `houseNumberAddition`, `street`, `city`) |
|
|
125
|
+
| `@emit-event` `{ event: 'open-quotation-modal', data }` | comparison create failed → fallback lead | `@error` — emits `(error, payload)`; build the fallback lead from `payload.user`. ITC rejects an unknown postcode the same way as a transport failure — check `error instanceof Error` if you need to tell them apart |
|
|
126
|
+
| `@emit-event` (no arguments) | submitted with unchanged data → "close me" | none by design — the form always emits `submitted`; the host owns update semantics, so compare the submitted data with what it passed as `initial-data` (e.g. lodash `isEqual`) and skip the update |
|
|
127
|
+
| `@redirect-page` | never reached hosts — the 1.x embedded shell consumed it internally | `submitted(url)` fires before the redirect; the `redirect` prop overrides navigation |
|
|
128
|
+
|
|
129
|
+
## Development
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
npm run dev # live sandbox (preview/) — demos for every component and form
|
|
133
|
+
npm run test:unit # vitest run
|
|
134
|
+
npm run typecheck # vue-tsc --noEmit
|
|
135
|
+
npm run lint # eslint src tests preview (lint:fix to autofix)
|
|
136
|
+
npm run format # prettier --write . (format:check to verify only)
|
|
39
137
|
```
|
|
40
138
|
|
|
41
|
-
|
|
139
|
+
Node version is pinned in `.nvmrc` (Node 24) — run `nvm use` (or fnm) before installing. Install
|
|
140
|
+
with `npm ci`, not `npm install`: it installs exactly from the committed `package-lock.json` and
|
|
141
|
+
avoids the npm optional-dependency bug ([npm#4828](https://github.com/npm/cli/issues/4828)) that
|
|
142
|
+
can drop rolldown's native binding and break `vite`. If a machine gets into that state, a clean
|
|
143
|
+
`rm -rf node_modules && npm ci` fixes it.
|
|
42
144
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
```
|
|
145
|
+
`src/environment/environment.ts` is gitignored — create it from the checked-in
|
|
146
|
+
`environment.dev.ts` / `environment.prod.ts` first.
|
|
46
147
|
|
|
47
|
-
|
|
148
|
+
### Builds
|
|
48
149
|
|
|
150
|
+
```bash
|
|
151
|
+
npm run build # typecheck, then every build below (also runs on prepublishOnly)
|
|
152
|
+
npm run build:lib # dist/vue — Vue 3 library, vue external
|
|
153
|
+
npm run build:wc # dist/wc — self-contained <vd-comparison-form> (ES; ITC + Vue inlined)
|
|
154
|
+
npm run build:wc-noitc # dist/wc-noitc — same element, UMD, ITC left external (host resolves it)
|
|
155
|
+
npm run build:wc-forms # dist/wc-forms — one CJS element bundle per form (<name>.cjs), ITC external
|
|
49
156
|
```
|
|
50
|
-
import '@vergelijkdirect/comparison-forms/styles';
|
|
51
|
-
```
|
|
52
157
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
| link | String/No | Indicate address, where user should be redirected after forms submit | &link=verzekeringen/results-page |
|
|
59
|
-
| has-new-design | Boolean/No | Indicate which version of form styles implemented. Missing value or false mean old form, true - new redesign form (non-required) | true |
|
|
60
|
-
| classes | String/No | Indicate which classes should be implemented for root element (vd-form-card) | vd-form-flat |
|
|
61
|
-
| insurance-state | Object/No | There should be indicated object with data for insurance. Used to show data in inputs, if user already filled in form. | for motor insurance can be included object motorState from store |
|
|
62
|
-
| user-information | Object/No | There should be indicated object with user's data. Used to show data in inputs, if user already filled in form. | Usually it's userInformation object from store |
|
|
63
|
-
| base-url | String/No | Base url should be used only for loans create forms, specify base url | / |
|
|
64
|
-
| title | String/No | Specify title of form (by default has value <insurance name> vergelijken) | Motorverzekering vergelijken |
|
|
65
|
-
| show-title | Boolean/No | Boolean, that specify should title, in title prop be showed (Use value false, if there is external modal title, to prevent double titles) | false |
|
|
66
|
-
| form-orientation | String/No | Specify form orientation (Vertical or Horizontal) Should be used only for create loan form | Vertical |
|
|
67
|
-
| form-location | String/No | String, that indicate, where form is located. Can be before flow, on result, coverages,family page. | IS_BEFORE_FLOW/IS_ON_RESULT_PAGE/IS_ON_COVERAGES_PAGE/IS_ON_FAMILY_PAGE |
|
|
68
|
-
| additional-options | Object/No | Props that contains all special data, for separate form. E.g. qustionnary data for only Risk scanner/business car forms. | { qa_id: 'some value' } |
|
|
69
|
-
| @change | Function/No | Function, that should be called, when user submit form. Has parameters ({ insuranceState: {...}, userInformation: {...} }), that can be used for furtner actions with this data | Any function, that should be called after form submit |
|
|
70
|
-
| @redirect-page | Function/No | Function, that should be called, when user submit form, and should be redirected to page, indicated in link props with necessary data in queries. | Any function, that should be called after form submit |
|
|
71
|
-
| @emit-event-hub | Function/No | Function, that should be called, when user want to use external emit event. Has parameters ({ event: String, data: {...}}) | emit('emit-event-hub', { event: 'call-some-external-event', data: { ...any data }) |
|
|
72
|
-
|
|
73
|
-
Example
|
|
158
|
+
`build:wc` is the self-contained drop-in used from a plain `<script>` tag. The `wc-noitc` /
|
|
159
|
+
`wc-forms` variants keep `@vergelijkdirect/insurance-transmission-client` external so a host
|
|
160
|
+
bundler (webpack 5) shares its own configured client with the forms.
|
|
161
|
+
|
|
162
|
+
## Architecture
|
|
74
163
|
|
|
75
164
|
```
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
:form-component="'motor-form'"
|
|
81
|
-
:user-information="userInformation"
|
|
82
|
-
:insurance-state="motorState"
|
|
83
|
-
:has-new-design="true"
|
|
84
|
-
:classes="'w-100 vd-form-card--flat'"
|
|
85
|
-
:link="'/'"
|
|
86
|
-
:show-title="false"
|
|
87
|
-
:form-location="'IS_ON_RESULT_PAGE'"
|
|
88
|
-
:additional-options="{
|
|
89
|
-
some-data-for-some-certain-form: 'some data'
|
|
90
|
-
}"
|
|
91
|
-
/>
|
|
165
|
+
entries (lib.ts, wc.ts) → flow (useComparisonSubmit, ComparisonFormFlow)
|
|
166
|
+
→ comparisons (registry + one dir per comparison: Form, schema, models, presenter)
|
|
167
|
+
→ components (fields: address/licensePlate/company → ui: Vd* primitives)
|
|
168
|
+
data/itc.ts — the single gateway to the ITC client interfaces — shared types
|
|
92
169
|
```
|
|
93
170
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
- bike-form
|
|
97
|
-
- bike-form-horizontal
|
|
98
|
-
- business-car-form
|
|
99
|
-
- business-car-form-horizontal
|
|
100
|
-
- business-liability-form
|
|
101
|
-
- car-form
|
|
102
|
-
- car-form-horizontal
|
|
103
|
-
- caravan-form
|
|
104
|
-
- caravan-form-horizontal
|
|
105
|
-
- default-form
|
|
106
|
-
- house-form
|
|
107
|
-
- house-form-horizontal
|
|
108
|
-
- legal-assistance-form
|
|
109
|
-
- legal-assistance-form-horizontal
|
|
110
|
-
- liability-form
|
|
111
|
-
- liability-form-horizontal
|
|
112
|
-
- loan-form
|
|
113
|
-
- loan-form-horizontal
|
|
114
|
-
- moped-form
|
|
115
|
-
- moped-form-horizontal
|
|
116
|
-
- motor-form
|
|
117
|
-
- motor-form-horizontal
|
|
118
|
-
- package-form
|
|
119
|
-
- pet-form
|
|
120
|
-
- pet-form-horizontal
|
|
121
|
-
- questionnaire-form
|
|
122
|
-
- risk-scanner-form
|
|
123
|
-
- travel-form
|
|
124
|
-
- travel-form-horizontal
|
|
125
|
-
|
|
126
|
-
Those names should be used in form-component prop for embedded mode, or for link address for standalone version, and should be exact as in this list. If there is a need to get old horizontal form, formComponent should include: form-type-horizontal-old, or form-type-old-horizontal. E.g. motor-form-horizontal-old.
|
|
127
|
-
|
|
128
|
-
NOTICE: If there is :link prop, user will be redirected to this address with appropriate queryparams.
|
|
129
|
-
|
|
130
|
-
### Embedded mode Comparison forms commands
|
|
131
|
-
|
|
132
|
-
- npm run watch - launch dev mode SSR app
|
|
133
|
-
- npm run serve - launch prod mode SSR app
|
|
134
|
-
- npm run test - launch test mode app
|
|
135
|
-
- npm run build - make build
|
|
136
|
-
- npm run rollup - make rollup of comparison forms
|
|
171
|
+
Forms are headless: they validate (yup via `useValidator`) and emit `submitted` with typed, valid
|
|
172
|
+
data — no API calls, no redirects, no global state inside a form.
|