@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.
- package/es/DialogForm/hooks.d.ts +1 -1
- package/es/Form/HFormConnect.js +4 -2
- package/es/Form/hooks/index.d.ts +7 -0
- package/es/Form/hooks/index.js +26 -3
- package/es/Form/hooks/useHForm.js +19 -5
- package/es/Form/hooks/useInitConfigData.d.ts +6 -2
- package/es/Form/hooks/useInitConfigData.js +59 -6
- package/es/Form/index.d.ts +1 -1
- package/es/Form/index.js +16 -7
- package/es/Form/modal.d.ts +8 -0
- package/es/Input/SelectInput.d.ts +1 -1
- package/es/Select/hooks/norHooks.d.ts +3 -3
- package/es/Select/hooks/norHooks.js +29 -12
- package/es/Select/index.js +6 -3
- package/es/Select/modal.d.ts +6 -1
- package/es/modal.d.ts +1 -1
- package/lib/DialogForm/hooks.d.ts +1 -1
- package/lib/Form/HFormConnect.js +4 -2
- package/lib/Form/hooks/index.d.ts +7 -0
- package/lib/Form/hooks/index.js +26 -2
- package/lib/Form/hooks/useHForm.js +19 -5
- package/lib/Form/hooks/useInitConfigData.d.ts +6 -2
- package/lib/Form/hooks/useInitConfigData.js +59 -6
- package/lib/Form/index.d.ts +1 -1
- package/lib/Form/index.js +15 -6
- package/lib/Form/modal.d.ts +8 -0
- package/lib/Input/SelectInput.d.ts +1 -1
- package/lib/Select/hooks/norHooks.d.ts +3 -3
- package/lib/Select/hooks/norHooks.js +29 -12
- package/lib/Select/index.js +6 -3
- package/lib/Select/modal.d.ts +6 -1
- package/lib/modal.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/DialogForm/ModalForm.tsx +2 -2
- package/src/components/DialogForm/hooks.ts +5 -5
- package/src/components/DialogForm/modal.ts +2 -2
- package/src/components/Form/HFormConnect.tsx +2 -2
- package/src/components/Form/hooks/index.ts +36 -0
- package/src/components/Form/hooks/useHForm.ts +13 -4
- package/src/components/Form/hooks/useInitConfigData.tsx +79 -2
- package/src/components/Form/index.tsx +16 -6
- package/src/components/Form/modal.ts +9 -2
- package/src/components/Input/SelectInput.tsx +0 -1
- package/src/components/Select/hooks/norHooks.ts +12 -9
- package/src/components/Select/index.tsx +3 -0
- package/src/components/Select/modal.ts +7 -1
- package/src/components/modal.ts +4 -1
- package/src/pages/Form/index.tsx +10 -2
- package/src/pages/ModalForm/index.tsx +0 -11
- package/src/pages/Select/index.tsx +0 -1
|
@@ -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
|
-
|
|
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 {
|
|
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) =>
|
|
4
|
+
declare const _default: ({ configData, form }: InitConfigModal) => {
|
|
5
|
+
newConfigData: HItemProps[];
|
|
6
|
+
dispatchSourceData: DispatchSourceDataModal;
|
|
7
|
+
};
|
|
4
8
|
export default _default;
|
|
@@ -6,7 +6,6 @@ var _Object$keys = require('@babel/runtime-corejs3/core-js/object/keys');
|
|
|
6
6
|
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js/object/get-own-property-symbols');
|
|
7
7
|
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/filter');
|
|
8
8
|
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js/object/get-own-property-descriptor');
|
|
9
|
-
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/for-each');
|
|
10
9
|
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js/object/get-own-property-descriptors');
|
|
11
10
|
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js/object/define-properties');
|
|
12
11
|
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js/object/define-property');
|
|
@@ -14,6 +13,8 @@ var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWit
|
|
|
14
13
|
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
15
14
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/map');
|
|
16
15
|
var _indexOfInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/index-of');
|
|
16
|
+
var _Array$isArray = require('@babel/runtime-corejs3/core-js/array/is-array');
|
|
17
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/for-each');
|
|
17
18
|
var React = require('react');
|
|
18
19
|
var config = require('../config.js');
|
|
19
20
|
var index = require('./index.js');
|
|
@@ -96,14 +97,66 @@ var itemControl = function itemControl(item, form, defaultComponents) {
|
|
|
96
97
|
render: render
|
|
97
98
|
});
|
|
98
99
|
};
|
|
99
|
-
var
|
|
100
|
-
var
|
|
101
|
-
|
|
100
|
+
var itemDispatchProvider = function itemDispatchProvider(name, config, dispatchSourceData) {
|
|
101
|
+
var dependencies = config.dependencies,
|
|
102
|
+
fnKey = config.fnKey;
|
|
103
|
+
var itemDispatch = dispatchSourceData[dependencies];
|
|
104
|
+
if (!itemDispatch) {
|
|
105
|
+
return _defineProperty({}, dependencies, _defineProperty({}, name, fnKey));
|
|
106
|
+
}
|
|
107
|
+
var itemNameDispatch = _defineProperty({}, name, fnKey);
|
|
108
|
+
return _defineProperty({}, dependencies, _objectSpread(_objectSpread({}, itemDispatch), itemNameDispatch));
|
|
109
|
+
};
|
|
110
|
+
var dispatchProvider = function dispatchProvider(item, dispatchSourceData) {
|
|
111
|
+
var _item$name = item.name,
|
|
112
|
+
name = _item$name === void 0 ? "" : _item$name,
|
|
113
|
+
_item$dispatch = item.dispatch,
|
|
114
|
+
dispatch = _item$dispatch === void 0 ? {} : _item$dispatch,
|
|
115
|
+
_item$dependencies = item.dependencies,
|
|
116
|
+
dependencies = _item$dependencies === void 0 ? "allDependencies" : _item$dependencies;
|
|
117
|
+
var fnKey = dispatch.fnKey,
|
|
118
|
+
_dispatch$dependencie = dispatch.dependencies,
|
|
119
|
+
dispatchDependencies = _dispatch$dependencie === void 0 ? dependencies : _dispatch$dependencie,
|
|
120
|
+
_dispatch$manual = dispatch.manual,
|
|
121
|
+
manual = _dispatch$manual === void 0 ? true : _dispatch$manual;
|
|
122
|
+
if (!fnKey) {
|
|
123
|
+
return {};
|
|
124
|
+
}
|
|
125
|
+
if (_Array$isArray(dispatchDependencies)) {
|
|
126
|
+
var allDispatch = _objectSpread({}, dispatchSourceData);
|
|
127
|
+
_forEachInstanceProperty(dispatchDependencies).call(dispatchDependencies, function (key) {
|
|
128
|
+
var itemDispatch = itemDispatchProvider(name, {
|
|
129
|
+
dependencies: key,
|
|
130
|
+
fnKey: fnKey,
|
|
131
|
+
manual: manual
|
|
132
|
+
}, dispatchSourceData);
|
|
133
|
+
allDispatch = _objectSpread(_objectSpread({}, allDispatch), itemDispatch);
|
|
134
|
+
});
|
|
135
|
+
return allDispatch;
|
|
136
|
+
}
|
|
137
|
+
var itemDispatch = itemDispatchProvider(name, {
|
|
138
|
+
dependencies: dispatchDependencies,
|
|
139
|
+
fnKey: fnKey,
|
|
140
|
+
manual: manual
|
|
141
|
+
}, dispatchSourceData);
|
|
142
|
+
return _objectSpread(_objectSpread({}, dispatchSourceData), itemDispatch);
|
|
143
|
+
};
|
|
144
|
+
var useInitConfigData = (function (_ref3) {
|
|
145
|
+
var configData = _ref3.configData,
|
|
146
|
+
form = _ref3.form;
|
|
102
147
|
var defaultComponents = index.useDefaultComponents();
|
|
103
148
|
return React.useMemo(function () {
|
|
104
|
-
|
|
105
|
-
|
|
149
|
+
var newConfigData = [];
|
|
150
|
+
var dispatchSourceData = {};
|
|
151
|
+
_forEachInstanceProperty(configData).call(configData, function (item) {
|
|
152
|
+
var itemDispatch = dispatchProvider(item, dispatchSourceData);
|
|
153
|
+
dispatchSourceData = _objectSpread(_objectSpread({}, dispatchSourceData), itemDispatch);
|
|
154
|
+
newConfigData.push(itemControl(item, form, defaultComponents));
|
|
106
155
|
});
|
|
156
|
+
return {
|
|
157
|
+
newConfigData: newConfigData,
|
|
158
|
+
dispatchSourceData: dispatchSourceData
|
|
159
|
+
};
|
|
107
160
|
}, [configData]);
|
|
108
161
|
});
|
|
109
162
|
|
package/lib/Form/index.d.ts
CHANGED
|
@@ -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/lib/Form/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var index$1 = require('../PageHandler/index.js');
|
|
|
23
23
|
var useInitConfigData = require('./hooks/useInitConfigData.js');
|
|
24
24
|
var InitSet = require('./InitSet.js');
|
|
25
25
|
|
|
26
|
-
var _excluded = ["configData", "labelWidth", "form", "request", "onFinish", "infoRequest", "valueType", "initialValues", "params"];
|
|
26
|
+
var _excluded = ["configData", "labelWidth", "form", "request", "onFinish", "infoRequest", "valueType", "initialValues", "params", "onValuesChange"];
|
|
27
27
|
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; }
|
|
28
28
|
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; }
|
|
29
29
|
var HForm = (function (_ref) {
|
|
@@ -38,12 +38,15 @@ var HForm = (function (_ref) {
|
|
|
38
38
|
initialValues = _ref.initialValues,
|
|
39
39
|
_ref$params = _ref.params,
|
|
40
40
|
params = _ref$params === void 0 ? {} : _ref$params,
|
|
41
|
+
onValuesChange = _ref.onValuesChange,
|
|
41
42
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
42
43
|
var hForm = index.useCurrentForm(form);
|
|
43
|
-
var
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
var _useInitConfigData = useInitConfigData.default({
|
|
45
|
+
configData: configData,
|
|
46
|
+
form: hForm
|
|
47
|
+
}),
|
|
48
|
+
newConfigData = _useInitConfigData.newConfigData,
|
|
49
|
+
dispatchSourceData = _useInitConfigData.dispatchSourceData;
|
|
47
50
|
var _useInfoReq = index.useInfoReq({
|
|
48
51
|
initialValues: initialValues,
|
|
49
52
|
request: request,
|
|
@@ -55,6 +58,11 @@ var HForm = (function (_ref) {
|
|
|
55
58
|
}),
|
|
56
59
|
subControl = _useInfoReq.subControl,
|
|
57
60
|
infoControl = _useInfoReq.infoControl;
|
|
61
|
+
var valuesChange = index.useValuesChange({
|
|
62
|
+
onValuesChange: onValuesChange,
|
|
63
|
+
dispatch: dispatchSourceData,
|
|
64
|
+
form: hForm
|
|
65
|
+
});
|
|
58
66
|
var run = subControl.run,
|
|
59
67
|
loading = subControl.loading;
|
|
60
68
|
var infoRun = infoControl.run,
|
|
@@ -79,7 +87,8 @@ var HForm = (function (_ref) {
|
|
|
79
87
|
},
|
|
80
88
|
children: jsxRuntime.jsxs(antd.Form, _objectSpread(_objectSpread({
|
|
81
89
|
form: hForm,
|
|
82
|
-
onFinish: run
|
|
90
|
+
onFinish: run,
|
|
91
|
+
onValuesChange: valuesChange
|
|
83
92
|
}, props), {}, {
|
|
84
93
|
children: [_mapInstanceProperty(newConfigData).call(newConfigData, function (itemData, index) {
|
|
85
94
|
var itemLabelWidth = itemData.labelWidth;
|
package/lib/Form/modal.d.ts
CHANGED
|
@@ -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("
|
|
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: (
|
|
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
|
|
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 {};
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
|
|
4
4
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
5
5
|
var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
|
|
6
|
+
var _valuesInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/values');
|
|
6
7
|
var _Promise = require('@babel/runtime-corejs3/core-js/promise');
|
|
7
8
|
var React = require('react');
|
|
8
9
|
var ahooks = require('ahooks');
|
|
10
|
+
var index = require('../../Form/Context/index.js');
|
|
9
11
|
|
|
10
12
|
var useOptionReq = function useOptionReq(_ref) {
|
|
11
13
|
var manual = _ref.manual,
|
|
@@ -13,37 +15,48 @@ var useOptionReq = function useOptionReq(_ref) {
|
|
|
13
15
|
options = _ref.options,
|
|
14
16
|
serviceSearch = _ref.serviceSearch,
|
|
15
17
|
showSearch = _ref.showSearch,
|
|
16
|
-
propsOnSearch = _ref.onSearch
|
|
18
|
+
propsOnSearch = _ref.onSearch,
|
|
19
|
+
_ref$dispatch = _ref.dispatch,
|
|
20
|
+
dispatch = _ref$dispatch === void 0 ? {} : _ref$dispatch;
|
|
21
|
+
var dispatchManual = dispatch.manual;
|
|
22
|
+
var _useFormContext = index.useFormContext(),
|
|
23
|
+
form = _useFormContext.form;
|
|
17
24
|
var _useState = React.useState(),
|
|
18
25
|
_useState2 = _slicedToArray(_useState, 2),
|
|
19
26
|
data = _useState2[0],
|
|
20
27
|
setData = _useState2[1];
|
|
21
28
|
var _useRequest = ahooks.useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
22
|
-
var
|
|
29
|
+
var requestParams,
|
|
30
|
+
_requestParams$params,
|
|
31
|
+
params,
|
|
32
|
+
values,
|
|
33
|
+
_requestParams$type,
|
|
23
34
|
type,
|
|
35
|
+
formData,
|
|
24
36
|
_args = arguments;
|
|
25
37
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
26
38
|
while (1) switch (_context.prev = _context.next) {
|
|
27
39
|
case 0:
|
|
28
|
-
|
|
29
|
-
|
|
40
|
+
requestParams = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
|
|
41
|
+
_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;
|
|
42
|
+
formData = values || (form === null || form === void 0 ? void 0 : form.getFieldsValue());
|
|
30
43
|
if (type === "init") {
|
|
31
44
|
setData(undefined);
|
|
32
45
|
}
|
|
33
46
|
if (!request) {
|
|
34
|
-
_context.next =
|
|
47
|
+
_context.next = 6;
|
|
35
48
|
break;
|
|
36
49
|
}
|
|
37
|
-
return _context.abrupt("return", request(params));
|
|
38
|
-
case 5:
|
|
39
|
-
return _context.abrupt("return", _Promise.resolve(options));
|
|
50
|
+
return _context.abrupt("return", request(params, formData));
|
|
40
51
|
case 6:
|
|
52
|
+
return _context.abrupt("return", _Promise.resolve(options));
|
|
53
|
+
case 7:
|
|
41
54
|
case "end":
|
|
42
55
|
return _context.stop();
|
|
43
56
|
}
|
|
44
57
|
}, _callee);
|
|
45
58
|
})), {
|
|
46
|
-
manual: manual,
|
|
59
|
+
manual: dispatchManual === false ? true : manual,
|
|
47
60
|
debounceInterval: 300,
|
|
48
61
|
onSuccess: function onSuccess(resultData) {
|
|
49
62
|
setData(resultData);
|
|
@@ -54,11 +67,13 @@ var useOptionReq = function useOptionReq(_ref) {
|
|
|
54
67
|
error = _useRequest.error;
|
|
55
68
|
var reload = function reload(_ref3) {
|
|
56
69
|
var changeOpts = _ref3.options,
|
|
57
|
-
|
|
70
|
+
params = _ref3.params;
|
|
58
71
|
if (changeOpts) {
|
|
59
72
|
return setData(changeOpts);
|
|
60
73
|
}
|
|
61
|
-
return run(
|
|
74
|
+
return run({
|
|
75
|
+
params: params
|
|
76
|
+
});
|
|
62
77
|
};
|
|
63
78
|
var onSearch = function onSearch(inputValue) {
|
|
64
79
|
if (!serviceSearch) {
|
|
@@ -66,7 +81,9 @@ var useOptionReq = function useOptionReq(_ref) {
|
|
|
66
81
|
return;
|
|
67
82
|
}
|
|
68
83
|
run({
|
|
69
|
-
|
|
84
|
+
params: {
|
|
85
|
+
inputValue: inputValue
|
|
86
|
+
}
|
|
70
87
|
});
|
|
71
88
|
};
|
|
72
89
|
React.useEffect(function () {
|
package/lib/Select/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var AllSelect = require('./components/AllSelect.js');
|
|
|
23
23
|
var index = require('../hooks/index.js');
|
|
24
24
|
var HFormConnect = require('../Form/HFormConnect.js');
|
|
25
25
|
|
|
26
|
-
var _excluded = ["style", "mode", "options", "modeConfig", "value", "onChange", "fieldNames", "request", "manual", "optionLabelProp", "filterProvider", "optionFilterProp", "serviceSearch", "onSearch", "filterOption", "showSearch", "labelInValue", "noMatchItemRender", "allSelect", "addDispatchListener"];
|
|
26
|
+
var _excluded = ["style", "mode", "options", "modeConfig", "value", "onChange", "fieldNames", "request", "manual", "optionLabelProp", "filterProvider", "optionFilterProp", "serviceSearch", "onSearch", "filterOption", "showSearch", "labelInValue", "noMatchItemRender", "allSelect", "addDispatchListener", "addFormat", "dispatch"];
|
|
27
27
|
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; }
|
|
28
28
|
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; }
|
|
29
29
|
var Option = antd.Select.Option;
|
|
@@ -54,7 +54,9 @@ var Index = function Index(_ref) {
|
|
|
54
54
|
_ref$noMatchItemRende = _ref.noMatchItemRender,
|
|
55
55
|
noMatchItemRender = _ref$noMatchItemRende === void 0 ? defaultConfig.defaultSelectConfig.noMatchItemRender : _ref$noMatchItemRende,
|
|
56
56
|
allSelect = _ref.allSelect,
|
|
57
|
-
addDispatchListener = _ref.addDispatchListener
|
|
57
|
+
addDispatchListener = _ref.addDispatchListener;
|
|
58
|
+
_ref.addFormat;
|
|
59
|
+
var dispatch = _ref.dispatch,
|
|
58
60
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
59
61
|
var _ref2 = (modeConfig === null || modeConfig === void 0 ? void 0 : modeConfig[mode || ""]) || {},
|
|
60
62
|
icon = _ref2.icon,
|
|
@@ -74,7 +76,8 @@ var Index = function Index(_ref) {
|
|
|
74
76
|
request: request,
|
|
75
77
|
serviceSearch: serviceSearch,
|
|
76
78
|
showSearch: showSearch,
|
|
77
|
-
onSearch: propsOnSearch
|
|
79
|
+
onSearch: propsOnSearch,
|
|
80
|
+
dispatch: dispatch
|
|
78
81
|
}),
|
|
79
82
|
run = _useOptionReq.run,
|
|
80
83
|
loading = _useOptionReq.loading,
|
package/lib/Select/modal.d.ts
CHANGED
|
@@ -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/lib/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;
|
package/package.json
CHANGED
|
@@ -25,14 +25,14 @@ export default ({
|
|
|
25
25
|
setModalVisible,
|
|
26
26
|
initValue,
|
|
27
27
|
formParams,
|
|
28
|
-
title:modalTitle
|
|
28
|
+
title: modalTitle,
|
|
29
29
|
} = useModifyProps({
|
|
30
30
|
configData,
|
|
31
31
|
visible,
|
|
32
32
|
initialValues,
|
|
33
33
|
dialogForm: currentForm,
|
|
34
34
|
params,
|
|
35
|
-
title
|
|
35
|
+
title,
|
|
36
36
|
});
|
|
37
37
|
const cancel = () => {
|
|
38
38
|
if (onCancel) {
|
|
@@ -14,13 +14,13 @@ export const useModifyProps = ({
|
|
|
14
14
|
dialogForm,
|
|
15
15
|
afterClose,
|
|
16
16
|
params,
|
|
17
|
-
title
|
|
17
|
+
title,
|
|
18
18
|
}: ModifyPropsModal) => {
|
|
19
19
|
const [modalVisible, setModalVisible] = useState(visible);
|
|
20
20
|
const [modalFormData, setModalFormData] = useState(configData);
|
|
21
21
|
const [initValue, setInitValue] = useState(initialValues);
|
|
22
22
|
const [formParams, setFormParams] = useState(params);
|
|
23
|
-
const [modalTitle,setModalTitle]=useState(title)
|
|
23
|
+
const [modalTitle, setModalTitle] = useState(title);
|
|
24
24
|
const onAfterClose = () => {
|
|
25
25
|
setTimeout(() => {
|
|
26
26
|
dialogForm.resetFields();
|
|
@@ -47,7 +47,7 @@ export const useModifyProps = ({
|
|
|
47
47
|
configData: changeConfigData,
|
|
48
48
|
initialValues: changeInitialValues,
|
|
49
49
|
params: changeParams,
|
|
50
|
-
title:changeTitle
|
|
50
|
+
title: changeTitle,
|
|
51
51
|
} = showParams;
|
|
52
52
|
if (!!changeConfigData) {
|
|
53
53
|
setModalFormData(changeConfigData);
|
|
@@ -55,7 +55,7 @@ export const useModifyProps = ({
|
|
|
55
55
|
if (!!changeParams) {
|
|
56
56
|
setFormParams(changeParams);
|
|
57
57
|
}
|
|
58
|
-
if (!!changeTitle){
|
|
58
|
+
if (!!changeTitle) {
|
|
59
59
|
setModalTitle(changeTitle);
|
|
60
60
|
}
|
|
61
61
|
setInitValue(changeInitialValues);
|
|
@@ -75,7 +75,7 @@ export const useModifyProps = ({
|
|
|
75
75
|
setInitValue,
|
|
76
76
|
onAfterClose,
|
|
77
77
|
formParams,
|
|
78
|
-
title:modalTitle
|
|
78
|
+
title: modalTitle,
|
|
79
79
|
};
|
|
80
80
|
};
|
|
81
81
|
export const useHDialogForm = () => {
|
|
@@ -11,7 +11,7 @@ export interface ModifyPropsModal<P = any> {
|
|
|
11
11
|
dialogForm: HDialogFormInstance;
|
|
12
12
|
afterClose?: VoidFunction;
|
|
13
13
|
params?: P;
|
|
14
|
-
title?:DialogFormProps["title"];
|
|
14
|
+
title?: DialogFormProps["title"];
|
|
15
15
|
}
|
|
16
16
|
export interface ShowParamsModal<P = any, T = any> {
|
|
17
17
|
configData?: HItemProps[];
|
|
@@ -19,7 +19,7 @@ export interface ShowParamsModal<P = any, T = any> {
|
|
|
19
19
|
initialValues?: Record<string, any>;
|
|
20
20
|
infoRequest?: PromiseFnResult<P, T>;
|
|
21
21
|
params?: P;
|
|
22
|
-
title?:DialogFormProps["title"];
|
|
22
|
+
title?: DialogFormProps["title"];
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export interface HDialogFormInstance<P = any, T = any> extends HFormInstance {
|
|
@@ -36,7 +36,7 @@ export default (
|
|
|
36
36
|
props: HFormItemProps,
|
|
37
37
|
ref
|
|
38
38
|
) => {
|
|
39
|
-
const { name = "" } = props;
|
|
39
|
+
const { name = "", dispatch } = props;
|
|
40
40
|
|
|
41
41
|
const { form, valueType = "float" } = useFormContext();
|
|
42
42
|
|
|
@@ -48,7 +48,7 @@ export default (
|
|
|
48
48
|
form?.addFormat(name, formatMaker(props, aFormat[valueType]));
|
|
49
49
|
};
|
|
50
50
|
const addDispatchListener = (key: string, fn: argsFn) => {
|
|
51
|
-
form?.addDispatchListener({ key, name }, fn);
|
|
51
|
+
form?.addDispatchListener({ key, name, dispatch }, fn);
|
|
52
52
|
};
|
|
53
53
|
const Component = component as React.ForwardRefRenderFunction<
|
|
54
54
|
any,
|
|
@@ -4,6 +4,14 @@ import useHForm from "./useHForm";
|
|
|
4
4
|
import { useEffect, useMemo } from "react";
|
|
5
5
|
import FormConfig from "../config";
|
|
6
6
|
import { useFormConfigContext } from "../Context/FormConfigProvider";
|
|
7
|
+
import type { DispatchModal } from "../modal";
|
|
8
|
+
|
|
9
|
+
interface UseValuesChangeModal {
|
|
10
|
+
onValuesChange: HFormProps["onValuesChange"];
|
|
11
|
+
dispatch: DispatchModal;
|
|
12
|
+
form: HFormInstance;
|
|
13
|
+
}
|
|
14
|
+
|
|
7
15
|
export const useCurrentForm = (form?: HFormInstance) => {
|
|
8
16
|
const selfForm = useHForm();
|
|
9
17
|
return form || selfForm;
|
|
@@ -66,3 +74,31 @@ export const useDefaultComponents = () => {
|
|
|
66
74
|
const defaultComponent = useFormConfigContext("defaultComponent");
|
|
67
75
|
return { ...FormConfig, ...defaultComponent };
|
|
68
76
|
};
|
|
77
|
+
|
|
78
|
+
export const useValuesChange = ({
|
|
79
|
+
onValuesChange,
|
|
80
|
+
dispatch,
|
|
81
|
+
form,
|
|
82
|
+
}: UseValuesChangeModal) => {
|
|
83
|
+
return (changedValues: any, values: any) => {
|
|
84
|
+
const changeKey = Object.keys(changedValues)[0];
|
|
85
|
+
const dispatchItem = dispatch[changeKey];
|
|
86
|
+
if (!!dispatchItem) {
|
|
87
|
+
const dispatchKey = Object.keys(dispatchItem);
|
|
88
|
+
dispatchKey.forEach((name) => {
|
|
89
|
+
const key = dispatchItem[name];
|
|
90
|
+
form.dispatch(
|
|
91
|
+
{
|
|
92
|
+
key,
|
|
93
|
+
name,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
changedValues,
|
|
97
|
+
oldValues: values,
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
onValuesChange?.(changedValues, values);
|
|
103
|
+
};
|
|
104
|
+
};
|
|
@@ -13,9 +13,13 @@ export default () => {
|
|
|
13
13
|
return useMemo<HFormInstance>(() => {
|
|
14
14
|
const formatSourceData: Record<string, FormatItemModal> = {};
|
|
15
15
|
let dispatchSourceData: Record<string, DispatchItemData> = {};
|
|
16
|
+
const initDispatch: argsFn[] = [];
|
|
16
17
|
let cacheValues: Record<string, any> = {};
|
|
17
18
|
let isLoading = false;
|
|
18
|
-
const norAddItemDispatch = (name, fn) => {
|
|
19
|
+
const norAddItemDispatch = (name, manual, fn) => {
|
|
20
|
+
if (manual === false) {
|
|
21
|
+
initDispatch.push(fn);
|
|
22
|
+
}
|
|
19
23
|
if (!name) {
|
|
20
24
|
return {
|
|
21
25
|
keysFn: {},
|
|
@@ -34,10 +38,14 @@ export default () => {
|
|
|
34
38
|
return Promise.resolve(params);
|
|
35
39
|
},
|
|
36
40
|
initValues() {
|
|
41
|
+
let newValue = {};
|
|
37
42
|
if (cacheValues) {
|
|
38
|
-
|
|
43
|
+
newValue = this.formatValues(cacheValues);
|
|
39
44
|
form.setFieldsValue(newValue);
|
|
40
45
|
}
|
|
46
|
+
initDispatch.forEach((fn) => {
|
|
47
|
+
fn({ changedValues: newValue, oldValues: newValue });
|
|
48
|
+
});
|
|
41
49
|
isLoading = true;
|
|
42
50
|
},
|
|
43
51
|
addFormat(name: string, format?: FormatItemModal) {
|
|
@@ -89,10 +97,11 @@ export default () => {
|
|
|
89
97
|
});
|
|
90
98
|
},
|
|
91
99
|
addDispatchListener(action, fn) {
|
|
92
|
-
const { key, name } = action;
|
|
100
|
+
const { key, name, dispatch = {} } = action;
|
|
101
|
+
const { manual } = dispatch;
|
|
93
102
|
const items = dispatchSourceData[key];
|
|
94
103
|
if (!items) {
|
|
95
|
-
dispatchSourceData[key] = norAddItemDispatch(name, fn);
|
|
104
|
+
dispatchSourceData[key] = norAddItemDispatch(name, manual, fn);
|
|
96
105
|
return;
|
|
97
106
|
}
|
|
98
107
|
const { keysFn, defaultFn } = items;
|