@salla.sa/twilight-components 2.11.54 → 2.11.55

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 (25) hide show
  1. package/dist/cjs/salla-add-product-button.cjs.entry.js +10 -9
  2. package/dist/cjs/salla-button_36.cjs.entry.js +42 -28
  3. package/dist/cjs/salla-product-options.cjs.entry.js +1 -1
  4. package/dist/collection/components/salla-add-product-button/salla-add-product-button.js +14 -9
  5. package/dist/collection/components/salla-product-availability/salla-product-availability.js +42 -28
  6. package/dist/collection/components/salla-product-options/salla-product-options.js +2 -2
  7. package/dist/components/salla-add-product-button.js +10 -9
  8. package/dist/components/salla-product-availability2.js +42 -28
  9. package/dist/components/salla-product-options.js +1 -1
  10. package/dist/esm/salla-add-product-button.entry.js +10 -9
  11. package/dist/esm/salla-button_36.entry.js +42 -28
  12. package/dist/esm/salla-product-options.entry.js +1 -1
  13. package/dist/esm-es5/salla-add-product-button.entry.js +2 -2
  14. package/dist/esm-es5/salla-button_36.entry.js +1 -1
  15. package/dist/twilight/{p-b4d54536.entry.js → p-6dc9f167.entry.js} +1 -1
  16. package/dist/twilight/p-84d8b36b.system.js +1 -1
  17. package/dist/twilight/{p-bebccd3d.system.entry.js → p-9fbf1baf.system.entry.js} +1 -1
  18. package/dist/twilight/p-ca92ba53.system.entry.js +4 -0
  19. package/dist/twilight/p-edc8a654.entry.js +4 -0
  20. package/dist/twilight/twilight.esm.js +1 -1
  21. package/dist/types/components/salla-product-options/salla-product-options.d.ts +1 -1
  22. package/dist/types/components.d.ts +1 -1
  23. package/package.json +2 -2
  24. package/dist/twilight/p-cdb6aa9e.entry.js +0 -4
  25. package/dist/twilight/p-d9579b04.system.entry.js +0 -4
@@ -91,10 +91,10 @@ const SallaAddProductButton = class {
91
91
  return '';
92
92
  }
93
93
  if (this.hasSubscribedOptions) {
94
- return index.h(index.Host, null, index.h("salla-product-availability", Object.assign({}, this.getBtnAttributes(), { "is-subscribed": true })));
94
+ return index.h(index.Host, null, index.h("salla-product-availability", Object.assign({}, this.getBtnAttributes(), { "is-subscribed": true }), index.h("span", { class: "s-hidden" }, index.h("slot", null))));
95
95
  }
96
96
  if ((this.productStatus === 'out-and-notify' && this.channels) || this.hasOutOfStockOption) {
97
- return index.h(index.Host, null, index.h("salla-product-availability", Object.assign({}, this.getBtnAttributes())));
97
+ return index.h(index.Host, null, index.h("salla-product-availability", Object.assign({}, this.getBtnAttributes()), index.h("span", { class: "s-hidden" }, index.h("slot", null))));
98
98
  }
99
99
  return index.h(index.Host, null, index.h("salla-button", Object.assign({ color: this.productStatus === 'sale' ? 'primary' : 'light', type: "button", fill: this.productStatus === 'sale' ? 'solid' : 'outline', ref: el => this.btn = el, onClick: event => this.addProductToCart(event), disabled: this.productStatus !== 'sale' }, this.getBtnAttributes(), { "loader-position": "center" }), index.h("slot", null)));
100
100
  }
@@ -103,19 +103,20 @@ const SallaAddProductButton = class {
103
103
  return;
104
104
  }
105
105
  salla.event.on('product-options::change', async (data) => {
106
- var _a;
106
+ var _a, _b;
107
107
  if (!['thumbnail', 'color', 'single-option'].includes(data.option.type)) {
108
108
  return;
109
109
  }
110
- this.hasOutOfStockOption = await ((_a = document.querySelector(`salla-product-options[product-id="${this.productId}"]`)) === null || _a === void 0 ? void 0 : _a.hasOutOfStockOption());
110
+ this.hasSubscribedOptions = false;
111
111
  this.hasLabel = false;
112
- if (!this.subscribedOptions || this.subscribedOptions === 'null') {
112
+ this.selectedOptions = await ((_a = document.querySelector(`salla-product-options[product-id="${this.productId}"]`)) === null || _a === void 0 ? void 0 : _a.getSelectedOptions());
113
+ this.hasOutOfStockOption = await ((_b = document.querySelector(`salla-product-options[product-id="${this.productId}"]`)) === null || _b === void 0 ? void 0 : _b.hasOutOfStockOption());
114
+ let subscribedDetails = salla.storage.get(`product-${this.productId}-subscribed-options`);
115
+ if (!subscribedDetails && !this.subscribedOptions || !this.hasOutOfStockOption) {
113
116
  return;
114
117
  }
115
- //check if subscribedOptions are the selected now
116
- this.hasSubscribedOptions = JSON.parse(this.subscribedOptions)
117
- .filter(ids => ids.every(id => this.selectedOptions.some(option => option.id === id)))
118
- .length > 0;
118
+ const parsedSubscribedDetails = subscribedDetails ? subscribedDetails.map(ids => ids.split(',').map(id => parseInt(id))) : [];
119
+ this.hasSubscribedOptions = parsedSubscribedDetails.length > 0 && parsedSubscribedDetails.some(ids => ids.every(id => this.selectedOptions.some(option => option.id === id)));
119
120
  });
120
121
  }
121
122
  componentDidRender() {
@@ -23249,12 +23249,34 @@ const SallaProductAvailability = class {
23249
23249
  * is current user already subscribed
23250
23250
  */
23251
23251
  this.isSubscribed = false;
23252
+ this.handleSubmitOptions = async () => {
23253
+ let payload = { id: this.productId };
23254
+ if (!this.notifyOptionsAvailability) {
23255
+ return payload;
23256
+ }
23257
+ let optionsElement = document.querySelector(`salla-product-options[product-id="${this.productId}"]`);
23258
+ let options = Object.values(await (optionsElement === null || optionsElement === void 0 ? void 0 : optionsElement.getSelectedOptionsData()) || {});
23259
+ //if all options not selected, show message && throw exception
23260
+ if (options.length && !await (optionsElement === null || optionsElement === void 0 ? void 0 : optionsElement.reportValidity())) {
23261
+ let errorMessage = salla.lang.get('common.messages.required_fields');
23262
+ salla.error(errorMessage);
23263
+ throw errorMessage;
23264
+ }
23265
+ payload.options = [];
23266
+ options.forEach(option => {
23267
+ //inject numbers only, without zeros
23268
+ if (option && !isNaN(option)) {
23269
+ payload.options.push(Number(option));
23270
+ }
23271
+ });
23272
+ return payload;
23273
+ };
23252
23274
  // helpers
23253
- this.typing = (e, submitMethod) => {
23275
+ this.typing = (e) => {
23254
23276
  const error = e.target.nextElementSibling;
23255
23277
  e.target.classList.remove('s-has-error');
23256
23278
  (error === null || error === void 0 ? void 0 : error.classList.contains('s-product-availability-error-msg')) && (error.innerText = '');
23257
- e.key == 'Enter' && submitMethod();
23279
+ e.keyCode === 13 && this.submit();
23258
23280
  };
23259
23281
  salla.lang.onLoaded(() => {
23260
23282
  var _a;
@@ -23276,28 +23298,6 @@ const SallaProductAvailability = class {
23276
23298
  channelsWatcher(newValue) {
23277
23299
  this.channels_ = !!newValue ? newValue.split(',') : [];
23278
23300
  }
23279
- async handleSubmitOptions() {
23280
- let payload = { id: this.productId };
23281
- if (!this.notifyOptionsAvailability) {
23282
- return payload;
23283
- }
23284
- let optionsElement = document.querySelector(`salla-product-options[product-id="${this.productId}"]`);
23285
- let options = Object.values(await (optionsElement === null || optionsElement === void 0 ? void 0 : optionsElement.getSelectedOptionsData()) || {});
23286
- //if all options not selected, show message && throw exception
23287
- if (options.length && !await (optionsElement === null || optionsElement === void 0 ? void 0 : optionsElement.reportValidity())) {
23288
- let errorMessage = salla.lang.get('common.messages.required_fields');
23289
- salla.error(errorMessage);
23290
- throw errorMessage;
23291
- }
23292
- payload.options = [];
23293
- options.forEach(option => {
23294
- //inject numbers only, without zeros
23295
- if (option && !isNaN(option)) {
23296
- payload.options.push(Number(option));
23297
- }
23298
- });
23299
- return payload;
23300
- }
23301
23301
  openModel() {
23302
23302
  this.handleSubmitOptions().then(isSuccess => isSuccess ? this.modal.open() : null);
23303
23303
  }
@@ -23320,9 +23320,23 @@ const SallaProductAvailability = class {
23320
23320
  .then(() => this.btn.disable())
23321
23321
  .then(() => salla.api.product.availabilitySubscribe(payload))
23322
23322
  .then(() => {
23323
+ if (!this.notifyOptionsAvailability) {
23324
+ salla.storage.set(`product-${this.productId}-subscribed`, true);
23325
+ return;
23326
+ }
23327
+ if (payload.options.length) {
23328
+ let options = salla.storage.get(`product-${this.productId}-subscribed-options`) || [];
23329
+ let selectedOptionsString = payload.options.join(',');
23330
+ if (!options.includes(selectedOptionsString)) {
23331
+ options.push(selectedOptionsString);
23332
+ salla.storage.set(`product-${this.productId}-subscribed-options`, options);
23333
+ }
23334
+ else {
23335
+ salla.log('already subscribed to this options');
23336
+ }
23337
+ }
23323
23338
  this.isSubscribed = true;
23324
- salla.storage.set(`product-${this.productId}-subscribed`, true);
23325
- }) //no need to wait until finishing alert animation
23339
+ })
23326
23340
  .then(() => this.btn.stop())
23327
23341
  .then(() => this.modal.close())
23328
23342
  .catch(() => this.btn.stop() && this.btn.enable());
@@ -23358,11 +23372,11 @@ const SallaProductAvailability = class {
23358
23372
  renderModal() {
23359
23373
  return (index.h("salla-modal", { ref: modal => this.modal = modal, "modal-title": this.title_, subTitle: salla.lang.get('pages.products.notify_availability_subtitle'), width: "sm" }, index.h("span", { slot: 'icon', class: "s-product-availability-header-icon", innerHTML: BellRing }), index.h("div", { class: "s-product-availability-body" }, this.channels_.includes('email') ? [
23360
23374
  index.h("label", { class: "s-product-availability-label" }, salla.lang.get('common.elements.email')),
23361
- index.h("input", { class: "s-product-availability-input", onKeyDown: e => this.typing(e, this.submit), placeholder: salla.lang.get('common.elements.email_placeholder') || 'your@email.com', ref: el => this.email = el, type: "email" }),
23375
+ index.h("input", { class: "s-product-availability-input", onKeyDown: e => this.typing(e), placeholder: salla.lang.get('common.elements.email_placeholder') || 'your@email.com', ref: el => this.email = el, type: "email" }),
23362
23376
  index.h("span", { class: "s-product-availability-error-msg" })
23363
23377
  ] : '', this.channels_.includes('sms') ? [
23364
23378
  index.h("label", { class: "s-product-availability-label" }, salla.lang.get('common.elements.mobile')),
23365
- index.h("salla-tel-input", { ref: el => this.mobileInput = el, onKeyDown: e => this.typing(e, this.submit) })
23379
+ index.h("salla-tel-input", { ref: el => this.mobileInput = el, onKeyDown: e => this.typing(e) })
23366
23380
  ] : ''), index.h("div", { slot: "footer", class: "s-product-availability-footer" }, index.h("salla-button", { class: "modal-cancel-btn", width: "wide", color: "light", fill: "outline", onClick: () => this.modal.close() }, salla.lang.get('common.elements.cancel')), index.h("salla-button", { class: "submit-btn", "loader-position": 'center', width: "wide", ref: btn => this.btn = btn, onClick: () => this.submit() }, salla.lang.get('common.elements.submit')))));
23367
23381
  }
23368
23382
  get host() { return index.getElement(this); }
@@ -114,7 +114,7 @@ const SallaProductOptions = class {
114
114
  return selectedOptions;
115
115
  }
116
116
  /**
117
- * Get the id's of the selected options.
117
+ * Report options form validity.
118
118
  * */
119
119
  async reportValidity() {
120
120
  let requiredElements = this.host.querySelectorAll('[required]');
@@ -82,11 +82,15 @@ export class SallaAddProductButton {
82
82
  }
83
83
  if (this.hasSubscribedOptions) {
84
84
  return h(Host, null,
85
- h("salla-product-availability", Object.assign({}, this.getBtnAttributes(), { "is-subscribed": true })));
85
+ h("salla-product-availability", Object.assign({}, this.getBtnAttributes(), { "is-subscribed": true }),
86
+ h("span", { class: "s-hidden" },
87
+ h("slot", null))));
86
88
  }
87
89
  if ((this.productStatus === 'out-and-notify' && this.channels) || this.hasOutOfStockOption) {
88
90
  return h(Host, null,
89
- h("salla-product-availability", Object.assign({}, this.getBtnAttributes())));
91
+ h("salla-product-availability", Object.assign({}, this.getBtnAttributes()),
92
+ h("span", { class: "s-hidden" },
93
+ h("slot", null))));
90
94
  }
91
95
  return h(Host, null,
92
96
  h("salla-button", Object.assign({ color: this.productStatus === 'sale' ? 'primary' : 'light', type: "button", fill: this.productStatus === 'sale' ? 'solid' : 'outline', ref: el => this.btn = el, onClick: event => this.addProductToCart(event), disabled: this.productStatus !== 'sale' }, this.getBtnAttributes(), { "loader-position": "center" }),
@@ -97,19 +101,20 @@ export class SallaAddProductButton {
97
101
  return;
98
102
  }
99
103
  salla.event.on('product-options::change', async (data) => {
100
- var _a;
104
+ var _a, _b;
101
105
  if (!['thumbnail', 'color', 'single-option'].includes(data.option.type)) {
102
106
  return;
103
107
  }
104
- this.hasOutOfStockOption = await ((_a = document.querySelector(`salla-product-options[product-id="${this.productId}"]`)) === null || _a === void 0 ? void 0 : _a.hasOutOfStockOption());
108
+ this.hasSubscribedOptions = false;
105
109
  this.hasLabel = false;
106
- if (!this.subscribedOptions || this.subscribedOptions === 'null') {
110
+ this.selectedOptions = await ((_a = document.querySelector(`salla-product-options[product-id="${this.productId}"]`)) === null || _a === void 0 ? void 0 : _a.getSelectedOptions());
111
+ this.hasOutOfStockOption = await ((_b = document.querySelector(`salla-product-options[product-id="${this.productId}"]`)) === null || _b === void 0 ? void 0 : _b.hasOutOfStockOption());
112
+ let subscribedDetails = salla.storage.get(`product-${this.productId}-subscribed-options`);
113
+ if (!subscribedDetails && !this.subscribedOptions || !this.hasOutOfStockOption) {
107
114
  return;
108
115
  }
109
- //check if subscribedOptions are the selected now
110
- this.hasSubscribedOptions = JSON.parse(this.subscribedOptions)
111
- .filter(ids => ids.every(id => this.selectedOptions.some(option => option.id === id)))
112
- .length > 0;
116
+ const parsedSubscribedDetails = subscribedDetails ? subscribedDetails.map(ids => ids.split(',').map(id => parseInt(id))) : [];
117
+ this.hasSubscribedOptions = parsedSubscribedDetails.length > 0 && parsedSubscribedDetails.some(ids => ids.every(id => this.selectedOptions.some(option => option.id === id)));
113
118
  });
114
119
  }
115
120
  componentDidRender() {
@@ -16,12 +16,34 @@ export class SallaProductAvailability {
16
16
  * is current user already subscribed
17
17
  */
18
18
  this.isSubscribed = false;
19
+ this.handleSubmitOptions = async () => {
20
+ let payload = { id: this.productId };
21
+ if (!this.notifyOptionsAvailability) {
22
+ return payload;
23
+ }
24
+ let optionsElement = document.querySelector(`salla-product-options[product-id="${this.productId}"]`);
25
+ let options = Object.values(await (optionsElement === null || optionsElement === void 0 ? void 0 : optionsElement.getSelectedOptionsData()) || {});
26
+ //if all options not selected, show message && throw exception
27
+ if (options.length && !await (optionsElement === null || optionsElement === void 0 ? void 0 : optionsElement.reportValidity())) {
28
+ let errorMessage = salla.lang.get('common.messages.required_fields');
29
+ salla.error(errorMessage);
30
+ throw errorMessage;
31
+ }
32
+ payload.options = [];
33
+ options.forEach(option => {
34
+ //inject numbers only, without zeros
35
+ if (option && !isNaN(option)) {
36
+ payload.options.push(Number(option));
37
+ }
38
+ });
39
+ return payload;
40
+ };
19
41
  // helpers
20
- this.typing = (e, submitMethod) => {
42
+ this.typing = (e) => {
21
43
  const error = e.target.nextElementSibling;
22
44
  e.target.classList.remove('s-has-error');
23
45
  (error === null || error === void 0 ? void 0 : error.classList.contains('s-product-availability-error-msg')) && (error.innerText = '');
24
- e.key == 'Enter' && submitMethod();
46
+ e.keyCode === 13 && this.submit();
25
47
  };
26
48
  salla.lang.onLoaded(() => {
27
49
  var _a;
@@ -43,28 +65,6 @@ export class SallaProductAvailability {
43
65
  channelsWatcher(newValue) {
44
66
  this.channels_ = !!newValue ? newValue.split(',') : [];
45
67
  }
46
- async handleSubmitOptions() {
47
- let payload = { id: this.productId };
48
- if (!this.notifyOptionsAvailability) {
49
- return payload;
50
- }
51
- let optionsElement = document.querySelector(`salla-product-options[product-id="${this.productId}"]`);
52
- let options = Object.values(await (optionsElement === null || optionsElement === void 0 ? void 0 : optionsElement.getSelectedOptionsData()) || {});
53
- //if all options not selected, show message && throw exception
54
- if (options.length && !await (optionsElement === null || optionsElement === void 0 ? void 0 : optionsElement.reportValidity())) {
55
- let errorMessage = salla.lang.get('common.messages.required_fields');
56
- salla.error(errorMessage);
57
- throw errorMessage;
58
- }
59
- payload.options = [];
60
- options.forEach(option => {
61
- //inject numbers only, without zeros
62
- if (option && !isNaN(option)) {
63
- payload.options.push(Number(option));
64
- }
65
- });
66
- return payload;
67
- }
68
68
  openModel() {
69
69
  this.handleSubmitOptions().then(isSuccess => isSuccess ? this.modal.open() : null);
70
70
  }
@@ -87,9 +87,23 @@ export class SallaProductAvailability {
87
87
  .then(() => this.btn.disable())
88
88
  .then(() => salla.api.product.availabilitySubscribe(payload))
89
89
  .then(() => {
90
+ if (!this.notifyOptionsAvailability) {
91
+ salla.storage.set(`product-${this.productId}-subscribed`, true);
92
+ return;
93
+ }
94
+ if (payload.options.length) {
95
+ let options = salla.storage.get(`product-${this.productId}-subscribed-options`) || [];
96
+ let selectedOptionsString = payload.options.join(',');
97
+ if (!options.includes(selectedOptionsString)) {
98
+ options.push(selectedOptionsString);
99
+ salla.storage.set(`product-${this.productId}-subscribed-options`, options);
100
+ }
101
+ else {
102
+ salla.log('already subscribed to this options');
103
+ }
104
+ }
90
105
  this.isSubscribed = true;
91
- salla.storage.set(`product-${this.productId}-subscribed`, true);
92
- }) //no need to wait until finishing alert animation
106
+ })
93
107
  .then(() => this.btn.stop())
94
108
  .then(() => this.modal.close())
95
109
  .catch(() => this.btn.stop() && this.btn.enable());
@@ -132,12 +146,12 @@ export class SallaProductAvailability {
132
146
  h("div", { class: "s-product-availability-body" },
133
147
  this.channels_.includes('email') ? [
134
148
  h("label", { class: "s-product-availability-label" }, salla.lang.get('common.elements.email')),
135
- h("input", { class: "s-product-availability-input", onKeyDown: e => this.typing(e, this.submit), placeholder: salla.lang.get('common.elements.email_placeholder') || 'your@email.com', ref: el => this.email = el, type: "email" }),
149
+ h("input", { class: "s-product-availability-input", onKeyDown: e => this.typing(e), placeholder: salla.lang.get('common.elements.email_placeholder') || 'your@email.com', ref: el => this.email = el, type: "email" }),
136
150
  h("span", { class: "s-product-availability-error-msg" })
137
151
  ] : '',
138
152
  this.channels_.includes('sms') ? [
139
153
  h("label", { class: "s-product-availability-label" }, salla.lang.get('common.elements.mobile')),
140
- h("salla-tel-input", { ref: el => this.mobileInput = el, onKeyDown: e => this.typing(e, this.submit) })
154
+ h("salla-tel-input", { ref: el => this.mobileInput = el, onKeyDown: e => this.typing(e) })
141
155
  ] : ''),
142
156
  h("div", { slot: "footer", class: "s-product-availability-footer" },
143
157
  h("salla-button", { class: "modal-cancel-btn", width: "wide", color: "light", fill: "outline", onClick: () => this.modal.close() }, salla.lang.get('common.elements.cancel')),
@@ -68,7 +68,7 @@ export class SallaProductOptions {
68
68
  return selectedOptions;
69
69
  }
70
70
  /**
71
- * Get the id's of the selected options.
71
+ * Report options form validity.
72
72
  * */
73
73
  async reportValidity() {
74
74
  let requiredElements = this.host.querySelectorAll('[required]');
@@ -441,7 +441,7 @@ export class SallaProductOptions {
441
441
  "return": "Promise<boolean>"
442
442
  },
443
443
  "docs": {
444
- "text": "Get the id's of the selected options.",
444
+ "text": "Report options form validity.",
445
445
  "tags": []
446
446
  }
447
447
  },
@@ -93,10 +93,10 @@ const SallaAddProductButton$1 = /*@__PURE__*/ proxyCustomElement(class extends H
93
93
  return '';
94
94
  }
95
95
  if (this.hasSubscribedOptions) {
96
- return h(Host, null, h("salla-product-availability", Object.assign({}, this.getBtnAttributes(), { "is-subscribed": true })));
96
+ return h(Host, null, h("salla-product-availability", Object.assign({}, this.getBtnAttributes(), { "is-subscribed": true }), h("span", { class: "s-hidden" }, h("slot", null))));
97
97
  }
98
98
  if ((this.productStatus === 'out-and-notify' && this.channels) || this.hasOutOfStockOption) {
99
- return h(Host, null, h("salla-product-availability", Object.assign({}, this.getBtnAttributes())));
99
+ return h(Host, null, h("salla-product-availability", Object.assign({}, this.getBtnAttributes()), h("span", { class: "s-hidden" }, h("slot", null))));
100
100
  }
101
101
  return h(Host, null, h("salla-button", Object.assign({ color: this.productStatus === 'sale' ? 'primary' : 'light', type: "button", fill: this.productStatus === 'sale' ? 'solid' : 'outline', ref: el => this.btn = el, onClick: event => this.addProductToCart(event), disabled: this.productStatus !== 'sale' }, this.getBtnAttributes(), { "loader-position": "center" }), h("slot", null)));
102
102
  }
@@ -105,19 +105,20 @@ const SallaAddProductButton$1 = /*@__PURE__*/ proxyCustomElement(class extends H
105
105
  return;
106
106
  }
107
107
  salla.event.on('product-options::change', async (data) => {
108
- var _a;
108
+ var _a, _b;
109
109
  if (!['thumbnail', 'color', 'single-option'].includes(data.option.type)) {
110
110
  return;
111
111
  }
112
- this.hasOutOfStockOption = await ((_a = document.querySelector(`salla-product-options[product-id="${this.productId}"]`)) === null || _a === void 0 ? void 0 : _a.hasOutOfStockOption());
112
+ this.hasSubscribedOptions = false;
113
113
  this.hasLabel = false;
114
- if (!this.subscribedOptions || this.subscribedOptions === 'null') {
114
+ this.selectedOptions = await ((_a = document.querySelector(`salla-product-options[product-id="${this.productId}"]`)) === null || _a === void 0 ? void 0 : _a.getSelectedOptions());
115
+ this.hasOutOfStockOption = await ((_b = document.querySelector(`salla-product-options[product-id="${this.productId}"]`)) === null || _b === void 0 ? void 0 : _b.hasOutOfStockOption());
116
+ let subscribedDetails = salla.storage.get(`product-${this.productId}-subscribed-options`);
117
+ if (!subscribedDetails && !this.subscribedOptions || !this.hasOutOfStockOption) {
115
118
  return;
116
119
  }
117
- //check if subscribedOptions are the selected now
118
- this.hasSubscribedOptions = JSON.parse(this.subscribedOptions)
119
- .filter(ids => ids.every(id => this.selectedOptions.some(option => option.id === id)))
120
- .length > 0;
120
+ const parsedSubscribedDetails = subscribedDetails ? subscribedDetails.map(ids => ids.split(',').map(id => parseInt(id))) : [];
121
+ this.hasSubscribedOptions = parsedSubscribedDetails.length > 0 && parsedSubscribedDetails.some(ids => ids.every(id => this.selectedOptions.some(option => option.id === id)));
121
122
  });
122
123
  }
123
124
  componentDidRender() {
@@ -25,12 +25,34 @@ const SallaProductAvailability = /*@__PURE__*/ proxyCustomElement(class extends
25
25
  * is current user already subscribed
26
26
  */
27
27
  this.isSubscribed = false;
28
+ this.handleSubmitOptions = async () => {
29
+ let payload = { id: this.productId };
30
+ if (!this.notifyOptionsAvailability) {
31
+ return payload;
32
+ }
33
+ let optionsElement = document.querySelector(`salla-product-options[product-id="${this.productId}"]`);
34
+ let options = Object.values(await (optionsElement === null || optionsElement === void 0 ? void 0 : optionsElement.getSelectedOptionsData()) || {});
35
+ //if all options not selected, show message && throw exception
36
+ if (options.length && !await (optionsElement === null || optionsElement === void 0 ? void 0 : optionsElement.reportValidity())) {
37
+ let errorMessage = salla.lang.get('common.messages.required_fields');
38
+ salla.error(errorMessage);
39
+ throw errorMessage;
40
+ }
41
+ payload.options = [];
42
+ options.forEach(option => {
43
+ //inject numbers only, without zeros
44
+ if (option && !isNaN(option)) {
45
+ payload.options.push(Number(option));
46
+ }
47
+ });
48
+ return payload;
49
+ };
28
50
  // helpers
29
- this.typing = (e, submitMethod) => {
51
+ this.typing = (e) => {
30
52
  const error = e.target.nextElementSibling;
31
53
  e.target.classList.remove('s-has-error');
32
54
  (error === null || error === void 0 ? void 0 : error.classList.contains('s-product-availability-error-msg')) && (error.innerText = '');
33
- e.key == 'Enter' && submitMethod();
55
+ e.keyCode === 13 && this.submit();
34
56
  };
35
57
  salla.lang.onLoaded(() => {
36
58
  var _a;
@@ -52,28 +74,6 @@ const SallaProductAvailability = /*@__PURE__*/ proxyCustomElement(class extends
52
74
  channelsWatcher(newValue) {
53
75
  this.channels_ = !!newValue ? newValue.split(',') : [];
54
76
  }
55
- async handleSubmitOptions() {
56
- let payload = { id: this.productId };
57
- if (!this.notifyOptionsAvailability) {
58
- return payload;
59
- }
60
- let optionsElement = document.querySelector(`salla-product-options[product-id="${this.productId}"]`);
61
- let options = Object.values(await (optionsElement === null || optionsElement === void 0 ? void 0 : optionsElement.getSelectedOptionsData()) || {});
62
- //if all options not selected, show message && throw exception
63
- if (options.length && !await (optionsElement === null || optionsElement === void 0 ? void 0 : optionsElement.reportValidity())) {
64
- let errorMessage = salla.lang.get('common.messages.required_fields');
65
- salla.error(errorMessage);
66
- throw errorMessage;
67
- }
68
- payload.options = [];
69
- options.forEach(option => {
70
- //inject numbers only, without zeros
71
- if (option && !isNaN(option)) {
72
- payload.options.push(Number(option));
73
- }
74
- });
75
- return payload;
76
- }
77
77
  openModel() {
78
78
  this.handleSubmitOptions().then(isSuccess => isSuccess ? this.modal.open() : null);
79
79
  }
@@ -96,9 +96,23 @@ const SallaProductAvailability = /*@__PURE__*/ proxyCustomElement(class extends
96
96
  .then(() => this.btn.disable())
97
97
  .then(() => salla.api.product.availabilitySubscribe(payload))
98
98
  .then(() => {
99
+ if (!this.notifyOptionsAvailability) {
100
+ salla.storage.set(`product-${this.productId}-subscribed`, true);
101
+ return;
102
+ }
103
+ if (payload.options.length) {
104
+ let options = salla.storage.get(`product-${this.productId}-subscribed-options`) || [];
105
+ let selectedOptionsString = payload.options.join(',');
106
+ if (!options.includes(selectedOptionsString)) {
107
+ options.push(selectedOptionsString);
108
+ salla.storage.set(`product-${this.productId}-subscribed-options`, options);
109
+ }
110
+ else {
111
+ salla.log('already subscribed to this options');
112
+ }
113
+ }
99
114
  this.isSubscribed = true;
100
- salla.storage.set(`product-${this.productId}-subscribed`, true);
101
- }) //no need to wait until finishing alert animation
115
+ })
102
116
  .then(() => this.btn.stop())
103
117
  .then(() => this.modal.close())
104
118
  .catch(() => this.btn.stop() && this.btn.enable());
@@ -134,11 +148,11 @@ const SallaProductAvailability = /*@__PURE__*/ proxyCustomElement(class extends
134
148
  renderModal() {
135
149
  return (h("salla-modal", { ref: modal => this.modal = modal, "modal-title": this.title_, subTitle: salla.lang.get('pages.products.notify_availability_subtitle'), width: "sm" }, h("span", { slot: 'icon', class: "s-product-availability-header-icon", innerHTML: BellRing }), h("div", { class: "s-product-availability-body" }, this.channels_.includes('email') ? [
136
150
  h("label", { class: "s-product-availability-label" }, salla.lang.get('common.elements.email')),
137
- h("input", { class: "s-product-availability-input", onKeyDown: e => this.typing(e, this.submit), placeholder: salla.lang.get('common.elements.email_placeholder') || 'your@email.com', ref: el => this.email = el, type: "email" }),
151
+ h("input", { class: "s-product-availability-input", onKeyDown: e => this.typing(e), placeholder: salla.lang.get('common.elements.email_placeholder') || 'your@email.com', ref: el => this.email = el, type: "email" }),
138
152
  h("span", { class: "s-product-availability-error-msg" })
139
153
  ] : '', this.channels_.includes('sms') ? [
140
154
  h("label", { class: "s-product-availability-label" }, salla.lang.get('common.elements.mobile')),
141
- h("salla-tel-input", { ref: el => this.mobileInput = el, onKeyDown: e => this.typing(e, this.submit) })
155
+ h("salla-tel-input", { ref: el => this.mobileInput = el, onKeyDown: e => this.typing(e) })
142
156
  ] : ''), h("div", { slot: "footer", class: "s-product-availability-footer" }, h("salla-button", { class: "modal-cancel-btn", width: "wide", color: "light", fill: "outline", onClick: () => this.modal.close() }, salla.lang.get('common.elements.cancel')), h("salla-button", { class: "submit-btn", "loader-position": 'center', width: "wide", ref: btn => this.btn = btn, onClick: () => this.submit() }, salla.lang.get('common.elements.submit')))));
143
157
  }
144
158
  get host() { return this; }
@@ -120,7 +120,7 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class extends HTM
120
120
  return selectedOptions;
121
121
  }
122
122
  /**
123
- * Get the id's of the selected options.
123
+ * Report options form validity.
124
124
  * */
125
125
  async reportValidity() {
126
126
  let requiredElements = this.host.querySelectorAll('[required]');
@@ -87,10 +87,10 @@ const SallaAddProductButton = class {
87
87
  return '';
88
88
  }
89
89
  if (this.hasSubscribedOptions) {
90
- return h(Host, null, h("salla-product-availability", Object.assign({}, this.getBtnAttributes(), { "is-subscribed": true })));
90
+ return h(Host, null, h("salla-product-availability", Object.assign({}, this.getBtnAttributes(), { "is-subscribed": true }), h("span", { class: "s-hidden" }, h("slot", null))));
91
91
  }
92
92
  if ((this.productStatus === 'out-and-notify' && this.channels) || this.hasOutOfStockOption) {
93
- return h(Host, null, h("salla-product-availability", Object.assign({}, this.getBtnAttributes())));
93
+ return h(Host, null, h("salla-product-availability", Object.assign({}, this.getBtnAttributes()), h("span", { class: "s-hidden" }, h("slot", null))));
94
94
  }
95
95
  return h(Host, null, h("salla-button", Object.assign({ color: this.productStatus === 'sale' ? 'primary' : 'light', type: "button", fill: this.productStatus === 'sale' ? 'solid' : 'outline', ref: el => this.btn = el, onClick: event => this.addProductToCart(event), disabled: this.productStatus !== 'sale' }, this.getBtnAttributes(), { "loader-position": "center" }), h("slot", null)));
96
96
  }
@@ -99,19 +99,20 @@ const SallaAddProductButton = class {
99
99
  return;
100
100
  }
101
101
  salla.event.on('product-options::change', async (data) => {
102
- var _a;
102
+ var _a, _b;
103
103
  if (!['thumbnail', 'color', 'single-option'].includes(data.option.type)) {
104
104
  return;
105
105
  }
106
- this.hasOutOfStockOption = await ((_a = document.querySelector(`salla-product-options[product-id="${this.productId}"]`)) === null || _a === void 0 ? void 0 : _a.hasOutOfStockOption());
106
+ this.hasSubscribedOptions = false;
107
107
  this.hasLabel = false;
108
- if (!this.subscribedOptions || this.subscribedOptions === 'null') {
108
+ this.selectedOptions = await ((_a = document.querySelector(`salla-product-options[product-id="${this.productId}"]`)) === null || _a === void 0 ? void 0 : _a.getSelectedOptions());
109
+ this.hasOutOfStockOption = await ((_b = document.querySelector(`salla-product-options[product-id="${this.productId}"]`)) === null || _b === void 0 ? void 0 : _b.hasOutOfStockOption());
110
+ let subscribedDetails = salla.storage.get(`product-${this.productId}-subscribed-options`);
111
+ if (!subscribedDetails && !this.subscribedOptions || !this.hasOutOfStockOption) {
109
112
  return;
110
113
  }
111
- //check if subscribedOptions are the selected now
112
- this.hasSubscribedOptions = JSON.parse(this.subscribedOptions)
113
- .filter(ids => ids.every(id => this.selectedOptions.some(option => option.id === id)))
114
- .length > 0;
114
+ const parsedSubscribedDetails = subscribedDetails ? subscribedDetails.map(ids => ids.split(',').map(id => parseInt(id))) : [];
115
+ this.hasSubscribedOptions = parsedSubscribedDetails.length > 0 && parsedSubscribedDetails.some(ids => ids.every(id => this.selectedOptions.some(option => option.id === id)));
115
116
  });
116
117
  }
117
118
  componentDidRender() {
@@ -23245,12 +23245,34 @@ const SallaProductAvailability = class {
23245
23245
  * is current user already subscribed
23246
23246
  */
23247
23247
  this.isSubscribed = false;
23248
+ this.handleSubmitOptions = async () => {
23249
+ let payload = { id: this.productId };
23250
+ if (!this.notifyOptionsAvailability) {
23251
+ return payload;
23252
+ }
23253
+ let optionsElement = document.querySelector(`salla-product-options[product-id="${this.productId}"]`);
23254
+ let options = Object.values(await (optionsElement === null || optionsElement === void 0 ? void 0 : optionsElement.getSelectedOptionsData()) || {});
23255
+ //if all options not selected, show message && throw exception
23256
+ if (options.length && !await (optionsElement === null || optionsElement === void 0 ? void 0 : optionsElement.reportValidity())) {
23257
+ let errorMessage = salla.lang.get('common.messages.required_fields');
23258
+ salla.error(errorMessage);
23259
+ throw errorMessage;
23260
+ }
23261
+ payload.options = [];
23262
+ options.forEach(option => {
23263
+ //inject numbers only, without zeros
23264
+ if (option && !isNaN(option)) {
23265
+ payload.options.push(Number(option));
23266
+ }
23267
+ });
23268
+ return payload;
23269
+ };
23248
23270
  // helpers
23249
- this.typing = (e, submitMethod) => {
23271
+ this.typing = (e) => {
23250
23272
  const error = e.target.nextElementSibling;
23251
23273
  e.target.classList.remove('s-has-error');
23252
23274
  (error === null || error === void 0 ? void 0 : error.classList.contains('s-product-availability-error-msg')) && (error.innerText = '');
23253
- e.key == 'Enter' && submitMethod();
23275
+ e.keyCode === 13 && this.submit();
23254
23276
  };
23255
23277
  salla.lang.onLoaded(() => {
23256
23278
  var _a;
@@ -23272,28 +23294,6 @@ const SallaProductAvailability = class {
23272
23294
  channelsWatcher(newValue) {
23273
23295
  this.channels_ = !!newValue ? newValue.split(',') : [];
23274
23296
  }
23275
- async handleSubmitOptions() {
23276
- let payload = { id: this.productId };
23277
- if (!this.notifyOptionsAvailability) {
23278
- return payload;
23279
- }
23280
- let optionsElement = document.querySelector(`salla-product-options[product-id="${this.productId}"]`);
23281
- let options = Object.values(await (optionsElement === null || optionsElement === void 0 ? void 0 : optionsElement.getSelectedOptionsData()) || {});
23282
- //if all options not selected, show message && throw exception
23283
- if (options.length && !await (optionsElement === null || optionsElement === void 0 ? void 0 : optionsElement.reportValidity())) {
23284
- let errorMessage = salla.lang.get('common.messages.required_fields');
23285
- salla.error(errorMessage);
23286
- throw errorMessage;
23287
- }
23288
- payload.options = [];
23289
- options.forEach(option => {
23290
- //inject numbers only, without zeros
23291
- if (option && !isNaN(option)) {
23292
- payload.options.push(Number(option));
23293
- }
23294
- });
23295
- return payload;
23296
- }
23297
23297
  openModel() {
23298
23298
  this.handleSubmitOptions().then(isSuccess => isSuccess ? this.modal.open() : null);
23299
23299
  }
@@ -23316,9 +23316,23 @@ const SallaProductAvailability = class {
23316
23316
  .then(() => this.btn.disable())
23317
23317
  .then(() => salla.api.product.availabilitySubscribe(payload))
23318
23318
  .then(() => {
23319
+ if (!this.notifyOptionsAvailability) {
23320
+ salla.storage.set(`product-${this.productId}-subscribed`, true);
23321
+ return;
23322
+ }
23323
+ if (payload.options.length) {
23324
+ let options = salla.storage.get(`product-${this.productId}-subscribed-options`) || [];
23325
+ let selectedOptionsString = payload.options.join(',');
23326
+ if (!options.includes(selectedOptionsString)) {
23327
+ options.push(selectedOptionsString);
23328
+ salla.storage.set(`product-${this.productId}-subscribed-options`, options);
23329
+ }
23330
+ else {
23331
+ salla.log('already subscribed to this options');
23332
+ }
23333
+ }
23319
23334
  this.isSubscribed = true;
23320
- salla.storage.set(`product-${this.productId}-subscribed`, true);
23321
- }) //no need to wait until finishing alert animation
23335
+ })
23322
23336
  .then(() => this.btn.stop())
23323
23337
  .then(() => this.modal.close())
23324
23338
  .catch(() => this.btn.stop() && this.btn.enable());
@@ -23354,11 +23368,11 @@ const SallaProductAvailability = class {
23354
23368
  renderModal() {
23355
23369
  return (h("salla-modal", { ref: modal => this.modal = modal, "modal-title": this.title_, subTitle: salla.lang.get('pages.products.notify_availability_subtitle'), width: "sm" }, h("span", { slot: 'icon', class: "s-product-availability-header-icon", innerHTML: BellRing }), h("div", { class: "s-product-availability-body" }, this.channels_.includes('email') ? [
23356
23370
  h("label", { class: "s-product-availability-label" }, salla.lang.get('common.elements.email')),
23357
- h("input", { class: "s-product-availability-input", onKeyDown: e => this.typing(e, this.submit), placeholder: salla.lang.get('common.elements.email_placeholder') || 'your@email.com', ref: el => this.email = el, type: "email" }),
23371
+ h("input", { class: "s-product-availability-input", onKeyDown: e => this.typing(e), placeholder: salla.lang.get('common.elements.email_placeholder') || 'your@email.com', ref: el => this.email = el, type: "email" }),
23358
23372
  h("span", { class: "s-product-availability-error-msg" })
23359
23373
  ] : '', this.channels_.includes('sms') ? [
23360
23374
  h("label", { class: "s-product-availability-label" }, salla.lang.get('common.elements.mobile')),
23361
- h("salla-tel-input", { ref: el => this.mobileInput = el, onKeyDown: e => this.typing(e, this.submit) })
23375
+ h("salla-tel-input", { ref: el => this.mobileInput = el, onKeyDown: e => this.typing(e) })
23362
23376
  ] : ''), h("div", { slot: "footer", class: "s-product-availability-footer" }, h("salla-button", { class: "modal-cancel-btn", width: "wide", color: "light", fill: "outline", onClick: () => this.modal.close() }, salla.lang.get('common.elements.cancel')), h("salla-button", { class: "submit-btn", "loader-position": 'center', width: "wide", ref: btn => this.btn = btn, onClick: () => this.submit() }, salla.lang.get('common.elements.submit')))));
23363
23377
  }
23364
23378
  get host() { return getElement(this); }