@hw-component/form 0.0.2-bate → 0.0.2-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.
Files changed (112) hide show
  1. package/es/CheckboxGroup/index.d.ts +1 -1
  2. package/es/CheckboxGroup/index.js +4 -2
  3. package/es/DialogForm/DrawerForm/Footer.d.ts +4 -0
  4. package/es/DialogForm/DrawerForm/Footer.js +23 -0
  5. package/es/DialogForm/DrawerForm/Title.d.ts +4 -0
  6. package/es/DialogForm/DrawerForm/Title.js +18 -0
  7. package/es/DialogForm/DrawerForm/index.d.ts +4 -0
  8. package/es/DialogForm/DrawerForm/index.js +111 -0
  9. package/es/DialogForm/ModalForm.d.ts +4 -0
  10. package/es/DialogForm/ModalForm.js +89 -0
  11. package/es/DialogForm/hooks.d.ts +14 -0
  12. package/es/DialogForm/hooks.js +124 -0
  13. package/es/DialogForm/modal.d.ts +25 -0
  14. package/es/Form/HFormConnect.d.ts +1 -2
  15. package/es/Form/HFormConnect.js +17 -16
  16. package/es/Form/InitSet.d.ts +1 -4
  17. package/es/Form/InitSet.js +2 -3
  18. package/es/Form/config.d.ts +5 -4
  19. package/es/Form/config.js +6 -4
  20. package/es/Form/hooks/index.d.ts +0 -6
  21. package/es/Form/hooks/index.js +1 -33
  22. package/es/Form/hooks/useHForm.js +72 -15
  23. package/es/Form/index.js +46 -15
  24. package/es/Form/modal.d.ts +20 -8
  25. package/es/Input/SelectInput.d.ts +2 -2
  26. package/es/Input/SelectInput.js +8 -5
  27. package/es/Input/modal.d.ts +2 -0
  28. package/es/Select/hooks/norHooks.d.ts +1 -1
  29. package/es/TDPicker/RangePicker.d.ts +1 -1
  30. package/es/TDPicker/RangePicker.js +4 -2
  31. package/es/TextArea/index.js +21 -0
  32. package/es/Upload/UrlUpload/index.d.ts +2 -2
  33. package/es/Upload/UrlUpload/index.js +3 -3
  34. package/es/Upload/hooks/customRequest.js +99 -36
  35. package/es/Upload/index.d.ts +1 -2
  36. package/es/Upload/index.js +40 -5
  37. package/es/Upload/modal.d.ts +2 -0
  38. package/es/config.js +4 -4
  39. package/es/index.css +1 -1
  40. package/es/index.d.ts +8 -4
  41. package/es/index.js +7 -1
  42. package/lib/CheckboxGroup/index.d.ts +1 -1
  43. package/lib/CheckboxGroup/index.js +4 -2
  44. package/lib/DialogForm/DrawerForm/Footer.d.ts +4 -0
  45. package/lib/DialogForm/DrawerForm/Footer.js +26 -0
  46. package/lib/DialogForm/DrawerForm/Title.d.ts +4 -0
  47. package/lib/DialogForm/DrawerForm/Title.js +21 -0
  48. package/lib/DialogForm/DrawerForm/index.d.ts +4 -0
  49. package/lib/DialogForm/DrawerForm/index.js +114 -0
  50. package/lib/DialogForm/ModalForm.d.ts +4 -0
  51. package/lib/DialogForm/ModalForm.js +92 -0
  52. package/lib/DialogForm/hooks.d.ts +14 -0
  53. package/lib/DialogForm/hooks.js +128 -0
  54. package/lib/DialogForm/modal.d.ts +25 -0
  55. package/lib/Form/HFormConnect.d.ts +1 -2
  56. package/lib/Form/HFormConnect.js +17 -16
  57. package/lib/Form/InitSet.d.ts +1 -4
  58. package/lib/Form/InitSet.js +2 -3
  59. package/lib/Form/config.d.ts +5 -4
  60. package/lib/Form/config.js +3 -1
  61. package/lib/Form/hooks/index.d.ts +0 -6
  62. package/lib/Form/hooks/index.js +0 -33
  63. package/lib/Form/hooks/useHForm.js +72 -15
  64. package/lib/Form/index.js +53 -22
  65. package/lib/Form/modal.d.ts +20 -8
  66. package/lib/Input/SelectInput.d.ts +2 -2
  67. package/lib/Input/SelectInput.js +8 -5
  68. package/lib/Input/modal.d.ts +2 -0
  69. package/lib/Select/hooks/norHooks.d.ts +1 -1
  70. package/lib/TDPicker/RangePicker.d.ts +1 -1
  71. package/lib/TDPicker/RangePicker.js +4 -2
  72. package/lib/TextArea/index.js +24 -0
  73. package/lib/Upload/UrlUpload/index.d.ts +2 -2
  74. package/lib/Upload/UrlUpload/index.js +3 -3
  75. package/lib/Upload/hooks/customRequest.js +99 -36
  76. package/lib/Upload/index.d.ts +1 -2
  77. package/lib/Upload/index.js +40 -5
  78. package/lib/Upload/modal.d.ts +2 -0
  79. package/lib/config.js +4 -4
  80. package/lib/index.css +1 -1
  81. package/lib/index.d.ts +8 -4
  82. package/lib/index.js +10 -0
  83. package/package.json +1 -1
  84. package/src/components/CheckboxGroup/index.tsx +2 -2
  85. package/src/components/DialogForm/DrawerForm/Footer.tsx +19 -0
  86. package/src/components/DialogForm/DrawerForm/Title.tsx +12 -0
  87. package/src/components/DialogForm/DrawerForm/index.tsx +85 -0
  88. package/src/components/DialogForm/ModalForm.tsx +60 -0
  89. package/src/components/DialogForm/hooks.ts +87 -0
  90. package/src/components/DialogForm/modal.ts +27 -0
  91. package/src/components/Form/FormItem/Helper.tsx +3 -4
  92. package/src/components/Form/HFormConnect.tsx +26 -8
  93. package/src/components/Form/InitSet.tsx +3 -5
  94. package/src/components/Form/config.ts +2 -1
  95. package/src/components/Form/hooks/index.ts +0 -20
  96. package/src/components/Form/hooks/useHForm.ts +67 -14
  97. package/src/components/Form/index.less +1 -1
  98. package/src/components/Form/index.tsx +25 -7
  99. package/src/components/Form/modal.ts +22 -10
  100. package/src/components/Input/SelectInput.tsx +4 -2
  101. package/src/components/Input/modal.ts +2 -0
  102. package/src/components/TDPicker/RangePicker.tsx +5 -6
  103. package/src/components/Upload/UrlUpload/index.tsx +2 -2
  104. package/src/components/Upload/hooks/customRequest.ts +57 -14
  105. package/src/components/Upload/index.tsx +40 -7
  106. package/src/components/Upload/modal.ts +2 -0
  107. package/src/components/config.ts +4 -4
  108. package/src/components/index.tsx +6 -0
  109. package/src/pages/DrawerForm/index.tsx +127 -0
  110. package/src/pages/Form/index.tsx +3 -0
  111. package/src/pages/ModalForm/index.tsx +127 -0
  112. package/src/routes.tsx +12 -0
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import type { DialogFormProps, HDialogFormInstance, ModifyPropsModal } from "./modal";
3
+ export declare const useModifyProps: ({ visible, configData, initialValues, dialogForm, afterClose, }: 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
+ onAfterClose: () => void;
11
+ };
12
+ export declare const useHDialogForm: () => HDialogFormInstance;
13
+ export declare const useCurrentForm: (hDialogForm?: HDialogFormInstance) => HDialogFormInstance;
14
+ export declare const useSub: ({ request, onFinish }: Partial<DialogFormProps>) => import("@ahooksjs/use-request/lib/types").BaseResult<any, [values: any]>;
@@ -0,0 +1,128 @@
1
+ 'use strict';
2
+
3
+ var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
4
+ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
5
+ var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
6
+ var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
7
+ var _setTimeout = require('@babel/runtime-corejs3/core-js/set-timeout');
8
+ var _Object$keys = require('@babel/runtime-corejs3/core-js/object/keys');
9
+ var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js/object/get-own-property-symbols');
10
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/filter');
11
+ var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js/object/get-own-property-descriptor');
12
+ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/for-each');
13
+ var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js/object/get-own-property-descriptors');
14
+ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js/object/define-properties');
15
+ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js/object/define-property');
16
+ var React = require('react');
17
+ var useHForm = require('../Form/hooks/useHForm.js');
18
+ var ahooks = require('ahooks');
19
+
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; }
21
+ 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; }
22
+ var useModifyProps = function useModifyProps(_ref) {
23
+ var visible = _ref.visible,
24
+ configData = _ref.configData,
25
+ initialValues = _ref.initialValues,
26
+ dialogForm = _ref.dialogForm,
27
+ afterClose = _ref.afterClose;
28
+ var _useState = React.useState(visible),
29
+ _useState2 = _slicedToArray(_useState, 2),
30
+ modalVisible = _useState2[0],
31
+ setModalVisible = _useState2[1];
32
+ var _useState3 = React.useState(configData),
33
+ _useState4 = _slicedToArray(_useState3, 2),
34
+ modalFormData = _useState4[0],
35
+ setModalFormData = _useState4[1];
36
+ var _useState5 = React.useState(initialValues),
37
+ _useState6 = _slicedToArray(_useState5, 2),
38
+ initValue = _useState6[0],
39
+ setInitValue = _useState6[1];
40
+ var onAfterClose = function onAfterClose() {
41
+ _setTimeout(function () {
42
+ dialogForm.resetFields();
43
+ afterClose === null || afterClose === void 0 ? void 0 : afterClose();
44
+ }, 0);
45
+ };
46
+ React.useEffect(function () {
47
+ setModalVisible(visible);
48
+ }, [visible]);
49
+ React.useEffect(function () {
50
+ setModalFormData(configData);
51
+ }, [configData]);
52
+ React.useEffect(function () {
53
+ dialogForm.show = function () {
54
+ var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
55
+ var changeConfigData = params.configData,
56
+ changeInitialValues = params.initialValues;
57
+ if (!!changeConfigData) {
58
+ setModalFormData(changeConfigData);
59
+ }
60
+ setInitValue(changeInitialValues);
61
+ setModalVisible(true);
62
+ };
63
+ dialogForm.hide = function () {
64
+ setModalVisible(false);
65
+ onAfterClose();
66
+ };
67
+ }, [afterClose]);
68
+ return {
69
+ modalFormData: modalFormData,
70
+ modalVisible: modalVisible,
71
+ setModalVisible: setModalVisible,
72
+ setModalFormData: setModalFormData,
73
+ initValue: initValue,
74
+ setInitValue: setInitValue,
75
+ onAfterClose: onAfterClose
76
+ };
77
+ };
78
+ var useHDialogForm = function useHDialogForm() {
79
+ var hForm = useHForm.default();
80
+ return React.useMemo(function () {
81
+ return _objectSpread(_objectSpread({}, hForm), {}, {
82
+ show: function show(params) {},
83
+ hide: function hide() {}
84
+ });
85
+ }, []);
86
+ };
87
+ var useCurrentForm = function useCurrentForm(hDialogForm) {
88
+ var defaultHModalForm = useHDialogForm();
89
+ return hDialogForm || defaultHModalForm;
90
+ };
91
+ var useSub = function useSub(_ref2) {
92
+ var request = _ref2.request,
93
+ onFinish = _ref2.onFinish;
94
+ return ahooks.useRequest( /*#__PURE__*/function () {
95
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(values) {
96
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
97
+ while (1) switch (_context.prev = _context.next) {
98
+ case 0:
99
+ if (!onFinish) {
100
+ _context.next = 2;
101
+ break;
102
+ }
103
+ return _context.abrupt("return", onFinish(values));
104
+ case 2:
105
+ if (!request) {
106
+ _context.next = 4;
107
+ break;
108
+ }
109
+ return _context.abrupt("return", request(values));
110
+ case 4:
111
+ case "end":
112
+ return _context.stop();
113
+ }
114
+ }, _callee);
115
+ }));
116
+ return function (_x) {
117
+ return _ref3.apply(this, arguments);
118
+ };
119
+ }(), {
120
+ manual: true
121
+ });
122
+ };
123
+
124
+ exports.useCurrentForm = useCurrentForm;
125
+ exports.useHDialogForm = useHDialogForm;
126
+ exports.useModifyProps = useModifyProps;
127
+ exports.useSub = useSub;
128
+ // powered by h
@@ -0,0 +1,25 @@
1
+ import type { ModalProps } from "antd";
2
+ import type { HFormInstance, HItemProps, HFormProps } from "../Form/modal";
3
+ import type { PromiseFnResult } from "../modal";
4
+ type RootProps = HFormProps & ModalProps;
5
+ export interface ModifyPropsModal {
6
+ configData: HItemProps[];
7
+ visible?: boolean;
8
+ initialValues?: Record<string, any>;
9
+ dialogForm: HDialogFormInstance;
10
+ afterClose?: VoidFunction;
11
+ }
12
+ export interface ShowParamsModal {
13
+ configData?: HItemProps[];
14
+ visible?: boolean;
15
+ initialValues?: Record<string, any>;
16
+ }
17
+ export interface HDialogFormInstance extends HFormInstance {
18
+ show: (data?: ShowParamsModal) => void;
19
+ hide: VoidFunction;
20
+ }
21
+ export interface DialogFormProps extends Omit<RootProps, "onFinish"> {
22
+ dialogForm?: HDialogFormInstance;
23
+ onFinish?: PromiseFnResult;
24
+ }
25
+ export {};
@@ -1,6 +1,5 @@
1
1
  import type { HFormItemProps } from "@/components/Form/modal";
2
2
  import React from "react";
3
3
  import type { ConnectConfigModal } from "@/components/Form/modal";
4
- import type { ConnectResultProps } from "@/components/Form/modal";
5
- declare const _default: (Component: React.FunctionComponent | React.ComponentClass, config?: ConnectConfigModal) => (props: HFormItemProps) => React.ReactElement<ConnectResultProps, string | React.JSXElementConstructor<any>>;
4
+ declare const _default: (component: React.FunctionComponent | React.ComponentClass | React.ForwardRefRenderFunction<any, any>, config?: ConnectConfigModal) => React.ForwardRefExoticComponent<HFormItemProps & React.RefAttributes<any>>;
6
5
  export default _default;
@@ -2,20 +2,10 @@
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
- var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js/object/get-own-property-symbols');
7
- var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/filter');
8
- var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js/object/get-own-property-descriptor');
9
- var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/for-each');
10
- var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js/object/get-own-property-descriptors');
11
- var _Object$defineProperties = require('@babel/runtime-corejs3/core-js/object/define-properties');
12
- var _Object$defineProperty = require('@babel/runtime-corejs3/core-js/object/define-property');
13
- var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
5
+ var _extends = require('@babel/runtime-corejs3/helpers/extends');
14
6
  var index = require('./Context/index.js');
15
7
  var React = require('react');
16
8
 
17
- 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 _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; }
19
9
  var formatMaker = function formatMaker(itemProps, formats) {
20
10
  if (!formats) {
21
11
  return formats;
@@ -31,12 +21,13 @@ var formatMaker = function formatMaker(itemProps, formats) {
31
21
  }
32
22
  };
33
23
  };
34
- var HFormConnect = (function (Component) {
24
+ var HFormConnect = (function (component) {
35
25
  var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
36
26
  var _config$format = config.format,
37
27
  format = _config$format === void 0 ? {} : _config$format;
38
- return function (props) {
39
- var name = props.name;
28
+ var Index = function Index(props, ref) {
29
+ var _props$name = props.name,
30
+ name = _props$name === void 0 ? "" : _props$name;
40
31
  var _useFormContext = index.useFormContext(),
41
32
  form = _useFormContext.form,
42
33
  _useFormContext$value = _useFormContext.valueType,
@@ -47,10 +38,20 @@ var HFormConnect = (function (Component) {
47
38
  var addFormat = function addFormat(aFormat) {
48
39
  form === null || form === void 0 ? void 0 : form.addFormat(name, formatMaker(props, aFormat[valueType]));
49
40
  };
50
- return /*#__PURE__*/React.createElement(Component, _objectSpread(_objectSpread({}, props), {}, {
51
- addFormat: addFormat
41
+ var addDispatchListener = function addDispatchListener(key, fn) {
42
+ form === null || form === void 0 ? void 0 : form.addDispatchListener({
43
+ key: key,
44
+ name: name
45
+ }, fn);
46
+ };
47
+ var Component = component;
48
+ return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
49
+ addFormat: addFormat,
50
+ addDispatchListener: addDispatchListener,
51
+ ref: ref
52
52
  }));
53
53
  };
54
+ return /*#__PURE__*/React.forwardRef(Index);
54
55
  });
55
56
 
56
57
  exports.default = HFormConnect;
@@ -1,6 +1,3 @@
1
1
  /// <reference types="react" />
2
- interface InitSetProps {
3
- initValues?: Record<string, any>;
4
- }
5
- declare const _default: ({ initValues }: InitSetProps) => JSX.Element;
2
+ declare const _default: () => JSX.Element;
6
3
  export default _default;
@@ -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 (_ref) {
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(initValues);
12
+ form.initValues();
14
13
  }, []);
15
14
  return /*#__PURE__*/React.createElement(React.Fragment, null);
16
15
  });
@@ -6,23 +6,24 @@ 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: ({ selectProps, value, onChange, valueName, ...props }: import("../Input/modal").HSelectInputProps) => JSX.Element;
9
+ selectInput: import("react").ForwardRefExoticComponent<import("./modal").HFormItemProps & import("react").RefAttributes<any>>;
10
10
  buttonInput: import("react").FC<import("../Input/modal").HButtonInputProps>;
11
- checkboxGroup: (props: import("./modal").HFormItemProps) => import("react").ReactElement<import("./modal").ConnectResultProps, string | import("react").JSXElementConstructor<any>>;
11
+ checkboxGroup: import("react").ForwardRefExoticComponent<import("./modal").HFormItemProps & import("react").RefAttributes<any>>;
12
12
  checkBox: import("react").FC<import("../CheckboxGroup/modal").HCheckboxProps>;
13
13
  radioGroup: ({ value, options, onChange, fieldNames: propsFieldNames, ...props }: import("../RadioGroup").HRadioGroupProps) => JSX.Element;
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: ({ value, onChange, showTime, format, valueMap, ranges, name, ...props }: import("../TDPicker/modal").HRangePickerProps) => JSX.Element;
17
+ Component: import("react").ForwardRefExoticComponent<import("./modal").HFormItemProps & import("react").RefAttributes<any>>;
18
18
  placeholder: ({ label }: import("./modal").HItemProps) => string[];
19
19
  requiredErrMsg: ({ label }: import("./modal").HItemProps) => string;
20
20
  };
21
21
  timePicker: ({ value, format, onChange, ...props }: import("../TDPicker/modal").HTimePickerProps) => JSX.Element;
22
22
  input: ({ ...props }: import("antd").InputProps) => JSX.Element;
23
- upload: import("react").ForwardRefExoticComponent<import("../Upload/modal").IUpLoadProps & import("react").RefAttributes<import("../Upload/modal").IUploadRefModal>>;
23
+ upload: import("react").ForwardRefExoticComponent<import("./modal").HFormItemProps & import("react").RefAttributes<any>>;
24
24
  urlUpload: ({ placeholder, value, onChange, mediaType, ...props }: import("../Upload/modal").IUrlUploadProps) => JSX.Element;
25
25
  submit: ({ text, type, form, loading, ...props }: import("../Submit").ISubmitProps) => JSX.Element;
26
26
  formConfigProvider: import("react").FC<import("./modal").IFormConfigContextProps>;
27
+ textArea: ({ autoSize, ...props }: import("antd/es/input").TextAreaProps) => JSX.Element;
27
28
  };
28
29
  export default _default;
@@ -18,6 +18,7 @@ var index$7 = require('../Upload/index.js');
18
18
  var index$8 = require('../Upload/UrlUpload/index.js');
19
19
  var index$9 = require('../Submit/index.js');
20
20
  var FormConfigProvider = require('./Context/FormConfigProvider.js');
21
+ var index$a = require('../TextArea/index.js');
21
22
 
22
23
  var placeholderConfig = {
23
24
  inputType: ["input", "inputNumber", "selectInput", "buttonInput"],
@@ -39,7 +40,8 @@ var FormConfig = {
39
40
  upload: index$7.default,
40
41
  urlUpload: index$8.default,
41
42
  submit: index$9.default,
42
- formConfigProvider: FormConfigProvider.default
43
+ formConfigProvider: FormConfigProvider.default,
44
+ textArea: index$a.default
43
45
  };
44
46
 
45
47
  exports.default = FormConfig;
@@ -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 {};
@@ -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 _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; }
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(key) {
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
- _forEachInstanceProperty(items).call(items, function (fn) {
68
- fn();
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(key, fn) {
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] = [fn];
113
+ dispatchSourceData[key] = norAddItemDispatch(name, fn);
75
114
  return;
76
115
  }
77
- items.push(fn);
78
- dispatchSourceData[key] = items;
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(key) {
81
- if (!key) {
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$4 = require('./FormItem/index.js');
11
- var index$1 = require('./hooks/index.js');
12
- var index$3 = require('./Context/index.js');
13
- var index$2 = require('../PageHandler/index.js');
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 index = (function (_ref) {
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$1.useCurrentForm(form);
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$1.useSub({
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 _useInit = index$1.useInit({
43
- infoRequest: infoRequest,
44
- initialValues: initialValues
45
- }),
46
- infoRun = _useInit.infoRun,
47
- infoLoading = _useInit.infoLoading,
48
- infoErr = _useInit.infoErr,
49
- infoData = _useInit.infoData;
50
- return /*#__PURE__*/React.createElement(index$2.default, {
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$3.FormContext.Provider, {
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$4.default, _extends({}, itemData, {
99
+ return /*#__PURE__*/React.createElement(index$3.default, _extends({}, itemData, {
67
100
  key: index,
68
101
  labelWidth: itemLabelWidth || labelWidth
69
102
  }));
70
- })), /*#__PURE__*/React.createElement(InitSet.default, {
71
- initValues: infoData
72
- })));
103
+ }), /*#__PURE__*/React.createElement(InitSet.default, null))));
73
104
  });
74
105
 
75
- exports.default = index;
106
+ exports.default = HForm;
76
107
  // powered by h