@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.
Files changed (4) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/index.d.ts +268 -256
  3. package/index.js +48 -51
  4. 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
- declare module '@skbkontur/react-ui-validations' {
6
- import { text, tooltip } from '@skbkontur/react-ui-validations/src/ErrorRenderer';
7
- import { ValidationContainer, ValidationContainerProps } from '@skbkontur/react-ui-validations/src/ValidationContainer';
8
- import { TooltipPosition, ValidationTooltip, ValidationTooltipProps } from '@skbkontur/react-ui-validations/src/ValidationTooltip';
9
- import { RenderErrorMessage, Validation, ValidationBehaviour } from '@skbkontur/react-ui-validations/src/ValidationWrapperInternal';
10
- import { ValidationWrapper, ValidationInfo, ValidationWrapperProps } from '@skbkontur/react-ui-validations/src/ValidationWrapper';
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, };
13
- export * from '@skbkontur/react-ui-validations/src/Validations';
14
- }
15
-
16
- declare module '@skbkontur/react-ui-validations/src/ErrorRenderer' {
17
- import { TooltipPosition } from '@skbkontur/react-ui-validations/src/ValidationTooltip';
18
- import { RenderErrorMessage } from '@skbkontur/react-ui-validations/src/ValidationWrapperInternal';
19
- export function tooltip(pos: TooltipPosition): RenderErrorMessage;
20
- export function text(pos?: 'bottom' | 'right'): RenderErrorMessage;
21
- }
22
-
23
- declare module '@skbkontur/react-ui-validations/src/ValidationContainer' {
24
- import React from 'react';
25
- import { Nullable } from '@skbkontur/react-ui-validations/typings/Types';
26
- export interface ScrollOffset {
27
- top?: number;
28
- bottom?: number;
29
- }
30
- export interface ValidationContainerProps {
31
- children?: React.ReactNode;
32
- onValidationUpdated?: (isValid?: Nullable<boolean>) => void;
33
- scrollOffset?: number | ScrollOffset;
34
- disableSmoothScroll: boolean;
35
- }
36
- export class ValidationContainer extends React.Component<ValidationContainerProps> {
37
- static __KONTUR_REACT_UI__: string;
38
- static defaultProps: {
39
- disableSmoothScroll: boolean;
40
- };
41
- static propTypes: {
42
- scrollOffset(props: ValidationContainerProps, propName: keyof ValidationContainerProps, componentName: string): Error | undefined;
43
- };
44
- submit(withoutFocus?: boolean): Promise<void>;
45
- validate(withoutFocus?: boolean): Promise<boolean>;
46
- render(): JSX.Element;
47
- }
48
- }
49
-
50
- declare module '@skbkontur/react-ui-validations/src/ValidationTooltip' {
51
- import React from 'react';
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';
53
- export interface ValidationTooltipProps {
54
- children: React.ReactElement<any>;
55
- error: boolean;
56
- pos?: TooltipPosition;
57
- render?: () => React.ReactNode;
58
- }
59
- export class ValidationTooltip extends React.Component<ValidationTooltipProps> {
60
- render(): JSX.Element;
61
- }
62
- }
63
-
64
- declare module '@skbkontur/react-ui-validations/src/ValidationWrapperInternal' {
65
- import React from 'react';
66
- import { Nullable } from '@skbkontur/react-ui-validations/typings/Types';
67
- import { ValidationContextType } from '@skbkontur/react-ui-validations/src/ValidationContextWrapper';
68
- export type ValidationBehaviour = 'immediate' | 'lostfocus' | 'submit';
69
- export type ValidationLevel = 'error' | 'warning';
70
- export interface Validation {
71
- level: ValidationLevel;
72
- behaviour: ValidationBehaviour;
73
- message: React.ReactNode;
74
- independent: boolean;
75
- }
76
- export type RenderErrorMessage = (control: React.ReactElement<any>, hasError: boolean, validation: Nullable<Validation>) => React.ReactElement<any>;
77
- export interface ValidationWrapperInternalProps {
78
- children?: React.ReactElement<any>;
79
- validation: Nullable<Validation>;
80
- errorMessage: RenderErrorMessage;
81
- }
82
- interface ValidationWrapperInternalState {
83
- validation: Nullable<Validation>;
84
- }
85
- interface Point {
86
- x: number;
87
- y: number;
88
- }
89
- export class ValidationWrapperInternal extends React.Component<ValidationWrapperInternalProps, ValidationWrapperInternalState> {
90
- state: ValidationWrapperInternalState;
91
- isChanging: boolean;
92
- static contextType: React.Context<ValidationContextType>;
93
- context: ValidationContextType;
94
- componentDidMount(): void;
95
- componentWillUnmount(): void;
96
- componentDidUpdate(): void;
97
- focus(): Promise<void>;
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>;
100
- getControlPosition(): Nullable<Point>;
101
- processBlur(): Promise<void>;
102
- processSubmit(): Promise<void>;
103
- hasError(): boolean;
104
- isIndependent(): boolean;
105
- }
106
- export {};
107
- }
108
-
109
- declare module '@skbkontur/react-ui-validations/src/ValidationWrapper' {
110
- import React from 'react';
111
- import { Nullable } from '@skbkontur/react-ui-validations/typings/Types';
112
- import { RenderErrorMessage, ValidationBehaviour, ValidationLevel } from '@skbkontur/react-ui-validations/src/ValidationWrapperInternal';
113
- export interface ValidationInfo {
114
- type?: Nullable<ValidationBehaviour>;
115
- level?: Nullable<ValidationLevel>;
116
- message: React.ReactNode;
117
- independent?: boolean;
118
- }
119
- export interface ValidationWrapperProps {
120
- children?: React.ReactElement<any>;
121
- validationInfo: Nullable<ValidationInfo>;
122
- renderMessage?: Nullable<RenderErrorMessage>;
123
- }
124
- export class ValidationWrapper extends React.Component<ValidationWrapperProps> {
125
- static __KONTUR_REACT_UI__: string;
126
- render(): JSX.Element;
127
- }
128
- }
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
-
168
- declare module '@skbkontur/react-ui-validations/src/Validations' {
169
- import { ValidationBuilder } from '@skbkontur/react-ui-validations/src/Validations/ValidationBuilder';
170
- import { RootValidationRule, ValidationRule, ItemValidationRule } from '@skbkontur/react-ui-validations/src/Validations/Types';
171
- import { ValidationReader } from '@skbkontur/react-ui-validations/src/Validations/ValidationReader';
172
- export type Validator<T> = (value: T) => ValidationReader<T>;
173
- export function createValidator<T>(rule: RootValidationRule<T>): Validator<T>;
174
- export { ValidationReader, ValidationBuilder, RootValidationRule, ValidationRule, ItemValidationRule };
175
- }
176
-
177
- declare module '@skbkontur/react-ui-validations/typings/Types' {
178
- export type Nullable<T> = T | null | undefined;
179
- export type Omit<T extends object, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
180
- export type ExtractItem<T> = T extends Array<infer TItem> ? TItem : never;
181
- }
182
-
183
- declare module '@skbkontur/react-ui-validations/src/Validations/ValidationBuilder' {
184
- import React from 'react';
185
- import { ValidationBehaviour, ValidationLevel } from '@skbkontur/react-ui-validations/src/ValidationWrapperInternal';
186
- import { ValidationInfo } from '@skbkontur/react-ui-validations/src/ValidationWrapper';
187
- import { LambdaPath, PathTokensCache } from '@skbkontur/react-ui-validations/src/Validations/PathHelper';
188
- import { ValidationWriter } from '@skbkontur/react-ui-validations/src/Validations/ValidationWriter';
189
- import { ItemValidationRule, ValidationRule } from '@skbkontur/react-ui-validations/src/Validations/Types';
190
- export class ValidationBuilder<TRoot, T> {
191
- constructor(writer: ValidationWriter<TRoot>, tokens: PathTokensCache, path: string[], data: T);
192
- prop<TChild>(lambdaPath: LambdaPath<T, TChild>, rule: ValidationRule<TRoot, TChild>): void;
193
- array<TChild>(lambdaPath: LambdaPath<T, TChild[]>, rule: ItemValidationRule<TRoot, TChild>): void;
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;
196
- }
197
- }
198
-
199
- declare module '@skbkontur/react-ui-validations/src/Validations/Types' {
200
- import { Nullable } from '@skbkontur/react-ui-validations/typings/Types';
201
- import { ValidationInfo } from '@skbkontur/react-ui-validations/src/ValidationWrapper';
202
- import { ValidationBuilder } from '@skbkontur/react-ui-validations/src/Validations/ValidationBuilder';
203
- export interface ValidationNode<T> {
204
- validation: Nullable<ValidationInfo>;
205
- children: Nullable<{
206
- [K in keyof T]: ValidationNode<T[K]>;
207
- }>;
208
- }
209
- export type ValidationRule<TRoot, T> = (builder: ValidationBuilder<TRoot, T>, value: T) => void;
210
- export type ItemValidationRule<TRoot, T> = (builder: ValidationBuilder<TRoot, T>, value: T, index: number, array: T[]) => void;
211
- export type RootValidationRule<T> = ValidationRule<T, T>;
212
- }
213
-
214
- declare module '@skbkontur/react-ui-validations/src/Validations/ValidationReader' {
215
- import { ValidationInfo } from '@skbkontur/react-ui-validations/src/ValidationWrapper';
216
- import { ExtractItem, Nullable } from '@skbkontur/react-ui-validations/typings/Types';
217
- import { ValidationNode } from '@skbkontur/react-ui-validations/src/Validations/Types';
218
- import { LambdaPath, PathTokensCache } from '@skbkontur/react-ui-validations/src/Validations/PathHelper';
219
- export class ValidationReader<T> {
220
- constructor(node: Nullable<ValidationNode<T>>, tokens: PathTokensCache);
221
- getNode<TChild>(lambdaPath: LambdaPath<T, TChild>): ValidationReader<TChild>;
222
- getNodeByIndex(index: number): ValidationReader<ExtractItem<T>>;
223
- getNodeByKey<TKey extends keyof T>(key: TKey): ValidationReader<T[TKey]>;
224
- get(): Nullable<ValidationInfo>;
225
- }
226
- }
227
-
228
- declare module '@skbkontur/react-ui-validations/src/Validations/PathHelper' {
229
- type NonNullableRecursive<T> = {
230
- [K in keyof T]: T[K] extends object ? NonNullable<NonNullableRecursive<T[K]>> : NonNullable<T[K]>;
231
- };
232
- export type LambdaPath<T, TChild> = (x: NonNullable<NonNullableRecursive<T>>) => TChild;
233
- export function extractPath(lambda: string): string;
234
- export function extractTokens(path: string): string[];
235
- export class PathTokensCache {
236
- getOrAdd<T, TChild>(lambdaPath: LambdaPath<T, TChild>): string[];
237
- has<T, TChild>(lambdaPath: LambdaPath<T, TChild>): boolean;
238
- get size(): number;
239
- }
240
- export {};
241
- }
242
-
243
- declare module '@skbkontur/react-ui-validations/src/Validations/ValidationWriter' {
244
- import { ValidationInfo } from '@skbkontur/react-ui-validations/src/ValidationWrapper';
245
- import { ValidationNode } from '@skbkontur/react-ui-validations/src/Validations/Types';
246
- import { ValidationReader } from '@skbkontur/react-ui-validations/src/Validations/ValidationReader';
247
- import { PathTokensCache } from '@skbkontur/react-ui-validations/src/Validations/PathHelper';
248
- export class ValidationWriter<T> {
249
- constructor(node?: ValidationNode<T>);
250
- getReader(tokens: PathTokensCache): ValidationReader<T>;
251
- set(validation: ValidationInfo): void;
252
- isValidated(): boolean;
253
- getNode<TChild>(path: string[]): ValidationWriter<TChild>;
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 = 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() {
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
- ValidationContextWrapper.prototype.getSettings = function () {
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
- ValidationContextWrapper.prototype.register = function (wrapper) {
224
+ ValidationContext.prototype.register = function (wrapper) {
230
225
  this.childWrappers.push(wrapper);
231
226
  };
232
- ValidationContextWrapper.prototype.unregister = function (wrapper) {
227
+ ValidationContext.prototype.unregister = function (wrapper) {
233
228
  this.childWrappers.splice(this.childWrappers.indexOf(wrapper), 1);
234
229
  this.onValidationRemoved();
235
230
  };
236
- ValidationContextWrapper.prototype.instanceProcessBlur = function (instance) {
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
- ValidationContextWrapper.prototype.onValidationUpdated = function (wrapper, isValid) {
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
- ValidationContextWrapper.prototype.isAnyWrapperInChangingMode = function () {
249
+ ValidationContext.prototype.isAnyWrapperInChangingMode = function () {
255
250
  return this.childWrappers.some(function (x) { return x.isChanging; });
256
251
  };
257
- ValidationContextWrapper.prototype.onValidationRemoved = function () {
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
- ValidationContextWrapper.prototype.getChildWrappersSortedByPosition = function () {
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
- ValidationContextWrapper.prototype.validate = function (withoutFocus) {
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
- ValidationContextWrapper.prototype.render = function () {
311
- return (React__default['default'].createElement(ValidationContext.Provider, { value: this },
312
- React__default['default'].createElement("span", null, this.props.children)));
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 ValidationContextWrapper;
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(ValidationContextWrapper, { ref: this.refChildContext, scrollOffset: this.props.scrollOffset, disableSmoothScroll: this.props.disableSmoothScroll, onValidationUpdated: this.props.onValidationUpdated }, this.props.children));
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 ValidationContainer.\n' +
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.register(this);
569
- this.applyValidation(this.props.validation);
561
+ if (this.context.validationContext) {
562
+ this.context.validationContext.register(this);
563
+ }
570
564
  };
571
565
  ValidationWrapperInternal.prototype.componentWillUnmount = function () {
572
- this.context.unregister(this);
566
+ if (this.context.validationContext) {
567
+ this.context.validationContext.unregister(this);
568
+ }
573
569
  };
574
- ValidationWrapperInternal.prototype.componentDidUpdate = function () {
575
- this.applyValidation(this.props.validation);
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 = this.getRootNode();
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", { ref: this.setRootNode }, clonedChild), !!validation, validation);
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 = this.getRootNode();
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.contextType = ValidationContext;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skbkontur/react-ui-validations",
3
- "version": "1.6.0-beta.1",
3
+ "version": "1.6.0",
4
4
  "description": "Validations for @skbkontur/react-ui",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",