@lexical/react
Version:
This package provides Lexical components and hooks for React applications.
10 lines (8 loc) • 2.12 kB
JavaScript
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
;var r=require("react"),e=require("react/jsx-runtime");function t(r){var e=Object.create(null);if(r)for(var t in r)e[t]=r[t];return e.default=r,e}var n=t(r);function o(r,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,e){return r.__proto__=e,r},o(r,e)}var a={error:null},i=function(r){var e,t;function i(){for(var e,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];return(e=r.call.apply(r,[this].concat(n))||this).state=a,e.resetErrorBoundary=function(){for(var r,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];null==e.props.onReset||(r=e.props).onReset.apply(r,n),e.reset()},e}t=r,(e=i).prototype=Object.create(t.prototype),e.prototype.constructor=e,o(e,t),i.getDerivedStateFromError=function(r){return{error:r}};var s=i.prototype;return s.reset=function(){this.setState(a)},s.componentDidCatch=function(r,e){var t,n;null==(t=(n=this.props).onError)||t.call(n,r,e)},s.componentDidUpdate=function(r,e){var t,n,o,a,i=this.state.error,s=this.props.resetKeys;null!==i&&null!==e.error&&(void 0===(o=r.resetKeys)&&(o=[]),void 0===(a=s)&&(a=[]),o.length!==a.length||o.some((function(r,e){return!Object.is(r,a[e])})))&&(null==(t=(n=this.props).onResetKeysChange)||t.call(n,r.resetKeys,s),this.reset())},s.render=function(){var r=this.state.error,e=this.props,t=e.fallbackRender,o=e.FallbackComponent,a=e.fallback;if(null!==r){var i={error:r,resetErrorBoundary:this.resetErrorBoundary};if(n.isValidElement(a))return a;if("function"==typeof t)return t(i);if(o)return n.createElement(o,i);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},i}(n.Component);exports.LexicalErrorBoundary=function({children:r,onError:t}){return e.jsx(i,{fallback:e.jsx("div",{style:{border:"1px solid #f00",color:"#f00",padding:"8px"},children:"An error was thrown."}),onError:t,children:r})};