@wayke-se/components-react 5.2.0 → 6.0.0-beta.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.
Files changed (126) hide show
  1. package/README.md +222 -122
  2. package/dist/index.js +1365 -1489
  3. package/dist/index.js.map +4 -4
  4. package/dist/index.mjs +1381 -1505
  5. package/dist/index.mjs.map +4 -4
  6. package/dist/types/src/@types/filter.d.ts +7 -1
  7. package/dist/types/src/Gql/ad/legacyWaykeId.d.ts +1 -0
  8. package/dist/types/src/Gql/ad/propertyTree.d.ts +5 -0
  9. package/dist/types/src/Gql/ad/queries.d.ts +9 -0
  10. package/dist/types/src/Gql/ad/types.d.ts +378 -0
  11. package/dist/types/src/Gql/ad/useAd.d.ts +8 -0
  12. package/dist/types/src/Gql/ad/useInsuranceInquiry.d.ts +11 -0
  13. package/dist/types/src/Gql/ad/useLoanCalculation.d.ts +14 -0
  14. package/dist/types/src/Gql/ad/useRelatedAds.d.ts +12 -0
  15. package/dist/types/src/Gql/ad/view.d.ts +94 -0
  16. package/dist/types/src/Gql/client.d.ts +11 -0
  17. package/dist/types/src/Gql/config.d.ts +9 -0
  18. package/dist/types/src/Gql/facets.d.ts +19 -0
  19. package/dist/types/src/Gql/hit.d.ts +5 -0
  20. package/dist/types/src/Gql/legacyParams.d.ts +7 -0
  21. package/dist/types/src/Gql/queries.d.ts +17 -0
  22. package/dist/types/src/Gql/searchParams.d.ts +55 -0
  23. package/dist/types/src/Gql/suggest.d.ts +8 -0
  24. package/dist/types/src/Gql/types.d.ts +131 -0
  25. package/dist/types/src/Gql/useAdsSearch.d.ts +21 -0
  26. package/dist/types/src/State/Ad/AdContext.d.ts +5 -0
  27. package/dist/types/src/State/Router/RouterContext.d.ts +15 -0
  28. package/dist/types/src/State/Router/RouterProvider.d.ts +6 -0
  29. package/dist/types/src/State/Router/useRouter.d.ts +2 -0
  30. package/dist/types/src/State/Search/SearchContext.d.ts +15 -9
  31. package/dist/types/src/State/Search/SearchProvider.d.ts +1 -5
  32. package/dist/types/src/State/Settings/SettingsContext.d.ts +2 -12
  33. package/dist/types/src/State/Settings/settings.d.ts +56 -0
  34. package/dist/types/src/State/Settings/useSettings.d.ts +1 -1
  35. package/dist/types/src/components/ActionList/index.d.ts +3 -10
  36. package/dist/types/src/components/DocumentList/index.d.ts +3 -3
  37. package/dist/types/src/components/Filter/index.d.ts +1 -3
  38. package/dist/types/src/components/FilterPanel/checkListFacet.d.ts +2 -3
  39. package/dist/types/src/components/FilterPanel/colorFacet.d.ts +2 -3
  40. package/dist/types/src/components/FilterPanel/faceSelector.d.ts +2 -3
  41. package/dist/types/src/components/FilterPanel/index.d.ts +8 -15
  42. package/dist/types/src/components/FilterPanel/rangeFacet.d.ts +3 -3
  43. package/dist/types/src/components/FinancialOptions/LoanModal.d.ts +3 -7
  44. package/dist/types/src/components/FinancialOptions/index.d.ts +5 -7
  45. package/dist/types/src/components/FinancialOptions/leasing.d.ts +3 -3
  46. package/dist/types/src/components/FinancialOptions/loan.d.ts +3 -7
  47. package/dist/types/src/components/Gallery/index.d.ts +3 -5
  48. package/dist/types/src/components/Grid/index.d.ts +3 -7
  49. package/dist/types/src/components/InsuranceOptions/Insurance.d.ts +4 -6
  50. package/dist/types/src/components/InsuranceOptions/InsuranceFree.d.ts +5 -7
  51. package/dist/types/src/components/InsuranceOptions/InsuranceFreeModal.d.ts +4 -4
  52. package/dist/types/src/components/InsuranceOptions/InsuranceModal.d.ts +4 -6
  53. package/dist/types/src/components/InsuranceOptions/index.d.ts +5 -6
  54. package/dist/types/src/components/LeadForm/index.d.ts +1 -6
  55. package/dist/types/src/components/Lightbox/index.d.ts +2 -2
  56. package/dist/types/src/components/Map/index.d.ts +4 -2
  57. package/dist/types/src/components/OpeningHours/index.d.ts +2 -2
  58. package/dist/types/src/components/ProductCard/HitCard.d.ts +10 -0
  59. package/dist/types/src/components/ProductCard/index.d.ts +9 -13
  60. package/dist/types/src/components/SearchBar/index.d.ts +4 -1
  61. package/dist/types/src/components/SearchBar/wrapper.d.ts +10 -0
  62. package/dist/types/src/components/SortSelect/index.d.ts +1 -2
  63. package/dist/types/src/hooks/useSubmitLead.d.ts +1 -1
  64. package/dist/types/src/index.d.ts +5 -4
  65. package/dist/types/src/layouts/WaykeComposite.d.ts +3 -8
  66. package/dist/types/src/layouts/WaykeCompositeWithProvider.d.ts +1 -1
  67. package/dist/types/src/layouts/search/index.d.ts +6 -7
  68. package/dist/types/src/layouts/searchItem/Accessories/AccessoryModal.d.ts +2 -2
  69. package/dist/types/src/layouts/searchItem/Accessories/index.d.ts +2 -2
  70. package/dist/types/src/layouts/searchItem/Branch.d.ts +3 -4
  71. package/dist/types/src/layouts/searchItem/CheckList.d.ts +3 -15
  72. package/dist/types/src/layouts/searchItem/Documents.d.ts +2 -2
  73. package/dist/types/src/layouts/searchItem/ManufacturerPackagesOption.d.ts +2 -2
  74. package/dist/types/src/layouts/searchItem/PackageOptions.d.ts +3 -3
  75. package/dist/types/src/layouts/searchItem/Property.d.ts +1 -6
  76. package/dist/types/src/layouts/searchItem/Related.d.ts +5 -6
  77. package/dist/types/src/layouts/searchItem/index.d.ts +8 -6
  78. package/dist/types/src/layouts/searchItem/useEcom.d.ts +7 -3
  79. package/dist/types/src/providers/WaykeProvider.d.ts +7 -21
  80. package/dist/types/src/utils/image.d.ts +14 -0
  81. package/dist/types/src/utils/sortOptions.d.ts +4 -13
  82. package/package.json +10 -16
  83. package/dist/types/src/@types/action.d.ts +0 -3
  84. package/dist/types/src/@types/codegen/types.d.ts +0 -433
  85. package/dist/types/src/@types/queryFilter.d.ts +0 -5
  86. package/dist/types/src/@types/search.d.ts +0 -114
  87. package/dist/types/src/State/CentralStorage/CentralStorageContext.d.ts +0 -5
  88. package/dist/types/src/State/CentralStorage/CentralStorageProvider.d.ts +0 -6
  89. package/dist/types/src/State/CentralStorage/useCentralStorage.d.ts +0 -6
  90. package/dist/types/src/State/Path/PathContext.d.ts +0 -8
  91. package/dist/types/src/State/Path/PathProvider.d.ts +0 -6
  92. package/dist/types/src/State/Path/reducer.d.ts +0 -14
  93. package/dist/types/src/State/Path/usePath.d.ts +0 -3
  94. package/dist/types/src/State/RelatedSearch/RelatedSearchContext.d.ts +0 -9
  95. package/dist/types/src/State/RelatedSearch/RelatedSearchProvider.d.ts +0 -9
  96. package/dist/types/src/State/RelatedSearch/useRelatedSearch.d.ts +0 -2
  97. package/dist/types/src/State/Settings/SettingsProvider.d.ts +0 -11
  98. package/dist/types/src/components/Video/QuickNavVideo.d.ts +0 -7
  99. package/dist/types/src/hooks/apolloTypes.d.ts +0 -6
  100. package/dist/types/src/hooks/useHasBeenVisible.d.ts +0 -2
  101. package/dist/types/src/hooks/useHashGuid.d.ts +0 -2
  102. package/dist/types/src/hooks/useInsurance.d.ts +0 -4
  103. package/dist/types/src/hooks/useLoan.d.ts +0 -4
  104. package/dist/types/src/hooks/useOnScreen.d.ts +0 -2
  105. package/dist/types/src/hooks/usePrevious.d.ts +0 -2
  106. package/dist/types/src/hooks/useSearchItem.d.ts +0 -4
  107. package/dist/types/src/hooks/useSearchItemBranch.d.ts +0 -4
  108. package/dist/types/src/hooks/useSessionStorage.d.ts +0 -7
  109. package/dist/types/src/layouts/searchItem/BranchModal.d.ts +0 -9
  110. package/dist/types/src/providers/WaykeItemProvidet.d.ts +0 -24
  111. package/dist/types/src/providers/graphqlProvider.d.ts +0 -6
  112. package/dist/types/src/queries/INSURANCE_CALCULATION.d.ts +0 -2
  113. package/dist/types/src/queries/LOAN_CALCULATION.d.ts +0 -2
  114. package/dist/types/src/queries/SEARCH_ITEM_BRANCH_QUERY.d.ts +0 -2
  115. package/dist/types/src/queries/SEARCH_ITEM_QUERY.d.ts +0 -2
  116. package/dist/types/src/utils/deep-copy.d.ts +0 -5
  117. package/dist/types/src/utils/regex.d.ts +0 -3
  118. package/dist/types/src/utils/specification.d.ts +0 -28
  119. package/dist/types/src/utils/url.d.ts +0 -1
  120. package/dist/types/src/utils/vehicle-properties/compare-basic-properties.d.ts +0 -3
  121. package/dist/types/src/utils/vehicle-properties/compare-categories.d.ts +0 -3
  122. package/dist/types/src/utils/vehicle-properties/compare-properties.d.ts +0 -3
  123. package/dist/types/src/utils/vehicle-properties/custom-property-adder.d.ts +0 -13
  124. package/dist/types/src/utils/vehicle-properties/property-remover.d.ts +0 -7
  125. package/dist/types/src/utils/vehicle-properties/property-tree-creator.d.ts +0 -31
  126. package/dist/types/src/utils/vehicle-properties/property-tree-sorter.d.ts +0 -3
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Vehicle search and vehicle pages from Wayke, ready to add to a dealer or partner website. Visitors can search and filter the vehicles, open a vehicle, contact the dealer and buy the vehicle online.
4
4
 
5
+ Upgrading from 5.x? See [Migrating from 5.x to 6.0](#migrating-from-5x-to-60).
6
+
5
7
  ## Quick start
6
8
 
7
9
  Add this where the vehicles should be shown, for example in an HTML block in your CMS, such as WordPress:
@@ -9,16 +11,9 @@ Add this where the vehicles should be shown, for example in an HTML block in you
9
11
  ```html
10
12
  <div id="wayke"></div>
11
13
  <script type="module">
12
- import { mount } from 'https://cdn.wayke.se/public-assets/wayke-components-react/5.2.0/index.js';
13
-
14
- mount('#wayke', {
15
- provider: {
16
- graphQlUrl: 'https://gql.wayke.se/query',
17
- url: 'https://api.wayke.se/vehicles',
18
- urlMlt: 'https://api.wayke.se/vehicles-mlt-ext',
19
- ecomSettings: { url: 'https://ecom.wayke.se' },
20
- },
21
- });
14
+ import { mount } from 'https://cdn.wayke.se/public-assets/wayke-components-react/6.0.0/index.js';
15
+
16
+ mount('#wayke');
22
17
  </script>
23
18
  ```
24
19
 
@@ -37,6 +32,7 @@ That is all you need on most sites. The rest of this page covers other ways to a
37
32
  * [Routing](#routing)
38
33
  * [Events](#events)
39
34
  * [Reference](#reference)
35
+ * [Migrating from 5.x to 6.0](#migrating-from-5x-to-60)
40
36
 
41
37
  ## Add to your site
42
38
 
@@ -48,7 +44,7 @@ That is all you need on most sites. The rest of this page covers other ways to a
48
44
 
49
45
  ### CDN
50
46
 
51
- Every release from `5.2.0` is published to the Wayke CDN with everything included: React, the styles and the buy online flow. Nothing needs to be installed.
47
+ Every release is published to the Wayke CDN with everything included: React, the styles and the buy online flow. Nothing needs to be installed.
52
48
 
53
49
  ```
54
50
  https://cdn.wayke.se/public-assets/wayke-components-react/<version>/index.js
@@ -64,16 +60,11 @@ There are two ways to load the script. They show the same thing and take the sam
64
60
 
65
61
  ```html
66
62
  <div id="wayke"></div>
67
- <script type="module" src="https://cdn.wayke.se/public-assets/wayke-components-react/5.2.0/index.js"></script>
63
+ <script type="module" src="https://cdn.wayke.se/public-assets/wayke-components-react/6.0.0/index.js"></script>
68
64
  <script>
69
65
  window.addEventListener('DOMContentLoaded', () => {
70
66
  WaykeComponents.mount('#wayke', {
71
- provider: {
72
- graphQlUrl: 'https://gql.wayke.se/query',
73
- url: 'https://api.wayke.se/vehicles',
74
- urlMlt: 'https://api.wayke.se/vehicles-mlt-ext',
75
- ecomSettings: { url: 'https://ecom.wayke.se' },
76
- },
67
+ provider: { ecomSettings: {} },
77
68
  });
78
69
  });
79
70
  </script>
@@ -81,14 +72,14 @@ There are two ways to load the script. They show the same thing and take the sam
81
72
 
82
73
  #### Functions
83
74
 
84
- | Function | Settings | Shows |
85
- |---------------|-------------------------------------------|-------------------------------------------|
86
- | `mount` | `{ provider, composite? }` | Search, and the vehicle page when a vehicle is opened ([WaykeComposite](#waykecomposite)) |
87
- | `mountSearch` | `{ provider, search? }` | Only the search ([WaykeSearch](#waykesearch)) |
88
- | `mountItem` | `{ provider, item }` | Only one vehicle page, `item.id` is required ([WaykeSearchItem](#waykesearchitem)) |
75
+ | Function | Settings | Shows |
76
+ |---------------|--------------------------------|-------------------------------------------|
77
+ | `mount` | `{ provider?, composite? }` | Search, and the vehicle page when a vehicle is opened ([WaykeComposite](#waykecomposite)) |
78
+ | `mountSearch` | `{ provider?, search? }` | Only the search ([WaykeSearch](#waykesearch)) |
79
+ | `mountItem` | `{ provider?, item }` | Only one vehicle page, `item.id` is required ([WaykeSearchItem](#waykesearchitem)) |
89
80
 
90
81
  * The first argument is a CSS selector, such as `'#wayke'`, or an element.
91
- * `provider` is [WaykeProviderSettings](#waykeprovidersettings) (for `mountItem`: [WaykeItemProviderSettings](#waykeitemprovidersettings)).
82
+ * `provider` is [WaykeProviderSettings](#waykeprovidersettings), the same for all three.
92
83
  * Each function returns `{ unmount }`, which removes the components again.
93
84
  * `WaykePubSub` is exported too, and is available as `WaykeComponents.WaykePubSub` in option B. See [Events](#events).
94
85
 
@@ -99,13 +90,13 @@ The script adds its stylesheet, `index.css` in the same folder, to the top of `<
99
90
  To load the stylesheet yourself, add a `<link>` to it with the same URL. The script finds it and does not add it again. This works with both options.
100
91
 
101
92
  ```html
102
- <link rel="stylesheet" href="https://cdn.wayke.se/public-assets/wayke-components-react/5.2.0/index.css">
93
+ <link rel="stylesheet" href="https://cdn.wayke.se/public-assets/wayke-components-react/6.0.0/index.css">
103
94
  ```
104
95
 
105
96
  To not load the stylesheet at all, add `disablecssinjection` to the script tag in option B. The image carousel, the 360 viewer and buy online are then unstyled.
106
97
 
107
98
  ```html
108
- <script type="module" src="https://cdn.wayke.se/public-assets/wayke-components-react/5.2.0/index.js" disablecssinjection></script>
99
+ <script type="module" src="https://cdn.wayke.se/public-assets/wayke-components-react/6.0.0/index.js" disablecssinjection></script>
109
100
  ```
110
101
 
111
102
  ### React
@@ -124,10 +115,7 @@ import '@wayke-se/components-react/dist/assets/default.css';
124
115
  import '@wayke-se/ecom-web/dist/index.css'; // Only with ecomSettings
125
116
 
126
117
  const ProviderSettings: WaykeProviderSettings = {
127
- graphQlUrl: 'https://gql.wayke.se/query',
128
- url: 'https://api.wayke.se/vehicles',
129
- urlMlt: 'https://api.wayke.se/vehicles-mlt-ext',
130
- ecomSettings: { url: 'https://ecom.wayke.se' },
118
+ ecomSettings: {},
131
119
  };
132
120
 
133
121
  const App = () => <WaykeComposite provider={ProviderSettings} />;
@@ -160,12 +148,7 @@ import '@wayke-se/ecom-web/dist/index.css'; // Only with ecomSettings
160
148
 
161
149
  createRoot(document.getElementById('wayke')).render(
162
150
  createElement(WaykeComposite, {
163
- provider: {
164
- graphQlUrl: 'https://gql.wayke.se/query',
165
- url: 'https://api.wayke.se/vehicles',
166
- urlMlt: 'https://api.wayke.se/vehicles-mlt-ext',
167
- ecomSettings: { url: 'https://ecom.wayke.se' },
168
- },
151
+ provider: { ecomSettings: {} },
169
152
  })
170
153
  );
171
154
  ```
@@ -174,14 +157,18 @@ createRoot(document.getElementById('wayke')).render(
174
157
 
175
158
  ## Environments
176
159
 
177
- The examples on this page use production. Use test while you develop, to work with test data.
160
+ The components use production by default. Set `environment: 'test'` while you develop, to work with test data:
178
161
 
179
- | Setting | Test | Production |
180
- |--------------------|---------------------------------------------|-----------------------------------------|
181
- | `graphQlUrl` | `https://gql.wayketech.se/query` | `https://gql.wayke.se/query` |
182
- | `url` | `https://api.wayketech.se/vehicles` | `https://api.wayke.se/vehicles` |
183
- | `urlMlt` | `https://api.wayketech.se/vehicles-mlt-ext` | `https://api.wayke.se/vehicles-mlt-ext` |
184
- | `ecomSettings.url` | `https://ecom.wayketech.se` | `https://ecom.wayke.se` |
162
+ ```javascript
163
+ mount('#wayke', {
164
+ provider: { environment: 'test' },
165
+ });
166
+ ```
167
+
168
+ | `environment` | Vehicles and loans | Leads | Buy online |
169
+ |------------------------|---------------------------------------------|---------------------------------|-----------------------------|
170
+ | `production` (default) | `https://public-api.wayke.com/graphql` | `https://api.wayke.se/lead` | `https://ecom.wayke.se` |
171
+ | `test` | `https://public-test-api.wayke.com/graphql` | `https://api.wayketech.se/lead` | `https://ecom.wayketech.se` |
185
172
 
186
173
  Each environment shows the vehicles of the domain the request comes from, so the domain has to be registered in that environment. To develop on `localhost` or a staging domain, have it registered in test. Instead of the domain, a site can be identified with `apiKey`, see [WaykeProviderSettings](#waykeprovidersettings).
187
174
 
@@ -278,9 +265,9 @@ composite: {
278
265
 
279
266
  | type | Button | Default style | Shown when |
280
267
  |---------------|-----------------------|---------------|----------------------------------------------------|
281
- | `ecom` | Buy online | primary | `ecomSettings` is set and the vehicle can be bought online |
282
- | `leadMessage` | Send message (form) | primary | The vehicle belongs to a branch |
283
- | `leadCallMe` | Get a callback (form) | primary | The vehicle belongs to a branch |
268
+ | `ecom` | Buy online | primary | `ecomSettings` is set and the dealer sells the vehicle online |
269
+ | `leadMessage` | Send message (form) | primary | Always |
270
+ | `leadCallMe` | Get a callback (form) | primary | Always |
284
271
  | `email` | Show email address | secondary | The branch or contact has an email address |
285
272
  | `phone` | Show phone number | secondary | The branch or contact has a phone number |
286
273
 
@@ -308,7 +295,7 @@ Both can be changed, as a text or a function of the vehicle. The vehicle has `id
308
295
 
309
296
  ### Filters
310
297
 
311
- Choose which filters are shown, in the order they are listed. `displayName` changes the title of a filter. See [SearchFilterTypes](#searchfiltertypes) for all filters.
298
+ Choose which filters are shown, in the order they are listed. `displayName` changes the title of a filter. See [SearchFilterTypes](#searchfiltertypes) for all filters. A filter with nothing to pick, such as business leasing on a site without leasing cars, is left out.
312
299
 
313
300
  ```javascript
314
301
  composite: {
@@ -319,7 +306,7 @@ composite: {
319
306
  }
320
307
  ```
321
308
 
322
- To set the filters that are applied when the search loads, use `initialQueryParams`. See [WaykeSearch](#waykesearch) for the available parameters.
309
+ To set the filters that are applied when the search loads, use `initialQueryParams`. It takes the same parameters as the url, see [Search parameters](#search-parameters).
323
310
 
324
311
  ```javascript
325
312
  const initialQueryParams = new URLSearchParams();
@@ -332,16 +319,18 @@ composite: {
332
319
  }
333
320
  ```
334
321
 
322
+ The search field suggests makes and models while the visitor types. Picking one, or typing one exactly, such as "volvo v60", filters on it instead of searching the text.
323
+
335
324
  ### Language
336
325
 
337
- The components are in Swedish by default. For Norwegian, set `marketCode: 'NO'` in `composite`.
326
+ The components are in Swedish by default. For Norwegian, set `marketCode: 'NO'` in `provider`.
338
327
 
339
- * The mileage filter is shown in Swedish miles (`mileage`, 1 mil = 10 km) in Swedish, and in kilometers (`odometerValueAsKm`) in Norwegian, unless `filterList` is set.
340
- * The language is set once, by the first component that is shown.
328
+ * The mileage filter is in Swedish miles (1 mil = 10 km) in Swedish, and in kilometers in Norwegian.
329
+ * The language is set once, by the first provider that is shown.
341
330
 
342
331
  ### Search or vehicle page only
343
332
 
344
- To show only the search or only one vehicle page, use `mountSearch` or `mountItem` on the CDN, see [Functions](#functions). In React, use the component with its provider. Place the provider close to the root of your app, so that its cache is kept.
333
+ To show only the search or only one vehicle page, use `mountSearch` or `mountItem` on the CDN, see [Functions](#functions). In React, use the component with `WaykeProvider`. Place the provider close to the root of your app, so that its cache is kept.
345
334
 
346
335
  Search only:
347
336
 
@@ -350,50 +339,79 @@ import React from 'react';
350
339
  import { WaykeProvider, WaykeSearch } from '@wayke-se/components-react';
351
340
 
352
341
  const App = () => (
353
- <WaykeProvider {...ProviderSettings}>
354
- <WaykeSearch onClickSearchItem={(data) => console.log(data.id, data.branchId, data.branchName)} />
342
+ <WaykeProvider {...ProviderSettings} routing={{ mode: 'none' }}>
343
+ <WaykeSearch />
355
344
  </WaykeProvider>
356
345
  );
357
346
  ```
358
347
 
359
- Without `hashRoute` or `pathRoute`, the vehicles in the search are not links. Use `onClickSearchItem` to open the vehicle yourself.
348
+ With `routing.mode: 'none'`, the vehicles in the search are not links. Subscribe to the `ItemClicked` [event](#events) to open the vehicle yourself.
360
349
 
361
350
  Vehicle page only:
362
351
 
363
352
  ```tsx
364
353
  import React from 'react';
365
- import { WaykeItemProvider, WaykeSearchItem } from '@wayke-se/components-react';
354
+ import { WaykeProvider, WaykeSearchItem } from '@wayke-se/components-react';
366
355
 
367
356
  const App = () => (
368
- <WaykeItemProvider {...ProviderSettings}>
369
- <WaykeSearchItem
370
- id="d01f79a3-7552-49c4-9d4d-deb3aa581c31"
371
- onClickSearchItem={(id) => console.log(id)} // A related vehicle is clicked
372
- />
373
- </WaykeItemProvider>
357
+ <WaykeProvider {...ProviderSettings}>
358
+ <WaykeSearchItem id="019cd398-f71a-7ee6-893f-4684c0104a60" />
359
+ </WaykeProvider>
374
360
  );
375
361
  ```
376
362
 
363
+ Older vehicle ids still work: the vehicle is found and the id in the url is replaced with the current one.
364
+
377
365
  ## Routing
378
366
 
379
- `mount` and `WaykeComposite` show the search, and switch to the vehicle page when a vehicle is opened. By default the vehicle is added to the url after a `#`, such as `/vehicles#01a09074-dfab-7e61-9b78-b816c8233b27`. This works on any page, without any server setup, and the url can be shared. Other hashes, such as `#content`, are ignored and show the search.
367
+ Routing is set in `provider.routing`.
368
+
369
+ `mount` and `WaykeComposite` show the search, and switch to the vehicle page when a vehicle is opened. By default the vehicle is added to the url after a `#`, such as `/vehicles#019cd398-f71a-7ee6-893f-4684c0104a60`. This works on any page, without any server setup, and the url can be shared. Other hashes, such as `#content`, are ignored and show the search.
380
370
 
381
- To use a path instead, such as `/vehicles/01a09074-dfab-7e61-9b78-b816c8233b27`, set `pathRoute`:
371
+ To use a path instead, such as `/vehicles/019cd398-f71a-7ee6-893f-4684c0104a60`, set `mode: 'path'` and `basePath`:
382
372
 
383
373
  ```javascript
384
- composite: {
385
- pathRoute: '/vehicles',
374
+ provider: {
375
+ routing: { mode: 'path', basePath: '/vehicles' },
376
+ }
377
+ ```
378
+
379
+ Your server then has to show the same page for `/vehicles` and `/vehicles/<vehicle id>`, so that a vehicle page still works when it is reloaded or shared. The vehicle id is added after a `/`, so `basePath` should not end with a `/`. A relative `basePath` is resolved from the page the components are shown on, and an absolute url is used as it is. With the page at `/search/vehicles`:
380
+
381
+ | `basePath` | Vehicle url |
382
+ |--------------------------------|------------------------------------------------|
383
+ | `/search/vehicles` | `yoursite.com/search/vehicles/<vehicle id>` |
384
+ | `/item` | `yoursite.com/item/<vehicle id>` |
385
+ | `item` | `yoursite.com/search/item/<vehicle id>` |
386
+ | `https://www.example.se/bilar` | `https://www.example.se/bilar/<vehicle id>` |
387
+
388
+ Links on the same site open without reloading the page. Ctrl- or cmd-click opens them in a new tab.
389
+
390
+ To keep the filters in the url, so that a search can be shared and the back button returns to it, set `syncUrl: true`. The filters in the url then win over `initialQueryParams`, which only add what the url doesn't have.
391
+
392
+ ```javascript
393
+ provider: {
394
+ routing: { syncUrl: true },
386
395
  }
387
396
  ```
388
397
 
389
- Your server then has to show the same page for `/vehicles` and `/vehicles/<vehicle id>`, so that a vehicle page still works when it is reloaded or shared. The vehicle id is added after a `/`, so `pathRoute` should not end with a `/`. A relative `pathRoute` is resolved from the current page, and an absolute url is used as it is. With the page at `/search/vehicles`:
398
+ ### Search parameters
399
+
400
+ The url, `initialQueryParams` and the `onFilterUpdate` action use the same parameters as wayke.se:
401
+
402
+ | Parameter | Example | Filters on |
403
+ |-----------|---------|------------|
404
+ | `q` | `q=drag` | Free text |
405
+ | `manufacturer`, `model`, `modelSeries`, `fuelType`, `gearboxType`, `branchDisplayName`, `branchCity`, `colorName`, `environmentClass`, `segment`, `bodyStyle`, `trimLevel`, `inventoryStatus`, `drivetrainType`, `engineBaseType` | `manufacturer=Volvo&manufacturer=Audi` | One or more values |
406
+ | `price.min`, `price.max` | `price.max=300000` | Price in kr |
407
+ | `odometer.min`, `odometer.max` | `odometer.max=8000` | Mileage, in mil in Swedish and in km in Norwegian |
408
+ | `modelYear.min`, `modelYear.max` | `modelYear.min=2018` | Model year |
409
+ | `privateLease.min`, `privateLease.max` | `privateLease.max=5000` | Private leasing per month |
410
+ | `businessLease.min`, `businessLease.max` | `businessLease.max=5000` | Business leasing per month |
411
+ | `certifiedPreOwned`, `isDemoVersion`, `deductibleVat`, `ecom`, `leasing`, `businessLeasing` | `ecom=true` | Yes or no |
412
+ | `sort` | `sort=price-asc` | `published-desc` (default), `published-asc`, `price-asc`, `price-desc`, `modelYear-desc`, `modelYear-asc`, `odometer-asc`, `odometer-desc` |
390
413
 
391
- | `pathRoute` | Vehicle url |
392
- |-------------------------------|------------------------------------------------|
393
- | `/search/vehicles` | `yoursite.com/search/vehicles/<vehicle id>` |
394
- | `/item` | `yoursite.com/item/<vehicle id>` |
395
- | `item` | `yoursite.com/search/item/<vehicle id>` |
396
- | `https://www.example.se/bilar` | `https://www.example.se/bilar/<vehicle id>` |
414
+ The parameters from before 6.0, such as `query`, `color`, `mileage.max` and `sort=mileage-asc`, still work: they are translated, a warning in the console names the new ones, and with `syncUrl` the url is updated to them.
397
415
 
398
416
  ## Events
399
417
 
@@ -403,14 +421,14 @@ On the CDN:
403
421
 
404
422
  ```html
405
423
  <script type="module">
406
- import { mount, WaykePubSub } from 'https://cdn.wayke.se/public-assets/wayke-components-react/5.2.0/index.js';
424
+ import { mount, WaykePubSub } from 'https://cdn.wayke.se/public-assets/wayke-components-react/6.0.0/index.js';
407
425
 
408
426
  WaykePubSub.subscribe({
409
427
  eventName: 'ItemClicked',
410
428
  callback: (data) => console.log('ItemClicked', data),
411
429
  });
412
430
 
413
- mount('#wayke', { provider: { /* ... */ } });
431
+ mount('#wayke');
414
432
  </script>
415
433
  ```
416
434
 
@@ -430,6 +448,12 @@ WaykePubSub.unsubscribe(event); // The same object that was passed to subscribe
430
448
 
431
449
  Use `eventName: 'All'` to get every event, with the callback `(eventName, data) => void`.
432
450
 
451
+ To change the filters from your own code, publish the `onFilterUpdate` action with the [search parameters](#search-parameters):
452
+
453
+ ```javascript
454
+ WaykePubSub.publishAction('onFilterUpdate', 'manufacturer=Volvo&sort=price-asc');
455
+ ```
456
+
433
457
  | Event | When | Data |
434
458
  |-------------------------|----------------------------------------------------------------|----------------------------------------|
435
459
  | `View` | The search or a vehicle page is shown | [ViewData](#viewdata) |
@@ -450,14 +474,14 @@ Use `eventName: 'All'` to get every event, with the callback `(eventName, data)
450
474
  | `InsuranceOpen` | The insurance details are opened | [ItemData](#itemdata) |
451
475
  | `InsuranceClose` | The insurance details are closed | [ItemData](#itemdata) |
452
476
  | `InsuranceInterest` | Insurance prices are requested | [ItemData](#itemdata) |
453
- | `Search` | A search text is submitted | [SearchData](#searchdata) |
477
+ | `Search` | A search text or a suggestion is submitted | [SearchData](#searchdata) |
454
478
  | `SearchInitiated` | A search starts: when the search loads, and after the search text or a filter changes | [SearchData](#searchdata) |
455
479
  | `SearchCompleted` | A search has returned its results | [SearchCompletedData](#searchcompleteddata) |
456
480
  | `SearchClearQuery` | The search text is cleared | [SearchClearQueryData](#searchclearquerydata) |
457
481
  | `SearchClearAllFilters` | All filters are cleared | [SearchData](#searchdata) |
458
482
  | `FilterApply` | A filter is changed | [FilterApplyData](#filterapplydata) |
459
483
 
460
- The data types below describe the payloads. They are not exported from the package.
484
+ The data types below describe the payloads. In TypeScript they are exported with the events, as `CallbackItem`, `CallbackLeadData`, `CallbackSearchCompletedData` and so on. Every `query` uses the [search parameters](#search-parameters).
461
485
 
462
486
  #### ViewData
463
487
  | Property | Type |
@@ -521,7 +545,7 @@ The data types below describe the payloads. They are not exported from the packa
521
545
  | Property | Type |
522
546
  |----------|---------------------------------------|
523
547
  | type | `"checkbox" \| "range"` |
524
- | filter | string |
548
+ | filter | string, a [filter name](#searchfiltertypes) |
525
549
  | value | string \| undefined (checkbox only) |
526
550
  | checked | boolean \| undefined (checkbox only) |
527
551
  | min | number \| undefined (range only) |
@@ -533,73 +557,68 @@ The data types below describe the payloads. They are not exported from the packa
533
557
 
534
558
  The search, and the vehicle page when a vehicle is opened. This is what `mount` shows on the CDN.
535
559
 
536
- | Property | Type | Required |
537
- |-----------|-----------------------------------------------|----------|
538
- | provider | [WaykeProviderSettings](#waykeprovidersettings) | Yes |
539
- | composite | WaykeCompositeProps | No |
560
+ | Property | Type | Required |
561
+ |-----------|-------------------------------------------------|----------|
562
+ | provider | [WaykeProviderSettings](#waykeprovidersettings) | No |
563
+ | composite | WaykeCompositeProps | No |
540
564
 
541
- `WaykeCompositeProps` takes the settings of [WaykeSearch](#waykesearch) and [WaykeSearchItem](#waykesearchitem), except `id`. `hashRoute` and `onClickSearchItem` have no effect here, since `WaykeComposite` handles the routing itself. To know when a vehicle is clicked, subscribe to the `ItemClicked` [event](#events).
565
+ `WaykeCompositeProps` takes the settings of [WaykeSearch](#waykesearch) and [WaykeSearchItem](#waykesearchitem), except `id`.
542
566
 
543
567
  ### WaykeSearch
544
568
 
545
- | Property | Type | Description |
546
- |---------------------------|-----------------------------------------|-------------|
547
- | marketCode | `'SE' \| 'NO'` | Language, see [Language](#language). Default `'SE'`. |
548
- | filterList | [SearchFilterTypes](#searchfiltertypes)[] | The filters to show, in this order. By default all filters, with the mileage filter depending on [Language](#language). |
549
- | initialQueryParams | URLSearchParams \| string | Filters applied when the search loads, see below. |
550
- | removeSearchBar | boolean | Hides the search field. |
551
- | removeFilterOptions | boolean | Hides the filters. |
552
- | placeholderImage | string | Url to an image for vehicles without images. |
553
- | pathRoute | string | Makes the vehicles links to `pathRoute/<vehicle id>`, see [Routing](#routing). |
554
- | hashRoute | boolean | Makes the vehicles links to `#<vehicle id>`. Not used if `pathRoute` is set. |
555
- | onClickSearchItem | `(data: { id, branchId?, branchName? }) => void` | Called when a vehicle is clicked. |
556
- | modifyDocumentTitleSearch | string | Sets the page title. |
557
- | displayBranchName | boolean | Shows the branch name on the vehicles. |
558
-
559
- `initialQueryParams` is passed on to the search API. The parameters are `query`, `manufacturer`, `modelSeries`, `fuelType`, `gearboxType`, `branch`, `color`, `environmentClass`, `properties.segment`, `drivingWheel`, `price.min`, `price.max`, `mileage.min`, `mileage.max`, `odometerValueAsKm.min`, `odometerValueAsKm.max`, `modelYear.min`, `modelYear.max`, `leasingPrice.min`, `leasingPrice.max`, `businessLeasingPrice.min`, `businessLeasingPrice.max`, `sort` (default `published-desc`) and `hits` (default `30`).
569
+ | Property | Type | Description |
570
+ |---------------------------|-------------------------------------------|-------------|
571
+ | filterList | [SearchFilterTypes](#searchfiltertypes)[] | The filters to show, in this order. By default all filters. |
572
+ | initialQueryParams | URLSearchParams \| string | Filters applied when the search loads, see [Search parameters](#search-parameters). |
573
+ | removeSearchBar | boolean | Hides the search field. |
574
+ | removeFilterOptions | boolean | Hides the filters. |
575
+ | placeholderImage | string | Url to an image for vehicles without images. |
576
+ | modifyDocumentTitleSearch | string | Sets the page title. |
577
+ | displayBranchName | boolean | Shows the branch name on the vehicles. |
560
578
 
561
579
  ### WaykeSearchItem
562
580
 
563
581
  | Property | Type | Description |
564
582
  |--------------------------|----------------------------|-------------|
565
- | id | string | **Required.** The id of the vehicle. |
566
- | marketCode | `'SE' \| 'NO'` | Language, see [Language](#language). Default `'SE'`. |
583
+ | id | string | **Required.** The id of the vehicle. Older ids work too. |
567
584
  | conversionOptions | ConversionOption[] | The buttons on the vehicle page, see [Contact buttons](#contact-buttons). |
568
585
  | modifyDocumentTitleItem | boolean | Sets the page title to the vehicle (registration number, title and short description). |
569
586
  | displayBranchName | boolean | Shows the branch name on related vehicles and where the vehicle is located. |
570
587
  | placeholderImage | string | Url to an image for vehicles without images. |
571
588
  | disableResetScrollOnInit | boolean | Keeps the scroll position when the vehicle page opens. By default it scrolls to the top. |
572
- | pathRoute | string | Makes related vehicles links to `pathRoute/<vehicle id>`, see [Routing](#routing). |
573
- | hashRoute | boolean | Makes related vehicles links to `#<vehicle id>`. Not used if `pathRoute` is set. |
574
- | onClickSearchItem | `(id: string) => void` | Called when a related vehicle is clicked. |
575
589
 
576
590
  ### WaykeProviderSettings
577
591
 
578
- | Property | Type | Description |
579
- |-----------------------|-------------------------------|-------------|
580
- | url | string | **Required.** The vehicle search API, see [Environments](#environments). |
581
- | graphQlUrl | string | **Required.** The GraphQL API, see [Environments](#environments). |
582
- | urlMlt | string | The API for related vehicles. Without it, the latest vehicles are shown as related vehicles. |
583
- | ecomSettings | [EcomSettings](#ecomsettings) | Turns on buy online. |
584
- | apiKey | string | Identifies the site instead of its domain. Sent as `x-api-key`. |
585
- | googleMapsApiKey | string | A Google Maps Static API key. With it, the map button on the vehicle page shows a map. Without it, the button opens Google Maps. |
586
- | googleMapsMarker | string | Url to a custom marker for the map. |
587
- | useQueryParamsFromUrl | boolean | Reads and writes the search filters in the url. Values in `initialQueryParams` are added unless the url already has them. |
588
- | pathRoute | string | Used with `useQueryParamsFromUrl`: the part of the path from `pathRoute` is removed when the filters are written to the url. `composite.pathRoute` is not passed on, so set it here as well. |
589
-
590
- ### WaykeItemProviderSettings
591
-
592
- The same as [WaykeProviderSettings](#waykeprovidersettings), without `useQueryParamsFromUrl` and `pathRoute`. Used with `WaykeItemProvider` and `mountItem`.
592
+ All settings are optional.
593
+
594
+ | Property | Type | Description |
595
+ |------------------|---------------------------------------|-------------|
596
+ | environment | `'production' \| 'test'` | Which Wayke environment to use, see [Environments](#environments). Default `'production'`. |
597
+ | marketCode | `'SE' \| 'NO'` | Language and market, see [Language](#language). Default `'SE'`. |
598
+ | routing | [RoutingSettings](#routingsettings) | How vehicles are opened, see [Routing](#routing). |
599
+ | ecomSettings | [EcomSettings](#ecomsettings) | Turns on buy online. `{}` is enough. |
600
+ | apiKey | string | Identifies the site instead of its domain. Sent as `x-api-key`. |
601
+ | branchGroupId | string | Limits the vehicles to a group of branches. By default the domain or `apiKey` decides which vehicles are shown. |
602
+ | googleMapsApiKey | string | A Google Maps Static API key. With it, the map button on the vehicle page shows a map. Without it, the button opens Google Maps. |
603
+ | googleMapsMarker | string | Url to a custom marker for the map. |
604
+ | publicApiUrl | string | Replaces the vehicle API of `environment`. |
605
+ | leadUrl | string | Replaces the lead API of `environment`. |
606
+
607
+ ### RoutingSettings
608
+
609
+ | Property | Type | Description |
610
+ |----------|------------------------------|-------------|
611
+ | mode | `'hash' \| 'path' \| 'none'` | `hash` (default) opens a vehicle at `#<id>`, `path` at `<basePath>/<id>`, `none` makes the vehicles plain cards that only publish `ItemClicked`. |
612
+ | basePath | string | **Required for `path`.** Where the vehicle pages are, see [Routing](#routing). |
613
+ | syncUrl | boolean | Reads and writes the search filters in the url. |
593
614
 
594
615
  ### EcomSettings
595
616
 
596
617
  | Property | Type | Description |
597
618
  |--------------------|---------|-------------|
598
- | url | string | **Required.** The ecom API, see [Environments](#environments). |
619
+ | url | string | Replaces the ecom API of `environment`. |
599
620
  | serviceLogotypeUrl | string | Url to the logo shown in buy online, as an image file (not a `data:` url). The logo of the make is used by default. |
600
621
  | bankIdThumbprint | string | A custom BankID certificate thumbprint. |
601
- | useBankId | boolean | Deprecated, has no effect since 3.0.0. |
602
- | displayBankIdAlert | boolean | Deprecated, has no effect since 3.0.0. |
603
622
 
604
623
  See [wayke-ecom-web](https://github.com/wayke-se/wayke-ecom-web) for more about buy online.
605
624
 
@@ -607,5 +626,86 @@ See [wayke-ecom-web](https://github.com/wayke-se/wayke-ecom-web) for more about
607
626
 
608
627
  | Property | Type | Description |
609
628
  |-------------|--------|-------------|
610
- | filterName | string | **Required.** One of `manufacturer`, `modelSeries`, `fuelType`, `gearboxType`, `branch`, `color`, `environmentClass`, `properties.segment`, `drivingWheel`, `price`, `mileage`, `odometerValueAsKm`, `modelYear`, `leasingPrice`, `businessLeasingPrice`. |
629
+ | filterName | string | **Required.** One of `manufacturer`, `model`, `modelSeries`, `fuelType`, `gearboxType`, `branchDisplayName`, `branchCity`, `colorName`, `environmentClass`, `segment`, `bodyStyle`, `trimLevel`, `inventoryStatus`, `drivetrainType`, `engineBaseType`, `price`, `odometer`, `modelYear`, `privateLease`, `businessLease`. |
611
630
  | displayName | string | The title of the filter. The translated title by default. |
631
+
632
+ By default the list is `manufacturer`, `modelSeries`, `fuelType`, `gearboxType`, `branchDisplayName`, `colorName`, `environmentClass`, `segment`, `drivetrainType`, `price`, `privateLease`, `businessLease`, `odometer` and `modelYear`.
633
+
634
+ ## Migrating from 5.x to 6.0
635
+
636
+ 6.0 gets the vehicles from Wayke's public API (`public-api.wayke.com`) instead of `api.wayke.se` and `gql.wayke.se`, and has fewer settings: most sites only set what is different from the defaults. Leads and buy online work as before.
637
+
638
+ The old filter names, url parameters and vehicle ids keep working, with a warning in the console, so a site that only changes its settings keeps its links and saved searches.
639
+
640
+ ### 1. Provider settings
641
+
642
+ Remove the API urls. Production is the default; set `environment: 'test'` for test.
643
+
644
+ ```javascript
645
+ // 5.x
646
+ provider: {
647
+ url: 'https://api.wayke.se/vehicles',
648
+ graphQlUrl: 'https://gql.wayke.se/query',
649
+ urlMlt: 'https://api.wayke.se/vehicles-mlt-ext',
650
+ ecomSettings: { url: 'https://ecom.wayke.se' },
651
+ },
652
+
653
+ // 6.0
654
+ provider: {
655
+ ecomSettings: {},
656
+ },
657
+ ```
658
+
659
+ | 5.x | 6.0 |
660
+ |-----|-----|
661
+ | `url`, `graphQlUrl`, `urlMlt` | Removed. Use `environment` (`publicApiUrl` and `leadUrl` replace single urls if you need to) |
662
+ | `ecomSettings.url` | Optional, follows `environment` |
663
+ | `ecomSettings.useBankId`, `ecomSettings.displayBankIdAlert` | Removed, no effect since 3.0.0 |
664
+ | `useQueryParamsFromUrl` | `routing.syncUrl` |
665
+ | `pathRoute` (provider and composite) | `routing: { mode: 'path', basePath }` |
666
+ | `marketCode` (composite, search, item) | `provider.marketCode` |
667
+ | `apiKey` | Unchanged; now also identifies the site to the vehicle API |
668
+ | `WaykeItemProvider`, `WaykeItemProviderSettings` | `WaykeProvider`, `WaykeProviderSettings` |
669
+
670
+ ### 2. Routing and clicks
671
+
672
+ | 5.x | 6.0 |
673
+ |-----|-----|
674
+ | Hash routing (`#<id>`) by default in `mount` and `WaykeComposite` | Unchanged |
675
+ | `hashRoute` | Removed; hash is the default |
676
+ | `WaykeSearch` alone without `hashRoute` or `pathRoute`: plain cards | Set `routing: { mode: 'none' }`; the default is now hash links |
677
+ | `onClickSearchItem` (search and item) | Removed; subscribe to the `ItemClicked` event |
678
+
679
+ ### 3. Filters and parameters
680
+
681
+ `filterList`, `initialQueryParams`, the `onFilterUpdate` action and the url take the names in [Search parameters](#search-parameters). The old names are translated:
682
+
683
+ | 5.x | 6.0 |
684
+ |-----|-----|
685
+ | `query` | `q` |
686
+ | `branch` | `branchDisplayName` |
687
+ | `color` | `colorName` |
688
+ | `properties.segment` | `segment` |
689
+ | `drivingWheel` | `drivetrainType` |
690
+ | `mileage`, `odometerValueAsKm` | `odometer` (mil in Swedish, km in Norwegian) |
691
+ | `leasingPrice` | `privateLease` |
692
+ | `businessLeasingPrice` | `businessLease` |
693
+ | `sort=model-asc`, `model-desc`, `mileage-asc`, `mileage-desc` | `modelYear-asc`, `modelYear-desc`, `odometer-asc`, `odometer-desc` |
694
+ | `hits`, `offset` | Removed; 30 vehicles per page, "Show more" loads the next |
695
+
696
+ The search field now suggests makes and models. A free text that is exactly a make or model, such as "audi", filters on it.
697
+
698
+ ### 4. Events
699
+
700
+ The event names and data are the same. What changes:
701
+
702
+ * `query` in `Search`, `SearchInitiated`, `SearchCompleted`, `SearchClearAllFilters` uses the new parameter names.
703
+ * `filter` in `FilterApply` is the new filter name, for example `colorName` instead of `color`.
704
+ * `id` is the vehicle's id in the public API. New vehicles have new ids; older ones mostly keep theirs.
705
+
706
+ ### 5. Removed
707
+
708
+ * Central storage (switching to another branch on the vehicle page).
709
+ * The campaign filter. Dealer packages are still shown on the vehicle page.
710
+ * Related vehicles are now the latest vehicles of the same make.
711
+ * A vehicle without a cash price, such as a leasing-only car, shows no price instead of 0 kr.