@postnord/pn-marketweb-components 1.0.17 → 1.0.21
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/cjs/MarketWebContextService-420668a7.js +166 -0
- package/cjs/loader.cjs.js +1 -1
- package/cjs/pn-filter-checkbox.cjs.entry.js +67 -0
- package/cjs/pn-language-selector_9.cjs.entry.js +34 -11
- package/cjs/pn-mainnav-link.cjs.entry.js +1 -1
- package/cjs/{pn-mainnav-store-661b0b11.js → pn-mainnav-store-87a95686.js} +1 -0
- package/cjs/pn-market-web-components.cjs.js +1 -1
- package/cjs/pn-marketweb-sitefooter.cjs.entry.js +48 -6
- package/cjs/pn-marketweb-siteheader.cjs.entry.js +62 -9
- package/collection/collection-manifest.json +1 -0
- package/collection/components/input/pn-filter-checkbox/checkbox.stories.js +34 -0
- package/collection/components/input/pn-filter-checkbox/pn-filter-checkbox.css +73 -0
- package/collection/components/input/pn-filter-checkbox/pn-filter-checkbox.js +183 -0
- package/collection/components/layout-components/pn-marketweb-sitefooter/pn-marketweb-sitefooter.js +75 -12
- package/collection/components/layout-components/pn-marketweb-sitefooter/pn-marketweb-sitefooter.stories.js +16 -0
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login.js +8 -1
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.js +172 -68
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.stories.js +23 -12
- package/collection/components/navigation/pn-language-selector/pn-language-selector.js +28 -7
- package/collection/components/navigation/pn-mainnav/pn-mainnav-level.css +3 -0
- package/collection/components/navigation/pn-mainnav/pn-mainnav-level.js +5 -1
- package/collection/components/navigation/pn-mainnav/pn-mainnav-store.js +1 -0
- package/collection/components/navigation/pn-mainnav/pn-mainnav.js +1 -1
- package/collection/components/navigation/pn-site-selector/pn-site-selector.js +6 -6
- package/collection/globals/MarketWebContextService.js +163 -0
- package/custom-elements/index.d.ts +6 -0
- package/custom-elements/index.js +376 -32
- package/esm/MarketWebContextService-9a201388.js +164 -0
- package/esm/loader.js +1 -1
- package/esm/pn-filter-checkbox.entry.js +63 -0
- package/esm/pn-language-selector_9.entry.js +34 -11
- package/esm/pn-mainnav-link.entry.js +1 -1
- package/esm/{pn-mainnav-store-4b030e31.js → pn-mainnav-store-8e518460.js} +1 -0
- package/esm/pn-market-web-components.js +1 -1
- package/esm/pn-marketweb-sitefooter.entry.js +48 -6
- package/esm/pn-marketweb-siteheader.entry.js +63 -10
- package/esm-es5/MarketWebContextService-9a201388.js +1 -0
- package/esm-es5/loader.js +1 -1
- package/esm-es5/pn-filter-checkbox.entry.js +1 -0
- package/esm-es5/pn-language-selector_9.entry.js +1 -1
- package/esm-es5/pn-mainnav-link.entry.js +1 -1
- package/esm-es5/pn-mainnav-store-8e518460.js +1 -0
- package/esm-es5/pn-market-web-components.js +1 -1
- package/esm-es5/pn-marketweb-sitefooter.entry.js +1 -1
- package/esm-es5/pn-marketweb-siteheader.entry.js +1 -1
- package/package.json +2 -2
- package/pn-market-web-components/p-02eed66e.system.entry.js +1 -0
- package/pn-market-web-components/{p-facf4ecb.system.entry.js → p-251d44f2.system.entry.js} +1 -1
- package/pn-market-web-components/p-25bdf3f8.system.js +1 -1
- package/pn-market-web-components/p-2da203c9.system.entry.js +1 -0
- package/pn-market-web-components/p-363a27ff.entry.js +1 -0
- package/pn-market-web-components/p-582dbd9c.entry.js +1 -0
- package/pn-market-web-components/p-64dc840d.js +1 -0
- package/pn-market-web-components/p-86a9f853.system.js +1 -0
- package/pn-market-web-components/p-8c072330.entry.js +1 -0
- package/pn-market-web-components/p-8d62c46f.system.entry.js +1 -0
- package/pn-market-web-components/p-8dad5ed9.js +1 -0
- package/pn-market-web-components/p-a320fe58.system.js +1 -0
- package/pn-market-web-components/p-ae0e5fd8.entry.js +1 -0
- package/pn-market-web-components/{p-f7d60229.entry.js → p-e220ea83.entry.js} +1 -1
- package/pn-market-web-components/p-ecfabe25.system.entry.js +1 -0
- package/pn-market-web-components/pn-market-web-components.esm.js +1 -1
- package/types/components/input/pn-filter-checkbox/pn-filter-checkbox.d.ts +22 -0
- package/types/components/layout-components/pn-marketweb-sitefooter/pn-marketweb-sitefooter.d.ts +5 -0
- package/types/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.d.ts +8 -0
- package/types/components/navigation/pn-language-selector/pn-language-selector.d.ts +2 -0
- package/types/components/navigation/pn-mainnav/pn-mainnav-store.d.ts +2 -0
- package/types/components.d.ts +61 -0
- package/types/globals/MarketWebContextService.d.ts +51 -0
- package/esm-es5/pn-mainnav-store-4b030e31.js +0 -1
- package/pn-market-web-components/p-6b735c44.system.js +0 -1
- package/pn-market-web-components/p-a74e5481.js +0 -1
- package/pn-market-web-components/p-b80600a3.system.entry.js +0 -1
- package/pn-market-web-components/p-cc6e3bcb.entry.js +0 -1
- package/pn-market-web-components/p-d2da364d.system.entry.js +0 -1
- package/pn-market-web-components/p-ed135751.entry.js +0 -1
- package/pn-market-web-components/p-f55ad3f8.system.entry.js +0 -1
- package/pn-market-web-components/p-f5dddd2d.entry.js +0 -1
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
class MarketWebContextService {
|
|
2
|
+
constructor(href = window.location.href) {
|
|
3
|
+
this.href = "";
|
|
4
|
+
this.market = "";
|
|
5
|
+
this.language = "";
|
|
6
|
+
this.environment = "";
|
|
7
|
+
this.url = null;
|
|
8
|
+
this.allowedLanguages = ["sv", "da", "fi", "no", "en"];
|
|
9
|
+
this.allowedMarkets = ["se", "dk", "fi", "no", "com"];
|
|
10
|
+
this.developmentDomains = ["localhost", ".local", "local.", ".dev", "dev."];
|
|
11
|
+
this.markets = {
|
|
12
|
+
"se": {
|
|
13
|
+
fallbackLanguage: "sv",
|
|
14
|
+
},
|
|
15
|
+
"dk": {
|
|
16
|
+
fallbackLanguage: "da",
|
|
17
|
+
},
|
|
18
|
+
"fi": {
|
|
19
|
+
fallbackLanguage: "fi",
|
|
20
|
+
},
|
|
21
|
+
"no": {
|
|
22
|
+
fallbackLanguage: "no",
|
|
23
|
+
},
|
|
24
|
+
"com": {
|
|
25
|
+
fallbackLanguage: "en",
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
this.environmentTypes = ["integration", "preproduction", "production"];
|
|
29
|
+
this.environments = {
|
|
30
|
+
"production": {
|
|
31
|
+
"name": "production",
|
|
32
|
+
"url": "https://com-production.postnord.com/"
|
|
33
|
+
},
|
|
34
|
+
"preproduction": {
|
|
35
|
+
"name": "preproduction",
|
|
36
|
+
"url": "https://com-preproduction.postnord.com/"
|
|
37
|
+
},
|
|
38
|
+
"integration": {
|
|
39
|
+
"name": "integration",
|
|
40
|
+
"url": "https://com-integration.postnord.com/"
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
this.href = href;
|
|
44
|
+
this.url = new URL(this.href);
|
|
45
|
+
}
|
|
46
|
+
async getLanguage() {
|
|
47
|
+
if (this.language) {
|
|
48
|
+
return this.language;
|
|
49
|
+
}
|
|
50
|
+
await this.resolveLanguage();
|
|
51
|
+
return this.language;
|
|
52
|
+
}
|
|
53
|
+
async getMarket() {
|
|
54
|
+
if (this.market) {
|
|
55
|
+
return this.market;
|
|
56
|
+
}
|
|
57
|
+
await this.resolveMarket();
|
|
58
|
+
return this.market;
|
|
59
|
+
}
|
|
60
|
+
async getEndpoint(environmentName) {
|
|
61
|
+
if (this.environments[environmentName]) {
|
|
62
|
+
return this.environments[environmentName].url;
|
|
63
|
+
}
|
|
64
|
+
return this.environments.production.url;
|
|
65
|
+
}
|
|
66
|
+
async getEnvironmentName() {
|
|
67
|
+
const likelyEnvironment = this.environmentTypes.filter(x => this.url.hostname.indexOf(('-' + x)) !== -1)[0];
|
|
68
|
+
if (likelyEnvironment) {
|
|
69
|
+
this.environment = likelyEnvironment;
|
|
70
|
+
return this.environment;
|
|
71
|
+
}
|
|
72
|
+
if (this.url.hostname.indexOf('www.') !== -1) {
|
|
73
|
+
this.environment = this.environments.production.name;
|
|
74
|
+
return this.environment;
|
|
75
|
+
}
|
|
76
|
+
this.environment = this.environments.integration.name;
|
|
77
|
+
return this.environment;
|
|
78
|
+
}
|
|
79
|
+
isDevEnvironment() {
|
|
80
|
+
const matchedDevEnvironment = this.developmentDomains.filter(x => this.url.hostname.indexOf(x) !== -1)[0];
|
|
81
|
+
return matchedDevEnvironment.length > 0;
|
|
82
|
+
}
|
|
83
|
+
async resolveMarket() {
|
|
84
|
+
// Resolve market from www domains
|
|
85
|
+
if (this.href.indexOf("//www.") !== -1) {
|
|
86
|
+
const domainRoot = this.url.hostname.substring(this.url.hostname.lastIndexOf('.') + 1, this.url.hostname.length);
|
|
87
|
+
if (domainRoot && this.markets[domainRoot]) {
|
|
88
|
+
this.market = domainRoot;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
console.warn("Unable to define market from www. domain", this.href);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Check if domains are on one of the integration environments
|
|
95
|
+
const likelyEnvironment = this.environmentTypes.filter(x => this.url.hostname.indexOf(('-' + x)) !== -1);
|
|
96
|
+
if (!this.market && likelyEnvironment && likelyEnvironment.length > 0) {
|
|
97
|
+
const matchedEnvironment = likelyEnvironment[0];
|
|
98
|
+
const marketPrefix = this.url.hostname.substring(0, this.url.hostname.indexOf('-' + matchedEnvironment));
|
|
99
|
+
if (marketPrefix && this.markets[marketPrefix]) {
|
|
100
|
+
this.market = marketPrefix;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
console.warn("Unable to define market from preset environment names", this.href);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Check if we're on a development environment
|
|
107
|
+
if (!this.market) {
|
|
108
|
+
const matchedDevEnvironment = this.developmentDomains.filter(x => this.url.hostname.indexOf(x) !== -1)[0];
|
|
109
|
+
if (!matchedDevEnvironment) {
|
|
110
|
+
// Fallback to first allowed market
|
|
111
|
+
this.market = this.allowedMarkets[0];
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const urlWithoutDomain = this.href.replace(matchedDevEnvironment, "");
|
|
115
|
+
// We see if the dev environment contains something like /dk
|
|
116
|
+
let matchedMarket = this.allowedMarkets.filter(x => {
|
|
117
|
+
const typesOfFallback = ['.' + x, x + '.', '/' + x + '/']; // Ex /dk, dk.html, /dk/
|
|
118
|
+
const matchedTypeOfFallback = typesOfFallback.filter(y => urlWithoutDomain.indexOf(y) !== -1);
|
|
119
|
+
return matchedTypeOfFallback.length > 0;
|
|
120
|
+
})[0];
|
|
121
|
+
if (matchedMarket) {
|
|
122
|
+
this.market = matchedMarket;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
// We do a similar filter for subpaths but for language this time
|
|
126
|
+
let filteredMarket = Object.entries(this.markets).filter((item) => {
|
|
127
|
+
const typesOfFallback = ['.' + item[1].fallbackLanguage, item[1].fallbackLanguage + '.', '/' + item[1].fallbackLanguage + '/']; // Ex /dk, dk.html, /dk/
|
|
128
|
+
const matchedTypeOfFallback = typesOfFallback.filter(y => urlWithoutDomain.indexOf(y) !== -1);
|
|
129
|
+
return matchedTypeOfFallback.length > 0;
|
|
130
|
+
})[0];
|
|
131
|
+
if (filteredMarket && filteredMarket[0]) {
|
|
132
|
+
this.market = filteredMarket[0];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (!this.market) {
|
|
136
|
+
console.info("Was unable to detect market, used fallback");
|
|
137
|
+
this.market = this.allowedMarkets[0];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async resolveLanguage() {
|
|
142
|
+
var _a, _b, _c, _d;
|
|
143
|
+
if (this.language) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const potentialLanguages = [
|
|
147
|
+
(_a = document.querySelector("html[lang]")) === null || _a === void 0 ? void 0 : _a.getAttribute("lang"),
|
|
148
|
+
(_b = document.querySelector('[http-equiv="content-language"][content]')) === null || _b === void 0 ? void 0 : _b.getAttribute("content"),
|
|
149
|
+
(_c = document.querySelector('[property="og:locale"][content]')) === null || _c === void 0 ? void 0 : _c.getAttribute("content"),
|
|
150
|
+
(_d = document.querySelector("[lang]")) === null || _d === void 0 ? void 0 : _d.getAttribute("lang"),
|
|
151
|
+
];
|
|
152
|
+
potentialLanguages.filter(x => x).forEach((language) => {
|
|
153
|
+
if (this.allowedLanguages.indexOf(language)) {
|
|
154
|
+
this.language = language;
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
if (!this.language && this.market) {
|
|
159
|
+
this.language = this.markets[this.market].fallbackLanguage;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export { MarketWebContextService };
|
|
@@ -8,6 +8,12 @@ export const PnChoiceButton: {
|
|
|
8
8
|
new (): PnChoiceButton;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
+
interface PnFilterCheckbox extends Components.PnFilterCheckbox, HTMLElement {}
|
|
12
|
+
export const PnFilterCheckbox: {
|
|
13
|
+
prototype: PnFilterCheckbox;
|
|
14
|
+
new (): PnFilterCheckbox;
|
|
15
|
+
};
|
|
16
|
+
|
|
11
17
|
interface PnFilterSearch extends Components.PnFilterSearch, HTMLElement {}
|
|
12
18
|
export const PnFilterSearch: {
|
|
13
19
|
prototype: PnFilterSearch;
|