@gravity-ui/dynamic-forms 4.3.0 → 4.5.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.
@@ -3,19 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DynamicField = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
+ const get_1 = tslib_1.__importDefault(require("lodash/get"));
6
7
  const isFunction_1 = tslib_1.__importDefault(require("lodash/isFunction"));
7
8
  const isString_1 = tslib_1.__importDefault(require("lodash/isString"));
8
- const get_1 = tslib_1.__importDefault(require("lodash/get"));
9
9
  const react_is_1 = require("react-is");
10
10
  const helpers_1 = require("../../helpers");
11
11
  const Controller_1 = require("./Controller");
12
12
  const hooks_1 = require("./hooks");
13
13
  const utils_1 = require("./utils");
14
- const DynamicField = ({ name, spec, config, Monaco, generateRandomValue, search, withoutInsertFFDebounce, mutators: externalMutators, __mirror, }) => {
14
+ const DynamicField = ({ name, spec, config, Monaco, generateRandomValue, search, withoutInsertFFDebounce, destroyOnUnregister = true, mutators: externalMutators, __mirror, }) => {
15
15
  const DynamicFormsCtx = (0, hooks_1.useCreateContext)();
16
16
  const SearchContext = (0, hooks_1.useCreateSearchContext)();
17
17
  const { tools, store } = (0, hooks_1.useStore)(name);
18
- const watcher = (0, hooks_1.useIntegrationFF)(store, withoutInsertFFDebounce);
18
+ const watcher = (0, hooks_1.useIntegrationFF)(store, withoutInsertFFDebounce, destroyOnUnregister);
19
19
  const { mutatorsStore, mutateDFState } = (0, hooks_1.useMutators)(externalMutators);
20
20
  const { store: searchStore, setField, removeField, isHiddenField } = (0, hooks_1.useSearchStore)();
21
21
  const context = react_1.default.useMemo(() => ({
@@ -5,11 +5,12 @@ const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const debounce_1 = tslib_1.__importDefault(require("lodash/debounce"));
7
7
  const get_1 = tslib_1.__importDefault(require("lodash/get"));
8
+ const isEqual_1 = tslib_1.__importDefault(require("lodash/isEqual"));
8
9
  const isFunction_1 = tslib_1.__importDefault(require("lodash/isFunction"));
9
10
  const values_1 = tslib_1.__importDefault(require("lodash/values"));
10
11
  const react_final_form_1 = require("react-final-form");
11
12
  const utils_1 = require("../utils");
12
- const useIntegrationFF = (store, withoutDebounce) => {
13
+ const useIntegrationFF = (store, withoutDebounce, destroyOnUnregister) => {
13
14
  const form = (0, react_final_form_1.useForm)();
14
15
  const watcher = react_1.default.useMemo(() => {
15
16
  const props = {
@@ -34,6 +35,7 @@ const useIntegrationFF = (store, withoutDebounce) => {
34
35
  }
35
36
  return error;
36
37
  },
38
+ isEqual: isEqual_1.default,
37
39
  };
38
40
  return react_1.default.createElement(react_final_form_1.Field, Object.assign({}, props));
39
41
  }, [store.name, store.errors]);
@@ -53,7 +55,7 @@ const useIntegrationFF = (store, withoutDebounce) => {
53
55
  }, [store.values]);
54
56
  react_1.default.useEffect(() => {
55
57
  return () => {
56
- if (store.name) {
58
+ if (store.name && destroyOnUnregister) {
57
59
  form.change(store.name, undefined);
58
60
  }
59
61
  };
@@ -10,6 +10,7 @@ export interface DynamicFieldProps {
10
10
  search?: string | ((spec: Spec, input: FieldValue, name: string) => boolean);
11
11
  generateRandomValue?: (spec: StringSpec) => string;
12
12
  withoutInsertFFDebounce?: boolean;
13
+ destroyOnUnregister?: boolean;
13
14
  mutators?: DynamicFormMutators;
14
15
  __mirror?: WonderMirror;
15
16
  }
@@ -1,17 +1,17 @@
1
1
  import React from 'react';
2
+ import get from 'lodash/get';
2
3
  import isFunction from 'lodash/isFunction';
3
4
  import isString from 'lodash/isString';
4
- import get from 'lodash/get';
5
5
  import { isValidElementType } from 'react-is';
6
6
  import { isCorrectSpec } from '../../helpers';
7
7
  import { Controller } from './Controller';
8
8
  import { useCreateContext, useCreateSearchContext, useDynamicFieldMirror, useIntegrationFF, useMutators, useSearchStore, useStore, } from './hooks';
9
9
  import { getDefaultSearchFunction, isCorrectConfig } from './utils';
10
- export const DynamicField = ({ name, spec, config, Monaco, generateRandomValue, search, withoutInsertFFDebounce, mutators: externalMutators, __mirror, }) => {
10
+ export const DynamicField = ({ name, spec, config, Monaco, generateRandomValue, search, withoutInsertFFDebounce, destroyOnUnregister = true, mutators: externalMutators, __mirror, }) => {
11
11
  const DynamicFormsCtx = useCreateContext();
12
12
  const SearchContext = useCreateSearchContext();
13
13
  const { tools, store } = useStore(name);
14
- const watcher = useIntegrationFF(store, withoutInsertFFDebounce);
14
+ const watcher = useIntegrationFF(store, withoutInsertFFDebounce, destroyOnUnregister);
15
15
  const { mutatorsStore, mutateDFState } = useMutators(externalMutators);
16
16
  const { store: searchStore, setField, removeField, isHiddenField } = useSearchStore();
17
17
  const context = React.useMemo(() => ({
@@ -1,2 +1,2 @@
1
1
  import { DynamicFieldStore } from '../types';
2
- export declare const useIntegrationFF: (store: DynamicFieldStore, withoutDebounce?: boolean) => JSX.Element;
2
+ export declare const useIntegrationFF: (store: DynamicFieldStore, withoutDebounce?: boolean, destroyOnUnregister?: boolean) => JSX.Element;
@@ -1,11 +1,12 @@
1
1
  import React from 'react';
2
2
  import debounce from 'lodash/debounce';
3
3
  import get from 'lodash/get';
4
+ import isEqual from 'lodash/isEqual';
4
5
  import isFunction from 'lodash/isFunction';
5
6
  import values from 'lodash/values';
6
7
  import { Field as FinalFormField, useForm } from 'react-final-form';
7
8
  import { transformArrOut } from '../utils';
8
- export const useIntegrationFF = (store, withoutDebounce) => {
9
+ export const useIntegrationFF = (store, withoutDebounce, destroyOnUnregister) => {
9
10
  const form = useForm();
10
11
  const watcher = React.useMemo(() => {
11
12
  const props = {
@@ -30,6 +31,7 @@ export const useIntegrationFF = (store, withoutDebounce) => {
30
31
  }
31
32
  return error;
32
33
  },
34
+ isEqual,
33
35
  };
34
36
  return React.createElement(FinalFormField, Object.assign({}, props));
35
37
  }, [store.name, store.errors]);
@@ -49,7 +51,7 @@ export const useIntegrationFF = (store, withoutDebounce) => {
49
51
  }, [store.values]);
50
52
  React.useEffect(() => {
51
53
  return () => {
52
- if (store.name) {
54
+ if (store.name && destroyOnUnregister) {
53
55
  form.change(store.name, undefined);
54
56
  }
55
57
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dynamic-forms",
3
- "version": "4.3.0",
3
+ "version": "4.5.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/cjs/index.js",
@@ -65,6 +65,8 @@
65
65
  "@storybook/preset-scss": "^1.0.3",
66
66
  "@storybook/react": "^7.0.27",
67
67
  "@storybook/react-webpack5": "^7.0.27",
68
+ "@swc/core": "^1.5.0",
69
+ "@swc/jest": "^0.2.36",
68
70
  "@testing-library/jest-dom": "^5.16.5",
69
71
  "@testing-library/react": "^14.0.0",
70
72
  "@testing-library/user-event": "^14.4.3",
@@ -84,7 +86,7 @@
84
86
  "gulp-replace": "^1.1.4",
85
87
  "gulp-typescript": "^6.0.0-alpha.1",
86
88
  "husky": "^7.0.4",
87
- "jest": "^29.5.0",
89
+ "jest": "^29.7.0",
88
90
  "jest-environment-jsdom": "^29.5.0",
89
91
  "jest-transform-css": "^6.0.1",
90
92
  "monaco-editor": "^0.30.1",