@salla.sa/twilight-components 1.0.10 → 1.0.12

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 (86) hide show
  1. package/dist/cjs/Helper-8852feaa.js +23 -0
  2. package/dist/cjs/index-23da2c6b.js +1601 -0
  3. package/dist/cjs/index.cjs.js +12 -0
  4. package/dist/cjs/loader.cjs.js +21 -0
  5. package/dist/cjs/multi-warehouse_4.cjs.entry.js +242 -0
  6. package/dist/cjs/salla-localization.cjs.entry.js +76 -0
  7. package/dist/cjs/salla-login-476fb312.js +14 -0
  8. package/dist/cjs/salla-product-availability.cjs.entry.js +78 -0
  9. package/dist/cjs/salla-rating.cjs.entry.js +299 -0
  10. package/dist/cjs/salla-search-f9e00be9.js +97 -0
  11. package/dist/cjs/salla-search.cjs.entry.js +10 -0
  12. package/dist/cjs/salla-verify.cjs.entry.js +96 -0
  13. package/dist/cjs/twilight-components.cjs.js +19 -0
  14. package/dist/collection/Helpers/Helper.js +19 -0
  15. package/dist/collection/collection-manifest.json +20 -0
  16. package/dist/collection/components/generate-summary.js +35 -0
  17. package/dist/collection/components/multi-warehouse/multi-warehouse.css +13 -0
  18. package/dist/collection/components/multi-warehouse/multi-warehouse.js +238 -0
  19. package/dist/collection/components/salla-button/salla-button.css +3 -0
  20. package/dist/collection/components/salla-button/salla-button.js +219 -0
  21. package/dist/collection/components/salla-localization/salla-localization.js +201 -0
  22. package/dist/collection/components/salla-login/salla-login.js +31 -0
  23. package/dist/collection/components/salla-modal/salla-modal.js +316 -0
  24. package/dist/collection/components/salla-product-availability/salla-product-availability.js +316 -0
  25. package/dist/collection/components/salla-rating/salla-rating.css +3 -0
  26. package/dist/collection/components/salla-rating/salla-rating.js +484 -0
  27. package/dist/collection/components/salla-search/salla-search.js +155 -0
  28. package/dist/collection/components/salla-verify/salla-verify.js +99 -0
  29. package/dist/collection/index.js +2 -0
  30. package/dist/collection/interfaces/colors.js +1 -0
  31. package/dist/collection/interfaces/index.js +2 -0
  32. package/dist/collection/interfaces/ratio.js +1 -0
  33. package/dist/collection/plugins/tailwind-theme/generator.js +53 -0
  34. package/dist/collection/plugins/tailwind-theme/index.js +26 -0
  35. package/dist/{twilight-components/Helper-23b2de40.js → esm/Helper-81ac9a8c.js} +3 -0
  36. package/dist/esm/index-643344dc.js +1573 -0
  37. package/dist/esm/index.js +3 -0
  38. package/dist/esm/loader.js +17 -0
  39. package/dist/esm/multi-warehouse_4.entry.js +235 -0
  40. package/dist/esm/polyfills/core-js.js +11 -0
  41. package/dist/esm/polyfills/css-shim.js +1 -0
  42. package/dist/esm/polyfills/dom.js +79 -0
  43. package/dist/esm/polyfills/es5-html-element.js +1 -0
  44. package/dist/esm/polyfills/index.js +34 -0
  45. package/dist/esm/polyfills/system.js +6 -0
  46. package/dist/esm/salla-localization.entry.js +72 -0
  47. package/dist/{twilight-components/salla-login-97e0a9ab.js → esm/salla-login-0e85b2d8.js} +1 -1
  48. package/dist/{twilight-components → esm}/salla-product-availability.entry.js +38 -19
  49. package/dist/esm/salla-rating.entry.js +295 -0
  50. package/dist/{twilight-components/salla-search-df1c9b54.js → esm/salla-search-615b8f94.js} +1 -1
  51. package/dist/esm/salla-search.entry.js +2 -0
  52. package/dist/{twilight-components → esm}/salla-verify.entry.js +2 -2
  53. package/dist/esm/twilight-components.js +17 -0
  54. package/dist/index.cjs.js +1 -0
  55. package/dist/index.js +1 -0
  56. package/dist/twilight-components/index.esm.js +1 -3
  57. package/dist/twilight-components/p-2b8a5fa4.entry.js +1 -0
  58. package/dist/twilight-components/p-36c87e2e.js +1 -0
  59. package/dist/twilight-components/p-4e37a6cb.entry.js +1 -0
  60. package/dist/twilight-components/p-751643d8.entry.js +1 -0
  61. package/dist/twilight-components/p-8a2410e6.js +1 -0
  62. package/dist/twilight-components/p-94b18718.entry.js +1 -0
  63. package/dist/twilight-components/p-9bc28e0c.js +1 -0
  64. package/dist/twilight-components/p-bb503365.entry.js +1 -0
  65. package/dist/twilight-components/p-d1ef2268.js +1 -0
  66. package/dist/twilight-components/p-d34bbfc4.entry.js +1 -0
  67. package/dist/twilight-components/twilight-components.esm.js +1 -125
  68. package/dist/types/Helpers/Helper.d.ts +1 -0
  69. package/dist/types/components/salla-button/salla-button.d.ts +2 -1
  70. package/dist/types/components/salla-localization/salla-localization.d.ts +9 -2
  71. package/dist/types/components/salla-product-availability/salla-product-availability.d.ts +6 -3
  72. package/dist/types/components/{order-rating/order-rating.d.ts → salla-rating/salla-rating.d.ts} +13 -4
  73. package/dist/types/components.d.ts +40 -24
  74. package/package.json +1 -1
  75. package/dist/twilight-components/app-globals-0f993ce5.js +0 -3
  76. package/dist/twilight-components/css-shim-a64b8820.js +0 -4
  77. package/dist/twilight-components/dom-d08ba8aa.js +0 -73
  78. package/dist/twilight-components/index-8cf58712.js +0 -3010
  79. package/dist/twilight-components/multi-warehouse.entry.js +0 -86
  80. package/dist/twilight-components/order-rating.entry.js +0 -257
  81. package/dist/twilight-components/salla-button.entry.js +0 -57
  82. package/dist/twilight-components/salla-localization.entry.js +0 -48
  83. package/dist/twilight-components/salla-login.entry.js +0 -2
  84. package/dist/twilight-components/salla-modal.entry.js +0 -84
  85. package/dist/twilight-components/salla-search.entry.js +0 -2
  86. package/dist/twilight-components/shadow-css-bc14d9fd.js +0 -389
@@ -0,0 +1,238 @@
1
+ import { Component, h, Prop, Method, State, Element } from "@stencil/core";
2
+ // import Helper from "../../Helpers/Helper";
3
+ let engine = require('store/src/store-engine');
4
+ let storages = require('store/storages/sessionStorage');
5
+ let sessionStore = engine.createStore(storages);
6
+ export class MultiWarehouse {
7
+ constructor() {
8
+ this.open = false;
9
+ this.isOpenedBefore = sessionStore.get("multi-warehouse-opened-before");
10
+ this.displayAs = 'default';
11
+ this.browseProductsFrom = 'all';
12
+ this.branches = [
13
+ { id: 1, name: 'فرع الرياض', open: true, available: true, limited: false, tag: 'متوفر' },
14
+ { id: 2, name: 'فرع جدة', open: false, available: false, limited: false, tag: 'غير متوفر' },
15
+ { id: 3, name: 'فرع مكة', open: true, available: true, limited: false, tag: 'متوفر' },
16
+ { id: 4, name: 'فرع المدينة', open: true, available: true, limited: false, tag: 'متوفر' },
17
+ { id: 5, name: 'فرع جازان', open: true, available: true, limited: true, tag: 'الكمية محدودة' }
18
+ ];
19
+ this.current = 1;
20
+ this.currentBranch = (prop) => {
21
+ return this.branches.filter((el) => el.id == this.current)[0][prop];
22
+ };
23
+ this.statusColor = (branch = null) => {
24
+ return branch ?
25
+ branch.limited ? 'text-red-400' : branch.available ? 'text-green-500' : 'text-gray-400'
26
+ :
27
+ this.currentBranch('limited') ? 'text-red-400' : this.currentBranch('available') ? 'text-green-500' : 'text-gray-400';
28
+ };
29
+ this.isChoiceable = () => {
30
+ return (this.browseProductsFrom !== 'all' && this.position == 'single') || this.position == 'header';
31
+ };
32
+ this.formTitle = () => {
33
+ return this.isChoiceable() ?
34
+ 'توفر المنتج في الفروع الآخرى'
35
+ : 'التسوق من فرع آخر';
36
+ };
37
+ salla.event.on('branches::show', () => this.show());
38
+ }
39
+ async show() {
40
+ return this.modal.show();
41
+ }
42
+ async hide() {
43
+ return this.modal.hide();
44
+ }
45
+ handelChange(event) {
46
+ this.selected = event.target.value;
47
+ }
48
+ handleSubmit() {
49
+ this.btn.load().then(() => {
50
+ setTimeout(() => location.reload(), 2000);
51
+ });
52
+ sessionStore.set("multi-warehouse-opened-before", true);
53
+ this.show();
54
+ setTimeout(() => {
55
+ this.current = this.selected;
56
+ }, 300);
57
+ }
58
+ render() {
59
+ return (h("salla-modal", { icon: "sicon-store-alt", title: "\u0641\u0631\u0639 \u0627\u0644\u0631\u064A\u0627\u0636", "sub-title": "\u0623\u0646\u062A \u0627\u0644\u0622\u0646 \u062A\u062A\u0635\u0641\u062D \u0627\u0644\u0645\u062A\u062C\u0631 \u0645\u0646", "is-closable": !this.isOpenedBefore && this.displayAs == 'popup' ? 'false' : 'true', ref: modal => this.modal = modal, "modal-width": "w-116", id: "s-multi-warehouse-modal", class: "hidden" },
60
+ h("div", { class: "text-right" },
61
+ h("fieldset", { class: "mt-4" },
62
+ h("h4", { class: "text-sm text-gray-600 mb-6" }, this.formTitle()),
63
+ h("legend", { class: "sr-only" }, this.formTitle()),
64
+ this.branches.length <= 5 ?
65
+ h("div", { class: "space-y-5" }, this.branches.map((branch) => h("div", { class: "flex items-center" },
66
+ h("input", { id: this.position + '_branch_' + branch.id, disabled: !branch.open && this.isChoiceable(), name: "lang", type: "radio", value: branch.id, onChange: (event) => this.handelChange(event), class: {
67
+ 'me-3 focus:ring-primary h-4 w-4 text-primary border-gray-300': true,
68
+ 'opacity-50': !branch.open,
69
+ 'hidden': !this.isChoiceable()
70
+ }, checked: this.current == branch.id }),
71
+ h("label", { htmlFor: this.position + '_branch_' + branch.id, class: {
72
+ 'flex items-center justify-between text-sm font-medium text-gray-700 flex-grow': true,
73
+ 'cursor-pointer': this.isChoiceable()
74
+ } },
75
+ h("span", { class: { 'opacity-50': !branch.open } }, branch.name),
76
+ this.isChoiceable() ?
77
+ h("small", { class: "text-red-400" }, branch.open ? '' : 'مُغلق')
78
+ :
79
+ h("span", { class: this.statusColor(branch) }, branch.tag)))))
80
+ :
81
+ h("select", { class: "w-full h-10 transition-colors duration-300 focus:ring-transparent focus:border-primary sm:text-sm border-gray-200 rounded-md appearance-none visibility_condition px-4", onInput: (event) => this.handelChange(event) }, this.branches.map(branch => (h("option", { value: branch.id, disabled: !branch.open, selected: this.selected == branch.id },
82
+ branch.name,
83
+ " ",
84
+ branch.open ? '' : '- مُغلق')))))),
85
+ this.isChoiceable() ?
86
+ h("div", { slot: "footer", class: "mt-6" },
87
+ h("slot", { name: "footer" },
88
+ h("salla-button", { "loader-position": "before", ref: btn => this.btn = btn, onClick: () => this.handleSubmit(), class: "w-full" }, salla.lang.get('common.elements.ok'))))
89
+ : ''));
90
+ }
91
+ componentDidRender() {
92
+ if (!this.isOpenedBefore && this.displayAs == 'popup') {
93
+ this.show();
94
+ }
95
+ }
96
+ static get is() { return "multi-warehouse"; }
97
+ static get originalStyleUrls() { return {
98
+ "$": ["multi-warehouse.css"]
99
+ }; }
100
+ static get styleUrls() { return {
101
+ "$": ["multi-warehouse.css"]
102
+ }; }
103
+ static get properties() { return {
104
+ "position": {
105
+ "type": "string",
106
+ "mutable": false,
107
+ "complexType": {
108
+ "original": "string",
109
+ "resolved": "string",
110
+ "references": {}
111
+ },
112
+ "required": false,
113
+ "optional": false,
114
+ "docs": {
115
+ "tags": [],
116
+ "text": ""
117
+ },
118
+ "attribute": "position",
119
+ "reflect": false
120
+ },
121
+ "displayAs": {
122
+ "type": "string",
123
+ "mutable": false,
124
+ "complexType": {
125
+ "original": "string",
126
+ "resolved": "string",
127
+ "references": {}
128
+ },
129
+ "required": false,
130
+ "optional": false,
131
+ "docs": {
132
+ "tags": [],
133
+ "text": ""
134
+ },
135
+ "attribute": "display-as",
136
+ "reflect": false,
137
+ "defaultValue": "'default'"
138
+ },
139
+ "browseProductsFrom": {
140
+ "type": "string",
141
+ "mutable": false,
142
+ "complexType": {
143
+ "original": "string",
144
+ "resolved": "string",
145
+ "references": {}
146
+ },
147
+ "required": false,
148
+ "optional": false,
149
+ "docs": {
150
+ "tags": [],
151
+ "text": ""
152
+ },
153
+ "attribute": "browse-products-from",
154
+ "reflect": false,
155
+ "defaultValue": "'all'"
156
+ },
157
+ "branches": {
158
+ "type": "unknown",
159
+ "mutable": false,
160
+ "complexType": {
161
+ "original": "any[]",
162
+ "resolved": "any[]",
163
+ "references": {}
164
+ },
165
+ "required": false,
166
+ "optional": false,
167
+ "docs": {
168
+ "tags": [],
169
+ "text": ""
170
+ },
171
+ "defaultValue": "[\n {id: 1, name: '\u0641\u0631\u0639 \u0627\u0644\u0631\u064A\u0627\u0636', open: true, available: true, limited: false, tag: '\u0645\u062A\u0648\u0641\u0631'},\n {id: 2, name: '\u0641\u0631\u0639 \u062C\u062F\u0629', open: false, available: false, limited: false, tag: '\u063A\u064A\u0631 \u0645\u062A\u0648\u0641\u0631'},\n {id: 3, name: '\u0641\u0631\u0639 \u0645\u0643\u0629', open: true, available: true, limited: false, tag: '\u0645\u062A\u0648\u0641\u0631'},\n {id: 4, name: '\u0641\u0631\u0639 \u0627\u0644\u0645\u062F\u064A\u0646\u0629', open: true, available: true, limited: false, tag: '\u0645\u062A\u0648\u0641\u0631'},\n {id: 5, name: '\u0641\u0631\u0639 \u062C\u0627\u0632\u0627\u0646', open: true, available: true, limited: true, tag: '\u0627\u0644\u0643\u0645\u064A\u0629 \u0645\u062D\u062F\u0648\u062F\u0629'}\n ]"
172
+ },
173
+ "current": {
174
+ "type": "number",
175
+ "mutable": true,
176
+ "complexType": {
177
+ "original": "number",
178
+ "resolved": "number",
179
+ "references": {}
180
+ },
181
+ "required": false,
182
+ "optional": false,
183
+ "docs": {
184
+ "tags": [],
185
+ "text": ""
186
+ },
187
+ "attribute": "current",
188
+ "reflect": false,
189
+ "defaultValue": "1"
190
+ }
191
+ }; }
192
+ static get states() { return {
193
+ "open": {},
194
+ "selected": {},
195
+ "isOpenedBefore": {}
196
+ }; }
197
+ static get methods() { return {
198
+ "show": {
199
+ "complexType": {
200
+ "signature": "() => Promise<HTMLElement>",
201
+ "parameters": [],
202
+ "references": {
203
+ "Promise": {
204
+ "location": "global"
205
+ },
206
+ "HTMLElement": {
207
+ "location": "global"
208
+ }
209
+ },
210
+ "return": "Promise<HTMLElement>"
211
+ },
212
+ "docs": {
213
+ "text": "",
214
+ "tags": []
215
+ }
216
+ },
217
+ "hide": {
218
+ "complexType": {
219
+ "signature": "() => Promise<HTMLElement>",
220
+ "parameters": [],
221
+ "references": {
222
+ "Promise": {
223
+ "location": "global"
224
+ },
225
+ "HTMLElement": {
226
+ "location": "global"
227
+ }
228
+ },
229
+ "return": "Promise<HTMLElement>"
230
+ },
231
+ "docs": {
232
+ "text": "",
233
+ "tags": []
234
+ }
235
+ }
236
+ }; }
237
+ static get elementRef() { return "host"; }
238
+ }
@@ -0,0 +1,3 @@
1
+ :host {
2
+ display: block;
3
+ }
@@ -0,0 +1,219 @@
1
+ import { Component, Element, h, Method, Prop, Watch } from '@stencil/core';
2
+ import Helper from "../../Helpers/Helper";
3
+ export class SallaButton {
4
+ constructor() {
5
+ this.btnStyle = 'primary'; // outline, outline-primary ,danger
6
+ this.loading = false;
7
+ this.disabled = false;
8
+ this.loaderPosition = 'before';
9
+ this.hostAttributes = {};
10
+ //============= Initiate Button Attributes =============//
11
+ for (let i = 0; i < this.host.attributes.length; i++) {
12
+ this.hostAttributes[this.host.attributes[i].name] = this.host.attributes[i].value;
13
+ }
14
+ this.hostAttributes.type = this.hostAttributes.type || 'button';
15
+ this.hostAttributes.class = (this.hostAttributes.class || '') +
16
+ ' s-button-btn btn--has-loading btn-' + this.btnStyle + ' loader-' + this.loaderPosition;
17
+ this.hostAttributes.class += this.loaderPosition == 'before' ? ' flex-row-reverse' : '';
18
+ // if(this.hostAttributes.onclick){
19
+ // this.hostAttributes.onclick=eval(this.hostAttributes.onclick);
20
+ // }
21
+ delete this.hostAttributes['btn-style'];
22
+ delete this.hostAttributes['id'];
23
+ }
24
+ async load() {
25
+ if (this.loaderPosition == 'center')
26
+ this.host.querySelector('.btn-text').classList.add('opacity-0');
27
+ this.host.setAttribute('loading', '');
28
+ return this.host;
29
+ }
30
+ async stop() {
31
+ this.host.removeAttribute('loading');
32
+ return this.host;
33
+ }
34
+ async disable() {
35
+ this.host.setAttribute('disabled', '');
36
+ }
37
+ async enable() {
38
+ this.host.removeAttribute('disabled');
39
+ }
40
+ handleVisible(newKind, oldKind) {
41
+ this.btn.classList.remove('btn-' + oldKind);
42
+ this.btn.classList.add('btn-' + newKind);
43
+ }
44
+ handleLoading(newVal) {
45
+ Helper.toggleElement(this.btn, 'btn--is-loading', 'btn--no-loading', () => newVal);
46
+ }
47
+ render() {
48
+ return (h("button", Object.assign({ ref: btn => this.btn = btn, disabled: this.disabled }, this.hostAttributes),
49
+ h("span", { class: "btn-text transition-opacity duration-300" },
50
+ h("slot", null)),
51
+ this.loading ? h("span", { class: {
52
+ 'loader loader--small s-button-loader': true,
53
+ 'absolute right-2': this.loaderPosition === 'start',
54
+ 'absolute left-2': this.loaderPosition === 'end',
55
+ 'absolute top-1/2 left-1/2 !-translate-x-1/2 !-translate-y-1/2 !m-0': this.loaderPosition === 'center',
56
+ } }) : ''));
57
+ }
58
+ static get is() { return "salla-button"; }
59
+ static get originalStyleUrls() { return {
60
+ "$": ["salla-button.css"]
61
+ }; }
62
+ static get styleUrls() { return {
63
+ "$": ["salla-button.css"]
64
+ }; }
65
+ static get properties() { return {
66
+ "btnStyle": {
67
+ "type": "string",
68
+ "mutable": false,
69
+ "complexType": {
70
+ "original": "string",
71
+ "resolved": "string",
72
+ "references": {}
73
+ },
74
+ "required": false,
75
+ "optional": false,
76
+ "docs": {
77
+ "tags": [],
78
+ "text": ""
79
+ },
80
+ "attribute": "btn-style",
81
+ "reflect": true,
82
+ "defaultValue": "'primary'"
83
+ },
84
+ "loading": {
85
+ "type": "boolean",
86
+ "mutable": false,
87
+ "complexType": {
88
+ "original": "boolean",
89
+ "resolved": "boolean",
90
+ "references": {}
91
+ },
92
+ "required": false,
93
+ "optional": false,
94
+ "docs": {
95
+ "tags": [],
96
+ "text": ""
97
+ },
98
+ "attribute": "loading",
99
+ "reflect": true,
100
+ "defaultValue": "false"
101
+ },
102
+ "disabled": {
103
+ "type": "boolean",
104
+ "mutable": false,
105
+ "complexType": {
106
+ "original": "boolean",
107
+ "resolved": "boolean",
108
+ "references": {}
109
+ },
110
+ "required": false,
111
+ "optional": false,
112
+ "docs": {
113
+ "tags": [],
114
+ "text": ""
115
+ },
116
+ "attribute": "disabled",
117
+ "reflect": true,
118
+ "defaultValue": "false"
119
+ },
120
+ "loaderPosition": {
121
+ "type": "string",
122
+ "mutable": false,
123
+ "complexType": {
124
+ "original": "string",
125
+ "resolved": "string",
126
+ "references": {}
127
+ },
128
+ "required": false,
129
+ "optional": false,
130
+ "docs": {
131
+ "tags": [],
132
+ "text": ""
133
+ },
134
+ "attribute": "loader-position",
135
+ "reflect": false,
136
+ "defaultValue": "'before'"
137
+ }
138
+ }; }
139
+ static get methods() { return {
140
+ "load": {
141
+ "complexType": {
142
+ "signature": "() => Promise<HTMLElement>",
143
+ "parameters": [],
144
+ "references": {
145
+ "Promise": {
146
+ "location": "global"
147
+ },
148
+ "HTMLElement": {
149
+ "location": "global"
150
+ }
151
+ },
152
+ "return": "Promise<HTMLElement>"
153
+ },
154
+ "docs": {
155
+ "text": "",
156
+ "tags": []
157
+ }
158
+ },
159
+ "stop": {
160
+ "complexType": {
161
+ "signature": "() => Promise<HTMLElement>",
162
+ "parameters": [],
163
+ "references": {
164
+ "Promise": {
165
+ "location": "global"
166
+ },
167
+ "HTMLElement": {
168
+ "location": "global"
169
+ }
170
+ },
171
+ "return": "Promise<HTMLElement>"
172
+ },
173
+ "docs": {
174
+ "text": "",
175
+ "tags": []
176
+ }
177
+ },
178
+ "disable": {
179
+ "complexType": {
180
+ "signature": "() => Promise<void>",
181
+ "parameters": [],
182
+ "references": {
183
+ "Promise": {
184
+ "location": "global"
185
+ }
186
+ },
187
+ "return": "Promise<void>"
188
+ },
189
+ "docs": {
190
+ "text": "",
191
+ "tags": []
192
+ }
193
+ },
194
+ "enable": {
195
+ "complexType": {
196
+ "signature": "() => Promise<void>",
197
+ "parameters": [],
198
+ "references": {
199
+ "Promise": {
200
+ "location": "global"
201
+ }
202
+ },
203
+ "return": "Promise<void>"
204
+ },
205
+ "docs": {
206
+ "text": "",
207
+ "tags": []
208
+ }
209
+ }
210
+ }; }
211
+ static get elementRef() { return "host"; }
212
+ static get watchers() { return [{
213
+ "propName": "btnStyle",
214
+ "methodName": "handleVisible"
215
+ }, {
216
+ "propName": "loading",
217
+ "methodName": "handleLoading"
218
+ }]; }
219
+ }
@@ -0,0 +1,201 @@
1
+ import { Component, Element, h, Method, Prop } from '@stencil/core';
2
+ import Helper from "../../Helpers/Helper";
3
+ export class SallaLocalization {
4
+ constructor() {
5
+ var _a, _b;
6
+ this.language = salla.config.language;
7
+ this.currency = salla.config.currency;
8
+ this.languages = salla.lang.get('common.titles.language');
9
+ this.currencies = salla.lang.get('common.titles.currency');
10
+ this.ok = salla.lang.get('common.elements.ok');
11
+ Helper.setHost(this.host);
12
+ salla.event.on('localization::show', () => this.show());
13
+ /**
14
+ * letting developer to insert his own slot like:
15
+ * <salla-localization>
16
+ * <div slot="language">...{name}....</div>
17
+ * <div slot="currency">...{name}....</div>
18
+ * </salla-localization>
19
+ * Because scoped templates not supported in stencil );
20
+ * we made a workaround to pass language & currency attributes, then replace names in rendering
21
+ */
22
+ this.languageSlot = ((_a = Helper.getElement('[slot="language"]')) === null || _a === void 0 ? void 0 : _a.innerHTML) || '<label class="s-localization-label" for"lang-{code}"><span>{name}</span><div class="s-localization-flag flag iti__flag iti__{country_code}"></div></label>';
23
+ this.currencySlot = ((_b = Helper.getElement('[slot="currency"]')) === null || _b === void 0 ? void 0 : _b.innerHTML) || '<label class="s-localization-label" for="currency-{code}"><span>{name}</span><small class="s-localization-currency">{code}</small></label>';
24
+ }
25
+ async show() {
26
+ return this.modal.show();
27
+ }
28
+ async hide() {
29
+ return this.modal.hide();
30
+ }
31
+ async submit() {
32
+ let url;
33
+ this.btn.load()
34
+ .then(() => {
35
+ if (this.currency && this.currency.code !== salla.config.currency.code) {
36
+ url = window.location.href;
37
+ return salla.currency.api.change(this.currency.code);
38
+ }
39
+ }).then(() => {
40
+ if (this.language && this.language.code !== salla.config.language.code) {
41
+ url = this.language.url;
42
+ }
43
+ }).then(() => this.btn.stop())
44
+ .then(() => this.hide())
45
+ .then(() => url && (window.location.href = url));
46
+ }
47
+ render() {
48
+ return (h("salla-modal", { id: "salla-localization", class: "hidden", ref: modal => this.modal = modal },
49
+ h("slot", { name: "header" },
50
+ h("div", { slot: "header" })),
51
+ h("div", { class: "s-localization-inner" },
52
+ salla.config.languages
53
+ ? h("div", { class: "s-localization-section" },
54
+ h("label", { class: "s-localization-title" }, this.languages),
55
+ h("fieldset", { class: "s-localization-fieldset" },
56
+ h("legend", { class: "sr-only" }, salla.lang.get('blocks.header.change_language')),
57
+ h("div", { class: "s-localization-section-inner" }, salla.config.languages.map(lang => h("div", { class: "s-localization-item" },
58
+ h("input", { class: "s-localization-input", type: "radio", checked: this.language.code == lang.code, onChange: () => this.language = lang, name: "language", id: 'lang-' + lang.code.toLowerCase(), value: lang.code }),
59
+ h("div", { id: "language-slot", innerHTML: this.languageSlot
60
+ .replace(/\{name\}/g, lang.name)
61
+ .replace(/\{code\}/g, lang.code)
62
+ .replace(/\{country_code\}/g, lang.country_code) }))))))
63
+ : '',
64
+ salla.config.currencies
65
+ ? h("div", { class: "s-localization-section" },
66
+ h("label", { class: "s-localization-title" }, this.currencies),
67
+ h("fieldset", { class: "s-localization-fieldset" },
68
+ h("legend", { class: "sr-only" }, salla.lang.get('blocks.header.change_currency')),
69
+ h("div", { class: "s-localization-section-inner" }, salla.config.currencies.map(currency => h("div", { class: "s-localization-item" },
70
+ h("input", { class: "s-localization-input", type: "radio", name: "currency", checked: this.currency.code == currency.code, onChange: () => this.currency = currency, id: 'currency-' + currency.code, value: currency.code }),
71
+ h("div", { id: "currency-slot", innerHTML: this.currencySlot
72
+ .replace(/\{name\}/g, currency.name)
73
+ .replace(/\{code\}/g, currency.code)
74
+ .replace(/\{country_code\}/g, currency.country_code) }))))))
75
+ : ''),
76
+ h("p", { slot: "footer" },
77
+ h("slot", { name: "footer" },
78
+ h("salla-button", { ref: btn => this.btn = btn, onClick: () => this.submit(), class: "w-full" }, this.ok)))));
79
+ }
80
+ /**
81
+ * to reduce dom levels we will move slot data into the parent dom
82
+ */
83
+ componentDidRender() {
84
+ this.host.querySelectorAll('#currency-slot').forEach(el => el.replaceWith(el.firstChild));
85
+ this.host.querySelectorAll('#language-slot').forEach(el => el.replaceWith(el.firstChild));
86
+ }
87
+ static get is() { return "salla-localization"; }
88
+ static get properties() { return {
89
+ "languages": {
90
+ "type": "string",
91
+ "mutable": false,
92
+ "complexType": {
93
+ "original": "string",
94
+ "resolved": "string",
95
+ "references": {}
96
+ },
97
+ "required": false,
98
+ "optional": false,
99
+ "docs": {
100
+ "tags": [],
101
+ "text": ""
102
+ },
103
+ "attribute": "languages",
104
+ "reflect": false,
105
+ "defaultValue": "salla.lang.get('common.titles.language')"
106
+ },
107
+ "currencies": {
108
+ "type": "string",
109
+ "mutable": false,
110
+ "complexType": {
111
+ "original": "string",
112
+ "resolved": "string",
113
+ "references": {}
114
+ },
115
+ "required": false,
116
+ "optional": false,
117
+ "docs": {
118
+ "tags": [],
119
+ "text": ""
120
+ },
121
+ "attribute": "currencies",
122
+ "reflect": false,
123
+ "defaultValue": "salla.lang.get('common.titles.currency')"
124
+ },
125
+ "ok": {
126
+ "type": "string",
127
+ "mutable": false,
128
+ "complexType": {
129
+ "original": "string",
130
+ "resolved": "string",
131
+ "references": {}
132
+ },
133
+ "required": false,
134
+ "optional": false,
135
+ "docs": {
136
+ "tags": [],
137
+ "text": ""
138
+ },
139
+ "attribute": "ok",
140
+ "reflect": false,
141
+ "defaultValue": "salla.lang.get('common.elements.ok')"
142
+ }
143
+ }; }
144
+ static get methods() { return {
145
+ "show": {
146
+ "complexType": {
147
+ "signature": "() => Promise<HTMLElement>",
148
+ "parameters": [],
149
+ "references": {
150
+ "Promise": {
151
+ "location": "global"
152
+ },
153
+ "HTMLElement": {
154
+ "location": "global"
155
+ }
156
+ },
157
+ "return": "Promise<HTMLElement>"
158
+ },
159
+ "docs": {
160
+ "text": "",
161
+ "tags": []
162
+ }
163
+ },
164
+ "hide": {
165
+ "complexType": {
166
+ "signature": "() => Promise<HTMLElement>",
167
+ "parameters": [],
168
+ "references": {
169
+ "Promise": {
170
+ "location": "global"
171
+ },
172
+ "HTMLElement": {
173
+ "location": "global"
174
+ }
175
+ },
176
+ "return": "Promise<HTMLElement>"
177
+ },
178
+ "docs": {
179
+ "text": "",
180
+ "tags": []
181
+ }
182
+ },
183
+ "submit": {
184
+ "complexType": {
185
+ "signature": "() => Promise<void>",
186
+ "parameters": [],
187
+ "references": {
188
+ "Promise": {
189
+ "location": "global"
190
+ }
191
+ },
192
+ "return": "Promise<void>"
193
+ },
194
+ "docs": {
195
+ "text": "",
196
+ "tags": []
197
+ }
198
+ }
199
+ }; }
200
+ static get elementRef() { return "host"; }
201
+ }