@swisspost/internet-header 1.15.12 → 1.15.13
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/dist/cjs/index.cjs.js +1 -1
- package/dist/cjs/{post-internet-header-73538cc1.js → post-internet-header-a97a7cf2.js} +43 -38
- package/dist/cjs/swisspost-internet-header.cjs.entry.js +1 -1
- package/dist/collection/services/route.service.js +41 -36
- package/dist/components/swisspost-internet-header.js +43 -38
- package/dist/docs.json +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/{post-internet-header-96053f9b.js → post-internet-header-c7e6cae4.js} +43 -38
- package/dist/esm/swisspost-internet-header.entry.js +1 -1
- package/dist/esm-es5/index.js +1 -1
- package/dist/esm-es5/post-internet-header-c7e6cae4.js +1 -0
- package/dist/esm-es5/swisspost-internet-header.entry.js +1 -1
- package/dist/swisspost-internet-header/index.esm.js +1 -1
- package/dist/swisspost-internet-header/p-11de4a87.js +1 -0
- package/dist/swisspost-internet-header/p-297916c1.system.js +1 -0
- package/dist/swisspost-internet-header/p-695fe962.system.js +1 -1
- package/dist/swisspost-internet-header/{p-e5cbad90.system.js → p-876f9c55.system.js} +1 -1
- package/dist/swisspost-internet-header/{p-eb84e447.entry.js → p-b73ccb68.entry.js} +1 -1
- package/dist/swisspost-internet-header/{p-41799f6b.system.entry.js → p-e9f1c4ac.system.entry.js} +1 -1
- package/dist/swisspost-internet-header/swisspost-internet-header.esm.js +1 -1
- package/dist/types/services/route.service.d.ts +11 -11
- package/package.json +2 -2
- package/dist/esm-es5/post-internet-header-96053f9b.js +0 -1
- package/dist/swisspost-internet-header/p-2e092180.js +0 -1
- package/dist/swisspost-internet-header/p-c164ea99.system.js +0 -1
package/dist/cjs/index.cjs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const postInternetHeader = require('./post-internet-header-
|
|
5
|
+
const postInternetHeader = require('./post-internet-header-a97a7cf2.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');
|
|
@@ -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
|
|
24
|
-
let
|
|
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
|
-
|
|
32
|
+
referenceUrl = new URL(window.location.href);
|
|
32
33
|
}
|
|
33
34
|
else {
|
|
34
35
|
try {
|
|
35
|
-
|
|
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,
|
|
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
|
|
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
|
|
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,
|
|
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
|
|
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
|
|
108
|
-
const score = compareRoutes(
|
|
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
|
|
134
|
-
* @param
|
|
135
|
-
* @param
|
|
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 = (
|
|
140
|
-
|
|
141
|
-
|
|
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
|
|
145
|
-
const
|
|
146
|
-
// Exact match,
|
|
147
|
-
if (
|
|
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
|
|
151
|
-
if (
|
|
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
|
|
156
|
-
|
|
157
|
-
...
|
|
161
|
+
const referenceSegments = [
|
|
162
|
+
referenceUrl.origin.toLocaleLowerCase(),
|
|
163
|
+
...referenceUrlPath.split('/').filter(x => x !== null && x !== ''),
|
|
158
164
|
];
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
...
|
|
165
|
+
const navItemSegments = [
|
|
166
|
+
navItemUrl.origin.toLocaleLowerCase(),
|
|
167
|
+
...navItemUrlPath.split('/').filter(x => x !== null && x !== ''),
|
|
162
168
|
];
|
|
163
|
-
const score = getSimilarityScore(
|
|
164
|
-
|
|
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
|
|
172
|
-
* @param b
|
|
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.
|
|
376
|
+
const version = "1.15.13";
|
|
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.
|
|
417
|
+
"@swisspost/design-system-styles": "workspace:8.10.0",
|
|
413
418
|
"body-scroll-lock": "4.0.0-beta.0",
|
|
414
419
|
"iframe-resizer": "4.4.5",
|
|
415
420
|
jquery: "3.7.1",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const postInternetHeader = require('./post-internet-header-
|
|
5
|
+
const postInternetHeader = require('./post-internet-header-a97a7cf2.js');
|
|
6
6
|
require('./index-ecd8c9bb.js');
|
|
7
7
|
require('./index-fbcc9ff3.js');
|
|
8
8
|
require('./language.service-2a3c77d1.js');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Activate the current route based on the config and the match mode
|
|
3
3
|
* @param config Main Navigation Config
|
|
4
|
-
* @param activeRouteProp Match mode
|
|
4
|
+
* @param activeRouteProp Match mode or custom URL to compare against
|
|
5
5
|
* @returns Modified Main Navigation Config
|
|
6
6
|
*/
|
|
7
7
|
export const markActiveRoute = (config, activeRouteProp) => {
|
|
@@ -9,26 +9,28 @@ export const markActiveRoute = (config, activeRouteProp) => {
|
|
|
9
9
|
if (activeRouteProp === false) {
|
|
10
10
|
return config;
|
|
11
11
|
}
|
|
12
|
-
// Set
|
|
13
|
-
let
|
|
12
|
+
// Set reference URL to compare nav items against
|
|
13
|
+
let referenceUrl;
|
|
14
|
+
let isRelativeReference = false;
|
|
14
15
|
config = resetOverrideConfig(config);
|
|
15
16
|
if (activeRouteProp === 'auto' || activeRouteProp === 'exact') {
|
|
16
17
|
// Check if an active route is already configured, set override to that and return
|
|
17
18
|
if (hasActivePortalRoute(config)) {
|
|
18
19
|
return resetActiveStateToPortalConfig(config);
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
+
referenceUrl = new URL(window.location.href);
|
|
21
22
|
}
|
|
22
23
|
else {
|
|
23
24
|
try {
|
|
24
|
-
|
|
25
|
+
isRelativeReference = activeRouteProp.startsWith('/') || activeRouteProp.startsWith('./');
|
|
26
|
+
referenceUrl = new URL(activeRouteProp, window.location.href);
|
|
25
27
|
}
|
|
26
28
|
catch (error) {
|
|
27
29
|
console.warn(`Active Route: ${activeRouteProp} is not a valid URL. Navigation highlighting has been disabled.`);
|
|
28
30
|
return config;
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
|
-
const scoreList = compileScoreList(config,
|
|
33
|
+
const scoreList = compileScoreList(config, referenceUrl, activeRouteProp, isRelativeReference);
|
|
32
34
|
if (scoreList.length === 0) {
|
|
33
35
|
// No match found or already active links defined
|
|
34
36
|
return config;
|
|
@@ -62,13 +64,13 @@ const resetOverrideConfig = (config) => {
|
|
|
62
64
|
});
|
|
63
65
|
};
|
|
64
66
|
/**
|
|
65
|
-
* Compile a list of scores based on
|
|
67
|
+
* Compile a list of scores based on how well nav items match the reference URL
|
|
66
68
|
* @param config Main Nav Config
|
|
67
|
-
* @param
|
|
69
|
+
* @param referenceUrl URL to compare nav items against (window.location or custom)
|
|
68
70
|
* @param activeRouteProp Match mode
|
|
69
71
|
* @returns A list of scored URLs if any matched
|
|
70
72
|
*/
|
|
71
|
-
export const compileScoreList = (config,
|
|
73
|
+
export const compileScoreList = (config, referenceUrl, activeRouteProp, isRelativeReference) => {
|
|
72
74
|
// Flag to check if the Portal set any active links or if there are any exact matches
|
|
73
75
|
let hadAnyActiveLink = false;
|
|
74
76
|
const scoreList = [];
|
|
@@ -77,7 +79,8 @@ export const compileScoreList = (config, compareUrl, activeRouteProp) => {
|
|
|
77
79
|
.forEach(mainNav => {
|
|
78
80
|
var _a;
|
|
79
81
|
try {
|
|
80
|
-
const
|
|
82
|
+
const navItemUrl = new URL(mainNav.url);
|
|
83
|
+
const score = compareRoutes(referenceUrl, navItemUrl, isRelativeReference, activeRouteProp);
|
|
81
84
|
hadAnyActiveLink = updateScoreList(scoreList, score, { main: mainNav, score }, hadAnyActiveLink);
|
|
82
85
|
}
|
|
83
86
|
catch (_b) {
|
|
@@ -93,8 +96,8 @@ export const compileScoreList = (config, compareUrl, activeRouteProp) => {
|
|
|
93
96
|
return;
|
|
94
97
|
}
|
|
95
98
|
try {
|
|
96
|
-
const
|
|
97
|
-
const score = compareRoutes(
|
|
99
|
+
const flyoutNavUrl = new URL(linklist.url);
|
|
100
|
+
const score = compareRoutes(referenceUrl, flyoutNavUrl, isRelativeReference, activeRouteProp);
|
|
98
101
|
hadAnyActiveLink = updateScoreList(scoreList, score, { main: mainNav, sub: linklist, score }, hadAnyActiveLink);
|
|
99
102
|
}
|
|
100
103
|
catch (_a) {
|
|
@@ -119,46 +122,48 @@ function updateScoreList(scoreList, score, scoreListItem, hadAnyActiveLink) {
|
|
|
119
122
|
return hadActiveLink;
|
|
120
123
|
}
|
|
121
124
|
/**
|
|
122
|
-
* Compare
|
|
123
|
-
* @param
|
|
124
|
-
* @param
|
|
125
|
+
* Compare a nav item URL against the reference URL for similarity
|
|
126
|
+
* @param referenceUrl URL we're comparing against (from window.location or custom)
|
|
127
|
+
* @param navItemUrl URL from the navigation item
|
|
125
128
|
* @param matchMode exact or auto matching
|
|
126
|
-
* @returns Score
|
|
129
|
+
* @returns Score indicating how well the URLs match
|
|
127
130
|
*/
|
|
128
|
-
export const compareRoutes = (
|
|
129
|
-
|
|
130
|
-
|
|
131
|
+
export const compareRoutes = (referenceUrl, navItemUrl, isRelativeReference, matchMode) => {
|
|
132
|
+
if (referenceUrl === null || navItemUrl === null) {
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
// Only compare origins if reference URL is not relative
|
|
136
|
+
if (!isRelativeReference && referenceUrl.origin !== navItemUrl.origin) {
|
|
131
137
|
return 0;
|
|
132
138
|
}
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
// Exact match,
|
|
136
|
-
if (
|
|
139
|
+
const referenceUrlPath = referenceUrl.pathname.toLocaleLowerCase();
|
|
140
|
+
const navItemUrlPath = navItemUrl.pathname.toLocaleLowerCase();
|
|
141
|
+
// Exact match, pathname is the same
|
|
142
|
+
if (referenceUrlPath === navItemUrlPath) {
|
|
137
143
|
return Infinity;
|
|
138
144
|
}
|
|
139
|
-
// The
|
|
140
|
-
if (
|
|
145
|
+
// The reference path is shorter than nav item path, a match is impossible
|
|
146
|
+
if (referenceUrl.pathname.length < navItemUrl.pathname.length) {
|
|
141
147
|
return 0;
|
|
142
148
|
}
|
|
143
149
|
if (matchMode === 'auto') {
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
...
|
|
150
|
+
const referenceSegments = [
|
|
151
|
+
referenceUrl.origin.toLocaleLowerCase(),
|
|
152
|
+
...referenceUrlPath.split('/').filter(x => x !== null && x !== ''),
|
|
147
153
|
];
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
...
|
|
154
|
+
const navItemSegments = [
|
|
155
|
+
navItemUrl.origin.toLocaleLowerCase(),
|
|
156
|
+
...navItemUrlPath.split('/').filter(x => x !== null && x !== ''),
|
|
151
157
|
];
|
|
152
|
-
const score = getSimilarityScore(
|
|
153
|
-
|
|
154
|
-
return Math.min(baseSegments.length, compareSegments.length) === score ? score : 0;
|
|
158
|
+
const score = getSimilarityScore(referenceSegments, navItemSegments);
|
|
159
|
+
return Math.min(referenceSegments.length, navItemSegments.length) === score ? score : 0;
|
|
155
160
|
}
|
|
156
161
|
return 0;
|
|
157
162
|
};
|
|
158
163
|
/**
|
|
159
164
|
* Check how many items in an array match
|
|
160
|
-
* @param a
|
|
161
|
-
* @param b
|
|
165
|
+
* @param a Reference array
|
|
166
|
+
* @param b Nav item array to compare
|
|
162
167
|
* @returns Score
|
|
163
168
|
*/
|
|
164
169
|
export const getSimilarityScore = (a, b) => {
|
|
@@ -17,7 +17,7 @@ import { d as defineCustomElement$2 } from './post-skiplinks2.js';
|
|
|
17
17
|
/**
|
|
18
18
|
* Activate the current route based on the config and the match mode
|
|
19
19
|
* @param config Main Navigation Config
|
|
20
|
-
* @param activeRouteProp Match mode
|
|
20
|
+
* @param activeRouteProp Match mode or custom URL to compare against
|
|
21
21
|
* @returns Modified Main Navigation Config
|
|
22
22
|
*/
|
|
23
23
|
const markActiveRoute = (config, activeRouteProp) => {
|
|
@@ -25,26 +25,28 @@ const markActiveRoute = (config, activeRouteProp) => {
|
|
|
25
25
|
if (activeRouteProp === false) {
|
|
26
26
|
return config;
|
|
27
27
|
}
|
|
28
|
-
// Set
|
|
29
|
-
let
|
|
28
|
+
// Set reference URL to compare nav items against
|
|
29
|
+
let referenceUrl;
|
|
30
|
+
let isRelativeReference = false;
|
|
30
31
|
config = resetOverrideConfig(config);
|
|
31
32
|
if (activeRouteProp === 'auto' || activeRouteProp === 'exact') {
|
|
32
33
|
// Check if an active route is already configured, set override to that and return
|
|
33
34
|
if (hasActivePortalRoute(config)) {
|
|
34
35
|
return resetActiveStateToPortalConfig(config);
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
+
referenceUrl = new URL(window.location.href);
|
|
37
38
|
}
|
|
38
39
|
else {
|
|
39
40
|
try {
|
|
40
|
-
|
|
41
|
+
isRelativeReference = activeRouteProp.startsWith('/') || activeRouteProp.startsWith('./');
|
|
42
|
+
referenceUrl = new URL(activeRouteProp, window.location.href);
|
|
41
43
|
}
|
|
42
44
|
catch (error) {
|
|
43
45
|
console.warn(`Active Route: ${activeRouteProp} is not a valid URL. Navigation highlighting has been disabled.`);
|
|
44
46
|
return config;
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
|
-
const scoreList = compileScoreList(config,
|
|
49
|
+
const scoreList = compileScoreList(config, referenceUrl, activeRouteProp, isRelativeReference);
|
|
48
50
|
if (scoreList.length === 0) {
|
|
49
51
|
// No match found or already active links defined
|
|
50
52
|
return config;
|
|
@@ -78,13 +80,13 @@ const resetOverrideConfig = (config) => {
|
|
|
78
80
|
});
|
|
79
81
|
};
|
|
80
82
|
/**
|
|
81
|
-
* Compile a list of scores based on
|
|
83
|
+
* Compile a list of scores based on how well nav items match the reference URL
|
|
82
84
|
* @param config Main Nav Config
|
|
83
|
-
* @param
|
|
85
|
+
* @param referenceUrl URL to compare nav items against (window.location or custom)
|
|
84
86
|
* @param activeRouteProp Match mode
|
|
85
87
|
* @returns A list of scored URLs if any matched
|
|
86
88
|
*/
|
|
87
|
-
const compileScoreList = (config,
|
|
89
|
+
const compileScoreList = (config, referenceUrl, activeRouteProp, isRelativeReference) => {
|
|
88
90
|
// Flag to check if the Portal set any active links or if there are any exact matches
|
|
89
91
|
let hadAnyActiveLink = false;
|
|
90
92
|
const scoreList = [];
|
|
@@ -93,7 +95,8 @@ const compileScoreList = (config, compareUrl, activeRouteProp) => {
|
|
|
93
95
|
.forEach(mainNav => {
|
|
94
96
|
var _a;
|
|
95
97
|
try {
|
|
96
|
-
const
|
|
98
|
+
const navItemUrl = new URL(mainNav.url);
|
|
99
|
+
const score = compareRoutes(referenceUrl, navItemUrl, isRelativeReference, activeRouteProp);
|
|
97
100
|
hadAnyActiveLink = updateScoreList(scoreList, score, { main: mainNav, score }, hadAnyActiveLink);
|
|
98
101
|
}
|
|
99
102
|
catch (_b) {
|
|
@@ -109,8 +112,8 @@ const compileScoreList = (config, compareUrl, activeRouteProp) => {
|
|
|
109
112
|
return;
|
|
110
113
|
}
|
|
111
114
|
try {
|
|
112
|
-
const
|
|
113
|
-
const score = compareRoutes(
|
|
115
|
+
const flyoutNavUrl = new URL(linklist.url);
|
|
116
|
+
const score = compareRoutes(referenceUrl, flyoutNavUrl, isRelativeReference, activeRouteProp);
|
|
114
117
|
hadAnyActiveLink = updateScoreList(scoreList, score, { main: mainNav, sub: linklist, score }, hadAnyActiveLink);
|
|
115
118
|
}
|
|
116
119
|
catch (_a) {
|
|
@@ -135,46 +138,48 @@ function updateScoreList(scoreList, score, scoreListItem, hadAnyActiveLink) {
|
|
|
135
138
|
return hadActiveLink;
|
|
136
139
|
}
|
|
137
140
|
/**
|
|
138
|
-
* Compare
|
|
139
|
-
* @param
|
|
140
|
-
* @param
|
|
141
|
+
* Compare a nav item URL against the reference URL for similarity
|
|
142
|
+
* @param referenceUrl URL we're comparing against (from window.location or custom)
|
|
143
|
+
* @param navItemUrl URL from the navigation item
|
|
141
144
|
* @param matchMode exact or auto matching
|
|
142
|
-
* @returns Score
|
|
145
|
+
* @returns Score indicating how well the URLs match
|
|
143
146
|
*/
|
|
144
|
-
const compareRoutes = (
|
|
145
|
-
|
|
146
|
-
|
|
147
|
+
const compareRoutes = (referenceUrl, navItemUrl, isRelativeReference, matchMode) => {
|
|
148
|
+
if (referenceUrl === null || navItemUrl === null) {
|
|
149
|
+
return 0;
|
|
150
|
+
}
|
|
151
|
+
// Only compare origins if reference URL is not relative
|
|
152
|
+
if (!isRelativeReference && referenceUrl.origin !== navItemUrl.origin) {
|
|
147
153
|
return 0;
|
|
148
154
|
}
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
// Exact match,
|
|
152
|
-
if (
|
|
155
|
+
const referenceUrlPath = referenceUrl.pathname.toLocaleLowerCase();
|
|
156
|
+
const navItemUrlPath = navItemUrl.pathname.toLocaleLowerCase();
|
|
157
|
+
// Exact match, pathname is the same
|
|
158
|
+
if (referenceUrlPath === navItemUrlPath) {
|
|
153
159
|
return Infinity;
|
|
154
160
|
}
|
|
155
|
-
// The
|
|
156
|
-
if (
|
|
161
|
+
// The reference path is shorter than nav item path, a match is impossible
|
|
162
|
+
if (referenceUrl.pathname.length < navItemUrl.pathname.length) {
|
|
157
163
|
return 0;
|
|
158
164
|
}
|
|
159
165
|
if (matchMode === 'auto') {
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
...
|
|
166
|
+
const referenceSegments = [
|
|
167
|
+
referenceUrl.origin.toLocaleLowerCase(),
|
|
168
|
+
...referenceUrlPath.split('/').filter(x => x !== null && x !== ''),
|
|
163
169
|
];
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
...
|
|
170
|
+
const navItemSegments = [
|
|
171
|
+
navItemUrl.origin.toLocaleLowerCase(),
|
|
172
|
+
...navItemUrlPath.split('/').filter(x => x !== null && x !== ''),
|
|
167
173
|
];
|
|
168
|
-
const score = getSimilarityScore(
|
|
169
|
-
|
|
170
|
-
return Math.min(baseSegments.length, compareSegments.length) === score ? score : 0;
|
|
174
|
+
const score = getSimilarityScore(referenceSegments, navItemSegments);
|
|
175
|
+
return Math.min(referenceSegments.length, navItemSegments.length) === score ? score : 0;
|
|
171
176
|
}
|
|
172
177
|
return 0;
|
|
173
178
|
};
|
|
174
179
|
/**
|
|
175
180
|
* Check how many items in an array match
|
|
176
|
-
* @param a
|
|
177
|
-
* @param b
|
|
181
|
+
* @param a Reference array
|
|
182
|
+
* @param b Nav item array to compare
|
|
178
183
|
* @returns Score
|
|
179
184
|
*/
|
|
180
185
|
const getSimilarityScore = (a, b) => {
|
|
@@ -373,7 +378,7 @@ const setMainNavigationIds = (navMainEntities) => {
|
|
|
373
378
|
};
|
|
374
379
|
|
|
375
380
|
const name = "@swisspost/internet-header";
|
|
376
|
-
const version = "1.15.
|
|
381
|
+
const version = "1.15.13";
|
|
377
382
|
const description = "The header for client facing applications.";
|
|
378
383
|
const author = "Swiss Post <design-system@post.ch>";
|
|
379
384
|
const license = "Apache-2.0";
|
|
@@ -414,7 +419,7 @@ const scripts = {
|
|
|
414
419
|
generate: "stencil generate"
|
|
415
420
|
};
|
|
416
421
|
const dependencies = {
|
|
417
|
-
"@swisspost/design-system-styles": "workspace:8.
|
|
422
|
+
"@swisspost/design-system-styles": "workspace:8.10.0",
|
|
418
423
|
"body-scroll-lock": "4.0.0-beta.0",
|
|
419
424
|
"iframe-resizer": "4.4.5",
|
|
420
425
|
jquery: "3.7.1",
|
package/dist/docs.json
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { P as PostInternetHeader } from './post-internet-header-
|
|
1
|
+
export { P as PostInternetHeader } from './post-internet-header-c7e6cae4.js';
|
|
2
2
|
export { P as PostInternetBreadcrumbs } from './post-internet-breadcrumbs-853096c4.js';
|
|
3
3
|
export { P as PostInternetFooter } from './post-internet-footer-3a7024bf.js';
|
|
4
4
|
export { P as PostSkiplinks } from './post-skiplinks-8c64cda3.js';
|