@neeloong/form 0.29.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 +31 -33
- package/index.full.js +190 -149
- package/index.full.min.js +2 -2
- package/index.full.min.mjs +4 -4
- package/index.min.mjs +2 -2
- package/index.mjs +190 -149
- 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;
|
|
@@ -466,11 +476,21 @@ declare class Store<T = any, M = any, S extends {
|
|
|
466
476
|
/**
|
|
467
477
|
* 监听事件
|
|
468
478
|
* @template {keyof Schema.Events} K
|
|
479
|
+
* @overload
|
|
469
480
|
* @param {K} event
|
|
470
481
|
* @param {(this: this, p: Schema.Events[K], store: this) => void | boolean | null} listener
|
|
471
482
|
* @returns {() => void}
|
|
472
483
|
*/
|
|
473
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;
|
|
474
494
|
/** 是否为无效空存储 */
|
|
475
495
|
get null(): boolean;
|
|
476
496
|
/** 存储类类别,继承的自定义类需要设置自定义的此只读属性 */
|
|
@@ -692,28 +712,6 @@ type StoreOptions<T = any, M = any, S extends {
|
|
|
692
712
|
*/
|
|
693
713
|
values?: (string | number | Schema.Value | Schema.Value.Group)[] | undefined;
|
|
694
714
|
validator?: Schema.Validator | Schema.Validator[] | null | undefined;
|
|
695
|
-
validators?: {
|
|
696
|
-
/**
|
|
697
|
-
* 输入
|
|
698
|
-
*/
|
|
699
|
-
input?: Schema.AsyncValidator | Schema.AsyncValidator[] | null | undefined;
|
|
700
|
-
/**
|
|
701
|
-
* 变化
|
|
702
|
-
*/
|
|
703
|
-
change?: Schema.AsyncValidator | Schema.AsyncValidator[] | null | undefined;
|
|
704
|
-
/**
|
|
705
|
-
* 点击
|
|
706
|
-
*/
|
|
707
|
-
click?: Schema.AsyncValidator | Schema.AsyncValidator[] | null | undefined;
|
|
708
|
-
/**
|
|
709
|
-
* 聚焦
|
|
710
|
-
*/
|
|
711
|
-
focus?: Schema.AsyncValidator | Schema.AsyncValidator[] | null | undefined;
|
|
712
|
-
/**
|
|
713
|
-
* 失焦
|
|
714
|
-
*/
|
|
715
|
-
blur?: Schema.AsyncValidator | Schema.AsyncValidator[] | null | undefined;
|
|
716
|
-
} | undefined;
|
|
717
715
|
ref?: Ref | null | undefined;
|
|
718
716
|
setValue?: ((value: any) => any) | null | undefined;
|
|
719
717
|
convert?: ((value: any) => any) | null | undefined;
|
|
@@ -1468,4 +1466,4 @@ declare function renderStore<T>(store: Store, fieldRenderer: StoreLayout.Rendere
|
|
|
1468
1466
|
clone?: boolean;
|
|
1469
1467
|
}) | null): void;
|
|
1470
1468
|
|
|
1471
|
-
export { ArrayStore, BindObjectStore, Component, Enhancement, index_d as Layout, ObjectStore, type Ref, Schema, Store, StoreLayout, type StoreOptions, 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 };
|
package/index.full.js
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
|
*/
|
|
@@ -779,79 +779,127 @@
|
|
|
779
779
|
/**
|
|
780
780
|
*
|
|
781
781
|
* @param {Store} store
|
|
782
|
-
* @param
|
|
782
|
+
* @param {Schema.SyncValidator[]} syncValidators
|
|
783
783
|
* @returns
|
|
784
784
|
*/
|
|
785
|
-
function
|
|
786
|
-
const allValidators = validators.flat().filter(v => typeof v === 'function');
|
|
787
|
-
if (!allValidators.length) {
|
|
788
|
-
return new exports.Signal.Computed(() => /** @type {string[]} */([]));
|
|
789
|
-
}
|
|
785
|
+
function createSyncValidator(store, syncValidators) {
|
|
790
786
|
return new exports.Signal.Computed(() => {
|
|
791
787
|
const results = [];
|
|
792
|
-
for (const
|
|
788
|
+
for (const item of syncValidators) {
|
|
793
789
|
try {
|
|
794
|
-
results.push(
|
|
795
|
-
} catch (e){
|
|
790
|
+
results.push(item(store));
|
|
791
|
+
} catch (e) {
|
|
796
792
|
results.push(e);
|
|
797
793
|
}
|
|
798
794
|
}
|
|
799
795
|
return results.flat().map(toResult).filter(Boolean);
|
|
800
|
-
})
|
|
796
|
+
});
|
|
801
797
|
}
|
|
798
|
+
|
|
802
799
|
/**
|
|
803
800
|
*
|
|
804
801
|
* @param {Store} store
|
|
805
|
-
* @param
|
|
806
|
-
* @returns {[
|
|
802
|
+
* @param {Map<string, Schema.AsyncValidator[]>} eventsValidators
|
|
803
|
+
* @returns {[Record<string, () => Promise<string[]>>, results: Signal.State<string[]>[], stop: () => void]}
|
|
807
804
|
*/
|
|
808
|
-
function
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
805
|
+
function createEventsValidator(store, eventsValidators) {
|
|
806
|
+
/** @type {Record<string, () => Promise<string[]>>} */
|
|
807
|
+
const eventExecMap = {};
|
|
808
|
+
/** @type {(() => void)[]} */
|
|
809
|
+
const allCancels = [];
|
|
810
|
+
/** @type {Signal.State<string[]>[]} */
|
|
811
|
+
const results = [];
|
|
812
|
+
for (const [name, validators] of eventsValidators) {
|
|
813
|
+
const st = new exports.Signal.State(/** @type {string[]} */([]));
|
|
814
|
+
/**
|
|
815
|
+
*
|
|
816
|
+
* @param {Schema.AsyncValidator} validator
|
|
817
|
+
* @param {AbortSignal} signal
|
|
818
|
+
*/
|
|
819
|
+
async function run(validator, signal) {
|
|
820
|
+
let results = [];
|
|
821
|
+
try {
|
|
822
|
+
results.push(await validator(store, signal));
|
|
823
|
+
} catch (e) {
|
|
824
|
+
results.push(e);
|
|
825
|
+
}
|
|
826
|
+
const list = results.flat().map(toResult).filter(Boolean);
|
|
827
|
+
if (!signal.aborted && list.length) { st.set([...st.get(), ...list]); }
|
|
828
|
+
return list;
|
|
829
829
|
}
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
830
|
+
/** @type {AbortController?} */
|
|
831
|
+
let ac = null;
|
|
832
|
+
function exec() {
|
|
833
|
+
ac?.abort();
|
|
834
|
+
ac = new AbortController();
|
|
835
|
+
const signal = ac.signal;
|
|
836
|
+
st.set([]);
|
|
837
|
+
|
|
838
|
+
return Promise.all(validators.map(f => run(f, signal))).then(v => v.flat());
|
|
839
|
+
}
|
|
840
|
+
eventExecMap[name] = exec;
|
|
841
|
+
allCancels.push(() => { ac?.abort(); st.set([]); });
|
|
842
|
+
results.push(st);
|
|
833
843
|
}
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
}
|
|
844
|
-
return [exec, new exports.Signal.Computed(() => st.get()), () => {ac?.abort(); st.set([]);}]
|
|
844
|
+
|
|
845
|
+
function stop() {
|
|
846
|
+
for (const c of allCancels) {
|
|
847
|
+
c();
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
return [eventExecMap, results, stop];
|
|
845
853
|
}
|
|
846
854
|
|
|
847
855
|
/**
|
|
848
856
|
*
|
|
849
|
-
* @param
|
|
850
|
-
* @
|
|
857
|
+
* @param {Store} store
|
|
858
|
+
* @param {...Schema.Validator | undefined | null | (Schema.Validator | undefined | null)[]} validators
|
|
859
|
+
* @returns {[exec: () => Promise<string[]>, Record<string, () => Promise<string[]>>, state: Signal.Computed<string[]>, stop: () => void]}
|
|
851
860
|
*/
|
|
852
|
-
function
|
|
853
|
-
|
|
854
|
-
|
|
861
|
+
function createValidator(store, ...validators) {
|
|
862
|
+
|
|
863
|
+
/** @type {Schema.SyncValidator[]} */
|
|
864
|
+
const syncValidators = [];
|
|
865
|
+
/** @type {Map<string, Schema.AsyncValidator[]>} */
|
|
866
|
+
const eventsValidators = new Map();
|
|
867
|
+
for (const v of validators.flat()) {
|
|
868
|
+
if (!v) { continue; }
|
|
869
|
+
if (typeof v === 'function') {
|
|
870
|
+
syncValidators.push(v);
|
|
871
|
+
continue;
|
|
872
|
+
}
|
|
873
|
+
const { event, validator } = v;
|
|
874
|
+
if (typeof validator !== 'function') { continue; }
|
|
875
|
+
if (typeof event !== 'string') {
|
|
876
|
+
syncValidators.push(validator);
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
879
|
+
const list = eventsValidators.get(event);
|
|
880
|
+
if (list) {
|
|
881
|
+
list.push(validator);
|
|
882
|
+
} else {
|
|
883
|
+
eventsValidators.set(event, [validator]);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
const validatorResult = syncValidators.length
|
|
889
|
+
? createSyncValidator(store, syncValidators)
|
|
890
|
+
: new exports.Signal.Computed(() => /** @type {string[]} */([]));
|
|
891
|
+
if (!eventsValidators.size) {
|
|
892
|
+
return [() => Promise.resolve(validatorResult.get()), {}, validatorResult, () => {}];
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
const [eventExecMap, results, stop] = createEventsValidator(store, eventsValidators);
|
|
896
|
+
|
|
897
|
+
const errors = new exports.Signal.Computed(() => [validatorResult, ...results].flatMap(v => v.get()));
|
|
898
|
+
const execAll = () => Promise.all([
|
|
899
|
+
validatorResult.get(),
|
|
900
|
+
...Object.values(eventExecMap).map(exec => exec()),
|
|
901
|
+
]).then(v => v.flat());
|
|
902
|
+
return [execAll, eventExecMap, errors, stop];
|
|
855
903
|
}
|
|
856
904
|
|
|
857
905
|
/** @import Store from './Store.mjs' */
|
|
@@ -910,10 +958,25 @@
|
|
|
910
958
|
/**
|
|
911
959
|
* 监听事件
|
|
912
960
|
* @template {keyof Schema.Events} K
|
|
961
|
+
* @overload
|
|
913
962
|
* @param {K} event
|
|
914
963
|
* @param {(this: this, p: Schema.Events[K], store: this) => void | boolean | null} listener
|
|
915
964
|
* @returns {() => void}
|
|
916
965
|
*/
|
|
966
|
+
/**
|
|
967
|
+
* 监听事件
|
|
968
|
+
* @template {keyof Schema.Events} K
|
|
969
|
+
* @overload
|
|
970
|
+
* @param {string} event
|
|
971
|
+
* @param {(this: this, p: unknown, store: this) => void | boolean | null} listener
|
|
972
|
+
* @returns {() => void}
|
|
973
|
+
*/
|
|
974
|
+
/**
|
|
975
|
+
* 监听事件
|
|
976
|
+
* @param {string} event
|
|
977
|
+
* @param {(this: this, p: unknown, store: this) => void | boolean | null} listener
|
|
978
|
+
* @returns {() => void}
|
|
979
|
+
*/
|
|
917
980
|
listen(event, listener) {
|
|
918
981
|
const originStore = this.#originStore;
|
|
919
982
|
if (originStore) { return originStore.listen(event, p => listener.call(this, p, this)); }
|
|
@@ -963,73 +1026,70 @@
|
|
|
963
1026
|
constructor(schema, options) {
|
|
964
1027
|
if (schema instanceof Store) {
|
|
965
1028
|
const store = schema.#originStore || schema;
|
|
966
|
-
this.#originStore= store;
|
|
967
|
-
this.#schema= store.#schema;
|
|
968
|
-
this.#null= store.#null;
|
|
969
|
-
this.#ref= store.#ref;
|
|
970
|
-
this.#states= store.#states;
|
|
971
|
-
this.#layout= store.#layout;
|
|
972
|
-
this.#createDefault= store.#createDefault;
|
|
973
|
-
this.#setValue= store.#setValue;
|
|
974
|
-
this.#convert= store.#convert;
|
|
975
|
-
this.#onUpdate= store.#onUpdate;
|
|
976
|
-
this.#parent= store.#parent;
|
|
977
|
-
this.#root= store.#root;
|
|
978
|
-
this.#type= store.#type;
|
|
979
|
-
this.#meta= store.#meta;
|
|
980
|
-
this.#component= store.#component;
|
|
981
|
-
this.#selfLoading= store.#selfLoading;
|
|
982
|
-
this.#loading= store.#loading;
|
|
983
|
-
this.#size= store.#size;
|
|
984
|
-
this.#index= store.#index;
|
|
985
|
-
this.#creatable= store.#creatable;
|
|
986
|
-
this.#immutable= store.#immutable;
|
|
987
|
-
this.#new= store.#new;
|
|
988
|
-
this.#selfNew= store.#selfNew;
|
|
989
|
-
this.#selfHidden= store.#selfHidden;
|
|
990
|
-
this.#hidden= store.#hidden;
|
|
991
|
-
this.#selfClearable= store.#selfClearable;
|
|
992
|
-
this.#clearable= store.#clearable;
|
|
993
|
-
this.#selfRequired= store.#selfRequired;
|
|
994
|
-
this.#required= store.#required;
|
|
995
|
-
this.#selfDisabled= store.#selfDisabled;
|
|
996
|
-
this.#disabled= store.#disabled;
|
|
997
|
-
this.#selfReadonly= store.#selfReadonly;
|
|
998
|
-
this.#readonly= store.#readonly;
|
|
999
|
-
this.#selfRemovable= store.#selfRemovable;
|
|
1000
|
-
this.#removable= store.#removable;
|
|
1001
|
-
this.#selfLabel= store.#selfLabel;
|
|
1002
|
-
this.#label= store.#label;
|
|
1003
|
-
this.#selfDescription= store.#selfDescription;
|
|
1004
|
-
this.#description= store.#description;
|
|
1005
|
-
this.#selfPlaceholder= store.#selfPlaceholder;
|
|
1006
|
-
this.#placeholder= store.#placeholder;
|
|
1007
|
-
this.#selfMin= store.#selfMin;
|
|
1008
|
-
this.#min= store.#min;
|
|
1009
|
-
this.#selfMax= store.#selfMax;
|
|
1010
|
-
this.#max= store.#max;
|
|
1011
|
-
this.#selfStep= store.#selfStep;
|
|
1012
|
-
this.#step= store.#step;
|
|
1013
|
-
this.#selfMinLength= store.#selfMinLength;
|
|
1014
|
-
this.#minLength= store.#minLength;
|
|
1015
|
-
this.#selfMaxLength= store.#selfMaxLength;
|
|
1016
|
-
this.#maxLength= store.#maxLength;
|
|
1017
|
-
this.#selfPattern= store.#selfPattern;
|
|
1018
|
-
this.#pattern= store.#pattern;
|
|
1019
|
-
this.#selfValues= store.#selfValues;
|
|
1020
|
-
this.#values= store.#values;
|
|
1021
|
-
this.#errors= store.#errors;
|
|
1022
|
-
this.#
|
|
1023
|
-
this.#
|
|
1024
|
-
this.#
|
|
1025
|
-
this.#
|
|
1026
|
-
this.#
|
|
1027
|
-
this.#set= store.#set;
|
|
1028
|
-
this.#initValue= store.#initValue;
|
|
1029
|
-
this.#value= store.#value;
|
|
1029
|
+
this.#originStore = store;
|
|
1030
|
+
this.#schema = store.#schema;
|
|
1031
|
+
this.#null = store.#null;
|
|
1032
|
+
this.#ref = store.#ref;
|
|
1033
|
+
this.#states = store.#states;
|
|
1034
|
+
this.#layout = store.#layout;
|
|
1035
|
+
this.#createDefault = store.#createDefault;
|
|
1036
|
+
this.#setValue = store.#setValue;
|
|
1037
|
+
this.#convert = store.#convert;
|
|
1038
|
+
this.#onUpdate = store.#onUpdate;
|
|
1039
|
+
this.#parent = store.#parent;
|
|
1040
|
+
this.#root = store.#root;
|
|
1041
|
+
this.#type = store.#type;
|
|
1042
|
+
this.#meta = store.#meta;
|
|
1043
|
+
this.#component = store.#component;
|
|
1044
|
+
this.#selfLoading = store.#selfLoading;
|
|
1045
|
+
this.#loading = store.#loading;
|
|
1046
|
+
this.#size = store.#size;
|
|
1047
|
+
this.#index = store.#index;
|
|
1048
|
+
this.#creatable = store.#creatable;
|
|
1049
|
+
this.#immutable = store.#immutable;
|
|
1050
|
+
this.#new = store.#new;
|
|
1051
|
+
this.#selfNew = store.#selfNew;
|
|
1052
|
+
this.#selfHidden = store.#selfHidden;
|
|
1053
|
+
this.#hidden = store.#hidden;
|
|
1054
|
+
this.#selfClearable = store.#selfClearable;
|
|
1055
|
+
this.#clearable = store.#clearable;
|
|
1056
|
+
this.#selfRequired = store.#selfRequired;
|
|
1057
|
+
this.#required = store.#required;
|
|
1058
|
+
this.#selfDisabled = store.#selfDisabled;
|
|
1059
|
+
this.#disabled = store.#disabled;
|
|
1060
|
+
this.#selfReadonly = store.#selfReadonly;
|
|
1061
|
+
this.#readonly = store.#readonly;
|
|
1062
|
+
this.#selfRemovable = store.#selfRemovable;
|
|
1063
|
+
this.#removable = store.#removable;
|
|
1064
|
+
this.#selfLabel = store.#selfLabel;
|
|
1065
|
+
this.#label = store.#label;
|
|
1066
|
+
this.#selfDescription = store.#selfDescription;
|
|
1067
|
+
this.#description = store.#description;
|
|
1068
|
+
this.#selfPlaceholder = store.#selfPlaceholder;
|
|
1069
|
+
this.#placeholder = store.#placeholder;
|
|
1070
|
+
this.#selfMin = store.#selfMin;
|
|
1071
|
+
this.#min = store.#min;
|
|
1072
|
+
this.#selfMax = store.#selfMax;
|
|
1073
|
+
this.#max = store.#max;
|
|
1074
|
+
this.#selfStep = store.#selfStep;
|
|
1075
|
+
this.#step = store.#step;
|
|
1076
|
+
this.#selfMinLength = store.#selfMinLength;
|
|
1077
|
+
this.#minLength = store.#minLength;
|
|
1078
|
+
this.#selfMaxLength = store.#selfMaxLength;
|
|
1079
|
+
this.#maxLength = store.#maxLength;
|
|
1080
|
+
this.#selfPattern = store.#selfPattern;
|
|
1081
|
+
this.#pattern = store.#pattern;
|
|
1082
|
+
this.#selfValues = store.#selfValues;
|
|
1083
|
+
this.#values = store.#values;
|
|
1084
|
+
this.#errors = store.#errors;
|
|
1085
|
+
this.#execValidators = store.#execValidators;
|
|
1086
|
+
this.#cancelEventValidator = store.#cancelEventValidator;
|
|
1087
|
+
this.#set = store.#set;
|
|
1088
|
+
this.#initValue = store.#initValue;
|
|
1089
|
+
this.#value = store.#value;
|
|
1030
1090
|
const signal = options instanceof AbortSignal ? options : null;
|
|
1031
1091
|
if (signal?.aborted) { return; }
|
|
1032
|
-
const subBindStores= store.#subBindStores;
|
|
1092
|
+
const subBindStores = store.#subBindStores;
|
|
1033
1093
|
subBindStores.add(this);
|
|
1034
1094
|
signal?.addEventListener('abort', () => subBindStores.delete(this));
|
|
1035
1095
|
store.#requestUpdate();
|
|
@@ -1037,8 +1097,7 @@
|
|
|
1037
1097
|
}
|
|
1038
1098
|
const {
|
|
1039
1099
|
null: isNull, ref, default: defaultValue,
|
|
1040
|
-
setValue, convert, onUpdate, states,
|
|
1041
|
-
validator, validators,
|
|
1100
|
+
setValue, convert, onUpdate, states, validator,
|
|
1042
1101
|
index, size, new: isNew, parent: parentNode,
|
|
1043
1102
|
hidden, clearable, required, disabled, readonly, removable,
|
|
1044
1103
|
label, description, placeholder, min, max, step, minLength, maxLength, pattern, values: values$1
|
|
@@ -1113,9 +1172,6 @@
|
|
|
1113
1172
|
|
|
1114
1173
|
[this.#selfRemovable, this.#removable] = createBooleanStates(this, removable, schema.removable ?? true);
|
|
1115
1174
|
|
|
1116
|
-
const validatorResult = createValidator(this, schema.validator, validator);
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
1175
|
const schemaStates = schema.states;
|
|
1120
1176
|
this.#states = schemaStates ? Object.defineProperties(Object.create(null),
|
|
1121
1177
|
Object.fromEntries(
|
|
@@ -1131,16 +1187,13 @@
|
|
|
1131
1187
|
})
|
|
1132
1188
|
)) : null;
|
|
1133
1189
|
|
|
1134
|
-
const [
|
|
1135
|
-
const [
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
this.#errors =
|
|
1139
|
-
this.#
|
|
1140
|
-
this.#
|
|
1141
|
-
this.#blurred = blurred;
|
|
1142
|
-
this.#cancelChange = cancelChange;
|
|
1143
|
-
this.#cancelBlur = cancelBlur;
|
|
1190
|
+
const [execValidators, eventExecMap, errors, cancelEventValidator] = createValidator(this, schema.validator, validator);
|
|
1191
|
+
for (const [name, exec] of Object.entries(eventExecMap)) {
|
|
1192
|
+
this.listen(name, () => { exec(); });
|
|
1193
|
+
}
|
|
1194
|
+
this.#errors = errors;
|
|
1195
|
+
this.#execValidators = execValidators;
|
|
1196
|
+
this.#cancelEventValidator = cancelEventValidator;
|
|
1144
1197
|
|
|
1145
1198
|
if (size instanceof exports.Signal.State || size instanceof exports.Signal.Computed) {
|
|
1146
1199
|
this.#size = size;
|
|
@@ -1425,16 +1478,10 @@
|
|
|
1425
1478
|
|
|
1426
1479
|
/** @type {Signal.Computed<string[]>} */
|
|
1427
1480
|
#errors;
|
|
1428
|
-
/** @type {Signal.Computed<string[]>} */
|
|
1429
|
-
#validatorResult;
|
|
1430
1481
|
/** @type {() => Promise<string[]>} */
|
|
1431
|
-
#
|
|
1432
|
-
/** @type {() => Promise<string[]>} */
|
|
1433
|
-
#blurred;
|
|
1434
|
-
/** @type {() => void} */
|
|
1435
|
-
#cancelChange;
|
|
1482
|
+
#execValidators;
|
|
1436
1483
|
/** @type {() => void} */
|
|
1437
|
-
#
|
|
1484
|
+
#cancelEventValidator;
|
|
1438
1485
|
/** 所有校验错误列表 */
|
|
1439
1486
|
get errors() { return this.#errors.get(); }
|
|
1440
1487
|
/** 字段校验错误信息 */
|
|
@@ -1498,8 +1545,7 @@
|
|
|
1498
1545
|
this.#selfNew.set(isNew);
|
|
1499
1546
|
const newValue = this.#setValue?.(v);
|
|
1500
1547
|
const value = newValue === undefined ? v : newValue;
|
|
1501
|
-
this.#
|
|
1502
|
-
this.#cancelBlur();
|
|
1548
|
+
this.#cancelEventValidator();
|
|
1503
1549
|
this.#set = true;
|
|
1504
1550
|
if (!value || typeof value !== 'object') {
|
|
1505
1551
|
for (const bind of [this, ...this.#subBindStores]) {
|
|
@@ -1595,11 +1641,7 @@
|
|
|
1595
1641
|
validate(path) {
|
|
1596
1642
|
if (path === true) {
|
|
1597
1643
|
if (this.#originStore) { return Promise.resolve(null); }
|
|
1598
|
-
return
|
|
1599
|
-
.then(v => {
|
|
1600
|
-
const errors = v.flat();
|
|
1601
|
-
return errors.length ? errors : null;
|
|
1602
|
-
});
|
|
1644
|
+
return this.#execValidators().then(errors => errors.length ? errors : null);
|
|
1603
1645
|
}
|
|
1604
1646
|
const selfPath = Array.isArray(path) ? path : [];
|
|
1605
1647
|
if (!this.#originStore && this.#hidden.get()) { return Promise.resolve([]); }
|
|
@@ -1647,7 +1689,6 @@
|
|
|
1647
1689
|
* @property {RegExp} [pattern]
|
|
1648
1690
|
* @property {(Schema.Value.Group | Schema.Value | string | number)[]} [values] 可选值
|
|
1649
1691
|
* @property {Schema.Validator | Schema.Validator[] | null} [validator]
|
|
1650
|
-
* @property {{[k in keyof Schema.Events]?: Schema.AsyncValidator | Schema.AsyncValidator[] | null}} [validators]
|
|
1651
1692
|
*
|
|
1652
1693
|
* @property {Ref?} [ref]
|
|
1653
1694
|
*
|