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

react-filtered-multiselect

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-filtered-multiselect - npm Package Compare versions

Comparing version 0.4.2 to 0.5.0

es/index.js

10

CHANGES.md

@@ -1,3 +0,11 @@

# 1.2.4 / 2015-11-12
# 0.5.0 / 2017-05-31
**Breaking:** Now requires React >= 0.14.9.
Changed: use `React.Component` and the prop-types module to avoid deprecation warnings [[#11](https://github.com/insin/react-filtered-multiselect/issues/11)] [[jarekwg](https://github.com/jarekwg)]
Changed: link to [unpkg](https://unpkg.com/) for UMD build distribution.
# 0.4.2 / 2015-11-12
Changed UMD build directory.

@@ -4,0 +12,0 @@

250

lib/index.js
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.__esModule = true;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _class, _temp, _initialiseProps;
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _react = require('react');

@@ -13,2 +15,10 @@

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function makeLookup(arr, prop) {

@@ -46,52 +56,27 @@ var lkup = {};

exports['default'] = _react2['default'].createClass({
displayName: 'FilteredMultiSelect',
var FilteredMultiSelect = (_temp = _class = function (_React$Component) {
_inherits(FilteredMultiSelect, _React$Component);
propTypes: {
onChange: _react.PropTypes.func.isRequired,
options: _react.PropTypes.array.isRequired,
function FilteredMultiSelect(props) {
_classCallCheck(this, FilteredMultiSelect);
buttonText: _react.PropTypes.string,
className: _react.PropTypes.string,
classNames: _react.PropTypes.object,
defaultFilter: _react.PropTypes.string,
disabled: _react.PropTypes.bool,
placeholder: _react.PropTypes.string,
selectedOptions: _react.PropTypes.array,
size: _react.PropTypes.number,
textProp: _react.PropTypes.string,
valueProp: _react.PropTypes.string
},
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
getDefaultProps: function getDefaultProps() {
return {
buttonText: 'Select',
className: 'FilteredMultiSelect',
classNames: {},
defaultFilter: '',
disabled: false,
placeholder: 'type to filter',
size: 6,
selectedOptions: [],
textProp: 'text',
valueProp: 'value'
};
},
_initialiseProps.call(_this);
getInitialState: function getInitialState() {
var _props = this.props;
var defaultFilter = _props.defaultFilter;
var selectedOptions = _props.selectedOptions;
var defaultFilter = props.defaultFilter,
selectedOptions = props.selectedOptions;
return {
_this.state = {
// Filter text
filter: defaultFilter,
// Options which haven't been selected and match the filter text
filteredOptions: this._filterOptions(defaultFilter, selectedOptions),
filteredOptions: _this._filterOptions(defaultFilter, selectedOptions),
// Values of <options> currently selected in the <select>
selectedValues: []
};
},
return _this;
}
componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
FilteredMultiSelect.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
// Update visibile options in response to options or selectedOptions

@@ -105,5 +90,5 @@ // changing. Also update selected values after the re-render completes, as

}
},
};
_getClassName: function _getClassName(name) {
FilteredMultiSelect.prototype._getClassName = function _getClassName(name) {
var classNames = [this.props.classNames[name] || DEFAULT_CLASS_NAMES[name]];

@@ -121,5 +106,5 @@

return classNames.join(' ');
},
};
_filterOptions: function _filterOptions(filter, selectedOptions, options) {
FilteredMultiSelect.prototype._filterOptions = function _filterOptions(filter, selectedOptions, options) {
if (typeof filter == 'undefined') {

@@ -136,5 +121,5 @@ filter = this.state.filter;

var _props2 = this.props;
var textProp = _props2.textProp;
var valueProp = _props2.valueProp;
var _props = this.props,
textProp = _props.textProp,
valueProp = _props.valueProp;

@@ -151,44 +136,4 @@ var selectedValueLookup = makeLookup(selectedOptions, valueProp);

return filteredOptions;
},
};
_onFilterChange: function _onFilterChange(e) {
var filter = e.target.value;
this.setState({
filter: filter,
filteredOptions: this._filterOptions(filter)
}, this._updateSelectedValues);
},
_onFilterKeyPress: function _onFilterKeyPress(e) {
var _this = this;
if (e.key === 'Enter') {
e.preventDefault();
if (this.state.filteredOptions.length === 1) {
(function () {
var selectedOption = _this.state.filteredOptions[0];
var selectedOptions = _this.props.selectedOptions.concat([selectedOption]);
_this.setState({ filter: '', selectedValues: [] }, function () {
_this.props.onChange(selectedOptions);
});
})();
}
}
},
_updateSelectedValues: function _updateSelectedValues(e) {
var el = e ? e.target : this.refs.select;
var selectedValues = [];
for (var i = 0, l = el.options.length; i < l; i++) {
if (el.options[i].selected) {
selectedValues.push(el.options[i].value);
}
}
// Always update if we were handling an event, otherwise only update if
// selectedValues has actually changed.
if (e || String(this.state.selectedValues) !== String(selectedValues)) {
this.setState({ selectedValues: selectedValues });
}
},
/**

@@ -198,29 +143,22 @@ * Adds backing objects for the currently selected options to the selection

*/
_addSelectedToSelection: function _addSelectedToSelection(e) {
var _this2 = this;
var selectedOptions = this.props.selectedOptions.concat(getItemsByProp(this.state.filteredOptions, this.props.valueProp, this.state.selectedValues));
this.setState({ selectedValues: [] }, function () {
_this2.props.onChange(selectedOptions);
});
},
render: function render() {
var _state = this.state;
var filter = _state.filter;
var filteredOptions = _state.filteredOptions;
var selectedValues = _state.selectedValues;
var _props3 = this.props;
var className = _props3.className;
var disabled = _props3.disabled;
var placeholder = _props3.placeholder;
var size = _props3.size;
var textProp = _props3.textProp;
var valueProp = _props3.valueProp;
FilteredMultiSelect.prototype.render = function render() {
var _state = this.state,
filter = _state.filter,
filteredOptions = _state.filteredOptions,
selectedValues = _state.selectedValues;
var _props2 = this.props,
className = _props2.className,
disabled = _props2.disabled,
placeholder = _props2.placeholder,
size = _props2.size,
textProp = _props2.textProp,
valueProp = _props2.valueProp;
var hasSelectedOptions = selectedValues.length > 0;
return _react2['default'].createElement(
return _react2.default.createElement(
'div',
{ className: className },
_react2['default'].createElement('input', {
_react2.default.createElement('input', {
type: 'text',

@@ -234,6 +172,6 @@ className: this._getClassName('filter'),

}),
_react2['default'].createElement(
_react2.default.createElement(
'select',
{ multiple: true,
ref: 'select',
ref: this._selectRef,
className: this._getClassName('select'),

@@ -246,3 +184,3 @@ size: size,

filteredOptions.map(function (option) {
return _react2['default'].createElement(
return _react2.default.createElement(
'option',

@@ -254,3 +192,3 @@ { key: option[valueProp], value: option[valueProp] },

),
_react2['default'].createElement(
_react2.default.createElement(
'button',

@@ -264,4 +202,82 @@ { type: 'button',

);
}
});
};
return FilteredMultiSelect;
}(_react2.default.Component), _class.defaultProps = {
buttonText: 'Select',
className: 'FilteredMultiSelect',
classNames: {},
defaultFilter: '',
disabled: false,
placeholder: 'type to filter',
size: 6,
selectedOptions: [],
textProp: 'text',
valueProp: 'value'
}, _initialiseProps = function _initialiseProps() {
var _this2 = this;
this._selectRef = function (select) {
_this2._select = select;
};
this._onFilterChange = function (e) {
var filter = e.target.value;
_this2.setState({
filter: filter,
filteredOptions: _this2._filterOptions(filter)
}, _this2._updateSelectedValues);
};
this._onFilterKeyPress = function (e) {
if (e.key === 'Enter') {
e.preventDefault();
if (_this2.state.filteredOptions.length === 1) {
var selectedOption = _this2.state.filteredOptions[0];
var selectedOptions = _this2.props.selectedOptions.concat([selectedOption]);
_this2.setState({ filter: '', selectedValues: [] }, function () {
_this2.props.onChange(selectedOptions);
});
}
}
};
this._updateSelectedValues = function (e) {
var el = e ? e.target : _this2._select;
var selectedValues = [];
for (var i = 0, l = el.options.length; i < l; i++) {
if (el.options[i].selected) {
selectedValues.push(el.options[i].value);
}
}
// Always update if we were handling an event, otherwise only update if
// selectedValues has actually changed.
if (e || String(_this2.state.selectedValues) !== String(selectedValues)) {
_this2.setState({ selectedValues: selectedValues });
}
};
this._addSelectedToSelection = function (e) {
var selectedOptions = _this2.props.selectedOptions.concat(getItemsByProp(_this2.state.filteredOptions, _this2.props.valueProp, _this2.state.selectedValues));
_this2.setState({ selectedValues: [] }, function () {
_this2.props.onChange(selectedOptions);
});
};
}, _temp);
FilteredMultiSelect.propTypes = process.env.NODE_ENV !== "production" ? {
onChange: _propTypes2.default.func.isRequired,
options: _propTypes2.default.array.isRequired,
buttonText: _propTypes2.default.string,
className: _propTypes2.default.string,
classNames: _propTypes2.default.object,
defaultFilter: _propTypes2.default.string,
disabled: _propTypes2.default.bool,
placeholder: _propTypes2.default.string,
selectedOptions: _propTypes2.default.array,
size: _propTypes2.default.number,
textProp: _propTypes2.default.string,
valueProp: _propTypes2.default.string
} : {};
exports.default = FilteredMultiSelect;
module.exports = exports['default'];
{
"name": "react-filtered-multiselect",
"version": "0.5.0",
"description": "Filtered multi-select React component",
"version": "0.4.2",
"main": "lib/index.js",
"jsnext:main": "src/index.js",
"global": "FilteredMultiSelect",
"externals": {
"react": "React"
},
"homepage": "https://github.com/insin/react-filtered-multiselect",
"license": "MIT",
"author": "Jonny Buchanan <jonathan.buchanan@gmail.com>",
"scripts": {
"test": "nwb lint"
},
"module": "es/index.js",
"files": [
"es",
"lib",
"src",
"umd"
],
"scripts": {
"build": "nwb build-react-component",
"clean": "nwb clean-module && nwb clean-demo",
"lint": "eslint src demo",
"start": "nwb serve-react-demo",
"test": "npm run lint"
},
"dependencies": {
"prop-types": "^15.5.7"
},
"peerDependencies": {
"react": ">=0.14.0"
"react": ">=0.14.9"
},
"devDependencies": {
"bootstrap": "3.3.5",
"nwb": "*",
"react": "0.14.2",
"react-dom": "0.14.2"
"bootstrap": "3.3.x",
"eslint-config-jonnybuchanan": "5.0.x",
"nwb": "0.16.x",
"react": "15.x",
"react-dom": "15.x"
},
"author": "Jonny Buchanan <jonathan.buchanan@gmail.com>",
"homepage": "https://github.com/insin/react-filtered-multiselect",
"license": "MIT",
"repository": {

@@ -34,0 +36,0 @@ "type": "git",

# react-filtered-multiselect
[![Travis][build-badge]][build]
[![Codecov][coverage-badge]][coverage]
[![npm package][npm-badge]][npm]

@@ -37,3 +36,3 @@

````
```
npm install react-filtered-multiselect

@@ -43,5 +42,5 @@ ```

```javascript
var FilteredMultiSelect = require('react-filtered-multiselect')
import FilteredMultiSelect from 'react-filtered-multiselect'
// or
import FilteredMultiSelect from 'react-filtered-multiselect'
const FilteredMultiSelect = require('react-filtered-multiselect')
```

@@ -53,4 +52,4 @@

* [react-filtered-multiselect.js](https://npmcdn.com/react-filtered-multiselect/umd/react-filtered-multiselect.js) (development version)
* [react-filtered-multiselect.min.js](https://npmcdn.com/react-filtered-multiselect/umd/react-filtered-multiselect.min.js) (compressed production version)
* [react-filtered-multiselect.js](https://unpkg.com/react-filtered-multiselect/umd/react-filtered-multiselect.js) (development version)
* [react-filtered-multiselect.min.js](https://unpkg.com/react-filtered-multiselect/umd/react-filtered-multiselect.min.js) (compressed production version)

@@ -63,4 +62,4 @@ ## API

```javascript
var options = [
```js
let options = [
{value: 1, text: 'Item One'},

@@ -78,3 +77,3 @@ {value: 2, text: 'Item Two'}

The component will update its display if its `options` list changes length or is replaced with a different list, but it will *not* be able to detect changes which don't affect length or object equality, such as replacement of one option with another. Consider using `react-addons-update` or other immutability helpers if you need to do this.
The component will update its display if its `options` list changes length or is replaced with a different list, but it will *not* be able to detect changes which don't affect length or object equality, such as replacement of one option with another. Consider using [immutability-helper](https://github.com/kolodny/immutability-helper) or other immutability libraries if you need to do this.

@@ -110,3 +109,3 @@ `onChange(selectedOptions)` - callback which will be called with selected option objects each time the selection is added to.

```javascript
```js
{

@@ -136,4 +135,4 @@ buttonText: 'Select',

```javascript
var CULTURE_SHIPS = [
```js
const CULTURE_SHIPS = [
{id: 1, name: '5*Gelish-Oplule'},

@@ -146,6 +145,4 @@ {id: 2, name: '7*Uagren'},

var Example = React.createClass({
getInitialState() {
return {selectedShips: []}
},
class Example extends React.Component {
state = {selectedShips: []}

@@ -156,6 +153,7 @@ handleDeselect(index) {

this.setState({selectedShips})
},
handleSelectionChange(selectedShips) {
}
handleSelectionChange = (selectedShips) => {
this.setState({selectedShips})
},
}

@@ -176,3 +174,3 @@ render() {

{`${ship.name} `}
<button type="button" onClick={this.handleDeselect.bind(null, i)}>
<button type="button" onClick={() => this.handleDeselect(i)}>
&times;

@@ -184,13 +182,10 @@ </button>

}
})
}
```
## MIT Licensed
[build-badge]: https://img.shields.io/travis/insin/react-filtered-multiselect/master.svg
[build-badge]: https://img.shields.io/travis/insin/react-filtered-multiselect/master.png?style=flat-square
[build]: https://travis-ci.org/insin/react-filtered-multiselect
[coverage-badge]: https://img.shields.io/codecov/c/github/insin/react-filtered-multiselect.svg
[coverage]: https://codecov.io/github/insin/react-filtered-multiselect
[npm-badge]: https://img.shields.io/npm/v/react-filtered-multiselect.svg
[npm-badge]: https://img.shields.io/npm/v/react-filtered-multiselect.png?style=flat-square
[npm]: https://www.npmjs.org/package/react-filtered-multiselect
/*!
* react-filtered-multiselect 0.4.2 - https://github.com/insin/react-filtered-multiselect
* react-filtered-multiselect v0.5.0 - https://github.com/insin/react-filtered-multiselect
* MIT Licensed

@@ -14,43 +14,69 @@ */

root["FilteredMultiSelect"] = factory(root["React"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__) {
})(this, function(__WEBPACK_EXTERNAL_MODULE_8__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ return __webpack_require__(__webpack_require__.s = 9);
/******/ })

@@ -60,270 +86,1138 @@ /************************************************************************/

/* 0 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {
'use strict';
"use strict";
Object.defineProperty(exports, '__esModule', {
value: true
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
/**
* 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.
*
*
*/
var _react = __webpack_require__(1);
function makeEmptyFunction(arg) {
return function () {
return arg;
};
}
var _react2 = _interopRequireDefault(_react);
/**
* 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() {};
function makeLookup(arr, prop) {
var lkup = {};
for (var i = 0, l = arr.length; i < l; i++) {
if (prop) {
lkup[arr[i][prop]] = true;
} else {
lkup[arr[i]] = true;
}
}
return lkup;
}
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;
};
function getItemsByProp(arr, prop, values) {
var items = [];
var found = 0;
var valuesLookup = makeLookup(values);
for (var i = 0, la = arr.length, lv = values.length; i < la && found < lv; i++) {
if (valuesLookup[arr[i][prop]]) {
items.push(arr[i]);
found++;
}
}
return items;
}
module.exports = emptyFunction;
var DEFAULT_CLASS_NAMES = {
button: 'FilteredMultiSelect__button',
buttonActive: 'FilteredMultiSelect__button--active',
filter: 'FilteredMultiSelect__filter',
select: 'FilteredMultiSelect__select'
};
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
exports['default'] = _react2['default'].createClass({
displayName: 'FilteredMultiSelect',
"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.
*
*/
propTypes: {
onChange: _react.PropTypes.func.isRequired,
options: _react.PropTypes.array.isRequired,
buttonText: _react.PropTypes.string,
className: _react.PropTypes.string,
classNames: _react.PropTypes.object,
defaultFilter: _react.PropTypes.string,
disabled: _react.PropTypes.bool,
placeholder: _react.PropTypes.string,
selectedOptions: _react.PropTypes.array,
size: _react.PropTypes.number,
textProp: _react.PropTypes.string,
valueProp: _react.PropTypes.string
},
getDefaultProps: function getDefaultProps() {
return {
buttonText: 'Select',
className: 'FilteredMultiSelect',
classNames: {},
defaultFilter: '',
disabled: false,
placeholder: 'type to filter',
size: 6,
selectedOptions: [],
textProp: 'text',
valueProp: 'value'
};
},
/**
* 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.
*/
getInitialState: function getInitialState() {
var _props = this.props;
var defaultFilter = _props.defaultFilter;
var selectedOptions = _props.selectedOptions;
var validateFormat = function validateFormat(format) {};
return {
// Filter text
filter: defaultFilter,
// Options which haven't been selected and match the filter text
filteredOptions: this._filterOptions(defaultFilter, selectedOptions),
// Values of <options> currently selected in the <select>
selectedValues: []
};
},
if (true) {
validateFormat = function validateFormat(format) {
if (format === undefined) {
throw new Error('invariant requires an error message argument');
}
};
}
componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
// Update visibile options in response to options or selectedOptions
// changing. Also update selected values after the re-render completes, as
// one of the previously selected options may have been removed.
if (nextProps.options !== this.props.options || nextProps.selectedOptions !== this.props.selectedOptions || nextProps.options.length !== this.props.options.length || nextProps.selectedOptions.length !== this.props.selectedOptions.length) {
this.setState({
filteredOptions: this._filterOptions(this.state.filter, nextProps.selectedOptions, nextProps.options)
}, this._updateSelectedValues);
}
},
function invariant(condition, format, a, b, c, d, e, f) {
validateFormat(format);
_getClassName: function _getClassName(name) {
var classNames = [this.props.classNames[name] || DEFAULT_CLASS_NAMES[name]];
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';
}
for (var _len = arguments.length, modifiers = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
modifiers[_key - 1] = arguments[_key];
}
error.framesToPop = 1; // we don't care about invariant's own frame
throw error;
}
}
for (var i = 0, l = modifiers.length; i < l; i++) {
if (modifiers[i]) {
classNames.push(this.props.classNames[modifiers[i]] || DEFAULT_CLASS_NAMES[modifiers[i]]);
}
}
return classNames.join(' ');
},
module.exports = invariant;
_filterOptions: function _filterOptions(filter, selectedOptions, options) {
if (typeof filter == 'undefined') {
filter = this.state.filter;
}
if (typeof selectedOptions == 'undefined') {
selectedOptions = this.props.selectedOptions;
}
if (typeof options == 'undefined') {
options = this.props.options;
}
filter = filter.toUpperCase();
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
var _props2 = this.props;
var textProp = _props2.textProp;
var valueProp = _props2.valueProp;
"use strict";
/**
* 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.
*
*/
var selectedValueLookup = makeLookup(selectedOptions, valueProp);
var filteredOptions = [];
for (var i = 0, l = options.length; i < l; i++) {
if (!selectedValueLookup[options[i][valueProp]] && (!filter || options[i][textProp].toUpperCase().indexOf(filter) !== -1)) {
filteredOptions.push(options[i]);
}
}
return filteredOptions;
},
var emptyFunction = __webpack_require__(0);
_onFilterChange: function _onFilterChange(e) {
var filter = e.target.value;
this.setState({
filter: filter,
filteredOptions: this._filterOptions(filter)
}, this._updateSelectedValues);
},
/**
* 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.
*/
_onFilterKeyPress: function _onFilterKeyPress(e) {
var _this = this;
var warning = emptyFunction;
if (e.key === 'Enter') {
e.preventDefault();
if (this.state.filteredOptions.length === 1) {
(function () {
var selectedOption = _this.state.filteredOptions[0];
var selectedOptions = _this.props.selectedOptions.concat([selectedOption]);
_this.setState({ filter: '', selectedValues: [] }, function () {
_this.props.onChange(selectedOptions);
});
})();
}
}
},
if (true) {
(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];
}
_updateSelectedValues: function _updateSelectedValues(e) {
var el = e ? e.target : this.refs.select;
var selectedValues = [];
for (var i = 0, l = el.options.length; i < l; i++) {
if (el.options[i].selected) {
selectedValues.push(el.options[i].value);
}
}
// Always update if we were handling an event, otherwise only update if
// selectedValues has actually changed.
if (e || String(this.state.selectedValues) !== String(selectedValues)) {
this.setState({ selectedValues: selectedValues });
}
},
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) {}
};
/**
* Adds backing objects for the currently selected options to the selection
* and calls back with the new list.
*/
_addSelectedToSelection: function _addSelectedToSelection(e) {
var _this2 = this;
warning = function warning(condition, format) {
if (format === undefined) {
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
}
var selectedOptions = this.props.selectedOptions.concat(getItemsByProp(this.state.filteredOptions, this.props.valueProp, this.state.selectedValues));
this.setState({ selectedValues: [] }, function () {
_this2.props.onChange(selectedOptions);
});
},
if (format.indexOf('Failed Composite propType: ') === 0) {
return; // Ignore CompositeComponent proptype check.
}
render: function render() {
var _state = this.state;
var filter = _state.filter;
var filteredOptions = _state.filteredOptions;
var selectedValues = _state.selectedValues;
var _props3 = this.props;
var className = _props3.className;
var disabled = _props3.disabled;
var placeholder = _props3.placeholder;
var size = _props3.size;
var textProp = _props3.textProp;
var valueProp = _props3.valueProp;
if (!condition) {
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
args[_key2 - 2] = arguments[_key2];
}
var hasSelectedOptions = selectedValues.length > 0;
return _react2['default'].createElement(
'div',
{ className: className },
_react2['default'].createElement('input', {
type: 'text',
className: this._getClassName('filter'),
placeholder: placeholder,
value: filter,
onChange: this._onFilterChange,
onKeyPress: this._onFilterKeyPress,
disabled: disabled
}),
_react2['default'].createElement(
'select',
{ multiple: true,
ref: 'select',
className: this._getClassName('select'),
size: size,
value: selectedValues,
onChange: this._updateSelectedValues,
onDoubleClick: this._addSelectedToSelection,
disabled: disabled },
filteredOptions.map(function (option) {
return _react2['default'].createElement(
'option',
{ key: option[valueProp], value: option[valueProp] },
option[textProp]
);
})
),
_react2['default'].createElement(
'button',
{ type: 'button',
className: this._getClassName('button', hasSelectedOptions && 'buttonActive'),
disabled: !hasSelectedOptions,
onClick: this._addSelectedToSelection },
this.props.buttonText
)
);
}
});
module.exports = exports['default'];
printWarning.apply(undefined, [format].concat(args));
}
};
})();
}
/***/ },
/* 1 */
/***/ function(module, exports) {
module.exports = warning;
module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
/***/ }
/******/ ])
});
;
"use strict";
/**
* 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.
*/
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
module.exports = ReactPropTypesSecret;
/***/ }),
/* 4 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_prop_types__ = __webpack_require__(7);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_prop_types___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_prop_types__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_react__ = __webpack_require__(8);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_react___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_react__);
var _class,
_temp,
_initialiseProps,
_jsxFileName = 'C:\\Users\\Jonny\\repos\\react-filtered-multiselect\\src\\index.js';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function makeLookup(arr, prop) {
var lkup = {};
for (var i = 0, l = arr.length; i < l; i++) {
if (prop) {
lkup[arr[i][prop]] = true;
} else {
lkup[arr[i]] = true;
}
}
return lkup;
}
function getItemsByProp(arr, prop, values) {
var items = [];
var found = 0;
var valuesLookup = makeLookup(values);
for (var i = 0, la = arr.length, lv = values.length; i < la && found < lv; i++) {
if (valuesLookup[arr[i][prop]]) {
items.push(arr[i]);
found++;
}
}
return items;
}
var DEFAULT_CLASS_NAMES = {
button: 'FilteredMultiSelect__button',
buttonActive: 'FilteredMultiSelect__button--active',
filter: 'FilteredMultiSelect__filter',
select: 'FilteredMultiSelect__select'
};
var FilteredMultiSelect = (_temp = _class = function (_React$Component) {
_inherits(FilteredMultiSelect, _React$Component);
function FilteredMultiSelect(props) {
_classCallCheck(this, FilteredMultiSelect);
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
_initialiseProps.call(_this);
var defaultFilter = props.defaultFilter,
selectedOptions = props.selectedOptions;
_this.state = {
// Filter text
filter: defaultFilter,
// Options which haven't been selected and match the filter text
filteredOptions: _this._filterOptions(defaultFilter, selectedOptions),
// Values of <options> currently selected in the <select>
selectedValues: []
};
return _this;
}
FilteredMultiSelect.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
// Update visibile options in response to options or selectedOptions
// changing. Also update selected values after the re-render completes, as
// one of the previously selected options may have been removed.
if (nextProps.options !== this.props.options || nextProps.selectedOptions !== this.props.selectedOptions || nextProps.options.length !== this.props.options.length || nextProps.selectedOptions.length !== this.props.selectedOptions.length) {
this.setState({
filteredOptions: this._filterOptions(this.state.filter, nextProps.selectedOptions, nextProps.options)
}, this._updateSelectedValues);
}
};
FilteredMultiSelect.prototype._getClassName = function _getClassName(name) {
var classNames = [this.props.classNames[name] || DEFAULT_CLASS_NAMES[name]];
for (var _len = arguments.length, modifiers = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
modifiers[_key - 1] = arguments[_key];
}
for (var i = 0, l = modifiers.length; i < l; i++) {
if (modifiers[i]) {
classNames.push(this.props.classNames[modifiers[i]] || DEFAULT_CLASS_NAMES[modifiers[i]]);
}
}
return classNames.join(' ');
};
FilteredMultiSelect.prototype._filterOptions = function _filterOptions(filter, selectedOptions, options) {
if (typeof filter == 'undefined') {
filter = this.state.filter;
}
if (typeof selectedOptions == 'undefined') {
selectedOptions = this.props.selectedOptions;
}
if (typeof options == 'undefined') {
options = this.props.options;
}
filter = filter.toUpperCase();
var _props = this.props,
textProp = _props.textProp,
valueProp = _props.valueProp;
var selectedValueLookup = makeLookup(selectedOptions, valueProp);
var filteredOptions = [];
for (var i = 0, l = options.length; i < l; i++) {
if (!selectedValueLookup[options[i][valueProp]] && (!filter || options[i][textProp].toUpperCase().indexOf(filter) !== -1)) {
filteredOptions.push(options[i]);
}
}
return filteredOptions;
};
/**
* Adds backing objects for the currently selected options to the selection
* and calls back with the new list.
*/
FilteredMultiSelect.prototype.render = function render() {
var _this2 = this;
var _state = this.state,
filter = _state.filter,
filteredOptions = _state.filteredOptions,
selectedValues = _state.selectedValues;
var _props2 = this.props,
className = _props2.className,
disabled = _props2.disabled,
placeholder = _props2.placeholder,
size = _props2.size,
textProp = _props2.textProp,
valueProp = _props2.valueProp;
var hasSelectedOptions = selectedValues.length > 0;
return __WEBPACK_IMPORTED_MODULE_1_react___default.a.createElement(
'div',
{ className: className, __source: {
fileName: _jsxFileName,
lineNumber: 193
},
__self: this
},
__WEBPACK_IMPORTED_MODULE_1_react___default.a.createElement('input', {
type: 'text',
className: this._getClassName('filter'),
placeholder: placeholder,
value: filter,
onChange: this._onFilterChange,
onKeyPress: this._onFilterKeyPress,
disabled: disabled,
__source: {
fileName: _jsxFileName,
lineNumber: 194
},
__self: this
}),
__WEBPACK_IMPORTED_MODULE_1_react___default.a.createElement(
'select',
{ multiple: true,
ref: this._selectRef,
className: this._getClassName('select'),
size: size,
value: selectedValues,
onChange: this._updateSelectedValues,
onDoubleClick: this._addSelectedToSelection,
disabled: disabled, __source: {
fileName: _jsxFileName,
lineNumber: 203
},
__self: this
},
filteredOptions.map(function (option) {
return __WEBPACK_IMPORTED_MODULE_1_react___default.a.createElement(
'option',
{ key: option[valueProp], value: option[valueProp], __source: {
fileName: _jsxFileName,
lineNumber: 212
},
__self: _this2
},
option[textProp]
);
})
),
__WEBPACK_IMPORTED_MODULE_1_react___default.a.createElement(
'button',
{ type: 'button',
className: this._getClassName('button', hasSelectedOptions && 'buttonActive'),
disabled: !hasSelectedOptions,
onClick: this._addSelectedToSelection, __source: {
fileName: _jsxFileName,
lineNumber: 215
},
__self: this
},
this.props.buttonText
)
);
};
return FilteredMultiSelect;
}(__WEBPACK_IMPORTED_MODULE_1_react___default.a.Component), _class.propTypes = {
onChange: __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.func.isRequired,
options: __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.array.isRequired,
buttonText: __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.string,
className: __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.string,
classNames: __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.object,
defaultFilter: __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.string,
disabled: __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.bool,
placeholder: __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.string,
selectedOptions: __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.array,
size: __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.number,
textProp: __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.string,
valueProp: __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.string
}, _class.defaultProps = {
buttonText: 'Select',
className: 'FilteredMultiSelect',
classNames: {},
defaultFilter: '',
disabled: false,
placeholder: 'type to filter',
size: 6,
selectedOptions: [],
textProp: 'text',
valueProp: 'value'
}, _initialiseProps = function _initialiseProps() {
var _this3 = this;
this._selectRef = function (select) {
_this3._select = select;
};
this._onFilterChange = function (e) {
var filter = e.target.value;
_this3.setState({
filter: filter,
filteredOptions: _this3._filterOptions(filter)
}, _this3._updateSelectedValues);
};
this._onFilterKeyPress = function (e) {
if (e.key === 'Enter') {
e.preventDefault();
if (_this3.state.filteredOptions.length === 1) {
var selectedOption = _this3.state.filteredOptions[0];
var selectedOptions = _this3.props.selectedOptions.concat([selectedOption]);
_this3.setState({ filter: '', selectedValues: [] }, function () {
_this3.props.onChange(selectedOptions);
});
}
}
};
this._updateSelectedValues = function (e) {
var el = e ? e.target : _this3._select;
var selectedValues = [];
for (var i = 0, l = el.options.length; i < l; i++) {
if (el.options[i].selected) {
selectedValues.push(el.options[i].value);
}
}
// Always update if we were handling an event, otherwise only update if
// selectedValues has actually changed.
if (e || String(_this3.state.selectedValues) !== String(selectedValues)) {
_this3.setState({ selectedValues: selectedValues });
}
};
this._addSelectedToSelection = function (e) {
var selectedOptions = _this3.props.selectedOptions.concat(getItemsByProp(_this3.state.filteredOptions, _this3.props.valueProp, _this3.state.selectedValues));
_this3.setState({ selectedValues: [] }, function () {
_this3.props.onChange(selectedOptions);
});
};
}, _temp);
/* harmony default export */ __webpack_exports__["default"] = (FilteredMultiSelect);
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* 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 (true) {
var invariant = __webpack_require__(1);
var warning = __webpack_require__(2);
var ReactPropTypesSecret = __webpack_require__(3);
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 (true) {
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;
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* 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.
*/
var emptyFunction = __webpack_require__(0);
var invariant = __webpack_require__(1);
var warning = __webpack_require__(2);
var ReactPropTypesSecret = __webpack_require__(3);
var checkPropTypes = __webpack_require__(5);
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 = '<<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 (true) {
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 ("development" !== '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)) {
true ? 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)) {
true ? 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;
};
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
/**
* 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 (true) {
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 = __webpack_require__(6)(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')();
}
/***/ }),
/* 8 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_8__;
/***/ }),
/* 9 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(4);
/***/ })
/******/ ]);
});
/*!
* react-filtered-multiselect 0.4.2 - https://github.com/insin/react-filtered-multiselect
* react-filtered-multiselect v0.5.0 - https://github.com/insin/react-filtered-multiselect
* MIT Licensed
*/
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.FilteredMultiSelect=t(require("react")):e.FilteredMultiSelect=t(e.React)}(this,function(e){return function(e){function t(i){if(s[i])return s[i].exports;var l=s[i]={exports:{},id:i,loaded:!1};return e[i].call(l.exports,l,l.exports,t),l.loaded=!0,l.exports}var s={};return t.m=e,t.c=s,t.p="",t(0)}([function(e,t,s){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}function l(e,t){for(var s={},i=0,l=e.length;l>i;i++)t?s[e[i][t]]=!0:s[e[i]]=!0;return s}function o(e,t,s){for(var i=[],o=0,r=l(s),n=0,a=e.length,p=s.length;a>n&&p>o;n++)r[e[n][t]]&&(i.push(e[n]),o++);return i}Object.defineProperty(t,"__esModule",{value:!0});var r=s(1),n=i(r),a={button:"FilteredMultiSelect__button",buttonActive:"FilteredMultiSelect__button--active",filter:"FilteredMultiSelect__filter",select:"FilteredMultiSelect__select"};t.default=n.default.createClass({displayName:"FilteredMultiSelect",propTypes:{onChange:r.PropTypes.func.isRequired,options:r.PropTypes.array.isRequired,buttonText:r.PropTypes.string,className:r.PropTypes.string,classNames:r.PropTypes.object,defaultFilter:r.PropTypes.string,disabled:r.PropTypes.bool,placeholder:r.PropTypes.string,selectedOptions:r.PropTypes.array,size:r.PropTypes.number,textProp:r.PropTypes.string,valueProp:r.PropTypes.string},getDefaultProps:function(){return{buttonText:"Select",className:"FilteredMultiSelect",classNames:{},defaultFilter:"",disabled:!1,placeholder:"type to filter",size:6,selectedOptions:[],textProp:"text",valueProp:"value"}},getInitialState:function(){var e=this.props,t=e.defaultFilter,s=e.selectedOptions;return{filter:t,filteredOptions:this._filterOptions(t,s),selectedValues:[]}},componentWillReceiveProps:function(e){(e.options!==this.props.options||e.selectedOptions!==this.props.selectedOptions||e.options.length!==this.props.options.length||e.selectedOptions.length!==this.props.selectedOptions.length)&&this.setState({filteredOptions:this._filterOptions(this.state.filter,e.selectedOptions,e.options)},this._updateSelectedValues)},_getClassName:function(e){for(var t=[this.props.classNames[e]||a[e]],s=arguments.length,i=Array(s>1?s-1:0),l=1;s>l;l++)i[l-1]=arguments[l];for(var o=0,r=i.length;r>o;o++)i[o]&&t.push(this.props.classNames[i[o]]||a[i[o]]);return t.join(" ")},_filterOptions:function(e,t,s){"undefined"==typeof e&&(e=this.state.filter),"undefined"==typeof t&&(t=this.props.selectedOptions),"undefined"==typeof s&&(s=this.props.options),e=e.toUpperCase();for(var i=this.props,o=i.textProp,r=i.valueProp,n=l(t,r),a=[],p=0,u=s.length;u>p;p++)n[s[p][r]]||e&&-1===s[p][o].toUpperCase().indexOf(e)||a.push(s[p]);return a},_onFilterChange:function(e){var t=e.target.value;this.setState({filter:t,filteredOptions:this._filterOptions(t)},this._updateSelectedValues)},_onFilterKeyPress:function(e){var t=this;"Enter"===e.key&&(e.preventDefault(),1===this.state.filteredOptions.length&&!function(){var e=t.state.filteredOptions[0],s=t.props.selectedOptions.concat([e]);t.setState({filter:"",selectedValues:[]},function(){t.props.onChange(s)})}())},_updateSelectedValues:function(e){for(var t=e?e.target:this.refs.select,s=[],i=0,l=t.options.length;l>i;i++)t.options[i].selected&&s.push(t.options[i].value);(e||String(this.state.selectedValues)!==String(s))&&this.setState({selectedValues:s})},_addSelectedToSelection:function(e){var t=this,s=this.props.selectedOptions.concat(o(this.state.filteredOptions,this.props.valueProp,this.state.selectedValues));this.setState({selectedValues:[]},function(){t.props.onChange(s)})},render:function(){var e=this.state,t=e.filter,s=e.filteredOptions,i=e.selectedValues,l=this.props,o=l.className,r=l.disabled,a=l.placeholder,p=l.size,u=l.textProp,c=l.valueProp,d=i.length>0;return n.default.createElement("div",{className:o},n.default.createElement("input",{type:"text",className:this._getClassName("filter"),placeholder:a,value:t,onChange:this._onFilterChange,onKeyPress:this._onFilterKeyPress,disabled:r}),n.default.createElement("select",{multiple:!0,ref:"select",className:this._getClassName("select"),size:p,value:i,onChange:this._updateSelectedValues,onDoubleClick:this._addSelectedToSelection,disabled:r},s.map(function(e){return n.default.createElement("option",{key:e[c],value:e[c]},e[u])})),n.default.createElement("button",{type:"button",className:this._getClassName("button",d&&"buttonActive"),disabled:!d,onClick:this._addSelectedToSelection},this.props.buttonText))}}),e.exports=t.default},function(t,s){t.exports=e}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.FilteredMultiSelect=t(require("react")):e.FilteredMultiSelect=t(e.React)}(this,function(e){return function(e){function t(n){if(o[n])return o[n].exports;var s=o[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,t),s.l=!0,s.exports}var o={};return t.m=e,t.c=o,t.i=function(e){return e},t.d=function(e,o,n){t.o(e,o)||Object.defineProperty(e,o,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var o=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(o,"a",o),o},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=2)}([function(e,t,o){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function r(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function i(e,t){for(var o={},n=0,s=e.length;n<s;n++)t?o[e[n][t]]=!0:o[e[n]]=!0;return o}function l(e,t,o){for(var n=[],s=0,r=i(o),l=0,a=e.length,p=o.length;l<a&&s<p;l++)r[e[l][t]]&&(n.push(e[l]),s++);return n}Object.defineProperty(t,"__esModule",{value:!0});var a,p,c,u=o(1),f=o.n(u),d={button:"FilteredMultiSelect__button",buttonActive:"FilteredMultiSelect__button--active",filter:"FilteredMultiSelect__filter",select:"FilteredMultiSelect__select"},h=(p=a=function(e){function t(o){n(this,t);var r=s(this,e.call(this,o));c.call(r);var i=o.defaultFilter,l=o.selectedOptions;return r.state={filter:i,filteredOptions:r._filterOptions(i,l),selectedValues:[]},r}return r(t,e),t.prototype.componentWillReceiveProps=function(e){e.options===this.props.options&&e.selectedOptions===this.props.selectedOptions&&e.options.length===this.props.options.length&&e.selectedOptions.length===this.props.selectedOptions.length||this.setState({filteredOptions:this._filterOptions(this.state.filter,e.selectedOptions,e.options)},this._updateSelectedValues)},t.prototype._getClassName=function(e){for(var t=[this.props.classNames[e]||d[e]],o=arguments.length,n=Array(o>1?o-1:0),s=1;s<o;s++)n[s-1]=arguments[s];for(var r=0,i=n.length;r<i;r++)n[r]&&t.push(this.props.classNames[n[r]]||d[n[r]]);return t.join(" ")},t.prototype._filterOptions=function(e,t,o){void 0===e&&(e=this.state.filter),void 0===t&&(t=this.props.selectedOptions),void 0===o&&(o=this.props.options),e=e.toUpperCase();for(var n=this.props,s=n.textProp,r=n.valueProp,l=i(t,r),a=[],p=0,c=o.length;p<c;p++)l[o[p][r]]||e&&-1===o[p][s].toUpperCase().indexOf(e)||a.push(o[p]);return a},t.prototype.render=function(){var e=this.state,t=e.filter,o=e.filteredOptions,n=e.selectedValues,s=this.props,r=s.className,i=s.disabled,l=s.placeholder,a=s.size,p=s.textProp,c=s.valueProp,u=n.length>0;return f.a.createElement("div",{className:r},f.a.createElement("input",{type:"text",className:this._getClassName("filter"),placeholder:l,value:t,onChange:this._onFilterChange,onKeyPress:this._onFilterKeyPress,disabled:i}),f.a.createElement("select",{multiple:!0,ref:this._selectRef,className:this._getClassName("select"),size:a,value:n,onChange:this._updateSelectedValues,onDoubleClick:this._addSelectedToSelection,disabled:i},o.map(function(e){return f.a.createElement("option",{key:e[c],value:e[c]},e[p])})),f.a.createElement("button",{type:"button",className:this._getClassName("button",u&&"buttonActive"),disabled:!u,onClick:this._addSelectedToSelection},this.props.buttonText))},t}(f.a.Component),a.defaultProps={buttonText:"Select",className:"FilteredMultiSelect",classNames:{},defaultFilter:"",disabled:!1,placeholder:"type to filter",size:6,selectedOptions:[],textProp:"text",valueProp:"value"},c=function(){var e=this;this._selectRef=function(t){e._select=t},this._onFilterChange=function(t){var o=t.target.value;e.setState({filter:o,filteredOptions:e._filterOptions(o)},e._updateSelectedValues)},this._onFilterKeyPress=function(t){if("Enter"===t.key&&(t.preventDefault(),1===e.state.filteredOptions.length)){var o=e.state.filteredOptions[0],n=e.props.selectedOptions.concat([o]);e.setState({filter:"",selectedValues:[]},function(){e.props.onChange(n)})}},this._updateSelectedValues=function(t){for(var o=t?t.target:e._select,n=[],s=0,r=o.options.length;s<r;s++)o.options[s].selected&&n.push(o.options[s].value);(t||String(e.state.selectedValues)!==String(n))&&e.setState({selectedValues:n})},this._addSelectedToSelection=function(t){var o=e.props.selectedOptions.concat(l(e.state.filteredOptions,e.props.valueProp,e.state.selectedValues));e.setState({selectedValues:[]},function(){e.props.onChange(o)})}},p);t.default=h},function(t,o){t.exports=e},function(e,t,o){e.exports=o(0)}])});
//# sourceMappingURL=react-filtered-multiselect.min.js.map

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc