@gravity-ui/dynamic-forms 4.7.3 → 4.9.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.
@@ -48,8 +48,11 @@
48
48
  margin-left: 10px;
49
49
  }
50
50
  .df-card__title {
51
- display: flex;
52
51
  max-width: 533px;
52
+ height: 20px;
53
+ }
54
+ .df-card__title-popover {
55
+ height: 20px;
53
56
  }
54
57
  .df-card__note {
55
58
  margin-left: 5px;
@@ -37,7 +37,7 @@ const Card = ({ name, title: propsTitle, description, actions, open: propsOpen,
37
37
  const title = react_1.default.useMemo(() => {
38
38
  if ((0, isString_1.default)(propsTitle)) {
39
39
  return (react_1.default.createElement(react_1.default.Fragment, null,
40
- react_1.default.createElement(uikit_1.Popover, { content: propsTitle, disabled: titlePopoverDisabled, placement: common_1.COMMON_POPOVER_PLACEMENT },
40
+ react_1.default.createElement(uikit_1.Popover, { content: propsTitle, disabled: titlePopoverDisabled, placement: common_1.COMMON_POPOVER_PLACEMENT, className: b('title-popover') },
41
41
  react_1.default.createElement(uikit_1.Text, { className: b('title'), ellipsis: true, ref: titleRef, variant: "subheader-2" }, propsTitle)),
42
42
  description ? (react_1.default.createElement("div", { className: b('note') },
43
43
  react_1.default.createElement(components_1.HelpPopover, { htmlContent: description, placement: common_1.COMMON_POPOVER_PLACEMENT }))) : null));
@@ -9,7 +9,6 @@
9
9
  }
10
10
  .df-section__header_with-popover {
11
11
  display: flex;
12
- align-items: center;
13
12
  }
14
13
  .df-section__title {
15
14
  max-width: 533px;
@@ -8,11 +8,14 @@ const uikit_1 = require("@gravity-ui/uikit");
8
8
  const utils_1 = require("../../utils");
9
9
  const b = (0, utils_1.block)('long-value');
10
10
  const LongValue = (_a) => {
11
- var { value, className } = _a, restProps = tslib_1.__rest(_a, ["value", "className"]);
11
+ var { value, onClick, className } = _a, restProps = tslib_1.__rest(_a, ["value", "onClick", "className"]);
12
12
  const ref = react_1.default.useRef(null);
13
13
  const [open, setOpen] = react_1.default.useState(false);
14
14
  const [long, setLong] = react_1.default.useState(false);
15
- const handleClick = react_1.default.useCallback(() => setOpen((f) => !f), [setOpen]);
15
+ const handleClick = react_1.default.useCallback((e) => {
16
+ onClick === null || onClick === void 0 ? void 0 : onClick(e);
17
+ setOpen((f) => !f);
18
+ }, [setOpen, onClick]);
16
19
  react_1.default.useEffect(() => {
17
20
  if (ref.current) {
18
21
  const { offsetWidth, scrollWidth } = ref.current;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.END_TIME = exports.START_TIME = exports.OBJECT_VALUE_PROPERTY_NAME = exports.COMMON_TITLE_MAX_WIDTH = exports.COMMON_POPOVER_PLACEMENT = void 0;
4
4
  exports.COMMON_POPOVER_PLACEMENT = ['bottom', 'top'];
5
- exports.COMMON_TITLE_MAX_WIDTH = 533;
5
+ exports.COMMON_TITLE_MAX_WIDTH = 523;
6
6
  exports.OBJECT_VALUE_PROPERTY_NAME = 'value';
7
7
  exports.START_TIME = 'start';
8
8
  exports.END_TIME = 'end';
@@ -8,6 +8,7 @@ const isNil_1 = tslib_1.__importDefault(require("lodash/isNil"));
8
8
  const isObject_1 = tslib_1.__importDefault(require("lodash/isObject"));
9
9
  const isObjectLike_1 = tslib_1.__importDefault(require("lodash/isObjectLike"));
10
10
  const isString_1 = tslib_1.__importDefault(require("lodash/isString"));
11
+ const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
11
12
  const core_1 = require("../../core");
12
13
  const helpers_1 = require("../validators/helpers");
13
14
  const bigIntMath_1 = require("./bigIntMath");
@@ -40,7 +41,7 @@ const isNotEmptyValue = (value, spec) => {
40
41
  return true;
41
42
  };
42
43
  exports.isNotEmptyValue = isNotEmptyValue;
43
- const prepareSpec = (spec, parseJsonDefaultValue) => {
44
+ const prepareSpec = (spec, parseJsonDefaultValue, overridePatternError) => {
44
45
  var _a, _b, _c, _d, _e, _f, _g, _h;
45
46
  if ((0, isObjectLike_1.default)(spec)) {
46
47
  const result = (0, cloneDeep_1.default)(spec);
@@ -100,8 +101,11 @@ const prepareSpec = (spec, parseJsonDefaultValue) => {
100
101
  result.minLength = BigInt(result.minLength);
101
102
  }
102
103
  }
104
+ if (!(0, isEmpty_1.default)(result.pattern) && (0, isEmpty_1.default)(result.patternError) && overridePatternError) {
105
+ result.patternError = overridePatternError(result.pattern);
106
+ }
103
107
  if (result.items) {
104
- result.items = (0, exports.prepareSpec)(result.items, parseJsonDefaultValue);
108
+ result.items = (0, exports.prepareSpec)(result.items, parseJsonDefaultValue, overridePatternError);
105
109
  }
106
110
  if (result.maximum === 0 && result.minimum === 0) {
107
111
  result.maximum = undefined;
@@ -120,7 +124,7 @@ const prepareSpec = (spec, parseJsonDefaultValue) => {
120
124
  }
121
125
  if ((0, isObjectLike_1.default)(result.properties)) {
122
126
  Object.keys(result.properties).forEach((key) => {
123
- result.properties[key] = (0, exports.prepareSpec)(result.properties[key], parseJsonDefaultValue);
127
+ result.properties[key] = (0, exports.prepareSpec)(result.properties[key], parseJsonDefaultValue, overridePatternError);
124
128
  });
125
129
  }
126
130
  return result;
@@ -48,8 +48,11 @@
48
48
  margin-left: 10px;
49
49
  }
50
50
  .df-card__title {
51
- display: flex;
52
51
  max-width: 533px;
52
+ height: 20px;
53
+ }
54
+ .df-card__title-popover {
55
+ height: 20px;
53
56
  }
54
57
  .df-card__note {
55
58
  margin-left: 5px;
@@ -34,7 +34,7 @@ export const Card = ({ name, title: propsTitle, description, actions, open: prop
34
34
  const title = React.useMemo(() => {
35
35
  if (isString(propsTitle)) {
36
36
  return (React.createElement(React.Fragment, null,
37
- React.createElement(Popover, { content: propsTitle, disabled: titlePopoverDisabled, placement: COMMON_POPOVER_PLACEMENT },
37
+ React.createElement(Popover, { content: propsTitle, disabled: titlePopoverDisabled, placement: COMMON_POPOVER_PLACEMENT, className: b('title-popover') },
38
38
  React.createElement(Text, { className: b('title'), ellipsis: true, ref: titleRef, variant: "subheader-2" }, propsTitle)),
39
39
  description ? (React.createElement("div", { className: b('note') },
40
40
  React.createElement(HelpPopover, { htmlContent: description, placement: COMMON_POPOVER_PLACEMENT }))) : null));
@@ -9,7 +9,6 @@
9
9
  }
10
10
  .df-section__header_with-popover {
11
11
  display: flex;
12
- align-items: center;
13
12
  }
14
13
  .df-section__title {
15
14
  max-width: 533px;
@@ -3,5 +3,6 @@ import { type TextProps } from '@gravity-ui/uikit';
3
3
  import './LongValue.css';
4
4
  export interface LongValueProps extends TextProps {
5
5
  value?: string | number | boolean;
6
+ onClick?: (e: React.MouseEvent<HTMLDivElement>) => void;
6
7
  }
7
8
  export declare const LongValue: React.FC<LongValueProps>;
@@ -6,11 +6,14 @@ import { block } from '../../utils';
6
6
  import './LongValue.css';
7
7
  const b = block('long-value');
8
8
  export const LongValue = (_a) => {
9
- var { value, className } = _a, restProps = __rest(_a, ["value", "className"]);
9
+ var { value, onClick, className } = _a, restProps = __rest(_a, ["value", "onClick", "className"]);
10
10
  const ref = React.useRef(null);
11
11
  const [open, setOpen] = React.useState(false);
12
12
  const [long, setLong] = React.useState(false);
13
- const handleClick = React.useCallback(() => setOpen((f) => !f), [setOpen]);
13
+ const handleClick = React.useCallback((e) => {
14
+ onClick === null || onClick === void 0 ? void 0 : onClick(e);
15
+ setOpen((f) => !f);
16
+ }, [setOpen, onClick]);
14
17
  React.useEffect(() => {
15
18
  if (ref.current) {
16
19
  const { offsetWidth, scrollWidth } = ref.current;
@@ -1,6 +1,6 @@
1
1
  import type { PopoverProps } from '@gravity-ui/uikit';
2
2
  export declare const COMMON_POPOVER_PLACEMENT: PopoverProps['placement'];
3
- export declare const COMMON_TITLE_MAX_WIDTH = 533;
3
+ export declare const COMMON_TITLE_MAX_WIDTH = 523;
4
4
  export declare const OBJECT_VALUE_PROPERTY_NAME = "value";
5
5
  export declare const START_TIME = "start";
6
6
  export declare const END_TIME = "end";
@@ -1,5 +1,5 @@
1
1
  export const COMMON_POPOVER_PLACEMENT = ['bottom', 'top'];
2
- export const COMMON_TITLE_MAX_WIDTH = 533;
2
+ export const COMMON_TITLE_MAX_WIDTH = 523;
3
3
  export const OBJECT_VALUE_PROPERTY_NAME = 'value';
4
4
  export const START_TIME = 'start';
5
5
  export const END_TIME = 'end';
@@ -1,4 +1,4 @@
1
1
  import { FormValue, Spec, StringSpec } from '../../core';
2
2
  export declare const isNotEmptyValue: (value: FormValue | undefined, spec: Spec | undefined) => boolean;
3
- export declare const prepareSpec: <Type extends Spec<any, undefined, undefined>>(spec: Type, parseJsonDefaultValue?: boolean) => Type;
3
+ export declare const prepareSpec: <Type extends Spec<any, undefined, undefined>>(spec: Type, parseJsonDefaultValue?: boolean, overridePatternError?: ((pattern?: string) => string) | undefined) => Type;
4
4
  export declare const isCorrectSizeParams: (spec: StringSpec) => boolean;
@@ -4,6 +4,7 @@ import isNil from 'lodash/isNil';
4
4
  import isObject from 'lodash/isObject';
5
5
  import isObjectLike from 'lodash/isObjectLike';
6
6
  import isString from 'lodash/isString';
7
+ import isEmpty from 'lodash/isEmpty';
7
8
  import { SpecTypes, isArraySpec, isObjectSpec, isStringSpec, } from '../../core';
8
9
  import { isFloat } from '../validators/helpers';
9
10
  import { divide } from './bigIntMath';
@@ -35,7 +36,7 @@ export const isNotEmptyValue = (value, spec) => {
35
36
  }
36
37
  return true;
37
38
  };
38
- export const prepareSpec = (spec, parseJsonDefaultValue) => {
39
+ export const prepareSpec = (spec, parseJsonDefaultValue, overridePatternError) => {
39
40
  var _a, _b, _c, _d, _e, _f, _g, _h;
40
41
  if (isObjectLike(spec)) {
41
42
  const result = cloneDeep(spec);
@@ -95,8 +96,11 @@ export const prepareSpec = (spec, parseJsonDefaultValue) => {
95
96
  result.minLength = BigInt(result.minLength);
96
97
  }
97
98
  }
99
+ if (!isEmpty(result.pattern) && isEmpty(result.patternError) && overridePatternError) {
100
+ result.patternError = overridePatternError(result.pattern);
101
+ }
98
102
  if (result.items) {
99
- result.items = prepareSpec(result.items, parseJsonDefaultValue);
103
+ result.items = prepareSpec(result.items, parseJsonDefaultValue, overridePatternError);
100
104
  }
101
105
  if (result.maximum === 0 && result.minimum === 0) {
102
106
  result.maximum = undefined;
@@ -115,7 +119,7 @@ export const prepareSpec = (spec, parseJsonDefaultValue) => {
115
119
  }
116
120
  if (isObjectLike(result.properties)) {
117
121
  Object.keys(result.properties).forEach((key) => {
118
- result.properties[key] = prepareSpec(result.properties[key], parseJsonDefaultValue);
122
+ result.properties[key] = prepareSpec(result.properties[key], parseJsonDefaultValue, overridePatternError);
119
123
  });
120
124
  }
121
125
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dynamic-forms",
3
- "version": "4.7.3",
3
+ "version": "4.9.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/cjs/index.js",