@neeloong/form 0.7.0 → 0.8.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/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.1
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 | Relatedness) => () => 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,21 @@ 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;
229
+ type Relatedness = {
230
+ focus?: (() => void) | undefined;
231
+ scrollIntoView?: (() => void) | undefined;
232
+ input?: Element | undefined;
233
+ root?: Element | undefined;
234
+ };
218
235
 
219
236
  declare const ref: unique symbol;
220
237
  type Ref = {
@@ -223,7 +240,7 @@ type Ref = {
223
240
  };
224
241
 
225
242
  /** @import { Ref } from './ref.mjs' */
226
- /** @import { Schema } from '../types.mjs' */
243
+ /** @import { AsyncValidator, Schema, Validator } from '../types.mjs' */
227
244
  /**
228
245
  * @template [T=any]
229
246
  */
@@ -264,7 +281,12 @@ declare class Store<T = any> {
264
281
  * @param {number} [options.min] 日期、时间、数字的最小值
265
282
  * @param {number} [options.max] 日期、时间、数字的最大值
266
283
  * @param {number} [options.step] 日期、时间、数字的步长
284
+ * @param {number} [options.minLength]
285
+ * @param {number} [options.maxLength]
286
+ * @param {RegExp} [options.pattern]
267
287
  * @param {(Schema.Value.Group | Schema.Value | string | number)[]} [options.values] 可选值
288
+ * @param {Validator | Validator[] | null} [options.validator]
289
+ * @param {{[k in keyof Schema.Events]?: AsyncValidator | AsyncValidator[] | null}} [options.validators]
268
290
  *
269
291
  * @param {Ref?} [options.ref]
270
292
  *
@@ -275,7 +297,7 @@ declare class Store<T = any> {
275
297
  * @param {((value: T?, index: any, store: Store) => void)?} [options.onUpdate]
276
298
  * @param {((value: T?, index: any, store: Store) => void)?} [options.onUpdateState]
277
299
  */
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 }?: {
300
+ 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
301
  parent?: any;
280
302
  state?: any;
281
303
  index?: string | number | null | undefined;
@@ -293,7 +315,18 @@ declare class Store<T = any> {
293
315
  min?: number | undefined;
294
316
  max?: number | undefined;
295
317
  step?: number | undefined;
318
+ minLength?: number | undefined;
319
+ maxLength?: number | undefined;
320
+ pattern?: RegExp | undefined;
296
321
  values?: (string | number | Schema.Value | Schema.Value.Group)[] | undefined;
322
+ validator?: Validator | Validator[] | null | undefined;
323
+ validators?: {
324
+ input?: AsyncValidator | AsyncValidator[] | null | undefined;
325
+ change?: AsyncValidator | AsyncValidator[] | null | undefined;
326
+ click?: AsyncValidator | AsyncValidator[] | null | undefined;
327
+ focus?: AsyncValidator | AsyncValidator[] | null | undefined;
328
+ blur?: AsyncValidator | AsyncValidator[] | null | undefined;
329
+ } | undefined;
297
330
  ref?: Ref | null | undefined;
298
331
  setValue?: ((value: any) => any) | null | undefined;
299
332
  setState?: ((value: any) => any) | null | undefined;
@@ -380,10 +413,24 @@ declare class Store<T = any> {
380
413
  get selfStep(): number | null;
381
414
  set step(v: number | null);
382
415
  get step(): number | null;
416
+ set selfMinLength(v: number | null);
417
+ get selfMinLength(): number | null;
418
+ set minLength(v: number | null);
419
+ get minLength(): number | null;
420
+ set selfMaxLength(v: number | null);
421
+ get selfMaxLength(): number | null;
422
+ set maxLength(v: number | null);
423
+ get maxLength(): number | null;
424
+ set selfPattern(v: RegExp | null);
425
+ get selfPattern(): RegExp | null;
426
+ set pattern(v: RegExp | null);
427
+ get pattern(): RegExp | null;
383
428
  set selfValues(v: (Schema.Value | Schema.Value.Group)[] | null);
384
429
  get selfValues(): (Schema.Value | Schema.Value.Group)[] | null;
385
430
  set values(v: (Schema.Value | Schema.Value.Group)[] | null);
386
431
  get values(): (Schema.Value | Schema.Value.Group)[] | null;
432
+ get errors(): string[];
433
+ get error(): string;
387
434
  /**
388
435
  *
389
436
  * @param {string | number} key
@@ -396,35 +443,48 @@ declare class Store<T = any> {
396
443
  set state(v: any);
397
444
  get state(): any;
398
445
  reset(value?: T | null): void;
446
+ /**
447
+ *
448
+ * @overload
449
+ * @param {null} [path]
450
+ * @returns {Promise<string[] | null>}
451
+ */
452
+ validate(path?: null | undefined): Promise<string[] | null>;
453
+ /**
454
+ * @overload
455
+ * @param {(string | number)[]} path
456
+ * @returns {Promise<{ path: (string | number)[]; store: Store; errors: string[]}[]>}
457
+ */
458
+ validate(path: (string | number)[]): Promise<{
459
+ path: (string | number)[];
460
+ store: Store;
461
+ errors: string[];
462
+ }[]>;
399
463
  /** @returns {IterableIterator<[key: string | number, value: Store]>} */
400
464
  [Symbol.iterator](): IterableIterator<[key: string | number, value: Store]>;
401
465
  #private;
402
466
  }
403
467
 
404
468
  /**
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
469
  * @param {Store} store
422
470
  * @param {(Layout.Node | string)[]} layouts
423
471
  * @param {Element} parent
424
- * @param {Component.Getter?} [components]
472
+ * @param {object} [options]
473
+ * @param {Record<string, Store | {get?(): any; set?(v: any): void; exec?(...p: any[]): any; calc?(...p: any[]): any }>} [options.global]
474
+ * @param {(path: string[]) => Component?} [options.component]
475
+ * @param {(store: Store, el: Element | Relatedness) => () => void} [options.relate]
425
476
  * @returns {() => void}
426
477
  */
427
- declare function _default(store: Store, layouts: (Node | string)[], parent: Element, components?: Component.Getter | null | undefined): () => void;
478
+ declare function _default(store: Store, layouts: (Node | string)[], parent: Element, { component, global, relate }?: {
479
+ global?: Record<string, Store<any> | {
480
+ get?(): any;
481
+ set?(v: any): void;
482
+ exec?(...p: any[]): any;
483
+ calc?(...p: any[]): any;
484
+ }> | undefined;
485
+ component?: ((path: string[]) => Component | null) | undefined;
486
+ relate?: ((store: Store, el: Element | Relatedness) => () => void) | undefined;
487
+ }): () => void;
428
488
 
429
489
  /**
430
490
  * 创建可赋值计算值
@@ -443,4 +503,4 @@ declare function watch<T>(getter: () => T, callback: (value: T) => void, immedia
443
503
  */
444
504
  declare function effect(fn: () => void): () => void;
445
505
 
446
- export { Component, index_d as Layout, type Ref, Schema, Store, type VerifyError, effect, _default as render, watch };
506
+ export { type AsyncValidator, Component, index_d as Layout, type Ref, type Relatedness, Schema, Store, type Validator, type VerifyError, effect, _default as render, watch };