@neeloong/form 0.6.2 → 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 +8 -0
- package/index.d.mts +113 -62
- package/index.js +463 -172
- package/index.min.js +8 -8
- package/index.min.mjs +6 -6
- package/index.mjs +463 -172
- package/package.json +1 -1
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.
|
|
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
|
|
177
|
-
clearable?: boolean | ((store: Store
|
|
178
|
-
required?: boolean | ((store: Store
|
|
179
|
-
disabled?: boolean | ((store: Store
|
|
180
|
-
readonly?: boolean | ((store: Store
|
|
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
|
|
185
|
+
label?: string | ((store: Store) => string | null) | null | undefined;
|
|
185
186
|
/**
|
|
186
187
|
* 字段描述
|
|
187
188
|
*/
|
|
188
|
-
description?: string | ((store: Store
|
|
189
|
+
description?: string | ((store: Store) => string | null) | null | undefined;
|
|
189
190
|
/**
|
|
190
191
|
* 占位符
|
|
191
192
|
*/
|
|
192
|
-
placeholder?: string | ((store: Store
|
|
193
|
+
placeholder?: string | ((store: Store) => string | null) | null | undefined;
|
|
193
194
|
/**
|
|
194
195
|
* 日期、时间、数字的最小值
|
|
195
196
|
*/
|
|
196
|
-
min?: number | ((store: Store
|
|
197
|
+
min?: number | ((store: Store) => number | null) | null | undefined;
|
|
197
198
|
/**
|
|
198
199
|
* 日期、时间、数字的最大值
|
|
199
200
|
*/
|
|
200
|
-
max?: number | ((store: Store
|
|
201
|
+
max?: number | ((store: Store) => number | null) | null | undefined;
|
|
201
202
|
/**
|
|
202
203
|
* 日期、时间、数字的步长
|
|
203
204
|
*/
|
|
204
|
-
step?: number | ((store: Store
|
|
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,10 +217,24 @@ 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
|
+
|
|
230
|
+
declare const ref: unique symbol;
|
|
231
|
+
type Ref = {
|
|
232
|
+
[ref]: Store;
|
|
233
|
+
[k: string]: Ref | undefined;
|
|
234
|
+
};
|
|
218
235
|
|
|
219
|
-
/** @import {
|
|
236
|
+
/** @import { Ref } from './ref.mjs' */
|
|
237
|
+
/** @import { AsyncValidator, Schema, Validator } from '../types.mjs' */
|
|
220
238
|
/**
|
|
221
239
|
* @template [T=any]
|
|
222
240
|
*/
|
|
@@ -228,10 +246,17 @@ declare class Store<T = any> {
|
|
|
228
246
|
*/
|
|
229
247
|
static create(schema: Schema, options?: {
|
|
230
248
|
new?: boolean | undefined;
|
|
231
|
-
}):
|
|
249
|
+
}): Store<any>;
|
|
250
|
+
/**
|
|
251
|
+
* @param {string} type
|
|
252
|
+
* @param {{new(...p: ConstructorParameters<typeof Store>): Store}} Class
|
|
253
|
+
*/
|
|
254
|
+
static setStore(type: string, Class: {
|
|
255
|
+
new (...p: ConstructorParameters<typeof Store>): Store;
|
|
256
|
+
}): void;
|
|
232
257
|
/**
|
|
233
258
|
* @param {Schema.Field} schema
|
|
234
|
-
* @param {object} options
|
|
259
|
+
* @param {object} [options]
|
|
235
260
|
* @param {*} [options.parent]
|
|
236
261
|
* @param {*} [options.state]
|
|
237
262
|
* @param {number | string | null} [options.index]
|
|
@@ -250,15 +275,23 @@ declare class Store<T = any> {
|
|
|
250
275
|
* @param {number} [options.min] 日期、时间、数字的最小值
|
|
251
276
|
* @param {number} [options.max] 日期、时间、数字的最大值
|
|
252
277
|
* @param {number} [options.step] 日期、时间、数字的步长
|
|
278
|
+
* @param {number} [options.minLength]
|
|
279
|
+
* @param {number} [options.maxLength]
|
|
280
|
+
* @param {RegExp} [options.pattern]
|
|
253
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]
|
|
284
|
+
*
|
|
285
|
+
* @param {Ref?} [options.ref]
|
|
254
286
|
*
|
|
255
287
|
* @param {((value: any) => any)?} [options.setValue]
|
|
256
288
|
* @param {((value: any) => any)?} [options.setState]
|
|
257
289
|
* @param {((value: any, state: any) => [value: any, state: any])?} [options.convert]
|
|
258
|
-
*
|
|
259
|
-
* @param {((value: T?, index: any) => void)?} [options.
|
|
290
|
+
*
|
|
291
|
+
* @param {((value: T?, index: any, store: Store) => void)?} [options.onUpdate]
|
|
292
|
+
* @param {((value: T?, index: any, store: Store) => void)?} [options.onUpdateState]
|
|
260
293
|
*/
|
|
261
|
-
constructor(schema: Schema.Field, { null: isNull, state, 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 }?: {
|
|
262
295
|
parent?: any;
|
|
263
296
|
state?: any;
|
|
264
297
|
index?: string | number | null | undefined;
|
|
@@ -276,12 +309,24 @@ declare class Store<T = any> {
|
|
|
276
309
|
min?: number | undefined;
|
|
277
310
|
max?: number | undefined;
|
|
278
311
|
step?: number | undefined;
|
|
312
|
+
minLength?: number | undefined;
|
|
313
|
+
maxLength?: number | undefined;
|
|
314
|
+
pattern?: RegExp | undefined;
|
|
279
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;
|
|
324
|
+
ref?: Ref | null | undefined;
|
|
280
325
|
setValue?: ((value: any) => any) | null | undefined;
|
|
281
326
|
setState?: ((value: any) => any) | null | undefined;
|
|
282
327
|
convert?: ((value: any, state: any) => [value: any, state: any]) | null | undefined;
|
|
283
|
-
onUpdate?: ((value: T | null, index: any) => void) | null | undefined;
|
|
284
|
-
onUpdateState?: ((value: T | null, index: any) => void) | null | undefined;
|
|
328
|
+
onUpdate?: ((value: T | null, index: any, store: Store) => void) | null | undefined;
|
|
329
|
+
onUpdateState?: ((value: T | null, index: any, store: Store) => void) | null | undefined;
|
|
285
330
|
});
|
|
286
331
|
/**
|
|
287
332
|
*
|
|
@@ -300,6 +345,7 @@ declare class Store<T = any> {
|
|
|
300
345
|
listen<K extends keyof Schema.Events>(event: K, listener: (this: this, p: Schema.Events[K], store: this) => void | boolean | null): () => void;
|
|
301
346
|
get null(): boolean;
|
|
302
347
|
get kind(): string;
|
|
348
|
+
get ref(): Ref;
|
|
303
349
|
schema: Schema.Field;
|
|
304
350
|
get store(): this;
|
|
305
351
|
get parent(): Store<any> | null;
|
|
@@ -361,10 +407,24 @@ declare class Store<T = any> {
|
|
|
361
407
|
get selfStep(): number | null;
|
|
362
408
|
set step(v: number | null);
|
|
363
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;
|
|
364
422
|
set selfValues(v: (Schema.Value | Schema.Value.Group)[] | null);
|
|
365
423
|
get selfValues(): (Schema.Value | Schema.Value.Group)[] | null;
|
|
366
424
|
set values(v: (Schema.Value | Schema.Value.Group)[] | null);
|
|
367
425
|
get values(): (Schema.Value | Schema.Value.Group)[] | null;
|
|
426
|
+
get errors(): string[];
|
|
427
|
+
get error(): string;
|
|
368
428
|
/**
|
|
369
429
|
*
|
|
370
430
|
* @param {string | number} key
|
|
@@ -372,62 +432,53 @@ declare class Store<T = any> {
|
|
|
372
432
|
*/
|
|
373
433
|
child(key: string | number): Store | null;
|
|
374
434
|
get changed(): boolean;
|
|
375
|
-
get saved(): boolean;
|
|
376
435
|
set value(v: T | null);
|
|
377
436
|
get value(): T | null;
|
|
378
437
|
set state(v: any);
|
|
379
438
|
get state(): any;
|
|
380
|
-
|
|
381
|
-
destroy(): void;
|
|
382
|
-
/** @returns {IterableIterator<[key: string | number, value: Store]>} */
|
|
383
|
-
[Symbol.iterator](): IterableIterator<[key: string | number, value: Store]>;
|
|
384
|
-
#private;
|
|
385
|
-
}
|
|
386
|
-
declare class ObjectStore extends Store<any> {
|
|
439
|
+
reset(value?: T | null): void;
|
|
387
440
|
/**
|
|
388
|
-
*
|
|
389
|
-
* @
|
|
390
|
-
* @param {
|
|
391
|
-
* @
|
|
392
|
-
* @param {boolean} [options.new]
|
|
393
|
-
* @param {(value: any, index: any) => void} [options.onUpdate]
|
|
394
|
-
* @param {(value: any, index: any) => void} [options.onUpdateState]
|
|
441
|
+
*
|
|
442
|
+
* @overload
|
|
443
|
+
* @param {null} [path]
|
|
444
|
+
* @returns {Promise<string[] | null>}
|
|
395
445
|
*/
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
+
}[]>;
|
|
457
|
+
/** @returns {IterableIterator<[key: string | number, value: Store]>} */
|
|
458
|
+
[Symbol.iterator](): IterableIterator<[key: string | number, value: Store]>;
|
|
404
459
|
#private;
|
|
405
460
|
}
|
|
406
461
|
|
|
407
462
|
/**
|
|
408
|
-
* @overload
|
|
409
|
-
* @param {Store} store
|
|
410
|
-
* @param {(Layout.Node | string)[]} layouts
|
|
411
|
-
* @param {Element} parent
|
|
412
|
-
* @param {Record<string, Store | {get?(): any; set?(v: any): void; exec?(...p: any[]): any; calc?(...p: any[]): any }>} [global]
|
|
413
|
-
* @param {(path: string[]) => Component?} [components]
|
|
414
|
-
* @returns {() => void}
|
|
415
|
-
*/
|
|
416
|
-
declare function _default(store: Store, layouts: (Node | string)[], parent: Element, global?: Record<string, Store<any> | {
|
|
417
|
-
get?(): any;
|
|
418
|
-
set?(v: any): void;
|
|
419
|
-
exec?(...p: any[]): any;
|
|
420
|
-
calc?(...p: any[]): any;
|
|
421
|
-
}> | undefined, components?: ((path: string[]) => Component | null) | undefined): () => void;
|
|
422
|
-
/**
|
|
423
|
-
* @overload
|
|
424
463
|
* @param {Store} store
|
|
425
464
|
* @param {(Layout.Node | string)[]} layouts
|
|
426
465
|
* @param {Element} parent
|
|
427
|
-
* @param {
|
|
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]
|
|
428
470
|
* @returns {() => void}
|
|
429
471
|
*/
|
|
430
|
-
declare function _default(store: Store, layouts: (Node | string)[], parent: Element,
|
|
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;
|
|
431
482
|
|
|
432
483
|
/**
|
|
433
484
|
* 创建可赋值计算值
|
|
@@ -446,4 +497,4 @@ declare function watch<T>(getter: () => T, callback: (value: T) => void, immedia
|
|
|
446
497
|
*/
|
|
447
498
|
declare function effect(fn: () => void): () => void;
|
|
448
499
|
|
|
449
|
-
export { Component, index_d as Layout, 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 };
|