@skbkontur/react-ui-validations 1.5.5 → 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 CHANGED
@@ -3,6 +3,36 @@
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
+
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)
18
+
19
+ **Note:** Version bump only for package react-ui-validations
20
+
21
+
22
+
23
+
24
+
25
+ ## [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)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * **validations:** update package name ([b5e4741](https://github.com/skbkontur/retail-ui/tree/master/packages/react-ui-validations/commit/b5e4741b157c2ab6f37188b356376f0fddf1e7cf))
31
+
32
+
33
+
34
+
35
+
6
36
  ## [1.5.5](https://github.com/skbkontur/retail-ui/tree/master/packages/react-ui-validations/compare/react-ui-validations@1.5.4...react-ui-validations@1.5.5) (2021-09-16)
7
37
 
8
38
 
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # react-ui-validations
1
+ # React UI validations
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/react-ui-validations.svg?maxAge=300&style=flat-square)](https://www.npmjs.com/package/react-ui-validations)
4
4
 
@@ -6,13 +6,13 @@
6
6
 
7
7
  ## Документация
8
8
 
9
- - [Docs & Demos](http://tech.skbkontur.ru/react-ui-validations/)
9
+ - [Docs & Demos](https://tech.skbkontur.ru/react-ui-validations/)
10
10
  - [Validation guides](https://guides.kontur.ru/principles/validation/)
11
11
 
12
12
  ## Использование
13
13
 
14
14
  ```shell
15
- npm install --save react-ui-validations
15
+ npm install --save @skbkontur/react-ui-validations
16
16
  ```
17
17
 
18
18
  ```jsx
package/index.d.ts CHANGED
@@ -117,6 +117,7 @@ declare module '@skbkontur/react-ui-validations/src/ValidationWrapperInternal' {
117
117
  level: ValidationLevel;
118
118
  behaviour: ValidationBehaviour;
119
119
  message: React.ReactNode;
120
+ independent: boolean;
120
121
  }
121
122
  export type RenderErrorMessage = (control: React.ReactElement<any>, hasError: boolean, validation: Nullable<Validation>) => React.ReactElement<any>;
122
123
  export interface ValidationWrapperInternalProps {
@@ -150,6 +151,7 @@ declare module '@skbkontur/react-ui-validations/src/ValidationWrapperInternal' {
150
151
  processBlur(): Promise<void>;
151
152
  processSubmit(): Promise<void>;
152
153
  hasError(): boolean;
154
+ isIndependent(): boolean;
153
155
  }
154
156
  export {};
155
157
  }
@@ -162,6 +164,7 @@ declare module '@skbkontur/react-ui-validations/src/ValidationWrapper' {
162
164
  type?: Nullable<ValidationBehaviour>;
163
165
  level?: Nullable<ValidationLevel>;
164
166
  message: React.ReactNode;
167
+ independent?: boolean;
165
168
  }
166
169
  export interface ValidationWrapperProps {
167
170
  children?: React.ReactElement<any>;
@@ -192,6 +195,7 @@ declare module '@skbkontur/react-ui-validations/typings/Types' {
192
195
  declare module '@skbkontur/react-ui-validations/src/Validations/ValidationBuilder' {
193
196
  import React from 'react';
194
197
  import { ValidationBehaviour, ValidationLevel } from '@skbkontur/react-ui-validations/src/ValidationWrapperInternal';
198
+ import { ValidationInfo } from '@skbkontur/react-ui-validations/src/ValidationWrapper';
195
199
  import { LambdaPath, PathTokensCache } from '@skbkontur/react-ui-validations/src/Validations/PathHelper';
196
200
  import { ValidationWriter } from '@skbkontur/react-ui-validations/src/Validations/ValidationWriter';
197
201
  import { ItemValidationRule, ValidationRule } from '@skbkontur/react-ui-validations/src/Validations/Types';
@@ -199,7 +203,8 @@ declare module '@skbkontur/react-ui-validations/src/Validations/ValidationBuilde
199
203
  constructor(writer: ValidationWriter<TRoot>, tokens: PathTokensCache, path: string[], data: T);
200
204
  prop<TChild>(lambdaPath: LambdaPath<T, TChild>, rule: ValidationRule<TRoot, TChild>): void;
201
205
  array<TChild>(lambdaPath: LambdaPath<T, TChild[]>, rule: ItemValidationRule<TRoot, TChild>): void;
202
- invalid(isInvalid: (value: T) => boolean, message: React.ReactNode, type?: ValidationBehaviour, level?: ValidationLevel): 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;
203
208
  }
204
209
  }
205
210
 
package/index.js CHANGED
@@ -229,7 +229,7 @@ var ValidationContext = /** @class */ (function (_super) {
229
229
  this.onValidationRemoved();
230
230
  };
231
231
  ValidationContext.prototype.instanceProcessBlur = function (instance) {
232
- for (var _i = 0, _a = this.childWrappers.filter(function (x) { return x !== instance; }); _i < _a.length; _i++) {
232
+ for (var _i = 0, _a = this.childWrappers.filter(function (x) { return x !== instance && !x.isIndependent(); }); _i < _a.length; _i++) {
233
233
  var wrapper = _a[_i];
234
234
  wrapper.processBlur();
235
235
  }
@@ -523,11 +523,19 @@ function getType(validation) {
523
523
  function getLevel(validation) {
524
524
  return validation ? validation.level : null;
525
525
  }
526
+ function getIndependent(validation) {
527
+ return validation ? validation.independent : null;
528
+ }
526
529
  function isEqual(a, b) {
527
530
  if (a === b) {
528
531
  return true;
529
532
  }
530
- return !!a && !!b && a.behaviour === b.behaviour && a.level === a.level && a.message === b.message;
533
+ return (!!a &&
534
+ !!b &&
535
+ a.behaviour === b.behaviour &&
536
+ a.level === a.level &&
537
+ a.message === b.message &&
538
+ a.independent === b.independent);
531
539
  }
532
540
 
533
541
  if (isBrowser && typeof HTMLElement === 'undefined') {
@@ -549,7 +557,7 @@ var ValidationWrapperInternal = /** @class */ (function (_super) {
549
557
  };
550
558
  ValidationWrapperInternal.prototype.componentDidMount = function () {
551
559
  warning__default['default'](this.context.validationContext, 'ValidationWrapper should appears as child of ValidationContext.\n' +
552
- 'http://tech.skbkontur.ru/react-ui-validations/#/getting-started');
560
+ 'https://tech.skbkontur.ru/react-ui-validations/#/getting-started');
553
561
  if (this.context.validationContext) {
554
562
  this.context.validationContext.register(this);
555
563
  }
@@ -684,11 +692,16 @@ var ValidationWrapperInternal = /** @class */ (function (_super) {
684
692
  ValidationWrapperInternal.prototype.hasError = function () {
685
693
  return getLevel(this.state.validation) === 'error';
686
694
  };
695
+ ValidationWrapperInternal.prototype.isIndependent = function () {
696
+ return getIndependent(this.state.validation || this.props.validation) === true;
697
+ };
687
698
  ValidationWrapperInternal.prototype.handleBlur = function () {
688
699
  var _this = this;
689
700
  setTimeout(function () {
690
701
  _this.processBlur();
691
- _this.context.validationContext.instanceProcessBlur(_this);
702
+ if (!_this.isIndependent()) {
703
+ _this.context.validationContext.instanceProcessBlur(_this);
704
+ }
692
705
  _this.setState({});
693
706
  });
694
707
  };
@@ -743,6 +756,7 @@ var ValidationWrapper = /** @class */ (function (_super) {
743
756
  level: validationInfo.level || 'error',
744
757
  behaviour: validationInfo.type || 'lostfocus',
745
758
  message: validationInfo.message,
759
+ independent: validationInfo.independent || false,
746
760
  }
747
761
  : null;
748
762
  return (React__default['default'].createElement(ValidationWrapperInternal, { errorMessage: renderMessage || tooltip('right top'), validation: validation }, children));
@@ -778,7 +792,7 @@ var ValidationBuilder = /** @class */ (function () {
778
792
  rule(builder, builder.data, i, array);
779
793
  }
780
794
  };
781
- ValidationBuilder.prototype.invalid = function (isInvalid, message, type, level) {
795
+ ValidationBuilder.prototype.invalid = function (isInvalid, messageOrValidationInfo, type, level, independent) {
782
796
  var validationWriter = this.writer.getNode(this.path);
783
797
  if (validationWriter.isValidated()) {
784
798
  return;
@@ -787,7 +801,12 @@ var ValidationBuilder = /** @class */ (function () {
787
801
  if (!invalid) {
788
802
  return;
789
803
  }
790
- validationWriter.set({ message: message, type: type, level: level });
804
+ if (isValidationInfo(messageOrValidationInfo)) {
805
+ validationWriter.set(messageOrValidationInfo);
806
+ }
807
+ else {
808
+ validationWriter.set({ message: messageOrValidationInfo, type: type, level: level, independent: independent });
809
+ }
791
810
  };
792
811
  ValidationBuilder.prototype.getPathInfo = function (lambdaPath) {
793
812
  var path = this.tokens.getOrAdd(lambdaPath);
@@ -802,7 +821,10 @@ var ValidationBuilder = /** @class */ (function () {
802
821
  return { data: data, path: __spreadArrays(this.path, path) };
803
822
  };
804
823
  return ValidationBuilder;
805
- }());
824
+ }());
825
+ var isValidationInfo = function (argument) {
826
+ return typeof argument === 'object' && Object.prototype.hasOwnProperty.call(argument, 'message');
827
+ };
806
828
 
807
829
  var ValidationReader = /** @class */ (function () {
808
830
  function ValidationReader(node, tokens) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skbkontur/react-ui-validations",
3
- "version": "1.5.5",
3
+ "version": "1.6.0",
4
4
  "description": "Validations for @skbkontur/react-ui",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",