UNPKG

clean-react-directives

Version:
46 lines (42 loc) 5.04 kB
/** * MIT License * * Copyright (c) 2019 Dejan Sandic - Deyo * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ !function(r,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):(r=r||self).lib=e(r.React)}(this,(function(r){"use strict";var e="default"in r?r.default:r,n=function(){return(n=Object.assign||function(r){for(var e,n=1,t=arguments.length;n<t;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o]);return r}).apply(this,arguments)}; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */function t(r,e){var n="function"==typeof Symbol&&r[Symbol.iterator];if(!n)return r;var t,o,i=n.call(r),s=[];try{for(;(void 0===e||e-- >0)&&!(t=i.next()).done;)s.push(t.value)}catch(r){o={error:r}}finally{try{t&&!t.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function o(){for(var r=[],e=0;e<arguments.length;e++)r=r.concat(t(arguments[e]));return r}var i=function(r,e){return r(e={exports:{}},e.exports),e.exports}((function(r){ /*! Copyright (c) 2017 Jed Watson. Licensed under the MIT License (MIT), see http://jedwatson.github.io/classnames */ !function(){var e={}.hasOwnProperty;function n(){for(var r=[],t=0;t<arguments.length;t++){var o=arguments[t];if(o){var i=typeof o;if("string"===i||"number"===i)r.push(o);else if(Array.isArray(o)&&o.length){var s=n.apply(null,o);s&&r.push(s)}else if("object"===i)for(var f in o)e.call(o,f)&&o[f]&&r.push(f)}}return r.join(" ")}r.exports?(n.default=n,r.exports=n):window.classNames=n}()}));function s(t){var o=t.children,l=t.deep;return r.createElement(r.Fragment,{},function t(o,l){var a=!1,u="";return r.Children.map(o,(function(o){if(!e.isValidElement(o))return o;if(o.type===s)return o;var c=n({},o.props),p=c.children,v=!1;if(l&&p&&(p=t(p,l),v=!0),"r-html"in c){var h=c["r-html"];if("string"!=typeof h)throw new Error("r-html expects a string as its value.");c=n({},c,{dangerouslySetInnerHTML:{__html:h}}),v=!0}if("r-class"in c){var d=c["r-class"],y=c.className?i(c.className,d):i(d);c=n({},c,{className:y}),v=!0}if("r-show"in c&&!c["r-show"]){var m=o.props.style||{};c=n({},c,{style:n({},m,{display:"none"})}),v=!0}var w="r-if"in c&&"r-if",g="r-else-if"in c&&"r-else-if",b="r-else"in c&&"r-else";if(w&&g||w&&b||g&&b)throw new Error("You cannot combine r-if, r-else-if and r-else on the same component");if(w&&(u=w,!(a=c[w])))return null;if(g||b){if("r-if"!==u&&"r-else-if"!==u)throw u=g||b,new Error(u+" can only be placed after r-if or r-else-if");if(!b&&!c[g]||a)return null;a=!0}return v&&(f.forEach((function(r){return delete c[r]})),o=r.createElement(o.type,n({},c),p)),o}))}(o,l))}var f=["r-if","r-else-if","r-else","r-show","r-class","r-html"];if(process&&process.env&&!process.env.rif&&"production"!==process.env.NODE_ENV){var l=console.error;console.error=function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];function n(r,e){return"string"==typeof r&&r.includes(e)}var t=r.some((function(r){return n(r,"non-boolean")})),i=r.some((function(r){return f.some((function(e){return n(r,e)}))}));t&&i||l.apply(void 0,o(r))},process.env.rif="true"}return s}));