@neeloong/form 0.24.0 → 0.26.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 +132 -46
- package/index.full.js +231 -141
- package/index.full.min.js +4 -4
- package/index.full.min.mjs +7 -7
- package/index.min.mjs +2 -2
- package/index.mjs +231 -141
- package/package.json +1 -1
package/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @neeloong/form v0.
|
|
2
|
+
* @neeloong/form v0.26.0
|
|
3
3
|
* (c) 2024-2026 Fierflame
|
|
4
4
|
* @license Apache-2.0
|
|
5
5
|
*/
|
|
@@ -73,6 +73,7 @@ declare namespace StoreLayout {
|
|
|
73
73
|
html?: string | ParentNode | null | undefined;
|
|
74
74
|
fields?: StoreLayout.Item<T_1>[] | null | undefined;
|
|
75
75
|
renderer?: T_1 | undefined;
|
|
76
|
+
editable?: boolean | null | undefined;
|
|
76
77
|
};
|
|
77
78
|
type Field<T_1 = unknown> = {
|
|
78
79
|
type?: "field" | undefined;
|
|
@@ -105,9 +106,9 @@ declare namespace StoreLayout {
|
|
|
105
106
|
required?: boolean | undefined;
|
|
106
107
|
label?: string | undefined;
|
|
107
108
|
description?: string | undefined;
|
|
108
|
-
disabled?: ((store: Store<any, any>, options?: StoreLayout.Options | null) => boolean) | undefined;
|
|
109
|
-
text?: string | ((store: Store<any, any>, options?: StoreLayout.Options | null) => string) | undefined;
|
|
110
|
-
click?: string | ((event: Event, store: Store<any, any>, options?: StoreLayout.Options | null) => void) | undefined;
|
|
109
|
+
disabled?: ((store: Store<any, any, any>, options?: StoreLayout.Options | null) => boolean) | undefined;
|
|
110
|
+
text?: string | ((store: Store<any, any, any>, options?: StoreLayout.Options | null) => string) | undefined;
|
|
111
|
+
click?: string | ((event: Event, store: Store<any, any, any>, options?: StoreLayout.Options | null) => void) | undefined;
|
|
111
112
|
};
|
|
112
113
|
type Html = {
|
|
113
114
|
type: "html";
|
|
@@ -128,12 +129,16 @@ declare namespace StoreLayout {
|
|
|
128
129
|
relate?: ((store: Store, el: Element | StoreLayout.Relatedness) => () => void) | undefined;
|
|
129
130
|
editable?: boolean | undefined;
|
|
130
131
|
signal?: AbortSignal | undefined;
|
|
131
|
-
call?: ((name: string, event: Event, store: Store<any, any>, options?: StoreLayout.Options | null) => void) | undefined;
|
|
132
|
+
call?: ((name: string, event: Event, store: Store<any, any, any>, options?: StoreLayout.Options | null) => void) | undefined;
|
|
132
133
|
};
|
|
133
|
-
type Renderer<T_1 = unknown> = (store: Store<any, any>, renderer?: T_1, options?: StoreLayout.Options | null) => HTMLElement | null;
|
|
134
|
+
type Renderer<T_1 = unknown> = (store: Store<any, any, any>, renderer?: T_1, options?: StoreLayout.Options | null) => HTMLElement | null;
|
|
134
135
|
}
|
|
135
136
|
|
|
136
|
-
type Schema<M = any
|
|
137
|
+
type Schema<M = any, S extends {
|
|
138
|
+
[x: string]: Schema.State;
|
|
139
|
+
} = {
|
|
140
|
+
[x: string]: Schema.State;
|
|
141
|
+
}> = Record<string, Schema.Field<M, S>>;
|
|
137
142
|
declare namespace Schema {
|
|
138
143
|
/**
|
|
139
144
|
* 同步验证器
|
|
@@ -146,7 +151,11 @@ declare namespace Schema {
|
|
|
146
151
|
/**
|
|
147
152
|
* 字段定义
|
|
148
153
|
*/
|
|
149
|
-
type Field<M_1 = any
|
|
154
|
+
type Field<M_1 = any, S_1 extends {
|
|
155
|
+
[x: string]: Schema.State;
|
|
156
|
+
} = {
|
|
157
|
+
[x: string]: State;
|
|
158
|
+
}> = (Schema.Object<M_1, S_1> | Schema.Type) & Schema.Attr<M_1, S_1>;
|
|
150
159
|
/**
|
|
151
160
|
* 可选值
|
|
152
161
|
*/
|
|
@@ -205,11 +214,15 @@ declare namespace Schema {
|
|
|
205
214
|
/**
|
|
206
215
|
* 对象类型定义
|
|
207
216
|
*/
|
|
208
|
-
type Object<M_1 = any
|
|
217
|
+
type Object<M_1 = any, S_1 extends {
|
|
218
|
+
[x: string]: Schema.State;
|
|
219
|
+
} = {
|
|
220
|
+
[x: string]: State;
|
|
221
|
+
}> = {
|
|
209
222
|
/**
|
|
210
223
|
* 字段定义
|
|
211
224
|
*/
|
|
212
|
-
type: Record<string, Schema.Field<M_1>>;
|
|
225
|
+
type: Record<string, Schema.Field<M_1, S_1>>;
|
|
213
226
|
/**
|
|
214
227
|
* 是否为数组
|
|
215
228
|
*/
|
|
@@ -253,11 +266,21 @@ declare namespace Schema {
|
|
|
253
266
|
*/
|
|
254
267
|
blur: Event;
|
|
255
268
|
};
|
|
256
|
-
type
|
|
269
|
+
type Stater<T, S_1 = any> = {
|
|
270
|
+
get: (arg0: Store, arg1: Signal.State<S_1>) => T;
|
|
271
|
+
set: (arg0: Store, arg1: Signal.State<S_1>, arg2: any) => void;
|
|
272
|
+
toState: (arg0: any) => S_1;
|
|
273
|
+
};
|
|
274
|
+
type Attr<M_1 = any, S_1 extends {
|
|
275
|
+
[x: string]: Schema.State;
|
|
276
|
+
} = {
|
|
277
|
+
[x: string]: State;
|
|
278
|
+
}> = {
|
|
257
279
|
/**
|
|
258
280
|
* 元信息
|
|
259
281
|
*/
|
|
260
282
|
meta?: M_1 | undefined;
|
|
283
|
+
states?: { [k in keyof S_1]: Schema.Stater<S_1[k], any>; } | undefined;
|
|
261
284
|
default?: ((store: Store) => any) | any;
|
|
262
285
|
/**
|
|
263
286
|
* 自定义组件
|
|
@@ -377,6 +400,7 @@ declare namespace Schema {
|
|
|
377
400
|
} | undefined;
|
|
378
401
|
layout?: StoreLayout.Field<any> | undefined;
|
|
379
402
|
};
|
|
403
|
+
type State = string | boolean | number | Object | null;
|
|
380
404
|
}
|
|
381
405
|
|
|
382
406
|
declare const ref: unique symbol;
|
|
@@ -392,18 +416,30 @@ type Ref = {
|
|
|
392
416
|
* 管理单个表单字段的状态和行为
|
|
393
417
|
* @template [T=any]
|
|
394
418
|
* @template [M=any]
|
|
419
|
+
* @template {Object.<string, Schema.State>} [S=Object.<string, Schema.State>]
|
|
395
420
|
*/
|
|
396
|
-
declare class Store<T = any, M = any
|
|
421
|
+
declare class Store<T = any, M = any, S extends {
|
|
422
|
+
[x: string]: Schema.State;
|
|
423
|
+
} = {
|
|
424
|
+
[x: string]: Schema.State;
|
|
425
|
+
}> {
|
|
397
426
|
/**
|
|
398
427
|
* 从数据结构模式创建存储
|
|
399
428
|
* @template [M=any]
|
|
400
|
-
* @
|
|
429
|
+
* @template {Object.<string, Schema.State>} [S=Object.<string, Schema.State>]
|
|
430
|
+
* @param {Schema<M, S>} schema 数据结构模式
|
|
401
431
|
* @param {object} [options] 选项
|
|
402
432
|
* @param {boolean} [options.new] 是否为新建环境
|
|
403
433
|
*/
|
|
404
|
-
static create<M_1 = any
|
|
434
|
+
static create<M_1 = any, S_1 extends {
|
|
435
|
+
[x: string]: Schema.State;
|
|
436
|
+
} = {
|
|
437
|
+
[x: string]: Schema.State;
|
|
438
|
+
}>(schema: Schema<M_1, S_1>, options?: {
|
|
405
439
|
new?: boolean | undefined;
|
|
406
|
-
}): Store<any, any
|
|
440
|
+
}): Store<any, any, {
|
|
441
|
+
[x: string]: Schema.State;
|
|
442
|
+
}>;
|
|
407
443
|
/**
|
|
408
444
|
* 设置自定义类型的存储类
|
|
409
445
|
* @param {string} type
|
|
@@ -413,9 +449,10 @@ declare class Store<T = any, M = any> {
|
|
|
413
449
|
new (...p: ConstructorParameters<typeof Store>): Store;
|
|
414
450
|
}): void;
|
|
415
451
|
/**
|
|
416
|
-
* @param {Schema.Field<M>} schema 字段的 Schema 定义
|
|
452
|
+
* @param {Schema.Field<M, S>} schema 字段的 Schema 定义
|
|
417
453
|
* @param {object} [options] 可选配置
|
|
418
454
|
* @param {Store?} [options.parent]
|
|
455
|
+
* @param {Partial<S>?} [options.states]
|
|
419
456
|
* @param {((store: Store, value?: any) => any) | object | number | string | boolean | null | undefined} [options.default]
|
|
420
457
|
* @param {number | string | null} [options.index]
|
|
421
458
|
* @param {number | Signal.State<number> | Signal.Computed<number>} [options.size]
|
|
@@ -448,8 +485,11 @@ declare class Store<T = any, M = any> {
|
|
|
448
485
|
*
|
|
449
486
|
* @param {((value: T?, index: any, store: Store) => void)?} [options.onUpdate]
|
|
450
487
|
*/
|
|
451
|
-
constructor(schema: Schema.Field<M>, { null: isNull, ref, default: defaultValue, setValue, convert, onUpdate, validator, validators, index, size, new: isNew, parent: parentNode, hidden, clearable, required, disabled, readonly, removable, label, description, placeholder, min, max, step, minLength, maxLength, pattern, values }?: {
|
|
452
|
-
parent?: Store<any, any
|
|
488
|
+
constructor(schema: Schema.Field<M, S>, { null: isNull, ref, default: defaultValue, setValue, convert, onUpdate, states, validator, validators, index, size, new: isNew, parent: parentNode, hidden, clearable, required, disabled, readonly, removable, label, description, placeholder, min, max, step, minLength, maxLength, pattern, values }?: {
|
|
489
|
+
parent?: Store<any, any, {
|
|
490
|
+
[x: string]: Schema.State;
|
|
491
|
+
}> | null | undefined;
|
|
492
|
+
states?: Partial<S> | null | undefined;
|
|
453
493
|
default?: ((store: Store, value?: any) => any) | object | number | string | boolean | null | undefined;
|
|
454
494
|
index?: string | number | null | undefined;
|
|
455
495
|
size?: number | Signal.State<number> | Signal.Computed<number> | undefined;
|
|
@@ -519,7 +559,8 @@ declare class Store<T = any, M = any> {
|
|
|
519
559
|
/** 存储类类别,继承的自定义类需要设置自定义的此只读属性 */
|
|
520
560
|
get kind(): string;
|
|
521
561
|
get ref(): Ref;
|
|
522
|
-
schema: Schema.Field<M>;
|
|
562
|
+
schema: Schema.Field<M, S>;
|
|
563
|
+
get states(): S | null;
|
|
523
564
|
get layout(): StoreLayout.Field<any>;
|
|
524
565
|
/** @param {any} [value] @returns {any} */
|
|
525
566
|
createDefault(value?: any): any;
|
|
@@ -528,9 +569,13 @@ declare class Store<T = any, M = any> {
|
|
|
528
569
|
/** 存储对象自身 */
|
|
529
570
|
get store(): this;
|
|
530
571
|
/** 父级存储对象 */
|
|
531
|
-
get parent(): Store<any, any
|
|
572
|
+
get parent(): Store<any, any, {
|
|
573
|
+
[x: string]: Schema.State;
|
|
574
|
+
}> | null;
|
|
532
575
|
/** 根节点的存储对象 */
|
|
533
|
-
get root(): Store<any, any
|
|
576
|
+
get root(): Store<any, any, {
|
|
577
|
+
[x: string]: Schema.State;
|
|
578
|
+
}>;
|
|
534
579
|
/** 字段类型 */
|
|
535
580
|
get type(): any;
|
|
536
581
|
/** 字段元信息 */
|
|
@@ -599,39 +644,46 @@ declare class Store<T = any, M = any> {
|
|
|
599
644
|
/** 字段的占位符信息 */
|
|
600
645
|
get placeholder(): string | null;
|
|
601
646
|
set selfMin(v: number | null);
|
|
647
|
+
/** @deprecated */
|
|
602
648
|
get selfMin(): number | null;
|
|
603
649
|
set min(v: number | null);
|
|
604
|
-
/** 数值字段的最小值限制 */
|
|
650
|
+
/** @deprecated 数值字段的最小值限制 */
|
|
605
651
|
get min(): number | null;
|
|
606
652
|
set selfMax(v: number | null);
|
|
653
|
+
/** @deprecated */
|
|
607
654
|
get selfMax(): number | null;
|
|
608
655
|
set max(v: number | null);
|
|
609
|
-
/** 数值字段的最大值限制 */
|
|
656
|
+
/** @deprecated 数值字段的最大值限制 */
|
|
610
657
|
get max(): number | null;
|
|
611
658
|
set selfStep(v: number | null);
|
|
659
|
+
/** @deprecated */
|
|
612
660
|
get selfStep(): number | null;
|
|
613
661
|
set step(v: number | null);
|
|
614
|
-
/** 数值字段的步长 */
|
|
662
|
+
/** @deprecated 数值字段的步长 */
|
|
615
663
|
get step(): number | null;
|
|
616
664
|
set selfMinLength(v: number | null);
|
|
665
|
+
/** @deprecated */
|
|
617
666
|
get selfMinLength(): number | null;
|
|
618
667
|
set minLength(v: number | null);
|
|
619
|
-
/** 最小长度 */
|
|
668
|
+
/** @deprecated 最小长度 */
|
|
620
669
|
get minLength(): number | null;
|
|
621
670
|
set selfMaxLength(v: number | null);
|
|
671
|
+
/** @deprecated */
|
|
622
672
|
get selfMaxLength(): number | null;
|
|
623
673
|
set maxLength(v: number | null);
|
|
624
|
-
/** 最大长度 */
|
|
674
|
+
/** @deprecated 最大长度 */
|
|
625
675
|
get maxLength(): number | null;
|
|
626
676
|
set selfPattern(v: RegExp | null);
|
|
677
|
+
/** @deprecated */
|
|
627
678
|
get selfPattern(): RegExp | null;
|
|
628
679
|
set pattern(v: RegExp | null);
|
|
629
|
-
/** 模式 */
|
|
680
|
+
/** @deprecated 模式 */
|
|
630
681
|
get pattern(): RegExp | null;
|
|
631
682
|
set selfValues(v: (Schema.Value | Schema.Value.Group)[] | null);
|
|
683
|
+
/** @deprecated */
|
|
632
684
|
get selfValues(): (Schema.Value | Schema.Value.Group)[] | null;
|
|
633
685
|
set values(v: (Schema.Value | Schema.Value.Group)[] | null);
|
|
634
|
-
/** 可选值列表 */
|
|
686
|
+
/** @deprecated 可选值列表 */
|
|
635
687
|
get values(): (Schema.Value | Schema.Value.Group)[] | null;
|
|
636
688
|
/** 所有校验错误列表 */
|
|
637
689
|
get errors(): string[];
|
|
@@ -643,20 +695,30 @@ declare class Store<T = any, M = any> {
|
|
|
643
695
|
* @returns {Store?}
|
|
644
696
|
*/
|
|
645
697
|
child(key: string | number): Store | null;
|
|
646
|
-
/**
|
|
647
|
-
|
|
698
|
+
/**
|
|
699
|
+
* @template [M=any]
|
|
700
|
+
* @template {Object.<string, Schema.State>} [S=Object.<string, Schema.State>]
|
|
701
|
+
* @param {Schema<M, S>} schema 数据结构模式
|
|
702
|
+
*/
|
|
703
|
+
bindObject<M_1 = any, S_1 extends {
|
|
704
|
+
[x: string]: Schema.State;
|
|
705
|
+
} = {
|
|
706
|
+
[x: string]: Schema.State;
|
|
707
|
+
}>(schema: Schema<M_1, S_1>): () => void;
|
|
648
708
|
set value(v: T | null);
|
|
649
709
|
/** 字段当前值 */
|
|
650
710
|
get value(): T | null;
|
|
711
|
+
/** 内容是否已改变 */
|
|
712
|
+
get changed(): boolean;
|
|
651
713
|
/** 重置数据 */
|
|
652
714
|
reset(value?: unknown, isNew?: boolean): void;
|
|
653
715
|
/**
|
|
654
716
|
* 异步校验
|
|
655
717
|
* @overload
|
|
656
|
-
* @param {true} [
|
|
718
|
+
* @param {true} [self]
|
|
657
719
|
* @returns {Promise<string[] | null>}
|
|
658
720
|
*/
|
|
659
|
-
validate(
|
|
721
|
+
validate(self?: true | undefined): Promise<string[] | null>;
|
|
660
722
|
/**
|
|
661
723
|
* 异步校验
|
|
662
724
|
* @overload
|
|
@@ -677,24 +739,33 @@ declare class Store<T = any, M = any> {
|
|
|
677
739
|
/**
|
|
678
740
|
* @template {Record<string, any>} [T=Record<string, any>]
|
|
679
741
|
* @template [M=any]
|
|
680
|
-
* @
|
|
742
|
+
* @template {Object.<string, Schema.State>} [S=Object.<string, Schema.State>]
|
|
743
|
+
* @extends {Store<T, M, S>}
|
|
681
744
|
*/
|
|
682
|
-
declare class ObjectStore<T extends Record<string, any> = Record<string, any>, M = any
|
|
745
|
+
declare class ObjectStore<T extends Record<string, any> = Record<string, any>, M = any, S extends {
|
|
746
|
+
[x: string]: Schema.State;
|
|
747
|
+
} = {
|
|
748
|
+
[x: string]: Schema.State;
|
|
749
|
+
}> extends Store<T, M, S> {
|
|
683
750
|
/**
|
|
684
|
-
* @param {Schema.Object<M> & Schema.Attr<M>} schema
|
|
751
|
+
* @param {Schema.Object<M, S> & Schema.Attr<M, S>} schema
|
|
685
752
|
* @param {object} [options]
|
|
686
753
|
* @param {Store?} [options.parent]
|
|
687
754
|
* @param {number | string | null} [options.index]
|
|
688
755
|
* @param {boolean} [options.new]
|
|
689
756
|
* @param {((value: T?, index: any, store: Store) => void)?} [options.onUpdate]
|
|
690
757
|
*/
|
|
691
|
-
constructor(schema: Schema.Object<M> & Schema.Attr<M>, { parent, index, new: isNew, onUpdate }?: {
|
|
692
|
-
parent?: Store<any, any
|
|
758
|
+
constructor(schema: Schema.Object<M, S> & Schema.Attr<M, S>, { parent, index, new: isNew, onUpdate }?: {
|
|
759
|
+
parent?: Store<any, any, {
|
|
760
|
+
[x: string]: Schema.State;
|
|
761
|
+
}> | null | undefined;
|
|
693
762
|
index?: string | number | null | undefined;
|
|
694
763
|
new?: boolean | undefined;
|
|
695
764
|
onUpdate?: ((value: T | null, index: any, store: Store) => void) | null | undefined;
|
|
696
765
|
});
|
|
697
|
-
[Symbol.iterator](): Generator<[string, Store<any, any
|
|
766
|
+
[Symbol.iterator](): Generator<[string, Store<any, any, {
|
|
767
|
+
[x: string]: Schema.State;
|
|
768
|
+
}>], void, unknown>;
|
|
698
769
|
#private;
|
|
699
770
|
}
|
|
700
771
|
|
|
@@ -702,11 +773,16 @@ declare class ObjectStore<T extends Record<string, any> = Record<string, any>, M
|
|
|
702
773
|
/**
|
|
703
774
|
* @template [T=any]
|
|
704
775
|
* @template [M=any]
|
|
705
|
-
* @
|
|
776
|
+
* @template {Object.<string, Schema.State>} [S=Object.<string, Schema.State>]
|
|
777
|
+
* @extends {Store<(T | null)[], M, S>}
|
|
706
778
|
*/
|
|
707
|
-
declare class ArrayStore<T = any, M = any
|
|
779
|
+
declare class ArrayStore<T = any, M = any, S extends {
|
|
780
|
+
[x: string]: Schema.State;
|
|
781
|
+
} = {
|
|
782
|
+
[x: string]: Schema.State;
|
|
783
|
+
}> extends Store<(T | null)[], M, S> {
|
|
708
784
|
/**
|
|
709
|
-
* @param {Schema.Field<M>} schema
|
|
785
|
+
* @param {Schema.Field<M, S>} schema
|
|
710
786
|
* @param {object} [options]
|
|
711
787
|
* @param {Store?} [options.parent]
|
|
712
788
|
* @param {string | number | null} [options.index]
|
|
@@ -714,14 +790,20 @@ declare class ArrayStore<T = any, M = any> extends Store<(T | null)[], M> {
|
|
|
714
790
|
* @param {boolean} [options.addable]
|
|
715
791
|
* @param {(value: any, index: any, store: Store) => void} [options.onUpdate]
|
|
716
792
|
*/
|
|
717
|
-
constructor(schema: Schema.Field<M>, { parent, onUpdate, index, new: isNew, addable }?: {
|
|
718
|
-
parent?: Store<any, any
|
|
793
|
+
constructor(schema: Schema.Field<M, S>, { parent, onUpdate, index, new: isNew, addable }?: {
|
|
794
|
+
parent?: Store<any, any, {
|
|
795
|
+
[x: string]: Schema.State;
|
|
796
|
+
}> | null | undefined;
|
|
719
797
|
index?: string | number | null | undefined;
|
|
720
798
|
new?: boolean | undefined;
|
|
721
799
|
addable?: boolean | undefined;
|
|
722
800
|
onUpdate?: ((value: any, index: any, store: Store) => void) | undefined;
|
|
723
801
|
});
|
|
724
|
-
get children(): Store<any, any
|
|
802
|
+
get children(): Store<any, any, {
|
|
803
|
+
[x: string]: Schema.State;
|
|
804
|
+
}>[];
|
|
805
|
+
/** @returns {never} */
|
|
806
|
+
bindObject(): never;
|
|
725
807
|
set selfAddable(v: boolean | null);
|
|
726
808
|
get selfAddable(): boolean | null;
|
|
727
809
|
set addable(v: boolean);
|
|
@@ -762,7 +844,9 @@ declare class ArrayStore<T = any, M = any> extends Store<(T | null)[], M> {
|
|
|
762
844
|
* @returns
|
|
763
845
|
*/
|
|
764
846
|
exchange(a: number, b: number): boolean;
|
|
765
|
-
[Symbol.iterator](): Generator<[number, Store<any, any
|
|
847
|
+
[Symbol.iterator](): Generator<[number, Store<any, any, {
|
|
848
|
+
[x: string]: Schema.State;
|
|
849
|
+
}>], undefined, unknown>;
|
|
766
850
|
#private;
|
|
767
851
|
}
|
|
768
852
|
|
|
@@ -1287,7 +1371,9 @@ declare namespace Enhancement {
|
|
|
1287
1371
|
* @returns {() => void}
|
|
1288
1372
|
*/
|
|
1289
1373
|
declare function render(store: Store, layouts: Child[], parent: Element, { component, global, relate, enhancements }?: {
|
|
1290
|
-
global?: Record<string, Store<any, any
|
|
1374
|
+
global?: Record<string, Store<any, any, {
|
|
1375
|
+
[x: string]: Schema.State;
|
|
1376
|
+
}> | {
|
|
1291
1377
|
get?(): any;
|
|
1292
1378
|
set?(v: any): void;
|
|
1293
1379
|
exec?(...p: any[]): any;
|