@tramvai/react 1.84.2 → 1.90.1
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.
- package/lib/di/hoc.d.ts +3 -1
- package/lib/error/UniversalErrorBoundary.d.ts +2 -1
- package/lib/error/component.d.ts +2 -1
- package/lib/error/hoc.d.ts +3 -1
- package/lib/react.es.js +22 -28
- package/lib/react.js +27 -34
- package/package.json +2 -2
package/lib/di/hoc.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ProviderDeps, ProvideDepsIterator } from '@tinkoff/dippy';
|
|
3
|
-
export declare const withDi: <T extends ProviderDeps>(deps: T) => <C extends React.ComponentType<Partial<ProvideDepsIterator<T
|
|
3
|
+
export declare const withDi: <T extends ProviderDeps>(deps: T) => <C extends React.ComponentType<Partial<ProvideDepsIterator<T>> & {
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
}>>(WrappedComponent: C) => C;
|
|
@@ -17,6 +17,7 @@ export interface UniversalErrorBoundaryProps {
|
|
|
17
17
|
* @deprecated
|
|
18
18
|
*/
|
|
19
19
|
fallbackFromDi?: React.ReactElement | null;
|
|
20
|
+
children?: React.ReactNode;
|
|
20
21
|
}
|
|
21
22
|
interface State {
|
|
22
23
|
error: AnyError | null;
|
|
@@ -34,6 +35,6 @@ export declare class UniversalErrorBoundary extends Component<Props, State> {
|
|
|
34
35
|
error: AnyError;
|
|
35
36
|
};
|
|
36
37
|
componentDidCatch(error: AnyError, errorInfo: React.ErrorInfo): void;
|
|
37
|
-
render(): React.
|
|
38
|
+
render(): string | number | boolean | React.ReactFragment | JSX.Element | null | undefined;
|
|
38
39
|
}
|
|
39
40
|
export {};
|
package/lib/error/component.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ interface Props {
|
|
|
4
4
|
errorHandlers?: typeof ERROR_BOUNDARY_TOKEN | null;
|
|
5
5
|
fallbackComponent?: React.ReactElement | null;
|
|
6
6
|
fallbackComponentFromDi?: React.ReactElement | null;
|
|
7
|
+
children?: React.ReactNode;
|
|
7
8
|
}
|
|
8
9
|
interface State {
|
|
9
10
|
hasError: boolean;
|
|
@@ -18,6 +19,6 @@ export declare class ErrorBoundary extends Component<Props, State> {
|
|
|
18
19
|
hasError: boolean;
|
|
19
20
|
};
|
|
20
21
|
componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void;
|
|
21
|
-
render(): React.
|
|
22
|
+
render(): string | number | boolean | React.ReactFragment | JSX.Element | null | undefined;
|
|
22
23
|
}
|
|
23
24
|
export {};
|
package/lib/error/hoc.d.ts
CHANGED
|
@@ -4,4 +4,6 @@ import React from 'react';
|
|
|
4
4
|
*/
|
|
5
5
|
export declare const withError: ({ fallbackComponent, }?: {
|
|
6
6
|
fallbackComponent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
|
|
7
|
-
}) => <T extends React.ComponentType<
|
|
7
|
+
}) => <T extends React.ComponentType<{
|
|
8
|
+
children?: React.ReactNode;
|
|
9
|
+
}>>(WrappedComponent: T) => T;
|
package/lib/react.es.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createContext, useContext, useMemo, Component } from 'react';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
3
|
import hoistStatics from 'hoist-non-react-statics';
|
|
3
4
|
import mapObj from '@tinkoff/utils/object/map';
|
|
4
5
|
import { __decorate } from 'tslib';
|
|
@@ -39,35 +40,29 @@ const withDi = (deps) => (WrappedComponent) => {
|
|
|
39
40
|
function WrapperWithPropsFromDi(props) {
|
|
40
41
|
const depsInstance = useDi(deps);
|
|
41
42
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
42
|
-
return
|
|
43
|
+
return jsx(WrappedComponent, Object.assign({}, props, depsInstance), void 0);
|
|
43
44
|
}
|
|
44
45
|
return hoistStatics(WrapperWithPropsFromDi, WrappedComponent);
|
|
45
46
|
};
|
|
46
47
|
|
|
47
|
-
/* eslint-disable jsx-a11y/anchor-is-valid */
|
|
48
48
|
const FallbackError = () => {
|
|
49
|
-
return (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
} },
|
|
65
|
-
"\u041F\u043E\u043F\u0440\u043E\u0431\u0443\u0439\u0442\u0435",
|
|
66
|
-
' ',
|
|
67
|
-
React.createElement("a", { href: "", onClick: () => window.location.reload() }, "\u043F\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044C \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u0443"))));
|
|
49
|
+
return (jsxs("div", { children: [jsx("div", Object.assign({ style: {
|
|
50
|
+
textAlign: 'center',
|
|
51
|
+
marginBottom: 11,
|
|
52
|
+
paddingTop: 26,
|
|
53
|
+
fontSize: 30,
|
|
54
|
+
lineHeight: '36px',
|
|
55
|
+
fontWeight: 200,
|
|
56
|
+
} }, { children: "\u0412\u043E\u0437\u043D\u0438\u043A\u043B\u0430 \u043E\u0448\u0438\u0431\u043A\u0430 :(" }), void 0),
|
|
57
|
+
jsxs("div", Object.assign({ style: {
|
|
58
|
+
textAlign: 'center',
|
|
59
|
+
marginBottom: 17,
|
|
60
|
+
color: '#9299a2',
|
|
61
|
+
fontSize: 20,
|
|
62
|
+
lineHeight: '24px',
|
|
63
|
+
} }, { children: ["\u041F\u043E\u043F\u0440\u043E\u0431\u0443\u0439\u0442\u0435", ' ', jsx("a", Object.assign({ href: "", onClick: () => window.location.reload() }, { children: "\u043F\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044C \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u0443" }), void 0)] }), void 0)] }, void 0));
|
|
68
64
|
};
|
|
69
65
|
FallbackError.displayName = 'FallbackError';
|
|
70
|
-
/* eslint-enable jsx-a11y/anchor-is-valid */
|
|
71
66
|
|
|
72
67
|
class UniversalErrorBoundary extends Component {
|
|
73
68
|
constructor(props) {
|
|
@@ -102,12 +97,12 @@ class UniversalErrorBoundary extends Component {
|
|
|
102
97
|
return children;
|
|
103
98
|
}
|
|
104
99
|
if (Fallback) {
|
|
105
|
-
return
|
|
100
|
+
return jsx(Fallback, { url: url, error: error }, void 0);
|
|
106
101
|
}
|
|
107
102
|
if (fallbackFromDi) {
|
|
108
103
|
return fallbackFromDi;
|
|
109
104
|
}
|
|
110
|
-
return
|
|
105
|
+
return jsx(FallbackError, {}, void 0);
|
|
111
106
|
}
|
|
112
107
|
}
|
|
113
108
|
UniversalErrorBoundary.displayName = 'UniversalErrorBoundary';
|
|
@@ -148,7 +143,7 @@ let ErrorBoundary = class ErrorBoundary extends Component {
|
|
|
148
143
|
if (!hasError) {
|
|
149
144
|
return children;
|
|
150
145
|
}
|
|
151
|
-
return fallbackComponent || fallbackComponentFromDi ||
|
|
146
|
+
return fallbackComponent || fallbackComponentFromDi || jsx(FallbackError, {}, void 0);
|
|
152
147
|
}
|
|
153
148
|
};
|
|
154
149
|
ErrorBoundary.displayName = 'ErrorBoundary';
|
|
@@ -164,8 +159,7 @@ ErrorBoundary = __decorate([
|
|
|
164
159
|
*/
|
|
165
160
|
const withError = ({ fallbackComponent, } = {}) => (WrappedComponent) => {
|
|
166
161
|
function WrapperWithError(props) {
|
|
167
|
-
return (
|
|
168
|
-
React.createElement(WrappedComponent, Object.assign({}, props))));
|
|
162
|
+
return (jsx(ErrorBoundary, Object.assign({ fallbackComponent: fallbackComponent }, { children: jsx(WrappedComponent, Object.assign({}, props), void 0) }), void 0));
|
|
169
163
|
}
|
|
170
164
|
return hoistStatics(WrapperWithError, WrappedComponent);
|
|
171
165
|
};
|
package/lib/react.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
7
|
var hoistStatics = require('hoist-non-react-statics');
|
|
7
8
|
var mapObj = require('@tinkoff/utils/object/map');
|
|
8
9
|
var tslib = require('tslib');
|
|
@@ -11,15 +12,14 @@ var loadable = require('@loadable/component');
|
|
|
11
12
|
|
|
12
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
14
|
|
|
14
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
15
15
|
var hoistStatics__default = /*#__PURE__*/_interopDefaultLegacy(hoistStatics);
|
|
16
16
|
var mapObj__default = /*#__PURE__*/_interopDefaultLegacy(mapObj);
|
|
17
17
|
var loadable__default = /*#__PURE__*/_interopDefaultLegacy(loadable);
|
|
18
18
|
|
|
19
|
-
const DIContext =
|
|
19
|
+
const DIContext = react.createContext(null);
|
|
20
20
|
|
|
21
21
|
const useDiContainer = () => {
|
|
22
|
-
const di =
|
|
22
|
+
const di = react.useContext(DIContext);
|
|
23
23
|
if (!di) {
|
|
24
24
|
if (process.env.NODE_ENV !== 'production') {
|
|
25
25
|
throw new Error(`DI-контейнер не найден, убедитесь что в приложении используется 'DIContext.Provider' из '@tramvai/react'
|
|
@@ -38,7 +38,7 @@ const isTokenObject = (token) => {
|
|
|
38
38
|
};
|
|
39
39
|
function useDi(deps) {
|
|
40
40
|
const di = useDiContainer();
|
|
41
|
-
return
|
|
41
|
+
return react.useMemo(() => {
|
|
42
42
|
if (deps.toString() !== '[object Object]' || isTokenObject(deps)) {
|
|
43
43
|
return di.get(deps);
|
|
44
44
|
}
|
|
@@ -50,37 +50,31 @@ const withDi = (deps) => (WrappedComponent) => {
|
|
|
50
50
|
function WrapperWithPropsFromDi(props) {
|
|
51
51
|
const depsInstance = useDi(deps);
|
|
52
52
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
53
|
-
return
|
|
53
|
+
return jsxRuntime.jsx(WrappedComponent, Object.assign({}, props, depsInstance), void 0);
|
|
54
54
|
}
|
|
55
55
|
return hoistStatics__default["default"](WrapperWithPropsFromDi, WrappedComponent);
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
-
/* eslint-disable jsx-a11y/anchor-is-valid */
|
|
59
58
|
const FallbackError = () => {
|
|
60
|
-
return (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
} },
|
|
76
|
-
"\u041F\u043E\u043F\u0440\u043E\u0431\u0443\u0439\u0442\u0435",
|
|
77
|
-
' ',
|
|
78
|
-
React__default["default"].createElement("a", { href: "", onClick: () => window.location.reload() }, "\u043F\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044C \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u0443"))));
|
|
59
|
+
return (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", Object.assign({ style: {
|
|
60
|
+
textAlign: 'center',
|
|
61
|
+
marginBottom: 11,
|
|
62
|
+
paddingTop: 26,
|
|
63
|
+
fontSize: 30,
|
|
64
|
+
lineHeight: '36px',
|
|
65
|
+
fontWeight: 200,
|
|
66
|
+
} }, { children: "\u0412\u043E\u0437\u043D\u0438\u043A\u043B\u0430 \u043E\u0448\u0438\u0431\u043A\u0430 :(" }), void 0),
|
|
67
|
+
jsxRuntime.jsxs("div", Object.assign({ style: {
|
|
68
|
+
textAlign: 'center',
|
|
69
|
+
marginBottom: 17,
|
|
70
|
+
color: '#9299a2',
|
|
71
|
+
fontSize: 20,
|
|
72
|
+
lineHeight: '24px',
|
|
73
|
+
} }, { children: ["\u041F\u043E\u043F\u0440\u043E\u0431\u0443\u0439\u0442\u0435", ' ', jsxRuntime.jsx("a", Object.assign({ href: "", onClick: () => window.location.reload() }, { children: "\u043F\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044C \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u0443" }), void 0)] }), void 0)] }, void 0));
|
|
79
74
|
};
|
|
80
75
|
FallbackError.displayName = 'FallbackError';
|
|
81
|
-
/* eslint-enable jsx-a11y/anchor-is-valid */
|
|
82
76
|
|
|
83
|
-
class UniversalErrorBoundary extends
|
|
77
|
+
class UniversalErrorBoundary extends react.Component {
|
|
84
78
|
constructor(props) {
|
|
85
79
|
super(props);
|
|
86
80
|
this.state = {
|
|
@@ -113,12 +107,12 @@ class UniversalErrorBoundary extends React.Component {
|
|
|
113
107
|
return children;
|
|
114
108
|
}
|
|
115
109
|
if (Fallback) {
|
|
116
|
-
return
|
|
110
|
+
return jsxRuntime.jsx(Fallback, { url: url, error: error }, void 0);
|
|
117
111
|
}
|
|
118
112
|
if (fallbackFromDi) {
|
|
119
113
|
return fallbackFromDi;
|
|
120
114
|
}
|
|
121
|
-
return
|
|
115
|
+
return jsxRuntime.jsx(FallbackError, {}, void 0);
|
|
122
116
|
}
|
|
123
117
|
}
|
|
124
118
|
UniversalErrorBoundary.displayName = 'UniversalErrorBoundary';
|
|
@@ -135,7 +129,7 @@ const ERROR_BOUNDARY_FALLBACK_COMPONENT_TOKEN = dippy.createToken('errorBoundary
|
|
|
135
129
|
/**
|
|
136
130
|
* @deprecated Use UniversalErrorBoundary component
|
|
137
131
|
*/
|
|
138
|
-
exports.ErrorBoundary = class ErrorBoundary extends
|
|
132
|
+
exports.ErrorBoundary = class ErrorBoundary extends react.Component {
|
|
139
133
|
constructor(props) {
|
|
140
134
|
super(props);
|
|
141
135
|
this.state = {
|
|
@@ -159,7 +153,7 @@ exports.ErrorBoundary = class ErrorBoundary extends React.Component {
|
|
|
159
153
|
if (!hasError) {
|
|
160
154
|
return children;
|
|
161
155
|
}
|
|
162
|
-
return fallbackComponent || fallbackComponentFromDi ||
|
|
156
|
+
return fallbackComponent || fallbackComponentFromDi || jsxRuntime.jsx(FallbackError, {}, void 0);
|
|
163
157
|
}
|
|
164
158
|
};
|
|
165
159
|
exports.ErrorBoundary.displayName = 'ErrorBoundary';
|
|
@@ -175,8 +169,7 @@ exports.ErrorBoundary = tslib.__decorate([
|
|
|
175
169
|
*/
|
|
176
170
|
const withError = ({ fallbackComponent, } = {}) => (WrappedComponent) => {
|
|
177
171
|
function WrapperWithError(props) {
|
|
178
|
-
return (
|
|
179
|
-
React__default["default"].createElement(WrappedComponent, Object.assign({}, props))));
|
|
172
|
+
return (jsxRuntime.jsx(exports.ErrorBoundary, Object.assign({ fallbackComponent: fallbackComponent }, { children: jsxRuntime.jsx(WrappedComponent, Object.assign({}, props), void 0) }), void 0));
|
|
180
173
|
}
|
|
181
174
|
return hoistStatics__default["default"](WrapperWithError, WrappedComponent);
|
|
182
175
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.90.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/react.js",
|
|
6
6
|
"typings": "lib/react.d.ts",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@tinkoff/dippy": "0.7.39",
|
|
27
27
|
"@tinkoff/utils": "^2.1.2",
|
|
28
28
|
"@tinkoff/url": "0.7.37",
|
|
29
|
-
"@tramvai/core": "1.
|
|
29
|
+
"@tramvai/core": "1.90.1",
|
|
30
30
|
"react": ">=16.8.0",
|
|
31
31
|
"react-dom": ">=16.8.0",
|
|
32
32
|
"tslib": "^2.0.3"
|