react-live
Advanced tools
Comparing version 4.1.7 to 4.1.8
@@ -44,2 +44,3 @@ import { Prism, themes } from 'prism-react-renderer'; | ||
code: string; | ||
newCode?: string; | ||
disabled: boolean; | ||
@@ -46,0 +47,0 @@ language: string; |
@@ -107,11 +107,16 @@ "use strict"; | ||
}, [props.code]); | ||
(0, import_use_editable.useEditable)(editorRef, (text) => setCode(text.slice(0, -1)), { | ||
disabled: props.disabled, | ||
indentation: tabMode === "indentation" ? 2 : void 0 | ||
}); | ||
(0, import_react.useEffect)(() => { | ||
if (props.onChange) { | ||
props.onChange(code); | ||
(0, import_use_editable.useEditable)( | ||
editorRef, | ||
(text) => { | ||
const t = text.slice(0, -1); | ||
setCode(t); | ||
if (props.onChange) { | ||
props.onChange(t); | ||
} | ||
}, | ||
{ | ||
disabled: props.disabled, | ||
indentation: tabMode === "indentation" ? 2 : void 0 | ||
} | ||
}, [code]); | ||
); | ||
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: props.className, style: props.style, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( | ||
@@ -266,3 +271,6 @@ import_prism_react_renderer.Highlight, | ||
const errorCallback = (error) => { | ||
setState({ error: error.toString(), element: void 0 }); | ||
setState((previousState) => __spreadProps(__spreadValues({}, previousState), { | ||
error: error.toString(), | ||
element: void 0 | ||
})); | ||
}; | ||
@@ -273,3 +281,3 @@ try { | ||
const transformedCode = yield Promise.resolve(transformResult); | ||
const renderElement = (element) => setState({ error: void 0, element }); | ||
const renderElement = (element) => setState({ error: void 0, element, newCode }); | ||
if (typeof transformedCode !== "string") { | ||
@@ -284,3 +292,6 @@ throw new Error("Code failed to transform"); | ||
if (noInline) { | ||
setState({ error: void 0, element: null }); | ||
setState((previousState) => __spreadProps(__spreadValues({}, previousState), { | ||
error: void 0, | ||
element: null | ||
})); | ||
renderElementAsync(input, renderElement, errorCallback); | ||
@@ -349,8 +360,32 @@ } else { | ||
// src/components/Live/LivePreview.tsx | ||
var import_react9 = require("react"); | ||
// src/components/Live/ErrorBoundary.tsx | ||
var import_react8 = require("react"); | ||
var ErrorBoundary = class extends import_react8.Component { | ||
static getDerivedStateFromError() { | ||
return { hasError: true }; | ||
} | ||
constructor(props) { | ||
super(props); | ||
this.state = { hasError: false }; | ||
} | ||
componentDidCatch(err) { | ||
var _a, _b; | ||
(_b = (_a = this.props).onError) == null ? void 0 : _b.call(_a, err); | ||
} | ||
render() { | ||
if (this.state.hasError) { | ||
return null; | ||
} | ||
return this.props.children; | ||
} | ||
}; | ||
// src/components/Live/LivePreview.tsx | ||
var import_jsx_runtime6 = require("react/jsx-runtime"); | ||
function LivePreview(_a) { | ||
var _b = _a, { Component: Component2 = "div" } = _b, rest = __objRest(_b, ["Component"]); | ||
const { element: Element } = (0, import_react8.useContext)(LiveContext_default); | ||
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Component2, __spreadProps(__spreadValues({}, rest), { children: Element ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Element, {}) : null })); | ||
var _b = _a, { Component: Component3 = "div" } = _b, rest = __objRest(_b, ["Component"]); | ||
const { element: Element, onError, newCode } = (0, import_react9.useContext)(LiveContext_default); | ||
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ErrorBoundary, { onError, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Component3, __spreadProps(__spreadValues({}, rest), { children: Element ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Element, {}) : null })) }, newCode); | ||
} | ||
@@ -357,0 +392,0 @@ var LivePreview_default = LivePreview; |
{ | ||
"name": "react-live", | ||
"version": "4.1.7", | ||
"version": "4.1.8", | ||
"description": "A production-focused playground for live editing React code", | ||
@@ -11,4 +11,4 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"prism-react-renderer": "^2.0.6", | ||
"sucrase": "^3.31.0", | ||
"prism-react-renderer": "^2.4.0", | ||
"sucrase": "^3.35.0", | ||
"use-editable": "^2.3.3" | ||
@@ -15,0 +15,0 @@ }, |
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
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
77446
848
Updatedprism-react-renderer@^2.4.0
Updatedsucrase@^3.35.0