@salla.sa/twilight-components 2.9.41 → 2.9.42
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.
- package/dist/cjs/index-1d2b3370.js +2 -2
- package/dist/cjs/{index-8abe1667.js → index-53c1e9f1.js} +2232 -39
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/{salla-button_33.cjs.entry.js → salla-button_34.cjs.entry.js} +614 -0
- package/dist/cjs/twilight.cjs.js +2 -2
- package/dist/collection/assets/svg/location-marker.svg +4 -0
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/salla-map/map-styles.js +345 -0
- package/dist/collection/components/salla-map/salla-map.css +59 -0
- package/dist/collection/components/salla-map/salla-map.js +393 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +2233 -39
- package/dist/components/salla-map.d.ts +11 -0
- package/dist/components/salla-map.js +670 -0
- package/dist/esm/{index-fa058d0e.js → index-dc279949.js} +2232 -39
- package/dist/esm/index-f1d446ac.js +2 -2
- package/dist/esm/loader.js +2 -2
- package/dist/esm/{salla-button_33.entry.js → salla-button_34.entry.js} +614 -1
- package/dist/esm/twilight.js +2 -2
- package/dist/esm-es5/index-dc279949.js +30 -0
- package/dist/esm-es5/index-f1d446ac.js +1 -1
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/{salla-button_33.entry.js → salla-button_34.entry.js} +4 -4
- package/dist/esm-es5/twilight.js +1 -1
- package/dist/twilight/p-19ce7aa8.js +24 -0
- package/dist/twilight/{p-6f94dcce.entry.js → p-382b121a.entry.js} +4 -4
- package/dist/twilight/p-4733b689.system.js +4 -0
- package/dist/twilight/p-6b59d89a.system.js +30 -0
- package/dist/twilight/{p-79eae6ae.system.entry.js → p-b45e1ab3.system.entry.js} +5 -5
- package/dist/twilight/twilight.esm.js +1 -1
- package/dist/twilight/twilight.js +1 -1
- package/dist/types/components/salla-map/map-styles.d.ts +6 -0
- package/dist/types/components/salla-map/salla-map.d.ts +57 -0
- package/dist/types/components.d.ts +75 -0
- package/package.json +4 -3
- package/dist/esm-es5/index-fa058d0e.js +0 -24
- package/dist/twilight/p-175df7e0.system.js +0 -24
- package/dist/twilight/p-9e980a1a.js +0 -24
- package/dist/twilight/p-cb28d2ec.system.js +0 -4
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Crafted with ❤ by Salla
|
|
3
|
+
*/
|
|
4
|
+
import { Component, Host, h, Prop, Method, State, Event } from '@stencil/core';
|
|
5
|
+
import Location from '../../assets/svg/location.svg';
|
|
6
|
+
import Edit from '../../assets/svg/edit.svg';
|
|
7
|
+
import CurrentLocation from '../../assets/svg/location-target.svg';
|
|
8
|
+
import LocationMarker from '../../assets/svg/location-marker.svg';
|
|
9
|
+
import styles from './map-styles';
|
|
10
|
+
// import google maps
|
|
11
|
+
import { Loader } from 'google-maps';
|
|
12
|
+
export class SallaMap {
|
|
13
|
+
constructor() {
|
|
14
|
+
// state variables
|
|
15
|
+
this.modalActivityTitle = 'Activity Location';
|
|
16
|
+
this.confirmButtonTitle = 'Confirm';
|
|
17
|
+
this.locateButtonTitle = 'Locate';
|
|
18
|
+
this.locateButtonEdit = 'Edit';
|
|
19
|
+
this.searchInputValue = null;
|
|
20
|
+
/**
|
|
21
|
+
* Sets the search bar visibility.
|
|
22
|
+
*/
|
|
23
|
+
this.seachable = false;
|
|
24
|
+
/**
|
|
25
|
+
* Sets the start location.
|
|
26
|
+
*/
|
|
27
|
+
// start in mecca 🕋 ❤️
|
|
28
|
+
this.lat = 21.419421;
|
|
29
|
+
this.lng = 39.82553;
|
|
30
|
+
/**
|
|
31
|
+
* Sets the search bar visibility.
|
|
32
|
+
*/
|
|
33
|
+
this.apiKey = null;
|
|
34
|
+
/**
|
|
35
|
+
* Sets start map zoom.
|
|
36
|
+
*/
|
|
37
|
+
this.zoom = 10;
|
|
38
|
+
/**
|
|
39
|
+
* Sets map style.
|
|
40
|
+
*/
|
|
41
|
+
this.theme = 'light';
|
|
42
|
+
salla.lang.onLoaded(() => {
|
|
43
|
+
this.modalActivityTitle = salla.lang.get('pages.checkout.select_your_address_from_map');
|
|
44
|
+
this.confirmButtonTitle = salla.lang.get('pages.checkout.confirm_address');
|
|
45
|
+
this.locateButtonTitle = salla.lang.get('pages.checkout.confirm_address');
|
|
46
|
+
this.locateButtonEdit = salla.lang.get('common.elements.edit');
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
formatAddress(address) {
|
|
50
|
+
return address.length > 25 ? address.substring(0, 25) + '...' : address;
|
|
51
|
+
}
|
|
52
|
+
getPositionAddress(location) {
|
|
53
|
+
if (this.seachable) {
|
|
54
|
+
// get address and set it to search input
|
|
55
|
+
const Geocoder = new google.maps.Geocoder();
|
|
56
|
+
Geocoder.geocode({
|
|
57
|
+
location,
|
|
58
|
+
}, (results, status) => {
|
|
59
|
+
if (status === google.maps.GeocoderStatus.OK) {
|
|
60
|
+
this.searchInputValue = results[0].formatted_address;
|
|
61
|
+
this.searchInput.value = results[0].formatted_address;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
initGoogleMaps(options, mapDOM) {
|
|
67
|
+
const loader = new Loader(this.apiKey, options);
|
|
68
|
+
loader.load().then(google => {
|
|
69
|
+
this.map = new google.maps.Map(mapDOM, {
|
|
70
|
+
center: {
|
|
71
|
+
lat: this.lat,
|
|
72
|
+
lng: this.lng,
|
|
73
|
+
},
|
|
74
|
+
zoom: this.zoom,
|
|
75
|
+
zoomControl: true,
|
|
76
|
+
mapTypeControl: false,
|
|
77
|
+
scaleControl: false,
|
|
78
|
+
streetViewControl: false,
|
|
79
|
+
rotateControl: false,
|
|
80
|
+
fullscreenControl: false,
|
|
81
|
+
disableDefaultUI: false,
|
|
82
|
+
});
|
|
83
|
+
this.map.setOptions({
|
|
84
|
+
styles: this.theme === 'light' ? styles.light : styles.dark,
|
|
85
|
+
});
|
|
86
|
+
this.marker = new google.maps.Marker({
|
|
87
|
+
position: this.map.getCenter(),
|
|
88
|
+
map: this.map,
|
|
89
|
+
icon: {
|
|
90
|
+
url: 'data:image/svg+xml;utf8,' + encodeURIComponent(LocationMarker),
|
|
91
|
+
scaledSize: new google.maps.Size(30, 30),
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
if (this.seachable) {
|
|
95
|
+
const searchBox = new google.maps.places.SearchBox(this.searchInput);
|
|
96
|
+
google.maps.event.addListener(searchBox, 'places_changed', () => {
|
|
97
|
+
const places = searchBox.getPlaces();
|
|
98
|
+
// goto first place
|
|
99
|
+
if (places.length > 0 && this.map) {
|
|
100
|
+
this.map.setCenter(places[0].geometry.location);
|
|
101
|
+
this.lat = places[0].geometry.location.lat();
|
|
102
|
+
this.lng = places[0].geometry.location.lng();
|
|
103
|
+
// set marker
|
|
104
|
+
this.marker.setPosition(places[0].geometry.location);
|
|
105
|
+
this.searchInputValue = places[0].formatted_address;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
// add listener to map
|
|
110
|
+
google.maps.event.addListener(this.map, 'click', e => {
|
|
111
|
+
this.searchInputValue = null;
|
|
112
|
+
this.marker.setPosition(e.latLng);
|
|
113
|
+
this.lat = e.latLng.lat();
|
|
114
|
+
this.lng = e.latLng.lng();
|
|
115
|
+
this.getPositionAddress(e.latLng);
|
|
116
|
+
this.mapClicked.emit({
|
|
117
|
+
lat: e.latLng.lat(),
|
|
118
|
+
lng: e.latLng.lng(),
|
|
119
|
+
address: this.searchInputValue ? this.searchInputValue : null,
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
// get current location
|
|
123
|
+
this.getCurrentLocation();
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
getCurrentLocation() {
|
|
127
|
+
if (navigator.geolocation && this.map) {
|
|
128
|
+
navigator.geolocation.getCurrentPosition(position => {
|
|
129
|
+
// set map to this location
|
|
130
|
+
const mapOptions = {
|
|
131
|
+
center: new google.maps.LatLng(position.coords.latitude, position.coords.longitude),
|
|
132
|
+
zoom: 15,
|
|
133
|
+
};
|
|
134
|
+
this.map.setOptions(mapOptions);
|
|
135
|
+
// set marker
|
|
136
|
+
this.marker.setPosition(mapOptions.center);
|
|
137
|
+
this.getPositionAddress(mapOptions.center);
|
|
138
|
+
this.currentLocationChanged.emit({
|
|
139
|
+
lat: position.coords.latitude,
|
|
140
|
+
lng: position.coords.longitude,
|
|
141
|
+
address: this.searchInputValue ? this.searchInputValue : null,
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Open location component
|
|
148
|
+
*/
|
|
149
|
+
async open() {
|
|
150
|
+
var _a, _b;
|
|
151
|
+
// only init google maps on modal open :) to save resources
|
|
152
|
+
if (!this.map)
|
|
153
|
+
this.initGoogleMaps({
|
|
154
|
+
libraries: this.seachable ? ['places', 'search'] : [],
|
|
155
|
+
language: salla.config.get('user.language_code') ||
|
|
156
|
+
((_a = document.querySelector("meta[charset='UTF-8']")) === null || _a === void 0 ? void 0 : _a.getAttribute('lang')) ||
|
|
157
|
+
'ar',
|
|
158
|
+
}, this.mapElement);
|
|
159
|
+
return (_b = this.locationModal) === null || _b === void 0 ? void 0 : _b.open();
|
|
160
|
+
}
|
|
161
|
+
// rendering functions
|
|
162
|
+
getLocationModal() {
|
|
163
|
+
return (h("div", null,
|
|
164
|
+
h("div", { class: "s-map-title" }, this.modalActivityTitle),
|
|
165
|
+
h("div", { class: "s-map-modal-body" },
|
|
166
|
+
h("div", { class: "s-map-element ", ref: el => (this.mapElement = el) }),
|
|
167
|
+
this.seachable && (h("div", { class: "s-map-search-wrapper" },
|
|
168
|
+
h("input", { class: "s-map-search-input", ref: el => (this.searchInput = el) }))),
|
|
169
|
+
h("salla-button", { class: "s-map-my-location-icon", onClick: () => {
|
|
170
|
+
this.getCurrentLocation();
|
|
171
|
+
}, shape: "icon", color: "primary" },
|
|
172
|
+
h("span", { class: "s-map-location-icon", innerHTML: CurrentLocation })),
|
|
173
|
+
h("salla-button", { color: "primary", width: "wide", onClick: () => {
|
|
174
|
+
let points = {
|
|
175
|
+
lat: this.lat,
|
|
176
|
+
lng: this.lng,
|
|
177
|
+
address: this.searchInputValue ? this.searchInputValue : null,
|
|
178
|
+
};
|
|
179
|
+
salla.event.emit('salla-map::selected', points);
|
|
180
|
+
this.selected.emit(points);
|
|
181
|
+
this.locationModal.close();
|
|
182
|
+
} }, this.confirmButtonTitle))));
|
|
183
|
+
}
|
|
184
|
+
// render
|
|
185
|
+
render() {
|
|
186
|
+
return (h(Host, { class: "s-map-wrapper" },
|
|
187
|
+
h("salla-modal", { class: "s-map-modal-wrapper", ref: modal => {
|
|
188
|
+
this.locationModal = modal;
|
|
189
|
+
} }, this.getLocationModal()),
|
|
190
|
+
h("slot", { name: "button" },
|
|
191
|
+
h("salla-button", { onClick: () => {
|
|
192
|
+
this.open();
|
|
193
|
+
}, color: "primary", class: "s-map-location-button" },
|
|
194
|
+
h("span", { class: "s-map-location-icon", innerHTML: this.searchInputValue ? Edit : Location }),
|
|
195
|
+
this.searchInputValue ? (h("div", null,
|
|
196
|
+
this.locateButtonEdit,
|
|
197
|
+
" | ",
|
|
198
|
+
this.formatAddress(this.searchInputValue))) : (this.locateButtonTitle)))));
|
|
199
|
+
}
|
|
200
|
+
static get is() { return "salla-map"; }
|
|
201
|
+
static get originalStyleUrls() { return {
|
|
202
|
+
"$": ["salla-map.scss"]
|
|
203
|
+
}; }
|
|
204
|
+
static get styleUrls() { return {
|
|
205
|
+
"$": ["salla-map.css"]
|
|
206
|
+
}; }
|
|
207
|
+
static get properties() { return {
|
|
208
|
+
"seachable": {
|
|
209
|
+
"type": "boolean",
|
|
210
|
+
"mutable": true,
|
|
211
|
+
"complexType": {
|
|
212
|
+
"original": "boolean",
|
|
213
|
+
"resolved": "boolean",
|
|
214
|
+
"references": {}
|
|
215
|
+
},
|
|
216
|
+
"required": false,
|
|
217
|
+
"optional": false,
|
|
218
|
+
"docs": {
|
|
219
|
+
"tags": [],
|
|
220
|
+
"text": "Sets the search bar visibility."
|
|
221
|
+
},
|
|
222
|
+
"attribute": "seachable",
|
|
223
|
+
"reflect": false,
|
|
224
|
+
"defaultValue": "false"
|
|
225
|
+
},
|
|
226
|
+
"lat": {
|
|
227
|
+
"type": "number",
|
|
228
|
+
"mutable": true,
|
|
229
|
+
"complexType": {
|
|
230
|
+
"original": "number",
|
|
231
|
+
"resolved": "number",
|
|
232
|
+
"references": {}
|
|
233
|
+
},
|
|
234
|
+
"required": false,
|
|
235
|
+
"optional": false,
|
|
236
|
+
"docs": {
|
|
237
|
+
"tags": [],
|
|
238
|
+
"text": "Sets the start location."
|
|
239
|
+
},
|
|
240
|
+
"attribute": "lat",
|
|
241
|
+
"reflect": false,
|
|
242
|
+
"defaultValue": "21.419421"
|
|
243
|
+
},
|
|
244
|
+
"lng": {
|
|
245
|
+
"type": "number",
|
|
246
|
+
"mutable": true,
|
|
247
|
+
"complexType": {
|
|
248
|
+
"original": "number",
|
|
249
|
+
"resolved": "number",
|
|
250
|
+
"references": {}
|
|
251
|
+
},
|
|
252
|
+
"required": false,
|
|
253
|
+
"optional": false,
|
|
254
|
+
"docs": {
|
|
255
|
+
"tags": [],
|
|
256
|
+
"text": ""
|
|
257
|
+
},
|
|
258
|
+
"attribute": "lng",
|
|
259
|
+
"reflect": false,
|
|
260
|
+
"defaultValue": "39.82553"
|
|
261
|
+
},
|
|
262
|
+
"apiKey": {
|
|
263
|
+
"type": "string",
|
|
264
|
+
"mutable": true,
|
|
265
|
+
"complexType": {
|
|
266
|
+
"original": "string",
|
|
267
|
+
"resolved": "string",
|
|
268
|
+
"references": {}
|
|
269
|
+
},
|
|
270
|
+
"required": false,
|
|
271
|
+
"optional": false,
|
|
272
|
+
"docs": {
|
|
273
|
+
"tags": [],
|
|
274
|
+
"text": "Sets the search bar visibility."
|
|
275
|
+
},
|
|
276
|
+
"attribute": "api-key",
|
|
277
|
+
"reflect": false,
|
|
278
|
+
"defaultValue": "null"
|
|
279
|
+
},
|
|
280
|
+
"zoom": {
|
|
281
|
+
"type": "number",
|
|
282
|
+
"mutable": true,
|
|
283
|
+
"complexType": {
|
|
284
|
+
"original": "number",
|
|
285
|
+
"resolved": "number",
|
|
286
|
+
"references": {}
|
|
287
|
+
},
|
|
288
|
+
"required": false,
|
|
289
|
+
"optional": false,
|
|
290
|
+
"docs": {
|
|
291
|
+
"tags": [],
|
|
292
|
+
"text": "Sets start map zoom."
|
|
293
|
+
},
|
|
294
|
+
"attribute": "zoom",
|
|
295
|
+
"reflect": false,
|
|
296
|
+
"defaultValue": "10"
|
|
297
|
+
},
|
|
298
|
+
"theme": {
|
|
299
|
+
"type": "string",
|
|
300
|
+
"mutable": true,
|
|
301
|
+
"complexType": {
|
|
302
|
+
"original": "string",
|
|
303
|
+
"resolved": "string",
|
|
304
|
+
"references": {}
|
|
305
|
+
},
|
|
306
|
+
"required": false,
|
|
307
|
+
"optional": false,
|
|
308
|
+
"docs": {
|
|
309
|
+
"tags": [],
|
|
310
|
+
"text": "Sets map style."
|
|
311
|
+
},
|
|
312
|
+
"attribute": "theme",
|
|
313
|
+
"reflect": false,
|
|
314
|
+
"defaultValue": "'light'"
|
|
315
|
+
}
|
|
316
|
+
}; }
|
|
317
|
+
static get states() { return {
|
|
318
|
+
"modalActivityTitle": {},
|
|
319
|
+
"confirmButtonTitle": {},
|
|
320
|
+
"locateButtonTitle": {},
|
|
321
|
+
"locateButtonEdit": {},
|
|
322
|
+
"searchInputValue": {},
|
|
323
|
+
"searchInput": {},
|
|
324
|
+
"mapElement": {}
|
|
325
|
+
}; }
|
|
326
|
+
static get events() { return [{
|
|
327
|
+
"method": "selected",
|
|
328
|
+
"name": "selected",
|
|
329
|
+
"bubbles": true,
|
|
330
|
+
"cancelable": true,
|
|
331
|
+
"composed": true,
|
|
332
|
+
"docs": {
|
|
333
|
+
"tags": [],
|
|
334
|
+
"text": "Custome DOM event emitter when location is selected"
|
|
335
|
+
},
|
|
336
|
+
"complexType": {
|
|
337
|
+
"original": "any",
|
|
338
|
+
"resolved": "any",
|
|
339
|
+
"references": {}
|
|
340
|
+
}
|
|
341
|
+
}, {
|
|
342
|
+
"method": "mapClicked",
|
|
343
|
+
"name": "mapClicked",
|
|
344
|
+
"bubbles": true,
|
|
345
|
+
"cancelable": true,
|
|
346
|
+
"composed": true,
|
|
347
|
+
"docs": {
|
|
348
|
+
"tags": [],
|
|
349
|
+
"text": "Custome DOM event emitter when map is clicked"
|
|
350
|
+
},
|
|
351
|
+
"complexType": {
|
|
352
|
+
"original": "any",
|
|
353
|
+
"resolved": "any",
|
|
354
|
+
"references": {}
|
|
355
|
+
}
|
|
356
|
+
}, {
|
|
357
|
+
"method": "currentLocationChanged",
|
|
358
|
+
"name": "currentLocationChanged",
|
|
359
|
+
"bubbles": true,
|
|
360
|
+
"cancelable": true,
|
|
361
|
+
"composed": true,
|
|
362
|
+
"docs": {
|
|
363
|
+
"tags": [],
|
|
364
|
+
"text": "Custome DOM event emitter when current location is selected"
|
|
365
|
+
},
|
|
366
|
+
"complexType": {
|
|
367
|
+
"original": "any",
|
|
368
|
+
"resolved": "any",
|
|
369
|
+
"references": {}
|
|
370
|
+
}
|
|
371
|
+
}]; }
|
|
372
|
+
static get methods() { return {
|
|
373
|
+
"open": {
|
|
374
|
+
"complexType": {
|
|
375
|
+
"signature": "() => Promise<HTMLElement>",
|
|
376
|
+
"parameters": [],
|
|
377
|
+
"references": {
|
|
378
|
+
"Promise": {
|
|
379
|
+
"location": "global"
|
|
380
|
+
},
|
|
381
|
+
"HTMLElement": {
|
|
382
|
+
"location": "global"
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
"return": "Promise<HTMLElement>"
|
|
386
|
+
},
|
|
387
|
+
"docs": {
|
|
388
|
+
"text": "Open location component",
|
|
389
|
+
"tags": []
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}; }
|
|
393
|
+
}
|
|
@@ -15,6 +15,7 @@ export { SallaLocalizationModal as SallaLocalizationModal } from '../types/compo
|
|
|
15
15
|
export { SallaLoginModal as SallaLoginModal } from '../types/components/salla-login-modal/salla-login-modal';
|
|
16
16
|
export { SallaLoyalty as SallaLoyalty } from '../types/components/salla-loyalty/salla-loyalty';
|
|
17
17
|
export { SallaLoyaltyPrizeItem as SallaLoyaltyPrizeItem } from '../types/components/salla-loyalty/salla-loyalty-prize-item';
|
|
18
|
+
export { SallaMap as SallaMap } from '../types/components/salla-map/salla-map';
|
|
18
19
|
export { SallaModal as SallaModal } from '../types/components/salla-modal/salla-modal';
|
|
19
20
|
export { SallaOfferModal as SallaOfferModal } from '../types/components/salla-offer-modal/salla-offer-modal';
|
|
20
21
|
export { SallaPlaceholder as SallaPlaceholder } from '../types/components/salla-placeholder/salla-placeholder';
|