@janiscommerce/ui-web 0.37.0 → 0.38.0

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/CHANGELOG.md CHANGED
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.38.0] - 2025-05-08
11
+
12
+ ### ADDED
13
+
14
+ - forwardRef, useImperativeHandle and useEffect for set bounds and zoom in Map component
15
+
16
+ ### REMOVED
17
+
18
+ - getCenterByGeolocationOrCenter, getGeolocationCoordinates map utils
19
+
10
20
  ## [0.37.0] - 2025-05-02
11
21
 
12
22
  ### Removed
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import React__default, { useState, useEffect, useRef, PureComponent, useMemo, useCallback, useLayoutEffect, createContext } from 'react';
2
+ import React__default, { useState, useEffect, useRef, PureComponent, useMemo, useCallback, useLayoutEffect, createContext, forwardRef, useImperativeHandle } from 'react';
3
3
  import styled$g, { css, keyframes } from 'styled-components';
4
4
  import * as ReactDOM from 'react-dom';
5
5
  import ReactDOM__default from 'react-dom';
@@ -489,7 +489,7 @@ var isCallable$k = function (argument) {
489
489
 
490
490
  var isCallable$j = isCallable$k;
491
491
 
492
- var isObject$d = function (it) {
492
+ var isObject$c = function (it) {
493
493
  return typeof it == 'object' ? it !== null : isCallable$j(it);
494
494
  };
495
495
 
@@ -614,7 +614,7 @@ var getMethod$5 = function (V, P) {
614
614
  var global$L = global$T;
615
615
  var call$f = functionCall;
616
616
  var isCallable$f = isCallable$k;
617
- var isObject$c = isObject$d;
617
+ var isObject$b = isObject$c;
618
618
 
619
619
  var TypeError$k = global$L.TypeError;
620
620
 
@@ -622,9 +622,9 @@ var TypeError$k = global$L.TypeError;
622
622
  // https://tc39.es/ecma262/#sec-ordinarytoprimitive
623
623
  var ordinaryToPrimitive$1 = function (input, pref) {
624
624
  var fn, val;
625
- if (pref === 'string' && isCallable$f(fn = input.toString) && !isObject$c(val = call$f(fn, input))) return val;
626
- if (isCallable$f(fn = input.valueOf) && !isObject$c(val = call$f(fn, input))) return val;
627
- if (pref !== 'string' && isCallable$f(fn = input.toString) && !isObject$c(val = call$f(fn, input))) return val;
625
+ if (pref === 'string' && isCallable$f(fn = input.toString) && !isObject$b(val = call$f(fn, input))) return val;
626
+ if (isCallable$f(fn = input.valueOf) && !isObject$b(val = call$f(fn, input))) return val;
627
+ if (pref !== 'string' && isCallable$f(fn = input.toString) && !isObject$b(val = call$f(fn, input))) return val;
628
628
  throw TypeError$k("Can't convert object to primitive value");
629
629
  };
630
630
 
@@ -724,7 +724,7 @@ var wellKnownSymbol$m = function (name) {
724
724
 
725
725
  var global$G = global$T;
726
726
  var call$e = functionCall;
727
- var isObject$b = isObject$d;
727
+ var isObject$a = isObject$c;
728
728
  var isSymbol$2 = isSymbol$3;
729
729
  var getMethod$4 = getMethod$5;
730
730
  var ordinaryToPrimitive = ordinaryToPrimitive$1;
@@ -736,13 +736,13 @@ var TO_PRIMITIVE = wellKnownSymbol$l('toPrimitive');
736
736
  // `ToPrimitive` abstract operation
737
737
  // https://tc39.es/ecma262/#sec-toprimitive
738
738
  var toPrimitive$2 = function (input, pref) {
739
- if (!isObject$b(input) || isSymbol$2(input)) return input;
739
+ if (!isObject$a(input) || isSymbol$2(input)) return input;
740
740
  var exoticToPrim = getMethod$4(input, TO_PRIMITIVE);
741
741
  var result;
742
742
  if (exoticToPrim) {
743
743
  if (pref === undefined) pref = 'default';
744
744
  result = call$e(exoticToPrim, input, pref);
745
- if (!isObject$b(result) || isSymbol$2(result)) return result;
745
+ if (!isObject$a(result) || isSymbol$2(result)) return result;
746
746
  throw TypeError$j("Can't convert object to primitive value");
747
747
  }
748
748
  if (pref === undefined) pref = 'number';
@@ -760,11 +760,11 @@ var toPropertyKey$3 = function (argument) {
760
760
  };
761
761
 
762
762
  var global$F = global$T;
763
- var isObject$a = isObject$d;
763
+ var isObject$9 = isObject$c;
764
764
 
765
765
  var document$3 = global$F.document;
766
766
  // typeof document.createElement is 'object' in old IE
767
- var EXISTS$1 = isObject$a(document$3) && isObject$a(document$3.createElement);
767
+ var EXISTS$1 = isObject$9(document$3) && isObject$9(document$3.createElement);
768
768
 
769
769
  var documentCreateElement$2 = function (it) {
770
770
  return EXISTS$1 ? document$3.createElement(it) : {};
@@ -821,14 +821,14 @@ var v8PrototypeDefineBug = DESCRIPTORS$a && fails$k(function () {
821
821
  });
822
822
 
823
823
  var global$E = global$T;
824
- var isObject$9 = isObject$d;
824
+ var isObject$8 = isObject$c;
825
825
 
826
826
  var String$4 = global$E.String;
827
827
  var TypeError$i = global$E.TypeError;
828
828
 
829
829
  // `Assert: Type(argument) is Object`
830
830
  var anObject$h = function (argument) {
831
- if (isObject$9(argument)) return argument;
831
+ if (isObject$8(argument)) return argument;
832
832
  throw TypeError$i(String$4(argument) + ' is not an object');
833
833
  };
834
834
 
@@ -927,7 +927,7 @@ var hiddenKeys$4 = {};
927
927
  var NATIVE_WEAK_MAP = nativeWeakMap;
928
928
  var global$B = global$T;
929
929
  var uncurryThis$o = functionUncurryThis;
930
- var isObject$8 = isObject$d;
930
+ var isObject$7 = isObject$c;
931
931
  var createNonEnumerableProperty$6 = createNonEnumerableProperty$7;
932
932
  var hasOwn$a = hasOwnProperty_1;
933
933
  var shared$1 = sharedStore;
@@ -946,7 +946,7 @@ var enforce = function (it) {
946
946
  var getterFor = function (TYPE) {
947
947
  return function (it) {
948
948
  var state;
949
- if (!isObject$8(it) || (state = get(it)).type !== TYPE) {
949
+ if (!isObject$7(it) || (state = get(it)).type !== TYPE) {
950
950
  throw TypeError$g('Incompatible receiver, ' + TYPE + ' required');
951
951
  } return state;
952
952
  };
@@ -1411,7 +1411,7 @@ var isConstructor$3 = !construct || fails$i(function () {
1411
1411
  var global$x = global$T;
1412
1412
  var isArray$2 = isArray$3;
1413
1413
  var isConstructor$2 = isConstructor$3;
1414
- var isObject$7 = isObject$d;
1414
+ var isObject$6 = isObject$c;
1415
1415
  var wellKnownSymbol$i = wellKnownSymbol$m;
1416
1416
 
1417
1417
  var SPECIES$5 = wellKnownSymbol$i('species');
@@ -1425,7 +1425,7 @@ var arraySpeciesConstructor$1 = function (originalArray) {
1425
1425
  C = originalArray.constructor;
1426
1426
  // cross-realm fallback
1427
1427
  if (isConstructor$2(C) && (C === Array$3 || isArray$2(C.prototype))) C = undefined;
1428
- else if (isObject$7(C)) {
1428
+ else if (isObject$6(C)) {
1429
1429
  C = C[SPECIES$5];
1430
1430
  if (C === null) C = undefined;
1431
1431
  }
@@ -1464,7 +1464,7 @@ var $$i = _export;
1464
1464
  var global$w = global$T;
1465
1465
  var fails$g = fails$q;
1466
1466
  var isArray$1 = isArray$3;
1467
- var isObject$6 = isObject$d;
1467
+ var isObject$5 = isObject$c;
1468
1468
  var toObject$7 = toObject$9;
1469
1469
  var lengthOfArrayLike$7 = lengthOfArrayLike$9;
1470
1470
  var createProperty$2 = createProperty$3;
@@ -1490,7 +1490,7 @@ var IS_CONCAT_SPREADABLE_SUPPORT = V8_VERSION$1 >= 51 || !fails$g(function () {
1490
1490
  var SPECIES_SUPPORT = arrayMethodHasSpeciesSupport$1('concat');
1491
1491
 
1492
1492
  var isConcatSpreadable = function (O) {
1493
- if (!isObject$6(O)) return false;
1493
+ if (!isObject$5(O)) return false;
1494
1494
  var spreadable = O[IS_CONCAT_SPREADABLE];
1495
1495
  return spreadable !== undefined ? !!spreadable : isArray$1(O);
1496
1496
  };
@@ -3103,7 +3103,7 @@ var hasOwn$3 = hasOwnProperty_1;
3103
3103
  var bind$7 = functionBindContext;
3104
3104
  var classof$2 = classof$8;
3105
3105
  var anObject$5 = anObject$h;
3106
- var isObject$5 = isObject$d;
3106
+ var isObject$4 = isObject$c;
3107
3107
  var $toString$2 = toString$9;
3108
3108
  var create = objectCreate;
3109
3109
  var createPropertyDescriptor = createPropertyDescriptor$5;
@@ -3206,7 +3206,7 @@ var URLSearchParamsState = function (init) {
3206
3206
  this.url = null;
3207
3207
 
3208
3208
  if (init !== undefined) {
3209
- if (isObject$5(init)) this.parseObject(init);
3209
+ if (isObject$4(init)) this.parseObject(init);
3210
3210
  else this.parseQuery(typeof init == 'string' ? charAt$1(init, 0) === '?' ? stringSlice$2(init, 1) : init : $toString$2(init));
3211
3211
  }
3212
3212
  };
@@ -3423,7 +3423,7 @@ if (!USE_NATIVE_URL$1 && isCallable$3(Headers)) {
3423
3423
  var headersSet = uncurryThis$d(HeadersPrototype.set);
3424
3424
 
3425
3425
  var wrapRequestOptions = function (init) {
3426
- if (isObject$5(init)) {
3426
+ if (isObject$4(init)) {
3427
3427
  var body = init.body;
3428
3428
  var headers;
3429
3429
  if (classof$2(body) === URL_SEARCH_PARAMS) {
@@ -4522,7 +4522,7 @@ var functionApply = typeof Reflect == 'object' && Reflect.apply || (NATIVE_BIND
4522
4522
  return call$3.apply(apply$2, arguments);
4523
4523
  });
4524
4524
 
4525
- var isObject$4 = isObject$d;
4525
+ var isObject$3 = isObject$c;
4526
4526
  var classof$1 = classofRaw$1;
4527
4527
  var wellKnownSymbol$5 = wellKnownSymbol$m;
4528
4528
 
@@ -4532,7 +4532,7 @@ var MATCH$1 = wellKnownSymbol$5('match');
4532
4532
  // https://tc39.es/ecma262/#sec-isregexp
4533
4533
  var isRegexp = function (it) {
4534
4534
  var isRegExp;
4535
- return isObject$4(it) && ((isRegExp = it[MATCH$1]) !== undefined ? !!isRegExp : classof$1(it) == 'RegExp');
4535
+ return isObject$3(it) && ((isRegExp = it[MATCH$1]) !== undefined ? !!isRegExp : classof$1(it) == 'RegExp');
4536
4536
  };
4537
4537
 
4538
4538
  var global$f = global$T;
@@ -4957,7 +4957,7 @@ $$d({ target: 'Number', stat: true }, {
4957
4957
  });
4958
4958
 
4959
4959
  var isCallable$2 = isCallable$k;
4960
- var isObject$3 = isObject$d;
4960
+ var isObject$2 = isObject$c;
4961
4961
  var setPrototypeOf$1 = objectSetPrototypeOf;
4962
4962
 
4963
4963
  // makes subclassing work correct for wrapped built-ins
@@ -4969,7 +4969,7 @@ var inheritIfRequired$1 = function ($this, dummy, Wrapper) {
4969
4969
  // we haven't completely correct pre-ES6 way for getting `new.target`, so use this
4970
4970
  isCallable$2(NewTarget = dummy.constructor) &&
4971
4971
  NewTarget !== Wrapper &&
4972
- isObject$3(NewTargetPrototype = NewTarget.prototype) &&
4972
+ isObject$2(NewTargetPrototype = NewTarget.prototype) &&
4973
4973
  NewTargetPrototype !== Wrapper.prototype
4974
4974
  ) setPrototypeOf$1($this, NewTargetPrototype);
4975
4975
  return $this;
@@ -17057,40 +17057,6 @@ var getBoundsFromMarkers = (function () {
17057
17057
  return getBounds(markersFlatted);
17058
17058
  });
17059
17059
 
17060
- /**
17061
- * Sets the map center based on the provided markers or a default center value.
17062
- * @param {Object} center A default center object with latitude and longitude values.
17063
- * @param {number} center.lat The latitude value of the default center.
17064
- * @param {number} center.lng The longitude value of the default center.
17065
- */
17066
-
17067
- var getCenterByGeolocationOrCenter = (function () {
17068
- var center = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
17069
- if (validateCoordinates(center)) return center;
17070
- return getGeolocationCoordinates();
17071
- });
17072
-
17073
- /**
17074
- * Retrieves the current geolocation of the user and updates the map's center coordinates.
17075
- */
17076
- var getGeolocationCoordinates = (function () {
17077
- try {
17078
- navigator.geolocation.getCurrentPosition(function () {
17079
- var pos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
17080
- var _pos$coords = pos.coords,
17081
- lat = _pos$coords.latitude,
17082
- lng = _pos$coords.longitude;
17083
- return {
17084
- lat: lat,
17085
- lng: lng
17086
- };
17087
- });
17088
- } catch (error) {
17089
- console.log(error);
17090
- return {};
17091
- }
17092
- });
17093
-
17094
17060
  var LIBRARIES = ['geometry', 'drawing', 'places'];
17095
17061
  var DEFAULT_CENTER = {
17096
17062
  lat: 0,
@@ -17269,15 +17235,6 @@ var getParsedComponents = (function () {
17269
17235
  });
17270
17236
  });
17271
17237
 
17272
- /**
17273
- * Function to check if a value is an object
17274
- * @param {*} value Value to check if it is an object
17275
- * @returns Returns true if the value is an object
17276
- */
17277
- var isObject$2 = function isObject(value) {
17278
- return _typeof(value) === 'object' && !Array.isArray(value) && value instanceof Object;
17279
- };
17280
-
17281
17238
  var global$7 = global$T;
17282
17239
 
17283
17240
  var nativePromiseConstructor = global$7.Promise;
@@ -17610,7 +17567,7 @@ newPromiseCapability$2.f = function (C) {
17610
17567
  };
17611
17568
 
17612
17569
  var anObject = anObject$h;
17613
- var isObject$1 = isObject$d;
17570
+ var isObject$1 = isObject$c;
17614
17571
  var newPromiseCapability$1 = newPromiseCapability$2;
17615
17572
 
17616
17573
  var promiseResolve$1 = function (C, x) {
@@ -17677,7 +17634,7 @@ var setToStringTag = setToStringTag$5;
17677
17634
  var setSpecies = setSpecies$1;
17678
17635
  var aCallable = aCallable$7;
17679
17636
  var isCallable = isCallable$k;
17680
- var isObject = isObject$d;
17637
+ var isObject = isObject$c;
17681
17638
  var anInstance = anInstance$3;
17682
17639
  var inspectSource = inspectSource$4;
17683
17640
  var iterate = iterate$1;
@@ -35397,28 +35354,6 @@ var parsePlaces = (function (places, parsedData) {
35397
35354
  }, _objectSpread2({}, parsedData));
35398
35355
  });
35399
35356
 
35400
- /**
35401
- * @function validateCoordinates
35402
- * @description return true or false is region has latitude and longitude keys and type number
35403
- * @param {object} coordinates - object with latitude and longitude
35404
- * @param {number} coordinates.lng - longitude
35405
- * @param {number} coordinates.lat - latitude
35406
- * @returns {boolean}
35407
- * @example isValidRegionData({latitude: -345345, longitude: -345435345}) => true
35408
- * @example isValidRegionData({latitude: -345345, longitude: '3453453453'}) => false
35409
- * @example isValidRegionData({latitude: -345345}) => false
35410
- */
35411
-
35412
- var validateCoordinates = (function () {
35413
- var coordinates = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
35414
- if (!isObject$2(coordinates) || !Object.keys(coordinates).length) return false;
35415
- var lng = coordinates.lng,
35416
- lat = coordinates.lat;
35417
- if (!lng || !lat) return false;
35418
- if (!lodash.exports.isNumber(lng) || !lodash.exports.isNumber(lat)) return false;
35419
- return true;
35420
- });
35421
-
35422
35357
  var styled = {
35423
35358
  LoadingElement: styled$g.div.withConfig({
35424
35359
  displayName: "styles__LoadingElement",
@@ -35486,8 +35421,7 @@ var SearchBox = function SearchBox(_ref) {
35486
35421
  };
35487
35422
 
35488
35423
  var _excluded = ["googleMapsApiKey", "width", "height", "center", "zoom", "markers", "markerOptions", "options", "callbackOnSuccessDirections", "callbackOnErrorDirections"];
35489
-
35490
- var Map$1 = function Map(_ref) {
35424
+ var Map$1 = /*#__PURE__*/forwardRef(function (_ref, ref) {
35491
35425
  var _mapRef$current;
35492
35426
 
35493
35427
  var _ref$googleMapsApiKey = _ref.googleMapsApiKey,
@@ -35496,8 +35430,7 @@ var Map$1 = function Map(_ref) {
35496
35430
  width = _ref$width === void 0 ? '800px' : _ref$width,
35497
35431
  _ref$height = _ref.height,
35498
35432
  height = _ref$height === void 0 ? '400px' : _ref$height,
35499
- _ref$center = _ref.center,
35500
- center = _ref$center === void 0 ? DEFAULT_CENTER : _ref$center,
35433
+ center = _ref.center,
35501
35434
  _ref$zoom = _ref.zoom,
35502
35435
  zoom = _ref$zoom === void 0 ? 13 : _ref$zoom,
35503
35436
  _ref$markers = _ref.markers,
@@ -35540,7 +35473,7 @@ var Map$1 = function Map(_ref) {
35540
35473
  mapRef.current.panTo(newCenter);
35541
35474
  };
35542
35475
 
35543
- var onLoad = useCallback(function (map) {
35476
+ var onLoad = function onLoad(map) {
35544
35477
  if (!map) return;
35545
35478
  mapRef.current = map;
35546
35479
  mapRef.current.setOptions({
@@ -35549,10 +35482,22 @@ var Map$1 = function Map(_ref) {
35549
35482
  var fullScreenPos = mapOptions.showSearchBar ? 'RIGHT_BOTTOM' : 'RIGHT_TOP';
35550
35483
  handlePositions('fullScreen', window.google.maps.ControlPosition[fullScreenPos]);
35551
35484
  handlePositions('zoom', window.google.maps.ControlPosition.RIGHT_BOTTOM);
35552
- if (!(markers !== null && markers !== void 0 && markers.length)) mapRef.current.setCenter(getCenterByGeolocationOrCenter(center || DEFAULT_CENTER));
35553
- if (markers !== null && markers !== void 0 && markers.length) mapRef.current.fitBounds(getBoundsFromMarkers(markers));
35554
- mapRef.current.setZoom(zoom);
35555
- }, [center, markers, options, zoom]);
35485
+ if (!(markers !== null && markers !== void 0 && markers.length)) mapRef.current.setCenter(center || DEFAULT_CENTER);
35486
+ mapRef.current.setZoom(!center ? 2 : zoom);
35487
+ };
35488
+
35489
+ useImperativeHandle(ref, function () {
35490
+ return {
35491
+ setZoom: function setZoom(zoom) {
35492
+ return mapRef.current.setZoom(zoom);
35493
+ }
35494
+ };
35495
+ });
35496
+ useEffect(function () {
35497
+ if (mapRef.current && markers !== null && markers !== void 0 && markers.length) {
35498
+ mapRef.current.fitBounds(getBoundsFromMarkers(markers));
35499
+ }
35500
+ }, [mapRef.current, markers]);
35556
35501
  if (!isLoaded) return null;
35557
35502
  return /*#__PURE__*/React__default.createElement(GoogleMap, _extends$1({
35558
35503
  className: "google-map-component",
@@ -35562,7 +35507,7 @@ var Map$1 = function Map(_ref) {
35562
35507
  width: width
35563
35508
  },
35564
35509
  options: mapOptions,
35565
- center: (_mapRef$current = mapRef.current) === null || _mapRef$current === void 0 ? void 0 : _mapRef$current.center
35510
+ center: (_mapRef$current = mapRef.current) === null || _mapRef$current === void 0 ? void 0 : _mapRef$current.getCenter()
35566
35511
  }, props), mapOptions.showSearchBar && /*#__PURE__*/React__default.createElement(SearchBox, {
35567
35512
  updateMarker: updateMarker,
35568
35513
  className: "google-map-component__search-box"
@@ -35574,7 +35519,8 @@ var Map$1 = function Map(_ref) {
35574
35519
  callbackOnErrorDirections: callbackOnErrorDirections,
35575
35520
  googleMapsApiKey: googleMapsApiKey
35576
35521
  }));
35577
- };
35522
+ });
35523
+ Map$1.displayName = 'Map';
35578
35524
 
35579
35525
  var rotate = keyframes(["to{transform:rotate(360deg);}"]);
35580
35526
  var Spinner$1 = styled$g.div.withConfig({