@neeloong/form 0.28.0 → 0.29.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.full.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @neeloong/form v0.28.0
2
+ * @neeloong/form v0.29.0
3
3
  * (c) 2024-2026 Fierflame
4
4
  * @license Apache-2.0
5
5
  */
@@ -716,7 +716,7 @@
716
716
 
717
717
 
718
718
  /** @type {{new(...p: ConstructorParameters<typeof Store>): Store}?} */
719
- let ObjectStore$2 = null;
719
+ let ObjectStore$1 = null;
720
720
  /** @type {{new(...p: ConstructorParameters<typeof Store>): ArrayStore}?} */
721
721
  let ArrayStoreClass = null;
722
722
  /** @type {Record<string, {new(...p: ConstructorParameters<typeof Store>): Store}?>} */
@@ -741,14 +741,14 @@
741
741
  const C = TypeStores[type];
742
742
  if (C) { Class = C; }
743
743
  } else if (type && typeof type === 'object') {
744
- if (ObjectStore$2) { Class = ObjectStore$2; }
744
+ if (ObjectStore$1) { Class = ObjectStore$1; }
745
745
  }
746
746
  return new Class(schema, options);
747
747
  }
748
748
 
749
749
  /** @param {{new(...p: ConstructorParameters<typeof Store>): Store}} Class */
750
750
  function setObjectStore(Class) {
751
- ObjectStore$2 = Class;
751
+ ObjectStore$1 = Class;
752
752
  }
753
753
 
754
754
  /** @param {{new(...p: ConstructorParameters<typeof Store>): ArrayStore}} Class */
@@ -870,52 +870,6 @@
870
870
  return (value) => structuredClone(def(store, value));
871
871
  }
872
872
 
873
- /** @import { Schema } from '../Schema.types.mjs' */
874
-
875
- /**
876
- * @template [T=any]
877
- * @template [M=any]
878
- * @template {Object.<string, Schema.State>} [S=Object.<string, Schema.State>]
879
- * @extends {Store<T, M, S>}
880
- */
881
- class BindObjectStore extends Store {
882
-
883
- get kind() { return 'object'; }
884
- /** @type {Record<string, Store>} */
885
- #children = Object.create(null);
886
- *[Symbol.iterator]() { yield* Object.entries(this.#children); }
887
- /**
888
- *
889
- * @param {string | number} key
890
- * @returns {Store?}
891
- */
892
- child(key) { return this.#children[key] || null; }
893
- /**
894
- * @param {Schema<any, Object.<string, Schema.State>>} schema 数据结构模式
895
- * @param {Store<T, M, S>} store
896
- */
897
- constructor(schema, store) {
898
- super(store);
899
- const children = this.#children;
900
- for (const [index, field] of Object.entries(schema)) {
901
- const bindStore = create(field, {
902
- index, parent: this,
903
- /** @param {*} value @param {*} index @param {Store} store */
904
- onUpdate: (value, index, store) => {
905
- if (store !== children[index]) { return; }
906
- const val = this.value ?? null;
907
- if (typeof val !== 'object' || Array.isArray(val)) { return; }
908
- // @ts-ignore
909
- this.value = { ...val, [index]: value };
910
- },
911
- });
912
- children[index] = bindStore;
913
- }
914
- }
915
- }
916
- // @ts-ignore
917
- setObjectStore(ObjectStore);
918
-
919
873
  /** @import { Ref } from './ref.mjs' */
920
874
  /** @import { Schema } from '../Schema.types.mjs' */
921
875
  /** @import { StoreLayout } from '../StoreLayout.types.mjs' */
@@ -1004,116 +958,91 @@
1004
958
  get ref() { return this.#ref || createRef(this); }
1005
959
  /**
1006
960
  * @param {Schema.Field<M, S> | Store<T,M,S>} schema 字段的 Schema 定义
1007
- * @param {object} [options] 可选配置
1008
- * @param {Store?} [options.parent]
1009
- * @param {Partial<S>?} [options.states]
1010
- * @param {((store: Store, value?: any) => any) | object | number | string | boolean | null | undefined} [options.default]
1011
- * @param {number | string | null} [options.index]
1012
- * @param {number | Signal.State<number> | Signal.Computed<number>} [options.size]
1013
- * @param {boolean} [options.null]
1014
- * @param {boolean} [options.new]
1015
- * @param {boolean} [options.hidden]
1016
- * @param {boolean} [options.clearable]
1017
- * @param {boolean} [options.required]
1018
- * @param {boolean} [options.disabled]
1019
- * @param {boolean} [options.readonly]
1020
- * @param {boolean} [options.removable]
1021
- *
1022
- * @param {string} [options.label] 字段标签
1023
- * @param {string} [options.description] 字段描述
1024
- * @param {string} [options.placeholder] 占位符
1025
- * @param {number} [options.min] 日期、时间、数字的最小值
1026
- * @param {number} [options.max] 日期、时间、数字的最大值
1027
- * @param {number} [options.step] 日期、时间、数字的步长
1028
- * @param {number} [options.minLength]
1029
- * @param {number} [options.maxLength]
1030
- * @param {RegExp} [options.pattern]
1031
- * @param {(Schema.Value.Group | Schema.Value | string | number)[]} [options.values] 可选值
1032
- * @param {Schema.Validator | Schema.Validator[] | null} [options.validator]
1033
- * @param {{[k in keyof Schema.Events]?: Schema.AsyncValidator | Schema.AsyncValidator[] | null}} [options.validators]
1034
- *
1035
- * @param {Ref?} [options.ref]
1036
- *
1037
- * @param {((value: any) => any)?} [options.setValue]
1038
- * @param {((value: any) => any)?} [options.convert]
1039
- *
1040
- * @param {((value: T?, index: any, store: Store) => void)?} [options.onUpdate]
961
+ * @param {StoreOptions | AbortSignal | null} [options] 可选配置
1041
962
  */
1042
- constructor(schema, {
1043
- null: isNull, ref, default: defaultValue,
1044
- setValue, convert, onUpdate, states,
1045
- validator, validators,
1046
- index, size, new: isNew, parent: parentNode,
1047
- hidden, clearable, required, disabled, readonly, removable,
1048
- label, description, placeholder, min, max, step, minLength, maxLength, pattern, values: values$1
1049
- } = {}) {
963
+ constructor(schema, options) {
1050
964
  if (schema instanceof Store) {
1051
- this.#originStore = schema;
1052
- this.#schema = schema.#schema;
1053
- this.#null = schema.#null;
1054
- this.#ref = schema.#ref;
1055
- this.#states = schema.#states;
1056
- this.#layout = schema.#layout;
1057
- this.#createDefault = schema.#createDefault;
1058
- this.#setValue = schema.#setValue;
1059
- this.#convert = schema.#convert;
1060
- this.#onUpdate = schema.#onUpdate;
1061
- this.#parent = schema.#parent;
1062
- this.#root = schema.#root;
1063
- this.#type = schema.#type;
1064
- this.#meta = schema.#meta;
1065
- this.#component = schema.#component;
1066
- this.#selfLoading = schema.#selfLoading;
1067
- this.#loading = schema.#loading;
1068
- this.#size = schema.#size;
1069
- this.#index = schema.#index;
1070
- this.#creatable = schema.#creatable;
1071
- this.#immutable = schema.#immutable;
1072
- this.#new = schema.#new;
1073
- this.#selfNew = schema.#selfNew;
1074
- this.#selfHidden = schema.#selfHidden;
1075
- this.#hidden = schema.#hidden;
1076
- this.#selfClearable = schema.#selfClearable;
1077
- this.#clearable = schema.#clearable;
1078
- this.#selfRequired = schema.#selfRequired;
1079
- this.#required = schema.#required;
1080
- this.#selfDisabled = schema.#selfDisabled;
1081
- this.#disabled = schema.#disabled;
1082
- this.#selfReadonly = schema.#selfReadonly;
1083
- this.#readonly = schema.#readonly;
1084
- this.#selfRemovable = schema.#selfRemovable;
1085
- this.#removable = schema.#removable;
1086
- this.#selfLabel = schema.#selfLabel;
1087
- this.#label = schema.#label;
1088
- this.#selfDescription = schema.#selfDescription;
1089
- this.#description = schema.#description;
1090
- this.#selfPlaceholder = schema.#selfPlaceholder;
1091
- this.#placeholder = schema.#placeholder;
1092
- this.#selfMin = schema.#selfMin;
1093
- this.#min = schema.#min;
1094
- this.#selfMax = schema.#selfMax;
1095
- this.#max = schema.#max;
1096
- this.#selfStep = schema.#selfStep;
1097
- this.#step = schema.#step;
1098
- this.#selfMinLength = schema.#selfMinLength;
1099
- this.#minLength = schema.#minLength;
1100
- this.#selfMaxLength = schema.#selfMaxLength;
1101
- this.#maxLength = schema.#maxLength;
1102
- this.#selfPattern = schema.#selfPattern;
1103
- this.#pattern = schema.#pattern;
1104
- this.#selfValues = schema.#selfValues;
1105
- this.#values = schema.#values;
1106
- this.#errors = schema.#errors;
1107
- this.#validatorResult = schema.#validatorResult;
1108
- this.#changed = schema.#changed;
1109
- this.#blurred = schema.#blurred;
1110
- this.#cancelChange = schema.#cancelChange;
1111
- this.#cancelBlur = schema.#cancelBlur;
1112
- this.#set = schema.#set;
1113
- this.#initValue = schema.#initValue;
1114
- this.#value = schema.#value;
965
+ 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.#validatorResult= store.#validatorResult;
1023
+ this.#changed= store.#changed;
1024
+ this.#blurred= store.#blurred;
1025
+ this.#cancelChange= store.#cancelChange;
1026
+ this.#cancelBlur= store.#cancelBlur;
1027
+ this.#set= store.#set;
1028
+ this.#initValue= store.#initValue;
1029
+ this.#value= store.#value;
1030
+ const signal = options instanceof AbortSignal ? options : null;
1031
+ if (signal?.aborted) { return; }
1032
+ const subBindStores= store.#subBindStores;
1033
+ subBindStores.add(this);
1034
+ signal?.addEventListener('abort', () => subBindStores.delete(this));
1035
+ store.#requestUpdate();
1115
1036
  return;
1116
1037
  }
1038
+ const {
1039
+ null: isNull, ref, default: defaultValue,
1040
+ setValue, convert, onUpdate, states,
1041
+ validator, validators,
1042
+ index, size, new: isNew, parent: parentNode,
1043
+ hidden, clearable, required, disabled, readonly, removable,
1044
+ label, description, placeholder, min, max, step, minLength, maxLength, pattern, values: values$1
1045
+ } = !(options instanceof AbortSignal) && options || {};
1117
1046
  this.#schema = schema;
1118
1047
  const parent = parentNode instanceof Store ? parentNode : null;
1119
1048
  if (parent) {
@@ -1526,24 +1455,6 @@
1526
1455
 
1527
1456
  /** @type {Set<Store>} */
1528
1457
  #subBindStores = new Set();
1529
- /**
1530
- * @template [M=any]
1531
- * @template {Object.<string, Schema.State>} [S=Object.<string, Schema.State>]
1532
- * @param {Schema<M, S>} schema 数据结构模式
1533
- * @param {AbortSignal} [signal]
1534
- * @returns {BindObjectStore}
1535
- */
1536
- bindObject(schema, signal) {
1537
- const originStore = this.#originStore;
1538
- if (originStore) { return originStore.bindObject(schema, signal); }
1539
- const store = new BindObjectStore(schema, this);
1540
- if (signal?.aborted) { return store; }
1541
- const subBindStores = this.#subBindStores;
1542
- subBindStores.add(store);
1543
- signal?.addEventListener('abort', () => subBindStores.delete(store));
1544
- this.#requestUpdate();
1545
- return store;
1546
- }
1547
1458
 
1548
1459
  /** 内容是否已改变 */
1549
1460
  get changed() { return !Object.is(this.#value.get(), this.#initValue.get()); }
@@ -1640,7 +1551,7 @@
1640
1551
  // @ts-ignore
1641
1552
  let newValues = Array.isArray(val) ? [...val] : { ...val };
1642
1553
  let updated = false;
1643
- for (const bind of [this,...this.#subBindStores]) {
1554
+ for (const bind of [this, ...this.#subBindStores]) {
1644
1555
  for (const [key, field] of bind) {
1645
1556
  // @ts-ignore
1646
1557
  const data = Object.hasOwn(val, key) ? val[key] : undefined;
@@ -1706,6 +1617,46 @@
1706
1617
  }
1707
1618
  }
1708
1619
 
1620
+ /**
1621
+ * @template [T=any]
1622
+ * @template [M=any]
1623
+ * @template {Object.<string, Schema.State>} [S=Object.<string, Schema.State>]
1624
+ * @typedef {object} StoreOptions
1625
+ * @property {Store?} [parent]
1626
+ * @property {Partial<S>?} [states]
1627
+ * @property {((store: Store, value?: any) => any) | object | number | string | boolean | null | undefined} [default]
1628
+ * @property {number | string | null} [index]
1629
+ * @property {number | Signal.State<number> | Signal.Computed<number>} [size]
1630
+ * @property {boolean} [null]
1631
+ * @property {boolean} [new]
1632
+ * @property {boolean} [hidden]
1633
+ * @property {boolean} [clearable]
1634
+ * @property {boolean} [required]
1635
+ * @property {boolean} [disabled]
1636
+ * @property {boolean} [readonly]
1637
+ * @property {boolean} [removable]
1638
+ *
1639
+ * @property {string} [label] 字段标签
1640
+ * @property {string} [description] 字段描述
1641
+ * @property {string} [placeholder] 占位符
1642
+ * @property {number} [min] 日期、时间、数字的最小值
1643
+ * @property {number} [max] 日期、时间、数字的最大值
1644
+ * @property {number} [step] 日期、时间、数字的步长
1645
+ * @property {number} [minLength]
1646
+ * @property {number} [maxLength]
1647
+ * @property {RegExp} [pattern]
1648
+ * @property {(Schema.Value.Group | Schema.Value | string | number)[]} [values] 可选值
1649
+ * @property {Schema.Validator | Schema.Validator[] | null} [validator]
1650
+ * @property {{[k in keyof Schema.Events]?: Schema.AsyncValidator | Schema.AsyncValidator[] | null}} [validators]
1651
+ *
1652
+ * @property {Ref?} [ref]
1653
+ *
1654
+ * @property {((value: any) => any)?} [setValue]
1655
+ * @property {((value: any) => any)?} [convert]
1656
+ *
1657
+ * @property {((value: T?, index: any, store: Store) => void)?} [onUpdate]
1658
+ */
1659
+
1709
1660
  /** @import { Schema } from '../Schema.types.mjs' */
1710
1661
 
1711
1662
  /**
@@ -1714,7 +1665,7 @@
1714
1665
  * @template {Object.<string, Schema.State>} [S=Object.<string, Schema.State>]
1715
1666
  * @extends {Store<T, M, S>}
1716
1667
  */
1717
- let ObjectStore$1 = class ObjectStore extends Store {
1668
+ class ObjectStore extends Store {
1718
1669
  get kind() { return 'object'; }
1719
1670
  /** @type {Record<string, Store>} */
1720
1671
  #children;
@@ -1767,9 +1718,9 @@
1767
1718
  }
1768
1719
  this.#children = children;
1769
1720
  }
1770
- };
1721
+ }
1771
1722
  // @ts-ignore
1772
- setObjectStore(ObjectStore$1);
1723
+ setObjectStore(ObjectStore);
1773
1724
 
1774
1725
  /** @import { Schema } from '../Schema.types.mjs' */
1775
1726
 
@@ -2011,6 +1962,51 @@
2011
1962
  // @ts-ignore
2012
1963
  setArrayStore(ArrayStore);
2013
1964
 
1965
+ /** @import { Schema } from '../Schema.types.mjs' */
1966
+
1967
+ /**
1968
+ * @template [T=any]
1969
+ * @template [M=any]
1970
+ * @template {Object.<string, Schema.State>} [S=Object.<string, Schema.State>]
1971
+ * @extends {Store<T, M, S>}
1972
+ */
1973
+ class BindObjectStore extends Store {
1974
+
1975
+ get kind() { return 'object'; }
1976
+ /** @type {Record<string, Store>} */
1977
+ #children = Object.create(null);
1978
+ *[Symbol.iterator]() { yield* Object.entries(this.#children); }
1979
+ /**
1980
+ *
1981
+ * @param {string | number} key
1982
+ * @returns {Store?}
1983
+ */
1984
+ child(key) { return this.#children[key] || null; }
1985
+ /**
1986
+ * @param {Schema<any, Object.<string, Schema.State>>} schema 数据结构模式
1987
+ * @param {Store<T, M, S>} store
1988
+ * @param {AbortSignal} [signal]
1989
+ */
1990
+ constructor(schema, store, signal) {
1991
+ super(store, signal);
1992
+ const children = this.#children;
1993
+ for (const [index, field] of Object.entries(schema)) {
1994
+ const bindStore = create(field, {
1995
+ index, parent: this,
1996
+ /** @param {*} value @param {*} index @param {Store} store */
1997
+ onUpdate: (value, index, store) => {
1998
+ if (store !== children[index]) { return; }
1999
+ const val = this.value ?? null;
2000
+ if (typeof val !== 'object' || Array.isArray(val)) { return; }
2001
+ // @ts-ignore
2002
+ this.value = { ...val, [index]: value };
2003
+ },
2004
+ });
2005
+ children[index] = bindStore;
2006
+ }
2007
+ }
2008
+ }
2009
+
2014
2010
  /** @import * as Layout from './index.mjs' */
2015
2011
 
2016
2012
  /** @import { OldNode } from './createElement.mjs' */
@@ -5439,7 +5435,7 @@
5439
5435
  if (list instanceof ArrayStore) {
5440
5436
  return renderArray(parent, next, list, env, r, layout.sort);
5441
5437
  }
5442
- if (list instanceof ObjectStore$1) {
5438
+ if (list instanceof ObjectStore) {
5443
5439
  return renderObject(parent, next, list, env, r, layout.sort);
5444
5440
  }
5445
5441
  if (typeof list === 'function') {
@@ -7172,8 +7168,9 @@
7172
7168
  }
7173
7169
 
7174
7170
  exports.ArrayStore = ArrayStore;
7171
+ exports.BindObjectStore = BindObjectStore;
7175
7172
  exports.Layout = index;
7176
- exports.ObjectStore = ObjectStore$1;
7173
+ exports.ObjectStore = ObjectStore;
7177
7174
  exports.Store = Store;
7178
7175
  exports.effect = effect;
7179
7176
  exports.render = render;