@skbkontur/react-ui-validations 1.6.0-beta.1 → 1.6.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 +11 -0
- package/index.d.ts +268 -256
- package/index.js +48 -51
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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.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)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **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))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [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)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package react-ui-validations
|
package/index.d.ts
CHANGED
|
@@ -1,256 +1,268 @@
|
|
|
1
|
-
// Generated by dts-bundle v0.7.3
|
|
2
|
-
// Dependencies for this module:
|
|
3
|
-
// ../../react
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
export function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
import
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
static
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
export
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
declare module '@skbkontur/react-ui-validations/src/
|
|
110
|
-
import
|
|
111
|
-
import
|
|
112
|
-
import {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
export
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
export
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
import {
|
|
201
|
-
import {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
1
|
+
// Generated by dts-bundle v0.7.3
|
|
2
|
+
// Dependencies for this module:
|
|
3
|
+
// ../../react
|
|
4
|
+
// ../../prop-types
|
|
5
|
+
|
|
6
|
+
declare module '@skbkontur/react-ui-validations' {
|
|
7
|
+
import { text, tooltip } from '@skbkontur/react-ui-validations/src/ErrorRenderer';
|
|
8
|
+
import { ValidationContainer, ValidationContainerProps } from '@skbkontur/react-ui-validations/src/ValidationContainer';
|
|
9
|
+
import { ValidationContext, ValidationContextProps } from '@skbkontur/react-ui-validations/src/ValidationContext';
|
|
10
|
+
import { TooltipPosition, ValidationTooltip, ValidationTooltipProps } from '@skbkontur/react-ui-validations/src/ValidationTooltip';
|
|
11
|
+
import { RenderErrorMessage, Validation, ValidationBehaviour } from '@skbkontur/react-ui-validations/src/ValidationWrapperInternal';
|
|
12
|
+
import { ValidationWrapper, ValidationInfo, ValidationWrapperProps } from '@skbkontur/react-ui-validations/src/ValidationWrapper';
|
|
13
|
+
export { ValidationContainer, ValidationContainerProps, ValidationContext, ValidationContextProps, ValidationWrapper as ValidationWrapperV1, ValidationWrapperProps as ValidationWrapperV1Props, RenderErrorMessage, ValidationBehaviour, Validation, ValidationWrapper, ValidationWrapperProps, ValidationInfo, ValidationTooltip, ValidationTooltipProps, TooltipPosition, tooltip, text, };
|
|
14
|
+
export * from '@skbkontur/react-ui-validations/src/Validations';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare module '@skbkontur/react-ui-validations/src/ErrorRenderer' {
|
|
18
|
+
import { TooltipPosition } from '@skbkontur/react-ui-validations/src/ValidationTooltip';
|
|
19
|
+
import { RenderErrorMessage } from '@skbkontur/react-ui-validations/src/ValidationWrapperInternal';
|
|
20
|
+
export function tooltip(pos: TooltipPosition): RenderErrorMessage;
|
|
21
|
+
export function text(pos?: 'bottom' | 'right'): RenderErrorMessage;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare module '@skbkontur/react-ui-validations/src/ValidationContainer' {
|
|
25
|
+
import React from 'react';
|
|
26
|
+
import { Nullable } from '@skbkontur/react-ui-validations/typings/Types';
|
|
27
|
+
export interface ScrollOffset {
|
|
28
|
+
top?: number;
|
|
29
|
+
bottom?: number;
|
|
30
|
+
}
|
|
31
|
+
export interface ValidationContainerProps {
|
|
32
|
+
children?: React.ReactNode;
|
|
33
|
+
onValidationUpdated?: (isValid?: Nullable<boolean>) => void;
|
|
34
|
+
scrollOffset?: number | ScrollOffset;
|
|
35
|
+
disableSmoothScroll: boolean;
|
|
36
|
+
}
|
|
37
|
+
export class ValidationContainer extends React.Component<ValidationContainerProps> {
|
|
38
|
+
static __KONTUR_REACT_UI__: string;
|
|
39
|
+
static defaultProps: {
|
|
40
|
+
disableSmoothScroll: boolean;
|
|
41
|
+
};
|
|
42
|
+
static propTypes: {
|
|
43
|
+
scrollOffset(props: ValidationContainerProps, propName: keyof ValidationContainerProps, componentName: string): Error | undefined;
|
|
44
|
+
};
|
|
45
|
+
submit(withoutFocus?: boolean): Promise<void>;
|
|
46
|
+
validate(withoutFocus?: boolean): Promise<boolean>;
|
|
47
|
+
render(): JSX.Element;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
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
|
+
declare module '@skbkontur/react-ui-validations/src/ValidationTooltip' {
|
|
96
|
+
import React from 'react';
|
|
97
|
+
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';
|
|
98
|
+
export interface ValidationTooltipProps {
|
|
99
|
+
children: React.ReactElement<any>;
|
|
100
|
+
error: boolean;
|
|
101
|
+
pos?: TooltipPosition;
|
|
102
|
+
render?: () => React.ReactNode;
|
|
103
|
+
}
|
|
104
|
+
export class ValidationTooltip extends React.Component<ValidationTooltipProps> {
|
|
105
|
+
render(): JSX.Element;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
declare module '@skbkontur/react-ui-validations/src/ValidationWrapperInternal' {
|
|
110
|
+
import * as PropTypes from 'prop-types';
|
|
111
|
+
import React from 'react';
|
|
112
|
+
import { Nullable } from '@skbkontur/react-ui-validations/typings/Types';
|
|
113
|
+
import { IValidationContext } from '@skbkontur/react-ui-validations/src/ValidationContext';
|
|
114
|
+
export type ValidationBehaviour = 'immediate' | 'lostfocus' | 'submit';
|
|
115
|
+
export type ValidationLevel = 'error' | 'warning';
|
|
116
|
+
export interface Validation {
|
|
117
|
+
level: ValidationLevel;
|
|
118
|
+
behaviour: ValidationBehaviour;
|
|
119
|
+
message: React.ReactNode;
|
|
120
|
+
independent: boolean;
|
|
121
|
+
}
|
|
122
|
+
export type RenderErrorMessage = (control: React.ReactElement<any>, hasError: boolean, validation: Nullable<Validation>) => React.ReactElement<any>;
|
|
123
|
+
export interface ValidationWrapperInternalProps {
|
|
124
|
+
children?: React.ReactElement<any>;
|
|
125
|
+
validation: Nullable<Validation>;
|
|
126
|
+
errorMessage: RenderErrorMessage;
|
|
127
|
+
}
|
|
128
|
+
interface ValidationWrapperInternalState {
|
|
129
|
+
validation: Nullable<Validation>;
|
|
130
|
+
}
|
|
131
|
+
interface Point {
|
|
132
|
+
x: number;
|
|
133
|
+
y: number;
|
|
134
|
+
}
|
|
135
|
+
export class ValidationWrapperInternal extends React.Component<ValidationWrapperInternalProps, ValidationWrapperInternalState> {
|
|
136
|
+
static contextTypes: {
|
|
137
|
+
validationContext: PropTypes.Requireable<any>;
|
|
138
|
+
};
|
|
139
|
+
state: ValidationWrapperInternalState;
|
|
140
|
+
context: {
|
|
141
|
+
validationContext: IValidationContext;
|
|
142
|
+
};
|
|
143
|
+
isChanging: boolean;
|
|
144
|
+
UNSAFE_componentWillMount(): void;
|
|
145
|
+
componentDidMount(): void;
|
|
146
|
+
componentWillUnmount(): void;
|
|
147
|
+
UNSAFE_componentWillReceiveProps(nextProps: ValidationWrapperInternalProps): void;
|
|
148
|
+
focus(): Promise<void>;
|
|
149
|
+
render(): React.ReactElement<any, string | ((props: any) => React.ReactElement<any, any> | null) | (new (props: any) => React.Component<any, any, any>)>;
|
|
150
|
+
getControlPosition(): Nullable<Point>;
|
|
151
|
+
processBlur(): Promise<void>;
|
|
152
|
+
processSubmit(): Promise<void>;
|
|
153
|
+
hasError(): boolean;
|
|
154
|
+
isIndependent(): boolean;
|
|
155
|
+
}
|
|
156
|
+
export {};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
declare module '@skbkontur/react-ui-validations/src/ValidationWrapper' {
|
|
160
|
+
import React from 'react';
|
|
161
|
+
import { Nullable } from '@skbkontur/react-ui-validations/typings/Types';
|
|
162
|
+
import { RenderErrorMessage, ValidationBehaviour, ValidationLevel } from '@skbkontur/react-ui-validations/src/ValidationWrapperInternal';
|
|
163
|
+
export interface ValidationInfo {
|
|
164
|
+
type?: Nullable<ValidationBehaviour>;
|
|
165
|
+
level?: Nullable<ValidationLevel>;
|
|
166
|
+
message: React.ReactNode;
|
|
167
|
+
independent?: boolean;
|
|
168
|
+
}
|
|
169
|
+
export interface ValidationWrapperProps {
|
|
170
|
+
children?: React.ReactElement<any>;
|
|
171
|
+
validationInfo: Nullable<ValidationInfo>;
|
|
172
|
+
renderMessage?: Nullable<RenderErrorMessage>;
|
|
173
|
+
}
|
|
174
|
+
export class ValidationWrapper extends React.Component<ValidationWrapperProps> {
|
|
175
|
+
static __KONTUR_REACT_UI__: string;
|
|
176
|
+
render(): JSX.Element;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
declare module '@skbkontur/react-ui-validations/src/Validations' {
|
|
181
|
+
import { ValidationBuilder } from '@skbkontur/react-ui-validations/src/Validations/ValidationBuilder';
|
|
182
|
+
import { RootValidationRule, ValidationRule, ItemValidationRule } from '@skbkontur/react-ui-validations/src/Validations/Types';
|
|
183
|
+
import { ValidationReader } from '@skbkontur/react-ui-validations/src/Validations/ValidationReader';
|
|
184
|
+
export type Validator<T> = (value: T) => ValidationReader<T>;
|
|
185
|
+
export function createValidator<T>(rule: RootValidationRule<T>): Validator<T>;
|
|
186
|
+
export { ValidationReader, ValidationBuilder, RootValidationRule, ValidationRule, ItemValidationRule };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
declare module '@skbkontur/react-ui-validations/typings/Types' {
|
|
190
|
+
export type Nullable<T> = T | null | undefined;
|
|
191
|
+
export type Omit<T extends object, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
192
|
+
export type ExtractItem<T> = T extends Array<infer TItem> ? TItem : never;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
declare module '@skbkontur/react-ui-validations/src/Validations/ValidationBuilder' {
|
|
196
|
+
import React from 'react';
|
|
197
|
+
import { ValidationBehaviour, ValidationLevel } from '@skbkontur/react-ui-validations/src/ValidationWrapperInternal';
|
|
198
|
+
import { ValidationInfo } from '@skbkontur/react-ui-validations/src/ValidationWrapper';
|
|
199
|
+
import { LambdaPath, PathTokensCache } from '@skbkontur/react-ui-validations/src/Validations/PathHelper';
|
|
200
|
+
import { ValidationWriter } from '@skbkontur/react-ui-validations/src/Validations/ValidationWriter';
|
|
201
|
+
import { ItemValidationRule, ValidationRule } from '@skbkontur/react-ui-validations/src/Validations/Types';
|
|
202
|
+
export class ValidationBuilder<TRoot, T> {
|
|
203
|
+
constructor(writer: ValidationWriter<TRoot>, tokens: PathTokensCache, path: string[], data: T);
|
|
204
|
+
prop<TChild>(lambdaPath: LambdaPath<T, TChild>, rule: ValidationRule<TRoot, TChild>): void;
|
|
205
|
+
array<TChild>(lambdaPath: LambdaPath<T, TChild[]>, rule: ItemValidationRule<TRoot, TChild>): void;
|
|
206
|
+
invalid(isInvalid: (value: T) => boolean, validationInfo: ValidationInfo): void;
|
|
207
|
+
invalid(isInvalid: (value: T) => boolean, message: React.ReactNode, type?: ValidationBehaviour, level?: ValidationLevel, independent?: boolean): void;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
declare module '@skbkontur/react-ui-validations/src/Validations/Types' {
|
|
212
|
+
import { Nullable } from '@skbkontur/react-ui-validations/typings/Types';
|
|
213
|
+
import { ValidationInfo } from '@skbkontur/react-ui-validations/src/ValidationWrapper';
|
|
214
|
+
import { ValidationBuilder } from '@skbkontur/react-ui-validations/src/Validations/ValidationBuilder';
|
|
215
|
+
export interface ValidationNode<T> {
|
|
216
|
+
validation: Nullable<ValidationInfo>;
|
|
217
|
+
children: Nullable<{
|
|
218
|
+
[K in keyof T]: ValidationNode<T[K]>;
|
|
219
|
+
}>;
|
|
220
|
+
}
|
|
221
|
+
export type ValidationRule<TRoot, T> = (builder: ValidationBuilder<TRoot, T>, value: T) => void;
|
|
222
|
+
export type ItemValidationRule<TRoot, T> = (builder: ValidationBuilder<TRoot, T>, value: T, index: number, array: T[]) => void;
|
|
223
|
+
export type RootValidationRule<T> = ValidationRule<T, T>;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
declare module '@skbkontur/react-ui-validations/src/Validations/ValidationReader' {
|
|
227
|
+
import { ValidationInfo } from '@skbkontur/react-ui-validations/src/ValidationWrapper';
|
|
228
|
+
import { ExtractItem, Nullable } from '@skbkontur/react-ui-validations/typings/Types';
|
|
229
|
+
import { ValidationNode } from '@skbkontur/react-ui-validations/src/Validations/Types';
|
|
230
|
+
import { LambdaPath, PathTokensCache } from '@skbkontur/react-ui-validations/src/Validations/PathHelper';
|
|
231
|
+
export class ValidationReader<T> {
|
|
232
|
+
constructor(node: Nullable<ValidationNode<T>>, tokens: PathTokensCache);
|
|
233
|
+
getNode<TChild>(lambdaPath: LambdaPath<T, TChild>): ValidationReader<TChild>;
|
|
234
|
+
getNodeByIndex(index: number): ValidationReader<ExtractItem<T>>;
|
|
235
|
+
getNodeByKey<TKey extends keyof T>(key: TKey): ValidationReader<T[TKey]>;
|
|
236
|
+
get(): Nullable<ValidationInfo>;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
declare module '@skbkontur/react-ui-validations/src/Validations/PathHelper' {
|
|
241
|
+
type NonNullableRecursive<T> = {
|
|
242
|
+
[K in keyof T]: T[K] extends object ? NonNullable<NonNullableRecursive<T[K]>> : NonNullable<T[K]>;
|
|
243
|
+
};
|
|
244
|
+
export type LambdaPath<T, TChild> = (x: NonNullable<NonNullableRecursive<T>>) => TChild;
|
|
245
|
+
export function extractPath(lambda: string): string;
|
|
246
|
+
export function extractTokens(path: string): string[];
|
|
247
|
+
export class PathTokensCache {
|
|
248
|
+
getOrAdd<T, TChild>(lambdaPath: LambdaPath<T, TChild>): string[];
|
|
249
|
+
has<T, TChild>(lambdaPath: LambdaPath<T, TChild>): boolean;
|
|
250
|
+
get size(): number;
|
|
251
|
+
}
|
|
252
|
+
export {};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
declare module '@skbkontur/react-ui-validations/src/Validations/ValidationWriter' {
|
|
256
|
+
import { ValidationInfo } from '@skbkontur/react-ui-validations/src/ValidationWrapper';
|
|
257
|
+
import { ValidationNode } from '@skbkontur/react-ui-validations/src/Validations/Types';
|
|
258
|
+
import { ValidationReader } from '@skbkontur/react-ui-validations/src/Validations/ValidationReader';
|
|
259
|
+
import { PathTokensCache } from '@skbkontur/react-ui-validations/src/Validations/PathHelper';
|
|
260
|
+
export class ValidationWriter<T> {
|
|
261
|
+
constructor(node?: ValidationNode<T>);
|
|
262
|
+
getReader(tokens: PathTokensCache): ValidationReader<T>;
|
|
263
|
+
set(validation: ValidationInfo): void;
|
|
264
|
+
isValidated(): boolean;
|
|
265
|
+
getNode<TChild>(path: string[]): ValidationWriter<TChild>;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
package/index.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
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');
|
|
6
8
|
var warning = require('warning');
|
|
7
9
|
|
|
8
10
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -190,26 +192,19 @@ var isReactUITestEnv = Boolean(REACT_UI_TEST) || // for cases when NODE_ENV is n
|
|
|
190
192
|
var isTestEnv = NODE_ENV === 'test' || isReactUITestEnv;
|
|
191
193
|
var isBrowser = typeof window !== 'undefined';
|
|
192
194
|
|
|
193
|
-
var ValidationContext =
|
|
194
|
-
|
|
195
|
-
|
|
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() {
|
|
195
|
+
var ValidationContext = /** @class */ (function (_super) {
|
|
196
|
+
__extends(ValidationContext, _super);
|
|
197
|
+
function ValidationContext() {
|
|
208
198
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
209
199
|
_this.childWrappers = [];
|
|
210
200
|
return _this;
|
|
211
201
|
}
|
|
212
|
-
|
|
202
|
+
ValidationContext.prototype.getChildContext = function () {
|
|
203
|
+
return {
|
|
204
|
+
validationContext: this,
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
ValidationContext.prototype.getSettings = function () {
|
|
213
208
|
var scrollOffset = {};
|
|
214
209
|
if (typeof this.props.scrollOffset === 'number') {
|
|
215
210
|
scrollOffset = { top: this.props.scrollOffset };
|
|
@@ -226,20 +221,20 @@ var ValidationContextWrapper = /** @class */ (function (_super) {
|
|
|
226
221
|
disableSmoothScroll: this.props.disableSmoothScroll,
|
|
227
222
|
};
|
|
228
223
|
};
|
|
229
|
-
|
|
224
|
+
ValidationContext.prototype.register = function (wrapper) {
|
|
230
225
|
this.childWrappers.push(wrapper);
|
|
231
226
|
};
|
|
232
|
-
|
|
227
|
+
ValidationContext.prototype.unregister = function (wrapper) {
|
|
233
228
|
this.childWrappers.splice(this.childWrappers.indexOf(wrapper), 1);
|
|
234
229
|
this.onValidationRemoved();
|
|
235
230
|
};
|
|
236
|
-
|
|
231
|
+
ValidationContext.prototype.instanceProcessBlur = function (instance) {
|
|
237
232
|
for (var _i = 0, _a = this.childWrappers.filter(function (x) { return x !== instance && !x.isIndependent(); }); _i < _a.length; _i++) {
|
|
238
233
|
var wrapper = _a[_i];
|
|
239
234
|
wrapper.processBlur();
|
|
240
235
|
}
|
|
241
236
|
};
|
|
242
|
-
|
|
237
|
+
ValidationContext.prototype.onValidationUpdated = function (wrapper, isValid) {
|
|
243
238
|
var onValidationUpdated = this.props.onValidationUpdated;
|
|
244
239
|
if (onValidationUpdated) {
|
|
245
240
|
var isValidResult = !this.childWrappers.find(function (x) {
|
|
@@ -251,17 +246,17 @@ var ValidationContextWrapper = /** @class */ (function (_super) {
|
|
|
251
246
|
onValidationUpdated(isValidResult);
|
|
252
247
|
}
|
|
253
248
|
};
|
|
254
|
-
|
|
249
|
+
ValidationContext.prototype.isAnyWrapperInChangingMode = function () {
|
|
255
250
|
return this.childWrappers.some(function (x) { return x.isChanging; });
|
|
256
251
|
};
|
|
257
|
-
|
|
252
|
+
ValidationContext.prototype.onValidationRemoved = function () {
|
|
258
253
|
var onValidationUpdated = this.props.onValidationUpdated;
|
|
259
254
|
if (onValidationUpdated) {
|
|
260
255
|
var isValidResult = !this.childWrappers.find(function (x) { return x.hasError(); });
|
|
261
256
|
onValidationUpdated(isValidResult);
|
|
262
257
|
}
|
|
263
258
|
};
|
|
264
|
-
|
|
259
|
+
ValidationContext.prototype.getChildWrappersSortedByPosition = function () {
|
|
265
260
|
var wrappersWithPosition = __spreadArrays(this.childWrappers).map(function (x) { return ({
|
|
266
261
|
target: x,
|
|
267
262
|
position: x.getControlPosition(),
|
|
@@ -285,7 +280,7 @@ var ValidationContextWrapper = /** @class */ (function (_super) {
|
|
|
285
280
|
});
|
|
286
281
|
return wrappersWithPosition.map(function (x) { return x.target; });
|
|
287
282
|
};
|
|
288
|
-
|
|
283
|
+
ValidationContext.prototype.validate = function (withoutFocus) {
|
|
289
284
|
return __awaiter(this, void 0, void 0, function () {
|
|
290
285
|
var firstInvalid;
|
|
291
286
|
return __generator(this, function (_a) {
|
|
@@ -307,11 +302,13 @@ var ValidationContextWrapper = /** @class */ (function (_super) {
|
|
|
307
302
|
});
|
|
308
303
|
});
|
|
309
304
|
};
|
|
310
|
-
|
|
311
|
-
return
|
|
312
|
-
|
|
305
|
+
ValidationContext.prototype.render = function () {
|
|
306
|
+
return React__default['default'].createElement("span", null, this.props.children);
|
|
307
|
+
};
|
|
308
|
+
ValidationContext.childContextTypes = {
|
|
309
|
+
validationContext: PropTypes.any,
|
|
313
310
|
};
|
|
314
|
-
return
|
|
311
|
+
return ValidationContext;
|
|
315
312
|
}(React__default['default'].Component));
|
|
316
313
|
|
|
317
314
|
var ValidationContainer = /** @class */ (function (_super) {
|
|
@@ -347,7 +344,7 @@ var ValidationContainer = /** @class */ (function (_super) {
|
|
|
347
344
|
return this.childContext.validate(withoutFocus);
|
|
348
345
|
};
|
|
349
346
|
ValidationContainer.prototype.render = function () {
|
|
350
|
-
return (React__default['default'].createElement(
|
|
347
|
+
return (React__default['default'].createElement(ValidationContext, { ref: this.refChildContext, scrollOffset: this.props.scrollOffset, disableSmoothScroll: this.props.disableSmoothScroll, onValidationUpdated: this.props.onValidationUpdated }, this.props.children));
|
|
351
348
|
};
|
|
352
349
|
ValidationContainer.__KONTUR_REACT_UI__ = 'ValidationContainer';
|
|
353
350
|
ValidationContainer.defaultProps = {
|
|
@@ -553,26 +550,25 @@ var ValidationWrapperInternal = /** @class */ (function (_super) {
|
|
|
553
550
|
validation: null,
|
|
554
551
|
};
|
|
555
552
|
_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
|
-
};
|
|
563
553
|
return _this;
|
|
564
554
|
}
|
|
555
|
+
ValidationWrapperInternal.prototype.UNSAFE_componentWillMount = function () {
|
|
556
|
+
this.applyValidation(this.props.validation);
|
|
557
|
+
};
|
|
565
558
|
ValidationWrapperInternal.prototype.componentDidMount = function () {
|
|
566
|
-
warning__default['default'](this.context, 'ValidationWrapper should appears as child of
|
|
559
|
+
warning__default['default'](this.context.validationContext, 'ValidationWrapper should appears as child of ValidationContext.\n' +
|
|
567
560
|
'https://tech.skbkontur.ru/react-ui-validations/#/getting-started');
|
|
568
|
-
this.context.
|
|
569
|
-
|
|
561
|
+
if (this.context.validationContext) {
|
|
562
|
+
this.context.validationContext.register(this);
|
|
563
|
+
}
|
|
570
564
|
};
|
|
571
565
|
ValidationWrapperInternal.prototype.componentWillUnmount = function () {
|
|
572
|
-
this.context.
|
|
566
|
+
if (this.context.validationContext) {
|
|
567
|
+
this.context.validationContext.unregister(this);
|
|
568
|
+
}
|
|
573
569
|
};
|
|
574
|
-
ValidationWrapperInternal.prototype.
|
|
575
|
-
this.applyValidation(
|
|
570
|
+
ValidationWrapperInternal.prototype.UNSAFE_componentWillReceiveProps = function (nextProps) {
|
|
571
|
+
this.applyValidation(nextProps.validation);
|
|
576
572
|
};
|
|
577
573
|
ValidationWrapperInternal.prototype.focus = function () {
|
|
578
574
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -580,9 +576,9 @@ var ValidationWrapperInternal = /** @class */ (function (_super) {
|
|
|
580
576
|
return __generator(this, function (_b) {
|
|
581
577
|
switch (_b.label) {
|
|
582
578
|
case 0:
|
|
583
|
-
htmlElement =
|
|
579
|
+
htmlElement = ReactDom.findDOMNode(this);
|
|
584
580
|
if (!(htmlElement instanceof HTMLElement)) return [3 /*break*/, 3];
|
|
585
|
-
_a = this.context.getSettings(), disableSmoothScroll = _a.disableSmoothScroll, scrollOffset = _a.scrollOffset;
|
|
581
|
+
_a = this.context.validationContext.getSettings(), disableSmoothScroll = _a.disableSmoothScroll, scrollOffset = _a.scrollOffset;
|
|
586
582
|
if (!!disableSmoothScroll) return [3 /*break*/, 2];
|
|
587
583
|
return [4 /*yield*/, smoothScrollIntoView(htmlElement, scrollOffset)];
|
|
588
584
|
case 1:
|
|
@@ -669,10 +665,10 @@ var ValidationWrapperInternal = /** @class */ (function (_super) {
|
|
|
669
665
|
},
|
|
670
666
|
});
|
|
671
667
|
}
|
|
672
|
-
return this.props.errorMessage(React__default['default'].createElement("span",
|
|
668
|
+
return this.props.errorMessage(React__default['default'].createElement("span", null, clonedChild), !!validation, validation);
|
|
673
669
|
};
|
|
674
670
|
ValidationWrapperInternal.prototype.getControlPosition = function () {
|
|
675
|
-
var htmlElement =
|
|
671
|
+
var htmlElement = ReactDom.findDOMNode(this);
|
|
676
672
|
if (htmlElement instanceof HTMLElement) {
|
|
677
673
|
var rect = htmlElement.getBoundingClientRect();
|
|
678
674
|
return { x: rect.top, y: rect.left };
|
|
@@ -704,7 +700,7 @@ var ValidationWrapperInternal = /** @class */ (function (_super) {
|
|
|
704
700
|
setTimeout(function () {
|
|
705
701
|
_this.processBlur();
|
|
706
702
|
if (!_this.isIndependent()) {
|
|
707
|
-
_this.context.instanceProcessBlur(_this);
|
|
703
|
+
_this.context.validationContext.instanceProcessBlur(_this);
|
|
708
704
|
}
|
|
709
705
|
_this.setState({});
|
|
710
706
|
});
|
|
@@ -722,7 +718,7 @@ var ValidationWrapperInternal = /** @class */ (function (_super) {
|
|
|
722
718
|
return new Promise(function (resolve) {
|
|
723
719
|
_this.setState({ validation: validation }, resolve);
|
|
724
720
|
if (Boolean(current) !== Boolean(validation)) {
|
|
725
|
-
_this.context.onValidationUpdated(_this, !validation);
|
|
721
|
+
_this.context.validationContext.onValidationUpdated(_this, !validation);
|
|
726
722
|
}
|
|
727
723
|
});
|
|
728
724
|
};
|
|
@@ -739,10 +735,12 @@ var ValidationWrapperInternal = /** @class */ (function (_super) {
|
|
|
739
735
|
if (isEqual(visible, actual)) {
|
|
740
736
|
return visible;
|
|
741
737
|
}
|
|
742
|
-
var changing = this.context.isAnyWrapperInChangingMode();
|
|
738
|
+
var changing = this.context.validationContext.isAnyWrapperInChangingMode();
|
|
743
739
|
return getVisibleValidation(visible, actual, changing);
|
|
744
740
|
};
|
|
745
|
-
ValidationWrapperInternal.
|
|
741
|
+
ValidationWrapperInternal.contextTypes = {
|
|
742
|
+
validationContext: PropTypes.any,
|
|
743
|
+
};
|
|
746
744
|
return ValidationWrapperInternal;
|
|
747
745
|
}(React__default['default'].Component));
|
|
748
746
|
|
|
@@ -956,7 +954,6 @@ function createValidator(rule) {
|
|
|
956
954
|
exports.ValidationBuilder = ValidationBuilder;
|
|
957
955
|
exports.ValidationContainer = ValidationContainer;
|
|
958
956
|
exports.ValidationContext = ValidationContext;
|
|
959
|
-
exports.ValidationContextWrapper = ValidationContextWrapper;
|
|
960
957
|
exports.ValidationReader = ValidationReader;
|
|
961
958
|
exports.ValidationTooltip = ValidationTooltip;
|
|
962
959
|
exports.ValidationWrapper = ValidationWrapper;
|