react-runner
Advanced tools
Comparing version 1.0.0-alpha.3 to 1.0.0-alpha.4
@@ -1,2 +0,2 @@ | ||
import e,{isValidElement as r,createElement as t,Fragment as n,Component as o,useRef as l,useState as c,useEffect as s}from"react";import{transform as u}from"sucrase";function d(){return d=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},d.apply(this,arguments)}const p=/^export default(?=\s+)/m,i=/^render(?=\s*\([^)])/m,a=/^</,m=o=>{const{code:l,scope:c}=o,s=l.trim();if(!s)return null;const m=(e=>u(e,{transforms:["jsx","typescript"],production:!0}).code)((e=>p.test(e)?e.replace(p,"return"):i.test(e)?e.replace(i,"return"):(e=e.replace(/;$/,""),a.test(e)&&(e="<>"+e+"</>"),"return ("+e+")"))(s)),v=((e,r)=>{const t=Object.keys(r),n=t.map(e=>r[e]);return new Function(...t,e)(...n)})(m,d({React:e},c));return v?r(v)?v:"function"==typeof v?t(v):"string"==typeof v?t(n,void 0,v):null:null};class v extends o{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:m(e),error:r.error&&e.code!==r.prevCode?null:r.error,prevCode:e.code}}catch(r){return{element:null,error:r.toString(),prevCode:e.code}}}static getDerivedStateFromError(e){return{error:e.toString()}}componentDidMount(){var e,r,t;null==(e=(r=this.props).onRendered)||e.call(r,null==(t=this.state.error)?void 0:t.toString())}shouldComponentUpdate(e){return e.code!==this.props.code}componentDidUpdate(){var e,r,t;null==(e=(r=this.props).onRendered)||e.call(r,null==(t=this.state.error)?void 0:t.toString())}render(){return this.state.error?null:this.state.element}}const f=e=>{let{code:r,scope:n,disableCache:o}=e;const u=l(!0),d=l(null),p=l(n);p.current=n;const[i,a]=c(()=>{const e=t(v,{code:r,scope:p.current,onRendered:r=>{r?a({element:o?null:d.current,error:r}):d.current=e}});return{element:e,error:null}});return s(()=>{if(u.current)return void(u.current=!1);const e=t(v,{code:r,scope:p.current,onRendered:r=>{r?a({element:o?null:d.current,error:r}):d.current=e}});a({element:e,error:null})},[r,o]),i};export{v as Runner,m as generateElement,f as useRunner}; | ||
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 p(){return p=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},p.apply(this,arguments)}const i=/^export default(?=\s+)/m,d=/^render(?=\s*\([^)])/m,a=/^</,m=o=>{const{code:s,scope:c,imports:l}=o,m=s.trim();if(!m)return null;const f=!!l&&Object.keys(l).length>0,h=((r,e)=>u(r,{transforms:e?["jsx","typescript","imports"]:["jsx","typescript"],production:!0}).code)((r=>i.test(r)?r.replace(i,"return"):d.test(r)?r.replace(d,"return"):(r=r.replace(/;$/,""),a.test(r)&&(r="<>"+r+"</>"),"return ("+r+")"))(m),f),v=p({React:r},c);f&&(v.require=r=>{if(!l.hasOwnProperty(r))throw new Error("Module not found: '"+r+"'");return l[r]});const y=((r,e)=>{const t=Object.keys(e),n=t.map(r=>e[r]);return new Function(...t,r)(...n)})(h,v);return y?e(y)?y:"function"==typeof y?t(y):"string"==typeof y?t(n,void 0,y):null:null};class f 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:m(r),error:e.error&&r.code!==e.prevCode?null:e.error,prevCode:r.code}}catch(e){return{element:null,error:e.toString(),prevCode:r.code}}}static getDerivedStateFromError(r){return{error:r.toString()}}componentDidMount(){var r,e,t;null==(r=(e=this.props).onRendered)||r.call(e,null==(t=this.state.error)?void 0:t.toString())}shouldComponentUpdate(r){return r.code!==this.props.code}componentDidUpdate(){var r,e,t;null==(r=(e=this.props).onRendered)||r.call(e,null==(t=this.state.error)?void 0:t.toString())}render(){return this.state.error?null:this.state.element}}const h=r=>{let{code:e,scope:n,imports:o,disableCache:u}=r;const p=s(!0),i=s(null),d=s(n);d.current=n;const a=s(o);a.current=o;const[m,h]=c(()=>{const r=t(f,{code:e,scope:d.current,imports:a.current,onRendered:e=>{e?h({element:u?null:i.current,error:e}):i.current=r}});return{element:r,error:null}});return l(()=>{if(p.current)return void(p.current=!1);const r=t(f,{code:e,scope:d.current,imports:a.current,onRendered:e=>{e?h({element:u?null:i.current,error:e}):i.current=r}});h({element:r,error:null})},[e,u]),m};export{f as Runner,m as generateElement,h 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 l=/^export default(?=\s+)/m,u=/^render(?=\s*\([^)])/m,c=/^</,s=t=>{const{code:s,scope:a}=t,d=s.trim();if(!d)return null;const i=(e=>r.transform(e,{transforms:["jsx","typescript"],production:!0}).code)((e=>l.test(e)?e.replace(l,"return"):u.test(e)?e.replace(u,"return"):(e=e.replace(/;$/,""),c.test(e)&&(e="<>"+e+"</>"),"return ("+e+")"))(d)),p=((e,r)=>{const t=Object.keys(r),n=t.map(e=>r[e]);return new Function(...t,e)(...n)})(i,o({React:n.default},a));return p?e.isValidElement(p)?p:"function"==typeof p?e.createElement(p):"string"==typeof p?e.createElement(e.Fragment,void 0,p):null:null};class a 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:s(e),error:r.error&&e.code!==r.prevCode?null:r.error,prevCode:e.code}}catch(r){return{element:null,error:r.toString(),prevCode:e.code}}}static getDerivedStateFromError(e){return{error:e.toString()}}componentDidMount(){var e,r,t;null==(e=(r=this.props).onRendered)||e.call(r,null==(t=this.state.error)?void 0:t.toString())}shouldComponentUpdate(e){return e.code!==this.props.code}componentDidUpdate(){var e,r,t;null==(e=(r=this.props).onRendered)||e.call(r,null==(t=this.state.error)?void 0:t.toString())}render(){return this.state.error?null:this.state.element}}exports.Runner=a,exports.generateElement=s,exports.useRunner=r=>{let{code:t,scope:n,disableCache:o}=r;const l=e.useRef(!0),u=e.useRef(null),c=e.useRef(n);c.current=n;const[s,d]=e.useState(()=>{const r=e.createElement(a,{code:t,scope:c.current,onRendered:e=>{e?d({element:o?null:u.current,error:e}):u.current=r}});return{element:r,error:null}});return e.useEffect(()=>{if(l.current)return void(l.current=!1);const r=e.createElement(a,{code:t,scope:c.current,onRendered:e=>{e?d({element:o?null:u.current,error:e}):u.current=r}});d({element:r,error:null})},[t,o]),s}; | ||
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 u=/^export default(?=\s+)/m,s=/^render(?=\s*\([^)])/m,c=/^</,l=t=>{const{code:l,scope:i,imports:a}=t,p=l.trim();if(!p)return null;const d=!!a&&Object.keys(a).length>0,m=((e,t)=>r.transform(e,{transforms:t?["jsx","typescript","imports"]:["jsx","typescript"],production:!0}).code)((e=>u.test(e)?e.replace(u,"return"):s.test(e)?e.replace(s,"return"):(e=e.replace(/;$/,""),c.test(e)&&(e="<>"+e+"</>"),"return ("+e+")"))(p),d),f=o({React:n.default},i);d&&(f.require=e=>{if(!a.hasOwnProperty(e))throw new Error("Module not found: '"+e+"'");return a[e]});const v=((e,r)=>{const t=Object.keys(r),n=t.map(e=>r[e]);return new Function(...t,e)(...n)})(m,f);return v?e.isValidElement(v)?v:"function"==typeof v?e.createElement(v):"string"==typeof v?e.createElement(e.Fragment,void 0,v):null:null};class i 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:l(e),error:r.error&&e.code!==r.prevCode?null:r.error,prevCode:e.code}}catch(r){return{element:null,error:r.toString(),prevCode:e.code}}}static getDerivedStateFromError(e){return{error:e.toString()}}componentDidMount(){var e,r,t;null==(e=(r=this.props).onRendered)||e.call(r,null==(t=this.state.error)?void 0:t.toString())}shouldComponentUpdate(e){return e.code!==this.props.code}componentDidUpdate(){var e,r,t;null==(e=(r=this.props).onRendered)||e.call(r,null==(t=this.state.error)?void 0:t.toString())}render(){return this.state.error?null:this.state.element}}exports.Runner=i,exports.generateElement=l,exports.useRunner=r=>{let{code:t,scope:n,imports:o,disableCache:u}=r;const s=e.useRef(!0),c=e.useRef(null),l=e.useRef(n);l.current=n;const a=e.useRef(o);a.current=o;const[p,d]=e.useState(()=>{const r=e.createElement(i,{code:t,scope:l.current,imports:a.current,onRendered:e=>{e?d({element:u?null:c.current,error:e}):c.current=r}});return{element:r,error:null}});return e.useEffect(()=>{if(s.current)return void(s.current=!1);const r=e.createElement(i,{code:t,scope:l.current,imports:a.current,onRendered:e=>{e?d({element:u?null:c.current,error:e}):c.current=r}});d({element:r,error:null})},[t,u]),p}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import e,{isValidElement as r,createElement as t,Fragment as n,Component as o,useRef as c,useState as l,useEffect as s}from"react";import{transform as u}from"sucrase";function d(){return d=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},d.apply(this,arguments)}const p=/^export default(?=\s+)/m,i=/^render(?=\s*\([^)])/m,a=/^</,m=o=>{const{code:c,scope:l}=o,s=c.trim();if(!s)return null;const m=(e=>u(e,{transforms:["jsx","typescript"],production:!0}).code)((e=>p.test(e)?e.replace(p,"return"):i.test(e)?e.replace(i,"return"):(e=e.replace(/;$/,""),a.test(e)&&(e=`<>${e}</>`),`return (${e})`))(s)),v=((e,r)=>{const t=Object.keys(r),n=t.map(e=>r[e]);return new Function(...t,e)(...n)})(m,d({React:e},l));return v?r(v)?v:"function"==typeof v?t(v):"string"==typeof v?t(n,void 0,v):null:null};class v extends o{constructor(...e){super(...e),this.state={element:null,error:null,prevCode:null}}static getDerivedStateFromProps(e,r){if(r.prevCode===e.code)return null;try{return{element:m(e),error:r.error&&e.code!==r.prevCode?null:r.error,prevCode:e.code}}catch(r){return{element:null,error:r.toString(),prevCode:e.code}}}static getDerivedStateFromError(e){return{error:e.toString()}}componentDidMount(){var e,r,t;null==(e=(r=this.props).onRendered)||e.call(r,null==(t=this.state.error)?void 0:t.toString())}shouldComponentUpdate(e){return e.code!==this.props.code}componentDidUpdate(){var e,r,t;null==(e=(r=this.props).onRendered)||e.call(r,null==(t=this.state.error)?void 0:t.toString())}render(){return this.state.error?null:this.state.element}}const f=({code:e,scope:r,disableCache:n})=>{const o=c(!0),u=c(null),d=c(r);d.current=r;const[p,i]=l(()=>{const r=t(v,{code:e,scope:d.current,onRendered:e=>{e?i({element:n?null:u.current,error:e}):u.current=r}});return{element:r,error:null}});return s(()=>{if(o.current)return void(o.current=!1);const r=t(v,{code:e,scope:d.current,onRendered:e=>{e?i({element:n?null:u.current,error:e}):u.current=r}});i({element:r,error:null})},[e,n]),p};export{v as Runner,m as generateElement,f as useRunner}; | ||
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 p(){return p=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},p.apply(this,arguments)}const i=/^export default(?=\s+)/m,d=/^render(?=\s*\([^)])/m,a=/^</,m=o=>{const{code:s,scope:c,imports:l}=o,m=s.trim();if(!m)return null;const f=!!l&&Object.keys(l).length>0,h=((r,e)=>u(r,{transforms:e?["jsx","typescript","imports"]:["jsx","typescript"],production:!0}).code)((r=>i.test(r)?r.replace(i,"return"):d.test(r)?r.replace(d,"return"):(r=r.replace(/;$/,""),a.test(r)&&(r=`<>${r}</>`),`return (${r})`))(m),f),v=p({React:r},c);f&&(v.require=r=>{if(!l.hasOwnProperty(r))throw new Error(`Module not found: '${r}'`);return l[r]});const y=((r,e)=>{const t=Object.keys(e),n=t.map(r=>e[r]);return new Function(...t,r)(...n)})(h,v);return y?e(y)?y:"function"==typeof y?t(y):"string"==typeof y?t(n,void 0,y):null:null};class f 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:m(r),error:e.error&&r.code!==e.prevCode?null:e.error,prevCode:r.code}}catch(e){return{element:null,error:e.toString(),prevCode:r.code}}}static getDerivedStateFromError(r){return{error:r.toString()}}componentDidMount(){var r,e,t;null==(r=(e=this.props).onRendered)||r.call(e,null==(t=this.state.error)?void 0:t.toString())}shouldComponentUpdate(r){return r.code!==this.props.code}componentDidUpdate(){var r,e,t;null==(r=(e=this.props).onRendered)||r.call(e,null==(t=this.state.error)?void 0:t.toString())}render(){return this.state.error?null:this.state.element}}const h=({code:r,scope:e,imports:n,disableCache:o})=>{const u=s(!0),p=s(null),i=s(e);i.current=e;const d=s(n);d.current=n;const[a,m]=c(()=>{const e=t(f,{code:r,scope:i.current,imports:d.current,onRendered:r=>{r?m({element:o?null:p.current,error:r}):p.current=e}});return{element:e,error:null}});return l(()=>{if(u.current)return void(u.current=!1);const e=t(f,{code:r,scope:i.current,imports:d.current,onRendered:r=>{r?m({element:o?null:p.current,error:r}):p.current=e}});m({element:e,error:null})},[r,o]),a};export{f as Runner,m as generateElement,h 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 l=/^export default(?=\s+)/m,c=/^render(?=\s*\([^)])/m,s=/^</,a=e=>{const{code:n,scope:a}=e,d=n.trim();if(!d)return null;const i=(e=>t.transform(e,{transforms:["jsx","typescript"],production:!0}).code)((e=>l.test(e)?e.replace(l,"return"):c.test(e)?e.replace(c,"return"):(e=e.replace(/;$/,""),s.test(e)&&(e="<>"+e+"</>"),"return ("+e+")"))(d)),p=((e,r)=>{const t=Object.keys(r),n=t.map(e=>r[e]);return new Function(...t,e)(...n)})(i,u({React:o.default},a));return p?r.isValidElement(p)?p:"function"==typeof p?r.createElement(p):"string"==typeof p?r.createElement(r.Fragment,void 0,p):null:null};class d 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:a(e),error:r.error&&e.code!==r.prevCode?null:r.error,prevCode:e.code}}catch(r){return{element:null,error:r.toString(),prevCode:e.code}}}static getDerivedStateFromError(e){return{error:e.toString()}}componentDidMount(){var e,r,t;null==(e=(r=this.props).onRendered)||e.call(r,null==(t=this.state.error)?void 0:t.toString())}shouldComponentUpdate(e){return e.code!==this.props.code}componentDidUpdate(){var e,r,t;null==(e=(r=this.props).onRendered)||e.call(r,null==(t=this.state.error)?void 0:t.toString())}render(){return this.state.error?null:this.state.element}}e.Runner=d,e.generateElement=a,e.useRunner=e=>{let{code:t,scope:n,disableCache:o}=e;const u=r.useRef(!0),l=r.useRef(null),c=r.useRef(n);c.current=n;const[s,a]=r.useState(()=>{const e=r.createElement(d,{code:t,scope:c.current,onRendered:r=>{r?a({element:o?null:l.current,error:r}):l.current=e}});return{element:e,error:null}});return r.useEffect(()=>{if(u.current)return void(u.current=!1);const e=r.createElement(d,{code:t,scope:c.current,onRendered:r=>{r?a({element:o?null:l.current,error:r}):l.current=e}});a({element:e,error:null})},[t,o]),s}}); | ||
!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=/^</,i=e=>{const{code:n,scope:i,imports:a}=e,d=n.trim();if(!d)return null;const p=!!a&&Object.keys(a).length>0,f=((e,r)=>t.transform(e,{transforms:r?["jsx","typescript","imports"]:["jsx","typescript"],production:!0}).code)((e=>s.test(e)?e.replace(s,"return"):c.test(e)?e.replace(c,"return"):(e=e.replace(/;$/,""),l.test(e)&&(e="<>"+e+"</>"),"return ("+e+")"))(d),p),m=u({React:o.default},i);p&&(m.require=e=>{if(!a.hasOwnProperty(e))throw new Error("Module not found: '"+e+"'");return a[e]});const h=((e,r)=>{const t=Object.keys(r),n=t.map(e=>r[e]);return new Function(...t,e)(...n)})(f,m);return h?r.isValidElement(h)?h:"function"==typeof h?r.createElement(h):"string"==typeof h?r.createElement(r.Fragment,void 0,h):null:null};class a 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:i(e),error:r.error&&e.code!==r.prevCode?null:r.error,prevCode:e.code}}catch(r){return{element:null,error:r.toString(),prevCode:e.code}}}static getDerivedStateFromError(e){return{error:e.toString()}}componentDidMount(){var e,r,t;null==(e=(r=this.props).onRendered)||e.call(r,null==(t=this.state.error)?void 0:t.toString())}shouldComponentUpdate(e){return e.code!==this.props.code}componentDidUpdate(){var e,r,t;null==(e=(r=this.props).onRendered)||e.call(r,null==(t=this.state.error)?void 0:t.toString())}render(){return this.state.error?null:this.state.element}}e.Runner=a,e.generateElement=i,e.useRunner=e=>{let{code:t,scope:n,imports:o,disableCache:u}=e;const s=r.useRef(!0),c=r.useRef(null),l=r.useRef(n);l.current=n;const i=r.useRef(o);i.current=o;const[d,p]=r.useState(()=>{const e=r.createElement(a,{code:t,scope:l.current,imports:i.current,onRendered:r=>{r?p({element:u?null:c.current,error:r}):c.current=e}});return{element:e,error:null}});return r.useEffect(()=>{if(s.current)return void(s.current=!1);const e=r.createElement(a,{code:t,scope:l.current,imports:i.current,onRendered:r=>{r?p({element:u?null:c.current,error:r}):c.current=e}});p({element:e,error:null})},[t,u]),d}}); | ||
//# sourceMappingURL=index.umd.js.map |
import { Component, ReactElement } from 'react'; | ||
import { RunnerOptions } from './types'; | ||
export declare type RunnerProps = RunnerOptions & { | ||
/** callback on code be rendered, returns error message when code is invalid */ | ||
onRendered?: (error?: string) => void; | ||
@@ -5,0 +6,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
export declare const transform: (code: string) => string; | ||
export declare const transform: (code: string, hasImports?: boolean | undefined) => string; |
export declare type Scope = Record<string, any>; | ||
export declare type RunnerOptions = { | ||
/** the code to run */ | ||
code: string; | ||
/** globals that could be used in code */ | ||
scope?: Scope; | ||
/** imports that could be used in code */ | ||
imports?: Scope; | ||
}; |
import { ReactElement } from 'react'; | ||
import { RunnerOptions } from './types'; | ||
export declare type UseRunnerProps = RunnerOptions & { | ||
/** whether to cache previous element when error occurs with current code */ | ||
disableCache?: boolean; | ||
@@ -10,2 +11,2 @@ }; | ||
}; | ||
export declare const useRunner: ({ code, scope, disableCache, }: UseRunnerProps) => UseRunnerReturn; | ||
export declare const useRunner: ({ code, scope, imports, disableCache, }: UseRunnerProps) => UseRunnerReturn; |
{ | ||
"name": "react-runner", | ||
"version": "1.0.0-alpha.3", | ||
"version": "1.0.0-alpha.4", | ||
"description": "Run your React code on the go", | ||
"homepage": "https://nihgwu.github.io/react-runner/", | ||
"homepage": "https://react-runner.vercel.app", | ||
"repository": { | ||
@@ -30,3 +30,3 @@ "type": "git", | ||
"test:ci": "jest --coverage", | ||
"tsc": "tsc", | ||
"typecheck": "tsc --noEmit", | ||
"build": "microbundle build", | ||
@@ -67,3 +67,3 @@ "watch": "microbundle watch", | ||
}, | ||
"gitHead": "45b0aaa9ad2d4a368e1e916b253d8a715ea92232" | ||
"gitHead": "013b30f469c9c4e3899c8493f6de7e4f6f9fc79a" | ||
} |
# React Runner | ||
Run your React code on the go [https://nihgwu.github.io/react-runner/](https://nihgwu.github.io/react-runner/) | ||
Run your React code on the go [https://react-runner.vercel.app](https://react-runner.vercel.app) | ||
@@ -14,3 +14,3 @@ ## Features | ||
Hacker News [in react-runner](https://nihgwu.github.io/react-runner/#hacker-news) vs [in real world](https://nihgwu.github.io/react-runner/examples/hacker-news), with the same code | ||
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 | ||
@@ -31,2 +31,3 @@ ## Install | ||
- **scope** `object` globals that could be used in `code` | ||
- **imports** `object` imports that could be used in `code` | ||
@@ -38,3 +39,3 @@ ## Usage | ||
const { element, error } = useRunner({ code, scope }) | ||
const { element, error } = useRunner({ code, scope, imports }) | ||
``` | ||
@@ -47,3 +48,10 @@ | ||
const element = <Runner code={code} scope={scope} onRendered={handleRendered} /> | ||
const element = ( | ||
<Runner | ||
code={code} | ||
scope={scope} | ||
imports={imports} | ||
onRendered={handleRendered} | ||
/> | ||
) | ||
``` | ||
@@ -80,6 +88,6 @@ | ||
... | ||
<LiveProvider code={code}> | ||
<LiveProvider code={code} scope={scope} imports={imports}> | ||
<LiveEditor /> | ||
<LivePreview /> | ||
<LiveError /> | ||
<LivePreview /> | ||
</LiveProvider> | ||
@@ -92,3 +100,3 @@ ... | ||
```jsx | ||
import { useLiveRunner } from 'react-live-runner' | ||
import { useLiveRunner, CodeEditor } from 'react-live-runner' | ||
@@ -98,4 +106,13 @@ const { element, error, code, onChange } = useLiveRunner({ | ||
scope, | ||
imports, | ||
transformCode, | ||
}) | ||
... | ||
<> | ||
<CodeEditor value={code} onChange={onChange}> | ||
<div>{element}</div> | ||
{error && <pre>{error}</pre>} | ||
</> | ||
... | ||
``` | ||
@@ -110,3 +127,3 @@ | ||
const [code, onChange] = useState(initialCode) | ||
const { element, error } = useRunner({ code, scope }) | ||
const { element, error } = useRunner({ code, scope, imports }) | ||
@@ -116,5 +133,13 @@ useEffect(() => { | ||
}, [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.js | ||
See the real world usage here https://github.com/nihgwu/react-runner/blob/master/website/src/components/LiveRunner.tsx | ||
@@ -121,0 +146,0 @@ ## License |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53668
94
140