/* * * ReactShades * */ var Shades = (function(){ "use strict"; function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } var PureRenderMixin = React.addons.PureRenderMixin; function Slot(props, context) { var contents = context.lightTree[props.name]; if (!contents) return React.createElement("span", null); var root = React.Children.only(props.children || React.createElement("span", null)); var inner = root && root.props.children; var children = []; var rootProps = {}; contents.forEach(function (content) { var _content$props = content.props; var lightTree = _content$props.children; var slot = _content$props.slot; var props = _objectWithoutProperties(_content$props, ["children", "slot"]); var child = lightTree || React.createElement("span", null); if (inner) { child = React.cloneElement(inner, props, lightTree); } else { rootProps = props; } children.push(child); }); return React.cloneElement(root, rootProps, children); } Slot.contextTypes = { lightTree: React.PropTypes.object }; function Content(props) { return React.createElement( "div", null, props.children ); } var Shade = React.createClass({ displayName: "Shade", mixins: [PureRenderMixin], statics: { Content: Content, Slot: Slot, visit: function visit(nodes, visitor) { React.Children.forEach(nodes, function (node, idx) { if (visitor(node) !== false) { Shade.visit(node.props.children, visitor); } }); } }, childContextTypes: { lightTree: React.PropTypes.object }, getChildContext: function getChildContext() { var slots = {}; Shade.visit(this.props.lightTree, function (child) { if (child.type === Shade || child.type === Slot) { return false; } else if (!child.props.slot) { return; } (slots[child.props.slot] || (slots[child.props.slot] = [])).push(child); return false; }); return { lightTree: slots }; }, render: function render() { return React.Children.only(this.props.children); } }); return Shade; })(React);