@salla.sa/twilight-components 1.0.19 → 1.0.21

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 (92) hide show
  1. package/dist/{esm → twilight-components}/Helper-d07ebbc7.js +0 -0
  2. package/dist/twilight-components/app-globals-0f993ce5.js +3 -0
  3. package/dist/twilight-components/css-shim-a64b8820.js +4 -0
  4. package/dist/twilight-components/dom-d08ba8aa.js +73 -0
  5. package/dist/twilight-components/index-9c087700.js +3010 -0
  6. package/dist/twilight-components/index.esm.js +4 -1
  7. package/dist/{esm → twilight-components}/salla-branches.entry.js +1 -1
  8. package/dist/twilight-components/salla-button.entry.js +75 -0
  9. package/dist/{esm → twilight-components}/salla-localization.entry.js +1 -1
  10. package/dist/{esm/salla-login-38586400.js → twilight-components/salla-login-57b18c2c.js} +1 -1
  11. package/dist/twilight-components/salla-login.entry.js +3 -0
  12. package/dist/twilight-components/salla-modal.entry.js +113 -0
  13. package/dist/twilight-components/salla-offer.entry.js +75 -0
  14. package/dist/{esm → twilight-components}/salla-product-availability.entry.js +1 -1
  15. package/dist/twilight-components/salla-rating.entry.js +228 -0
  16. package/dist/{esm/salla-search-ca856aab.js → twilight-components/salla-search-30fec1e8.js} +1 -1
  17. package/dist/twilight-components/salla-search.entry.js +3 -0
  18. package/dist/{esm/salla-button_5.entry.js → twilight-components/salla-tel-input.entry.js} +33 -294
  19. package/dist/twilight-components/salla-verify.entry.js +114 -0
  20. package/dist/twilight-components/shadow-css-bc14d9fd.js +389 -0
  21. package/dist/twilight-components/twilight-components.css +3 -1
  22. package/dist/twilight-components/twilight-components.esm.js +125 -1
  23. package/dist/types/components/salla-offer/offer-schema.d.ts +47 -0
  24. package/dist/types/components/salla-offer/salla-offer.d.ts +13 -48
  25. package/dist/types/components/salla-rating/order-feedback-response.d.ts +62 -0
  26. package/dist/types/components/salla-rating/salla-rating.d.ts +25 -23
  27. package/dist/types/components.d.ts +2 -10
  28. package/package.json +1 -1
  29. package/dist/cjs/Helper-fcea994c.js +0 -23
  30. package/dist/cjs/index-4b8b3ffe.js +0 -1696
  31. package/dist/cjs/index.cjs.js +0 -13
  32. package/dist/cjs/loader.cjs.js +0 -21
  33. package/dist/cjs/salla-branches.cjs.entry.js +0 -92
  34. package/dist/cjs/salla-button_5.cjs.entry.js +0 -1686
  35. package/dist/cjs/salla-localization.cjs.entry.js +0 -82
  36. package/dist/cjs/salla-login-008cc893.js +0 -125
  37. package/dist/cjs/salla-offer.cjs.entry.js +0 -50
  38. package/dist/cjs/salla-product-availability.cjs.entry.js +0 -75
  39. package/dist/cjs/salla-rating.cjs.entry.js +0 -300
  40. package/dist/cjs/salla-search-c7aad59a.js +0 -81
  41. package/dist/cjs/salla-search.cjs.entry.js +0 -11
  42. package/dist/cjs/twilight-components.cjs.js +0 -19
  43. package/dist/collection/Helpers/Helper.js +0 -19
  44. package/dist/collection/collection-manifest.json +0 -22
  45. package/dist/collection/components/generate-summary.js +0 -35
  46. package/dist/collection/components/salla-branches/salla-branches.css +0 -12
  47. package/dist/collection/components/salla-branches/salla-branches.js +0 -233
  48. package/dist/collection/components/salla-button/salla-button.css +0 -3
  49. package/dist/collection/components/salla-button/salla-button.js +0 -246
  50. package/dist/collection/components/salla-localization/salla-localization.js +0 -208
  51. package/dist/collection/components/salla-login/salla-login.css +0 -3
  52. package/dist/collection/components/salla-login/salla-login.js +0 -378
  53. package/dist/collection/components/salla-modal/salla-modal.js +0 -459
  54. package/dist/collection/components/salla-offer/salla-offer.js +0 -81
  55. package/dist/collection/components/salla-product-availability/salla-product-availability.js +0 -331
  56. package/dist/collection/components/salla-rating/salla-rating.css +0 -7
  57. package/dist/collection/components/salla-rating/salla-rating.js +0 -483
  58. package/dist/collection/components/salla-search/salla-search.js +0 -132
  59. package/dist/collection/components/salla-tel-input/salla-tel-input.js +0 -14
  60. package/dist/collection/components/salla-verify/salla-verify.js +0 -273
  61. package/dist/collection/index.js +0 -2
  62. package/dist/collection/interfaces/colors.js +0 -1
  63. package/dist/collection/interfaces/index.js +0 -2
  64. package/dist/collection/interfaces/ratio.js +0 -1
  65. package/dist/collection/plugins/tailwind-theme/generator.js +0 -62
  66. package/dist/collection/plugins/tailwind-theme/index.js +0 -26
  67. package/dist/esm/index-092659c7.js +0 -1668
  68. package/dist/esm/index.js +0 -4
  69. package/dist/esm/loader.js +0 -17
  70. package/dist/esm/polyfills/core-js.js +0 -11
  71. package/dist/esm/polyfills/css-shim.js +0 -1
  72. package/dist/esm/polyfills/dom.js +0 -79
  73. package/dist/esm/polyfills/es5-html-element.js +0 -1
  74. package/dist/esm/polyfills/index.js +0 -34
  75. package/dist/esm/polyfills/system.js +0 -6
  76. package/dist/esm/salla-offer.entry.js +0 -46
  77. package/dist/esm/salla-rating.entry.js +0 -296
  78. package/dist/esm/salla-search.entry.js +0 -3
  79. package/dist/esm/twilight-components.js +0 -17
  80. package/dist/index.cjs.js +0 -1
  81. package/dist/index.js +0 -1
  82. package/dist/twilight-components/p-03d0ec44.entry.js +0 -1
  83. package/dist/twilight-components/p-13a55257.entry.js +0 -1
  84. package/dist/twilight-components/p-160062c6.js +0 -1
  85. package/dist/twilight-components/p-47f17d3b.js +0 -1
  86. package/dist/twilight-components/p-5307c7b5.entry.js +0 -1
  87. package/dist/twilight-components/p-6a1f43c6.entry.js +0 -1
  88. package/dist/twilight-components/p-7088e517.entry.js +0 -1
  89. package/dist/twilight-components/p-924e3c88.js +0 -1
  90. package/dist/twilight-components/p-e8965b01.js +0 -1
  91. package/dist/twilight-components/p-ecb1b6cc.entry.js +0 -1
  92. package/dist/twilight-components/p-f11b401a.entry.js +0 -1
@@ -1 +1,4 @@
1
- export{S as SallaLogin}from"./p-160062c6.js";export{S as SallaSearch}from"./p-924e3c88.js";import"./p-e8965b01.js";import"./p-47f17d3b.js";
1
+ export { S as SallaLogin } from './salla-login-57b18c2c.js';
2
+ export { S as SallaSearch } from './salla-search-30fec1e8.js';
3
+ import './index-9c087700.js';
4
+ import './Helper-d07ebbc7.js';
@@ -1,4 +1,4 @@
1
- import { r as registerInstance, h, g as getElement } from './index-092659c7.js';
1
+ import { r as registerInstance, h, g as getElement } from './index-9c087700.js';
2
2
 
3
3
  const sallaBranchesCss = ":host{display:block}";
4
4
 
@@ -0,0 +1,75 @@
1
+ import { r as registerInstance, h, e as Host, g as getElement } from './index-9c087700.js';
2
+ import { H as Helper } from './Helper-d07ebbc7.js';
3
+
4
+ const sallaButtonCss = ":host{display:block}";
5
+
6
+ const SallaButton = class {
7
+ constructor(hostRef) {
8
+ registerInstance(this, hostRef);
9
+ this.btnStyle = 'primary';
10
+ this.loading = false;
11
+ this.disabled = false;
12
+ this.loaderPosition = 'before';
13
+ this.wide = false;
14
+ this.hostAttributes = {};
15
+ //============= Initiate Button Attributes =============//
16
+ for (let i = 0; i < this.host.attributes.length; i++) {
17
+ this.hostAttributes[this.host.attributes[i].name] = this.host.attributes[i].value;
18
+ }
19
+ this.hostAttributes.type = this.hostAttributes.type || 'button';
20
+ this.hostAttributes.class += ' s-button-btn btn--has-loading'
21
+ + ' s-button-' + this.btnStyle
22
+ + (this.wide ? ' s-button-wide ' : '')
23
+ + ' loader-' + this.loaderPosition
24
+ + (this.loaderPosition == 'before' ? ' s-button-loader-after' : '');
25
+ delete this.hostAttributes['btn-style'];
26
+ delete this.hostAttributes['id'];
27
+ if (this.wide) {
28
+ this.host.classList.add('s-button-wide');
29
+ }
30
+ }
31
+ async load() {
32
+ if (this.loaderPosition == 'center')
33
+ this.text.classList.add('s-button-hide');
34
+ this.host.setAttribute('loading', '');
35
+ return this.host;
36
+ }
37
+ async stop() {
38
+ this.host.removeAttribute('loading');
39
+ return this.host;
40
+ }
41
+ async disable() {
42
+ this.host.setAttribute('disabled', '');
43
+ }
44
+ async enable() {
45
+ this.host.removeAttribute('disabled');
46
+ }
47
+ handleVisible(newKind, oldKind) {
48
+ //todo::use united styles
49
+ this.btn.classList.remove('btn-' + oldKind);
50
+ this.btn.classList.add('btn-' + newKind);
51
+ }
52
+ handleLoading(newVal) {
53
+ //todo::use united styles
54
+ Helper.toggleElement(this.btn, 'btn--is-loading', 'btn--no-loading', () => newVal);
55
+ }
56
+ render() {
57
+ return (
58
+ //TODO:: use HOST then fake button behaviours
59
+ h(Host, { class: "s-button-host-tag" }, h("button", Object.assign({ ref: btn => this.btn = btn, disabled: this.disabled }, this.hostAttributes), h("span", { class: "s-button-text", ref: el => this.text = el }, h("slot", null)), this.loading ? h("span", { class: {
60
+ //todo::use united styles
61
+ 's-button-loader': true,
62
+ 's-button-loader-start': this.loaderPosition === 'start',
63
+ 's-button-loader-end': this.loaderPosition === 'end',
64
+ 's-button-loader-center': this.loaderPosition === 'center',
65
+ } }) : '')));
66
+ }
67
+ get host() { return getElement(this); }
68
+ static get watchers() { return {
69
+ "btnStyle": ["handleVisible"],
70
+ "loading": ["handleLoading"]
71
+ }; }
72
+ };
73
+ SallaButton.style = sallaButtonCss;
74
+
75
+ export { SallaButton as salla_button };
@@ -1,4 +1,4 @@
1
- import { r as registerInstance, h, g as getElement } from './index-092659c7.js';
1
+ import { r as registerInstance, h, g as getElement } from './index-9c087700.js';
2
2
  import { H as Helper } from './Helper-d07ebbc7.js';
3
3
 
4
4
  const SallaLocalization = class {
@@ -1,4 +1,4 @@
1
- import { r as registerInstance, h, g as getElement } from './index-092659c7.js';
1
+ import { r as registerInstance, h, g as getElement } from './index-9c087700.js';
2
2
  import { H as Helper } from './Helper-d07ebbc7.js';
3
3
 
4
4
  const sallaLoginCss = "salla-verify{display:block}";
@@ -0,0 +1,3 @@
1
+ export { S as salla_login } from './salla-login-57b18c2c.js';
2
+ import './index-9c087700.js';
3
+ import './Helper-d07ebbc7.js';
@@ -0,0 +1,113 @@
1
+ import { r as registerInstance, f as createEvent, h, e as Host, g as getElement } from './index-9c087700.js';
2
+ import { H as Helper } from './Helper-d07ebbc7.js';
3
+
4
+ const SallaModal = class {
5
+ constructor(hostRef) {
6
+ registerInstance(this, hostRef);
7
+ this.modalOpened = createEvent(this, "modalOpened", 7);
8
+ this.modalClosed = createEvent(this, "modalClosed", 7);
9
+ var _a;
10
+ //todo:: unite three colors (error, success, primary) in one prop
11
+ this.error = false;
12
+ this.success = false;
13
+ this.primary = false;
14
+ this.isClosable = true;
15
+ this.width = 'md';
16
+ this.visible = false;
17
+ this.isLoading = false;
18
+ this.subTitleFirst = false;
19
+ this.subTitle = '';
20
+ this.icon = '';
21
+ this.imageIcon = '';
22
+ Helper.setHost(this.host);
23
+ salla.event.on('modal::open', btn => btn.dataset.target == this.host.id && this.show());
24
+ salla.event.on('modal::close', btn => btn.dataset.target == this.host.id && this.hide());
25
+ this.title = this.host.title;
26
+ this.host.removeAttribute('title');
27
+ (_a = Helper.getElement('[slot=body]')) === null || _a === void 0 ? void 0 : _a.classList.add('s-modal-body', 's-modal-' + this.width);
28
+ }
29
+ handleVisible(newValue) {
30
+ if (!newValue) {
31
+ this.toggleModal(false);
32
+ this.modalClosed.emit();
33
+ return;
34
+ }
35
+ this.host.classList.remove('hidden');
36
+ setTimeout(() => this.toggleModal(true)); //small amont of time to running toggle After adding hidden
37
+ this.modalOpened.emit();
38
+ }
39
+ async show() {
40
+ this.host.setAttribute('visible', '');
41
+ return this.host;
42
+ }
43
+ async hide() {
44
+ this.host.removeAttribute('visible');
45
+ return this.host;
46
+ }
47
+ async setTitle(title) {
48
+ this.title = title;
49
+ return this.host;
50
+ }
51
+ async loading() {
52
+ this.isLoading = true;
53
+ return this.host;
54
+ }
55
+ async stopLoading() {
56
+ this.isLoading = false;
57
+ return this.host;
58
+ }
59
+ toggleModal(isOpen) {
60
+ Helper
61
+ // .toggleElement(this.host.querySelector('.s-modal-body'), 's-modal-entering', 's-modal-leaving', () => isOpen)
62
+ .toggleElement(this.host.querySelector('[slot=body]') || this.host, 's-modal-entering', 's-modal-leaving', () => isOpen)
63
+ .toggleElement(this.overlay, 's-modal-entering', 's-modal-overlay-leaving', () => isOpen)
64
+ //todo:: use united class names
65
+ .toggleElement(document.body, 'modal-is-open', 'modal-is-closed', () => isOpen);
66
+ if (!isOpen) {
67
+ setTimeout(() => this.host.classList.add('hidden'), 350);
68
+ }
69
+ }
70
+ closeModal() {
71
+ if (!this.isClosable) {
72
+ return;
73
+ }
74
+ this.host.removeAttribute('visible');
75
+ }
76
+ //todo:: pref for each modal
77
+ render() {
78
+ this.host.id = this.host.id || 'salla-modal';
79
+ return (
80
+ //todo:: use suitable class name instead of hidden
81
+ h(Host, { class: 's-modal-container hidden', "aria-modal": "true", role: "dialog" }, h("div", { class: "s-modal-wrapper" }, h("div", { class: "s-modal-overlay", ref: el => this.overlay = el, onClick: () => this.closeModal() }), h("span", { class: "s-modal-spacer" }, "\u200B"), h("slot", { name: "body" }, h("div", { class: 's-modal-body ' + 's-modal-' + this.width, slot: "body" }, this.isLoading
82
+ ? h("span", null, "Loading...")
83
+ : [h("div", { class: { 's-modal-header': true, 's-modal-is-center': this.icon != '' || this.imageIcon != '' } }, this.isClosable ?
84
+ //todo:: remove cursor-pointer
85
+ h("button", { class: "s-modal-close cursor-pointer", onClick: () => this.closeModal(), type: "button" }, h("span", { class: "sicon-cancel" }))
86
+ : '', this.error || this.success || this.icon
87
+ ? h("div", { class: {
88
+ 's-modal-icon': true,
89
+ 's-modal-bg-error': this.error,
90
+ 's-modal-bg-success': this.success,
91
+ 's-modal-bg-normal': !this.error && !this.success,
92
+ 's-modal-bg-primary': this.primary
93
+ } }, h("i", { class: {
94
+ [this.icon]: true,
95
+ 's-modal-text-error': this.error,
96
+ 's-modal-text-success': this.success,
97
+ } }))
98
+ : this.imageIcon ?
99
+ h("img", { class: "s-modal-header-img", src: this.imageIcon })
100
+ : '', this.title || this.subTitle ?
101
+ h("div", { class: "s-modal-header-content" }, h("div", { class: { 's-modal-title': true, 's-modal-title-below': this.subTitleFirst }, innerHTML: this.title }), h("p", { class: { 's-modal-sub-title': true }, innerHTML: this.subTitle }))
102
+ : ''),
103
+ h("slot", null),
104
+ h("slot", { name: "footer" })
105
+ ])))));
106
+ }
107
+ get host() { return getElement(this); }
108
+ static get watchers() { return {
109
+ "visible": ["handleVisible"]
110
+ }; }
111
+ };
112
+
113
+ export { SallaModal as salla_modal };
@@ -0,0 +1,75 @@
1
+ import { r as registerInstance, h, g as getElement } from './index-9c087700.js';
2
+ import { H as Helper } from './Helper-d07ebbc7.js';
3
+
4
+ const SallaOffer = class {
5
+ constructor(hostRef) {
6
+ registerInstance(this, hostRef);
7
+ var _a, _b, _c;
8
+ this.offer = null;
9
+ Helper.setHost(this.host);
10
+ this.headerSlot = ((_a = Helper.getElement('[slot="header"]')) === null || _a === void 0 ? void 0 : _a.innerHTML) || '<b class="s-offer-title">{name}</b><h3 class="s-offer-subtitle">{message}</h3>';
11
+ this.categorySlot = ((_b = Helper.getElement('[slot="category"]')) === null || _b === void 0 ? void 0 : _b.innerHTML) || '<i class="s-offer-badge-icon sicon-tag"></i><span class="s-offer-badge-text">{name}</span>';
12
+ this.productSlot = ((_c = Helper.getElement('[slot="product"]')) === null || _c === void 0 ? void 0 : _c.innerHTML) || this.defaultProductSlot();
13
+ salla.offer.event.onExisted(data => {
14
+ //TODO:: use the best, should we hide the offer by product Id or Offer id🤔
15
+ if (salla.localStore.get('remember-offer-' + data.offer.offer_id)) {
16
+ salla.log('User selected to don\'t show this offer again.');
17
+ return;
18
+ }
19
+ this.show(data.product_id);
20
+ });
21
+ }
22
+ async show(productId) {
23
+ return this.modal.show()
24
+ .then(() => salla.api.offer.details(productId))
25
+ //TODO:: make sure there is only one offer
26
+ .then(response => this.offer = response.data[0]);
27
+ }
28
+ rememberMe(event) {
29
+ salla.localStore.set('remember-offer-' + this.offer.id, event.target.checked);
30
+ }
31
+ addItem() {
32
+ // this here, is sallaButton
33
+ this['load']();
34
+ return salla.cart.api
35
+ .quickAdd(this['dataset'].id)
36
+ .finally(() => this['stop']());
37
+ }
38
+ defaultProductSlot() {
39
+ return '<a href={url} class="s-offer-product-image"><img class="s-offer-product-img" src="{image}" /></a>' +
40
+ '<div class="s-offer-product-info">' +
41
+ ' <a href={url} class="s-offer-product-name">{name}</a>' +
42
+ ' <div class="s-offer-product-price">{price}</div>' +
43
+ '</div>';
44
+ }
45
+ render() {
46
+ var _a, _b;
47
+ return h("salla-modal", { ref: modal => this.modal = modal, "is-loading": this.offer === null }, this.offer !== null
48
+ ? [h("div", { class: "s-offer-header", innerHTML: this.headerSlot
49
+ .replace(/\{name\}/g, this.offer.name)
50
+ .replace(/\{message\}/g, this.offer.message) }),
51
+ h("div", { class: "s-offer-body" }, ((_a = this.offer.get.categories) === null || _a === void 0 ? void 0 : _a.length) > 0
52
+ ? this.offer.get.categories.map(category => h("a", { href: category.urls.customer, class: "s-offer-badge", innerHTML: this.categorySlot
53
+ .replace(/\{name\}/g, category.name)
54
+ .replace(/\{url\}/g, category.urls.customer) }))
55
+ : (_b = this.offer.get.products) === null || _b === void 0 ? void 0 : _b.map(product => h("div", { class: "s-offer-product", id: 'product_' + product.id, innerHTML: this.productSlot
56
+ .replace(/\{name\}/g, product.name)
57
+ .replace(/\{url\}/g, product.url)
58
+ .replace(/\{image\}/g, product.thumbnail)
59
+ .replace(/\{price\}/g, product.has_special_price
60
+ ? salla.money(product.sale_price) + '<span class="s-offer-product-old-price">' + salla.money(product.regular_price) + '</span>'
61
+ : salla.money(product.price)) }, h("salla-button", { "btn-style": 'outline-primary', "data-id": product.id, onClick: this.addItem }, salla.lang.get('pages.cart.add_to_cart'))))),
62
+ h("div", { class: "s-offer-footer", slot: "footer" }, this.offer.expiry_date ?
63
+ h("p", { class: "s-offer-expiry" }, salla.lang.get('pages.products.offer_expires_in'), " ", this.offer.expiry_date)
64
+ : '', h("label", { class: "s-offer-remember-label" }, h("input", { type: "checkbox", onChange: e => this.rememberMe(e), class: "s-offer-remember-input" }), "\u00A0 ", salla.lang.get('common.remember_my_choice'))),
65
+ ] : '');
66
+ }
67
+ componentDidRender() {
68
+ //todo:: know from where there is hidden attributes to the doms🤔
69
+ //todo:: add animation
70
+ this.modal.querySelectorAll('[hidden]').forEach(el => el.removeAttribute('hidden'));
71
+ }
72
+ get host() { return getElement(this); }
73
+ };
74
+
75
+ export { SallaOffer as salla_offer };
@@ -1,4 +1,4 @@
1
- import { r as registerInstance, h, H as Host, g as getElement } from './index-092659c7.js';
1
+ import { r as registerInstance, h, e as Host, g as getElement } from './index-9c087700.js';
2
2
  import { H as Helper } from './Helper-d07ebbc7.js';
3
3
 
4
4
  const SallaProductAvailability = class {
@@ -0,0 +1,228 @@
1
+ import { r as registerInstance, h, e as Host, g as getElement } from './index-9c087700.js';
2
+ import { H as Helper } from './Helper-d07ebbc7.js';
3
+
4
+ const sallaRatingCss = ":host{display:block}.unicode{unicode-bidi:plaintext}";
5
+
6
+ const SallaRating = class {
7
+ constructor(hostRef) {
8
+ registerInstance(this, hostRef);
9
+ /**
10
+ * Set to true to display store rating step
11
+ */
12
+ this.isStoreRating = false;
13
+ /**
14
+ * Set to true to display products rating step
15
+ */
16
+ this.isProductsRating = false;
17
+ /**
18
+ * Set to true to display shipping rating step
19
+ */
20
+ this.isShippingRating = false;
21
+ this.stepsCount = 0;
22
+ this.currentIndex = 0;
23
+ Helper.setHost(this.host);
24
+ salla.event.on('rating::show', () => this.show());
25
+ }
26
+ async show() {
27
+ return this.modal.show()
28
+ .then(() => salla.feedback.api.order(salla.get('page.id')))
29
+ .then(res => this.order = res.data)
30
+ .then(() => this.modal.setTitle(salla.lang.get('pages.rating.rate_order') + ' <span class="unicode">(#' + this.order.id + ')</span>'))
31
+ .then(() => this.modal.stopLoading())
32
+ .then(() => this.stepsCount = [this.order.testimonials_enabled, this.order.products_enabled, this.order.shipping_enabled].filter(enabled => enabled).length)
33
+ .then(() => setTimeout(() => this.initiateRating(), 100));
34
+ }
35
+ async hide() {
36
+ return this.modal.hide();
37
+ }
38
+ initiateRating() {
39
+ this.handleWizard();
40
+ this.starsRating();
41
+ this.highlightSelectedStars();
42
+ }
43
+ // handle wizard
44
+ handleWizard() {
45
+ this.steps = this.host.querySelectorAll(".s-rating-step");
46
+ this.dots = this.host.querySelectorAll(".s-rating-step-dot");
47
+ this.showActiveStep();
48
+ Helper.onClick("#prev-btn", event => {
49
+ Helper.toggleElement(event.target, 's-rating-unvisiable', 'block', () => this.currentIndex == 0);
50
+ this.currentIndex > 0 && this.currentIndex--;
51
+ this.showActiveStep();
52
+ });
53
+ }
54
+ showActiveStep(current = null) {
55
+ var _a;
56
+ this.currentTab = current || this.steps[this.currentIndex];
57
+ Helper.toggle('.s-rating-step', 's-rating-active', 's-rating-hidden', tab => tab == this.currentTab)
58
+ .toggle('.s-rating-step-dot', 's-rating-bg-gray', 's-rating-bg-primary', dot => dot != this.dots[this.currentIndex]);
59
+ // the animation
60
+ Helper.toggleElement(this.currentTab, 's-rating-unactive', 's-rating-hidden', () => true);
61
+ setTimeout(() => Helper.toggleElement(this.currentTab, 's-rating-active', 's-rating-unactive', () => true), 300);
62
+ // Btn text
63
+ let nextType = (_a = this.steps[this.currentIndex + 1]) === null || _a === void 0 ? void 0 : _a.dataset.type;
64
+ this.nextBtn.querySelector('.s-button-text').innerHTML = nextType
65
+ ? salla.lang.get('pages.rating.rate') + ' ' + salla.lang.get('pages.rating.' + nextType)
66
+ : salla.lang.get('pages.rating.send_ratings');
67
+ setTimeout(() => { var _a; return this.body.setAttribute('style', 'height:' + ((_a = this.currentTab) === null || _a === void 0 ? void 0 : _a.scrollHeight) + 'px'); });
68
+ }
69
+ // handle star rating
70
+ starsRating() {
71
+ let selectedClasses = ['selected'];
72
+ // Listen for form submissions
73
+ salla.document.event.onSubmit('.s-rating-stars-element', function (event) {
74
+ // Prevent form from submitting
75
+ event.preventDefault();
76
+ // Get the selected star - activeElement is not supported in safari
77
+ let activeStars = event.target.querySelectorAll('.s-rating-btn-star.hovered');
78
+ let selected = activeStars[activeStars.length - 1];
79
+ if (!selected)
80
+ return;
81
+ let selectedIndex = parseInt(selected.dataset.star, 10);
82
+ event.target.querySelector('.rating_hidden_input').value = selectedIndex;
83
+ // Get all stars in this form (only search in the form, not the whole document)
84
+ // Loop through each star, and add or remove the `.selected` class to toggle highlighting
85
+ event.target
86
+ .querySelectorAll('.s-rating-btn-star')
87
+ .forEach(function (star, index) {
88
+ if (index < selectedIndex) {
89
+ // Selected star or before it, Add highlighting
90
+ star.classList.add(...selectedClasses);
91
+ return;
92
+ }
93
+ // After selected star, Remove highlight
94
+ star.classList.remove(...selectedClasses);
95
+ });
96
+ // Remove aria-pressed from any previously selected star
97
+ var previousRating = event.target.querySelector('.s-rating-btn-star[aria-pressed="true"]');
98
+ if (previousRating) {
99
+ previousRating.removeAttribute('aria-pressed');
100
+ }
101
+ // Add aria-pressed role to the selected button
102
+ selected.setAttribute('aria-pressed', true);
103
+ });
104
+ }
105
+ highlightSelectedStars() {
106
+ let hover = ['hovered'];
107
+ Helper.all('.s-rating-stars-element', el => {
108
+ let starElements = el.querySelectorAll('.s-rating-btn-star');
109
+ // remove hovered state from stars ---
110
+ el.addEventListener('mouseout', () => starElements.forEach(star => star.classList.remove(...hover)));
111
+ starElements.forEach((starElement, index) => {
112
+ starElement.addEventListener('mouseover', () => {
113
+ starElement.classList.add(...hover);
114
+ if (index <= 1) {
115
+ starElement.previousElementSibling.tagName === 'BUTTON' ? starElement.previousElementSibling.classList.add(...hover) : null;
116
+ }
117
+ else {
118
+ for (let i = 0; i < index; i++) {
119
+ starElements[i].classList.add(...hover);
120
+ }
121
+ }
122
+ });
123
+ starElement.addEventListener('mouseout', () => starElement.classList.remove(...hover));
124
+ });
125
+ });
126
+ }
127
+ sendFeedback(current = null, type = null) {
128
+ if (!current && this.currentTab.dataset.type === 'products') {
129
+ let forms = Array.from(this.currentTab.querySelectorAll('.rating-outer-form'));
130
+ let promise = this.sendFeedback(forms[0], 'product');
131
+ forms.slice(1).forEach(form => promise.then(() => this.sendFeedback(form, 'product')));
132
+ return promise;
133
+ }
134
+ type = type || this.currentTab.dataset.type;
135
+ current = current || this.currentTab;
136
+ let data = {};
137
+ current.querySelectorAll('[name]').forEach(input => {
138
+ //decode names like `<input name="jamal[inner]" value="hi">` to be name(jamal), value: {inner:"hi"}
139
+ let inputData = salla.helpers.inputData(input.name, input.value, data);
140
+ data[inputData.name] = inputData.value;
141
+ });
142
+ if (Object.keys(data).length == 0) {
143
+ return;
144
+ }
145
+ data['order_id'] = this.order.id;
146
+ data['type'] = this.currentTab.dataset.type;
147
+ return salla.feedback.api[type](data);
148
+ }
149
+ submit() {
150
+ this.validate();
151
+ if (this.currentIndex == this.stepsCount - 1) {
152
+ this.showThankYou();
153
+ return;
154
+ }
155
+ salla.config.canLeave = false;
156
+ this.nextBtn.load()
157
+ .then(() => this.sendFeedback())
158
+ .then(() => this.currentIndex < this.stepsCount - 1 && this.currentIndex++)
159
+ .then(() => this.showActiveStep())
160
+ .then(() => Helper.toggle('#prev-btn', 'block', 's-rating-unvisiable', () => true))
161
+ .finally(() => this.nextBtn.stop() && (salla.config.canLeave = true));
162
+ }
163
+ validate(rating = null, type = null) {
164
+ if (!rating && this.currentTab.dataset.type == 'products') {
165
+ return this.currentTab.querySelectorAll('.rating-outer-form').forEach(rating => this.validate(rating, 'product'));
166
+ }
167
+ rating = rating || this.currentTab;
168
+ let stars = rating.querySelector('.rating_hidden_input').value;
169
+ let comment = rating.querySelector('.s-rating-comment');
170
+ let validationMessage = rating.querySelector('.s-rating-validation-msg');
171
+ if (stars && comment.value && comment.value.length > 3) {
172
+ comment.classList.remove('s-rating-has-error');
173
+ validationMessage.innerHTML = '';
174
+ return;
175
+ }
176
+ type = type || rating['dataset'].type;
177
+ Helper.toggleElement(comment, 'save', 's-rating-has-error', el => el.value.length > 3);
178
+ throw validationMessage.innerHTML = stars
179
+ ? (salla.lang.get('common.errors.not_less_than_chars', { chars: 4 }) + ' ' + comment.getAttribute('placeholder'))
180
+ : salla.lang.get(`pages.rating.rate_${type}_stars`).replace(' (:item)', '');
181
+ }
182
+ showThankYou() {
183
+ let seconds = 10;
184
+ let timeToClose = setInterval(() => {
185
+ this.thanksTime.innerHTML = '00:0' + (seconds--);
186
+ seconds < 0 && this.hide() && clearInterval(timeToClose);
187
+ }, 1000);
188
+ this.host.querySelector('.s-rating-footer').classList.add('s-rating-unvisiable');
189
+ this.showActiveStep(this.thanksTab);
190
+ }
191
+ renderStoreRating() {
192
+ return this.order.testimonials_enabled ?
193
+ h("div", { class: "rating-outer-form s-rating-step-wrap s-rating-step", "data-type": "store" }, h("div", { class: "s-rating-rounded-icon" }, h("img", { src: salla.get('store.logo'), alt: "store name", class: "s-rating-store-logo" })), h("h2", { class: "s-rating-title" }, salla.lang.get('pages.rating.rate_the_store')), h("div", { class: "s-rating-stars-company" }, " ", this.getStarsRating('large')), h("textarea", { id: "storeReview", name: "comment", class: "s-rating-comment", placeholder: salla.lang.get('pages.rating.write_store_rate') }), h("small", { class: "s-rating-validation-msg" }))
194
+ : '';
195
+ }
196
+ renderShippingRating() {
197
+ return this.order.shipping_enabled
198
+ ?
199
+ h("div", { class: "rating-outer-form s-rating-step-wrap s-rating-step", "data-type": "shipping" }, h("input", { type: "hidden", name: "shipping_company_id", value: this.order.shipping.company.id }), h("div", { class: "s-rating-rounded-icon" }, h("img", { src: this.order.shipping.company.logo, alt: "company name", class: "s-rating-shipping-logo" })), h("h2", { class: "s-rating-title" }, " ", salla.lang.get('pages.rating.rate_shipping') + ' ' + this.order.shipping.company.name), h("div", { class: "s-rating-stars-company" }, " ", this.getStarsRating('large')), h("textarea", { name: "comment", class: "s-rating-comment", placeholder: salla.lang.get('pages.rating.write_shipping_rate') }), h("small", { class: "s-rating-validation-msg" }))
200
+ : '';
201
+ }
202
+ renderProductsRating() {
203
+ return this.order.products_enabled
204
+ ? h("section", { class: "s-rating-step", "data-type": "products" }, this.order.products.map((item, index) => h("div", { class: "rating-outer-form s-rating-product", "data-stars-error": salla.lang.get('pages.rating.rate_product_stars') }, h("img", { src: item.product.thumbnail, alt: item.product.name, class: "s-rating-product-img" }), h("div", { class: "s-rating-product-details" }, h("h3", { class: "s-rating-product-title" }, " ", item.product.name), h("div", { class: "s-rating-stars-product" }, " ", this.getStarsRating('small')), h("input", { type: "hidden", name: `products[${index}][id]`, value: item.product.id }), h("textarea", { placeholder: salla.lang.get('pages.rating.write_product_rate'), name: `products[${index}][comment]`, class: "s-rating-comment" }), h("small", { class: "s-rating-validation-msg" })))))
205
+ : '';
206
+ }
207
+ renderThanksView() {
208
+ return (h("div", { class: "s-rating-thanks s-rating-hidden", ref: el => this.thanksTab = el }, h("span", { class: "s-rating-thanks-icon sicon-check-circle2" }), h("h3", { class: "s-rating-thanks-title" }, salla.lang.get('pages.rating.thanks')), h("div", { class: "s-rating-thanks-msg", innerHTML: this.thanksMsg }), h("a", { href: "#!", onClick: () => this.hide(), class: "s-rating-thanks-btn" }, "\u0639\u0648\u062F\u0629 \u0625\u0644\u064A \u062A\u0641\u0627\u0635\u064A\u0644 \u0627\u0644\u0637\u0644\u0628"), h("time", { class: "s-rating-thanks-time", ref: el => this.thanksTime = el })));
209
+ }
210
+ getStarsRating(size) {
211
+ return (h("form", { class: "s-rating-stars-element" }, h("input", { type: "hidden", class: "rating_hidden_input", name: "rating", value: "" }), [1, 2, 3, 4, 5].map(star => h("button", { type: "submit", class: `s-rating-btn-star s-rating-btn-star-` + size, "data-star": star }, h("i", { class: "sicon-star2" })))));
212
+ }
213
+ // render
214
+ render() {
215
+ return (h(Host, null, h("salla-modal", { isLoading: true, width: "md", ref: modal => this.modal = modal }, this.order
216
+ ? [h("div", { class: "s-rating-wrapper", ref: el => this.body = el }, this.renderStoreRating(), this.renderProductsRating(), this.renderShippingRating(), this.renderThanksView()),
217
+ h("div", { class: "s-rating-footer" }, h("button", { id: "prev-btn", class: "s-rating-btn s-rating-unvisiable" }, salla.lang.get('common.elements.back')), this.stepsCount > 1 ? h("ul", { class: "s-rating-dots" }, [0, 1, 2].slice(0, this.stepsCount).map(() => h("li", { class: 's-rating-bg-gray s-rating-step-dot' }))) : '', h("salla-button", { ref: el => this.nextBtn = el, onClick: () => this.submit() }, salla.lang.get('common.elements.next'))),]
218
+ : '')));
219
+ }
220
+ componentDidRender() {
221
+ //todo:: know from where there is hidden attributes to the doms🤔
222
+ this.modal.querySelectorAll('[hidden]').forEach(el => el.removeAttribute('hidden'));
223
+ }
224
+ get host() { return getElement(this); }
225
+ };
226
+ SallaRating.style = sallaRatingCss;
227
+
228
+ export { SallaRating as salla_rating };
@@ -1,4 +1,4 @@
1
- import { r as registerInstance, h, H as Host, g as getElement } from './index-092659c7.js';
1
+ import { r as registerInstance, h, e as Host, g as getElement } from './index-9c087700.js';
2
2
  import { H as Helper } from './Helper-d07ebbc7.js';
3
3
 
4
4
  const SallaSearch = class {
@@ -0,0 +1,3 @@
1
+ export { S as salla_search } from './salla-search-30fec1e8.js';
2
+ import './index-9c087700.js';
3
+ import './Helper-d07ebbc7.js';