@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
package/lib/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/lib/Input/SelectInput.js
CHANGED
|
@@ -20,7 +20,7 @@ var index = require('../Select/index.js');
|
|
|
20
20
|
var defaultConfig = require('./defaultConfig.js');
|
|
21
21
|
var HFormConnect = require('../Form/HFormConnect.js');
|
|
22
22
|
|
|
23
|
-
var _excluded = ["selectProps", "value", "onChange", "valueName", "addFormat"],
|
|
23
|
+
var _excluded = ["selectProps", "value", "onChange", "valueName", "addFormat", "addDispatchListener"],
|
|
24
24
|
_excluded2 = ["style", "placeholder"];
|
|
25
25
|
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; }
|
|
26
26
|
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; }
|
|
@@ -37,8 +37,9 @@ var Index = function Index(_ref) {
|
|
|
37
37
|
onChange = _ref.onChange,
|
|
38
38
|
_ref$valueName = _ref.valueName,
|
|
39
39
|
valueName = _ref$valueName === void 0 ? defaultConfig.defaultValueName : _ref$valueName,
|
|
40
|
-
addFormat = _ref.addFormat
|
|
41
|
-
|
|
40
|
+
addFormat = _ref.addFormat;
|
|
41
|
+
_ref.addDispatchListener;
|
|
42
|
+
var props = _objectWithoutProperties(_ref, _excluded);
|
|
42
43
|
var _valueName$input = valueName.input,
|
|
43
44
|
input = _valueName$input === void 0 ? "" : _valueName$input,
|
|
44
45
|
_valueName$select = valueName.select,
|
|
@@ -60,7 +61,8 @@ var Index = function Index(_ref) {
|
|
|
60
61
|
"float": {
|
|
61
62
|
inputValue: function inputValue(item, initValue) {
|
|
62
63
|
var _context;
|
|
63
|
-
var name = item.name
|
|
64
|
+
var _item$name = item.name,
|
|
65
|
+
name = _item$name === void 0 ? "" : _item$name;
|
|
64
66
|
var resultObj = {};
|
|
65
67
|
_forEachInstanceProperty(_context = _Object$values(valueName)).call(_context, function (key) {
|
|
66
68
|
resultObj[key] = initValue[key];
|
|
@@ -68,7 +70,8 @@ var Index = function Index(_ref) {
|
|
|
68
70
|
return _defineProperty({}, name, resultObj);
|
|
69
71
|
},
|
|
70
72
|
outputValue: function outputValue(item, _outputValue) {
|
|
71
|
-
var
|
|
73
|
+
var _item$name2 = item.name,
|
|
74
|
+
name = _item$name2 === void 0 ? "" : _item$name2;
|
|
72
75
|
var _outputValue$name = _outputValue[name],
|
|
73
76
|
itemVal = _outputValue$name === void 0 ? {} : _outputValue$name;
|
|
74
77
|
var newItemVal = _defineProperty({}, itemVal[select], itemVal[input]);
|
package/lib/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,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _Object$keys = require('@babel/runtime-corejs3/core-js/object/keys');
|
|
4
|
+
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js/object/get-own-property-symbols');
|
|
5
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/filter');
|
|
6
|
+
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js/object/get-own-property-descriptor');
|
|
7
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/for-each');
|
|
8
|
+
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js/object/get-own-property-descriptors');
|
|
9
|
+
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js/object/define-properties');
|
|
10
|
+
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js/object/define-property');
|
|
11
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
12
|
+
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
13
|
+
var React = require('react');
|
|
14
|
+
var useHForm = require('../Form/hooks/useHForm.js');
|
|
15
|
+
|
|
16
|
+
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; }
|
|
17
|
+
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; }
|
|
18
|
+
var useModifyProps = function useModifyProps(_ref) {
|
|
19
|
+
var visible = _ref.visible,
|
|
20
|
+
configData = _ref.configData,
|
|
21
|
+
initialValues = _ref.initialValues;
|
|
22
|
+
var _useState = React.useState(visible),
|
|
23
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
24
|
+
modalVisible = _useState2[0],
|
|
25
|
+
setModalVisible = _useState2[1];
|
|
26
|
+
var _useState3 = React.useState(configData),
|
|
27
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
28
|
+
modalFormData = _useState4[0],
|
|
29
|
+
setModalFormData = _useState4[1];
|
|
30
|
+
var _useState5 = React.useState(initialValues),
|
|
31
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
32
|
+
initValue = _useState6[0],
|
|
33
|
+
setInitValue = _useState6[1];
|
|
34
|
+
React.useEffect(function () {
|
|
35
|
+
setModalVisible(visible);
|
|
36
|
+
}, [visible]);
|
|
37
|
+
React.useEffect(function () {
|
|
38
|
+
setModalFormData(configData);
|
|
39
|
+
}, [configData]);
|
|
40
|
+
return {
|
|
41
|
+
modalFormData: modalFormData,
|
|
42
|
+
modalVisible: modalVisible,
|
|
43
|
+
setModalVisible: setModalVisible,
|
|
44
|
+
setModalFormData: setModalFormData,
|
|
45
|
+
initValue: initValue,
|
|
46
|
+
setInitValue: setInitValue
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
var useHModalForm = function useHModalForm() {
|
|
50
|
+
var hForm = useHForm.default();
|
|
51
|
+
return React.useMemo(function () {
|
|
52
|
+
return _objectSpread(_objectSpread({}, hForm), {}, {
|
|
53
|
+
show: function show(params) {},
|
|
54
|
+
hide: function hide() {}
|
|
55
|
+
});
|
|
56
|
+
}, []);
|
|
57
|
+
};
|
|
58
|
+
var useCurrentForm = function useCurrentForm(hModalForm) {
|
|
59
|
+
var defaultHModalForm = useHModalForm();
|
|
60
|
+
return hModalForm || defaultHModalForm;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
exports.useCurrentForm = useCurrentForm;
|
|
64
|
+
exports.useHModalForm = useHModalForm;
|
|
65
|
+
exports.useModifyProps = useModifyProps;
|
|
66
|
+
// powered by h
|
|
@@ -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;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var _extends = require('@babel/runtime-corejs3/helpers/extends');
|
|
7
|
+
var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
|
|
8
|
+
var antd = require('antd');
|
|
9
|
+
var index = require('../Form/index.js');
|
|
10
|
+
var hooks = require('./hooks.js');
|
|
11
|
+
|
|
12
|
+
var _excluded = ["visible", "title", "onCancel", "configData", "infoRequest", "request", "afterClose", "modalForm", "initialValues"];
|
|
13
|
+
var ModalForm = (function (_ref) {
|
|
14
|
+
var visible = _ref.visible,
|
|
15
|
+
title = _ref.title,
|
|
16
|
+
onCancel = _ref.onCancel,
|
|
17
|
+
configData = _ref.configData,
|
|
18
|
+
infoRequest = _ref.infoRequest;
|
|
19
|
+
_ref.request;
|
|
20
|
+
var _afterClose = _ref.afterClose,
|
|
21
|
+
modalForm = _ref.modalForm,
|
|
22
|
+
_ref$initialValues = _ref.initialValues,
|
|
23
|
+
initialValues = _ref$initialValues === void 0 ? {} : _ref$initialValues,
|
|
24
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
25
|
+
var _useModifyProps = hooks.useModifyProps({
|
|
26
|
+
configData: configData,
|
|
27
|
+
visible: visible,
|
|
28
|
+
initialValues: initialValues
|
|
29
|
+
}),
|
|
30
|
+
modalVisible = _useModifyProps.modalVisible,
|
|
31
|
+
modalFormData = _useModifyProps.modalFormData,
|
|
32
|
+
setModalVisible = _useModifyProps.setModalVisible,
|
|
33
|
+
setModalFormData = _useModifyProps.setModalFormData,
|
|
34
|
+
initValue = _useModifyProps.initValue,
|
|
35
|
+
setInitValue = _useModifyProps.setInitValue;
|
|
36
|
+
var currentForm = hooks.useCurrentForm(modalForm);
|
|
37
|
+
React.useEffect(function () {
|
|
38
|
+
currentForm.show = function (_ref2) {
|
|
39
|
+
var changeConfigData = _ref2.configData,
|
|
40
|
+
changeInitialValues = _ref2.initialValues;
|
|
41
|
+
if (!!changeConfigData) {
|
|
42
|
+
setModalFormData(changeConfigData);
|
|
43
|
+
}
|
|
44
|
+
setInitValue(changeInitialValues);
|
|
45
|
+
setModalVisible(true);
|
|
46
|
+
};
|
|
47
|
+
currentForm.hide = function () {
|
|
48
|
+
setModalVisible(false);
|
|
49
|
+
};
|
|
50
|
+
}, []);
|
|
51
|
+
var cancel = function cancel(e) {
|
|
52
|
+
if (onCancel) {
|
|
53
|
+
return onCancel === null || onCancel === void 0 ? void 0 : onCancel(e);
|
|
54
|
+
}
|
|
55
|
+
setModalVisible(false);
|
|
56
|
+
};
|
|
57
|
+
return /*#__PURE__*/React.createElement(antd.Modal, _extends({
|
|
58
|
+
title: title,
|
|
59
|
+
visible: modalVisible,
|
|
60
|
+
onCancel: cancel,
|
|
61
|
+
afterClose: function afterClose() {
|
|
62
|
+
currentForm.resetFields();
|
|
63
|
+
_afterClose === null || _afterClose === void 0 ? void 0 : _afterClose();
|
|
64
|
+
}
|
|
65
|
+
}, props), /*#__PURE__*/React.createElement(index.default, _extends({
|
|
66
|
+
configData: modalFormData,
|
|
67
|
+
initialValues: initValue
|
|
68
|
+
}, props, {
|
|
69
|
+
form: currentForm,
|
|
70
|
+
infoRequest: infoRequest
|
|
71
|
+
})));
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
exports.default = ModalForm;
|
|
75
|
+
// powered by h
|
|
@@ -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;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _Object$keys = require('@babel/runtime-corejs3/core-js/object/keys');
|
|
6
5
|
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js/object/get-own-property-symbols');
|
|
7
6
|
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/filter');
|
|
8
7
|
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js/object/get-own-property-descriptor');
|
|
@@ -14,6 +13,7 @@ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
|
14
13
|
var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
|
|
15
14
|
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/for-each');
|
|
16
15
|
var _Object$values = require('@babel/runtime-corejs3/core-js/object/values');
|
|
16
|
+
var _Object$keys = require('@babel/runtime-corejs3/core-js/object/keys');
|
|
17
17
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/map');
|
|
18
18
|
var antd = require('antd');
|
|
19
19
|
var hooks = require('./hooks.js');
|
|
@@ -70,15 +70,20 @@ var HRangePicker = function HRangePicker(_ref) {
|
|
|
70
70
|
"float": {
|
|
71
71
|
inputValue: function inputValue(item, initValue) {
|
|
72
72
|
var _context;
|
|
73
|
-
var
|
|
73
|
+
var _item$name = item.name,
|
|
74
|
+
valueName = _item$name === void 0 ? "" : _item$name;
|
|
74
75
|
var resultObj = {};
|
|
75
76
|
_forEachInstanceProperty(_context = _Object$values(dateMapKeys)).call(_context, function (key) {
|
|
76
|
-
|
|
77
|
+
if (initValue[key]) {
|
|
78
|
+
resultObj[key] = initValue[key];
|
|
79
|
+
}
|
|
77
80
|
});
|
|
78
|
-
|
|
81
|
+
var hasKeys = _Object$keys(resultObj).length !== 0;
|
|
82
|
+
return _defineProperty({}, valueName, hasKeys ? resultObj : null);
|
|
79
83
|
},
|
|
80
84
|
outputValue: function outputValue(item, _outputValue) {
|
|
81
|
-
var
|
|
85
|
+
var _item$name2 = item.name,
|
|
86
|
+
valueName = _item$name2 === void 0 ? "" : _item$name2;
|
|
82
87
|
var _outputValue$valueNam = _outputValue[valueName],
|
|
83
88
|
itemVal = _outputValue$valueNam === void 0 ? {} : _outputValue$valueNam;
|
|
84
89
|
return _objectSpread({}, itemVal);
|
package/lib/TextArea/index.d.ts
CHANGED
package/lib/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/lib/index.js
CHANGED
|
@@ -4,6 +4,8 @@ var config = require('./Form/config.js');
|
|
|
4
4
|
var index$1 = require('./PageHandler/index.js');
|
|
5
5
|
var index = require('./Form/index.js');
|
|
6
6
|
var useHForm = require('./Form/hooks/useHForm.js');
|
|
7
|
+
var hooks = require('./ModalForm/hooks.js');
|
|
8
|
+
var index$2 = require('./ModalForm/index.js');
|
|
7
9
|
|
|
8
10
|
var HSelect = config.default.select;
|
|
9
11
|
var HInput = config.default.input;
|
|
@@ -21,9 +23,11 @@ var HTimePicker = config.default.timePicker;
|
|
|
21
23
|
var HInputNumber = config.default.inputNumber;
|
|
22
24
|
var HPageHandler = index$1.default;
|
|
23
25
|
var HFormConfigProvider = config.default.formConfigProvider;
|
|
26
|
+
var HModalForm = index$2.default;
|
|
24
27
|
|
|
25
28
|
exports.HForm = index.default;
|
|
26
29
|
exports.useHForm = useHForm.default;
|
|
30
|
+
exports.useHModalForm = hooks.useHModalForm;
|
|
27
31
|
exports.HButtonInput = HButtonInput;
|
|
28
32
|
exports.HCheckBox = HCheckBox;
|
|
29
33
|
exports.HCheckboxGroup = HCheckboxGroup;
|
|
@@ -31,6 +35,7 @@ exports.HDatePicker = HDatePicker;
|
|
|
31
35
|
exports.HFormConfigProvider = HFormConfigProvider;
|
|
32
36
|
exports.HInput = HInput;
|
|
33
37
|
exports.HInputNumber = HInputNumber;
|
|
38
|
+
exports.HModalForm = HModalForm;
|
|
34
39
|
exports.HPageHandler = HPageHandler;
|
|
35
40
|
exports.HRadioGroup = HRadioGroup;
|
|
36
41
|
exports.HRangePicker = HRangePicker;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hw-component/form",
|
|
3
|
-
"version": "0.0.1-
|
|
3
|
+
"version": "0.0.1-beta-v2",
|
|
4
4
|
"description": "基于antd二次开发",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@ant-design/icons": "4.6.2",
|
|
31
31
|
"ahooks": "2.10.9",
|
|
32
|
-
"antd": "4.20.
|
|
32
|
+
"antd": "4.20.7",
|
|
33
33
|
"react": "16.14.0",
|
|
34
34
|
"react-dom": "17.0.2",
|
|
35
35
|
"react-router-dom": "^6.11.2"
|
|
@@ -32,7 +32,7 @@ const Index = ({
|
|
|
32
32
|
addFormat?.({
|
|
33
33
|
float: {
|
|
34
34
|
inputValue: (item, initValue) => {
|
|
35
|
-
const { name } = item;
|
|
35
|
+
const { name = "" } = item;
|
|
36
36
|
const keys = checkOptions?.map((optItem) => {
|
|
37
37
|
return optItem.value;
|
|
38
38
|
});
|
|
@@ -45,7 +45,7 @@ const Index = ({
|
|
|
45
45
|
};
|
|
46
46
|
},
|
|
47
47
|
outputValue: (item, outputValue) => {
|
|
48
|
-
const { name } = item;
|
|
48
|
+
const { name = "" } = item;
|
|
49
49
|
const { [name]: itemVal = {} } = outputValue;
|
|
50
50
|
return {
|
|
51
51
|
...itemVal,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import type { HItemProps } from "@/components/Form/modal";
|
|
3
|
-
import
|
|
4
|
-
import { Typography, Row } from "antd";
|
|
2
|
+
import type { HItemProps, HFormInstance } from "@/components/Form/modal";
|
|
3
|
+
import { Typography } from "antd";
|
|
5
4
|
import { useFormContext } from "../Context";
|
|
6
5
|
|
|
7
6
|
interface HelperProps {
|
|
@@ -16,7 +15,7 @@ const Index: React.FC<HelperProps> = ({ helper }) => {
|
|
|
16
15
|
if (typeof helper === "function") {
|
|
17
16
|
return (
|
|
18
17
|
<Typography.Text type={"secondary"}>
|
|
19
|
-
{helper(form as
|
|
18
|
+
{helper(form as HFormInstance)}
|
|
20
19
|
</Typography.Text>
|
|
21
20
|
);
|
|
22
21
|
}
|
|
@@ -4,6 +4,7 @@ import React, { useEffect } from "react";
|
|
|
4
4
|
import type { ConnectConfigModal } from "@/components/Form/modal";
|
|
5
5
|
import type { addFormatItemModal } from "@/components/Form/modal";
|
|
6
6
|
import type { ConnectResultProps } from "@/components/Form/modal";
|
|
7
|
+
import type { argsFn } from "@/components/Form/modal";
|
|
7
8
|
|
|
8
9
|
const formatMaker = (
|
|
9
10
|
itemProps: HFormItemProps,
|
|
@@ -29,7 +30,7 @@ export default (
|
|
|
29
30
|
) => {
|
|
30
31
|
const { format = {} } = config;
|
|
31
32
|
return (props: HFormItemProps) => {
|
|
32
|
-
const { name } = props;
|
|
33
|
+
const { name = "" } = props;
|
|
33
34
|
|
|
34
35
|
const { form, valueType = "float" } = useFormContext();
|
|
35
36
|
|
|
@@ -40,10 +41,13 @@ export default (
|
|
|
40
41
|
const addFormat = (aFormat: Record<string, addFormatItemModal>) => {
|
|
41
42
|
form?.addFormat(name, formatMaker(props, aFormat[valueType]));
|
|
42
43
|
};
|
|
43
|
-
|
|
44
|
+
const addDispatchListener = (key: string, fn: argsFn) => {
|
|
45
|
+
form?.addDispatchListener({ key, name }, fn);
|
|
46
|
+
};
|
|
44
47
|
return React.createElement<ConnectResultProps>(Component, {
|
|
45
48
|
...props,
|
|
46
49
|
addFormat,
|
|
50
|
+
addDispatchListener,
|
|
47
51
|
});
|
|
48
52
|
};
|
|
49
53
|
};
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { useFormContext } from "./Context";
|
|
2
2
|
import { useEffect } from "react";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
export default ({ initValues }: InitSetProps) => {
|
|
3
|
+
|
|
4
|
+
export default () => {
|
|
7
5
|
const { form } = useFormContext();
|
|
8
6
|
useEffect(() => {
|
|
9
|
-
form.initValues(
|
|
7
|
+
form.initValues();
|
|
10
8
|
}, []);
|
|
11
9
|
return <></>;
|
|
12
10
|
};
|
|
@@ -20,23 +20,3 @@ export const useSub = ({ request, onFinish, form }: ParamsModal) => {
|
|
|
20
20
|
{ manual: true }
|
|
21
21
|
);
|
|
22
22
|
}; //提交
|
|
23
|
-
|
|
24
|
-
export const useInit = ({ infoRequest, initialValues = {} }: ParamsModal) => {
|
|
25
|
-
const {
|
|
26
|
-
run: infoRun,
|
|
27
|
-
loading: infoLoading,
|
|
28
|
-
error: infoErr,
|
|
29
|
-
data: infoData,
|
|
30
|
-
} = useRequest(async () => {
|
|
31
|
-
if (infoRequest) {
|
|
32
|
-
return infoRequest();
|
|
33
|
-
}
|
|
34
|
-
return initialValues;
|
|
35
|
-
});
|
|
36
|
-
return {
|
|
37
|
-
infoRun,
|
|
38
|
-
infoLoading,
|
|
39
|
-
infoErr,
|
|
40
|
-
infoData,
|
|
41
|
-
};
|
|
42
|
-
}; //初始化
|