@skbkontur/react-ui-validations 1.5.6 → 1.7.0
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/CHANGELOG.md +38 -0
- package/README.md +5 -1
- package/index.d.ts +51 -58
- package/index.js +80 -53
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,44 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.7.0](https://github.com/skbkontur/retail-ui/tree/master/packages/react-ui-validations/compare/react-ui-validations@1.6.0...react-ui-validations@1.7.0) (2022-01-27)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **react-ui:** [StrictMode] give up findDomNode ([#2518](https://github.com/skbkontur/retail-ui/tree/master/packages/react-ui-validations/issues/2518)) ([8028cdd](https://github.com/skbkontur/retail-ui/tree/master/packages/react-ui-validations/commit/8028cdd3c2289fd48816bdaf92da6a28892f40a7))
|
|
12
|
+
* **react-ui:** [StrictMode] give up legacy context ([#2694](https://github.com/skbkontur/retail-ui/tree/master/packages/react-ui-validations/issues/2694)) ([d0253cc](https://github.com/skbkontur/retail-ui/tree/master/packages/react-ui-validations/commit/d0253ccc089764a317ccaa79aa00cc96fbb7aa0a))
|
|
13
|
+
* **react-ui:** [StrictMode] give up unsafe methods ([#2514](https://github.com/skbkontur/retail-ui/tree/master/packages/react-ui-validations/issues/2514)) ([6cc2201](https://github.com/skbkontur/retail-ui/tree/master/packages/react-ui-validations/commit/6cc2201f0e8f711441e6c63229b703c03d4b6953))
|
|
14
|
+
* **react-ui:** call original refs while replacing them ([#2736](https://github.com/skbkontur/retail-ui/tree/master/packages/react-ui-validations/issues/2736)) ([01ff2ab](https://github.com/skbkontur/retail-ui/tree/master/packages/react-ui-validations/commit/01ff2ab3243082c9347d20e844368ac775e54449))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* support React.StrictMode ([04a4bc9](https://github.com/skbkontur/retail-ui/tree/master/packages/react-ui-validations/commit/04a4bc9f2dd35fa98ea4d9526ddd775dd1017b71))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# [1.6.0](https://github.com/skbkontur/retail-ui/tree/master/packages/react-ui-validations/compare/react-ui-validations@1.5.7...react-ui-validations@1.6.0) (2021-12-27)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
* **react-ui-validations:** add independent validation ([#2632](https://github.com/skbkontur/retail-ui/tree/master/packages/react-ui-validations/issues/2632)) ([f1f2a9a](https://github.com/skbkontur/retail-ui/tree/master/packages/react-ui-validations/commit/f1f2a9adf61e2b9b096f9e1f4dbeb04c4046e582))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## [1.5.7](https://github.com/skbkontur/retail-ui/tree/master/packages/react-ui-validations/compare/react-ui-validations@1.5.6...react-ui-validations@1.5.7) (2021-10-25)
|
|
37
|
+
|
|
38
|
+
**Note:** Version bump only for package react-ui-validations
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
6
44
|
## [1.5.6](https://github.com/skbkontur/retail-ui/tree/master/packages/react-ui-validations/compare/react-ui-validations@1.5.5...react-ui-validations@1.5.6) (2021-10-06)
|
|
7
45
|
|
|
8
46
|
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
## Документация
|
|
8
8
|
|
|
9
|
-
- [Docs & Demos](
|
|
9
|
+
- [Docs & Demos](https://tech.skbkontur.ru/react-ui-validations/)
|
|
10
10
|
- [Validation guides](https://guides.kontur.ru/principles/validation/)
|
|
11
11
|
|
|
12
12
|
## Использование
|
|
@@ -39,3 +39,7 @@ export default class DataEditor extends React.Component {
|
|
|
39
39
|
```shell
|
|
40
40
|
yarn start:docs
|
|
41
41
|
```
|
|
42
|
+
|
|
43
|
+
## StrictMode
|
|
44
|
+
|
|
45
|
+
Библиотека поддерживает работу в React.StrictMode начиная с версии `1.7.0`. [Подробнее](https://github.com/skbkontur/retail-ui/blob/master/packages/react-ui/README.md#strictmode).
|
package/index.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
// Generated by dts-bundle v0.7.3
|
|
2
2
|
// Dependencies for this module:
|
|
3
3
|
// ../../react
|
|
4
|
-
// ../../prop-types
|
|
5
4
|
|
|
6
5
|
declare module '@skbkontur/react-ui-validations' {
|
|
7
6
|
import { text, tooltip } from '@skbkontur/react-ui-validations/src/ErrorRenderer';
|
|
8
7
|
import { ValidationContainer, ValidationContainerProps } from '@skbkontur/react-ui-validations/src/ValidationContainer';
|
|
9
|
-
import { ValidationContext, ValidationContextProps } from '@skbkontur/react-ui-validations/src/ValidationContext';
|
|
10
8
|
import { TooltipPosition, ValidationTooltip, ValidationTooltipProps } from '@skbkontur/react-ui-validations/src/ValidationTooltip';
|
|
11
9
|
import { RenderErrorMessage, Validation, ValidationBehaviour } from '@skbkontur/react-ui-validations/src/ValidationWrapperInternal';
|
|
12
10
|
import { ValidationWrapper, ValidationInfo, ValidationWrapperProps } from '@skbkontur/react-ui-validations/src/ValidationWrapper';
|
|
13
|
-
|
|
11
|
+
import { ValidationContext, ValidationContextType, ValidationContextWrapper, ValidationContextWrapperProps } from '@skbkontur/react-ui-validations/src/ValidationContextWrapper';
|
|
12
|
+
export { ValidationContainer, ValidationContainerProps, ValidationContext, ValidationContextType, ValidationContextWrapper, ValidationContextWrapperProps, ValidationWrapper as ValidationWrapperV1, ValidationWrapperProps as ValidationWrapperV1Props, RenderErrorMessage, ValidationBehaviour, Validation, ValidationWrapper, ValidationWrapperProps, ValidationInfo, ValidationTooltip, ValidationTooltipProps, TooltipPosition, tooltip, text, };
|
|
14
13
|
export * from '@skbkontur/react-ui-validations/src/Validations';
|
|
15
14
|
}
|
|
16
15
|
|
|
@@ -48,50 +47,6 @@ declare module '@skbkontur/react-ui-validations/src/ValidationContainer' {
|
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
declare module '@skbkontur/react-ui-validations/src/ValidationContext' {
|
|
52
|
-
import * as PropTypes from 'prop-types';
|
|
53
|
-
import React from 'react';
|
|
54
|
-
import { ValidationWrapperInternal } from '@skbkontur/react-ui-validations/src/ValidationWrapperInternal';
|
|
55
|
-
import { ScrollOffset } from '@skbkontur/react-ui-validations/src/ValidationContainer';
|
|
56
|
-
export interface ValidationContextSettings {
|
|
57
|
-
scrollOffset: ScrollOffset;
|
|
58
|
-
disableSmoothScroll: boolean;
|
|
59
|
-
}
|
|
60
|
-
export interface IValidationContext {
|
|
61
|
-
register(wrapper: ValidationWrapperInternal): void;
|
|
62
|
-
unregister(wrapper: ValidationWrapperInternal): void;
|
|
63
|
-
instanceProcessBlur(wrapper: ValidationWrapperInternal): void;
|
|
64
|
-
onValidationUpdated(wrapper: ValidationWrapperInternal, isValid: boolean): void;
|
|
65
|
-
getSettings(): ValidationContextSettings;
|
|
66
|
-
isAnyWrapperInChangingMode(): boolean;
|
|
67
|
-
}
|
|
68
|
-
export interface ValidationContextProps {
|
|
69
|
-
children?: React.ReactNode;
|
|
70
|
-
onValidationUpdated?: (isValid?: boolean) => void;
|
|
71
|
-
scrollOffset?: number | ScrollOffset;
|
|
72
|
-
disableSmoothScroll: boolean;
|
|
73
|
-
}
|
|
74
|
-
export class ValidationContext extends React.Component<ValidationContextProps> implements IValidationContext {
|
|
75
|
-
static childContextTypes: {
|
|
76
|
-
validationContext: PropTypes.Requireable<any>;
|
|
77
|
-
};
|
|
78
|
-
childWrappers: ValidationWrapperInternal[];
|
|
79
|
-
getChildContext(): {
|
|
80
|
-
validationContext: IValidationContext;
|
|
81
|
-
};
|
|
82
|
-
getSettings(): ValidationContextSettings;
|
|
83
|
-
register(wrapper: ValidationWrapperInternal): void;
|
|
84
|
-
unregister(wrapper: ValidationWrapperInternal): void;
|
|
85
|
-
instanceProcessBlur(instance: ValidationWrapperInternal): void;
|
|
86
|
-
onValidationUpdated(wrapper: ValidationWrapperInternal, isValid?: boolean): void;
|
|
87
|
-
isAnyWrapperInChangingMode(): boolean;
|
|
88
|
-
onValidationRemoved(): void;
|
|
89
|
-
getChildWrappersSortedByPosition(): ValidationWrapperInternal[];
|
|
90
|
-
validate(withoutFocus: boolean): Promise<boolean>;
|
|
91
|
-
render(): JSX.Element;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
50
|
declare module '@skbkontur/react-ui-validations/src/ValidationTooltip' {
|
|
96
51
|
import React from 'react';
|
|
97
52
|
export type TooltipPosition = 'top left' | 'top center' | 'top right' | 'bottom left' | 'bottom center' | 'bottom right' | 'left top' | 'left middle' | 'left bottom' | 'right top' | 'right middle' | 'right bottom';
|
|
@@ -107,16 +62,16 @@ declare module '@skbkontur/react-ui-validations/src/ValidationTooltip' {
|
|
|
107
62
|
}
|
|
108
63
|
|
|
109
64
|
declare module '@skbkontur/react-ui-validations/src/ValidationWrapperInternal' {
|
|
110
|
-
import * as PropTypes from 'prop-types';
|
|
111
65
|
import React from 'react';
|
|
112
66
|
import { Nullable } from '@skbkontur/react-ui-validations/typings/Types';
|
|
113
|
-
import {
|
|
67
|
+
import { ValidationContextType } from '@skbkontur/react-ui-validations/src/ValidationContextWrapper';
|
|
114
68
|
export type ValidationBehaviour = 'immediate' | 'lostfocus' | 'submit';
|
|
115
69
|
export type ValidationLevel = 'error' | 'warning';
|
|
116
70
|
export interface Validation {
|
|
117
71
|
level: ValidationLevel;
|
|
118
72
|
behaviour: ValidationBehaviour;
|
|
119
73
|
message: React.ReactNode;
|
|
74
|
+
independent: boolean;
|
|
120
75
|
}
|
|
121
76
|
export type RenderErrorMessage = (control: React.ReactElement<any>, hasError: boolean, validation: Nullable<Validation>) => React.ReactElement<any>;
|
|
122
77
|
export interface ValidationWrapperInternalProps {
|
|
@@ -132,24 +87,21 @@ declare module '@skbkontur/react-ui-validations/src/ValidationWrapperInternal' {
|
|
|
132
87
|
y: number;
|
|
133
88
|
}
|
|
134
89
|
export class ValidationWrapperInternal extends React.Component<ValidationWrapperInternalProps, ValidationWrapperInternalState> {
|
|
135
|
-
static contextTypes: {
|
|
136
|
-
validationContext: PropTypes.Requireable<any>;
|
|
137
|
-
};
|
|
138
90
|
state: ValidationWrapperInternalState;
|
|
139
|
-
context: {
|
|
140
|
-
validationContext: IValidationContext;
|
|
141
|
-
};
|
|
142
91
|
isChanging: boolean;
|
|
143
|
-
|
|
92
|
+
static contextType: React.Context<ValidationContextType>;
|
|
93
|
+
context: ValidationContextType;
|
|
144
94
|
componentDidMount(): void;
|
|
145
95
|
componentWillUnmount(): void;
|
|
146
|
-
|
|
96
|
+
componentDidUpdate(): void;
|
|
147
97
|
focus(): Promise<void>;
|
|
148
98
|
render(): React.ReactElement<any, string | ((props: any) => React.ReactElement<any, any> | null) | (new (props: any) => React.Component<any, any, any>)>;
|
|
99
|
+
getRootNode: () => Nullable<HTMLElement>;
|
|
149
100
|
getControlPosition(): Nullable<Point>;
|
|
150
101
|
processBlur(): Promise<void>;
|
|
151
102
|
processSubmit(): Promise<void>;
|
|
152
103
|
hasError(): boolean;
|
|
104
|
+
isIndependent(): boolean;
|
|
153
105
|
}
|
|
154
106
|
export {};
|
|
155
107
|
}
|
|
@@ -162,6 +114,7 @@ declare module '@skbkontur/react-ui-validations/src/ValidationWrapper' {
|
|
|
162
114
|
type?: Nullable<ValidationBehaviour>;
|
|
163
115
|
level?: Nullable<ValidationLevel>;
|
|
164
116
|
message: React.ReactNode;
|
|
117
|
+
independent?: boolean;
|
|
165
118
|
}
|
|
166
119
|
export interface ValidationWrapperProps {
|
|
167
120
|
children?: React.ReactElement<any>;
|
|
@@ -174,6 +127,44 @@ declare module '@skbkontur/react-ui-validations/src/ValidationWrapper' {
|
|
|
174
127
|
}
|
|
175
128
|
}
|
|
176
129
|
|
|
130
|
+
declare module '@skbkontur/react-ui-validations/src/ValidationContextWrapper' {
|
|
131
|
+
import React from 'react';
|
|
132
|
+
import { ValidationWrapperInternal } from '@skbkontur/react-ui-validations/src/ValidationWrapperInternal';
|
|
133
|
+
import { ScrollOffset } from '@skbkontur/react-ui-validations/src/ValidationContainer';
|
|
134
|
+
export interface ValidationContextSettings {
|
|
135
|
+
scrollOffset: ScrollOffset;
|
|
136
|
+
disableSmoothScroll: boolean;
|
|
137
|
+
}
|
|
138
|
+
export interface ValidationContextWrapperProps {
|
|
139
|
+
children?: React.ReactNode;
|
|
140
|
+
onValidationUpdated?: (isValid?: boolean) => void;
|
|
141
|
+
scrollOffset?: number | ScrollOffset;
|
|
142
|
+
disableSmoothScroll: boolean;
|
|
143
|
+
}
|
|
144
|
+
export interface ValidationContextType {
|
|
145
|
+
register: (wrapper: ValidationWrapperInternal) => void;
|
|
146
|
+
unregister: (wrapper: ValidationWrapperInternal) => void;
|
|
147
|
+
instanceProcessBlur: (wrapper: ValidationWrapperInternal) => void;
|
|
148
|
+
onValidationUpdated: (wrapper: ValidationWrapperInternal, isValid: boolean) => void;
|
|
149
|
+
getSettings: () => ValidationContextSettings;
|
|
150
|
+
isAnyWrapperInChangingMode: () => boolean;
|
|
151
|
+
}
|
|
152
|
+
export const ValidationContext: React.Context<ValidationContextType>;
|
|
153
|
+
export class ValidationContextWrapper extends React.Component<ValidationContextWrapperProps> {
|
|
154
|
+
childWrappers: ValidationWrapperInternal[];
|
|
155
|
+
getSettings(): ValidationContextSettings;
|
|
156
|
+
register(wrapper: ValidationWrapperInternal): void;
|
|
157
|
+
unregister(wrapper: ValidationWrapperInternal): void;
|
|
158
|
+
instanceProcessBlur(instance: ValidationWrapperInternal): void;
|
|
159
|
+
onValidationUpdated(wrapper: ValidationWrapperInternal, isValid?: boolean): void;
|
|
160
|
+
isAnyWrapperInChangingMode(): boolean;
|
|
161
|
+
onValidationRemoved(): void;
|
|
162
|
+
getChildWrappersSortedByPosition(): ValidationWrapperInternal[];
|
|
163
|
+
validate(withoutFocus: boolean): Promise<boolean>;
|
|
164
|
+
render(): JSX.Element;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
177
168
|
declare module '@skbkontur/react-ui-validations/src/Validations' {
|
|
178
169
|
import { ValidationBuilder } from '@skbkontur/react-ui-validations/src/Validations/ValidationBuilder';
|
|
179
170
|
import { RootValidationRule, ValidationRule, ItemValidationRule } from '@skbkontur/react-ui-validations/src/Validations/Types';
|
|
@@ -192,6 +183,7 @@ declare module '@skbkontur/react-ui-validations/typings/Types' {
|
|
|
192
183
|
declare module '@skbkontur/react-ui-validations/src/Validations/ValidationBuilder' {
|
|
193
184
|
import React from 'react';
|
|
194
185
|
import { ValidationBehaviour, ValidationLevel } from '@skbkontur/react-ui-validations/src/ValidationWrapperInternal';
|
|
186
|
+
import { ValidationInfo } from '@skbkontur/react-ui-validations/src/ValidationWrapper';
|
|
195
187
|
import { LambdaPath, PathTokensCache } from '@skbkontur/react-ui-validations/src/Validations/PathHelper';
|
|
196
188
|
import { ValidationWriter } from '@skbkontur/react-ui-validations/src/Validations/ValidationWriter';
|
|
197
189
|
import { ItemValidationRule, ValidationRule } from '@skbkontur/react-ui-validations/src/Validations/Types';
|
|
@@ -199,7 +191,8 @@ declare module '@skbkontur/react-ui-validations/src/Validations/ValidationBuilde
|
|
|
199
191
|
constructor(writer: ValidationWriter<TRoot>, tokens: PathTokensCache, path: string[], data: T);
|
|
200
192
|
prop<TChild>(lambdaPath: LambdaPath<T, TChild>, rule: ValidationRule<TRoot, TChild>): void;
|
|
201
193
|
array<TChild>(lambdaPath: LambdaPath<T, TChild[]>, rule: ItemValidationRule<TRoot, TChild>): void;
|
|
202
|
-
invalid(isInvalid: (value: T) => boolean,
|
|
194
|
+
invalid(isInvalid: (value: T) => boolean, validationInfo: ValidationInfo): void;
|
|
195
|
+
invalid(isInvalid: (value: T) => boolean, message: React.ReactNode, type?: ValidationBehaviour, level?: ValidationLevel, independent?: boolean): void;
|
|
203
196
|
}
|
|
204
197
|
}
|
|
205
198
|
|
package/index.js
CHANGED
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var React = require('react');
|
|
6
|
-
var PropTypes = require('prop-types');
|
|
7
|
-
var ReactDom = require('react-dom');
|
|
8
6
|
var warning = require('warning');
|
|
9
7
|
|
|
10
8
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -192,19 +190,26 @@ var isReactUITestEnv = Boolean(REACT_UI_TEST) || // for cases when NODE_ENV is n
|
|
|
192
190
|
var isTestEnv = NODE_ENV === 'test' || isReactUITestEnv;
|
|
193
191
|
var isBrowser = typeof window !== 'undefined';
|
|
194
192
|
|
|
195
|
-
var ValidationContext =
|
|
196
|
-
|
|
197
|
-
function
|
|
193
|
+
var ValidationContext = React__default['default'].createContext({
|
|
194
|
+
register: function () { return undefined; },
|
|
195
|
+
unregister: function () { return undefined; },
|
|
196
|
+
instanceProcessBlur: function () { return undefined; },
|
|
197
|
+
onValidationUpdated: function () { return undefined; },
|
|
198
|
+
getSettings: function () { return ({
|
|
199
|
+
scrollOffset: {},
|
|
200
|
+
disableSmoothScroll: false,
|
|
201
|
+
}); },
|
|
202
|
+
isAnyWrapperInChangingMode: function () { return false; },
|
|
203
|
+
});
|
|
204
|
+
ValidationContext.displayName = 'ValidationContext';
|
|
205
|
+
var ValidationContextWrapper = /** @class */ (function (_super) {
|
|
206
|
+
__extends(ValidationContextWrapper, _super);
|
|
207
|
+
function ValidationContextWrapper() {
|
|
198
208
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
199
209
|
_this.childWrappers = [];
|
|
200
210
|
return _this;
|
|
201
211
|
}
|
|
202
|
-
|
|
203
|
-
return {
|
|
204
|
-
validationContext: this,
|
|
205
|
-
};
|
|
206
|
-
};
|
|
207
|
-
ValidationContext.prototype.getSettings = function () {
|
|
212
|
+
ValidationContextWrapper.prototype.getSettings = function () {
|
|
208
213
|
var scrollOffset = {};
|
|
209
214
|
if (typeof this.props.scrollOffset === 'number') {
|
|
210
215
|
scrollOffset = { top: this.props.scrollOffset };
|
|
@@ -221,20 +226,20 @@ var ValidationContext = /** @class */ (function (_super) {
|
|
|
221
226
|
disableSmoothScroll: this.props.disableSmoothScroll,
|
|
222
227
|
};
|
|
223
228
|
};
|
|
224
|
-
|
|
229
|
+
ValidationContextWrapper.prototype.register = function (wrapper) {
|
|
225
230
|
this.childWrappers.push(wrapper);
|
|
226
231
|
};
|
|
227
|
-
|
|
232
|
+
ValidationContextWrapper.prototype.unregister = function (wrapper) {
|
|
228
233
|
this.childWrappers.splice(this.childWrappers.indexOf(wrapper), 1);
|
|
229
234
|
this.onValidationRemoved();
|
|
230
235
|
};
|
|
231
|
-
|
|
232
|
-
for (var _i = 0, _a = this.childWrappers.filter(function (x) { return x !== instance; }); _i < _a.length; _i++) {
|
|
236
|
+
ValidationContextWrapper.prototype.instanceProcessBlur = function (instance) {
|
|
237
|
+
for (var _i = 0, _a = this.childWrappers.filter(function (x) { return x !== instance && !x.isIndependent(); }); _i < _a.length; _i++) {
|
|
233
238
|
var wrapper = _a[_i];
|
|
234
239
|
wrapper.processBlur();
|
|
235
240
|
}
|
|
236
241
|
};
|
|
237
|
-
|
|
242
|
+
ValidationContextWrapper.prototype.onValidationUpdated = function (wrapper, isValid) {
|
|
238
243
|
var onValidationUpdated = this.props.onValidationUpdated;
|
|
239
244
|
if (onValidationUpdated) {
|
|
240
245
|
var isValidResult = !this.childWrappers.find(function (x) {
|
|
@@ -246,17 +251,17 @@ var ValidationContext = /** @class */ (function (_super) {
|
|
|
246
251
|
onValidationUpdated(isValidResult);
|
|
247
252
|
}
|
|
248
253
|
};
|
|
249
|
-
|
|
254
|
+
ValidationContextWrapper.prototype.isAnyWrapperInChangingMode = function () {
|
|
250
255
|
return this.childWrappers.some(function (x) { return x.isChanging; });
|
|
251
256
|
};
|
|
252
|
-
|
|
257
|
+
ValidationContextWrapper.prototype.onValidationRemoved = function () {
|
|
253
258
|
var onValidationUpdated = this.props.onValidationUpdated;
|
|
254
259
|
if (onValidationUpdated) {
|
|
255
260
|
var isValidResult = !this.childWrappers.find(function (x) { return x.hasError(); });
|
|
256
261
|
onValidationUpdated(isValidResult);
|
|
257
262
|
}
|
|
258
263
|
};
|
|
259
|
-
|
|
264
|
+
ValidationContextWrapper.prototype.getChildWrappersSortedByPosition = function () {
|
|
260
265
|
var wrappersWithPosition = __spreadArrays(this.childWrappers).map(function (x) { return ({
|
|
261
266
|
target: x,
|
|
262
267
|
position: x.getControlPosition(),
|
|
@@ -280,7 +285,7 @@ var ValidationContext = /** @class */ (function (_super) {
|
|
|
280
285
|
});
|
|
281
286
|
return wrappersWithPosition.map(function (x) { return x.target; });
|
|
282
287
|
};
|
|
283
|
-
|
|
288
|
+
ValidationContextWrapper.prototype.validate = function (withoutFocus) {
|
|
284
289
|
return __awaiter(this, void 0, void 0, function () {
|
|
285
290
|
var firstInvalid;
|
|
286
291
|
return __generator(this, function (_a) {
|
|
@@ -302,13 +307,11 @@ var ValidationContext = /** @class */ (function (_super) {
|
|
|
302
307
|
});
|
|
303
308
|
});
|
|
304
309
|
};
|
|
305
|
-
|
|
306
|
-
return React__default['default'].createElement(
|
|
310
|
+
ValidationContextWrapper.prototype.render = function () {
|
|
311
|
+
return (React__default['default'].createElement(ValidationContext.Provider, { value: this },
|
|
312
|
+
React__default['default'].createElement("span", null, this.props.children)));
|
|
307
313
|
};
|
|
308
|
-
|
|
309
|
-
validationContext: PropTypes.any,
|
|
310
|
-
};
|
|
311
|
-
return ValidationContext;
|
|
314
|
+
return ValidationContextWrapper;
|
|
312
315
|
}(React__default['default'].Component));
|
|
313
316
|
|
|
314
317
|
var ValidationContainer = /** @class */ (function (_super) {
|
|
@@ -344,7 +347,7 @@ var ValidationContainer = /** @class */ (function (_super) {
|
|
|
344
347
|
return this.childContext.validate(withoutFocus);
|
|
345
348
|
};
|
|
346
349
|
ValidationContainer.prototype.render = function () {
|
|
347
|
-
return (React__default['default'].createElement(
|
|
350
|
+
return (React__default['default'].createElement(ValidationContextWrapper, { ref: this.refChildContext, scrollOffset: this.props.scrollOffset, disableSmoothScroll: this.props.disableSmoothScroll, onValidationUpdated: this.props.onValidationUpdated }, this.props.children));
|
|
348
351
|
};
|
|
349
352
|
ValidationContainer.__KONTUR_REACT_UI__ = 'ValidationContainer';
|
|
350
353
|
ValidationContainer.defaultProps = {
|
|
@@ -523,11 +526,19 @@ function getType(validation) {
|
|
|
523
526
|
function getLevel(validation) {
|
|
524
527
|
return validation ? validation.level : null;
|
|
525
528
|
}
|
|
529
|
+
function getIndependent(validation) {
|
|
530
|
+
return validation ? validation.independent : null;
|
|
531
|
+
}
|
|
526
532
|
function isEqual(a, b) {
|
|
527
533
|
if (a === b) {
|
|
528
534
|
return true;
|
|
529
535
|
}
|
|
530
|
-
return !!a &&
|
|
536
|
+
return (!!a &&
|
|
537
|
+
!!b &&
|
|
538
|
+
a.behaviour === b.behaviour &&
|
|
539
|
+
a.level === a.level &&
|
|
540
|
+
a.message === b.message &&
|
|
541
|
+
a.independent === b.independent);
|
|
531
542
|
}
|
|
532
543
|
|
|
533
544
|
if (isBrowser && typeof HTMLElement === 'undefined') {
|
|
@@ -542,25 +553,28 @@ var ValidationWrapperInternal = /** @class */ (function (_super) {
|
|
|
542
553
|
validation: null,
|
|
543
554
|
};
|
|
544
555
|
_this.isChanging = false;
|
|
556
|
+
_this.context = _this.context;
|
|
557
|
+
_this.setRootNode = function (element) {
|
|
558
|
+
_this.rootNode = element;
|
|
559
|
+
};
|
|
560
|
+
_this.getRootNode = function () {
|
|
561
|
+
return _this.rootNode;
|
|
562
|
+
};
|
|
545
563
|
return _this;
|
|
546
564
|
}
|
|
547
|
-
ValidationWrapperInternal.prototype.UNSAFE_componentWillMount = function () {
|
|
548
|
-
this.applyValidation(this.props.validation);
|
|
549
|
-
};
|
|
550
565
|
ValidationWrapperInternal.prototype.componentDidMount = function () {
|
|
551
|
-
warning__default['default'](this.context
|
|
552
|
-
'
|
|
553
|
-
if (this.context
|
|
554
|
-
this.context.
|
|
566
|
+
warning__default['default'](this.context, 'ValidationWrapper should appears as child of ValidationContainer.\n' +
|
|
567
|
+
'https://tech.skbkontur.ru/react-ui-validations/#/getting-started');
|
|
568
|
+
if (this.context) {
|
|
569
|
+
this.context.register(this);
|
|
555
570
|
}
|
|
571
|
+
this.applyValidation(this.props.validation);
|
|
556
572
|
};
|
|
557
573
|
ValidationWrapperInternal.prototype.componentWillUnmount = function () {
|
|
558
|
-
|
|
559
|
-
this.context.validationContext.unregister(this);
|
|
560
|
-
}
|
|
574
|
+
this.context.unregister(this);
|
|
561
575
|
};
|
|
562
|
-
ValidationWrapperInternal.prototype.
|
|
563
|
-
this.applyValidation(
|
|
576
|
+
ValidationWrapperInternal.prototype.componentDidUpdate = function () {
|
|
577
|
+
this.applyValidation(this.props.validation);
|
|
564
578
|
};
|
|
565
579
|
ValidationWrapperInternal.prototype.focus = function () {
|
|
566
580
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -568,9 +582,9 @@ var ValidationWrapperInternal = /** @class */ (function (_super) {
|
|
|
568
582
|
return __generator(this, function (_b) {
|
|
569
583
|
switch (_b.label) {
|
|
570
584
|
case 0:
|
|
571
|
-
htmlElement =
|
|
585
|
+
htmlElement = this.getRootNode();
|
|
572
586
|
if (!(htmlElement instanceof HTMLElement)) return [3 /*break*/, 3];
|
|
573
|
-
_a = this.context.
|
|
587
|
+
_a = this.context.getSettings(), disableSmoothScroll = _a.disableSmoothScroll, scrollOffset = _a.scrollOffset;
|
|
574
588
|
if (!!disableSmoothScroll) return [3 /*break*/, 2];
|
|
575
589
|
return [4 /*yield*/, smoothScrollIntoView(htmlElement, scrollOffset)];
|
|
576
590
|
case 1:
|
|
@@ -657,10 +671,10 @@ var ValidationWrapperInternal = /** @class */ (function (_super) {
|
|
|
657
671
|
},
|
|
658
672
|
});
|
|
659
673
|
}
|
|
660
|
-
return this.props.errorMessage(React__default['default'].createElement("span",
|
|
674
|
+
return this.props.errorMessage(React__default['default'].createElement("span", { ref: this.setRootNode }, clonedChild), !!validation, validation);
|
|
661
675
|
};
|
|
662
676
|
ValidationWrapperInternal.prototype.getControlPosition = function () {
|
|
663
|
-
var htmlElement =
|
|
677
|
+
var htmlElement = this.getRootNode();
|
|
664
678
|
if (htmlElement instanceof HTMLElement) {
|
|
665
679
|
var rect = htmlElement.getBoundingClientRect();
|
|
666
680
|
return { x: rect.top, y: rect.left };
|
|
@@ -684,11 +698,16 @@ var ValidationWrapperInternal = /** @class */ (function (_super) {
|
|
|
684
698
|
ValidationWrapperInternal.prototype.hasError = function () {
|
|
685
699
|
return getLevel(this.state.validation) === 'error';
|
|
686
700
|
};
|
|
701
|
+
ValidationWrapperInternal.prototype.isIndependent = function () {
|
|
702
|
+
return getIndependent(this.state.validation || this.props.validation) === true;
|
|
703
|
+
};
|
|
687
704
|
ValidationWrapperInternal.prototype.handleBlur = function () {
|
|
688
705
|
var _this = this;
|
|
689
706
|
setTimeout(function () {
|
|
690
707
|
_this.processBlur();
|
|
691
|
-
_this.
|
|
708
|
+
if (!_this.isIndependent()) {
|
|
709
|
+
_this.context.instanceProcessBlur(_this);
|
|
710
|
+
}
|
|
692
711
|
_this.setState({});
|
|
693
712
|
});
|
|
694
713
|
};
|
|
@@ -705,7 +724,7 @@ var ValidationWrapperInternal = /** @class */ (function (_super) {
|
|
|
705
724
|
return new Promise(function (resolve) {
|
|
706
725
|
_this.setState({ validation: validation }, resolve);
|
|
707
726
|
if (Boolean(current) !== Boolean(validation)) {
|
|
708
|
-
_this.context.
|
|
727
|
+
_this.context.onValidationUpdated(_this, !validation);
|
|
709
728
|
}
|
|
710
729
|
});
|
|
711
730
|
};
|
|
@@ -722,12 +741,10 @@ var ValidationWrapperInternal = /** @class */ (function (_super) {
|
|
|
722
741
|
if (isEqual(visible, actual)) {
|
|
723
742
|
return visible;
|
|
724
743
|
}
|
|
725
|
-
var changing = this.context.
|
|
744
|
+
var changing = this.context.isAnyWrapperInChangingMode();
|
|
726
745
|
return getVisibleValidation(visible, actual, changing);
|
|
727
746
|
};
|
|
728
|
-
ValidationWrapperInternal.
|
|
729
|
-
validationContext: PropTypes.any,
|
|
730
|
-
};
|
|
747
|
+
ValidationWrapperInternal.contextType = ValidationContext;
|
|
731
748
|
return ValidationWrapperInternal;
|
|
732
749
|
}(React__default['default'].Component));
|
|
733
750
|
|
|
@@ -743,6 +760,7 @@ var ValidationWrapper = /** @class */ (function (_super) {
|
|
|
743
760
|
level: validationInfo.level || 'error',
|
|
744
761
|
behaviour: validationInfo.type || 'lostfocus',
|
|
745
762
|
message: validationInfo.message,
|
|
763
|
+
independent: validationInfo.independent || false,
|
|
746
764
|
}
|
|
747
765
|
: null;
|
|
748
766
|
return (React__default['default'].createElement(ValidationWrapperInternal, { errorMessage: renderMessage || tooltip('right top'), validation: validation }, children));
|
|
@@ -778,7 +796,7 @@ var ValidationBuilder = /** @class */ (function () {
|
|
|
778
796
|
rule(builder, builder.data, i, array);
|
|
779
797
|
}
|
|
780
798
|
};
|
|
781
|
-
ValidationBuilder.prototype.invalid = function (isInvalid,
|
|
799
|
+
ValidationBuilder.prototype.invalid = function (isInvalid, messageOrValidationInfo, type, level, independent) {
|
|
782
800
|
var validationWriter = this.writer.getNode(this.path);
|
|
783
801
|
if (validationWriter.isValidated()) {
|
|
784
802
|
return;
|
|
@@ -787,7 +805,12 @@ var ValidationBuilder = /** @class */ (function () {
|
|
|
787
805
|
if (!invalid) {
|
|
788
806
|
return;
|
|
789
807
|
}
|
|
790
|
-
|
|
808
|
+
if (isValidationInfo(messageOrValidationInfo)) {
|
|
809
|
+
validationWriter.set(messageOrValidationInfo);
|
|
810
|
+
}
|
|
811
|
+
else {
|
|
812
|
+
validationWriter.set({ message: messageOrValidationInfo, type: type, level: level, independent: independent });
|
|
813
|
+
}
|
|
791
814
|
};
|
|
792
815
|
ValidationBuilder.prototype.getPathInfo = function (lambdaPath) {
|
|
793
816
|
var path = this.tokens.getOrAdd(lambdaPath);
|
|
@@ -802,7 +825,10 @@ var ValidationBuilder = /** @class */ (function () {
|
|
|
802
825
|
return { data: data, path: __spreadArrays(this.path, path) };
|
|
803
826
|
};
|
|
804
827
|
return ValidationBuilder;
|
|
805
|
-
}());
|
|
828
|
+
}());
|
|
829
|
+
var isValidationInfo = function (argument) {
|
|
830
|
+
return typeof argument === 'object' && Object.prototype.hasOwnProperty.call(argument, 'message');
|
|
831
|
+
};
|
|
806
832
|
|
|
807
833
|
var ValidationReader = /** @class */ (function () {
|
|
808
834
|
function ValidationReader(node, tokens) {
|
|
@@ -932,6 +958,7 @@ function createValidator(rule) {
|
|
|
932
958
|
exports.ValidationBuilder = ValidationBuilder;
|
|
933
959
|
exports.ValidationContainer = ValidationContainer;
|
|
934
960
|
exports.ValidationContext = ValidationContext;
|
|
961
|
+
exports.ValidationContextWrapper = ValidationContextWrapper;
|
|
935
962
|
exports.ValidationReader = ValidationReader;
|
|
936
963
|
exports.ValidationTooltip = ValidationTooltip;
|
|
937
964
|
exports.ValidationWrapper = ValidationWrapper;
|