@postnord/pn-marketweb-components 1.0.35 → 1.0.36
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/FetchHelper-f80943bf.js +87 -0
- package/cjs/loader.cjs.js +1 -1
- package/cjs/pn-mainnav-link.cjs.entry.js +1 -1
- package/cjs/pn-market-web-components.cjs.js +1 -1
- package/cjs/pn-marketweb-sitefooter.cjs.entry.js +15 -2
- package/cjs/pn-marketweb-siteheader.cjs.entry.js +22 -13
- package/collection/components/layout-components/pn-marketweb-sitefooter/pn-marketweb-sitefooter.js +33 -2
- package/collection/components/layout-components/pn-marketweb-sitefooter/pn-marketweb-sitefooter.stories.js +3 -3
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.js +40 -13
- package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.stories.js +2 -1
- package/collection/components/navigation/pn-mainnav/pn-mainnav-link.js +1 -1
- package/collection/globals/FetchHelper.js +84 -0
- package/custom-elements/index.js +122 -18
- package/esm/FetchHelper-a0c8aa54.js +85 -0
- package/esm/loader.js +1 -1
- package/esm/pn-mainnav-link.entry.js +1 -1
- package/esm/pn-market-web-components.js +1 -1
- package/esm/pn-marketweb-sitefooter.entry.js +15 -2
- package/esm/pn-marketweb-siteheader.entry.js +22 -13
- package/esm-es5/FetchHelper-a0c8aa54.js +1 -0
- package/esm-es5/loader.js +1 -1
- package/esm-es5/pn-mainnav-link.entry.js +1 -1
- 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 +1 -1
- package/pn-market-web-components/p-25bdf3f8.system.js +1 -1
- package/pn-market-web-components/p-4921fcc3.entry.js +1 -0
- package/pn-market-web-components/p-4f1a53f4.entry.js +1 -0
- package/pn-market-web-components/p-6d718a66.system.entry.js +1 -0
- package/pn-market-web-components/p-97dc5687.js +1 -0
- package/pn-market-web-components/p-d6a17042.system.js +1 -0
- package/pn-market-web-components/p-daa6ddb3.system.entry.js +1 -0
- package/pn-market-web-components/p-dc471243.entry.js +1 -0
- package/pn-market-web-components/{p-251d44f2.system.entry.js → p-e3fb52a6.system.entry.js} +1 -1
- package/pn-market-web-components/pn-market-web-components.esm.js +1 -1
- 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 +5 -0
- package/types/components.d.ts +16 -0
- package/types/globals/FetchHelper.d.ts +17 -0
- package/pn-market-web-components/p-031d91aa.entry.js +0 -1
- package/pn-market-web-components/p-134f14eb.system.entry.js +0 -1
- package/pn-market-web-components/p-2f494f64.system.entry.js +0 -1
- package/pn-market-web-components/p-3562a62f.entry.js +0 -1
- package/pn-market-web-components/p-e220ea83.entry.js +0 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class FetchHelper {
|
|
4
|
+
constructor(namespace = "") {
|
|
5
|
+
this.storagePrefix = "";
|
|
6
|
+
this.store = {
|
|
7
|
+
get: (key, permanentStorageFirst = false) => {
|
|
8
|
+
const firstProfider = permanentStorageFirst ? window.localStorage : window.sessionStorage;
|
|
9
|
+
const secondProvider = permanentStorageFirst ? window.sessionStorage : window.localStorage;
|
|
10
|
+
let value = firstProfider.getItem(`${this.storagePrefix}-${key}`);
|
|
11
|
+
if (!value) {
|
|
12
|
+
value = secondProvider.getItem(`${this.storagePrefix}-${key}`);
|
|
13
|
+
}
|
|
14
|
+
if (!value) {
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
if (value.indexOf('{') === 0) {
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(value);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (value.indexOf(',') !== -1) {
|
|
25
|
+
return value.split(',');
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
},
|
|
29
|
+
set: (key, value, permanent = false) => {
|
|
30
|
+
const provider = permanent ? window.localStorage : window.sessionStorage;
|
|
31
|
+
if (typeof value === "object" && typeof value.length === "undefined") {
|
|
32
|
+
provider.setItem(`${this.storagePrefix}-${key}`, JSON.stringify(value));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
provider.setItem(`${this.storagePrefix}-${key}`, value);
|
|
36
|
+
},
|
|
37
|
+
remove: (key) => {
|
|
38
|
+
window.sessionStorage.removeItem(`${this.storagePrefix}-${key}`);
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
this.storagePrefix = namespace;
|
|
42
|
+
}
|
|
43
|
+
async fetchJson(input, init = {}, useCache = false, onCacheUpdated = null) {
|
|
44
|
+
const requestPromise = new Promise(async (resolve) => {
|
|
45
|
+
let doFetchRequest = true;
|
|
46
|
+
const url = (typeof input === "string") ? input : input.url;
|
|
47
|
+
const cacheKey = url;
|
|
48
|
+
let jsonData = null;
|
|
49
|
+
let cachedData = null;
|
|
50
|
+
if (useCache) {
|
|
51
|
+
cachedData = this.store.get(cacheKey);
|
|
52
|
+
// If the data was stored in session storage, then we don't need to do a full request
|
|
53
|
+
if (cachedData && !cachedData.permanent) {
|
|
54
|
+
doFetchRequest = false;
|
|
55
|
+
}
|
|
56
|
+
if (cachedData && cachedData.data) {
|
|
57
|
+
jsonData = cachedData.data;
|
|
58
|
+
resolve(jsonData);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (doFetchRequest) {
|
|
62
|
+
const response = await window.fetch(input, init);
|
|
63
|
+
jsonData = await response.json();
|
|
64
|
+
resolve(jsonData);
|
|
65
|
+
if (useCache) {
|
|
66
|
+
if (typeof onCacheUpdated === "function" && cachedData != null) {
|
|
67
|
+
onCacheUpdated(jsonData);
|
|
68
|
+
}
|
|
69
|
+
this.store.set(cacheKey, this.wrapJson(jsonData, true), true);
|
|
70
|
+
this.store.set(cacheKey, this.wrapJson(jsonData, false), false);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return requestPromise;
|
|
75
|
+
}
|
|
76
|
+
wrapJson(data, permanent = false) {
|
|
77
|
+
const now = new Date();
|
|
78
|
+
return {
|
|
79
|
+
timestamp: now.getTime(),
|
|
80
|
+
time: now.toISOString(),
|
|
81
|
+
data: data,
|
|
82
|
+
permanent: permanent
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
exports.FetchHelper = FetchHelper;
|
package/cjs/loader.cjs.js
CHANGED
|
@@ -14,7 +14,7 @@ const patchEsm = () => {
|
|
|
14
14
|
const defineCustomElements = (win, options) => {
|
|
15
15
|
if (typeof window === 'undefined') return Promise.resolve();
|
|
16
16
|
return patchEsm().then(() => {
|
|
17
|
-
return index.bootstrapLazy([["pn-marketweb-siteheader.cjs",[[4,"pn-marketweb-siteheader",{"market":[1537],"language":[1537],"environment":[1537],"endpoint":[1],"hideSiteSelector":[1540,"hide-site-selector"],"hideLanguageSelector":[1540,"hide-language-selector"],"hideSearch":[1540,"hide-search"],"hideLogin":[1540,"hide-login"],"sessionForward":[4,"session-forward"],"spaMode":[4,"spa-mode"],"i18n":[32],"gotData":[32],"fetchingData":[32],"homePageLink":[32],"menuItems":[32],"siteDefinition":[32],"search":[32],"siteSelector":[32],"languageSelector":[32],"languageOptions":[32],"loginDialog":[32],"minimizeSearch":[32]},[[0,"setLanguage","onLanguageSelectorChange"],[0,"loginStateChange","onLoginStateChange"],[9,"resize","handleResize"]]]]],["pn-find-service-and-price.cjs",[[0,"pn-find-service-and-price",{"source":[1],"language":[1025],"market":[1025],"filteredItems":[32],"postagetype":[32],"weight":[32],"weightvalue":[32],"deliveryscope":[32],"sourceData":[32]}]]],["pn-product-pricelist.cjs",[[4,"pn-product-pricelist",{"source":[1],"language":[1025],"market":[1025],"productid":[1],"filteredItems":[32],"sourceData":[32],"gotData":[32],"loading":[32],"postagetype":[32],"weight":[32],"weightvalue":[32]}]]],["pn-marketweb-sitefooter.cjs",[[0,"pn-marketweb-sitefooter",{"market":[1537],"language":[1537],"environment":[1537],"endpoint":[1],"siteDefinition":[32],"footerContent":[32],"i18n":[32],"gotData":[32],"fetchingData":[32]}]]],["pn-filter-checkbox.cjs",[[1,"pn-filter-checkbox",{"value":[520],"name":[1],"checkboxid":[1],"disabled":[4],"checked":[4],"indeterminate":[1028]},[[0,"change","handlechange"]]]]],["pn-filter-search.cjs",[[1,"pn-filter-search",{"disabled":[4],"placeholder":[1],"inputid":[1],"name":[1],"autocomplete":[1],"value":[1],"label":[1],"loading":[4],"button":[1],"light":[4]},[[0,"input","inputHandler"]]]]],["pn-profile-selector.cjs",[[0,"pn-profile-selector",{"language":[1537],"returnUrl":[1,"return-url"],"endpoint":[1],"loginManager":[32],"loggedIn":[32],"i18n":[32],"isLoading":[32],"numberOfProfiles":[32]}]]],["pn-sidenav.cjs",[[4,"pn-sidenav",{"language":[1],"navLabel":[1,"nav-label"],"i18n":[32]},[[0,"language","setLanguage"],[0,"openSubMenuLevelChange","onOpenSubMenuLevelChange"]]]]],["pn-sidenav-level.cjs",[[4,"pn-sidenav-level",{"level":[32],"levelId":[32],"isOpen":[32],"parentName":[32],"parentHref":[32],"parentLinkId":[32],"alignment":[32]}]]],["pn-sidenav-link.cjs",[[4,"pn-sidenav-link",{"name":[1],"href":[1],"target":[1],"linkid":[1],"icon":[1],"current":[4],"levelId":[32],"open":[32],"hasChildren":[32]}]]],["pn-product-tile_3.cjs",[[4,"pn-product-tile"],[0,"pn-product-tile-info",{"label":[1],"text":[1],"icon":[1]}],[0,"pn-product-tile-price",{"label":[1],"amount":[1],"currency":[1],"url":[1]}]]],["pn-product-pricelist-result.cjs",[[0,"pn-product-pricelist-result",{"item":[1040],"shownitems":[16],"weightText":[32]}]]],["pn-choice-button_2.cjs",[[0,"pn-find-service-and-price-result",{"item":[1040],"shownitems":[16],"weightText":[32]}],[4,"pn-choice-button",{"value":[520],"name":[1],"choiceid":[1],"type":[1],"disabled":[4],"checked":[4],"indeterminate":[1028]},[[0,"change","handlechange"]]]]],["pn-site-footer_2.cjs",[[4,"pn-site-footer",{"url":[1]}],[4,"pn-site-footer-col"]]],["pn-mainnav-link.cjs",[[4,"pn-mainnav-link",{"name":[1],"href":[1],"target":[1],"linkid":[1],"levelId":[32],"open":[32],"hasChildren":[32]}]]],["pn-language-selector_9.cjs",[[4,"pn-mainnav-level",{"level":[32],"levelId":[32],"isOpen":[32],"parentName":[32],"parentHref":[32],"parentLinkId":[32],"listCount":[32],"alignment":[32]}],[4,"pn-language-selector",{"value":[1537],"selectedLanguageName":[32],"options":[32],"i18n":[32]}],[0,"pn-language-selector-option",{"name":[1],"code":[1],"url":[1],"selected":[4],"currentLanguage":[1,"current-language"]}],[4,"pn-mainnav",{"market":[1],"language":[1],"navigationId":[1,"navigation-id"],"openMenu":[1028,"open-menu"],"navLabel":[1,"nav-label"]},[[0,"language","setLanguage"],[0,"market","setMarket"],[0,"menuLanguageChange","onLanguageChange"],[0,"setmenuopenstate","setMenuOpenState"],[0,"openMenuLevelChange","onOpenMenuLevelChange"]]],[4,"pn-mainnav-list",{"heading":[1],"linkCount":[32]}],[0,"pn-marketweb-siteheader-login",{"endpoint":[1],"i18n":[8,"i-1-8n"],"emitEvents":[4,"emit-events"],"loginDialog":[1040],"loginManager":[32],"loggedIn":[32],"toggleButtonText":[32],"username":[32]}],[0,"pn-marketweb-siteheader-search",{"i18n":[8,"i-1-8n"],"showOnlyLink":[1028,"show-only-link"],"hideSearch":[1028,"hide-search"],"search":[1040]}],[4,"pn-site-selector",{"buttontext":[1537],"heading":[1537],"language":[1537],"i18n":[32]}],[0,"pn-site-selector-item",{"url":[1],"heading":[1],"description":[1],"newwindow":[4]}]]]], options);
|
|
17
|
+
return index.bootstrapLazy([["pn-marketweb-siteheader.cjs",[[4,"pn-marketweb-siteheader",{"market":[1537],"language":[1537],"environment":[1537],"endpoint":[1],"hideSiteSelector":[1540,"hide-site-selector"],"hideLanguageSelector":[1540,"hide-language-selector"],"hideSearch":[1540,"hide-search"],"hideLogin":[1540,"hide-login"],"sessionForward":[4,"session-forward"],"cache":[4],"spaMode":[4,"spa-mode"],"i18n":[32],"gotData":[32],"fetchingData":[32],"homePageLink":[32],"menuItems":[32],"siteDefinition":[32],"search":[32],"siteSelector":[32],"languageSelector":[32],"languageOptions":[32],"loginDialog":[32],"minimizeSearch":[32]},[[0,"setLanguage","onLanguageSelectorChange"],[0,"loginStateChange","onLoginStateChange"],[9,"resize","handleResize"]]]]],["pn-find-service-and-price.cjs",[[0,"pn-find-service-and-price",{"source":[1],"language":[1025],"market":[1025],"filteredItems":[32],"postagetype":[32],"weight":[32],"weightvalue":[32],"deliveryscope":[32],"sourceData":[32]}]]],["pn-product-pricelist.cjs",[[4,"pn-product-pricelist",{"source":[1],"language":[1025],"market":[1025],"productid":[1],"filteredItems":[32],"sourceData":[32],"gotData":[32],"loading":[32],"postagetype":[32],"weight":[32],"weightvalue":[32]}]]],["pn-marketweb-sitefooter.cjs",[[0,"pn-marketweb-sitefooter",{"market":[1537],"language":[1537],"environment":[1537],"endpoint":[1],"cache":[4],"siteDefinition":[32],"footerContent":[32],"i18n":[32],"gotData":[32],"fetchingData":[32]}]]],["pn-filter-checkbox.cjs",[[1,"pn-filter-checkbox",{"value":[520],"name":[1],"checkboxid":[1],"disabled":[4],"checked":[4],"indeterminate":[1028]},[[0,"change","handlechange"]]]]],["pn-filter-search.cjs",[[1,"pn-filter-search",{"disabled":[4],"placeholder":[1],"inputid":[1],"name":[1],"autocomplete":[1],"value":[1],"label":[1],"loading":[4],"button":[1],"light":[4]},[[0,"input","inputHandler"]]]]],["pn-profile-selector.cjs",[[0,"pn-profile-selector",{"language":[1537],"returnUrl":[1,"return-url"],"endpoint":[1],"loginManager":[32],"loggedIn":[32],"i18n":[32],"isLoading":[32],"numberOfProfiles":[32]}]]],["pn-sidenav.cjs",[[4,"pn-sidenav",{"language":[1],"navLabel":[1,"nav-label"],"i18n":[32]},[[0,"language","setLanguage"],[0,"openSubMenuLevelChange","onOpenSubMenuLevelChange"]]]]],["pn-sidenav-level.cjs",[[4,"pn-sidenav-level",{"level":[32],"levelId":[32],"isOpen":[32],"parentName":[32],"parentHref":[32],"parentLinkId":[32],"alignment":[32]}]]],["pn-sidenav-link.cjs",[[4,"pn-sidenav-link",{"name":[1],"href":[1],"target":[1],"linkid":[1],"icon":[1],"current":[4],"levelId":[32],"open":[32],"hasChildren":[32]}]]],["pn-product-tile_3.cjs",[[4,"pn-product-tile"],[0,"pn-product-tile-info",{"label":[1],"text":[1],"icon":[1]}],[0,"pn-product-tile-price",{"label":[1],"amount":[1],"currency":[1],"url":[1]}]]],["pn-product-pricelist-result.cjs",[[0,"pn-product-pricelist-result",{"item":[1040],"shownitems":[16],"weightText":[32]}]]],["pn-choice-button_2.cjs",[[0,"pn-find-service-and-price-result",{"item":[1040],"shownitems":[16],"weightText":[32]}],[4,"pn-choice-button",{"value":[520],"name":[1],"choiceid":[1],"type":[1],"disabled":[4],"checked":[4],"indeterminate":[1028]},[[0,"change","handlechange"]]]]],["pn-site-footer_2.cjs",[[4,"pn-site-footer",{"url":[1]}],[4,"pn-site-footer-col"]]],["pn-mainnav-link.cjs",[[4,"pn-mainnav-link",{"name":[1],"href":[1],"target":[1],"linkid":[1],"levelId":[32],"open":[32],"hasChildren":[32]}]]],["pn-language-selector_9.cjs",[[4,"pn-mainnav-level",{"level":[32],"levelId":[32],"isOpen":[32],"parentName":[32],"parentHref":[32],"parentLinkId":[32],"listCount":[32],"alignment":[32]}],[4,"pn-language-selector",{"value":[1537],"selectedLanguageName":[32],"options":[32],"i18n":[32]}],[0,"pn-language-selector-option",{"name":[1],"code":[1],"url":[1],"selected":[4],"currentLanguage":[1,"current-language"]}],[4,"pn-mainnav",{"market":[1],"language":[1],"navigationId":[1,"navigation-id"],"openMenu":[1028,"open-menu"],"navLabel":[1,"nav-label"]},[[0,"language","setLanguage"],[0,"market","setMarket"],[0,"menuLanguageChange","onLanguageChange"],[0,"setmenuopenstate","setMenuOpenState"],[0,"openMenuLevelChange","onOpenMenuLevelChange"]]],[4,"pn-mainnav-list",{"heading":[1],"linkCount":[32]}],[0,"pn-marketweb-siteheader-login",{"endpoint":[1],"i18n":[8,"i-1-8n"],"emitEvents":[4,"emit-events"],"loginDialog":[1040],"loginManager":[32],"loggedIn":[32],"toggleButtonText":[32],"username":[32]}],[0,"pn-marketweb-siteheader-search",{"i18n":[8,"i-1-8n"],"showOnlyLink":[1028,"show-only-link"],"hideSearch":[1028,"hide-search"],"search":[1040]}],[4,"pn-site-selector",{"buttontext":[1537],"heading":[1537],"language":[1537],"i18n":[32]}],[0,"pn-site-selector-item",{"url":[1],"heading":[1],"description":[1],"newwindow":[4]}]]]], options);
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
20
|
|
|
@@ -36,7 +36,7 @@ let PnMainnavLink = class {
|
|
|
36
36
|
pnMainnavStore.state.openLevel = (pnMainnavStore.state.openLevel + "" === this.levelId + "") ? '' : this.levelId;
|
|
37
37
|
}
|
|
38
38
|
render() {
|
|
39
|
-
return (index.h(index.Host, { role: "listitem", name: this.name, href: this.href, linkid: this.linkid }, this.hasChildren ? (index.h("button", { onClick: this.setOpenMenuLevel.bind(this), "aria-controls": this.levelId, "aria-pressed": "", "aria-expanded": ((pnMainnavStore.state.openLevel + "" === this.levelId + "")) + '' }, this.name, index.h("pn-icon", { class: "first-level_icon", symbol: "angle-small-down", color: "blue700" }), index.h("pn-icon", { class: "first-level_arrow", symbol: "arrow-right", color: "blue700" }))) : (index.h("a", Object.assign({ href: this.href }, (this.target ? { target: this.target } : {}), (this.linkid ? { id: this.linkid } : {})), this.name, this.target === "_blank" ? (index.h("pn-icon", { symbol: "open-in-new", color: "blue700" })) : null)), index.h("slot", null)));
|
|
39
|
+
return (index.h(index.Host, { role: "listitem", name: this.name, href: this.href, linkid: this.linkid }, this.hasChildren ? (index.h("button", { onClick: this.setOpenMenuLevel.bind(this), "aria-controls": this.levelId, "aria-pressed": "", "aria-expanded": ((pnMainnavStore.state.openLevel + "" === this.levelId + "")) + '' }, this.name, index.h("pn-icon", { class: "first-level_icon", symbol: "angle-small-down", color: "blue700" }), index.h("pn-icon", { class: "first-level_arrow", symbol: "arrow-right", color: "blue700" }))) : (index.h("a", Object.assign({ href: this.href }, (this.target ? { target: this.target } : {}), (this.target === "_blank" ? { rel: "nofollow noopener" } : {}), (this.linkid ? { id: this.linkid } : {})), this.name, this.target === "_blank" ? (index.h("pn-icon", { symbol: "open-in-new", color: "blue700" })) : null)), index.h("slot", null)));
|
|
40
40
|
}
|
|
41
41
|
get hostElement() { return index.getElement(this); }
|
|
42
42
|
};
|
|
@@ -55,5 +55,5 @@ const patchCloneNodeFix = (HTMLElementPrototype) => {
|
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
patchBrowser().then(options => {
|
|
58
|
-
return index.bootstrapLazy([["pn-marketweb-siteheader.cjs",[[4,"pn-marketweb-siteheader",{"market":[1537],"language":[1537],"environment":[1537],"endpoint":[1],"hideSiteSelector":[1540,"hide-site-selector"],"hideLanguageSelector":[1540,"hide-language-selector"],"hideSearch":[1540,"hide-search"],"hideLogin":[1540,"hide-login"],"sessionForward":[4,"session-forward"],"spaMode":[4,"spa-mode"],"i18n":[32],"gotData":[32],"fetchingData":[32],"homePageLink":[32],"menuItems":[32],"siteDefinition":[32],"search":[32],"siteSelector":[32],"languageSelector":[32],"languageOptions":[32],"loginDialog":[32],"minimizeSearch":[32]},[[0,"setLanguage","onLanguageSelectorChange"],[0,"loginStateChange","onLoginStateChange"],[9,"resize","handleResize"]]]]],["pn-find-service-and-price.cjs",[[0,"pn-find-service-and-price",{"source":[1],"language":[1025],"market":[1025],"filteredItems":[32],"postagetype":[32],"weight":[32],"weightvalue":[32],"deliveryscope":[32],"sourceData":[32]}]]],["pn-product-pricelist.cjs",[[4,"pn-product-pricelist",{"source":[1],"language":[1025],"market":[1025],"productid":[1],"filteredItems":[32],"sourceData":[32],"gotData":[32],"loading":[32],"postagetype":[32],"weight":[32],"weightvalue":[32]}]]],["pn-marketweb-sitefooter.cjs",[[0,"pn-marketweb-sitefooter",{"market":[1537],"language":[1537],"environment":[1537],"endpoint":[1],"siteDefinition":[32],"footerContent":[32],"i18n":[32],"gotData":[32],"fetchingData":[32]}]]],["pn-filter-checkbox.cjs",[[1,"pn-filter-checkbox",{"value":[520],"name":[1],"checkboxid":[1],"disabled":[4],"checked":[4],"indeterminate":[1028]},[[0,"change","handlechange"]]]]],["pn-filter-search.cjs",[[1,"pn-filter-search",{"disabled":[4],"placeholder":[1],"inputid":[1],"name":[1],"autocomplete":[1],"value":[1],"label":[1],"loading":[4],"button":[1],"light":[4]},[[0,"input","inputHandler"]]]]],["pn-profile-selector.cjs",[[0,"pn-profile-selector",{"language":[1537],"returnUrl":[1,"return-url"],"endpoint":[1],"loginManager":[32],"loggedIn":[32],"i18n":[32],"isLoading":[32],"numberOfProfiles":[32]}]]],["pn-sidenav.cjs",[[4,"pn-sidenav",{"language":[1],"navLabel":[1,"nav-label"],"i18n":[32]},[[0,"language","setLanguage"],[0,"openSubMenuLevelChange","onOpenSubMenuLevelChange"]]]]],["pn-sidenav-level.cjs",[[4,"pn-sidenav-level",{"level":[32],"levelId":[32],"isOpen":[32],"parentName":[32],"parentHref":[32],"parentLinkId":[32],"alignment":[32]}]]],["pn-sidenav-link.cjs",[[4,"pn-sidenav-link",{"name":[1],"href":[1],"target":[1],"linkid":[1],"icon":[1],"current":[4],"levelId":[32],"open":[32],"hasChildren":[32]}]]],["pn-product-tile_3.cjs",[[4,"pn-product-tile"],[0,"pn-product-tile-info",{"label":[1],"text":[1],"icon":[1]}],[0,"pn-product-tile-price",{"label":[1],"amount":[1],"currency":[1],"url":[1]}]]],["pn-product-pricelist-result.cjs",[[0,"pn-product-pricelist-result",{"item":[1040],"shownitems":[16],"weightText":[32]}]]],["pn-choice-button_2.cjs",[[0,"pn-find-service-and-price-result",{"item":[1040],"shownitems":[16],"weightText":[32]}],[4,"pn-choice-button",{"value":[520],"name":[1],"choiceid":[1],"type":[1],"disabled":[4],"checked":[4],"indeterminate":[1028]},[[0,"change","handlechange"]]]]],["pn-site-footer_2.cjs",[[4,"pn-site-footer",{"url":[1]}],[4,"pn-site-footer-col"]]],["pn-mainnav-link.cjs",[[4,"pn-mainnav-link",{"name":[1],"href":[1],"target":[1],"linkid":[1],"levelId":[32],"open":[32],"hasChildren":[32]}]]],["pn-language-selector_9.cjs",[[4,"pn-mainnav-level",{"level":[32],"levelId":[32],"isOpen":[32],"parentName":[32],"parentHref":[32],"parentLinkId":[32],"listCount":[32],"alignment":[32]}],[4,"pn-language-selector",{"value":[1537],"selectedLanguageName":[32],"options":[32],"i18n":[32]}],[0,"pn-language-selector-option",{"name":[1],"code":[1],"url":[1],"selected":[4],"currentLanguage":[1,"current-language"]}],[4,"pn-mainnav",{"market":[1],"language":[1],"navigationId":[1,"navigation-id"],"openMenu":[1028,"open-menu"],"navLabel":[1,"nav-label"]},[[0,"language","setLanguage"],[0,"market","setMarket"],[0,"menuLanguageChange","onLanguageChange"],[0,"setmenuopenstate","setMenuOpenState"],[0,"openMenuLevelChange","onOpenMenuLevelChange"]]],[4,"pn-mainnav-list",{"heading":[1],"linkCount":[32]}],[0,"pn-marketweb-siteheader-login",{"endpoint":[1],"i18n":[8,"i-1-8n"],"emitEvents":[4,"emit-events"],"loginDialog":[1040],"loginManager":[32],"loggedIn":[32],"toggleButtonText":[32],"username":[32]}],[0,"pn-marketweb-siteheader-search",{"i18n":[8,"i-1-8n"],"showOnlyLink":[1028,"show-only-link"],"hideSearch":[1028,"hide-search"],"search":[1040]}],[4,"pn-site-selector",{"buttontext":[1537],"heading":[1537],"language":[1537],"i18n":[32]}],[0,"pn-site-selector-item",{"url":[1],"heading":[1],"description":[1],"newwindow":[4]}]]]], options);
|
|
58
|
+
return index.bootstrapLazy([["pn-marketweb-siteheader.cjs",[[4,"pn-marketweb-siteheader",{"market":[1537],"language":[1537],"environment":[1537],"endpoint":[1],"hideSiteSelector":[1540,"hide-site-selector"],"hideLanguageSelector":[1540,"hide-language-selector"],"hideSearch":[1540,"hide-search"],"hideLogin":[1540,"hide-login"],"sessionForward":[4,"session-forward"],"cache":[4],"spaMode":[4,"spa-mode"],"i18n":[32],"gotData":[32],"fetchingData":[32],"homePageLink":[32],"menuItems":[32],"siteDefinition":[32],"search":[32],"siteSelector":[32],"languageSelector":[32],"languageOptions":[32],"loginDialog":[32],"minimizeSearch":[32]},[[0,"setLanguage","onLanguageSelectorChange"],[0,"loginStateChange","onLoginStateChange"],[9,"resize","handleResize"]]]]],["pn-find-service-and-price.cjs",[[0,"pn-find-service-and-price",{"source":[1],"language":[1025],"market":[1025],"filteredItems":[32],"postagetype":[32],"weight":[32],"weightvalue":[32],"deliveryscope":[32],"sourceData":[32]}]]],["pn-product-pricelist.cjs",[[4,"pn-product-pricelist",{"source":[1],"language":[1025],"market":[1025],"productid":[1],"filteredItems":[32],"sourceData":[32],"gotData":[32],"loading":[32],"postagetype":[32],"weight":[32],"weightvalue":[32]}]]],["pn-marketweb-sitefooter.cjs",[[0,"pn-marketweb-sitefooter",{"market":[1537],"language":[1537],"environment":[1537],"endpoint":[1],"cache":[4],"siteDefinition":[32],"footerContent":[32],"i18n":[32],"gotData":[32],"fetchingData":[32]}]]],["pn-filter-checkbox.cjs",[[1,"pn-filter-checkbox",{"value":[520],"name":[1],"checkboxid":[1],"disabled":[4],"checked":[4],"indeterminate":[1028]},[[0,"change","handlechange"]]]]],["pn-filter-search.cjs",[[1,"pn-filter-search",{"disabled":[4],"placeholder":[1],"inputid":[1],"name":[1],"autocomplete":[1],"value":[1],"label":[1],"loading":[4],"button":[1],"light":[4]},[[0,"input","inputHandler"]]]]],["pn-profile-selector.cjs",[[0,"pn-profile-selector",{"language":[1537],"returnUrl":[1,"return-url"],"endpoint":[1],"loginManager":[32],"loggedIn":[32],"i18n":[32],"isLoading":[32],"numberOfProfiles":[32]}]]],["pn-sidenav.cjs",[[4,"pn-sidenav",{"language":[1],"navLabel":[1,"nav-label"],"i18n":[32]},[[0,"language","setLanguage"],[0,"openSubMenuLevelChange","onOpenSubMenuLevelChange"]]]]],["pn-sidenav-level.cjs",[[4,"pn-sidenav-level",{"level":[32],"levelId":[32],"isOpen":[32],"parentName":[32],"parentHref":[32],"parentLinkId":[32],"alignment":[32]}]]],["pn-sidenav-link.cjs",[[4,"pn-sidenav-link",{"name":[1],"href":[1],"target":[1],"linkid":[1],"icon":[1],"current":[4],"levelId":[32],"open":[32],"hasChildren":[32]}]]],["pn-product-tile_3.cjs",[[4,"pn-product-tile"],[0,"pn-product-tile-info",{"label":[1],"text":[1],"icon":[1]}],[0,"pn-product-tile-price",{"label":[1],"amount":[1],"currency":[1],"url":[1]}]]],["pn-product-pricelist-result.cjs",[[0,"pn-product-pricelist-result",{"item":[1040],"shownitems":[16],"weightText":[32]}]]],["pn-choice-button_2.cjs",[[0,"pn-find-service-and-price-result",{"item":[1040],"shownitems":[16],"weightText":[32]}],[4,"pn-choice-button",{"value":[520],"name":[1],"choiceid":[1],"type":[1],"disabled":[4],"checked":[4],"indeterminate":[1028]},[[0,"change","handlechange"]]]]],["pn-site-footer_2.cjs",[[4,"pn-site-footer",{"url":[1]}],[4,"pn-site-footer-col"]]],["pn-mainnav-link.cjs",[[4,"pn-mainnav-link",{"name":[1],"href":[1],"target":[1],"linkid":[1],"levelId":[32],"open":[32],"hasChildren":[32]}]]],["pn-language-selector_9.cjs",[[4,"pn-mainnav-level",{"level":[32],"levelId":[32],"isOpen":[32],"parentName":[32],"parentHref":[32],"parentLinkId":[32],"listCount":[32],"alignment":[32]}],[4,"pn-language-selector",{"value":[1537],"selectedLanguageName":[32],"options":[32],"i18n":[32]}],[0,"pn-language-selector-option",{"name":[1],"code":[1],"url":[1],"selected":[4],"currentLanguage":[1,"current-language"]}],[4,"pn-mainnav",{"market":[1],"language":[1],"navigationId":[1,"navigation-id"],"openMenu":[1028,"open-menu"],"navLabel":[1,"nav-label"]},[[0,"language","setLanguage"],[0,"market","setMarket"],[0,"menuLanguageChange","onLanguageChange"],[0,"setmenuopenstate","setMenuOpenState"],[0,"openMenuLevelChange","onOpenMenuLevelChange"]]],[4,"pn-mainnav-list",{"heading":[1],"linkCount":[32]}],[0,"pn-marketweb-siteheader-login",{"endpoint":[1],"i18n":[8,"i-1-8n"],"emitEvents":[4,"emit-events"],"loginDialog":[1040],"loginManager":[32],"loggedIn":[32],"toggleButtonText":[32],"username":[32]}],[0,"pn-marketweb-siteheader-search",{"i18n":[8,"i-1-8n"],"showOnlyLink":[1028,"show-only-link"],"hideSearch":[1028,"hide-search"],"search":[1040]}],[4,"pn-site-selector",{"buttontext":[1537],"heading":[1537],"language":[1537],"i18n":[32]}],[0,"pn-site-selector-item",{"url":[1],"heading":[1],"description":[1],"newwindow":[4]}]]]], options);
|
|
59
59
|
});
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const index = require('./index-0404c97e.js');
|
|
6
6
|
const MarketWebContextService = require('./MarketWebContextService-bdc46f40.js');
|
|
7
|
+
const FetchHelper = require('./FetchHelper-f80943bf.js');
|
|
7
8
|
|
|
8
9
|
const translations = {
|
|
9
10
|
'sv': {
|
|
@@ -67,8 +68,12 @@ let PnMarketwebSiteheader = class {
|
|
|
67
68
|
this.environment = null; //sv
|
|
68
69
|
/** Specifies which endpoint domain we should load from */
|
|
69
70
|
this.endpoint = null;
|
|
71
|
+
/** If the component should use cached requests */
|
|
72
|
+
this.cache = false;
|
|
70
73
|
this.gotData = false;
|
|
71
74
|
this.fetchingData = false;
|
|
75
|
+
// FetchHelper
|
|
76
|
+
this.fetchHelper = new FetchHelper.FetchHelper("sitefooter");
|
|
72
77
|
}
|
|
73
78
|
componentWillLoad() {
|
|
74
79
|
this.setInitialValues().then(() => {
|
|
@@ -120,8 +125,13 @@ let PnMarketwebSiteheader = class {
|
|
|
120
125
|
this.fetchingData = true;
|
|
121
126
|
const endpointBase = (this.endpoint.lastIndexOf("/") === this.endpoint.length - 1) ? this.endpoint.substring(0, this.endpoint.length - 1) : this.endpoint;
|
|
122
127
|
const fetchUrl = `${endpointBase}${this.endpointPath}?market=${this.market}&language=${this.language}`;
|
|
123
|
-
const
|
|
124
|
-
|
|
128
|
+
const data = await this.fetchHelper.fetchJson(fetchUrl, {
|
|
129
|
+
'mode': 'cors'
|
|
130
|
+
}, this.cache, this.onFetchRefreshed.bind(this));
|
|
131
|
+
await this.setStateFromData(data);
|
|
132
|
+
}
|
|
133
|
+
onFetchRefreshed(data) {
|
|
134
|
+
console.log('Data was updated after request', data);
|
|
125
135
|
this.setStateFromData(data);
|
|
126
136
|
}
|
|
127
137
|
getLinkContentByType(linkType = "") {
|
|
@@ -167,6 +177,9 @@ let PnMarketwebSiteheader = class {
|
|
|
167
177
|
render() {
|
|
168
178
|
var _a, _b, _c, _d, _e;
|
|
169
179
|
return (index.h(index.Host, { language: this.language, market: this.market, environment: this.environment }, index.h("pn-site-footer", { url: (_b = (_a = this.siteDefinition) === null || _a === void 0 ? void 0 : _a.url) !== null && _b !== void 0 ? _b : "" }, (this.gotData && ((_c = this.footerContent) === null || _c === void 0 ? void 0 : _c.columns)) ? this.footerContent.columns.map((column) => (index.h("pn-site-footer-col", null, index.h("h3", null, column.heading), column.links ? (index.h("ul", Object.assign({}, ((column.links && column.links[0] && column.links[0].linkType) && { 'class': 'social-media' })), column.links.map((link) => {
|
|
180
|
+
if (!link.linkHref) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
170
183
|
let linkText = link.linkText;
|
|
171
184
|
if (link.linkType) {
|
|
172
185
|
linkText = this.getLinkContentByType(link.linkType);
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const index = require('./index-0404c97e.js');
|
|
6
6
|
const MarketWebContextService = require('./MarketWebContextService-bdc46f40.js');
|
|
7
|
+
const FetchHelper = require('./FetchHelper-f80943bf.js');
|
|
7
8
|
|
|
8
9
|
const translations = {
|
|
9
10
|
'sv': {
|
|
@@ -81,6 +82,8 @@ let PnMarketwebSiteheader = class {
|
|
|
81
82
|
this.hideLogin = false;
|
|
82
83
|
/** Forward session to backend */
|
|
83
84
|
this.sessionForward = false;
|
|
85
|
+
/** If the component should use cached requests */
|
|
86
|
+
this.cache = false;
|
|
84
87
|
/** Event based only language switch */
|
|
85
88
|
this.spaMode = false;
|
|
86
89
|
this.gotData = false;
|
|
@@ -98,6 +101,8 @@ let PnMarketwebSiteheader = class {
|
|
|
98
101
|
// Login dialog
|
|
99
102
|
this.loginDialog = null;
|
|
100
103
|
this.minimizeSearch = false;
|
|
104
|
+
// FetchHelper
|
|
105
|
+
this.fetchHelper = new FetchHelper.FetchHelper("siteheader");
|
|
101
106
|
}
|
|
102
107
|
componentWillLoad() {
|
|
103
108
|
this.setInitialValues().then(() => {
|
|
@@ -155,12 +160,14 @@ let PnMarketwebSiteheader = class {
|
|
|
155
160
|
this.fetchingData = true;
|
|
156
161
|
const endpointBase = (this.endpoint.lastIndexOf("/") === this.endpoint.length - 1) ? this.endpoint.substring(0, this.endpoint.length - 1) : this.endpoint;
|
|
157
162
|
const fetchUrl = `${endpointBase}${this.endpointPath}?market=${this.market}&language=${this.language}`;
|
|
158
|
-
const
|
|
163
|
+
const data = await this.fetchHelper.fetchJson(fetchUrl, {
|
|
159
164
|
'mode': 'cors'
|
|
160
|
-
});
|
|
161
|
-
const data = await response.json();
|
|
165
|
+
}, this.cache, this.onFetchRefreshed.bind(this));
|
|
162
166
|
await this.setStateFromData(data);
|
|
163
167
|
}
|
|
168
|
+
onFetchRefreshed(data) {
|
|
169
|
+
this.setStateFromData(data);
|
|
170
|
+
}
|
|
164
171
|
getLanguageVersionUrl(item) {
|
|
165
172
|
if (this.spaMode) {
|
|
166
173
|
return null;
|
|
@@ -174,7 +181,7 @@ let PnMarketwebSiteheader = class {
|
|
|
174
181
|
return siteUrl + ((siteUrl.lastIndexOf("/") !== siteUrl.length - 1) ? "/" : "") + item.twoLetterISOLanguageName;
|
|
175
182
|
}
|
|
176
183
|
async setStateFromData(data) {
|
|
177
|
-
var _a, _b;
|
|
184
|
+
var _a, _b, _c;
|
|
178
185
|
if (typeof data !== "object") {
|
|
179
186
|
console.warn('Data was not valid', data);
|
|
180
187
|
}
|
|
@@ -183,14 +190,16 @@ let PnMarketwebSiteheader = class {
|
|
|
183
190
|
// Set navigation information
|
|
184
191
|
this.menuItems = data.mainMenu.menuItems;
|
|
185
192
|
// Create the "Home" link
|
|
186
|
-
this.menuItems.
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
193
|
+
if (!this.menuItems[0] || ((_a = this.menuItems[0]) === null || _a === void 0 ? void 0 : _a.name) !== this.i18n.menuHomeButton) {
|
|
194
|
+
this.menuItems.unshift({
|
|
195
|
+
href: this.siteDefinition.url,
|
|
196
|
+
name: this.i18n.menuHomeButton,
|
|
197
|
+
id: 'homelink',
|
|
198
|
+
open: false,
|
|
199
|
+
selected: false,
|
|
200
|
+
children: []
|
|
201
|
+
});
|
|
202
|
+
}
|
|
194
203
|
// Set search
|
|
195
204
|
this.search = data.search;
|
|
196
205
|
// Set site selector
|
|
@@ -202,7 +211,7 @@ let PnMarketwebSiteheader = class {
|
|
|
202
211
|
await this.spaModeAdjustments();
|
|
203
212
|
this.gotData = true;
|
|
204
213
|
this.fetchingData = true;
|
|
205
|
-
this.homePageLink = (
|
|
214
|
+
this.homePageLink = (_c = (_b = this.siteDefinition) === null || _b === void 0 ? void 0 : _b.url) !== null && _c !== void 0 ? _c : document.location.hostname;
|
|
206
215
|
window.setTimeout(() => { this.checkMenuOverflow(); }, 100);
|
|
207
216
|
}
|
|
208
217
|
setLanguageOptions() {
|
package/collection/components/layout-components/pn-marketweb-sitefooter/pn-marketweb-sitefooter.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Component, Prop, h, State, Element, Host, Watch } from "@stencil/core";
|
|
2
2
|
import { translations } from "./translations";
|
|
3
3
|
import { MarketWebContextService } from "../../../globals/MarketWebContextService";
|
|
4
|
+
import { FetchHelper } from "../../../globals/FetchHelper";
|
|
4
5
|
export class PnMarketwebSiteheader {
|
|
5
6
|
constructor() {
|
|
6
7
|
this.endpointPath = "/api/footer/footer";
|
|
@@ -12,8 +13,12 @@ export class PnMarketwebSiteheader {
|
|
|
12
13
|
this.environment = null; //sv
|
|
13
14
|
/** Specifies which endpoint domain we should load from */
|
|
14
15
|
this.endpoint = null;
|
|
16
|
+
/** If the component should use cached requests */
|
|
17
|
+
this.cache = false;
|
|
15
18
|
this.gotData = false;
|
|
16
19
|
this.fetchingData = false;
|
|
20
|
+
// FetchHelper
|
|
21
|
+
this.fetchHelper = new FetchHelper("sitefooter");
|
|
17
22
|
}
|
|
18
23
|
componentWillLoad() {
|
|
19
24
|
this.setInitialValues().then(() => {
|
|
@@ -65,8 +70,13 @@ export class PnMarketwebSiteheader {
|
|
|
65
70
|
this.fetchingData = true;
|
|
66
71
|
const endpointBase = (this.endpoint.lastIndexOf("/") === this.endpoint.length - 1) ? this.endpoint.substring(0, this.endpoint.length - 1) : this.endpoint;
|
|
67
72
|
const fetchUrl = `${endpointBase}${this.endpointPath}?market=${this.market}&language=${this.language}`;
|
|
68
|
-
const
|
|
69
|
-
|
|
73
|
+
const data = await this.fetchHelper.fetchJson(fetchUrl, {
|
|
74
|
+
'mode': 'cors'
|
|
75
|
+
}, this.cache, this.onFetchRefreshed.bind(this));
|
|
76
|
+
await this.setStateFromData(data);
|
|
77
|
+
}
|
|
78
|
+
onFetchRefreshed(data) {
|
|
79
|
+
console.log('Data was updated after request', data);
|
|
70
80
|
this.setStateFromData(data);
|
|
71
81
|
}
|
|
72
82
|
getLinkContentByType(linkType = "") {
|
|
@@ -116,6 +126,9 @@ export class PnMarketwebSiteheader {
|
|
|
116
126
|
(this.gotData && ((_c = this.footerContent) === null || _c === void 0 ? void 0 : _c.columns)) ? this.footerContent.columns.map((column) => (h("pn-site-footer-col", null,
|
|
117
127
|
h("h3", null, column.heading),
|
|
118
128
|
column.links ? (h("ul", Object.assign({}, ((column.links && column.links[0] && column.links[0].linkType) && { 'class': 'social-media' })), column.links.map((link) => {
|
|
129
|
+
if (!link.linkHref) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
119
132
|
let linkText = link.linkText;
|
|
120
133
|
if (link.linkType) {
|
|
121
134
|
linkText = this.getLinkContentByType(link.linkType);
|
|
@@ -214,6 +227,24 @@ export class PnMarketwebSiteheader {
|
|
|
214
227
|
"attribute": "endpoint",
|
|
215
228
|
"reflect": false,
|
|
216
229
|
"defaultValue": "null"
|
|
230
|
+
},
|
|
231
|
+
"cache": {
|
|
232
|
+
"type": "boolean",
|
|
233
|
+
"mutable": false,
|
|
234
|
+
"complexType": {
|
|
235
|
+
"original": "boolean",
|
|
236
|
+
"resolved": "boolean",
|
|
237
|
+
"references": {}
|
|
238
|
+
},
|
|
239
|
+
"required": false,
|
|
240
|
+
"optional": false,
|
|
241
|
+
"docs": {
|
|
242
|
+
"tags": [],
|
|
243
|
+
"text": "If the component should use cached requests"
|
|
244
|
+
},
|
|
245
|
+
"attribute": "cache",
|
|
246
|
+
"reflect": false,
|
|
247
|
+
"defaultValue": "false"
|
|
217
248
|
}
|
|
218
249
|
}; }
|
|
219
250
|
static get states() { return {
|
|
@@ -50,10 +50,10 @@ const Template = ({ ...args }) => {
|
|
|
50
50
|
|
|
51
51
|
export const Primary = Template.bind({});
|
|
52
52
|
Primary.args = {
|
|
53
|
-
market : "
|
|
54
|
-
language: '
|
|
53
|
+
market : "se",
|
|
54
|
+
language: 'sv',
|
|
55
55
|
environment: "production",
|
|
56
|
-
endpoint: "",// 'https://www.postnord.se'
|
|
56
|
+
endpoint: "https://com-production.postnord.com",// 'https://www.postnord.se'
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
|
package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Component, Prop, h, State, Element, Listen, Watch, Host, Event } from "@stencil/core";
|
|
2
2
|
import { translations } from "./translations";
|
|
3
3
|
import { MarketWebContextService } from "../../../globals/MarketWebContextService";
|
|
4
|
+
import { FetchHelper } from "../../../globals/FetchHelper";
|
|
4
5
|
export class PnMarketwebSiteheader {
|
|
5
6
|
constructor() {
|
|
6
7
|
this.endpointPath = "/api/navigation/header";
|
|
@@ -24,6 +25,8 @@ export class PnMarketwebSiteheader {
|
|
|
24
25
|
this.hideLogin = false;
|
|
25
26
|
/** Forward session to backend */
|
|
26
27
|
this.sessionForward = false;
|
|
28
|
+
/** If the component should use cached requests */
|
|
29
|
+
this.cache = false;
|
|
27
30
|
/** Event based only language switch */
|
|
28
31
|
this.spaMode = false;
|
|
29
32
|
this.gotData = false;
|
|
@@ -41,6 +44,8 @@ export class PnMarketwebSiteheader {
|
|
|
41
44
|
// Login dialog
|
|
42
45
|
this.loginDialog = null;
|
|
43
46
|
this.minimizeSearch = false;
|
|
47
|
+
// FetchHelper
|
|
48
|
+
this.fetchHelper = new FetchHelper("siteheader");
|
|
44
49
|
}
|
|
45
50
|
componentWillLoad() {
|
|
46
51
|
this.setInitialValues().then(() => {
|
|
@@ -98,12 +103,14 @@ export class PnMarketwebSiteheader {
|
|
|
98
103
|
this.fetchingData = true;
|
|
99
104
|
const endpointBase = (this.endpoint.lastIndexOf("/") === this.endpoint.length - 1) ? this.endpoint.substring(0, this.endpoint.length - 1) : this.endpoint;
|
|
100
105
|
const fetchUrl = `${endpointBase}${this.endpointPath}?market=${this.market}&language=${this.language}`;
|
|
101
|
-
const
|
|
106
|
+
const data = await this.fetchHelper.fetchJson(fetchUrl, {
|
|
102
107
|
'mode': 'cors'
|
|
103
|
-
});
|
|
104
|
-
const data = await response.json();
|
|
108
|
+
}, this.cache, this.onFetchRefreshed.bind(this));
|
|
105
109
|
await this.setStateFromData(data);
|
|
106
110
|
}
|
|
111
|
+
onFetchRefreshed(data) {
|
|
112
|
+
this.setStateFromData(data);
|
|
113
|
+
}
|
|
107
114
|
getLanguageVersionUrl(item) {
|
|
108
115
|
if (this.spaMode) {
|
|
109
116
|
return null;
|
|
@@ -117,7 +124,7 @@ export class PnMarketwebSiteheader {
|
|
|
117
124
|
return siteUrl + ((siteUrl.lastIndexOf("/") !== siteUrl.length - 1) ? "/" : "") + item.twoLetterISOLanguageName;
|
|
118
125
|
}
|
|
119
126
|
async setStateFromData(data) {
|
|
120
|
-
var _a, _b;
|
|
127
|
+
var _a, _b, _c;
|
|
121
128
|
if (typeof data !== "object") {
|
|
122
129
|
console.warn('Data was not valid', data);
|
|
123
130
|
}
|
|
@@ -126,14 +133,16 @@ export class PnMarketwebSiteheader {
|
|
|
126
133
|
// Set navigation information
|
|
127
134
|
this.menuItems = data.mainMenu.menuItems;
|
|
128
135
|
// Create the "Home" link
|
|
129
|
-
this.menuItems.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
136
|
+
if (!this.menuItems[0] || ((_a = this.menuItems[0]) === null || _a === void 0 ? void 0 : _a.name) !== this.i18n.menuHomeButton) {
|
|
137
|
+
this.menuItems.unshift({
|
|
138
|
+
href: this.siteDefinition.url,
|
|
139
|
+
name: this.i18n.menuHomeButton,
|
|
140
|
+
id: 'homelink',
|
|
141
|
+
open: false,
|
|
142
|
+
selected: false,
|
|
143
|
+
children: []
|
|
144
|
+
});
|
|
145
|
+
}
|
|
137
146
|
// Set search
|
|
138
147
|
this.search = data.search;
|
|
139
148
|
// Set site selector
|
|
@@ -145,7 +154,7 @@ export class PnMarketwebSiteheader {
|
|
|
145
154
|
await this.spaModeAdjustments();
|
|
146
155
|
this.gotData = true;
|
|
147
156
|
this.fetchingData = true;
|
|
148
|
-
this.homePageLink = (
|
|
157
|
+
this.homePageLink = (_c = (_b = this.siteDefinition) === null || _b === void 0 ? void 0 : _b.url) !== null && _c !== void 0 ? _c : document.location.hostname;
|
|
149
158
|
window.setTimeout(() => { this.checkMenuOverflow(); }, 100);
|
|
150
159
|
}
|
|
151
160
|
setLanguageOptions() {
|
|
@@ -433,6 +442,24 @@ export class PnMarketwebSiteheader {
|
|
|
433
442
|
"reflect": false,
|
|
434
443
|
"defaultValue": "false"
|
|
435
444
|
},
|
|
445
|
+
"cache": {
|
|
446
|
+
"type": "boolean",
|
|
447
|
+
"mutable": false,
|
|
448
|
+
"complexType": {
|
|
449
|
+
"original": "boolean",
|
|
450
|
+
"resolved": "boolean",
|
|
451
|
+
"references": {}
|
|
452
|
+
},
|
|
453
|
+
"required": false,
|
|
454
|
+
"optional": false,
|
|
455
|
+
"docs": {
|
|
456
|
+
"tags": [],
|
|
457
|
+
"text": "If the component should use cached requests"
|
|
458
|
+
},
|
|
459
|
+
"attribute": "cache",
|
|
460
|
+
"reflect": false,
|
|
461
|
+
"defaultValue": "false"
|
|
462
|
+
},
|
|
436
463
|
"spaMode": {
|
|
437
464
|
"type": "boolean",
|
|
438
465
|
"mutable": false,
|
|
@@ -49,6 +49,7 @@ const PrimaryTemplate = ({ ...args }) => {
|
|
|
49
49
|
hide-language-selector="false"
|
|
50
50
|
hide-search="false"
|
|
51
51
|
hide-login="false"
|
|
52
|
+
cache="true"
|
|
52
53
|
session-forward="true">
|
|
53
54
|
<a href="" class="header-cart" slot="toprightend" style="align-self:center;position:relative;text-decoration:none;">
|
|
54
55
|
<span>Varukorg</span>
|
|
@@ -71,7 +72,7 @@ export const Primary = PrimaryTemplate.bind({});
|
|
|
71
72
|
Primary.args = {
|
|
72
73
|
market : "se",
|
|
73
74
|
language: 'sv',
|
|
74
|
-
endpoint: '
|
|
75
|
+
endpoint: 'https://com-production.postnord.com'
|
|
75
76
|
};
|
|
76
77
|
|
|
77
78
|
|
|
@@ -31,7 +31,7 @@ export class PnMainnavLink {
|
|
|
31
31
|
this.hasChildren ? (h("button", { onClick: this.setOpenMenuLevel.bind(this), "aria-controls": this.levelId, "aria-pressed": "", "aria-expanded": ((state.openLevel + "" === this.levelId + "")) + '' },
|
|
32
32
|
this.name,
|
|
33
33
|
h("pn-icon", { class: "first-level_icon", symbol: "angle-small-down", color: "blue700" }),
|
|
34
|
-
h("pn-icon", { class: "first-level_arrow", symbol: "arrow-right", color: "blue700" }))) : (h("a", Object.assign({ href: this.href }, (this.target ? { target: this.target } : {}), (this.linkid ? { id: this.linkid } : {})),
|
|
34
|
+
h("pn-icon", { class: "first-level_arrow", symbol: "arrow-right", color: "blue700" }))) : (h("a", Object.assign({ href: this.href }, (this.target ? { target: this.target } : {}), (this.target === "_blank" ? { rel: "nofollow noopener" } : {}), (this.linkid ? { id: this.linkid } : {})),
|
|
35
35
|
this.name,
|
|
36
36
|
this.target === "_blank" ? (h("pn-icon", { symbol: "open-in-new", color: "blue700" })) : null)),
|
|
37
37
|
h("slot", null)));
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
class FetchHelper {
|
|
2
|
+
constructor(namespace = "") {
|
|
3
|
+
this.storagePrefix = "";
|
|
4
|
+
this.store = {
|
|
5
|
+
get: (key, permanentStorageFirst = false) => {
|
|
6
|
+
const firstProfider = permanentStorageFirst ? window.localStorage : window.sessionStorage;
|
|
7
|
+
const secondProvider = permanentStorageFirst ? window.sessionStorage : window.localStorage;
|
|
8
|
+
let value = firstProfider.getItem(`${this.storagePrefix}-${key}`);
|
|
9
|
+
if (!value) {
|
|
10
|
+
value = secondProvider.getItem(`${this.storagePrefix}-${key}`);
|
|
11
|
+
}
|
|
12
|
+
if (!value) {
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
if (value.indexOf('{') === 0) {
|
|
16
|
+
try {
|
|
17
|
+
return JSON.parse(value);
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (value.indexOf(',') !== -1) {
|
|
23
|
+
return value.split(',');
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
},
|
|
27
|
+
set: (key, value, permanent = false) => {
|
|
28
|
+
const provider = permanent ? window.localStorage : window.sessionStorage;
|
|
29
|
+
if (typeof value === "object" && typeof value.length === "undefined") {
|
|
30
|
+
provider.setItem(`${this.storagePrefix}-${key}`, JSON.stringify(value));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
provider.setItem(`${this.storagePrefix}-${key}`, value);
|
|
34
|
+
},
|
|
35
|
+
remove: (key) => {
|
|
36
|
+
window.sessionStorage.removeItem(`${this.storagePrefix}-${key}`);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
this.storagePrefix = namespace;
|
|
40
|
+
}
|
|
41
|
+
async fetchJson(input, init = {}, useCache = false, onCacheUpdated = null) {
|
|
42
|
+
const requestPromise = new Promise(async (resolve) => {
|
|
43
|
+
let doFetchRequest = true;
|
|
44
|
+
const url = (typeof input === "string") ? input : input.url;
|
|
45
|
+
const cacheKey = url;
|
|
46
|
+
let jsonData = null;
|
|
47
|
+
let cachedData = null;
|
|
48
|
+
if (useCache) {
|
|
49
|
+
cachedData = this.store.get(cacheKey);
|
|
50
|
+
// If the data was stored in session storage, then we don't need to do a full request
|
|
51
|
+
if (cachedData && !cachedData.permanent) {
|
|
52
|
+
doFetchRequest = false;
|
|
53
|
+
}
|
|
54
|
+
if (cachedData && cachedData.data) {
|
|
55
|
+
jsonData = cachedData.data;
|
|
56
|
+
resolve(jsonData);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (doFetchRequest) {
|
|
60
|
+
const response = await window.fetch(input, init);
|
|
61
|
+
jsonData = await response.json();
|
|
62
|
+
resolve(jsonData);
|
|
63
|
+
if (useCache) {
|
|
64
|
+
if (typeof onCacheUpdated === "function" && cachedData != null) {
|
|
65
|
+
onCacheUpdated(jsonData);
|
|
66
|
+
}
|
|
67
|
+
this.store.set(cacheKey, this.wrapJson(jsonData, true), true);
|
|
68
|
+
this.store.set(cacheKey, this.wrapJson(jsonData, false), false);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return requestPromise;
|
|
73
|
+
}
|
|
74
|
+
wrapJson(data, permanent = false) {
|
|
75
|
+
const now = new Date();
|
|
76
|
+
return {
|
|
77
|
+
timestamp: now.getTime(),
|
|
78
|
+
time: now.toISOString(),
|
|
79
|
+
data: data,
|
|
80
|
+
permanent: permanent
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export { FetchHelper };
|