Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"plugins": ["react", "import", "react-hooks", "@typescript-eslint"],
"plugins": ["react", "import", "react-hooks", "@typescript-eslint", "codegen"],
"extends": ["prettier", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"env": {
Expand Down Expand Up @@ -320,6 +320,7 @@
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/no-unused-vars": ["error"],
"@typescript-eslint/no-use-before-define": ["error"]
"@typescript-eslint/no-use-before-define": ["error"],
"codegen/codegen": "error"
}
}
2,608 changes: 1,893 additions & 715 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
"url": "git://github.com/ubilabs/google-maps-react-hooks.git"
},
"scripts": {
"build": "rm -rf dist/* && microbundle -o dist/index.js -f modern,umd --external react=React --sourcemap false --jsx React.createElement --no-compress --tsconfig ./tsconfig.json",
"dev": "rm -rf dist/* && microbundle watch -o dist/index.js -f modern,umd --external react=React --sourcemap false --jsx React.createElement --no-compress --tsconfig ./tsconfig.json",
"build": "npm run barrel && npm run microbundle:build",
"start": "npm run barrel:watch && npm run mircobundle:dev",
"microbundle:build": "rm -rf dist/* && microbundle -o dist/index.js -f modern,umd --external react=React --sourcemap false --jsx React.createElement --no-compress --tsconfig ./tsconfig.json",
"microbundle:dev": "rm -rf dist/* && microbundle watch -o dist/index.js -f modern,umd --external react=React --sourcemap false --jsx React.createElement --no-compress --tsconfig ./tsconfig.json",
"lint": "eslint './{src,examples}/**/*.{ts,tsx}'",
"types": "tsc --project tsconfig.json --noEmit",
"test": "npm run lint && npm run types",
Expand All @@ -22,6 +24,8 @@
"preversion": "npm run test",
"version": "npm run changelog && git checkout -b chore/release-${npm_package_version} && git add .",
"postversion": "git push -u origin chore/release-${npm_package_version} && git push --tags --no-verify",
"barrel": "eslint --fix src/index.ts",
"barrel:watch": "nodemon --delay 1 -e ts,tsx --watch src/hooks -x 'npm run barrel --silent || exit 1'",
"postinstall": "npm install --prefix examples",
"start:sample-map": "cd examples && npm run clean-examples && npm run start:map",
"start:map-with-markers": "cd examples && npm run clean-examples && npm run start:map-markers",
Expand All @@ -45,11 +49,13 @@
"conventional-changelog-cli": "^2.1.1",
"eslint": "^8.25.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-codegen": "^0.16.1",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"microbundle": "^0.15.1",
"nodemon": "^2.0.20",
"prettier": "^2.3.2",
"typescript": "^4.3.5"
},
Expand Down
8 changes: 3 additions & 5 deletions src/hooks/autocomplete.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {useState, useRef, useEffect} from 'react';

import useGoogleMap from './map-instance';
import {useGoogleMap} from './map-instance';

interface AutocompleteProps {
export interface AutocompleteProps {
inputField: HTMLInputElement | null;
options?: google.maps.places.AutocompleteOptions;
onPlaceChanged: (place: google.maps.places.PlaceResult) => void;
Expand All @@ -12,7 +12,7 @@ interface AutocompleteProps {
* Hook to get a Google Maps Places Autocomplete instance
* monitoring an input field
*/
const useAutocomplete = (
export const useAutocomplete = (
props: AutocompleteProps
): google.maps.places.Autocomplete | null => {
const {inputField, options, onPlaceChanged} = props;
Expand Down Expand Up @@ -57,5 +57,3 @@ const useAutocomplete = (

return autocomplete;
};

export default useAutocomplete;
10 changes: 5 additions & 5 deletions src/hooks/directions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {useMemo, useEffect, useCallback} from 'react';

import useGoogleMap from './map-instance';
import {useGoogleMap} from './map-instance';

interface DirectionsProps {
export interface DirectionsProps {
renderOnMap?: boolean;
renderOptions?: google.maps.DirectionsRendererOptions;
}
Expand All @@ -25,7 +25,9 @@ interface DirectionsHookReturns {
/**
* Hook to get Google Maps Places Directions Service instance
*/
const useDirections = (props: DirectionsProps = {}): DirectionsHookReturns => {
export const useDirections = (
props: DirectionsProps = {}
): DirectionsHookReturns => {
const {renderOnMap, renderOptions} = props;
const {map, loading} = useGoogleMap();

Expand Down Expand Up @@ -131,5 +133,3 @@ const useDirections = (props: DirectionsProps = {}): DirectionsHookReturns => {
renderRouteOfIndex
};
};

export default useDirections;
6 changes: 2 additions & 4 deletions src/hooks/distance-matrix.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {useMemo} from 'react';

import useGoogleMap from './map-instance';
import {useGoogleMap} from './map-instance';

/**
* Hook to get Distance Matrix Service instance
*/
const useDistanceMatrix =
export const useDistanceMatrix =
(): google.maps.DistanceMatrixService | null => {
const {map} = useGoogleMap();

Expand All @@ -26,5 +26,3 @@ const useDistanceMatrix =

return distanceMatrixService;
};

export default useDistanceMatrix;
21 changes: 9 additions & 12 deletions src/hooks/elevation.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import {useMemo} from 'react';

import useGoogleMap from './map-instance';
import {useGoogleMap} from './map-instance';

/**
* Hook to get Elevation Service instance
*/
const useElevationService = (): google.maps.ElevationService | null => {
export const useElevationService = (): google.maps.ElevationService | null => {
const {map} = useGoogleMap();

// Creates an Elevation Service instance
const elevationService =
useMemo<google.maps.ElevationService | null>(() => {
// Wait for map to be initialized
if (!map) {
return null;
}
const elevationService = useMemo<google.maps.ElevationService | null>(() => {
// Wait for map to be initialized
if (!map) {
return null;
}

return new google.maps.ElevationService();
}, [map]);
return new google.maps.ElevationService();
}, [map]);

return elevationService;
};

export default useElevationService;
6 changes: 2 additions & 4 deletions src/hooks/geocoder.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {useMemo} from 'react';

import useGoogleMap from './map-instance';
import {useGoogleMap} from './map-instance';

/**
* Hook to get Google Maps Geocoder instance
*/
const useGeocoder = (): google.maps.Geocoder | null => {
export const useGeocoder = (): google.maps.Geocoder | null => {
const {map} = useGoogleMap();

// Creates a Geocoder instance
Expand All @@ -20,5 +20,3 @@ const useGeocoder = (): google.maps.Geocoder | null => {

return geocoder;
};

export default useGeocoder;
5 changes: 2 additions & 3 deletions src/hooks/map-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ import {GoogleMapContext, GoogleMapContextType} from '../map-provider';
/**
* Hook to get global map instance
*/
const useGoogleMap = (): GoogleMapContextType => useContext(GoogleMapContext);

export default useGoogleMap;
export const useGoogleMap = (): GoogleMapContextType =>
useContext(GoogleMapContext);
21 changes: 9 additions & 12 deletions src/hooks/max-zoom.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import {useMemo} from 'react';

import useGoogleMap from './map-instance';
import {useGoogleMap} from './map-instance';

/**
* Hook to get Max Zoom Service instance
*/
const useMaxZoomService = (): google.maps.MaxZoomService | null => {
export const useMaxZoomService = (): google.maps.MaxZoomService | null => {
const {map} = useGoogleMap();

// Creates a Max Zoom Service instance
const maxZoomService =
useMemo<google.maps.MaxZoomService | null>(() => {
// Wait for map to be initialized
if (!map) {
return null;
}
const maxZoomService = useMemo<google.maps.MaxZoomService | null>(() => {
// Wait for map to be initialized
if (!map) {
return null;
}

return new google.maps.MaxZoomService();
}, [map]);
return new google.maps.MaxZoomService();
}, [map]);

return maxZoomService;
};

export default useMaxZoomService;
6 changes: 2 additions & 4 deletions src/hooks/places.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {useMemo} from 'react';

import useGoogleMap from './map-instance';
import {useGoogleMap} from './map-instance';

/**
* Hook to get Google Maps Places Service instance
*/
const usePlacesService = (): google.maps.places.PlacesService | null => {
export const usePlacesService = (): google.maps.places.PlacesService | null => {
const {map} = useGoogleMap();

// Creates a Places Service instance
Expand All @@ -26,5 +26,3 @@ const usePlacesService = (): google.maps.places.PlacesService | null => {

return placesService;
};

export default usePlacesService;
18 changes: 10 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
export {default as GoogleMapProvider} from './map-provider';
export {default as useGoogleMap} from './hooks/map-instance';
export {default as usePlacesService} from './hooks/places';
export {default as useAutocomplete} from './hooks/autocomplete';
export {default as useDirections} from './hooks/directions';
export {default as useGeocoder} from './hooks/geocoder';
export {default as useDistanceMatrix} from './hooks/distance-matrix';

// codegen:start {preset: barrel, include: ./hooks/*.ts}
export * from './hooks/autocomplete';
export * from './hooks/directions';
export * from './hooks/distance-matrix';
export * from './hooks/elevation';
export * from './hooks/geocoder';
export * from './hooks/map-instance';
export * from './hooks/max-zoom';
export * from './hooks/places';
// codegen:end