Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-autosuggest-geocoder

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-autosuggest-geocoder - npm Package Compare versions

Comparing version 1.0.0-beta.3 to 1.0.0-beta.4

2

package.json
{
"name": "react-autosuggest-geocoder",
"description": "Autosuggest addresses using a Pelias service.",
"version": "1.0.0-beta.3",
"version": "1.0.0-beta.4",
"repository": "https://github.com/abec/react-autosuggest-geocoder",

@@ -6,0 +6,0 @@ "main": "src/index.js",

@@ -21,2 +21,3 @@

onSearchSelected: React.PropTypes.func,
onSuggestionSelected: React.PropTypes.func,

@@ -54,2 +55,4 @@ onReverseSelected: React.PropTypes.func,

this.fetch_request_number = 0;
this._onSuggestionsFetchRequested = _.debounce(this.onSuggestionsFetchRequested, this.props.fetchDelay);

@@ -62,9 +65,11 @@ }

reverse (center, bounds) {
const url = this.props.url + '/reverse';
queryParameters ({ apiKey, sources, focus, center, bounds }, extra = {}) {
const data = {
api_key: this.props.apiKey,
layers: 'address',
size: 1
api_key: apiKey,
sources: sources
};
if (focus) {
data['focus.point.lat'] = focus.latitude;
data['focus.point.lon'] = focus.longitude;
}
if (center) {

@@ -80,2 +85,16 @@ data['point.lat'] = center.latitude;

}
return _.assign({}, data, extra);
}
reverse (center, bounds) {
const url = this.props.url + '/reverse';
const { apiKey } = this.props;
const data = this.queryParameters({
apiKey,
center,
bounds
}, {
layers: 'address',
size: 1
});
return fetch(url + '?' + stringify(data), {

@@ -92,7 +111,12 @@ method: 'get',

const url = this.props.url + '/search';
return fetch(url + '?' + stringify({
api_key: this.props.apiKey,
sources: this.props.sources,
const { apiKey, sources, center, bounds } = this.props;
const data = this.queryParameters({
apiKey,
sources,
focus: center,
bounds
}, {
text: text
}), {
});
return fetch(url + '?' + stringify(data), {
method: 'get',

@@ -108,17 +132,11 @@ headers: {

const url = this.props.url + '/autocomplete';
const data = {
api_key: this.props.apiKey,
sources: this.props.sources,
const { apiKey, sources, center, bounds } = this.props;
const data = this.queryParameters({
apiKey,
sources,
focus: center,
bounds
}, {
text: text
};
if (this.props.center) {
data['focus.point.lat'] = this.props.center.latitude;
data['focus.point.lon'] = this.props.center.longitude;
}
if (this.props.bounds) {
data['boundary.rect.min_lon'] = this.props.bounds[0];
data['boundary.rect.min_lat'] = this.props.bounds[1];
data['boundary.rect.max_lon'] = this.props.bounds[2];
data['boundary.rect.max_lat'] = this.props.bounds[3];
}
});
return fetch(url + '?' + stringify(data), {

@@ -172,3 +190,3 @@ method: 'get',

onChange = (event, { newValue }) => {
onChange = (event, { newValue, method }) => {
this.setState({

@@ -181,8 +199,12 @@ value: newValue,

onSuggestionsFetchRequested = ({ value }) => {
let request_number = this.fetch_request_number = (this.fetch_request_number + 1) % 10;
return this.autocomplete(value).then((data) => {
this.setState({
suggestions: _.uniqBy(data.features, (feature) => {
return feature.properties.label;
})
});
if (request_number === this.fetch_request_number) {
this.setState({
suggestions: _.uniqBy(data.features, (feature) => {
return feature.properties.label;
})
});
}
});

@@ -198,10 +220,48 @@ };

onSuggestionSelected = (event, { suggestion, suggestionValue, suggestionIndex, sectionIndex, method }) => {
if (this.props.onSuggestionSelected) {
return this.props.onSuggestionSelected(event, { suggestion, suggestionValue, suggestionIndex, sectionIndex, method });
}
};
onEnterCapture = (event) => {
if (event.keyCode !== 13) {
return;
}
if (!this.autosuggest) {
return;
}
if (this.autosuggest.getHighlightedSuggestion() !== null) {
return;
}
return this.onEnterWithoutHighlight(event);
};
onEnterWithoutHighlight = (event) => {
let { value } = this.state;
let suggestionValue = value;
return this.search(suggestionValue).then((data) => {
if (!data) {
return;
}
if (!data.features) {
return;
}
if (!data.features.length) {
return;
}
let suggestion = data.features[0];
this.setState({
selected: true,
value: suggestionValue
value: suggestion.properties.label
});
if (this.props.onSuggestionSelected) {
return this.props.onSuggestionSelected(event, { search: data, suggestion, suggestionValue, suggestionIndex, sectionIndex, method });
if (this.props.onSearchSelected) {
return this.props.onSearchSelected(event, { search: data, suggestion, suggestionValue, method: 'enter' });
}

@@ -221,3 +281,3 @@ });

} = this.props;
const { onFocus, onBlur, ...restOfInputProps } = (inputProps || {});
const { onFocus, onBlur, onKeyDownCapture, ...restOfInputProps } = (inputProps || {});

@@ -234,3 +294,4 @@ return (

onFocus: e => _.isFunction(onFocus) ? onFocus(e) : undefined,
onBlur: e => _.isFunction(onBlur) ? onBlur(e) : undefined
onBlur: e => _.isFunction(onBlur) ? onBlur(e) : undefined,
onKeyDownCapture: this.onEnterCapture
})}

@@ -237,0 +298,0 @@ ref={(autosuggestRef) => {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc