@hw-component/form 1.9.70 → 1.9.72
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/.eslintcache +1 -1
- package/es/DialogForm/DrawerForm/index.js +40 -32
- package/es/DialogForm/ModalForm.js +40 -32
- package/es/DialogForm/hooks.d.ts +7 -3
- package/es/DialogForm/hooks.js +3 -4
- package/es/DialogForm/modal.d.ts +3 -2
- package/es/Form/Basic.d.ts +1 -1
- package/es/Form/FormItem/index.js +2 -0
- package/es/Form/HFormConnect.d.ts +2 -3
- package/es/Form/HFormConnect.js +2 -32
- package/es/Form/config.d.ts +1 -0
- package/es/Form/config.js +4 -2
- package/es/Form/hooks/index.d.ts +1 -0
- package/es/Form/hooks/useAddFormat.d.ts +8 -0
- package/es/Form/hooks/useAddFormat.js +44 -0
- package/es/Form/modal.d.ts +5 -0
- package/es/RichEditor/hooks.d.ts +15 -0
- package/es/RichEditor/hooks.js +110 -0
- package/es/RichEditor/index.d.ts +4 -0
- package/es/RichEditor/index.js +96 -0
- package/es/RichEditor/modal.d.ts +11 -0
- package/es/config.js +27 -1
- package/es/index.css +22 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +2 -1
- package/lib/DialogForm/DrawerForm/index.js +40 -32
- package/lib/DialogForm/ModalForm.js +40 -32
- package/lib/DialogForm/hooks.d.ts +7 -3
- package/lib/DialogForm/hooks.js +3 -4
- package/lib/DialogForm/modal.d.ts +3 -2
- package/lib/Form/Basic.d.ts +1 -1
- package/lib/Form/FormItem/index.js +2 -0
- package/lib/Form/HFormConnect.d.ts +2 -3
- package/lib/Form/HFormConnect.js +2 -32
- package/lib/Form/config.d.ts +1 -0
- package/lib/Form/config.js +4 -2
- package/lib/Form/hooks/index.d.ts +1 -0
- package/lib/Form/hooks/useAddFormat.d.ts +8 -0
- package/lib/Form/hooks/useAddFormat.js +48 -0
- package/lib/Form/modal.d.ts +5 -0
- package/lib/RichEditor/hooks.d.ts +15 -0
- package/lib/RichEditor/hooks.js +114 -0
- package/lib/RichEditor/index.d.ts +4 -0
- package/lib/RichEditor/index.js +99 -0
- package/lib/RichEditor/modal.d.ts +11 -0
- package/lib/config.js +27 -1
- package/lib/index.css +22 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/package.json +2 -1
- package/src/components/DialogForm/DrawerForm/index.tsx +18 -10
- package/src/components/DialogForm/ModalForm.tsx +18 -9
- package/src/components/DialogForm/hooks.tsx +12 -10
- package/src/components/DialogForm/modal.ts +4 -3
- package/src/components/Form/Basic.tsx +5 -9
- package/src/components/Form/FormItem/BasicItem.tsx +5 -3
- package/src/components/Form/FormItem/index.tsx +2 -0
- package/src/components/Form/HFormConnect.tsx +3 -39
- package/src/components/Form/config.ts +4 -0
- package/src/components/Form/hooks/index.ts +4 -0
- package/src/components/Form/hooks/useAddFormat.tsx +44 -0
- package/src/components/Form/index.less +4 -3
- package/src/components/Form/modal.ts +9 -3
- package/src/components/InputGroup/index.tsx +2 -2
- package/src/components/RichEditor/hooks.ts +83 -0
- package/src/components/RichEditor/index.less +26 -0
- package/src/components/RichEditor/index.tsx +84 -0
- package/src/components/RichEditor/modal.ts +13 -0
- package/src/components/Upload/hooks/change.ts +4 -5
- package/src/components/config.ts +8 -0
- package/src/components/index.tsx +2 -0
- package/src/components/styles/index.less +1 -0
- package/src/pages/Form/index.tsx +31 -19
- package/src/pages/Input/index.tsx +1 -1
- package/src/pages/ModalForm/index.tsx +1 -0
- package/src/pages/Select/index.tsx +2 -2
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IHRichEditorProps } from "src/components/RichEditor/modal";
|
|
2
|
+
export declare const useProps: ({ fileRequest, valueType }: IHRichEditorProps) => {
|
|
3
|
+
fileRequest: any;
|
|
4
|
+
valueType: any;
|
|
5
|
+
};
|
|
6
|
+
export declare const useFocusClassname: ({ bordered, onFocus: focusProps, onBlur: blurProps, }: IHRichEditorProps) => {
|
|
7
|
+
focusClassname: string;
|
|
8
|
+
onFocus: (editState: any) => void;
|
|
9
|
+
onBlur: (editState: any) => void;
|
|
10
|
+
};
|
|
11
|
+
export declare const useVC: ({ value, onChange, valueType }: IHRichEditorProps) => {
|
|
12
|
+
richValue: any;
|
|
13
|
+
change: (editorState: any) => void;
|
|
14
|
+
};
|
|
15
|
+
export declare const useUploadFn: ({ fileRequest }: IHRichEditorProps) => (params: any) => Promise<void>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
|
|
4
|
+
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
5
|
+
var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
|
|
6
|
+
var FormConfigProvider = require('../Form/Context/FormConfigProvider.js');
|
|
7
|
+
var config = require('../config.js');
|
|
8
|
+
var index = require('../hooks/index.js');
|
|
9
|
+
var React = require('react');
|
|
10
|
+
var BraftEditor = require('braft-editor');
|
|
11
|
+
|
|
12
|
+
var useProps = function useProps(_ref) {
|
|
13
|
+
var _baseConfig$richEdito;
|
|
14
|
+
var fileRequest = _ref.fileRequest,
|
|
15
|
+
valueType = _ref.valueType;
|
|
16
|
+
var _useFormConfigContext = FormConfigProvider.useFormConfigContext("richEditorProps"),
|
|
17
|
+
_useFormConfigContext2 = _useFormConfigContext.fileRequest,
|
|
18
|
+
contextFileRequest = _useFormConfigContext2 === void 0 ? fileRequest : _useFormConfigContext2,
|
|
19
|
+
_useFormConfigContext3 = _useFormConfigContext.valueType,
|
|
20
|
+
contextValueType = _useFormConfigContext3 === void 0 ? valueType : _useFormConfigContext3;
|
|
21
|
+
var cuRequest = fileRequest === null ? (_baseConfig$richEdito = config.baseConfig.richEditorProps) === null || _baseConfig$richEdito === void 0 ? void 0 : _baseConfig$richEdito.fileRequest : contextFileRequest;
|
|
22
|
+
return {
|
|
23
|
+
fileRequest: cuRequest,
|
|
24
|
+
valueType: contextValueType
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
var useFocusClassname = function useFocusClassname(_ref2) {
|
|
28
|
+
var bordered = _ref2.bordered,
|
|
29
|
+
focusProps = _ref2.onFocus,
|
|
30
|
+
blurProps = _ref2.onBlur;
|
|
31
|
+
var styleFocusClassName = index.useClassName("hw-rich-editor-focus");
|
|
32
|
+
var _useState = React.useState(""),
|
|
33
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
34
|
+
focusClassname = _useState2[0],
|
|
35
|
+
setFocusClassname = _useState2[1];
|
|
36
|
+
var onFocus = function onFocus(editState) {
|
|
37
|
+
focusProps === null || focusProps === void 0 || focusProps(editState);
|
|
38
|
+
if (!bordered) {
|
|
39
|
+
setFocusClassname("");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
setFocusClassname(styleFocusClassName);
|
|
43
|
+
};
|
|
44
|
+
var onBlur = function onBlur(editState) {
|
|
45
|
+
setFocusClassname("");
|
|
46
|
+
blurProps === null || blurProps === void 0 || blurProps(editState);
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
focusClassname: focusClassname,
|
|
50
|
+
onFocus: onFocus,
|
|
51
|
+
onBlur: onBlur
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
var useVC = function useVC(_ref3) {
|
|
55
|
+
var value = _ref3.value,
|
|
56
|
+
onChange = _ref3.onChange,
|
|
57
|
+
valueType = _ref3.valueType;
|
|
58
|
+
var richValue = valueType === "html" ? BraftEditor.createEditorState(value) : value;
|
|
59
|
+
var change = function change(editorState) {
|
|
60
|
+
var changeVal = valueType === "html" ? editorState.toHTML() : editorState;
|
|
61
|
+
var isEmpty = !!richValue ? richValue.isEmpty() : true;
|
|
62
|
+
if (isEmpty && editorState.isEmpty()) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
onChange === null || onChange === void 0 || onChange(changeVal);
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
richValue: richValue,
|
|
69
|
+
change: change
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
var useUploadFn = function useUploadFn(_ref4) {
|
|
73
|
+
var fileRequest = _ref4.fileRequest;
|
|
74
|
+
return /*#__PURE__*/function () {
|
|
75
|
+
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
|
|
76
|
+
var file, id, _yield$fileRequest, url;
|
|
77
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
78
|
+
while (1) switch (_context.prev = _context.next) {
|
|
79
|
+
case 0:
|
|
80
|
+
file = params.file, id = params.id;
|
|
81
|
+
_context.next = 3;
|
|
82
|
+
return fileRequest === null || fileRequest === void 0 ? void 0 : fileRequest(file, params);
|
|
83
|
+
case 3:
|
|
84
|
+
_yield$fileRequest = _context.sent;
|
|
85
|
+
url = _yield$fileRequest.url;
|
|
86
|
+
params.success({
|
|
87
|
+
url: url,
|
|
88
|
+
meta: {
|
|
89
|
+
id: id,
|
|
90
|
+
title: file.name,
|
|
91
|
+
alt: "媒体资源",
|
|
92
|
+
loop: false,
|
|
93
|
+
autoPlay: false,
|
|
94
|
+
controls: true,
|
|
95
|
+
poster: url
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
case 6:
|
|
99
|
+
case "end":
|
|
100
|
+
return _context.stop();
|
|
101
|
+
}
|
|
102
|
+
}, _callee);
|
|
103
|
+
}));
|
|
104
|
+
return function (_x) {
|
|
105
|
+
return _ref5.apply(this, arguments);
|
|
106
|
+
};
|
|
107
|
+
}();
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
exports.useFocusClassname = useFocusClassname;
|
|
111
|
+
exports.useProps = useProps;
|
|
112
|
+
exports.useUploadFn = useUploadFn;
|
|
113
|
+
exports.useVC = useVC;
|
|
114
|
+
// powered by h
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
6
|
+
var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
var BraftEditor = require('braft-editor');
|
|
9
|
+
require('braft-editor/dist/index.css');
|
|
10
|
+
var hooks = require('./hooks.js');
|
|
11
|
+
var index = require('../hooks/index.js');
|
|
12
|
+
var React = require('react');
|
|
13
|
+
var HFormConnect = require('../Form/HFormConnect.js');
|
|
14
|
+
|
|
15
|
+
var _excluded = ["value", "onChange", "valueType", "fileRequest", "media", "contentStyle", "bordered", "onBlur", "onFocus", "addFormat"];
|
|
16
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
|
+
var defaultContentStyle = {
|
|
19
|
+
height: 400
|
|
20
|
+
};
|
|
21
|
+
var Index = function Index(_ref, ref) {
|
|
22
|
+
var value = _ref.value,
|
|
23
|
+
onChange = _ref.onChange,
|
|
24
|
+
valueType = _ref.valueType,
|
|
25
|
+
fileRequest = _ref.fileRequest,
|
|
26
|
+
media = _ref.media,
|
|
27
|
+
_ref$contentStyle = _ref.contentStyle,
|
|
28
|
+
contentStyle = _ref$contentStyle === void 0 ? defaultContentStyle : _ref$contentStyle,
|
|
29
|
+
_ref$bordered = _ref.bordered,
|
|
30
|
+
bordered = _ref$bordered === void 0 ? true : _ref$bordered,
|
|
31
|
+
onBlur = _ref.onBlur,
|
|
32
|
+
onFocus = _ref.onFocus,
|
|
33
|
+
addFormat = _ref.addFormat,
|
|
34
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
35
|
+
var _useProps = hooks.useProps({
|
|
36
|
+
fileRequest: fileRequest,
|
|
37
|
+
valueType: valueType
|
|
38
|
+
}),
|
|
39
|
+
fileReq = _useProps.fileRequest,
|
|
40
|
+
vType = _useProps.valueType;
|
|
41
|
+
var _useFocusClassname = hooks.useFocusClassname({
|
|
42
|
+
bordered: bordered,
|
|
43
|
+
onBlur: onBlur,
|
|
44
|
+
onFocus: onFocus
|
|
45
|
+
}),
|
|
46
|
+
focusClassname = _useFocusClassname.focusClassname,
|
|
47
|
+
selfFocus = _useFocusClassname.onFocus,
|
|
48
|
+
selfBlur = _useFocusClassname.onBlur;
|
|
49
|
+
var _useVC = hooks.useVC({
|
|
50
|
+
value: value,
|
|
51
|
+
onChange: onChange,
|
|
52
|
+
valueType: vType
|
|
53
|
+
}),
|
|
54
|
+
richValue = _useVC.richValue,
|
|
55
|
+
change = _useVC.change;
|
|
56
|
+
var uploadFn = hooks.useUploadFn({
|
|
57
|
+
fileRequest: fileReq
|
|
58
|
+
});
|
|
59
|
+
var bodyClassName = index.useClassName("hw-rich-editor");
|
|
60
|
+
var borderClassName = index.useClassName("hw-rich-editor-border");
|
|
61
|
+
addFormat === null || addFormat === void 0 || addFormat({
|
|
62
|
+
float: {
|
|
63
|
+
inputValue: function inputValue(item, initValue) {
|
|
64
|
+
var _item$name = item.name,
|
|
65
|
+
name = _item$name === void 0 ? "" : _item$name;
|
|
66
|
+
var keyName = name;
|
|
67
|
+
var itemVal = initValue[keyName];
|
|
68
|
+
var initVal = typeof itemVal === "string" ? BraftEditor.createEditorState(itemVal) : itemVal;
|
|
69
|
+
return _defineProperty({}, keyName, initVal);
|
|
70
|
+
},
|
|
71
|
+
outputValue: function outputValue(item, _outputValue) {
|
|
72
|
+
var _item$name2 = item.name,
|
|
73
|
+
name = _item$name2 === void 0 ? "" : _item$name2;
|
|
74
|
+
var keyName = name;
|
|
75
|
+
var itemVal = _outputValue[keyName];
|
|
76
|
+
var outputVal = typeof itemVal === "string" ? itemVal : itemVal === null || itemVal === void 0 ? void 0 : itemVal.toHTML();
|
|
77
|
+
return _defineProperty({}, keyName, outputVal);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return jsxRuntime.jsx("div", {
|
|
82
|
+
className: "".concat(bodyClassName, " ").concat(bordered ? borderClassName : "", " ").concat(focusClassname),
|
|
83
|
+
children: jsxRuntime.jsx(BraftEditor, _objectSpread({
|
|
84
|
+
contentStyle: contentStyle,
|
|
85
|
+
value: richValue,
|
|
86
|
+
onChange: change,
|
|
87
|
+
onFocus: selfFocus,
|
|
88
|
+
ref: ref,
|
|
89
|
+
onBlur: selfBlur,
|
|
90
|
+
media: _objectSpread({
|
|
91
|
+
uploadFn: uploadFn
|
|
92
|
+
}, media)
|
|
93
|
+
}, props))
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
var HRichEditor = HFormConnect.default(/*#__PURE__*/React.forwardRef(Index));
|
|
97
|
+
|
|
98
|
+
exports.default = HRichEditor;
|
|
99
|
+
// powered by h
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BraftEditorProps, EditorState } from "braft-editor";
|
|
2
|
+
import { PromiseFnResult } from "../modal";
|
|
3
|
+
import { addFormatItemModal } from "../Form/modal";
|
|
4
|
+
export interface IHRichEditorProps extends Omit<BraftEditorProps, "value" | "onChange"> {
|
|
5
|
+
value?: string | EditorState;
|
|
6
|
+
onChange?: (value: string | EditorState) => void;
|
|
7
|
+
fileRequest?: PromiseFnResult;
|
|
8
|
+
valueType?: "html" | "state";
|
|
9
|
+
bordered?: boolean;
|
|
10
|
+
addFormat?: (config: Record<string, addFormatItemModal>) => void;
|
|
11
|
+
}
|
package/lib/config.js
CHANGED
|
@@ -70,7 +70,33 @@ var baseConfig = {
|
|
|
70
70
|
},
|
|
71
71
|
defaultComponent: {},
|
|
72
72
|
formItemStyle: {},
|
|
73
|
-
itemProps: {}
|
|
73
|
+
itemProps: {},
|
|
74
|
+
richEditorProps: {
|
|
75
|
+
fileRequest: function () {
|
|
76
|
+
var _fileRequest = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(file) {
|
|
77
|
+
var url;
|
|
78
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
79
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
80
|
+
case 0:
|
|
81
|
+
_context2.next = 2;
|
|
82
|
+
return util.fileToBase64(file);
|
|
83
|
+
case 2:
|
|
84
|
+
url = _context2.sent;
|
|
85
|
+
return _context2.abrupt("return", {
|
|
86
|
+
url: url
|
|
87
|
+
});
|
|
88
|
+
case 4:
|
|
89
|
+
case "end":
|
|
90
|
+
return _context2.stop();
|
|
91
|
+
}
|
|
92
|
+
}, _callee2);
|
|
93
|
+
}));
|
|
94
|
+
function fileRequest(_x2) {
|
|
95
|
+
return _fileRequest.apply(this, arguments);
|
|
96
|
+
}
|
|
97
|
+
return fileRequest;
|
|
98
|
+
}()
|
|
99
|
+
}
|
|
74
100
|
};
|
|
75
101
|
|
|
76
102
|
exports.baseConfig = baseConfig;
|
package/lib/index.css
CHANGED
|
@@ -290,3 +290,25 @@
|
|
|
290
290
|
.ant-form-item-has-error .ant-hw-input-group-body {
|
|
291
291
|
border-color: #ff4d4f !important;
|
|
292
292
|
}
|
|
293
|
+
.ant-hw-rich-editor {
|
|
294
|
+
box-sizing: border-box;
|
|
295
|
+
width: 100%;
|
|
296
|
+
}
|
|
297
|
+
.ant-hw-rich-editor .bf-container .public-DraftEditorPlaceholder-root {
|
|
298
|
+
color: #bfbfbf;
|
|
299
|
+
font-size: 14px;
|
|
300
|
+
}
|
|
301
|
+
.ant-hw-rich-editor-border {
|
|
302
|
+
border: 1px solid #d9d9d9;
|
|
303
|
+
border-radius: 2px;
|
|
304
|
+
}
|
|
305
|
+
.ant-hw-rich-editor-border:hover {
|
|
306
|
+
border-color: #40a9ff;
|
|
307
|
+
}
|
|
308
|
+
.ant-hw-rich-editor-focus {
|
|
309
|
+
border-color: #40a9ff;
|
|
310
|
+
box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
|
|
311
|
+
}
|
|
312
|
+
.ant-form-item-has-error .ant-hw-rich-editor-border {
|
|
313
|
+
border-color: #ff4d4f !important;
|
|
314
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export { default as HBasicForm } from "./Form/Basic";
|
|
|
8
8
|
export { default as HInputGroup } from "./InputGroup";
|
|
9
9
|
export declare const HSelect: import("react").ForwardRefExoticComponent<import("./Form/modal").HFormItemProps & import("react").RefAttributes<any>>;
|
|
10
10
|
export declare const HInput: ({ copy: copyProps, value, addonAfter, ...props }: import("./Input/modal").HInputProps) => JSX.Element;
|
|
11
|
+
export declare const HRichEditor: import("react").ForwardRefExoticComponent<import("./Form/modal").HFormItemProps & import("react").RefAttributes<any>>;
|
|
11
12
|
export declare const HSelectInput: import("react").ForwardRefExoticComponent<import("./Form/modal").HFormItemProps & import("react").RefAttributes<any>>;
|
|
12
13
|
export declare const HUpload: import("react").ForwardRefExoticComponent<import("./Form/modal").HFormItemProps & import("react").RefAttributes<any>>;
|
|
13
14
|
export declare const HUrlUpload: ({ placeholder, value, onChange, mediaType, inputHelper, style, exFiles, spaceSize, ...props }: import("./Upload/modal").IUrlUploadProps) => JSX.Element;
|
package/lib/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var index$3 = require('./DialogForm/DrawerForm/index.js');
|
|
|
14
14
|
|
|
15
15
|
var HSelect = config.default.select;
|
|
16
16
|
var HInput = config.default.input;
|
|
17
|
+
var HRichEditor = config.default.richEditor;
|
|
17
18
|
var HSelectInput = config.default.selectInput;
|
|
18
19
|
var HUpload = config.default.upload;
|
|
19
20
|
var HUrlUpload = config.default.urlUpload.Component;
|
|
@@ -58,6 +59,7 @@ exports.HModalForm = HModalForm;
|
|
|
58
59
|
exports.HPageHandler = HPageHandler;
|
|
59
60
|
exports.HRadioGroup = HRadioGroup;
|
|
60
61
|
exports.HRangePicker = HRangePicker;
|
|
62
|
+
exports.HRichEditor = HRichEditor;
|
|
61
63
|
exports.HSelect = HSelect;
|
|
62
64
|
exports.HSelectInput = HSelectInput;
|
|
63
65
|
exports.HSwitch = HSwitch;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hw-component/form",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.72",
|
|
4
4
|
"description": "基于antd二次开发",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@babel/runtime-corejs3": "^7.26.0",
|
|
38
38
|
"ahooks": "2.10.9",
|
|
39
|
+
"braft-editor": "^2.3.9",
|
|
39
40
|
"copy-to-clipboard": "3.3.1",
|
|
40
41
|
"react-color": "2.19.3"
|
|
41
42
|
},
|
|
@@ -66,14 +66,29 @@ const Index: React.FC<DialogFormProps> = ({
|
|
|
66
66
|
setModalVisible(false);
|
|
67
67
|
};
|
|
68
68
|
const { loading, run } = useSub({ request, onFinish });
|
|
69
|
-
|
|
69
|
+
const finish=async (values, subParams) => {
|
|
70
|
+
const result = await run(values, subParams);
|
|
71
|
+
const close = onOk?.(result, subParams);
|
|
72
|
+
if (close === false) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
cancel();
|
|
76
|
+
}
|
|
77
|
+
const footerOnOk=()=>{
|
|
78
|
+
if (modalFormData){
|
|
79
|
+
dialogForm?.submit();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
finish({},formParams);
|
|
83
|
+
}
|
|
70
84
|
const defaultFooter = useFooterRender({
|
|
71
85
|
dialogForm,
|
|
72
86
|
footer,
|
|
73
87
|
confirmLoading: loading,
|
|
74
88
|
params: formParams,
|
|
89
|
+
onOk :footerOnOk
|
|
75
90
|
});
|
|
76
|
-
const node = (
|
|
91
|
+
const node = modalFormData&&(
|
|
77
92
|
<HForm
|
|
78
93
|
configData={modalFormData}
|
|
79
94
|
initialValues={initValue}
|
|
@@ -81,14 +96,7 @@ const Index: React.FC<DialogFormProps> = ({
|
|
|
81
96
|
{...props}
|
|
82
97
|
form={currentForm}
|
|
83
98
|
params={formParams}
|
|
84
|
-
onFinish={
|
|
85
|
-
const result = await run(values, subParams);
|
|
86
|
-
const close = onOk?.(result, subParams);
|
|
87
|
-
if (close === false) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
cancel();
|
|
91
|
-
}}
|
|
99
|
+
onFinish={finish}
|
|
92
100
|
infoRequest={infoRequest}
|
|
93
101
|
labelWidth={labelWidth}
|
|
94
102
|
/>
|
|
@@ -58,19 +58,27 @@ const Index: React.FC<DialogFormProps> = ({
|
|
|
58
58
|
setModalVisible(false);
|
|
59
59
|
};
|
|
60
60
|
const { loading, run } = useSub({ request, onFinish });
|
|
61
|
-
const
|
|
61
|
+
const finish=async (values, outParams)=>{
|
|
62
|
+
const result = await run(values, outParams);
|
|
63
|
+
const close = onOk?.(result, outParams);
|
|
64
|
+
if (close === false) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
cancel();
|
|
68
|
+
}
|
|
69
|
+
const footerOnOk=()=>{
|
|
70
|
+
if (modalFormData){
|
|
71
|
+
dialogForm?.submit();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
finish({},formParams);
|
|
75
|
+
}
|
|
76
|
+
const node = modalFormData&&(
|
|
62
77
|
<HForm
|
|
63
78
|
configData={modalFormData}
|
|
64
79
|
initialValues={initValue}
|
|
65
80
|
onValuesChange={onValuesChange}
|
|
66
|
-
onFinish={
|
|
67
|
-
const result = await run(values, outParams);
|
|
68
|
-
const close = onOk?.(result, outParams);
|
|
69
|
-
if (close === false) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
cancel();
|
|
73
|
-
}}
|
|
81
|
+
onFinish={finish}
|
|
74
82
|
{...props}
|
|
75
83
|
params={formParams}
|
|
76
84
|
form={currentForm}
|
|
@@ -82,6 +90,7 @@ const Index: React.FC<DialogFormProps> = ({
|
|
|
82
90
|
footer,
|
|
83
91
|
confirmLoading: loading,
|
|
84
92
|
params: formParams,
|
|
93
|
+
onOk:footerOnOk
|
|
85
94
|
});
|
|
86
95
|
return (
|
|
87
96
|
<Modal
|
|
@@ -72,9 +72,9 @@ export const useModifyProps = ({
|
|
|
72
72
|
setModalVisible(false);
|
|
73
73
|
};
|
|
74
74
|
}, [afterClose, autoClear]);
|
|
75
|
-
dialogForm.getParams=()=>{
|
|
76
|
-
return (formParams as Record<string, any>)||{};
|
|
77
|
-
}
|
|
75
|
+
dialogForm.getParams = () => {
|
|
76
|
+
return (formParams as Record<string, any>) || {};
|
|
77
|
+
};
|
|
78
78
|
return {
|
|
79
79
|
modalFormData,
|
|
80
80
|
modalVisible,
|
|
@@ -94,9 +94,9 @@ export const useHDialogForm = () => {
|
|
|
94
94
|
...hForm,
|
|
95
95
|
show: (params) => {},
|
|
96
96
|
hide: () => {},
|
|
97
|
-
getParams:()=>{
|
|
98
|
-
return {}
|
|
99
|
-
}
|
|
97
|
+
getParams: () => {
|
|
98
|
+
return {};
|
|
99
|
+
},
|
|
100
100
|
};
|
|
101
101
|
}, []);
|
|
102
102
|
};
|
|
@@ -119,13 +119,17 @@ export const useSub = ({ request, onFinish }: Partial<DialogFormProps>) => {
|
|
|
119
119
|
{ manual: true }
|
|
120
120
|
);
|
|
121
121
|
};
|
|
122
|
+
interface FooterRenderParamsModal extends Omit<DialogFormProps, "configData">{
|
|
123
|
+
onOk:VoidFunction;
|
|
124
|
+
}
|
|
122
125
|
|
|
123
126
|
export const useFooterRender = ({
|
|
124
127
|
footer,
|
|
125
128
|
confirmLoading,
|
|
126
129
|
dialogForm,
|
|
127
130
|
params,
|
|
128
|
-
|
|
131
|
+
onOk
|
|
132
|
+
}: FooterRenderParamsModal) => {
|
|
129
133
|
if (footer === null) {
|
|
130
134
|
return null;
|
|
131
135
|
}
|
|
@@ -138,9 +142,7 @@ export const useFooterRender = ({
|
|
|
138
142
|
onCancel={() => {
|
|
139
143
|
dialogForm?.hide();
|
|
140
144
|
}}
|
|
141
|
-
onOk={
|
|
142
|
-
dialogForm?.submit();
|
|
143
|
-
}}
|
|
145
|
+
onOk={onOk}
|
|
144
146
|
confirmLoading={confirmLoading}
|
|
145
147
|
/>
|
|
146
148
|
)
|
|
@@ -6,7 +6,7 @@ import type React from "react";
|
|
|
6
6
|
type RootProps = HFormProps & ModalProps;
|
|
7
7
|
|
|
8
8
|
export interface ModifyPropsModal<P = any> {
|
|
9
|
-
configData
|
|
9
|
+
configData?: HItemProps[];
|
|
10
10
|
visible?: boolean;
|
|
11
11
|
initialValues?: Record<string, any>;
|
|
12
12
|
dialogForm: HDialogFormInstance;
|
|
@@ -28,7 +28,7 @@ export interface ShowParamsModal<P = any, T = any> {
|
|
|
28
28
|
export interface HDialogFormInstance<P = any, T = any> extends HFormInstance {
|
|
29
29
|
show: (data?: ShowParamsModal<P, T>) => void;
|
|
30
30
|
hide: VoidFunction;
|
|
31
|
-
getParams:()=>Record<string, any>;
|
|
31
|
+
getParams: () => Record<string, any>;
|
|
32
32
|
}
|
|
33
33
|
export type FooterRender = (
|
|
34
34
|
dialogForm?: HDialogFormInstance,
|
|
@@ -38,9 +38,10 @@ export type FooterRender = (
|
|
|
38
38
|
export interface DialogFormProps<P = any, T = any>
|
|
39
39
|
extends Omit<
|
|
40
40
|
RootProps,
|
|
41
|
-
"onFinish" | "onCancel" | "onOk" | "infoRequest" | "title" | "footer"
|
|
41
|
+
"onFinish" | "onCancel" | "onOk" | "infoRequest" | "title" | "footer"|"configData"
|
|
42
42
|
> {
|
|
43
43
|
dialogForm?: HDialogFormInstance;
|
|
44
|
+
configData?:HFormProps["configData"];
|
|
44
45
|
onFinish?: (values: T, params: P) => Promise<any>;
|
|
45
46
|
onCancel?: VoidFunction;
|
|
46
47
|
onOk?: (data: T, params: P) => boolean | void;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
HFormProps,
|
|
3
|
-
HItemProps,
|
|
4
|
-
ItemPropsType,
|
|
5
|
-
} from "./modal";
|
|
1
|
+
import type { HFormProps, HItemProps, ItemPropsType } from "./modal";
|
|
6
2
|
import Item from "./FormItem";
|
|
7
3
|
import { Row } from "antd";
|
|
8
4
|
import { useFormContext } from "./Context";
|
|
@@ -15,8 +11,8 @@ export default ({
|
|
|
15
11
|
dismissOnPressEnter = true,
|
|
16
12
|
itemSpan,
|
|
17
13
|
labelWidth,
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
formItemStyle,
|
|
15
|
+
flexBox: formFlexBox,
|
|
20
16
|
}: HFormProps) => {
|
|
21
17
|
const {
|
|
22
18
|
form,
|
|
@@ -49,7 +45,7 @@ export default ({
|
|
|
49
45
|
colon: itemColon,
|
|
50
46
|
itemSpan: configItemSpan,
|
|
51
47
|
nameKey,
|
|
52
|
-
|
|
48
|
+
flexBox = formFlexBox,
|
|
53
49
|
} = itemData;
|
|
54
50
|
const defaultItemProps = {
|
|
55
51
|
onPressEnter: dismissOnPressEnter ? undefined : defaultOnPressEnter,
|
|
@@ -58,7 +54,7 @@ export default ({
|
|
|
58
54
|
};
|
|
59
55
|
const arrayName = Array.isArray(name) ? name.join(".") : name;
|
|
60
56
|
const key = arrayName || nameKey;
|
|
61
|
-
const itemStyle=style||formItemStyle;
|
|
57
|
+
const itemStyle = style || formItemStyle;
|
|
62
58
|
return (
|
|
63
59
|
<Item
|
|
64
60
|
{...itemData}
|
|
@@ -56,7 +56,7 @@ const Index: React.FC<HFormItemProps> = (props) => {
|
|
|
56
56
|
noStyle = false,
|
|
57
57
|
hidden,
|
|
58
58
|
rowWrapper,
|
|
59
|
-
|
|
59
|
+
flexBox,
|
|
60
60
|
...oProps
|
|
61
61
|
} = props;
|
|
62
62
|
const { labelAlign: align = "right", itemProps, ...inProps } = props;
|
|
@@ -73,7 +73,7 @@ const Index: React.FC<HFormItemProps> = (props) => {
|
|
|
73
73
|
{ ...inProps, itemProps: defaultItemProps },
|
|
74
74
|
defaultComponent
|
|
75
75
|
);
|
|
76
|
-
const rowClassname=useClassName("hw-form-item-row");
|
|
76
|
+
const rowClassname = useClassName("hw-form-item-row");
|
|
77
77
|
const className = usePositionClassName(align);
|
|
78
78
|
const hideItem = useHide({ hide, form });
|
|
79
79
|
const disHide = useHide({ hide: hidden, form });
|
|
@@ -87,7 +87,9 @@ const Index: React.FC<HFormItemProps> = (props) => {
|
|
|
87
87
|
return (
|
|
88
88
|
<Col
|
|
89
89
|
{...itemSpan}
|
|
90
|
-
className={`${colClassName} ${itemClassName} ${
|
|
90
|
+
className={`${colClassName} ${itemClassName} ${
|
|
91
|
+
flexBox ? rowClassname : ""
|
|
92
|
+
}`}
|
|
91
93
|
style={colStyle}
|
|
92
94
|
>
|
|
93
95
|
<Form.Item
|
|
@@ -2,6 +2,7 @@ import { useFormItemDomControl } from "./hooks";
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import type { HItemProps } from "../modal";
|
|
4
4
|
import { useFormContext } from "../Context";
|
|
5
|
+
import useAddFormat from "../hooks/useAddFormat";
|
|
5
6
|
|
|
6
7
|
export default (props: HItemProps) => {
|
|
7
8
|
const {
|
|
@@ -20,6 +21,7 @@ export default (props: HItemProps) => {
|
|
|
20
21
|
colon,
|
|
21
22
|
rowWrapper = formRowWrapper,
|
|
22
23
|
} = props;
|
|
24
|
+
useAddFormat(props);
|
|
23
25
|
const Component = useFormItemDomControl(props);
|
|
24
26
|
return (
|
|
25
27
|
<Component
|
|
@@ -1,44 +1,14 @@
|
|
|
1
1
|
import { useFormContext } from "./Context";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import type { addFormatItemModal } from "@/components/Form/modal";
|
|
6
|
-
import type { ConnectResultProps } from "@/components/Form/modal";
|
|
7
|
-
import type { argsFn } from "@/components/Form/modal";
|
|
8
|
-
interface ResultModal {
|
|
9
|
-
inputValue?: (value: Record<string, any>) => Record<string, any>;
|
|
10
|
-
outputValue?: (value: Record<string, any>) => Record<string, any>;
|
|
11
|
-
}
|
|
12
|
-
const formatMaker = (
|
|
13
|
-
itemProps: HFormItemProps,
|
|
14
|
-
formats?: addFormatItemModal
|
|
15
|
-
) => {
|
|
16
|
-
const { inputValue, outputValue } = formats || {};
|
|
17
|
-
const { initValueProvider = inputValue, subProvider = outputValue } =
|
|
18
|
-
itemProps;
|
|
19
|
-
const resultObj: ResultModal = {};
|
|
20
|
-
if (initValueProvider) {
|
|
21
|
-
resultObj.inputValue = (value) => {
|
|
22
|
-
return initValueProvider(itemProps, value);
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
if (subProvider) {
|
|
26
|
-
resultObj.outputValue = (value) => {
|
|
27
|
-
return subProvider(itemProps, value);
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
const keysLen = Object.keys(resultObj).length;
|
|
31
|
-
return keysLen === 0 ? undefined : resultObj;
|
|
32
|
-
};
|
|
2
|
+
import React from "react";
|
|
3
|
+
import type { addFormatItemModal ,HFormItemProps,ConnectResultProps,argsFn} from "./modal";
|
|
4
|
+
import {formatMaker} from "./hooks/useAddFormat";
|
|
33
5
|
|
|
34
6
|
export default (
|
|
35
7
|
component:
|
|
36
8
|
| React.FunctionComponent
|
|
37
9
|
| React.ComponentClass
|
|
38
10
|
| React.ForwardRefRenderFunction<any, any>,
|
|
39
|
-
config: ConnectConfigModal = {}
|
|
40
11
|
) => {
|
|
41
|
-
const { format = {} } = config;
|
|
42
12
|
const Index: React.ForwardRefRenderFunction<any, HFormItemProps> = (
|
|
43
13
|
props: HFormItemProps,
|
|
44
14
|
ref
|
|
@@ -46,12 +16,6 @@ export default (
|
|
|
46
16
|
const { form, valueType = "float" } = useFormContext();
|
|
47
17
|
const { name } = props;
|
|
48
18
|
const relName = Array.isArray(name) ? name.join(".") : name;
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
if (!relName) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
form?.addFormat(relName, formatMaker(props, format[valueType]));
|
|
54
|
-
}, [valueType, props]);
|
|
55
19
|
const addFormat = (aFormat: Record<string, addFormatItemModal>) => {
|
|
56
20
|
if (!relName) {
|
|
57
21
|
return;
|