@salla.sa/twilight-components 1.0.100 → 1.0.107

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 (109) hide show
  1. package/README.md +8 -1
  2. package/dist/cjs/{index-3771e52a.js → index-b4140db0.js} +18 -11
  3. package/dist/cjs/loader.cjs.js +3 -3
  4. package/dist/cjs/salla-add-product-button.cjs.entry.js +85 -0
  5. package/dist/cjs/{salla-add-product-button_6.cjs.entry.js → salla-branches_13.cjs.entry.js} +1015 -80
  6. package/dist/cjs/salla-conditional-fields.cjs.entry.js +4 -2
  7. package/dist/cjs/salla-installment.cjs.entry.js +1 -1
  8. package/dist/cjs/salla-quantity-input.cjs.entry.js +2 -2
  9. package/dist/cjs/twilight-components.cjs.js +3 -3
  10. package/dist/collection/collection-manifest.json +1 -1
  11. package/dist/collection/components/salla-add-product-button/salla-add-product-button.js +13 -28
  12. package/dist/collection/components/salla-branches/salla-branches.css +0 -3
  13. package/dist/collection/components/salla-branches/salla-branches.js +9 -5
  14. package/dist/collection/components/salla-button/salla-button.css +0 -3
  15. package/dist/collection/components/salla-conditional-fields/salla-conditional-fields.js +3 -1
  16. package/dist/collection/components/salla-infinite-scroll/salla-infinite-scroll.css +0 -3
  17. package/dist/collection/components/salla-installment/salla-installment.css +0 -3
  18. package/dist/collection/components/salla-localization-modal/salla-localization-modal.css +2 -5
  19. package/dist/collection/components/salla-localization-modal/salla-localization-modal.js +3 -2
  20. package/dist/collection/components/salla-login-modal/salla-login-modal.css +0 -3
  21. package/dist/collection/components/salla-login-modal/salla-login-modal.js +16 -5
  22. package/dist/collection/components/salla-modal/salla-modal.css +0 -3
  23. package/dist/collection/components/salla-modal/salla-modal.js +12 -11
  24. package/dist/collection/components/salla-offer-modal/salla-offer-modal.css +0 -3
  25. package/dist/collection/components/salla-offer-modal/salla-offer-modal.js +1 -0
  26. package/dist/collection/components/salla-product-availability/salla-product-availability.css +0 -3
  27. package/dist/collection/components/salla-product-availability/salla-product-availability.js +18 -13
  28. package/dist/collection/components/salla-quantity-input/salla-quantity-input.css +0 -3
  29. package/dist/collection/components/salla-quantity-input/salla-quantity-input.js +2 -2
  30. package/dist/collection/components/salla-rating-modal/salla-rating-modal.css +0 -3
  31. package/dist/collection/components/salla-rating-stars/salla-rating-stars.css +0 -3
  32. package/dist/collection/components/salla-search/salla-search.css +0 -3
  33. package/dist/collection/components/salla-tel-input/salla-tel-input.css +2 -5
  34. package/dist/collection/components/salla-verify/salla-verify.css +0 -3
  35. package/dist/collection/global/app.js +23 -0
  36. package/dist/collection/plugins/tailwind-theme/index.js +3 -4
  37. package/dist/components/index.d.ts +17 -5
  38. package/dist/components/index.js +17 -0
  39. package/dist/components/salla-add-product-button.js +14 -12
  40. package/dist/components/salla-branches.js +8 -4
  41. package/dist/components/salla-conditional-fields.js +3 -1
  42. package/dist/components/salla-localization-modal.js +4 -3
  43. package/dist/components/salla-login-modal.js +11 -3
  44. package/dist/components/salla-modal2.js +6 -6
  45. package/dist/components/salla-offer-modal.js +1 -0
  46. package/dist/components/salla-product-availability2.js +17 -12
  47. package/dist/components/salla-quantity-input.js +1 -1
  48. package/dist/components/salla-tel-input2.js +3 -3
  49. package/dist/esm/{index-ee729716.js → index-20b84fd0.js} +18 -11
  50. package/dist/esm/loader.js +3 -3
  51. package/dist/esm/polyfills/css-shim.js +1 -1
  52. package/dist/esm/salla-add-product-button.entry.js +81 -0
  53. package/dist/esm/{salla-add-product-button_6.entry.js → salla-branches_13.entry.js} +1008 -80
  54. package/dist/esm/salla-conditional-fields.entry.js +4 -2
  55. package/dist/esm/salla-installment.entry.js +1 -1
  56. package/dist/esm/salla-quantity-input.entry.js +2 -2
  57. package/dist/esm/twilight-components.js +3 -3
  58. package/dist/twilight-components/{p-f0f7a51b.entry.js → p-15fac4f2.entry.js} +1 -1
  59. package/dist/twilight-components/p-27d01075.entry.js +4 -0
  60. package/dist/twilight-components/{p-9a75d4ec.entry.js → p-5ee94c9e.entry.js} +1 -1
  61. package/dist/twilight-components/p-6f4f4260.entry.js +4 -0
  62. package/dist/twilight-components/p-7b5b8647.entry.js +4 -0
  63. package/dist/twilight-components/p-c2bef5f2.js +5 -0
  64. package/dist/twilight-components/twilight-components.esm.js +1 -1
  65. package/dist/types/components/salla-add-product-button/salla-add-product-button.d.ts +1 -2
  66. package/dist/types/components/salla-login-modal/salla-login-modal.d.ts +1 -1
  67. package/dist/types/components.d.ts +17 -13
  68. package/dist/types/global/app.d.ts +3 -0
  69. package/example/assets/tailwind.css +3938 -3
  70. package/example/assets/translations.js +4981 -0
  71. package/example/index.html +177 -155
  72. package/package.json +17 -14
  73. package/dist/cjs/salla-branches.cjs.entry.js +0 -94
  74. package/dist/cjs/salla-infinite-scroll.cjs.entry.js +0 -93
  75. package/dist/cjs/salla-localization-modal.cjs.entry.js +0 -120
  76. package/dist/cjs/salla-login-modal.cjs.entry.js +0 -196
  77. package/dist/cjs/salla-offer-modal.cjs.entry.js +0 -144
  78. package/dist/cjs/salla-rating-modal.cjs.entry.js +0 -177
  79. package/dist/cjs/salla-rating-stars.cjs.entry.js +0 -76
  80. package/dist/cjs/salla-verify.cjs.entry.js +0 -168
  81. package/dist/esm/salla-branches.entry.js +0 -90
  82. package/dist/esm/salla-infinite-scroll.entry.js +0 -89
  83. package/dist/esm/salla-localization-modal.entry.js +0 -116
  84. package/dist/esm/salla-login-modal.entry.js +0 -192
  85. package/dist/esm/salla-offer-modal.entry.js +0 -140
  86. package/dist/esm/salla-rating-modal.entry.js +0 -173
  87. package/dist/esm/salla-rating-stars.entry.js +0 -72
  88. package/dist/esm/salla-verify.entry.js +0 -164
  89. package/dist/twilight-components/p-00c61851.entry.js +0 -4
  90. package/dist/twilight-components/p-058ae0f8.entry.js +0 -4
  91. package/dist/twilight-components/p-27530b47.entry.js +0 -4
  92. package/dist/twilight-components/p-3f90fa16.entry.js +0 -4
  93. package/dist/twilight-components/p-5c1d4ef9.entry.js +0 -4
  94. package/dist/twilight-components/p-714ff288.entry.js +0 -4
  95. package/dist/twilight-components/p-77af5fef.entry.js +0 -4
  96. package/dist/twilight-components/p-a268e672.entry.js +0 -4
  97. package/dist/twilight-components/p-d566f357.js +0 -4
  98. package/dist/twilight-components/p-df7417e4.entry.js +0 -4
  99. package/dist/twilight-components/p-e97c00e1.entry.js +0 -4
  100. package/example/.DS_Store +0 -0
  101. package/example/.gitignore +0 -2
  102. package/example/dist/.DS_Store +0 -0
  103. package/example/dist/demo.js +0 -153
  104. package/example/dist/flags.png +0 -0
  105. package/example/dist/flags@2x.png +0 -0
  106. package/example/dist/intlTelInput.min.css +0 -1
  107. package/example/dist/tailwind.css +0 -3856
  108. package/example/dist/translations.js +0 -1
  109. package/example/dist/twilight.js +0 -437
package/README.md CHANGED
@@ -52,4 +52,11 @@ todo :: finx the publish scripts
52
52
 
53
53
  ```
54
54
  node publish.js
55
- ```
55
+ ```
56
+
57
+ ## Deveplement
58
+
59
+ 1. make sure you are update the tailwind output everytime `npm run tailwind`
60
+ 1. Everytime you change the utilities json you should run this command to update the output of tailwind css (TODO :: make it automatic with watch command)
61
+ 2. Change the store settings in `src/global/app.ts`
62
+ 3. Run watch `npm run watch`
@@ -45,10 +45,10 @@ const plt = {
45
45
  };
46
46
  const supportsShadow = true;
47
47
  const promiseResolve = (v) => Promise.resolve(v);
48
- const supportsConstructibleStylesheets = /*@__PURE__*/ (() => {
48
+ const supportsConstructableStylesheets = /*@__PURE__*/ (() => {
49
49
  try {
50
50
  new CSSStyleSheet();
51
- return typeof new CSSStyleSheet().replace === 'function';
51
+ return typeof new CSSStyleSheet().replaceSync === 'function';
52
52
  }
53
53
  catch (e) { }
54
54
  return false;
@@ -114,9 +114,14 @@ const uniqueTime = (key, measureText) => {
114
114
  const rootAppliedStyles = new WeakMap();
115
115
  const registerStyle = (scopeId, cssText, allowCS) => {
116
116
  let style = styles.get(scopeId);
117
- if (supportsConstructibleStylesheets && allowCS) {
117
+ if (supportsConstructableStylesheets && allowCS) {
118
118
  style = (style || new CSSStyleSheet());
119
- style.replace(cssText);
119
+ if (typeof style === 'string') {
120
+ style = cssText;
121
+ }
122
+ else {
123
+ style.replaceSync(cssText);
124
+ }
120
125
  }
121
126
  else {
122
127
  style = cssText;
@@ -125,7 +130,7 @@ const registerStyle = (scopeId, cssText, allowCS) => {
125
130
  };
126
131
  const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
127
132
  let scopeId = getScopeId(cmpMeta);
128
- let style = styles.get(scopeId);
133
+ const style = styles.get(scopeId);
129
134
  // if an element is NOT connected then getRootNode() will return the wrong root node
130
135
  // so the fallback is to always use the document for the root node in those cases
131
136
  styleContainerNode = styleContainerNode.nodeType === 11 /* DocumentFragment */ ? styleContainerNode : doc;
@@ -199,7 +204,7 @@ const h = (nodeName, vnodeData, ...children) => {
199
204
  let slotName = null;
200
205
  let simple = false;
201
206
  let lastSimple = false;
202
- let vNodeChildren = [];
207
+ const vNodeChildren = [];
203
208
  const walk = (c) => {
204
209
  for (let i = 0; i < c.length; i++) {
205
210
  child = c[i];
@@ -374,7 +379,7 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
374
379
  if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
375
380
  try {
376
381
  if (!elm.tagName.includes('-')) {
377
- let n = newValue == null ? '' : newValue;
382
+ const n = newValue == null ? '' : newValue;
378
383
  // Workaround for Safari, moving the <input> caret when re-assigning the same valued
379
384
  if (memberName === 'list') {
380
385
  isProp = false;
@@ -451,7 +456,7 @@ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
451
456
  };
452
457
  const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
453
458
  // tslint:disable-next-line: prefer-const
454
- let newVNode = newParentVNode.$children$[childIndex];
459
+ const newVNode = newParentVNode.$children$[childIndex];
455
460
  let i = 0;
456
461
  let elm;
457
462
  let childNode;
@@ -747,7 +752,7 @@ const patch = (oldVNode, newVNode) => {
747
752
  };
748
753
  const updateFallbackSlotVisibility = (elm) => {
749
754
  // tslint:disable-next-line: prefer-const
750
- let childNodes = elm.childNodes;
755
+ const childNodes = elm.childNodes;
751
756
  let childNode;
752
757
  let i;
753
758
  let ilen;
@@ -800,8 +805,8 @@ const relocateSlotContent = (elm) => {
800
805
  let relocateNodeData;
801
806
  let j;
802
807
  let i = 0;
803
- let childNodes = elm.childNodes;
804
- let ilen = childNodes.length;
808
+ const childNodes = elm.childNodes;
809
+ const ilen = childNodes.length;
805
810
  for (; i < ilen; i++) {
806
811
  childNode = childNodes[i];
807
812
  if (childNode['s-sr'] && (node = childNode['s-cr']) && node.parentNode) {
@@ -1841,7 +1846,9 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
1841
1846
  if (module) {
1842
1847
  return module[exportName];
1843
1848
  }
1849
+ /*!__STENCIL_STATIC_IMPORT_SWITCH__*/
1844
1850
  return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(
1851
+ /* @vite-ignore */
1845
1852
  /* webpackInclude: /\.entry\.js$/ */
1846
1853
  /* webpackExclude: /\.system\.entry\.js$/ */
1847
1854
  /* webpackMode: "lazy" */
@@ -5,10 +5,10 @@
5
5
 
6
6
  Object.defineProperty(exports, '__esModule', { value: true });
7
7
 
8
- const index = require('./index-3771e52a.js');
8
+ const index = require('./index-b4140db0.js');
9
9
 
10
10
  /*
11
- Stencil Client Patch Esm v2.15.0 | MIT Licensed | https://stenciljs.com
11
+ Stencil Client Patch Esm v2.17.1 | MIT Licensed | https://stenciljs.com
12
12
  */
13
13
  const patchEsm = () => {
14
14
  return index.promiseResolve();
@@ -17,7 +17,7 @@ const patchEsm = () => {
17
17
  const defineCustomElements = (win, options) => {
18
18
  if (typeof window === 'undefined') return Promise.resolve();
19
19
  return patchEsm().then(() => {
20
- return index.bootstrapLazy([["salla-add-product-button_6.cjs",[[4,"salla-add-product-button",{"channels":[513],"quantity":[514],"donatingAmount":[514,"donating-amount"],"productId":[520,"product-id"],"productStatus":[513,"product-status"],"productType":[513,"product-type"],"disabled":[516]}],[0,"salla-search",{"inline":[4],"oval":[4],"height":[2],"results":[32],"placeholder":[32],"noResultsText":[32],"typing":[32],"debounce":[32],"search_term":[32]}],[0,"salla-product-availability",{"channels":[1],"productId":[2,"product-id"],"isSubscribed":[1028,"is-subscribed"],"subTitle":[32],"mobileLabel":[32],"emailLabel":[32],"emailPlaceholder":[32],"subscribedMessage":[32],"title_":[32],"emailErrorMsg":[32],"isVisitorSubscribed":[32]}],[0,"salla-tel-input",{"phone":[1025],"name":[1],"countryCode":[1025,"country-code"],"mobileRequired":[32],"countryCodeLabel":[32],"mobileLabel":[32],"tooShort":[32],"tooLong":[32],"invalidCountryCode":[32],"invalidNumber":[32],"errorMap":[32],"getValues":[64],"isValid":[64]}],[4,"salla-button",{"shape":[513],"color":[513],"fill":[513],"size":[513],"width":[513],"loading":[516],"disabled":[516],"loaderPosition":[1,"loader-position"],"href":[1],"load":[64],"stop":[64],"setText":[64],"disable":[64],"enable":[64]}],[4,"salla-modal",{"isClosable":[1028,"is-closable"],"width":[513],"position":[513],"visible":[516],"isLoading":[1540,"is-loading"],"subTitleFirst":[4,"sub-title-first"],"noPadding":[4,"no-padding"],"subTitle":[1,"sub-title"],"icon":[1],"iconStyle":[1,"icon-style"],"imageIcon":[1,"image-icon"],"modalTitle":[32],"open":[64],"close":[64],"setTitle":[64],"loading":[64],"stopLoading":[64]}]]],["salla-login-modal.cjs",[[4,"salla-login-modal",{"isEmailAllowed":[1028,"is-email-allowed"],"isMobileAllowed":[1028,"is-mobile-allowed"],"isEmailRequired":[1028,"is-email-required"],"title":[32],"loginTypeTitle":[32],"loginText":[32],"smsLabel":[32],"mobileLabel":[32],"emailLabel":[32],"enterText":[32],"bySMSText":[32],"byEmailText":[32],"emailErrorMsg":[32],"firstNameLabel":[32],"lastNameLabel":[32],"firstNameErrorMsg":[32],"lastNameErrorMsg":[32],"open":[64]},[[8,"verified","onVerified"]]]]],["salla-rating-modal.cjs",[[0,"salla-rating-modal",{"orderId":[2,"order-id"],"order":[32],"open":[64],"close":[64]}]]],["salla-branches.cjs",[[4,"salla-branches",{"position":[1],"displayAs":[1,"display-as"],"browseProductsFrom":[1,"browse-products-from"],"branches":[16],"current":[1026],"open":[32],"selected":[32],"isOpenedBefore":[32],"show":[64],"hide":[64]}]]],["salla-localization-modal.cjs",[[0,"salla-localization-modal",{"language":[1537],"currency":[1537],"languages":[32],"currencies":[32],"languagesTitle":[32],"currenciesTitle":[32],"isLoading":[32],"open":[64],"close":[64],"submit":[64]}]]],["salla-offer-modal.cjs",[[0,"salla-offer-modal",{"offer":[32],"offer_name":[32],"offer_message":[32],"offer_expires_in":[32],"remember_my_choice":[32],"add_to_cart":[32],"out_of_stock":[32],"open":[64],"showOffer":[64]}]]],["salla-conditional-fields.cjs",[[4,"salla-conditional-fields",null,[[0,"change","changeHandler"]]]]],["salla-infinite-scroll.cjs",[[4,"salla-infinite-scroll",{"nextPage":[1,"next-page"],"autoload":[1028],"container":[1],"item":[1],"loadMore":[32],"noMore":[32],"failedToLoad":[32]}]]],["salla-installment.cjs",[[0,"salla-installment",{"price":[1],"language":[1],"currency":[1],"tamaraIsActive":[32],"tabbyIsActive":[32],"spotiiIsActive":[32]}]]],["salla-quantity-input.cjs",[[4,"salla-quantity-input",{"quantity":[32],"decrease":[64],"increase":[64],"setValue":[64]}]]],["salla-verify.cjs",[[4,"salla-verify",{"display":[1],"type":[1025],"autoReload":[4,"auto-reload"],"title":[32],"resendAfter":[32],"isProfileVerify":[32],"getCode":[64],"open":[64]}]]],["salla-rating-stars.cjs",[[0,"salla-rating-stars",{"name":[1],"size":[1],"value":[2]}]]]], options);
20
+ return index.bootstrapLazy([["salla-branches_13.cjs",[[4,"salla-login-modal",{"isEmailAllowed":[1028,"is-email-allowed"],"isMobileAllowed":[1028,"is-mobile-allowed"],"isEmailRequired":[1028,"is-email-required"],"title":[32],"loginTypeTitle":[32],"loginText":[32],"smsLabel":[32],"mobileLabel":[32],"emailLabel":[32],"enterText":[32],"bySMSText":[32],"byEmailText":[32],"emailErrorMsg":[32],"firstNameLabel":[32],"lastNameLabel":[32],"firstNameErrorMsg":[32],"lastNameErrorMsg":[32],"open":[64]},[[8,"verified","onVerified"]]],[0,"salla-rating-modal",{"orderId":[2,"order-id"],"order":[32],"open":[64],"close":[64]}],[4,"salla-branches",{"position":[1],"displayAs":[1,"display-as"],"browseProductsFrom":[1,"browse-products-from"],"branches":[16],"current":[1026],"open":[32],"selected":[32],"isOpenedBefore":[32],"show":[64],"hide":[64]}],[0,"salla-localization-modal",{"language":[1537],"currency":[1537],"languages":[32],"currencies":[32],"languagesTitle":[32],"currenciesTitle":[32],"isLoading":[32],"open":[64],"close":[64],"submit":[64]}],[0,"salla-offer-modal",{"offer":[32],"offer_name":[32],"offer_message":[32],"offer_expires_in":[32],"remember_my_choice":[32],"add_to_cart":[32],"out_of_stock":[32],"open":[64],"showOffer":[64]}],[0,"salla-search",{"inline":[4],"oval":[4],"height":[2],"results":[32],"placeholder":[32],"noResultsText":[32],"typing":[32],"debounce":[32],"search_term":[32]}],[4,"salla-infinite-scroll",{"nextPage":[1,"next-page"],"autoload":[1028],"container":[1],"item":[1],"loadMore":[32],"noMore":[32],"failedToLoad":[32]}],[0,"salla-product-availability",{"channels":[1],"productId":[2,"product-id"],"isSubscribed":[1028,"is-subscribed"],"subTitle":[32],"mobileLabel":[32],"emailLabel":[32],"emailPlaceholder":[32],"subscribedMessage":[32],"title_":[32],"emailErrorMsg":[32],"isVisitorSubscribed":[32]}],[4,"salla-verify",{"display":[1],"type":[1025],"autoReload":[4,"auto-reload"],"title":[32],"resendAfter":[32],"isProfileVerify":[32],"getCode":[64],"open":[64]}],[0,"salla-rating-stars",{"name":[1],"size":[1],"value":[2]}],[0,"salla-tel-input",{"phone":[1025],"name":[1],"countryCode":[1025,"country-code"],"mobileRequired":[32],"countryCodeLabel":[32],"mobileLabel":[32],"tooShort":[32],"tooLong":[32],"invalidCountryCode":[32],"invalidNumber":[32],"errorMap":[32],"getValues":[64],"isValid":[64]}],[4,"salla-button",{"shape":[513],"color":[513],"fill":[513],"size":[513],"width":[513],"loading":[516],"disabled":[516],"loaderPosition":[1,"loader-position"],"href":[1],"load":[64],"stop":[64],"setText":[64],"disable":[64],"enable":[64]}],[4,"salla-modal",{"isClosable":[1028,"is-closable"],"width":[513],"position":[513],"visible":[516],"isLoading":[1540,"is-loading"],"subTitleFirst":[4,"sub-title-first"],"noPadding":[4,"no-padding"],"subTitle":[1,"sub-title"],"icon":[1],"iconStyle":[1,"icon-style"],"imageIcon":[1,"image-icon"],"modalTitle":[32],"open":[64],"close":[64],"setTitle":[64],"loading":[64],"stopLoading":[64]}]]],["salla-add-product-button.cjs",[[4,"salla-add-product-button",{"channels":[513],"quantity":[514],"donatingAmount":[514,"donating-amount"],"productId":[520,"product-id"],"productStatus":[513,"product-status"],"productType":[513,"product-type"]}]]],["salla-conditional-fields.cjs",[[4,"salla-conditional-fields",null,[[0,"change","changeHandler"]]]]],["salla-installment.cjs",[[0,"salla-installment",{"price":[1],"language":[1],"currency":[1],"tamaraIsActive":[32],"tabbyIsActive":[32],"spotiiIsActive":[32]}]]],["salla-quantity-input.cjs",[[4,"salla-quantity-input",{"quantity":[32],"decrease":[64],"increase":[64],"setValue":[64]}]]]], options);
21
21
  });
22
22
  };
23
23
 
@@ -0,0 +1,85 @@
1
+ /*!
2
+ * Crafted with ❤ by Salla
3
+ */
4
+ 'use strict';
5
+
6
+ Object.defineProperty(exports, '__esModule', { value: true });
7
+
8
+ const index = require('./index-b4140db0.js');
9
+
10
+ const sallaAddProductButtonCss = ":host{display:block}salla-add-product-button[width=wide]{width:100%}";
11
+
12
+ const SallaAddProductButton = class {
13
+ constructor(hostRef) {
14
+ index.registerInstance(this, hostRef);
15
+ this.success = index.createEvent(this, "success", 7);
16
+ this.failed = index.createEvent(this, "failed", 7);
17
+ this.hostAttributes = {};
18
+ this.hasLabel = false;
19
+ this.channels = null;
20
+ this.quantity = 0;
21
+ this.donatingAmount = 0;
22
+ this.productStatus = 'sale';
23
+ this.productType = 'product';
24
+ }
25
+ getLabel() {
26
+ if (this.productStatus === 'sale') {
27
+ return salla.lang.get('pages.cart.add_to_cart');
28
+ }
29
+ if (this.productType !== 'donating') {
30
+ return salla.lang.get('pages.products.out_of_stock');
31
+ }
32
+ // donating
33
+ return salla.lang.get('pages.products.donation_exceed');
34
+ }
35
+ addProductToCart(event) {
36
+ // we want to ignore the click action when the type of button is submit a form
37
+ if (this.hostAttributes['type'] === 'submit') {
38
+ return false;
39
+ }
40
+ event.preventDefault();
41
+ /**
42
+ * by default the quick add is just an alias for add item function
43
+ * but its work only when the id is the only value is passed via the object
44
+ * so we will filter the object entities to remove null and zero values in case we don't want the normal add item action
45
+ */
46
+ const data = Object.entries({
47
+ id: this.productId,
48
+ donating_amount: this.donatingAmount,
49
+ quantity: this.quantity
50
+ }).reduce((a, [k, v]) => (v ? (a[k] = v, a) : a), {});
51
+ return salla.cart.quickAdd(data)
52
+ .then((response) => {
53
+ console.log("🚀 ~ file: salla-add-product-button.tsx ~ line 67 ~ SallaAddProductButton ~ .then ~ response", response);
54
+ return this.success.emit(response);
55
+ })
56
+ .catch((error) => {
57
+ console.log("🚀 ~ file: salla-add-product-button.tsx ~ line 70 ~ SallaAddProductButton ~ addProductToCart ~ error", error);
58
+ return this.failed.emit(error);
59
+ });
60
+ }
61
+ getBtnAttributes() {
62
+ for (let i = 0; i < this.host.attributes.length; i++) {
63
+ if (!['id', 'class'].includes(this.host.attributes[i].name)) {
64
+ this.hostAttributes[this.host.attributes[i].name] = this.host.attributes[i].value;
65
+ }
66
+ }
67
+ return this.hostAttributes;
68
+ }
69
+ componentWillLoad() {
70
+ this.hasLabel = !!this.host.innerHTML.replace('<!---->', '').trim();
71
+ }
72
+ render() {
73
+ return (index.h(index.Host, null, this.productStatus === 'out-and-notify' && this.channels ?
74
+ index.h("salla-product-availability", Object.assign({}, this.getBtnAttributes()), index.h("slot", null)) :
75
+ index.h("salla-button", Object.assign({ ref: el => this.btn = el, 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 !== 'sale' }), index.h("slot", null))));
76
+ }
77
+ componentDidRender() {
78
+ //if label not passed, get label
79
+ this.hasLabel || salla.event.on('languages::translations.loaded', () => this.btn.setText(this.getLabel() || 'اضافة للسلة'));
80
+ }
81
+ get host() { return index.getElement(this); }
82
+ };
83
+ SallaAddProductButton.style = sallaAddProductButtonCss;
84
+
85
+ exports.salla_add_product_button = SallaAddProductButton;