@hw-component/form 0.0.4-beta-v4 → 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 (50) hide show
  1. package/es/DialogForm/hooks.d.ts +1 -1
  2. package/es/Form/HFormConnect.js +4 -2
  3. package/es/Form/hooks/index.d.ts +7 -0
  4. package/es/Form/hooks/index.js +26 -3
  5. package/es/Form/hooks/useHForm.js +19 -5
  6. package/es/Form/hooks/useInitConfigData.d.ts +6 -2
  7. package/es/Form/hooks/useInitConfigData.js +59 -6
  8. package/es/Form/index.d.ts +1 -1
  9. package/es/Form/index.js +16 -7
  10. package/es/Form/modal.d.ts +8 -0
  11. package/es/Input/SelectInput.d.ts +1 -1
  12. package/es/Select/hooks/norHooks.d.ts +3 -3
  13. package/es/Select/hooks/norHooks.js +29 -12
  14. package/es/Select/index.js +6 -3
  15. package/es/Select/modal.d.ts +6 -1
  16. package/es/modal.d.ts +1 -1
  17. package/lib/DialogForm/hooks.d.ts +1 -1
  18. package/lib/Form/HFormConnect.js +4 -2
  19. package/lib/Form/hooks/index.d.ts +7 -0
  20. package/lib/Form/hooks/index.js +26 -2
  21. package/lib/Form/hooks/useHForm.js +19 -5
  22. package/lib/Form/hooks/useInitConfigData.d.ts +6 -2
  23. package/lib/Form/hooks/useInitConfigData.js +59 -6
  24. package/lib/Form/index.d.ts +1 -1
  25. package/lib/Form/index.js +15 -6
  26. package/lib/Form/modal.d.ts +8 -0
  27. package/lib/Input/SelectInput.d.ts +1 -1
  28. package/lib/Select/hooks/norHooks.d.ts +3 -3
  29. package/lib/Select/hooks/norHooks.js +29 -12
  30. package/lib/Select/index.js +6 -3
  31. package/lib/Select/modal.d.ts +6 -1
  32. package/lib/modal.d.ts +1 -1
  33. package/package.json +1 -1
  34. package/src/components/DialogForm/ModalForm.tsx +2 -2
  35. package/src/components/DialogForm/hooks.ts +5 -5
  36. package/src/components/DialogForm/modal.ts +2 -2
  37. package/src/components/Form/HFormConnect.tsx +2 -2
  38. package/src/components/Form/hooks/index.ts +36 -0
  39. package/src/components/Form/hooks/useHForm.ts +13 -4
  40. package/src/components/Form/hooks/useInitConfigData.tsx +79 -2
  41. package/src/components/Form/index.tsx +16 -6
  42. package/src/components/Form/modal.ts +9 -2
  43. package/src/components/Input/SelectInput.tsx +0 -1
  44. package/src/components/Select/hooks/norHooks.ts +12 -9
  45. package/src/components/Select/index.tsx +3 -0
  46. package/src/components/Select/modal.ts +7 -1
  47. package/src/components/modal.ts +4 -1
  48. package/src/pages/Form/index.tsx +10 -2
  49. package/src/pages/ModalForm/index.tsx +0 -11
  50. package/src/pages/Select/index.tsx +0 -1
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import type { DialogFormProps, HDialogFormInstance, ModifyPropsModal } from "./modal";
3
- export declare const useModifyProps: ({ visible, configData, initialValues, dialogForm, afterClose, params, title }: ModifyPropsModal) => {
3
+ export declare const useModifyProps: ({ visible, configData, initialValues, dialogForm, afterClose, params, title, }: ModifyPropsModal) => {
4
4
  modalFormData: import("../Form/modal").HItemProps[];
5
5
  modalVisible: boolean | undefined;
6
6
  setModalVisible: import("react").Dispatch<import("react").SetStateAction<boolean | undefined>>;
@@ -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;
@@ -5,5 +5,5 @@ export declare enum SelectInputType {
5
5
  select = 1
6
6
  }
7
7
  export declare const Index: ({ selectProps, value, onChange, valueName, addFormat, addDispatchListener, ...props }: HSelectInputProps) => JSX.Element;
8
- declare const _default: import("react").ForwardRefExoticComponent<import("@/components/Form/modal").HFormItemProps & import("react").RefAttributes<any>>;
8
+ declare const _default: import("react").ForwardRefExoticComponent<import("../Form/modal").HFormItemProps & import("react").RefAttributes<any>>;
9
9
  export default _default;
@@ -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,9 +2,11 @@
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';
9
+ import { useFormContext } from '../../Form/Context/index.js';
8
10
 
9
11
  var useOptionReq = function useOptionReq(_ref) {
10
12
  var manual = _ref.manual,
@@ -12,37 +14,48 @@ var useOptionReq = function useOptionReq(_ref) {
12
14
  options = _ref.options,
13
15
  serviceSearch = _ref.serviceSearch,
14
16
  showSearch = _ref.showSearch,
15
- 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;
21
+ var _useFormContext = useFormContext(),
22
+ form = _useFormContext.form;
16
23
  var _useState = useState(),
17
24
  _useState2 = _slicedToArray(_useState, 2),
18
25
  data = _useState2[0],
19
26
  setData = _useState2[1];
20
27
  var _useRequest = useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
21
- var params,
28
+ var requestParams,
29
+ _requestParams$params,
30
+ params,
31
+ values,
32
+ _requestParams$type,
22
33
  type,
34
+ formData,
23
35
  _args = arguments;
24
36
  return _regeneratorRuntime.wrap(function _callee$(_context) {
25
37
  while (1) switch (_context.prev = _context.next) {
26
38
  case 0:
27
- params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
28
- type = _args.length > 1 && _args[1] !== undefined ? _args[1] : "init";
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());
29
42
  if (type === "init") {
30
43
  setData(undefined);
31
44
  }
32
45
  if (!request) {
33
- _context.next = 5;
46
+ _context.next = 6;
34
47
  break;
35
48
  }
36
- return _context.abrupt("return", request(params));
37
- case 5:
38
- return _context.abrupt("return", _Promise.resolve(options));
49
+ return _context.abrupt("return", request(params, formData));
39
50
  case 6:
51
+ return _context.abrupt("return", _Promise.resolve(options));
52
+ case 7:
40
53
  case "end":
41
54
  return _context.stop();
42
55
  }
43
56
  }, _callee);
44
57
  })), {
45
- manual: manual,
58
+ manual: dispatchManual === false ? true : manual,
46
59
  debounceInterval: 300,
47
60
  onSuccess: function onSuccess(resultData) {
48
61
  setData(resultData);
@@ -53,11 +66,13 @@ var useOptionReq = function useOptionReq(_ref) {
53
66
  error = _useRequest.error;
54
67
  var reload = function reload(_ref3) {
55
68
  var changeOpts = _ref3.options,
56
- requestParams = _ref3.params;
69
+ params = _ref3.params;
57
70
  if (changeOpts) {
58
71
  return setData(changeOpts);
59
72
  }
60
- return run(requestParams);
73
+ return run({
74
+ params: params
75
+ });
61
76
  };
62
77
  var onSearch = function onSearch(inputValue) {
63
78
  if (!serviceSearch) {
@@ -65,7 +80,9 @@ var useOptionReq = function useOptionReq(_ref) {
65
80
  return;
66
81
  }
67
82
  run({
68
- inputValue: inputValue
83
+ params: {
84
+ inputValue: inputValue
85
+ }
69
86
  });
70
87
  };
71
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"];
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;
@@ -51,7 +51,9 @@ var Index = function Index(_ref) {
51
51
  _ref$noMatchItemRende = _ref.noMatchItemRender,
52
52
  noMatchItemRender = _ref$noMatchItemRende === void 0 ? defaultSelectConfig.noMatchItemRender : _ref$noMatchItemRende,
53
53
  allSelect = _ref.allSelect,
54
- addDispatchListener = _ref.addDispatchListener,
54
+ addDispatchListener = _ref.addDispatchListener;
55
+ _ref.addFormat;
56
+ var dispatch = _ref.dispatch,
55
57
  props = _objectWithoutProperties(_ref, _excluded);
56
58
  var _ref2 = (modeConfig === null || modeConfig === void 0 ? void 0 : modeConfig[mode || ""]) || {},
57
59
  icon = _ref2.icon,
@@ -71,7 +73,8 @@ var Index = function Index(_ref) {
71
73
  request: request,
72
74
  serviceSearch: serviceSearch,
73
75
  showSearch: showSearch,
74
- onSearch: propsOnSearch
76
+ onSearch: propsOnSearch,
77
+ dispatch: dispatch
75
78
  }),
76
79
  run = _useOptionReq.run,
77
80
  loading = _useOptionReq.loading,
@@ -2,6 +2,8 @@ import type { SelectProps } from "antd";
2
2
  import type React from "react";
3
3
  import type { PromiseFnResult } from "../modal";
4
4
  import type { argsFn } from "@/components/Form/modal";
5
+ import type { addFormatItemModal } from "@/components/Form/modal";
6
+ import type { DispatchModal } from "@/components/Form/modal";
5
7
  export type OptionType = Record<string, any>;
6
8
  export type PartialHSelectProps = Partial<HSelectProps>;
7
9
  export type RenderFn = (data: OptionType) => React.ReactNode;
@@ -13,7 +15,7 @@ export interface ModeConfig {
13
15
  multiple?: ModeConfigItem;
14
16
  tags?: ModeConfigItem;
15
17
  }
16
- export interface HSelectProps extends Omit<SelectProps, "options"> {
18
+ export interface HSelectProps extends Omit<SelectProps, "options" | "placeholder"> {
17
19
  style?: React.CSSProperties;
18
20
  request?: PromiseFnResult<any, OptionType[]>;
19
21
  manual?: boolean;
@@ -24,6 +26,9 @@ export interface HSelectProps extends Omit<SelectProps, "options"> {
24
26
  noMatchItemRender?: RenderFn;
25
27
  allSelect?: boolean;
26
28
  addDispatchListener?: (key: string, fn: argsFn) => void;
29
+ addFormat?: (format: Record<string, addFormatItemModal>) => void;
30
+ placeholder?: string;
31
+ dispatch?: DispatchModal;
27
32
  }
28
33
  export interface FilterDataModal {
29
34
  value: any;
package/es/modal.d.ts CHANGED
@@ -2,7 +2,7 @@ export interface ValueCheckMapModal {
2
2
  checked?: any;
3
3
  noChecked?: any;
4
4
  }
5
- export type PromiseFnResult<T = any, R = any> = (params: T) => Promise<R>;
5
+ export type PromiseFnResult<T = any, R = any> = (params: T, formDataValues?: any) => Promise<R>;
6
6
  export interface ValueSwitchMapModal {
7
7
  open?: any;
8
8
  close?: any;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import type { DialogFormProps, HDialogFormInstance, ModifyPropsModal } from "./modal";
3
- export declare const useModifyProps: ({ visible, configData, initialValues, dialogForm, afterClose, params, title }: ModifyPropsModal) => {
3
+ export declare const useModifyProps: ({ visible, configData, initialValues, dialogForm, afterClose, params, title, }: ModifyPropsModal) => {
4
4
  modalFormData: import("../Form/modal").HItemProps[];
5
5
  modalVisible: boolean | undefined;
6
6
  setModalVisible: import("react").Dispatch<import("react").SetStateAction<boolean | undefined>>;
@@ -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