Showing content from https://unpkg.com/react-autocomplete@1.8.0/dist/react-autocomplete.js below:
(function (g, factory) { if (typeof exports === 'object' && typeof module !== 'undefined') { module.exports = factory(require('react'), require('react-dom')) } else if (typeof define === 'function' && define.amd) { define(['react', 'react-dom'], factory) } else { g['ReactAutocomplete'] = factory(g['React'], g['ReactDOM']) } })(this, function (dep0, dep1) { return (function (require) { var define, module, exports // Reset to avoid causing problems for any nested UMDs return ((function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o< arguments.length; i++) source="arguments[i];" key in source) if (object.prototype.hasownproperty.call(source, key)) target[key]="source[key];" } return target; }; _createclass="function" () defineproperties(target, props) props.length; descriptor="props[i];" descriptor.enumerable="descriptor.enumerable" false; descriptor.configurable="true;" (value descriptor) descriptor.writable="true;" object.defineproperty(target, descriptor.key, descriptor); (constructor, protoprops, staticprops) (protoprops) defineproperties(constructor.prototype, protoprops); (staticprops) defineproperties(constructor, staticprops); constructor; }(); _classcallcheck(instance, constructor) (!(instance instanceof constructor)) throw new typeerror(cannot call a as function); _possibleconstructorreturn(self, call) (!self) referenceerror(this hasnt been initialised - super() called); && (typeof object typeof function) ? : self; _inherits(subclass, superclass) superclass !="=" function null) typeerror(super expression must either be null or function, not + superclass); subclass.prototype="Object.create(superClass" superclass.prototype, constructor: value: subclass, enumerable: false, writable: true, configurable: true }); (superclass) object.setprototypeof object.setprototypeof(subclass, subclass.__proto__="superClass;" react="require('react');" proptypes="require('prop-types');" _require="require('react-dom')," finddomnode="_require.findDOMNode;" scrollintoview="require('dom-scroll-into-view');" imperative_api="['blur'," checkvalidity, click, focus, select, setcustomvalidity, setselectionrange, setrangetext]; getscrolloffset() x: window.pagexoffset undefined (document.documentelement document.body.parentnode document.body).scrollleft, y: window.pageyoffset document.body).scrolltop autocomplete="function" (_react$component) _inherits(autocomplete, _react$component); autocomplete(props) _classcallcheck(this, autocomplete); _this="_possibleConstructorReturn(this," (autocomplete.__proto__ object.getprototypeof(autocomplete)).call(this, props)); _this.state="{" isopen: highlightedindex: _this._debugstates="[];" _this.ensurehighlightedindex="_this.ensureHighlightedIndex.bind(_this);" _this.exposeapi="_this.exposeAPI.bind(_this);" _this.handleinputfocus="_this.handleInputFocus.bind(_this);" _this.handleinputblur="_this.handleInputBlur.bind(_this);" _this.handlechange="_this.handleChange.bind(_this);" _this.handlekeydown="_this.handleKeyDown.bind(_this);" _this.handleinputclick="_this.handleInputClick.bind(_this);" _this.maybeautocompletetext="_this.maybeAutoCompleteText.bind(_this);" _this; _createclass(autocomplete, [{ key: componentwillmount, componentwillmount() this.refs is frozen, so we need to assign object it this._ignoreblur="false;" this._ignorefocus="false;" this._scrolloffset="null;" this._scrolltimer="null;" }, componentwillunmount, componentwillunmount() cleartimeout(this._scrolltimer); componentwillreceiveprops, componentwillreceiveprops(nextprops) (this.state.highlightedindex this.setstate(this.ensurehighlightedindex); (nextprops.autohighlight (this.props.value nextprops.value this.state.highlightedindex="==" null)) this.setstate(this.maybeautocompletetext); componentdidmount, componentdidmount() (this.isopen()) this.setmenupositions(); componentdidupdate, componentdidupdate(prevprops, prevstate) (this.state.isopen !prevstate.isopen open this.props this.props.open !prevprops.open) this.maybescrollitemintoview(); (prevstate.isopen this.state.isopen) this.props.onmenuvisibilitychange(this.state.isopen); exposeapi, exposeapi(el) _this2="this;" this.refs.input="el;" imperative_api.foreach(function (ev) _this2[ev]="el" el[ev] el[ev].bind(el); maybescrollitemintoview, maybescrollitemintoview() (this.isopen() itemnode="this.refs['item-'" this.state.highlightedindex]; menunode="this.refs.menu;" scrollintoview(finddomnode(itemnode), finddomnode(menunode), onlyscrollifneeded: handlekeydown, handlekeydown(event) (autocomplete.keydownhandlers[event.key]) autocomplete.keydownhandlers[event.key].call(this, event);else (!this.isopen()) this.setstate({ handlechange, handlechange(event) this.props.onchange(event, event.target.value); getfiltereditems, getfiltereditems(props) items="props.items;" (props.shoulditemrender) (item) props.shoulditemrender(item, props.value); (props.sortitems) items.sort(function (a, b) props.sortitems(a, b, items;> = this.getFilteredItems(props).length) { return { highlightedIndex: null }; } } }, { key: 'setMenuPositions', value: function setMenuPositions() { var node = this.refs.input; var rect = node.getBoundingClientRect(); var computedStyle = global.window.getComputedStyle(node); var marginBottom = parseInt(computedStyle.marginBottom, 10) || 0; var marginLeft = parseInt(computedStyle.marginLeft, 10) || 0; var marginRight = parseInt(computedStyle.marginRight, 10) || 0; this.setState({ menuTop: rect.bottom + marginBottom, menuLeft: rect.left + marginLeft, menuWidth: rect.width + marginLeft + marginRight }); } }, { key: 'highlightItemFromMouse', value: function highlightItemFromMouse(index) { this.setState({ highlightedIndex: index }); } }, { key: 'selectItemFromMouse', value: function selectItemFromMouse(item) { var _this3 = this; var value = this.props.getItemValue(item); // The menu will de-render before a mouseLeave event // happens. Clear the flag to release control over focus this.setIgnoreBlur(false); this.setState({ isOpen: false, highlightedIndex: null }, function () { _this3.props.onSelect(value, item); }); } }, { key: 'setIgnoreBlur', value: function setIgnoreBlur(ignore) { this._ignoreBlur = ignore; } }, { key: 'renderMenu', value: function renderMenu() { var _this4 = this; var items = this.getFilteredItems(this.props).map(function (item, index) { var element = _this4.props.renderItem(item, _this4.state.highlightedIndex === index, { cursor: 'default' }); return React.cloneElement(element, { onMouseEnter: _this4.props.isItemSelectable(item) ? function () { return _this4.highlightItemFromMouse(index); } : null, onClick: _this4.props.isItemSelectable(item) ? function () { return _this4.selectItemFromMouse(item); } : null, ref: function ref(e) { return _this4.refs['item-' + index] = e; } }); }); var style = { left: this.state.menuLeft, top: this.state.menuTop, minWidth: this.state.menuWidth }; var menu = this.props.renderMenu(items, this.props.value, style); return React.cloneElement(menu, { ref: function ref(e) { return _this4.refs.menu = e; }, // Ignore blur to prevent menu from de-rendering before we can process click onMouseEnter: function onMouseEnter() { return _this4.setIgnoreBlur(true); }, onMouseLeave: function onMouseLeave() { return _this4.setIgnoreBlur(false); } }); } }, { key: 'handleInputBlur', value: function handleInputBlur(event) { var _this5 = this; if (this._ignoreBlur) { this._ignoreFocus = true; this._scrollOffset = getScrollOffset(); this.refs.input.focus(); return; } var setStateCallback = void 0; var highlightedIndex = this.state.highlightedIndex; if (this.props.selectOnBlur && highlightedIndex !== null) { var items = this.getFilteredItems(this.props); var item = items[highlightedIndex]; var value = this.props.getItemValue(item); setStateCallback = function setStateCallback() { return _this5.props.onSelect(value, item); }; } this.setState({ isOpen: false, highlightedIndex: null }, setStateCallback); var onBlur = this.props.inputProps.onBlur; if (onBlur) { onBlur(event); } } }, { key: 'handleInputFocus', value: function handleInputFocus(event) { var _this6 = this; if (this._ignoreFocus) { this._ignoreFocus = false; var _scrollOffset = this._scrollOffset, x = _scrollOffset.x, y = _scrollOffset.y; this._scrollOffset = null; // Focus will cause the browser to scroll the into view. // This can cause the mouse coords to change, which in turn // could cause a new highlight to happen, cancelling the click // event (when selecting with the mouse) window.scrollTo(x, y); // Some browsers wait until all focus event handlers have been // processed before scrolling the into view, so let's // scroll again on the next tick to ensure we're back to where // the user was before focus was lost. We could do the deferred // scroll only, but that causes a jarring split second jump in // some browsers that scroll before the focus event handlers // are triggered. clearTimeout(this._scrollTimer); this._scrollTimer = setTimeout(function () { _this6._scrollTimer = null; window.scrollTo(x, y); }, 0); return; } this.setState({ isOpen: true }); var onFocus = this.props.inputProps.onFocus; if (onFocus) { onFocus(event); } } }, { key: 'isInputFocused', value: function isInputFocused() { var el = this.refs.input; return el.ownerDocument && el === el.ownerDocument.activeElement; } }, { key: 'handleInputClick', value: function handleInputClick() { // Input will not be focused if it's disabled if (this.isInputFocused() && !this.isOpen()) this.setState({ isOpen: true }); } }, { key: 'composeEventHandlers', value: function composeEventHandlers(internal, external) { return external ? function (e) { internal(e);external(e); } : internal; } }, { key: 'isOpen', value: function isOpen() { return 'open' in this.props ? this.props.open : this.state.isOpen; } }, { key: 'render', value: function render() { if (this.props.debug) { // you don't like it, you love it this._debugStates.push({ id: this._debugStates.length, state: this.state }); } var inputProps = this.props.inputProps; var open = this.isOpen(); return React.createElement( 'div', _extends({ style: _extends({}, this.props.wrapperStyle) }, this.props.wrapperProps), this.props.renderInput(_extends({}, inputProps, { role: 'combobox', 'aria-autocomplete': 'list', 'aria-expanded': open, autoComplete: 'off', ref: this.exposeAPI, onFocus: this.handleInputFocus, onBlur: this.handleInputBlur, onChange: this.handleChange, onKeyDown: this.composeEventHandlers(this.handleKeyDown, inputProps.onKeyDown), onClick: this.composeEventHandlers(this.handleInputClick, inputProps.onClick), value: this.props.value })), open && this.renderMenu(), this.props.debug && React.createElement( 'pre', { style: { marginLeft: 300 } }, JSON.stringify(this._debugStates.slice(Math.max(0, this._debugStates.length - 5), this._debugStates.length), null, 2) ) ); } }]); return Autocomplete; }(React.Component); Autocomplete.propTypes = { /** * The items to display in the dropdown menu */ items: PropTypes.array.isRequired, /** * The value to display in the input field */ value: PropTypes.any, /** * Arguments: `event: Event, value: String` * * Invoked every time the user changes the input's value. */ onChange: PropTypes.func, /** * Arguments: `value: String, item: Any` * * Invoked when the user selects an item from the dropdown menu. */ onSelect: PropTypes.func, /** * Arguments: `item: Any, value: String` * * Invoked for each entry in `items` and its return value is used to * determine whether or not it should be displayed in the dropdown menu. * By default all items are always rendered. */ shouldItemRender: PropTypes.func, /** * Arguments: `item: Any` * * Invoked when attempting to select an item. The return value is used to * determine whether the item should be selectable or not. * By default all items are selectable. */ isItemSelectable: PropTypes.func, /** * Arguments: `itemA: Any, itemB: Any, value: String` * * The function which is used to sort `items` before display. */ sortItems: PropTypes.func, /** * Arguments: `item: Any` * * Used to read the display value from each entry in `items`. */ getItemValue: PropTypes.func.isRequired, /** * Arguments: `item: Any, isHighlighted: Boolean, styles: Object` * * Invoked for each entry in `items` that also passes `shouldItemRender` to * generate the render tree for each item in the dropdown menu. `styles` is * an optional set of styles that can be applied to improve the look/feel * of the items in the dropdown menu. */ renderItem: PropTypes.func.isRequired, /** * Arguments: `items: Array , value: String, styles: Object` * * Invoked to generate the render tree for the dropdown menu. Ensure the * returned tree includes every entry in `items` or else the highlight order * and keyboard navigation logic will break. `styles` will contain * { top, left, minWidth } which are the coordinates of the top-left corner * and the width of the dropdown menu. */ renderMenu: PropTypes.func, /** * Styles that are applied to the dropdown menu in the default `renderMenu` * implementation. If you override `renderMenu` and you want to use * `menuStyle` you must manually apply them (`this.props.menuStyle`). */ menuStyle: PropTypes.object, /** * Arguments: `props: Object` * * Invoked to generate the input element. The `props` argument is the result * of merging `props.inputProps` with a selection of props that are required * both for functionality and accessibility. At the very least you need to * apply `props.ref` and all `props.on ` event handlers. Failing to do * this will cause `Autocomplete` to behave unexpectedly. */ renderInput: PropTypes.func, /** * Props passed to `props.renderInput`. By default these props will be * applied to the `` element rendered by `Autocomplete`, unless you * have specified a custom value for `props.renderInput`. Any properties * supported by `HTMLInputElement` can be specified, apart from the * following which are set by `Autocomplete`: value, autoComplete, role, * aria-autocomplete. `inputProps` is commonly used for (but not limited to) * placeholder, event handlers (onFocus, onBlur, etc.), autoFocus, etc.. */ inputProps: PropTypes.object, /** * Props that are applied to the element which wraps the `` and * dropdown menu elements rendered by `Autocomplete`. */ wrapperProps: PropTypes.object, /** * This is a shorthand for `wrapperProps={{ style: }}`. * Note that `wrapperStyle` is applied before `wrapperProps`, so the latter * will win if it contains a `style` entry. */ wrapperStyle: PropTypes.object, /** * Whether or not to automatically highlight the top match in the dropdown * menu. */ autoHighlight: PropTypes.bool, /** * Whether or not to automatically select the highlighted item when the * `` loses focus. */ selectOnBlur: PropTypes.bool, /** * Arguments: `isOpen: Boolean` * * Invoked every time the dropdown menu's visibility changes (i.e. every * time it is displayed/hidden). */ onMenuVisibilityChange: PropTypes.func, /** * Used to override the internal logic which displays/hides the dropdown * menu. This is useful if you want to force a certain state based on your * UX/business logic. Use it together with `onMenuVisibilityChange` for * fine-grained control over the dropdown menu dynamics. */ open: PropTypes.bool, debug: PropTypes.bool }; Autocomplete.defaultProps = { value: '', wrapperProps: {}, wrapperStyle: { display: 'inline-block' }, inputProps: {}, renderInput: function renderInput(props) { return React.createElement('input', props); }, onChange: function onChange() {}, onSelect: function onSelect() {}, isItemSelectable: function isItemSelectable() { return true; }, renderMenu: function renderMenu(items, value, style) { return React.createElement('div', { style: _extends({}, style, this.menuStyle), children: items }); }, menuStyle: { borderRadius: '3px', boxShadow: '0 2px 12px rgba(0, 0, 0, 0.1)', background: 'rgba(255, 255, 255, 0.9)', padding: '2px 0', fontSize: '90%', position: 'fixed', overflow: 'auto', maxHeight: '50%' }, autoHighlight: true, selectOnBlur: false, onMenuVisibilityChange: function onMenuVisibilityChange() {} }; Autocomplete.keyDownHandlers = { ArrowDown: function ArrowDown(event) { event.preventDefault(); var items = this.getFilteredItems(this.props); if (!items.length) return; var highlightedIndex = this.state.highlightedIndex; var index = highlightedIndex === null ? -1 : highlightedIndex; for (var i = 0; i < items.length; i++) { var p = (index + i + 1) % items.length; if (this.props.isItemSelectable(items[p])) { index = p; break; } } if (index > -1 && index !== highlightedIndex) { this.setState({ highlightedIndex: index, isOpen: true }); } }, ArrowUp: function ArrowUp(event) { event.preventDefault(); var items = this.getFilteredItems(this.props); if (!items.length) return; var highlightedIndex = this.state.highlightedIndex; var index = highlightedIndex === null ? items.length : highlightedIndex; for (var i = 0; i < items.length; i++) { var p = (index - 1 + items.length) % items.length; if (this.props.isItemSelectable(items[p])) { index = p; break; } } if (index !== items.length) { this.setState({ highlightedIndex: index, isOpen: true }); } }, Enter: function Enter(event) { var _this7 = this; // Key code 229 is used for selecting items from character selectors (Pinyin, Kana, etc) if (event.keyCode !== 13) return; // In case the user is currently hovering over the menu this.setIgnoreBlur(false); if (!this.isOpen()) { // menu is closed so there is no selection to accept -> do nothing return; } else if (this.state.highlightedIndex == null) { // input has focus but no menu item is selected + enter is hit -> close the menu, highlight whatever's in input this.setState({ isOpen: false }, function () { _this7.refs.input.select(); }); } else { // text entered + menu item has been highlighted + enter is hit -> update value to that of selected menu item, close the menu event.preventDefault(); var item = this.getFilteredItems(this.props)[this.state.highlightedIndex]; var value = this.props.getItemValue(item); this.setState({ isOpen: false, highlightedIndex: null }, function () { //this.refs.input.focus() // TODO: file issue _this7.refs.input.setSelectionRange(value.length, value.length); _this7.props.onSelect(value, item); }); } }, Escape: function Escape() { // In case the user is currently hovering over the menu this.setIgnoreBlur(false); this.setState({ highlightedIndex: null, isOpen: false }); }, Tab: function Tab() { // In case the user is currently hovering over the menu this.setIgnoreBlur(false); } }; module.exports = Autocomplete; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"dom-scroll-into-view":2,"prop-types":11,"react":"react","react-dom":"react-dom"}],2:[function(require,module,exports){ module.exports = require('./lib/dom-scroll-into-view'); },{"./lib/dom-scroll-into-view":3}],3:[function(require,module,exports){ var util = require('./util'); function scrollIntoView(elem, container, config) { config = config || {}; // document 归一化到 window if (container.nodeType === 9) { container = util.getWindow(container); } var allowHorizontalScroll = config.allowHorizontalScroll; var onlyScrollIfNeeded = config.onlyScrollIfNeeded; var alignWithTop = config.alignWithTop; var alignWithLeft = config.alignWithLeft; allowHorizontalScroll = allowHorizontalScroll === undefined ? true : allowHorizontalScroll; var isWin = util.isWindow(container); var elemOffset = util.offset(elem); var eh = util.outerHeight(elem); var ew = util.outerWidth(elem); var containerOffset, ch, cw, containerScroll, diffTop, diffBottom, win, winScroll, ww, wh; if (isWin) { win = container; wh = util.height(win); ww = util.width(win); winScroll = { left: util.scrollLeft(win), top: util.scrollTop(win) }; // elem 相对 container 可视视窗的距离 diffTop = { left: elemOffset.left - winScroll.left, top: elemOffset.top - winScroll.top }; diffBottom = { left: elemOffset.left + ew - (winScroll.left + ww), top: elemOffset.top + eh - (winScroll.top + wh) }; containerScroll = winScroll; } else { containerOffset = util.offset(container); ch = container.clientHeight; cw = container.clientWidth; containerScroll = { left: container.scrollLeft, top: container.scrollTop }; // elem 相对 container 可视视窗的距离 // 注意边框, offset 是边框到根节点 diffTop = { left: elemOffset.left - (containerOffset.left + (parseFloat(util.css(container, 'borderLeftWidth')) || 0)), top: elemOffset.top - (containerOffset.top + (parseFloat(util.css(container, 'borderTopWidth')) || 0)) }; diffBottom = { left: elemOffset.left + ew - (containerOffset.left + cw + (parseFloat(util.css(container, 'borderRightWidth')) || 0)), top: elemOffset.top + eh - (containerOffset.top + ch + (parseFloat(util.css(container, 'borderBottomWidth')) || 0)) }; } if (diffTop.top < 0 || diffBottom.top > 0) { // 强制向上 if (alignWithTop === true) { util.scrollTop(container, containerScroll.top + diffTop.top); } else if (alignWithTop === false) { util.scrollTop(container, containerScroll.top + diffBottom.top); } else { // 自动调整 if (diffTop.top < 0) { util.scrollTop(container, containerScroll.top + diffTop.top); } else { util.scrollTop(container, containerScroll.top + diffBottom.top); } } } else { if (!onlyScrollIfNeeded) { alignWithTop = alignWithTop === undefined ? true : !!alignWithTop; if (alignWithTop) { util.scrollTop(container, containerScroll.top + diffTop.top); } else { util.scrollTop(container, containerScroll.top + diffBottom.top); } } } if (allowHorizontalScroll) { if (diffTop.left < 0 || diffBottom.left > 0) { // 强制向上 if (alignWithLeft === true) { util.scrollLeft(container, containerScroll.left + diffTop.left); } else if (alignWithLeft === false) { util.scrollLeft(container, containerScroll.left + diffBottom.left); } else { // 自动调整 if (diffTop.left < 0) { util.scrollLeft(container, containerScroll.left + diffTop.left); } else { util.scrollLeft(container, containerScroll.left + diffBottom.left); } } } else { if (!onlyScrollIfNeeded) { alignWithLeft = alignWithLeft === undefined ? true : !!alignWithLeft; if (alignWithLeft) { util.scrollLeft(container, containerScroll.left + diffTop.left); } else { util.scrollLeft(container, containerScroll.left + diffBottom.left); } } } } } module.exports = scrollIntoView; },{"./util":4}],4:[function(require,module,exports){ var RE_NUM = /[\-+]?(?:\d*\.|)\d+(?:[eE][\-+]?\d+|)/.source; function getClientPosition(elem) { var box, x, y; var doc = elem.ownerDocument; var body = doc.body; var docElem = doc && doc.documentElement; // 根据 GBS 最新数据,A-Grade Browsers 都已支持 getBoundingClientRect 方法,不用再考虑传统的实现方式 box = elem.getBoundingClientRect(); // 注:jQuery 还考虑减去 docElem.clientLeft/clientTop // 但测试发现,这样反而会导致当 html 和 body 有边距/边框样式时,获取的值不正确 // 此外,ie6 会忽略 html 的 margin 值,幸运地是没有谁会去设置 html 的 margin x = box.left; y = box.top; // In IE, most of the time, 2 extra pixels are added to the top and left // due to the implicit 2-pixel inset border. In IE6/7 quirks mode and // IE6 standards mode, this border can be overridden by setting the // document element's border to zero -- thus, we cannot rely on the // offset always being 2 pixels. // In quirks mode, the offset can be determined by querying the body's // clientLeft/clientTop, but in standards mode, it is found by querying // the document element's clientLeft/clientTop. Since we already called // getClientBoundingRect we have already forced a reflow, so it is not // too expensive just to query them all. // ie 下应该减去窗口的边框吧,毕竟默认 absolute 都是相对窗口定位的 // 窗口边框标准是设 documentElement ,quirks 时设置 body // 最好禁止在 body 和 html 上边框 ,但 ie < 9 html 默认有 2px ,减去 // 但是非 ie 不可能设置窗口边框,body html 也不是窗口 ,ie 可以通过 html,body 设置 // 标准 ie 下 docElem.clientTop 就是 border-top // ie7 html 即窗口边框改变不了。永远为 2 // 但标准 firefox/chrome/ie9 下 docElem.clientTop 是窗口边框,即使设了 border-top 也为 0 x -= docElem.clientLeft || body.clientLeft || 0; y -= docElem.clientTop || body.clientTop || 0; return {left: x, top: y}; } function getScroll(w, top) { var ret = w['page' + (top ? 'Y' : 'X') + 'Offset']; var method = 'scroll' + (top ? 'Top' : 'Left'); if (typeof ret !== 'number') { var d = w.document; //ie6,7,8 standard mode ret = d.documentElement[method]; if (typeof ret !== 'number') { //quirks mode ret = d.body[method]; } } return ret; } function getScrollLeft(w) { return getScroll(w); } function getScrollTop(w) { return getScroll(w, true); } function getOffset(el) { var pos = getClientPosition(el); var doc = el.ownerDocument; var w = doc.defaultView || doc.parentWindow; pos.left += getScrollLeft(w); pos.top += getScrollTop(w); return pos; } function _getComputedStyle(elem, name, computedStyle) { var val = ''; var d = elem.ownerDocument; // https://github.com/kissyteam/kissy/issues/61 if ((computedStyle = (computedStyle || d.defaultView.getComputedStyle(elem, null)))) { val = computedStyle.getPropertyValue(name) || computedStyle[name]; } return val; } var _RE_NUM_NO_PX = new RegExp('^(' + RE_NUM + ')(?!px)[a-z%]+$', 'i'); var RE_POS = /^(top|right|bottom|left)$/, CURRENT_STYLE = 'currentStyle', RUNTIME_STYLE = 'runtimeStyle', LEFT = 'left', PX = 'px'; function _getComputedStyleIE(elem, name) { // currentStyle maybe null // http://msdn.microsoft.com/en-us/library/ms535231.aspx var ret = elem[CURRENT_STYLE] && elem[CURRENT_STYLE][name]; // 当 width/height 设置为百分比时,通过 pixelLeft 方式转换的 width/height 值 // 一开始就处理了! CUSTOM_STYLE.height,CUSTOM_STYLE.width ,cssHook 解决@2011-08-19 // 在 ie 下不对,需要直接用 offset 方式 // borderWidth 等值也有问题,但考虑到 borderWidth 设为百分比的概率很小,这里就不考虑了 // From the awesome hack by Dean Edwards // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291 // If we're not dealing with a regular pixel number // but a number that has a weird ending, we need to convert it to pixels // exclude left right for relativity if (_RE_NUM_NO_PX.test(ret) && !RE_POS.test(name)) { // Remember the original values var style = elem.style, left = style[LEFT], rsLeft = elem[RUNTIME_STYLE][LEFT]; // prevent flashing of content elem[RUNTIME_STYLE][LEFT] = elem[CURRENT_STYLE][LEFT]; // Put in the new values to get a computed value out style[LEFT] = name === 'fontSize' ? '1em' : (ret || 0); ret = style.pixelLeft + PX; // Revert the changed values style[LEFT] = left; elem[RUNTIME_STYLE][LEFT] = rsLeft; } return ret === '' ? 'auto' : ret; } var getComputedStyleX; if (typeof window !== 'undefined') { getComputedStyleX = window.getComputedStyle ? _getComputedStyle : _getComputedStyleIE; } // 设置 elem 相对 elem.ownerDocument 的坐标 function setOffset(elem, offset) { // set position first, in-case top/left are set even on static elem if (css(elem, 'position') === 'static') { elem.style.position = 'relative'; } var old = getOffset(elem), ret = {}, current, key; for (key in offset) { current = parseFloat(css(elem, key)) || 0; ret[key] = current + offset[key] - old[key]; } css(elem, ret); } function each(arr, fn) { for (var i = 0; i < arr.length; i++) { fn(arr[i]); } } function isBorderBoxFn(elem) { return getComputedStyleX(elem, 'boxSizing') === 'border-box'; } var BOX_MODELS = ['margin', 'border', 'padding'], CONTENT_INDEX = -1, PADDING_INDEX = 2, BORDER_INDEX = 1, MARGIN_INDEX = 0; function swap(elem, options, callback) { var old = {}, style = elem.style, name; // Remember the old values, and insert the new ones for (name in options) { old[name] = style[name]; style[name] = options[name]; } callback.call(elem); // Revert the old values for (name in options) { style[name] = old[name]; } } function getPBMWidth(elem, props, which) { var value = 0, prop, j, i; for (j = 0; j < props.length; j++) { prop = props[j]; if (prop) { for (i = 0; i < which.length; i++) { var cssProp; if (prop === 'border') { cssProp = prop + which[i] + 'Width'; } else { cssProp = prop + which[i]; } value += parseFloat(getComputedStyleX(elem, cssProp)) || 0; } } } return value; } /** * A crude way of determining if an object is a window * @member util */ function isWindow(obj) { // must use == for ie8 /*jshint eqeqeq:false*/ return obj != null && obj == obj.window; } var domUtils = {}; each(['Width', 'Height'], function (name) { domUtils['doc' + name] = function (refWin) { var d = refWin.document; return Math.max( //firefox chrome documentElement.scrollHeight< body.scrollHeight //ie standard mode : documentElement.scrollHeight> body.scrollHeight d.documentElement['scroll' + name], //quirks : documentElement.scrollHeight 最大等于可视窗口多一点? d.body['scroll' + name], domUtils['viewport' + name](d)); }; domUtils['viewport' + name] = function (win) { // pc browser includes scrollbar in window.innerWidth var prop = 'client' + name, doc = win.document, body = doc.body, documentElement = doc.documentElement, documentElementProp = documentElement[prop]; // 标准模式取 documentElement // backcompat 取 body return doc.compatMode === 'CSS1Compat' && documentElementProp || body && body[prop] || documentElementProp; }; }); /* 得到元素的大小信息 @param elem @param name @param {String} [extra] 'padding' : (css width) + padding 'border' : (css width) + padding + border 'margin' : (css width) + padding + border + margin */ function getWH(elem, name, extra) { if (isWindow(elem)) { return name === 'width' ? domUtils.viewportWidth(elem) : domUtils.viewportHeight(elem); } else if (elem.nodeType === 9) { return name === 'width' ? domUtils.docWidth(elem) : domUtils.docHeight(elem); } var which = name === 'width' ? ['Left', 'Right'] : ['Top', 'Bottom'], borderBoxValue = name === 'width' ? elem.offsetWidth : elem.offsetHeight; var computedStyle = getComputedStyleX(elem); var isBorderBox = isBorderBoxFn(elem, computedStyle); var cssBoxValue = 0; if (borderBoxValue == null || borderBoxValue <= 0) { borderBoxValue = undefined; // Fall back to computed then un computed css if necessary cssBoxValue = getComputedStyleX(elem, name); if (cssBoxValue == null || (Number(cssBoxValue)) < 0) { cssBoxValue = elem.style[name] || 0; } // Normalize '', auto, and prepare for extra cssBoxValue = parseFloat(cssBoxValue) || 0; } if (extra === undefined) { extra = isBorderBox ? BORDER_INDEX : CONTENT_INDEX; } var borderBoxValueOrIsBorderBox = borderBoxValue !== undefined || isBorderBox; var val = borderBoxValue || cssBoxValue; if (extra === CONTENT_INDEX) { if (borderBoxValueOrIsBorderBox) { return val - getPBMWidth(elem, ['border', 'padding'], which, computedStyle); } else { return cssBoxValue; } } else if (borderBoxValueOrIsBorderBox) { return val + (extra === BORDER_INDEX ? 0 : (extra === PADDING_INDEX ? -getPBMWidth(elem, ['border'], which, computedStyle) : getPBMWidth(elem, ['margin'], which, computedStyle))); } else { return cssBoxValue + getPBMWidth(elem, BOX_MODELS.slice(extra), which, computedStyle); } } var cssShow = {position: 'absolute', visibility: 'hidden', display: 'block'}; // fix #119 : https://github.com/kissyteam/kissy/issues/119 function getWHIgnoreDisplay(elem) { var val, args = arguments; // in case elem is window // elem.offsetWidth === undefined if (elem.offsetWidth !== 0) { val = getWH.apply(undefined, args); } else { swap(elem, cssShow, function () { val = getWH.apply(undefined, args); }); } return val; } each(['width', 'height'], function (name) { var first = name.charAt(0).toUpperCase() + name.slice(1); domUtils['outer' + first] = function (el, includeMargin) { return el && getWHIgnoreDisplay(el, name, includeMargin ? MARGIN_INDEX : BORDER_INDEX); }; var which = name === 'width' ? ['Left', 'Right'] : ['Top', 'Bottom']; domUtils[name] = function (elem, val) { if (val !== undefined) { if (elem) { var computedStyle = getComputedStyleX(elem); var isBorderBox = isBorderBoxFn(elem); if (isBorderBox) { val += getPBMWidth(elem, ['padding', 'border'], which, computedStyle); } return css(elem, name, val); } return; } return elem && getWHIgnoreDisplay(elem, name, CONTENT_INDEX); }; }); function css(el, name, value) { if (typeof name === 'object') { for (var i in name) { css(el, i, name[i]); } return; } if (typeof value !== 'undefined') { if (typeof value === 'number') { value = value + 'px'; } el.style[name] = value; } else { return getComputedStyleX(el, name); } } function mix(to, from) { for (var i in from) { to[i] = from[i]; } return to; } var utils = module.exports = { getWindow: function (node) { var doc = node.ownerDocument || node; return doc.defaultView || doc.parentWindow; }, offset: function (el, value) { if (typeof value !== 'undefined') { setOffset(el, value); } else { return getOffset(el); } }, isWindow: isWindow, each: each, css: css, clone: function (obj) { var ret = {}; for (var i in obj) { ret[i] = obj[i]; } var overflow = obj.overflow; if (overflow) { for (i in obj) { ret.overflow[i] = obj.overflow[i]; } } return ret; }, mix: mix, scrollLeft: function (w, v) { if (isWindow(w)) { if (v === undefined) { return getScrollLeft(w); } else { window.scrollTo(v, getScrollTop(w)); } } else { if (v === undefined) { return w.scrollLeft; } else { w.scrollLeft = v; } } }, scrollTop: function (w, v) { if (isWindow(w)) { if (v === undefined) { return getScrollTop(w); } else { window.scrollTo(getScrollLeft(w), v); } } else { if (v === undefined) { return w.scrollTop; } else { w.scrollTop = v; } } }, merge: function () { var ret = {}; for (var i = 0; i < arguments.length; i++) { utils.mix(ret, arguments[i]); } return ret; }, viewportWidth: 0, viewportHeight: 0 }; mix(utils, domUtils); },{}],5:[function(require,module,exports){ "use strict"; /** * Copyright (c) 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * */ function makeEmptyFunction(arg) { return function () { return arg; }; } /** * This function accepts and discards inputs; it has no side effects. This is * primarily useful idiomatically for overridable function endpoints which * always need to be callable, since JS lacks a null-call idiom ala Cocoa. */ var emptyFunction = function emptyFunction() {}; emptyFunction.thatReturns = makeEmptyFunction; emptyFunction.thatReturnsFalse = makeEmptyFunction(false); emptyFunction.thatReturnsTrue = makeEmptyFunction(true); emptyFunction.thatReturnsNull = makeEmptyFunction(null); emptyFunction.thatReturnsThis = function () { return this; }; emptyFunction.thatReturnsArgument = function (arg) { return arg; }; module.exports = emptyFunction; },{}],6:[function(require,module,exports){ /** * Copyright (c) 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * */ 'use strict'; /** * Use invariant() to assert state which your program assumes to be true. * * Provide sprintf-style format (only %s is supported) and arguments * to provide information about what broke and what you were * expecting. * * The invariant message will be stripped in production, but the invariant * will remain to ensure logic does not differ in production. */ var validateFormat = function validateFormat(format) {}; if ("production" !== 'production') { validateFormat = function validateFormat(format) { if (format === undefined) { throw new Error('invariant requires an error message argument'); } }; } function invariant(condition, format, a, b, c, d, e, f) { validateFormat(format); if (!condition) { var error; if (format === undefined) { error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.'); } else { var args = [a, b, c, d, e, f]; var argIndex = 0; error = new Error(format.replace(/%s/g, function () { return args[argIndex++]; })); error.name = 'Invariant Violation'; } error.framesToPop = 1; // we don't care about invariant's own frame throw error; } } module.exports = invariant; },{}],7:[function(require,module,exports){ /** * Copyright 2014-2015, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * */ 'use strict'; var emptyFunction = require('./emptyFunction'); /** * Similar to invariant but only logs a warning if the condition is not met. * This can be used to log issues in development environments in critical * paths. Removing the logging code for production environments will keep the * same logic and follow the same code paths. */ var warning = emptyFunction; if ("production" !== 'production') { (function () { var printWarning = function printWarning(format) { for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } var argIndex = 0; var message = 'Warning: ' + format.replace(/%s/g, function () { return args[argIndex++]; }); if (typeof console !== 'undefined') { console.error(message); } try { // --- Welcome to debugging React --- // This error was thrown as a convenience so that you can use this stack // to find the callsite that caused this warning to fire. throw new Error(message); } catch (x) {} }; warning = function warning(condition, format) { if (format === undefined) { throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument'); } if (format.indexOf('Failed Composite propType: ') === 0) { return; // Ignore CompositeComponent proptype check. } if (!condition) { for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { args[_key2 - 2] = arguments[_key2]; } printWarning.apply(undefined, [format].concat(args)); } }; })(); } module.exports = warning; },{"./emptyFunction":5}],8:[function(require,module,exports){ /** * Copyright 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ 'use strict'; if ("production" !== 'production') { var invariant = require('fbjs/lib/invariant'); var warning = require('fbjs/lib/warning'); var ReactPropTypesSecret = require('./lib/ReactPropTypesSecret'); var loggedTypeFailures = {}; } /** * Assert that the values match with the type specs. * Error messages are memorized and will only be shown once. * * @param {object} typeSpecs Map of name to a ReactPropType * @param {object} values Runtime values that need to be type-checked * @param {string} location e.g. "prop", "context", "child context" * @param {string} componentName Name of the component for error messages. * @param {?Function} getStack Returns the component stack. * @private */ function checkPropTypes(typeSpecs, values, location, componentName, getStack) { if ("production" !== 'production') { for (var typeSpecName in typeSpecs) { if (typeSpecs.hasOwnProperty(typeSpecName)) { var error; // Prop type validation may throw. In case they do, we don't want to // fail the render phase where it didn't fail before. So we log it. // After these have been cleaned up, we'll let them throw. try { // This is intentionally an invariant that gets caught. It's the same // behavior as without this statement except with a better message. invariant(typeof typeSpecs[typeSpecName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', componentName || 'React class', location, typeSpecName); error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret); } catch (ex) { error = ex; } warning(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error); if (error instanceof Error && !(error.message in loggedTypeFailures)) { // Only monitor this failure once because there tends to be a lot of the // same error. loggedTypeFailures[error.message] = true; var stack = getStack ? getStack() : ''; warning(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : ''); } } } } } module.exports = checkPropTypes; },{"./lib/ReactPropTypesSecret":12,"fbjs/lib/invariant":6,"fbjs/lib/warning":7}],9:[function(require,module,exports){ /** * Copyright 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ 'use strict'; var emptyFunction = require('fbjs/lib/emptyFunction'); var invariant = require('fbjs/lib/invariant'); var ReactPropTypesSecret = require('./lib/ReactPropTypesSecret'); module.exports = function() { function shim(props, propName, componentName, location, propFullName, secret) { if (secret === ReactPropTypesSecret) { // It is still safe when called from React. return; } invariant( false, 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' + 'Use PropTypes.checkPropTypes() to call them. ' + 'Read more at http://fb.me/use-check-prop-types' ); }; shim.isRequired = shim; function getShim() { return shim; }; // Important! // Keep this list in sync with production version in `./factoryWithTypeCheckers.js`. var ReactPropTypes = { array: shim, bool: shim, func: shim, number: shim, object: shim, string: shim, symbol: shim, any: shim, arrayOf: getShim, element: shim, instanceOf: getShim, node: shim, objectOf: getShim, oneOf: getShim, oneOfType: getShim, shape: getShim }; ReactPropTypes.checkPropTypes = emptyFunction; ReactPropTypes.PropTypes = ReactPropTypes; return ReactPropTypes; }; },{"./lib/ReactPropTypesSecret":12,"fbjs/lib/emptyFunction":5,"fbjs/lib/invariant":6}],10:[function(require,module,exports){ /** * Copyright 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ 'use strict'; var emptyFunction = require('fbjs/lib/emptyFunction'); var invariant = require('fbjs/lib/invariant'); var warning = require('fbjs/lib/warning'); var ReactPropTypesSecret = require('./lib/ReactPropTypesSecret'); var checkPropTypes = require('./checkPropTypes'); module.exports = function(isValidElement, throwOnDirectAccess) { /* global Symbol */ var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec. /** * Returns the iterator method function contained on the iterable object. * * Be sure to invoke the function with the iterable as context: * * var iteratorFn = getIteratorFn(myIterable); * if (iteratorFn) { * var iterator = iteratorFn.call(myIterable); * ... * } * * @param {?object} maybeIterable * @return {?function} */ function getIteratorFn(maybeIterable) { var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]); if (typeof iteratorFn === 'function') { return iteratorFn; } } /** * Collection of methods that allow declaration and validation of props that are * supplied to React components. Example usage: * * var Props = require('ReactPropTypes'); * var MyArticle = React.createClass({ * propTypes: { * // An optional string prop named "description". * description: Props.string, * * // A required enum prop named "category". * category: Props.oneOf(['News','Photos']).isRequired, * * // A prop named "dialog" that requires an instance of Dialog. * dialog: Props.instanceOf(Dialog).isRequired * }, * render: function() { ... } * }); * * A more formal specification of how these methods are used: * * type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) * decl := ReactPropTypes.{type}(.isRequired)? * * Each and every declaration produces a function with the same signature. This * allows the creation of custom validation functions. For example: * * var MyLink = React.createClass({ * propTypes: { * // An optional string or URI prop named "href". * href: function(props, propName, componentName) { * var propValue = props[propName]; * if (propValue != null && typeof propValue !== 'string' && * !(propValue instanceof URI)) { * return new Error( * 'Expected a string or an URI for ' + propName + ' in ' + * componentName * ); * } * } * }, * render: function() {...} * }); * * @internal */ var ANONYMOUS = '< >'; // Important! // Keep this list in sync with production version in `./factoryWithThrowingShims.js`. var ReactPropTypes = { array: createPrimitiveTypeChecker('array'), bool: createPrimitiveTypeChecker('boolean'), func: createPrimitiveTypeChecker('function'), number: createPrimitiveTypeChecker('number'), object: createPrimitiveTypeChecker('object'), string: createPrimitiveTypeChecker('string'), symbol: createPrimitiveTypeChecker('symbol'), any: createAnyTypeChecker(), arrayOf: createArrayOfTypeChecker, element: createElementTypeChecker(), instanceOf: createInstanceTypeChecker, node: createNodeChecker(), objectOf: createObjectOfTypeChecker, oneOf: createEnumTypeChecker, oneOfType: createUnionTypeChecker, shape: createShapeTypeChecker }; /** * inlined Object.is polyfill to avoid requiring consumers ship their own * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is */ /*eslint-disable no-self-compare*/ function is(x, y) { // SameValue algorithm if (x === y) { // Steps 1-5, 7-10 // Steps 6.b-6.e: +0 != -0 return x !== 0 || 1 / x === 1 / y; } else { // Step 6.a: NaN == NaN return x !== x && y !== y; } } /*eslint-enable no-self-compare*/ /** * We use an Error-like object for backward compatibility as people may call * PropTypes directly and inspect their output. However, we don't use real * Errors anymore. We don't inspect their stack anyway, and creating them * is prohibitively expensive if they are created too often, such as what * happens in oneOfType() for any type before the one that matched. */ function PropTypeError(message) { this.message = message; this.stack = ''; } // Make `instanceof Error` still work for returned errors. PropTypeError.prototype = Error.prototype; function createChainableTypeChecker(validate) { if ("production" !== 'production') { var manualPropTypeCallCache = {}; var manualPropTypeWarningCount = 0; } function checkType(isRequired, props, propName, componentName, location, propFullName, secret) { componentName = componentName || ANONYMOUS; propFullName = propFullName || propName; if (secret !== ReactPropTypesSecret) { if (throwOnDirectAccess) { // New behavior only for users of `prop-types` package invariant( false, 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' + 'Use `PropTypes.checkPropTypes()` to call them. ' + 'Read more at http://fb.me/use-check-prop-types' ); } else if ("production" !== 'production' && typeof console !== 'undefined') { // Old behavior for people using React.PropTypes var cacheKey = componentName + ':' + propName; if ( !manualPropTypeCallCache[cacheKey] && // Avoid spamming the console because they are often not actionable except for lib authors manualPropTypeWarningCount < 3 ) { warning( false, 'You are manually calling a React.PropTypes validation ' + 'function for the `%s` prop on `%s`. This is deprecated ' + 'and will throw in the standalone `prop-types` package. ' + 'You may be seeing this warning due to a third-party PropTypes ' + 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.', propFullName, componentName ); manualPropTypeCallCache[cacheKey] = true; manualPropTypeWarningCount++; } } } if (props[propName] == null) { if (isRequired) { if (props[propName] === null) { return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.')); } return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.')); } return null; } else { return validate(props, propName, componentName, location, propFullName); } } var chainedCheckType = checkType.bind(null, false); chainedCheckType.isRequired = checkType.bind(null, true); return chainedCheckType; } function createPrimitiveTypeChecker(expectedType) { function validate(props, propName, componentName, location, propFullName, secret) { var propValue = props[propName]; var propType = getPropType(propValue); if (propType !== expectedType) { // `propValue` being instance of, say, date/regexp, pass the 'object' // check, but we can offer a more precise error message here rather than // 'of type `object`'. var preciseType = getPreciseType(propValue); return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.')); } return null; } return createChainableTypeChecker(validate); } function createAnyTypeChecker() { return createChainableTypeChecker(emptyFunction.thatReturnsNull); } function createArrayOfTypeChecker(typeChecker) { function validate(props, propName, componentName, location, propFullName) { if (typeof typeChecker !== 'function') { return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.'); } var propValue = props[propName]; if (!Array.isArray(propValue)) { var propType = getPropType(propValue); return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.')); } for (var i = 0; i < propValue.length; i++) { var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret); if (error instanceof Error) { return error; } } return null; } return createChainableTypeChecker(validate); } function createElementTypeChecker() { function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; if (!isValidElement(propValue)) { var propType = getPropType(propValue); return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.')); } return null; } return createChainableTypeChecker(validate); } function createInstanceTypeChecker(expectedClass) { function validate(props, propName, componentName, location, propFullName) { if (!(props[propName] instanceof expectedClass)) { var expectedClassName = expectedClass.name || ANONYMOUS; var actualClassName = getClassName(props[propName]); return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.')); } return null; } return createChainableTypeChecker(validate); } function createEnumTypeChecker(expectedValues) { if (!Array.isArray(expectedValues)) { "production" !== 'production' ? warning(false, 'Invalid argument supplied to oneOf, expected an instance of array.') : void 0; return emptyFunction.thatReturnsNull; } function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; for (var i = 0; i < expectedValues.length; i++) { if (is(propValue, expectedValues[i])) { return null; } } var valuesString = JSON.stringify(expectedValues); return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.')); } return createChainableTypeChecker(validate); } function createObjectOfTypeChecker(typeChecker) { function validate(props, propName, componentName, location, propFullName) { if (typeof typeChecker !== 'function') { return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.'); } var propValue = props[propName]; var propType = getPropType(propValue); if (propType !== 'object') { return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.')); } for (var key in propValue) { if (propValue.hasOwnProperty(key)) { var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret); if (error instanceof Error) { return error; } } } return null; } return createChainableTypeChecker(validate); } function createUnionTypeChecker(arrayOfTypeCheckers) { if (!Array.isArray(arrayOfTypeCheckers)) { "production" !== 'production' ? warning(false, 'Invalid argument supplied to oneOfType, expected an instance of array.') : void 0; return emptyFunction.thatReturnsNull; } for (var i = 0; i < arrayOfTypeCheckers.length; i++) { var checker = arrayOfTypeCheckers[i]; if (typeof checker !== 'function') { warning( false, 'Invalid argument supplid to oneOfType. Expected an array of check functions, but ' + 'received %s at index %s.', getPostfixForTypeWarning(checker), i ); return emptyFunction.thatReturnsNull; } } function validate(props, propName, componentName, location, propFullName) { for (var i = 0; i < arrayOfTypeCheckers.length; i++) { var checker = arrayOfTypeCheckers[i]; if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret) == null) { return null; } } return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.')); } return createChainableTypeChecker(validate); } function createNodeChecker() { function validate(props, propName, componentName, location, propFullName) { if (!isNode(props[propName])) { return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.')); } return null; } return createChainableTypeChecker(validate); } function createShapeTypeChecker(shapeTypes) { function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; var propType = getPropType(propValue); if (propType !== 'object') { return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); } for (var key in shapeTypes) { var checker = shapeTypes[key]; if (!checker) { continue; } var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret); if (error) { return error; } } return null; } return createChainableTypeChecker(validate); } function isNode(propValue) { switch (typeof propValue) { case 'number': case 'string': case 'undefined': return true; case 'boolean': return !propValue; case 'object': if (Array.isArray(propValue)) { return propValue.every(isNode); } if (propValue === null || isValidElement(propValue)) { return true; } var iteratorFn = getIteratorFn(propValue); if (iteratorFn) { var iterator = iteratorFn.call(propValue); var step; if (iteratorFn !== propValue.entries) { while (!(step = iterator.next()).done) { if (!isNode(step.value)) { return false; } } } else { // Iterator will provide entry [k,v] tuples rather than values. while (!(step = iterator.next()).done) { var entry = step.value; if (entry) { if (!isNode(entry[1])) { return false; } } } } } else { return false; } return true; default: return false; } } function isSymbol(propType, propValue) { // Native Symbol. if (propType === 'symbol') { return true; } // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol' if (propValue['@@toStringTag'] === 'Symbol') { return true; } // Fallback for non-spec compliant Symbols which are polyfilled. if (typeof Symbol === 'function' && propValue instanceof Symbol) { return true; } return false; } // Equivalent of `typeof` but with special handling for array and regexp. function getPropType(propValue) { var propType = typeof propValue; if (Array.isArray(propValue)) { return 'array'; } if (propValue instanceof RegExp) { // Old webkits (at least until Android 4.0) return 'function' rather than // 'object' for typeof a RegExp. We'll normalize this here so that /bla/ // passes PropTypes.object. return 'object'; } if (isSymbol(propType, propValue)) { return 'symbol'; } return propType; } // This handles more types than `getPropType`. Only used for error messages. // See `createPrimitiveTypeChecker`. function getPreciseType(propValue) { if (typeof propValue === 'undefined' || propValue === null) { return '' + propValue; } var propType = getPropType(propValue); if (propType === 'object') { if (propValue instanceof Date) { return 'date'; } else if (propValue instanceof RegExp) { return 'regexp'; } } return propType; } // Returns a string that is postfixed to a warning about an invalid type. // For example, "undefined" or "of type array" function getPostfixForTypeWarning(value) { var type = getPreciseType(value); switch (type) { case 'array': case 'object': return 'an ' + type; case 'boolean': case 'date': case 'regexp': return 'a ' + type; default: return type; } } // Returns class name of the object, if any. function getClassName(propValue) { if (!propValue.constructor || !propValue.constructor.name) { return ANONYMOUS; } return propValue.constructor.name; } ReactPropTypes.checkPropTypes = checkPropTypes; ReactPropTypes.PropTypes = ReactPropTypes; return ReactPropTypes; }; },{"./checkPropTypes":8,"./lib/ReactPropTypesSecret":12,"fbjs/lib/emptyFunction":5,"fbjs/lib/invariant":6,"fbjs/lib/warning":7}],11:[function(require,module,exports){ /** * Copyright 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ if ("production" !== 'production') { var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' && Symbol.for && Symbol.for('react.element')) || 0xeac7; var isValidElement = function(object) { return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE; }; // By explicitly using `prop-types` you are opting into new development behavior. // http://fb.me/prop-types-in-prod var throwOnDirectAccess = true; module.exports = require('./factoryWithTypeCheckers')(isValidElement, throwOnDirectAccess); } else { // By explicitly using `prop-types` you are opting into new production behavior. // http://fb.me/prop-types-in-prod module.exports = require('./factoryWithThrowingShims')(); } },{"./factoryWithThrowingShims":9,"./factoryWithTypeCheckers":10}],12:[function(require,module,exports){ /** * Copyright 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ 'use strict'; var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'; module.exports = ReactPropTypesSecret; },{}]},{},[1]) )(1) })(function newRequire (name) { if (name === 'react') return dep0 if (name === 'react-dom') return dep1 if (typeof require !== 'undefined') return require(name) var err = new Error("Cannot find module '" + name + "'") err.code = 'MODULE_NOT_FOUND' throw err }) }) //# sourceMappingURL=react-autocomplete.js.map
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4