@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
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// welcome to hoo hoo hoo
|
|
2
|
+
import React, { useEffect } from 'react';
|
|
3
|
+
import _extends from '@babel/runtime-corejs3/helpers/extends';
|
|
4
|
+
import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
|
|
5
|
+
import { Modal } from 'antd';
|
|
6
|
+
import HForm from '../Form/index.js';
|
|
7
|
+
import { useModifyProps, useCurrentForm } from './hooks.js';
|
|
8
|
+
|
|
9
|
+
var _excluded = ["visible", "title", "onCancel", "configData", "infoRequest", "request", "afterClose", "modalForm", "initialValues"];
|
|
10
|
+
var ModalForm = (function (_ref) {
|
|
11
|
+
var visible = _ref.visible,
|
|
12
|
+
title = _ref.title,
|
|
13
|
+
onCancel = _ref.onCancel,
|
|
14
|
+
configData = _ref.configData,
|
|
15
|
+
infoRequest = _ref.infoRequest;
|
|
16
|
+
_ref.request;
|
|
17
|
+
var _afterClose = _ref.afterClose,
|
|
18
|
+
modalForm = _ref.modalForm,
|
|
19
|
+
_ref$initialValues = _ref.initialValues,
|
|
20
|
+
initialValues = _ref$initialValues === void 0 ? {} : _ref$initialValues,
|
|
21
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
22
|
+
var _useModifyProps = useModifyProps({
|
|
23
|
+
configData: configData,
|
|
24
|
+
visible: visible,
|
|
25
|
+
initialValues: initialValues
|
|
26
|
+
}),
|
|
27
|
+
modalVisible = _useModifyProps.modalVisible,
|
|
28
|
+
modalFormData = _useModifyProps.modalFormData,
|
|
29
|
+
setModalVisible = _useModifyProps.setModalVisible,
|
|
30
|
+
setModalFormData = _useModifyProps.setModalFormData,
|
|
31
|
+
initValue = _useModifyProps.initValue,
|
|
32
|
+
setInitValue = _useModifyProps.setInitValue;
|
|
33
|
+
var currentForm = useCurrentForm(modalForm);
|
|
34
|
+
useEffect(function () {
|
|
35
|
+
currentForm.show = function (_ref2) {
|
|
36
|
+
var changeConfigData = _ref2.configData,
|
|
37
|
+
changeInitialValues = _ref2.initialValues;
|
|
38
|
+
if (!!changeConfigData) {
|
|
39
|
+
setModalFormData(changeConfigData);
|
|
40
|
+
}
|
|
41
|
+
setInitValue(changeInitialValues);
|
|
42
|
+
setModalVisible(true);
|
|
43
|
+
};
|
|
44
|
+
currentForm.hide = function () {
|
|
45
|
+
setModalVisible(false);
|
|
46
|
+
};
|
|
47
|
+
}, []);
|
|
48
|
+
var cancel = function cancel(e) {
|
|
49
|
+
if (onCancel) {
|
|
50
|
+
return onCancel === null || onCancel === void 0 ? void 0 : onCancel(e);
|
|
51
|
+
}
|
|
52
|
+
setModalVisible(false);
|
|
53
|
+
};
|
|
54
|
+
return /*#__PURE__*/React.createElement(Modal, _extends({
|
|
55
|
+
title: title,
|
|
56
|
+
visible: modalVisible,
|
|
57
|
+
onCancel: cancel,
|
|
58
|
+
afterClose: function afterClose() {
|
|
59
|
+
currentForm.resetFields();
|
|
60
|
+
_afterClose === null || _afterClose === void 0 ? void 0 : _afterClose();
|
|
61
|
+
}
|
|
62
|
+
}, props), /*#__PURE__*/React.createElement(HForm, _extends({
|
|
63
|
+
configData: modalFormData,
|
|
64
|
+
initialValues: initValue
|
|
65
|
+
}, props, {
|
|
66
|
+
form: currentForm,
|
|
67
|
+
infoRequest: infoRequest
|
|
68
|
+
})));
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
export { ModalForm as default };
|
|
72
|
+
// powered by hdj
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { HFormProps } from "@/components/Form/modal";
|
|
2
|
+
import type { ModalProps } from "antd";
|
|
3
|
+
import type { HFormInstance, HItemProps } from "@/components/Form/modal";
|
|
4
|
+
type RootProps = HFormProps & ModalProps;
|
|
5
|
+
export interface ModifyPropsModal {
|
|
6
|
+
configData: HItemProps[];
|
|
7
|
+
visible?: boolean;
|
|
8
|
+
initialValues?: Record<string, any>;
|
|
9
|
+
}
|
|
10
|
+
export interface ShowParamsModal extends Partial<ModifyPropsModal> {
|
|
11
|
+
initialValues?: Record<string, any>;
|
|
12
|
+
}
|
|
13
|
+
export interface HModalFormInstance extends HFormInstance {
|
|
14
|
+
show: (data: ShowParamsModal) => void;
|
|
15
|
+
hide: VoidFunction;
|
|
16
|
+
}
|
|
17
|
+
export interface ModalFormProps extends RootProps {
|
|
18
|
+
modalForm?: HModalFormInstance;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { OptionType, PartialHSelectProps } from "@/components/Select/modal";
|
|
2
2
|
export declare const useOptionReq: ({ manual, request, options, serviceSearch, showSearch, onSearch: propsOnSearch, }: PartialHSelectProps) => {
|
|
3
|
-
run: (params?: any, type?: any) => Promise<
|
|
3
|
+
run: (params?: any, type?: any) => Promise<OptionType[] | undefined>;
|
|
4
4
|
loading: boolean;
|
|
5
5
|
error: Error | undefined;
|
|
6
6
|
data: OptionType[] | undefined;
|
|
@@ -1,5 +1,4 @@
|
|
|
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';
|
|
@@ -11,6 +10,7 @@ import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
|
|
|
11
10
|
import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
|
|
12
11
|
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js/instance/for-each';
|
|
13
12
|
import _Object$values from '@babel/runtime-corejs3/core-js/object/values';
|
|
13
|
+
import _Object$keys from '@babel/runtime-corejs3/core-js/object/keys';
|
|
14
14
|
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js/instance/map';
|
|
15
15
|
import { DatePicker } from 'antd';
|
|
16
16
|
import { useGetTimeKey, useRangeValueProvider, useRangePickerTimeVal } from './hooks.js';
|
|
@@ -67,15 +67,20 @@ var HRangePicker = function HRangePicker(_ref) {
|
|
|
67
67
|
"float": {
|
|
68
68
|
inputValue: function inputValue(item, initValue) {
|
|
69
69
|
var _context;
|
|
70
|
-
var
|
|
70
|
+
var _item$name = item.name,
|
|
71
|
+
valueName = _item$name === void 0 ? "" : _item$name;
|
|
71
72
|
var resultObj = {};
|
|
72
73
|
_forEachInstanceProperty(_context = _Object$values(dateMapKeys)).call(_context, function (key) {
|
|
73
|
-
|
|
74
|
+
if (initValue[key]) {
|
|
75
|
+
resultObj[key] = initValue[key];
|
|
76
|
+
}
|
|
74
77
|
});
|
|
75
|
-
|
|
78
|
+
var hasKeys = _Object$keys(resultObj).length !== 0;
|
|
79
|
+
return _defineProperty({}, valueName, hasKeys ? resultObj : null);
|
|
76
80
|
},
|
|
77
81
|
outputValue: function outputValue(item, _outputValue) {
|
|
78
|
-
var
|
|
82
|
+
var _item$name2 = item.name,
|
|
83
|
+
valueName = _item$name2 === void 0 ? "" : _item$name2;
|
|
79
84
|
var _outputValue$valueNam = _outputValue[valueName],
|
|
80
85
|
itemVal = _outputValue$valueNam === void 0 ? {} : _outputValue$valueNam;
|
|
81
86
|
return _objectSpread({}, itemVal);
|
package/es/TextArea/index.d.ts
CHANGED
package/es/index.d.ts
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
import "./styles/index.less";
|
|
3
3
|
export { default as HForm } from "./Form";
|
|
4
4
|
export { default as useHForm } from "./Form/hooks/useHForm";
|
|
5
|
+
export { useHModalForm } from "./ModalForm/hooks";
|
|
5
6
|
export declare const HSelect: ({ 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;
|
|
6
7
|
export declare const HInput: ({ ...props }: import("antd").InputProps) => JSX.Element;
|
|
7
|
-
export declare const HSelectInput: (
|
|
8
|
+
export declare const HSelectInput: (props: import("./Form/modal").HFormItemProps) => import("react").ReactElement<import("./Form/modal").ConnectResultProps, string | import("react").JSXElementConstructor<any>>;
|
|
8
9
|
export declare const HUpload: import("react").ForwardRefExoticComponent<import("./Upload/modal").IUpLoadProps & import("react").RefAttributes<import("./Upload/modal").IUploadRefModal>>;
|
|
9
10
|
export declare const HUrlUpload: ({ placeholder, value, onChange, mediaType, ...props }: import("./Upload/modal").IUrlUploadProps) => JSX.Element;
|
|
10
11
|
export declare const HButtonInput: import("react").FC<import("./Input/modal").HButtonInputProps>;
|
|
@@ -12,9 +13,10 @@ export declare const HCheckBox: import("react").FC<import("./CheckboxGroup/modal
|
|
|
12
13
|
export declare const HSwitch: import("react").FC<import("./Switch").HSwitchProps>;
|
|
13
14
|
export declare const HCheckboxGroup: (props: import("./Form/modal").HFormItemProps) => import("react").ReactElement<import("./Form/modal").ConnectResultProps, string | import("react").JSXElementConstructor<any>>;
|
|
14
15
|
export declare const HDatePicker: ({ value, onChange, showTime, format, ...props }: import("./TDPicker/modal").HDatePickerProps) => JSX.Element;
|
|
15
|
-
export declare const HRangePicker: (
|
|
16
|
+
export declare const HRangePicker: (props: import("./Form/modal").HFormItemProps) => import("react").ReactElement<import("./Form/modal").ConnectResultProps, string | import("react").JSXElementConstructor<any>>;
|
|
16
17
|
export declare const HRadioGroup: ({ value, options, onChange, fieldNames: propsFieldNames, ...props }: import("./RadioGroup").HRadioGroupProps) => JSX.Element;
|
|
17
18
|
export declare const HTimePicker: ({ value, format, onChange, ...props }: import("./TDPicker/modal").HTimePickerProps) => JSX.Element;
|
|
18
19
|
export declare const HInputNumber: ({ style, ...props }: import("antd").InputNumberProps<string | number>) => JSX.Element;
|
|
19
20
|
export declare const HPageHandler: import("react").FC<import("./PageHandler/modal").IHPageHandler<any>>;
|
|
20
21
|
export declare const HFormConfigProvider: import("react").FC<import("./Form/modal").IFormConfigContextProps>;
|
|
22
|
+
export declare const HModalForm: ({ visible, title, onCancel, configData, infoRequest, request, afterClose, modalForm, initialValues, ...props }: import("./ModalForm/modal").ModalFormProps) => JSX.Element;
|
package/es/index.js
CHANGED
|
@@ -3,6 +3,8 @@ import FormConfig from './Form/config.js';
|
|
|
3
3
|
import Index from './PageHandler/index.js';
|
|
4
4
|
export { default as HForm } from './Form/index.js';
|
|
5
5
|
export { default as useHForm } from './Form/hooks/useHForm.js';
|
|
6
|
+
export { useHModalForm } from './ModalForm/hooks.js';
|
|
7
|
+
import ModalForm from './ModalForm/index.js';
|
|
6
8
|
|
|
7
9
|
var HSelect = FormConfig.select;
|
|
8
10
|
var HInput = FormConfig.input;
|
|
@@ -20,6 +22,7 @@ var HTimePicker = FormConfig.timePicker;
|
|
|
20
22
|
var HInputNumber = FormConfig.inputNumber;
|
|
21
23
|
var HPageHandler = Index;
|
|
22
24
|
var HFormConfigProvider = FormConfig.formConfigProvider;
|
|
25
|
+
var HModalForm = ModalForm;
|
|
23
26
|
|
|
24
|
-
export { HButtonInput, HCheckBox, HCheckboxGroup, HDatePicker, HFormConfigProvider, HInput, HInputNumber, HPageHandler, HRadioGroup, HRangePicker, HSelect, HSelectInput, HSwitch, HTimePicker, HUpload, HUrlUpload };
|
|
27
|
+
export { HButtonInput, HCheckBox, HCheckboxGroup, HDatePicker, HFormConfigProvider, HInput, HInputNumber, HModalForm, HPageHandler, HRadioGroup, HRangePicker, HSelect, HSelectInput, HSwitch, HTimePicker, HUpload, HUrlUpload };
|
|
25
28
|
// powered by hdj
|
|
@@ -53,7 +53,8 @@ var Index = function Index(_ref) {
|
|
|
53
53
|
addFormat === null || addFormat === void 0 ? void 0 : addFormat({
|
|
54
54
|
"float": {
|
|
55
55
|
inputValue: function inputValue(item, initValue) {
|
|
56
|
-
var name = item.name
|
|
56
|
+
var _item$name = item.name,
|
|
57
|
+
name = _item$name === void 0 ? "" : _item$name;
|
|
57
58
|
var keys = checkOptions === null || checkOptions === void 0 ? void 0 : _mapInstanceProperty(checkOptions).call(checkOptions, function (optItem) {
|
|
58
59
|
return optItem.value;
|
|
59
60
|
});
|
|
@@ -64,7 +65,8 @@ var Index = function Index(_ref) {
|
|
|
64
65
|
return _defineProperty({}, name, resultObj);
|
|
65
66
|
},
|
|
66
67
|
outputValue: function outputValue(item, _outputValue) {
|
|
67
|
-
var
|
|
68
|
+
var _item$name2 = item.name,
|
|
69
|
+
name = _item$name2 === void 0 ? "" : _item$name2;
|
|
68
70
|
var _outputValue$name = _outputValue[name],
|
|
69
71
|
itemVal = _outputValue$name === void 0 ? {} : _outputValue$name;
|
|
70
72
|
return _objectSpread({}, itemVal);
|
package/lib/Form/HFormConnect.js
CHANGED
|
@@ -36,7 +36,8 @@ var HFormConnect = (function (Component) {
|
|
|
36
36
|
var _config$format = config.format,
|
|
37
37
|
format = _config$format === void 0 ? {} : _config$format;
|
|
38
38
|
return function (props) {
|
|
39
|
-
var name = props.name
|
|
39
|
+
var _props$name = props.name,
|
|
40
|
+
name = _props$name === void 0 ? "" : _props$name;
|
|
40
41
|
var _useFormContext = index.useFormContext(),
|
|
41
42
|
form = _useFormContext.form,
|
|
42
43
|
_useFormContext$value = _useFormContext.valueType,
|
|
@@ -47,8 +48,15 @@ var HFormConnect = (function (Component) {
|
|
|
47
48
|
var addFormat = function addFormat(aFormat) {
|
|
48
49
|
form === null || form === void 0 ? void 0 : form.addFormat(name, formatMaker(props, aFormat[valueType]));
|
|
49
50
|
};
|
|
51
|
+
var addDispatchListener = function addDispatchListener(key, fn) {
|
|
52
|
+
form === null || form === void 0 ? void 0 : form.addDispatchListener({
|
|
53
|
+
key: key,
|
|
54
|
+
name: name
|
|
55
|
+
}, fn);
|
|
56
|
+
};
|
|
50
57
|
return /*#__PURE__*/React.createElement(Component, _objectSpread(_objectSpread({}, props), {}, {
|
|
51
|
-
addFormat: addFormat
|
|
58
|
+
addFormat: addFormat,
|
|
59
|
+
addDispatchListener: addDispatchListener
|
|
52
60
|
}));
|
|
53
61
|
};
|
|
54
62
|
});
|
package/lib/Form/InitSet.d.ts
CHANGED
package/lib/Form/InitSet.js
CHANGED
|
@@ -5,12 +5,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var index = require('./Context/index.js');
|
|
7
7
|
|
|
8
|
-
var InitSet = (function (
|
|
9
|
-
var initValues = _ref.initValues;
|
|
8
|
+
var InitSet = (function () {
|
|
10
9
|
var _useFormContext = index.useFormContext(),
|
|
11
10
|
form = _useFormContext.form;
|
|
12
11
|
React.useEffect(function () {
|
|
13
|
-
form.initValues(
|
|
12
|
+
form.initValues();
|
|
14
13
|
}, []);
|
|
15
14
|
return /*#__PURE__*/React.createElement(React.Fragment, null);
|
|
16
15
|
});
|
package/lib/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
|
};
|
|
@@ -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/lib/Form/hooks/index.js
CHANGED
|
@@ -41,40 +41,7 @@ var useSub = function useSub(_ref) {
|
|
|
41
41
|
manual: true
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
|
-
var useInit = function useInit(_ref3) {
|
|
45
|
-
var infoRequest = _ref3.infoRequest,
|
|
46
|
-
_ref3$initialValues = _ref3.initialValues,
|
|
47
|
-
initialValues = _ref3$initialValues === void 0 ? {} : _ref3$initialValues;
|
|
48
|
-
var _useRequest = ahooks.useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
49
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
50
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
51
|
-
case 0:
|
|
52
|
-
if (!infoRequest) {
|
|
53
|
-
_context2.next = 2;
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
return _context2.abrupt("return", infoRequest());
|
|
57
|
-
case 2:
|
|
58
|
-
return _context2.abrupt("return", initialValues);
|
|
59
|
-
case 3:
|
|
60
|
-
case "end":
|
|
61
|
-
return _context2.stop();
|
|
62
|
-
}
|
|
63
|
-
}, _callee2);
|
|
64
|
-
}))),
|
|
65
|
-
infoRun = _useRequest.run,
|
|
66
|
-
infoLoading = _useRequest.loading,
|
|
67
|
-
infoErr = _useRequest.error,
|
|
68
|
-
infoData = _useRequest.data;
|
|
69
|
-
return {
|
|
70
|
-
infoRun: infoRun,
|
|
71
|
-
infoLoading: infoLoading,
|
|
72
|
-
infoErr: infoErr,
|
|
73
|
-
infoData: infoData
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
44
|
|
|
77
45
|
exports.useCurrentForm = useCurrentForm;
|
|
78
|
-
exports.useInit = useInit;
|
|
79
46
|
exports.useSub = useSub;
|
|
80
47
|
// powered by h
|
|
@@ -8,17 +8,20 @@ var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js/o
|
|
|
8
8
|
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js/object/get-own-property-descriptors');
|
|
9
9
|
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js/object/define-properties');
|
|
10
10
|
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js/object/define-property');
|
|
11
|
+
var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
|
|
11
12
|
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
12
13
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
13
14
|
var _Object$keys = require('@babel/runtime-corejs3/core-js/object/keys');
|
|
14
15
|
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/for-each');
|
|
15
16
|
var _Reflect$deleteProperty = require('@babel/runtime-corejs3/core-js/reflect/delete-property');
|
|
17
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/concat');
|
|
18
|
+
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/map');
|
|
16
19
|
var _Promise = require('@babel/runtime-corejs3/core-js/promise');
|
|
17
20
|
var React = require('react');
|
|
18
21
|
var antd = require('antd');
|
|
19
22
|
|
|
20
23
|
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; }
|
|
21
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var
|
|
24
|
+
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; }
|
|
22
25
|
var useHForm = (function () {
|
|
23
26
|
var _Form$useForm = antd.Form.useForm(),
|
|
24
27
|
_Form$useForm2 = _slicedToArray(_Form$useForm, 1),
|
|
@@ -26,7 +29,26 @@ var useHForm = (function () {
|
|
|
26
29
|
return React.useMemo(function () {
|
|
27
30
|
var formatSourceData = {};
|
|
28
31
|
var dispatchSourceData = {};
|
|
32
|
+
var cacheValues = {};
|
|
33
|
+
var norAddItemDispatch = function norAddItemDispatch(name, fn) {
|
|
34
|
+
if (!name) {
|
|
35
|
+
return {
|
|
36
|
+
keysFn: {},
|
|
37
|
+
defaultFn: [fn]
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
keysFn: _defineProperty({}, name, fn),
|
|
42
|
+
defaultFn: []
|
|
43
|
+
};
|
|
44
|
+
};
|
|
29
45
|
return _objectSpread(_objectSpread({
|
|
46
|
+
initValues: function initValues() {
|
|
47
|
+
if (cacheValues) {
|
|
48
|
+
var newValue = this.formatValues(cacheValues);
|
|
49
|
+
form.setFieldsValue(newValue);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
30
52
|
addFormat: function addFormat(name, format) {
|
|
31
53
|
if (!format) {
|
|
32
54
|
return;
|
|
@@ -59,42 +81,77 @@ var useHForm = (function () {
|
|
|
59
81
|
});
|
|
60
82
|
return newValue;
|
|
61
83
|
},
|
|
62
|
-
dispatch: function dispatch(
|
|
84
|
+
dispatch: function dispatch(action) {
|
|
85
|
+
var _context2, _context3, _context4;
|
|
86
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
87
|
+
args[_key - 1] = arguments[_key];
|
|
88
|
+
}
|
|
89
|
+
var key = action.key,
|
|
90
|
+
name = action.name;
|
|
63
91
|
var items = dispatchSourceData[key];
|
|
64
92
|
if (!items) {
|
|
65
93
|
return;
|
|
66
94
|
}
|
|
67
|
-
|
|
68
|
-
|
|
95
|
+
var keysFn = items.keysFn,
|
|
96
|
+
defaultFn = items.defaultFn;
|
|
97
|
+
if (name) {
|
|
98
|
+
var _keysFn$name, _context;
|
|
99
|
+
return (_keysFn$name = keysFn[name]) === null || _keysFn$name === void 0 ? void 0 : _keysFn$name.call.apply(_keysFn$name, _concatInstanceProperty(_context = [keysFn]).call(_context, args));
|
|
100
|
+
}
|
|
101
|
+
var fnArrays = _mapInstanceProperty(_context2 = _Object$keys(keysFn)).call(_context2, function (itemKey) {
|
|
102
|
+
return keysFn[itemKey];
|
|
103
|
+
});
|
|
104
|
+
_forEachInstanceProperty(_context3 = _concatInstanceProperty(_context4 = []).call(_context4, _toConsumableArray(fnArrays), _toConsumableArray(defaultFn))).call(_context3, function (fn) {
|
|
105
|
+
fn.apply(void 0, args);
|
|
69
106
|
});
|
|
70
107
|
},
|
|
71
|
-
addDispatchListener: function addDispatchListener(
|
|
108
|
+
addDispatchListener: function addDispatchListener(action, fn) {
|
|
109
|
+
var key = action.key,
|
|
110
|
+
name = action.name;
|
|
72
111
|
var items = dispatchSourceData[key];
|
|
73
112
|
if (!items) {
|
|
74
|
-
dispatchSourceData[key] =
|
|
113
|
+
dispatchSourceData[key] = norAddItemDispatch(name, fn);
|
|
75
114
|
return;
|
|
76
115
|
}
|
|
77
|
-
items.
|
|
78
|
-
|
|
116
|
+
var keysFn = items.keysFn,
|
|
117
|
+
defaultFn = items.defaultFn;
|
|
118
|
+
if (name) {
|
|
119
|
+
keysFn[name] = fn;
|
|
120
|
+
} else {
|
|
121
|
+
defaultFn.push(fn);
|
|
122
|
+
}
|
|
123
|
+
dispatchSourceData[key] = {
|
|
124
|
+
keysFn: keysFn,
|
|
125
|
+
defaultFn: defaultFn
|
|
126
|
+
};
|
|
79
127
|
},
|
|
80
|
-
removeDispatchListener: function removeDispatchListener(
|
|
81
|
-
if (!
|
|
128
|
+
removeDispatchListener: function removeDispatchListener(action) {
|
|
129
|
+
if (!action) {
|
|
82
130
|
dispatchSourceData = {};
|
|
83
131
|
return;
|
|
84
132
|
}
|
|
133
|
+
var key = action.key,
|
|
134
|
+
name = action.name;
|
|
135
|
+
var items = dispatchSourceData[key];
|
|
136
|
+
if (!items) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (name) {
|
|
140
|
+
var keysFn = items.keysFn;
|
|
141
|
+
_Reflect$deleteProperty(keysFn, name);
|
|
142
|
+
items.keysFn = keysFn;
|
|
143
|
+
dispatchSourceData[key] = items;
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
85
146
|
_Reflect$deleteProperty(dispatchSourceData, key);
|
|
86
147
|
},
|
|
87
|
-
initValues: function initValues() {
|
|
88
|
-
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
89
|
-
var newValue = this.formatValues(value);
|
|
90
|
-
form.setFieldsValue(newValue);
|
|
91
|
-
},
|
|
92
148
|
outputValues: function outputValues(value) {
|
|
93
149
|
return this.formatValues(value, "outputValue");
|
|
94
150
|
}
|
|
95
151
|
}, form), {}, {
|
|
96
152
|
setFieldsValue: function setFieldsValue(values) {
|
|
97
153
|
var newValue = this.formatValues(values);
|
|
154
|
+
cacheValues = values;
|
|
98
155
|
form.setFieldsValue(newValue);
|
|
99
156
|
},
|
|
100
157
|
validateFields: function validateFields(nameList) {
|
package/lib/Form/index.js
CHANGED
|
@@ -4,18 +4,21 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var _extends = require('@babel/runtime-corejs3/helpers/extends');
|
|
7
|
+
var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
|
|
7
8
|
var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
|
|
8
9
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/map');
|
|
10
|
+
var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
|
|
9
11
|
var antd = require('antd');
|
|
10
|
-
var index$
|
|
11
|
-
var index
|
|
12
|
-
var index$
|
|
13
|
-
var index$
|
|
12
|
+
var index$3 = require('./FormItem/index.js');
|
|
13
|
+
var index = require('./hooks/index.js');
|
|
14
|
+
var index$2 = require('./Context/index.js');
|
|
15
|
+
var index$1 = require('../PageHandler/index.js');
|
|
14
16
|
var useInitConfigData = require('./hooks/useInitConfigData.js');
|
|
17
|
+
var ahooks = require('ahooks');
|
|
15
18
|
var InitSet = require('./InitSet.js');
|
|
16
19
|
|
|
17
20
|
var _excluded = ["configData", "labelWidth", "form", "request", "onFinish", "infoRequest", "valueType", "initialValues"];
|
|
18
|
-
var
|
|
21
|
+
var HForm = (function (_ref) {
|
|
19
22
|
var configData = _ref.configData,
|
|
20
23
|
labelWidth = _ref.labelWidth,
|
|
21
24
|
form = _ref.form,
|
|
@@ -26,12 +29,12 @@ var index = (function (_ref) {
|
|
|
26
29
|
valueType = _ref$valueType === void 0 ? "float" : _ref$valueType,
|
|
27
30
|
initialValues = _ref.initialValues,
|
|
28
31
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
29
|
-
var hForm = index
|
|
32
|
+
var hForm = index.useCurrentForm(form);
|
|
30
33
|
var newConfigData = useInitConfigData.default({
|
|
31
34
|
configData: configData,
|
|
32
35
|
form: hForm
|
|
33
36
|
});
|
|
34
|
-
var _useSub = index
|
|
37
|
+
var _useSub = index.useSub({
|
|
35
38
|
request: request,
|
|
36
39
|
onFinish: onFinish,
|
|
37
40
|
valueType: valueType,
|
|
@@ -39,20 +42,50 @@ var index = (function (_ref) {
|
|
|
39
42
|
}),
|
|
40
43
|
run = _useSub.run,
|
|
41
44
|
loading = _useSub.loading;
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
var _useRequest = ahooks.useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
46
|
+
var setValue;
|
|
47
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
48
|
+
while (1) switch (_context.prev = _context.next) {
|
|
49
|
+
case 0:
|
|
50
|
+
setValue = initialValues;
|
|
51
|
+
if (!(!initialValues && !infoRequest)) {
|
|
52
|
+
_context.next = 3;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
return _context.abrupt("return", {});
|
|
56
|
+
case 3:
|
|
57
|
+
if (!infoRequest) {
|
|
58
|
+
_context.next = 7;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
_context.next = 6;
|
|
62
|
+
return infoRequest();
|
|
63
|
+
case 6:
|
|
64
|
+
setValue = _context.sent;
|
|
65
|
+
case 7:
|
|
66
|
+
hForm.setFieldsValue(setValue);
|
|
67
|
+
return _context.abrupt("return", setValue);
|
|
68
|
+
case 9:
|
|
69
|
+
case "end":
|
|
70
|
+
return _context.stop();
|
|
71
|
+
}
|
|
72
|
+
}, _callee);
|
|
73
|
+
}))),
|
|
74
|
+
infoRun = _useRequest.run,
|
|
75
|
+
infoLoading = _useRequest.loading,
|
|
76
|
+
infoErr = _useRequest.error,
|
|
77
|
+
infoData = _useRequest.data;
|
|
78
|
+
React.useEffect(function () {
|
|
79
|
+
return function () {
|
|
80
|
+
hForm.removeDispatchListener();
|
|
81
|
+
};
|
|
82
|
+
}, []);
|
|
83
|
+
return /*#__PURE__*/React.createElement(index$1.default, {
|
|
51
84
|
loading: infoLoading,
|
|
52
85
|
error: infoErr,
|
|
53
86
|
data: infoData,
|
|
54
87
|
reload: infoRun
|
|
55
|
-
}, /*#__PURE__*/React.createElement(index$
|
|
88
|
+
}, /*#__PURE__*/React.createElement(index$2.FormContext.Provider, {
|
|
56
89
|
value: {
|
|
57
90
|
loading: loading,
|
|
58
91
|
form: hForm,
|
|
@@ -63,14 +96,12 @@ var index = (function (_ref) {
|
|
|
63
96
|
onFinish: run
|
|
64
97
|
}, props), _mapInstanceProperty(newConfigData).call(newConfigData, function (itemData, index) {
|
|
65
98
|
var itemLabelWidth = itemData.labelWidth;
|
|
66
|
-
return /*#__PURE__*/React.createElement(index$
|
|
99
|
+
return /*#__PURE__*/React.createElement(index$3.default, _extends({}, itemData, {
|
|
67
100
|
key: index,
|
|
68
101
|
labelWidth: itemLabelWidth || labelWidth
|
|
69
102
|
}));
|
|
70
|
-
})
|
|
71
|
-
initValues: infoData
|
|
72
|
-
})));
|
|
103
|
+
}), /*#__PURE__*/React.createElement(InitSet.default, null))));
|
|
73
104
|
});
|
|
74
105
|
|
|
75
|
-
exports.default =
|
|
106
|
+
exports.default = HForm;
|
|
76
107
|
// powered by h
|