From 7d66eb700d109f60fb550483578d0cc0b3235ede Mon Sep 17 00:00:00 2001 From: Robert Katzki Date: Thu, 22 Oct 2015 10:41:24 +0200 Subject: [PATCH] chore(release): version 1.12.0 --- CHANGELOG.md | 10 ++++++++ dist/react-geosuggest.js | 44 +++++++++++++++++++++++++++++------- dist/react-geosuggest.min.js | 2 +- package.json | 2 +- 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5112263..6076b933 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## 1.12.0 (2015-10-22) + + +#### Bug Fixes + +* doc comments, backward compatible changes ([96cca392](https://github.com/ubilabs/react-geosuggest/commit/96cca392f5b569247523cf784d34f1e1eb8b89d8)) +* add copy css in build module ([bb988a1c](https://github.com/ubilabs/react-geosuggest/commit/bb988a1c5bf3079b170cd24c79bbd21093f49f93)) +* googleMaps object moved out of props and set in componentDidMount ([955812df](https://github.com/ubilabs/react-geosuggest/commit/955812dfb702e8ea6318d89b2ef36d866c5c4354)) + + ### 1.11.1 (2015-10-12) diff --git a/dist/react-geosuggest.js b/dist/react-geosuggest.js index 8e9b78b7..f84105a9 100644 --- a/dist/react-geosuggest.js +++ b/dist/react-geosuggest.js @@ -34,7 +34,7 @@ var Geosuggest = _react2['default'].createClass({ bounds: null, country: null, types: null, - googleMaps: google && google.maps, + googleMaps: null, onSuggestSelect: function onSuggestSelect() {}, onFocus: function onFocus() {}, onBlur: function onBlur() {}, @@ -56,9 +56,7 @@ var Geosuggest = _react2['default'].createClass({ isSuggestsHidden: true, userInput: this.props.initialValue, activeSuggest: null, - suggests: [], - geocoder: new this.props.googleMaps.Geocoder(), - autocompleteService: new this.props.googleMaps.places.AutocompleteService() + suggests: [] }; }, @@ -72,6 +70,36 @@ var Geosuggest = _react2['default'].createClass({ } }, + /** + * Called on the client side after component is mounted. + * Google api sdk object will be obtained and cached as a instance property. + * Necessary objects of google api will also be determined and saved. + */ + componentDidMount: function componentDidMount() { + this.setInputValue(this.props.initialValue); + + var googleMaps = this.props.googleMaps || google && google.maps || this.googleMaps; + + if (!googleMaps) { + console.error('Google map api was not found in the page.'); + } else { + this.googleMaps = googleMaps; + } + + this.autocompleteService = new googleMaps.places.AutocompleteService(); + this.geocoder = new googleMaps.Geocoder(); + }, + + /** + * Method used for setting initial value. + * @param {string} value to set in input + */ + setInputValue: function setInputValue(value) { + this.setState({ + userInput: value + }); + }, + /** * When the input got changed */ @@ -121,7 +149,7 @@ var Geosuggest = _react2['default'].createClass({ var options = { input: this.state.userInput, - location: this.props.location || new this.props.googleMaps.LatLng(0, 0), + location: this.props.location || new this.googleMaps.LatLng(0, 0), radius: this.props.radius }; @@ -139,7 +167,7 @@ var Geosuggest = _react2['default'].createClass({ }; } - this.state.autocompleteService.getPlacePredictions(options, (function (suggestsGoogle) { + this.autocompleteService.getPlacePredictions(options, (function (suggestsGoogle) { this.updateSuggests(suggestsGoogle); if (this.props.autoActivateFirstSuggest) { @@ -296,8 +324,8 @@ var Geosuggest = _react2['default'].createClass({ * @param {Object} suggest The suggest */ geocodeSuggest: function geocodeSuggest(suggest) { - this.state.geocoder.geocode({ address: suggest.label }, (function (results, status) { - if (status !== this.props.googleMaps.GeocoderStatus.OK) { + this.geocoder.geocode({ address: suggest.label }, (function (results, status) { + if (status !== this.googleMaps.GeocoderStatus.OK) { return; } diff --git a/dist/react-geosuggest.min.js b/dist/react-geosuggest.min.js index 00800472..69853336 100644 --- a/dist/react-geosuggest.min.js +++ b/dist/react-geosuggest.min.js @@ -1 +1 @@ -!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.Geosuggest=t()}}(function(){return function t(e,s,i){function n(o,g){if(!s[o]){if(!e[o]){var a="function"==typeof require&&require;if(!g&&a)return a(o,!0);if(u)return u(o,!0);var r=new Error("Cannot find module '"+o+"'");throw r.code="MODULE_NOT_FOUND",r}var c=s[o]={exports:{}};e[o][0].call(c.exports,function(t){var s=e[o][1][t];return n(s?s:t)},c,c.exports,t,e,s,i)}return s[o].exports}for(var u="function"==typeof require&&require,o=0;o=u;u++)this.state.suggests[u]===this.state.activeSuggest&&(n=s?u+1:u-1);this.state.activeSuggest||(n=s?0:e),n>=0&&e>=n&&(i=this.state.suggests[n]),this.setState({activeSuggest:i})},selectSuggest:function(t){return t||(t={label:this.state.userInput}),this.setState({isSuggestsHidden:!0,userInput:t.label}),t.location?void this.props.onSuggestSelect(t):void this.geocodeSuggest(t)},geocodeSuggest:function(t){this.state.geocoder.geocode({address:t.label},function(e,s){if(s===this.props.googleMaps.GeocoderStatus.OK){var i=e[0],n=i.geometry.location;t.gmaps=i,t.location={lat:n.lat(),lng:n.lng()},this.props.onSuggestSelect(t)}}.bind(this))},render:function(){return n["default"].createElement("div",{className:"geosuggest "+this.props.className,onClick:this.onClick},n["default"].createElement("input",{className:"geosuggest__input",ref:"geosuggestInput",type:"text",value:this.state.userInput,placeholder:this.props.placeholder,disabled:this.props.disabled,onKeyDown:this.onInputKeyDown,onChange:this.onInputChange,onFocus:this.onFocus,onBlur:this.hideSuggests}),n["default"].createElement("ul",{className:this.getSuggestsClasses()},this.getSuggestItems()))},getSuggestItems:function(){return this.state.suggests.map(function(t){var e=this.state.activeSuggest&&t.placeId===this.state.activeSuggest.placeId;return n["default"].createElement(o["default"],{key:t.placeId,suggest:t,isActive:e,onSuggestSelect:this.selectSuggest})}.bind(this))},getSuggestsClasses:function(){var t="geosuggest__suggests";return t+=this.state.isSuggestsHidden?" geosuggest__suggests--hidden":""}});e.exports=g},{"./GeosuggestItem":2}],2:[function(t,e){"use strict";function s(t){return t&&t.__esModule?t:{"default":t}}var i=window.React,n=s(i),u=n["default"].createClass({displayName:"GeosuggestItem",getDefaultProps:function(){return{isActive:!1,suggest:{label:""},onSuggestSelect:function(){}}},onClick:function(t){t.preventDefault(),this.props.onSuggestSelect(this.props.suggest)},render:function(){return n["default"].createElement("li",{className:this.getSuggestClasses(),onClick:this.onClick},this.props.suggest.label)},getSuggestClasses:function(){var t=this.props.suggest.className,e="geosuggest-item";return e+=this.props.isActive?" geosuggest-item--active":"",e+=t?" "+t:""}});e.exports=u},{}]},{},[1])(1)}); \ No newline at end of file +!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.Geosuggest=t()}}(function(){return function t(e,s,i){function n(o,g){if(!s[o]){if(!e[o]){var a="function"==typeof require&&require;if(!g&&a)return a(o,!0);if(u)return u(o,!0);var r=new Error("Cannot find module '"+o+"'");throw r.code="MODULE_NOT_FOUND",r}var c=s[o]={exports:{}};e[o][0].call(c.exports,function(t){var s=e[o][1][t];return n(s?s:t)},c,c.exports,t,e,s,i)}return s[o].exports}for(var u="function"==typeof require&&require,o=0;o=u;u++)this.state.suggests[u]===this.state.activeSuggest&&(n=s?u+1:u-1);this.state.activeSuggest||(n=s?0:e),n>=0&&e>=n&&(i=this.state.suggests[n]),this.setState({activeSuggest:i})},selectSuggest:function(t){return t||(t={label:this.state.userInput}),this.setState({isSuggestsHidden:!0,userInput:t.label}),t.location?void this.props.onSuggestSelect(t):void this.geocodeSuggest(t)},geocodeSuggest:function(t){this.geocoder.geocode({address:t.label},function(e,s){if(s===this.googleMaps.GeocoderStatus.OK){var i=e[0],n=i.geometry.location;t.gmaps=i,t.location={lat:n.lat(),lng:n.lng()},this.props.onSuggestSelect(t)}}.bind(this))},render:function(){return n["default"].createElement("div",{className:"geosuggest "+this.props.className,onClick:this.onClick},n["default"].createElement("input",{className:"geosuggest__input",ref:"geosuggestInput",type:"text",value:this.state.userInput,placeholder:this.props.placeholder,disabled:this.props.disabled,onKeyDown:this.onInputKeyDown,onChange:this.onInputChange,onFocus:this.onFocus,onBlur:this.hideSuggests}),n["default"].createElement("ul",{className:this.getSuggestsClasses()},this.getSuggestItems()))},getSuggestItems:function(){return this.state.suggests.map(function(t){var e=this.state.activeSuggest&&t.placeId===this.state.activeSuggest.placeId;return n["default"].createElement(o["default"],{key:t.placeId,suggest:t,isActive:e,onSuggestSelect:this.selectSuggest})}.bind(this))},getSuggestsClasses:function(){var t="geosuggest__suggests";return t+=this.state.isSuggestsHidden?" geosuggest__suggests--hidden":""}});e.exports=g},{"./GeosuggestItem":2}],2:[function(t,e){"use strict";function s(t){return t&&t.__esModule?t:{"default":t}}var i=window.React,n=s(i),u=n["default"].createClass({displayName:"GeosuggestItem",getDefaultProps:function(){return{isActive:!1,suggest:{label:""},onSuggestSelect:function(){}}},onClick:function(t){t.preventDefault(),this.props.onSuggestSelect(this.props.suggest)},render:function(){return n["default"].createElement("li",{className:this.getSuggestClasses(),onClick:this.onClick},this.props.suggest.label)},getSuggestClasses:function(){var t=this.props.suggest.className,e="geosuggest-item";return e+=this.props.isActive?" geosuggest-item--active":"",e+=t?" "+t:""}});e.exports=u},{}]},{},[1])(1)}); \ No newline at end of file diff --git a/package.json b/package.json index 9f0a91ec..4354b00e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-geosuggest", - "version": "1.11.1", + "version": "1.12.0", "description": "A React autosuggest for the Google Maps Places API.", "main": "module/Geosuggest.js", "author": "Robert Katzki ",