@salla.sa/twilight-components 2.13.44 → 2.13.46

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 (54) hide show
  1. package/dist/cjs/{app-globals-45feca8f.js → app-globals-0efa4587.js} +3 -3
  2. package/dist/cjs/app-globals-0efa4587.js.map +1 -0
  3. package/dist/cjs/loader.cjs.js +2 -2
  4. package/dist/cjs/salla-add-product-button_47.cjs.entry.js +55 -48
  5. package/dist/cjs/salla-add-product-button_47.cjs.entry.js.map +1 -1
  6. package/dist/cjs/twilight.cjs.js +2 -2
  7. package/dist/collection/components/salla-breadcrumb/interfaces.js.map +1 -1
  8. package/dist/collection/components/salla-breadcrumb/salla-breadcrumb.js +55 -57
  9. package/dist/collection/components/salla-breadcrumb/salla-breadcrumb.js.map +1 -1
  10. package/dist/components/index.js +2 -2
  11. package/dist/components/index.js.map +1 -1
  12. package/dist/components/salla-breadcrumb.js +56 -51
  13. package/dist/components/salla-breadcrumb.js.map +1 -1
  14. package/dist/components/salla-quick-buy2.js.map +1 -1
  15. package/dist/esm/{app-globals-486fea68.js → app-globals-32c0b133.js} +3 -3
  16. package/dist/esm/app-globals-32c0b133.js.map +1 -0
  17. package/dist/esm/loader.js +2 -2
  18. package/dist/esm/salla-add-product-button_47.entry.js +55 -48
  19. package/dist/esm/salla-add-product-button_47.entry.js.map +1 -1
  20. package/dist/esm/twilight.js +2 -2
  21. package/dist/esm-es5/app-globals-32c0b133.js +25 -0
  22. package/dist/esm-es5/app-globals-32c0b133.js.map +1 -0
  23. package/dist/esm-es5/loader.js +1 -1
  24. package/dist/esm-es5/loader.js.map +1 -1
  25. package/dist/esm-es5/salla-add-product-button_47.entry.js +1 -1
  26. package/dist/esm-es5/salla-add-product-button_47.entry.js.map +1 -1
  27. package/dist/esm-es5/twilight.js +1 -1
  28. package/dist/esm-es5/twilight.js.map +1 -1
  29. package/dist/twilight/{p-ae737289.entry.js → p-08934db3.entry.js} +2 -2
  30. package/dist/twilight/p-08934db3.entry.js.map +1 -0
  31. package/dist/twilight/{p-40ce25f9.system.entry.js → p-1126a332.system.entry.js} +2 -2
  32. package/dist/twilight/p-1126a332.system.entry.js.map +1 -0
  33. package/dist/twilight/p-44a3fce3.system.js +25 -0
  34. package/dist/twilight/p-44a3fce3.system.js.map +1 -0
  35. package/dist/twilight/p-93a162ca.js +25 -0
  36. package/dist/twilight/p-93a162ca.js.map +1 -0
  37. package/dist/twilight/{p-bf392e76.system.js → p-b9c7fc02.system.js} +2 -2
  38. package/dist/twilight/{p-bf392e76.system.js.map → p-b9c7fc02.system.js.map} +1 -1
  39. package/dist/twilight/twilight.esm.js +1 -1
  40. package/dist/twilight/twilight.esm.js.map +1 -1
  41. package/dist/twilight/twilight.js +1 -1
  42. package/dist/types/components/salla-breadcrumb/interfaces.d.ts +1 -0
  43. package/dist/types/components/salla-breadcrumb/salla-breadcrumb.d.ts +2 -14
  44. package/package.json +5 -5
  45. package/dist/cjs/app-globals-45feca8f.js.map +0 -1
  46. package/dist/esm/app-globals-486fea68.js.map +0 -1
  47. package/dist/esm-es5/app-globals-486fea68.js +0 -25
  48. package/dist/esm-es5/app-globals-486fea68.js.map +0 -1
  49. package/dist/twilight/p-40ce25f9.system.entry.js.map +0 -1
  50. package/dist/twilight/p-6005717c.system.js +0 -25
  51. package/dist/twilight/p-6005717c.system.js.map +0 -1
  52. package/dist/twilight/p-ae737289.entry.js.map +0 -1
  53. package/dist/twilight/p-c1d20d62.js +0 -25
  54. package/dist/twilight/p-c1d20d62.js.map +0 -1
@@ -13,59 +13,69 @@ const SallaBreadcrumb$1 = /*@__PURE__*/ proxyCustomElement(class SallaBreadcrumb
13
13
  var _a, _b;
14
14
  this.items = undefined;
15
15
  this.breadcrumbs = undefined;
16
- this.currentPage = salla.config.get('page');
17
- this.isRtl = salla.config.get('theme.is_rtl', true);
18
- salla.onReady(() => {
19
- this.isRtl = salla.config.get('theme.is_rtl', true);
20
- this.currentPage = salla.config.get('page');
21
- });
22
16
  // Initialize slot HTML or use default if not provided
23
17
  this.itemSlot = ((_a = this.host.querySelector('[slot="item"]')) === null || _a === void 0 ? void 0 : _a.outerHTML) || '<li class="s-breadcrumb-item"><a href={url}>{title}</a></li>';
24
18
  this.iconSlot = (_b = this.host.querySelector('[slot="icon"]')) === null || _b === void 0 ? void 0 : _b.outerHTML;
25
19
  }
26
- /**
27
- * Checks if the given index is the last index in the breadcrumbs array.
28
- * @param index - The index to check.
29
- * @returns True if the index is the last, false otherwise.
30
- */
31
- isLast(index) {
32
- return index === this.breadcrumbs.length - 1;
33
- }
34
- async getBreadcrumbs() {
35
- try {
36
- let params = {
37
- id: this.currentPage.id,
38
- page: this.currentPage.slug
39
- };
40
- if (this.currentPage.slug == 'product.single') {
41
- params['parent_id'] = this.currentPage.product_id;
20
+ componentWillLoad() {
21
+ return (new Promise(resolve => salla.onReady(() => salla.lang.onLoaded(resolve))))
22
+ .then(() => {
23
+ const page = salla.config.get("page");
24
+ if (!page || !page.slug) {
25
+ salla.logger.error('salla-breadcrumbs:: page object not existed on salla.config.get("page")!');
26
+ return [];
42
27
  }
43
- let resp = await salla.api.landing.fetchBreadcrumbs(params);
44
- this.breadcrumbs = resp.data[0];
45
- }
46
- catch (error) {
47
- salla.error("Error fetching breadcrumbs");
28
+ //get from api on these pages
29
+ if (['product.single', 'product.index'].includes(page.slug)) {
30
+ return salla.api.navigation.fetchBreadcrumbs({ page: page.slug, id: page.id, referrer: document.referrer })
31
+ .then(resp => this.breadcrumbs = resp.data);
32
+ }
33
+ //otherwise generate the breadcrumb
34
+ this.breadcrumbs = [{ title: salla.lang.get('common.titles.home'), url: salla.url.get('') }];
35
+ //inject my_account on the breadcrumb
36
+ if (page.slug.includes("customer")) {
37
+ this.breadcrumbs.push({ title: salla.lang.get('common.titles.profile'), url: salla.url.get('profile') });
38
+ }
39
+ //inject blog on the breadcrumb
40
+ if (page.slug.includes("blog")) {
41
+ this.breadcrumbs.push({ title: salla.lang.get('blocks.footer.blog'), url: salla.url.get('blog') });
42
+ }
43
+ //inject brands on the breadcrumb
44
+ if (page.slug == 'brands.single') {
45
+ this.breadcrumbs.push({ title: salla.lang.get('common.titles.brands'), url: salla.url.get('brands') });
46
+ }
47
+ //add the current page title as the last breadcrumb item, only if it's not set before
48
+ if (page.title && !['customer.profile', 'brands.index', 'blog.index'].includes(page.slug)) {
49
+ this.breadcrumbs.push({ title: page.title });
50
+ }
51
+ return this.breadcrumbs;
52
+ })
53
+ .then(() => this.breadcrumbs.length && (this.breadcrumbs[this.breadcrumbs.length - 1].is_last = true))
54
+ .catch((error) => {
55
+ salla.logger.error('salla-breadcrumb:: unexpected error!', error);
48
56
  this.breadcrumbs = [];
49
- }
57
+ });
50
58
  }
51
59
  /**
52
60
  * Renders the breadcrumb component.
53
61
  * @returns JSX for rendering breadcrumbs.
54
62
  */
55
63
  render() {
56
- return (h("ol", { class: "s-breadcrumb-wrapper" }, !!this.breadcrumbs ? this.breadcrumbs.map((item, index) => (!this.isLast(index) ? ([h("div", { id: "breadcrumb-slot", innerHTML: this.itemSlot
57
- .replace(/\{url\}/g, item.url)
58
- .replace(/\{title\}/g, item.title) }), h("li", { class: "s-breadcrumb-arrow" }, h("div", { id: 'breadcrumb-icon-slot', class: { "s-breadcrumb-default-icon": !this.iconSlot }, innerHTML: this.iconSlot ? this.iconSlot : this.isRtl ? KeyBoardArrowLeftIcon : KeyBoardArrowRightIcon }))
59
- ]) : (h("div", { id: "breadcrumb-slot", innerHTML: this.itemSlot
60
- .replace(/\{url\}/g, item.url)
61
- .replace(/\{title\}/g, item.title) })))) : ''));
64
+ if (this.breadcrumbs.length <= 1) {
65
+ salla.log('salla-breadcrumb:: There is no breadcrumbs!', this.breadcrumbs);
66
+ return;
67
+ }
68
+ return (h("ol", { class: "s-breadcrumb-wrapper" }, this.breadcrumbs.map(item => [
69
+ h("div", { class: "s-breadcrumb-slot", innerHTML: this.itemSlot.replace(/\{url\}/g, item.url).replace(/\{title\}/g, item.title) }),
70
+ this.getArrowDomForItem(item),
71
+ ])));
62
72
  }
63
- /**
64
- * Lifecycle method called before the component is loaded.
65
- * Parses the items string into breadcrumb items.
66
- */
67
- async componentWillLoad() {
68
- await this.getBreadcrumbs();
73
+ getArrowDomForItem(item) {
74
+ if (item.is_last) {
75
+ return '';
76
+ }
77
+ let iconDom = this.iconSlot || (salla.config.get('theme.is_rtl', true) ? KeyBoardArrowLeftIcon : KeyBoardArrowRightIcon);
78
+ return h("li", { class: "s-breadcrumb-arrow" }, h("div", { class: { "s-breadcrumb-icon-slot": true, "s-breadcrumb-default-icon": !this.iconSlot }, innerHTML: iconDom }));
69
79
  }
70
80
  /**
71
81
  * Lifecycle method called after the component is rendered.
@@ -74,27 +84,22 @@ const SallaBreadcrumb$1 = /*@__PURE__*/ proxyCustomElement(class SallaBreadcrumb
74
84
  * - Replaces the last anchor tag in the breadcrumb with its content.
75
85
  */
76
86
  componentDidRender() {
77
- var _a, _b;
87
+ var _a, _b, _c;
78
88
  // Reduces the number of elements in the DOM
79
- this.host.querySelectorAll('#breadcrumb-slot').forEach(el => el.replaceWith(el.firstChild));
80
- this.host.querySelectorAll('#breadcrumb-icon-slot.s-breadcrumb-default-icon').forEach(el => el.replaceWith(el.querySelector('svg')));
89
+ this.host.querySelectorAll('.s-breadcrumb-slot').forEach(el => el.replaceWith(el.firstChild));
90
+ this.host.querySelectorAll('.s-breadcrumb-icon-slot.s-breadcrumb-default-icon').forEach(el => el.replaceWith(el.querySelector('svg')));
81
91
  // Removes the slots parent elements if exists
82
92
  (_a = this.host.querySelector('[slot="item"]')) === null || _a === void 0 ? void 0 : _a.remove();
83
93
  (_b = this.host.querySelector('[slot="icon"]')) === null || _b === void 0 ? void 0 : _b.remove();
84
94
  // Removes the last anchor tag in the breadcrumb
85
- this.host.querySelectorAll('.s-breadcrumb-item').forEach((el, index) => {
86
- if (index === this.breadcrumbs.length - 1) {
87
- el.querySelector('a').replaceWith(el.querySelector('a').firstChild);
88
- }
89
- });
95
+ let lastEl = (_c = this.host.querySelectorAll('.s-breadcrumb-item')[this.breadcrumbs.length - 1]) === null || _c === void 0 ? void 0 : _c.querySelector('a');
96
+ lastEl && lastEl.replaceWith(lastEl.firstChild);
90
97
  }
91
98
  get host() { return this; }
92
99
  static get style() { return sallaBreadcrumbCss; }
93
100
  }, [0, "salla-breadcrumb", {
94
101
  "items": [1],
95
- "breadcrumbs": [32],
96
- "currentPage": [32],
97
- "isRtl": [32]
102
+ "breadcrumbs": [32]
98
103
  }]);
99
104
  function defineCustomElement$1() {
100
105
  if (typeof customElements === "undefined") {
@@ -1 +1 @@
1
- {"file":"salla-breadcrumb.js","mappings":";;;;;;AAAA,MAAM,kBAAkB,GAAG,sBAAsB;;MCiBpCA,iBAAe;EAC1B;;;;;;uBAsBuB,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;iBACrB,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC;IAtB9D,KAAK,CAAC,OAAO,CAAC;MACZ,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;MACpD,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;KAC7C,CAAC,CAAC;;IAGH,IAAI,CAAC,QAAQ,GAAG,CAAA,MAAA,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,0CAAE,SAAS,KAAI,8DAA8D,CAAC;IACtI,IAAI,CAAC,QAAQ,GAAG,MAAA,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,0CAAE,SAAS,CAAA;GACpE;;;;;;EAqBO,MAAM,CAAC,KAAa;IAC1B,OAAO,KAAK,KAAK,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC;GAC9C;EAEO,MAAM,cAAc;IAC1B,IAAI;MACF,IAAI,MAAM,GAAG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salla-breadcrumb","src/components/salla-breadcrumb/salla-breadcrumb.tsx"],"sourcesContent":[":host {\n display: block;\n}\n","import { Component, Prop, State, h, Element } from '@stencil/core';\nimport { BreadcrumbItem } from './interfaces';\nimport KeyBoardArrowLeftIcon from \"../../assets/svg/keyboard_arrow_left.svg\"\nimport KeyBoardArrowRightIcon from \"../../assets/svg/keyboard_arrow_right.svg\"\n\n/**\n * @name SallaBreadcrumb\n * @description A StencilJS component for rendering breadcrumb navigation.\n * @tag salla-breadcrumb\n *\n * @slot item - Replaces breadcrumb item, has replaceable props `{url}`, `{title}`.\n * @slot icon - Replaces breadcrumb arrow icon.\n */\n@Component({\n tag: 'salla-breadcrumb',\n styleUrl: 'salla-breadcrumb.scss',\n})\nexport class SallaBreadcrumb {\n constructor() {\n salla.onReady(() => {\n this.isRtl = salla.config.get('theme.is_rtl', true);\n this.currentPage = salla.config.get('page');\n });\n\n // Initialize slot HTML or use default if not provided\n this.itemSlot = this.host.querySelector('[slot=\"item\"]')?.outerHTML || '<li class=\"s-breadcrumb-item\"><a href={url}>{title}</a></li>';\n this.iconSlot = this.host.querySelector('[slot=\"icon\"]')?.outerHTML\n }\n\n @Element() host: HTMLElement;\n\n /**\n * Breadcrumb items in array\n */\n @Prop() items: string;\n\n private readonly itemSlot: string;\n private readonly iconSlot: string\n\n @State() breadcrumbs: BreadcrumbItem[];\n @State() currentPage = salla.config.get('page');\n @State() isRtl: boolean = salla.config.get('theme.is_rtl', true);\n\n /**\n * Checks if the given index is the last index in the breadcrumbs array.\n * @param index - The index to check.\n * @returns True if the index is the last, false otherwise.\n */\n private isLast(index: number): boolean {\n return index === this.breadcrumbs.length - 1;\n }\n\n private async getBreadcrumbs() {\n try {\n let params = {\n id: this.currentPage.id,\n page: this.currentPage.slug\n }\n if (this.currentPage.slug == 'product.single') {\n params['parent_id'] = this.currentPage.product_id;\n }\n let resp = await salla.api.landing.fetchBreadcrumbs(params);\n this.breadcrumbs = resp.data[0];\n } catch (error) {\n salla.error(\"Error fetching breadcrumbs\");\n this.breadcrumbs = [];\n }\n\n }\n\n /**\n * Renders the breadcrumb component.\n * @returns JSX for rendering breadcrumbs.\n */\n render() {\n return (\n <ol class=\"s-breadcrumb-wrapper\">\n {!!this.breadcrumbs ? this.breadcrumbs.map((item, index) => (\n !this.isLast(index) ? (\n [<div id=\"breadcrumb-slot\" innerHTML={this.itemSlot\n .replace(/\\{url\\}/g, item.url)\n .replace(/\\{title\\}/g, item.title)\n }>\n </div>,\n <li class=\"s-breadcrumb-arrow\">\n <div id='breadcrumb-icon-slot' class={{ \"s-breadcrumb-default-icon\": !this.iconSlot }} innerHTML={this.iconSlot ? this.iconSlot : this.isRtl ? KeyBoardArrowLeftIcon : KeyBoardArrowRightIcon}></div>\n </li>\n ]\n ) : (\n <div id=\"breadcrumb-slot\" innerHTML={this.itemSlot\n .replace(/\\{url\\}/g, item.url)\n .replace(/\\{title\\}/g, item.title)\n }>\n </div>\n )\n )) : ''}\n </ol>\n );\n }\n\n /**\n * Lifecycle method called before the component is loaded.\n * Parses the items string into breadcrumb items.\n */\n async componentWillLoad() {\n await this.getBreadcrumbs();\n try {\n // this.breadcrumbs = JSON.parse(this.items);\n\n } catch (error) {\n console.error(error);\n this.breadcrumbs = [];\n }\n }\n\n /**\n * Lifecycle method called after the component is rendered.\n * - Reduces the number of elements in the DOM.\n * - Removes unnecessary slots parent elements.\n * - Replaces the last anchor tag in the breadcrumb with its content.\n */\n componentDidRender() {\n // Reduces the number of elements in the DOM\n this.host.querySelectorAll('#breadcrumb-slot').forEach(el => el.replaceWith(el.firstChild));\n this.host.querySelectorAll('#breadcrumb-icon-slot.s-breadcrumb-default-icon').forEach(el => el.replaceWith(el.querySelector('svg')));\n\n // Removes the slots parent elements if exists\n this.host.querySelector('[slot=\"item\"]')?.remove();\n this.host.querySelector('[slot=\"icon\"]')?.remove();\n\n // Removes the last anchor tag in the breadcrumb\n this.host.querySelectorAll('.s-breadcrumb-item').forEach((el, index) => {\n if (index === this.breadcrum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,EAAE,EAAE,SAAS,EAAE,OAAO,GAAQ,CACpH,CAAC;GACP;;;;;;;EAQD,kBAAkB;;;IAEhB,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAC9F,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,mDAAmD,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;;IAGvI,MAAA,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,0CAAE,MAAM,EAAE,CAAC;IACnD,MAAA,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,0CAAE,MAAM,EAAE,CAAC;;IAGnD,IAAI,MAAM,GAAG,MAAA,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,0CAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC/G,MAAM,IAAI,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;GACjD;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["SallaBreadcrumb"],"sources":["src/components/salla-breadcrumb/salla-breadcrumb.scss?tag=salla-breadcrumb","src/components/salla-breadcrumb/salla-breadcrumb.tsx"],"sourcesContent":[":host {\n display: block;\n}\n","import { Component, Prop, State, h, Element } from '@stencil/core';\nimport { BreadcrumbItem } from './interfaces';\nimport KeyBoardArrowLeftIcon from \"../../assets/svg/keyboard_arrow_left.svg\"\nimport KeyBoardArrowRightIcon from \"../../assets/svg/keyboard_arrow_right.svg\"\n\n/**\n * @name SallaBreadcrumb\n * @description A StencilJS component for rendering breadcrumb navigation.\n * @tag salla-breadcrumb\n *\n * @slot item - Replaces breadcrumb item, has replaceable props `{url}`, `{title}`.\n * @slot icon - Replaces breadcrumb arrow icon.\n */\n@Component({\n tag: 'salla-breadcrumb',\n styleUrl: 'salla-breadcrumb.scss',\n})\nexport class SallaBreadcrumb {\n constructor() {\n\n // Initialize slot HTML or use default if not provided\n this.itemSlot = this.host.querySelector('[slot=\"item\"]')?.outerHTML || '<li class=\"s-breadcrumb-item\"><a href={url}>{title}</a></li>';\n this.iconSlot = this.host.querySelector('[slot=\"icon\"]')?.outerHTML\n }\n\n @Element() host: HTMLElement;\n\n /**\n * Breadcrumb items in array\n */\n @Prop() items: string;\n\n private readonly itemSlot: string;\n private readonly iconSlot: string;\n\n @State() breadcrumbs: BreadcrumbItem[];\n componentWillLoad() {\n return (new Promise(resolve => salla.onReady(() => salla.lang.onLoaded(resolve))))\n .then(() => {\n const page = salla.config.get(\"page\");\n if (!page || !page.slug) {\n salla.logger.error('salla-breadcrumbs:: page object not existed on salla.config.get(\"page\")!');\n return [];\n }\n\n //get from api on these pages\n if (['product.single', 'product.index'].includes(page.slug)) {\n return salla.api.navigation.fetchBreadcrumbs({ page: page.slug, id: page.id, referrer: document.referrer })\n .then(resp => this.breadcrumbs = resp.data);\n }\n\n //otherwise generate the breadcrumb\n\n this.breadcrumbs = [{ title: salla.lang.get('common.titles.home'), url: salla.url.get('') }];\n\n //inject my_account on the breadcrumb\n if (page.slug.includes(\"customer\")) {\n this.breadcrumbs.push({ title: salla.lang.get('common.titles.profile'), url: salla.url.get('profile') });\n }\n\n //inject blog on the breadcrumb\n if (page.slug.includes(\"blog\")) {\n this.breadcrumbs.push({ title: salla.lang.get('blocks.footer.blog'), url: salla.url.get('blog') });\n }\n\n //inject brands on the breadcrumb\n if (page.slug == 'brands.single') {\n this.breadcrumbs.push({ title: salla.lang.get('common.titles.brands'), url: salla.url.get('brands') });\n }\n\n //add the current page title as the last breadcrumb item, only if it's not set before\n if (page.title && !['customer.profile', 'brands.index', 'blog.index'].includes(page.slug)) {\n this.breadcrumbs.push({ title: page.title });\n }\n\n return this.breadcrumbs;\n })\n .then(() => this.breadcrumbs.length && (this.breadcrumbs[this.breadcrumbs.length - 1].is_last = true))\n .catch((error) => {\n salla.logger.error('salla-breadcrumb:: unexpected error!', error);\n this.breadcrumbs = [];\n });\n }\n\n /**\n * Renders the breadcrumb component.\n * @returns JSX for rendering breadcrumbs.\n */\n render() {\n if (this.breadcrumbs.length <= 1) {\n salla.log('salla-breadcrumb:: There is no breadcrumbs!', this.breadcrumbs);\n return;\n }\n return (\n <ol class=\"s-breadcrumb-wrapper\">\n {this.breadcrumbs.map(item => [\n <div class=\"s-breadcrumb-slot\" innerHTML={this.itemSlot.replace(/\\{url\\}/g, item.url).replace(/\\{title\\}/g, item.title)}></div>,\n this.getArrowDomForItem(item),\n ]\n )}\n </ol>\n );\n }\n\n private getArrowDomForItem(item: BreadcrumbItem) {\n if (item.is_last) {\n return '';\n }\n let iconDom = this.iconSlot || (salla.config.get('theme.is_rtl', true) ? KeyBoardArrowLeftIcon : KeyBoardArrowRightIcon);\n\n return <li class=\"s-breadcrumb-arrow\">\n <div class={{ \"s-breadcrumb-icon-slot\": true, \"s-breadcrumb-default-icon\": !this.iconSlot }} innerHTML={iconDom}></div>\n </li>;\n }\n\n /**\n * Lifecycle method called after the component is rendered.\n * - Reduces the number of elements in the DOM.\n * - Removes unnecessary slots parent elements.\n * - Replaces the last anchor tag in the breadcrumb with its content.\n */\n componentDidRender() {\n // Reduces the number of elements in the DOM\n this.host.querySelectorAll('.s-breadcrumb-slot').forEach(el => el.replaceWith(el.firstChild));\n this.host.querySelectorAll('.s-breadcrumb-icon-slot.s-breadcrumb-default-icon').forEach(el => el.replaceWith(el.querySelector('svg')));\n\n // Removes the slots parent elements if exists\n this.host.querySelector('[slot=\"item\"]')?.remove();\n this.host.querySelector('[slot=\"icon\"]')?.remove();\n\n // Removes the last anchor tag in the breadcrumb\n let lastEl = this.host.querySelectorAll('.s-breadcrumb-item')[this.breadcrumbs.length - 1]?.querySelector('a');\n lastEl && lastEl.replaceWith(lastEl.firstChild);\n }\n}\n"],"version":3}