react-hold
Version:
Hold the empty presentational components in react.js
1 lines • 16.5 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["react","react-dom"],t):"object"==typeof exports?exports.ReactHold=t(require("react"),require("react-dom")):e.ReactHold=t(e.React,e.ReactDom)}(this,function(e,t){return function(e){function t(r){if(n[r])return n[r].exports;var l=n[r]={exports:{},id:r,loaded:!1};return e[r].call(l.exports,l,l.exports,t),l.loaded=!0,l.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){e.exports=n(15)},function(e,t,n){e.exports=n(19)()},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}t.__esModule=!0,t.fillerStyle=t.targetProps=t.cancelHold=t.height=t.width=t.color=void 0;var l=n(1),o=r(l),i=t.color=o.default.string,u=t.width=o.default.number,a=t.height=o.default.number,d=t.cancelHold=o.default.func,s=t.targetProps=o.default.object,f=t.fillerStyle=o.default.object;t.default={color:i,width:u,height:a,cancelHold:d,targetProps:s,fillerStyle:f}},function(t,n){t.exports=e},function(e,t){"use strict";t.__esModule=!0;var n=t.LEFT="left",r=t.CENTER="center",l=t.RIGHT="right";t.default={LEFT:n,CENTER:r,RIGHT:l}},function(e,t,n){"use strict";t.__esModule=!0;var r=t.isNull=function(e){return void 0===e||null===e};t.isFunction=function(e){return"function"==typeof e},t.isObject=function(e){return null!==e&&"[object Object]"===Object.prototype.toString.call(e)},t.getComputedStyle=window.getComputedStyle||document.defaultView.getComputedStyle,t.getNodeSize=function(e){return r(e)?null:{width:e.offsetWidth,height:e.offsetHeight}},t.getDisplayName=function(e){return r(e)?null:e.displayName||e.name||("string"==typeof e?e:"Unknown")},t.addHandler=window.addEventListener?function(e,t,n){e.addEventListener(t,n,!1)}:function(e,t,n){e.attachEvent("on"+t,n)},t.removeHandler=window.removeEventListener?function(e,t,n){e.removeEventListener(t,n,!1)}:function(e,t,n){e.detachEvent("on"+t,n)},t.warn=function(e){r(e)||console&&console.warn("[react-hold]",e)}},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function l(e,t){var n={};for(var r in e)t.indexOf(r)<0&&Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(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 u(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)}t.__esModule=!0;var a=Object.assign||function(e){for(var t=1;arguments.length>t;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},d=function(){function e(e,t){for(var n=0;t.length>n;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();t.default=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:b.default,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if(!(0,v.isFunction)(e)&&"string"!=typeof e)throw new TypeError("Expected the target component to be a string or class/function.");if(!(0,v.isFunction)(t))throw new TypeError("Expected the hold condition to be a function.");(0,v.isObject)(n)&&(r=n,n=b.default);var p=(0,v.getDisplayName)(e),y=(0,O.default)(e),m=function(n){function s(){var e;o(this,s);for(var t=arguments.length,n=Array(t),r=0;t>r;r++)n[r]=arguments[r];var l=i(this,(e=s.__proto__||Object.getPrototypeOf(s)).call.apply(e,[this].concat(n)));return l.state={hold:!0,copy:!0,holderAutoSize:{width:null,height:null}},l.originNodeStyle=null,l.resizeHandler=function(){l.state.hold&&l.updateHolderSizeIfNecessary()},l.cancelHold=l.cancelHold.bind(l),l}return u(s,n),d(s,[{key:"componentWillMount",value:function(){t.call(null,this.props,{})?y.refit():this.cancelHold()}},{key:"componentDidMount",value:function(){this.state.hold&&(this.originNodeStyle=this.computeOriginNodeStyle(),this.setState({copy:!1})),(0,v.addHandler)(window,"resize",this.resizeHandler)}},{key:"componentWillReceiveProps",value:function(e){t.call(null,e,this.props)?this.setState({hold:!0,copy:!0}):this.cancelHold()}},{key:"componentDidUpdate",value:function(){this.state.hold&&(this.state.copy?(y.refit(),this.originNodeStyle=this.computeOriginNodeStyle(),this.setState({copy:!1})):(0,v.isNull)(this.originNodeStyle)||(this.setFakeNodeStyle(this.originNodeStyle),this.updateHolderSizeIfNecessary(),this.originNodeStyle=null))}},{key:"componentWillUnmount",value:function(){(0,v.removeHandler)(window,"resize",this.resizeHandler)}},{key:"setFakeNodeStyle",value:function(e){if((0,v.isObject)(e)){var t=this.refs,n=t.fake,r=t.env,l=e.display&&e.display.indexOf("inline")>-1;n.style.display="none",Object.keys(e).forEach(function(t){"display"!==t&&(n.style[t]=e[t])}),n.style.opacity=1,n.style.background="transparent",n.style.borderColor="transparent",r.style.overflow=l?"hidden":"visible",n.style.display=l?"inline-block":e.display}}},{key:"computeOriginNodeStyle",value:function(){var e=null,t=(0,c.findDOMNode)(this),n=(0,v.getComputedStyle)(t,null),r=n.getPropertyValue("display");return t.style.display="none",n=(0,v.getComputedStyle)(t,null),Object.keys(n).forEach(function(t){if(/[0-9]+/.test(t)){var l=n[t];e=e||{},e[l]="display"===l?r:n.getPropertyValue(l)}}),e}},{key:"cancelHold",value:function(){var e=this.refs,t=e.fake,n=e.env;t&&t.removeAttribute("style"),n&&(n.style.overflow="visible"),y.undo(),this.originNodeStyle=null,this.setState({hold:!1,copy:!1})}},{key:"updateHolderSizeIfNecessary",value:function(){var e=this.refs.env;if(e){var t=this.state.holderAutoSize,n=this.props.holderProps||this.props.props||{},l=(0,v.isNull)(r.width)?n.width:r.width,o=(0,v.isNull)(r.height)?n.height:r.height;if((0,v.isNull)(l)||(0,v.isNull)(o)){var i=(0,v.getNodeSize)(e),u=(0,v.isNull)(l)?i.width:null,a=(0,v.isNull)(o)?i.height:null;t.width===u&&t.height===a||this.setState({holderAutoSize:{width:u,height:a}})}}}},{key:"render",value:function(){var t=this.state,n=t.hold,o=t.copy,i=t.holderAutoSize,u=this.props,d=u.innerRef,s=u.holder,c=u.holderProps,p=u.props,h=l(u,["innerRef","holder","holderProps","props"]);if(!n||o)return d&&!n&&(h.ref=d),f.default.createElement(e,h);var y=a({color:"#eee",width:null,height:null},r,p,c,{cancelHold:this.cancelHold,targetProps:h});return(0,v.isNull)(y.width)&&(y.width=i.width),(0,v.isNull)(y.height)&&(y.height=i.height),"string"==typeof y.children&&(y.children=y.children.replace(/ /g,_)),y.children=y.children||_.repeat(S),f.default.createElement("div",{ref:"fake"},f.default.createElement("div",{ref:"env",style:E},f.default.createElement(s,y)))}}]),s}(s.Component);return(0,g.default)(m,e),m.displayName="Hold("+p+")",m.propTypes={holder:h.default.oneOfType([h.default.string,h.default.func]),holderProps:h.default.object,props:h.default.object,innerRef:h.default.oneOfType([h.default.string,h.default.func])},m.defaultProps={holder:n,holderProps:null,props:null,innerRef:null},m};var s=n(3),f=r(s),c=n(21),p=n(1),h=r(p),y=n(18),g=r(y),v=n(5),m=n(7),b=r(m),w=n(10),O=r(w),_=" ",S=10,E={position:"relative",padding:"0px",margin:"0px",width:"100%",height:"100%",border:"none",overflow:"visible"}},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}t.__esModule=!0;var l=Object.assign||function(e){for(var t=1;arguments.length>t;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},o=n(3),i=r(o),u=n(1),a=r(u),d=n(2),s=r(d),f=n(4),c=function(e){var t=e.color,n=e.width,r=e.height,o=e.children,u=e.align,a=e.fillerStyle,d="string"==typeof r&&r.trim()?r:"number"==typeof r?r+"px":null;return i.default.createElement("div",{style:{textAlign:u}},i.default.createElement("div",{style:l({background:t},a,{display:"inline-block",textAlign:"center",width:n,height:r,lineHeight:d})},o))};c.propTypes=l({},s.default,{width:a.default.oneOfType([a.default.number,a.default.string]),height:a.default.oneOfType([a.default.number,a.default.string]),align:a.default.string}),c.defaultProps={width:null,height:null,align:f.CENTER,fillerStyle:null},t.default=c},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}t.__esModule=!0;var l=Object.assign||function(e){for(var t=1;arguments.length>t;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},o=n(3),i=r(o),u=n(1),a=r(u),d=n(2),s=r(d),f=n(4),c=n(5),p=function(e){var t=e.color,n=e.width,r=e.height,o=e.children,u=e.side,a=e.align,d=e.fillerStyle;(0,c.isNull)(u)&&((0,c.isNull)(n)||(0,c.isNull)(r)?(0,c.isNull)(n)?(0,c.isNull)(r)||(u=r):u=n:u=n>r?r:n);var s="string"==typeof u&&u.trim()?u:"number"==typeof u?u+"px":null;return i.default.createElement("div",{style:{textAlign:a}},i.default.createElement("div",{style:l({background:t},d,{display:"inline-block",textAlign:"center",width:u,height:u,lineHeight:s})},o))};p.propTypes=l({},s.default,{side:a.default.oneOfType([a.default.number,a.default.string]),align:a.default.string}),p.defaultProps={width:null,height:null,side:null,align:f.CENTER,fillerStyle:null},t.default=p},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}t.__esModule=!0,t.default=function(e,t,n){return function(r){return(0,o.default)(r,e,t,n)}};var l=n(6),o=r(l)},function(e,t,n){"use strict";t.__esModule=!0,t.symbol=void 0,t.default=function(e){if(e[l])return e[l];var t=null,n=function(){var n=void 0,l=void 0,o=e.prototype;(0,r.isNull)(t)&&o&&((0,r.isFunction)(o.componentDidMount)&&(n=o.componentDidMount,o.componentDidMount=null),(0,r.isFunction)(o.componentWillUnmount)&&(l=o.componentWillUnmount,o.componentWillUnmount=function(){try{l.call(this)}catch(e){}}),t={componentDidMount:n,componentWillUnmount:l})},o=function(){var n=t;!(0,r.isNull)(n)&&e.prototype&&(Object.keys(n).forEach(function(t){(0,r.isFunction)(n[t])&&(e.prototype[t]=n[t])}),t=null)},i={refit:n,undo:o};return"string"!=typeof e&&(e[l]=i),i};var r=n(5),l=t.symbol=Symbol?Symbol("react-hold/refiter"):"$$react-hold/refiter"},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}t.__esModule=!0;var l=Object.assign||function(e){for(var t=1;arguments.length>t;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},o=n(3),i=r(o),u=n(1),a=r(u),d=n(2),s=r(d),f=n(8),c=r(f),p=n(4),h=function(e){var t=e.color,n=e.width,r=e.height,o=e.children,u=e.diameter,a=e.align,d=e.fillerStyle;return i.default.createElement(c.default,{color:"transparent",width:n,height:r,side:u,align:a},i.default.createElement("div",{style:l({background:t},d,{width:"100%",height:"100%",borderRadius:"50%"})},o))};h.propTypes=l({},s.default,{diameter:c.default.propTypes.side,align:a.default.string}),h.defaultProps={width:null,height:null,diameter:null,align:p.CENTER,fillerStyle:null},t.default=h},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}t.__esModule=!0;var l=Object.assign||function(e){for(var t=1;arguments.length>t;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},o=n(3),i=r(o),u=n(1),a=r(u),d=n(2),s=r(d),f=n(4),c=n(5),p=2,h=2,y=2,g=" ",v=10,m=function(e,t,n){if(0>=e)return 0;var r=1===t?0:t-1,l=e-r*n;return l>0||((0,c.warn)("Expected option gap lower than "+e/r+", current "+n+". Default "+y+"."),l=0),l/t},b=function(e){var t=e.color,n=e.width,r=e.height,o=e.children,u=e.cols,a=e.rows,d=e.gap,s=e.align,f=e.fillerStyle;if(u=Math.ceil(u),a=Math.ceil(a),1>u)throw new TypeError("Expected option cols greater than 0.");if(1>a)throw new TypeError("Expected option rows greater than 0.");var c=m(n,u,d),p=m(r,a,d),h=[];if(c&&p)for(var y=0;u>y;y+=1)for(var b=0;a>b;b+=1)h.push(i.default.createElement("div",{key:y+"-"+b,style:l({background:t},f,{position:"absolute",top:b*(p+d),left:y*(c+d),width:c,height:p,lineHeight:p+"px",overflow:"hidden",textAlign:"center"})},o));return i.default.createElement("div",{style:{textAlign:s}},i.default.createElement("div",{style:{position:"relative",display:"inline-block",background:"transparent",width:n,height:r}},g.repeat(v),h))};b.propTypes=l({},s.default,{cols:a.default.number,rows:a.default.number,gap:a.default.number,align:a.default.string}),b.defaultProps={width:null,height:null,cols:p,rows:h,gap:y,align:f.CENTER,fillerStyle:null},t.default=b},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}t.__esModule=!0;var l=Object.assign||function(e){for(var t=1;arguments.length>t;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},o=n(3),i=r(o),u=n(1),a=r(u),d=n(2),s=r(d),f=" ",c=function(e){var t=e.color,n=e.width,r=e.height,o=e.length,u=e.lineHeight,a=e.fontSize,d=e.fillerStyle;return i.default.createElement("div",{style:{background:"transparent",overflow:"hidden",width:n,height:r,lineHeight:u,fontSize:a}},i.default.createElement("span",{style:l({background:t},d,{wordBreak:"break-word",wordWrap:"break-word"})},(""+f.repeat(2)).repeat(o)))};c.propTypes=l({},s.default,{length:a.default.number,lineHeight:a.default.oneOfType([a.default.number,a.default.string]),fontSize:a.default.oneOfType([a.default.number,a.default.string])}),c.defaultProps={width:null,height:null,length:100,lineHeight:2.3,fontSize:"0.7em",fillerStyle:null},t.default=c},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}t.__esModule=!0,t.Table=t.Text=t.Circle=t.Square=t.Fill=void 0;var l=n(7),o=r(l),i=n(8),u=r(i),a=n(11),d=r(a),s=n(13),f=r(s),c=n(12),p=r(c);t.Fill=o.default,t.Square=u.default,t.Circle=d.default,t.Text=f.default,t.Table=p.default,t.default={Fill:o.default,Square:u.default,Circle:d.default,Text:f.default,Table:p.default}},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}t.__esModule=!0,t.$nbsp=t.align=t.shapes=t.holders=t.holdify=t.Decorator=void 0;var l=n(6),o=r(l),i=n(9),u=r(i),a=n(14),d=r(a),s=n(2),f=r(s),c=n(4),p=r(c),h=" ",y=u.default;o.default.Decorator=u.default,o.default.holdify=y,o.default.hoders=d.default,o.default.shapes=f.default,o.default.align=p.default,o.default.$nbsp=h,t.default=o.default,t.Decorator=u.default,t.holdify=y,t.holders=d.default,t.shapes=f.default,t.align=p.default,t.$nbsp=h},function(e,t){"use strict";function n(e){return function(){return e}}var r=function(){};r.thatReturns=n,r.thatReturnsFalse=n(!1),r.thatReturnsTrue=n(!0),r.thatReturnsNull=n(null),r.thatReturnsThis=function(){return this},r.thatReturnsArgument=function(e){return e},e.exports=r},function(e,t,n){"use strict";function r(e,t,n,r,o,i,u,a){if(l(t),!e){var d;if(void 0===t)d=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=[n,r,o,i,u,a],f=0;d=Error(t.replace(/%s/g,function(){return s[f++]})),d.name="Invariant Violation"}throw d.framesToPop=1,d}}var l=function(e){};e.exports=r},function(e,t){"use strict";var n={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,mixins:!0,propTypes:!0,type:!0},r={name:!0,length:!0,prototype:!0,caller:!0,arguments:!0,arity:!0},l="function"==typeof Object.getOwnPropertySymbols;e.exports=function(e,t,o){if("string"!=typeof t){var i=Object.getOwnPropertyNames(t);l&&(i=i.concat(Object.getOwnPropertySymbols(t)));for(var u=0;i.length>u;++u)if(!(n[i[u]]||r[i[u]]||o&&o[i[u]]))try{e[i[u]]=t[i[u]]}catch(e){}}return e}},function(e,t,n){"use strict";var r=n(16),l=n(17),o=n(20);e.exports=function(){function e(e,t,n,r,i,u){u!==o&&l(!1,"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")}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t};return n.checkPropTypes=r,n.PropTypes=n,n}},function(e,t){"use strict";var n="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";e.exports=n},function(e,n){e.exports=t}])});