@reactuses/core 5.0.17 → 5.0.18

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/index.cjs CHANGED
@@ -1501,6 +1501,7 @@ const initCoord = {
1501
1501
  };
1502
1502
  const useGeolocation = (options = defaultOptions$1)=>{
1503
1503
  const { enableHighAccuracy = true, maximumAge = 30000, timeout = 27000 } = options;
1504
+ const isSupported = useSupported(()=>navigator && 'geolocation' in navigator);
1504
1505
  const [coordinates, setCoordinates] = React.useState(initCoord);
1505
1506
  const [locatedAt, setLocatedAt] = React.useState(null);
1506
1507
  const [error, setError] = React.useState(null);
@@ -1515,6 +1516,9 @@ const useGeolocation = (options = defaultOptions$1)=>{
1515
1516
  setError(err);
1516
1517
  }, []);
1517
1518
  React.useEffect(()=>{
1519
+ if (!isSupported) {
1520
+ return;
1521
+ }
1518
1522
  navigator.geolocation.getCurrentPosition(updatePosition, updateError);
1519
1523
  const watchId = navigator.geolocation.watchPosition(updatePosition, updateError, {
1520
1524
  enableHighAccuracy,
@@ -1528,6 +1532,7 @@ const useGeolocation = (options = defaultOptions$1)=>{
1528
1532
  };
1529
1533
  }, [
1530
1534
  enableHighAccuracy,
1535
+ isSupported,
1531
1536
  maximumAge,
1532
1537
  timeout,
1533
1538
  updateError,
@@ -1536,7 +1541,8 @@ const useGeolocation = (options = defaultOptions$1)=>{
1536
1541
  return {
1537
1542
  coordinates,
1538
1543
  locatedAt,
1539
- error
1544
+ error,
1545
+ isSupported
1540
1546
  };
1541
1547
  };
1542
1548
 
package/dist/index.d.cts CHANGED
@@ -981,14 +981,16 @@ declare const useFullscreen: UseFullscreen;
981
981
 
982
982
  /**
983
983
  * @title useGeoLocation
984
- * @returns 包含以下元素的元组:
984
+ * @returns 包含以下元素的对象:
985
985
  * - 坐标。
986
986
  * - 获取坐标的时间戳。
987
987
  * - 错误。
988
- * @returns_en A tuple with the following elements:
988
+ * - 浏览器是否支持 `geolocation`。
989
+ * @returns_en A object with the following elements:
989
990
  * - coordinates.
990
991
  * - timestamp when get coordinates.
991
992
  * - errors.
993
+ * - Whether the browser supports `geolocation`.
992
994
  */
993
995
  type UseGeolocation = (
994
996
  /**
@@ -999,6 +1001,11 @@ options?: Partial<PositionOptions>) => {
999
1001
  readonly coordinates: GeolocationCoordinates;
1000
1002
  readonly locatedAt: number | null;
1001
1003
  readonly error: GeolocationPositionError | null;
1004
+ /**
1005
+ * @zh 浏览器是否支持 `geolocation`
1006
+ * @en Whether the browser supports `geolocation`
1007
+ */
1008
+ readonly isSupported: boolean;
1002
1009
  };
1003
1010
 
1004
1011
  declare const useGeolocation: UseGeolocation;
package/dist/index.d.mts CHANGED
@@ -981,14 +981,16 @@ declare const useFullscreen: UseFullscreen;
981
981
 
982
982
  /**
983
983
  * @title useGeoLocation
984
- * @returns 包含以下元素的元组:
984
+ * @returns 包含以下元素的对象:
985
985
  * - 坐标。
986
986
  * - 获取坐标的时间戳。
987
987
  * - 错误。
988
- * @returns_en A tuple with the following elements:
988
+ * - 浏览器是否支持 `geolocation`。
989
+ * @returns_en A object with the following elements:
989
990
  * - coordinates.
990
991
  * - timestamp when get coordinates.
991
992
  * - errors.
993
+ * - Whether the browser supports `geolocation`.
992
994
  */
993
995
  type UseGeolocation = (
994
996
  /**
@@ -999,6 +1001,11 @@ options?: Partial<PositionOptions>) => {
999
1001
  readonly coordinates: GeolocationCoordinates;
1000
1002
  readonly locatedAt: number | null;
1001
1003
  readonly error: GeolocationPositionError | null;
1004
+ /**
1005
+ * @zh 浏览器是否支持 `geolocation`
1006
+ * @en Whether the browser supports `geolocation`
1007
+ */
1008
+ readonly isSupported: boolean;
1002
1009
  };
1003
1010
 
1004
1011
  declare const useGeolocation: UseGeolocation;
package/dist/index.d.ts CHANGED
@@ -981,14 +981,16 @@ declare const useFullscreen: UseFullscreen;
981
981
 
982
982
  /**
983
983
  * @title useGeoLocation
984
- * @returns 包含以下元素的元组:
984
+ * @returns 包含以下元素的对象:
985
985
  * - 坐标。
986
986
  * - 获取坐标的时间戳。
987
987
  * - 错误。
988
- * @returns_en A tuple with the following elements:
988
+ * - 浏览器是否支持 `geolocation`。
989
+ * @returns_en A object with the following elements:
989
990
  * - coordinates.
990
991
  * - timestamp when get coordinates.
991
992
  * - errors.
993
+ * - Whether the browser supports `geolocation`.
992
994
  */
993
995
  type UseGeolocation = (
994
996
  /**
@@ -999,6 +1001,11 @@ options?: Partial<PositionOptions>) => {
999
1001
  readonly coordinates: GeolocationCoordinates;
1000
1002
  readonly locatedAt: number | null;
1001
1003
  readonly error: GeolocationPositionError | null;
1004
+ /**
1005
+ * @zh 浏览器是否支持 `geolocation`
1006
+ * @en Whether the browser supports `geolocation`
1007
+ */
1008
+ readonly isSupported: boolean;
1002
1009
  };
1003
1010
 
1004
1011
  declare const useGeolocation: UseGeolocation;
package/dist/index.mjs CHANGED
@@ -1493,6 +1493,7 @@ const initCoord = {
1493
1493
  };
1494
1494
  const useGeolocation = (options = defaultOptions$1)=>{
1495
1495
  const { enableHighAccuracy = true, maximumAge = 30000, timeout = 27000 } = options;
1496
+ const isSupported = useSupported(()=>navigator && 'geolocation' in navigator);
1496
1497
  const [coordinates, setCoordinates] = useState(initCoord);
1497
1498
  const [locatedAt, setLocatedAt] = useState(null);
1498
1499
  const [error, setError] = useState(null);
@@ -1507,6 +1508,9 @@ const useGeolocation = (options = defaultOptions$1)=>{
1507
1508
  setError(err);
1508
1509
  }, []);
1509
1510
  useEffect(()=>{
1511
+ if (!isSupported) {
1512
+ return;
1513
+ }
1510
1514
  navigator.geolocation.getCurrentPosition(updatePosition, updateError);
1511
1515
  const watchId = navigator.geolocation.watchPosition(updatePosition, updateError, {
1512
1516
  enableHighAccuracy,
@@ -1520,6 +1524,7 @@ const useGeolocation = (options = defaultOptions$1)=>{
1520
1524
  };
1521
1525
  }, [
1522
1526
  enableHighAccuracy,
1527
+ isSupported,
1523
1528
  maximumAge,
1524
1529
  timeout,
1525
1530
  updateError,
@@ -1528,7 +1533,8 @@ const useGeolocation = (options = defaultOptions$1)=>{
1528
1533
  return {
1529
1534
  coordinates,
1530
1535
  locatedAt,
1531
- error
1536
+ error,
1537
+ isSupported
1532
1538
  };
1533
1539
  };
1534
1540
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactuses/core",
3
- "version": "5.0.17",
3
+ "version": "5.0.18",
4
4
  "license": "Unlicense",
5
5
  "homepage": "https://www.reactuse.com/",
6
6
  "repository": {