@everymatrix/promoting-banners 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/app-globals-3a1e7e63.js +5 -0
- package/dist/cjs/index-40277d4b.js +1249 -0
- package/dist/cjs/index.cjs.js +10 -0
- package/dist/cjs/loader.cjs.js +15 -0
- package/dist/cjs/promoting-banners-d707e229.js +206 -0
- package/dist/cjs/promoting-banners.cjs.entry.js +10 -0
- package/dist/cjs/promoting-banners.cjs.js +25 -0
- package/dist/collection/collection-manifest.json +12 -0
- package/dist/collection/components/promoting-banners/index.js +1 -0
- package/dist/collection/components/promoting-banners/promoting-banners.css +154 -0
- package/dist/collection/components/promoting-banners/promoting-banners.js +260 -0
- package/dist/collection/index.js +1 -0
- package/dist/collection/utils/locale.utils.js +48 -0
- package/dist/collection/utils/utils.js +27 -0
- package/dist/esm/app-globals-0f993ce5.js +3 -0
- package/dist/esm/index-936cf61c.js +1223 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/loader.js +11 -0
- package/dist/esm/promoting-banners-10e80966.js +204 -0
- package/dist/esm/promoting-banners.entry.js +2 -0
- package/dist/esm/promoting-banners.js +20 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/promoting-banners/index.esm.js +1 -0
- package/dist/promoting-banners/p-53a1c74c.js +1 -0
- package/dist/promoting-banners/p-7f9296a7.entry.js +1 -0
- package/dist/promoting-banners/p-a3d905a8.js +2 -0
- package/dist/promoting-banners/p-e1255160.js +1 -0
- package/dist/promoting-banners/promoting-banners.esm.js +1 -0
- package/dist/stencil.config.dev.js +14 -0
- package/dist/stencil.config.js +17 -0
- package/dist/types/Users/adrian.pripon/Documents/Work/widgets-monorepo/packages/stencil/promoting-banners/.stencil/packages/stencil/promoting-banners/stencil.config.d.ts +2 -0
- package/dist/types/Users/adrian.pripon/Documents/Work/widgets-monorepo/packages/stencil/promoting-banners/.stencil/packages/stencil/promoting-banners/stencil.config.dev.d.ts +2 -0
- package/dist/types/components/promoting-banners/index.d.ts +1 -0
- package/dist/types/components/promoting-banners/promoting-banners.d.ts +42 -0
- package/dist/types/components.d.ts +85 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/stencil-public-runtime.d.ts +1680 -0
- package/dist/types/utils/locale.utils.d.ts +2 -0
- package/dist/types/utils/utils.d.ts +2 -0
- package/loader/cdn.js +1 -0
- package/loader/index.cjs.js +1 -0
- package/loader/index.d.ts +24 -0
- package/loader/index.es2017.js +1 -0
- package/loader/index.js +2 -0
- package/loader/package.json +11 -0
- package/package.json +26 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { h } from "@stencil/core";
|
|
2
|
+
import { getDevice, getDevicePlatform } from "../../utils/utils";
|
|
3
|
+
import { translate, getTranslations } from "../../utils/locale.utils";
|
|
4
|
+
export class PromotingBanners {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.setClientStyling = () => {
|
|
7
|
+
let sheet = document.createElement('style');
|
|
8
|
+
sheet.innerHTML = this.clientStyling;
|
|
9
|
+
this.stylingContainer.prepend(sheet);
|
|
10
|
+
};
|
|
11
|
+
this.setClientStylingURL = () => {
|
|
12
|
+
let url = new URL(this.clientStylingUrl);
|
|
13
|
+
let cssFile = document.createElement('style');
|
|
14
|
+
fetch(url.href)
|
|
15
|
+
.then((res) => res.text())
|
|
16
|
+
.then((data) => {
|
|
17
|
+
cssFile.innerHTML = data;
|
|
18
|
+
setTimeout(() => { this.stylingContainer.prepend(cssFile); }, 1);
|
|
19
|
+
})
|
|
20
|
+
.catch((err) => {
|
|
21
|
+
console.log('error ', err);
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
this.componentDidLoad = () => {
|
|
25
|
+
if (this.stylingContainer) {
|
|
26
|
+
if (this.clientStyling)
|
|
27
|
+
this.setClientStyling();
|
|
28
|
+
if (this.clientStylingUrl)
|
|
29
|
+
this.setClientStylingURL();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
this.cmsEndpoint = '';
|
|
33
|
+
this.language = 'en';
|
|
34
|
+
this.cmsEnv = '';
|
|
35
|
+
this.clientStyling = '';
|
|
36
|
+
this.clientStylingUrl = '';
|
|
37
|
+
this.translationUrl = '';
|
|
38
|
+
this.promotingBannersArray = [];
|
|
39
|
+
this.hasErrors = false;
|
|
40
|
+
this.isLoading = true;
|
|
41
|
+
this.translationData = undefined;
|
|
42
|
+
}
|
|
43
|
+
handleStylingChange(newValue, oldValue) {
|
|
44
|
+
if (newValue !== oldValue)
|
|
45
|
+
this.setClientStyling();
|
|
46
|
+
}
|
|
47
|
+
handleNewTranslations() {
|
|
48
|
+
this.isLoading = true;
|
|
49
|
+
getTranslations(this.translationUrl).then(() => {
|
|
50
|
+
this.isLoading = false;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
connectedCallback() {
|
|
54
|
+
if (this.cmsEndpoint && this.language) {
|
|
55
|
+
this.getPromotingBanners();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
getPromotingBanners() {
|
|
59
|
+
const url = new URL(`${this.cmsEndpoint}/${this.language}/homepage`);
|
|
60
|
+
const params = new URLSearchParams();
|
|
61
|
+
params.append('language', this.language);
|
|
62
|
+
params.append('env', this.cmsEnv);
|
|
63
|
+
params.append('device', getDevicePlatform());
|
|
64
|
+
url.search = params.toString();
|
|
65
|
+
let requestOptions = {
|
|
66
|
+
method: 'GET',
|
|
67
|
+
headers: {
|
|
68
|
+
'Content-Type': 'application/json',
|
|
69
|
+
'Accept': 'application/json'
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
this.isLoading = true;
|
|
74
|
+
fetch(url.href, requestOptions)
|
|
75
|
+
.then(res => res.json())
|
|
76
|
+
.then(data => {
|
|
77
|
+
const { promotingBanners } = data;
|
|
78
|
+
this.promotingBannersArray = promotingBanners;
|
|
79
|
+
resolve(promotingBanners);
|
|
80
|
+
})
|
|
81
|
+
.catch(error => {
|
|
82
|
+
console.error('Error fetching data:', error);
|
|
83
|
+
this.hasErrors = true;
|
|
84
|
+
reject(error);
|
|
85
|
+
}).finally(() => {
|
|
86
|
+
this.isLoading = false;
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
sendOpenLink(url, isExternal, target) {
|
|
91
|
+
window.postMessage({ type: 'NavigateTo', path: url, target: target || null, externalLink: isExternal || false }, window.location.href);
|
|
92
|
+
}
|
|
93
|
+
async componentWillLoad() {
|
|
94
|
+
// Translation url logic
|
|
95
|
+
const promises = [];
|
|
96
|
+
if (this.translationUrl) {
|
|
97
|
+
const translationPromise = getTranslations(this.translationUrl).then((data) => {
|
|
98
|
+
this.translationData = JSON.stringify(data);
|
|
99
|
+
}).catch(err => {
|
|
100
|
+
console.log(err);
|
|
101
|
+
});
|
|
102
|
+
promises.push(translationPromise);
|
|
103
|
+
}
|
|
104
|
+
return Promise.all(promises);
|
|
105
|
+
}
|
|
106
|
+
renderBannersGrid(banner) {
|
|
107
|
+
var _a, _b, _c;
|
|
108
|
+
return h("a", { class: "PromotingBannersBox", href: banner === null || banner === void 0 ? void 0 : banner.url, target: banner.targetType, style: { backgroundImage: `url(${banner === null || banner === void 0 ? void 0 : banner.backgroundImage})` } }, h("div", { class: "PromotingBannersIconContainer" }, h("img", { src: (getDevice() === 'Android' || getDevice() === 'iPhone') ? (_a = banner.icon) === null || _a === void 0 ? void 0 : _a.mobile : (getDevice() === 'iPad') ? (_b = banner.image) === null || _b === void 0 ? void 0 : _b.srcTablet : (_c = banner.icon) === null || _c === void 0 ? void 0 : _c.desktop, alt: "Banner image" })), h("div", { class: "PromotingBannersTextContainer" }, h("h3", { class: "PromotingBannersTitle" }, banner === null || banner === void 0 ? void 0 : banner.title), h("div", { class: "PromotingBannersContent", innerHTML: banner === null || banner === void 0 ? void 0 : banner.description }), banner.button &&
|
|
109
|
+
h("button", { class: `PromotingBannersButton ${(banner === null || banner === void 0 ? void 0 : banner.button.text) ? '' : 'ButtonDisabled'}`, innerHTML: banner === null || banner === void 0 ? void 0 : banner.button.text, onClick: this.sendOpenLink.bind(this, banner === null || banner === void 0 ? void 0 : banner.button.url, banner === null || banner === void 0 ? void 0 : banner.button.externalLink, banner === null || banner === void 0 ? void 0 : banner.button.target) })));
|
|
110
|
+
}
|
|
111
|
+
render() {
|
|
112
|
+
var _a, _b, _c, _d;
|
|
113
|
+
return (h("div", { key: '80f15f2a7a49290bfd0fb80c6ccfb02b9fe3a0a9', class: "PromotingBannersSection", ref: el => this.stylingContainer = el }, this.hasErrors && h("div", { key: '392ef0a6910a457d17efc41a3a2443afc8be4a61', class: "AboutUsError" }, h("div", { key: 'c19eb8a49a8c8a422bd47557a7815e0252667005', class: "ErrorInfo" }, translate('error', this.language))), this.isLoading && h("div", { key: '28fc923e41227b8ca1529e8e2815ebd70678e50c', class: "SkeletonGrid" }, new Array(4).fill(null).map((index) => (h("div", { key: index, class: "Skeleton SkeletonItem" })))), !this.isLoading &&
|
|
114
|
+
h("div", { key: 'aff2d67a139ede5bdcc3c1ad240806594ab5fae7', class: "PromotingBannersWrapper" }, h("div", { key: '7d8caf2fee017407a618960ea37fff9d809e3eaa', class: getDevice() === 'PC' ? 'PromotingBannersHeader' : 'PromotingBannersHeader PromotingBannersHeaderMobile' }, ((_a = this.promotingBannersArray) === null || _a === void 0 ? void 0 : _a.title) && h("h1", { key: 'd947b41266fdfda8762ebc654c7a1c3516a08be5', class: "PromotingBannersSectionTitle" }, (_b = this.promotingBannersArray) === null || _b === void 0 ? void 0 : _b.title), ((_c = this.promotingBannersArray) === null || _c === void 0 ? void 0 : _c.description) && h("h5", { key: '72127f002e53c9e2d7430e222494c4470aca23e9', class: "PromotingBannersSectionSubtitle", style: { 'display': `${getDevice() !== 'PC' ? 'inline-block' : 'none'}` }, innerHTML: (_d = this.promotingBannersArray) === null || _d === void 0 ? void 0 : _d.description })), h("div", { key: '50c4fb4ae455f363d128993908016b0245c2bd50', class: "PromotingBannersGrid" }, this.promotingBannersArray.map(banner => (this.renderBannersGrid(banner)))))));
|
|
115
|
+
}
|
|
116
|
+
static get is() { return "promoting-banners"; }
|
|
117
|
+
static get encapsulation() { return "shadow"; }
|
|
118
|
+
static get originalStyleUrls() {
|
|
119
|
+
return {
|
|
120
|
+
"$": ["promoting-banners.scss"]
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
static get styleUrls() {
|
|
124
|
+
return {
|
|
125
|
+
"$": ["promoting-banners.css"]
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
static get properties() {
|
|
129
|
+
return {
|
|
130
|
+
"cmsEndpoint": {
|
|
131
|
+
"type": "string",
|
|
132
|
+
"mutable": false,
|
|
133
|
+
"complexType": {
|
|
134
|
+
"original": "string",
|
|
135
|
+
"resolved": "string",
|
|
136
|
+
"references": {}
|
|
137
|
+
},
|
|
138
|
+
"required": false,
|
|
139
|
+
"optional": false,
|
|
140
|
+
"docs": {
|
|
141
|
+
"tags": [],
|
|
142
|
+
"text": "The endpoint"
|
|
143
|
+
},
|
|
144
|
+
"attribute": "cms-endpoint",
|
|
145
|
+
"reflect": true,
|
|
146
|
+
"defaultValue": "''"
|
|
147
|
+
},
|
|
148
|
+
"language": {
|
|
149
|
+
"type": "string",
|
|
150
|
+
"mutable": false,
|
|
151
|
+
"complexType": {
|
|
152
|
+
"original": "string",
|
|
153
|
+
"resolved": "string",
|
|
154
|
+
"references": {}
|
|
155
|
+
},
|
|
156
|
+
"required": false,
|
|
157
|
+
"optional": false,
|
|
158
|
+
"docs": {
|
|
159
|
+
"tags": [],
|
|
160
|
+
"text": "The language"
|
|
161
|
+
},
|
|
162
|
+
"attribute": "language",
|
|
163
|
+
"reflect": true,
|
|
164
|
+
"defaultValue": "'en'"
|
|
165
|
+
},
|
|
166
|
+
"cmsEnv": {
|
|
167
|
+
"type": "string",
|
|
168
|
+
"mutable": false,
|
|
169
|
+
"complexType": {
|
|
170
|
+
"original": "string",
|
|
171
|
+
"resolved": "string",
|
|
172
|
+
"references": {}
|
|
173
|
+
},
|
|
174
|
+
"required": false,
|
|
175
|
+
"optional": false,
|
|
176
|
+
"docs": {
|
|
177
|
+
"tags": [],
|
|
178
|
+
"text": "The CMS environment"
|
|
179
|
+
},
|
|
180
|
+
"attribute": "cms-env",
|
|
181
|
+
"reflect": true,
|
|
182
|
+
"defaultValue": "''"
|
|
183
|
+
},
|
|
184
|
+
"clientStyling": {
|
|
185
|
+
"type": "string",
|
|
186
|
+
"mutable": false,
|
|
187
|
+
"complexType": {
|
|
188
|
+
"original": "string",
|
|
189
|
+
"resolved": "string",
|
|
190
|
+
"references": {}
|
|
191
|
+
},
|
|
192
|
+
"required": false,
|
|
193
|
+
"optional": false,
|
|
194
|
+
"docs": {
|
|
195
|
+
"tags": [],
|
|
196
|
+
"text": "Client custom styling via inline style"
|
|
197
|
+
},
|
|
198
|
+
"attribute": "client-styling",
|
|
199
|
+
"reflect": true,
|
|
200
|
+
"defaultValue": "''"
|
|
201
|
+
},
|
|
202
|
+
"clientStylingUrl": {
|
|
203
|
+
"type": "string",
|
|
204
|
+
"mutable": false,
|
|
205
|
+
"complexType": {
|
|
206
|
+
"original": "string",
|
|
207
|
+
"resolved": "string",
|
|
208
|
+
"references": {}
|
|
209
|
+
},
|
|
210
|
+
"required": false,
|
|
211
|
+
"optional": false,
|
|
212
|
+
"docs": {
|
|
213
|
+
"tags": [],
|
|
214
|
+
"text": "Client custom styling via url"
|
|
215
|
+
},
|
|
216
|
+
"attribute": "client-styling-url",
|
|
217
|
+
"reflect": true,
|
|
218
|
+
"defaultValue": "''"
|
|
219
|
+
},
|
|
220
|
+
"translationUrl": {
|
|
221
|
+
"type": "string",
|
|
222
|
+
"mutable": false,
|
|
223
|
+
"complexType": {
|
|
224
|
+
"original": "string",
|
|
225
|
+
"resolved": "string",
|
|
226
|
+
"references": {}
|
|
227
|
+
},
|
|
228
|
+
"required": false,
|
|
229
|
+
"optional": false,
|
|
230
|
+
"docs": {
|
|
231
|
+
"tags": [],
|
|
232
|
+
"text": "Translations via URL"
|
|
233
|
+
},
|
|
234
|
+
"attribute": "translation-url",
|
|
235
|
+
"reflect": true,
|
|
236
|
+
"defaultValue": "''"
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
static get states() {
|
|
241
|
+
return {
|
|
242
|
+
"promotingBannersArray": {},
|
|
243
|
+
"hasErrors": {},
|
|
244
|
+
"isLoading": {},
|
|
245
|
+
"translationData": {}
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
static get watchers() {
|
|
249
|
+
return [{
|
|
250
|
+
"propName": "clientStyling",
|
|
251
|
+
"methodName": "handleStylingChange"
|
|
252
|
+
}, {
|
|
253
|
+
"propName": "clientStylingUrl",
|
|
254
|
+
"methodName": "handleStylingChange"
|
|
255
|
+
}, {
|
|
256
|
+
"propName": "translationUrl",
|
|
257
|
+
"methodName": "handleNewTranslations"
|
|
258
|
+
}];
|
|
259
|
+
}
|
|
260
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components/promoting-banners';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const DEFAULT_LANGUAGE = 'en';
|
|
2
|
+
const TRANSLATIONS = {
|
|
3
|
+
en: {
|
|
4
|
+
error: 'Error',
|
|
5
|
+
noResults: 'Loading, please wait ...',
|
|
6
|
+
},
|
|
7
|
+
hu: {
|
|
8
|
+
error: 'Error',
|
|
9
|
+
noResults: 'Loading, please wait ...',
|
|
10
|
+
},
|
|
11
|
+
ro: {
|
|
12
|
+
error: 'Eroare',
|
|
13
|
+
noResults: 'Loading, please wait ...',
|
|
14
|
+
},
|
|
15
|
+
fr: {
|
|
16
|
+
error: 'Error',
|
|
17
|
+
noResults: 'Loading, please wait ...',
|
|
18
|
+
},
|
|
19
|
+
ar: {
|
|
20
|
+
error: 'خطأ',
|
|
21
|
+
noResults: 'Loading, please wait ...',
|
|
22
|
+
},
|
|
23
|
+
hr: {
|
|
24
|
+
error: 'Greška',
|
|
25
|
+
noResults: 'Učitavanje, molimo pričekajte ...',
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
export const translate = (key, customLang) => {
|
|
29
|
+
const lang = customLang;
|
|
30
|
+
return TRANSLATIONS[(lang !== undefined) && (lang in TRANSLATIONS) ? lang : DEFAULT_LANGUAGE][key];
|
|
31
|
+
};
|
|
32
|
+
export const getTranslations = (url) => {
|
|
33
|
+
// fetch url, get the data, replace the TRANSLATIONS content
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
fetch(url)
|
|
36
|
+
.then((res) => res.json())
|
|
37
|
+
.then((data) => {
|
|
38
|
+
Object.keys(data).forEach((item) => {
|
|
39
|
+
for (let key in data[item]) {
|
|
40
|
+
TRANSLATIONS[item][key] = data[item][key];
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
resolve(TRANSLATIONS);
|
|
44
|
+
}).catch(err => {
|
|
45
|
+
reject(err);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export const getDevice = () => {
|
|
2
|
+
let userAgent = window.navigator.userAgent;
|
|
3
|
+
if (userAgent.toLowerCase().match(/android/i)) {
|
|
4
|
+
return 'Android';
|
|
5
|
+
}
|
|
6
|
+
if (userAgent.toLowerCase().match(/iphone/i)) {
|
|
7
|
+
return 'iPhone';
|
|
8
|
+
}
|
|
9
|
+
if (userAgent.toLowerCase().match(/ipad|ipod/i)) {
|
|
10
|
+
return 'iPad';
|
|
11
|
+
}
|
|
12
|
+
return 'PC';
|
|
13
|
+
};
|
|
14
|
+
export const getDevicePlatform = () => {
|
|
15
|
+
const device = getDevice();
|
|
16
|
+
if (device) {
|
|
17
|
+
if (device === 'PC') {
|
|
18
|
+
return 'dk';
|
|
19
|
+
}
|
|
20
|
+
else if (device === 'iPad' || device === 'iPhone') {
|
|
21
|
+
return 'mtWeb';
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return 'mtWeb';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|