@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.
- package/dist/cjs/{app-globals-45feca8f.js → app-globals-0efa4587.js} +3 -3
- package/dist/cjs/app-globals-0efa4587.js.map +1 -0
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/salla-add-product-button_47.cjs.entry.js +55 -48
- package/dist/cjs/salla-add-product-button_47.cjs.entry.js.map +1 -1
- package/dist/cjs/twilight.cjs.js +2 -2
- package/dist/collection/components/salla-breadcrumb/interfaces.js.map +1 -1
- package/dist/collection/components/salla-breadcrumb/salla-breadcrumb.js +55 -57
- package/dist/collection/components/salla-breadcrumb/salla-breadcrumb.js.map +1 -1
- package/dist/components/index.js +2 -2
- package/dist/components/index.js.map +1 -1
- package/dist/components/salla-breadcrumb.js +56 -51
- package/dist/components/salla-breadcrumb.js.map +1 -1
- package/dist/components/salla-quick-buy2.js.map +1 -1
- package/dist/esm/{app-globals-486fea68.js → app-globals-32c0b133.js} +3 -3
- package/dist/esm/app-globals-32c0b133.js.map +1 -0
- package/dist/esm/loader.js +2 -2
- package/dist/esm/salla-add-product-button_47.entry.js +55 -48
- package/dist/esm/salla-add-product-button_47.entry.js.map +1 -1
- package/dist/esm/twilight.js +2 -2
- package/dist/esm-es5/app-globals-32c0b133.js +25 -0
- package/dist/esm-es5/app-globals-32c0b133.js.map +1 -0
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/loader.js.map +1 -1
- package/dist/esm-es5/salla-add-product-button_47.entry.js +1 -1
- package/dist/esm-es5/salla-add-product-button_47.entry.js.map +1 -1
- package/dist/esm-es5/twilight.js +1 -1
- package/dist/esm-es5/twilight.js.map +1 -1
- package/dist/twilight/{p-ae737289.entry.js → p-08934db3.entry.js} +2 -2
- package/dist/twilight/p-08934db3.entry.js.map +1 -0
- package/dist/twilight/{p-40ce25f9.system.entry.js → p-1126a332.system.entry.js} +2 -2
- package/dist/twilight/p-1126a332.system.entry.js.map +1 -0
- package/dist/twilight/p-44a3fce3.system.js +25 -0
- package/dist/twilight/p-44a3fce3.system.js.map +1 -0
- package/dist/twilight/p-93a162ca.js +25 -0
- package/dist/twilight/p-93a162ca.js.map +1 -0
- package/dist/twilight/{p-bf392e76.system.js → p-b9c7fc02.system.js} +2 -2
- package/dist/twilight/{p-bf392e76.system.js.map → p-b9c7fc02.system.js.map} +1 -1
- package/dist/twilight/twilight.esm.js +1 -1
- package/dist/twilight/twilight.esm.js.map +1 -1
- package/dist/twilight/twilight.js +1 -1
- package/dist/types/components/salla-breadcrumb/interfaces.d.ts +1 -0
- package/dist/types/components/salla-breadcrumb/salla-breadcrumb.d.ts +2 -14
- package/package.json +5 -5
- package/dist/cjs/app-globals-45feca8f.js.map +0 -1
- package/dist/esm/app-globals-486fea68.js.map +0 -1
- package/dist/esm-es5/app-globals-486fea68.js +0 -25
- package/dist/esm-es5/app-globals-486fea68.js.map +0 -1
- package/dist/twilight/p-40ce25f9.system.entry.js.map +0 -1
- package/dist/twilight/p-6005717c.system.js +0 -25
- package/dist/twilight/p-6005717c.system.js.map +0 -1
- package/dist/twilight/p-ae737289.entry.js.map +0 -1
- package/dist/twilight/p-c1d20d62.js +0 -25
- 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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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('
|
|
80
|
-
this.host.querySelectorAll('
|
|
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').
|
|
86
|
-
|
|
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
|
|
1
|
+
{"file":"salla-breadcrumb.js","mappings":";;;;;;AAAA,MAAM,kBAAkB,GAAG,sBAAsB;;MCiBpCA,iBAAe;EAC1B;;;;;;;IAGE,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;EAaD,iBAAiB;IACf,OAAO,CAAC,IAAI,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;OAC9E,IAAI,CAAC;MACJ,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;MACtC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;QACvB,KAAK,CAAC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,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}
|