@neeloong/form 0.28.0 → 0.30.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/index.d.mts +116 -136
- package/index.full.js +298 -260
- package/index.full.min.js +2 -2
- package/index.full.min.mjs +2 -2
- package/index.min.mjs +2 -2
- package/index.mjs +297 -260
- package/package.json +1 -1
package/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @neeloong/form v0.
|
|
2
|
+
* @neeloong/form v0.30.0
|
|
3
3
|
* (c) 2024-2026 Fierflame
|
|
4
4
|
* @license Apache-2.0
|
|
5
5
|
*/
|
|
@@ -135,20 +135,37 @@ declare namespace StoreLayout {
|
|
|
135
135
|
type Renderer<T_1 = unknown> = (store: Store<any, any, any>, renderer?: T_1 | string, options?: StoreLayout.Options | null) => HTMLElement | null;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
type MaybePromise<T> = PromiseLike<T> | T;
|
|
138
139
|
type Schema<M = any, S extends {
|
|
139
140
|
[x: string]: Schema.State;
|
|
140
141
|
} = {
|
|
141
142
|
[x: string]: Schema.State;
|
|
142
143
|
}> = Record<string, Schema.Field<M, S>>;
|
|
143
144
|
declare namespace Schema {
|
|
145
|
+
type ValidatorResult = string | string[] | void | null;
|
|
144
146
|
/**
|
|
145
147
|
* 同步验证器
|
|
146
148
|
*/
|
|
147
|
-
type
|
|
149
|
+
type SyncValidator = (store: Store) => Schema.ValidatorResult;
|
|
148
150
|
/**
|
|
149
151
|
* 异步验证器
|
|
150
152
|
*/
|
|
151
|
-
type AsyncValidator = (store: Store, signal: AbortSignal) =>
|
|
153
|
+
type AsyncValidator = (store: Store, signal: AbortSignal) => MaybePromise<Schema.ValidatorResult>;
|
|
154
|
+
/**
|
|
155
|
+
* 事件验证器
|
|
156
|
+
*/
|
|
157
|
+
type EventValidator = {
|
|
158
|
+
event: string;
|
|
159
|
+
validator: Schema.AsyncValidator;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* 即刻验证器
|
|
163
|
+
*/
|
|
164
|
+
type InstantValidator = {
|
|
165
|
+
event?: null | undefined;
|
|
166
|
+
validator: Schema.SyncValidator;
|
|
167
|
+
};
|
|
168
|
+
type Validator = Schema.InstantValidator | Schema.EventValidator | Schema.SyncValidator;
|
|
152
169
|
/**
|
|
153
170
|
* 字段定义
|
|
154
171
|
*/
|
|
@@ -392,13 +409,6 @@ declare namespace Schema {
|
|
|
392
409
|
* 同步验证器
|
|
393
410
|
*/
|
|
394
411
|
validator?: Schema.Validator | Schema.Validator[] | null | undefined;
|
|
395
|
-
/**
|
|
396
|
-
* 异步验证器
|
|
397
|
-
*/
|
|
398
|
-
validators?: {
|
|
399
|
-
change?: Schema.AsyncValidator | Schema.AsyncValidator[] | null | undefined;
|
|
400
|
-
blur?: Schema.AsyncValidator | Schema.AsyncValidator[] | null | undefined;
|
|
401
|
-
} | undefined;
|
|
402
412
|
layout?: StoreLayout.Field<any> | undefined;
|
|
403
413
|
};
|
|
404
414
|
type State = string | boolean | number | Object | null;
|
|
@@ -410,31 +420,6 @@ type Ref = {
|
|
|
410
420
|
[k: string]: Ref | undefined;
|
|
411
421
|
};
|
|
412
422
|
|
|
413
|
-
/** @import { Schema } from '../Schema.types.mjs' */
|
|
414
|
-
/**
|
|
415
|
-
* @template [T=any]
|
|
416
|
-
* @template [M=any]
|
|
417
|
-
* @template {Object.<string, Schema.State>} [S=Object.<string, Schema.State>]
|
|
418
|
-
* @extends {Store<T, M, S>}
|
|
419
|
-
*/
|
|
420
|
-
declare class BindObjectStore<T = any, M = any, S extends {
|
|
421
|
-
[x: string]: Schema.State;
|
|
422
|
-
} = {
|
|
423
|
-
[x: string]: Schema.State;
|
|
424
|
-
}> extends Store<T, M, S> {
|
|
425
|
-
/**
|
|
426
|
-
* @param {Schema<any, Object.<string, Schema.State>>} schema 数据结构模式
|
|
427
|
-
* @param {Store<T, M, S>} store
|
|
428
|
-
*/
|
|
429
|
-
constructor(schema: Schema<any, {
|
|
430
|
-
[x: string]: Schema.State;
|
|
431
|
-
}>, store: Store<T, M, S>);
|
|
432
|
-
[Symbol.iterator](): Generator<[string, Store<any, any, {
|
|
433
|
-
[x: string]: Schema.State;
|
|
434
|
-
}>], void, unknown>;
|
|
435
|
-
#private;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
423
|
/** @import { Ref } from './ref.mjs' */
|
|
439
424
|
/** @import { Schema } from '../Schema.types.mjs' */
|
|
440
425
|
/** @import { StoreLayout } from '../StoreLayout.types.mjs' */
|
|
@@ -476,95 +461,9 @@ declare class Store<T = any, M = any, S extends {
|
|
|
476
461
|
}): void;
|
|
477
462
|
/**
|
|
478
463
|
* @param {Schema.Field<M, S> | Store<T,M,S>} schema 字段的 Schema 定义
|
|
479
|
-
* @param {
|
|
480
|
-
* @param {Store?} [options.parent]
|
|
481
|
-
* @param {Partial<S>?} [options.states]
|
|
482
|
-
* @param {((store: Store, value?: any) => any) | object | number | string | boolean | null | undefined} [options.default]
|
|
483
|
-
* @param {number | string | null} [options.index]
|
|
484
|
-
* @param {number | Signal.State<number> | Signal.Computed<number>} [options.size]
|
|
485
|
-
* @param {boolean} [options.null]
|
|
486
|
-
* @param {boolean} [options.new]
|
|
487
|
-
* @param {boolean} [options.hidden]
|
|
488
|
-
* @param {boolean} [options.clearable]
|
|
489
|
-
* @param {boolean} [options.required]
|
|
490
|
-
* @param {boolean} [options.disabled]
|
|
491
|
-
* @param {boolean} [options.readonly]
|
|
492
|
-
* @param {boolean} [options.removable]
|
|
493
|
-
*
|
|
494
|
-
* @param {string} [options.label] 字段标签
|
|
495
|
-
* @param {string} [options.description] 字段描述
|
|
496
|
-
* @param {string} [options.placeholder] 占位符
|
|
497
|
-
* @param {number} [options.min] 日期、时间、数字的最小值
|
|
498
|
-
* @param {number} [options.max] 日期、时间、数字的最大值
|
|
499
|
-
* @param {number} [options.step] 日期、时间、数字的步长
|
|
500
|
-
* @param {number} [options.minLength]
|
|
501
|
-
* @param {number} [options.maxLength]
|
|
502
|
-
* @param {RegExp} [options.pattern]
|
|
503
|
-
* @param {(Schema.Value.Group | Schema.Value | string | number)[]} [options.values] 可选值
|
|
504
|
-
* @param {Schema.Validator | Schema.Validator[] | null} [options.validator]
|
|
505
|
-
* @param {{[k in keyof Schema.Events]?: Schema.AsyncValidator | Schema.AsyncValidator[] | null}} [options.validators]
|
|
506
|
-
*
|
|
507
|
-
* @param {Ref?} [options.ref]
|
|
508
|
-
*
|
|
509
|
-
* @param {((value: any) => any)?} [options.setValue]
|
|
510
|
-
* @param {((value: any) => any)?} [options.convert]
|
|
511
|
-
*
|
|
512
|
-
* @param {((value: T?, index: any, store: Store) => void)?} [options.onUpdate]
|
|
464
|
+
* @param {StoreOptions | AbortSignal | null} [options] 可选配置
|
|
513
465
|
*/
|
|
514
|
-
constructor(schema: Schema.Field<M, S> | Store<T, M, S>,
|
|
515
|
-
parent?: Store<any, any, {
|
|
516
|
-
[x: string]: Schema.State;
|
|
517
|
-
}> | null | undefined;
|
|
518
|
-
states?: Partial<S> | null | undefined;
|
|
519
|
-
default?: ((store: Store, value?: any) => any) | object | number | string | boolean | null | undefined;
|
|
520
|
-
index?: string | number | null | undefined;
|
|
521
|
-
size?: number | Signal.State<number> | Signal.Computed<number> | undefined;
|
|
522
|
-
null?: boolean | undefined;
|
|
523
|
-
new?: boolean | undefined;
|
|
524
|
-
hidden?: boolean | undefined;
|
|
525
|
-
clearable?: boolean | undefined;
|
|
526
|
-
required?: boolean | undefined;
|
|
527
|
-
disabled?: boolean | undefined;
|
|
528
|
-
readonly?: boolean | undefined;
|
|
529
|
-
removable?: boolean | undefined;
|
|
530
|
-
label?: string | undefined;
|
|
531
|
-
description?: string | undefined;
|
|
532
|
-
placeholder?: string | undefined;
|
|
533
|
-
min?: number | undefined;
|
|
534
|
-
max?: number | undefined;
|
|
535
|
-
step?: number | undefined;
|
|
536
|
-
minLength?: number | undefined;
|
|
537
|
-
maxLength?: number | undefined;
|
|
538
|
-
pattern?: RegExp | undefined;
|
|
539
|
-
values?: (string | number | Schema.Value | Schema.Value.Group)[] | undefined;
|
|
540
|
-
validator?: Schema.Validator | Schema.Validator[] | null | undefined;
|
|
541
|
-
validators?: {
|
|
542
|
-
/**
|
|
543
|
-
* 输入
|
|
544
|
-
*/
|
|
545
|
-
input?: Schema.AsyncValidator | Schema.AsyncValidator[] | null | undefined;
|
|
546
|
-
/**
|
|
547
|
-
* 变化
|
|
548
|
-
*/
|
|
549
|
-
change?: Schema.AsyncValidator | Schema.AsyncValidator[] | null | undefined;
|
|
550
|
-
/**
|
|
551
|
-
* 点击
|
|
552
|
-
*/
|
|
553
|
-
click?: Schema.AsyncValidator | Schema.AsyncValidator[] | null | undefined;
|
|
554
|
-
/**
|
|
555
|
-
* 聚焦
|
|
556
|
-
*/
|
|
557
|
-
focus?: Schema.AsyncValidator | Schema.AsyncValidator[] | null | undefined;
|
|
558
|
-
/**
|
|
559
|
-
* 失焦
|
|
560
|
-
*/
|
|
561
|
-
blur?: Schema.AsyncValidator | Schema.AsyncValidator[] | null | undefined;
|
|
562
|
-
} | undefined;
|
|
563
|
-
ref?: Ref | null | undefined;
|
|
564
|
-
setValue?: ((value: any) => any) | null | undefined;
|
|
565
|
-
convert?: ((value: any) => any) | null | undefined;
|
|
566
|
-
onUpdate?: ((value: T | null, index: any, store: Store) => void) | null | undefined;
|
|
567
|
-
});
|
|
466
|
+
constructor(schema: Schema.Field<M, S> | Store<T, M, S>, options?: StoreOptions | AbortSignal | null);
|
|
568
467
|
get schema(): Schema.Field<M, S>;
|
|
569
468
|
/**
|
|
570
469
|
* 触发事件并通知监听器
|
|
@@ -577,11 +476,21 @@ declare class Store<T = any, M = any, S extends {
|
|
|
577
476
|
/**
|
|
578
477
|
* 监听事件
|
|
579
478
|
* @template {keyof Schema.Events} K
|
|
479
|
+
* @overload
|
|
580
480
|
* @param {K} event
|
|
581
481
|
* @param {(this: this, p: Schema.Events[K], store: this) => void | boolean | null} listener
|
|
582
482
|
* @returns {() => void}
|
|
583
483
|
*/
|
|
584
484
|
listen<K extends keyof Schema.Events>(event: K, listener: (this: this, p: Schema.Events[K], store: this) => void | boolean | null): () => void;
|
|
485
|
+
/**
|
|
486
|
+
* 监听事件
|
|
487
|
+
* @template {keyof Schema.Events} K
|
|
488
|
+
* @overload
|
|
489
|
+
* @param {string} event
|
|
490
|
+
* @param {(this: this, p: unknown, store: this) => void | boolean | null} listener
|
|
491
|
+
* @returns {() => void}
|
|
492
|
+
*/
|
|
493
|
+
listen<K extends keyof Schema.Events>(event: string, listener: (this: this, p: unknown, store: this) => void | boolean | null): () => void;
|
|
585
494
|
/** 是否为无效空存储 */
|
|
586
495
|
get null(): boolean;
|
|
587
496
|
/** 存储类类别,继承的自定义类需要设置自定义的此只读属性 */
|
|
@@ -722,18 +631,6 @@ declare class Store<T = any, M = any, S extends {
|
|
|
722
631
|
* @returns {Store?}
|
|
723
632
|
*/
|
|
724
633
|
child(key: string | number): Store | null;
|
|
725
|
-
/**
|
|
726
|
-
* @template [M=any]
|
|
727
|
-
* @template {Object.<string, Schema.State>} [S=Object.<string, Schema.State>]
|
|
728
|
-
* @param {Schema<M, S>} schema 数据结构模式
|
|
729
|
-
* @param {AbortSignal} [signal]
|
|
730
|
-
* @returns {BindObjectStore}
|
|
731
|
-
*/
|
|
732
|
-
bindObject<M_1 = any, S_1 extends {
|
|
733
|
-
[x: string]: Schema.State;
|
|
734
|
-
} = {
|
|
735
|
-
[x: string]: Schema.State;
|
|
736
|
-
}>(schema: Schema<M_1, S_1>, signal?: AbortSignal): BindObjectStore;
|
|
737
634
|
/** 内容是否已改变 */
|
|
738
635
|
get changed(): boolean;
|
|
739
636
|
set value(v: T | null);
|
|
@@ -763,6 +660,63 @@ declare class Store<T = any, M = any, S extends {
|
|
|
763
660
|
[Symbol.iterator](): IterableIterator<[key: string | number, value: Store]>;
|
|
764
661
|
#private;
|
|
765
662
|
}
|
|
663
|
+
type StoreOptions<T = any, M = any, S extends {
|
|
664
|
+
[x: string]: Schema.State;
|
|
665
|
+
} = {
|
|
666
|
+
[x: string]: Schema.State;
|
|
667
|
+
}> = {
|
|
668
|
+
parent?: Store<any, any, {
|
|
669
|
+
[x: string]: Schema.State;
|
|
670
|
+
}> | null | undefined;
|
|
671
|
+
states?: Partial<S> | null | undefined;
|
|
672
|
+
default?: ((store: Store, value?: any) => any) | object | number | string | boolean | null | undefined;
|
|
673
|
+
index?: string | number | null | undefined;
|
|
674
|
+
size?: number | Signal.State<number> | Signal.Computed<number> | undefined;
|
|
675
|
+
null?: boolean | undefined;
|
|
676
|
+
new?: boolean | undefined;
|
|
677
|
+
hidden?: boolean | undefined;
|
|
678
|
+
clearable?: boolean | undefined;
|
|
679
|
+
required?: boolean | undefined;
|
|
680
|
+
disabled?: boolean | undefined;
|
|
681
|
+
readonly?: boolean | undefined;
|
|
682
|
+
removable?: boolean | undefined;
|
|
683
|
+
/**
|
|
684
|
+
* 字段标签
|
|
685
|
+
*/
|
|
686
|
+
label?: string | undefined;
|
|
687
|
+
/**
|
|
688
|
+
* 字段描述
|
|
689
|
+
*/
|
|
690
|
+
description?: string | undefined;
|
|
691
|
+
/**
|
|
692
|
+
* 占位符
|
|
693
|
+
*/
|
|
694
|
+
placeholder?: string | undefined;
|
|
695
|
+
/**
|
|
696
|
+
* 日期、时间、数字的最小值
|
|
697
|
+
*/
|
|
698
|
+
min?: number | undefined;
|
|
699
|
+
/**
|
|
700
|
+
* 日期、时间、数字的最大值
|
|
701
|
+
*/
|
|
702
|
+
max?: number | undefined;
|
|
703
|
+
/**
|
|
704
|
+
* 日期、时间、数字的步长
|
|
705
|
+
*/
|
|
706
|
+
step?: number | undefined;
|
|
707
|
+
minLength?: number | undefined;
|
|
708
|
+
maxLength?: number | undefined;
|
|
709
|
+
pattern?: RegExp | undefined;
|
|
710
|
+
/**
|
|
711
|
+
* 可选值
|
|
712
|
+
*/
|
|
713
|
+
values?: (string | number | Schema.Value | Schema.Value.Group)[] | undefined;
|
|
714
|
+
validator?: Schema.Validator | Schema.Validator[] | null | undefined;
|
|
715
|
+
ref?: Ref | null | undefined;
|
|
716
|
+
setValue?: ((value: any) => any) | null | undefined;
|
|
717
|
+
convert?: ((value: any) => any) | null | undefined;
|
|
718
|
+
onUpdate?: ((value: T | null, index: any, store: Store) => void) | null | undefined;
|
|
719
|
+
};
|
|
766
720
|
|
|
767
721
|
/** @import { Schema } from '../Schema.types.mjs' */
|
|
768
722
|
/**
|
|
@@ -879,6 +833,32 @@ declare class ArrayStore<T = any, M = any, S extends {
|
|
|
879
833
|
#private;
|
|
880
834
|
}
|
|
881
835
|
|
|
836
|
+
/** @import { Schema } from '../Schema.types.mjs' */
|
|
837
|
+
/**
|
|
838
|
+
* @template [T=any]
|
|
839
|
+
* @template [M=any]
|
|
840
|
+
* @template {Object.<string, Schema.State>} [S=Object.<string, Schema.State>]
|
|
841
|
+
* @extends {Store<T, M, S>}
|
|
842
|
+
*/
|
|
843
|
+
declare class BindObjectStore<T = any, M = any, S extends {
|
|
844
|
+
[x: string]: Schema.State;
|
|
845
|
+
} = {
|
|
846
|
+
[x: string]: Schema.State;
|
|
847
|
+
}> extends Store<T, M, S> {
|
|
848
|
+
/**
|
|
849
|
+
* @param {Schema<any, Object.<string, Schema.State>>} schema 数据结构模式
|
|
850
|
+
* @param {Store<T, M, S>} store
|
|
851
|
+
* @param {AbortSignal} [signal]
|
|
852
|
+
*/
|
|
853
|
+
constructor(schema: Schema<any, {
|
|
854
|
+
[x: string]: Schema.State;
|
|
855
|
+
}>, store: Store<T, M, S>, signal?: AbortSignal);
|
|
856
|
+
[Symbol.iterator](): Generator<[string, Store<any, any, {
|
|
857
|
+
[x: string]: Schema.State;
|
|
858
|
+
}>], void, unknown>;
|
|
859
|
+
#private;
|
|
860
|
+
}
|
|
861
|
+
|
|
882
862
|
/**
|
|
883
863
|
* 解析模板内容
|
|
884
864
|
* @param {string} source 输入源字符串
|
|
@@ -1486,4 +1466,4 @@ declare function renderStore<T>(store: Store, fieldRenderer: StoreLayout.Rendere
|
|
|
1486
1466
|
clone?: boolean;
|
|
1487
1467
|
}) | null): void;
|
|
1488
1468
|
|
|
1489
|
-
export { ArrayStore, Component, Enhancement, index_d as Layout, ObjectStore, type Ref, Schema, Store, StoreLayout, effect, render, renderStore, watch };
|
|
1469
|
+
export { ArrayStore, BindObjectStore, Component, Enhancement, index_d as Layout, type MaybePromise, ObjectStore, type Ref, Schema, Store, StoreLayout, type StoreOptions, effect, render, renderStore, watch };
|