@salla.sa/twilight-components 1.6.0 → 1.6.1

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 (62) hide show
  1. package/dist/cjs/Helper-8ae6a805.js +28 -0
  2. package/dist/cjs/arrow-right-3d137e4c.js +13 -0
  3. package/dist/cjs/cancel-ae668d91.js +13 -0
  4. package/dist/cjs/check-circle2-1aac98d1.js +13 -0
  5. package/dist/cjs/loader.cjs.js +1 -1
  6. package/dist/cjs/mail-2db058ee.js +13 -0
  7. package/dist/cjs/salla-add-product-button_13.cjs.entry.js +2870 -0
  8. package/dist/cjs/salla-infinite-scroll.cjs.entry.js +93 -0
  9. package/dist/cjs/salla-list-tile_2.cjs.entry.js +80 -0
  10. package/dist/cjs/salla-loyalty.cjs.entry.js +229 -0
  11. package/dist/cjs/salla-product-size-guide.cjs.entry.js +52 -0
  12. package/dist/cjs/salla-quantity-input.cjs.entry.js +101 -0
  13. package/dist/cjs/salla-rating-modal.cjs.entry.js +169 -0
  14. package/dist/cjs/salla-social-share.cjs.entry.js +1447 -0
  15. package/dist/cjs/salla-swiper.cjs.entry.js +5023 -0
  16. package/dist/cjs/salla-tab-content_3.cjs.entry.js +159 -0
  17. package/dist/cjs/star2-8288e6e1.js +13 -0
  18. package/dist/cjs/twilight-components.cjs.js +1 -1
  19. package/dist/collection/components/salla-login-modal/salla-login-modal.js +4 -3
  20. package/dist/components/salla-login-modal.js +4 -3
  21. package/dist/esm/Helper-e1d414a5.js +26 -0
  22. package/dist/esm/arrow-right-1c3e04f2.js +11 -0
  23. package/dist/esm/cancel-41a92070.js +11 -0
  24. package/dist/esm/check-circle2-f6e5f685.js +11 -0
  25. package/dist/esm/loader.js +1 -1
  26. package/dist/esm/mail-9d5204c6.js +11 -0
  27. package/dist/esm/salla-add-product-button_13.entry.js +2854 -0
  28. package/dist/esm/salla-infinite-scroll.entry.js +89 -0
  29. package/dist/esm/salla-list-tile_2.entry.js +75 -0
  30. package/dist/esm/salla-loyalty.entry.js +225 -0
  31. package/dist/esm/salla-product-size-guide.entry.js +48 -0
  32. package/dist/esm/salla-quantity-input.entry.js +97 -0
  33. package/dist/esm/salla-rating-modal.entry.js +165 -0
  34. package/dist/esm/salla-social-share.entry.js +1443 -0
  35. package/dist/esm/salla-swiper.entry.js +5019 -0
  36. package/dist/esm/salla-tab-content_3.entry.js +153 -0
  37. package/dist/esm/star2-b134fc74.js +11 -0
  38. package/dist/esm/twilight-components.js +1 -1
  39. package/dist/twilight-components/p-14f0ff17.entry.js +4 -0
  40. package/dist/twilight-components/p-2749c9d3.entry.js +4 -0
  41. package/dist/twilight-components/p-335abbbb.entry.js +4 -0
  42. package/dist/twilight-components/p-4cafb11b.entry.js +4 -0
  43. package/dist/twilight-components/p-5e63e308.entry.js +4 -0
  44. package/dist/twilight-components/p-648e74e5.entry.js +4 -0
  45. package/dist/twilight-components/p-897b2018.js +4 -0
  46. package/dist/twilight-components/p-93708e1e.js +4 -0
  47. package/dist/twilight-components/p-9d236cf4.entry.js +4 -0
  48. package/dist/twilight-components/p-9d2ca9c8.js +4 -0
  49. package/dist/twilight-components/p-af7d5660.js +4 -0
  50. package/dist/twilight-components/p-bdbd2386.entry.js +4 -0
  51. package/dist/twilight-components/p-cac3db69.entry.js +4 -0
  52. package/dist/twilight-components/p-d914a212.js +4 -0
  53. package/dist/twilight-components/p-dace8e6d.js +4 -0
  54. package/dist/twilight-components/p-f9253fda.entry.js +4 -0
  55. package/dist/twilight-components/twilight-components.esm.js +1 -1
  56. package/package.json +2 -2
  57. package/dist/cjs/salla-add-product-button.cjs.entry.js +0 -104
  58. package/dist/cjs/salla-button_24.cjs.entry.js +0 -10087
  59. package/dist/esm/salla-add-product-button.entry.js +0 -100
  60. package/dist/esm/salla-button_24.entry.js +0 -10060
  61. package/dist/twilight-components/p-30b2c5b0.entry.js +0 -4
  62. package/dist/twilight-components/p-76cb2574.entry.js +0 -4
@@ -0,0 +1,165 @@
1
+ /*!
2
+ * Crafted with ❤ by Salla
3
+ */
4
+ import { r as registerInstance, h, H as Host, g as getElement } from './index-4e30ffd0.js';
5
+ import { H as Helper } from './Helper-e1d414a5.js';
6
+ import { C as CheckCircle2 } from './check-circle2-f6e5f685.js';
7
+
8
+ const ShippingFast = `<!-- Generated by IcoMoon.io -->
9
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
10
+ <title>shipping-fast</title>
11
+ <path d="M10.667 14.667c0-0.737-0.597-1.333-1.333-1.333h-8c-0.736 0-1.333 0.596-1.333 1.333s0.597 1.333 1.333 1.333h8c0.736 0 1.333-0.596 1.333-1.333zM9.333 18.667c-2.941 0-5.333 2.392-5.333 5.333s2.392 5.333 5.333 5.333 5.333-2.392 5.333-5.333-2.392-5.333-5.333-5.333zM9.333 26.667c-1.471 0-2.667-1.196-2.667-2.667s1.196-2.667 2.667-2.667 2.667 1.196 2.667 2.667-1.196 2.667-2.667 2.667zM1.333 10.667h5.333c0.736 0 1.333-0.596 1.333-1.333s-0.597-1.333-1.333-1.333h-5.333c-0.736 0-1.333 0.596-1.333 1.333s0.597 1.333 1.333 1.333zM31.123 13.103l-3.147-3.935c-1.273-1.589-3.171-2.501-5.205-2.501h-1.437c0-2.205-1.795-4-4-4h-13.333c-0.736 0-1.333 0.596-1.333 1.333s0.597 1.333 1.333 1.333h13.333c0.735 0 1.333 0.597 1.333 1.333v1.333c0 0.248 0.087 0.468 0.204 0.667-0.117 0.199-0.204 0.419-0.204 0.667v5.333c0 0.737 0.597 1.333 1.333 1.333h9.333v6.667h-1.333c-0.063 0-0.117 0.028-0.179 0.036-0.583-2.313-2.664-4.036-5.155-4.036-2.941 0-5.333 2.392-5.333 5.333s2.392 5.333 5.333 5.333c2.491 0 4.572-1.723 5.155-4.036 0.061 0.008 0.116 0.036 0.179 0.036h2.667c0.736 0 1.333-0.596 1.333-1.333v-8.399c0-0.905-0.311-1.792-0.877-2.499zM21.333 13.333v-4h1.437c1.221 0 2.36 0.547 3.124 1.501l1.997 2.499zM22.667 26.667c-1.471 0-2.667-1.196-2.667-2.667s1.196-2.667 2.667-2.667 2.667 1.196 2.667 2.667-1.196 2.667-2.667 2.667z"></path>
12
+ </svg>
13
+ `;
14
+
15
+ const sallaRatingModalCss = "";
16
+
17
+ const SallaRatingModal = class {
18
+ constructor(hostRef) {
19
+ registerInstance(this, hostRef);
20
+ this.stepsCount = 0;
21
+ this.currentIndex = 0;
22
+ this.submitted = [];
23
+ /**
24
+ * The order id, to rate on its products & shipping
25
+ */
26
+ this.orderId = salla.config.get('page.id');
27
+ this.translationLoaded = false;
28
+ Helper.setHost(document);
29
+ salla.event.on('rating::open', () => this.open());
30
+ salla.lang.onLoaded(() => {
31
+ this.translationLoaded = true;
32
+ });
33
+ }
34
+ /**
35
+ * Show the rating modal
36
+ */
37
+ async open() {
38
+ return this.modal.open()
39
+ .then(() => this.order || salla.rating.api.order(this.orderId).then(res => this.order = res.data))
40
+ .then(() => this.modal.setTitle(salla.lang.get('pages.rating.rate_order') + ' <span class="unicode">(#' + this.order.id + ')</span>'))
41
+ .then(() => this.modal.stopLoading())
42
+ .then(() => this.stepsCount = [this.order.testimonials_enabled, this.order.products_enabled, this.order.shipping_enabled].filter(enabled => enabled).length)
43
+ .then(() => setTimeout(() => this.handleWizard(), 100));
44
+ }
45
+ /**
46
+ * Show the rating modal
47
+ */
48
+ async close() {
49
+ return this.modal.close();
50
+ }
51
+ // handle wizard
52
+ handleWizard() {
53
+ this.steps = this.modal.querySelectorAll(".s-rating-modal-step");
54
+ this.dots = this.modal.querySelectorAll(".s-rating-modal-step-dot");
55
+ this.showActiveStep();
56
+ }
57
+ showActiveStep(current = null) {
58
+ var _a;
59
+ this.currentTab = current || this.steps[this.currentIndex];
60
+ Helper.toggleClassIf('.s-rating-modal-step-dot', 's-rating-modal-bg-gray', 's-rating-modal-bg-primary', dot => dot != this.dots[this.currentIndex])
61
+ .toggleClassIf('.s-rating-modal-step', 's-rating-modal-active', 's-rating-modal-hidden', tab => tab == this.currentTab);
62
+ if (this.currentIndex != 0) {
63
+ // the animation
64
+ Helper.toggleElementClassIf(this.currentTab, 's-rating-modal-unactive', 's-rating-modal-hidden', () => true);
65
+ setTimeout(() => Helper.toggleElementClassIf(this.currentTab, 's-rating-modal-active', 's-rating-modal-unactive', () => true), 300);
66
+ }
67
+ // Btn text
68
+ let nextType = (_a = this.steps[this.currentIndex + 1]) === null || _a === void 0 ? void 0 : _a.dataset.type;
69
+ this.nextBtn.setText(nextType ? salla.lang.get('pages.rating.rate') + ' ' + salla.lang.get('pages.rating.' + nextType)
70
+ : salla.lang.get('pages.rating.send_ratings'));
71
+ setTimeout(() => { var _a; return this.body.setAttribute('style', 'height:' + ((_a = this.currentTab) === null || _a === void 0 ? void 0 : _a.scrollHeight) + 'px'); });
72
+ }
73
+ previousTab() {
74
+ this.currentIndex > 0 && this.currentIndex--;
75
+ Helper.toggleElementClassIf(this.backBtn, 's-rating-modal-unvisiable', 'block', () => this.currentIndex == 0);
76
+ this.showActiveStep();
77
+ }
78
+ submit() {
79
+ this.submittedBefore() || this.validate();
80
+ salla.config.canLeave = false;
81
+ this.nextBtn.load()
82
+ .then(() => this.submittedBefore() || this.sendFeedback())
83
+ .then(() => this.currentTab.querySelectorAll('[name],.s-rating-modal-btn-star').forEach(el => el.setAttribute('disabled', '')))
84
+ .then(() => this.currentIndex < this.stepsCount && this.currentIndex++)
85
+ .then(() => this.showActiveStep())
86
+ .then(() => Helper.toggleClassIf('#prev-btn', 'block', 's-rating-modal-unvisiable', () => true))
87
+ .finally(() => {
88
+ this.nextBtn.stop();
89
+ salla.config.canLeave = true;
90
+ this.currentIndex == this.stepsCount && this.showThankYou();
91
+ this.modal.isClosable = false;
92
+ });
93
+ }
94
+ submittedBefore() {
95
+ return this.submitted.includes(this.currentIndex);
96
+ }
97
+ validate(rating = null, type = null) {
98
+ if (!rating && this.currentTab.dataset.type == 'products') {
99
+ return this.currentTab.querySelectorAll('.rating-outer-form').forEach(rating => this.validate(rating, 'product'));
100
+ }
101
+ rating = rating || this.currentTab;
102
+ let stars = rating.querySelector('.rating_hidden_input').value;
103
+ let comment = rating.querySelector('.s-rating-modal-comment');
104
+ let validationMessage = rating.querySelector('.s-rating-modal-validation-msg');
105
+ if (stars && comment.value && comment.value.length > 3) {
106
+ comment.classList.remove('s-has-error');
107
+ validationMessage.innerHTML = '';
108
+ return;
109
+ }
110
+ type = type || rating['dataset'].type;
111
+ Helper.toggleElementClassIf(comment, 'save', 's-has-error', el => el.value.length > 3);
112
+ throw validationMessage.innerHTML = stars
113
+ ? (salla.lang.get('common.errors.not_less_than_chars', { chars: 4 }) + ' ' + comment.getAttribute('placeholder'))
114
+ : salla.lang.get(`pages.rating.rate_${type}_stars`).replace(' (:item)', '');
115
+ }
116
+ sendFeedback() {
117
+ let data = {};
118
+ this.currentTab.querySelectorAll('[name]').forEach((input) => {
119
+ //decode names like `<input name="jamal[inner]" value="hi">` to be {name:jamal, value: {inner:"hi"}}
120
+ let inputData = salla.helpers.inputData(input.name, input.value, data);
121
+ data[inputData.name] = inputData.value;
122
+ });
123
+ if (Object.keys(data).length == 0) {
124
+ return;
125
+ }
126
+ data['order_id'] = this.orderId;
127
+ data['type'] = this.currentTab.dataset.type;
128
+ this.submitted.push(this.currentIndex);
129
+ return salla.rating.api[this.currentTab.dataset.type](data);
130
+ }
131
+ showThankYou() {
132
+ let seconds = 10;
133
+ let timeToClose = setInterval(() => {
134
+ this.thanksTime.innerHTML = '00:0' + (seconds--);
135
+ if (seconds > 0) {
136
+ return;
137
+ }
138
+ clearInterval(timeToClose);
139
+ this.thanksTime.remove();
140
+ this.close().then(() => window.location.reload());
141
+ }, 1000);
142
+ this.modal.querySelector('.s-rating-modal-footer').classList.add('s-rating-modal-unvisiable');
143
+ this.showActiveStep(this.thanksTab);
144
+ }
145
+ render() {
146
+ return (h(Host, { class: "s-rating" }, h("salla-modal", { isLoading: true, width: "md", ref: modal => this.modal = modal }, this.order
147
+ ? [h("div", { class: "s-rating-modal-wrapper", ref: el => this.body = el }, this.order.testimonials_enabled ?
148
+ h("div", { class: "rating-outer-form s-rating-modal-step-wrap s-rating-modal-step s-rating-modal-hidden", "data-type": "store" }, h("div", { class: "s-rating-modal-rounded-icon" }, h("img", { src: salla.config.get('store.logo', 'https://assets.salla.sa/cp/assets/images/logo-new.png'), alt: "store name", class: "s-rating-modal-store-logo" })), h("h2", { class: "s-rating-modal-title" }, salla.lang.get('pages.rating.rate_the_store')), h("div", { class: "s-rating-modal-stars-company" }, h("salla-rating-stars", { size: "large" })), h("textarea", { name: "comment", class: "s-rating-modal-comment", placeholder: salla.lang.get('pages.rating.write_store_rate') }), h("small", { class: "s-rating-modal-validation-msg" }))
149
+ : '', this.order.products_enabled
150
+ ? h("section", { class: "s-rating-modal-step s-rating-modal-hidden", "data-type": "products" }, this.order.products.map((item, index) => h("div", { class: "rating-outer-form s-rating-modal-product", "data-stars-error": salla.lang.get('pages.rating.rate_product_stars') }, h("div", { class: "s-rating-modal-product-img-wrap" }, h("img", { src: item.product.thumbnail, alt: item.product.name, class: "s-rating-modal-product-img" })), h("div", { class: "s-rating-modal-product-details" }, h("h3", { class: "s-rating-modal-product-title" }, " ", item.product.name), h("div", { class: "s-rating-modal-stars-product" }, h("salla-rating-stars", { size: "small", name: `products[${index}][rating]` })), h("input", { type: "hidden", name: `products[${index}][product_id]`, value: item.product.id }), h("textarea", { placeholder: salla.lang.get('pages.rating.write_product_rate'), name: `products[${index}][comment]`, class: "s-rating-modal-comment" }), h("small", { class: "s-rating-modal-validation-msg" })))))
151
+ : '', this.order.shipping_enabled
152
+ ? h("div", { class: "rating-outer-form s-rating-modal-step-wrap s-rating-modal-step s-rating-modal-hidden", "data-type": "shipping" }, h("input", { type: "hidden", name: "shipping_company_id", value: this.order.shipping.company.id }), this.order.shipping.company.logo
153
+ ? h("div", { class: "s-rating-modal-rounded-icon" }, h("img", { src: this.order.shipping.company.logo, class: "s-rating-modal-shipping-logo", alt: this.order.shipping.company.name }))
154
+ : h("span", { class: "s-rating-modal-icon", innerHTML: ShippingFast }), h("div", { class: "s-rating-modal-title" }, " ", salla.lang.get('pages.rating.rate_shipping') + ' ' + this.order.shipping.company.name), h("div", { class: "s-rating-modal-stars-company" }, h("salla-rating-stars", { size: "large" })), h("textarea", { name: "comment", class: "s-rating-modal-comment", placeholder: salla.lang.get('pages.rating.write_shipping_rate') }), h("small", { class: "s-rating-modal-validation-msg" }))
155
+ : '', h("div", { class: "s-rating-modal-thanks s-rating-modal-hidden", ref: el => this.thanksTab = el }, h("span", { class: "s-rating-modal-icon", innerHTML: CheckCircle2 }), h("h3", { class: "s-rating-modal-thanks-title" }, salla.lang.get('pages.rating.thanks')), h("div", { class: "s-rating-modal-thanks-msg", innerHTML: this.order.thanks_message }), h("time", { class: "s-rating-modal-thanks-time", ref: el => this.thanksTime = el }))), h("div", { class: "s-rating-modal-footer" }, h("button", { ref: el => this.backBtn = el, onClick: () => this.previousTab(), class: "s-rating-modal-btn s-rating-modal-unvisiable" }, salla.lang.get('common.elements.back')), this.stepsCount > 1 ? h("ul", { class: "s-rating-modal-dots" }, [0, 1, 2].slice(0, this.stepsCount).map(() => h("li", { class: 's-rating-modal-bg-gray s-rating-modal-step-dot' }))) : '', h("salla-button", { "loader-position": 'center', ref: el => this.nextBtn = el, onClick: () => this.submit() }, salla.lang.get('common.elements.next'))),]
156
+ : '')));
157
+ }
158
+ componentDidLoad() {
159
+ salla.event.dispatch('rating::ready', this);
160
+ }
161
+ get host() { return getElement(this); }
162
+ };
163
+ SallaRatingModal.style = sallaRatingModalCss;
164
+
165
+ export { SallaRatingModal as salla_rating_modal };