@salla.sa/twilight-components 2.14.295 → 2.14.297

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 (158) hide show
  1. package/dist/cjs/{filepond-CEfkKwxm.js → filepond-B40UxVrp.js} +1 -1
  2. package/dist/cjs/{filepond-plugin-file-poster-U5caDeXK.js → filepond-plugin-file-poster-BJ2is-CR.js} +1 -1
  3. package/dist/cjs/{filepond-plugin-file-validate-size-5eUt8fIA.js → filepond-plugin-file-validate-size-jaoaOCNL.js} +1 -1
  4. package/dist/cjs/{filepond-plugin-file-validate-type-BdNoSu6e.js → filepond-plugin-file-validate-type-CjxCZWaY.js} +1 -1
  5. package/dist/cjs/{filepond-plugin-image-edit-DFm7eyxh.js → filepond-plugin-image-edit-JEKYuBL0.js} +1 -1
  6. package/dist/cjs/{filepond-plugin-image-exif-orientation-BfH19uNR.js → filepond-plugin-image-exif-orientation-DmK-aAfe.js} +1 -1
  7. package/dist/cjs/{filepond-plugin-image-preview-BCQL6DBC.js → filepond-plugin-image-preview-BZxhd7ci.js} +1 -1
  8. package/dist/cjs/{index-CMFmTYR8.js → index-Bc1Blm9E.js} +6 -2
  9. package/dist/cjs/{index-TCPzRuQa.js → index-CYgngxgk.js} +1 -1
  10. package/dist/cjs/interfaces-CX9-6aLf.js +24 -0
  11. package/dist/cjs/loader.cjs.js +2 -2
  12. package/dist/cjs/salla-accordion_62.cjs.entry.js +79 -124
  13. package/dist/cjs/salla-advertisement.cjs.entry.js +1 -1
  14. package/dist/cjs/salla-app-install-alert.cjs.entry.js +1 -1
  15. package/dist/cjs/salla-apps-icons.cjs.entry.js +1 -1
  16. package/dist/cjs/salla-cart-item-offers.cjs.entry.js +1 -1
  17. package/dist/cjs/salla-conditional-offer.cjs.entry.js +1 -1
  18. package/dist/cjs/salla-contacts.cjs.entry.js +1 -1
  19. package/dist/cjs/salla-custom-fields.cjs.entry.js +135 -0
  20. package/dist/cjs/salla-filters-widget.cjs.entry.js +1 -1
  21. package/dist/cjs/salla-filters.cjs.entry.js +1 -1
  22. package/dist/cjs/salla-installment.cjs.entry.js +1 -1
  23. package/dist/cjs/salla-loyalty-prize-item.cjs.entry.js +1 -1
  24. package/dist/cjs/salla-loyalty-program.cjs.entry.js +1 -1
  25. package/dist/cjs/salla-metadata.cjs.entry.js +1 -1
  26. package/dist/cjs/salla-notification-item.cjs.entry.js +1 -1
  27. package/dist/cjs/salla-notifications.cjs.entry.js +1 -1
  28. package/dist/cjs/salla-offer.cjs.entry.js +1 -1
  29. package/dist/cjs/salla-order-details-multiple-bundle-product.cjs.entry.js +1 -1
  30. package/dist/cjs/salla-order-details-options.cjs.entry.js +1 -1
  31. package/dist/cjs/salla-order-details.cjs.entry.js +1 -1
  32. package/dist/cjs/salla-order-summary.cjs.entry.js +1 -1
  33. package/dist/cjs/salla-order-totals-card.cjs.entry.js +1 -1
  34. package/dist/cjs/salla-orders.cjs.entry.js +1 -1
  35. package/dist/cjs/salla-payments.cjs.entry.js +1 -1
  36. package/dist/cjs/salla-price-range.cjs.entry.js +1 -1
  37. package/dist/cjs/salla-review-card.cjs.entry.js +1 -1
  38. package/dist/cjs/salla-reviews-page.cjs.entry.js +1 -1
  39. package/dist/cjs/salla-reviews.cjs.entry.js +1 -1
  40. package/dist/cjs/salla-social.cjs.entry.js +1 -1
  41. package/dist/cjs/salla-tiered-offer.cjs.entry.js +1 -1
  42. package/dist/cjs/salla-tooltip.cjs.entry.js +1 -1
  43. package/dist/cjs/salla-trust-badges.cjs.entry.js +1 -1
  44. package/dist/cjs/salla-verify.cjs.entry.js +1 -1
  45. package/dist/cjs/salla-wallet.cjs.entry.js +1 -1
  46. package/dist/cjs/twilight.cjs.js +2 -2
  47. package/dist/collection/collection-manifest.json +1 -0
  48. package/dist/collection/components/salla-custom-fields/salla-custom-fields.css +3 -0
  49. package/dist/collection/components/salla-custom-fields/salla-custom-fields.js +313 -0
  50. package/dist/collection/components/salla-file-upload/salla-file-upload.js +36 -3
  51. package/dist/collection/components/salla-user-menu/salla-user-menu.js +40 -22
  52. package/dist/collection/components/salla-user-profile/salla-user-profile.js +15 -132
  53. package/dist/components/index.js +2 -2
  54. package/dist/components/interfaces.js +15 -0
  55. package/dist/components/salla-custom-fields.d.ts +11 -0
  56. package/dist/components/salla-custom-fields.js +174 -0
  57. package/dist/components/salla-file-upload2.js +13 -3
  58. package/dist/components/salla-user-menu.js +46 -22
  59. package/dist/components/salla-user-profile.js +19 -97
  60. package/dist/esm/{filepond-vl78959W.js → filepond-DjIxwPi0.js} +1 -1
  61. package/dist/esm/{filepond-plugin-file-poster-CqR_Dwed.js → filepond-plugin-file-poster-CYvspSki.js} +1 -1
  62. package/dist/esm/{filepond-plugin-file-validate-size-B6Dk56YE.js → filepond-plugin-file-validate-size-Cf09KKtA.js} +1 -1
  63. package/dist/esm/{filepond-plugin-file-validate-type-P-_BDRkR.js → filepond-plugin-file-validate-type-ByZikBAG.js} +1 -1
  64. package/dist/esm/{filepond-plugin-image-edit-DWNUa3R3.js → filepond-plugin-image-edit-DbT6_H2k.js} +1 -1
  65. package/dist/esm/{filepond-plugin-image-exif-orientation-dnXbnCGP.js → filepond-plugin-image-exif-orientation-BhEk_QOu.js} +1 -1
  66. package/dist/esm/{filepond-plugin-image-preview-CGT6aBAl.js → filepond-plugin-image-preview-Bsa9hzKo.js} +1 -1
  67. package/dist/esm/{index-DvtO64lP.js → index-CYhDRQ7q.js} +1 -1
  68. package/dist/esm/{index-Ziat6EbF.js → index-D8Ikl-5X.js} +6 -2
  69. package/dist/esm/interfaces-CBT_Nxny.js +22 -0
  70. package/dist/esm/loader.js +3 -3
  71. package/dist/esm/salla-accordion_62.entry.js +78 -123
  72. package/dist/esm/salla-advertisement.entry.js +1 -1
  73. package/dist/esm/salla-app-install-alert.entry.js +1 -1
  74. package/dist/esm/salla-apps-icons.entry.js +1 -1
  75. package/dist/esm/salla-cart-item-offers.entry.js +1 -1
  76. package/dist/esm/salla-conditional-offer.entry.js +1 -1
  77. package/dist/esm/salla-contacts.entry.js +1 -1
  78. package/dist/esm/salla-custom-fields.entry.js +133 -0
  79. package/dist/esm/salla-filters-widget.entry.js +1 -1
  80. package/dist/esm/salla-filters.entry.js +1 -1
  81. package/dist/esm/salla-installment.entry.js +1 -1
  82. package/dist/esm/salla-loyalty-prize-item.entry.js +1 -1
  83. package/dist/esm/salla-loyalty-program.entry.js +1 -1
  84. package/dist/esm/salla-metadata.entry.js +1 -1
  85. package/dist/esm/salla-notification-item.entry.js +1 -1
  86. package/dist/esm/salla-notifications.entry.js +1 -1
  87. package/dist/esm/salla-offer.entry.js +1 -1
  88. package/dist/esm/salla-order-details-multiple-bundle-product.entry.js +1 -1
  89. package/dist/esm/salla-order-details-options.entry.js +1 -1
  90. package/dist/esm/salla-order-details.entry.js +1 -1
  91. package/dist/esm/salla-order-summary.entry.js +1 -1
  92. package/dist/esm/salla-order-totals-card.entry.js +1 -1
  93. package/dist/esm/salla-orders.entry.js +1 -1
  94. package/dist/esm/salla-payments.entry.js +1 -1
  95. package/dist/esm/salla-price-range.entry.js +1 -1
  96. package/dist/esm/salla-review-card.entry.js +1 -1
  97. package/dist/esm/salla-reviews-page.entry.js +1 -1
  98. package/dist/esm/salla-reviews.entry.js +1 -1
  99. package/dist/esm/salla-social.entry.js +1 -1
  100. package/dist/esm/salla-tiered-offer.entry.js +1 -1
  101. package/dist/esm/salla-tooltip.entry.js +1 -1
  102. package/dist/esm/salla-trust-badges.entry.js +1 -1
  103. package/dist/esm/salla-verify.entry.js +1 -1
  104. package/dist/esm/salla-wallet.entry.js +1 -1
  105. package/dist/esm/twilight.js +3 -3
  106. package/dist/twilight/p-00042305.entry.js +4 -0
  107. package/dist/twilight/{p-9b480b59.entry.js → p-03907a0b.entry.js} +1 -1
  108. package/dist/twilight/{p-8cfd00b9.entry.js → p-067eafaf.entry.js} +1 -1
  109. package/dist/twilight/{p-93a27904.entry.js → p-199025a7.entry.js} +1 -1
  110. package/dist/twilight/{p-d107dc1a.entry.js → p-243e9c31.entry.js} +1 -1
  111. package/dist/twilight/{p-2b8846ae.entry.js → p-26c2b559.entry.js} +1 -1
  112. package/dist/twilight/{p-67038367.entry.js → p-28eae4bb.entry.js} +1 -1
  113. package/dist/twilight/{p-b3fafad2.entry.js → p-2a59b701.entry.js} +1 -1
  114. package/dist/twilight/{p-6822a113.entry.js → p-37249106.entry.js} +1 -1
  115. package/dist/twilight/{p-2a2a02d6.entry.js → p-3d7b61c6.entry.js} +1 -1
  116. package/dist/twilight/{p-f38b2e17.entry.js → p-3f2a0489.entry.js} +1 -1
  117. package/dist/twilight/{p-a328c3d1.entry.js → p-3fe694f7.entry.js} +1 -1
  118. package/dist/twilight/{p-bf70d878.entry.js → p-407a5e84.entry.js} +1 -1
  119. package/dist/twilight/{p-3d19d1d8.entry.js → p-4713b2c5.entry.js} +1 -1
  120. package/dist/twilight/{p-15d9e580.entry.js → p-5fe10b3f.entry.js} +1 -1
  121. package/dist/twilight/{p-415cf3e3.entry.js → p-60a1cceb.entry.js} +1 -1
  122. package/dist/twilight/{p-5f9bc177.entry.js → p-60aa330e.entry.js} +1 -1
  123. package/dist/twilight/{p-917e7e9e.entry.js → p-62b33ee4.entry.js} +1 -1
  124. package/dist/twilight/{p-ab6a475b.entry.js → p-66ccff79.entry.js} +1 -1
  125. package/dist/twilight/{p-64d30453.entry.js → p-6781caef.entry.js} +1 -1
  126. package/dist/twilight/{p-c9109a79.entry.js → p-747b3306.entry.js} +1 -1
  127. package/dist/twilight/{p-a9c627f1.entry.js → p-8713ed50.entry.js} +1 -1
  128. package/dist/twilight/{p-9c51b8d3.entry.js → p-87c26055.entry.js} +1 -1
  129. package/dist/twilight/{p-30edc8e4.entry.js → p-9bb74d00.entry.js} +1 -1
  130. package/dist/twilight/{p-Ez0e1PVX.js → p-BENXSP8S.js} +1 -1
  131. package/dist/twilight/{p-BX_7gR2g.js → p-BdPzpmIq.js} +1 -1
  132. package/dist/twilight/p-CBT_Nxny.js +4 -0
  133. package/dist/twilight/{p-hVSNpsuQ.js → p-CFX5Won9.js} +1 -1
  134. package/dist/twilight/{p-BXOeDpV2.js → p-CYIyfWLw.js} +1 -1
  135. package/dist/twilight/{p-7wg_fRFs.js → p-CdhBe5Fz.js} +1 -1
  136. package/dist/twilight/{p-C0j6-TqH.js → p-D7xuopBR.js} +1 -1
  137. package/dist/twilight/{p-Ziat6EbF.js → p-D8Ikl-5X.js} +2 -2
  138. package/dist/twilight/{p-ZreQEa1A.js → p-DQJu53PU.js} +1 -1
  139. package/dist/twilight/{p-4edf534b.entry.js → p-a608994f.entry.js} +1 -1
  140. package/dist/twilight/{p-ca431a2c.entry.js → p-ade5c1b4.entry.js} +1 -1
  141. package/dist/twilight/{p-1287dd6d.entry.js → p-c0804853.entry.js} +1 -1
  142. package/dist/twilight/{p-745e8f76.entry.js → p-dded0945.entry.js} +1 -1
  143. package/dist/twilight/p-e7b610b8.entry.js +11 -0
  144. package/dist/twilight/{p-e79994cc.entry.js → p-e82e0803.entry.js} +1 -1
  145. package/dist/twilight/{p-cd7e4279.entry.js → p-ecdb32fb.entry.js} +1 -1
  146. package/dist/twilight/{p-a9da8a2e.entry.js → p-f0267809.entry.js} +1 -1
  147. package/dist/twilight/{p-66ab7e17.entry.js → p-f30f7e03.entry.js} +1 -1
  148. package/dist/twilight/{p-f5a11fd5.entry.js → p-f8beff97.entry.js} +1 -1
  149. package/dist/twilight/{p-BBY0-pTD.js → p-fl5mSXGV.js} +1 -1
  150. package/dist/twilight/twilight.esm.js +1 -1
  151. package/dist/types/components/salla-custom-fields/salla-custom-fields.d.ts +39 -0
  152. package/dist/types/components/salla-file-upload/salla-file-upload.d.ts +4 -0
  153. package/dist/types/components/salla-user-menu/salla-user-menu.d.ts +6 -2
  154. package/dist/types/components/salla-user-profile/interfaces.d.ts +1 -0
  155. package/dist/types/components/salla-user-profile/salla-user-profile.d.ts +1 -20
  156. package/dist/types/components.d.ts +74 -25
  157. package/package.json +5 -5
  158. package/dist/twilight/p-c6d04437.entry.js +0 -11
@@ -0,0 +1,15 @@
1
+ /*!
2
+ * Crafted with ❤ by Salla
3
+ */
4
+ var Genders;
5
+ (function (Genders) {
6
+ Genders["Female"] = "female";
7
+ Genders["Male"] = "male";
8
+ })(Genders || (Genders = {}));
9
+ var FormFieldTypes;
10
+ (function (FormFieldTypes) {
11
+ FormFieldTypes["Photo"] = "photo";
12
+ FormFieldTypes["Text"] = "Text";
13
+ })(FormFieldTypes || (FormFieldTypes = {}));
14
+
15
+ export { FormFieldTypes as F, Genders as G };
@@ -0,0 +1,11 @@
1
+ import type { Components, JSX } from "../types/components";
2
+
3
+ interface SallaCustomFields extends Components.SallaCustomFields, HTMLElement {}
4
+ export const SallaCustomFields: {
5
+ prototype: SallaCustomFields;
6
+ new (): SallaCustomFields;
7
+ };
8
+ /**
9
+ * Used to define this component and all nested components recursively.
10
+ */
11
+ export const defineCustomElement: () => void;
@@ -0,0 +1,174 @@
1
+ /*!
2
+ * Crafted with ❤ by Salla
3
+ */
4
+ import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
5
+ import { C as CameraIcon } from './camera.js';
6
+ import { F as FormFieldTypes } from './interfaces.js';
7
+ import { d as defineCustomElement$3 } from './salla-button2.js';
8
+ import { d as defineCustomElement$2 } from './salla-file-upload2.js';
9
+
10
+ const sallaCustomFieldsCss = ":host{display:block}";
11
+
12
+ const SallaCustomFields$1 = /*@__PURE__*/ proxyCustomElement(class SallaCustomFields extends HTMLElement {
13
+ constructor() {
14
+ super();
15
+ this.__registerHost();
16
+ this.fieldChanged = createEvent(this, "fieldChanged", 7);
17
+ this.fileUploaded = createEvent(this, "fileUploaded", 7);
18
+ this.isEditable = true;
19
+ this.fieldErrors = {};
20
+ this.isSubmitting = false;
21
+ }
22
+ get dragAndDropText() {
23
+ return salla.lang.get("common.uploader.drag_and_drop");
24
+ }
25
+ get browseText() {
26
+ return salla.lang.get("common.uploader.browse");
27
+ }
28
+ get saveButtonText() {
29
+ return salla.lang.get("common.elements.save");
30
+ }
31
+ async setFields(fields) {
32
+ this.parsedFields = fields;
33
+ }
34
+ async getFieldValues() {
35
+ return this.parsedFields?.reduce((values, field) => {
36
+ values[`custom_fields[${field.id}]`] = field.value;
37
+ return values;
38
+ }, {}) || {};
39
+ }
40
+ async validateFields() {
41
+ if (!this.parsedFields)
42
+ return true;
43
+ const errors = this.parsedFields.reduce((acc, field) => {
44
+ if (field.required && (!field.value || field.value === "")) {
45
+ acc[field.id.toString()] = `${field.label} is required`;
46
+ }
47
+ return acc;
48
+ }, {});
49
+ this.fieldErrors = errors;
50
+ return Object.keys(errors).length === 0;
51
+ }
52
+ handleFieldChange(field, event) {
53
+ const value = event.target.value;
54
+ field.value = value;
55
+ this.clearFieldError(field.id);
56
+ const isValid = !(field.required && !value);
57
+ if (!isValid) {
58
+ this.setFieldError(field.id, `${field.label} is required`);
59
+ }
60
+ this.fieldChanged.emit({ fieldId: field.id, value, isValid });
61
+ }
62
+ handleFileUpload(field, event) {
63
+ const { error, file } = event.detail;
64
+ const isValid = !error;
65
+ this.clearFieldError(field.id);
66
+ if (isValid) {
67
+ field.value = file;
68
+ }
69
+ else {
70
+ this.setFieldError(field.id, "File upload failed");
71
+ }
72
+ this.fileUploaded.emit({ fieldId: field.id, file, isValid });
73
+ }
74
+ clearFieldError(fieldId) {
75
+ this.fieldErrors = { ...this.fieldErrors };
76
+ delete this.fieldErrors[fieldId];
77
+ }
78
+ setFieldError(fieldId, message) {
79
+ this.fieldErrors = { ...this.fieldErrors, [fieldId]: message };
80
+ }
81
+ renderTextField(field) {
82
+ return (h("input", { disabled: !this.isEditable, type: field.type, id: `custom-field-${field.id}`, value: field.value?.toString() || "", onChange: (e) => this.handleFieldChange(field, e), name: `${field.id}`, class: "form-input", required: field.required }));
83
+ }
84
+ renderFileField(field) {
85
+ return (h("salla-file-upload", { url: salla.url.api('upload'), id: `custom-field-${field.id}`, name: `${field.id}`, type: "registration", value: field.value, height: "120px", onAdded: (e) => this.handleFileUpload(field, e), required: field.required, disabled: !this.isEditable, onUploaded: e => { e.target.value = e.target.value?.url; }, allowRemove: true, onRemoved: (e) => {
86
+ e.preventDefault();
87
+ e.stopPropagation();
88
+ field.value = "";
89
+ e.target.value = "";
90
+ }, payloadName: "files[]", payloadParams: { type: 'registration' }, "instant-upload": true }, h("div", { class: "s-custom-fields-filepond-placeholder" }, h("span", { class: "s-custom-fields-filepond-placeholder-icon" }, h("i", { innerHTML: CameraIcon })), h("p", { class: "s-custom-fields-filepond-placeholder-text" }, this.dragAndDropText), h("span", { class: "filepond--label-action" }, this.browseText))));
91
+ }
92
+ renderField(field) {
93
+ return (h("div", { class: "s-custom-fields-field", key: field.id }, h("label", { class: "s-custom-fields-field-label", htmlFor: `custom-field-${field.id}` }, field.label, field.required && h("span", { class: "s-custom-fields-required" }, "*")), h("div", null, field.type === FormFieldTypes.Photo
94
+ ? this.renderFileField(field)
95
+ : this.renderTextField(field), this.fieldErrors[field.id] && (h("p", { class: "s-custom-fields-error" }, this.fieldErrors[field.id])))));
96
+ }
97
+ componentWillLoad() {
98
+ this.parsedFields = this.parseFields(this.fields);
99
+ }
100
+ parseFields(fields) {
101
+ if (!fields)
102
+ return [];
103
+ return typeof fields === "string"
104
+ ? JSON.parse(fields)
105
+ : Array.isArray(fields) ? fields : [];
106
+ }
107
+ async handleSubmit(e) {
108
+ e.preventDefault();
109
+ this.isSubmitting = true;
110
+ try {
111
+ const payload = {};
112
+ const form = e.target;
113
+ const elements = form.elements;
114
+ for (let i = 0; i < elements.length; i++) {
115
+ const element = elements[i];
116
+ if (element.name && !element.name.startsWith("hidden") && element.value) {
117
+ payload[element.name] = element.value;
118
+ }
119
+ }
120
+ await salla.api.profile.updateCustomFields({
121
+ id: salla.config.get("store.id"),
122
+ fields: payload,
123
+ });
124
+ }
125
+ finally {
126
+ this.isSubmitting = false;
127
+ }
128
+ }
129
+ render() {
130
+ if (!this.parsedFields?.length)
131
+ return null;
132
+ return (h("form", { class: "s-custom-fields-wrapper", onSubmit: this.handleSubmit }, this.parsedFields.map(field => this.renderField(field)), h("salla-button", { type: "submit", loading: this.isSubmitting, disabled: this.isSubmitting || !this.isEditable, "loader-position": "end", class: "s-custom-fields-submit-btn" }, this.saveButtonText)));
133
+ }
134
+ static get style() { return sallaCustomFieldsCss; }
135
+ }, [0, "salla-custom-fields", {
136
+ "fields": [1],
137
+ "isEditable": [4, "is-editable"],
138
+ "fileUploadUrl": [1, "file-upload-url"],
139
+ "parsedFields": [32],
140
+ "fieldErrors": [32],
141
+ "isSubmitting": [32],
142
+ "setFields": [64],
143
+ "getFieldValues": [64],
144
+ "validateFields": [64]
145
+ }]);
146
+ function defineCustomElement$1() {
147
+ if (typeof customElements === "undefined") {
148
+ return;
149
+ }
150
+ const components = ["salla-custom-fields", "salla-button", "salla-file-upload"];
151
+ components.forEach(tagName => { switch (tagName) {
152
+ case "salla-custom-fields":
153
+ if (!customElements.get(tagName)) {
154
+ customElements.define(tagName, SallaCustomFields$1);
155
+ }
156
+ break;
157
+ case "salla-button":
158
+ if (!customElements.get(tagName)) {
159
+ defineCustomElement$3();
160
+ }
161
+ break;
162
+ case "salla-file-upload":
163
+ if (!customElements.get(tagName)) {
164
+ defineCustomElement$2();
165
+ }
166
+ break;
167
+ } });
168
+ }
169
+ defineCustomElement$1();
170
+
171
+ const SallaCustomFields = SallaCustomFields$1;
172
+ const defineCustomElement = defineCustomElement$1;
173
+
174
+ export { SallaCustomFields, defineCustomElement };
@@ -51,6 +51,10 @@ const SallaFileUpload = /*@__PURE__*/ proxyCustomElement(class SallaFileUpload e
51
51
  * Set the component to be profile image uploader with a preview and a circular shape
52
52
  */
53
53
  this.profileImage = false;
54
+ /**
55
+ * Allow to pass extra params to be sent with the upload request
56
+ */
57
+ this.payloadParams = {};
54
58
  /**
55
59
  * Accepted file types
56
60
  */
@@ -312,11 +316,11 @@ const SallaFileUpload = /*@__PURE__*/ proxyCustomElement(class SallaFileUpload e
312
316
  }
313
317
  }
314
318
  render() {
315
- return (h(Host, { key: 'b5d3d0cf960e703c563f8999d55a99cbfe7a85e3', class: {
319
+ return (h(Host, { key: '68939496fd8cfcc89a7a5d21e7e4daedab0db536', class: {
316
320
  "s-file-upload": true,
317
321
  "s-file-upload-profile-image": this.profileImage,
318
322
  "s-file-upload-multiple": this.allowMultiple,
319
- } }, h("input", { key: '5e9cc8cd73e83acbb0a9f04e15e530563e94988b', type: "file", name: this.name, value: this.value, ref: ele => this.fileUploader = ele, required: this.required, class: "s-file-upload-wrapper s-file-upload-input", accept: this.accept }), this.allowMultiple && this.showMaxCountHint ? h("div", { class: "s-file-upload-hint s-hidden" }, this.max_count_hint(this.maxFilesCount)) : '', h("input", { key: '13a402c070302bfb00d82a24f523a9b764e39037', class: "s-hidden", name: 'hidden-' + this.name, required: this.required, value: this.value, ref: input => this.hiddenInput = input })));
323
+ } }, h("input", { key: 'adef3f296d759850322faf038602143a0239201d', type: "file", name: this.name, value: this.value, ref: ele => this.fileUploader = ele, required: this.required, class: "s-file-upload-wrapper s-file-upload-input", accept: this.accept }), this.allowMultiple && this.showMaxCountHint ? h("div", { class: "s-file-upload-hint s-hidden" }, this.max_count_hint(this.maxFilesCount)) : '', h("input", { key: 'dc74f8a155eeedd294548f782ed158f1a889b373', class: "s-hidden", name: 'hidden-' + this.name, required: this.required, value: this.value, ref: input => this.hiddenInput = input })));
320
324
  }
321
325
  componentDidLoad() {
322
326
  let files = this.getFiles();
@@ -399,7 +403,7 @@ const SallaFileUpload = /*@__PURE__*/ proxyCustomElement(class SallaFileUpload e
399
403
  process: {
400
404
  onload: (response) => {
401
405
  let responseData = JSON.parse(response).data;
402
- if (this.allowMultiple && Array.isArray(responseData) && responseData.length > 0) {
406
+ if ((this.instantUpload || this.allowMultiple) && Array.isArray(responseData) && responseData.length > 0) {
403
407
  const fileId = `${this.host.id}-${Math.floor(100 + Math.random() * 900)}`;
404
408
  this.uploadedFiles.push({
405
409
  id: fileId,
@@ -443,6 +447,11 @@ const SallaFileUpload = /*@__PURE__*/ proxyCustomElement(class SallaFileUpload e
443
447
  formData.append(this.payloadName, this.filepond.getFile(0).file);
444
448
  formData.delete(this.name);
445
449
  }
450
+ if (this.payloadParams) {
451
+ for (const [k, v] of Object.entries(this.payloadParams)) {
452
+ formData.append(k, v);
453
+ }
454
+ }
446
455
  if (this.cartItemId) {
447
456
  formData.append('cart_item_id', this.cartItemId);
448
457
  }
@@ -497,6 +506,7 @@ const SallaFileUpload = /*@__PURE__*/ proxyCustomElement(class SallaFileUpload e
497
506
  "profileImage": [516, "profile-image"],
498
507
  "name": [1537],
499
508
  "payloadName": [1, "payload-name"],
509
+ "payloadParams": [16, "payload-params"],
500
510
  "type": [1],
501
511
  "accept": [1537],
502
512
  "fileId": [2, "file-id"],
@@ -38,21 +38,19 @@ var WalletIcon = `<!-- Generated by IcoMoon.io -->
38
38
  </svg>
39
39
  `;
40
40
 
41
+ var SettingstIcon = `<!-- Generated by IcoMoon.io -->
42
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
43
+ <title>settings</title>
44
+ <path d="M29.717 19.037l-1.817-1.499c0.067-0.512 0.1-1.028 0.1-1.539s-0.033-1.027-0.1-1.54l1.817-1.499c1.177-0.969 1.479-2.633 0.716-3.956l-1.159-2.009c-0.761-1.324-2.349-1.895-3.784-1.359l-2.212 0.829c-0.817-0.627-1.704-1.139-2.649-1.535l-0.388-2.332c-0.251-1.507-1.54-2.6-3.067-2.6h-2.319c-1.525 0-2.815 1.093-3.065 2.6l-0.388 2.332c-0.945 0.396-1.833 0.909-2.649 1.535l-2.212-0.829c-1.428-0.533-3.021 0.036-3.783 1.359l-1.16 2.011c-0.763 1.323-0.46 2.985 0.716 3.955l1.817 1.499c-0.067 0.513-0.1 1.029-0.1 1.54s0.033 1.027 0.1 1.539l-1.819 1.5c-1.176 0.971-1.476 2.635-0.715 3.955l1.159 2.011c0.763 1.324 2.356 1.899 3.784 1.36l2.212-0.831c0.816 0.625 1.703 1.139 2.649 1.535l0.388 2.332c0.251 1.507 1.54 2.6 3.067 2.6h2.319c1.527 0 2.816-1.093 3.065-2.6l0.389-2.332c0.947-0.396 1.833-0.909 2.649-1.535l2.212 0.831c1.432 0.539 3.023-0.035 3.783-1.36l1.16-2.011c0.76-1.32 0.459-2.984-0.717-3.956zM28.123 21.663l-1.16 2.011c-0.108 0.188-0.336 0.267-0.536 0.193l-2.931-1.1c-0.459-0.173-0.979-0.079-1.349 0.248-0.923 0.811-1.979 1.423-3.139 1.819-0.464 0.157-0.804 0.559-0.885 1.043l-0.515 3.087c-0.033 0.215-0.216 0.371-0.433 0.371h-2.319c-0.217 0-0.4-0.156-0.436-0.371l-0.513-3.087c-0.080-0.484-0.42-0.884-0.885-1.043-1.16-0.396-2.216-1.008-3.139-1.819-0.248-0.217-0.561-0.332-0.88-0.332-0.157 0-0.316 0.028-0.469 0.084l-2.931 1.1c-0.199 0.079-0.428-0.004-0.537-0.193l-1.159-2.011c-0.109-0.191-0.067-0.428 0.101-0.568l2.409-1.985c0.379-0.312 0.555-0.807 0.46-1.288-0.119-0.605-0.179-1.219-0.179-1.821 0-0.604 0.060-1.217 0.181-1.823 0.095-0.481-0.081-0.976-0.46-1.288l-2.409-1.985c-0.168-0.139-0.211-0.376-0.101-0.567l1.16-2.011c0.107-0.188 0.332-0.268 0.536-0.193l2.931 1.1c0.459 0.172 0.979 0.079 1.348-0.247 0.924-0.812 1.98-1.424 3.139-1.817 0.465-0.159 0.805-0.559 0.885-1.044l0.513-3.088c0.036-0.215 0.219-0.371 0.436-0.371h2.319c0.217 0 0.4 0.156 0.436 0.371l0.515 3.088c0.081 0.484 0.42 0.885 0.885 1.044 1.157 0.393 2.213 1.005 3.139 1.817 0.371 0.325 0.889 0.42 1.349 0.247l2.929-1.099c0.203-0.076 0.428 0.005 0.537 0.193l1.159 2.009c0.109 0.191 0.067 0.428-0.101 0.567l-2.409 1.985c-0.379 0.312-0.555 0.807-0.46 1.288 0.119 0.605 0.179 1.219 0.179 1.823 0 0.603-0.060 1.216-0.181 1.821-0.095 0.48 0.081 0.975 0.46 1.288l2.408 1.984c0.169 0.141 0.212 0.379 0.103 0.569zM16.016 10.667c-2.941 0-5.333 2.392-5.333 5.333s2.392 5.333 5.333 5.333 5.333-2.392 5.333-5.333-2.392-5.333-5.333-5.333zM16.016 18.667c-1.471 0-2.667-1.196-2.667-2.667s1.196-2.667 2.667-2.667 2.667 1.196 2.667 2.667-1.196 2.667-2.667 2.667z"></path>
45
+ </svg>
46
+ `;
47
+
41
48
  const sallaUserMenuCss = "";
42
49
 
43
50
  const SallaUserMenu$1 = /*@__PURE__*/ proxyCustomElement(class SallaUserMenu extends HTMLElement {
44
51
  constructor() {
45
52
  super();
46
53
  this.__registerHost();
47
- this.items = {
48
- notifications: BellRing,
49
- orders: OrderIcon,
50
- pending_orders: PendingOrdersIcon,
51
- wishlist: WishListIcon,
52
- profile: UserCircle,
53
- wallet: WalletIcon,
54
- loyalty_program: loyaltyProgramIcon,
55
- };
56
54
  this.accountLoading = false;
57
55
  this.opened = false;
58
56
  this.notifications = salla.lang.get('common.titles.notifications');
@@ -62,6 +60,7 @@ const SallaUserMenu$1 = /*@__PURE__*/ proxyCustomElement(class SallaUserMenu ext
62
60
  this.profile = salla.lang.get('common.titles.profile');
63
61
  this.rating = salla.lang.get('common.titles.rating');
64
62
  this.wallet = salla.lang.get('common.titles.wallet');
63
+ this.settings = salla.lang.get('common.titles.settings');
65
64
  this.loyalty_program = salla.lang.get('pages.loyalty_program.loyalty_points');
66
65
  this.logout = salla.lang.get('blocks.header.logout');
67
66
  this.hello = salla.lang.get('pages.checkout.hello');
@@ -72,6 +71,7 @@ const SallaUserMenu$1 = /*@__PURE__*/ proxyCustomElement(class SallaUserMenu ext
72
71
  notifications: salla.helpers.number(salla.storage.get('user.notifications') || 0),
73
72
  pending_orders: salla.helpers.number(salla.storage.get('user.pending_orders') || 0),
74
73
  };
74
+ this.sallaAccountEnabled = Salla.config.get('store.features').includes('salla-account');
75
75
  this.hasBadges = Number(salla.storage.get('user.pending_orders')) > 0 ||
76
76
  Number(salla.storage.get('user.notifications')) > 0;
77
77
  /**
@@ -94,6 +94,16 @@ const SallaUserMenu$1 = /*@__PURE__*/ proxyCustomElement(class SallaUserMenu ext
94
94
  this.opened = false;
95
95
  };
96
96
  this.OrderUpdate = 0;
97
+ this.items = {
98
+ notifications: BellRing,
99
+ orders: OrderIcon,
100
+ pending_orders: PendingOrdersIcon,
101
+ wishlist: WishListIcon,
102
+ wallet: WalletIcon,
103
+ loyalty_program: loyaltyProgramIcon,
104
+ profile: UserCircle,
105
+ ...(this.sallaAccountEnabled ? { settings: SettingstIcon } : {})
106
+ };
97
107
  // salla.auth.event.onLoggedIn(() => {
98
108
  // this.is_loggedIn = true
99
109
  // })
@@ -106,6 +116,7 @@ const SallaUserMenu$1 = /*@__PURE__*/ proxyCustomElement(class SallaUserMenu ext
106
116
  this.hello = salla.lang.get('pages.checkout.hello');
107
117
  this.rating = salla.lang.get('common.titles.rating');
108
118
  this.wallet = salla.lang.get('common.titles.wallet');
119
+ this.settings = salla.lang.get('common.titles.settings');
109
120
  this.loyalty_program = salla.lang.get('pages.loyalty_program.loyalty_points');
110
121
  this.logout = salla.lang.get('blocks.header.logout');
111
122
  });
@@ -147,8 +158,9 @@ const SallaUserMenu$1 = /*@__PURE__*/ proxyCustomElement(class SallaUserMenu ext
147
158
  });
148
159
  }
149
160
  componentWillLoad() {
150
- return new Promise(resolve => salla.onReady(resolve)).then(() => {
151
- let trigger = this.host.querySelector('[slot="trigger"]');
161
+ return salla.onReady().then(() => {
162
+ this.profileUrl = `${salla.config.get('account.url', 'https://accounts.salla.com')}/${salla.config.get('user.language_code')}/user?store=${salla.config.get('store.id')}&info=${salla.storage.get('token')}`;
163
+ const trigger = this.host.querySelector('[slot="trigger"]');
152
164
  this.triggerSlot =
153
165
  '<div class="s-user-menu-trigger"><div class="s-user-menu-avatar-wrap"><img class="s-user-menu-trigger-avatar" src="{avatar}" alt="{first_name}{last_name}" /></div><div class="s-user-menu-trigger-content"><span class="s-user-menu-trigger-hello">{hello}</span><p class="s-user-menu-trigger-name">{first_name} {last_name}</p></div> <i class="s-user-menu-trigger-icon">{icon}</i></div>';
154
166
  if (!trigger) {
@@ -185,8 +197,8 @@ const SallaUserMenu$1 = /*@__PURE__*/ proxyCustomElement(class SallaUserMenu ext
185
197
  window.addEventListener('click', this.onClickOutside);
186
198
  }
187
199
  }
188
- menuItemClicked(event, item) {
189
- if (item[0] !== 'logout') {
200
+ menuItemClicked(event, itemKey) {
201
+ if (itemKey !== 'logout') {
190
202
  return;
191
203
  }
192
204
  event.preventDefault();
@@ -205,18 +217,28 @@ const SallaUserMenu$1 = /*@__PURE__*/ proxyCustomElement(class SallaUserMenu ext
205
217
  's-user-menu-trigger-slot': true,
206
218
  's-user-menu-red-dot': this.hasBadges,
207
219
  's-user-menu-trigger-avatar-only': this.avatarOnly,
208
- }, id: "trigger-slot", onClick: e => this.open(e), innerHTML: this.replaceParams(this.triggerSlot) }));
220
+ }, id: "trigger-slot", onClick: e => this.open(e), onKeyUp: e => this.open(e), innerHTML: this.replaceParams(this.triggerSlot) }));
221
+ }
222
+ getItemAnchorLinkAttrs(itemKey) {
223
+ if (itemKey === 'profile' && this.profileUrl) {
224
+ return this.sallaAccountEnabled ?
225
+ { href: this.profileUrl, target: '_blank', rel: 'noopener noreferrer' } :
226
+ { href: '/profile' };
227
+ }
228
+ // Fix loyalty program URL mapping from master
229
+ const urlKey = itemKey === 'loyalty_program' ? 'loyalty' : itemKey;
230
+ return { href: salla.url.get(urlKey) };
209
231
  }
210
- getMenuItem(item, i) {
232
+ getMenuItem([itemKey, itemValue], i) {
211
233
  //todo:: enhancement support slot here
212
- if (item[0] === 'wallet' && !window.can_access_wallet)
234
+ if (itemKey === 'wallet' && !window.can_access_wallet)
213
235
  return;
214
- if (item[0] === 'loyalty_program' && !salla.config.get('store.features').includes('loyalty-system'))
236
+ if (itemKey === 'loyalty_program' && !salla.config.get('store.features').includes('loyalty-system'))
215
237
  return;
216
238
  return (h("li", { class: {
217
239
  's-user-menu-dropdown-item': true,
218
- 's-user-menu-dropdown-item-logout': i + 1 == Object.entries(this.items).length,
219
- } }, h("a", { href: salla.url.get(item[0] === 'loyalty_program' ? 'loyalty' : item[0]), onClick: event => this.menuItemClicked(event, item) }, h("i", { innerHTML: item[1] }, " "), h("span", { class: "s-user-menu-dropdown-item-title" }, this[item[0]]), !['٠', '0', undefined].includes(this.badges[item[0]]) ? (h("span", { class: "s-user-menu-dropdown-item-badge" }, this.badges[item[0]])) : (''))));
240
+ 's-user-menu-dropdown-item-logout': i + 1 === Object.entries(this.items).length,
241
+ } }, h("a", { ...this.getItemAnchorLinkAttrs(itemKey), class: "s-user-menu-dropdown-item-link", onClick: event => this.menuItemClicked(event, itemKey) }, h("i", { class: "s-user-menu-dropdown-item-prefix", innerHTML: itemValue }), h("span", { class: "s-user-menu-dropdown-item-title" }, this[itemKey]), !['٠', '0', undefined].includes(this.badges[itemKey]) ? (h("span", { class: "s-user-menu-dropdown-item-badge" }, this.badges[itemKey])) : (''))));
220
242
  }
221
243
  componentShouldUpdate() {
222
244
  if (!this.opened) {
@@ -225,7 +247,7 @@ const SallaUserMenu$1 = /*@__PURE__*/ proxyCustomElement(class SallaUserMenu ext
225
247
  }
226
248
  render() {
227
249
  if (!this.is_loggedIn) {
228
- return (h(Host, null, h("slot", { name: "login-btn" }, h("button", { class: "s-user-menu-login-btn", onClick: () => salla.event.dispatch('login::open'), innerHTML: UserCircle }))));
250
+ return (h(Host, null, h("slot", { name: "login-btn" }, h("button", { type: "button", class: "s-user-menu-login-btn", onClick: () => salla.event.dispatch('login::open'), innerHTML: UserCircle }))));
229
251
  }
230
252
  if (this.inline) {
231
253
  return (h(Host, null, h("ul", { class: "s-user-menu-inline" }, Object.entries(this.items).map((item, i) => this.getMenuItem(item, i)))));
@@ -233,10 +255,9 @@ const SallaUserMenu$1 = /*@__PURE__*/ proxyCustomElement(class SallaUserMenu ext
233
255
  return (h(Host, null, h("div", { class: {
234
256
  's-user-menu-wrapper': true,
235
257
  's-user-menu-relative-dropdown': this.relativeDropdown,
236
- } }, this.getTheHeader(), h("div", { class: { 's-user-menu-toggler': true, opened: this.opened } }, h("div", { class: "s-user-menu-dropdown", onClick: e => e.stopPropagation() }, this.showHeader ? (h("div", { class: "s-user-menu-dropdown-header" }, h("img", { src: this.avatar, alt: `${this.first_name} ${this.last_name}` }), h("div", { class: "s-user-menu-dropdown-header-content" }, h("span", null, this.hello), h("p", null, this.first_name, " ", this.last_name)), h("button", { class: "s-user-menu-dropdown-header-close", innerHTML: Cancel, onClick: () => (this.opened = false) }))) : (''), h("ul", { class: "s-user-menu-dropdown-list" }, Object.entries(this.items).map((item, i) => this.getMenuItem(item, i))))))));
258
+ } }, this.getTheHeader(), h("div", { class: { 's-user-menu-toggler': true, opened: this.opened } }, h("div", { class: "s-user-menu-dropdown", onClick: e => e.stopPropagation(), onKeyUp: e => e.stopPropagation() }, this.showHeader ? (h("div", { class: "s-user-menu-dropdown-header" }, h("img", { src: this.avatar, alt: `${this.first_name} ${this.last_name}` }), h("div", { class: "s-user-menu-dropdown-header-content" }, h("span", null, this.hello), h("p", null, this.first_name, " ", this.last_name)), h("button", { type: 'button', class: "s-user-menu-dropdown-header-close", innerHTML: Cancel, onClick: () => { this.opened = false; } }))) : (''), h("ul", { class: "s-user-menu-dropdown-list" }, Object.entries(this.items).map((item, i) => this.getMenuItem(item, i))))))));
237
259
  }
238
260
  componentDidLoad() {
239
- //make sure to load the avatar if it's lazy, we use it in Y
240
261
  document.lazyLoadInstance?.update(this.host.querySelectorAll('.lazy'));
241
262
  }
242
263
  get host() { return this; }
@@ -255,6 +276,7 @@ const SallaUserMenu$1 = /*@__PURE__*/ proxyCustomElement(class SallaUserMenu ext
255
276
  "profile": [32],
256
277
  "rating": [32],
257
278
  "wallet": [32],
279
+ "settings": [32],
258
280
  "loyalty_program": [32],
259
281
  "logout": [32],
260
282
  "hello": [32],
@@ -263,7 +285,9 @@ const SallaUserMenu$1 = /*@__PURE__*/ proxyCustomElement(class SallaUserMenu ext
263
285
  "avatar": [32],
264
286
  "is_loggedIn": [32],
265
287
  "badges": [32],
288
+ "sallaAccountEnabled": [32],
266
289
  "hasBadges": [32],
290
+ "profileUrl": [32],
267
291
  "OrderUpdate": [32]
268
292
  }]);
269
293
  function defineCustomElement$1() {
@@ -2,24 +2,12 @@
2
2
  * Crafted with ❤ by Salla
3
3
  */
4
4
  import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
5
- import { C as CameraIcon } from './camera.js';
6
- import { d as defineCustomElement$6 } from './salla-button2.js';
7
- import { d as defineCustomElement$5 } from './salla-datetime-picker2.js';
8
- import { d as defineCustomElement$4 } from './salla-file-upload2.js';
5
+ import { G as Genders } from './interfaces.js';
6
+ import { d as defineCustomElement$5 } from './salla-button2.js';
7
+ import { d as defineCustomElement$4 } from './salla-datetime-picker2.js';
9
8
  import { d as defineCustomElement$3 } from './salla-skeleton2.js';
10
9
  import { d as defineCustomElement$2 } from './salla-tel-input2.js';
11
10
 
12
- var Genders;
13
- (function (Genders) {
14
- Genders["Female"] = "female";
15
- Genders["Male"] = "male";
16
- })(Genders || (Genders = {}));
17
- var FormFieldTypes;
18
- (function (FormFieldTypes) {
19
- FormFieldTypes["Photo"] = "photo";
20
- FormFieldTypes["Text"] = "Text";
21
- })(FormFieldTypes || (FormFieldTypes = {}));
22
-
23
11
  const sallaUserProfileCss = ":host{display:block}";
24
12
 
25
13
  const SallaUserProfile$1 = /*@__PURE__*/ proxyCustomElement(class SallaUserProfile extends HTMLElement {
@@ -30,7 +18,6 @@ const SallaUserProfile$1 = /*@__PURE__*/ proxyCustomElement(class SallaUserProfi
30
18
  /**
31
19
  * The minimum allowed age for a user. Users with a birthdate indicating an age less than this value will be considered invalid.
32
20
  * Defaults to 10.
33
- * @type {number}
34
21
  */
35
22
  this.minAge = 10;
36
23
  this.isEditable = true;
@@ -77,20 +64,13 @@ const SallaUserProfile$1 = /*@__PURE__*/ proxyCustomElement(class SallaUserProfi
77
64
  });
78
65
  });
79
66
  }
80
- /**
81
- * Sets custom fields for the component. Can be handy for non HTML usage.
82
- *
83
- * @param fields - An array of custom fields.
84
- */
85
- async setCustomFields(fields) {
86
- this.userDefinedFields = fields;
87
- }
88
67
  // Event handler for phone number field changes
89
68
  phoneNumberFieldEventHandler(data) {
90
69
  if (!data.detail.number) {
91
- return (this.disableAction = true);
70
+ this.disableAction = true;
71
+ return;
92
72
  }
93
- this.userData.phone.number = parseInt(data.detail.number);
73
+ this.userData.phone.number = Number.parseInt(data.detail.number);
94
74
  this.userData.phone.country = data.detail.country_code;
95
75
  this.disableAction = false;
96
76
  }
@@ -106,74 +86,34 @@ const SallaUserProfile$1 = /*@__PURE__*/ proxyCustomElement(class SallaUserProfi
106
86
  }
107
87
  }
108
88
  }
109
- // Event handler for file upload changes
110
- handleOnFileAdded(key, data) {
111
- // TODO: the key in here, shall be not have whitespace. or the key for
112
- // the field shall be provided with one of the properties of the custom field
113
- if (!data.detail.error) {
114
- this.userData[key] = data.detail.file;
115
- this.disableAction = false;
116
- }
117
- else {
118
- this.disableAction = true;
119
- }
120
- }
121
89
  // Event handler for email input changes
122
90
  handleEmailInput(key, event) {
123
91
  const emailErrorDisplaySection = document.getElementById('email-error');
124
92
  const email = event.target.value;
125
93
  if (!email) {
126
94
  this.disableAction = true;
127
- return (emailErrorDisplaySection.textContent = this.email_required_trans);
95
+ emailErrorDisplaySection.textContent = this.email_required_trans;
96
+ return;
128
97
  }
129
98
  const emailPattern = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i;
130
99
  if (!emailPattern.test(email)) {
131
100
  this.disableAction = true;
132
- return (emailErrorDisplaySection.textContent = this.invalid_email_trans);
101
+ emailErrorDisplaySection.textContent = this.invalid_email_trans;
133
102
  }
134
103
  emailErrorDisplaySection.textContent = '';
135
104
  this.userData[key] = email;
136
105
  this.disableAction = false;
137
106
  }
138
- // Helper method to trim language code from URL
139
- trimLanguageCodeFromUrl(url, languageCode) {
140
- const pattern = new RegExp(`^(https?://[^/]+)\\/${languageCode}(.*)`, 'i');
141
- const match = url.replace(/\/+$/, '').match(pattern);
142
- if (match && match.length >= 2) {
143
- const [, baseUrl, restOfUrl] = match;
144
- return baseUrl + restOfUrl;
145
- }
146
- return url;
147
- }
148
- // Helper method to get file upload URL
149
- getFileUploadUrl() {
150
- return `${this.trimLanguageCodeFromUrl(salla.config.get('store.url'), salla.config.get('user.language_code'))}/upload-image`;
151
- }
152
- // Render custom fields based on user-defined fields
153
- renderCustomFields() {
154
- if (!this.userDefinedFields) {
155
- return '';
156
- }
157
- return this.userDefinedFields.map((field) => {
158
- return (h("div", { class: "s-user-profile-field" }, h("label", { htmlFor: `${field.id}`, class: "s-user-profile-field-label" }, field.label), this.renderCustomField(field)));
159
- });
160
- }
161
- renderCustomField(field) {
162
- if (field.type !== FormFieldTypes.Photo) {
163
- return (h("input", { type: field.type, id: `${field.id}`, value: field.value, onChange: event => this.handleFieldChange(`custom_fields[${field.id}]`, event), name: `custom_fields[${field.id}]`, class: "form-input", required: field.required }));
164
- }
165
- return (h("salla-file-upload", { "instant-upload": true, value: field.value, url: this.getFileUploadUrl(), name: `custom_fields[${field.id}]`, "payload-name": "image", height: "120px", onAdded: data => this.handleOnFileAdded(`custom_fields[${field.id}]`, data) }, h("div", { class: "s-user-profile-filepond-placeholder" }, h("span", { class: "s-user-profile-filepond-placeholder-icon" }, h("i", { innerHTML: CameraIcon })), h("p", { class: "s-user-profile-filepond-placeholder-text" }, this.drag_and_drop_trans), h("span", { class: "filepond--label-action" }, this.browse_trans))));
166
- }
167
107
  // Submit form method
168
108
  submitForm(event) {
169
109
  event.preventDefault();
170
110
  this.disableAction = true;
171
- let payload = Object.assign({}, this.userData);
172
- delete payload.phone;
111
+ const payload = Object.assign({}, this.userData);
112
+ payload.phone = undefined;
173
113
  //@ts-ignore
174
- payload['phone'] = this.userData.phone.number;
175
- payload['country_code'] = this.userData.phone.country;
176
- return salla.api.profile.update(payload).finally(() => (this.disableAction = false));
114
+ payload.phone = this.userData.phone.number;
115
+ payload.country_code = this.userData.phone.country;
116
+ salla.api.profile.update(payload).finally(() => { this.disableAction = false; });
177
117
  }
178
118
  getBirthDateRestriction() {
179
119
  const now = new Date();
@@ -182,19 +122,9 @@ const SallaUserProfile$1 = /*@__PURE__*/ proxyCustomElement(class SallaUserProfi
182
122
  return now;
183
123
  }
184
124
  fetchData() {
185
- let customFields = null;
186
- // Load user-defined fields and initial user data
187
- if (this.customFields) {
188
- customFields = typeof this.customFields === 'string'
189
- ? JSON.parse(this.customFields)
190
- : this.customFields;
191
- }
192
- if (customFields && Array.isArray(customFields)) {
193
- this.userDefinedFields = customFields;
194
- }
195
125
  return salla.api.profile
196
126
  .info()
197
- .then(resp => (this.userData = resp.data))
127
+ .then(resp => { this.userData = resp.data; })
198
128
  .finally(() => {
199
129
  this.isLoading = false;
200
130
  this.isEditable = !Salla.config.get('store.features').includes('sso-login');
@@ -210,15 +140,13 @@ const SallaUserProfile$1 = /*@__PURE__*/ proxyCustomElement(class SallaUserProfi
210
140
  if (this.isLoading) {
211
141
  return this.renderLoadingSection();
212
142
  }
213
- return (h("form", { onSubmit: event => this.submitForm(event) }, h("div", { class: "s-user-profile-wrapper" }, h("div", { class: "s-user-profile-field" }, h("label", { htmlFor: "first-name", class: "s-user-profile-field-label" }, this.first_name_trans), h("input", { disabled: !this.isEditable, type: "text", name: "first_name", value: this.userData.first_name, id: "first-name", required: true, autocomplete: "first_name", class: "form-input", onChange: event => this.handleFieldChange('first_name', event) })), h("div", { class: "s-user-profile-field" }, h("label", { htmlFor: "last-name", class: "s-user-profile-field-label" }, this.last_name_trans), h("input", { disabled: !this.isEditable, type: "text", name: "last_name", value: this.userData.last_name, id: "last-name", required: true, autocomplete: "last_name", class: "form-input", onChange: event => this.handleFieldChange('last_name', event) })), h("div", { class: "s-user-profile-field" }, h("label", { htmlFor: "birthday", class: "s-user-profile-field-label" }, this.birthday_trans), h("salla-datetime-picker", { disabled: !this.isEditable, dateFormat: "Y-m-d", value: this.userData.birthday, placeholder: this.birthday_placeholder_trans, required: true, maxDate: this.getBirthDateRestriction(), name: "birthday", onPicked: event => this.handleFieldChange('birthday', event) })), h("div", { class: "s-user-profile-field" }, h("label", { htmlFor: "gender", class: "s-user-profile-field-label" }, this.gender_trans), h("select", { disabled: !this.isEditable, class: "form-input", name: "gender", required: true, onChange: event => this.handleFieldChange('gender', event) }, h("option", { value: "" }, this.gender_placeholder_trans), h("option", { value: Genders.Male, selected: this.userData.gender == Genders.Male }, this.male_trans), h("option", { value: Genders.Female, selected: this.userData.gender == Genders.Female }, this.female_trans))), h("div", { class: "s-user-profile-field" }, h("label", { htmlFor: "email", class: "s-user-profile-field-label" }, this.email_trans), h("input", { disabled: !this.isEditable, type: "email", name: "email", value: this.userData.email, id: "email", class: "form-input", required: true, onInput: event => this.handleEmailInput('email', event) }), h("p", { id: "email-error", class: "s-user-profile-field-error" })), h("div", { class: "s-user-profile-field" }, h("label", { htmlFor: "international-mobile", class: "s-user-profile-field-label" }, this.mobile_trans), h("salla-tel-input", { disabled: !this.isEditable, name: "international-mobile", "country-code": this.userData.phone.country, phone: `${this.userData.phone.number}`, onPhoneEntered: data => this.phoneNumberFieldEventHandler(data) })), this.isEditable && this.renderCustomFields()), h("salla-button", { type: "submit", loading: this.disableAction, disabled: this.disableAction || !this.isEditable, "loader-position": "end", class: "s-user-profile-submit" }, this.save_btn_trans)));
143
+ return (h("form", { onSubmit: event => this.submitForm(event) }, h("div", { class: "s-user-profile-wrapper" }, h("div", { class: "s-user-profile-field" }, h("label", { htmlFor: "first-name", class: "s-user-profile-field-label" }, this.first_name_trans), h("input", { disabled: !this.isEditable, type: "text", name: "first_name", value: this.userData.first_name, id: "first-name", required: true, autocomplete: "first_name", class: "form-input", onChange: event => this.handleFieldChange('first_name', event) })), h("div", { class: "s-user-profile-field" }, h("label", { htmlFor: "last-name", class: "s-user-profile-field-label" }, this.last_name_trans), h("input", { disabled: !this.isEditable, type: "text", name: "last_name", value: this.userData.last_name, id: "last-name", required: true, autocomplete: "last_name", class: "form-input", onChange: event => this.handleFieldChange('last_name', event) })), h("div", { class: "s-user-profile-field" }, h("label", { htmlFor: "birthday", class: "s-user-profile-field-label" }, this.birthday_trans), h("salla-datetime-picker", { disabled: !this.isEditable, dateFormat: "Y-m-d", value: this.userData.birthday, placeholder: this.birthday_placeholder_trans, required: true, maxDate: this.getBirthDateRestriction(), name: "birthday", onPicked: event => this.handleFieldChange('birthday', event) })), h("div", { class: "s-user-profile-field" }, h("label", { htmlFor: "gender", class: "s-user-profile-field-label" }, this.gender_trans), h("select", { disabled: !this.isEditable, class: "form-input", name: "gender", required: true, onChange: event => this.handleFieldChange('gender', event) }, h("option", { value: "" }, this.gender_placeholder_trans), h("option", { value: Genders.Male, selected: this.userData.gender === Genders.Male }, this.male_trans), h("option", { value: Genders.Female, selected: this.userData.gender === Genders.Female }, this.female_trans))), h("div", { class: "s-user-profile-field" }, h("label", { htmlFor: "email", class: "s-user-profile-field-label" }, this.email_trans), h("input", { disabled: !this.isEditable, type: "email", name: "email", value: this.userData.email, id: "email", class: "form-input", required: true, onInput: event => this.handleEmailInput('email', event) }), h("p", { id: "email-error", class: "s-user-profile-field-error" })), h("div", { class: "s-user-profile-field" }, h("label", { htmlFor: "international-mobile", class: "s-user-profile-field-label" }, this.mobile_trans), h("salla-tel-input", { disabled: !this.isEditable, name: "international-mobile", "country-code": this.userData.phone.country, phone: `${this.userData.phone.number}`, onPhoneEntered: data => this.phoneNumberFieldEventHandler(data) }))), h("salla-button", { type: "submit", loading: this.disableAction, disabled: this.disableAction || !this.isEditable, "loader-position": "end", class: "s-user-profile-submit" }, this.save_btn_trans)));
214
144
  }
215
145
  static get style() { return sallaUserProfileCss; }
216
146
  }, [0, "salla-user-profile", {
217
- "customFields": [1, "custom-fields"],
218
147
  "minAge": [2, "min-age"],
219
148
  "userData": [32],
220
149
  "isEditable": [32],
221
- "userDefinedFields": [32],
222
150
  "disableAction": [32],
223
151
  "isLoading": [32],
224
152
  "first_name_trans": [32],
@@ -235,14 +163,13 @@ const SallaUserProfile$1 = /*@__PURE__*/ proxyCustomElement(class SallaUserProfi
235
163
  "drag_and_drop_trans": [32],
236
164
  "browse_trans": [32],
237
165
  "email_required_trans": [32],
238
- "invalid_email_trans": [32],
239
- "setCustomFields": [64]
166
+ "invalid_email_trans": [32]
240
167
  }]);
241
168
  function defineCustomElement$1() {
242
169
  if (typeof customElements === "undefined") {
243
170
  return;
244
171
  }
245
- const components = ["salla-user-profile", "salla-button", "salla-datetime-picker", "salla-file-upload", "salla-skeleton", "salla-tel-input"];
172
+ const components = ["salla-user-profile", "salla-button", "salla-datetime-picker", "salla-skeleton", "salla-tel-input"];
246
173
  components.forEach(tagName => { switch (tagName) {
247
174
  case "salla-user-profile":
248
175
  if (!customElements.get(tagName)) {
@@ -250,16 +177,11 @@ function defineCustomElement$1() {
250
177
  }
251
178
  break;
252
179
  case "salla-button":
253
- if (!customElements.get(tagName)) {
254
- defineCustomElement$6();
255
- }
256
- break;
257
- case "salla-datetime-picker":
258
180
  if (!customElements.get(tagName)) {
259
181
  defineCustomElement$5();
260
182
  }
261
183
  break;
262
- case "salla-file-upload":
184
+ case "salla-datetime-picker":
263
185
  if (!customElements.get(tagName)) {
264
186
  defineCustomElement$4();
265
187
  }