@everymatrix/blog-articles-grid 1.99.27 → 1.99.28

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.
@@ -3,6 +3,7 @@ import { translate } from "../../utils/locale.utils";
3
3
  import { setClientStyling, setClientStylingURL, setStreamStyling } from "../../../../../../../../libs/common/src/styling/index";
4
4
  import { getDevicePlatform, getDeviceType } from "../../../../../../../../libs/common/src/device/index";
5
5
  import "../../../../../helper-pagination/dist/types/index";
6
+ const ALL_CATEGORY_ID = 'all';
6
7
  export class BlogArticlesGrid {
7
8
  constructor() {
8
9
  this.lastPage = 1;
@@ -11,24 +12,24 @@ export class BlogArticlesGrid {
11
12
  nav#PaginationContainer {
12
13
  justify-content: right;
13
14
  }
14
- .LeftItems a .NavigationButton {
15
+ .LeftItems .PaginationControl .NavigationButton {
15
16
  display: none;
16
17
  }
17
- .LeftItems a:after, .RightItems a:after {
18
+ .LeftItems .PaginationControl:after, .RightItems .PaginationControl:after {
18
19
  padding: 7px 12px;
19
20
  font-size: 18px;
20
21
  font-weight: 700;
21
22
  line-height: 46px;
22
23
  }
23
- .LeftItems a:after {
24
+ .LeftItems .PaginationControl:after {
24
25
  content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='1.2em' viewBox='0 0 320 512'%3E%3C!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --%3E%3Cpath d='M9.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l192 192c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L77.3 256 246.6 86.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-192 192z'/%3E%3C/svg%3E");
25
26
  }
26
- .RightItems a:after {
27
+ .RightItems .PaginationControl:after {
27
28
  content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='1.2em' viewBox='0 0 320 512'%3E%3C!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --%3E%3Cpath d='M310.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-192 192c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L242.7 256 73.4 86.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l192 192z'/%3E%3C/svg%3E");
28
29
  display: block;
29
30
  height: 38px;
30
31
  }
31
- div.LeftItems a, div.RightItems a {
32
+ div.LeftItems .PaginationControl, div.RightItems .PaginationControl {
32
33
  width: unset;
33
34
  height: 40px;
34
35
  background-color: #fff;
@@ -39,12 +40,12 @@ export class BlogArticlesGrid {
39
40
  background-color: #989898;
40
41
  }
41
42
  }
42
- div.LeftItems a {
43
+ div.LeftItems .PaginationControl {
43
44
  min-width: 60px;
44
45
  border-radius: 20px 0 0 20px;
45
46
  border-right: 0;
46
47
  }
47
- div.RightItems a {
48
+ div.RightItems .PaginationControl {
48
49
  display: flex;
49
50
  min-width: 100px;
50
51
  justify-content: space-evenly;
@@ -52,7 +53,7 @@ export class BlogArticlesGrid {
52
53
  border-radius: 0 20px 20px 0;
53
54
  text-transform: none;
54
55
  }
55
- .RightItems a .NavigationButton {
56
+ .RightItems .PaginationControl .NavigationButton {
56
57
  padding: 12px 0 12px 12px;
57
58
  font-weight: 700;
58
59
  }`;
@@ -110,7 +111,7 @@ export class BlogArticlesGrid {
110
111
  this.allBlogResponse = undefined;
111
112
  this.totalBlogs = 0;
112
113
  this.customTranslations = {};
113
- this.selectedCategory = 'all';
114
+ this.selectedCategory = ALL_CATEGORY_ID;
114
115
  this.categories = [];
115
116
  }
116
117
  getArticleId(event, post) {
@@ -176,7 +177,12 @@ export class BlogArticlesGrid {
176
177
  if (!this.pageQueryParam)
177
178
  return;
178
179
  const url = new URL(window.location.href);
179
- url.searchParams.set(this.pageQueryParam, String(pageNumber));
180
+ if (pageNumber === 1) {
181
+ url.searchParams.delete(this.pageQueryParam);
182
+ }
183
+ else {
184
+ url.searchParams.set(this.pageQueryParam, String(pageNumber));
185
+ }
180
186
  window.history.pushState(null, '', `${url.pathname}${url.search}${url.hash}`);
181
187
  }
182
188
  handleClientStylingChange(newValue, oldValue) {
@@ -220,6 +226,13 @@ export class BlogArticlesGrid {
220
226
  getActiveCategory() {
221
227
  return this.categories.find(category => category.id === this.selectedCategory);
222
228
  }
229
+ getCategorySlug(category) {
230
+ return category.slug || category.name.toLowerCase().replace(/\s+/g, '-');
231
+ }
232
+ getCategoryHref(category) {
233
+ const blogPath = `/${encodeURIComponent(this.language)}/blog`;
234
+ return category.id === ALL_CATEGORY_ID ? blogPath : `${blogPath}/category/${encodeURIComponent(this.getCategorySlug(category))}`;
235
+ }
223
236
  sortArticlesByDate(blogItems) {
224
237
  blogItems.sort((a, b) => {
225
238
  if (a.publishingDate > b.publishingDate)
@@ -250,12 +263,11 @@ export class BlogArticlesGrid {
250
263
  }
251
264
  async fetchBlogPosts(page, allPosts = false) {
252
265
  const url = new URL(`${this.cmsEndpoint}/${this.language}/blog-posts`);
253
- if (this.showBlogSubcategories &&
254
- this.selectedCategory &&
255
- this.selectedCategory !== 'all') {
266
+ if (this.selectedCategory &&
267
+ this.selectedCategory !== ALL_CATEGORY_ID) {
256
268
  const category = this.categories.find(cat => cat.id == this.selectedCategory);
257
- if (category === null || category === void 0 ? void 0 : category.slug) {
258
- url.searchParams.append('category', category.slug);
269
+ if (category) {
270
+ url.searchParams.append('category', this.getCategorySlug(category));
259
271
  }
260
272
  }
261
273
  url.searchParams.append('per_page', allPosts ? '300' : this.blogsLimit);
@@ -306,7 +318,7 @@ export class BlogArticlesGrid {
306
318
  const visibleCategories = categories.filter(category => { var _a; return !hiddenCategories.includes((_a = category.name) === null || _a === void 0 ? void 0 : _a.toLowerCase()); });
307
319
  this.categories = [
308
320
  {
309
- id: 'all',
321
+ id: ALL_CATEGORY_ID,
310
322
  name: 'All',
311
323
  },
312
324
  ...visibleCategories,
@@ -367,13 +379,10 @@ export class BlogArticlesGrid {
367
379
  }
368
380
  async componentWillLoad() {
369
381
  var _a;
370
- if (this.showBlogSubcategories) {
382
+ if (this.cmsEndpoint && this.language) {
371
383
  await this.fetchCategories();
372
384
  if (this.category) {
373
- const category = this.categories.find(cat => {
374
- var _a;
375
- return ((_a = cat.name) === null || _a === void 0 ? void 0 : _a.toLowerCase().replace(/\s+/g, '-')) === this.category;
376
- });
385
+ const category = this.categories.find(cat => cat.id !== ALL_CATEGORY_ID && this.getCategorySlug(cat) === this.category);
377
386
  if (category) {
378
387
  this.selectedCategory = category.id;
379
388
  this.emitActiveCategory();
@@ -398,14 +407,21 @@ export class BlogArticlesGrid {
398
407
  const category = this.categories.find(cat => cat.id === this.selectedCategory);
399
408
  window.postMessage({
400
409
  type: 'BlogArticlesActiveCategory',
401
- category: this.selectedCategory === 'all'
410
+ category: this.selectedCategory === ALL_CATEGORY_ID
402
411
  ? null
403
412
  : category === null || category === void 0 ? void 0 : category.name,
404
- metadata: this.selectedCategory === 'all'
413
+ categorySlug: category && this.selectedCategory !== ALL_CATEGORY_ID ? this.getCategorySlug(category) : null,
414
+ metadata: this.selectedCategory === ALL_CATEGORY_ID
405
415
  ? null
406
416
  : (_a = category === null || category === void 0 ? void 0 : category.metadata) !== null && _a !== void 0 ? _a : null,
407
417
  }, window.location.href);
408
418
  }
419
+ handleCategoryClick(event, categoryId) {
420
+ if (!this.usePostmessage || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)
421
+ return;
422
+ event.preventDefault();
423
+ this.handleCategoryChange(categoryId);
424
+ }
409
425
  async handleCategoryChange(categoryId) {
410
426
  if (this.isLoading || this.selectedCategory === categoryId) {
411
427
  return;
@@ -453,7 +469,7 @@ export class BlogArticlesGrid {
453
469
  }
454
470
  formatDate(dateString) {
455
471
  const date = this.parseDate(dateString);
456
- return new Intl.DateTimeFormat(this.intlDateTimeFormat).format(date);
472
+ return new Intl.DateTimeFormat(this.intlDateTimeFormat || 'en-GB', { day: 'numeric', month: 'short', year: 'numeric' }).format(date);
457
473
  }
458
474
  render() {
459
475
  var _a;
@@ -469,21 +485,28 @@ export class BlogArticlesGrid {
469
485
  const showPagination = Boolean(this.paginationActive) && this.totalBlogs > +this.blogsLimit;
470
486
  const paginationClientStyling = !this.mbSource ? (this.clientStyling || this.paginationDefaultStyling) : undefined;
471
487
  const activeCategory = this.getActiveCategory();
472
- return (h("div", { ref: el => this.stylingContainer = el }, this.showBreadcrumb && (h("nav", { class: "breadcrumb", "aria-label": "Breadcrumb" }, h("a", { href: `/${encodeURIComponent(this.language)}` }, translate('home', this.language, this.customTranslations)), h("span", { "aria-hidden": "true" }, "\u203A"), h("span", { "aria-current": "page" }, translate('blog', this.language, this.customTranslations)))), this.showPageTitle && h("h1", { class: "BlogPageTitle" }, " ", this.selectedCategory !== 'all' ? activeCategory === null || activeCategory === void 0 ? void 0 : activeCategory.name : translate('blogPageTitle', this.language, this.customTranslations), " "), this.selectedCategory !== 'all' &&
488
+ return (h("div", { ref: el => this.stylingContainer = el }, this.showBreadcrumb && (h("nav", { class: "breadcrumb", "aria-label": "Breadcrumb" }, h("a", { href: `/${encodeURIComponent(this.language)}` }, translate('home', this.language, this.customTranslations)), h("span", { "aria-hidden": "true" }, "\u203A"), activeCategory && this.selectedCategory !== ALL_CATEGORY_ID ? [
489
+ h("a", { href: `/${encodeURIComponent(this.language)}/blog` }, translate('blog', this.language, this.customTranslations)),
490
+ h("span", { "aria-hidden": "true" }, "\u203A"),
491
+ h("span", { "aria-current": "page" }, activeCategory.name),
492
+ ] : h("span", { "aria-current": "page" }, translate('blog', this.language, this.customTranslations)))), this.showPageTitle && h("h1", { class: "BlogPageTitle" }, " ", this.selectedCategory !== ALL_CATEGORY_ID ? activeCategory === null || activeCategory === void 0 ? void 0 : activeCategory.name : translate('blogPageTitle', this.language, this.customTranslations), " "), this.selectedCategory !== ALL_CATEGORY_ID &&
473
493
  (activeCategory === null || activeCategory === void 0 ? void 0 : activeCategory.description) && (h("div", { class: "BlogPageDescription", innerHTML: activeCategory.description })), h("div", { class: "BlogPageContainer" }, this.showBlogSubcategories &&
474
- h("div", { class: "BlogCategoriesSliderWrapper" }, h("div", { class: "CarouselWrapper" }, h("div", { class: "CarouselContainer" }, h("div", { class: "BlogCategoriesWrapper" }, h("div", { class: "CategoryButtons" }, this.categories.map(category => (h("button", { disabled: this.isLoading || this.selectedCategory === category.id, key: category.id, class: {
494
+ h("div", { class: "BlogCategoriesSliderWrapper" }, h("div", { class: "CarouselWrapper" }, h("div", { class: "CarouselContainer" }, h("div", { class: "BlogCategoriesWrapper" }, h("div", { class: "CategoryButtons" }, this.categories.map(category => (h("a", { href: this.getCategoryHref(category), "aria-current": this.selectedCategory === category.id ? 'page' : undefined, key: category.id, class: {
475
495
  CategoryButton: true,
476
496
  active: this.selectedCategory === category.id,
477
- }, onClick: () => {
478
- this.handleCategoryChange(category.id);
479
- } }, category.name)))))))), h("div", { class: "BlogGridPaginationWrapper" }, showPagination && h("helper-pagination", { "next-page": this.nextPage, "prev-page": this.previousPage, offset: this.paginationBlogList.offset, limit: parseInt(this.blogsLimit, 10), total: this.totalBlogs, language: this.language, "mb-source": this.mbSource, "client-styling": paginationClientStyling, "client-styling-url": this.clientStylingUrl, "arrows-active": this.arrowsActive, "secondary-arrows-active": this.secondaryArrowsActive, "numbered-nav-active": this.numberedNavActive, "page-query-param": this.pageQueryParam })), !this.isLoading && ((_a = this.displayedBlogResponse) === null || _a === void 0 ? void 0 : _a.items.length) === 0 && (h("p", { class: "EmptyState", role: "status" }, translate(this.selectedCategory === 'all' ? 'emptyState' : 'emptyCategoryState', this.language, this.customTranslations))), (!this.isLoading) &&
497
+ }, onClick: event => this.handleCategoryClick(event, category.id) }, category.name)))))))), h("div", { class: "BlogGridPaginationWrapper" }, showPagination && h("helper-pagination", { "next-page": this.nextPage, "prev-page": this.previousPage, offset: this.paginationBlogList.offset, limit: parseInt(this.blogsLimit, 10), total: this.totalBlogs, language: this.language, "mb-source": this.mbSource, "client-styling": paginationClientStyling, "client-styling-url": this.clientStylingUrl, "arrows-active": this.arrowsActive, "secondary-arrows-active": this.secondaryArrowsActive, "numbered-nav-active": this.numberedNavActive, "page-query-param": this.pageQueryParam })), !this.isLoading && ((_a = this.displayedBlogResponse) === null || _a === void 0 ? void 0 : _a.items.length) === 0 && (h("p", { class: "EmptyState", role: "status" }, translate(this.selectedCategory === ALL_CATEGORY_ID ? 'emptyState' : 'emptyCategoryState', this.language, this.customTranslations))), (!this.isLoading) &&
480
498
  h("div", { class: `GridContainerWrapper BlogPage-${this.currentPage} ${this.device}` }, this.displayedBlogResponse && this.displayedBlogResponse.items.map((data) => {
481
499
  var _a, _b;
482
- return h("div", { key: data.postID, class: data.isFeaturedPost ? 'GridContainer FeaturedPost' : 'GridContainer' }, h("div", { class: "GridWrapper" }, h("div", { class: "GridSector" }, this.showPublishingDate &&
483
- h("div", { class: "BlogDate" }, h("time", { dateTime: data.publishingDate }, this.formatDate(data.publishingDate))), this.showImage && ((_a = data.image) === null || _a === void 0 ? void 0 : _a.src) ? (h("img", { class: "VisualContent", src: this.setImage(data.image), alt: data.image.alt || data.title, width: "400", height: "225", loading: "lazy" })) : (((_b = data.video) === null || _b === void 0 ? void 0 : _b.sources[this.device]) ? (h("video", { class: "VisualContent", src: data.video.sources[this.device] })) : (h("span", { class: "VisualContent", style: { color: "#fff" } }, "No Image")))), h("div", { class: "GridSector" }, this.showTitle &&
500
+ const cardCategories = this.categories.filter(category => {
501
+ var _a;
502
+ return category.id !== ALL_CATEGORY_ID
503
+ && ((_a = data.blogCategory) === null || _a === void 0 ? void 0 : _a.includes(this.getCategorySlug(category)));
504
+ });
505
+ return (h("div", { key: data.postID, class: data.isFeaturedPost ? 'GridContainer FeaturedPost' : 'GridContainer' }, h("div", { class: "GridWrapper" }, h("div", { class: "GridSector" }, this.showPublishingDate &&
506
+ h("div", { class: "BlogDate" }, h("time", { dateTime: data.publishingDate }, this.formatDate(data.publishingDate))), this.showImage && ((_a = data.image) === null || _a === void 0 ? void 0 : _a.src) ? (h("img", { class: "VisualContent", src: this.setImage(data.image), alt: data.image.alt || data.title, width: "400", height: "225", loading: "lazy" })) : (((_b = data.video) === null || _b === void 0 ? void 0 : _b.sources[this.device]) ? (h("video", { class: "VisualContent", src: data.video.sources[this.device] })) : (h("span", { class: "VisualContent", style: { color: "#fff" } }, "No Image")))), h("div", { class: "GridSector" }, cardCategories.length > 0 && h("div", { class: "CategoryButtons BlogCardCategories" }, cardCategories.map(category => (h("a", { class: "CategoryButton", href: this.getCategoryHref(category), onClick: event => this.handleCategoryClick(event, category.id) }, category.name)))), this.showTitle &&
484
507
  h("h2", { class: "BlogTitle" }, h("a", { class: "BlogCardLink", href: `/${encodeURIComponent(this.language)}/blog/${encodeURIComponent(data.customPath || data.slug)}`, onClick: event => this.getArticleId(event, data) }, data.title)), this.showContent &&
485
508
  this.renderContentConditionally(data.descriptionPreview), this.showButton &&
486
- h("span", { class: "BlogLink" }, translate('readmore', this.language, this.customTranslations)))));
509
+ h("span", { class: "BlogLink" }, translate('readmore', this.language, this.customTranslations))))));
487
510
  })), (this.isLoading) &&
488
511
  h("div", { class: "GridContainerWrapper LoadingGrid" }, placeholderCards))));
489
512
  }
@@ -10,9 +10,9 @@ const TRANSLATIONS = {
10
10
  emptyCategoryState: 'We haven’t published any posts in this category. Check back soon, or browse all our articles.',
11
11
  },
12
12
  ro: {
13
- error: 'Eroare',
13
+ error: 'Error',
14
14
  readmore: 'Read more',
15
- home: 'Acasă',
15
+ home: 'Home',
16
16
  blog: 'Blog',
17
17
  blogPageTitle: 'Blog',
18
18
  emptyState: 'We haven’t published any posts yet. Check back soon.',
@@ -21,43 +21,43 @@ const TRANSLATIONS = {
21
21
  fr: {
22
22
  error: 'Error',
23
23
  readmore: 'Read more',
24
- home: 'Accueil',
24
+ home: 'Home',
25
25
  blog: 'Blog',
26
26
  blogPageTitle: 'Blog',
27
27
  emptyState: 'We haven’t published any posts yet. Check back soon.',
28
28
  emptyCategoryState: 'We haven’t published any posts in this category. Check back soon, or browse all our articles.',
29
29
  },
30
30
  ar: {
31
- error: 'خطأ',
31
+ error: 'Error',
32
32
  readmore: 'Read more',
33
- home: 'الرئيسية',
34
- blog: 'المدونة',
35
- blogPageTitle: 'المدونة',
33
+ home: 'Home',
34
+ blog: 'Blog',
35
+ blogPageTitle: 'Blog',
36
36
  emptyState: 'We haven’t published any posts yet. Check back soon.',
37
37
  emptyCategoryState: 'We haven’t published any posts in this category. Check back soon, or browse all our articles.',
38
38
  },
39
39
  hu: {
40
- error: 'خطأ',
41
- readmore: 'Tovább olvasom',
42
- home: 'Kezdőlap',
40
+ error: 'Error',
41
+ readmore: 'Read more',
42
+ home: 'Home',
43
43
  blog: 'Blog',
44
44
  blogPageTitle: 'Blog',
45
45
  emptyState: 'We haven’t published any posts yet. Check back soon.',
46
46
  emptyCategoryState: 'We haven’t published any posts in this category. Check back soon, or browse all our articles.',
47
47
  },
48
48
  hr: {
49
- error: 'Greška',
50
- readmore: 'Pročitaj više',
51
- home: 'Početna',
49
+ error: 'Error',
50
+ readmore: 'Read more',
51
+ home: 'Home',
52
52
  blog: 'Blog',
53
53
  blogPageTitle: 'Blog',
54
54
  emptyState: 'We haven’t published any posts yet. Check back soon.',
55
55
  emptyCategoryState: 'We haven’t published any posts in this category. Check back soon, or browse all our articles.',
56
56
  },
57
57
  'pt-br': {
58
- error: 'Erro',
59
- readmore: 'Ler mais',
60
- home: 'Início',
58
+ error: 'Error',
59
+ readmore: 'Read more',
60
+ home: 'Home',
61
61
  blog: 'Blog',
62
62
  blogPageTitle: 'Blog',
63
63
  emptyState: 'We haven’t published any posts yet. Check back soon.',
@@ -65,8 +65,8 @@ const TRANSLATIONS = {
65
65
  },
66
66
  'es-mx': {
67
67
  error: 'Error',
68
- readmore: 'Leer más',
69
- home: 'Inicio',
68
+ readmore: 'Read more',
69
+ home: 'Home',
70
70
  blog: 'Blog',
71
71
  blogPageTitle: 'Blog',
72
72
  emptyState: 'We haven’t published any posts yet. Check back soon.',
@@ -1,5 +1,5 @@
1
- import { p as promiseResolve, b as bootstrapLazy } from './index-4af8e775.js';
2
- export { s as setNonce } from './index-4af8e775.js';
1
+ import { p as promiseResolve, b as bootstrapLazy } from './index-6b3cf3ac.js';
2
+ export { s as setNonce } from './index-6b3cf3ac.js';
3
3
  import { g as globalScripts } from './app-globals-0f993ce5.js';
4
4
 
5
5
  /*