From f43905a202679559404bc6f4d6dbdaa799e5f1b1 Mon Sep 17 00:00:00 2001 From: Ian Zhang Date: Tue, 6 Oct 2015 16:22:25 -0600 Subject: [PATCH 01/10] Changing it so react select renders a select behind the scenes for proper serialization --- dist/react-select.js | 12 +- dist/react-select.min.js | 2 +- examples/dist/app.js | 728 +- examples/dist/bundle.js | 12 +- examples/dist/common.js | 12274 +++++++++++++++++----------------- examples/dist/standalone.js | 12 +- lib/Select.js | 12 +- src/Select.js | 10 +- 8 files changed, 6567 insertions(+), 6495 deletions(-) diff --git a/dist/react-select.js b/dist/react-select.js index e86952f2fc..459c525afc 100644 --- a/dist/react-select.js +++ b/dist/react-select.js @@ -999,7 +999,17 @@ var Select = React.createClass({ return React.createElement( 'div', { ref: 'wrapper', className: selectClass }, - React.createElement('input', { type: 'hidden', ref: 'value', name: this.props.name, value: this.state.value, disabled: this.props.disabled }), + React.createElement( + 'select', + { className: 'hidden', ref: 'value', name: this.props.name, multiple: true, value: _.pluck(this.state.values, 'value'), disabled: this.props.disabled, readOnly: true }, + _.map(this.state.values, function (value) { + return React.createElement( + 'option', + { value: value.value, key: value.value }, + value.label + ); + }) + ), React.createElement( 'div', { className: 'Select-control', ref: 'control', onKeyDown: this.handleKeyDown, onMouseDown: this.handleMouseDown, onTouchEnd: this.handleMouseDown }, diff --git a/dist/react-select.min.js b/dist/react-select.min.js index 06436b124e..e1712d2f60 100644 --- a/dist/react-select.min.js +++ b/dist/react-select.min.js @@ -1 +1 @@ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.Select=e()}}(function(){return function e(t,s,o){function i(a,p){if(!s[a]){if(!t[a]){var r="function"==typeof require&&require;if(!p&&r)return r(a,!0);if(n)return n(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var u=s[a]={exports:{}};t[a][0].call(u.exports,function(e){var s=t[a][1][e];return i(s?s:e)},u,u.exports,e,t,s,o)}return s[a].exports}for(var n="function"==typeof require&&require,a=0;ai.bottom||o.top-1)return!1;if(this.props.filterOption)return this.props.filterOption.call(this,e,o);var t=String(e[this.props.valueKey]),s=String(e[this.props.labelKey]);return this.props.ignoreCase&&(t=t.toLowerCase(),s=s.toLowerCase(),o=o.toLowerCase()),o&&"start"!==this.props.matchPos?"label"!==this.props.matchProp&&t.indexOf(o)>=0||"value"!==this.props.matchProp&&s.indexOf(o)>=0:"label"!==this.props.matchProp&&t.substr(0,o.length)===o||"value"!==this.props.matchProp&&s.substr(0,o.length)===o};return(e||[]).filter(n,this)},selectFocusedOption:function(){return this.props.allowCreate&&!this.state.focusedOption?this.selectValue(this.state.inputValue):this.state.focusedOption?this.selectValue(this.state.focusedOption):void 0},focusOption:function(e){this.setState({focusedOption:e})},focusNextOption:function(){this.focusAdjacentOption("next")},focusPreviousOption:function(){this.focusAdjacentOption("previous")},focusAdjacentOption:function(e){this._focusedOptionReveal=!0;var t=this.state.filteredOptions.filter(function(e){return!e.disabled});if(!this.state.isOpen)return void this.setState({isOpen:!0,inputValue:"",focusedOption:this.state.focusedOption||t["next"===e?0:t.length-1]},this._bindCloseMenuIfClickedOutside);if(t.length){for(var s=-1,o=0;o-1&&s0?t[s-1]:t[t.length-1]),this.setState({focusedOption:i})}},unfocusOption:function(e){this.state.focusedOption===e&&this.setState({focusedOption:null})},renderOptionLabel:function(e){return e[this.props.labelKey]},buildMenu:function(){var e=this.state.focusedOption?this.state.focusedOption[this.props.valueKey]:null,t=this.props.optionRenderer||this.renderOptionLabel;this.state.filteredOptions.length>0&&(e=null==e?this.state.filteredOptions[0]:e);var s=this.state.filteredOptions;if(this.props.allowCreate&&this.state.inputValue.trim()){var o=this.state.inputValue;s=s.slice();var i=this.props.newOptionCreator?this.props.newOptionCreator(o):{value:o,label:o,create:!0};s.unshift(i)}var a=Object.keys(s).map(function(o){var i=s[o],a=this.state.value===i[this.props.valueKey],p=e===i[this.props.valueKey],l=r({"Select-option":!0,"is-selected":a,"is-focused":p,"is-disabled":i.disabled}),u=p?"focused":null,c=n.createElement(this.props.optionComponent,{key:"option-"+i[this.props.valueKey],className:l,renderFunc:t,mouseDown:this.selectValue,mouseEnter:this.focusOption,mouseLeave:this.unfocusOption,addLabelText:this.props.addLabelText,option:i,ref:u});return c},this);if(a.length)return a;var p,l;return this.isLoading()?(l="Select-searching",p=this.props.searchingText):this.state.inputValue||!this.props.asyncOptions?(l="Select-noresults",p=this.props.noResultsText):(l="Select-search-prompt",p=this.props.searchPromptText),n.createElement("div",{className:l},p)},handleOptionLabelClick:function(e,t){this.props.onOptionLabelClick&&this.props.onOptionLabelClick(e,t)},isLoading:function(){return this.props.isLoading||this.state.isLoading},render:function(){var e=r("Select",this.props.className,{"Select--multi":this.props.multi,"is-searchable":this.props.searchable,"is-open":this.state.isOpen,"is-focused":this.state.isFocused,"is-loading":this.isLoading(),"is-disabled":this.props.disabled,"has-value":this.state.value}),t=[];if(this.props.multi&&this.state.values.forEach(function(e){var s=this.props.valueRenderer||this.renderOptionLabel,o=this.handleOptionLabelClick.bind(this,e),i=this.removeValue.bind(this,e),a=n.createElement(this.props.valueComponent,{key:e[this.props.valueKey],option:e,renderer:s,optionLabelClick:!!this.props.onOptionLabelClick,onOptionLabelClick:o,onRemove:i,disabled:this.props.disabled});t.push(a)},this),!(this.state.inputValue||this.props.multi&&t.length)){var s=this.state.values[0]||null;if(this.props.valueRenderer&&this.state.values.length)t.push(n.createElement(l,{key:0,option:s,renderer:this.props.valueRenderer,disabled:this.props.disabled}));else{var o=n.createElement(this.props.singleValueComponent,{key:"placeholder",value:s,placeholder:this.state.placeholder});t.push(o)}}var a,u,c=this.isLoading()?n.createElement("span",{className:"Select-loading-zone","aria-hidden":"true"},n.createElement("span",{className:"Select-loading"})):null,h=this.props.clearable&&this.state.value&&!this.props.disabled&&!this.isLoading()?n.createElement("span",{className:"Select-clear-zone",title:this.props.multi?this.props.clearAllText:this.props.clearValueText,"aria-label":this.props.multi?this.props.clearAllText:this.props.clearValueText,onMouseDown:this.clearValue,onTouchEnd:this.clearValue,onClick:this.clearValue},n.createElement("span",{className:"Select-clear",dangerouslySetInnerHTML:{__html:"×"}})):null,d=n.createElement("span",{className:"Select-arrow-zone",onMouseDown:this.handleMouseDownOnArrow},n.createElement("span",{className:"Select-arrow",onMouseDown:this.handleMouseDownOnArrow}));this.state.isOpen&&(u={ref:"menu",className:"Select-menu",onMouseDown:this.handleMouseDownOnMenu},a=n.createElement("div",{ref:"selectMenuContainer",className:"Select-menu-outer"},n.createElement("div",u,this.buildMenu())));var f,v={ref:"input",className:"Select-input "+(this.props.inputProps.className||""),tabIndex:this.props.tabIndex||0,onFocus:this.handleInputFocus,onBlur:this.handleInputBlur};for(var m in this.props.inputProps)this.props.inputProps.hasOwnProperty(m)&&"className"!==m&&(v[m]=this.props.inputProps[m]);return this.props.disabled?this.props.multi&&this.state.values.length||(f=n.createElement("div",{className:"Select-input"}," ")):f=this.props.searchable?n.createElement(p,i({value:this.state.inputValue,onChange:this.handleInputChange,minWidth:"5"},v)):n.createElement("div",v," "),n.createElement("div",{ref:"wrapper",className:e},n.createElement("input",{type:"hidden",ref:"value",name:this.props.name,value:this.state.value,disabled:this.props.disabled}),n.createElement("div",{className:"Select-control",ref:"control",onKeyDown:this.handleKeyDown,onMouseDown:this.handleMouseDown,onTouchEnd:this.handleMouseDown},t,f,c,h,d),a)}});t.exports=d}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./Option":1,"./SingleValue":3,"./Value":4,"react-dom":void 0}],3:[function(e,t,s){(function(e){"use strict";var s="undefined"!=typeof window?window.React:"undefined"!=typeof e?e.React:null,o="undefined"!=typeof window?window.classNames:"undefined"!=typeof e?e.classNames:null,i=s.createClass({displayName:"SingleValue",propTypes:{placeholder:s.PropTypes.string,value:s.PropTypes.object},render:function(){var e=o("Select-placeholder",this.props.value&&this.props.value.className);return s.createElement("div",{className:e,style:this.props.value&&this.props.value.style,title:this.props.value&&this.props.value.title},this.props.placeholder)}});t.exports=i}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],4:[function(e,t,s){(function(e){"use strict";var s="undefined"!=typeof window?window.React:"undefined"!=typeof e?e.React:null,o="undefined"!=typeof window?window.classNames:"undefined"!=typeof e?e.classNames:null,i=s.createClass({displayName:"Value",propTypes:{disabled:s.PropTypes.bool,onOptionLabelClick:s.PropTypes.func,onRemove:s.PropTypes.func,option:s.PropTypes.object.isRequired,optionLabelClick:s.PropTypes.bool,renderer:s.PropTypes.func},blockEvent:function(e){e.stopPropagation()},handleOnRemove:function(e){this.props.disabled||this.props.onRemove(e)},render:function(){var e=this.props.option.label;return this.props.renderer&&(e=this.props.renderer(this.props.option)),this.props.onRemove||this.props.optionLabelClick?(this.props.optionLabelClick&&(e=s.createElement("a",{className:o("Select-item-label__a",this.props.option.className),onMouseDown:this.blockEvent,onTouchEnd:this.props.onOptionLabelClick,onClick:this.props.onOptionLabelClick,style:this.props.option.style,title:this.props.option.title},e)),s.createElement("div",{className:o("Select-item",this.props.option.className),style:this.props.option.style,title:this.props.option.title},s.createElement("span",{className:"Select-item-icon",onMouseDown:this.blockEvent,onClick:this.handleOnRemove,onTouchEnd:this.handleOnRemove},"×"),s.createElement("span",{className:"Select-item-label"},e))):s.createElement("div",{className:o("Select-value",this.props.option.className),style:this.props.option.style,title:this.props.option.title},e)}});t.exports=i}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[2])(2)}); \ No newline at end of file +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.Select=e()}}(function(){return function e(t,s,o){function i(a,p){if(!s[a]){if(!t[a]){var r="function"==typeof require&&require;if(!p&&r)return r(a,!0);if(n)return n(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var u=s[a]={exports:{}};t[a][0].call(u.exports,function(e){var s=t[a][1][e];return i(s?s:e)},u,u.exports,e,t,s,o)}return s[a].exports}for(var n="function"==typeof require&&require,a=0;ai.bottom||o.top-1)return!1;if(this.props.filterOption)return this.props.filterOption.call(this,e,o);var t=String(e[this.props.valueKey]),s=String(e[this.props.labelKey]);return this.props.ignoreCase&&(t=t.toLowerCase(),s=s.toLowerCase(),o=o.toLowerCase()),o&&"start"!==this.props.matchPos?"label"!==this.props.matchProp&&t.indexOf(o)>=0||"value"!==this.props.matchProp&&s.indexOf(o)>=0:"label"!==this.props.matchProp&&t.substr(0,o.length)===o||"value"!==this.props.matchProp&&s.substr(0,o.length)===o};return(e||[]).filter(n,this)},selectFocusedOption:function(){return this.props.allowCreate&&!this.state.focusedOption?this.selectValue(this.state.inputValue):this.state.focusedOption?this.selectValue(this.state.focusedOption):void 0},focusOption:function(e){this.setState({focusedOption:e})},focusNextOption:function(){this.focusAdjacentOption("next")},focusPreviousOption:function(){this.focusAdjacentOption("previous")},focusAdjacentOption:function(e){this._focusedOptionReveal=!0;var t=this.state.filteredOptions.filter(function(e){return!e.disabled});if(!this.state.isOpen)return void this.setState({isOpen:!0,inputValue:"",focusedOption:this.state.focusedOption||t["next"===e?0:t.length-1]},this._bindCloseMenuIfClickedOutside);if(t.length){for(var s=-1,o=0;o-1&&s0?t[s-1]:t[t.length-1]),this.setState({focusedOption:i})}},unfocusOption:function(e){this.state.focusedOption===e&&this.setState({focusedOption:null})},renderOptionLabel:function(e){return e[this.props.labelKey]},buildMenu:function(){var e=this.state.focusedOption?this.state.focusedOption[this.props.valueKey]:null,t=this.props.optionRenderer||this.renderOptionLabel;this.state.filteredOptions.length>0&&(e=null==e?this.state.filteredOptions[0]:e);var s=this.state.filteredOptions;if(this.props.allowCreate&&this.state.inputValue.trim()){var o=this.state.inputValue;s=s.slice();var i=this.props.newOptionCreator?this.props.newOptionCreator(o):{value:o,label:o,create:!0};s.unshift(i)}var a=Object.keys(s).map(function(o){var i=s[o],a=this.state.value===i[this.props.valueKey],p=e===i[this.props.valueKey],l=r({"Select-option":!0,"is-selected":a,"is-focused":p,"is-disabled":i.disabled}),u=p?"focused":null,c=n.createElement(this.props.optionComponent,{key:"option-"+i[this.props.valueKey],className:l,renderFunc:t,mouseDown:this.selectValue,mouseEnter:this.focusOption,mouseLeave:this.unfocusOption,addLabelText:this.props.addLabelText,option:i,ref:u});return c},this);if(a.length)return a;var p,l;return this.isLoading()?(l="Select-searching",p=this.props.searchingText):this.state.inputValue||!this.props.asyncOptions?(l="Select-noresults",p=this.props.noResultsText):(l="Select-search-prompt",p=this.props.searchPromptText),n.createElement("div",{className:l},p)},handleOptionLabelClick:function(e,t){this.props.onOptionLabelClick&&this.props.onOptionLabelClick(e,t)},isLoading:function(){return this.props.isLoading||this.state.isLoading},render:function(){var e=r("Select",this.props.className,{"Select--multi":this.props.multi,"is-searchable":this.props.searchable,"is-open":this.state.isOpen,"is-focused":this.state.isFocused,"is-loading":this.isLoading(),"is-disabled":this.props.disabled,"has-value":this.state.value}),t=[];if(this.props.multi&&this.state.values.forEach(function(e){var s=this.props.valueRenderer||this.renderOptionLabel,o=this.handleOptionLabelClick.bind(this,e),i=this.removeValue.bind(this,e),a=n.createElement(this.props.valueComponent,{key:e[this.props.valueKey],option:e,renderer:s,optionLabelClick:!!this.props.onOptionLabelClick,onOptionLabelClick:o,onRemove:i,disabled:this.props.disabled});t.push(a)},this),!(this.state.inputValue||this.props.multi&&t.length)){var s=this.state.values[0]||null;if(this.props.valueRenderer&&this.state.values.length)t.push(n.createElement(l,{key:0,option:s,renderer:this.props.valueRenderer,disabled:this.props.disabled}));else{var o=n.createElement(this.props.singleValueComponent,{key:"placeholder",value:s,placeholder:this.state.placeholder});t.push(o)}}var a,u,c=this.isLoading()?n.createElement("span",{className:"Select-loading-zone","aria-hidden":"true"},n.createElement("span",{className:"Select-loading"})):null,h=this.props.clearable&&this.state.value&&!this.props.disabled&&!this.isLoading()?n.createElement("span",{className:"Select-clear-zone",title:this.props.multi?this.props.clearAllText:this.props.clearValueText,"aria-label":this.props.multi?this.props.clearAllText:this.props.clearValueText,onMouseDown:this.clearValue,onTouchEnd:this.clearValue,onClick:this.clearValue},n.createElement("span",{className:"Select-clear",dangerouslySetInnerHTML:{__html:"×"}})):null,d=n.createElement("span",{className:"Select-arrow-zone",onMouseDown:this.handleMouseDownOnArrow},n.createElement("span",{className:"Select-arrow",onMouseDown:this.handleMouseDownOnArrow}));this.state.isOpen&&(u={ref:"menu",className:"Select-menu",onMouseDown:this.handleMouseDownOnMenu},a=n.createElement("div",{ref:"selectMenuContainer",className:"Select-menu-outer"},n.createElement("div",u,this.buildMenu())));var f,v={ref:"input",className:"Select-input "+(this.props.inputProps.className||""),tabIndex:this.props.tabIndex||0,onFocus:this.handleInputFocus,onBlur:this.handleInputBlur};for(var m in this.props.inputProps)this.props.inputProps.hasOwnProperty(m)&&"className"!==m&&(v[m]=this.props.inputProps[m]);return this.props.disabled?this.props.multi&&this.state.values.length||(f=n.createElement("div",{className:"Select-input"}," ")):f=this.props.searchable?n.createElement(p,i({value:this.state.inputValue,onChange:this.handleInputChange,minWidth:"5"},v)):n.createElement("div",v," "),n.createElement("div",{ref:"wrapper",className:e},n.createElement("select",{className:"hidden",ref:"value",name:this.props.name,multiple:!0,value:_.pluck(this.state.values,"value"),disabled:this.props.disabled,readOnly:!0},_.map(this.state.values,function(e){return n.createElement("option",{value:e.value,key:e.value},e.label)})),n.createElement("div",{className:"Select-control",ref:"control",onKeyDown:this.handleKeyDown,onMouseDown:this.handleMouseDown,onTouchEnd:this.handleMouseDown},t,f,c,h,d),a)}});t.exports=d}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./Option":1,"./SingleValue":3,"./Value":4,"react-dom":void 0}],3:[function(e,t,s){(function(e){"use strict";var s="undefined"!=typeof window?window.React:"undefined"!=typeof e?e.React:null,o="undefined"!=typeof window?window.classNames:"undefined"!=typeof e?e.classNames:null,i=s.createClass({displayName:"SingleValue",propTypes:{placeholder:s.PropTypes.string,value:s.PropTypes.object},render:function(){var e=o("Select-placeholder",this.props.value&&this.props.value.className);return s.createElement("div",{className:e,style:this.props.value&&this.props.value.style,title:this.props.value&&this.props.value.title},this.props.placeholder)}});t.exports=i}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],4:[function(e,t,s){(function(e){"use strict";var s="undefined"!=typeof window?window.React:"undefined"!=typeof e?e.React:null,o="undefined"!=typeof window?window.classNames:"undefined"!=typeof e?e.classNames:null,i=s.createClass({displayName:"Value",propTypes:{disabled:s.PropTypes.bool,onOptionLabelClick:s.PropTypes.func,onRemove:s.PropTypes.func,option:s.PropTypes.object.isRequired,optionLabelClick:s.PropTypes.bool,renderer:s.PropTypes.func},blockEvent:function(e){e.stopPropagation()},handleOnRemove:function(e){this.props.disabled||this.props.onRemove(e)},render:function(){var e=this.props.option.label;return this.props.renderer&&(e=this.props.renderer(this.props.option)),this.props.onRemove||this.props.optionLabelClick?(this.props.optionLabelClick&&(e=s.createElement("a",{className:o("Select-item-label__a",this.props.option.className),onMouseDown:this.blockEvent,onTouchEnd:this.props.onOptionLabelClick,onClick:this.props.onOptionLabelClick,style:this.props.option.style,title:this.props.option.title},e)),s.createElement("div",{className:o("Select-item",this.props.option.className),style:this.props.option.style,title:this.props.option.title},s.createElement("span",{className:"Select-item-icon",onMouseDown:this.blockEvent,onClick:this.handleOnRemove,onTouchEnd:this.handleOnRemove},"×"),s.createElement("span",{className:"Select-item-label"},e))):s.createElement("div",{className:o("Select-value",this.props.option.className),style:this.props.option.style,title:this.props.option.title},e)}});t.exports=i}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[2])(2)}); \ No newline at end of file diff --git a/examples/dist/app.js b/examples/dist/app.js index 0300796f8c..590d4525cf 100644 --- a/examples/dist/app.js +++ b/examples/dist/app.js @@ -293,7 +293,7 @@ var Option = _react2['default'].createClass({ module.exports = Option; -},{"react":undefined,"react-gravatar":25}],5:[function(require,module,exports){ +},{"react":undefined,"react-gravatar":20}],5:[function(require,module,exports){ 'use strict'; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } @@ -428,7 +428,7 @@ var SingleValue = _react2['default'].createClass({ module.exports = SingleValue; -},{"react":undefined,"react-gravatar":25}],7:[function(require,module,exports){ +},{"react":undefined,"react-gravatar":20}],7:[function(require,module,exports){ 'use strict'; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } @@ -1043,139 +1043,265 @@ exports.US = [{ value: 'AL', label: 'Alabama', disabled: true }, { value: 'AK', module.exports = [{ value: 'John Smith', label: 'John Smith', email: 'john@smith.com' }, { value: 'Merry Jane', label: 'Merry Jane', email: 'merry@jane.com' }, { value: 'Stan Hoper', label: 'Stan Hoper', email: 'stan@hoper.com' }]; },{}],17:[function(require,module,exports){ -var charenc = { - // UTF-8 encoding - utf8: { - // Convert a string to a byte array - stringToBytes: function(str) { - return charenc.bin.stringToBytes(unescape(encodeURIComponent(str))); - }, +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. - // Convert a byte array to a string - bytesToString: function(bytes) { - return decodeURIComponent(escape(charenc.bin.bytesToString(bytes))); +'use strict'; + +// If obj.hasOwnProperty has been overridden, then calling +// obj.hasOwnProperty(prop) will break. +// See: https://github.com/joyent/node/issues/1707 +function hasOwnProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); +} + +module.exports = function(qs, sep, eq, options) { + sep = sep || '&'; + eq = eq || '='; + var obj = {}; + + if (typeof qs !== 'string' || qs.length === 0) { + return obj; + } + + var regexp = /\+/g; + qs = qs.split(sep); + + var maxKeys = 1000; + if (options && typeof options.maxKeys === 'number') { + maxKeys = options.maxKeys; + } + + var len = qs.length; + // maxKeys <= 0 means that we should not limit keys count + if (maxKeys > 0 && len > maxKeys) { + len = maxKeys; + } + + for (var i = 0; i < len; ++i) { + var x = qs[i].replace(regexp, '%20'), + idx = x.indexOf(eq), + kstr, vstr, k, v; + + if (idx >= 0) { + kstr = x.substr(0, idx); + vstr = x.substr(idx + 1); + } else { + kstr = x; + vstr = ''; } - }, - // Binary encoding - bin: { - // Convert a string to a byte array - stringToBytes: function(str) { - for (var bytes = [], i = 0; i < str.length; i++) - bytes.push(str.charCodeAt(i) & 0xFF); - return bytes; - }, + k = decodeURIComponent(kstr); + v = decodeURIComponent(vstr); - // Convert a byte array to a string - bytesToString: function(bytes) { - for (var str = [], i = 0; i < bytes.length; i++) - str.push(String.fromCharCode(bytes[i])); - return str.join(''); + if (!hasOwnProperty(obj, k)) { + obj[k] = v; + } else if (isArray(obj[k])) { + obj[k].push(v); + } else { + obj[k] = [obj[k], v]; } } + + return obj; }; -module.exports = charenc; +var isArray = Array.isArray || function (xs) { + return Object.prototype.toString.call(xs) === '[object Array]'; +}; },{}],18:[function(require,module,exports){ -(function() { - var base64map - = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/', - - crypt = { - // Bit-wise rotation left - rotl: function(n, b) { - return (n << b) | (n >>> (32 - b)); - }, +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. - // Bit-wise rotation right - rotr: function(n, b) { - return (n << (32 - b)) | (n >>> b); - }, +'use strict'; - // Swap big-endian to little-endian and vice versa - endian: function(n) { - // If number given, swap endian - if (n.constructor == Number) { - return crypt.rotl(n, 8) & 0x00FF00FF | crypt.rotl(n, 24) & 0xFF00FF00; - } +var stringifyPrimitive = function(v) { + switch (typeof v) { + case 'string': + return v; - // Else, assume array and swap all items - for (var i = 0; i < n.length; i++) - n[i] = crypt.endian(n[i]); - return n; - }, + case 'boolean': + return v ? 'true' : 'false'; - // Generate an array of any length of random bytes - randomBytes: function(n) { - for (var bytes = []; n > 0; n--) - bytes.push(Math.floor(Math.random() * 256)); - return bytes; - }, + case 'number': + return isFinite(v) ? v : ''; - // Convert a byte array to big-endian 32-bit words - bytesToWords: function(bytes) { - for (var words = [], i = 0, b = 0; i < bytes.length; i++, b += 8) - words[b >>> 5] |= bytes[i] << (24 - b % 32); - return words; - }, + default: + return ''; + } +}; - // Convert big-endian 32-bit words to a byte array - wordsToBytes: function(words) { - for (var bytes = [], b = 0; b < words.length * 32; b += 8) - bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF); - return bytes; - }, +module.exports = function(obj, sep, eq, name) { + sep = sep || '&'; + eq = eq || '='; + if (obj === null) { + obj = undefined; + } - // Convert a byte array to a hex string - bytesToHex: function(bytes) { - for (var hex = [], i = 0; i < bytes.length; i++) { - hex.push((bytes[i] >>> 4).toString(16)); - hex.push((bytes[i] & 0xF).toString(16)); + if (typeof obj === 'object') { + return map(objectKeys(obj), function(k) { + var ks = encodeURIComponent(stringifyPrimitive(k)) + eq; + if (isArray(obj[k])) { + return map(obj[k], function(v) { + return ks + encodeURIComponent(stringifyPrimitive(v)); + }).join(sep); + } else { + return ks + encodeURIComponent(stringifyPrimitive(obj[k])); } - return hex.join(''); - }, + }).join(sep); - // Convert a hex string to a byte array - hexToBytes: function(hex) { - for (var bytes = [], c = 0; c < hex.length; c += 2) - bytes.push(parseInt(hex.substr(c, 2), 16)); - return bytes; - }, + } - // Convert a byte array to a base-64 string - bytesToBase64: function(bytes) { - for (var base64 = [], i = 0; i < bytes.length; i += 3) { - var triplet = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]; - for (var j = 0; j < 4; j++) - if (i * 8 + j * 6 <= bytes.length * 8) - base64.push(base64map.charAt((triplet >>> 6 * (3 - j)) & 0x3F)); - else - base64.push('='); - } - return base64.join(''); - }, + if (!name) return ''; + return encodeURIComponent(stringifyPrimitive(name)) + eq + + encodeURIComponent(stringifyPrimitive(obj)); +}; - // Convert a base-64 string to a byte array - base64ToBytes: function(base64) { - // Remove non-base-64 characters - base64 = base64.replace(/[^A-Z0-9+\/]/ig, ''); +var isArray = Array.isArray || function (xs) { + return Object.prototype.toString.call(xs) === '[object Array]'; +}; - for (var bytes = [], i = 0, imod4 = 0; i < base64.length; - imod4 = ++i % 4) { - if (imod4 == 0) continue; - bytes.push(((base64map.indexOf(base64.charAt(i - 1)) - & (Math.pow(2, -2 * imod4 + 8) - 1)) << (imod4 * 2)) - | (base64map.indexOf(base64.charAt(i)) >>> (6 - imod4 * 2))); - } - return bytes; - } - }; +function map (xs, f) { + if (xs.map) return xs.map(f); + var res = []; + for (var i = 0; i < xs.length; i++) { + res.push(f(xs[i], i)); + } + return res; +} - module.exports = crypt; -})(); +var objectKeys = Object.keys || function (obj) { + var res = []; + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key); + } + return res; +}; },{}],19:[function(require,module,exports){ +'use strict'; + +exports.decode = exports.parse = require('./decode'); +exports.encode = exports.stringify = require('./encode'); + +},{"./decode":17,"./encode":18}],20:[function(require,module,exports){ +// Generated by CoffeeScript 1.10.0 +var React, isRetina, md5, querystring; + +React = require('react'); + +md5 = require('md5'); + +querystring = require('querystring'); + +isRetina = require('is-retina'); + +module.exports = React.createClass({ + displayName: 'Gravatar', + propTypes: { + email: React.PropTypes.string, + md5: React.PropTypes.string, + size: React.PropTypes.number, + rating: React.PropTypes.string, + https: React.PropTypes.bool, + "default": React.PropTypes.string, + className: React.PropTypes.string + }, + getDefaultProps: function() { + return { + size: 50, + rating: 'g', + https: false, + "default": "retro", + className: "" + }; + }, + render: function() { + var base, hash, modernBrowser, query, retinaQuery, retinaSrc, src; + base = this.props.https ? "https://secure.gravatar.com/avatar/" : 'http://www.gravatar.com/avatar/'; + query = querystring.stringify({ + s: this.props.size, + r: this.props.rating, + d: this.props["default"] + }); + retinaQuery = querystring.stringify({ + s: this.props.size * 2, + r: this.props.rating, + d: this.props["default"] + }); + if (this.props.md5) { + hash = this.props.md5; + } else if (this.props.email) { + hash = md5(this.props.email); + } else { + console.warn('Gravatar image can not be fetched. Either the "email" or "md5" prop must be specified.'); + return React.createElement("script", null); + } + src = base + hash + "?" + query; + retinaSrc = base + hash + "?" + retinaQuery; + modernBrowser = true; + if (typeof window !== "undefined" && window !== null) { + modernBrowser = 'srcset' in document.createElement('img'); + } + if (!modernBrowser && isRetina()) { + return React.createElement("img", { + "style": this.props.style, + "className": "react-gravatar " + this.props.className, + "src": retinaSrc, + "height": this.props.size, + "width": this.props.size + }); + } else { + return React.createElement("img", { + "style": this.props.style, + "className": "react-gravatar " + this.props.className, + "src": src, + "srcSet": retinaSrc + " 2x", + "height": this.props.size, + "width": this.props.size + }); + } + } +}); + +},{"is-retina":21,"md5":22,"querystring":19,"react":undefined}],21:[function(require,module,exports){ module.exports = function() { var mediaQuery; if (typeof window !== "undefined" && window !== null) { @@ -1190,7 +1316,7 @@ module.exports = function() { return false; }; -},{}],20:[function(require,module,exports){ +},{}],22:[function(require,module,exports){ (function(){ var crypt = require('crypt'), utf8 = require('charenc').utf8, @@ -1352,282 +1478,156 @@ module.exports = function() { })(); -},{"charenc":17,"crypt":18,"is-buffer":21}],21:[function(require,module,exports){ -/** - * Determine if an object is Buffer - * - * Author: Feross Aboukhadijeh - * License: MIT - * - * `npm install is-buffer` - */ - -module.exports = function (obj) { - return !!( - obj != null && - obj.constructor && - typeof obj.constructor.isBuffer === 'function' && - obj.constructor.isBuffer(obj) - ) -} - -},{}],22:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; - -// If obj.hasOwnProperty has been overridden, then calling -// obj.hasOwnProperty(prop) will break. -// See: https://github.com/joyent/node/issues/1707 -function hasOwnProperty(obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -} - -module.exports = function(qs, sep, eq, options) { - sep = sep || '&'; - eq = eq || '='; - var obj = {}; - - if (typeof qs !== 'string' || qs.length === 0) { - return obj; - } - - var regexp = /\+/g; - qs = qs.split(sep); - - var maxKeys = 1000; - if (options && typeof options.maxKeys === 'number') { - maxKeys = options.maxKeys; - } - - var len = qs.length; - // maxKeys <= 0 means that we should not limit keys count - if (maxKeys > 0 && len > maxKeys) { - len = maxKeys; - } - - for (var i = 0; i < len; ++i) { - var x = qs[i].replace(regexp, '%20'), - idx = x.indexOf(eq), - kstr, vstr, k, v; +},{"charenc":23,"crypt":24,"is-buffer":25}],23:[function(require,module,exports){ +var charenc = { + // UTF-8 encoding + utf8: { + // Convert a string to a byte array + stringToBytes: function(str) { + return charenc.bin.stringToBytes(unescape(encodeURIComponent(str))); + }, - if (idx >= 0) { - kstr = x.substr(0, idx); - vstr = x.substr(idx + 1); - } else { - kstr = x; - vstr = ''; + // Convert a byte array to a string + bytesToString: function(bytes) { + return decodeURIComponent(escape(charenc.bin.bytesToString(bytes))); } + }, - k = decodeURIComponent(kstr); - v = decodeURIComponent(vstr); + // Binary encoding + bin: { + // Convert a string to a byte array + stringToBytes: function(str) { + for (var bytes = [], i = 0; i < str.length; i++) + bytes.push(str.charCodeAt(i) & 0xFF); + return bytes; + }, - if (!hasOwnProperty(obj, k)) { - obj[k] = v; - } else if (isArray(obj[k])) { - obj[k].push(v); - } else { - obj[k] = [obj[k], v]; + // Convert a byte array to a string + bytesToString: function(bytes) { + for (var str = [], i = 0; i < bytes.length; i++) + str.push(String.fromCharCode(bytes[i])); + return str.join(''); } } - - return obj; }; -var isArray = Array.isArray || function (xs) { - return Object.prototype.toString.call(xs) === '[object Array]'; -}; - -},{}],23:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; - -var stringifyPrimitive = function(v) { - switch (typeof v) { - case 'string': - return v; - - case 'boolean': - return v ? 'true' : 'false'; +module.exports = charenc; - case 'number': - return isFinite(v) ? v : ''; +},{}],24:[function(require,module,exports){ +(function() { + var base64map + = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/', - default: - return ''; - } -}; + crypt = { + // Bit-wise rotation left + rotl: function(n, b) { + return (n << b) | (n >>> (32 - b)); + }, -module.exports = function(obj, sep, eq, name) { - sep = sep || '&'; - eq = eq || '='; - if (obj === null) { - obj = undefined; - } + // Bit-wise rotation right + rotr: function(n, b) { + return (n << (32 - b)) | (n >>> b); + }, - if (typeof obj === 'object') { - return map(objectKeys(obj), function(k) { - var ks = encodeURIComponent(stringifyPrimitive(k)) + eq; - if (isArray(obj[k])) { - return map(obj[k], function(v) { - return ks + encodeURIComponent(stringifyPrimitive(v)); - }).join(sep); - } else { - return ks + encodeURIComponent(stringifyPrimitive(obj[k])); + // Swap big-endian to little-endian and vice versa + endian: function(n) { + // If number given, swap endian + if (n.constructor == Number) { + return crypt.rotl(n, 8) & 0x00FF00FF | crypt.rotl(n, 24) & 0xFF00FF00; } - }).join(sep); - } - - if (!name) return ''; - return encodeURIComponent(stringifyPrimitive(name)) + eq + - encodeURIComponent(stringifyPrimitive(obj)); -}; + // Else, assume array and swap all items + for (var i = 0; i < n.length; i++) + n[i] = crypt.endian(n[i]); + return n; + }, -var isArray = Array.isArray || function (xs) { - return Object.prototype.toString.call(xs) === '[object Array]'; -}; + // Generate an array of any length of random bytes + randomBytes: function(n) { + for (var bytes = []; n > 0; n--) + bytes.push(Math.floor(Math.random() * 256)); + return bytes; + }, -function map (xs, f) { - if (xs.map) return xs.map(f); - var res = []; - for (var i = 0; i < xs.length; i++) { - res.push(f(xs[i], i)); - } - return res; -} + // Convert a byte array to big-endian 32-bit words + bytesToWords: function(bytes) { + for (var words = [], i = 0, b = 0; i < bytes.length; i++, b += 8) + words[b >>> 5] |= bytes[i] << (24 - b % 32); + return words; + }, -var objectKeys = Object.keys || function (obj) { - var res = []; - for (var key in obj) { - if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key); - } - return res; -}; + // Convert big-endian 32-bit words to a byte array + wordsToBytes: function(words) { + for (var bytes = [], b = 0; b < words.length * 32; b += 8) + bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF); + return bytes; + }, -},{}],24:[function(require,module,exports){ -'use strict'; + // Convert a byte array to a hex string + bytesToHex: function(bytes) { + for (var hex = [], i = 0; i < bytes.length; i++) { + hex.push((bytes[i] >>> 4).toString(16)); + hex.push((bytes[i] & 0xF).toString(16)); + } + return hex.join(''); + }, -exports.decode = exports.parse = require('./decode'); -exports.encode = exports.stringify = require('./encode'); + // Convert a hex string to a byte array + hexToBytes: function(hex) { + for (var bytes = [], c = 0; c < hex.length; c += 2) + bytes.push(parseInt(hex.substr(c, 2), 16)); + return bytes; + }, -},{"./decode":22,"./encode":23}],25:[function(require,module,exports){ -// Generated by CoffeeScript 1.10.0 -var React, isRetina, md5, querystring; + // Convert a byte array to a base-64 string + bytesToBase64: function(bytes) { + for (var base64 = [], i = 0; i < bytes.length; i += 3) { + var triplet = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]; + for (var j = 0; j < 4; j++) + if (i * 8 + j * 6 <= bytes.length * 8) + base64.push(base64map.charAt((triplet >>> 6 * (3 - j)) & 0x3F)); + else + base64.push('='); + } + return base64.join(''); + }, -React = require('react'); + // Convert a base-64 string to a byte array + base64ToBytes: function(base64) { + // Remove non-base-64 characters + base64 = base64.replace(/[^A-Z0-9+\/]/ig, ''); -md5 = require('md5'); + for (var bytes = [], i = 0, imod4 = 0; i < base64.length; + imod4 = ++i % 4) { + if (imod4 == 0) continue; + bytes.push(((base64map.indexOf(base64.charAt(i - 1)) + & (Math.pow(2, -2 * imod4 + 8) - 1)) << (imod4 * 2)) + | (base64map.indexOf(base64.charAt(i)) >>> (6 - imod4 * 2))); + } + return bytes; + } + }; -querystring = require('querystring'); + module.exports = crypt; +})(); -isRetina = require('is-retina'); +},{}],25:[function(require,module,exports){ +/** + * Determine if an object is Buffer + * + * Author: Feross Aboukhadijeh + * License: MIT + * + * `npm install is-buffer` + */ -module.exports = React.createClass({ - displayName: 'Gravatar', - propTypes: { - email: React.PropTypes.string, - md5: React.PropTypes.string, - size: React.PropTypes.number, - rating: React.PropTypes.string, - https: React.PropTypes.bool, - "default": React.PropTypes.string, - className: React.PropTypes.string - }, - getDefaultProps: function() { - return { - size: 50, - rating: 'g', - https: false, - "default": "retro", - className: "" - }; - }, - render: function() { - var base, hash, modernBrowser, query, retinaQuery, retinaSrc, src; - base = this.props.https ? "https://secure.gravatar.com/avatar/" : 'http://www.gravatar.com/avatar/'; - query = querystring.stringify({ - s: this.props.size, - r: this.props.rating, - d: this.props["default"] - }); - retinaQuery = querystring.stringify({ - s: this.props.size * 2, - r: this.props.rating, - d: this.props["default"] - }); - if (this.props.md5) { - hash = this.props.md5; - } else if (this.props.email) { - hash = md5(this.props.email); - } else { - console.warn('Gravatar image can not be fetched. Either the "email" or "md5" prop must be specified.'); - return React.createElement("script", null); - } - src = base + hash + "?" + query; - retinaSrc = base + hash + "?" + retinaQuery; - modernBrowser = true; - if (typeof window !== "undefined" && window !== null) { - modernBrowser = 'srcset' in document.createElement('img'); - } - if (!modernBrowser && isRetina()) { - return React.createElement("img", { - "style": this.props.style, - "className": "react-gravatar " + this.props.className, - "src": retinaSrc, - "height": this.props.size, - "width": this.props.size - }); - } else { - return React.createElement("img", { - "style": this.props.style, - "className": "react-gravatar " + this.props.className, - "src": src, - "srcSet": retinaSrc + " 2x", - "height": this.props.size, - "width": this.props.size - }); - } - } -}); +module.exports = function (obj) { + return !!( + obj != null && + obj.constructor && + typeof obj.constructor.isBuffer === 'function' && + obj.constructor.isBuffer(obj) + ) +} -},{"is-retina":19,"md5":20,"querystring":24,"react":undefined}]},{},[1]); +},{}]},{},[1]); diff --git a/examples/dist/bundle.js b/examples/dist/bundle.js index 0cc805636e..e3a8d7ee88 100644 --- a/examples/dist/bundle.js +++ b/examples/dist/bundle.js @@ -1110,7 +1110,17 @@ var Select = React.createClass({ return React.createElement( 'div', { ref: 'wrapper', className: selectClass }, - React.createElement('input', { type: 'hidden', ref: 'value', name: this.props.name, value: this.state.value, disabled: this.props.disabled }), + React.createElement( + 'select', + { className: 'hidden', ref: 'value', name: this.props.name, multiple: true, value: _.pluck(this.state.values, 'value'), disabled: this.props.disabled, readOnly: true }, + _.map(this.state.values, function (value) { + return React.createElement( + 'option', + { value: value.value, key: value.value }, + value.label + ); + }) + ), React.createElement( 'div', { className: 'Select-control', ref: 'control', onKeyDown: this.handleKeyDown, onMouseDown: this.handleMouseDown, onTouchEnd: this.handleMouseDown }, diff --git a/examples/dist/common.js b/examples/dist/common.js index c6ab2b1dc8..837a0a060e 100644 --- a/examples/dist/common.js +++ b/examples/dist/common.js @@ -1,466 +1,447 @@ require=(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 8 && documentMode <= 11); -module.exports = ExecutionEnvironment; -},{}],3:[function(require,module,exports){ /** - * Copyright 2013-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. - * - * @providesModule camelize - * @typechecks + * Opera <= 12 includes TextEvent in window, but does not fire + * text input events. Rely on keypress instead. */ +function isPresto() { + var opera = window.opera; + return typeof opera === 'object' && typeof opera.version === 'function' && parseInt(opera.version(), 10) <= 12; +} -"use strict"; +var SPACEBAR_CODE = 32; +var SPACEBAR_CHAR = String.fromCharCode(SPACEBAR_CODE); -var _hyphenPattern = /-(.)/g; +var topLevelTypes = EventConstants.topLevelTypes; + +// Events and their corresponding property names. +var eventTypes = { + beforeInput: { + phasedRegistrationNames: { + bubbled: keyOf({ onBeforeInput: null }), + captured: keyOf({ onBeforeInputCapture: null }) + }, + dependencies: [topLevelTypes.topCompositionEnd, topLevelTypes.topKeyPress, topLevelTypes.topTextInput, topLevelTypes.topPaste] + }, + compositionEnd: { + phasedRegistrationNames: { + bubbled: keyOf({ onCompositionEnd: null }), + captured: keyOf({ onCompositionEndCapture: null }) + }, + dependencies: [topLevelTypes.topBlur, topLevelTypes.topCompositionEnd, topLevelTypes.topKeyDown, topLevelTypes.topKeyPress, topLevelTypes.topKeyUp, topLevelTypes.topMouseDown] + }, + compositionStart: { + phasedRegistrationNames: { + bubbled: keyOf({ onCompositionStart: null }), + captured: keyOf({ onCompositionStartCapture: null }) + }, + dependencies: [topLevelTypes.topBlur, topLevelTypes.topCompositionStart, topLevelTypes.topKeyDown, topLevelTypes.topKeyPress, topLevelTypes.topKeyUp, topLevelTypes.topMouseDown] + }, + compositionUpdate: { + phasedRegistrationNames: { + bubbled: keyOf({ onCompositionUpdate: null }), + captured: keyOf({ onCompositionUpdateCapture: null }) + }, + dependencies: [topLevelTypes.topBlur, topLevelTypes.topCompositionUpdate, topLevelTypes.topKeyDown, topLevelTypes.topKeyPress, topLevelTypes.topKeyUp, topLevelTypes.topMouseDown] + } +}; + +// Track whether we've ever handled a keypress on the space key. +var hasSpaceKeypress = false; /** - * Camelcases a hyphenated string, for example: - * - * > camelize('background-color') - * < "backgroundColor" - * - * @param {string} string - * @return {string} + * Return whether a native keypress event is assumed to be a command. + * This is required because Firefox fires `keypress` events for key commands + * (cut, copy, select-all, etc.) even though no character is inserted. */ -function camelize(string) { - return string.replace(_hyphenPattern, function (_, character) { - return character.toUpperCase(); - }); +function isKeypressCommand(nativeEvent) { + return (nativeEvent.ctrlKey || nativeEvent.altKey || nativeEvent.metaKey) && + // ctrlKey && altKey is equivalent to AltGr, and is not a command. + !(nativeEvent.ctrlKey && nativeEvent.altKey); } -module.exports = camelize; -},{}],4:[function(require,module,exports){ /** - * Copyright 2013-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. + * Translate native top level events into event types. * - * @providesModule camelizeStyleName - * @typechecks + * @param {string} topLevelType + * @return {object} */ - -'use strict'; - -var camelize = require('./camelize'); - -var msPattern = /^-ms-/; +function getCompositionEventType(topLevelType) { + switch (topLevelType) { + case topLevelTypes.topCompositionStart: + return eventTypes.compositionStart; + case topLevelTypes.topCompositionEnd: + return eventTypes.compositionEnd; + case topLevelTypes.topCompositionUpdate: + return eventTypes.compositionUpdate; + } +} /** - * Camelcases a hyphenated CSS property name, for example: - * - * > camelizeStyleName('background-color') - * < "backgroundColor" - * > camelizeStyleName('-moz-transition') - * < "MozTransition" - * > camelizeStyleName('-ms-transition') - * < "msTransition" - * - * As Andi Smith suggests - * (http://www.andismith.com/blog/2012/02/modernizr-prefixed/), an `-ms` prefix - * is converted to lowercase `ms`. + * Does our fallback best-guess model think this event signifies that + * composition has begun? * - * @param {string} string - * @return {string} + * @param {string} topLevelType + * @param {object} nativeEvent + * @return {boolean} */ -function camelizeStyleName(string) { - return camelize(string.replace(msPattern, 'ms-')); +function isFallbackCompositionStart(topLevelType, nativeEvent) { + return topLevelType === topLevelTypes.topKeyDown && nativeEvent.keyCode === START_KEYCODE; } -module.exports = camelizeStyleName; -},{"./camelize":3}],5:[function(require,module,exports){ -/** - * Copyright 2013-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. - * - * @providesModule containsNode - * @typechecks - */ - -'use strict'; - -var isTextNode = require('./isTextNode'); - -/*eslint-disable no-bitwise */ - /** - * Checks if a given DOM node contains or is another DOM node. + * Does our fallback mode think that this event is the end of composition? * - * @param {?DOMNode} outerNode Outer DOM node. - * @param {?DOMNode} innerNode Inner DOM node. - * @return {boolean} True if `outerNode` contains or is `innerNode`. + * @param {string} topLevelType + * @param {object} nativeEvent + * @return {boolean} */ -function containsNode(_x, _x2) { - var _again = true; - - _function: while (_again) { - var outerNode = _x, - innerNode = _x2; - _again = false; - - if (!outerNode || !innerNode) { - return false; - } else if (outerNode === innerNode) { +function isFallbackCompositionEnd(topLevelType, nativeEvent) { + switch (topLevelType) { + case topLevelTypes.topKeyUp: + // Command keys insert or clear IME input. + return END_KEYCODES.indexOf(nativeEvent.keyCode) !== -1; + case topLevelTypes.topKeyDown: + // Expect IME keyCode on each keydown. If we get any other + // code we must have exited earlier. + return nativeEvent.keyCode !== START_KEYCODE; + case topLevelTypes.topKeyPress: + case topLevelTypes.topMouseDown: + case topLevelTypes.topBlur: + // Events are not possible without cancelling IME. return true; - } else if (isTextNode(outerNode)) { - return false; - } else if (isTextNode(innerNode)) { - _x = outerNode; - _x2 = innerNode.parentNode; - _again = true; - continue _function; - } else if (outerNode.contains) { - return outerNode.contains(innerNode); - } else if (outerNode.compareDocumentPosition) { - return !!(outerNode.compareDocumentPosition(innerNode) & 16); - } else { + default: return false; - } } } -module.exports = containsNode; -},{"./isTextNode":18}],6:[function(require,module,exports){ /** - * Copyright 2013-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. + * Google Input Tools provides composition data via a CustomEvent, + * with the `data` property populated in the `detail` object. If this + * is available on the event object, use it. If not, this is a plain + * composition event and we have nothing special to extract. * - * @providesModule createArrayFromMixed - * @typechecks + * @param {object} nativeEvent + * @return {?string} */ +function getDataFromCustomEvent(nativeEvent) { + var detail = nativeEvent.detail; + if (typeof detail === 'object' && 'data' in detail) { + return detail.data; + } + return null; +} -'use strict'; - -var toArray = require('./toArray'); +// Track the current IME composition fallback object, if any. +var currentComposition = null; /** - * Perform a heuristic test to determine if an object is "array-like". - * - * A monk asked Joshu, a Zen master, "Has a dog Buddha nature?" - * Joshu replied: "Mu." - * - * This function determines if its argument has "array nature": it returns - * true if the argument is an actual array, an `arguments' object, or an - * HTMLCollection (e.g. node.childNodes or node.getElementsByTagName()). - * - * It will return false for other array-like objects like Filelist. - * - * @param {*} obj - * @return {boolean} + * @param {string} topLevelType Record from `EventConstants`. + * @param {DOMEventTarget} topLevelTarget The listening component root node. + * @param {string} topLevelTargetID ID of `topLevelTarget`. + * @param {object} nativeEvent Native browser event. + * @return {?object} A SyntheticCompositionEvent. */ -function hasArrayNature(obj) { - return( - // not null/false - !!obj && ( - // arrays are objects, NodeLists are functions in Safari - typeof obj == 'object' || typeof obj == 'function') && - // quacks like an array - 'length' in obj && - // not window - !('setInterval' in obj) && - // no DOM node should be considered an array-like - // a 'select' element has 'length' and 'item' properties on IE8 - typeof obj.nodeType != 'number' && ( - // a real array - Array.isArray(obj) || - // arguments - 'callee' in obj || - // HTMLCollection/NodeList - 'item' in obj) - ); -} +function extractCompositionEvent(topLevelType, topLevelTarget, topLevelTargetID, nativeEvent, nativeEventTarget) { + var eventType; + var fallbackData; -/** - * Ensure that the argument is an array by wrapping it in an array if it is not. - * Creates a copy of the argument if it is already an array. - * - * This is mostly useful idiomatically: - * - * var createArrayFromMixed = require('createArrayFromMixed'); - * - * function takesOneOrMoreThings(things) { - * things = createArrayFromMixed(things); - * ... - * } - * - * This allows you to treat `things' as an array, but accept scalars in the API. - * - * If you need to convert an array-like object, like `arguments`, into an array - * use toArray instead. - * - * @param {*} obj - * @return {array} - */ -function createArrayFromMixed(obj) { - if (!hasArrayNature(obj)) { - return [obj]; - } else if (Array.isArray(obj)) { - return obj.slice(); - } else { - return toArray(obj); + if (canUseCompositionEvent) { + eventType = getCompositionEventType(topLevelType); + } else if (!currentComposition) { + if (isFallbackCompositionStart(topLevelType, nativeEvent)) { + eventType = eventTypes.compositionStart; + } + } else if (isFallbackCompositionEnd(topLevelType, nativeEvent)) { + eventType = eventTypes.compositionEnd; } -} -module.exports = createArrayFromMixed; -},{"./toArray":26}],7:[function(require,module,exports){ -/** - * Copyright 2013-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. - * - * @providesModule createNodesFromMarkup - * @typechecks - */ + if (!eventType) { + return null; + } -/*eslint-disable fb-www/unsafe-html*/ + if (useFallbackCompositionData) { + // The current composition is stored statically and must not be + // overwritten while composition continues. + if (!currentComposition && eventType === eventTypes.compositionStart) { + currentComposition = FallbackCompositionState.getPooled(topLevelTarget); + } else if (eventType === eventTypes.compositionEnd) { + if (currentComposition) { + fallbackData = currentComposition.getData(); + } + } + } -'use strict'; + var event = SyntheticCompositionEvent.getPooled(eventType, topLevelTargetID, nativeEvent, nativeEventTarget); -var ExecutionEnvironment = require('./ExecutionEnvironment'); + if (fallbackData) { + // Inject data generated from fallback path into the synthetic event. + // This matches the property of native CompositionEventInterface. + event.data = fallbackData; + } else { + var customData = getDataFromCustomEvent(nativeEvent); + if (customData !== null) { + event.data = customData; + } + } -var createArrayFromMixed = require('./createArrayFromMixed'); -var getMarkupWrap = require('./getMarkupWrap'); -var invariant = require('./invariant'); + EventPropagators.accumulateTwoPhaseDispatches(event); + return event; +} /** - * Dummy container used to render all markup. + * @param {string} topLevelType Record from `EventConstants`. + * @param {object} nativeEvent Native browser event. + * @return {?string} The string corresponding to this `beforeInput` event. */ -var dummyNode = ExecutionEnvironment.canUseDOM ? document.createElement('div') : null; +function getNativeBeforeInputChars(topLevelType, nativeEvent) { + switch (topLevelType) { + case topLevelTypes.topCompositionEnd: + return getDataFromCustomEvent(nativeEvent); + case topLevelTypes.topKeyPress: + /** + * If native `textInput` events are available, our goal is to make + * use of them. However, there is a special case: the spacebar key. + * In Webkit, preventing default on a spacebar `textInput` event + * cancels character insertion, but it *also* causes the browser + * to fall back to its default spacebar behavior of scrolling the + * page. + * + * Tracking at: + * https://code.google.com/p/chromium/issues/detail?id=355103 + * + * To avoid this issue, use the keypress event as if no `textInput` + * event is available. + */ + var which = nativeEvent.which; + if (which !== SPACEBAR_CODE) { + return null; + } -/** - * Pattern used by `getNodeName`. - */ -var nodeNamePattern = /^\s*<(\w+)/; + hasSpaceKeypress = true; + return SPACEBAR_CHAR; -/** - * Extracts the `nodeName` of the first element in a string of markup. - * - * @param {string} markup String of markup. - * @return {?string} Node name of the supplied markup. - */ -function getNodeName(markup) { - var nodeNameMatch = markup.match(nodeNamePattern); - return nodeNameMatch && nodeNameMatch[1].toLowerCase(); + case topLevelTypes.topTextInput: + // Record the characters to be added to the DOM. + var chars = nativeEvent.data; + + // If it's a spacebar character, assume that we have already handled + // it at the keypress level and bail immediately. Android Chrome + // doesn't give us keycodes, so we need to blacklist it. + if (chars === SPACEBAR_CHAR && hasSpaceKeypress) { + return null; + } + + return chars; + + default: + // For other native event types, do nothing. + return null; + } } /** - * Creates an array containing the nodes rendered from the supplied markup. The - * optionally supplied `handleScript` function will be invoked once for each - *