@salla.sa/twilight-components 1.0.72 → 1.0.73

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 (36) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/{salla-tel-input.cjs.entry.js → salla-add-product-button_6.cjs.entry.js} +519 -0
  3. package/dist/cjs/salla-login-modal.cjs.entry.js +1 -1
  4. package/dist/cjs/twilight-components.cjs.js +1 -1
  5. package/dist/collection/collection-manifest.json +1 -0
  6. package/dist/collection/components/salla-add-product-button/salla-add-product-button.css +3 -0
  7. package/dist/collection/components/salla-add-product-button/salla-add-product-button.js +230 -0
  8. package/dist/collection/components/salla-button/salla-button.css +1 -1
  9. package/dist/collection/components/salla-login-modal/salla-login-modal.js +1 -1
  10. package/dist/collection/components/salla-product-availability/salla-product-availability.css +1 -1
  11. package/dist/collection/components/salla-product-availability/salla-product-availability.js +5 -3
  12. package/dist/components/salla-add-product-button.d.ts +11 -0
  13. package/dist/components/salla-add-product-button.js +121 -0
  14. package/dist/components/salla-button2.js +1 -1
  15. package/dist/components/salla-login-modal.js +1 -1
  16. package/dist/components/salla-product-availability.js +1 -155
  17. package/dist/{esm/salla-product-availability.entry.js → components/salla-product-availability2.js} +59 -12
  18. package/dist/esm/loader.js +1 -1
  19. package/dist/esm/{salla-tel-input.entry.js → salla-add-product-button_6.entry.js} +515 -1
  20. package/dist/esm/salla-login-modal.entry.js +1 -1
  21. package/dist/esm/twilight-components.js +1 -1
  22. package/dist/twilight-components/{p-44b84f44.entry.js → p-20a8492d.entry.js} +1 -1
  23. package/dist/twilight-components/p-a970ba23.entry.js +4 -0
  24. package/dist/twilight-components/twilight-components.esm.js +1 -1
  25. package/dist/types/components/salla-add-product-button/salla-add-product-button.d.ts +25 -0
  26. package/dist/types/components.d.ts +35 -0
  27. package/package.json +1 -1
  28. package/dist/cjs/salla-button.cjs.entry.js +0 -122
  29. package/dist/cjs/salla-modal_2.cjs.entry.js +0 -239
  30. package/dist/cjs/salla-product-availability.cjs.entry.js +0 -119
  31. package/dist/esm/salla-button.entry.js +0 -118
  32. package/dist/esm/salla-modal_2.entry.js +0 -234
  33. package/dist/twilight-components/p-3aabd1b6.entry.js +0 -4
  34. package/dist/twilight-components/p-960c050e.entry.js +0 -4
  35. package/dist/twilight-components/p-c3b196f3.entry.js +0 -4
  36. package/dist/twilight-components/p-ca4cf691.entry.js +0 -4
@@ -0,0 +1,230 @@
1
+ /*!
2
+ * Crafted with ❤ by Salla
3
+ */
4
+ import { Component, Element, Event, Host, Prop, h } from '@stencil/core';
5
+ export class SallaAddProductButton {
6
+ constructor() {
7
+ this.hostAttributes = {};
8
+ this.hasNotText = false;
9
+ this.channels = null;
10
+ this.quantity = 1;
11
+ this.donatingAmount = 0;
12
+ this.productStatus = 'sale';
13
+ this.productType = 'product';
14
+ /**
15
+ * Is the button currently disabled
16
+ */
17
+ this.disabled = false;
18
+ }
19
+ getLabel() {
20
+ if (this.productStatus === 'sale') {
21
+ return salla.lang.get('pages.cart.add_to_cart');
22
+ }
23
+ if (this.productType === 'product') {
24
+ return salla.lang.get('pages.products.out_of_stock');
25
+ }
26
+ // donating
27
+ return salla.lang.get('pages.products.donation_exceed');
28
+ }
29
+ componentWillLoad() {
30
+ this.hasNotText = !this.host.innerHTML || this.host.innerHTML === "" || this.host.innerHTML.trim().replace(/\s/g, '').localeCompare("<!---->") === 0;
31
+ }
32
+ componentDidRender() {
33
+ if (this.buttonLabel && this.hasNotText) {
34
+ salla.event.once('languages::translations.loaded', () => {
35
+ this.buttonLabel.innerHTML = this.getLabel() || 'اضافة للسلة';
36
+ });
37
+ }
38
+ }
39
+ addProductToCart(event) {
40
+ event.preventDefault();
41
+ return salla.cart.addItem({
42
+ id: this.productId,
43
+ donating_amount: this.donatingAmount,
44
+ quantity: this.quantity
45
+ }).then((response) => this.success.emit(response))
46
+ .catch((error) => this.failed.emit(error));
47
+ }
48
+ getBtnAttributes() {
49
+ for (let i = 0; i < this.host.attributes.length; i++) {
50
+ if (!['id', 'class'].includes(this.host.attributes[i].name)) {
51
+ this.hostAttributes[this.host.attributes[i].name] = this.host.attributes[i].value;
52
+ }
53
+ }
54
+ return this.hostAttributes;
55
+ }
56
+ render() {
57
+ return (h(Host, null, this.productStatus === 'out-and-notify' && this.channels ?
58
+ h("salla-product-availability", Object.assign({}, this.getBtnAttributes()),
59
+ h("slot", null)) :
60
+ h("salla-button", Object.assign({ onClick: (event) => this.addProductToCart(event), type: "button", fill: this.productStatus === 'sale' ? 'solid' : 'outline', color: this.productStatus === 'sale' ? 'primary' : 'light', "loader-position": "center" }, this.getBtnAttributes(), { disabled: this.productStatus === 'out' }),
61
+ h("slot", null),
62
+ h("span", { ref: (el) => this.buttonLabel = el }))));
63
+ }
64
+ static get is() { return "salla-add-product-button"; }
65
+ static get originalStyleUrls() { return {
66
+ "$": ["salla-add-product-button.css"]
67
+ }; }
68
+ static get styleUrls() { return {
69
+ "$": ["salla-add-product-button.css"]
70
+ }; }
71
+ static get properties() { return {
72
+ "channels": {
73
+ "type": "string",
74
+ "mutable": false,
75
+ "complexType": {
76
+ "original": "string",
77
+ "resolved": "string",
78
+ "references": {}
79
+ },
80
+ "required": false,
81
+ "optional": false,
82
+ "docs": {
83
+ "tags": [],
84
+ "text": ""
85
+ },
86
+ "attribute": "channels",
87
+ "reflect": true,
88
+ "defaultValue": "null"
89
+ },
90
+ "quantity": {
91
+ "type": "number",
92
+ "mutable": false,
93
+ "complexType": {
94
+ "original": "number",
95
+ "resolved": "number",
96
+ "references": {}
97
+ },
98
+ "required": false,
99
+ "optional": false,
100
+ "docs": {
101
+ "tags": [],
102
+ "text": ""
103
+ },
104
+ "attribute": "quantity",
105
+ "reflect": true,
106
+ "defaultValue": "1"
107
+ },
108
+ "donatingAmount": {
109
+ "type": "number",
110
+ "mutable": false,
111
+ "complexType": {
112
+ "original": "number",
113
+ "resolved": "number",
114
+ "references": {}
115
+ },
116
+ "required": false,
117
+ "optional": false,
118
+ "docs": {
119
+ "tags": [],
120
+ "text": ""
121
+ },
122
+ "attribute": "donating-amount",
123
+ "reflect": true,
124
+ "defaultValue": "0"
125
+ },
126
+ "productId": {
127
+ "type": "any",
128
+ "mutable": false,
129
+ "complexType": {
130
+ "original": "any",
131
+ "resolved": "any",
132
+ "references": {}
133
+ },
134
+ "required": false,
135
+ "optional": false,
136
+ "docs": {
137
+ "tags": [],
138
+ "text": ""
139
+ },
140
+ "attribute": "product-id",
141
+ "reflect": true
142
+ },
143
+ "productStatus": {
144
+ "type": "string",
145
+ "mutable": false,
146
+ "complexType": {
147
+ "original": "'sale' | 'out' | 'out-and-notify'",
148
+ "resolved": "\"out\" | \"out-and-notify\" | \"sale\"",
149
+ "references": {}
150
+ },
151
+ "required": false,
152
+ "optional": false,
153
+ "docs": {
154
+ "tags": [],
155
+ "text": ""
156
+ },
157
+ "attribute": "product-status",
158
+ "reflect": true,
159
+ "defaultValue": "'sale'"
160
+ },
161
+ "productType": {
162
+ "type": "string",
163
+ "mutable": false,
164
+ "complexType": {
165
+ "original": "'product' | 'service' | 'codes' | 'digital' | 'food' | 'donating' | 'group_products'",
166
+ "resolved": "\"codes\" | \"digital\" | \"donating\" | \"food\" | \"group_products\" | \"product\" | \"service\"",
167
+ "references": {}
168
+ },
169
+ "required": false,
170
+ "optional": false,
171
+ "docs": {
172
+ "tags": [],
173
+ "text": ""
174
+ },
175
+ "attribute": "product-type",
176
+ "reflect": true,
177
+ "defaultValue": "'product'"
178
+ },
179
+ "disabled": {
180
+ "type": "boolean",
181
+ "mutable": false,
182
+ "complexType": {
183
+ "original": "boolean",
184
+ "resolved": "boolean",
185
+ "references": {}
186
+ },
187
+ "required": false,
188
+ "optional": false,
189
+ "docs": {
190
+ "tags": [],
191
+ "text": "Is the button currently disabled"
192
+ },
193
+ "attribute": "disabled",
194
+ "reflect": true,
195
+ "defaultValue": "false"
196
+ }
197
+ }; }
198
+ static get events() { return [{
199
+ "method": "success",
200
+ "name": "success",
201
+ "bubbles": true,
202
+ "cancelable": true,
203
+ "composed": true,
204
+ "docs": {
205
+ "tags": [],
206
+ "text": ""
207
+ },
208
+ "complexType": {
209
+ "original": "any",
210
+ "resolved": "any",
211
+ "references": {}
212
+ }
213
+ }, {
214
+ "method": "failed",
215
+ "name": "failed",
216
+ "bubbles": true,
217
+ "cancelable": true,
218
+ "composed": true,
219
+ "docs": {
220
+ "tags": [],
221
+ "text": ""
222
+ },
223
+ "complexType": {
224
+ "original": "any",
225
+ "resolved": "any",
226
+ "references": {}
227
+ }
228
+ }]; }
229
+ static get elementRef() { return "host"; }
230
+ }
@@ -8,7 +8,7 @@
8
8
  salla-button {
9
9
  pointer-events: none;
10
10
  }
11
- salla-button[type=submit] {
11
+ salla-button[type=submit], salla-button[type=button], salla-button[type=reset] {
12
12
  -webkit-appearance: none;
13
13
  }
14
14
  salla-button[width=wide] {
@@ -160,7 +160,7 @@ export class SallaLoginModal {
160
160
  this.regType = tab === this.mobileTab ? 'phone' : 'email';
161
161
  }
162
162
  let isRegistrationTab = tab == this.registrationTab;
163
- isRegistrationTab && ((_a = this.firstName) === null || _a === void 0 ? void 0 : _a.focus());
163
+ (_a = tab.querySelector('input')) === null || _a === void 0 ? void 0 : _a.focus(); // focus the first input in tab
164
164
  (_b = this.modal) === null || _b === void 0 ? void 0 : _b.setTitle(isRegistrationTab ? salla.lang.get('common.titles.registration') : this.title);
165
165
  if (!isRegistrationTab) {
166
166
  Helper.toggleElementClassIf(this.regMobileBlock, 's-hidden', 's-show', () => this.regType === 'phone')
@@ -2,7 +2,7 @@
2
2
  * Global flags style [imported from Int-tel-input]
3
3
  */
4
4
  /*
5
- * Salla Product Availability Component: popup modal to notify user if the product is available,
5
+ * Salla Product Availability Component: popup modal to notify user if the product is available,
6
6
  * used in the product single page if the product isn't available.
7
7
  * You can use these classes to target the elements in the component.
8
8
  */
@@ -6,6 +6,8 @@ import Helper from "../../Helpers/Helper";
6
6
  export class SallaProductAvailability {
7
7
  constructor() {
8
8
  this.isUser = Helper.isUser();
9
+ this.mobileLabel = '555555555';
10
+ this.emailPlaceholder = 'your@email.com';
9
11
  /**
10
12
  * product id that can visitor subscribe to its availability notification
11
13
  */
@@ -48,9 +50,9 @@ export class SallaProductAvailability {
48
50
  this.subscribedMessage = salla.lang.get('pages.products.notify_availability_success');
49
51
  this.title_ = this.host.title || salla.lang.get('pages.products.notify_availability_title');
50
52
  this.subTitle = salla.lang.get('pages.products.notify_availability_subtitle');
51
- this.mobileLabel = salla.lang.get('common.elements.mobile');
53
+ this.mobileLabel = salla.lang.get('common.elements.mobile') || '555555555';
52
54
  this.emailLabel = salla.lang.get('common.elements.email');
53
- this.emailPlaceholder = salla.lang.get('common.elements.email_placeholder');
55
+ this.emailPlaceholder = salla.lang.get('common.elements.email_placeholder') || 'your@email.com';
54
56
  this.emailErrorMsg = salla.lang.get('common.elements.email_is_valid');
55
57
  (_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title_);
56
58
  (_b = this.btn) === null || _b === void 0 ? void 0 : _b.setText(salla.lang.get('common.elements.submit'));
@@ -86,7 +88,7 @@ export class SallaProductAvailability {
86
88
  field.nextElementSibling['innerText'] = '* ' + errorMsg;
87
89
  }
88
90
  render() {
89
- return (h(Host, { id: "s-product-availability" },
91
+ return (h(Host, { class: "s-product-availability-wrap" },
90
92
  this.isSubscribed || this.isVisitorSubscribed
91
93
  ? h("div", { class: "s-product-availability-subscribed" },
92
94
  h("i", { class: "sicon-bell-ring s-product-availability-subs-icon" }),
@@ -0,0 +1,11 @@
1
+ import type { Components, JSX } from "../types/components";
2
+
3
+ interface SallaAddProductButton extends Components.SallaAddProductButton, HTMLElement {}
4
+ export const SallaAddProductButton: {
5
+ prototype: SallaAddProductButton;
6
+ new (): SallaAddProductButton;
7
+ };
8
+ /**
9
+ * Used to define this component and all nested components recursively.
10
+ */
11
+ export const defineCustomElement: () => void;
@@ -0,0 +1,121 @@
1
+ /*!
2
+ * Crafted with ❤ by Salla
3
+ */
4
+ import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
5
+ import { d as defineCustomElement$5 } from './salla-button2.js';
6
+ import { d as defineCustomElement$4 } from './salla-modal2.js';
7
+ import { d as defineCustomElement$3 } from './salla-product-availability2.js';
8
+ import { d as defineCustomElement$2 } from './salla-tel-input2.js';
9
+
10
+ const sallaAddProductButtonCss = ":host{display:block}";
11
+
12
+ const SallaAddProductButton$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
13
+ constructor() {
14
+ super();
15
+ this.__registerHost();
16
+ this.success = createEvent(this, "success", 7);
17
+ this.failed = createEvent(this, "failed", 7);
18
+ this.hostAttributes = {};
19
+ this.hasNotText = false;
20
+ this.channels = null;
21
+ this.quantity = 1;
22
+ this.donatingAmount = 0;
23
+ this.productStatus = 'sale';
24
+ this.productType = 'product';
25
+ /**
26
+ * Is the button currently disabled
27
+ */
28
+ this.disabled = false;
29
+ }
30
+ getLabel() {
31
+ if (this.productStatus === 'sale') {
32
+ return salla.lang.get('pages.cart.add_to_cart');
33
+ }
34
+ if (this.productType === 'product') {
35
+ return salla.lang.get('pages.products.out_of_stock');
36
+ }
37
+ // donating
38
+ return salla.lang.get('pages.products.donation_exceed');
39
+ }
40
+ componentWillLoad() {
41
+ this.hasNotText = !this.host.innerHTML || this.host.innerHTML === "" || this.host.innerHTML.trim().replace(/\s/g, '').localeCompare("<!---->") === 0;
42
+ }
43
+ componentDidRender() {
44
+ if (this.buttonLabel && this.hasNotText) {
45
+ salla.event.once('languages::translations.loaded', () => {
46
+ this.buttonLabel.innerHTML = this.getLabel() || 'اضافة للسلة';
47
+ });
48
+ }
49
+ }
50
+ addProductToCart(event) {
51
+ event.preventDefault();
52
+ return salla.cart.addItem({
53
+ id: this.productId,
54
+ donating_amount: this.donatingAmount,
55
+ quantity: this.quantity
56
+ }).then((response) => this.success.emit(response))
57
+ .catch((error) => this.failed.emit(error));
58
+ }
59
+ getBtnAttributes() {
60
+ for (let i = 0; i < this.host.attributes.length; i++) {
61
+ if (!['id', 'class'].includes(this.host.attributes[i].name)) {
62
+ this.hostAttributes[this.host.attributes[i].name] = this.host.attributes[i].value;
63
+ }
64
+ }
65
+ return this.hostAttributes;
66
+ }
67
+ render() {
68
+ return (h(Host, null, this.productStatus === 'out-and-notify' && this.channels ?
69
+ h("salla-product-availability", Object.assign({}, this.getBtnAttributes()), h("slot", null)) :
70
+ h("salla-button", Object.assign({ onClick: (event) => this.addProductToCart(event), type: "button", fill: this.productStatus === 'sale' ? 'solid' : 'outline', color: this.productStatus === 'sale' ? 'primary' : 'light', "loader-position": "center" }, this.getBtnAttributes(), { disabled: this.productStatus === 'out' }), h("slot", null), h("span", { ref: (el) => this.buttonLabel = el }))));
71
+ }
72
+ get host() { return this; }
73
+ static get style() { return sallaAddProductButtonCss; }
74
+ }, [4, "salla-add-product-button", {
75
+ "channels": [513],
76
+ "quantity": [514],
77
+ "donatingAmount": [514, "donating-amount"],
78
+ "productId": [520, "product-id"],
79
+ "productStatus": [513, "product-status"],
80
+ "productType": [513, "product-type"],
81
+ "disabled": [516]
82
+ }]);
83
+ function defineCustomElement$1() {
84
+ if (typeof customElements === "undefined") {
85
+ return;
86
+ }
87
+ const components = ["salla-add-product-button", "salla-button", "salla-modal", "salla-product-availability", "salla-tel-input"];
88
+ components.forEach(tagName => { switch (tagName) {
89
+ case "salla-add-product-button":
90
+ if (!customElements.get(tagName)) {
91
+ customElements.define(tagName, SallaAddProductButton$1);
92
+ }
93
+ break;
94
+ case "salla-button":
95
+ if (!customElements.get(tagName)) {
96
+ defineCustomElement$5();
97
+ }
98
+ break;
99
+ case "salla-modal":
100
+ if (!customElements.get(tagName)) {
101
+ defineCustomElement$4();
102
+ }
103
+ break;
104
+ case "salla-product-availability":
105
+ if (!customElements.get(tagName)) {
106
+ defineCustomElement$3();
107
+ }
108
+ break;
109
+ case "salla-tel-input":
110
+ if (!customElements.get(tagName)) {
111
+ defineCustomElement$2();
112
+ }
113
+ break;
114
+ } });
115
+ }
116
+ defineCustomElement$1();
117
+
118
+ const SallaAddProductButton = SallaAddProductButton$1;
119
+ const defineCustomElement = defineCustomElement$1;
120
+
121
+ export { SallaAddProductButton, defineCustomElement };
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
5
5
 
6
- const sallaButtonCss = "salla-button{pointer-events:none}salla-button[type=submit]{-webkit-appearance:none}salla-button[width=wide]{width:100%}.s-button-wrap[loading]{pointer-events:none}.s-button-wrap[loading] .s-button-element{pointer-events:none !important}.s-button-wrap[loading] .s-button-loader-center .s-button-text{opacity:0}.s-button-wrap .s-button-element[loading]{pointer-events:none !important}.s-button-wrap .s-button-element:not(:disabled){pointer-events:auto}.s-button-wrap .s-button-solid .s-button-loader:before{border-color:#fff #fff rgba(255, 255, 255, 0.2) rgba(255, 255, 255, 0.2)}.s-button-wrap .s-button-outline{border:1px solid currentColor}.s-button-wrap .s-button-outline:hover{border-color:transparent}.s-button-wrap .s-button-outline .s-button-loader:before{border-top-color:currentColor;border-left-color:currentColor}.s-button-wrap .s-button-icon.s-button-large{width:56px;height:56px}.s-button-wrap .s-button-icon.s-button-small{width:24px;height:24px}.s-button-wrap .s-button-icon.s-button-small .s-button-loader:before{width:0.85rem;height:0.85rem}.s-button-wrap .s-button-loader-after .s-button-load{flex-direction:row}.s-button-wrap .s-button-loader-start.s-button-element{padding-left:32px;padding-right:32px}.s-button-wrap .s-button-loader-start .s-button-loader{position:absolute;right:8px}.s-button-wrap .s-button-loader-start .s-button-loader [dir=ltr]{left:8px;right:auto}.s-button-wrap .s-button-loader-end.s-button-element{padding-left:32px;padding-right:32px}.s-button-wrap .s-button-loader-end .s-button-loader{position:absolute;left:8px}.s-button-wrap .s-button-loader-end .s-button-loader [dir=ltr]{right:8px;left:auto}.s-button-wrap .s-button-loader-center .s-button-loader{position:absolute;top:50%;left:50%;transform:translateY(-50%) translateX(-50%);margin:0 !important}";
6
+ const sallaButtonCss = "salla-button{pointer-events:none}salla-button[type=submit],salla-button[type=button],salla-button[type=reset]{-webkit-appearance:none}salla-button[width=wide]{width:100%}.s-button-wrap[loading]{pointer-events:none}.s-button-wrap[loading] .s-button-element{pointer-events:none !important}.s-button-wrap[loading] .s-button-loader-center .s-button-text{opacity:0}.s-button-wrap .s-button-element[loading]{pointer-events:none !important}.s-button-wrap .s-button-element:not(:disabled){pointer-events:auto}.s-button-wrap .s-button-solid .s-button-loader:before{border-color:#fff #fff rgba(255, 255, 255, 0.2) rgba(255, 255, 255, 0.2)}.s-button-wrap .s-button-outline{border:1px solid currentColor}.s-button-wrap .s-button-outline:hover{border-color:transparent}.s-button-wrap .s-button-outline .s-button-loader:before{border-top-color:currentColor;border-left-color:currentColor}.s-button-wrap .s-button-icon.s-button-large{width:56px;height:56px}.s-button-wrap .s-button-icon.s-button-small{width:24px;height:24px}.s-button-wrap .s-button-icon.s-button-small .s-button-loader:before{width:0.85rem;height:0.85rem}.s-button-wrap .s-button-loader-after .s-button-load{flex-direction:row}.s-button-wrap .s-button-loader-start.s-button-element{padding-left:32px;padding-right:32px}.s-button-wrap .s-button-loader-start .s-button-loader{position:absolute;right:8px}.s-button-wrap .s-button-loader-start .s-button-loader [dir=ltr]{left:8px;right:auto}.s-button-wrap .s-button-loader-end.s-button-element{padding-left:32px;padding-right:32px}.s-button-wrap .s-button-loader-end .s-button-loader{position:absolute;left:8px}.s-button-wrap .s-button-loader-end .s-button-loader [dir=ltr]{right:8px;left:auto}.s-button-wrap .s-button-loader-center .s-button-loader{position:absolute;top:50%;left:50%;transform:translateY(-50%) translateX(-50%);margin:0 !important}";
7
7
 
8
8
  const SallaButton = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
9
9
  constructor() {
@@ -158,7 +158,7 @@ const SallaLoginModal$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLEle
158
158
  this.regType = tab === this.mobileTab ? 'phone' : 'email';
159
159
  }
160
160
  let isRegistrationTab = tab == this.registrationTab;
161
- isRegistrationTab && ((_a = this.firstName) === null || _a === void 0 ? void 0 : _a.focus());
161
+ (_a = tab.querySelector('input')) === null || _a === void 0 ? void 0 : _a.focus(); // focus the first input in tab
162
162
  (_b = this.modal) === null || _b === void 0 ? void 0 : _b.setTitle(isRegistrationTab ? salla.lang.get('common.titles.registration') : this.title);
163
163
  if (!isRegistrationTab) {
164
164
  Helper.toggleElementClassIf(this.regMobileBlock, 's-hidden', 's-show', () => this.regType === 'phone')
@@ -1,161 +1,7 @@
1
1
  /*!
2
2
  * Crafted with ❤ by Salla
3
3
  */
4
- import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
5
- import { H as Helper } from './Helper.js';
6
- import { d as defineCustomElement$4 } from './salla-button2.js';
7
- import { d as defineCustomElement$3 } from './salla-modal2.js';
8
- import { d as defineCustomElement$2 } from './salla-tel-input2.js';
9
-
10
- const sallaProductAvailabilityCss = "";
11
-
12
- const SallaProductAvailability$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
13
- constructor() {
14
- super();
15
- this.__registerHost();
16
- this.isUser = Helper.isUser();
17
- /**
18
- * product id that can visitor subscribe to its availability notification
19
- */
20
- this.productId = salla.config.get('page.id');
21
- /**
22
- * is current user already subscribed
23
- */
24
- this.isSubscribed = false;
25
- // @Method()
26
- this.submit = async () => {
27
- if (this.isUser) {
28
- return salla.api.product.availabilitySubscribe(this.productId)
29
- .then(() => this.isSubscribed = true);
30
- }
31
- let { mobile, countryCode } = await this.mobileInput.getValues(), data = { id: this.productId, country_code: countryCode };
32
- mobile !== '' && (data['mobile'] = mobile);
33
- this.email.value !== '' && (data['email'] = this.email.value);
34
- await this.validateform();
35
- return this.btn.load()
36
- .then(() => this.btn.disable())
37
- .then(() => salla.api.product.availabilitySubscribe(data))
38
- .then(() => {
39
- this.isSubscribed = true;
40
- salla.storage.set(`product-${this.productId}-subscribed`, true);
41
- }) //no need to wait until finishing alert animation
42
- .then(() => this.btn.stop())
43
- .then(() => this.modal.hide())
44
- .catch(() => this.btn.stop() && this.btn.enable());
45
- };
46
- // helpers
47
- this.typing = (e, submitMethod) => {
48
- const error = e.target.nextElementSibling;
49
- e.target.classList.remove('s-has-error');
50
- (error === null || error === void 0 ? void 0 : error.classList.contains('s-product-availability-error-msg')) && (error.innerText = '');
51
- e.key == 'Enter' && submitMethod();
52
- };
53
- salla.event.on('languages::translations.loaded', () => {
54
- var _a, _b, _c, _d;
55
- // console.log('translations:', salla.lang);
56
- this.subscribedMessage = salla.lang.get('pages.products.notify_availability_success');
57
- this.title_ = this.host.title || salla.lang.get('pages.products.notify_availability_title');
58
- this.subTitle = salla.lang.get('pages.products.notify_availability_subtitle');
59
- this.mobileLabel = salla.lang.get('common.elements.mobile');
60
- this.emailLabel = salla.lang.get('common.elements.email');
61
- this.emailPlaceholder = salla.lang.get('common.elements.email_placeholder');
62
- this.emailErrorMsg = salla.lang.get('common.elements.email_is_valid');
63
- (_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title_);
64
- (_b = this.btn) === null || _b === void 0 ? void 0 : _b.setText(salla.lang.get('common.elements.submit'));
65
- (_c = this.cancelBtn) === null || _c === void 0 ? void 0 : _c.setText(salla.lang.get('common.elements.cancel'));
66
- (_d = this.inlineBtn) === null || _d === void 0 ? void 0 : _d.setText(salla.lang.get('pages.products.notify_availability'));
67
- });
68
- if (this.isUser)
69
- return;
70
- this.channelsWatcher(this.channels);
71
- this.title_ = this.host.title || salla.lang.get('pages.products.notify_availability_title');
72
- this.host.removeAttribute('title');
73
- this.isVisitorSubscribed = salla.storage.get(`product-${this.productId}-subscribed`);
74
- }
75
- channelsWatcher(newValue) {
76
- this.channels_ = newValue.split(',');
77
- }
78
- async validateform() {
79
- if (this.channels_.includes('email')) {
80
- const isEmailValid = Helper.isValidEmail(this.email.value);
81
- if (isEmailValid)
82
- return;
83
- !isEmailValid && this.validateField(this.email, this.emailErrorMsg);
84
- }
85
- if (this.channels_.includes('sms')) {
86
- const isPhoneValid = await this.mobileInput.isValid();
87
- if (isPhoneValid)
88
- return;
89
- }
90
- throw ('Please insert required fields');
91
- }
92
- validateField(field, errorMsg) {
93
- field.classList.add('s-has-error');
94
- field.nextElementSibling['innerText'] = '* ' + errorMsg;
95
- }
96
- render() {
97
- return (h(Host, { id: "s-product-availability" }, this.isSubscribed || this.isVisitorSubscribed
98
- ? h("div", { class: "s-product-availability-subscribed" }, h("i", { class: "sicon-bell-ring s-product-availability-subs-icon" }), " ", this.subscribedMessage)
99
- :
100
- h("salla-button", { width: "wide", onClick: () => this.isUser ? this.submit() : this.modal.show(), ref: btn => this.inlineBtn = btn }, salla.lang.get('pages.products.notify_availability')), this.isUser || this.isSubscribed || this.isVisitorSubscribed ? '' : this.renderModal()));
101
- }
102
- renderModal() {
103
- return (h("salla-modal", { ref: modal => this.modal = modal, "modal-title": this.title_, subTitle: this.subTitle, icon: "sicon-bell-ring", width: "sm" }, h("div", { class: "s-product-availability-body" }, this.channels_.includes('email') ? [
104
- h("label", { class: "s-product-availability-label" }, this.emailLabel),
105
- h("input", { class: "s-product-availability-input", onKeyDown: e => this.typing(e, this.submit), placeholder: this.emailPlaceholder, ref: el => this.email = el, type: "email" }),
106
- h("span", { class: "s-product-availability-error-msg" })
107
- ] : '', this.channels_.includes('sms') ? [
108
- h("label", { class: "s-product-availability-label" }, this.mobileLabel),
109
- h("salla-tel-input", { ref: el => this.mobileInput = el, onKeyDown: e => this.typing(e, this.submit) })
110
- ] : ''), h("div", { slot: "footer", class: "s-product-availability-footer" }, h("salla-button", { width: "wide", color: "light", fill: "outline", onClick: () => this.modal.hide(), ref: btn => this.cancelBtn = btn }, salla.lang.get('common.elements.cancel')), h("salla-button", { "loader-position": 'center', width: "wide", ref: btn => this.btn = btn, onClick: () => this.submit() }, salla.lang.get('common.elements.submit')))));
111
- }
112
- get host() { return this; }
113
- static get watchers() { return {
114
- "channels": ["channelsWatcher"]
115
- }; }
116
- static get style() { return sallaProductAvailabilityCss; }
117
- }, [0, "salla-product-availability", {
118
- "channels": [1],
119
- "productId": [2, "product-id"],
120
- "isSubscribed": [1028, "is-subscribed"],
121
- "subTitle": [32],
122
- "mobileLabel": [32],
123
- "emailLabel": [32],
124
- "emailPlaceholder": [32],
125
- "subscribedMessage": [32],
126
- "title_": [32],
127
- "emailErrorMsg": [32],
128
- "isVisitorSubscribed": [32]
129
- }]);
130
- function defineCustomElement$1() {
131
- if (typeof customElements === "undefined") {
132
- return;
133
- }
134
- const components = ["salla-product-availability", "salla-button", "salla-modal", "salla-tel-input"];
135
- components.forEach(tagName => { switch (tagName) {
136
- case "salla-product-availability":
137
- if (!customElements.get(tagName)) {
138
- customElements.define(tagName, SallaProductAvailability$1);
139
- }
140
- break;
141
- case "salla-button":
142
- if (!customElements.get(tagName)) {
143
- defineCustomElement$4();
144
- }
145
- break;
146
- case "salla-modal":
147
- if (!customElements.get(tagName)) {
148
- defineCustomElement$3();
149
- }
150
- break;
151
- case "salla-tel-input":
152
- if (!customElements.get(tagName)) {
153
- defineCustomElement$2();
154
- }
155
- break;
156
- } });
157
- }
158
- defineCustomElement$1();
4
+ import { S as SallaProductAvailability$1, d as defineCustomElement$1 } from './salla-product-availability2.js';
159
5
 
160
6
  const SallaProductAvailability = SallaProductAvailability$1;
161
7
  const defineCustomElement = defineCustomElement$1;