@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,169 @@
1
+ /*!
2
+ * Crafted with ❤ by Salla
3
+ */
4
+ 'use strict';
5
+
6
+ Object.defineProperty(exports, '__esModule', { value: true });
7
+
8
+ const index = require('./index-0d0167d5.js');
9
+ const Helper = require('./Helper-8ae6a805.js');
10
+ const checkCircle2 = require('./check-circle2-1aac98d1.js');
11
+
12
+ const ShippingFast = `<!-- Generated by IcoMoon.io -->
13
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
14
+ <title>shipping-fast</title>
15
+ <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>
16
+ </svg>
17
+ `;
18
+
19
+ const sallaRatingModalCss = "";
20
+
21
+ const SallaRatingModal = class {
22
+ constructor(hostRef) {
23
+ index.registerInstance(this, hostRef);
24
+ this.stepsCount = 0;
25
+ this.currentIndex = 0;
26
+ this.submitted = [];
27
+ /**
28
+ * The order id, to rate on its products & shipping
29
+ */
30
+ this.orderId = salla.config.get('page.id');
31
+ this.translationLoaded = false;
32
+ Helper.Helper.setHost(document);
33
+ salla.event.on('rating::open', () => this.open());
34
+ salla.lang.onLoaded(() => {
35
+ this.translationLoaded = true;
36
+ });
37
+ }
38
+ /**
39
+ * Show the rating modal
40
+ */
41
+ async open() {
42
+ return this.modal.open()
43
+ .then(() => this.order || salla.rating.api.order(this.orderId).then(res => this.order = res.data))
44
+ .then(() => this.modal.setTitle(salla.lang.get('pages.rating.rate_order') + ' <span class="unicode">(#' + this.order.id + ')</span>'))
45
+ .then(() => this.modal.stopLoading())
46
+ .then(() => this.stepsCount = [this.order.testimonials_enabled, this.order.products_enabled, this.order.shipping_enabled].filter(enabled => enabled).length)
47
+ .then(() => setTimeout(() => this.handleWizard(), 100));
48
+ }
49
+ /**
50
+ * Show the rating modal
51
+ */
52
+ async close() {
53
+ return this.modal.close();
54
+ }
55
+ // handle wizard
56
+ handleWizard() {
57
+ this.steps = this.modal.querySelectorAll(".s-rating-modal-step");
58
+ this.dots = this.modal.querySelectorAll(".s-rating-modal-step-dot");
59
+ this.showActiveStep();
60
+ }
61
+ showActiveStep(current = null) {
62
+ var _a;
63
+ this.currentTab = current || this.steps[this.currentIndex];
64
+ Helper.Helper.toggleClassIf('.s-rating-modal-step-dot', 's-rating-modal-bg-gray', 's-rating-modal-bg-primary', dot => dot != this.dots[this.currentIndex])
65
+ .toggleClassIf('.s-rating-modal-step', 's-rating-modal-active', 's-rating-modal-hidden', tab => tab == this.currentTab);
66
+ if (this.currentIndex != 0) {
67
+ // the animation
68
+ Helper.Helper.toggleElementClassIf(this.currentTab, 's-rating-modal-unactive', 's-rating-modal-hidden', () => true);
69
+ setTimeout(() => Helper.Helper.toggleElementClassIf(this.currentTab, 's-rating-modal-active', 's-rating-modal-unactive', () => true), 300);
70
+ }
71
+ // Btn text
72
+ let nextType = (_a = this.steps[this.currentIndex + 1]) === null || _a === void 0 ? void 0 : _a.dataset.type;
73
+ this.nextBtn.setText(nextType ? salla.lang.get('pages.rating.rate') + ' ' + salla.lang.get('pages.rating.' + nextType)
74
+ : salla.lang.get('pages.rating.send_ratings'));
75
+ setTimeout(() => { var _a; return this.body.setAttribute('style', 'height:' + ((_a = this.currentTab) === null || _a === void 0 ? void 0 : _a.scrollHeight) + 'px'); });
76
+ }
77
+ previousTab() {
78
+ this.currentIndex > 0 && this.currentIndex--;
79
+ Helper.Helper.toggleElementClassIf(this.backBtn, 's-rating-modal-unvisiable', 'block', () => this.currentIndex == 0);
80
+ this.showActiveStep();
81
+ }
82
+ submit() {
83
+ this.submittedBefore() || this.validate();
84
+ salla.config.canLeave = false;
85
+ this.nextBtn.load()
86
+ .then(() => this.submittedBefore() || this.sendFeedback())
87
+ .then(() => this.currentTab.querySelectorAll('[name],.s-rating-modal-btn-star').forEach(el => el.setAttribute('disabled', '')))
88
+ .then(() => this.currentIndex < this.stepsCount && this.currentIndex++)
89
+ .then(() => this.showActiveStep())
90
+ .then(() => Helper.Helper.toggleClassIf('#prev-btn', 'block', 's-rating-modal-unvisiable', () => true))
91
+ .finally(() => {
92
+ this.nextBtn.stop();
93
+ salla.config.canLeave = true;
94
+ this.currentIndex == this.stepsCount && this.showThankYou();
95
+ this.modal.isClosable = false;
96
+ });
97
+ }
98
+ submittedBefore() {
99
+ return this.submitted.includes(this.currentIndex);
100
+ }
101
+ validate(rating = null, type = null) {
102
+ if (!rating && this.currentTab.dataset.type == 'products') {
103
+ return this.currentTab.querySelectorAll('.rating-outer-form').forEach(rating => this.validate(rating, 'product'));
104
+ }
105
+ rating = rating || this.currentTab;
106
+ let stars = rating.querySelector('.rating_hidden_input').value;
107
+ let comment = rating.querySelector('.s-rating-modal-comment');
108
+ let validationMessage = rating.querySelector('.s-rating-modal-validation-msg');
109
+ if (stars && comment.value && comment.value.length > 3) {
110
+ comment.classList.remove('s-has-error');
111
+ validationMessage.innerHTML = '';
112
+ return;
113
+ }
114
+ type = type || rating['dataset'].type;
115
+ Helper.Helper.toggleElementClassIf(comment, 'save', 's-has-error', el => el.value.length > 3);
116
+ throw validationMessage.innerHTML = stars
117
+ ? (salla.lang.get('common.errors.not_less_than_chars', { chars: 4 }) + ' ' + comment.getAttribute('placeholder'))
118
+ : salla.lang.get(`pages.rating.rate_${type}_stars`).replace(' (:item)', '');
119
+ }
120
+ sendFeedback() {
121
+ let data = {};
122
+ this.currentTab.querySelectorAll('[name]').forEach((input) => {
123
+ //decode names like `<input name="jamal[inner]" value="hi">` to be {name:jamal, value: {inner:"hi"}}
124
+ let inputData = salla.helpers.inputData(input.name, input.value, data);
125
+ data[inputData.name] = inputData.value;
126
+ });
127
+ if (Object.keys(data).length == 0) {
128
+ return;
129
+ }
130
+ data['order_id'] = this.orderId;
131
+ data['type'] = this.currentTab.dataset.type;
132
+ this.submitted.push(this.currentIndex);
133
+ return salla.rating.api[this.currentTab.dataset.type](data);
134
+ }
135
+ showThankYou() {
136
+ let seconds = 10;
137
+ let timeToClose = setInterval(() => {
138
+ this.thanksTime.innerHTML = '00:0' + (seconds--);
139
+ if (seconds > 0) {
140
+ return;
141
+ }
142
+ clearInterval(timeToClose);
143
+ this.thanksTime.remove();
144
+ this.close().then(() => window.location.reload());
145
+ }, 1000);
146
+ this.modal.querySelector('.s-rating-modal-footer').classList.add('s-rating-modal-unvisiable');
147
+ this.showActiveStep(this.thanksTab);
148
+ }
149
+ render() {
150
+ return (index.h(index.Host, { class: "s-rating" }, index.h("salla-modal", { isLoading: true, width: "md", ref: modal => this.modal = modal }, this.order
151
+ ? [index.h("div", { class: "s-rating-modal-wrapper", ref: el => this.body = el }, this.order.testimonials_enabled ?
152
+ index.h("div", { class: "rating-outer-form s-rating-modal-step-wrap s-rating-modal-step s-rating-modal-hidden", "data-type": "store" }, index.h("div", { class: "s-rating-modal-rounded-icon" }, index.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" })), index.h("h2", { class: "s-rating-modal-title" }, salla.lang.get('pages.rating.rate_the_store')), index.h("div", { class: "s-rating-modal-stars-company" }, index.h("salla-rating-stars", { size: "large" })), index.h("textarea", { name: "comment", class: "s-rating-modal-comment", placeholder: salla.lang.get('pages.rating.write_store_rate') }), index.h("small", { class: "s-rating-modal-validation-msg" }))
153
+ : '', this.order.products_enabled
154
+ ? index.h("section", { class: "s-rating-modal-step s-rating-modal-hidden", "data-type": "products" }, this.order.products.map((item, index$1) => index.h("div", { class: "rating-outer-form s-rating-modal-product", "data-stars-error": salla.lang.get('pages.rating.rate_product_stars') }, index.h("div", { class: "s-rating-modal-product-img-wrap" }, index.h("img", { src: item.product.thumbnail, alt: item.product.name, class: "s-rating-modal-product-img" })), index.h("div", { class: "s-rating-modal-product-details" }, index.h("h3", { class: "s-rating-modal-product-title" }, " ", item.product.name), index.h("div", { class: "s-rating-modal-stars-product" }, index.h("salla-rating-stars", { size: "small", name: `products[${index$1}][rating]` })), index.h("input", { type: "hidden", name: `products[${index$1}][product_id]`, value: item.product.id }), index.h("textarea", { placeholder: salla.lang.get('pages.rating.write_product_rate'), name: `products[${index$1}][comment]`, class: "s-rating-modal-comment" }), index.h("small", { class: "s-rating-modal-validation-msg" })))))
155
+ : '', this.order.shipping_enabled
156
+ ? index.h("div", { class: "rating-outer-form s-rating-modal-step-wrap s-rating-modal-step s-rating-modal-hidden", "data-type": "shipping" }, index.h("input", { type: "hidden", name: "shipping_company_id", value: this.order.shipping.company.id }), this.order.shipping.company.logo
157
+ ? index.h("div", { class: "s-rating-modal-rounded-icon" }, index.h("img", { src: this.order.shipping.company.logo, class: "s-rating-modal-shipping-logo", alt: this.order.shipping.company.name }))
158
+ : index.h("span", { class: "s-rating-modal-icon", innerHTML: ShippingFast }), index.h("div", { class: "s-rating-modal-title" }, " ", salla.lang.get('pages.rating.rate_shipping') + ' ' + this.order.shipping.company.name), index.h("div", { class: "s-rating-modal-stars-company" }, index.h("salla-rating-stars", { size: "large" })), index.h("textarea", { name: "comment", class: "s-rating-modal-comment", placeholder: salla.lang.get('pages.rating.write_shipping_rate') }), index.h("small", { class: "s-rating-modal-validation-msg" }))
159
+ : '', index.h("div", { class: "s-rating-modal-thanks s-rating-modal-hidden", ref: el => this.thanksTab = el }, index.h("span", { class: "s-rating-modal-icon", innerHTML: checkCircle2.CheckCircle2 }), index.h("h3", { class: "s-rating-modal-thanks-title" }, salla.lang.get('pages.rating.thanks')), index.h("div", { class: "s-rating-modal-thanks-msg", innerHTML: this.order.thanks_message }), index.h("time", { class: "s-rating-modal-thanks-time", ref: el => this.thanksTime = el }))), index.h("div", { class: "s-rating-modal-footer" }, index.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 ? index.h("ul", { class: "s-rating-modal-dots" }, [0, 1, 2].slice(0, this.stepsCount).map(() => index.h("li", { class: 's-rating-modal-bg-gray s-rating-modal-step-dot' }))) : '', index.h("salla-button", { "loader-position": 'center', ref: el => this.nextBtn = el, onClick: () => this.submit() }, salla.lang.get('common.elements.next'))),]
160
+ : '')));
161
+ }
162
+ componentDidLoad() {
163
+ salla.event.dispatch('rating::ready', this);
164
+ }
165
+ get host() { return index.getElement(this); }
166
+ };
167
+ SallaRatingModal.style = sallaRatingModalCss;
168
+
169
+ exports.salla_rating_modal = SallaRatingModal;