@neeloong/form 0.7.0 → 0.8.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.
package/README.md CHANGED
@@ -196,17 +196,25 @@ render(store, layouts, app);
196
196
  - `$min` 只读属性
197
197
  - `$max` 只读属性
198
198
  - `$step` 只读属性
199
+ - `$minLength` 只读属性
200
+ - `$maxLength` 只读属性
201
+ - `$pattern` 只读属性
199
202
  - `$values` 只读属性
200
203
  - `$type` 只读属性
201
204
  - `$meta` 只读属性
202
205
  - `$component` 只读属性
203
206
  - `$kind` 只读属性
207
+ - `$error` 只读属性
208
+ - `$errors` 只读属性
204
209
  1. 数组字段扩展隐式函数(只在事件中可用)
205
210
  - `$insert(index, value)`
206
211
  - `$add(value)`
207
212
  - `$remove(index)`
208
213
  - `$move(from, to)`
209
214
  - `$exchange(a, b)`
215
+ - `$reset()`
216
+ - `$validate()`
217
+ - `$validate(true)`
210
218
  1. 数组成员字段扩展隐式属性
211
219
  - `$upMovable` 只读属性
212
220
  - `$downMovable` 只读属性
package/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @neeloong/form v0.7.0
2
+ * @neeloong/form v0.8.0
3
3
  * (c) 2024-2025 Fierflame
4
4
  * @license Apache-2.0
5
5
  */
@@ -108,6 +108,7 @@ declare namespace Component {
108
108
  events: [string, ($event: any) => void, AddEventListenerOptions][];
109
109
  tagAttrs: Record<string, any>;
110
110
  watchAttr: (name: any, fn: (value: any, old: any, name: string) => void) => () => void;
111
+ relate: (el: Element) => () => void;
111
112
  destroyed: boolean;
112
113
  init: boolean;
113
114
  listen: <K extends keyof Component.Context.Events>(event: K, listener: (...p: Component.Context.Events[K]) => void) => () => void;
@@ -173,35 +174,38 @@ declare namespace Schema {
173
174
  component?: any;
174
175
  immutable?: boolean | undefined;
175
176
  creatable?: boolean | undefined;
176
- hidden?: boolean | ((store: Store, root: Store) => boolean) | null | undefined;
177
- clearable?: boolean | ((store: Store, root: Store) => boolean) | null | undefined;
178
- required?: boolean | ((store: Store, root: Store) => boolean) | null | undefined;
179
- disabled?: boolean | ((store: Store, root: Store) => boolean) | null | undefined;
180
- readonly?: boolean | ((store: Store, root: Store) => boolean) | null | undefined;
177
+ hidden?: boolean | ((store: Store) => boolean) | null | undefined;
178
+ clearable?: boolean | ((store: Store) => boolean) | null | undefined;
179
+ required?: boolean | ((store: Store) => boolean) | null | undefined;
180
+ disabled?: boolean | ((store: Store) => boolean) | null | undefined;
181
+ readonly?: boolean | ((store: Store) => boolean) | null | undefined;
181
182
  /**
182
183
  * 字段标签
183
184
  */
184
- label?: string | ((store: Store, root: Store) => string) | null | undefined;
185
+ label?: string | ((store: Store) => string | null) | null | undefined;
185
186
  /**
186
187
  * 字段描述
187
188
  */
188
- description?: string | ((store: Store, root: Store) => string) | null | undefined;
189
+ description?: string | ((store: Store) => string | null) | null | undefined;
189
190
  /**
190
191
  * 占位符
191
192
  */
192
- placeholder?: string | ((store: Store, root: Store) => string) | null | undefined;
193
+ placeholder?: string | ((store: Store) => string | null) | null | undefined;
193
194
  /**
194
195
  * 日期、时间、数字的最小值
195
196
  */
196
- min?: number | ((store: Store, root: Store) => number) | null | undefined;
197
+ min?: number | ((store: Store) => number | null) | null | undefined;
197
198
  /**
198
199
  * 日期、时间、数字的最大值
199
200
  */
200
- max?: number | ((store: Store, root: Store) => number) | null | undefined;
201
+ max?: number | ((store: Store) => number | null) | null | undefined;
201
202
  /**
202
203
  * 日期、时间、数字的步长
203
204
  */
204
- step?: number | ((store: Store, root: Store) => number) | null | undefined;
205
+ step?: number | ((store: Store) => number | null) | null | undefined;
206
+ minLength?: number | ((store: Store) => number | null) | null | undefined;
207
+ maxLength?: number | ((store: Store) => number | null) | null | undefined;
208
+ pattern?: RegExp | ((store: Store) => RegExp | null) | null | undefined;
205
209
  /**
206
210
  * 可选值
207
211
  */
@@ -213,8 +217,15 @@ declare namespace Schema {
213
217
  focus?: ((this: Store, value: Event, store: Store) => void | boolean | null) | null | undefined;
214
218
  blur?: ((this: Store, value: Event, store: Store) => void | boolean | null) | null | undefined;
215
219
  } | undefined;
220
+ validator?: Validator | Validator[] | null | undefined;
221
+ validators?: {
222
+ change?: AsyncValidator | AsyncValidator[] | null | undefined;
223
+ blur?: AsyncValidator | AsyncValidator[] | null | undefined;
224
+ } | undefined;
216
225
  };
217
226
  }
227
+ type Validator = (store: Store) => string | string[] | void | null;
228
+ type AsyncValidator = (store: Store, signal: AbortSignal) => PromiseLike<string | string[] | void | null> | string | string[] | void | null;
218
229
 
219
230
  declare const ref: unique symbol;
220
231
  type Ref = {
@@ -223,7 +234,7 @@ type Ref = {
223
234
  };
224
235
 
225
236
  /** @import { Ref } from './ref.mjs' */
226
- /** @import { Schema } from '../types.mjs' */
237
+ /** @import { AsyncValidator, Schema, Validator } from '../types.mjs' */
227
238
  /**
228
239
  * @template [T=any]
229
240
  */
@@ -264,7 +275,12 @@ declare class Store<T = any> {
264
275
  * @param {number} [options.min] 日期、时间、数字的最小值
265
276
  * @param {number} [options.max] 日期、时间、数字的最大值
266
277
  * @param {number} [options.step] 日期、时间、数字的步长
278
+ * @param {number} [options.minLength]
279
+ * @param {number} [options.maxLength]
280
+ * @param {RegExp} [options.pattern]
267
281
  * @param {(Schema.Value.Group | Schema.Value | string | number)[]} [options.values] 可选值
282
+ * @param {Validator | Validator[] | null} [options.validator]
283
+ * @param {{[k in keyof Schema.Events]?: AsyncValidator | AsyncValidator[] | null}} [options.validators]
268
284
  *
269
285
  * @param {Ref?} [options.ref]
270
286
  *
@@ -275,7 +291,7 @@ declare class Store<T = any> {
275
291
  * @param {((value: T?, index: any, store: Store) => void)?} [options.onUpdate]
276
292
  * @param {((value: T?, index: any, store: Store) => void)?} [options.onUpdateState]
277
293
  */
278
- constructor(schema: Schema.Field, { null: isNull, state, ref, setValue, setState, convert, onUpdate, onUpdateState, index, length, new: isNew, parent: parentNode, hidden, clearable, required, disabled, readonly, label, description, placeholder, min, max, step, values }?: {
294
+ constructor(schema: Schema.Field, { null: isNull, state, ref, setValue, setState, convert, onUpdate, onUpdateState, validator, validators, index, length, new: isNew, parent: parentNode, hidden, clearable, required, disabled, readonly, label, description, placeholder, min, max, step, minLength, maxLength, pattern, values }?: {
279
295
  parent?: any;
280
296
  state?: any;
281
297
  index?: string | number | null | undefined;
@@ -293,7 +309,18 @@ declare class Store<T = any> {
293
309
  min?: number | undefined;
294
310
  max?: number | undefined;
295
311
  step?: number | undefined;
312
+ minLength?: number | undefined;
313
+ maxLength?: number | undefined;
314
+ pattern?: RegExp | undefined;
296
315
  values?: (string | number | Schema.Value | Schema.Value.Group)[] | undefined;
316
+ validator?: Validator | Validator[] | null | undefined;
317
+ validators?: {
318
+ input?: AsyncValidator | AsyncValidator[] | null | undefined;
319
+ change?: AsyncValidator | AsyncValidator[] | null | undefined;
320
+ click?: AsyncValidator | AsyncValidator[] | null | undefined;
321
+ focus?: AsyncValidator | AsyncValidator[] | null | undefined;
322
+ blur?: AsyncValidator | AsyncValidator[] | null | undefined;
323
+ } | undefined;
297
324
  ref?: Ref | null | undefined;
298
325
  setValue?: ((value: any) => any) | null | undefined;
299
326
  setState?: ((value: any) => any) | null | undefined;
@@ -380,10 +407,24 @@ declare class Store<T = any> {
380
407
  get selfStep(): number | null;
381
408
  set step(v: number | null);
382
409
  get step(): number | null;
410
+ set selfMinLength(v: number | null);
411
+ get selfMinLength(): number | null;
412
+ set minLength(v: number | null);
413
+ get minLength(): number | null;
414
+ set selfMaxLength(v: number | null);
415
+ get selfMaxLength(): number | null;
416
+ set maxLength(v: number | null);
417
+ get maxLength(): number | null;
418
+ set selfPattern(v: RegExp | null);
419
+ get selfPattern(): RegExp | null;
420
+ set pattern(v: RegExp | null);
421
+ get pattern(): RegExp | null;
383
422
  set selfValues(v: (Schema.Value | Schema.Value.Group)[] | null);
384
423
  get selfValues(): (Schema.Value | Schema.Value.Group)[] | null;
385
424
  set values(v: (Schema.Value | Schema.Value.Group)[] | null);
386
425
  get values(): (Schema.Value | Schema.Value.Group)[] | null;
426
+ get errors(): string[];
427
+ get error(): string;
387
428
  /**
388
429
  *
389
430
  * @param {string | number} key
@@ -396,35 +437,48 @@ declare class Store<T = any> {
396
437
  set state(v: any);
397
438
  get state(): any;
398
439
  reset(value?: T | null): void;
440
+ /**
441
+ *
442
+ * @overload
443
+ * @param {null} [path]
444
+ * @returns {Promise<string[] | null>}
445
+ */
446
+ validate(path?: null | undefined): Promise<string[] | null>;
447
+ /**
448
+ * @overload
449
+ * @param {(string | number)[]} path
450
+ * @returns {Promise<{ path: (string | number)[]; store: Store; errors: string[]}[]>}
451
+ */
452
+ validate(path: (string | number)[]): Promise<{
453
+ path: (string | number)[];
454
+ store: Store;
455
+ errors: string[];
456
+ }[]>;
399
457
  /** @returns {IterableIterator<[key: string | number, value: Store]>} */
400
458
  [Symbol.iterator](): IterableIterator<[key: string | number, value: Store]>;
401
459
  #private;
402
460
  }
403
461
 
404
462
  /**
405
- * @overload
406
- * @param {Store} store
407
- * @param {(Layout.Node | string)[]} layouts
408
- * @param {Element} parent
409
- * @param {Record<string, Store | {get?(): any; set?(v: any): void; exec?(...p: any[]): any; calc?(...p: any[]): any }>} [global]
410
- * @param {(path: string[]) => Component?} [components]
411
- * @returns {() => void}
412
- */
413
- declare function _default(store: Store, layouts: (Node | string)[], parent: Element, global?: Record<string, Store<any> | {
414
- get?(): any;
415
- set?(v: any): void;
416
- exec?(...p: any[]): any;
417
- calc?(...p: any[]): any;
418
- }> | undefined, components?: ((path: string[]) => Component | null) | undefined): () => void;
419
- /**
420
- * @overload
421
463
  * @param {Store} store
422
464
  * @param {(Layout.Node | string)[]} layouts
423
465
  * @param {Element} parent
424
- * @param {Component.Getter?} [components]
466
+ * @param {object} [options]
467
+ * @param {Record<string, Store | {get?(): any; set?(v: any): void; exec?(...p: any[]): any; calc?(...p: any[]): any }>} [options.global]
468
+ * @param {(path: string[]) => Component?} [options.component]
469
+ * @param {(store: Store, el: Element) => () => void} [options.relate]
425
470
  * @returns {() => void}
426
471
  */
427
- declare function _default(store: Store, layouts: (Node | string)[], parent: Element, components?: Component.Getter | null | undefined): () => void;
472
+ declare function _default(store: Store, layouts: (Node | string)[], parent: Element, { component, global, relate }?: {
473
+ global?: Record<string, Store<any> | {
474
+ get?(): any;
475
+ set?(v: any): void;
476
+ exec?(...p: any[]): any;
477
+ calc?(...p: any[]): any;
478
+ }> | undefined;
479
+ component?: ((path: string[]) => Component | null) | undefined;
480
+ relate?: ((store: Store, el: Element) => () => void) | undefined;
481
+ }): () => void;
428
482
 
429
483
  /**
430
484
  * 创建可赋值计算值
@@ -443,4 +497,4 @@ declare function watch<T>(getter: () => T, callback: (value: T) => void, immedia
443
497
  */
444
498
  declare function effect(fn: () => void): () => void;
445
499
 
446
- export { Component, index_d as Layout, type Ref, Schema, Store, type VerifyError, effect, _default as render, watch };
500
+ export { type AsyncValidator, Component, index_d as Layout, type Ref, Schema, Store, type Validator, type VerifyError, effect, _default as render, watch };