UNPKG

react-basic-tabs

Version:
1,638 lines (1,302 loc) 60.2 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("React")); else if(typeof define === 'function' && define.amd) define(["React"], factory); else if(typeof exports === 'object') exports["TabPanel"] = factory(require("React")); else root["TabPanel"] = factory(root["React"]); })(this, function(__WEBPACK_EXTERNAL_MODULE_1__) { 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]) /******/ return installedModules[moduleId].exports; /******/ /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.loaded = 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; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ function(module, exports, __webpack_require__) { /** @jsx React.DOM */'use strict'; var React = __webpack_require__(1) var copy = __webpack_require__(5).copy var copyList = __webpack_require__(5).copyList var copyKeys = __webpack_require__(5).copyKeys var copyExceptKeys = __webpack_require__(5).copyExceptKeys var Strip = __webpack_require__(2) var Container = __webpack_require__(3) var StripFactory = React.createFactory(Strip) var ContainerFactory = React.createFactory(Container) var BASE_CLASS_NAME = __webpack_require__(4) function emptyFn(){} var TabPanel = React.createClass({displayName: 'TabPanel', propTypes: { activeIndex : React.PropTypes.number, //for panels activeStyle : React.PropTypes.object, activeClassName : React.PropTypes.string, defaultStyle : React.PropTypes.object, defaultClassName : React.PropTypes.string, //for titles titleStyle : React.PropTypes.object, titleClassName : React.PropTypes.string, activeTitleStyle : React.PropTypes.object, activeTitleClassName: React.PropTypes.string, onChange : React.PropTypes.func, stripListStyle : React.PropTypes.object, stripFactory : React.PropTypes.func, containerFactory: React.PropTypes.func, //specify 'bottom' if you want to render the strip after the container tabVerticalPosition : React.PropTypes.string }, getDefaultProps: function(){ return { activeIndex: 0, //for panels activeStyle: {}, activeClassName: 'active', defaultStyle: {}, defaultClassName: '', //for titles titleStyle: {}, titleClassName: '', activeTitleStyle: {}, activeTitleClassName: 'active', tabVerticalPosition: 'top' } }, render: function(){ var props = copy(this.props) props.children = props.children || [] var activeIndex = props.activeIndex || 0 props.activeIndex = Math.min(activeIndex, props.children.length - 1) props.className = props.className || '' props.className += ' ' + BASE_CLASS_NAME var StripComponent = this.renderStrip(props) var ContainerComponent = this.renderContainer(props) var Content = props.tabVerticalPosition == 'bottom'? [ContainerComponent, StripComponent]: [StripComponent, ContainerComponent] var divProps = { className: props.className, style : props.style } return ( React.createElement("div", React.__spread({}, divProps), Content ) ) }, renderContainer: function(props) { var containerProps = copyList(props, [ 'activeIndex', 'activeClassName', 'activeStyle', 'defaultStyle', 'defaultClassName', 'hiddenStyle', 'children' ]) containerProps.key = 'container' if (props.containerFactory){ return props.containerFactory(containerProps, ContainerFactory) } return ContainerFactory(containerProps) }, renderStrip: function(props){ var stripProps = copyExceptKeys(props, {},{ stripStyle: 1, activeTitleStyle: 1, activeTitleClassName: 1 }) copyKeys(props, stripProps, { stripStyle : 'style', activeTitleStyle : 'activeStyle', activeTitleClassName: 'activeClassName' }) stripProps.key = 'strip' stripProps.onChange = this.handleChange || emptyFn if (props.stripFactory){ return props.stripFactory(stripProps, StripFactory) } return StripFactory(stripProps) }, handleChange: function(index){ this.props.onChange(index) } }) TabPanel.Strip = Strip TabPanel.Container = Container module.exports = TabPanel /***/ }, /* 1 */ /***/ function(module, exports, __webpack_require__) { module.exports = __WEBPACK_EXTERNAL_MODULE_1__; /***/ }, /* 2 */ /***/ function(module, exports, __webpack_require__) { /** @jsx React.DOM */'use strict'; var React = __webpack_require__(1) var copy = __webpack_require__(5).copy var F = __webpack_require__(12) var buffer = F.buffer var BASE_CLASS_NAME = __webpack_require__(4) function stop(event){ event.preventDefault() event.stopPropagation() } var LIST_ITEM_STYLE = { display: 'inline-block' } var LIST_STYLE = { margin : 0, padding : 0, listStyle: 'none', position : 'relative', display : 'inline-block' } var SCROLLER_STYLE = { top : 0, position : 'absolute', // display : 'inline-block', height : '100%', cursor : 'pointer' } var Scroller = React.createClass({displayName: 'Scroller', display: 'Scroller', getDefaultProps: function(){ return { width: 5 } }, render: function(){ var props = this.props var side = this.props.side props.className = props.className || '' props.className += ' ' + BASE_CLASS_NAME + '-scroller ' + side if (props.active && props.visible){ props.className += ' active' } var scrollerStyle = copy(SCROLLER_STYLE) props.style = copy(props.style, scrollerStyle) props.style.width = props.style.width || props.width props.style[side] = 0 if (!props.visible){ props.style.display = 'none' } return props.factory? props.factory(props, side): React.createElement("div", React.__spread({}, props)) } }) var ScrollerFactory = React.createFactory(Scroller) module.exports = React.createClass({displayName: 'exports', display: 'TabPanel.Strip', propTypes: { activeIndex : React.PropTypes.number, activeStyle : React.PropTypes.object, activeClassName: React.PropTypes.string, titleStyle : React.PropTypes.object, titleClassName: React.PropTypes.string, anchorStyle : React.PropTypes.object, scrollerStyle : React.PropTypes.object, scrollerProps : React.PropTypes.object, scrollerWidth : React.PropTypes.number, scrollStep : React.PropTypes.number, scrollSpeed : React.PropTypes.number //each item in the TabPanel can also specify a titleStyle //and a titleClassName, which are added to the values in props }, getInitialState: function(){ return { adjustScroll: true, scrollPos : 0 } }, componentWillUnmount: function(){ if (this.props.enableScroll){ window.removeEventListener('resize', this.onResizeListener) } }, componentDidMount: function(){ if (this.props.enableScroll){ setTimeout(function(){ this.adjustScroll() window.addEventListener('resize', this.onResizeListener = buffer(this.onWindowResize, this.props.onWindowResizeBuffer, this)) }.bind(this), 0) } }, componentDidUpdate: function(){ this.props.enableScroll && this.adjustScroll() }, onWindowResize: function(){ this.adjustScroll() this.doScroll(0) }, adjustScroll: function(){ if (!this.props.enableScroll){ return } if (!this.state.adjustScroll){ this.state.adjustScroll = true return } var availableWidth = this.getAvailableStripWidth() var listWidth = this.getCurrentListWidth() var state = { adjustScroll : false, hasLeftScroll : false, hasRightScroll: false } if (listWidth > availableWidth){ state.maxScrollPos = listWidth - availableWidth state.hasLeftScroll = this.state.scrollPos !== 0 state.hasRightScroll = this.state.scrollPos != state.maxScrollPos } else { state.maxScrollPos = 0 state.scrollPos = 0 } this.setState(state) }, getCurrentListWidth: function(){ return this.refs.list.getDOMNode().offsetWidth }, getAvailableStripWidth: function(){ var dom = this.getDOMNode() var domComputedStyle = window.getComputedStyle(dom) var leftPadding = parseInt(domComputedStyle.left, 10) var rightPadding = parseInt(domComputedStyle.right, 10) if (isNaN(leftPadding)){ leftPadding = 0 } if (isNaN(rightPadding)){ rightPadding = 0 } return dom.clientWidth - leftPadding - rightPadding }, handleScrollLeft: function(event){ event.preventDefault() this.handleScroll(-1) }, handleScrollRight: function(event){ event.preventDefault() this.handleScroll(1) }, handleScrollLeftMax: function(event){ stop(event) this.handleScrollMax(-1) }, handleScrollRightMax: function(event){ stop(event) this.handleScrollMax(1) }, handleScrollMax: function(direction){ var maxPos = direction == -1? 0: this.state.maxScrollPos this.setScrollPosition(maxPos) }, handleScroll: function(direction /*1 to right, -1 to left*/){ var mouseUpListener = function(){ this.stopScroll() window.removeEventListener('mouseup', mouseUpListener) }.bind(this) window.addEventListener('mouseup', mouseUpListener) this.scrollInterval = setInterval(this.doScroll.bind(this, direction), this.props.scrollSpeed) }, doScroll: function(direction){ this.setState({ scrollDirection: direction }) var newScrollPos = this.state.scrollPos + direction * this.props.scrollStep this.setScrollPosition(newScrollPos) }, setScrollPosition: function(scrollPos){ if (scrollPos > this.state.maxScrollPos){ scrollPos = this.state.maxScrollPos } if (scrollPos < 0){ scrollPos = 0 } this.setState({ scrollPos: scrollPos, scrolling : true }) }, stopScroll: function(){ clearInterval(this.scrollInterval) this.setState({ scrolling: false }) }, getDefaultProps: function(){ return { onWindowResizeBuffer: 50, scrollStep : 5, scrollSpeed : 50, scrollerWidth : 8, scrollerProps : {}, enableScroll: false, hasLeftScroll: false, hasRightScroll: false, activeClassName: '', activeStyle: {}, anchorStyle: { color : 'inherit', textDecoration: 'inherit' } } }, renderTitle: F.curry(function(parentProps, classNameArray, titleStyle, child, index){ var anchorStyle = parentProps.anchorStyle var activeStyle = parentProps.activeStyle var activeClassName = parentProps.activeClassName var activeIndex = parentProps.activeIndex || 0 var childProps = child.props var title = childProps.tabTitle || childProps.title titleStyle = copy(titleStyle) //ALLOW each item to also specify a titleStyle copy(childProps.titleStyle, titleStyle) //and a titleClassName var titleClassName = classNameArray.concat(childProps.titleClassName || '') if (index == activeIndex){ copy(activeStyle, titleStyle) titleClassName.push(activeClassName || '') } return ( React.createElement("li", { key: index, onClick: this.handleChange.bind(this, index), style: titleStyle, className: titleClassName.join(' ') }, React.createElement("a", {href: "#", style: anchorStyle}, title) ) ) }), render: function(){ var props = copy(this.props) var titleStyle = copy(LIST_ITEM_STYLE) copy(props.titleStyle, titleStyle) var titleClassName = [props.titleClassName || '', BASE_CLASS_NAME + '-item-title'] var nodes = props.children.map(this.renderTitle(props, titleClassName, titleStyle), this) props.className = props.className || '' props.className += ' ' + BASE_CLASS_NAME + '-strip' props.style = props.style || {} props.style.position = 'relative' var listStyle = copy(LIST_STYLE) if (this.state.scrollPos){ listStyle.left = -this.state.scrollPos } var scrollerLeft = this.renderScroller(-1) var scrollerRight= this.renderScroller(1) return ( React.createElement("nav", React.__spread({}, props), React.createElement("ul", {ref: "list", style: listStyle}, nodes ), scrollerLeft, scrollerRight ) ) }, handleChange: function(index, event){ event.preventDefault() this.props.onChange(index) }, renderScroller: function(direction){ if (!this.props.enableScroll){ return } var onDoubleClick = direction == -1? this.handleScrollLeftMax: this.handleScrollRightMax var onMouseDown = direction == -1? this.handleScrollLeft: this.handleScrollRight var side = direction == -1? 'left': 'right' var visible = direction == -1? this.state.hasLeftScroll: this.state.hasRightScroll return ScrollerFactory(copy(this.props.scrollerProps, { factory : this.props.scrollerFactory, active : this.state.scrollDirection==direction && this.state.scrolling, onDoubleClick: onDoubleClick, onMouseDown : onMouseDown, style : this.props.scrollerStyle, side : side, width : this.props.scrollerWidth, visible : visible })) } }) /***/ }, /* 3 */ /***/ function(module, exports, __webpack_require__) { /** @jsx React.DOM */'use strict'; var React = __webpack_require__(1) var copy = __webpack_require__(5).copy var BASE_CLASS_NAME = __webpack_require__(4) module.exports = React.createClass({ displayName: 'TabPanel.Container', propTypes: { activeIndex : React.PropTypes.number, defaultClassName: React.PropTypes.string, defaultStyle : React.PropTypes.object, hiddenStyle : React.PropTypes.object, activeClassName : React.PropTypes.string, activeStyle : React.PropTypes.object }, getDefaultProps: function(){ return { activeIndex: 0, hiddenStyle: { display: 'none' } } }, render: function(){ return ( React.createElement("section", {className: BASE_CLASS_NAME + "-container"}, this.props.children.map(this.renderItem, this) ) ) }, renderItem: function(item, index, array){ var props = this.props var hiddenStyle = props.hiddenStyle var activeIndex = props.activeIndex || 0 //make sure the wrapping article gets the correct style //if it is the active item var style = {} var className = BASE_CLASS_NAME + '-item ' if (index !== activeIndex){ copy(hiddenStyle, style) } else { copy(props.activeStyle, style) className += props.activeClassName || '' } //default style for items if (props.defaultStyle){ item.props.style = copy(props.defaultStyle, item.props.style) } //default className for items if (props.defaultClassName){ item.props.className = item.props.className || '' item.props.className += ' ' + props.defaultClassName } return ( React.createElement("article", {key: index, style: style, className: className}, item ) ) } }) /***/ }, /* 4 */ /***/ function(module, exports, __webpack_require__) { module.exports = 'basic-tabs' /***/ }, /* 5 */ /***/ function(module, exports, __webpack_require__) { module.exports = function(){ 'use strict' var HAS_OWN = Object.prototype.hasOwnProperty, STR_OBJECT = 'object', STR_UNDEFINED = 'undefined' return { /** * Copies all properties from source to destination * * copy({name: 'jon',age:5}, this); * // => this will have the 'name' and 'age' properties set to 'jon' and 5 respectively * * @param {Object} source * @param {Object} destination * * @return {Object} destination */ copy: __webpack_require__(6), /** * Copies all properties from source to destination, if the property does not exist into the destination * * copyIf({name: 'jon',age:5}, {age:7}) * // => { name: 'jon', age: 7} * * @param {Object} source * @param {Object} destination * * @return {Object} destination */ copyIf: __webpack_require__(7), /** * Copies all properties from source to a new object, with the given value. This object is returned * * copyAs({name: 'jon',age:5}) * // => the resulting object will have the 'name' and 'age' properties set to 1 * * @param {Object} source * @param {Object/Number/String} [value=1] * * @return {Object} destination */ copyAs: function(source, value){ var destination = {} value = value || 1 if (source != null && typeof source === STR_OBJECT ){ for (var i in source) if ( HAS_OWN.call(source, i) ) { destination[i] = value } } return destination }, /** * Copies all properties named in the list, from source to destination * * copyList({name: 'jon',age:5, year: 2006}, {}, ['name','age']) * // => {name: 'jon', age: 5} * * @param {Object} source * @param {Object} destination * @param {Array} list the array with the names of the properties to copy * * @return {Object} destination */ copyList: __webpack_require__(8), /** * Copies all properties named in the list, from source to destination, if the property does not exist into the destination * * copyListIf({name: 'jon',age:5, year: 2006}, {age: 10}, ['name','age']) * // => {name: 'jon', age: 10} * * @param {Object} source * @param {Object} destination * @param {Array} list the array with the names of the properties to copy * * @return {Object} destination */ copyListIf: __webpack_require__(9), /** * Copies all properties named in the namedKeys, from source to destination * * copyKeys({name: 'jon',age:5, year: 2006, date: '2010/05/12'}, {}, {name:1 ,age: true, year: 'theYear'}) * // => {name: 'jon', age: 5, theYear: 2006} * * @param {Object} source * @param {Object} destination * @param {Object} namedKeys an object with keys denoting the properties to be copied * * @return {Object} destination */ copyKeys: __webpack_require__(10), /** * Copies all properties named in the namedKeys, from source to destination, * but only if the property does not already exist in the destination object * * copyKeysIf({name: 'jon',age:5, year: 2006}, {aname: 'test'}, {name:'aname' ,age: true}) * // => {aname: 'test', age: 5} * * @param {Object} source * @param {Object} destination * @param {Object} namedKeys an object with keys denoting the properties to be copied * * @return {Object} destination */ copyKeysIf: __webpack_require__(11), copyExceptKeys: function(source, destination, exceptKeys){ destination = destination || {} exceptKeys = exceptKeys || {} if (source != null && typeof source === STR_OBJECT ){ for (var i in source) if ( HAS_OWN.call(source, i) && !HAS_OWN.call(exceptKeys, i) ) { destination[i] = source[i] } } return destination }, /** * Copies the named keys from source to destination. * For the keys that are functions, copies the functions bound to the source * * @param {Object} source The source object * @param {Object} destination The target object * @param {Object} namedKeys An object with the names of the keys to copy The values from the keys in this object * need to be either numbers or booleans if you want to copy the property under the same name, * or a string if you want to copy the property under a different name * @return {Object} Returns the destination object */ bindCopyKeys: function(source, destination, namedKeys){ if (arguments.length == 2){ namedKeys = destination destination = null } destination = destination || {} if ( source != null && typeof source === STR_OBJECT && namedKeys != null && typeof namedKeys === STR_OBJECT ) { var typeOfNamedProperty, namedPropertyValue, typeOfSourceProperty, propValue for(var propName in namedKeys) if (HAS_OWN.call(namedKeys, propName)) { namedPropertyValue = namedKeys[propName] typeOfNamedProperty = typeof namedPropertyValue propValue = source[propName] typeOfSourceProperty = typeof propValue if ( typeOfSourceProperty !== STR_UNDEFINED ) { destination[ typeOfNamedProperty == 'string'? namedPropertyValue : propName ] = typeOfSourceProperty == 'function' ? propValue.bind(source): propValue } } } return destination } } }() /***/ }, /* 6 */ /***/ function(module, exports, __webpack_require__) { 'use strict' var HAS_OWN = Object.prototype.hasOwnProperty var STR_OBJECT = 'object' /** * Copies all properties from source to destination * * copy({name: 'jon',age:5}, this); * // => this will have the 'name' and 'age' properties set to 'jon' and 5 respectively * * @param {Object} source * @param {Object} destination * * @return {Object} destination */ module.exports = function(source, destination){ destination = destination || {} if (source != null && typeof source === STR_OBJECT ){ for (var i in source) if ( HAS_OWN.call(source, i) ) { destination[i] = source[i] } } return destination } /***/ }, /* 7 */ /***/ function(module, exports, __webpack_require__) { 'use strict' var HAS_OWN = Object.prototype.hasOwnProperty var STR_OBJECT = 'object' var STR_UNDEFINED = 'undefined' /** * Copies all properties from source to destination, if the property does not exist into the destination * * copyIf({name: 'jon',age:5}, {age:7}) * // => { name: 'jon', age: 7} * * @param {Object} source * @param {Object} destination * * @return {Object} destination */ module.exports = function(source, destination){ destination = destination || {} if (source != null && typeof source === STR_OBJECT){ for (var i in source) if ( HAS_OWN.call(source, i) && (typeof destination[i] === STR_UNDEFINED) ) { destination[i] = source[i] } } return destination } /***/ }, /* 8 */ /***/ function(module, exports, __webpack_require__) { 'use strict' var STR_UNDEFINED = 'undefined' /** * Copies all properties named in the list, from source to destination * * copyList({name: 'jon',age:5, year: 2006}, {}, ['name','age']) * // => {name: 'jon', age: 5} * * @param {Object} source * @param {Object} destination * @param {Array} list the array with the names of the properties to copy * * @return {Object} destination */ module.exports = function(source, destination, list){ if (arguments.length < 3){ list = destination destination = null } destination = destination || {} list = list || Object.keys(source) var i = 0 var len = list.length var propName for ( ; i < len; i++ ){ propName = list[i] if ( typeof source[propName] !== STR_UNDEFINED ) { destination[list[i]] = source[list[i]] } } return destination } /***/ }, /* 9 */ /***/ function(module, exports, __webpack_require__) { 'use strict' var STR_UNDEFINED = 'undefined' /** * Copies all properties named in the list, from source to destination, if the property does not exist into the destination * * copyListIf({name: 'jon',age:5, year: 2006}, {age: 10}, ['name','age']) * // => {name: 'jon', age: 10} * * @param {Object} source * @param {Object} destination * @param {Array} list the array with the names of the properties to copy * * @return {Object} destination */ module.exports = function(source, destination, list){ if (arguments.length < 3){ list = destination destination = null } destination = destination || {} list = list || Object.keys(source) var i = 0 var len = list.length var propName for ( ; i < len ; i++ ){ propName = list[i] if ( (typeof source[propName] !== STR_UNDEFINED) && (typeof destination[propName] === STR_UNDEFINED) ){ destination[propName] = source[propName] } } return destination } /***/ }, /* 10 */ /***/ function(module, exports, __webpack_require__) { 'use strict' var STR_UNDEFINED = 'undefined' var STR_OBJECT = 'object' var HAS_OWN = Object.prototype.hasOwnProperty var copyList = __webpack_require__(8) /** * Copies all properties named in the namedKeys, from source to destination * * copyKeys({name: 'jon',age:5, year: 2006, date: '2010/05/12'}, {}, {name:1 ,age: true, year: 'theYear'}) * // => {name: 'jon', age: 5, theYear: 2006} * * @param {Object} source * @param {Object} destination * @param {Object} namedKeys an object with keys denoting the properties to be copied * * @return {Object} destination */ module.exports = function(source, destination, namedKeys){ if (arguments.length < 3 ){ namedKeys = destination destination = null } destination = destination || {} if (!namedKeys || Array.isArray(namedKeys)){ return copyList(source, destination, namedKeys) } if ( source != null && typeof source === STR_OBJECT && namedKeys != null && typeof namedKeys === STR_OBJECT ) { var typeOfNamedProperty var namedPropertyValue for (var propName in namedKeys) if ( HAS_OWN.call(namedKeys, propName) ) { namedPropertyValue = namedKeys[propName] typeOfNamedProperty = typeof namedPropertyValue if (typeof source[propName] !== STR_UNDEFINED){ destination[typeOfNamedProperty == 'string'? namedPropertyValue : propName] = source[propName] } } } return destination } /***/ }, /* 11 */ /***/ function(module, exports, __webpack_require__) { 'use strict' var STR_UNDEFINED = 'undefined' var STR_OBJECT = 'object' var HAS_OWN = Object.prototype.hasOwnProperty var copyListIf = __webpack_require__(9) /** * Copies all properties named in the namedKeys, from source to destination, * but only if the property does not already exist in the destination object * * copyKeysIf({name: 'jon',age:5, year: 2006}, {aname: 'test'}, {name:'aname' ,age: true}) * // => {aname: 'test', age: 5} * * @param {Object} source * @param {Object} destination * @param {Object} namedKeys an object with keys denoting the properties to be copied * * @return {Object} destination */ module.exports = function(source, destination, namedKeys){ if (arguments.length < 3 ){ namedKeys = destination destination = null } destination = destination || {} if (!namedKeys || Array.isArray(namedKeys)){ return copyListIf(source, destination, namedKeys) } if ( source != null && typeof source === STR_OBJECT && namedKeys != null && typeof namedKeys === STR_OBJECT ) { var typeOfNamedProperty var namedPropertyValue var newPropertyName for (var propName in namedKeys) if ( HAS_OWN.call(namedKeys, propName) ) { namedPropertyValue = namedKeys[propName] typeOfNamedProperty = typeof namedPropertyValue newPropertyName = typeOfNamedProperty == 'string'? namedPropertyValue : propName if ( typeof source[propName] !== STR_UNDEFINED && typeof destination[newPropertyName] === STR_UNDEFINED ) { destination[newPropertyName] = source[propName] } } } return destination } /***/ }, /* 12 */ /***/ function(module, exports, __webpack_require__) { var setImmediate = function(fn){ setTimeout(fn, 0) } var clearImmediate = clearTimeout /** * Utility methods for working with functions. * These methods augment the Function prototype. * * Using {@link #before} * * function log(m){ * console.log(m) * } * * var doLog = function (m){ * console.log('LOG ') * }.before(log) * * doLog('test') * //will log * //"LOG " * //and then * //"test" * * * * Using {@link #bindArgs}: * * //returns the sum of all arguments * function add(){ * var sum = 0 * [].from(arguments).forEach(function(n){ * sum += n * }) * * return sum * } * * var add1 = add.bindArgs(1) * * add1(2, 3) == 6 * * Using {@link #lockArgs}: * * function add(){ * var sum = 0 * [].from(arguments).forEach(function(n){ * sum += n * }) * * return sum * } * * var add1_2 = add.lockArgs(1,2) * var add1_2_3 = add.lockArgs(1,2,3) * * add1_2(3,4) == 3 //args are locked to only be 1 and 2 * add1_2_3(6) == 6 //args are locked to only be 1, 2 and 3 * * * * Using {@link #compose}: * * function multiply(a,b){ * return a* b * } * * var multiply2 = multiply.curry()(2) * * Function.compose(multiply2( add(5,6) )) == multiply2( add(5,6) ) * * * @class Function */ var SLICE = Array.prototype.slice var curry = __webpack_require__(13), findFn = function(fn, target, onFound){ // if (typeof target.find == 'function'){ // return target.find(fn) // } onFound = typeof onFound == 'function'? onFound: function(found, key, target){ return found } if (Array.isArray(target)){ var i = 0 var len = target.length var it for(; i < len; i++){ it = target[i] if (fn(it, i, target)){ return onFound(it, i, target) } } return } if (typeof target == 'object'){ var keys = Object.keys(target) var i = 0 var len = keys.length var k var it for( ; i < len; i++){ k = keys[i] it = target[k] if (fn(it, k, target)){ return onFound(it, k, target) } } } }, find = curry(findFn, 2), findIndex = curry(function(fn, target){ return findFn(fn, target, function(it, i){ return i }) }), bindFunctionsOf = function(obj) { Object.keys(obj).forEach(function(k){ if (typeof obj[k] == 'function'){ obj[k] = obj[k].bind(obj) } }) return obj }, /* * @param {Function...} an enumeration of functions, each consuming the result of the following function. * * For example: compose(c, b, a)(1,4) == c(b(a(1,4))) * * @return the result of the first function in the enumeration */ compose = __webpack_require__(14), chain = __webpack_require__(15), once = __webpack_require__(16), bindArgsArray = __webpack_require__(17), bindArgs = __webpack_require__(18), lockArgsArray = __webpack_require__(19), lockArgs = __webpack_require__(20), skipArgs = function(fn, count){ return function(){ var args = SLICE.call(arguments, count || 0) return fn.apply(this, args) } }, intercept = function(interceptedFn, interceptingFn, withStopArg){ return function(){ var args = [].from(arguments), stopArg = { stop: false } if (withStopArg){ args.push(stopArg) } var result = interceptingFn.apply(this, args) if (withStopArg){ if (stopArg.stop === true){ return result } } else { if (result === false){ return result } } //the interception was not stopped return interceptedFn.apply(this, arguments) } }, delay = function(fn, delay, scope){ var delayIsNumber = delay * 1 == delay if (arguments.length == 2 && !delayIsNumber){ scope = delay delay = 0 } else { if (!delayIsNumber){ delay = 0 } } return function(){ var self = scope || this, args = arguments if (delay < 0){ fn.apply(self, args) return } if (delay || !setImmediate){ setTimeout(function(){ fn.apply(self, args) }, delay) } else { setImmediate(function(){ fn.apply(self, args) }) } } }, defer = function(fn, scope){ return delay(fn, 0, scope) }, buffer = function(fn, delay, scope){ var timeoutId = -1 return function(){ var self = scope || this, args = arguments if (delay < 0){ fn.apply(self, args) return } var withTimeout = delay || !setImmediate, clearFn = withTimeout? clearTimeout: clearImmediate, setFn = withTimeout? setTimeout: setImmediate if (timeoutId !== -1){ clearFn(timeoutId) } timeoutId = setFn(function(){ fn.apply(self, args) self = null }, delay) } }, throttle = function(fn, delay, scope) { var timeoutId = -1, self, args return function () { self = scope || this args = arguments if (timeoutId !== -1) { //the function was called once again in the delay interval } else { timeoutId = setTimeout(function () { fn.apply(self, args) self = null timeoutId = -1 }, delay) } } }, spread = function(fn, delay, scope){ var timeoutId = -1 var callCount = 0 var executeCount = 0 var nextArgs = {} var increaseCounter = true var resultingFnUnbound var resultingFn resultingFn = resultingFnUnbound = function(){ var args = arguments, self = scope || this if (increaseCounter){ nextArgs[callCount++] = {args: args, scope: self} } if (timeoutId !== -1){ //the function was called once again in the delay interval } else { timeoutId = setTimeout(function(){ fn.apply(self, args) timeoutId = -1 executeCount++ if (callCount !== executeCount){ resultingFn = bindArgsArray(resultingFnUnbound, nextArgs[executeCount].args).bind(nextArgs[executeCount].scope) delete nextArgs[executeCount] increaseCounter = false resultingFn.apply(self) increaseCounter = true } else { nextArgs = {} } }, delay) } } return resultingFn }, /* * @param {Array} args the array for which to create a cache key * @param {Number} [cacheParamNumber] the number of args to use for the cache key. Use this to limit the args that area actually used for the cache key */ getCacheKey = function(args, cacheParamNumber){ if (cacheParamNumber == null){ cacheParamNumber = -1 } var i = 0, len = Math.min(args.length, cacheParamNumber), cacheKey = [], it for ( ; i < len; i++){ it = args[i] if (root.check.isPlainObject(it) || Array.isArray(it)){ cacheKey.push(JSON.stringify(it)) } else { cacheKey.push(String(it)) } } return cacheKey.join(', ') }, /* * @param {Function} fn - the function to cache results for * @param {Number} skipCacheParamNumber - the index of the boolean parameter that makes this function skip the caching and * actually return computed results. * @param {Function|String} cacheBucketMethod - a function or the name of a method on this object which makes caching distributed across multiple buckets. * If given, cached results will be searched into the cache corresponding to this bucket. If no result found, return computed result. * * For example this param is very useful when a function from a prototype is cached, * but we want to return the same cached results only for one object that inherits that proto, not for all objects. Thus, for example for Wes.Element, * we use the 'getId' cacheBucketMethod to indicate cached results for one object only. * @param {Function} [cacheKeyBuilder] A function to be used to compose the cache key * * @return {Function} a new function, which returns results from cache, if they are available, otherwise uses the given fn to compute the results. * This returned function has a 'clearCache' function attached, which clears the caching. If a parameter ( a bucket id) is provided, * only clears the cache in the specified cache bucket. */ cache = function(fn, config){ config = config || {} var bucketCache = {}, cache = {}, skipCacheParamNumber = config.skipCacheIndex, cacheBucketMethod = config.cacheBucket, cacheKeyBuilder = config.cacheKey, cacheArgsLength = skipCacheParamNumber == null? fn.length: skipCacheParamNumber, cachingFn cachingFn = function(){ var result, skipCache = skipCacheParamNumber != null? arguments[skipCacheParamNumber] === true: false, args = skipCache? SLICE.call(arguments, 0, cacheArgsLength): SLICE.call(arguments), cacheBucketId = cacheBucketMethod != null? typeof cacheBucketMethod == 'function'? cacheBucketMethod(): typeof this[cacheBucketMethod] == 'function'? this[cacheBucketMethod](): null : null, cacheObject = cacheBucketId? bucketCache[cacheBucketId]: cache, cacheKey = (cacheKeyBuilder || getCacheKey)(args, cacheArgsLength) if (cacheBucketId && !cacheObject){ cacheObject = bucketCache[cacheBucketId] = {} } if (skipCache || cacheObject[cacheKey] == null){ cacheObject[cacheKey] = result = fn.apply(this, args) } else { result = cacheObject[cacheKey] } return result } /* * @param {String|Object|Number} [bucketId] the bucket for which to clear the cache. If none given, clears all the cache for this function. */ cachingFn.clearCache = function(bucketId){ if (bucketId){ delete bucketCache[String(bucketId)] } else { cache = {} bucketCache = {} } } /* * * @param {Array} cacheArgs The array of objects from which to create the cache key * @param {Number} [cacheParamNumber] A limit for the cache args that are actually used to compute the cache key. * @param {Function} [cacheKeyBuilder] The function to be used to compute the cache key from the given cacheArgs and cacheParamNumber */ cachingFn.getCache = function(cacheArgs, cacheParamNumber, cacheKeyBuilder){ return cachingFn.getBucketCache(null, cacheArgs, cacheParamNumber, cacheKeyBuilder) } /* * * @param {String} bucketId The id of the cache bucket from which to retrieve the cached value * @param {Array} cacheArgs The array of objects from which to create the cache key * @param {Number} [cacheParamNumber] A limit for the cache args that are actually used to compute the cache key. * @param {Function} [cacheKeyBuilder] The function to be used to compute the cache key from the given cacheArgs and cacheParam