litmoss-form 5.0.1 → 5.1.0

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.

Potentially problematic release.


This version of litmoss-form might be problematic. Click here for more details.

package/README.md CHANGED
@@ -36,7 +36,7 @@ npm i litmoss-form
36
36
  | `classnames` | `^2.5.1` |
37
37
  | `cyndi` | `^1.0.0` |
38
38
  | `exception-boundary` | `^2.0.1` |
39
- | `litmoss-hooks` | `^1.1.0` |
39
+ | `litmoss-hooks` | `^3.0.0` |
40
40
  | `lodash` | `^4.17.21` |
41
41
 
42
42
  ## 快速开始
@@ -133,6 +133,7 @@ function Demo() {
133
133
  | `setValueByPath(path, value)` | 设置指定表单项的值 |
134
134
  | `setHelpTextByPath(path, text)` | 设置指定表单项的提示信息 |
135
135
  | `validate({ focusOnError? })` | 校验表单,返回失败项的 `{ path, helpInfo }` 数组 |
136
+ | `validateField(path)` | 通过属性路径验证表单项的方法,并返回验证结果 |
136
137
  | `focusFieldByPath(path)` | 聚焦指定表单项 |
137
138
 
138
139
  ### 常量
@@ -244,6 +244,12 @@ export interface FormRef {
244
244
  validate: (options?: {
245
245
  focusOnError?: boolean;
246
246
  }) => FormItemHelper[];
247
+ /**
248
+ * 通过属性路径验证表单项的方法
249
+ * @param path 表单项的值路径
250
+ * @returns 验证结果,包含帮助信息和路径
251
+ */
252
+ validateField: (path: string) => FormItemHelper;
247
253
  /**
248
254
  * 通过属性路径聚焦表单项对应控件的方法
249
255
  * @param path 表单项的值路径
@@ -33,6 +33,16 @@ export declare function setValues(args: FormArgs, formRegister: FormRegister): F
33
33
  * @param formRegister 当前表单的注册器对象
34
34
  */
35
35
  export declare function setValueByPath(path: string, value: unknown, formRegister: FormRegister): FormHelperInfo;
36
+ /**
37
+ * 通过属性路径验证表单项的方法
38
+ * @param path 表单项的唯一路径(valuePath)
39
+ * @param formRegister 当前表单的注册器对象
40
+ * @returns 验证结果,包含帮助信息和路径
41
+ */
42
+ export declare function validateField(path: string, formRegister: FormRegister): {
43
+ helpInfo: FormHelperInfo;
44
+ path: string;
45
+ } | undefined;
36
46
  /**
37
47
  * 聚焦指定表单项
38
48
  * @param path 表单项的唯一路径(valuePath)
package/dist/index.js CHANGED
@@ -140,12 +140,23 @@ function M(e, t, n) {
140
140
  } else x(S(e));
141
141
  }
142
142
  function N(e, t) {
143
+ let n = t[e];
144
+ if (n !== void 0) {
145
+ let { validate: t, get: r } = n, i = r?.();
146
+ return {
147
+ helpInfo: t?.(i),
148
+ path: e
149
+ };
150
+ }
151
+ x(S(e));
152
+ }
153
+ function P(e, t) {
143
154
  let n = t[e];
144
155
  n ? n.fieldRef?.current?.focus ? n.fieldRef.current.focus() : x(E(e)) : x(S(e));
145
156
  }
146
157
  //#endregion
147
158
  //#region src/components/form/form.tsx
148
- var P = t(({ children: e, prefixCls: t, validationMode: n = f.all, ...r }, a) => {
159
+ var F = t(({ children: e, prefixCls: t, validationMode: n = f.all, ...r }, a) => {
149
160
  let [c] = o({}), [l, u] = o(), [p] = o(() => v(c, u));
150
161
  return i(a, () => ({
151
162
  getValues: () => O(c),
@@ -159,12 +170,13 @@ var P = t(({ children: e, prefixCls: t, validationMode: n = f.all, ...r }, a) =>
159
170
  let { focusOnError: t } = e || {}, r = g(c, n);
160
171
  if (t !== !1 && r.length > 0) {
161
172
  let e = r[0];
162
- N(e.path, c);
173
+ P(e.path, c);
163
174
  }
164
175
  return r;
165
176
  },
177
+ validateField: (e) => N(e, c),
166
178
  focusFieldByPath: (e) => {
167
- N(e, c);
179
+ P(e, c);
168
180
  }
169
181
  }), [c, n]), /* @__PURE__ */ d(s, {
170
182
  errorMsg: l,
@@ -178,10 +190,10 @@ var P = t(({ children: e, prefixCls: t, validationMode: n = f.all, ...r }, a) =>
178
190
  })
179
191
  });
180
192
  });
181
- P.displayName = c.Form;
193
+ F.displayName = c.Form;
182
194
  //#endregion
183
195
  //#region src/components/form/useForm.ts
184
- function F() {
196
+ function I() {
185
197
  let e = a(), [t, n] = o();
186
198
  return r(() => (n(e.current), () => {
187
199
  e.current = void 0;
@@ -189,7 +201,7 @@ function F() {
189
201
  }
190
202
  //#endregion
191
203
  //#region src/components/form/useFormItemValue.ts
192
- function I(e, t, i, a, s) {
204
+ function L(e, t, i, a, s) {
193
205
  let c = n(_), [l, u] = o(t);
194
206
  return r(() => (c?.checkValuePath(e), () => {
195
207
  c?.uninstall(e);
@@ -213,14 +225,14 @@ function I(e, t, i, a, s) {
213
225
  }
214
226
  //#endregion
215
227
  //#region src/components/inject.ts
216
- var L = {};
217
- function R(e) {
228
+ var R = {};
229
+ function z(e) {
218
230
  let { commonValidationAssert: t, getDefaultHelperInfo: n, getInitialValue: r } = e;
219
- L.commonValidationAssert = t, L.getDefaultHelperInfo = n, L.getInitialValue = r;
231
+ R.commonValidationAssert = t, R.getDefaultHelperInfo = n, R.getInitialValue = r;
220
232
  }
221
233
  //#endregion
222
234
  //#region src/components/form/useHelperInfo.ts
223
- function z(e) {
235
+ function B(e) {
224
236
  let [t, n] = o();
225
237
  function r(t, r) {
226
238
  let i, a = !1, o = e.length;
@@ -232,13 +244,13 @@ function z(e) {
232
244
  x(D(r));
233
245
  break;
234
246
  }
235
- } else if (L.commonValidationAssert) a = L.commonValidationAssert(t, s) === !1;
247
+ } else if (R.commonValidationAssert) a = R.commonValidationAssert(t, s) === !1;
236
248
  else {
237
249
  x(T());
238
250
  break;
239
251
  }
240
252
  if (a) {
241
- i = o ?? (L.getDefaultHelperInfo ? L.getDefaultHelperInfo(s) : void 0);
253
+ i = o ?? (R.getDefaultHelperInfo ? R.getDefaultHelperInfo(s) : void 0);
242
254
  break;
243
255
  }
244
256
  }
@@ -252,8 +264,8 @@ function z(e) {
252
264
  }
253
265
  //#endregion
254
266
  //#region src/components/mounter/mounter.tsx
255
- var B = ({ onDidMount: e }) => (r(() => {
267
+ var V = ({ onDidMount: e }) => (r(() => {
256
268
  e?.();
257
269
  }, []), null);
258
270
  //#endregion
259
- export { p as BaseValidationType, P as Form, B as Mounter, f as ValidationMode, R as initLittenForm, F as useForm, I as useFormItemValue, z as useHelperInfo };
271
+ export { p as BaseValidationType, F as Form, V as Mounter, f as ValidationMode, z as initLittenForm, I as useForm, L as useFormItemValue, B as useHelperInfo };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "litmoss-form",
3
3
  "private": false,
4
- "version": "5.0.1",
4
+ "version": "5.1.0",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -98,4 +98,4 @@
98
98
  "type": "git",
99
99
  "url": "git+https://github.com/liuxian496/litmoss-form.git"
100
100
  }
101
- }
101
+ }