@swisspost/internet-header 1.15.12 → 1.15.14

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 (42) hide show
  1. package/dist/cjs/index.cjs.js +2 -2
  2. package/dist/cjs/{post-internet-header-73538cc1.js → post-internet-header-47db5e7d.js} +43 -38
  3. package/dist/cjs/post-search-5990da07.js +603 -0
  4. package/dist/cjs/post-search.cjs.entry.js +1 -1
  5. package/dist/cjs/swisspost-internet-header.cjs.entry.js +1 -1
  6. package/dist/collection/components/post-search/post-search.css +1 -1
  7. package/dist/collection/services/route.service.js +41 -36
  8. package/dist/components/post-search2.js +1 -1
  9. package/dist/components/swisspost-internet-header.js +43 -38
  10. package/dist/docs.json +1 -1
  11. package/dist/esm/index.js +2 -2
  12. package/dist/esm/{post-internet-header-96053f9b.js → post-internet-header-9d752aa2.js} +43 -38
  13. package/dist/esm/post-search-814427e8.js +601 -0
  14. package/dist/esm/post-search.entry.js +1 -1
  15. package/dist/esm/swisspost-internet-header.entry.js +1 -1
  16. package/dist/esm-es5/index.js +1 -1
  17. package/dist/esm-es5/post-internet-header-9d752aa2.js +1 -0
  18. package/dist/esm-es5/post-search-814427e8.js +1 -0
  19. package/dist/esm-es5/post-search.entry.js +1 -1
  20. package/dist/esm-es5/swisspost-internet-header.entry.js +1 -1
  21. package/dist/swisspost-internet-header/index.esm.js +1 -1
  22. package/dist/swisspost-internet-header/{p-fcdc1363.entry.js → p-0518eae1.entry.js} +1 -1
  23. package/dist/swisspost-internet-header/{p-e5cbad90.system.js → p-3a52d871.system.js} +1 -1
  24. package/dist/swisspost-internet-header/p-46fb08ff.system.js +1 -0
  25. package/dist/swisspost-internet-header/p-4dbf53e6.system.js +1 -0
  26. package/dist/swisspost-internet-header/p-695fe962.system.js +1 -1
  27. package/dist/swisspost-internet-header/p-75fb959c.js +1 -0
  28. package/dist/swisspost-internet-header/{p-41799f6b.system.entry.js → p-899a3c69.system.entry.js} +1 -1
  29. package/dist/swisspost-internet-header/{p-eb84e447.entry.js → p-9a8c8349.entry.js} +1 -1
  30. package/dist/swisspost-internet-header/{p-54a5d06a.system.entry.js → p-caf85cd6.system.entry.js} +1 -1
  31. package/dist/swisspost-internet-header/p-ed62821f.js +1 -0
  32. package/dist/swisspost-internet-header/swisspost-internet-header.esm.js +1 -1
  33. package/dist/types/services/route.service.d.ts +11 -11
  34. package/package.json +2 -2
  35. package/dist/cjs/post-search-b188f1a0.js +0 -603
  36. package/dist/esm/post-search-5ebe2715.js +0 -601
  37. package/dist/esm-es5/post-internet-header-96053f9b.js +0 -1
  38. package/dist/esm-es5/post-search-5ebe2715.js +0 -1
  39. package/dist/swisspost-internet-header/p-2e092180.js +0 -1
  40. package/dist/swisspost-internet-header/p-c073b381.system.js +0 -1
  41. package/dist/swisspost-internet-header/p-c164ea99.system.js +0 -1
  42. package/dist/swisspost-internet-header/p-c2ec169e.js +0 -1
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const postInternetHeader = require('./post-internet-header-73538cc1.js');
5
+ const postInternetHeader = require('./post-internet-header-47db5e7d.js');
6
6
  const postInternetBreadcrumbs = require('./post-internet-breadcrumbs-ba6c9c31.js');
7
7
  const postInternetFooter = require('./post-internet-footer-69042a11.js');
8
8
  const postSkiplinks = require('./post-skiplinks-894eb1ca.js');
@@ -10,7 +10,7 @@ const postMetaNavigation = require('./post-meta-navigation-f92f8f4c.js');
10
10
  const postLanguageSwitch = require('./post-language-switch-f5f3d5bf.js');
11
11
  const postLogo = require('./post-logo-bcf3b0a3.js');
12
12
  const postMainNavigation = require('./post-main-navigation-c228865d.js');
13
- const postSearch = require('./post-search-b188f1a0.js');
13
+ const postSearch = require('./post-search-5990da07.js');
14
14
  const postKlpLoginWidget = require('./post-klp-login-widget-c7da014b.js');
15
15
  require('./index-ecd8c9bb.js');
16
16
  require('./index-fbcc9ff3.js');
@@ -12,7 +12,7 @@ const if_component = require('./if.component-31542061.js');
12
12
  /**
13
13
  * Activate the current route based on the config and the match mode
14
14
  * @param config Main Navigation Config
15
- * @param activeRouteProp Match mode
15
+ * @param activeRouteProp Match mode or custom URL to compare against
16
16
  * @returns Modified Main Navigation Config
17
17
  */
18
18
  const markActiveRoute = (config, activeRouteProp) => {
@@ -20,26 +20,28 @@ const markActiveRoute = (config, activeRouteProp) => {
20
20
  if (activeRouteProp === false) {
21
21
  return config;
22
22
  }
23
- // Set compare URL and check if activeRouteProp is valid
24
- let compareUrl;
23
+ // Set reference URL to compare nav items against
24
+ let referenceUrl;
25
+ let isRelativeReference = false;
25
26
  config = resetOverrideConfig(config);
26
27
  if (activeRouteProp === 'auto' || activeRouteProp === 'exact') {
27
28
  // Check if an active route is already configured, set override to that and return
28
29
  if (hasActivePortalRoute(config)) {
29
30
  return resetActiveStateToPortalConfig(config);
30
31
  }
31
- compareUrl = new URL(window.location.href);
32
+ referenceUrl = new URL(window.location.href);
32
33
  }
33
34
  else {
34
35
  try {
35
- compareUrl = new URL(activeRouteProp, document.location.origin);
36
+ isRelativeReference = activeRouteProp.startsWith('/') || activeRouteProp.startsWith('./');
37
+ referenceUrl = new URL(activeRouteProp, window.location.href);
36
38
  }
37
39
  catch (error) {
38
40
  console.warn(`Active Route: ${activeRouteProp} is not a valid URL. Navigation highlighting has been disabled.`);
39
41
  return config;
40
42
  }
41
43
  }
42
- const scoreList = compileScoreList(config, compareUrl, activeRouteProp);
44
+ const scoreList = compileScoreList(config, referenceUrl, activeRouteProp, isRelativeReference);
43
45
  if (scoreList.length === 0) {
44
46
  // No match found or already active links defined
45
47
  return config;
@@ -73,13 +75,13 @@ const resetOverrideConfig = (config) => {
73
75
  });
74
76
  };
75
77
  /**
76
- * Compile a list of scores based on the map mode, sorted in descending order
78
+ * Compile a list of scores based on how well nav items match the reference URL
77
79
  * @param config Main Nav Config
78
- * @param compareUrl Current Browser URL or a custom URL
80
+ * @param referenceUrl URL to compare nav items against (window.location or custom)
79
81
  * @param activeRouteProp Match mode
80
82
  * @returns A list of scored URLs if any matched
81
83
  */
82
- const compileScoreList = (config, compareUrl, activeRouteProp) => {
84
+ const compileScoreList = (config, referenceUrl, activeRouteProp, isRelativeReference) => {
83
85
  // Flag to check if the Portal set any active links or if there are any exact matches
84
86
  let hadAnyActiveLink = false;
85
87
  const scoreList = [];
@@ -88,7 +90,8 @@ const compileScoreList = (config, compareUrl, activeRouteProp) => {
88
90
  .forEach(mainNav => {
89
91
  var _a;
90
92
  try {
91
- const score = compareRoutes(compareUrl, new URL(mainNav.url), activeRouteProp);
93
+ const navItemUrl = new URL(mainNav.url);
94
+ const score = compareRoutes(referenceUrl, navItemUrl, isRelativeReference, activeRouteProp);
92
95
  hadAnyActiveLink = updateScoreList(scoreList, score, { main: mainNav, score }, hadAnyActiveLink);
93
96
  }
94
97
  catch (_b) {
@@ -104,8 +107,8 @@ const compileScoreList = (config, compareUrl, activeRouteProp) => {
104
107
  return;
105
108
  }
106
109
  try {
107
- const url = new URL(linklist.url);
108
- const score = compareRoutes(compareUrl, url, activeRouteProp);
110
+ const flyoutNavUrl = new URL(linklist.url);
111
+ const score = compareRoutes(referenceUrl, flyoutNavUrl, isRelativeReference, activeRouteProp);
109
112
  hadAnyActiveLink = updateScoreList(scoreList, score, { main: mainNav, sub: linklist, score }, hadAnyActiveLink);
110
113
  }
111
114
  catch (_a) {
@@ -130,46 +133,48 @@ function updateScoreList(scoreList, score, scoreListItem, hadAnyActiveLink) {
130
133
  return hadActiveLink;
131
134
  }
132
135
  /**
133
- * Compare two URLs for similarity based on a match mode
134
- * @param baseUrl Browser URL
135
- * @param compareUrl Navigatgion URL
136
+ * Compare a nav item URL against the reference URL for similarity
137
+ * @param referenceUrl URL we're comparing against (from window.location or custom)
138
+ * @param navItemUrl URL from the navigation item
136
139
  * @param matchMode exact or auto matching
137
- * @returns Score
140
+ * @returns Score indicating how well the URLs match
138
141
  */
139
- const compareRoutes = (baseUrl, compareUrl, matchMode) => {
140
- // One url is not defined or they don't share the same orign
141
- if (baseUrl === null || compareUrl === null || baseUrl.origin !== compareUrl.origin) {
142
+ const compareRoutes = (referenceUrl, navItemUrl, isRelativeReference, matchMode) => {
143
+ if (referenceUrl === null || navItemUrl === null) {
144
+ return 0;
145
+ }
146
+ // Only compare origins if reference URL is not relative
147
+ if (!isRelativeReference && referenceUrl.origin !== navItemUrl.origin) {
142
148
  return 0;
143
149
  }
144
- const baseUrlPath = baseUrl.pathname.toLocaleLowerCase();
145
- const compareUrlPath = compareUrl.pathname.toLocaleLowerCase();
146
- // Exact match, origin and pathname are the same
147
- if (baseUrlPath === compareUrlPath) {
150
+ const referenceUrlPath = referenceUrl.pathname.toLocaleLowerCase();
151
+ const navItemUrlPath = navItemUrl.pathname.toLocaleLowerCase();
152
+ // Exact match, pathname is the same
153
+ if (referenceUrlPath === navItemUrlPath) {
148
154
  return Infinity;
149
155
  }
150
- // The basepath is longer than the comparison, a match is impossible
151
- if (baseUrl.pathname.length < compareUrl.pathname.length) {
156
+ // The reference path is shorter than nav item path, a match is impossible
157
+ if (referenceUrl.pathname.length < navItemUrl.pathname.length) {
152
158
  return 0;
153
159
  }
154
160
  if (matchMode === 'auto') {
155
- const baseSegments = [
156
- baseUrl.origin.toLocaleLowerCase(),
157
- ...baseUrlPath.split('/').filter(x => x !== null && x !== ''),
161
+ const referenceSegments = [
162
+ referenceUrl.origin.toLocaleLowerCase(),
163
+ ...referenceUrlPath.split('/').filter(x => x !== null && x !== ''),
158
164
  ];
159
- const compareSegments = [
160
- compareUrl.origin.toLocaleLowerCase(),
161
- ...compareUrlPath.split('/').filter(x => x !== null && x !== ''),
165
+ const navItemSegments = [
166
+ navItemUrl.origin.toLocaleLowerCase(),
167
+ ...navItemUrlPath.split('/').filter(x => x !== null && x !== ''),
162
168
  ];
163
- const score = getSimilarityScore(baseSegments, compareSegments);
164
- // If only some segments match, but not the whole smaller array, it's not a match
165
- return Math.min(baseSegments.length, compareSegments.length) === score ? score : 0;
169
+ const score = getSimilarityScore(referenceSegments, navItemSegments);
170
+ return Math.min(referenceSegments.length, navItemSegments.length) === score ? score : 0;
166
171
  }
167
172
  return 0;
168
173
  };
169
174
  /**
170
175
  * Check how many items in an array match
171
- * @param a Base array
172
- * @param b Compare array
176
+ * @param a Reference array
177
+ * @param b Nav item array to compare
173
178
  * @returns Score
174
179
  */
175
180
  const getSimilarityScore = (a, b) => {
@@ -368,7 +373,7 @@ const setMainNavigationIds = (navMainEntities) => {
368
373
  };
369
374
 
370
375
  const name = "@swisspost/internet-header";
371
- const version = "1.15.12";
376
+ const version = "1.15.14";
372
377
  const description = "The header for client facing applications.";
373
378
  const author = "Swiss Post <design-system@post.ch>";
374
379
  const license = "Apache-2.0";
@@ -409,7 +414,7 @@ const scripts = {
409
414
  generate: "stencil generate"
410
415
  };
411
416
  const dependencies = {
412
- "@swisspost/design-system-styles": "workspace:8.9.4",
417
+ "@swisspost/design-system-styles": "workspace:9.0.0",
413
418
  "body-scroll-lock": "4.0.0-beta.0",
414
419
  "iframe-resizer": "4.4.5",
415
420
  jquery: "3.7.1",