@hw-component/form 0.0.1-bate → 0.0.1-beta-v2
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/CheckboxGroup/index.js +4 -2
- package/es/Form/HFormConnect.js +10 -2
- package/es/Form/InitSet.d.ts +1 -4
- package/es/Form/InitSet.js +2 -3
- package/es/Form/config.d.ts +2 -2
- package/es/Form/hooks/index.d.ts +0 -6
- package/es/Form/hooks/index.js +1 -33
- package/es/Form/hooks/useHForm.js +72 -15
- package/es/Form/index.js +46 -15
- package/es/Form/modal.d.ts +13 -7
- package/es/Input/SelectInput.d.ts +1 -1
- package/es/Input/SelectInput.js +8 -5
- package/es/Input/modal.d.ts +2 -0
- package/es/ModalForm/hooks.d.ts +12 -0
- package/es/ModalForm/hooks.js +63 -0
- package/es/ModalForm/index.d.ts +4 -0
- package/es/ModalForm/index.js +72 -0
- package/es/ModalForm/modal.d.ts +20 -0
- package/es/Select/hooks/norHooks.d.ts +1 -1
- package/es/TDPicker/RangePicker.js +10 -5
- package/es/TextArea/index.d.ts +1 -0
- package/es/index.d.ts +4 -2
- package/es/index.js +4 -1
- package/lib/CheckboxGroup/index.js +4 -2
- package/lib/Form/HFormConnect.js +10 -2
- package/lib/Form/InitSet.d.ts +1 -4
- package/lib/Form/InitSet.js +2 -3
- package/lib/Form/config.d.ts +2 -2
- package/lib/Form/hooks/index.d.ts +0 -6
- package/lib/Form/hooks/index.js +0 -33
- package/lib/Form/hooks/useHForm.js +72 -15
- package/lib/Form/index.js +53 -22
- package/lib/Form/modal.d.ts +13 -7
- package/lib/Input/SelectInput.d.ts +1 -1
- package/lib/Input/SelectInput.js +8 -5
- package/lib/Input/modal.d.ts +2 -0
- package/lib/ModalForm/hooks.d.ts +12 -0
- package/lib/ModalForm/hooks.js +66 -0
- package/lib/ModalForm/index.d.ts +4 -0
- package/lib/ModalForm/index.js +75 -0
- package/lib/ModalForm/modal.d.ts +20 -0
- package/lib/Select/hooks/norHooks.d.ts +1 -1
- package/lib/TDPicker/RangePicker.js +10 -5
- package/lib/TextArea/index.d.ts +1 -0
- package/lib/index.d.ts +4 -2
- package/lib/index.js +5 -0
- package/package.json +2 -2
- package/src/components/CheckboxGroup/index.tsx +2 -2
- package/src/components/Form/FormItem/Helper.tsx +3 -4
- package/src/components/Form/HFormConnect.tsx +6 -2
- package/src/components/Form/InitSet.tsx +3 -5
- package/src/components/Form/hooks/index.ts +0 -20
- package/src/components/Form/hooks/useHForm.ts +67 -14
- package/src/components/Form/index.tsx +25 -7
- package/src/components/Form/modal.ts +15 -9
- package/src/components/Input/SelectInput.tsx +3 -2
- package/src/components/Input/modal.ts +2 -0
- package/src/components/ModalForm/hooks.ts +45 -0
- package/src/components/ModalForm/index.tsx +69 -0
- package/src/components/ModalForm/modal.ts +22 -0
- package/src/components/TDPicker/RangePicker.tsx +7 -5
- package/src/components/TDPicker/modal.ts +1 -0
- package/src/components/index.tsx +4 -0
- package/src/pages/Form/index.tsx +2 -2
- package/src/pages/ModalForm/index.tsx +127 -0
- package/src/routes.tsx +6 -1
|
@@ -50,7 +50,8 @@ var Index = function Index(_ref) {
|
|
|
50
50
|
addFormat === null || addFormat === void 0 ? void 0 : addFormat({
|
|
51
51
|
"float": {
|
|
52
52
|
inputValue: function inputValue(item, initValue) {
|
|
53
|
-
var name = item.name
|
|
53
|
+
var _item$name = item.name,
|
|
54
|
+
name = _item$name === void 0 ? "" : _item$name;
|
|
54
55
|
var keys = checkOptions === null || checkOptions === void 0 ? void 0 : _mapInstanceProperty(checkOptions).call(checkOptions, function (optItem) {
|
|
55
56
|
return optItem.value;
|
|
56
57
|
});
|
|
@@ -61,7 +62,8 @@ var Index = function Index(_ref) {
|
|
|
61
62
|
return _defineProperty({}, name, resultObj);
|
|
62
63
|
},
|
|
63
64
|
outputValue: function outputValue(item, _outputValue) {
|
|
64
|
-
var
|
|
65
|
+
var _item$name2 = item.name,
|
|
66
|
+
name = _item$name2 === void 0 ? "" : _item$name2;
|
|
65
67
|
var _outputValue$name = _outputValue[name],
|
|
66
68
|
itemVal = _outputValue$name === void 0 ? {} : _outputValue$name;
|
|
67
69
|
return _objectSpread({}, itemVal);
|
package/es/Form/HFormConnect.js
CHANGED
|
@@ -33,7 +33,8 @@ var HFormConnect = (function (Component) {
|
|
|
33
33
|
var _config$format = config.format,
|
|
34
34
|
format = _config$format === void 0 ? {} : _config$format;
|
|
35
35
|
return function (props) {
|
|
36
|
-
var name = props.name
|
|
36
|
+
var _props$name = props.name,
|
|
37
|
+
name = _props$name === void 0 ? "" : _props$name;
|
|
37
38
|
var _useFormContext = useFormContext(),
|
|
38
39
|
form = _useFormContext.form,
|
|
39
40
|
_useFormContext$value = _useFormContext.valueType,
|
|
@@ -44,8 +45,15 @@ var HFormConnect = (function (Component) {
|
|
|
44
45
|
var addFormat = function addFormat(aFormat) {
|
|
45
46
|
form === null || form === void 0 ? void 0 : form.addFormat(name, formatMaker(props, aFormat[valueType]));
|
|
46
47
|
};
|
|
48
|
+
var addDispatchListener = function addDispatchListener(key, fn) {
|
|
49
|
+
form === null || form === void 0 ? void 0 : form.addDispatchListener({
|
|
50
|
+
key: key,
|
|
51
|
+
name: name
|
|
52
|
+
}, fn);
|
|
53
|
+
};
|
|
47
54
|
return /*#__PURE__*/React.createElement(Component, _objectSpread(_objectSpread({}, props), {}, {
|
|
48
|
-
addFormat: addFormat
|
|
55
|
+
addFormat: addFormat,
|
|
56
|
+
addDispatchListener: addDispatchListener
|
|
49
57
|
}));
|
|
50
58
|
};
|
|
51
59
|
});
|
package/es/Form/InitSet.d.ts
CHANGED
package/es/Form/InitSet.js
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
import React, { useEffect } from 'react';
|
|
3
3
|
import { useFormContext } from './Context/index.js';
|
|
4
4
|
|
|
5
|
-
var InitSet = (function (
|
|
6
|
-
var initValues = _ref.initValues;
|
|
5
|
+
var InitSet = (function () {
|
|
7
6
|
var _useFormContext = useFormContext(),
|
|
8
7
|
form = _useFormContext.form;
|
|
9
8
|
useEffect(function () {
|
|
10
|
-
form.initValues(
|
|
9
|
+
form.initValues();
|
|
11
10
|
}, []);
|
|
12
11
|
return /*#__PURE__*/React.createElement(React.Fragment, null);
|
|
13
12
|
});
|
package/es/Form/config.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const placeholderConfig: {
|
|
|
6
6
|
declare const _default: {
|
|
7
7
|
select: ({ style, mode, options, modeConfig, value, onChange, fieldNames: propsFieldNames, request, manual, optionLabelProp, filterProvider, optionFilterProp, serviceSearch, onSearch: propsOnSearch, filterOption, showSearch, labelInValue, noMatchItemRender, allSelect, ...props }: import("../Select/modal").HSelectProps) => JSX.Element;
|
|
8
8
|
inputNumber: ({ style, ...props }: import("antd").InputNumberProps<string | number>) => JSX.Element;
|
|
9
|
-
selectInput: (
|
|
9
|
+
selectInput: (props: import("./modal").HFormItemProps) => import("react").ReactElement<import("./modal").ConnectResultProps, string | import("react").JSXElementConstructor<any>>;
|
|
10
10
|
buttonInput: import("react").FC<import("../Input/modal").HButtonInputProps>;
|
|
11
11
|
checkboxGroup: (props: import("./modal").HFormItemProps) => import("react").ReactElement<import("./modal").ConnectResultProps, string | import("react").JSXElementConstructor<any>>;
|
|
12
12
|
checkBox: import("react").FC<import("../CheckboxGroup/modal").HCheckboxProps>;
|
|
@@ -14,7 +14,7 @@ declare const _default: {
|
|
|
14
14
|
switch: import("react").FC<import("../Switch").HSwitchProps>;
|
|
15
15
|
datePicker: ({ value, onChange, showTime, format, ...props }: import("../TDPicker/modal").HDatePickerProps) => JSX.Element;
|
|
16
16
|
rangePicker: {
|
|
17
|
-
Component: (
|
|
17
|
+
Component: (props: import("./modal").HFormItemProps) => import("react").ReactElement<import("./modal").ConnectResultProps, string | import("react").JSXElementConstructor<any>>;
|
|
18
18
|
placeholder: ({ label }: import("./modal").HItemProps) => string[];
|
|
19
19
|
requiredErrMsg: ({ label }: import("./modal").HItemProps) => string;
|
|
20
20
|
};
|
package/es/Form/hooks/index.d.ts
CHANGED
|
@@ -3,10 +3,4 @@ import type { HFormInstance } from "@/components/Form/modal";
|
|
|
3
3
|
export declare const useCurrentForm: (form?: HFormInstance) => HFormInstance;
|
|
4
4
|
type ParamsModal = Omit<HFormProps, "configData">;
|
|
5
5
|
export declare const useSub: ({ request, onFinish, form }: ParamsModal) => import("@ahooksjs/use-request/lib/types").BaseResult<void, [value: any]>;
|
|
6
|
-
export declare const useInit: ({ infoRequest, initialValues }: ParamsModal) => {
|
|
7
|
-
infoRun: () => Promise<any>;
|
|
8
|
-
infoLoading: boolean;
|
|
9
|
-
infoErr: Error | undefined;
|
|
10
|
-
infoData: any;
|
|
11
|
-
};
|
|
12
6
|
export {};
|
package/es/Form/hooks/index.js
CHANGED
|
@@ -40,38 +40,6 @@ var useSub = function useSub(_ref) {
|
|
|
40
40
|
manual: true
|
|
41
41
|
});
|
|
42
42
|
};
|
|
43
|
-
var useInit = function useInit(_ref3) {
|
|
44
|
-
var infoRequest = _ref3.infoRequest,
|
|
45
|
-
_ref3$initialValues = _ref3.initialValues,
|
|
46
|
-
initialValues = _ref3$initialValues === void 0 ? {} : _ref3$initialValues;
|
|
47
|
-
var _useRequest = useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
48
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
49
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
50
|
-
case 0:
|
|
51
|
-
if (!infoRequest) {
|
|
52
|
-
_context2.next = 2;
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
return _context2.abrupt("return", infoRequest());
|
|
56
|
-
case 2:
|
|
57
|
-
return _context2.abrupt("return", initialValues);
|
|
58
|
-
case 3:
|
|
59
|
-
case "end":
|
|
60
|
-
return _context2.stop();
|
|
61
|
-
}
|
|
62
|
-
}, _callee2);
|
|
63
|
-
}))),
|
|
64
|
-
infoRun = _useRequest.run,
|
|
65
|
-
infoLoading = _useRequest.loading,
|
|
66
|
-
infoErr = _useRequest.error,
|
|
67
|
-
infoData = _useRequest.data;
|
|
68
|
-
return {
|
|
69
|
-
infoRun: infoRun,
|
|
70
|
-
infoLoading: infoLoading,
|
|
71
|
-
infoErr: infoErr,
|
|
72
|
-
infoData: infoData
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
43
|
|
|
76
|
-
export { useCurrentForm,
|
|
44
|
+
export { useCurrentForm, useSub };
|
|
77
45
|
// powered by hdj
|
|
@@ -5,17 +5,20 @@ import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js/obj
|
|
|
5
5
|
import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js/object/get-own-property-descriptors';
|
|
6
6
|
import _Object$defineProperties from '@babel/runtime-corejs3/core-js/object/define-properties';
|
|
7
7
|
import _Object$defineProperty from '@babel/runtime-corejs3/core-js/object/define-property';
|
|
8
|
+
import _toConsumableArray from '@babel/runtime-corejs3/helpers/toConsumableArray';
|
|
8
9
|
import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
|
|
9
10
|
import _slicedToArray from '@babel/runtime-corejs3/helpers/slicedToArray';
|
|
10
11
|
import _Object$keys from '@babel/runtime-corejs3/core-js/object/keys';
|
|
11
12
|
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js/instance/for-each';
|
|
12
13
|
import _Reflect$deleteProperty from '@babel/runtime-corejs3/core-js/reflect/delete-property';
|
|
14
|
+
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js/instance/concat';
|
|
15
|
+
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js/instance/map';
|
|
13
16
|
import _Promise from '@babel/runtime-corejs3/core-js/promise';
|
|
14
17
|
import { useMemo } from 'react';
|
|
15
18
|
import { Form } from 'antd';
|
|
16
19
|
|
|
17
20
|
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; }
|
|
18
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var
|
|
21
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context5, _context6; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context5 = ownKeys(Object(source), !0)).call(_context5, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context6 = ownKeys(Object(source))).call(_context6, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
19
22
|
var useHForm = (function () {
|
|
20
23
|
var _Form$useForm = Form.useForm(),
|
|
21
24
|
_Form$useForm2 = _slicedToArray(_Form$useForm, 1),
|
|
@@ -23,7 +26,26 @@ var useHForm = (function () {
|
|
|
23
26
|
return useMemo(function () {
|
|
24
27
|
var formatSourceData = {};
|
|
25
28
|
var dispatchSourceData = {};
|
|
29
|
+
var cacheValues = {};
|
|
30
|
+
var norAddItemDispatch = function norAddItemDispatch(name, fn) {
|
|
31
|
+
if (!name) {
|
|
32
|
+
return {
|
|
33
|
+
keysFn: {},
|
|
34
|
+
defaultFn: [fn]
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
keysFn: _defineProperty({}, name, fn),
|
|
39
|
+
defaultFn: []
|
|
40
|
+
};
|
|
41
|
+
};
|
|
26
42
|
return _objectSpread(_objectSpread({
|
|
43
|
+
initValues: function initValues() {
|
|
44
|
+
if (cacheValues) {
|
|
45
|
+
var newValue = this.formatValues(cacheValues);
|
|
46
|
+
form.setFieldsValue(newValue);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
27
49
|
addFormat: function addFormat(name, format) {
|
|
28
50
|
if (!format) {
|
|
29
51
|
return;
|
|
@@ -56,42 +78,77 @@ var useHForm = (function () {
|
|
|
56
78
|
});
|
|
57
79
|
return newValue;
|
|
58
80
|
},
|
|
59
|
-
dispatch: function dispatch(
|
|
81
|
+
dispatch: function dispatch(action) {
|
|
82
|
+
var _context2, _context3, _context4;
|
|
83
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
84
|
+
args[_key - 1] = arguments[_key];
|
|
85
|
+
}
|
|
86
|
+
var key = action.key,
|
|
87
|
+
name = action.name;
|
|
60
88
|
var items = dispatchSourceData[key];
|
|
61
89
|
if (!items) {
|
|
62
90
|
return;
|
|
63
91
|
}
|
|
64
|
-
|
|
65
|
-
|
|
92
|
+
var keysFn = items.keysFn,
|
|
93
|
+
defaultFn = items.defaultFn;
|
|
94
|
+
if (name) {
|
|
95
|
+
var _keysFn$name, _context;
|
|
96
|
+
return (_keysFn$name = keysFn[name]) === null || _keysFn$name === void 0 ? void 0 : _keysFn$name.call.apply(_keysFn$name, _concatInstanceProperty(_context = [keysFn]).call(_context, args));
|
|
97
|
+
}
|
|
98
|
+
var fnArrays = _mapInstanceProperty(_context2 = _Object$keys(keysFn)).call(_context2, function (itemKey) {
|
|
99
|
+
return keysFn[itemKey];
|
|
100
|
+
});
|
|
101
|
+
_forEachInstanceProperty(_context3 = _concatInstanceProperty(_context4 = []).call(_context4, _toConsumableArray(fnArrays), _toConsumableArray(defaultFn))).call(_context3, function (fn) {
|
|
102
|
+
fn.apply(void 0, args);
|
|
66
103
|
});
|
|
67
104
|
},
|
|
68
|
-
addDispatchListener: function addDispatchListener(
|
|
105
|
+
addDispatchListener: function addDispatchListener(action, fn) {
|
|
106
|
+
var key = action.key,
|
|
107
|
+
name = action.name;
|
|
69
108
|
var items = dispatchSourceData[key];
|
|
70
109
|
if (!items) {
|
|
71
|
-
dispatchSourceData[key] =
|
|
110
|
+
dispatchSourceData[key] = norAddItemDispatch(name, fn);
|
|
72
111
|
return;
|
|
73
112
|
}
|
|
74
|
-
items.
|
|
75
|
-
|
|
113
|
+
var keysFn = items.keysFn,
|
|
114
|
+
defaultFn = items.defaultFn;
|
|
115
|
+
if (name) {
|
|
116
|
+
keysFn[name] = fn;
|
|
117
|
+
} else {
|
|
118
|
+
defaultFn.push(fn);
|
|
119
|
+
}
|
|
120
|
+
dispatchSourceData[key] = {
|
|
121
|
+
keysFn: keysFn,
|
|
122
|
+
defaultFn: defaultFn
|
|
123
|
+
};
|
|
76
124
|
},
|
|
77
|
-
removeDispatchListener: function removeDispatchListener(
|
|
78
|
-
if (!
|
|
125
|
+
removeDispatchListener: function removeDispatchListener(action) {
|
|
126
|
+
if (!action) {
|
|
79
127
|
dispatchSourceData = {};
|
|
80
128
|
return;
|
|
81
129
|
}
|
|
130
|
+
var key = action.key,
|
|
131
|
+
name = action.name;
|
|
132
|
+
var items = dispatchSourceData[key];
|
|
133
|
+
if (!items) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (name) {
|
|
137
|
+
var keysFn = items.keysFn;
|
|
138
|
+
_Reflect$deleteProperty(keysFn, name);
|
|
139
|
+
items.keysFn = keysFn;
|
|
140
|
+
dispatchSourceData[key] = items;
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
82
143
|
_Reflect$deleteProperty(dispatchSourceData, key);
|
|
83
144
|
},
|
|
84
|
-
initValues: function initValues() {
|
|
85
|
-
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
86
|
-
var newValue = this.formatValues(value);
|
|
87
|
-
form.setFieldsValue(newValue);
|
|
88
|
-
},
|
|
89
145
|
outputValues: function outputValues(value) {
|
|
90
146
|
return this.formatValues(value, "outputValue");
|
|
91
147
|
}
|
|
92
148
|
}, form), {}, {
|
|
93
149
|
setFieldsValue: function setFieldsValue(values) {
|
|
94
150
|
var newValue = this.formatValues(values);
|
|
151
|
+
cacheValues = values;
|
|
95
152
|
form.setFieldsValue(newValue);
|
|
96
153
|
},
|
|
97
154
|
validateFields: function validateFields(nameList) {
|
package/es/Form/index.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
// welcome to hoo hoo hoo
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { useEffect } from 'react';
|
|
3
3
|
import _extends from '@babel/runtime-corejs3/helpers/extends';
|
|
4
|
+
import _asyncToGenerator from '@babel/runtime-corejs3/helpers/asyncToGenerator';
|
|
4
5
|
import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
|
|
5
6
|
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js/instance/map';
|
|
7
|
+
import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
|
|
6
8
|
import { Form } from 'antd';
|
|
7
9
|
import Item from './FormItem/index.js';
|
|
8
|
-
import { useCurrentForm, useSub
|
|
10
|
+
import { useCurrentForm, useSub } from './hooks/index.js';
|
|
9
11
|
import { FormContext } from './Context/index.js';
|
|
10
12
|
import Index from '../PageHandler/index.js';
|
|
11
13
|
import useInitConfigData from './hooks/useInitConfigData.js';
|
|
14
|
+
import { useRequest } from 'ahooks';
|
|
12
15
|
import InitSet from './InitSet.js';
|
|
13
16
|
|
|
14
17
|
var _excluded = ["configData", "labelWidth", "form", "request", "onFinish", "infoRequest", "valueType", "initialValues"];
|
|
15
|
-
var
|
|
18
|
+
var HForm = (function (_ref) {
|
|
16
19
|
var configData = _ref.configData,
|
|
17
20
|
labelWidth = _ref.labelWidth,
|
|
18
21
|
form = _ref.form,
|
|
@@ -36,14 +39,44 @@ var index = (function (_ref) {
|
|
|
36
39
|
}),
|
|
37
40
|
run = _useSub.run,
|
|
38
41
|
loading = _useSub.loading;
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
var _useRequest = useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
43
|
+
var setValue;
|
|
44
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
45
|
+
while (1) switch (_context.prev = _context.next) {
|
|
46
|
+
case 0:
|
|
47
|
+
setValue = initialValues;
|
|
48
|
+
if (!(!initialValues && !infoRequest)) {
|
|
49
|
+
_context.next = 3;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
return _context.abrupt("return", {});
|
|
53
|
+
case 3:
|
|
54
|
+
if (!infoRequest) {
|
|
55
|
+
_context.next = 7;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
_context.next = 6;
|
|
59
|
+
return infoRequest();
|
|
60
|
+
case 6:
|
|
61
|
+
setValue = _context.sent;
|
|
62
|
+
case 7:
|
|
63
|
+
hForm.setFieldsValue(setValue);
|
|
64
|
+
return _context.abrupt("return", setValue);
|
|
65
|
+
case 9:
|
|
66
|
+
case "end":
|
|
67
|
+
return _context.stop();
|
|
68
|
+
}
|
|
69
|
+
}, _callee);
|
|
70
|
+
}))),
|
|
71
|
+
infoRun = _useRequest.run,
|
|
72
|
+
infoLoading = _useRequest.loading,
|
|
73
|
+
infoErr = _useRequest.error,
|
|
74
|
+
infoData = _useRequest.data;
|
|
75
|
+
useEffect(function () {
|
|
76
|
+
return function () {
|
|
77
|
+
hForm.removeDispatchListener();
|
|
78
|
+
};
|
|
79
|
+
}, []);
|
|
47
80
|
return /*#__PURE__*/React.createElement(Index, {
|
|
48
81
|
loading: infoLoading,
|
|
49
82
|
error: infoErr,
|
|
@@ -64,10 +97,8 @@ var index = (function (_ref) {
|
|
|
64
97
|
key: index,
|
|
65
98
|
labelWidth: itemLabelWidth || labelWidth
|
|
66
99
|
}));
|
|
67
|
-
})
|
|
68
|
-
initValues: infoData
|
|
69
|
-
})));
|
|
100
|
+
}), /*#__PURE__*/React.createElement(InitSet, null))));
|
|
70
101
|
});
|
|
71
102
|
|
|
72
|
-
export {
|
|
103
|
+
export { HForm as default };
|
|
73
104
|
// powered by hdj
|
package/es/Form/modal.d.ts
CHANGED
|
@@ -20,17 +20,17 @@ export interface HoverModal {
|
|
|
20
20
|
}
|
|
21
21
|
type HelperModal = (form: HFormInstance) => React.ReactNode | string;
|
|
22
22
|
export type HideModal = (form: HFormInstance) => boolean;
|
|
23
|
+
export type AddDispatchListenerFn = (action: ActionModal, fn: argsFn) => void;
|
|
23
24
|
export interface HItemProps extends Omit<FormItemProps, "name"> {
|
|
24
25
|
type?: string;
|
|
25
26
|
itemProps?: ItemPropsType;
|
|
26
27
|
render?: RenderFun;
|
|
27
|
-
helper?: HelperModal;
|
|
28
|
+
helper?: HelperModal | string;
|
|
28
29
|
hover?: string | HoverModal;
|
|
29
30
|
labelWidth?: number;
|
|
30
31
|
hide?: boolean | HideModal;
|
|
31
32
|
placeholder?: string | string[];
|
|
32
|
-
|
|
33
|
-
name: string;
|
|
33
|
+
name?: string;
|
|
34
34
|
}
|
|
35
35
|
export interface HFormProps<T = any, R = any> extends Omit<FormProps, "form"> {
|
|
36
36
|
configData: HItemProps[];
|
|
@@ -46,6 +46,7 @@ export interface HFormItemProps extends HItemProps {
|
|
|
46
46
|
export interface FormItemWithRender extends Omit<HFormItemProps, "render"> {
|
|
47
47
|
render: (form: HFormInstance) => React.ReactNode;
|
|
48
48
|
}
|
|
49
|
+
export type argsFn = (...args: any[]) => void;
|
|
49
50
|
export interface FormContextProps {
|
|
50
51
|
loading?: boolean;
|
|
51
52
|
form: HFormInstance;
|
|
@@ -64,14 +65,18 @@ export interface IFormConfigContextProps {
|
|
|
64
65
|
dateRanges?: RangePickerProps["ranges"];
|
|
65
66
|
uploadProps?: ConfigUploadProps;
|
|
66
67
|
}
|
|
68
|
+
interface ActionModal {
|
|
69
|
+
key: string;
|
|
70
|
+
name?: string;
|
|
71
|
+
}
|
|
67
72
|
export interface HFormInstance extends FormInstance {
|
|
68
73
|
addFormat: (name: string, formats?: FormatItemModal) => void;
|
|
69
|
-
initValues:
|
|
74
|
+
initValues: VoidFunction;
|
|
70
75
|
formatValues: (values?: Record<string, any>, formatKey?: string) => Record<string, any>;
|
|
71
|
-
dispatch: (
|
|
76
|
+
dispatch: (action: ActionModal, ...args: any[]) => void;
|
|
72
77
|
outputValues: (values?: Record<string, any>) => Record<string, any>;
|
|
73
|
-
addDispatchListener:
|
|
74
|
-
removeDispatchListener: (
|
|
78
|
+
addDispatchListener: AddDispatchListenerFn;
|
|
79
|
+
removeDispatchListener: (action?: ActionModal, fn?: argsFn) => void;
|
|
75
80
|
}
|
|
76
81
|
export interface ConnectConfigModal {
|
|
77
82
|
format?: Record<string, addFormatItemModal>;
|
|
@@ -88,5 +93,6 @@ export interface addFormatItemModal {
|
|
|
88
93
|
}
|
|
89
94
|
export interface ConnectResultProps {
|
|
90
95
|
addFormat?: (format: Record<string, addFormatItemModal>) => void;
|
|
96
|
+
addDispatchListener?: (key: string, fn: argsFn) => void;
|
|
91
97
|
}
|
|
92
98
|
export {};
|
|
@@ -4,6 +4,6 @@ export declare enum SelectInputType {
|
|
|
4
4
|
input = 0,
|
|
5
5
|
select = 1
|
|
6
6
|
}
|
|
7
|
-
export declare const Index: ({ selectProps, value, onChange, valueName, addFormat, ...props }: HSelectInputProps) => JSX.Element;
|
|
7
|
+
export declare const Index: ({ selectProps, value, onChange, valueName, addFormat, addDispatchListener, ...props }: HSelectInputProps) => JSX.Element;
|
|
8
8
|
declare const _default: (props: import("../Form/modal").HFormItemProps) => import("react").ReactElement<import("../Form/modal").ConnectResultProps, string | import("react").JSXElementConstructor<any>>;
|
|
9
9
|
export default _default;
|
package/es/Input/SelectInput.js
CHANGED
|
@@ -17,7 +17,7 @@ import HSelect from '../Select/index.js';
|
|
|
17
17
|
import { defaultValueName, defaultSelectStyle } from './defaultConfig.js';
|
|
18
18
|
import HFormConnect from '../Form/HFormConnect.js';
|
|
19
19
|
|
|
20
|
-
var _excluded = ["selectProps", "value", "onChange", "valueName", "addFormat"],
|
|
20
|
+
var _excluded = ["selectProps", "value", "onChange", "valueName", "addFormat", "addDispatchListener"],
|
|
21
21
|
_excluded2 = ["style", "placeholder"];
|
|
22
22
|
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; }
|
|
23
23
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -34,8 +34,9 @@ var Index = function Index(_ref) {
|
|
|
34
34
|
onChange = _ref.onChange,
|
|
35
35
|
_ref$valueName = _ref.valueName,
|
|
36
36
|
valueName = _ref$valueName === void 0 ? defaultValueName : _ref$valueName,
|
|
37
|
-
addFormat = _ref.addFormat
|
|
38
|
-
|
|
37
|
+
addFormat = _ref.addFormat;
|
|
38
|
+
_ref.addDispatchListener;
|
|
39
|
+
var props = _objectWithoutProperties(_ref, _excluded);
|
|
39
40
|
var _valueName$input = valueName.input,
|
|
40
41
|
input = _valueName$input === void 0 ? "" : _valueName$input,
|
|
41
42
|
_valueName$select = valueName.select,
|
|
@@ -57,7 +58,8 @@ var Index = function Index(_ref) {
|
|
|
57
58
|
"float": {
|
|
58
59
|
inputValue: function inputValue(item, initValue) {
|
|
59
60
|
var _context;
|
|
60
|
-
var name = item.name
|
|
61
|
+
var _item$name = item.name,
|
|
62
|
+
name = _item$name === void 0 ? "" : _item$name;
|
|
61
63
|
var resultObj = {};
|
|
62
64
|
_forEachInstanceProperty(_context = _Object$values(valueName)).call(_context, function (key) {
|
|
63
65
|
resultObj[key] = initValue[key];
|
|
@@ -65,7 +67,8 @@ var Index = function Index(_ref) {
|
|
|
65
67
|
return _defineProperty({}, name, resultObj);
|
|
66
68
|
},
|
|
67
69
|
outputValue: function outputValue(item, _outputValue) {
|
|
68
|
-
var
|
|
70
|
+
var _item$name2 = item.name,
|
|
71
|
+
name = _item$name2 === void 0 ? "" : _item$name2;
|
|
69
72
|
var _outputValue$name = _outputValue[name],
|
|
70
73
|
itemVal = _outputValue$name === void 0 ? {} : _outputValue$name;
|
|
71
74
|
var newItemVal = _defineProperty({}, itemVal[select], itemVal[input]);
|
package/es/Input/modal.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { HSelectProps } from "../Select/modal";
|
|
|
3
3
|
import type { SelectInputType } from "./SelectInput";
|
|
4
4
|
import type { PromiseFnResult } from "../modal";
|
|
5
5
|
import type { addFormatItemModal } from "../Form/modal";
|
|
6
|
+
import type { AddDispatchListenerFn } from "../Form/modal";
|
|
6
7
|
export type HInputProps = InputProps;
|
|
7
8
|
interface ValueNameModal {
|
|
8
9
|
input?: string;
|
|
@@ -14,6 +15,7 @@ export interface HSelectInputProps extends Omit<HInputProps, "value" | "onChange
|
|
|
14
15
|
onChange?: (value: Record<string, any>, type: SelectInputType) => void;
|
|
15
16
|
valueName?: ValueNameModal;
|
|
16
17
|
addFormat?: (config: Record<string, addFormatItemModal>) => void;
|
|
18
|
+
addDispatchListener?: AddDispatchListenerFn;
|
|
17
19
|
}
|
|
18
20
|
export interface HButtonProps extends Omit<ButtonProps, "onClick"> {
|
|
19
21
|
onClick: (value: string | readonly string[] | number | undefined, e: HTMLElement) => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { HModalFormInstance, ModifyPropsModal } from "@/components/ModalForm/modal";
|
|
3
|
+
export declare const useModifyProps: ({ visible, configData, initialValues, }: ModifyPropsModal) => {
|
|
4
|
+
modalFormData: import("../Form/modal").HItemProps[];
|
|
5
|
+
modalVisible: boolean | undefined;
|
|
6
|
+
setModalVisible: import("react").Dispatch<import("react").SetStateAction<boolean | undefined>>;
|
|
7
|
+
setModalFormData: import("react").Dispatch<import("react").SetStateAction<import("../Form/modal").HItemProps[]>>;
|
|
8
|
+
initValue: Record<string, any> | undefined;
|
|
9
|
+
setInitValue: import("react").Dispatch<import("react").SetStateAction<Record<string, any> | undefined>>;
|
|
10
|
+
};
|
|
11
|
+
export declare const useHModalForm: () => HModalFormInstance;
|
|
12
|
+
export declare const useCurrentForm: (hModalForm?: HModalFormInstance) => HModalFormInstance;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// welcome to hoo hoo hoo
|
|
2
|
+
import _Object$keys from '@babel/runtime-corejs3/core-js/object/keys';
|
|
3
|
+
import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js/object/get-own-property-symbols';
|
|
4
|
+
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js/instance/filter';
|
|
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
|
+
import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js/object/get-own-property-descriptors';
|
|
8
|
+
import _Object$defineProperties from '@babel/runtime-corejs3/core-js/object/define-properties';
|
|
9
|
+
import _Object$defineProperty from '@babel/runtime-corejs3/core-js/object/define-property';
|
|
10
|
+
import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
|
|
11
|
+
import _slicedToArray from '@babel/runtime-corejs3/helpers/slicedToArray';
|
|
12
|
+
import { useMemo, useState, useEffect } from 'react';
|
|
13
|
+
import useHForm from '../Form/hooks/useHForm.js';
|
|
14
|
+
|
|
15
|
+
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; }
|
|
16
|
+
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; }
|
|
17
|
+
var useModifyProps = function useModifyProps(_ref) {
|
|
18
|
+
var visible = _ref.visible,
|
|
19
|
+
configData = _ref.configData,
|
|
20
|
+
initialValues = _ref.initialValues;
|
|
21
|
+
var _useState = useState(visible),
|
|
22
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
23
|
+
modalVisible = _useState2[0],
|
|
24
|
+
setModalVisible = _useState2[1];
|
|
25
|
+
var _useState3 = useState(configData),
|
|
26
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
27
|
+
modalFormData = _useState4[0],
|
|
28
|
+
setModalFormData = _useState4[1];
|
|
29
|
+
var _useState5 = useState(initialValues),
|
|
30
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
31
|
+
initValue = _useState6[0],
|
|
32
|
+
setInitValue = _useState6[1];
|
|
33
|
+
useEffect(function () {
|
|
34
|
+
setModalVisible(visible);
|
|
35
|
+
}, [visible]);
|
|
36
|
+
useEffect(function () {
|
|
37
|
+
setModalFormData(configData);
|
|
38
|
+
}, [configData]);
|
|
39
|
+
return {
|
|
40
|
+
modalFormData: modalFormData,
|
|
41
|
+
modalVisible: modalVisible,
|
|
42
|
+
setModalVisible: setModalVisible,
|
|
43
|
+
setModalFormData: setModalFormData,
|
|
44
|
+
initValue: initValue,
|
|
45
|
+
setInitValue: setInitValue
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
var useHModalForm = function useHModalForm() {
|
|
49
|
+
var hForm = useHForm();
|
|
50
|
+
return useMemo(function () {
|
|
51
|
+
return _objectSpread(_objectSpread({}, hForm), {}, {
|
|
52
|
+
show: function show(params) {},
|
|
53
|
+
hide: function hide() {}
|
|
54
|
+
});
|
|
55
|
+
}, []);
|
|
56
|
+
};
|
|
57
|
+
var useCurrentForm = function useCurrentForm(hModalForm) {
|
|
58
|
+
var defaultHModalForm = useHModalForm();
|
|
59
|
+
return hModalForm || defaultHModalForm;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export { useCurrentForm, useHModalForm, useModifyProps };
|
|
63
|
+
// powered by hdj
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ModalFormProps } from "@/components/ModalForm/modal";
|
|
3
|
+
declare const _default: ({ visible, title, onCancel, configData, infoRequest, request, afterClose, modalForm, initialValues, ...props }: ModalFormProps) => JSX.Element;
|
|
4
|
+
export default _default;
|