@salla.sa/twilight-components 1.0.14 → 1.0.15

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