@hw-component/form 0.0.4-beta-v9 → 0.0.5-beta-v1
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/Form/hooks/index.js +29 -20
- package/lib/Form/hooks/index.js +29 -20
- package/package.json +1 -1
- package/src/components/Form/hooks/index.ts +23 -17
- package/src/components/Form/hooks/useHForm.ts +5 -5
- package/src/components/Form/hooks/useInitConfigData.tsx +9 -9
- package/src/components/Form/modal.ts +5 -2
- package/src/components/Select/hooks/changeHooks.tsx +1 -1
package/es/Form/hooks/index.js
CHANGED
|
@@ -114,6 +114,31 @@ var useDefaultComponents = function useDefaultComponents() {
|
|
|
114
114
|
var defaultComponent = useFormConfigContext("defaultComponent");
|
|
115
115
|
return _objectSpread(_objectSpread({}, componentConfig), defaultComponent);
|
|
116
116
|
};
|
|
117
|
+
var dispatchControl = function dispatchControl(form, params, dispatch) {
|
|
118
|
+
if (!dispatch) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
var dispatchKey = _Object$keys(dispatch);
|
|
122
|
+
_forEachInstanceProperty(dispatchKey).call(dispatchKey, function (name) {
|
|
123
|
+
var _dispatch$name = dispatch[name],
|
|
124
|
+
fnKey = _dispatch$name.fnKey,
|
|
125
|
+
reset = _dispatch$name.reset;
|
|
126
|
+
if (reset) {
|
|
127
|
+
form.setFields([{
|
|
128
|
+
name: name,
|
|
129
|
+
value: null,
|
|
130
|
+
errors: []
|
|
131
|
+
}]);
|
|
132
|
+
}
|
|
133
|
+
if (!fnKey) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
form.dispatch({
|
|
137
|
+
key: fnKey,
|
|
138
|
+
name: name
|
|
139
|
+
}, params);
|
|
140
|
+
});
|
|
141
|
+
};
|
|
117
142
|
var useValuesChange = function useValuesChange(_ref4) {
|
|
118
143
|
var onValuesChange = _ref4.onValuesChange,
|
|
119
144
|
dispatch = _ref4.dispatch,
|
|
@@ -121,26 +146,10 @@ var useValuesChange = function useValuesChange(_ref4) {
|
|
|
121
146
|
return function (changedValues, values) {
|
|
122
147
|
var changeKey = _Object$keys(changedValues)[0];
|
|
123
148
|
var dispatchItem = dispatch[changeKey];
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
fnKey = _dispatchItem$name.fnKey,
|
|
129
|
-
reset = _dispatchItem$name.reset;
|
|
130
|
-
reset && form.setFields([{
|
|
131
|
-
name: name,
|
|
132
|
-
value: null,
|
|
133
|
-
errors: []
|
|
134
|
-
}]);
|
|
135
|
-
form.dispatch({
|
|
136
|
-
key: fnKey,
|
|
137
|
-
name: name
|
|
138
|
-
}, {
|
|
139
|
-
changedValues: changedValues,
|
|
140
|
-
oldValues: values
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
}
|
|
149
|
+
dispatchControl(form, {
|
|
150
|
+
changedValues: changedValues,
|
|
151
|
+
oldValues: values
|
|
152
|
+
}, dispatchItem);
|
|
144
153
|
onValuesChange === null || onValuesChange === void 0 ? void 0 : onValuesChange(changedValues, values);
|
|
145
154
|
};
|
|
146
155
|
};
|
package/lib/Form/hooks/index.js
CHANGED
|
@@ -115,6 +115,31 @@ var useDefaultComponents = function useDefaultComponents() {
|
|
|
115
115
|
var defaultComponent = FormConfigProvider.useFormConfigContext("defaultComponent");
|
|
116
116
|
return _objectSpread(_objectSpread({}, config.default), defaultComponent);
|
|
117
117
|
};
|
|
118
|
+
var dispatchControl = function dispatchControl(form, params, dispatch) {
|
|
119
|
+
if (!dispatch) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
var dispatchKey = _Object$keys(dispatch);
|
|
123
|
+
_forEachInstanceProperty(dispatchKey).call(dispatchKey, function (name) {
|
|
124
|
+
var _dispatch$name = dispatch[name],
|
|
125
|
+
fnKey = _dispatch$name.fnKey,
|
|
126
|
+
reset = _dispatch$name.reset;
|
|
127
|
+
if (reset) {
|
|
128
|
+
form.setFields([{
|
|
129
|
+
name: name,
|
|
130
|
+
value: null,
|
|
131
|
+
errors: []
|
|
132
|
+
}]);
|
|
133
|
+
}
|
|
134
|
+
if (!fnKey) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
form.dispatch({
|
|
138
|
+
key: fnKey,
|
|
139
|
+
name: name
|
|
140
|
+
}, params);
|
|
141
|
+
});
|
|
142
|
+
};
|
|
118
143
|
var useValuesChange = function useValuesChange(_ref4) {
|
|
119
144
|
var onValuesChange = _ref4.onValuesChange,
|
|
120
145
|
dispatch = _ref4.dispatch,
|
|
@@ -122,26 +147,10 @@ var useValuesChange = function useValuesChange(_ref4) {
|
|
|
122
147
|
return function (changedValues, values) {
|
|
123
148
|
var changeKey = _Object$keys(changedValues)[0];
|
|
124
149
|
var dispatchItem = dispatch[changeKey];
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
fnKey = _dispatchItem$name.fnKey,
|
|
130
|
-
reset = _dispatchItem$name.reset;
|
|
131
|
-
reset && form.setFields([{
|
|
132
|
-
name: name,
|
|
133
|
-
value: null,
|
|
134
|
-
errors: []
|
|
135
|
-
}]);
|
|
136
|
-
form.dispatch({
|
|
137
|
-
key: fnKey,
|
|
138
|
-
name: name
|
|
139
|
-
}, {
|
|
140
|
-
changedValues: changedValues,
|
|
141
|
-
oldValues: values
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
}
|
|
150
|
+
dispatchControl(form, {
|
|
151
|
+
changedValues: changedValues,
|
|
152
|
+
oldValues: values
|
|
153
|
+
}, dispatchItem);
|
|
145
154
|
onValuesChange === null || onValuesChange === void 0 ? void 0 : onValuesChange(changedValues, values);
|
|
146
155
|
};
|
|
147
156
|
};
|
package/package.json
CHANGED
|
@@ -75,6 +75,28 @@ export const useDefaultComponents = () => {
|
|
|
75
75
|
return { ...FormConfig, ...defaultComponent };
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
+
const dispatchControl=(form:HFormInstance,params,dispatch?:Record<string, DispatchModal>)=>{
|
|
79
|
+
if (!dispatch){
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const dispatchKey = Object.keys(dispatch);
|
|
83
|
+
dispatchKey.forEach((name) => {
|
|
84
|
+
const { fnKey, reset } = dispatch[name];
|
|
85
|
+
if (reset) {
|
|
86
|
+
form.setFields([{ name, value: null, errors: [] }]);
|
|
87
|
+
}
|
|
88
|
+
if (!fnKey){
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
form.dispatch(
|
|
92
|
+
{
|
|
93
|
+
key: fnKey,
|
|
94
|
+
name,
|
|
95
|
+
},
|
|
96
|
+
params
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
};//触发
|
|
78
100
|
export const useValuesChange = ({
|
|
79
101
|
onValuesChange,
|
|
80
102
|
dispatch,
|
|
@@ -83,23 +105,7 @@ export const useValuesChange = ({
|
|
|
83
105
|
return (changedValues: any, values: any) => {
|
|
84
106
|
const changeKey = Object.keys(changedValues)[0];
|
|
85
107
|
const dispatchItem = dispatch[changeKey];
|
|
86
|
-
|
|
87
|
-
const dispatchKey = Object.keys(dispatchItem);
|
|
88
|
-
dispatchKey.forEach((name) => {
|
|
89
|
-
const {fnKey,reset} = dispatchItem[name];
|
|
90
|
-
reset&&form.setFields([{name,value:null,errors:[]}]);
|
|
91
|
-
form.dispatch(
|
|
92
|
-
{
|
|
93
|
-
key:fnKey,
|
|
94
|
-
name,
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
changedValues,
|
|
98
|
-
oldValues: values,
|
|
99
|
-
}
|
|
100
|
-
);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
108
|
+
dispatchControl(form,{ changedValues,oldValues: values},dispatchItem);
|
|
103
109
|
onValuesChange?.(changedValues, values);
|
|
104
110
|
};
|
|
105
111
|
};
|
|
@@ -18,8 +18,8 @@ export default () => {
|
|
|
18
18
|
let isLoading = false;
|
|
19
19
|
|
|
20
20
|
const norAddItemDispatch = (name, manual, fn) => {
|
|
21
|
-
if (manual === false&&name) {
|
|
22
|
-
initDispatch[name]=fn;
|
|
21
|
+
if (manual === false && name) {
|
|
22
|
+
initDispatch[name] = fn;
|
|
23
23
|
}
|
|
24
24
|
if (!name) {
|
|
25
25
|
return {
|
|
@@ -44,7 +44,7 @@ export default () => {
|
|
|
44
44
|
newValue = this.formatValues(cacheValues);
|
|
45
45
|
form.setFieldsValue(newValue);
|
|
46
46
|
}
|
|
47
|
-
const initKeys=Object.keys(initDispatch);
|
|
47
|
+
const initKeys = Object.keys(initDispatch);
|
|
48
48
|
initKeys.forEach((key) => {
|
|
49
49
|
initDispatch[key]({ changedValues: newValue, oldValues: newValue });
|
|
50
50
|
});
|
|
@@ -112,8 +112,8 @@ export default () => {
|
|
|
112
112
|
} else {
|
|
113
113
|
defaultFn.push(fn);
|
|
114
114
|
}
|
|
115
|
-
if (manual===false&&name){
|
|
116
|
-
initDispatch[name]=fn;
|
|
115
|
+
if (manual === false && name) {
|
|
116
|
+
initDispatch[name] = fn;
|
|
117
117
|
}
|
|
118
118
|
dispatchSourceData[key] = {
|
|
119
119
|
keysFn,
|
|
@@ -105,22 +105,22 @@ const itemDispatchProvider = (
|
|
|
105
105
|
config: Required<DispatchModal<string>>,
|
|
106
106
|
dispatchSourceData: DispatchSourceDataModal
|
|
107
107
|
) => {
|
|
108
|
-
const { dependencies, fnKey
|
|
108
|
+
const { dependencies, fnKey, reset } = config;
|
|
109
109
|
const itemDispatch = dispatchSourceData[dependencies as string];
|
|
110
110
|
if (!itemDispatch) {
|
|
111
111
|
return {
|
|
112
112
|
[dependencies]: {
|
|
113
|
-
[name]:{
|
|
113
|
+
[name]: {
|
|
114
114
|
fnKey,
|
|
115
|
-
reset
|
|
115
|
+
reset,
|
|
116
116
|
},
|
|
117
117
|
},
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
120
|
const itemNameDispatch = {
|
|
121
|
-
[name]:{
|
|
121
|
+
[name]: {
|
|
122
122
|
fnKey,
|
|
123
|
-
reset
|
|
123
|
+
reset,
|
|
124
124
|
},
|
|
125
125
|
};
|
|
126
126
|
return {
|
|
@@ -139,7 +139,7 @@ const dispatchProvider = (
|
|
|
139
139
|
fnKey,
|
|
140
140
|
dependencies: dispatchDependencies = dependencies as string | string[],
|
|
141
141
|
manual = true,
|
|
142
|
-
reset=true
|
|
142
|
+
reset = true,
|
|
143
143
|
} = dispatch;
|
|
144
144
|
if (!fnKey) {
|
|
145
145
|
return {};
|
|
@@ -151,7 +151,7 @@ const dispatchProvider = (
|
|
|
151
151
|
dispatchDependencies.forEach((key) => {
|
|
152
152
|
const itemDispatch = itemDispatchProvider(
|
|
153
153
|
name,
|
|
154
|
-
{ dependencies: key, fnKey, manual
|
|
154
|
+
{ dependencies: key, fnKey, manual, reset },
|
|
155
155
|
dispatchSourceData
|
|
156
156
|
);
|
|
157
157
|
allDispatch = {
|
|
@@ -163,7 +163,7 @@ const dispatchProvider = (
|
|
|
163
163
|
}
|
|
164
164
|
const itemDispatch = itemDispatchProvider(
|
|
165
165
|
name,
|
|
166
|
-
{ dependencies: dispatchDependencies, fnKey, manual
|
|
166
|
+
{ dependencies: dispatchDependencies, fnKey, manual, reset },
|
|
167
167
|
dispatchSourceData
|
|
168
168
|
);
|
|
169
169
|
return {
|
|
@@ -176,7 +176,7 @@ type InitConfigModal = Required<Pick<HFormProps, "configData" | "form">>;
|
|
|
176
176
|
export default ({ configData, form }: InitConfigModal) => {
|
|
177
177
|
const defaultComponents = useDefaultComponents();
|
|
178
178
|
return useMemo(() => {
|
|
179
|
-
const newConfigData:HItemProps[] = [];
|
|
179
|
+
const newConfigData: HItemProps[] = [];
|
|
180
180
|
let dispatchSourceData: DispatchSourceDataModal = {};
|
|
181
181
|
configData.forEach((item) => {
|
|
182
182
|
const itemDispatch = dispatchProvider(item, dispatchSourceData);
|
|
@@ -57,12 +57,15 @@ type HelperModal = (form: HFormInstance) => React.ReactNode | string;
|
|
|
57
57
|
export type HideModal = (form: HFormInstance) => boolean;
|
|
58
58
|
|
|
59
59
|
export type AddDispatchListenerFn = (action: ActionModal, fn: argsFn) => void;
|
|
60
|
-
export type DispatchSourceDataModal = Record<
|
|
60
|
+
export type DispatchSourceDataModal = Record<
|
|
61
|
+
string,
|
|
62
|
+
Record<string, DispatchModal>
|
|
63
|
+
>;
|
|
61
64
|
export interface DispatchModal<T = string | string[]> {
|
|
62
65
|
fnKey?: string;
|
|
63
66
|
dependencies?: T;
|
|
64
67
|
manual?: boolean;
|
|
65
|
-
reset?:boolean;
|
|
68
|
+
reset?: boolean;
|
|
66
69
|
}
|
|
67
70
|
export interface HItemProps extends Omit<FormItemProps, "name"> {
|
|
68
71
|
type?: string;
|
|
@@ -138,7 +138,7 @@ export const useValueChange = (params: PartialHSelectProps) => {
|
|
|
138
138
|
onChange(newChangeVal, subItemOps);
|
|
139
139
|
};
|
|
140
140
|
useEffect(() => {
|
|
141
|
-
if (mode === "tags"||value===null||value===undefined) {
|
|
141
|
+
if (mode === "tags" || value === null || value === undefined) {
|
|
142
142
|
setVal(value);
|
|
143
143
|
return;
|
|
144
144
|
}
|