UNPKG

laif-ds

Version:

Design System di Laif con componenti React basati su principi di Atomic Design

50 lines (49 loc) 2.29 kB
"use client"; import * as d from "react"; import { jsx as y } from "react/jsx-runtime"; function h(i, s) { return h = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(c, p) { return c.__proto__ = p, c; }, h(i, s); } var m = { error: null }, g = (function(i) { var s, c; function p() { for (var r, o = arguments.length, t = new Array(o), e = 0; e < o; e++) t[e] = arguments[e]; return (r = i.call.apply(i, [this].concat(t)) || this).state = m, r.resetErrorBoundary = function() { for (var n, a = arguments.length, f = new Array(a), l = 0; l < a; l++) f[l] = arguments[l]; r.props.onReset == null || (n = r.props).onReset.apply(n, f), r.reset(); }, r; } c = i, (s = p).prototype = Object.create(c.prototype), s.prototype.constructor = s, h(s, c), p.getDerivedStateFromError = function(r) { return { error: r }; }; var u = p.prototype; return u.reset = function() { this.setState(m); }, u.componentDidCatch = function(r, o) { var t, e; (t = (e = this.props).onError) == null || t.call(e, r, o); }, u.componentDidUpdate = function(r, o) { var t, e, n, a, f = this.state.error, l = this.props.resetKeys; f !== null && o.error !== null && ((n = r.resetKeys) === void 0 && (n = []), (a = l) === void 0 && (a = []), n.length !== a.length || n.some((function(b, v) { return !Object.is(b, a[v]); }))) && ((t = (e = this.props).onResetKeysChange) == null || t.call(e, r.resetKeys, l), this.reset()); }, u.render = function() { var r = this.state.error, o = this.props, t = o.fallbackRender, e = o.FallbackComponent, n = o.fallback; if (r !== null) { var a = { error: r, resetErrorBoundary: this.resetErrorBoundary }; if (d.isValidElement(n)) return n; if (typeof t == "function") return t(a); if (e) return d.createElement(e, a); throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop"); } return this.props.children; }, p; })(d.Component); function k({ children: i, onError: s }) { return y(g, { fallback: y("div", { style: { border: "1px solid #f00", color: "#f00", padding: "8px" }, children: "An error was thrown." }), onError: s, children: i }); } export { k as LexicalErrorBoundary };