nuke-theme-provider
Advanced tools
Comparing version 2.1.10 to 2.2.2
@@ -6,2 +6,37 @@ # Change Log | ||
<a name="2.2.2"></a> | ||
## [2.2.2](https://gitlab.alibaba-inc.com/nuke/theme-provider/compare/v2.2.1...v2.2.2) (2018-08-23) | ||
**Note:** Version bump only for package nuke-theme-provider | ||
<a name="2.2.1"></a> | ||
## [2.2.1](https://gitlab.alibaba-inc.com/nuke/theme-provider/compare/v2.2.0...v2.2.1) (2018-08-23) | ||
**Note:** Version bump only for package nuke-theme-provider | ||
<a name="2.2.0"></a> | ||
# [2.2.0](https://gitlab.alibaba-inc.com/nuke/theme-provider/compare/v2.1.10...v2.2.0) (2018-08-23) | ||
### Bug Fixes | ||
* merge conflict ([7a4e427](https://gitlab.alibaba-inc.com/nuke/theme-provider/commit/7a4e427)) | ||
### Features | ||
* add jest test suite ([ebe6aba](https://gitlab.alibaba-inc.com/nuke/theme-provider/commit/ebe6aba)) | ||
<a name="2.1.10"></a> | ||
@@ -8,0 +43,0 @@ ## [2.1.10](https://gitlab.alibaba-inc.com/nuke/theme-provider/compare/v2.1.9...v2.1.10) (2018-08-20) |
@@ -1,1 +0,259 @@ | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var _extends=Object.assign||function(target){for(var source,i=1;i<arguments.length;i++)for(var key in source=arguments[i],source)Object.prototype.hasOwnProperty.call(source,key)&&(target[key]=source[key]);return target},_createClass=function(){function defineProperties(target,props){for(var descriptor,i=0;i<props.length;i++)descriptor=props[i],descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,'value'in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}return function(Constructor,protoProps,staticProps){return protoProps&&defineProperties(Constructor.prototype,protoProps),staticProps&&defineProperties(Constructor,staticProps),Constructor}}(),_rax=require('rax'),_hoistNonReactStatics=require('hoist-non-react-statics'),_hoistNonReactStatics2=_interopRequireDefault(_hoistNonReactStatics),_theme=require('./theme'),_theme2=_interopRequireDefault(_theme);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++)arr2[i]=arr[i];return arr2}return Array.from(arr)}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&&('object'==typeof call||'function'==typeof call)?call:self}function _inherits(subClass,superClass){if('function'!=typeof superClass&&null!==superClass)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:!1,writable:!0,configurable:!0}}),superClass&&(Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass)}var cacheStatic=void 0;function getTheme(context){return context.theme&&(cacheStatic=context.theme),context.theme||cacheStatic||_theme2.default.getDefaultTheme()}exports.default=function(){function getComponentDisplayName(WrappedComponent){return WrappedComponent.displayName||WrappedComponent.name||'Component'}var componentStyleProvider=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},options=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{};return function(WrappedComponent){var _class,_temp,componentDisplayName=getComponentDisplayName(WrappedComponent),StyledComponent=(_temp=_class=function(_Component){function StyledComponent(props,context){_classCallCheck(this,StyledComponent);var _this=_possibleConstructorReturn(this,(StyledComponent.__proto__||Object.getPrototypeOf(StyledComponent)).call(this,props,context)),style=props.style,theme=getTheme(context);_this.displayName=componentDisplayName;var componentStyle=componentStyleProvider(theme.themeStyle);_this.setWrappedInstance=_this.setWrappedInstance.bind(_this);var finalStyle=_this.getFinalStyle(componentStyle,context,style);return _this.state={style:finalStyle,componentStyle:componentStyle,addedProps:_this.resolveAddedProps()},_this}return _inherits(StyledComponent,_Component),_createClass(StyledComponent,[{key:'getChildContext',value:function getChildContext(){return{namespace:this.getNamespace(),parentPath:this.getParentPath()}}},{key:'componentWillReceiveProps',value:function componentWillReceiveProps(nextProps,nextContext){var theme=getTheme(nextContext),componentStyle=componentStyleProvider(theme.themeStyle),style=nextProps.style,finalStyle=this.getFinalStyle(componentStyle,nextContext,style);this.setState({style:finalStyle})}},{key:'getFinalStyle',value:function getFinalStyle(componentStyle,context,style){var currentPath=context.parentPath?[].concat(_toConsumableArray(context.parentPath)):[];currentPath.push(this.displayName);for(var key,stylesObject={},i=0;i<currentPath.length;i++)key=currentPath.slice(currentPath.length-1-i).join('.'),componentStyle[key]&&(stylesObject=_extends({},stylesObject,componentStyle[key]));return _extends({},stylesObject,style)}},{key:'getParentPath',value:function getParentPath(){return this.context.parentPath?[].concat(_toConsumableArray(this.context.parentPath),[this.displayName]):[this.displayName]}},{key:'getNamespace',value:function getNamespace(){return this.context.namespace||'Nuke'}},{key:'setNativeProps',value:function setNativeProps(nativeProps){this.wrappedInstance.setNativeProps&&this.wrappedInstance.setNativeProps(nativeProps)}},{key:'setWrappedInstance',value:function setWrappedInstance(component){var _this2=this;this._root=component&&component._root?component._root:component,this.wrappedInstance=this._root,this.wrappedInstance&&Object.keys(this.wrappedInstance).forEach(function(attr){_this2[attr]||(_this2[attr]=_this2.wrappedInstance[attr])})}},{key:'resolveAddedProps',value:function resolveAddedProps(){var addedProps={};return options.withRef&&(addedProps.ref='wrappedInstance'),addedProps}},{key:'render',value:function render(){var _state=this.state,addedProps=_state.addedProps,style=_state.style;return(0,_rax.createElement)(WrappedComponent,_extends({},this.props,addedProps,{themeStyle:style,ref:this.setWrappedInstance}))}}]),StyledComponent}(_rax.Component),_class.contextTypes={theme:_rax.PropTypes.object,parentPath:_rax.PropTypes.array,namespace:_rax.PropTypes.string},_class.childContextTypes={parentPath:_rax.PropTypes.array,parentStyle:_rax.PropTypes.object,namespace:_rax.PropTypes.string},_class.propTypes={style:_rax.PropTypes.object},_class.WrappedComponent=WrappedComponent,_temp);return(0,_hoistNonReactStatics2.default)(StyledComponent,WrappedComponent)}},module.exports=exports['default']; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _rax = require('rax'); | ||
var _hoistNonReactStatics = require('hoist-non-react-statics'); | ||
var _hoistNonReactStatics2 = _interopRequireDefault(_hoistNonReactStatics); | ||
var _theme = require('./theme'); | ||
var _theme2 = _interopRequireDefault(_theme); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
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; } /** @jsx createElement */ | ||
// import pickby from 'lodash.pickby'; | ||
// function throwConnectStyleError(errorMessage, componentDisplayName) { | ||
// throw Error( | ||
// `${errorMessage} - when connecting ${componentDisplayName} component to style.` | ||
// ); | ||
// } | ||
// 处理 componentStyle 有多层的情况,例如: | ||
// componentStyle: { | ||
// Card : { | ||
// normal:{ | ||
// width:100, | ||
// height:100 | ||
// }, | ||
// footer:{ | ||
// flex:1 | ||
// } | ||
// } , | ||
// [Card.Item]:{ | ||
// wrap:{ | ||
// backgroundColor:'#cccccc' | ||
// } | ||
// }, | ||
// [Card.Item.Button]:{ | ||
// primary:{ | ||
// backgroundColor:'#cccccc' | ||
// } | ||
// } | ||
// } | ||
var cacheStatic = void 0; | ||
function getTheme(context) { | ||
if (context.theme) { | ||
cacheStatic = context.theme; | ||
} | ||
// Fallback to a default theme if the component isn't | ||
// rendered in a StyleProvider. | ||
// return Theme.get(namespace) || Theme.getDefaultTheme(); | ||
// var a = Theme.get(); | ||
return context.theme || cacheStatic || _theme2.default.getDefaultTheme(); | ||
} | ||
/** | ||
* 过滤,传递需要的样式到子节点 | ||
* @param {[object]} componentStyle [样式] | ||
* @param {[string]} componentDisplayName [组件名] | ||
* @param {[array]} parentPath [父级路径] | ||
* @return {[type]} [description] | ||
*/ | ||
// function injectToChildFilter( | ||
// componentStyle, | ||
// componentDisplayName, | ||
// parentPath = [] | ||
// ) { | ||
// return pickby(componentStyle, (value, key) => { | ||
// let nextPath = [...parentPath]; | ||
// nextPath.push(componentDisplayName); | ||
// let maxCurrentStyleKey = nextPath.join('.'); | ||
// //当前 keyPath 是否是currentPath 的子路径, 例如 keyPath : Cart.Item.Button, currentPath: Cart.Item, return true | ||
// return ( | ||
// key.indexOf(maxCurrentStyleKey) === 0 && key.length > maxCurrentStyleKey | ||
// ); | ||
// }); | ||
// } | ||
/** | ||
* add display name property in each componeent to prevent being aliasd. | ||
*/ | ||
exports.default = function () { | ||
var componentStyleProvider = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
function getComponentDisplayName(WrappedComponent) { | ||
return WrappedComponent.displayName || WrappedComponent.name || 'Component'; | ||
} | ||
return function wrapWithStyledComponent(WrappedComponent) { | ||
var _class, _temp; | ||
var componentDisplayName = getComponentDisplayName(WrappedComponent); | ||
var StyledComponent = (_temp = _class = function (_Component) { | ||
_inherits(StyledComponent, _Component); | ||
function StyledComponent(props, context) { | ||
_classCallCheck(this, StyledComponent); | ||
var _this = _possibleConstructorReturn(this, (StyledComponent.__proto__ || Object.getPrototypeOf(StyledComponent)).call(this, props, context)); | ||
var style = props.style; | ||
var theme = getTheme(context); | ||
_this.displayName = componentDisplayName; | ||
var componentStyle = componentStyleProvider(theme.themeStyle); | ||
_this.setWrappedInstance = _this.setWrappedInstance.bind(_this); | ||
var finalStyle = _this.getFinalStyle(componentStyle, context, style); | ||
_this.state = { | ||
style: finalStyle, | ||
componentStyle: componentStyle, | ||
addedProps: _this.resolveAddedProps() | ||
}; | ||
return _this; | ||
} | ||
_createClass(StyledComponent, [{ | ||
key: 'getChildContext', | ||
value: function getChildContext() { | ||
return { | ||
// parentStyle: injectToChildFilter( | ||
// this.state.componentStyle, | ||
// this.displayName, | ||
// this.currentPath | ||
// ), | ||
namespace: this.getNamespace(), | ||
// this.context.parentStyle : | ||
// this.state.childrenStyle, | ||
// resolveStyle: this.resolveConnectedComponentStyle, | ||
parentPath: this.getParentPath() | ||
}; | ||
} | ||
}, { | ||
key: 'componentWillReceiveProps', | ||
value: function componentWillReceiveProps(nextProps, nextContext) { | ||
var theme = getTheme(nextContext); | ||
var componentStyle = componentStyleProvider(theme.themeStyle); | ||
var style = nextProps.style; | ||
var finalStyle = this.getFinalStyle(componentStyle, nextContext, style); | ||
this.setState({ | ||
style: finalStyle | ||
}); | ||
} | ||
// getStyleFromKlsName(klassName) { | ||
// // console.log(klassName); | ||
// } | ||
}, { | ||
key: 'getFinalStyle', | ||
value: function getFinalStyle(componentStyle, context, style) { | ||
var currentPath = context.parentPath ? [].concat(_toConsumableArray(context.parentPath)) : []; | ||
currentPath.push(this.displayName); | ||
var stylesObject = {}; | ||
for (var i = 0; i < currentPath.length; i++) { | ||
var key = currentPath.slice(currentPath.length - 1 - i).join('.'); | ||
if (componentStyle[key]) { | ||
stylesObject = _extends({}, stylesObject, componentStyle[key]); | ||
} | ||
} | ||
return _extends({}, stylesObject, style); | ||
} | ||
}, { | ||
key: 'getParentPath', | ||
value: function getParentPath() { | ||
if (!this.context.parentPath) { | ||
return [this.displayName]; | ||
} | ||
return [].concat(_toConsumableArray(this.context.parentPath), [this.displayName]); | ||
} | ||
}, { | ||
key: 'getNamespace', | ||
value: function getNamespace() { | ||
return this.context.namespace || 'Nuke'; | ||
} | ||
}, { | ||
key: 'setNativeProps', | ||
value: function setNativeProps(nativeProps) { | ||
if (this.wrappedInstance.setNativeProps) { | ||
this.wrappedInstance.setNativeProps(nativeProps); | ||
} | ||
} | ||
}, { | ||
key: 'setWrappedInstance', | ||
value: function setWrappedInstance(component) { | ||
var _this2 = this; | ||
if (component && component._root) { | ||
this._root = component._root; | ||
} else { | ||
this._root = component; | ||
} | ||
this.wrappedInstance = this._root; | ||
this.wrappedInstance && Object.keys(this.wrappedInstance).forEach(function (attr) { | ||
if (!_this2[attr]) { | ||
_this2[attr] = _this2.wrappedInstance[attr]; | ||
} | ||
}); | ||
} | ||
}, { | ||
key: 'resolveAddedProps', | ||
value: function resolveAddedProps() { | ||
var addedProps = {}; | ||
if (options.withRef) { | ||
addedProps.ref = 'wrappedInstance'; | ||
} | ||
return addedProps; | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
var _state = this.state, | ||
addedProps = _state.addedProps, | ||
style = _state.style; | ||
return (0, _rax.createElement)(WrappedComponent, _extends({}, this.props, addedProps, { themeStyle: style, ref: this.setWrappedInstance })); | ||
} | ||
}]); | ||
return StyledComponent; | ||
}(_rax.Component), _class.contextTypes = { | ||
theme: _rax.PropTypes.object, | ||
parentPath: _rax.PropTypes.array, | ||
namespace: _rax.PropTypes.string | ||
}, _class.childContextTypes = { | ||
parentPath: _rax.PropTypes.array, | ||
parentStyle: _rax.PropTypes.object, | ||
namespace: _rax.PropTypes.string | ||
}, _class.propTypes = { | ||
// Element style that overrides any other style of the component | ||
style: _rax.PropTypes.object | ||
}, _class.WrappedComponent = WrappedComponent, _temp); | ||
// return StyledComponent; | ||
return (0, _hoistNonReactStatics2.default)(StyledComponent, WrappedComponent); | ||
}; | ||
}; | ||
module.exports = exports['default']; |
@@ -1,1 +0,26 @@ | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var _connectStyle=require('./connect-style'),_connectStyle2=_interopRequireDefault(_connectStyle),_theme=require('./theme'),_theme2=_interopRequireDefault(_theme),_styleProvider=require('./style-provider'),_styleProvider2=_interopRequireDefault(_styleProvider);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}exports.default={connectStyle:_connectStyle2.default,Theme:_theme2.default,StyleProvider:_styleProvider2.default},module.exports=exports['default']; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _connectStyle = require('./connect-style'); | ||
var _connectStyle2 = _interopRequireDefault(_connectStyle); | ||
var _theme = require('./theme'); | ||
var _theme2 = _interopRequireDefault(_theme); | ||
var _styleProvider = require('./style-provider'); | ||
var _styleProvider2 = _interopRequireDefault(_styleProvider); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = { | ||
connectStyle: _connectStyle2.default, | ||
Theme: _theme2.default, | ||
StyleProvider: _styleProvider2.default | ||
}; | ||
module.exports = exports['default']; |
@@ -1,1 +0,103 @@ | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:!0}),exports.default=void 0;var _class,_temp,_createClass=function(){function defineProperties(target,props){for(var descriptor,i=0;i<props.length;i++)descriptor=props[i],descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,'value'in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}return function(Constructor,protoProps,staticProps){return protoProps&&defineProperties(Constructor.prototype,protoProps),staticProps&&defineProperties(Constructor,staticProps),Constructor}}(),_rax=require('rax'),_theme=require('./theme'),_theme2=_interopRequireDefault(_theme);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&&('object'==typeof call||'function'==typeof call)?call:self}function _inherits(subClass,superClass){if('function'!=typeof superClass&&null!==superClass)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:!1,writable:!0,configurable:!0}}),superClass&&(Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass)}var StyleProvider=(_temp=_class=function(_Component){function StyleProvider(props,context){_classCallCheck(this,StyleProvider);var _this=_possibleConstructorReturn(this,(StyleProvider.__proto__||Object.getPrototypeOf(StyleProvider)).call(this,props,context));return _this.state={theme:_this.createTheme(props)},_this}return _inherits(StyleProvider,_Component),_createClass(StyleProvider,[{key:'getChildContext',value:function getChildContext(){return{theme:this.state.theme,androidConfigs:this.getAndroidConfigs(this.props),compatibilityConfigs:this.getCompatConfigs(this.props),commonConfigs:this.getCommonConfigs(this.props)}}},{key:'componentWillReceiveProps',value:function componentWillReceiveProps(nextProps){nextProps.style!==this.props.style&&this.setState({theme:this.createTheme(nextProps)})}},{key:'getAndroidConfigs',value:function getAndroidConfigs(props){return props.androidConfigs||{}}},{key:'getCompatConfigs',value:function getCompatConfigs(props){return props.compatibilityConfigs||{}}},{key:'getCommonConfigs',value:function getCommonConfigs(props){return props.commonConfigs||{}}},{key:'createTheme',value:function createTheme(props){return new _theme2.default(props.style)}},{key:'render',value:function render(){var children=this.props.children;return children}}]),StyleProvider}(_rax.Component),_class.propTypes={children:_rax.PropTypes.element.isRequired,style:_rax.PropTypes.object},_class.defaultProps={style:{}},_class.childContextTypes={theme:_rax.PropTypes.object},_temp);exports.default=StyleProvider,module.exports=exports['default']; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = undefined; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _class, _temp; /** @jsx createElement */ | ||
var _rax = require('rax'); | ||
var _theme = require('./theme'); | ||
var _theme2 = _interopRequireDefault(_theme); | ||
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; } | ||
/** | ||
* Provides a theme to child components trough context. | ||
*/ | ||
var StyleProvider = (_temp = _class = function (_Component) { | ||
_inherits(StyleProvider, _Component); | ||
function StyleProvider(props, context) { | ||
_classCallCheck(this, StyleProvider); | ||
var _this = _possibleConstructorReturn(this, (StyleProvider.__proto__ || Object.getPrototypeOf(StyleProvider)).call(this, props, context)); | ||
_this.state = { | ||
theme: _this.createTheme(props) | ||
}; | ||
return _this; | ||
} | ||
_createClass(StyleProvider, [{ | ||
key: 'getChildContext', | ||
value: function getChildContext() { | ||
return { | ||
theme: this.state.theme, | ||
androidConfigs: this.getAndroidConfigs(this.props), | ||
compatibilityConfigs: this.getCompatConfigs(this.props), | ||
commonConfigs: this.getCommonConfigs(this.props) | ||
}; | ||
} | ||
}, { | ||
key: 'componentWillReceiveProps', | ||
value: function componentWillReceiveProps(nextProps) { | ||
if (nextProps.style !== this.props.style) { | ||
this.setState({ | ||
theme: this.createTheme(nextProps) | ||
}); | ||
} | ||
} | ||
}, { | ||
key: 'getAndroidConfigs', | ||
value: function getAndroidConfigs(props) { | ||
return props.androidConfigs || {}; | ||
} | ||
}, { | ||
key: 'getCompatConfigs', | ||
value: function getCompatConfigs(props) { | ||
return props.compatibilityConfigs || {}; // {toRemString:true} | ||
} | ||
}, { | ||
key: 'getCommonConfigs', | ||
value: function getCommonConfigs(props) { | ||
return props.commonConfigs || {}; // {zoomFont:true} | ||
} | ||
}, { | ||
key: 'createTheme', | ||
value: function createTheme(props) { | ||
return new _theme2.default(props.style); | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
var children = this.props.children; | ||
return children; | ||
} | ||
}]); | ||
return StyleProvider; | ||
}(_rax.Component), _class.propTypes = { | ||
children: _rax.PropTypes.element.isRequired, | ||
style: _rax.PropTypes.object | ||
}, _class.defaultProps = { | ||
style: {} | ||
}, _class.childContextTypes = { | ||
theme: _rax.PropTypes.object | ||
}, _temp); | ||
exports.default = StyleProvider; | ||
module.exports = exports['default']; |
108
lib/theme.js
@@ -1,1 +0,107 @@ | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:!0}),exports.default=void 0;var _createClass=function(){function defineProperties(target,props){for(var descriptor,i=0;i<props.length;i++)descriptor=props[i],descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,'value'in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}return function(Constructor,protoProps,staticProps){return protoProps&&defineProperties(Constructor.prototype,protoProps),staticProps&&defineProperties(Constructor,staticProps),Constructor}}(),_nukeCore=require('nuke-core'),_nukeCore2=_interopRequireDefault(_nukeCore);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')}var THEME_STYLE='themeStyle',THEME_STYLE_CACHE='themeCachedStyle',defaultTheme=void 0;function mergeComponentAndThemeStyles(){}var resolveStyle=function(style,baseStyle){return resolveIncludes(style,baseStyle)},Theme=function(){function Theme(themeStyle){_classCallCheck(this,Theme),this[THEME_STYLE]=themeStyle,this[THEME_STYLE].Core=Object.assign(_nukeCore2.default,this[THEME_STYLE].Core),this[THEME_STYLE_CACHE]={}}return _createClass(Theme,[{key:'createComponentStyle',value:function createComponentStyle(componentName){return this[THEME_STYLE_CACHE][componentName]?this[THEME_STYLE_CACHE][componentName]:this[THEME_STYLE_CACHE][componentName]}},{key:'getComponentRelavantStyle',value:function getComponentRelavantStyle(){}}],[{key:'setDefaultThemeStyle',value:function setDefaultThemeStyle(style){defaultTheme=new Theme(style)}},{key:'getDefaultTheme',value:function getDefaultTheme(){return defaultTheme||(defaultTheme=new Theme({Core:_nukeCore2.default})),defaultTheme}}]),Theme}();exports.default=Theme,module.exports=exports['default']; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = undefined; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _nukeCore = require('nuke-core'); | ||
var _nukeCore2 = _interopRequireDefault(_nukeCore); | ||
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"); } } | ||
// Privates, ideally those should be symbols | ||
var THEME_STYLE = 'themeStyle'; | ||
var THEME_STYLE_CACHE = 'themeCachedStyle'; | ||
var defaultTheme = void 0; | ||
function mergeComponentAndThemeStyles() {} | ||
var resolveStyle = function resolveStyle(style, baseStyle) { | ||
return resolveIncludes(style, baseStyle); | ||
}; | ||
var Theme = function () { | ||
function Theme(themeStyle) { | ||
_classCallCheck(this, Theme); | ||
this[THEME_STYLE] = themeStyle; | ||
this[THEME_STYLE].Core = Object.assign(_nukeCore2.default, this[THEME_STYLE].Core); | ||
this[THEME_STYLE_CACHE] = {}; | ||
} | ||
/** | ||
* Sets the given style as a default theme style. | ||
*/ | ||
_createClass(Theme, [{ | ||
key: 'createComponentStyle', | ||
/** | ||
* Creates a component style by merging the theme style on top of the | ||
* provided default component style. Any rules in the theme style will | ||
* override the rules from the base component style. | ||
* | ||
* This method will also resolve any INCLUDE keywords in the theme or | ||
* component styles before returning the final style. | ||
* | ||
* @param componentName fully qualified component name. | ||
* @param defaultStyle - default component style that will be used as base style. | ||
*/ | ||
value: function createComponentStyle(componentName) { | ||
if (this[THEME_STYLE_CACHE][componentName]) { | ||
return this[THEME_STYLE_CACHE][componentName]; | ||
} | ||
// const componentIncludedStyle = resolveStyle( | ||
// defaultStyle, | ||
// this[THEME_STYLE] | ||
// ); | ||
return this[THEME_STYLE_CACHE][componentName]; | ||
} | ||
}, { | ||
key: 'getComponentRelavantStyle', | ||
value: function getComponentRelavantStyle(componentName) { | ||
// if (this[THEME_STYLE_CACHE][componentName]) { | ||
// return this[THEME_STYLE_CACHE][componentName]; | ||
// } | ||
// let obj = { | ||
// Core: Object.assign(Core, this[THEME_STYLE]['Core']) | ||
// } | ||
// this[THEME_STYLE_CACHE][componentName]['Core'] = | ||
} | ||
}], [{ | ||
key: 'setDefaultThemeStyle', | ||
value: function setDefaultThemeStyle(style) { | ||
defaultTheme = new Theme(style); | ||
} | ||
/** | ||
* Returns the default theme that will be used as fallback | ||
* if the StyleProvider is not configured in the app. | ||
*/ | ||
}, { | ||
key: 'getDefaultTheme', | ||
value: function getDefaultTheme() { | ||
if (!defaultTheme) { | ||
defaultTheme = new Theme({ Core: _nukeCore2.default }); | ||
} | ||
return defaultTheme; | ||
} | ||
}]); | ||
return Theme; | ||
}(); | ||
exports.default = Theme; | ||
module.exports = exports['default']; |
{ | ||
"name": "nuke-theme-provider", | ||
"version": "2.1.10", | ||
"version": "2.2.2", | ||
"description": "主题换肤", | ||
@@ -43,15 +43,9 @@ "main": "lib/index", | ||
"hoist-non-react-statics": "^2.3.0", | ||
"nuke-core": "^2.1.10" | ||
"nuke-core": "^2.2.2" | ||
}, | ||
"devDependencies": { | ||
"babel-eslint": "^7.2.3", | ||
"eslint": "3.19.0", | ||
"eslint-config-ali": "2.0.0", | ||
"eslint-plugin-import": "2.6.0", | ||
"eslint-plugin-jsx-a11y": "6.0.2", | ||
"eslint-plugin-react": "7.1.0", | ||
"nuke-button": "^2.1.10", | ||
"nuke-dialog": "^2.1.10", | ||
"nuke-env": "^2.1.10", | ||
"nuke-page": "^2.1.10", | ||
"nuke-button": "^2.2.2", | ||
"nuke-dialog": "^2.2.2", | ||
"nuke-env": "^2.2.2", | ||
"nuke-page": "^2.2.2", | ||
"rax-text": "^0.x.x" | ||
@@ -63,3 +57,3 @@ }, | ||
"license": "Apache", | ||
"gitHead": "3f456cd7f92241938769ceee9057f543a2034fd1" | ||
"gitHead": "ffcb4269489cb30dfded592190c4997ff2376c18" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
42138
5
796
1
Updatednuke-core@^2.2.2