@dartcom/ui-kit 3.8.4 → 3.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ import { CustomErrorBoundaryProps } from './types';
3
+ declare const CustomErrorBoundary: React.FC<React.PropsWithChildren<CustomErrorBoundaryProps>>;
4
+ export default CustomErrorBoundary;
5
+ //# sourceMappingURL=error-boundary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-boundary.d.ts","sourceRoot":"","sources":["../../../src/components/error-boundary/error-boundary.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAmBnD,QAAA,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CACjC,KAAK,CAAC,iBAAiB,CAAC,wBAAwB,CAAC,CAOlD,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { default as ErrorBoundary } from './error-boundary';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/error-boundary/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { ErrorBoundary } from 'react-error-boundary';
2
+ export type CustomErrorBoundaryProps = Pick<React.ComponentProps<typeof ErrorBoundary>, 'FallbackComponent'> & {};
3
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/error-boundary/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,MAAM,wBAAwB,GAAG,IAAI,CACzC,KAAK,CAAC,cAAc,CAAC,OAAO,aAAa,CAAC,EAC1C,mBAAmB,CACpB,GAAG,EAAE,CAAC"}
@@ -9,4 +9,5 @@ export * from './drag-list';
9
9
  export * from './layers';
10
10
  export * from './card';
11
11
  export * from './loader';
12
+ export * from './error-boundary';
12
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC"}
package/dist/index.cjs CHANGED
@@ -49407,6 +49407,116 @@ const Loader = ({ color = 'inherit' }) => {
49407
49407
  return jsxRuntime.jsx(CircularProgress, { color: color });
49408
49408
  };
49409
49409
 
49410
+ const ErrorBoundaryContext = React.createContext(null);
49411
+
49412
+ const initialState = {
49413
+ didCatch: false,
49414
+ error: null
49415
+ };
49416
+ class ErrorBoundary extends React.Component {
49417
+ constructor(props) {
49418
+ super(props);
49419
+ this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
49420
+ this.state = initialState;
49421
+ }
49422
+ static getDerivedStateFromError(error) {
49423
+ return {
49424
+ didCatch: true,
49425
+ error
49426
+ };
49427
+ }
49428
+ resetErrorBoundary() {
49429
+ const {
49430
+ error
49431
+ } = this.state;
49432
+ if (error !== null) {
49433
+ var _this$props$onReset, _this$props;
49434
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
49435
+ args[_key] = arguments[_key];
49436
+ }
49437
+ (_this$props$onReset = (_this$props = this.props).onReset) === null || _this$props$onReset === void 0 ? void 0 : _this$props$onReset.call(_this$props, {
49438
+ args,
49439
+ reason: "imperative-api"
49440
+ });
49441
+ this.setState(initialState);
49442
+ }
49443
+ }
49444
+ componentDidCatch(error, info) {
49445
+ var _this$props$onError, _this$props2;
49446
+ (_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error, info);
49447
+ }
49448
+ componentDidUpdate(prevProps, prevState) {
49449
+ const {
49450
+ didCatch
49451
+ } = this.state;
49452
+ const {
49453
+ resetKeys
49454
+ } = this.props;
49455
+
49456
+ // There's an edge case where if the thing that triggered the error happens to *also* be in the resetKeys array,
49457
+ // we'd end up resetting the error boundary immediately.
49458
+ // This would likely trigger a second error to be thrown.
49459
+ // So we make sure that we don't check the resetKeys on the first call of cDU after the error is set.
49460
+
49461
+ if (didCatch && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {
49462
+ var _this$props$onReset2, _this$props3;
49463
+ (_this$props$onReset2 = (_this$props3 = this.props).onReset) === null || _this$props$onReset2 === void 0 ? void 0 : _this$props$onReset2.call(_this$props3, {
49464
+ next: resetKeys,
49465
+ prev: prevProps.resetKeys,
49466
+ reason: "keys"
49467
+ });
49468
+ this.setState(initialState);
49469
+ }
49470
+ }
49471
+ render() {
49472
+ const {
49473
+ children,
49474
+ fallbackRender,
49475
+ FallbackComponent,
49476
+ fallback
49477
+ } = this.props;
49478
+ const {
49479
+ didCatch,
49480
+ error
49481
+ } = this.state;
49482
+ let childToRender = children;
49483
+ if (didCatch) {
49484
+ const props = {
49485
+ error,
49486
+ resetErrorBoundary: this.resetErrorBoundary
49487
+ };
49488
+ if (typeof fallbackRender === "function") {
49489
+ childToRender = fallbackRender(props);
49490
+ } else if (FallbackComponent) {
49491
+ childToRender = React.createElement(FallbackComponent, props);
49492
+ } else if (fallback !== undefined) {
49493
+ childToRender = fallback;
49494
+ } else {
49495
+ throw error;
49496
+ }
49497
+ }
49498
+ return React.createElement(ErrorBoundaryContext.Provider, {
49499
+ value: {
49500
+ didCatch,
49501
+ error,
49502
+ resetErrorBoundary: this.resetErrorBoundary
49503
+ }
49504
+ }, childToRender);
49505
+ }
49506
+ }
49507
+ function hasArrayChanged() {
49508
+ let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
49509
+ let b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
49510
+ return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
49511
+ }
49512
+
49513
+ const ErrorFallback = ({ error, resetErrorBoundary, }) => {
49514
+ return (jsxRuntime.jsxs(Box, { role: "alert", sx: { padding: '20px', background: '#fee' }, children: [jsxRuntime.jsx(Typography, { variant: "h2", children: "\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u044F" }), jsxRuntime.jsx(Typography, { variant: "body1", color: "error", children: error.message }), jsxRuntime.jsx(Button$1, { onClick: resetErrorBoundary, children: "\u041F\u043E\u043F\u0440\u043E\u0431\u043E\u0432\u0430\u0442\u044C \u0441\u043D\u043E\u0432\u0430" })] }));
49515
+ };
49516
+ const CustomErrorBoundary = ({ children, FallbackComponent = ErrorFallback }) => {
49517
+ return (jsxRuntime.jsx(ErrorBoundary, { FallbackComponent: FallbackComponent, children: children }));
49518
+ };
49519
+
49410
49520
  // src/subscribable.ts
49411
49521
  var Subscribable = class {
49412
49522
  constructor() {
@@ -63997,6 +64107,7 @@ exports.DartcomProviders = DartcomProviders;
63997
64107
  exports.DeleteButton = DeleteButton;
63998
64108
  exports.DragList = DragList;
63999
64109
  exports.EditButton = EditButton;
64110
+ exports.ErrorBoundary = CustomErrorBoundary;
64000
64111
  exports.Form = CustomForm;
64001
64112
  exports.GlobalConfig = GlobalConfig;
64002
64113
  exports.Input = CustomInput;