@gravity-ui/dynamic-forms 4.12.0 → 4.13.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 (31) hide show
  1. package/build/cjs/lib/core/components/Form/DynamicField.js +13 -1
  2. package/build/cjs/lib/core/components/Form/hooks/index.js +2 -0
  3. package/build/cjs/lib/core/components/Form/hooks/useFormShared.js +6 -0
  4. package/build/cjs/lib/core/components/Form/hooks/useFormSharedStore.js +11 -0
  5. package/build/cjs/lib/core/components/Form/index.js +2 -1
  6. package/build/cjs/lib/core/components/View/DynamicView.js +3 -1
  7. package/build/cjs/lib/core/components/View/hooks/index.js +2 -0
  8. package/build/cjs/lib/core/components/View/hooks/useViewShared.js +6 -0
  9. package/build/cjs/lib/core/components/View/hooks/useViewSharedStore.js +11 -0
  10. package/build/cjs/lib/core/components/View/index.js +2 -1
  11. package/build/esm/lib/core/components/Form/DynamicField.js +14 -2
  12. package/build/esm/lib/core/components/Form/hooks/index.d.ts +2 -0
  13. package/build/esm/lib/core/components/Form/hooks/index.js +2 -0
  14. package/build/esm/lib/core/components/Form/hooks/useFormShared.d.ts +4 -0
  15. package/build/esm/lib/core/components/Form/hooks/useFormShared.js +2 -0
  16. package/build/esm/lib/core/components/Form/hooks/useFormSharedStore.d.ts +4 -0
  17. package/build/esm/lib/core/components/Form/hooks/useFormSharedStore.js +6 -0
  18. package/build/esm/lib/core/components/Form/index.d.ts +1 -1
  19. package/build/esm/lib/core/components/Form/index.js +1 -1
  20. package/build/esm/lib/core/components/Form/types/context.d.ts +4 -0
  21. package/build/esm/lib/core/components/View/DynamicView.js +4 -2
  22. package/build/esm/lib/core/components/View/hooks/index.d.ts +2 -0
  23. package/build/esm/lib/core/components/View/hooks/index.js +2 -0
  24. package/build/esm/lib/core/components/View/hooks/useViewShared.d.ts +4 -0
  25. package/build/esm/lib/core/components/View/hooks/useViewShared.js +2 -0
  26. package/build/esm/lib/core/components/View/hooks/useViewSharedStore.d.ts +4 -0
  27. package/build/esm/lib/core/components/View/hooks/useViewSharedStore.js +6 -0
  28. package/build/esm/lib/core/components/View/index.d.ts +1 -1
  29. package/build/esm/lib/core/components/View/index.js +1 -1
  30. package/build/esm/lib/core/components/View/types/context.d.ts +4 -0
  31. package/package.json +2 -1
@@ -18,15 +18,27 @@ const DynamicField = ({ name, spec, config, Monaco, generateRandomValue, search,
18
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
+ const shared = (0, hooks_1.useFormSharedStore)();
21
22
  const context = react_1.default.useMemo(() => ({
22
23
  config,
23
24
  Monaco: (0, react_is_1.isValidElementType)(Monaco) ? Monaco : undefined,
24
25
  generateRandomValue,
25
26
  tools: Object.assign(Object.assign({}, tools), { mutateDFState }),
26
27
  store,
28
+ shared,
27
29
  mutatorsStore,
28
30
  __mirror,
29
- }), [tools, config, Monaco, __mirror, generateRandomValue, mutatorsStore, mutateDFState, store]);
31
+ }), [
32
+ tools,
33
+ shared,
34
+ config,
35
+ Monaco,
36
+ __mirror,
37
+ generateRandomValue,
38
+ mutatorsStore,
39
+ mutateDFState,
40
+ store,
41
+ ]);
30
42
  const searchContext = react_1.default.useMemo(() => ({
31
43
  setField,
32
44
  removeField,
@@ -5,6 +5,8 @@ tslib_1.__exportStar(require("./useControllerMirror"), exports);
5
5
  tslib_1.__exportStar(require("./useCreateContext"), exports);
6
6
  tslib_1.__exportStar(require("./useDynamicFieldMirror"), exports);
7
7
  tslib_1.__exportStar(require("./useDynamicFormsCtx"), exports);
8
+ tslib_1.__exportStar(require("./useFormShared"), exports);
9
+ tslib_1.__exportStar(require("./useFormSharedStore"), exports);
8
10
  tslib_1.__exportStar(require("./useGenerateRandomValue"), exports);
9
11
  tslib_1.__exportStar(require("./useIntegrationFF"), exports);
10
12
  tslib_1.__exportStar(require("./useMutateDFState"), exports);
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useFormShared = void 0;
4
+ const useDynamicFormsCtx_1 = require("./useDynamicFormsCtx");
5
+ const useFormShared = () => (0, useDynamicFormsCtx_1.useDynamicFormsCtx)().shared;
6
+ exports.useFormShared = useFormShared;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useFormSharedStore = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const useFormSharedStore = () => {
7
+ const [store, setStore] = react_1.default.useState({});
8
+ const onChangeShared = react_1.default.useCallback((name, value) => setStore((s) => (Object.assign(Object.assign({}, s), { [name]: value }))), [setStore]);
9
+ return { store, onChangeShared };
10
+ };
11
+ exports.useFormSharedStore = useFormSharedStore;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useStoreValue = exports.useMutateDFState = void 0;
3
+ exports.useFormShared = exports.useStoreValue = exports.useMutateDFState = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  tslib_1.__exportStar(require("./constants"), exports);
6
6
  tslib_1.__exportStar(require("./Controller"), exports);
@@ -8,5 +8,6 @@ tslib_1.__exportStar(require("./DynamicField"), exports);
8
8
  var hooks_1 = require("./hooks");
9
9
  Object.defineProperty(exports, "useMutateDFState", { enumerable: true, get: function () { return hooks_1.useMutateDFState; } });
10
10
  Object.defineProperty(exports, "useStoreValue", { enumerable: true, get: function () { return hooks_1.useStoreValue; } });
11
+ Object.defineProperty(exports, "useFormShared", { enumerable: true, get: function () { return hooks_1.useFormShared; } });
11
12
  tslib_1.__exportStar(require("./types"), exports);
12
13
  tslib_1.__exportStar(require("./utils"), exports);
@@ -10,13 +10,15 @@ const helpers_2 = require("./helpers");
10
10
  const hooks_1 = require("./hooks");
11
11
  const DynamicView = ({ value, spec, config, Link, Monaco, showLayoutDescription, }) => {
12
12
  const DynamicFormsCtx = (0, hooks_1.useCreateContext)();
13
+ const shared = (0, hooks_1.useViewSharedStore)();
13
14
  const context = react_1.default.useMemo(() => ({
14
15
  config,
15
16
  value,
16
17
  showLayoutDescription,
17
18
  Link,
18
19
  Monaco: (0, react_is_1.isValidElementType)(Monaco) ? Monaco : undefined,
19
- }), [config, value, Link, Monaco, showLayoutDescription]);
20
+ shared,
21
+ }), [config, value, Link, Monaco, showLayoutDescription, shared]);
20
22
  if ((0, helpers_1.isCorrectSpec)(spec) && (0, helpers_2.isCorrectViewConfig)(config)) {
21
23
  return (react_1.default.createElement(DynamicFormsCtx.Provider, { value: context },
22
24
  react_1.default.createElement(ViewController_1.ViewController, { spec: spec, name: "" })));
@@ -6,3 +6,5 @@ tslib_1.__exportStar(require("./useCreateContext"), exports);
6
6
  tslib_1.__exportStar(require("./useDynamicFormsCtx"), exports);
7
7
  tslib_1.__exportStar(require("./useRender"), exports);
8
8
  tslib_1.__exportStar(require("./useMonaco"), exports);
9
+ tslib_1.__exportStar(require("./useViewShared"), exports);
10
+ tslib_1.__exportStar(require("./useViewSharedStore"), exports);
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useViewShared = void 0;
4
+ const useDynamicFormsCtx_1 = require("./useDynamicFormsCtx");
5
+ const useViewShared = () => (0, useDynamicFormsCtx_1.useDynamicFormsCtx)().shared;
6
+ exports.useViewShared = useViewShared;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useViewSharedStore = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const useViewSharedStore = () => {
7
+ const [store, setStore] = react_1.default.useState({});
8
+ const onChangeShared = react_1.default.useCallback((name, value) => setStore((s) => (Object.assign(Object.assign({}, s), { [name]: value }))), [setStore]);
9
+ return { store, onChangeShared };
10
+ };
11
+ exports.useViewSharedStore = useViewSharedStore;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useDynamicFormsCtx = void 0;
3
+ exports.useViewShared = exports.useDynamicFormsCtx = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  tslib_1.__exportStar(require("./DynamicView"), exports);
6
6
  tslib_1.__exportStar(require("./ViewController"), exports);
@@ -8,3 +8,4 @@ tslib_1.__exportStar(require("./helpers"), exports);
8
8
  tslib_1.__exportStar(require("./types"), exports);
9
9
  var hooks_1 = require("./hooks");
10
10
  Object.defineProperty(exports, "useDynamicFormsCtx", { enumerable: true, get: function () { return hooks_1.useDynamicFormsCtx; } });
11
+ Object.defineProperty(exports, "useViewShared", { enumerable: true, get: function () { return hooks_1.useViewShared; } });
@@ -5,7 +5,7 @@ import isString from 'lodash/isString';
5
5
  import { isValidElementType } from 'react-is';
6
6
  import { isCorrectSpec } from '../../helpers';
7
7
  import { Controller } from './Controller';
8
- import { useCreateContext, useCreateSearchContext, useDynamicFieldMirror, useIntegrationFF, useMutators, useSearchStore, useStore, } from './hooks';
8
+ import { useCreateContext, useCreateSearchContext, useDynamicFieldMirror, useFormSharedStore, useIntegrationFF, useMutators, useSearchStore, useStore, } from './hooks';
9
9
  import { getDefaultSearchFunction, isCorrectConfig } from './utils';
10
10
  export const DynamicField = ({ name, spec, config, Monaco, generateRandomValue, search, withoutInsertFFDebounce, destroyOnUnregister = true, mutators: externalMutators, __mirror, }) => {
11
11
  const DynamicFormsCtx = useCreateContext();
@@ -14,15 +14,27 @@ export const DynamicField = ({ name, spec, config, Monaco, generateRandomValue,
14
14
  const watcher = useIntegrationFF(store, withoutInsertFFDebounce, destroyOnUnregister);
15
15
  const { mutatorsStore, mutateDFState } = useMutators(externalMutators);
16
16
  const { store: searchStore, setField, removeField, isHiddenField } = useSearchStore();
17
+ const shared = useFormSharedStore();
17
18
  const context = React.useMemo(() => ({
18
19
  config,
19
20
  Monaco: isValidElementType(Monaco) ? Monaco : undefined,
20
21
  generateRandomValue,
21
22
  tools: Object.assign(Object.assign({}, tools), { mutateDFState }),
22
23
  store,
24
+ shared,
23
25
  mutatorsStore,
24
26
  __mirror,
25
- }), [tools, config, Monaco, __mirror, generateRandomValue, mutatorsStore, mutateDFState, store]);
27
+ }), [
28
+ tools,
29
+ shared,
30
+ config,
31
+ Monaco,
32
+ __mirror,
33
+ generateRandomValue,
34
+ mutatorsStore,
35
+ mutateDFState,
36
+ store,
37
+ ]);
26
38
  const searchContext = React.useMemo(() => ({
27
39
  setField,
28
40
  removeField,
@@ -2,6 +2,8 @@ export * from './useControllerMirror';
2
2
  export * from './useCreateContext';
3
3
  export * from './useDynamicFieldMirror';
4
4
  export * from './useDynamicFormsCtx';
5
+ export * from './useFormShared';
6
+ export * from './useFormSharedStore';
5
7
  export * from './useGenerateRandomValue';
6
8
  export * from './useIntegrationFF';
7
9
  export * from './useMutateDFState';
@@ -2,6 +2,8 @@ export * from './useControllerMirror';
2
2
  export * from './useCreateContext';
3
3
  export * from './useDynamicFieldMirror';
4
4
  export * from './useDynamicFormsCtx';
5
+ export * from './useFormShared';
6
+ export * from './useFormSharedStore';
5
7
  export * from './useGenerateRandomValue';
6
8
  export * from './useIntegrationFF';
7
9
  export * from './useMutateDFState';
@@ -0,0 +1,4 @@
1
+ export declare const useFormShared: <SharedStore extends Record<string, any>>() => {
2
+ store: SharedStore;
3
+ onChangeShared: <Name extends keyof SharedStore, Value extends SharedStore[Name]>(name: Name, value: Value) => void;
4
+ };
@@ -0,0 +1,2 @@
1
+ import { useDynamicFormsCtx } from './useDynamicFormsCtx';
2
+ export const useFormShared = () => useDynamicFormsCtx().shared;
@@ -0,0 +1,4 @@
1
+ export declare const useFormSharedStore: () => {
2
+ store: {};
3
+ onChangeShared: (name: string, value: any) => void;
4
+ };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export const useFormSharedStore = () => {
3
+ const [store, setStore] = React.useState({});
4
+ const onChangeShared = React.useCallback((name, value) => setStore((s) => (Object.assign(Object.assign({}, s), { [name]: value }))), [setStore]);
5
+ return { store, onChangeShared };
6
+ };
@@ -1,6 +1,6 @@
1
1
  export * from './constants';
2
2
  export * from './Controller';
3
3
  export * from './DynamicField';
4
- export { useMutateDFState, useStoreValue } from './hooks';
4
+ export { useMutateDFState, useStoreValue, useFormShared } from './hooks';
5
5
  export * from './types';
6
6
  export * from './utils';
@@ -1,6 +1,6 @@
1
1
  export * from './constants';
2
2
  export * from './Controller';
3
3
  export * from './DynamicField';
4
- export { useMutateDFState, useStoreValue } from './hooks';
4
+ export { useMutateDFState, useStoreValue, useFormShared } from './hooks';
5
5
  export * from './types';
6
6
  export * from './utils';
@@ -14,6 +14,10 @@ export interface DynamicFormsContext {
14
14
  mutateDFState: (mutators: DynamicFormMutators) => void;
15
15
  };
16
16
  store: DynamicFieldStore;
17
+ shared: {
18
+ store: Record<string, any>;
19
+ onChangeShared: (name: string, value: any) => void;
20
+ };
17
21
  mutatorsStore: DynamicFormMutatorsStore;
18
22
  __mirror?: WonderMirror;
19
23
  }
@@ -3,16 +3,18 @@ import { isValidElementType } from 'react-is';
3
3
  import { isCorrectSpec } from '../../helpers';
4
4
  import { ViewController } from './ViewController';
5
5
  import { isCorrectViewConfig } from './helpers';
6
- import { useCreateContext } from './hooks';
6
+ import { useCreateContext, useViewSharedStore } from './hooks';
7
7
  export const DynamicView = ({ value, spec, config, Link, Monaco, showLayoutDescription, }) => {
8
8
  const DynamicFormsCtx = useCreateContext();
9
+ const shared = useViewSharedStore();
9
10
  const context = React.useMemo(() => ({
10
11
  config,
11
12
  value,
12
13
  showLayoutDescription,
13
14
  Link,
14
15
  Monaco: isValidElementType(Monaco) ? Monaco : undefined,
15
- }), [config, value, Link, Monaco, showLayoutDescription]);
16
+ shared,
17
+ }), [config, value, Link, Monaco, showLayoutDescription, shared]);
16
18
  if (isCorrectSpec(spec) && isCorrectViewConfig(config)) {
17
19
  return (React.createElement(DynamicFormsCtx.Provider, { value: context },
18
20
  React.createElement(ViewController, { spec: spec, name: "" })));
@@ -3,3 +3,5 @@ export * from './useCreateContext';
3
3
  export * from './useDynamicFormsCtx';
4
4
  export * from './useRender';
5
5
  export * from './useMonaco';
6
+ export * from './useViewShared';
7
+ export * from './useViewSharedStore';
@@ -3,3 +3,5 @@ export * from './useCreateContext';
3
3
  export * from './useDynamicFormsCtx';
4
4
  export * from './useRender';
5
5
  export * from './useMonaco';
6
+ export * from './useViewShared';
7
+ export * from './useViewSharedStore';
@@ -0,0 +1,4 @@
1
+ export declare const useViewShared: <SharedStore extends Record<string, any>>() => {
2
+ store: SharedStore;
3
+ onChangeShared: <Name extends keyof SharedStore, Value extends SharedStore[Name]>(name: Name, value: Value) => void;
4
+ };
@@ -0,0 +1,2 @@
1
+ import { useDynamicFormsCtx } from './useDynamicFormsCtx';
2
+ export const useViewShared = () => useDynamicFormsCtx().shared;
@@ -0,0 +1,4 @@
1
+ export declare const useViewSharedStore: () => {
2
+ store: {};
3
+ onChangeShared: (name: string, value: any) => void;
4
+ };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export const useViewSharedStore = () => {
3
+ const [store, setStore] = React.useState({});
4
+ const onChangeShared = React.useCallback((name, value) => setStore((s) => (Object.assign(Object.assign({}, s), { [name]: value }))), [setStore]);
5
+ return { store, onChangeShared };
6
+ };
@@ -2,4 +2,4 @@ export * from './DynamicView';
2
2
  export * from './ViewController';
3
3
  export * from './helpers';
4
4
  export * from './types';
5
- export { useDynamicFormsCtx } from './hooks';
5
+ export { useDynamicFormsCtx, useViewShared } from './hooks';
@@ -2,4 +2,4 @@ export * from './DynamicView';
2
2
  export * from './ViewController';
3
3
  export * from './helpers';
4
4
  export * from './types';
5
- export { useDynamicFormsCtx } from './hooks';
5
+ export { useDynamicFormsCtx, useViewShared } from './hooks';
@@ -11,4 +11,8 @@ export interface DynamicViewContext {
11
11
  link: Spec['viewSpec']['link'];
12
12
  }>;
13
13
  Monaco?: React.ComponentType<MonacoEditorProps>;
14
+ shared: {
15
+ store: Record<string, any>;
16
+ onChangeShared: (name: string, value: any) => void;
17
+ };
14
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dynamic-forms",
3
- "version": "4.12.0",
3
+ "version": "4.13.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/cjs/index.js",
@@ -38,6 +38,7 @@
38
38
  "playwright:install": "playwright install --with-deps",
39
39
  "playwright": "playwright test --config=playwright/playwright.config.ts",
40
40
  "playwright:update": "npm run playwright -- -u",
41
+ "playwright:clear-cache": "rm -rf ./playwright/.cache",
41
42
  "playwright:docker": "./scripts/playwright-docker.sh 'npm run playwright'",
42
43
  "playwright:docker:update": "./scripts/playwright-docker.sh 'npm run playwright:update'",
43
44
  "playwright:docker:clear-cache": "./scripts/playwright-docker.sh clear-cache"