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