@hw-component/form 0.0.4-beta-v5 → 0.0.4-beta-v6

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 (38) hide show
  1. package/es/Form/HFormConnect.js +4 -2
  2. package/es/Form/hooks/index.d.ts +7 -0
  3. package/es/Form/hooks/index.js +26 -3
  4. package/es/Form/hooks/useHForm.js +19 -5
  5. package/es/Form/hooks/useInitConfigData.d.ts +6 -2
  6. package/es/Form/hooks/useInitConfigData.js +59 -6
  7. package/es/Form/index.d.ts +1 -1
  8. package/es/Form/index.js +16 -7
  9. package/es/Form/modal.d.ts +8 -0
  10. package/es/Select/hooks/norHooks.d.ts +3 -3
  11. package/es/Select/hooks/norHooks.js +21 -9
  12. package/es/Select/index.js +5 -3
  13. package/es/Select/modal.d.ts +2 -0
  14. package/lib/Form/HFormConnect.js +4 -2
  15. package/lib/Form/hooks/index.d.ts +7 -0
  16. package/lib/Form/hooks/index.js +26 -2
  17. package/lib/Form/hooks/useHForm.js +19 -5
  18. package/lib/Form/hooks/useInitConfigData.d.ts +6 -2
  19. package/lib/Form/hooks/useInitConfigData.js +59 -6
  20. package/lib/Form/index.d.ts +1 -1
  21. package/lib/Form/index.js +15 -6
  22. package/lib/Form/modal.d.ts +8 -0
  23. package/lib/Select/hooks/norHooks.d.ts +3 -3
  24. package/lib/Select/hooks/norHooks.js +21 -9
  25. package/lib/Select/index.js +5 -3
  26. package/lib/Select/modal.d.ts +2 -0
  27. package/package.json +1 -1
  28. package/src/components/Form/HFormConnect.tsx +2 -2
  29. package/src/components/Form/hooks/index.ts +36 -0
  30. package/src/components/Form/hooks/useHForm.ts +13 -4
  31. package/src/components/Form/hooks/useInitConfigData.tsx +79 -2
  32. package/src/components/Form/index.tsx +16 -6
  33. package/src/components/Form/modal.ts +9 -2
  34. package/src/components/Select/hooks/norHooks.ts +9 -9
  35. package/src/components/Select/index.tsx +2 -0
  36. package/src/components/Select/modal.ts +2 -0
  37. package/src/pages/Form/index.tsx +8 -1
  38. package/src/pages/ModalForm/index.tsx +0 -11
@@ -35,7 +35,8 @@ var HFormConnect = (function (component) {
35
35
  format = _config$format === void 0 ? {} : _config$format;
36
36
  var Index = function Index(props, ref) {
37
37
  var _props$name = props.name,
38
- name = _props$name === void 0 ? "" : _props$name;
38
+ name = _props$name === void 0 ? "" : _props$name,
39
+ dispatch = props.dispatch;
39
40
  var _useFormContext = useFormContext(),
40
41
  form = _useFormContext.form,
41
42
  _useFormContext$value = _useFormContext.valueType,
@@ -49,7 +50,8 @@ var HFormConnect = (function (component) {
49
50
  var addDispatchListener = function addDispatchListener(key, fn) {
50
51
  form === null || form === void 0 ? void 0 : form.addDispatchListener({
51
52
  key: key,
52
- name: name
53
+ name: name,
54
+ dispatch: dispatch
53
55
  }, fn);
54
56
  };
55
57
  var Component = component;
@@ -1,4 +1,10 @@
1
1
  import type { HFormProps, HFormInstance } from "../modal";
2
+ import type { DispatchModal } from "../modal";
3
+ interface UseValuesChangeModal {
4
+ onValuesChange: HFormProps["onValuesChange"];
5
+ dispatch: DispatchModal;
6
+ form: HFormInstance;
7
+ }
2
8
  export declare const useCurrentForm: (form?: HFormInstance) => HFormInstance;
3
9
  type ParamsModal = Omit<HFormProps, "configData">;
4
10
  export declare const useInfoReq: ({ initialValues, infoRequest, form, params, request, onFinish, }: ParamsModal) => {
@@ -6,4 +12,5 @@ export declare const useInfoReq: ({ initialValues, infoRequest, form, params, re
6
12
  infoControl: import("@ahooksjs/use-request/lib/types").BaseResult<import("rc-field-form/lib/interface").Store, [reqParams?: any]>;
7
13
  };
8
14
  export declare const useDefaultComponents: () => any;
15
+ export declare const useValuesChange: ({ onValuesChange, dispatch, form, }: UseValuesChangeModal) => (changedValues: any, values: any) => void;
9
16
  export {};
@@ -1,14 +1,14 @@
1
1
  // welcome to hoo hoo hoo
2
- import _Object$keys from '@babel/runtime-corejs3/core-js/object/keys';
3
2
  import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js/object/get-own-property-symbols';
4
3
  import _filterInstanceProperty from '@babel/runtime-corejs3/core-js/instance/filter';
5
4
  import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js/object/get-own-property-descriptor';
6
- import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js/instance/for-each';
7
5
  import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js/object/get-own-property-descriptors';
8
6
  import _Object$defineProperties from '@babel/runtime-corejs3/core-js/object/define-properties';
9
7
  import _Object$defineProperty from '@babel/runtime-corejs3/core-js/object/define-property';
10
8
  import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
11
9
  import _asyncToGenerator from '@babel/runtime-corejs3/helpers/asyncToGenerator';
10
+ import _Object$keys from '@babel/runtime-corejs3/core-js/object/keys';
11
+ import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js/instance/for-each';
12
12
  import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
13
13
  import { useRequest } from 'ahooks';
14
14
  import useHForm from './useHForm.js';
@@ -114,6 +114,29 @@ var useDefaultComponents = function useDefaultComponents() {
114
114
  var defaultComponent = useFormConfigContext("defaultComponent");
115
115
  return _objectSpread(_objectSpread({}, componentConfig), defaultComponent);
116
116
  };
117
+ var useValuesChange = function useValuesChange(_ref4) {
118
+ var onValuesChange = _ref4.onValuesChange,
119
+ dispatch = _ref4.dispatch,
120
+ form = _ref4.form;
121
+ return function (changedValues, values) {
122
+ var changeKey = _Object$keys(changedValues)[0];
123
+ var dispatchItem = dispatch[changeKey];
124
+ if (!!dispatchItem) {
125
+ var dispatchKey = _Object$keys(dispatchItem);
126
+ _forEachInstanceProperty(dispatchKey).call(dispatchKey, function (name) {
127
+ var key = dispatchItem[name];
128
+ form.dispatch({
129
+ key: key,
130
+ name: name
131
+ }, {
132
+ changedValues: changedValues,
133
+ oldValues: values
134
+ });
135
+ });
136
+ }
137
+ onValuesChange === null || onValuesChange === void 0 ? void 0 : onValuesChange(changedValues, values);
138
+ };
139
+ };
117
140
 
118
- export { useCurrentForm, useDefaultComponents, useInfoReq };
141
+ export { useCurrentForm, useDefaultComponents, useInfoReq, useValuesChange };
119
142
  // powered by hdj
@@ -9,8 +9,8 @@ import _toConsumableArray from '@babel/runtime-corejs3/helpers/toConsumableArray
9
9
  import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
10
10
  import _slicedToArray from '@babel/runtime-corejs3/helpers/slicedToArray';
11
11
  import _Promise from '@babel/runtime-corejs3/core-js/promise';
12
- import _Object$keys from '@babel/runtime-corejs3/core-js/object/keys';
13
12
  import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js/instance/for-each';
13
+ import _Object$keys from '@babel/runtime-corejs3/core-js/object/keys';
14
14
  import _Reflect$deleteProperty from '@babel/runtime-corejs3/core-js/reflect/delete-property';
15
15
  import _concatInstanceProperty from '@babel/runtime-corejs3/core-js/instance/concat';
16
16
  import _mapInstanceProperty from '@babel/runtime-corejs3/core-js/instance/map';
@@ -26,9 +26,13 @@ var useHForm = (function () {
26
26
  return useMemo(function () {
27
27
  var formatSourceData = {};
28
28
  var dispatchSourceData = {};
29
+ var initDispatch = [];
29
30
  var cacheValues = {};
30
31
  var isLoading = false;
31
- var norAddItemDispatch = function norAddItemDispatch(name, fn) {
32
+ var norAddItemDispatch = function norAddItemDispatch(name, manual, fn) {
33
+ if (manual === false) {
34
+ initDispatch.push(fn);
35
+ }
32
36
  if (!name) {
33
37
  return {
34
38
  keysFn: {},
@@ -45,10 +49,17 @@ var useHForm = (function () {
45
49
  return _Promise.resolve(params);
46
50
  },
47
51
  initValues: function initValues() {
52
+ var newValue = {};
48
53
  if (cacheValues) {
49
- var newValue = this.formatValues(cacheValues);
54
+ newValue = this.formatValues(cacheValues);
50
55
  form.setFieldsValue(newValue);
51
56
  }
57
+ _forEachInstanceProperty(initDispatch).call(initDispatch, function (fn) {
58
+ fn({
59
+ changedValues: newValue,
60
+ oldValues: newValue
61
+ });
62
+ });
52
63
  isLoading = true;
53
64
  },
54
65
  addFormat: function addFormat(name, format) {
@@ -109,10 +120,13 @@ var useHForm = (function () {
109
120
  },
110
121
  addDispatchListener: function addDispatchListener(action, fn) {
111
122
  var key = action.key,
112
- name = action.name;
123
+ name = action.name,
124
+ _action$dispatch = action.dispatch,
125
+ dispatch = _action$dispatch === void 0 ? {} : _action$dispatch;
126
+ var manual = dispatch.manual;
113
127
  var items = dispatchSourceData[key];
114
128
  if (!items) {
115
- dispatchSourceData[key] = norAddItemDispatch(name, fn);
129
+ dispatchSourceData[key] = norAddItemDispatch(name, manual, fn);
116
130
  return;
117
131
  }
118
132
  var keysFn = items.keysFn,
@@ -1,4 +1,8 @@
1
- import type { HFormItemProps, HFormProps } from "../modal";
1
+ import type { HFormProps, HItemProps } from "../modal";
2
+ import type { DispatchSourceDataModal } from "../modal";
2
3
  type InitConfigModal = Required<Pick<HFormProps, "configData" | "form">>;
3
- declare const _default: ({ configData, form }: InitConfigModal) => HFormItemProps[];
4
+ declare const _default: ({ configData, form }: InitConfigModal) => {
5
+ newConfigData: HItemProps[];
6
+ dispatchSourceData: DispatchSourceDataModal;
7
+ };
4
8
  export default _default;
@@ -3,7 +3,6 @@ import _Object$keys from '@babel/runtime-corejs3/core-js/object/keys';
3
3
  import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js/object/get-own-property-symbols';
4
4
  import _filterInstanceProperty from '@babel/runtime-corejs3/core-js/instance/filter';
5
5
  import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js/object/get-own-property-descriptor';
6
- import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js/instance/for-each';
7
6
  import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js/object/get-own-property-descriptors';
8
7
  import _Object$defineProperties from '@babel/runtime-corejs3/core-js/object/define-properties';
9
8
  import _Object$defineProperty from '@babel/runtime-corejs3/core-js/object/define-property';
@@ -11,6 +10,8 @@ import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWitho
11
10
  import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
12
11
  import _mapInstanceProperty from '@babel/runtime-corejs3/core-js/instance/map';
13
12
  import _indexOfInstanceProperty from '@babel/runtime-corejs3/core-js/instance/index-of';
13
+ import _Array$isArray from '@babel/runtime-corejs3/core-js/array/is-array';
14
+ import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js/instance/for-each';
14
15
  import { useMemo } from 'react';
15
16
  import { placeholderConfig } from '../config.js';
16
17
  import { useDefaultComponents } from './index.js';
@@ -93,14 +94,66 @@ var itemControl = function itemControl(item, form, defaultComponents) {
93
94
  render: render
94
95
  });
95
96
  };
96
- var useInitConfigData = (function (_ref) {
97
- var configData = _ref.configData,
98
- form = _ref.form;
97
+ var itemDispatchProvider = function itemDispatchProvider(name, config, dispatchSourceData) {
98
+ var dependencies = config.dependencies,
99
+ fnKey = config.fnKey;
100
+ var itemDispatch = dispatchSourceData[dependencies];
101
+ if (!itemDispatch) {
102
+ return _defineProperty({}, dependencies, _defineProperty({}, name, fnKey));
103
+ }
104
+ var itemNameDispatch = _defineProperty({}, name, fnKey);
105
+ return _defineProperty({}, dependencies, _objectSpread(_objectSpread({}, itemDispatch), itemNameDispatch));
106
+ };
107
+ var dispatchProvider = function dispatchProvider(item, dispatchSourceData) {
108
+ var _item$name = item.name,
109
+ name = _item$name === void 0 ? "" : _item$name,
110
+ _item$dispatch = item.dispatch,
111
+ dispatch = _item$dispatch === void 0 ? {} : _item$dispatch,
112
+ _item$dependencies = item.dependencies,
113
+ dependencies = _item$dependencies === void 0 ? "allDependencies" : _item$dependencies;
114
+ var fnKey = dispatch.fnKey,
115
+ _dispatch$dependencie = dispatch.dependencies,
116
+ dispatchDependencies = _dispatch$dependencie === void 0 ? dependencies : _dispatch$dependencie,
117
+ _dispatch$manual = dispatch.manual,
118
+ manual = _dispatch$manual === void 0 ? true : _dispatch$manual;
119
+ if (!fnKey) {
120
+ return {};
121
+ }
122
+ if (_Array$isArray(dispatchDependencies)) {
123
+ var allDispatch = _objectSpread({}, dispatchSourceData);
124
+ _forEachInstanceProperty(dispatchDependencies).call(dispatchDependencies, function (key) {
125
+ var itemDispatch = itemDispatchProvider(name, {
126
+ dependencies: key,
127
+ fnKey: fnKey,
128
+ manual: manual
129
+ }, dispatchSourceData);
130
+ allDispatch = _objectSpread(_objectSpread({}, allDispatch), itemDispatch);
131
+ });
132
+ return allDispatch;
133
+ }
134
+ var itemDispatch = itemDispatchProvider(name, {
135
+ dependencies: dispatchDependencies,
136
+ fnKey: fnKey,
137
+ manual: manual
138
+ }, dispatchSourceData);
139
+ return _objectSpread(_objectSpread({}, dispatchSourceData), itemDispatch);
140
+ };
141
+ var useInitConfigData = (function (_ref3) {
142
+ var configData = _ref3.configData,
143
+ form = _ref3.form;
99
144
  var defaultComponents = useDefaultComponents();
100
145
  return useMemo(function () {
101
- return _mapInstanceProperty(configData).call(configData, function (item) {
102
- return itemControl(item, form, defaultComponents);
146
+ var newConfigData = [];
147
+ var dispatchSourceData = {};
148
+ _forEachInstanceProperty(configData).call(configData, function (item) {
149
+ var itemDispatch = dispatchProvider(item, dispatchSourceData);
150
+ dispatchSourceData = _objectSpread(_objectSpread({}, dispatchSourceData), itemDispatch);
151
+ newConfigData.push(itemControl(item, form, defaultComponents));
103
152
  });
153
+ return {
154
+ newConfigData: newConfigData,
155
+ dispatchSourceData: dispatchSourceData
156
+ };
104
157
  }, [configData]);
105
158
  });
106
159
 
@@ -1,3 +1,3 @@
1
1
  import type { HFormProps } from "./modal";
2
- declare const _default: ({ configData, labelWidth, form, request, onFinish, infoRequest, valueType, initialValues, params, ...props }: HFormProps) => JSX.Element;
2
+ declare const _default: ({ configData, labelWidth, form, request, onFinish, infoRequest, valueType, initialValues, params, onValuesChange, ...props }: HFormProps) => JSX.Element;
3
3
  export default _default;
package/es/Form/index.js CHANGED
@@ -14,13 +14,13 @@ import { jsx, jsxs } from 'react/jsx-runtime';
14
14
  import { useEffect, createElement } from 'react';
15
15
  import { Form } from 'antd';
16
16
  import Item from './FormItem/index.js';
17
- import { useCurrentForm, useInfoReq } from './hooks/index.js';
17
+ import { useCurrentForm, useInfoReq, useValuesChange } from './hooks/index.js';
18
18
  import { FormContext } from './Context/index.js';
19
19
  import Index from '../PageHandler/index.js';
20
20
  import useInitConfigData from './hooks/useInitConfigData.js';
21
21
  import InitSet from './InitSet.js';
22
22
 
23
- var _excluded = ["configData", "labelWidth", "form", "request", "onFinish", "infoRequest", "valueType", "initialValues", "params"];
23
+ var _excluded = ["configData", "labelWidth", "form", "request", "onFinish", "infoRequest", "valueType", "initialValues", "params", "onValuesChange"];
24
24
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
25
25
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
26
26
  var HForm = (function (_ref) {
@@ -35,12 +35,15 @@ var HForm = (function (_ref) {
35
35
  initialValues = _ref.initialValues,
36
36
  _ref$params = _ref.params,
37
37
  params = _ref$params === void 0 ? {} : _ref$params,
38
+ onValuesChange = _ref.onValuesChange,
38
39
  props = _objectWithoutProperties(_ref, _excluded);
39
40
  var hForm = useCurrentForm(form);
40
- var newConfigData = useInitConfigData({
41
- configData: configData,
42
- form: hForm
43
- });
41
+ var _useInitConfigData = useInitConfigData({
42
+ configData: configData,
43
+ form: hForm
44
+ }),
45
+ newConfigData = _useInitConfigData.newConfigData,
46
+ dispatchSourceData = _useInitConfigData.dispatchSourceData;
44
47
  var _useInfoReq = useInfoReq({
45
48
  initialValues: initialValues,
46
49
  request: request,
@@ -52,6 +55,11 @@ var HForm = (function (_ref) {
52
55
  }),
53
56
  subControl = _useInfoReq.subControl,
54
57
  infoControl = _useInfoReq.infoControl;
58
+ var valuesChange = useValuesChange({
59
+ onValuesChange: onValuesChange,
60
+ dispatch: dispatchSourceData,
61
+ form: hForm
62
+ });
55
63
  var run = subControl.run,
56
64
  loading = subControl.loading;
57
65
  var infoRun = infoControl.run,
@@ -76,7 +84,8 @@ var HForm = (function (_ref) {
76
84
  },
77
85
  children: jsxs(Form, _objectSpread(_objectSpread({
78
86
  form: hForm,
79
- onFinish: run
87
+ onFinish: run,
88
+ onValuesChange: valuesChange
80
89
  }, props), {}, {
81
90
  children: [_mapInstanceProperty(newConfigData).call(newConfigData, function (itemData, index) {
82
91
  var itemLabelWidth = itemData.labelWidth;
@@ -23,6 +23,12 @@ export interface HoverModal {
23
23
  type HelperModal = (form: HFormInstance) => React.ReactNode | string;
24
24
  export type HideModal = (form: HFormInstance) => boolean;
25
25
  export type AddDispatchListenerFn = (action: ActionModal, fn: argsFn) => void;
26
+ export type DispatchSourceDataModal = Record<string, Record<string, string>>;
27
+ export interface DispatchModal<T = string | string[]> {
28
+ fnKey?: string;
29
+ dependencies?: T;
30
+ manual?: boolean;
31
+ }
26
32
  export interface HItemProps extends Omit<FormItemProps, "name"> {
27
33
  type?: string;
28
34
  itemProps?: ItemPropsType;
@@ -33,6 +39,7 @@ export interface HItemProps extends Omit<FormItemProps, "name"> {
33
39
  hide?: boolean | HideModal;
34
40
  placeholder?: string | string[];
35
41
  name?: string;
42
+ dispatch?: DispatchModal;
36
43
  }
37
44
  export interface HFormProps<T = any, R = any> extends Omit<FormProps, "form" | "onFinish"> {
38
45
  configData: HItemProps[];
@@ -80,6 +87,7 @@ export interface IFormConfigContextProps {
80
87
  interface ActionModal {
81
88
  key: string;
82
89
  name?: string;
90
+ dispatch?: DispatchModal;
83
91
  }
84
92
  export interface HFormInstance extends FormInstance {
85
93
  addFormat: (name: string, formats?: FormatItemModal) => void;
@@ -3,14 +3,14 @@ interface ParamsModal {
3
3
  options?: OptionType[];
4
4
  params?: any;
5
5
  }
6
- export declare const useOptionReq: ({ manual, request, options, serviceSearch, showSearch, onSearch: propsOnSearch, }: PartialHSelectProps) => {
7
- run: (params?: any, type?: any) => Promise<OptionType[] | undefined>;
6
+ export declare const useOptionReq: ({ manual, request, options, serviceSearch, showSearch, onSearch: propsOnSearch, dispatch, }: PartialHSelectProps) => {
7
+ run: (requestParams?: any) => Promise<OptionType[] | undefined>;
8
8
  loading: boolean;
9
9
  error: Error | undefined;
10
10
  data: OptionType[] | undefined;
11
11
  onSearch: ((value: string) => void) | undefined;
12
12
  mathShowSearch: boolean | undefined;
13
- reload: ({ options: changeOpts, params: requestParams, }: ParamsModal) => void | Promise<OptionType[] | undefined>;
13
+ reload: ({ options: changeOpts, params }: ParamsModal) => void | Promise<OptionType[] | undefined>;
14
14
  };
15
15
  export declare const useFilterOption: ({ filterOption, serviceSearch, }: PartialHSelectProps) => boolean | import("rc-select/lib/Select").FilterFunc<import("rc-select/lib/Select").DefaultOptionType> | undefined;
16
16
  export {};
@@ -2,6 +2,7 @@
2
2
  import _asyncToGenerator from '@babel/runtime-corejs3/helpers/asyncToGenerator';
3
3
  import _slicedToArray from '@babel/runtime-corejs3/helpers/slicedToArray';
4
4
  import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
5
+ import _valuesInstanceProperty from '@babel/runtime-corejs3/core-js/instance/values';
5
6
  import _Promise from '@babel/runtime-corejs3/core-js/promise';
6
7
  import { useState, useEffect } from 'react';
7
8
  import { useRequest } from 'ahooks';
@@ -13,7 +14,10 @@ var useOptionReq = function useOptionReq(_ref) {
13
14
  options = _ref.options,
14
15
  serviceSearch = _ref.serviceSearch,
15
16
  showSearch = _ref.showSearch,
16
- propsOnSearch = _ref.onSearch;
17
+ propsOnSearch = _ref.onSearch,
18
+ _ref$dispatch = _ref.dispatch,
19
+ dispatch = _ref$dispatch === void 0 ? {} : _ref$dispatch;
20
+ var dispatchManual = dispatch.manual;
17
21
  var _useFormContext = useFormContext(),
18
22
  form = _useFormContext.form;
19
23
  var _useState = useState(),
@@ -21,16 +25,20 @@ var useOptionReq = function useOptionReq(_ref) {
21
25
  data = _useState2[0],
22
26
  setData = _useState2[1];
23
27
  var _useRequest = useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
24
- var params,
28
+ var requestParams,
29
+ _requestParams$params,
30
+ params,
31
+ values,
32
+ _requestParams$type,
25
33
  type,
26
34
  formData,
27
35
  _args = arguments;
28
36
  return _regeneratorRuntime.wrap(function _callee$(_context) {
29
37
  while (1) switch (_context.prev = _context.next) {
30
38
  case 0:
31
- params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
32
- type = _args.length > 1 && _args[1] !== undefined ? _args[1] : "init";
33
- formData = form === null || form === void 0 ? void 0 : form.getFieldsValue();
39
+ requestParams = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
40
+ _requestParams$params = requestParams.params, params = _requestParams$params === void 0 ? {} : _requestParams$params, values = _valuesInstanceProperty(requestParams), _requestParams$type = requestParams.type, type = _requestParams$type === void 0 ? "init" : _requestParams$type;
41
+ formData = values || (form === null || form === void 0 ? void 0 : form.getFieldsValue());
34
42
  if (type === "init") {
35
43
  setData(undefined);
36
44
  }
@@ -47,7 +55,7 @@ var useOptionReq = function useOptionReq(_ref) {
47
55
  }
48
56
  }, _callee);
49
57
  })), {
50
- manual: manual,
58
+ manual: dispatchManual === false ? true : manual,
51
59
  debounceInterval: 300,
52
60
  onSuccess: function onSuccess(resultData) {
53
61
  setData(resultData);
@@ -58,11 +66,13 @@ var useOptionReq = function useOptionReq(_ref) {
58
66
  error = _useRequest.error;
59
67
  var reload = function reload(_ref3) {
60
68
  var changeOpts = _ref3.options,
61
- requestParams = _ref3.params;
69
+ params = _ref3.params;
62
70
  if (changeOpts) {
63
71
  return setData(changeOpts);
64
72
  }
65
- return run(requestParams);
73
+ return run({
74
+ params: params
75
+ });
66
76
  };
67
77
  var onSearch = function onSearch(inputValue) {
68
78
  if (!serviceSearch) {
@@ -70,7 +80,9 @@ var useOptionReq = function useOptionReq(_ref) {
70
80
  return;
71
81
  }
72
82
  run({
73
- inputValue: inputValue
83
+ params: {
84
+ inputValue: inputValue
85
+ }
74
86
  });
75
87
  };
76
88
  useEffect(function () {
@@ -20,7 +20,7 @@ import Index$2 from './components/AllSelect.js';
20
20
  import { useMatchConfigProps, useChangeOptions } from '../hooks/index.js';
21
21
  import HFormConnect from '../Form/HFormConnect.js';
22
22
 
23
- var _excluded = ["style", "mode", "options", "modeConfig", "value", "onChange", "fieldNames", "request", "manual", "optionLabelProp", "filterProvider", "optionFilterProp", "serviceSearch", "onSearch", "filterOption", "showSearch", "labelInValue", "noMatchItemRender", "allSelect", "addDispatchListener", "addFormat"];
23
+ var _excluded = ["style", "mode", "options", "modeConfig", "value", "onChange", "fieldNames", "request", "manual", "optionLabelProp", "filterProvider", "optionFilterProp", "serviceSearch", "onSearch", "filterOption", "showSearch", "labelInValue", "noMatchItemRender", "allSelect", "addDispatchListener", "addFormat", "dispatch"];
24
24
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
25
25
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
26
26
  var Option = Select.Option;
@@ -53,7 +53,8 @@ var Index = function Index(_ref) {
53
53
  allSelect = _ref.allSelect,
54
54
  addDispatchListener = _ref.addDispatchListener;
55
55
  _ref.addFormat;
56
- var props = _objectWithoutProperties(_ref, _excluded);
56
+ var dispatch = _ref.dispatch,
57
+ props = _objectWithoutProperties(_ref, _excluded);
57
58
  var _ref2 = (modeConfig === null || modeConfig === void 0 ? void 0 : modeConfig[mode || ""]) || {},
58
59
  icon = _ref2.icon,
59
60
  render = _ref2.render;
@@ -72,7 +73,8 @@ var Index = function Index(_ref) {
72
73
  request: request,
73
74
  serviceSearch: serviceSearch,
74
75
  showSearch: showSearch,
75
- onSearch: propsOnSearch
76
+ onSearch: propsOnSearch,
77
+ dispatch: dispatch
76
78
  }),
77
79
  run = _useOptionReq.run,
78
80
  loading = _useOptionReq.loading,
@@ -3,6 +3,7 @@ import type React from "react";
3
3
  import type { PromiseFnResult } from "../modal";
4
4
  import type { argsFn } from "@/components/Form/modal";
5
5
  import type { addFormatItemModal } from "@/components/Form/modal";
6
+ import type { DispatchModal } from "@/components/Form/modal";
6
7
  export type OptionType = Record<string, any>;
7
8
  export type PartialHSelectProps = Partial<HSelectProps>;
8
9
  export type RenderFn = (data: OptionType) => React.ReactNode;
@@ -27,6 +28,7 @@ export interface HSelectProps extends Omit<SelectProps, "options" | "placeholder
27
28
  addDispatchListener?: (key: string, fn: argsFn) => void;
28
29
  addFormat?: (format: Record<string, addFormatItemModal>) => void;
29
30
  placeholder?: string;
31
+ dispatch?: DispatchModal;
30
32
  }
31
33
  export interface FilterDataModal {
32
34
  value: any;
@@ -38,7 +38,8 @@ var HFormConnect = (function (component) {
38
38
  format = _config$format === void 0 ? {} : _config$format;
39
39
  var Index = function Index(props, ref) {
40
40
  var _props$name = props.name,
41
- name = _props$name === void 0 ? "" : _props$name;
41
+ name = _props$name === void 0 ? "" : _props$name,
42
+ dispatch = props.dispatch;
42
43
  var _useFormContext = index.useFormContext(),
43
44
  form = _useFormContext.form,
44
45
  _useFormContext$value = _useFormContext.valueType,
@@ -52,7 +53,8 @@ var HFormConnect = (function (component) {
52
53
  var addDispatchListener = function addDispatchListener(key, fn) {
53
54
  form === null || form === void 0 ? void 0 : form.addDispatchListener({
54
55
  key: key,
55
- name: name
56
+ name: name,
57
+ dispatch: dispatch
56
58
  }, fn);
57
59
  };
58
60
  var Component = component;
@@ -1,4 +1,10 @@
1
1
  import type { HFormProps, HFormInstance } from "../modal";
2
+ import type { DispatchModal } from "../modal";
3
+ interface UseValuesChangeModal {
4
+ onValuesChange: HFormProps["onValuesChange"];
5
+ dispatch: DispatchModal;
6
+ form: HFormInstance;
7
+ }
2
8
  export declare const useCurrentForm: (form?: HFormInstance) => HFormInstance;
3
9
  type ParamsModal = Omit<HFormProps, "configData">;
4
10
  export declare const useInfoReq: ({ initialValues, infoRequest, form, params, request, onFinish, }: ParamsModal) => {
@@ -6,4 +12,5 @@ export declare const useInfoReq: ({ initialValues, infoRequest, form, params, re
6
12
  infoControl: import("@ahooksjs/use-request/lib/types").BaseResult<import("rc-field-form/lib/interface").Store, [reqParams?: any]>;
7
13
  };
8
14
  export declare const useDefaultComponents: () => any;
15
+ export declare const useValuesChange: ({ onValuesChange, dispatch, form, }: UseValuesChangeModal) => (changedValues: any, values: any) => void;
9
16
  export {};
@@ -1,15 +1,15 @@
1
1
  'use strict';
2
2
 
3
- var _Object$keys = require('@babel/runtime-corejs3/core-js/object/keys');
4
3
  var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js/object/get-own-property-symbols');
5
4
  var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/filter');
6
5
  var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js/object/get-own-property-descriptor');
7
- var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/for-each');
8
6
  var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js/object/get-own-property-descriptors');
9
7
  var _Object$defineProperties = require('@babel/runtime-corejs3/core-js/object/define-properties');
10
8
  var _Object$defineProperty = require('@babel/runtime-corejs3/core-js/object/define-property');
11
9
  var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
12
10
  var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
11
+ var _Object$keys = require('@babel/runtime-corejs3/core-js/object/keys');
12
+ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/for-each');
13
13
  var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
14
14
  var ahooks = require('ahooks');
15
15
  var useHForm = require('./useHForm.js');
@@ -115,8 +115,32 @@ var useDefaultComponents = function useDefaultComponents() {
115
115
  var defaultComponent = FormConfigProvider.useFormConfigContext("defaultComponent");
116
116
  return _objectSpread(_objectSpread({}, config.default), defaultComponent);
117
117
  };
118
+ var useValuesChange = function useValuesChange(_ref4) {
119
+ var onValuesChange = _ref4.onValuesChange,
120
+ dispatch = _ref4.dispatch,
121
+ form = _ref4.form;
122
+ return function (changedValues, values) {
123
+ var changeKey = _Object$keys(changedValues)[0];
124
+ var dispatchItem = dispatch[changeKey];
125
+ if (!!dispatchItem) {
126
+ var dispatchKey = _Object$keys(dispatchItem);
127
+ _forEachInstanceProperty(dispatchKey).call(dispatchKey, function (name) {
128
+ var key = dispatchItem[name];
129
+ form.dispatch({
130
+ key: key,
131
+ name: name
132
+ }, {
133
+ changedValues: changedValues,
134
+ oldValues: values
135
+ });
136
+ });
137
+ }
138
+ onValuesChange === null || onValuesChange === void 0 ? void 0 : onValuesChange(changedValues, values);
139
+ };
140
+ };
118
141
 
119
142
  exports.useCurrentForm = useCurrentForm;
120
143
  exports.useDefaultComponents = useDefaultComponents;
121
144
  exports.useInfoReq = useInfoReq;
145
+ exports.useValuesChange = useValuesChange;
122
146
  // powered by h
@@ -12,8 +12,8 @@ var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArr
12
12
  var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
13
13
  var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
14
14
  var _Promise = require('@babel/runtime-corejs3/core-js/promise');
15
- var _Object$keys = require('@babel/runtime-corejs3/core-js/object/keys');
16
15
  var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/for-each');
16
+ var _Object$keys = require('@babel/runtime-corejs3/core-js/object/keys');
17
17
  var _Reflect$deleteProperty = require('@babel/runtime-corejs3/core-js/reflect/delete-property');
18
18
  var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/concat');
19
19
  var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/map');
@@ -29,9 +29,13 @@ var useHForm = (function () {
29
29
  return React.useMemo(function () {
30
30
  var formatSourceData = {};
31
31
  var dispatchSourceData = {};
32
+ var initDispatch = [];
32
33
  var cacheValues = {};
33
34
  var isLoading = false;
34
- var norAddItemDispatch = function norAddItemDispatch(name, fn) {
35
+ var norAddItemDispatch = function norAddItemDispatch(name, manual, fn) {
36
+ if (manual === false) {
37
+ initDispatch.push(fn);
38
+ }
35
39
  if (!name) {
36
40
  return {
37
41
  keysFn: {},
@@ -48,10 +52,17 @@ var useHForm = (function () {
48
52
  return _Promise.resolve(params);
49
53
  },
50
54
  initValues: function initValues() {
55
+ var newValue = {};
51
56
  if (cacheValues) {
52
- var newValue = this.formatValues(cacheValues);
57
+ newValue = this.formatValues(cacheValues);
53
58
  form.setFieldsValue(newValue);
54
59
  }
60
+ _forEachInstanceProperty(initDispatch).call(initDispatch, function (fn) {
61
+ fn({
62
+ changedValues: newValue,
63
+ oldValues: newValue
64
+ });
65
+ });
55
66
  isLoading = true;
56
67
  },
57
68
  addFormat: function addFormat(name, format) {
@@ -112,10 +123,13 @@ var useHForm = (function () {
112
123
  },
113
124
  addDispatchListener: function addDispatchListener(action, fn) {
114
125
  var key = action.key,
115
- name = action.name;
126
+ name = action.name,
127
+ _action$dispatch = action.dispatch,
128
+ dispatch = _action$dispatch === void 0 ? {} : _action$dispatch;
129
+ var manual = dispatch.manual;
116
130
  var items = dispatchSourceData[key];
117
131
  if (!items) {
118
- dispatchSourceData[key] = norAddItemDispatch(name, fn);
132
+ dispatchSourceData[key] = norAddItemDispatch(name, manual, fn);
119
133
  return;
120
134
  }
121
135
  var keysFn = items.keysFn,
@@ -1,4 +1,8 @@
1
- import type { HFormItemProps, HFormProps } from "../modal";
1
+ import type { HFormProps, HItemProps } from "../modal";
2
+ import type { DispatchSourceDataModal } from "../modal";
2
3
  type InitConfigModal = Required<Pick<HFormProps, "configData" | "form">>;
3
- declare const _default: ({ configData, form }: InitConfigModal) => HFormItemProps[];
4
+ declare const _default: ({ configData, form }: InitConfigModal) => {
5
+ newConfigData: HItemProps[];
6
+ dispatchSourceData: DispatchSourceDataModal;
7
+ };
4
8
  export default _default;