Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-runner

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-runner - npm Package Compare versions

Comparing version 1.0.0-alpha.6 to 1.0.0-alpha.7

2

dist/index.esm.js

@@ -1,2 +0,2 @@

import r,{isValidElement as e,createElement as t,Fragment as n,Component as o,useRef as s,useState as c,useEffect as l}from"react";import{transform as u}from"sucrase";function a(){return a=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r},a.apply(this,arguments)}const i=/^export default(?=\s+)/m,p=/^render(?=\s*\([^)])/m,d=/^<[^>]*>/,m=/^(function|\(\)|class)[^\w]+/,f={React:r,jsxPragma:r.createElement,jsxFragmentPragma:r.Fragment},g=r=>e=>{if(!r.hasOwnProperty(e))throw new Error("Module not found: '"+e+"'");return r[e]},h=r=>{const{code:o,scope:s}=r,c=o.trim();if(!c)return null;const l=(null==s?void 0:s.require)&&"function"==typeof s.require,g=((r,e)=>u(r,{transforms:e?["jsx","typescript","imports"]:["jsx","typescript"],production:!0,jsxPragma:"jsxPragma",jsxFragmentPragma:"jsxFragmentPragma"}).code)((r=>d.test(r)?"return (<>"+r+"</>)":i.test(r)?r.replace(i,"return"):p.test(r)?r.replace(p,"return"):m.test(r)?"return ("+r.replace(/;$/,"")+")":r)(c),l),h=((r,e)=>{const t=Object.keys(e),n=t.map(r=>e[r]);return new Function(...t,r)(...n)})(g,a({},f,s));return h?e(h)?h:"function"==typeof h?t(h):"string"==typeof h?t(n,void 0,h):null:null};class v extends o{constructor(){super(...arguments),this.state={element:null,error:null,prevCode:null}}static getDerivedStateFromProps(r,e){if(e.prevCode===r.code)return null;try{return{element:h(r),error:e.error&&r.code!==e.prevCode?null:e.error,prevCode:r.code}}catch(e){return{element:null,error:e,prevCode:r.code}}}static getDerivedStateFromError(r){return{error:r}}componentDidMount(){var r,e;null==(r=(e=this.props).onRendered)||r.call(e,this.state.error||void 0)}shouldComponentUpdate(r,e){return r.code!==this.props.code||e.error!==this.state.error}componentDidUpdate(){var r,e;null==(r=(e=this.props).onRendered)||r.call(e,this.state.error||void 0)}render(){return this.state.error?null:this.state.element}}const j=r=>{let{code:e,scope:n,disableCache:o}=r;const u=s(!0),a=s(null),i=s(n);i.current=n;const[p,d]=c(()=>{const r=t(v,{code:e,scope:i.current,onRendered:e=>{e?d({element:o?null:a.current,error:e.toString()}):a.current=r}});return{element:r,error:null}});return l(()=>{if(u.current)return void(u.current=!1);const r=t(v,{code:e,scope:i.current,onRendered:e=>{e?d({element:o?null:a.current,error:e.toString()}):a.current=r}});d({element:r,error:null})},[e,o]),p};export{v as Runner,g as createRequire,h as generateElement,j as useRunner};
import e,{isValidElement as r,createElement as t,Component as o,useRef as n,useState as s,useEffect as c}from"react";import{transform as l}from"sucrase";function u(){return u=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},u.apply(this,arguments)}const p=e=>l(e,{transforms:["jsx","typescript","imports"],production:!0}).code.substring(13),d=/^<[^>]*>/,i=/^(function|\(\)|class)[^\w]+/,a=(e,r)=>{const t=Object.keys(r),o=t.map(e=>r[e]);return new Function(...t,e)(...o)},m=o=>{const{code:n,scope:s}=o,c=(e=>{const r=e.trim();return r?d.test(r)||i.test(r)?"export default "+r:e:r})(n);if(!c)return null;const l=p(c),m={};a(l,u({React:e,render:e=>{m.default=e}},s,{exports:m}));const f=m.default;return f?r(f)?f:"function"==typeof f?t(f):"string"==typeof f?f:null:null},f=e=>r=>{if(!e.hasOwnProperty(r))throw new Error("Module not found: '"+r+"'");return e[r]},h=(r,t)=>{const o={};return a(p(r),u({React:e},t,{exports:o})),o};class v extends o{constructor(){super(...arguments),this.state={element:null,error:null,prevCode:null,prevScope:null}}static getDerivedStateFromProps(e,r){if(r.prevCode===e.code&&r.prevScope===e.scope)return null;try{return{element:m(e),error:null,prevCode:e.code,prevScope:e.scope}}catch(r){return{element:null,error:r,prevCode:e.code,prevScope:e.scope}}}static getDerivedStateFromError(e){return{error:e}}componentDidMount(){var e,r;null==(e=(r=this.props).onRendered)||e.call(r,this.state.error||void 0)}shouldComponentUpdate(e,r){return e.code!==this.props.code||e.scope!==this.props.scope||r.error!==this.state.error}componentDidUpdate(){var e,r;null==(e=(r=this.props).onRendered)||e.call(r,this.state.error||void 0)}render(){return this.state.error?null:this.state.element}}const y=e=>{let{code:r,scope:o,disableCache:l}=e;const u=n(!0),p=n(null),[d,i]=s(()=>{const e=t(v,{code:r,scope:o,onRendered:r=>{r?i({element:l?null:p.current,error:r.toString()}):p.current=e}});return{element:e,error:null}});return c(()=>{if(u.current)return void(u.current=!1);const e=t(v,{code:r,scope:o,onRendered:r=>{r?i({element:l?null:p.current,error:r.toString()}):p.current=e}});i({element:e,error:null})},[r,o,l]),d};export{v as Runner,f as createRequire,m as generateElement,h as importCode,y as useRunner};
//# sourceMappingURL=index.esm.js.map

@@ -1,2 +0,2 @@

var e=require("react"),r=require("sucrase");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=/*#__PURE__*/t(e);function o(){return o=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},o.apply(this,arguments)}const s=/^export default(?=\s+)/m,u=/^render(?=\s*\([^)])/m,l=/^<[^>]*>/,c=/^(function|\(\)|class)[^\w]+/,a={React:n.default,jsxPragma:n.default.createElement,jsxFragmentPragma:n.default.Fragment},i=t=>{const{code:n,scope:i}=t,d=n.trim();if(!d)return null;const p=(null==i?void 0:i.require)&&"function"==typeof i.require,m=((e,t)=>r.transform(e,{transforms:t?["jsx","typescript","imports"]:["jsx","typescript"],production:!0,jsxPragma:"jsxPragma",jsxFragmentPragma:"jsxFragmentPragma"}).code)((e=>l.test(e)?"return (<>"+e+"</>)":s.test(e)?e.replace(s,"return"):u.test(e)?e.replace(u,"return"):c.test(e)?"return ("+e.replace(/;$/,"")+")":e)(d),p),f=((e,r)=>{const t=Object.keys(r),n=t.map(e=>r[e]);return new Function(...t,e)(...n)})(m,o({},a,i));return f?e.isValidElement(f)?f:"function"==typeof f?e.createElement(f):"string"==typeof f?e.createElement(e.Fragment,void 0,f):null:null};class d extends e.Component{constructor(){super(...arguments),this.state={element:null,error:null,prevCode:null}}static getDerivedStateFromProps(e,r){if(r.prevCode===e.code)return null;try{return{element:i(e),error:r.error&&e.code!==r.prevCode?null:r.error,prevCode:e.code}}catch(r){return{element:null,error:r,prevCode:e.code}}}static getDerivedStateFromError(e){return{error:e}}componentDidMount(){var e,r;null==(e=(r=this.props).onRendered)||e.call(r,this.state.error||void 0)}shouldComponentUpdate(e,r){return e.code!==this.props.code||r.error!==this.state.error}componentDidUpdate(){var e,r;null==(e=(r=this.props).onRendered)||e.call(r,this.state.error||void 0)}render(){return this.state.error?null:this.state.element}}exports.Runner=d,exports.createRequire=e=>r=>{if(!e.hasOwnProperty(r))throw new Error("Module not found: '"+r+"'");return e[r]},exports.generateElement=i,exports.useRunner=r=>{let{code:t,scope:n,disableCache:o}=r;const s=e.useRef(!0),u=e.useRef(null),l=e.useRef(n);l.current=n;const[c,a]=e.useState(()=>{const r=e.createElement(d,{code:t,scope:l.current,onRendered:e=>{e?a({element:o?null:u.current,error:e.toString()}):u.current=r}});return{element:r,error:null}});return e.useEffect(()=>{if(s.current)return void(s.current=!1);const r=e.createElement(d,{code:t,scope:l.current,onRendered:e=>{e?a({element:o?null:u.current,error:e.toString()}):u.current=r}});a({element:r,error:null})},[t,o]),c};
var e=require("react"),r=require("sucrase");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=/*#__PURE__*/t(e);function o(){return o=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},o.apply(this,arguments)}const s=e=>r.transform(e,{transforms:["jsx","typescript","imports"],production:!0}).code.substring(13),c=/^<[^>]*>/,u=/^(function|\(\)|class)[^\w]+/,l=(e,r)=>{const t=Object.keys(r),n=t.map(e=>r[e]);return new Function(...t,e)(...n)},p=r=>{const{code:t,scope:p}=r,a=(e=>{const r=e.trim();return r?c.test(r)||u.test(r)?"export default "+r:e:r})(t);if(!a)return null;const d=s(a),i={};l(d,o({React:n.default,render:e=>{i.default=e}},p,{exports:i}));const f=i.default;return f?e.isValidElement(f)?f:"function"==typeof f?e.createElement(f):"string"==typeof f?f:null:null};class a extends e.Component{constructor(){super(...arguments),this.state={element:null,error:null,prevCode:null,prevScope:null}}static getDerivedStateFromProps(e,r){if(r.prevCode===e.code&&r.prevScope===e.scope)return null;try{return{element:p(e),error:null,prevCode:e.code,prevScope:e.scope}}catch(r){return{element:null,error:r,prevCode:e.code,prevScope:e.scope}}}static getDerivedStateFromError(e){return{error:e}}componentDidMount(){var e,r;null==(e=(r=this.props).onRendered)||e.call(r,this.state.error||void 0)}shouldComponentUpdate(e,r){return e.code!==this.props.code||e.scope!==this.props.scope||r.error!==this.state.error}componentDidUpdate(){var e,r;null==(e=(r=this.props).onRendered)||e.call(r,this.state.error||void 0)}render(){return this.state.error?null:this.state.element}}exports.Runner=a,exports.createRequire=e=>r=>{if(!e.hasOwnProperty(r))throw new Error("Module not found: '"+r+"'");return e[r]},exports.generateElement=p,exports.importCode=(e,r)=>{const t={};return l(s(e),o({React:n.default},r,{exports:t})),t},exports.useRunner=r=>{let{code:t,scope:n,disableCache:o}=r;const s=e.useRef(!0),c=e.useRef(null),[u,l]=e.useState(()=>{const r=e.createElement(a,{code:t,scope:n,onRendered:e=>{e?l({element:o?null:c.current,error:e.toString()}):c.current=r}});return{element:r,error:null}});return e.useEffect(()=>{if(s.current)return void(s.current=!1);const r=e.createElement(a,{code:t,scope:n,onRendered:e=>{e?l({element:o?null:c.current,error:e.toString()}):c.current=r}});l({element:r,error:null})},[t,n,o]),u};
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import r,{isValidElement as e,createElement as t,Fragment as n,Component as o,useRef as s,useState as c,useEffect as u}from"react";import{transform as l}from"sucrase";function a(){return a=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r},a.apply(this,arguments)}const i=/^export default(?=\s+)/m,p=/^render(?=\s*\([^)])/m,d=/^<[^>]*>/,m=/^(function|\(\)|class)[^\w]+/,f={React:r,jsxPragma:r.createElement,jsxFragmentPragma:r.Fragment},g=r=>e=>{if(!r.hasOwnProperty(e))throw new Error(`Module not found: '${e}'`);return r[e]},h=r=>{const{code:o,scope:s}=r,c=o.trim();if(!c)return null;const u=(null==s?void 0:s.require)&&"function"==typeof s.require,g=((r,e)=>l(r,{transforms:e?["jsx","typescript","imports"]:["jsx","typescript"],production:!0,jsxPragma:"jsxPragma",jsxFragmentPragma:"jsxFragmentPragma"}).code)((r=>d.test(r)?`return (<>${r}</>)`:i.test(r)?r.replace(i,"return"):p.test(r)?r.replace(p,"return"):m.test(r)?`return (${r.replace(/;$/,"")})`:r)(c),u),h=((r,e)=>{const t=Object.keys(e),n=t.map(r=>e[r]);return new Function(...t,r)(...n)})(g,a({},f,s));return h?e(h)?h:"function"==typeof h?t(h):"string"==typeof h?t(n,void 0,h):null:null};class v extends o{constructor(...r){super(...r),this.state={element:null,error:null,prevCode:null}}static getDerivedStateFromProps(r,e){if(e.prevCode===r.code)return null;try{return{element:h(r),error:e.error&&r.code!==e.prevCode?null:e.error,prevCode:r.code}}catch(e){return{element:null,error:e,prevCode:r.code}}}static getDerivedStateFromError(r){return{error:r}}componentDidMount(){var r,e;null==(r=(e=this.props).onRendered)||r.call(e,this.state.error||void 0)}shouldComponentUpdate(r,e){return r.code!==this.props.code||e.error!==this.state.error}componentDidUpdate(){var r,e;null==(r=(e=this.props).onRendered)||r.call(e,this.state.error||void 0)}render(){return this.state.error?null:this.state.element}}const j=({code:r,scope:e,disableCache:n})=>{const o=s(!0),l=s(null),a=s(e);a.current=e;const[i,p]=c(()=>{const e=t(v,{code:r,scope:a.current,onRendered:r=>{r?p({element:n?null:l.current,error:r.toString()}):l.current=e}});return{element:e,error:null}});return u(()=>{if(o.current)return void(o.current=!1);const e=t(v,{code:r,scope:a.current,onRendered:r=>{r?p({element:n?null:l.current,error:r.toString()}):l.current=e}});p({element:e,error:null})},[r,n]),i};export{v as Runner,g as createRequire,h as generateElement,j as useRunner};
import e,{isValidElement as r,createElement as t,Component as o,useRef as n,useState as s,useEffect as c}from"react";import{transform as l}from"sucrase";function u(){return u=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},u.apply(this,arguments)}const p=e=>l(e,{transforms:["jsx","typescript","imports"],production:!0}).code.substring(13),d=/^<[^>]*>/,i=/^(function|\(\)|class)[^\w]+/,a=(e,r)=>{const t=Object.keys(r),o=t.map(e=>r[e]);return new Function(...t,e)(...o)},m=o=>{const{code:n,scope:s}=o,c=(e=>{const r=e.trim();return r?d.test(r)||i.test(r)?`export default ${r}`:e:r})(n);if(!c)return null;const l=p(c),m={};a(l,u({React:e,render:e=>{m.default=e}},s,{exports:m}));const f=m.default;return f?r(f)?f:"function"==typeof f?t(f):"string"==typeof f?f:null:null},f=e=>r=>{if(!e.hasOwnProperty(r))throw new Error(`Module not found: '${r}'`);return e[r]},h=(r,t)=>{const o={};return a(p(r),u({React:e},t,{exports:o})),o};class v extends o{constructor(...e){super(...e),this.state={element:null,error:null,prevCode:null,prevScope:null}}static getDerivedStateFromProps(e,r){if(r.prevCode===e.code&&r.prevScope===e.scope)return null;try{return{element:m(e),error:null,prevCode:e.code,prevScope:e.scope}}catch(r){return{element:null,error:r,prevCode:e.code,prevScope:e.scope}}}static getDerivedStateFromError(e){return{error:e}}componentDidMount(){var e,r;null==(e=(r=this.props).onRendered)||e.call(r,this.state.error||void 0)}shouldComponentUpdate(e,r){return e.code!==this.props.code||e.scope!==this.props.scope||r.error!==this.state.error}componentDidUpdate(){var e,r;null==(e=(r=this.props).onRendered)||e.call(r,this.state.error||void 0)}render(){return this.state.error?null:this.state.element}}const y=({code:e,scope:r,disableCache:o})=>{const l=n(!0),u=n(null),[p,d]=s(()=>{const n=t(v,{code:e,scope:r,onRendered:e=>{e?d({element:o?null:u.current,error:e.toString()}):u.current=n}});return{element:n,error:null}});return c(()=>{if(l.current)return void(l.current=!1);const n=t(v,{code:e,scope:r,onRendered:e=>{e?d({element:o?null:u.current,error:e.toString()}):u.current=n}});d({element:n,error:null})},[e,r,o]),p};export{v as Runner,f as createRequire,m as generateElement,h as importCode,y as useRunner};
//# sourceMappingURL=index.modern.js.map

@@ -1,2 +0,2 @@

!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react"),require("sucrase")):"function"==typeof define&&define.amd?define(["exports","react","sucrase"],r):r((e||self).reactRunner={},e.react,e.sucrase)}(this,function(e,r,t){function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=/*#__PURE__*/n(r);function u(){return u=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},u.apply(this,arguments)}const s=/^export default(?=\s+)/m,c=/^render(?=\s*\([^)])/m,l=/^<[^>]*>/,a=/^(function|\(\)|class)[^\w]+/,i={React:o.default,jsxPragma:o.default.createElement,jsxFragmentPragma:o.default.Fragment},d=e=>{const{code:n,scope:o}=e,d=n.trim();if(!d)return null;const p=(null==o?void 0:o.require)&&"function"==typeof o.require,f=((e,r)=>t.transform(e,{transforms:r?["jsx","typescript","imports"]:["jsx","typescript"],production:!0,jsxPragma:"jsxPragma",jsxFragmentPragma:"jsxFragmentPragma"}).code)((e=>l.test(e)?"return (<>"+e+"</>)":s.test(e)?e.replace(s,"return"):c.test(e)?e.replace(c,"return"):a.test(e)?"return ("+e.replace(/;$/,"")+")":e)(d),p),m=((e,r)=>{const t=Object.keys(r),n=t.map(e=>r[e]);return new Function(...t,e)(...n)})(f,u({},i,o));return m?r.isValidElement(m)?m:"function"==typeof m?r.createElement(m):"string"==typeof m?r.createElement(r.Fragment,void 0,m):null:null};class p extends r.Component{constructor(){super(...arguments),this.state={element:null,error:null,prevCode:null}}static getDerivedStateFromProps(e,r){if(r.prevCode===e.code)return null;try{return{element:d(e),error:r.error&&e.code!==r.prevCode?null:r.error,prevCode:e.code}}catch(r){return{element:null,error:r,prevCode:e.code}}}static getDerivedStateFromError(e){return{error:e}}componentDidMount(){var e,r;null==(e=(r=this.props).onRendered)||e.call(r,this.state.error||void 0)}shouldComponentUpdate(e,r){return e.code!==this.props.code||r.error!==this.state.error}componentDidUpdate(){var e,r;null==(e=(r=this.props).onRendered)||e.call(r,this.state.error||void 0)}render(){return this.state.error?null:this.state.element}}e.Runner=p,e.createRequire=e=>r=>{if(!e.hasOwnProperty(r))throw new Error("Module not found: '"+r+"'");return e[r]},e.generateElement=d,e.useRunner=e=>{let{code:t,scope:n,disableCache:o}=e;const u=r.useRef(!0),s=r.useRef(null),c=r.useRef(n);c.current=n;const[l,a]=r.useState(()=>{const e=r.createElement(p,{code:t,scope:c.current,onRendered:r=>{r?a({element:o?null:s.current,error:r.toString()}):s.current=e}});return{element:e,error:null}});return r.useEffect(()=>{if(u.current)return void(u.current=!1);const e=r.createElement(p,{code:t,scope:c.current,onRendered:r=>{r?a({element:o?null:s.current,error:r.toString()}):s.current=e}});a({element:e,error:null})},[t,o]),l}});
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react"),require("sucrase")):"function"==typeof define&&define.amd?define(["exports","react","sucrase"],r):r((e||self).reactRunner={},e.react,e.sucrase)}(this,function(e,r,t){function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=/*#__PURE__*/n(r);function s(){return s=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},s.apply(this,arguments)}const c=e=>t.transform(e,{transforms:["jsx","typescript","imports"],production:!0}).code.substring(13),u=/^<[^>]*>/,l=/^(function|\(\)|class)[^\w]+/,p=(e,r)=>{const t=Object.keys(r),n=t.map(e=>r[e]);return new Function(...t,e)(...n)},a=e=>{const{code:t,scope:n}=e,a=(e=>{const r=e.trim();return r?u.test(r)||l.test(r)?"export default "+r:e:r})(t);if(!a)return null;const i=c(a),d={};p(i,s({React:o.default,render:e=>{d.default=e}},n,{exports:d}));const f=d.default;return f?r.isValidElement(f)?f:"function"==typeof f?r.createElement(f):"string"==typeof f?f:null:null};class i extends r.Component{constructor(){super(...arguments),this.state={element:null,error:null,prevCode:null,prevScope:null}}static getDerivedStateFromProps(e,r){if(r.prevCode===e.code&&r.prevScope===e.scope)return null;try{return{element:a(e),error:null,prevCode:e.code,prevScope:e.scope}}catch(r){return{element:null,error:r,prevCode:e.code,prevScope:e.scope}}}static getDerivedStateFromError(e){return{error:e}}componentDidMount(){var e,r;null==(e=(r=this.props).onRendered)||e.call(r,this.state.error||void 0)}shouldComponentUpdate(e,r){return e.code!==this.props.code||e.scope!==this.props.scope||r.error!==this.state.error}componentDidUpdate(){var e,r;null==(e=(r=this.props).onRendered)||e.call(r,this.state.error||void 0)}render(){return this.state.error?null:this.state.element}}e.Runner=i,e.createRequire=e=>r=>{if(!e.hasOwnProperty(r))throw new Error("Module not found: '"+r+"'");return e[r]},e.generateElement=a,e.importCode=(e,r)=>{const t={};return p(c(e),s({React:o.default},r,{exports:t})),t},e.useRunner=e=>{let{code:t,scope:n,disableCache:o}=e;const s=r.useRef(!0),c=r.useRef(null),[u,l]=r.useState(()=>{const e=r.createElement(i,{code:t,scope:n,onRendered:r=>{r?l({element:o?null:c.current,error:r.toString()}):c.current=e}});return{element:e,error:null}});return r.useEffect(()=>{if(s.current)return void(s.current=!1);const e=r.createElement(i,{code:t,scope:n,onRendered:r=>{r?l({element:o?null:c.current,error:r.toString()}):c.current=e}});l({element:e,error:null})},[t,n,o]),u}});
//# sourceMappingURL=index.umd.js.map
import { Component, ReactElement } from 'react';
import { RunnerOptions } from './types';
import { RunnerOptions, Scope } from './types';
export declare type RunnerProps = RunnerOptions & {

@@ -11,2 +11,3 @@ /** callback on code be rendered, returns error message when code is invalid */

prevCode: string | null;
prevScope: Scope | null;
};

@@ -13,0 +14,0 @@ export declare class Runner extends Component<RunnerProps, RunnerState> {

@@ -1,1 +0,1 @@

export declare const transform: (code: string, transformImports?: boolean | undefined) => string;
export declare const transform: (code: string) => string;
import { ReactElement } from 'react';
import { RunnerOptions, Scope } from './types';
export declare const generateElement: (options: RunnerOptions) => ReactElement | null;
export declare const createRequire: (imports: Scope) => (module: string) => any;
export declare const generateElement: (options: RunnerOptions) => ReactElement | null;
export declare const importCode: (code: string, scope?: Scope | undefined) => Scope;
{
"name": "react-runner",
"version": "1.0.0-alpha.6",
"version": "1.0.0-alpha.7",
"description": "Run your React code on the go",

@@ -24,2 +24,3 @@ "homepage": "https://react-runner.vercel.app",

"types": "dist/index.d.ts",
"sideEffects": false,
"files": [

@@ -67,3 +68,3 @@ "dist"

},
"gitHead": "a789960bd317e986054550ba0afa96fa45daf689"
"gitHead": "89f3d187a3b8f57c0acebbb0a54c072fe9fa5026"
}
# React Runner
Run your React code on the go [https://react-runner.vercel.app](https://react-runner.vercel.app)
## Features
- Inline element(s)
- Function component
- Class component, **with class fields support**
- Composing components with `render` or `export default`
- Server Side Rendering
- Support `Typescript`
- Support `import` statement via `createRequire` utility
Hacker News [in react-runner](https://react-runner.vercel.app/#hacker-news) vs [in real world](https://react-runner.vercel.app/examples/hacker-news), with the same code
## Install
```bash
# Yarn
yarn add react-runner
# NPM
npm install --save react-runner
```
## Options
- **code** `string`, _required_ the code to be ran
- **scope** `object` globals that could be used in `code`
### Predefined scope
```js
{
React,
jsxPragma: React.createElement, // useful if you are using Emotion with `css` prop
jsxFragmentPragma: React.Fragment,
}
```
## Usage
```jsx
import { useRunner } from 'react-runner'
const { element, error } = useRunner({ code, scope })
```
or use `Runner` as a component directly and handle error with `onRendered`
```jsx
import { Runner } from 'react-runner'
const element = <Runner code={code} scope={scope} onRendered={handleRendered} />
```
### `import` statement
```js
// you can define your own version of `createRequire`
import { createRequire } from 'react-runner'
import * as YourPkg from 'your-pkg'
const scope = {
require: createRquire({
'your-pkg': YourPkg,
}),
}
```
then in your code you can use `import Foo, { Bar } from 'your-pkg'`
## Browser support
```
"browserslist": [
"Chrome > 61",
"Edge > 16",
"Firefox > 60",
"Safari > 10.1"
]
```
## react-live-runner
`react-runner` is inspired by [react-live](https://github.com/FormidableLabs/react-live) heavily,
I love it, but I love arrow functions for event handlers instead of bind them manually as well as other modern features,
and I don't want to change my code to be compliant with restrictions, so I created this project,
use [Sucrase](https://github.com/alangpierce/sucrase) instead of [Bublé](https://github.com/bublejs/buble) to transpile the code.
If you are using `react-live` in your project and want a smooth transition, `react-live-runner` is there for you which provide the identical way to play with, and `react-live-runner` re-exports `react-runner` so you can use everything in `react-runner` by importing `react-live-runner`
```jsx
import {
LiveProvider,
LiveEditor,
LiveError,
LivePreview,
} from 'react-live-runner'
...
<LiveProvider code={code} scope={scope}>
<LiveEditor />
<LivePreview />
<LiveError />
</LiveProvider>
...
```
or hooks for better custom rendering
```jsx
import { useLiveRunner, CodeEditor } from 'react-live-runner'
const { element, error, code, onChange } = useLiveRunner({
initialCode,
scope,
transformCode,
})
...
<>
<CodeEditor value={code} onChange={onChange}>
<div>{element}</div>
{error && <pre>{error}</pre>}
</>
...
```
or use `react-runner` directly
```jsx
import { useState, useEffect } from 'react'
import { useRunner } from 'react-runner'
const [code, onChange] = useState(initialCode)
const { element, error } = useRunner({ code, scope })
useEffect(() => {
onChange(initialCode)
}, [initialCode])
...
<>
<textarea value={code} onChange={event => onChange(event.target.value)}>
<div>{element}</div>
{error && <pre>{error}</pre>}
</>
...
```
See the real world usage here https://github.com/nihgwu/react-runner/blob/master/website/src/components/LiveRunner.tsx
## License
MIT © [Neo Nie](https://github.com/nihgwu)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc