@everymatrix/blog-article-details 1.0.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/blog-article-details/blog-article-details.esm.js +1 -0
  2. package/dist/blog-article-details/index.esm.js +0 -0
  3. package/dist/blog-article-details/p-0783b0ba.js +2 -0
  4. package/dist/blog-article-details/p-db82d889.entry.js +1 -0
  5. package/dist/blog-article-details/p-e1255160.js +1 -0
  6. package/dist/cjs/app-globals-3a1e7e63.js +5 -0
  7. package/dist/cjs/blog-article-details.cjs.entry.js +259 -0
  8. package/dist/cjs/blog-article-details.cjs.js +25 -0
  9. package/dist/cjs/index-ade27b33.js +1254 -0
  10. package/dist/cjs/index.cjs.js +2 -0
  11. package/dist/cjs/loader.cjs.js +15 -0
  12. package/dist/collection/collection-manifest.json +12 -0
  13. package/dist/collection/components/blog-article-details/blog-article-details.css +47 -0
  14. package/dist/collection/components/blog-article-details/blog-article-details.js +474 -0
  15. package/dist/collection/components/blog-article-details/index.js +1 -0
  16. package/dist/collection/index.js +1 -0
  17. package/dist/collection/utils/locale.utils.js +29 -0
  18. package/dist/collection/utils/utils.js +59 -0
  19. package/dist/esm/app-globals-0f993ce5.js +3 -0
  20. package/dist/esm/blog-article-details.entry.js +255 -0
  21. package/dist/esm/blog-article-details.js +20 -0
  22. package/dist/esm/index-9d94198d.js +1228 -0
  23. package/dist/esm/index.js +1 -0
  24. package/dist/esm/loader.js +11 -0
  25. package/dist/index.cjs.js +1 -0
  26. package/dist/index.js +1 -0
  27. package/dist/stencil.config.dev.js +17 -0
  28. package/dist/stencil.config.js +17 -0
  29. package/dist/types/Users/raul.vasile/workspace/everymatrix/widgets-monorepo/packages/stencil/blog-article-details/.stencil/packages/stencil/blog-article-details/stencil.config.d.ts +2 -0
  30. package/dist/types/Users/raul.vasile/workspace/everymatrix/widgets-monorepo/packages/stencil/blog-article-details/.stencil/packages/stencil/blog-article-details/stencil.config.dev.d.ts +2 -0
  31. package/dist/types/components/blog-article-details/blog-article-details.d.ts +80 -0
  32. package/dist/types/components/blog-article-details/index.d.ts +1 -0
  33. package/dist/types/components.d.ts +149 -0
  34. package/dist/types/index.d.ts +1 -0
  35. package/dist/types/stencil-public-runtime.d.ts +1674 -0
  36. package/dist/types/utils/locale.utils.d.ts +1 -0
  37. package/dist/types/utils/utils.d.ts +4 -0
  38. package/loader/cdn.js +1 -0
  39. package/loader/index.cjs.js +1 -0
  40. package/loader/index.d.ts +24 -0
  41. package/loader/index.es2017.js +1 -0
  42. package/loader/index.js +2 -0
  43. package/loader/package.json +11 -0
  44. package/package.json +26 -0
@@ -0,0 +1,255 @@
1
+ import { r as registerInstance, h } from './index-9d94198d.js';
2
+
3
+ const DEFAULT_LANGUAGE = 'en';
4
+ const SUPPORTED_LANGUAGES = ['ro', 'en', 'fr', 'ar', 'hr'];
5
+ const TRANSLATIONS = {
6
+ en: {
7
+ error: 'Error',
8
+ },
9
+ ro: {
10
+ error: 'Eroare',
11
+ },
12
+ fr: {
13
+ error: 'Error',
14
+ },
15
+ ar: {
16
+ error: 'خطأ',
17
+ },
18
+ hr: {
19
+ error: 'Greška',
20
+ },
21
+ 'pt-br': {
22
+ error: 'Erro'
23
+ },
24
+ 'es-mx': {
25
+ error: 'Error'
26
+ }
27
+ };
28
+ const translate = (key, customLang) => {
29
+ const lang = customLang;
30
+ return TRANSLATIONS[lang !== undefined && SUPPORTED_LANGUAGES.includes(lang) ? lang : DEFAULT_LANGUAGE][key];
31
+ };
32
+
33
+ const getDevice = () => {
34
+ let userAgent = window.navigator.userAgent;
35
+ if (userAgent.toLowerCase().match(/android/i)) {
36
+ return 'Android';
37
+ }
38
+ if (userAgent.toLowerCase().match(/iphone/i)) {
39
+ return 'iPhone';
40
+ }
41
+ if (userAgent.toLowerCase().match(/ipad|ipod/i)) {
42
+ return 'iPad';
43
+ }
44
+ return 'PC';
45
+ };
46
+ function checkCustomDeviceWidth() {
47
+ const width = screen.availWidth;
48
+ if (width < 600) {
49
+ return 'mobile';
50
+ }
51
+ else if (width >= 600 && width < 1100) {
52
+ return 'tablet';
53
+ }
54
+ }
55
+ function getDeviceCustom() {
56
+ const userAgent = navigator.userAgent.toLowerCase();
57
+ let source = '';
58
+ source = (userAgent.includes('android') || userAgent.includes('iphone') || userAgent.includes('ipad')) ? checkCustomDeviceWidth() : 'desktop';
59
+ return source;
60
+ }
61
+ const getDevicePlatform = () => {
62
+ const device = getDevice();
63
+ if (device) {
64
+ if (device === 'PC') {
65
+ return 'dk';
66
+ }
67
+ else if (device === 'iPad' || device === 'iPhone') {
68
+ return 'mtWeb';
69
+ }
70
+ else {
71
+ return 'mtWeb';
72
+ }
73
+ }
74
+ };
75
+
76
+ const blogArticleDetailsCss = ":host {\n display: block;\n}\n\n.DetailsContainer {\n background-color: #07072A;\n color: #fff;\n display: flex;\n flex-direction: column;\n}\n.DetailsContainer .BlogBanner div {\n height: 400px;\n}\n.DetailsContainer .DetailsHeadWrapper {\n position: relative;\n}\n.DetailsContainer .DetailsBodyWrapper {\n padding: 30px;\n}\n.DetailsContainer .BlogDate {\n font-size: 12px;\n border-radius: 5px 5px 0 0;\n padding: 10px;\n width: fit-content;\n text-align: center;\n background-color: #0D0D4D;\n z-index: 1;\n text-wrap: nowrap;\n position: absolute;\n bottom: 0;\n left: 30px;\n}\n.DetailsContainer .BlogTitle {\n font-size: 24px;\n}\n.DetailsContainer .BlogContent {\n font-size: 14px;\n}\n.DetailsContainer .BlogContent p:last-child {\n margin-bottom: 0;\n}\n\n@container (max-width: 475px) {\n .DetailsContainer {\n font-size: 12px;\n }\n}";
77
+ const BlogArticleDetailsStyle0 = blogArticleDetailsCss;
78
+
79
+ const BlogArticleDetails = class {
80
+ constructor(hostRef) {
81
+ registerInstance(this, hostRef);
82
+ this.setClientStyling = () => {
83
+ let sheet = document.createElement('style');
84
+ sheet.innerHTML = this.clientStyling;
85
+ this.stylingContainer.prepend(sheet);
86
+ };
87
+ this.setClientStylingURL = () => {
88
+ let url = new URL(this.clientStylingUrl);
89
+ let cssFile = document.createElement('style');
90
+ fetch(url.href)
91
+ .then((res) => res.text())
92
+ .then((data) => {
93
+ cssFile.innerHTML = data;
94
+ setTimeout(() => { this.stylingContainer.prepend(cssFile); }, 1);
95
+ })
96
+ .catch((err) => {
97
+ console.log('Error ', err);
98
+ });
99
+ };
100
+ this.renderContentConditionally = (content) => {
101
+ const hasBanner = (content === null || content === void 0 ? void 0 : content.indexOf('<bannermatrix-banner')) !== -1;
102
+ if (!hasBanner) {
103
+ return h("div", { class: "BlogContent", innerHTML: content });
104
+ }
105
+ if (this.bannerMatrixReady) {
106
+ return h("div", { class: "BlogContent", innerHTML: content });
107
+ }
108
+ return null;
109
+ };
110
+ this.setImage = (image) => {
111
+ let source = '';
112
+ switch (this.device) {
113
+ case 'mobile':
114
+ source = image.sources[0].pictureSource;
115
+ break;
116
+ case 'tablet':
117
+ source = image.sources[1].pictureSource;
118
+ break;
119
+ case 'desktop':
120
+ source = image.sources[2].pictureSource;
121
+ break;
122
+ }
123
+ return source;
124
+ };
125
+ this.cmsEndpoint = undefined;
126
+ this.language = 'en';
127
+ this.userRoles = 'everyone';
128
+ this.cmsEnv = 'stage';
129
+ this.clientStyling = '';
130
+ this.clientStylingUrl = '';
131
+ this.showPublishingDate = true;
132
+ this.showImage = true;
133
+ this.showTitle = true;
134
+ this.showContent = true;
135
+ this.postId = undefined;
136
+ this.postSlug = undefined;
137
+ this.postCustomPath = undefined;
138
+ this.intlDateTimeFormat = '';
139
+ this.hasErrors = false;
140
+ this.limitStylingAppends = false;
141
+ this.isLoading = true;
142
+ this.bannerMatrixReady = false;
143
+ this.device = '';
144
+ }
145
+ // Rerender when bannermatrix has finished loaded. Issue when bannermatrix passed as content from CMS.
146
+ handleBannerReady() {
147
+ this.bannerMatrixReady = true;
148
+ }
149
+ watchEndpoint(newValue, oldValue) {
150
+ if (newValue && newValue != oldValue && this.cmsEndpoint && this.language && (this.postCustomPath || this.postSlug || this.postId)) {
151
+ this.getBlogArticleDetails();
152
+ }
153
+ }
154
+ handleStylingChange(newValue, oldValue) {
155
+ if (newValue !== oldValue)
156
+ this.setClientStyling();
157
+ }
158
+ handleStylingUrlChange(newValue, oldValue) {
159
+ if (newValue !== oldValue)
160
+ this.setClientStylingURL();
161
+ }
162
+ connectedCallback() {
163
+ if (this.cmsEndpoint && this.language && (this.postCustomPath || this.postSlug || this.postId)) {
164
+ this.getBlogArticleDetails();
165
+ }
166
+ }
167
+ getBlogArticleDetails() {
168
+ if (!this.postId && !this.postSlug && !this.postCustomPath) {
169
+ this.hasErrors = true;
170
+ throw new Error('postId, postSlug or postCustomPath parameter has to be provided!');
171
+ }
172
+ this.isLoading = true;
173
+ let url = new URL(`${this.cmsEndpoint}/${this.language}/blog-posts${this.postCustomPath ? '' : '/' + this.postSlug || '/' + this.postId}`);
174
+ url.searchParams.append('env', this.cmsEnv);
175
+ url.searchParams.append('userRoles', this.userRoles);
176
+ url.searchParams.append('device', getDevicePlatform());
177
+ if (this.postCustomPath) {
178
+ url.searchParams.append('customURL', this.postCustomPath);
179
+ }
180
+ fetch(url.href)
181
+ .then((res) => {
182
+ if (res.status >= 300) {
183
+ this.hasErrors = true;
184
+ throw new Error('There was an error while fetching the data');
185
+ }
186
+ return res.json();
187
+ })
188
+ .then((blogContent) => {
189
+ if (blogContent.count >= 1 && this.postCustomPath) {
190
+ let firstBlogPublishDate = new Date(blogContent.items[0].publishingDate);
191
+ let indexOfLatestPublished = 0;
192
+ for (let i = 1; i < blogContent.items.length; i++) {
193
+ const blogDate = new Date(blogContent.items[i].publishingDate);
194
+ if (firstBlogPublishDate.getTime() < blogDate.getTime()) {
195
+ firstBlogPublishDate = blogDate;
196
+ indexOfLatestPublished = i;
197
+ }
198
+ }
199
+ this.blogData = blogContent.items[indexOfLatestPublished];
200
+ }
201
+ else {
202
+ this.blogData = blogContent;
203
+ }
204
+ this.isLoading = false;
205
+ })
206
+ .catch((err) => {
207
+ this.hasErrors = true;
208
+ console.log('Error', err);
209
+ })
210
+ .finally(() => this.isLoading = false);
211
+ }
212
+ componentDidRender() {
213
+ // start custom styling area
214
+ if (!this.limitStylingAppends && this.stylingContainer) {
215
+ if (this.clientStyling)
216
+ this.setClientStyling();
217
+ if (this.clientStylingUrl)
218
+ this.setClientStylingURL();
219
+ this.limitStylingAppends = true;
220
+ }
221
+ // end custom styling area
222
+ }
223
+ componentDidLoad() {
224
+ this.detectAndAlertDeviceType();
225
+ }
226
+ detectAndAlertDeviceType() {
227
+ this.device = getDeviceCustom();
228
+ }
229
+ formatDate(dateString) {
230
+ return new Intl.DateTimeFormat(this.intlDateTimeFormat || 'en-GB').format(new Date(dateString));
231
+ }
232
+ render() {
233
+ var _a, _b, _c, _d, _e;
234
+ if (this.hasErrors) {
235
+ return (h("div", { class: "BlogArticleDetails" }, h("div", { class: "Title" }, translate('error', this.language))));
236
+ }
237
+ if (!this.isLoading) {
238
+ return (h("div", { ref: el => this.stylingContainer = el }, h("div", { class: "DetailsContainer" }, h("div", { class: "DetailsHeadWrapper" }, this.showPublishingDate && this.blogData.publishingDate &&
239
+ h("div", { class: "BlogDate" }, this.formatDate((_a = this.blogData) === null || _a === void 0 ? void 0 : _a.publishingDate)), this.showImage && (h("div", { class: "BlogBanner" }, ((_b = this.blogData.image) === null || _b === void 0 ? void 0 : _b.src) ? (h("div", { style: { background: `url(${this.setImage(this.blogData.image)}) no-repeat center center / cover` } })) : (((_c = this.blogData.video) === null || _c === void 0 ? void 0 : _c.sources[this.device]) ? (h("video", { src: this.blogData.video.sources[this.device], controls: true })) : (h("h1", { style: { color: "white" } }, "No Image")))))), h("div", { class: "DetailsBodyWrapper" }, this.showTitle &&
240
+ h("div", { class: "BlogTitle" }, (_d = this.blogData) === null || _d === void 0 ? void 0 : _d.title), this.showContent && this.renderContentConditionally((_e = this.blogData) === null || _e === void 0 ? void 0 : _e.content)))));
241
+ }
242
+ }
243
+ static get watchers() { return {
244
+ "postId": ["watchEndpoint"],
245
+ "postSlug": ["watchEndpoint"],
246
+ "postCustomPath": ["watchEndpoint"],
247
+ "cmsEndpoint": ["watchEndpoint"],
248
+ "language": ["watchEndpoint"],
249
+ "clientStyling": ["handleStylingChange"],
250
+ "clientStylingUrl": ["handleStylingUrlChange"]
251
+ }; }
252
+ };
253
+ BlogArticleDetails.style = BlogArticleDetailsStyle0;
254
+
255
+ export { BlogArticleDetails as blog_article_details };
@@ -0,0 +1,20 @@
1
+ import { p as promiseResolve, b as bootstrapLazy } from './index-9d94198d.js';
2
+ export { s as setNonce } from './index-9d94198d.js';
3
+ import { g as globalScripts } from './app-globals-0f993ce5.js';
4
+
5
+ /*
6
+ Stencil Client Patch Browser v4.20.0 | MIT Licensed | https://stenciljs.com
7
+ */
8
+ var patchBrowser = () => {
9
+ const importMeta = import.meta.url;
10
+ const opts = {};
11
+ if (importMeta !== "") {
12
+ opts.resourcesUrl = new URL(".", importMeta).href;
13
+ }
14
+ return promiseResolve(opts);
15
+ };
16
+
17
+ patchBrowser().then(async (options) => {
18
+ await globalScripts();
19
+ return bootstrapLazy([["blog-article-details",[[1,"blog-article-details",{"cmsEndpoint":[513,"cms-endpoint"],"language":[513],"userRoles":[513,"user-roles"],"cmsEnv":[513,"cms-env"],"clientStyling":[513,"client-styling"],"clientStylingUrl":[513,"client-styling-url"],"showPublishingDate":[516,"show-publishing-date"],"showImage":[516,"show-image"],"showTitle":[516,"show-title"],"showContent":[516,"show-content"],"postId":[514,"post-id"],"postSlug":[513,"post-slug"],"postCustomPath":[513,"post-custom-path"],"intlDateTimeFormat":[1,"intl-date-time-format"],"hasErrors":[32],"limitStylingAppends":[32],"isLoading":[32],"bannerMatrixReady":[32],"device":[32]},[[8,"BannerMatrixReady","handleBannerReady"]],{"postId":["watchEndpoint"],"postSlug":["watchEndpoint"],"postCustomPath":["watchEndpoint"],"cmsEndpoint":["watchEndpoint"],"language":["watchEndpoint"],"clientStyling":["handleStylingChange"],"clientStylingUrl":["handleStylingUrlChange"]}]]]], options);
20
+ });