@neeloong/form 0.12.1 → 0.14.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/README.md +12 -2
- package/index.d.mts +121 -7
- package/index.js +167 -43
- package/index.min.js +5 -5
- package/index.min.mjs +5 -5
- package/index.mjs +166 -44
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -175,6 +175,13 @@ render(store, layouts, app);
|
|
|
175
175
|
<li !enum="items" !text="$item"></li> <!-- items 是数组 -->
|
|
176
176
|
</ul>
|
|
177
177
|
```
|
|
178
|
+
#### 自定义排序
|
|
179
|
+
|
|
180
|
+
```html
|
|
181
|
+
<ul>
|
|
182
|
+
<li !enum="object" !sort="$key" !text="$item"></li> <!-- object 是对象,将按照其键排序,渲染其值 -->
|
|
183
|
+
</ul>
|
|
184
|
+
```
|
|
178
185
|
|
|
179
186
|
#### 嵌套循环
|
|
180
187
|
|
|
@@ -284,7 +291,7 @@ render(store, layouts, app);
|
|
|
284
291
|
1. 模板定义: `!template`
|
|
285
292
|
1. 条件: `!if` `!else`
|
|
286
293
|
1. 子属性: `!value`
|
|
287
|
-
1. 枚举: `!enum`
|
|
294
|
+
1. 枚举: `!enum` `!sort`
|
|
288
295
|
1. 别名、计算名与显式变量: `*别名` `*计算名` `+变量`
|
|
289
296
|
1. 片段与模板调用: `!fragment`
|
|
290
297
|
1. 属性与事件: `:绑定属性` `@事件` `普通属性` `!bind`
|
|
@@ -304,6 +311,7 @@ render(store, layouts, app);
|
|
|
304
311
|
- `$creatable` 只读 值是否可创建(`$new` 为 `true` 时,字段只读)
|
|
305
312
|
- `$immutable` 只读 值是否不可改变(`$new` 为 `false` 时,字段只读)
|
|
306
313
|
- `$new` 只读 是否新建项
|
|
314
|
+
- `$loading` 只读 加载状态
|
|
307
315
|
- `$readonly` 只读 是否只读
|
|
308
316
|
- `$hidden` 只读 是否可隐藏
|
|
309
317
|
- `$clearable` 只读 是否可清除
|
|
@@ -325,7 +333,9 @@ render(store, layouts, app);
|
|
|
325
333
|
- `$kind` 只读 字段类别
|
|
326
334
|
- `$error` 只读 字段校验错误信息
|
|
327
335
|
- `$errors` 只读 所有校验错误列表
|
|
328
|
-
|
|
336
|
+
- `$addable` 只读 是否可以为当前数组增加项目,非数组上下文总是为 `false`
|
|
337
|
+
- `$removable` 只读 是否可以将当前项从数组中移除,非数组成员上下文总是为 `false`
|
|
338
|
+
1. 字段扩展隐式函数(只在事件中可用)
|
|
329
339
|
- `$reset()` 重置数据
|
|
330
340
|
- `$validate()` 触发当前项的异步校验
|
|
331
341
|
- `$validate(true)` 触发当前项及其后代的异步校验
|
package/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @neeloong/form v0.
|
|
2
|
+
* @neeloong/form v0.14.0
|
|
3
3
|
* (c) 2024-2025 Fierflame
|
|
4
4
|
* @license Apache-2.0
|
|
5
5
|
*/
|
|
@@ -253,6 +253,7 @@ type Enum = {
|
|
|
253
253
|
templates?: Record<string, Template> | undefined;
|
|
254
254
|
type: "enum";
|
|
255
255
|
value: Node.Name | Node.Calc | Node.Value;
|
|
256
|
+
sort?: Node.Name | Node.Calc | Node.Value<any> | undefined;
|
|
256
257
|
/**
|
|
257
258
|
* 子元素
|
|
258
259
|
*/
|
|
@@ -653,6 +654,14 @@ declare namespace Schema {
|
|
|
653
654
|
* 模式规则
|
|
654
655
|
*/
|
|
655
656
|
pattern?: RegExp | ((store: Store) => RegExp | null) | null | undefined;
|
|
657
|
+
/**
|
|
658
|
+
* 数组内是否可添加
|
|
659
|
+
*/
|
|
660
|
+
addable?: boolean | ((store: Store) => boolean) | null | undefined;
|
|
661
|
+
/**
|
|
662
|
+
* 数组内是否可移除
|
|
663
|
+
*/
|
|
664
|
+
removable?: boolean | ((store: Store) => boolean) | null | undefined;
|
|
656
665
|
/**
|
|
657
666
|
* 可选值
|
|
658
667
|
*/
|
|
@@ -804,7 +813,7 @@ declare class Store<T = any, M = any> {
|
|
|
804
813
|
/**
|
|
805
814
|
* @param {Schema.Field<M>} schema 字段的 Schema 定义
|
|
806
815
|
* @param {object} [options] 可选配置
|
|
807
|
-
* @param {
|
|
816
|
+
* @param {Store?} [options.parent]
|
|
808
817
|
* @param {*} [options.state]
|
|
809
818
|
* @param {number | string | null} [options.index]
|
|
810
819
|
* @param {number | Signal.State<number> | Signal.Computed<number>} [options.size]
|
|
@@ -813,8 +822,9 @@ declare class Store<T = any, M = any> {
|
|
|
813
822
|
* @param {boolean} [options.hidden]
|
|
814
823
|
* @param {boolean} [options.clearable]
|
|
815
824
|
* @param {boolean} [options.required]
|
|
816
|
-
* @param {boolean} [options.readonly]
|
|
817
825
|
* @param {boolean} [options.disabled]
|
|
826
|
+
* @param {boolean} [options.readonly]
|
|
827
|
+
* @param {boolean} [options.removable]
|
|
818
828
|
*
|
|
819
829
|
* @param {string} [options.label] 字段标签
|
|
820
830
|
* @param {string} [options.description] 字段描述
|
|
@@ -838,8 +848,8 @@ declare class Store<T = any, M = any> {
|
|
|
838
848
|
* @param {((value: T?, index: any, store: Store) => void)?} [options.onUpdate]
|
|
839
849
|
* @param {((value: T?, index: any, store: Store) => void)?} [options.onUpdateState]
|
|
840
850
|
*/
|
|
841
|
-
constructor(schema: Schema.Field<M>, { null: isNull, state, ref, setValue, setState, convert, onUpdate, onUpdateState, validator, validators, index, size, new: isNew, parent: parentNode, hidden, clearable, required, disabled, readonly, label, description, placeholder, min, max, step, minLength, maxLength, pattern, values }?: {
|
|
842
|
-
parent?: any;
|
|
851
|
+
constructor(schema: Schema.Field<M>, { null: isNull, state, ref, setValue, setState, convert, onUpdate, onUpdateState, validator, validators, index, size, new: isNew, parent: parentNode, hidden, clearable, required, disabled, readonly, removable, label, description, placeholder, min, max, step, minLength, maxLength, pattern, values }?: {
|
|
852
|
+
parent?: Store<any, any> | null | undefined;
|
|
843
853
|
state?: any;
|
|
844
854
|
index?: string | number | null | undefined;
|
|
845
855
|
size?: number | Signal.State<number> | Signal.Computed<number> | undefined;
|
|
@@ -848,8 +858,9 @@ declare class Store<T = any, M = any> {
|
|
|
848
858
|
hidden?: boolean | undefined;
|
|
849
859
|
clearable?: boolean | undefined;
|
|
850
860
|
required?: boolean | undefined;
|
|
851
|
-
readonly?: boolean | undefined;
|
|
852
861
|
disabled?: boolean | undefined;
|
|
862
|
+
readonly?: boolean | undefined;
|
|
863
|
+
removable?: boolean | undefined;
|
|
853
864
|
label?: string | undefined;
|
|
854
865
|
description?: string | undefined;
|
|
855
866
|
placeholder?: string | undefined;
|
|
@@ -911,6 +922,8 @@ declare class Store<T = any, M = any> {
|
|
|
911
922
|
get kind(): string;
|
|
912
923
|
get ref(): Ref;
|
|
913
924
|
schema: Schema.Field<M>;
|
|
925
|
+
set loading(loading: boolean);
|
|
926
|
+
get loading(): boolean;
|
|
914
927
|
/** 存储对象自身 */
|
|
915
928
|
get store(): this;
|
|
916
929
|
/** 父级存储对象 */
|
|
@@ -964,6 +977,11 @@ declare class Store<T = any, M = any> {
|
|
|
964
977
|
set readonly(v: boolean);
|
|
965
978
|
/** 是否只读 */
|
|
966
979
|
get readonly(): boolean;
|
|
980
|
+
set selfRemovable(v: boolean | null);
|
|
981
|
+
get selfRemovable(): boolean | null;
|
|
982
|
+
set removable(v: boolean);
|
|
983
|
+
/** 是否只读 */
|
|
984
|
+
get removable(): boolean;
|
|
967
985
|
set selfLabel(v: string | null);
|
|
968
986
|
get selfLabel(): string | null;
|
|
969
987
|
set label(v: string | null);
|
|
@@ -1057,6 +1075,102 @@ declare class Store<T = any, M = any> {
|
|
|
1057
1075
|
#private;
|
|
1058
1076
|
}
|
|
1059
1077
|
|
|
1078
|
+
/** @import { Schema } from '../types.mjs' */
|
|
1079
|
+
/**
|
|
1080
|
+
* @template {Record<string, any>} [T=Record<string, any>]
|
|
1081
|
+
* @template [M=any]
|
|
1082
|
+
* @extends {Store<T, M>}
|
|
1083
|
+
*/
|
|
1084
|
+
declare class ObjectStore<T extends Record<string, any> = Record<string, any>, M = any> extends Store<T, M> {
|
|
1085
|
+
/**
|
|
1086
|
+
* @param {Schema.Object<M> & Schema.Attr<M>} schema
|
|
1087
|
+
* @param {object} [options]
|
|
1088
|
+
* @param {Store?} [options.parent]
|
|
1089
|
+
* @param {number | string | null} [options.index]
|
|
1090
|
+
* @param {boolean} [options.new]
|
|
1091
|
+
* @param {((value: T?, index: any, store: Store) => void)?} [options.onUpdate]
|
|
1092
|
+
* @param {((value: T?, index: any, store: Store) => void)?} [options.onUpdateState]
|
|
1093
|
+
*/
|
|
1094
|
+
constructor(schema: Schema.Object<M> & Schema.Attr<M>, { parent, index, new: isNew, onUpdate, onUpdateState }?: {
|
|
1095
|
+
parent?: Store<any, any> | null | undefined;
|
|
1096
|
+
index?: string | number | null | undefined;
|
|
1097
|
+
new?: boolean | undefined;
|
|
1098
|
+
onUpdate?: ((value: T | null, index: any, store: Store) => void) | null | undefined;
|
|
1099
|
+
onUpdateState?: ((value: T | null, index: any, store: Store) => void) | null | undefined;
|
|
1100
|
+
});
|
|
1101
|
+
[Symbol.iterator](): Generator<[string, Store<any, any>], void, unknown>;
|
|
1102
|
+
#private;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
/** @import { Schema } from '../types.mjs' */
|
|
1106
|
+
/**
|
|
1107
|
+
* @template [T=any]
|
|
1108
|
+
* @template [M=any]
|
|
1109
|
+
* @extends {Store<(T | null)[], M>}
|
|
1110
|
+
*/
|
|
1111
|
+
declare class ArrayStore<T = any, M = any> extends Store<(T | null)[], M> {
|
|
1112
|
+
/**
|
|
1113
|
+
* @param {Schema.Field<M>} schema
|
|
1114
|
+
* @param {object} [options]
|
|
1115
|
+
* @param {Store?} [options.parent]
|
|
1116
|
+
* @param {string | number | null} [options.index]
|
|
1117
|
+
* @param {boolean} [options.new]
|
|
1118
|
+
* @param {boolean} [options.addable]
|
|
1119
|
+
* @param {(value: any, index: any, store: Store) => void} [options.onUpdate]
|
|
1120
|
+
* @param {(value: any, index: any, store: Store) => void} [options.onUpdateState]
|
|
1121
|
+
*/
|
|
1122
|
+
constructor(schema: Schema.Field<M>, { parent, onUpdate, onUpdateState, index, new: isNew, addable }?: {
|
|
1123
|
+
parent?: Store<any, any> | null | undefined;
|
|
1124
|
+
index?: string | number | null | undefined;
|
|
1125
|
+
new?: boolean | undefined;
|
|
1126
|
+
addable?: boolean | undefined;
|
|
1127
|
+
onUpdate?: ((value: any, index: any, store: Store) => void) | undefined;
|
|
1128
|
+
onUpdateState?: ((value: any, index: any, store: Store) => void) | undefined;
|
|
1129
|
+
});
|
|
1130
|
+
get children(): Store<any, any>[];
|
|
1131
|
+
set selfAddable(v: boolean | null);
|
|
1132
|
+
get selfAddable(): boolean | null;
|
|
1133
|
+
set addable(v: boolean);
|
|
1134
|
+
/** 是否禁用字段 */
|
|
1135
|
+
get addable(): boolean;
|
|
1136
|
+
/**
|
|
1137
|
+
*
|
|
1138
|
+
* @param {number} index
|
|
1139
|
+
* @param {T?} [value]
|
|
1140
|
+
* @param {boolean} [isNew]
|
|
1141
|
+
* @returns
|
|
1142
|
+
*/
|
|
1143
|
+
insert(index: number, value?: T | null, isNew?: boolean): boolean;
|
|
1144
|
+
/**
|
|
1145
|
+
*
|
|
1146
|
+
* @param {T?} [value]
|
|
1147
|
+
* @returns
|
|
1148
|
+
*/
|
|
1149
|
+
add(value?: T | null): boolean;
|
|
1150
|
+
/**
|
|
1151
|
+
*
|
|
1152
|
+
* @param {number} index
|
|
1153
|
+
* @returns
|
|
1154
|
+
*/
|
|
1155
|
+
remove(index: number): T | null | undefined;
|
|
1156
|
+
/**
|
|
1157
|
+
*
|
|
1158
|
+
* @param {number} from
|
|
1159
|
+
* @param {number} to
|
|
1160
|
+
* @returns
|
|
1161
|
+
*/
|
|
1162
|
+
move(from: number, to: number): boolean;
|
|
1163
|
+
/**
|
|
1164
|
+
*
|
|
1165
|
+
* @param {number} a
|
|
1166
|
+
* @param {number} b
|
|
1167
|
+
* @returns
|
|
1168
|
+
*/
|
|
1169
|
+
exchange(a: number, b: number): boolean;
|
|
1170
|
+
[Symbol.iterator](): Generator<[number, Store<any, any>], undefined, unknown>;
|
|
1171
|
+
#private;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1060
1174
|
/**
|
|
1061
1175
|
* @param {Store} store 存储实例
|
|
1062
1176
|
* @param {Layout.Child[]} layouts 布局信息
|
|
@@ -1097,4 +1211,4 @@ declare function watch<T>(getter: () => T, callback: (value: T) => void, immedia
|
|
|
1097
1211
|
*/
|
|
1098
1212
|
declare function effect(fn: () => void): () => void;
|
|
1099
1213
|
|
|
1100
|
-
export { type AsyncValidator, Component, Enhancement, index_d as Layout, type Ref, type Relatedness, Schema, Store, type Validator, type VerifyError, effect, render, watch };
|
|
1214
|
+
export { ArrayStore, type AsyncValidator, Component, Enhancement, index_d as Layout, ObjectStore, type Ref, type Relatedness, Schema, Store, type Validator, type VerifyError, effect, render, watch };
|