@salla.sa/twilight-components 1.0.21 → 1.0.22

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 (95) hide show
  1. package/dist/cjs/Helper-fcea994c.js +23 -0
  2. package/dist/cjs/index-714023c8.js +1653 -0
  3. package/dist/cjs/index.cjs.js +13 -0
  4. package/dist/cjs/loader.cjs.js +21 -0
  5. package/dist/cjs/salla-branches.cjs.entry.js +92 -0
  6. package/dist/cjs/salla-button_5.cjs.entry.js +1727 -0
  7. package/dist/cjs/salla-localization.cjs.entry.js +82 -0
  8. package/dist/cjs/salla-login-c438bb35.js +128 -0
  9. package/dist/cjs/salla-offer.cjs.entry.js +79 -0
  10. package/dist/cjs/salla-product-availability.cjs.entry.js +75 -0
  11. package/dist/cjs/salla-rating.cjs.entry.js +195 -0
  12. package/dist/cjs/salla-search-45173394.js +85 -0
  13. package/dist/cjs/salla-search.cjs.entry.js +11 -0
  14. package/dist/cjs/twilight-components.cjs.js +19 -0
  15. package/dist/collection/Helpers/Helper.js +19 -0
  16. package/dist/collection/collection-manifest.json +22 -0
  17. package/dist/collection/components/generate-summary.js +35 -0
  18. package/dist/collection/components/salla-branches/salla-branches.css +12 -0
  19. package/dist/collection/components/salla-branches/salla-branches.js +233 -0
  20. package/dist/collection/components/salla-button/salla-button.css +3 -0
  21. package/dist/collection/components/salla-button/salla-button.js +246 -0
  22. package/dist/collection/components/salla-localization/salla-localization.js +208 -0
  23. package/dist/collection/components/salla-login/salla-login.css +3 -0
  24. package/dist/collection/components/salla-login/salla-login.js +380 -0
  25. package/dist/collection/components/salla-modal/salla-modal.js +477 -0
  26. package/dist/collection/components/salla-offer/offer-schema.js +1 -0
  27. package/dist/collection/components/salla-offer/salla-offer.js +110 -0
  28. package/dist/collection/components/salla-product-availability/salla-product-availability.js +331 -0
  29. package/dist/collection/components/salla-rating/order-feedback-response.js +1 -0
  30. package/dist/collection/components/salla-rating/salla-rating.css +7 -0
  31. package/dist/collection/components/salla-rating/salla-rating.js +277 -0
  32. package/dist/collection/components/salla-search/salla-search.css +24 -0
  33. package/dist/collection/components/salla-search/salla-search.js +143 -0
  34. package/dist/collection/components/salla-tel-input/salla-tel-input.js +121 -0
  35. package/dist/collection/components/salla-verify/salla-verify.js +280 -0
  36. package/dist/collection/index.js +2 -0
  37. package/dist/collection/interfaces/colors.js +1 -0
  38. package/dist/collection/interfaces/index.js +2 -0
  39. package/dist/collection/interfaces/ratio.js +1 -0
  40. package/dist/collection/plugins/tailwind-theme/generator.js +62 -0
  41. package/dist/collection/plugins/tailwind-theme/index.js +26 -0
  42. package/dist/{twilight-components → esm}/Helper-d07ebbc7.js +0 -0
  43. package/dist/esm/index-a1bf769d.js +1625 -0
  44. package/dist/esm/index.js +4 -0
  45. package/dist/esm/loader.js +17 -0
  46. package/dist/esm/polyfills/core-js.js +11 -0
  47. package/dist/esm/polyfills/css-shim.js +1 -0
  48. package/dist/esm/polyfills/dom.js +79 -0
  49. package/dist/esm/polyfills/es5-html-element.js +1 -0
  50. package/dist/esm/polyfills/index.js +34 -0
  51. package/dist/esm/polyfills/system.js +6 -0
  52. package/dist/{twilight-components → esm}/salla-branches.entry.js +2 -2
  53. package/dist/{twilight-components/salla-tel-input.entry.js → esm/salla-button_5.entry.js} +337 -35
  54. package/dist/{twilight-components → esm}/salla-localization.entry.js +1 -1
  55. package/dist/{twilight-components/salla-login-57b18c2c.js → esm/salla-login-dd957742.js} +26 -23
  56. package/dist/{twilight-components → esm}/salla-offer.entry.js +1 -1
  57. package/dist/{twilight-components → esm}/salla-product-availability.entry.js +1 -1
  58. package/dist/{twilight-components → esm}/salla-rating.entry.js +71 -108
  59. package/dist/{twilight-components/salla-search-30fec1e8.js → esm/salla-search-5e691ebb.js} +15 -11
  60. package/dist/esm/salla-search.entry.js +3 -0
  61. package/dist/esm/twilight-components.js +17 -0
  62. package/dist/index.cjs.js +1 -0
  63. package/dist/index.js +1 -0
  64. package/dist/twilight-components/index.esm.js +1 -4
  65. package/dist/twilight-components/p-1a6d8171.entry.js +1 -0
  66. package/dist/twilight-components/p-1deb8111.entry.js +1 -0
  67. package/dist/twilight-components/p-3a4d963e.js +1 -0
  68. package/dist/twilight-components/p-47f17d3b.js +1 -0
  69. package/dist/twilight-components/p-5b2eb87d.entry.js +1 -0
  70. package/dist/twilight-components/p-6a5be894.js +1 -0
  71. package/dist/twilight-components/p-7fbdf746.entry.js +1 -0
  72. package/dist/twilight-components/p-7fe5d346.entry.js +1 -0
  73. package/dist/twilight-components/p-81a61f4e.js +1 -0
  74. package/dist/twilight-components/p-ce991664.entry.js +1 -0
  75. package/dist/twilight-components/p-da73fc9b.entry.js +1 -0
  76. package/dist/twilight-components/twilight-components.css +1 -3
  77. package/dist/twilight-components/twilight-components.esm.js +1 -125
  78. package/dist/types/components/salla-login/salla-login.d.ts +3 -3
  79. package/dist/types/components/salla-modal/salla-modal.d.ts +1 -0
  80. package/dist/types/components/salla-rating/salla-rating.d.ts +6 -23
  81. package/dist/types/components/salla-search/salla-search.d.ts +1 -1
  82. package/dist/types/components/salla-tel-input/salla-tel-input.d.ts +14 -0
  83. package/dist/types/components/salla-verify/salla-verify.d.ts +3 -1
  84. package/dist/types/components.d.ts +12 -35
  85. package/package.json +1 -1
  86. package/dist/twilight-components/app-globals-0f993ce5.js +0 -3
  87. package/dist/twilight-components/css-shim-a64b8820.js +0 -4
  88. package/dist/twilight-components/dom-d08ba8aa.js +0 -73
  89. package/dist/twilight-components/index-9c087700.js +0 -3010
  90. package/dist/twilight-components/salla-button.entry.js +0 -75
  91. package/dist/twilight-components/salla-login.entry.js +0 -3
  92. package/dist/twilight-components/salla-modal.entry.js +0 -113
  93. package/dist/twilight-components/salla-search.entry.js +0 -3
  94. package/dist/twilight-components/salla-verify.entry.js +0 -114
  95. package/dist/twilight-components/shadow-css-bc14d9fd.js +0 -389
@@ -0,0 +1,331 @@
1
+ import { Component, Host, h, Prop, Watch, Element, Method } from '@stencil/core';
2
+ import Helper from "../../Helpers/Helper";
3
+ export class SallaProductAvailability {
4
+ constructor() {
5
+ this.isUser = Helper.isUser();
6
+ this.buttonText = salla.lang.get('pages.products.notify_availability');
7
+ this.countryCode = salla.config.country_code || 'SA';
8
+ this.subscribeText = salla.lang.get('common.elements.submit');
9
+ this.cancelText = salla.lang.get('common.elements.cancel');
10
+ this.subTitle = salla.lang.get('pages.products.notify_availability_subtitle');
11
+ this.mobileLabel = salla.lang.get('common.elements.mobile');
12
+ this.emailLabel = salla.lang.get('common.elements.email');
13
+ this.mobilePlaceholder = salla.lang.get('common.elements.mobile_placeholder');
14
+ this.emailPlaceholder = salla.lang.get('common.elements.email_placeholder');
15
+ this.productId = salla.config.page.id;
16
+ this.subscribedMessage = salla.lang.get('pages.products.notify_availability_success');
17
+ this.isSubscribed = false;
18
+ if (this.isUser) {
19
+ return;
20
+ }
21
+ this.channelsWatcher(this.channels);
22
+ this.title_ = this.host.title || salla.lang.get('pages.products.notify_availability_title');
23
+ this.host.removeAttribute('title');
24
+ }
25
+ channelsWatcher(newValue) {
26
+ this.channels_ = newValue.split(',');
27
+ }
28
+ async submit() {
29
+ if (this.isUser) {
30
+ return salla.api.product.availabilitySubscribe(this.productId)
31
+ .then(() => this.isSubscribed = true);
32
+ }
33
+ let data = { id: this.productId, country_code: this.countryCode };
34
+ if (this.mobile.value !== '') {
35
+ data['mobile'] = this.mobile.value;
36
+ }
37
+ if (this.email.value !== '') {
38
+ data['email'] = this.email.value;
39
+ }
40
+ return this.btn.load()
41
+ .then(() => this.btn.disable())
42
+ .then(() => salla.api.product.availabilitySubscribe(data))
43
+ .then(() => this.isSubscribed = true) //no need to wait until finishing alert animation
44
+ .then(() => this.btn.stop())
45
+ .then(() => this.modal.hide())
46
+ .catch(() => this.btn.stop() && this.btn.enable());
47
+ }
48
+ render() {
49
+ return (h(Host, null,
50
+ this.isSubscribed
51
+ ? h("div", { class: "s-product-availability-subscribed" }, this.subscribedMessage)
52
+ : h("slot", null,
53
+ h("salla-button", { wide: true, onClick: () => this.isUser ? this.submit() : this.modal.show() }, this.buttonText)),
54
+ this.isUser || this.isSubscribed ? '' : this.renderModal()));
55
+ }
56
+ renderModal() {
57
+ return (h("salla-modal", { ref: modal => this.modal = modal, title: this.title_, subTitle: this.subTitle, icon: "sicon-bell-ring", width: "md" },
58
+ h("div", { class: "s-product-availability-body" },
59
+ this.channels_.includes('email') ? [
60
+ h("label", { class: "s-product-availability-label" }, this.emailLabel),
61
+ h("input", { class: "s-product-availability-input", placeholder: this.emailPlaceholder, ref: el => this.email = el, type: "email" })
62
+ ] : '',
63
+ this.channels_.includes('sms') ? [
64
+ h("label", { class: "s-product-availability-label" }, this.mobileLabel),
65
+ h("input", { class: "s-product-availability-input", placeholder: this.mobilePlaceholder, ref: el => this.mobile = el, type: "text" }),
66
+ h("input", { type: "hidden", value: this.countryCode }),
67
+ ] : ''),
68
+ h("div", { slot: "footer", class: "s-product-availability-footer" },
69
+ h("salla-button", { wide: true, ref: btn => this.btn = btn, onClick: () => this.submit() }, this.subscribeText),
70
+ h("salla-button", { wide: true, "btn-style": "outline" }, this.cancelText))));
71
+ }
72
+ static get is() { return "salla-product-availability"; }
73
+ static get properties() { return {
74
+ "channels": {
75
+ "type": "string",
76
+ "mutable": false,
77
+ "complexType": {
78
+ "original": "string",
79
+ "resolved": "string",
80
+ "references": {}
81
+ },
82
+ "required": false,
83
+ "optional": false,
84
+ "docs": {
85
+ "tags": [],
86
+ "text": ""
87
+ },
88
+ "attribute": "channels",
89
+ "reflect": false
90
+ },
91
+ "buttonText": {
92
+ "type": "string",
93
+ "mutable": false,
94
+ "complexType": {
95
+ "original": "string",
96
+ "resolved": "string",
97
+ "references": {}
98
+ },
99
+ "required": false,
100
+ "optional": false,
101
+ "docs": {
102
+ "tags": [],
103
+ "text": ""
104
+ },
105
+ "attribute": "button-text",
106
+ "reflect": false,
107
+ "defaultValue": "salla.lang.get('pages.products.notify_availability')"
108
+ },
109
+ "countryCode": {
110
+ "type": "string",
111
+ "mutable": false,
112
+ "complexType": {
113
+ "original": "string",
114
+ "resolved": "string",
115
+ "references": {}
116
+ },
117
+ "required": false,
118
+ "optional": false,
119
+ "docs": {
120
+ "tags": [],
121
+ "text": ""
122
+ },
123
+ "attribute": "country-code",
124
+ "reflect": false,
125
+ "defaultValue": "salla.config.country_code || 'SA'"
126
+ },
127
+ "subscribeText": {
128
+ "type": "string",
129
+ "mutable": false,
130
+ "complexType": {
131
+ "original": "string",
132
+ "resolved": "string",
133
+ "references": {}
134
+ },
135
+ "required": false,
136
+ "optional": false,
137
+ "docs": {
138
+ "tags": [],
139
+ "text": ""
140
+ },
141
+ "attribute": "subscribe-text",
142
+ "reflect": false,
143
+ "defaultValue": "salla.lang.get('common.elements.submit')"
144
+ },
145
+ "cancelText": {
146
+ "type": "string",
147
+ "mutable": false,
148
+ "complexType": {
149
+ "original": "string",
150
+ "resolved": "string",
151
+ "references": {}
152
+ },
153
+ "required": false,
154
+ "optional": false,
155
+ "docs": {
156
+ "tags": [],
157
+ "text": ""
158
+ },
159
+ "attribute": "cancel-text",
160
+ "reflect": false,
161
+ "defaultValue": "salla.lang.get('common.elements.cancel')"
162
+ },
163
+ "subTitle": {
164
+ "type": "string",
165
+ "mutable": false,
166
+ "complexType": {
167
+ "original": "string",
168
+ "resolved": "string",
169
+ "references": {}
170
+ },
171
+ "required": false,
172
+ "optional": false,
173
+ "docs": {
174
+ "tags": [],
175
+ "text": ""
176
+ },
177
+ "attribute": "sub-title",
178
+ "reflect": false,
179
+ "defaultValue": "salla.lang.get('pages.products.notify_availability_subtitle')"
180
+ },
181
+ "mobileLabel": {
182
+ "type": "string",
183
+ "mutable": false,
184
+ "complexType": {
185
+ "original": "string",
186
+ "resolved": "string",
187
+ "references": {}
188
+ },
189
+ "required": false,
190
+ "optional": false,
191
+ "docs": {
192
+ "tags": [],
193
+ "text": ""
194
+ },
195
+ "attribute": "mobile-label",
196
+ "reflect": false,
197
+ "defaultValue": "salla.lang.get('common.elements.mobile')"
198
+ },
199
+ "emailLabel": {
200
+ "type": "string",
201
+ "mutable": false,
202
+ "complexType": {
203
+ "original": "string",
204
+ "resolved": "string",
205
+ "references": {}
206
+ },
207
+ "required": false,
208
+ "optional": false,
209
+ "docs": {
210
+ "tags": [],
211
+ "text": ""
212
+ },
213
+ "attribute": "email-label",
214
+ "reflect": false,
215
+ "defaultValue": "salla.lang.get('common.elements.email')"
216
+ },
217
+ "mobilePlaceholder": {
218
+ "type": "string",
219
+ "mutable": false,
220
+ "complexType": {
221
+ "original": "string",
222
+ "resolved": "string",
223
+ "references": {}
224
+ },
225
+ "required": false,
226
+ "optional": false,
227
+ "docs": {
228
+ "tags": [],
229
+ "text": ""
230
+ },
231
+ "attribute": "mobile-placeholder",
232
+ "reflect": false,
233
+ "defaultValue": "salla.lang.get('common.elements.mobile_placeholder')"
234
+ },
235
+ "emailPlaceholder": {
236
+ "type": "string",
237
+ "mutable": false,
238
+ "complexType": {
239
+ "original": "string",
240
+ "resolved": "string",
241
+ "references": {}
242
+ },
243
+ "required": false,
244
+ "optional": false,
245
+ "docs": {
246
+ "tags": [],
247
+ "text": ""
248
+ },
249
+ "attribute": "email-placeholder",
250
+ "reflect": false,
251
+ "defaultValue": "salla.lang.get('common.elements.email_placeholder')"
252
+ },
253
+ "productId": {
254
+ "type": "number",
255
+ "mutable": false,
256
+ "complexType": {
257
+ "original": "number",
258
+ "resolved": "number",
259
+ "references": {}
260
+ },
261
+ "required": false,
262
+ "optional": false,
263
+ "docs": {
264
+ "tags": [],
265
+ "text": ""
266
+ },
267
+ "attribute": "product-id",
268
+ "reflect": false,
269
+ "defaultValue": "salla.config.page.id"
270
+ },
271
+ "subscribedMessage": {
272
+ "type": "string",
273
+ "mutable": false,
274
+ "complexType": {
275
+ "original": "string",
276
+ "resolved": "string",
277
+ "references": {}
278
+ },
279
+ "required": false,
280
+ "optional": false,
281
+ "docs": {
282
+ "tags": [],
283
+ "text": ""
284
+ },
285
+ "attribute": "subscribed-message",
286
+ "reflect": false,
287
+ "defaultValue": "salla.lang.get('pages.products.notify_availability_success')"
288
+ },
289
+ "isSubscribed": {
290
+ "type": "boolean",
291
+ "mutable": true,
292
+ "complexType": {
293
+ "original": "boolean",
294
+ "resolved": "boolean",
295
+ "references": {}
296
+ },
297
+ "required": false,
298
+ "optional": false,
299
+ "docs": {
300
+ "tags": [],
301
+ "text": ""
302
+ },
303
+ "attribute": "is-subscribed",
304
+ "reflect": false,
305
+ "defaultValue": "false"
306
+ }
307
+ }; }
308
+ static get methods() { return {
309
+ "submit": {
310
+ "complexType": {
311
+ "signature": "() => Promise<any>",
312
+ "parameters": [],
313
+ "references": {
314
+ "Promise": {
315
+ "location": "global"
316
+ }
317
+ },
318
+ "return": "Promise<any>"
319
+ },
320
+ "docs": {
321
+ "text": "",
322
+ "tags": []
323
+ }
324
+ }
325
+ }; }
326
+ static get elementRef() { return "host"; }
327
+ static get watchers() { return [{
328
+ "propName": "channels",
329
+ "methodName": "channelsWatcher"
330
+ }]; }
331
+ }
@@ -0,0 +1,7 @@
1
+ :host {
2
+ display: block;
3
+ }
4
+
5
+ .unicode{
6
+ unicode-bidi: plaintext;
7
+ }
@@ -0,0 +1,277 @@
1
+ import { Component, h, Method, Element, Host, State } from '@stencil/core';
2
+ import Helper from "../../Helpers/Helper";
3
+ export class SallaRating {
4
+ constructor() {
5
+ this.stepsCount = 0;
6
+ this.currentIndex = 0;
7
+ this.submitted = [];
8
+ Helper.setHost(this.host);
9
+ salla.event.on('rating::show', () => this.show());
10
+ }
11
+ async show() {
12
+ return this.modal.show()
13
+ .then(() => salla.feedback.api.order(salla.get('page.id')))
14
+ .then(res => this.order = res.data)
15
+ .then(() => this.modal.setTitle(salla.lang.get('pages.rating.rate_order') + ' <span class="unicode">(#' + this.order.id + ')</span>'))
16
+ .then(() => this.modal.stopLoading())
17
+ .then(() => this.stepsCount = [this.order.testimonials_enabled, this.order.products_enabled, this.order.shipping_enabled].filter(enabled => enabled).length)
18
+ .then(() => setTimeout(() => this.initiateRating(), 100));
19
+ }
20
+ async hide() {
21
+ return this.modal.hide();
22
+ }
23
+ initiateRating() {
24
+ this.handleWizard();
25
+ this.highlightSelectedStars();
26
+ salla.document.event.onSubmit('.s-rating-stars-element', function (event) {
27
+ // Prevent form from submitting
28
+ event.preventDefault();
29
+ // Get the selected star - activeElement is not supported in safari
30
+ let activeStars = event.target.querySelectorAll('.s-rating-btn-star.hovered');
31
+ let selected = activeStars[activeStars.length - 1];
32
+ if (!selected)
33
+ return;
34
+ let selectedIndex = parseInt(selected.dataset.star, 10);
35
+ event.target.querySelector('.rating_hidden_input').value = selectedIndex;
36
+ // Get all stars in this form (only search in the form, not the whole document)
37
+ // Loop through each star, and add or remove the `.selected` class to toggle highlighting
38
+ event.target
39
+ .querySelectorAll('.s-rating-btn-star')
40
+ .forEach((star, index) => Helper.toggleElement(star, 'selected', 'un-selected', () => index < selectedIndex));
41
+ // Remove aria-pressed from any previously selected star
42
+ event.target.querySelectorAll('.s-rating-btn-star[aria-pressed="true"]').forEach(star => star.removeAttribute('aria-pressed'));
43
+ // Add aria-pressed role to the selected button
44
+ selected.setAttribute('aria-pressed', '');
45
+ });
46
+ }
47
+ // handle wizard
48
+ handleWizard() {
49
+ this.steps = this.host.querySelectorAll(".s-rating-step");
50
+ this.dots = this.host.querySelectorAll(".s-rating-step-dot");
51
+ this.showActiveStep();
52
+ }
53
+ showActiveStep(current = null) {
54
+ var _a;
55
+ this.currentTab = current || this.steps[this.currentIndex];
56
+ Helper.toggle('.s-rating-step', 's-rating-active', 's-rating-hidden', tab => tab == this.currentTab)
57
+ .toggle('.s-rating-step-dot', 's-rating-bg-gray', 's-rating-bg-primary', dot => dot != this.dots[this.currentIndex]);
58
+ // the animation
59
+ Helper.toggleElement(this.currentTab, 's-rating-unactive', 's-rating-hidden', () => true);
60
+ setTimeout(() => Helper.toggleElement(this.currentTab, 's-rating-active', 's-rating-unactive', () => true), 300);
61
+ // Btn text
62
+ let nextType = (_a = this.steps[this.currentIndex + 1]) === null || _a === void 0 ? void 0 : _a.dataset.type;
63
+ this.nextBtn.querySelector('.s-button-text').innerHTML = nextType
64
+ ? salla.lang.get('pages.rating.rate') + ' ' + salla.lang.get('pages.rating.' + nextType)
65
+ : salla.lang.get('pages.rating.send_ratings');
66
+ setTimeout(() => { var _a; return this.body.setAttribute('style', 'height:' + ((_a = this.currentTab) === null || _a === void 0 ? void 0 : _a.scrollHeight) + 'px'); });
67
+ }
68
+ highlightSelectedStars() {
69
+ let hover = ['hovered'];
70
+ Helper.all('.s-rating-stars-element', el => {
71
+ let starElements = el.querySelectorAll('.s-rating-btn-star');
72
+ // remove hovered state from stars ---
73
+ el.addEventListener('mouseout', () => starElements.forEach(star => star.classList.remove(...hover)));
74
+ starElements.forEach((starElement, index) => {
75
+ starElement.addEventListener('mouseover', () => {
76
+ starElement.classList.add(...hover);
77
+ if (index <= 1) {
78
+ starElement.previousElementSibling.tagName === 'BUTTON' ? starElement.previousElementSibling.classList.add(...hover) : null;
79
+ }
80
+ else {
81
+ for (let i = 0; i < index; i++) {
82
+ starElements[i].classList.add(...hover);
83
+ }
84
+ }
85
+ });
86
+ starElement.addEventListener('mouseout', () => starElement.classList.remove(...hover));
87
+ });
88
+ });
89
+ }
90
+ previousTab() {
91
+ this.currentIndex > 0 && this.currentIndex--;
92
+ Helper.toggleElement(this.backBtn, 's-rating-unvisiable', 'block', () => this.currentIndex == 0);
93
+ this.showActiveStep();
94
+ }
95
+ submit() {
96
+ this.submittedBefore() || this.validate();
97
+ salla.config.canLeave = false;
98
+ this.nextBtn.load()
99
+ .then(() => this.submittedBefore() || this.sendFeedback())
100
+ .then(() => this.currentTab.querySelectorAll('[name],.s-rating-btn-star').forEach(el => el.setAttribute('disabled', '')))
101
+ .then(() => this.currentIndex < this.stepsCount && this.currentIndex++)
102
+ .then(() => this.showActiveStep())
103
+ .then(() => Helper.toggle('#prev-btn', 'block', 's-rating-unvisiable', () => true))
104
+ .finally(() => {
105
+ this.nextBtn.stop();
106
+ salla.config.canLeave = true;
107
+ this.currentIndex == this.stepsCount && this.showThankYou();
108
+ });
109
+ }
110
+ submittedBefore() {
111
+ return this.submitted.includes(this.currentIndex);
112
+ }
113
+ validate(rating = null, type = null) {
114
+ if (!rating && this.currentTab.dataset.type == 'products') {
115
+ return this.currentTab.querySelectorAll('.rating-outer-form').forEach(rating => this.validate(rating, 'product'));
116
+ }
117
+ rating = rating || this.currentTab;
118
+ let stars = rating.querySelector('.rating_hidden_input').value;
119
+ let comment = rating.querySelector('.s-rating-comment');
120
+ let validationMessage = rating.querySelector('.s-rating-validation-msg');
121
+ if (stars && comment.value && comment.value.length > 3) {
122
+ comment.classList.remove('s-rating-has-error');
123
+ validationMessage.innerHTML = '';
124
+ return;
125
+ }
126
+ type = type || rating['dataset'].type;
127
+ Helper.toggleElement(comment, 'save', 's-rating-has-error', el => el.value.length > 3);
128
+ throw validationMessage.innerHTML = stars
129
+ ? (salla.lang.get('common.errors.not_less_than_chars', { chars: 4 }) + ' ' + comment.getAttribute('placeholder'))
130
+ : salla.lang.get(`pages.rating.rate_${type}_stars`).replace(' (:item)', '');
131
+ }
132
+ sendFeedback() {
133
+ let data = {};
134
+ this.currentTab.querySelectorAll('[name]').forEach((input) => {
135
+ //decode names like `<input name="jamal[inner]" value="hi">` to be name(jamal), value: {inner:"hi"}
136
+ let inputData = salla.helpers.inputData(input.name, input.value, data);
137
+ data[inputData.name] = inputData.value;
138
+ });
139
+ if (Object.keys(data).length == 0) {
140
+ return;
141
+ }
142
+ data['order_id'] = salla.get('page.id');
143
+ data['type'] = this.currentTab.dataset.type;
144
+ this.submitted.push(this.currentIndex);
145
+ return salla.feedback.api[this.currentTab.dataset.type](data);
146
+ }
147
+ showThankYou() {
148
+ let seconds = 10;
149
+ let timeToClose = setInterval(() => {
150
+ this.thanksTime.innerHTML = '00:0' + (seconds--);
151
+ if (seconds > 0) {
152
+ return;
153
+ }
154
+ clearInterval(timeToClose);
155
+ this.thanksTime.remove();
156
+ this.hide().then(() => window.location.reload());
157
+ }, 1000);
158
+ this.host.querySelector('.s-rating-footer').classList.add('s-rating-unvisiable');
159
+ this.showActiveStep(this.thanksTab);
160
+ }
161
+ renderRatingStars(size, name = 'rating') {
162
+ return (h("form", { class: "s-rating-stars-element" },
163
+ h("input", { type: "hidden", class: "rating_hidden_input", name: name, value: "" }),
164
+ [1, 2, 3, 4, 5].map(star => h("button", { type: "submit", class: `s-rating-btn-star s-rating-btn-star-` + size, "data-star": star },
165
+ h("i", { class: "sicon-star2" })))));
166
+ }
167
+ // render
168
+ render() {
169
+ return (h(Host, null,
170
+ h("salla-modal", { isLoading: true, width: "md", ref: modal => this.modal = modal }, this.order
171
+ ? [h("div", { class: "s-rating-wrapper", ref: el => this.body = el },
172
+ this.order.testimonials_enabled ?
173
+ h("div", { class: "rating-outer-form s-rating-step-wrap s-rating-step", "data-type": "store" },
174
+ h("div", { class: "s-rating-rounded-icon" },
175
+ h("img", { src: salla.get('store.logo'), alt: "store name", class: "s-rating-store-logo" })),
176
+ h("h2", { class: "s-rating-title" }, salla.lang.get('pages.rating.rate_the_store')),
177
+ h("div", { class: "s-rating-stars-company" },
178
+ " ",
179
+ this.renderRatingStars('large')),
180
+ h("textarea", { id: "storeReview", name: "comment", class: "s-rating-comment", placeholder: salla.lang.get('pages.rating.write_store_rate') }),
181
+ h("small", { class: "s-rating-validation-msg" }))
182
+ : '',
183
+ this.order.products_enabled
184
+ ? 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') },
185
+ h("img", { src: item.product.thumbnail, alt: item.product.name, class: "s-rating-product-img" }),
186
+ h("div", { class: "s-rating-product-details" },
187
+ h("h3", { class: "s-rating-product-title" },
188
+ " ",
189
+ item.product.name),
190
+ h("div", { class: "s-rating-stars-product" },
191
+ " ",
192
+ this.renderRatingStars('small', `products[${index}][rating]`)),
193
+ h("input", { type: "hidden", name: `products[${index}][product_id]`, value: item.product.id }),
194
+ h("textarea", { placeholder: salla.lang.get('pages.rating.write_product_rate'), name: `products[${index}][comment]`, class: "s-rating-comment" }),
195
+ h("small", { class: "s-rating-validation-msg" })))))
196
+ : '',
197
+ this.order.shipping_enabled
198
+ ? h("div", { class: "rating-outer-form s-rating-step-wrap s-rating-step", "data-type": "shipping" },
199
+ h("input", { type: "hidden", name: "shipping_company_id", value: this.order.shipping.company.id }),
200
+ this.order.shipping.company.logo
201
+ ? h("div", { class: "s-rating-rounded-icon" },
202
+ h("img", { src: this.order.shipping.company.logo, class: "s-rating-shipping-logo", alt: this.order.shipping.company.name }))
203
+ : h("span", { class: "s-rating-icon sicon-shipping-fast" }),
204
+ h("div", { class: "s-rating-title" },
205
+ " ",
206
+ salla.lang.get('pages.rating.rate_shipping') + ' ' + this.order.shipping.company.name),
207
+ h("div", { class: "s-rating-stars-company" }, this.renderRatingStars('large')),
208
+ h("textarea", { name: "comment", class: "s-rating-comment", placeholder: salla.lang.get('pages.rating.write_shipping_rate') }),
209
+ h("small", { class: "s-rating-validation-msg" }))
210
+ : '',
211
+ h("div", { class: "s-rating-thanks s-rating-hidden", ref: el => this.thanksTab = el },
212
+ h("span", { class: "s-rating-icon sicon-check-circle2" }),
213
+ h("h3", { class: "s-rating-thanks-title" }, salla.lang.get('pages.rating.thanks')),
214
+ h("div", { class: "s-rating-thanks-msg", innerHTML: this.order.thanks_message }),
215
+ h("time", { class: "s-rating-thanks-time", ref: el => this.thanksTime = el }))),
216
+ h("div", { class: "s-rating-footer" },
217
+ h("button", { ref: el => this.backBtn = el, onClick: () => this.previousTab(), class: "s-rating-btn s-rating-unvisiable" }, salla.lang.get('common.elements.back')),
218
+ 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' }))) : '',
219
+ h("salla-button", { ref: el => this.nextBtn = el, onClick: () => this.submit() }, salla.lang.get('common.elements.next'))),]
220
+ : '')));
221
+ }
222
+ componentDidRender() {
223
+ //todo:: know from where there is hidden attributes to the doms🤔
224
+ this.modal.querySelectorAll('[hidden]').forEach(el => el.removeAttribute('hidden'));
225
+ }
226
+ static get is() { return "salla-rating"; }
227
+ static get originalStyleUrls() { return {
228
+ "$": ["salla-rating.css"]
229
+ }; }
230
+ static get styleUrls() { return {
231
+ "$": ["salla-rating.css"]
232
+ }; }
233
+ static get states() { return {
234
+ "order": {}
235
+ }; }
236
+ static get methods() { return {
237
+ "show": {
238
+ "complexType": {
239
+ "signature": "() => Promise<NodeJS.Timeout>",
240
+ "parameters": [],
241
+ "references": {
242
+ "Promise": {
243
+ "location": "global"
244
+ },
245
+ "NodeJS": {
246
+ "location": "global"
247
+ }
248
+ },
249
+ "return": "Promise<Timeout>"
250
+ },
251
+ "docs": {
252
+ "text": "",
253
+ "tags": []
254
+ }
255
+ },
256
+ "hide": {
257
+ "complexType": {
258
+ "signature": "() => Promise<HTMLElement>",
259
+ "parameters": [],
260
+ "references": {
261
+ "Promise": {
262
+ "location": "global"
263
+ },
264
+ "HTMLElement": {
265
+ "location": "global"
266
+ }
267
+ },
268
+ "return": "Promise<HTMLElement>"
269
+ },
270
+ "docs": {
271
+ "text": "",
272
+ "tags": []
273
+ }
274
+ }
275
+ }; }
276
+ static get elementRef() { return "host"; }
277
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Initial Variables
3
+ */
4
+ /**
5
+ * Functions
6
+ */
7
+ /**
8
+ * Delivered variables
9
+ */
10
+ #s-search-modal .s-modal-wrapper {
11
+ align-items: flex-start;
12
+ padding: 0;
13
+ }
14
+ #s-search-modal .s-modal-spacer {
15
+ display: inline;
16
+ }
17
+ #s-search-modal .s-modal-body {
18
+ padding: 0;
19
+ max-width: 90%;
20
+ margin-top: 3.2rem;
21
+ }
22
+ #s-search-modal .s-modal-close {
23
+ top: 1rem;
24
+ }