@rainbow-oh/yee-c 0.8.20 → 0.9.1
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/dist/cjs/Form/Field.js +6 -6
- package/dist/cjs/Form/demo/async-validate.js +2 -2
- package/dist/cjs/Form/demo/field-status.d.ts +3 -0
- package/dist/cjs/Form/demo/field-status.js +116 -0
- package/dist/cjs/Form/demo/validate.js +2 -2
- package/dist/cjs/Form/form-store.d.ts +6 -1
- package/dist/cjs/Form/form-store.js +93 -8
- package/dist/cjs/Form/index.d.ts +1 -1
- package/dist/cjs/Form/interface.d.ts +26 -3
- package/dist/cjs/Form/style/index.less +26 -0
- package/dist/cjs/Form/utils/path.js +1 -1
- package/dist/cjs/TreeSelect/tree-select.js +14 -4
- package/dist/cjs/style/themes.css +1 -1
- package/dist/cjs/style/variables.css +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Form/Field.js +6 -6
- package/dist/esm/Form/demo/async-validate.js +2 -2
- package/dist/esm/Form/demo/field-status.d.ts +3 -0
- package/dist/esm/Form/demo/field-status.js +104 -0
- package/dist/esm/Form/demo/validate.js +2 -2
- package/dist/esm/Form/form-store.d.ts +6 -1
- package/dist/esm/Form/form-store.js +118 -13
- package/dist/esm/Form/hooks/useForm.js +0 -175
- package/dist/esm/Form/index.d.ts +1 -1
- package/dist/esm/Form/interface.d.ts +26 -3
- package/dist/esm/Form/style/index.less +26 -0
- package/dist/esm/Form/utils/path.js +2 -1
- package/dist/esm/TreeSelect/tree-select.js +20 -6
- package/dist/esm/style/themes.css +1 -1
- package/dist/esm/style/variables.css +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/yee-c.min.css +1 -1
- package/dist/umd/yee-c.min.js +1 -1
- package/package.json +1 -1
- package/src/Form/Field.tsx +7 -8
- package/src/Form/demo/async-validate.tsx +3 -2
- package/src/Form/demo/field-status.tsx +108 -0
- package/src/Form/demo/validate.tsx +3 -2
- package/src/Form/form-store.test.ts +156 -0
- package/src/Form/form-store.ts +117 -8
- package/src/Form/hooks/useForm.ts +0 -175
- package/src/Form/index.en-US.md +93 -88
- package/src/Form/index.ts +3 -0
- package/src/Form/index.zh-CN.md +56 -51
- package/src/Form/interface.ts +28 -3
- package/src/Form/style/index.less +26 -0
- package/src/Form/utils/path.ts +2 -1
- package/src/TreeSelect/tree-select.tsx +21 -4
- package/src/version.ts +1 -1
package/dist/cjs/Form/Field.js
CHANGED
|
@@ -98,7 +98,7 @@ var Field = (props) => {
|
|
|
98
98
|
} = props;
|
|
99
99
|
const {
|
|
100
100
|
getCallbacks,
|
|
101
|
-
|
|
101
|
+
getFieldStatus,
|
|
102
102
|
getFieldValue,
|
|
103
103
|
getFieldsValue,
|
|
104
104
|
setFieldsValue,
|
|
@@ -129,7 +129,7 @@ var Field = (props) => {
|
|
|
129
129
|
const isRequired = () => {
|
|
130
130
|
return Array.isArray(rules) && rules.find((rule) => rule.required) || required;
|
|
131
131
|
};
|
|
132
|
-
const
|
|
132
|
+
const fieldStatus = getFieldStatus == null ? void 0 : getFieldStatus(normalizedName);
|
|
133
133
|
const tooltipConfig = (0, import_react2.useMemo)(() => {
|
|
134
134
|
if (tooltip === void 0 || tooltip === null || tooltip === false)
|
|
135
135
|
return null;
|
|
@@ -183,7 +183,7 @@ var Field = (props) => {
|
|
|
183
183
|
`${prefixCls}-item`,
|
|
184
184
|
`${prefixCls}-item-${layout}`,
|
|
185
185
|
{
|
|
186
|
-
[`${prefixCls}-item-${
|
|
186
|
+
[`${prefixCls}-item-${fieldStatus == null ? void 0 : fieldStatus.status}`]: fieldStatus == null ? void 0 : fieldStatus.status
|
|
187
187
|
},
|
|
188
188
|
className
|
|
189
189
|
),
|
|
@@ -216,7 +216,7 @@ var Field = (props) => {
|
|
|
216
216
|
getControlled(children)
|
|
217
217
|
) : /* @__PURE__ */ import_react2.default.createElement("span", null, children)
|
|
218
218
|
)),
|
|
219
|
-
/* @__PURE__ */ import_react2.default.createElement(import_react.AnimatePresence, null,
|
|
219
|
+
/* @__PURE__ */ import_react2.default.createElement(import_react.AnimatePresence, null, (fieldStatus == null ? void 0 : fieldStatus.message) && /* @__PURE__ */ import_react2.default.createElement(
|
|
220
220
|
import_react.motion.small,
|
|
221
221
|
{
|
|
222
222
|
initial: { opacity: 0, y: -10 },
|
|
@@ -224,10 +224,10 @@ var Field = (props) => {
|
|
|
224
224
|
exit: { opacity: 0, y: -10 },
|
|
225
225
|
transition: { duration: 0.16 },
|
|
226
226
|
className: (0, import_clsx.default)(`${prefixCls}-item-additional`, {
|
|
227
|
-
[`${prefixCls}-item-additional-${
|
|
227
|
+
[`${prefixCls}-item-additional-${fieldStatus.status}`]: fieldStatus.status
|
|
228
228
|
})
|
|
229
229
|
},
|
|
230
|
-
|
|
230
|
+
fieldStatus.message
|
|
231
231
|
))
|
|
232
232
|
);
|
|
233
233
|
};
|
|
@@ -65,8 +65,8 @@ var async_validate_default = () => {
|
|
|
65
65
|
const onFinish = (values) => {
|
|
66
66
|
console.log("Received values:", values);
|
|
67
67
|
};
|
|
68
|
-
const onFinishFailed = (
|
|
69
|
-
console.log("Failed:",
|
|
68
|
+
const onFinishFailed = (errors) => {
|
|
69
|
+
console.log("Failed:", errors);
|
|
70
70
|
};
|
|
71
71
|
return /* @__PURE__ */ import_react.default.createElement(import_yee_c.Form, { form, onFinish, onFinishFailed }, /* @__PURE__ */ import_react.default.createElement(import_yee_c.Grid, null, /* @__PURE__ */ import_react.default.createElement(
|
|
72
72
|
import_yee_c.Form.Field,
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/Form/demo/field-status.tsx
|
|
30
|
+
var field_status_exports = {};
|
|
31
|
+
__export(field_status_exports, {
|
|
32
|
+
default: () => field_status_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(field_status_exports);
|
|
35
|
+
var import_yee_c = require("../..");
|
|
36
|
+
var import_react = __toESM(require("react"));
|
|
37
|
+
var field_status_default = () => {
|
|
38
|
+
const [form] = import_yee_c.Form.useForm();
|
|
39
|
+
const [currentStatus, setCurrentStatus] = (0, import_react.useState)(
|
|
40
|
+
null
|
|
41
|
+
);
|
|
42
|
+
const [submitResult, setSubmitResult] = (0, import_react.useState)("");
|
|
43
|
+
const applyStatus = (status) => {
|
|
44
|
+
form.setFieldStatus("username", status);
|
|
45
|
+
setCurrentStatus(form.getFieldStatus("username"));
|
|
46
|
+
setSubmitResult("");
|
|
47
|
+
};
|
|
48
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
49
|
+
import_yee_c.Form,
|
|
50
|
+
{
|
|
51
|
+
form,
|
|
52
|
+
initialValues: { username: "demo-user" },
|
|
53
|
+
onFinish: () => setSubmitResult("Submit succeeded"),
|
|
54
|
+
onFinishFailed: () => setSubmitResult("Submit blocked by the blocking error")
|
|
55
|
+
},
|
|
56
|
+
/* @__PURE__ */ import_react.default.createElement(
|
|
57
|
+
import_yee_c.Form.Field,
|
|
58
|
+
{
|
|
59
|
+
name: "username",
|
|
60
|
+
label: "Username",
|
|
61
|
+
rules: [{ required: true, message: "Please input your username!" }]
|
|
62
|
+
},
|
|
63
|
+
/* @__PURE__ */ import_react.default.createElement(import_yee_c.Input, { placeholder: "Please input your username" })
|
|
64
|
+
),
|
|
65
|
+
/* @__PURE__ */ import_react.default.createElement(import_yee_c.Space, { style: { marginTop: 28, flexWrap: "wrap" } }, /* @__PURE__ */ import_react.default.createElement(
|
|
66
|
+
import_yee_c.Button,
|
|
67
|
+
{
|
|
68
|
+
onClick: () => applyStatus({
|
|
69
|
+
status: "error",
|
|
70
|
+
message: "This username is unavailable"
|
|
71
|
+
})
|
|
72
|
+
},
|
|
73
|
+
"Error"
|
|
74
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
75
|
+
import_yee_c.Button,
|
|
76
|
+
{
|
|
77
|
+
onClick: () => applyStatus({
|
|
78
|
+
status: "error",
|
|
79
|
+
message: "This error prevents submission",
|
|
80
|
+
blocking: true
|
|
81
|
+
})
|
|
82
|
+
},
|
|
83
|
+
"Blocking error"
|
|
84
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
85
|
+
import_yee_c.Button,
|
|
86
|
+
{
|
|
87
|
+
onClick: () => applyStatus({
|
|
88
|
+
status: "warning",
|
|
89
|
+
message: "This username is commonly used"
|
|
90
|
+
})
|
|
91
|
+
},
|
|
92
|
+
"Warning"
|
|
93
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
94
|
+
import_yee_c.Button,
|
|
95
|
+
{
|
|
96
|
+
onClick: () => applyStatus({
|
|
97
|
+
status: "success",
|
|
98
|
+
message: "This username is available"
|
|
99
|
+
})
|
|
100
|
+
},
|
|
101
|
+
"Success"
|
|
102
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
103
|
+
import_yee_c.Button,
|
|
104
|
+
{
|
|
105
|
+
onClick: () => applyStatus({
|
|
106
|
+
status: "info",
|
|
107
|
+
message: "The username can be changed later"
|
|
108
|
+
})
|
|
109
|
+
},
|
|
110
|
+
"Info"
|
|
111
|
+
), /* @__PURE__ */ import_react.default.createElement(import_yee_c.Button, { onClick: () => applyStatus(null) }, "Clear"), /* @__PURE__ */ import_react.default.createElement(import_yee_c.Button, { type: "primary", htmlType: "submit" }, "Submit")),
|
|
112
|
+
/* @__PURE__ */ import_react.default.createElement("pre", { style: { marginTop: 16 } }, "Current status: ", JSON.stringify(currentStatus, null, 2)),
|
|
113
|
+
submitResult ? /* @__PURE__ */ import_react.default.createElement("div", null, submitResult) : null,
|
|
114
|
+
/* @__PURE__ */ import_react.default.createElement("div", { style: { marginTop: 8, color: "#999" } }, "Tip: set Success, then clear the input — the rule error takes display precedence over the manually set status.")
|
|
115
|
+
);
|
|
116
|
+
};
|
|
@@ -39,8 +39,8 @@ var validate_default = () => {
|
|
|
39
39
|
const onFinish = (values) => {
|
|
40
40
|
console.log("Received values:", values);
|
|
41
41
|
};
|
|
42
|
-
const onFinishFailed = (
|
|
43
|
-
console.log("Failed:",
|
|
42
|
+
const onFinishFailed = (errors) => {
|
|
43
|
+
console.log("Failed:", errors);
|
|
44
44
|
};
|
|
45
45
|
return /* @__PURE__ */ import_react.default.createElement(import_yee_c.Form, { form, onFinish, onFinishFailed }, /* @__PURE__ */ import_react.default.createElement(import_yee_c.Grid, null, /* @__PURE__ */ import_react.default.createElement(
|
|
46
46
|
import_yee_c.Form.Field,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { Callbacks, FieldEntity, FormInstance, FormListField, FormListOperation, GroupEntity, Name, NamePath, Store, TRIGGER, ValidateMessage } from './interface';
|
|
1
|
+
import type { Callbacks, FieldEntity, FieldStatusData, FormInstance, FormListField, FormListOperation, GroupEntity, Name, NamePath, Store, TRIGGER, ValidateMessage } from './interface';
|
|
2
2
|
export declare class FormStore {
|
|
3
3
|
private store;
|
|
4
4
|
private callbacks;
|
|
5
5
|
private fieldEntities;
|
|
6
6
|
private fieldMap;
|
|
7
7
|
private validateMessages;
|
|
8
|
+
private fieldStatuses;
|
|
8
9
|
private initialized;
|
|
9
10
|
private initialValues;
|
|
10
11
|
private listKeyManagers;
|
|
@@ -23,6 +24,10 @@ export declare class FormStore {
|
|
|
23
24
|
private getValueByPath;
|
|
24
25
|
getFieldValue: (name: Name) => any;
|
|
25
26
|
getFieldValidate: (name: Name) => ValidateMessage | null;
|
|
27
|
+
getFieldStatus: (name: NamePath) => FieldStatusData | null;
|
|
28
|
+
setFieldStatus: (name: NamePath, status: FieldStatusData | null) => void;
|
|
29
|
+
private deleteRelatedEntries;
|
|
30
|
+
private clearFieldStatuses;
|
|
26
31
|
setFieldsValue: (newStore: Store, trigger?: TRIGGER) => void;
|
|
27
32
|
resetFields: (name?: Name[]) => void;
|
|
28
33
|
clearFields: (name?: Name[]) => void;
|
|
@@ -88,6 +88,7 @@ var FormStore = class {
|
|
|
88
88
|
this.fieldEntities = [];
|
|
89
89
|
this.fieldMap = /* @__PURE__ */ new Map();
|
|
90
90
|
this.validateMessages = /* @__PURE__ */ new Map();
|
|
91
|
+
this.fieldStatuses = /* @__PURE__ */ new Map();
|
|
91
92
|
this.initialized = false;
|
|
92
93
|
this.initialValues = {};
|
|
93
94
|
// List key manager
|
|
@@ -143,10 +144,64 @@ var FormStore = class {
|
|
|
143
144
|
}
|
|
144
145
|
return null;
|
|
145
146
|
};
|
|
147
|
+
this.getFieldStatus = (name) => {
|
|
148
|
+
var _a;
|
|
149
|
+
const normalizedName = (0, import_path.stringifyPath)((0, import_path.getNamePath)(name));
|
|
150
|
+
const manualStatus = this.fieldStatuses.get(normalizedName);
|
|
151
|
+
const validateMessage = (_a = this.validateMessages.get(normalizedName)) == null ? void 0 : _a[0];
|
|
152
|
+
if ((validateMessage == null ? void 0 : validateMessage.status) === "error") {
|
|
153
|
+
return {
|
|
154
|
+
status: "error",
|
|
155
|
+
message: validateMessage.message
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
if (manualStatus) {
|
|
159
|
+
return __spreadValues({}, manualStatus);
|
|
160
|
+
}
|
|
161
|
+
if (validateMessage) {
|
|
162
|
+
return {
|
|
163
|
+
status: validateMessage.status,
|
|
164
|
+
message: validateMessage.message
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
return null;
|
|
168
|
+
};
|
|
169
|
+
this.setFieldStatus = (name, status) => {
|
|
170
|
+
var _a;
|
|
171
|
+
const normalizedName = (0, import_path.stringifyPath)((0, import_path.getNamePath)(name));
|
|
172
|
+
if (!normalizedName)
|
|
173
|
+
return;
|
|
174
|
+
if (status) {
|
|
175
|
+
this.fieldStatuses.set(normalizedName, __spreadValues({}, status));
|
|
176
|
+
} else {
|
|
177
|
+
this.fieldStatuses.delete(normalizedName);
|
|
178
|
+
}
|
|
179
|
+
(_a = this.fieldMap.get(normalizedName)) == null ? void 0 : _a.onStoreChange();
|
|
180
|
+
};
|
|
181
|
+
// Delete entries whose key equals or nests under one of `names`
|
|
182
|
+
// (no names = delete all). Keeps rule messages and manual statuses in
|
|
183
|
+
// sync with the fields that reset/clear actually touched.
|
|
184
|
+
this.deleteRelatedEntries = (entries, names) => {
|
|
185
|
+
if (!names) {
|
|
186
|
+
entries.clear();
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const normalizedNames = names.map(
|
|
190
|
+
(name) => (0, import_path.stringifyPath)((0, import_path.getNamePath)(name))
|
|
191
|
+
);
|
|
192
|
+
Array.from(entries.keys()).forEach((fieldName) => {
|
|
193
|
+
if (normalizedNames.some((name) => isRelatedNamePath(fieldName, name))) {
|
|
194
|
+
entries.delete(fieldName);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
this.clearFieldStatuses = (names) => {
|
|
199
|
+
this.deleteRelatedEntries(this.fieldStatuses, names);
|
|
200
|
+
};
|
|
146
201
|
this.setFieldsValue = (newStore, trigger = "onChange") => {
|
|
147
202
|
var _a, _b, _c, _d;
|
|
148
203
|
if (trigger === "reset" || trigger === "clear") {
|
|
149
|
-
this.store = newStore;
|
|
204
|
+
this.store = trigger === "reset" ? newStore : __spreadValues(__spreadValues({}, this.store), newStore);
|
|
150
205
|
if (trigger === "reset") {
|
|
151
206
|
(_b = (_a = this.callbacks) == null ? void 0 : _a.onReset) == null ? void 0 : _b.call(_a);
|
|
152
207
|
} else {
|
|
@@ -208,17 +263,32 @@ var FormStore = class {
|
|
|
208
263
|
});
|
|
209
264
|
}
|
|
210
265
|
(_b = (_a = this.callbacks) == null ? void 0 : _a.onReset) == null ? void 0 : _b.call(_a);
|
|
211
|
-
this.validateMessages
|
|
266
|
+
this.deleteRelatedEntries(this.validateMessages, name);
|
|
267
|
+
this.clearFieldStatuses(name);
|
|
212
268
|
this.groupEntities.forEach((entity) => entity.reset());
|
|
213
269
|
this.refreshField();
|
|
214
270
|
};
|
|
215
271
|
this.clearFields = (name) => {
|
|
272
|
+
var _a, _b;
|
|
216
273
|
const names = name || Object.keys(this.store);
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
274
|
+
let clearStore = __spreadValues({}, this.store);
|
|
275
|
+
names.forEach((n) => {
|
|
276
|
+
const parsedPath = (0, import_path.parsePath)(n);
|
|
277
|
+
if (parsedPath.length > 1) {
|
|
278
|
+
clearStore = (0, import_path.setValueByPath)(clearStore, parsedPath, void 0);
|
|
279
|
+
} else {
|
|
280
|
+
clearStore[n] = void 0;
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
this.deleteRelatedEntries(this.validateMessages, name);
|
|
284
|
+
this.clearFieldStatuses(name);
|
|
285
|
+
this.store = clearStore;
|
|
286
|
+
(_b = (_a = this.callbacks) == null ? void 0 : _a.onClear) == null ? void 0 : _b.call(_a);
|
|
287
|
+
this.getRelatedFieldNames(names).forEach((fieldName) => {
|
|
288
|
+
var _a2;
|
|
289
|
+
(_a2 = this.fieldMap.get(fieldName)) == null ? void 0 : _a2.onStoreChange();
|
|
290
|
+
});
|
|
291
|
+
this.notifyWatchers(names);
|
|
222
292
|
};
|
|
223
293
|
this.validateField = (name, trigger) => __async(this, null, function* () {
|
|
224
294
|
var _a;
|
|
@@ -483,7 +553,20 @@ var FormStore = class {
|
|
|
483
553
|
const { onFinish, onFinishFailed } = this.callbacks;
|
|
484
554
|
const fieldErrors = yield this.validateFields();
|
|
485
555
|
const groupErrors = yield this.validateGroups(true);
|
|
486
|
-
const
|
|
556
|
+
const statusErrors = Array.from(this.fieldStatuses.entries()).filter(
|
|
557
|
+
([, status]) => status.status === "error" && status.blocking === true
|
|
558
|
+
).map(
|
|
559
|
+
([name, status]) => {
|
|
560
|
+
var _a;
|
|
561
|
+
return {
|
|
562
|
+
name,
|
|
563
|
+
message: (_a = status.message) != null ? _a : "",
|
|
564
|
+
value: this.getFieldValue(name),
|
|
565
|
+
status: "error"
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
);
|
|
569
|
+
const allErrors = [...fieldErrors, ...groupErrors, ...statusErrors];
|
|
487
570
|
if (allErrors.length === 0) {
|
|
488
571
|
onFinish == null ? void 0 : onFinish(this.getFieldsValue());
|
|
489
572
|
} else {
|
|
@@ -520,6 +603,8 @@ var FormStore = class {
|
|
|
520
603
|
getForm() {
|
|
521
604
|
return {
|
|
522
605
|
getFieldValidate: this.getFieldValidate,
|
|
606
|
+
getFieldStatus: this.getFieldStatus,
|
|
607
|
+
setFieldStatus: this.setFieldStatus,
|
|
523
608
|
getFieldsValue: this.getFieldsValue,
|
|
524
609
|
getFieldValue: this.getFieldValue,
|
|
525
610
|
setFieldsValue: this.setFieldsValue,
|
package/dist/cjs/Form/index.d.ts
CHANGED
|
@@ -16,5 +16,5 @@ type FormInterface = typeof InternalForm & {
|
|
|
16
16
|
List: typeof List;
|
|
17
17
|
};
|
|
18
18
|
declare const Form: FormInterface;
|
|
19
|
-
export type { FieldGroupProps, FormInstance, FormListProps, FormProps, } from './interface';
|
|
19
|
+
export type { FieldGroupProps, FieldStatus, FieldStatusData, FormInstance, FormListProps, FormProps, ValidateMessage, } from './interface';
|
|
20
20
|
export default Form;
|
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
import type { TooltipProps } from '../Tooltip';
|
|
3
3
|
import type { DataAttributeProps } from '../utils/types';
|
|
4
4
|
export type StoreValue = any;
|
|
5
|
+
/**
|
|
6
|
+
* Form values keyed by field name. Nested-path fields (e.g.
|
|
7
|
+
* name="user.name") hold their values in nested objects:
|
|
8
|
+
* `{ user: { name: 'tom' } }`
|
|
9
|
+
*/
|
|
5
10
|
export type Store = Record<string, StoreValue>;
|
|
6
11
|
export type Name = string;
|
|
7
12
|
export type NamePath = string | string[] | number | (string | number)[];
|
|
@@ -37,7 +42,9 @@ export interface FormProps<Values = any> extends DataAttributeProps {
|
|
|
37
42
|
*/
|
|
38
43
|
disabled?: boolean;
|
|
39
44
|
/**
|
|
40
|
-
* Initial values
|
|
45
|
+
* Initial values, keyed by field name. Nested-path fields (e.g.
|
|
46
|
+
* name="user.name") take their values from nested objects:
|
|
47
|
+
* `{ user: { name: 'tom' } }`
|
|
41
48
|
*/
|
|
42
49
|
initialValues?: Store;
|
|
43
50
|
/**
|
|
@@ -81,7 +88,7 @@ export interface Callbacks<Values = any> {
|
|
|
81
88
|
/**
|
|
82
89
|
* Triggered on failed form submit
|
|
83
90
|
* */
|
|
84
|
-
onFinishFailed?: (
|
|
91
|
+
onFinishFailed?: (errors: ValidateMessage[]) => void;
|
|
85
92
|
/**
|
|
86
93
|
* Triggered on form reset
|
|
87
94
|
* */
|
|
@@ -96,6 +103,15 @@ export interface FormInstance<Values = any> {
|
|
|
96
103
|
* Get field validation info
|
|
97
104
|
*/
|
|
98
105
|
getFieldValidate: (name: Name) => ValidateMessage | null;
|
|
106
|
+
/**
|
|
107
|
+
* Get the displayed field status. Rule validation errors take display
|
|
108
|
+
* precedence; otherwise a manually set status overrides validation.
|
|
109
|
+
*/
|
|
110
|
+
getFieldStatus: (name: NamePath) => FieldStatusData | null;
|
|
111
|
+
/**
|
|
112
|
+
* Set or clear a field's displayed status. Pass null to clear it.
|
|
113
|
+
*/
|
|
114
|
+
setFieldStatus: (name: NamePath, status: FieldStatusData | null) => void;
|
|
99
115
|
/**
|
|
100
116
|
* Get field value
|
|
101
117
|
*/
|
|
@@ -225,11 +241,18 @@ export type Rule = {
|
|
|
225
241
|
*/
|
|
226
242
|
validateTrigger?: 'onBlur' | 'onChange' | 'onSubmit' | 'reset' | Array<'onBlur' | 'onChange' | 'onSubmit'>;
|
|
227
243
|
};
|
|
244
|
+
export type FieldStatus = 'error' | 'success' | 'warning' | 'info';
|
|
245
|
+
export type FieldStatusData = {
|
|
246
|
+
status: FieldStatus;
|
|
247
|
+
message?: string;
|
|
248
|
+
/** Whether an error status should prevent form submission. */
|
|
249
|
+
blocking?: boolean;
|
|
250
|
+
};
|
|
228
251
|
export type ValidateMessage = {
|
|
229
252
|
name: NamePath | NamePath[] | undefined;
|
|
230
253
|
message: string;
|
|
231
254
|
value: unknown;
|
|
232
|
-
status:
|
|
255
|
+
status: FieldStatus;
|
|
233
256
|
};
|
|
234
257
|
export type FieldConfigurableTooltip = Omit<TooltipProps, 'children'> & {
|
|
235
258
|
/**
|
|
@@ -79,6 +79,18 @@
|
|
|
79
79
|
&-error {
|
|
80
80
|
color: var(--yee-error-color);
|
|
81
81
|
}
|
|
82
|
+
|
|
83
|
+
&-warning {
|
|
84
|
+
color: var(--yee-warning-color);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
&-success {
|
|
88
|
+
color: var(--yee-success-color);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
&-info {
|
|
92
|
+
color: var(--yee-info-color);
|
|
93
|
+
}
|
|
82
94
|
}
|
|
83
95
|
|
|
84
96
|
// 表单校验态:在此重定义控件读取的 border / box-shadow 变量,
|
|
@@ -97,5 +109,19 @@
|
|
|
97
109
|
--yee-input-focus-bs-color: var(--yee-warning-color-border);
|
|
98
110
|
--yee-checkbox-border-color: var(--yee-warning-color);
|
|
99
111
|
}
|
|
112
|
+
|
|
113
|
+
&&-success {
|
|
114
|
+
--yee-input-border-color: var(--yee-success-color);
|
|
115
|
+
--yee-input-hover-border-color: var(--yee-success-color-hover);
|
|
116
|
+
--yee-input-focus-bs-color: var(--yee-success-color-border);
|
|
117
|
+
--yee-checkbox-border-color: var(--yee-success-color);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
&&-info {
|
|
121
|
+
--yee-input-border-color: var(--yee-info-color);
|
|
122
|
+
--yee-input-hover-border-color: var(--yee-info-color-hover);
|
|
123
|
+
--yee-input-focus-bs-color: var(--yee-info-color-border);
|
|
124
|
+
--yee-checkbox-border-color: var(--yee-info-color);
|
|
125
|
+
}
|
|
100
126
|
}
|
|
101
127
|
}
|
|
@@ -71,7 +71,7 @@ function setValueByPath(store, path, value) {
|
|
|
71
71
|
let current = newStore;
|
|
72
72
|
for (let i = 0; i < path.length - 1; i++) {
|
|
73
73
|
const key = String(path[i]);
|
|
74
|
-
if (
|
|
74
|
+
if (current[key] == null) {
|
|
75
75
|
current[key] = typeof path[i + 1] === "number" ? [] : {};
|
|
76
76
|
}
|
|
77
77
|
current = current[key];
|
|
@@ -138,6 +138,16 @@ var TreeSelect = (baseprops) => {
|
|
|
138
138
|
),
|
|
139
139
|
[dataSource, mergedFieldNames]
|
|
140
140
|
);
|
|
141
|
+
const keyItemMap = (0, import_react.useMemo)(() => {
|
|
142
|
+
const map = /* @__PURE__ */ new Map();
|
|
143
|
+
itemMap.forEach((item) => {
|
|
144
|
+
const k = String(item.key);
|
|
145
|
+
if (!map.has(k)) {
|
|
146
|
+
map.set(k, item);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
return map;
|
|
150
|
+
}, [itemMap]);
|
|
141
151
|
const filteredDataSource = (0, import_react.useMemo)(() => {
|
|
142
152
|
const sourceArray = Array.isArray(dataSource) ? dataSource : [dataSource];
|
|
143
153
|
if (!searchValue) {
|
|
@@ -170,7 +180,7 @@ var TreeSelect = (baseprops) => {
|
|
|
170
180
|
}, [searchValue, dataSource, mergedFieldNames, onFilter]);
|
|
171
181
|
const selectedOptions = (0, import_react.useMemo)(() => {
|
|
172
182
|
return mergedValue.map((key) => {
|
|
173
|
-
const item =
|
|
183
|
+
const item = keyItemMap.get(String(key));
|
|
174
184
|
if (!item)
|
|
175
185
|
return null;
|
|
176
186
|
const label = typeof optionLabelProp === "function" ? optionLabelProp(item.original) : String(item[optionLabelProp] || item.label);
|
|
@@ -179,7 +189,7 @@ var TreeSelect = (baseprops) => {
|
|
|
179
189
|
label
|
|
180
190
|
}, item.original);
|
|
181
191
|
}).filter(Boolean);
|
|
182
|
-
}, [mergedValue,
|
|
192
|
+
}, [mergedValue, keyItemMap, optionLabelProp]);
|
|
183
193
|
const getNodes = (keys) => {
|
|
184
194
|
var _a2;
|
|
185
195
|
if (keys === "" || keys === null) {
|
|
@@ -191,10 +201,10 @@ var TreeSelect = (baseprops) => {
|
|
|
191
201
|
}
|
|
192
202
|
return keys.map((key) => {
|
|
193
203
|
var _a3;
|
|
194
|
-
return (_a3 =
|
|
204
|
+
return (_a3 = keyItemMap.get(String(key))) == null ? void 0 : _a3.original;
|
|
195
205
|
}).filter((node) => node !== void 0);
|
|
196
206
|
}
|
|
197
|
-
return (_a2 =
|
|
207
|
+
return (_a2 = keyItemMap.get(String(keys))) == null ? void 0 : _a2.original;
|
|
198
208
|
};
|
|
199
209
|
const handleSelect = (selectedKeys) => {
|
|
200
210
|
let keys;
|
package/dist/cjs/version.d.ts
CHANGED
package/dist/cjs/version.js
CHANGED
package/dist/esm/Form/Field.js
CHANGED
|
@@ -55,7 +55,7 @@ var Field = function Field(props) {
|
|
|
55
55
|
formatter = props.formatter;
|
|
56
56
|
var _useContext = useContext(FieldContext),
|
|
57
57
|
getCallbacks = _useContext.getCallbacks,
|
|
58
|
-
|
|
58
|
+
getFieldStatus = _useContext.getFieldStatus,
|
|
59
59
|
getFieldValue = _useContext.getFieldValue,
|
|
60
60
|
getFieldsValue = _useContext.getFieldsValue,
|
|
61
61
|
setFieldsValue = _useContext.setFieldsValue,
|
|
@@ -98,7 +98,7 @@ var Field = function Field(props) {
|
|
|
98
98
|
return rule.required;
|
|
99
99
|
}) || required;
|
|
100
100
|
};
|
|
101
|
-
var
|
|
101
|
+
var fieldStatus = getFieldStatus === null || getFieldStatus === void 0 ? void 0 : getFieldStatus(normalizedName);
|
|
102
102
|
|
|
103
103
|
// Normalize tooltip into { icon, ...tooltipProps }, or null when not provided.
|
|
104
104
|
// Everything except `icon` is forwarded to <Tooltip>, so any Tooltip prop
|
|
@@ -163,7 +163,7 @@ var Field = function Field(props) {
|
|
|
163
163
|
});
|
|
164
164
|
};
|
|
165
165
|
return /*#__PURE__*/React.createElement("div", {
|
|
166
|
-
className: clsx("".concat(prefixCls, "-item"), "".concat(prefixCls, "-item-").concat(layout), _defineProperty({}, "".concat(prefixCls, "-item-").concat(
|
|
166
|
+
className: clsx("".concat(prefixCls, "-item"), "".concat(prefixCls, "-item-").concat(layout), _defineProperty({}, "".concat(prefixCls, "-item-").concat(fieldStatus === null || fieldStatus === void 0 ? void 0 : fieldStatus.status), fieldStatus === null || fieldStatus === void 0 ? void 0 : fieldStatus.status), className),
|
|
167
167
|
style: style
|
|
168
168
|
}, /*#__PURE__*/React.createElement("div", {
|
|
169
169
|
className: clsx("".concat(prefixCls, "-item-row"))
|
|
@@ -178,7 +178,7 @@ var Field = function Field(props) {
|
|
|
178
178
|
}, tooltipConfig.icon)) : null) : null, /*#__PURE__*/React.createElement("div", {
|
|
179
179
|
className: clsx("".concat(prefixCls, "-item-control"), classNames === null || classNames === void 0 ? void 0 : classNames.control),
|
|
180
180
|
style: styles === null || styles === void 0 ? void 0 : styles.control
|
|
181
|
-
}, /*#__PURE__*/React.isValidElement(children) ? ( /*#__PURE__*/React.cloneElement(children, getControlled(children))) : /*#__PURE__*/React.createElement("span", null, children))), /*#__PURE__*/React.createElement(AnimatePresence, null,
|
|
181
|
+
}, /*#__PURE__*/React.isValidElement(children) ? ( /*#__PURE__*/React.cloneElement(children, getControlled(children))) : /*#__PURE__*/React.createElement("span", null, children))), /*#__PURE__*/React.createElement(AnimatePresence, null, (fieldStatus === null || fieldStatus === void 0 ? void 0 : fieldStatus.message) && /*#__PURE__*/React.createElement(motion.small, {
|
|
182
182
|
initial: {
|
|
183
183
|
opacity: 0,
|
|
184
184
|
y: -10
|
|
@@ -194,7 +194,7 @@ var Field = function Field(props) {
|
|
|
194
194
|
transition: {
|
|
195
195
|
duration: 0.16
|
|
196
196
|
},
|
|
197
|
-
className: clsx("".concat(prefixCls, "-item-additional"), _defineProperty({}, "".concat(prefixCls, "-item-additional-").concat(
|
|
198
|
-
},
|
|
197
|
+
className: clsx("".concat(prefixCls, "-item-additional"), _defineProperty({}, "".concat(prefixCls, "-item-additional-").concat(fieldStatus.status), fieldStatus.status))
|
|
198
|
+
}, fieldStatus.message)));
|
|
199
199
|
};
|
|
200
200
|
export default Field;
|
|
@@ -27,8 +27,8 @@ export default (function () {
|
|
|
27
27
|
var onFinish = function onFinish(values) {
|
|
28
28
|
console.log('Received values:', values);
|
|
29
29
|
};
|
|
30
|
-
var onFinishFailed = function onFinishFailed(
|
|
31
|
-
console.log('Failed:',
|
|
30
|
+
var onFinishFailed = function onFinishFailed(errors) {
|
|
31
|
+
console.log('Failed:', errors);
|
|
32
32
|
};
|
|
33
33
|
return /*#__PURE__*/React.createElement(Form, {
|
|
34
34
|
form: form,
|