@hw-component/form 0.0.9-beta-v19 → 0.0.9-beta-v21

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 (116) hide show
  1. package/.eslintcache +1 -0
  2. package/.idea/hw-component-form.iml +12 -0
  3. package/.idea/inspectionProfiles/Project_Default.xml +7 -0
  4. package/.idea/misc.xml +6 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/vcs.xml +6 -0
  7. package/es/Select/modal.d.ts +1 -3
  8. package/lib/Select/modal.d.ts +1 -3
  9. package/package.json +1 -1
  10. package/public/index.html +0 -19
  11. package/scripts/rollup.config.js +0 -90
  12. package/scripts/webpack.config.js +0 -76
  13. package/src/Layout.tsx +0 -61
  14. package/src/app.tsx +0 -33
  15. package/src/components/Cascader/index.tsx +0 -31
  16. package/src/components/CheckboxGroup/CheckBox/index.tsx +0 -38
  17. package/src/components/CheckboxGroup/hooks.ts +0 -105
  18. package/src/components/CheckboxGroup/index.tsx +0 -85
  19. package/src/components/CheckboxGroup/modal.ts +0 -17
  20. package/src/components/DialogForm/DrawerForm/Footer.tsx +0 -20
  21. package/src/components/DialogForm/DrawerForm/Title.tsx +0 -12
  22. package/src/components/DialogForm/DrawerForm/index.tsx +0 -110
  23. package/src/components/DialogForm/ModalForm.tsx +0 -91
  24. package/src/components/DialogForm/hooks.ts +0 -122
  25. package/src/components/DialogForm/modal.ts +0 -44
  26. package/src/components/Form/Context/FormConfigProvider.tsx +0 -38
  27. package/src/components/Form/Context/index.tsx +0 -14
  28. package/src/components/Form/FormItem/BasicItem.tsx +0 -95
  29. package/src/components/Form/FormItem/Helper.tsx +0 -25
  30. package/src/components/Form/FormItem/RegularFormItem.tsx +0 -13
  31. package/src/components/Form/FormItem/UpFormItem.tsx +0 -21
  32. package/src/components/Form/FormItem/hooks.tsx +0 -54
  33. package/src/components/Form/FormItem/index.tsx +0 -8
  34. package/src/components/Form/HFormConnect.tsx +0 -74
  35. package/src/components/Form/InitSet.tsx +0 -10
  36. package/src/components/Form/Label.tsx +0 -50
  37. package/src/components/Form/config.ts +0 -58
  38. package/src/components/Form/hooks/index.ts +0 -114
  39. package/src/components/Form/hooks/useDefaultRender.tsx +0 -45
  40. package/src/components/Form/hooks/useHForm.ts +0 -182
  41. package/src/components/Form/hooks/useInitConfigData.tsx +0 -194
  42. package/src/components/Form/index.less +0 -54
  43. package/src/components/Form/index.tsx +0 -113
  44. package/src/components/Form/modal.ts +0 -206
  45. package/src/components/Input/ButtonInput.tsx +0 -47
  46. package/src/components/Input/ColorInput/Picker.tsx +0 -18
  47. package/src/components/Input/ColorInput/data.ts +0 -102
  48. package/src/components/Input/ColorInput/index.less +0 -10
  49. package/src/components/Input/ColorInput/index.tsx +0 -58
  50. package/src/components/Input/InputNumber.tsx +0 -5
  51. package/src/components/Input/SelectInput.tsx +0 -75
  52. package/src/components/Input/TrimInput.tsx +0 -26
  53. package/src/components/Input/VerificationCodeInput.tsx +0 -74
  54. package/src/components/Input/defaultConfig.ts +0 -8
  55. package/src/components/Input/index.tsx +0 -26
  56. package/src/components/Input/modal.ts +0 -40
  57. package/src/components/PageHandler/ErrorComponent.tsx +0 -20
  58. package/src/components/PageHandler/LoadingComponent.tsx +0 -9
  59. package/src/components/PageHandler/index.tsx +0 -14
  60. package/src/components/PageHandler/modal.ts +0 -6
  61. package/src/components/RadioGroup/index.tsx +0 -45
  62. package/src/components/Select/components/AllSelect.tsx +0 -54
  63. package/src/components/Select/components/CheckBoxOption.tsx +0 -14
  64. package/src/components/Select/components/DropdownComponent.tsx +0 -36
  65. package/src/components/Select/components/NoFindItem.tsx +0 -7
  66. package/src/components/Select/components/NotFoundContent.tsx +0 -25
  67. package/src/components/Select/defaultConfig.tsx +0 -23
  68. package/src/components/Select/hooks/changeHooks.tsx +0 -159
  69. package/src/components/Select/hooks/norHooks.ts +0 -85
  70. package/src/components/Select/index.less +0 -22
  71. package/src/components/Select/index.tsx +0 -126
  72. package/src/components/Select/modal.ts +0 -38
  73. package/src/components/Select/utils.ts +0 -18
  74. package/src/components/Submit/components.tsx +0 -57
  75. package/src/components/Submit/hooks.ts +0 -31
  76. package/src/components/Submit/index.tsx +0 -33
  77. package/src/components/Switch/index.tsx +0 -77
  78. package/src/components/TDPicker/RangePicker.tsx +0 -109
  79. package/src/components/TDPicker/TimePicker.tsx +0 -29
  80. package/src/components/TDPicker/hooks.ts +0 -150
  81. package/src/components/TDPicker/index.tsx +0 -33
  82. package/src/components/TDPicker/modal.ts +0 -48
  83. package/src/components/TextArea/TrimTextArea.tsx +0 -30
  84. package/src/components/TextArea/index.tsx +0 -8
  85. package/src/components/Upload/Btn.tsx +0 -24
  86. package/src/components/Upload/MediaTypeEle/TypeEle.tsx +0 -26
  87. package/src/components/Upload/MediaTypeEle/index.tsx +0 -34
  88. package/src/components/Upload/Preview/index.tsx +0 -14
  89. package/src/components/Upload/UrlUpload/index.tsx +0 -104
  90. package/src/components/Upload/enums.ts +0 -5
  91. package/src/components/Upload/hooks/change.ts +0 -79
  92. package/src/components/Upload/hooks/customRequest.ts +0 -87
  93. package/src/components/Upload/hooks/propsMaker.ts +0 -20
  94. package/src/components/Upload/index.tsx +0 -119
  95. package/src/components/Upload/modal.ts +0 -33
  96. package/src/components/Upload/util.ts +0 -27
  97. package/src/components/config.ts +0 -47
  98. package/src/components/hooks/index.ts +0 -53
  99. package/src/components/index.tsx +0 -37
  100. package/src/components/modal.ts +0 -20
  101. package/src/components/styles/index.less +0 -3
  102. package/src/components/styles/local.less +0 -1
  103. package/src/components/typings.d.ts +0 -11
  104. package/src/index.less +0 -20
  105. package/src/index.tsx +0 -12
  106. package/src/pages/Checkbox/index.tsx +0 -14
  107. package/src/pages/DatePicker/index.tsx +0 -33
  108. package/src/pages/DrawerForm/index.tsx +0 -145
  109. package/src/pages/Form/index.tsx +0 -172
  110. package/src/pages/Input/index.tsx +0 -30
  111. package/src/pages/ModalForm/index.tsx +0 -191
  112. package/src/pages/Radio/index.tsx +0 -18
  113. package/src/pages/Select/index.tsx +0 -63
  114. package/src/pages/Switch/index.tsx +0 -18
  115. package/src/pages/Upload/index.tsx +0 -14
  116. package/src/routes.tsx +0 -80
@@ -1,182 +0,0 @@
1
- import { useMemo } from "react";
2
- import { Form } from "antd";
3
- import type { FormatItemModal, HFormInstance } from "../modal";
4
- import type { argsFn } from "../modal";
5
-
6
- interface DispatchItemData {
7
- keysFn: Record<string, argsFn>;
8
- defaultFn: argsFn[];
9
- }
10
-
11
- export default () => {
12
- const [form] = Form.useForm();
13
- return useMemo<HFormInstance>(() => {
14
- const formatSourceData: Record<string, FormatItemModal> = {};
15
- let dispatchSourceData: Record<string, DispatchItemData> = {};
16
- const initDispatch: Record<string, argsFn> = {};
17
- let cacheValues: Record<string, any> = {};
18
- let isLoading = false;
19
- let initSaveValue = {};
20
- const norAddItemDispatch = (name, manual, fn) => {
21
- if (manual === false && name) {
22
- initDispatch[name] = fn;
23
- }
24
- if (!name) {
25
- return {
26
- keysFn: {},
27
- defaultFn: [fn],
28
- };
29
- }
30
- return {
31
- keysFn: {
32
- [name]: fn,
33
- },
34
- defaultFn: [],
35
- };
36
- };
37
- return {
38
- reload: (params) => {
39
- return Promise.resolve(params);
40
- },
41
- initValues() {
42
- let newValue = {};
43
- if (cacheValues) {
44
- newValue = this.formatValues(cacheValues);
45
- initSaveValue = newValue;
46
- form.setFieldsValue(newValue);
47
- }
48
- const initKeys = Object.keys(initDispatch);
49
- initKeys.forEach((key) => {
50
- initDispatch[key]({ changedValues: newValue, oldValues: newValue });
51
- });
52
- isLoading = true;
53
- },
54
- addFormat(name: string, format?: FormatItemModal) {
55
- if (!format) {
56
- return;
57
- }
58
- const { inputValue, outputValue } = format;
59
- formatSourceData[name] = {
60
- inputValue,
61
- outputValue,
62
- };
63
- }, //注册转化方法
64
- formatValues(value = {}, formatKey = "inputValue") {
65
- const valKeys = Object.keys(value).length;
66
- if (!valKeys) {
67
- return {};
68
- }
69
- let newValue = { ...value };
70
- const keys = Object.keys(formatSourceData);
71
- keys.forEach((key) => {
72
- const format = formatSourceData[key]?.[formatKey];
73
- if (!format) {
74
- return;
75
- }
76
- const resultValue = format(value);
77
- Reflect.deleteProperty(newValue, key);
78
- newValue = {
79
- ...newValue,
80
- ...resultValue,
81
- };
82
- });
83
- return newValue;
84
- }, //转化方法
85
- dispatch(action, ...args) {
86
- const { key, name } = action;
87
- const items = dispatchSourceData[key];
88
- if (!items) {
89
- return;
90
- }
91
- const { keysFn, defaultFn } = items;
92
- if (name) {
93
- return keysFn[name]?.(...args);
94
- }
95
- const fnArrays = Object.keys(keysFn).map((itemKey) => {
96
- return keysFn[itemKey];
97
- }); //不存在name就合并
98
- [...fnArrays, ...defaultFn].forEach((fn) => {
99
- fn(...args);
100
- });
101
- },
102
- addDispatchListener(action, fn) {
103
- const { key, name, dispatch = {} } = action;
104
- const { manual } = dispatch;
105
- const items = dispatchSourceData[key];
106
- if (!items) {
107
- dispatchSourceData[key] = norAddItemDispatch(name, manual, fn);
108
- return;
109
- }
110
- const { keysFn, defaultFn } = items;
111
- if (name) {
112
- keysFn[name] = fn;
113
- } else {
114
- defaultFn.push(fn);
115
- }
116
- if (manual === false && name) {
117
- initDispatch[name] = fn;
118
- }
119
- dispatchSourceData[key] = {
120
- keysFn,
121
- defaultFn,
122
- };
123
- },
124
- removeDispatchListener(action) {
125
- if (!action) {
126
- dispatchSourceData = {};
127
- return;
128
- }
129
- const { key, name } = action;
130
- const items = dispatchSourceData[key];
131
- if (!items) {
132
- return;
133
- }
134
- if (name) {
135
- const { keysFn } = items;
136
- Reflect.deleteProperty(keysFn, name);
137
- items.keysFn = keysFn;
138
- dispatchSourceData[key] = items;
139
- return;
140
- }
141
- Reflect.deleteProperty(dispatchSourceData, key);
142
- },
143
- outputValues(value) {
144
- const val = value || form.getFieldsValue();
145
- return this.formatValues(val, "outputValue");
146
- },
147
- ...form,
148
- setFieldsValue(values) {
149
- if (!isLoading) {
150
- cacheValues = values;
151
- return;
152
- }
153
- const newValue = this.formatValues(values);
154
- form.setFieldsValue(newValue);
155
- },
156
- validateFields(nameList) {
157
- return new Promise((resolve) => {
158
- form.validateFields(nameList).then((value) => {
159
- const result = this.formatValues(value, "outputValue");
160
- return resolve(result);
161
- });
162
- });
163
- },
164
- resetFieldsInitValue: () => {
165
- const oldValue = form.getFieldsValue();
166
- const keys = Object.keys(oldValue);
167
- const newVale = {};
168
- keys.forEach((key) => {
169
- newVale[key] = undefined;
170
- });
171
- form.setFieldsValue({
172
- ...newVale,
173
- ...initSaveValue,
174
- });
175
- },
176
- clear: () => {
177
- form.resetFields();
178
- isLoading = false;
179
- },
180
- };
181
- }, []);
182
- };
@@ -1,194 +0,0 @@
1
- import React, { useMemo } from "react";
2
- import type {
3
- HFormItemProps,
4
- HFormProps,
5
- HItemProps,
6
- DefaultComponentModal,
7
- } from "../modal";
8
- import { placeholderConfig } from "../config";
9
- import type { Rule } from "rc-field-form/lib/interface";
10
- import type { FormInstance } from "antd";
11
- import { useDefaultComponents } from "../hooks";
12
- import type { ConfigComponentModal } from "../modal";
13
- import type { DispatchSourceDataModal } from "../modal";
14
- import type { DispatchModal } from "../modal";
15
-
16
- const mathRequired = (
17
- configItem: HFormItemProps,
18
- form: FormInstance,
19
- defaultComponents: DefaultComponentModal
20
- ) => {
21
- const { required, placeholder, rules, type = "input" } = configItem;
22
- let resultRequired = false;
23
- const dom = defaultComponents[type];
24
- const resultRules = rules?.map((item) => {
25
- let eachItem = item;
26
- if (typeof item === "function") {
27
- eachItem = item(form);
28
- }
29
-
30
- const { required: itemRequired, message } = eachItem as any;
31
- if (itemRequired) {
32
- resultRequired = itemRequired;
33
- }
34
- if (itemRequired && !message) {
35
- let msg = placeholder;
36
- const itemDom = dom as ConfigComponentModal;
37
- if (itemDom?.requiredErrMsg) {
38
- msg = itemDom.requiredErrMsg(configItem);
39
- }
40
- return {
41
- ...eachItem,
42
- required: itemRequired,
43
- message: msg,
44
- };
45
- }
46
- return eachItem;
47
- });
48
- return {
49
- required: typeof required === "boolean" ? required : resultRequired,
50
- rules: resultRules as Rule[],
51
- };
52
- }; //是否必填
53
- const matchDefaultPlaceholder = (
54
- props: HFormItemProps,
55
- defaultComponents: DefaultComponentModal
56
- ) => {
57
- const { label, placeholder, type = "input" } = props;
58
- const dom = defaultComponents[type];
59
- if (placeholder) {
60
- return placeholder;
61
- }
62
- const itemDom = dom as ConfigComponentModal;
63
- if (itemDom?.placeholder) {
64
- return itemDom.placeholder(props);
65
- }
66
- if (placeholderConfig.inputType.indexOf(type) !== -1) {
67
- return `请输入${label}`;
68
- }
69
- return `请选择${label}`;
70
- }; //自动构建
71
-
72
- const defaultPlaceholderPropsMaker = (
73
- props: HFormItemProps,
74
- defaultComponents: DefaultComponentModal
75
- ) => {
76
- const placeholder = matchDefaultPlaceholder(props, defaultComponents);
77
- return {
78
- ...props,
79
- placeholder,
80
- };
81
- }; //组装参数
82
- const itemControl = (
83
- item: HItemProps,
84
- form: FormInstance,
85
- defaultComponents: DefaultComponentModal
86
- ): HFormItemProps => {
87
- const { render, ...defaultProps } = defaultPlaceholderPropsMaker(
88
- item,
89
- defaultComponents
90
- );
91
- const { rules, required } = mathRequired(
92
- defaultProps,
93
- form,
94
- defaultComponents
95
- );
96
- return {
97
- ...defaultProps,
98
- required,
99
- rules,
100
- render,
101
- };
102
- };
103
- const itemDispatchProvider = (
104
- name: string,
105
- config: Required<DispatchModal<string>>,
106
- dispatchSourceData: DispatchSourceDataModal
107
- ) => {
108
- const { dependencies, fnKey, reset } = config;
109
- const itemDispatch = dispatchSourceData[dependencies as string];
110
- if (!itemDispatch) {
111
- return {
112
- [dependencies]: {
113
- [name]: {
114
- fnKey,
115
- reset,
116
- },
117
- },
118
- };
119
- }
120
- const itemNameDispatch = {
121
- [name]: {
122
- fnKey,
123
- reset,
124
- },
125
- };
126
- return {
127
- [dependencies]: {
128
- ...itemDispatch,
129
- ...itemNameDispatch,
130
- },
131
- };
132
- };
133
- const dispatchProvider = (
134
- item: HItemProps,
135
- dispatchSourceData: DispatchSourceDataModal
136
- ) => {
137
- const { name = "", dispatch = {}, dependencies = "allDependencies" } = item;
138
- const {
139
- fnKey,
140
- dependencies: dispatchDependencies = dependencies as string | string[],
141
- manual = true,
142
- reset = true,
143
- } = dispatch;
144
- if (!fnKey) {
145
- return {};
146
- }
147
- if (Array.isArray(dispatchDependencies)) {
148
- let allDispatch: DispatchSourceDataModal = {
149
- ...dispatchSourceData,
150
- };
151
- dispatchDependencies.forEach((key) => {
152
- const itemDispatch = itemDispatchProvider(
153
- name,
154
- { dependencies: key, fnKey, manual, reset },
155
- dispatchSourceData
156
- );
157
- allDispatch = {
158
- ...allDispatch,
159
- ...itemDispatch,
160
- };
161
- });
162
- return allDispatch;
163
- }
164
- const itemDispatch = itemDispatchProvider(
165
- name,
166
- { dependencies: dispatchDependencies, fnKey, manual, reset },
167
- dispatchSourceData
168
- );
169
- return {
170
- ...dispatchSourceData,
171
- ...itemDispatch,
172
- };
173
- };
174
- type InitConfigModal = Required<Pick<HFormProps, "configData" | "form">>;
175
-
176
- export default ({ configData, form }: InitConfigModal) => {
177
- const defaultComponents = useDefaultComponents();
178
- return useMemo(() => {
179
- const newConfigData: HItemProps[] = [];
180
- let dispatchSourceData: DispatchSourceDataModal = {};
181
- configData.forEach((item) => {
182
- const itemDispatch = dispatchProvider(item, dispatchSourceData);
183
- dispatchSourceData = {
184
- ...dispatchSourceData,
185
- ...itemDispatch,
186
- };
187
- newConfigData.push(itemControl(item, form, defaultComponents));
188
- });
189
- return {
190
- newConfigData,
191
- dispatchSourceData,
192
- };
193
- }, [configData]);
194
- };
@@ -1,54 +0,0 @@
1
- @import "../styles/local.less";
2
- .@{ant-prefix}-hw-form-item-colon:after {
3
- position: relative;
4
- top: -0.5px;
5
- margin: 0 0 0 2px;
6
- content: ":";
7
- }
8
- .@{ant-prefix}-hw-form-item-required:before {
9
- display: inline-block;
10
- margin-right: 4px;
11
- color: #ff4d4f;
12
- font-size: 14px;
13
- font-family: SimSun, sans-serif;
14
- line-height: 1;
15
- content: "*";
16
- }
17
-
18
- .@{ant-prefix}-hw-form-base-item {
19
- display: flex;
20
- align-items: center;
21
- min-height: 32px;
22
- }
23
- .@{ant-prefix}-hw-form-base-item-top-left {
24
- .@{ant-prefix}-form-item-label > label {
25
- height: auto;
26
- }
27
- .@{ant-prefix}-hw-form-item-colon {
28
- text-align: left;
29
- }
30
- }
31
- .@{ant-prefix}-hw-form-base-item-top-right {
32
- .@{ant-prefix}-form-item-label > label {
33
- height: auto;
34
- }
35
- .@{ant-prefix}-hw-form-item-colon {
36
- text-align: right;
37
- }
38
- }
39
- .@{ant-prefix}-hw-form-base-item-top {
40
- .@{ant-prefix}-form-item-label > label {
41
- height: auto;
42
- }
43
- }
44
- .@{ant-prefix}-hw-form-base-item-right {
45
- .@{ant-prefix}-hw-form-item-colon {
46
- text-align: right;
47
- }
48
- }
49
-
50
- .@{ant-prefix}-hw-form-base-item-left {
51
- .@{ant-prefix}-hw-form-item-colon {
52
- text-align: left;
53
- }
54
- }
@@ -1,113 +0,0 @@
1
- import { Form, Row } from "antd";
2
- import type { HFormProps, HItemProps } from "./modal";
3
- import Item from "./FormItem";
4
- import { useCurrentForm, useInfoReq, useValuesChange } from "./hooks";
5
- import { FormContext } from "./Context";
6
- import PageHandler from "../PageHandler";
7
- import useInitConfigData from "./hooks/useInitConfigData";
8
- import { useEffect } from "react";
9
- import InitSet from "./InitSet";
10
- import {ItemPropsType} from "./modal";
11
-
12
- export default ({
13
- configData,
14
- labelWidth,
15
- form,
16
- request,
17
- onFinish,
18
- infoRequest,
19
- valueType = "float",
20
- initialValues,
21
- params = {},
22
- onValuesChange,
23
- itemSpan,
24
- hideLabel: formHideLabel = false,
25
- gutter,
26
- submitLoading,
27
- labelAlign: formLabelAlign,
28
- formItemStyle,
29
- itemProps:formItemProps={},
30
- ...props
31
- }: HFormProps) => {
32
- const hForm = useCurrentForm(form);
33
- const { newConfigData, dispatchSourceData } = useInitConfigData({
34
- configData,
35
- form: hForm,
36
- });
37
- const { subControl, infoControl } = useInfoReq({
38
- initialValues,
39
- request,
40
- onFinish,
41
- valueType,
42
- form: hForm,
43
- infoRequest,
44
- params,
45
- });
46
- const valuesChange = useValuesChange({
47
- onValuesChange,
48
- dispatch: dispatchSourceData,
49
- form: hForm,
50
- });
51
- const { run, loading } = subControl;
52
- const {
53
- run: infoRun,
54
- loading: infoLoading,
55
- error: infoErr,
56
- data: infoData,
57
- } = infoControl;
58
-
59
- useEffect(() => {
60
- return () => {
61
- hForm.removeDispatchListener();
62
- };
63
- }, []);
64
- return (
65
- <PageHandler
66
- loading={infoLoading}
67
- error={infoErr}
68
- data={infoData}
69
- reload={infoRun}
70
- >
71
- <FormContext.Provider
72
- value={{ loading: submitLoading || loading, form: hForm, valueType }}
73
- >
74
- <Form
75
- form={hForm}
76
- onFinish={run}
77
- onValuesChange={valuesChange}
78
- {...props}
79
- >
80
- <Row gutter={gutter}>
81
- {newConfigData.map((itemData: HItemProps, index) => {
82
- const {
83
- labelWidth: itemLabelWidth,
84
- hideLabel = formHideLabel,
85
- labelAlign = formLabelAlign,
86
- name,
87
- style=formItemStyle,
88
- itemProps={},
89
- } = itemData;
90
- const defaultItemProps={
91
- ...formItemProps,
92
- ...itemProps
93
- }
94
- return (
95
- <Item
96
- {...itemData}
97
- labelAlign={labelAlign}
98
- key={name||index}
99
- style={style}
100
- itemProps={(defaultItemProps as ItemPropsType)}
101
- hideLabel={hideLabel}
102
- itemSpan={itemSpan}
103
- labelWidth={itemLabelWidth || labelWidth}
104
- />
105
- );
106
- })}
107
- </Row>
108
- <InitSet />
109
- </Form>
110
- </FormContext.Provider>
111
- </PageHandler>
112
- );
113
- };