UNPKG

@rednetio/react-include

Version:

Server Side Include / Edge Side Include components for isomorphic rendering with React.

2 lines (1 loc) 2.39 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("prop-types"),require("react-lifecycles-compat")):"function"==typeof define&&define.amd?define(["exports","react","prop-types","react-lifecycles-compat"],e):e(t.ReactInclude={},t.React,t.PropTypes,t.reactLifecyclesCompat)}(this,function(t,e,r,n){"use strict";var o="default"in e?e.default:e;r=r&&r.hasOwnProperty("default")?r.default:r;var i=Object.assign||function(t){for(var e=1;arguments.length>e;e++){var r=arguments[e];for(var n in r)({}).hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},c=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},u=function(t,u,p,a){var s,f;return n.polyfill((f=s=function(t){function e(){for(var e,r,n=arguments.length,o=Array(n),i=0;n>i;i++)o[i]=arguments[i];return e=r=c(this,t.call.apply(t,[this].concat(o))),r.state={},c(r,e)}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.componentDidMount=function(){var t=this,e=new XMLHttpRequest;e.open("GET",this.props[p]),e.onload=function(){return t.setState({text:e.responseText})},this.setState({xhr:e})},e.prototype.componentWillUnmount=function(){var t=this.state.xhr;XMLHttpRequest.DONE!==t.readyState&&t.abort()},e.prototype.render=function(){var t=this.state.text,e=this.props,r=e.component,n=function(t,e){var r={};for(var n in t)0>e.indexOf(n)&&{}.hasOwnProperty.call(t,n)&&(r[n]=t[n]);return r}(e,["component",p]);return o.createElement(r,i({},n,{dangerouslySetInnerHTML:{__html:"string"==typeof t?t:a(this.props)}}))},e}(e.PureComponent),s.displayName=t,s.propTypes=i({},u,{component:r.string.isRequired}),s.defaultProps={component:"div"},f))},p=/[<>"]/g,a={"<":"&lt;",">":"&gt;",'"':"&quot;"},s=function(t){return a[t]},f=function(t){return t.replace(p,s)},l=u("ESI",{src:r.string.isRequired},"src",function(t){return'<esi:include src="'+f(t.src)+'" />'}),y=u("SSI",{virtual:r.string.isRequired},"virtual",function(t){return'\x3c!--# include virtual="'+f(t.virtual)+'" --\x3e'});t.ESI=l,t.SSI=y});