330 lines
8.3 KiB
JavaScript
330 lines
8.3 KiB
JavaScript
"use strict"
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true,
|
|
})
|
|
exports.InfoWindow = undefined
|
|
|
|
var _defineProperty2 = require("babel-runtime/helpers/defineProperty")
|
|
|
|
var _defineProperty3 = _interopRequireDefault(_defineProperty2)
|
|
|
|
var _getPrototypeOf = require("babel-runtime/core-js/object/get-prototype-of")
|
|
|
|
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf)
|
|
|
|
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck")
|
|
|
|
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2)
|
|
|
|
var _createClass2 = require("babel-runtime/helpers/createClass")
|
|
|
|
var _createClass3 = _interopRequireDefault(_createClass2)
|
|
|
|
var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn")
|
|
|
|
var _possibleConstructorReturn3 = _interopRequireDefault(
|
|
_possibleConstructorReturn2
|
|
)
|
|
|
|
var _inherits2 = require("babel-runtime/helpers/inherits")
|
|
|
|
var _inherits3 = _interopRequireDefault(_inherits2)
|
|
|
|
var _InfoWindow$contextTy /*
|
|
* -----------------------------------------------------------------------------
|
|
* This file is auto-generated from the corresponding file at `src/macros/`.
|
|
* Please **DO NOT** edit this file directly when creating PRs.
|
|
* -----------------------------------------------------------------------------
|
|
*/
|
|
/* global google */
|
|
|
|
var _invariant = require("invariant")
|
|
|
|
var _invariant2 = _interopRequireDefault(_invariant)
|
|
|
|
var _canUseDom = require("can-use-dom")
|
|
|
|
var _canUseDom2 = _interopRequireDefault(_canUseDom)
|
|
|
|
var _react = require("react")
|
|
|
|
var _react2 = _interopRequireDefault(_react)
|
|
|
|
var _reactDom = require("react-dom")
|
|
|
|
var _reactDom2 = _interopRequireDefault(_reactDom)
|
|
|
|
var _propTypes = require("prop-types")
|
|
|
|
var _propTypes2 = _interopRequireDefault(_propTypes)
|
|
|
|
var _MapChildHelper = require("../utils/MapChildHelper")
|
|
|
|
var _constants = require("../constants")
|
|
|
|
function _interopRequireDefault(obj) {
|
|
return obj && obj.__esModule ? obj : { default: obj }
|
|
}
|
|
|
|
/**
|
|
* A wrapper around `google.maps.InfoWindow`
|
|
*
|
|
* @see https://developers.google.com/maps/documentation/javascript/3.exp/reference#InfoWindow
|
|
*/
|
|
var InfoWindow = (exports.InfoWindow = (function(_React$PureComponent) {
|
|
;(0, _inherits3.default)(InfoWindow, _React$PureComponent)
|
|
|
|
/*
|
|
* @see https://developers.google.com/maps/documentation/javascript/3.exp/reference#InfoWindow
|
|
*/
|
|
function InfoWindow(props, context) {
|
|
;(0, _classCallCheck3.default)(this, InfoWindow)
|
|
|
|
var _this = (0, _possibleConstructorReturn3.default)(
|
|
this,
|
|
(InfoWindow.__proto__ || (0, _getPrototypeOf2.default)(InfoWindow)).call(
|
|
this,
|
|
props,
|
|
context
|
|
)
|
|
)
|
|
|
|
var infoWindow = new google.maps.InfoWindow()
|
|
;(0, _MapChildHelper.construct)(
|
|
InfoWindow.propTypes,
|
|
updaterMap,
|
|
_this.props,
|
|
infoWindow
|
|
)
|
|
infoWindow.setMap(_this.context[_constants.MAP])
|
|
_this.state = (0, _defineProperty3.default)(
|
|
{},
|
|
_constants.INFO_WINDOW,
|
|
infoWindow
|
|
)
|
|
return _this
|
|
}
|
|
|
|
;(0, _createClass3.default)(InfoWindow, [
|
|
{
|
|
key: "componentWillMount",
|
|
value: function componentWillMount() {
|
|
if (!_canUseDom2.default || this.containerElement) {
|
|
return
|
|
}
|
|
if (_react2.default.version.match(/^16/)) {
|
|
this.containerElement = document.createElement("div")
|
|
}
|
|
},
|
|
},
|
|
{
|
|
key: "componentDidMount",
|
|
value: function componentDidMount() {
|
|
;(0, _MapChildHelper.componentDidMount)(
|
|
this,
|
|
this.state[_constants.INFO_WINDOW],
|
|
eventMap
|
|
)
|
|
if (_react2.default.version.match(/^16/)) {
|
|
this.state[_constants.INFO_WINDOW].setContent(this.containerElement)
|
|
open(
|
|
this.state[_constants.INFO_WINDOW],
|
|
this.context[_constants.ANCHOR]
|
|
)
|
|
this.containerElement = undefined
|
|
return
|
|
}
|
|
var content = document.createElement("div")
|
|
_reactDom2.default.unstable_renderSubtreeIntoContainer(
|
|
this,
|
|
_react2.default.Children.only(this.props.children),
|
|
content
|
|
)
|
|
this.state[_constants.INFO_WINDOW].setContent(content)
|
|
open(
|
|
this.state[_constants.INFO_WINDOW],
|
|
this.context[_constants.ANCHOR]
|
|
)
|
|
},
|
|
},
|
|
{
|
|
key: "componentDidUpdate",
|
|
value: function componentDidUpdate(prevProps) {
|
|
;(0, _MapChildHelper.componentDidUpdate)(
|
|
this,
|
|
this.state[_constants.INFO_WINDOW],
|
|
eventMap,
|
|
updaterMap,
|
|
prevProps
|
|
)
|
|
if (_react2.default.version.match(/^16/)) {
|
|
return
|
|
}
|
|
if (this.props.children !== prevProps.children) {
|
|
_reactDom2.default.unstable_renderSubtreeIntoContainer(
|
|
this,
|
|
_react2.default.Children.only(this.props.children),
|
|
this.state[_constants.INFO_WINDOW].getContent()
|
|
)
|
|
}
|
|
},
|
|
},
|
|
{
|
|
key: "componentWillUnmount",
|
|
value: function componentWillUnmount() {
|
|
;(0, _MapChildHelper.componentWillUnmount)(this)
|
|
var infoWindow = this.state[_constants.INFO_WINDOW]
|
|
if (infoWindow) {
|
|
if (
|
|
!_react2.default.version.match(/^16/) &&
|
|
infoWindow.getContent()
|
|
) {
|
|
_reactDom2.default.unmountComponentAtNode(infoWindow.getContent())
|
|
}
|
|
infoWindow.setMap(null)
|
|
}
|
|
},
|
|
},
|
|
{
|
|
key: "render",
|
|
value: function render() {
|
|
if (_react2.default.version.match(/^16/)) {
|
|
return _reactDom2.default.createPortal(
|
|
_react2.default.Children.only(this.props.children),
|
|
this.containerElement
|
|
)
|
|
}
|
|
return false
|
|
},
|
|
|
|
/**
|
|
*
|
|
* @type LatLng
|
|
* @public
|
|
*/
|
|
},
|
|
{
|
|
key: "getPosition",
|
|
value: function getPosition() {
|
|
return this.state[_constants.INFO_WINDOW].getPosition()
|
|
},
|
|
|
|
/**
|
|
*
|
|
* @type number
|
|
* @public
|
|
*/
|
|
},
|
|
{
|
|
key: "getZIndex",
|
|
value: function getZIndex() {
|
|
return this.state[_constants.INFO_WINDOW].getZIndex()
|
|
},
|
|
},
|
|
])
|
|
return InfoWindow
|
|
})(_react2.default.PureComponent))
|
|
|
|
InfoWindow.propTypes = {
|
|
/**
|
|
* @type InfoWindowOptions
|
|
*/
|
|
defaultOptions: _propTypes2.default.any,
|
|
|
|
/**
|
|
* @type LatLng|LatLngLiteral
|
|
*/
|
|
defaultPosition: _propTypes2.default.any,
|
|
|
|
/**
|
|
* @type number
|
|
*/
|
|
defaultZIndex: _propTypes2.default.number,
|
|
|
|
/**
|
|
* @type InfoWindowOptions
|
|
*/
|
|
options: _propTypes2.default.any,
|
|
|
|
/**
|
|
* @type LatLng|LatLngLiteral
|
|
*/
|
|
position: _propTypes2.default.any,
|
|
|
|
/**
|
|
* @type number
|
|
*/
|
|
zIndex: _propTypes2.default.number,
|
|
|
|
/**
|
|
* function
|
|
*/
|
|
onCloseClick: _propTypes2.default.func,
|
|
|
|
/**
|
|
* function
|
|
*/
|
|
onDomReady: _propTypes2.default.func,
|
|
|
|
/**
|
|
* function
|
|
*/
|
|
onContentChanged: _propTypes2.default.func,
|
|
|
|
/**
|
|
* function
|
|
*/
|
|
onPositionChanged: _propTypes2.default.func,
|
|
|
|
/**
|
|
* function
|
|
*/
|
|
onZindexChanged: _propTypes2.default.func,
|
|
}
|
|
InfoWindow.contextTypes = ((_InfoWindow$contextTy = {}),
|
|
(0, _defineProperty3.default)(
|
|
_InfoWindow$contextTy,
|
|
_constants.MAP,
|
|
_propTypes2.default.object
|
|
),
|
|
(0, _defineProperty3.default)(
|
|
_InfoWindow$contextTy,
|
|
_constants.ANCHOR,
|
|
_propTypes2.default.object
|
|
),
|
|
_InfoWindow$contextTy)
|
|
exports.default = InfoWindow
|
|
|
|
var open = function open(infoWindow, anchor) {
|
|
if (anchor) {
|
|
infoWindow.open(infoWindow.getMap(), anchor)
|
|
} else if (infoWindow.getPosition()) {
|
|
infoWindow.open(infoWindow.getMap())
|
|
} else {
|
|
;(0, _invariant2.default)(
|
|
false,
|
|
"You must provide either an anchor (typically render it inside a <Marker>) or a position props for <InfoWindow>."
|
|
)
|
|
}
|
|
}
|
|
|
|
var eventMap = {
|
|
onCloseClick: "closeclick",
|
|
onDomReady: "domready",
|
|
onContentChanged: "content_changed",
|
|
onPositionChanged: "position_changed",
|
|
onZindexChanged: "zindex_changed",
|
|
}
|
|
|
|
var updaterMap = {
|
|
options: function options(instance, _options) {
|
|
instance.setOptions(_options)
|
|
},
|
|
position: function position(instance, _position) {
|
|
instance.setPosition(_position)
|
|
},
|
|
zIndex: function zIndex(instance, _zIndex) {
|
|
instance.setZIndex(_zIndex)
|
|
},
|
|
}
|