@neeloong/form 0.10.0 → 0.12.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 +15 -13
- package/index.d.mts +228 -82
- package/index.js +546 -423
- package/index.min.js +6 -6
- package/index.min.mjs +6 -6
- package/index.mjs +545 -422
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ const template = `
|
|
|
14
14
|
<li !value="list" !enum>
|
|
15
15
|
<input !bind="b" />
|
|
16
16
|
<ul !value="c" +x="0">
|
|
17
|
-
<li !enum +b=alias$
|
|
17
|
+
<li !enum +b=alias$size +a=2 +k="++x">
|
|
18
18
|
<div !fragment !text="k"></div>
|
|
19
19
|
<button @click="a+=1">a+1:<span !fragment !text="a"></span></button>
|
|
20
20
|
<button @click="b+=1">b+1:<span !fragment !text="b"></span></button>
|
|
@@ -24,7 +24,7 @@ const template = `
|
|
|
24
24
|
<button @click="$upMove" :disabled="!$upMovable">上移</button>
|
|
25
25
|
<button @click="$downMove()" :disabled="!$downMovable">下移</button>
|
|
26
26
|
</li>
|
|
27
|
-
<li><button @click="$add(0)">添加</button><button @click="$add( - $
|
|
27
|
+
<li><button @click="$add(0)">添加</button><button @click="$add( - $size - 1)">添加(<span !fragment !text=" - $size - 1"></span>)</button></li>
|
|
28
28
|
</ul>
|
|
29
29
|
</li>
|
|
30
30
|
</ul>
|
|
@@ -127,7 +127,7 @@ render(store, layouts, app);
|
|
|
127
127
|
- **别名(`*alias`)**:
|
|
128
128
|
为复杂表达式或字段设置别名,简化引用。
|
|
129
129
|
```html
|
|
130
|
-
<div *len="array$
|
|
130
|
+
<div *len="array$size" !text="len"></div> <!-- 别名 len 指向当前数组长度 -->
|
|
131
131
|
```
|
|
132
132
|
|
|
133
133
|
- **计算值(`*computed`)**:
|
|
@@ -144,8 +144,7 @@ render(store, layouts, app);
|
|
|
144
144
|
|
|
145
145
|
#### **2.2 变量优先级**
|
|
146
146
|
变量优先级从高到低:
|
|
147
|
-
1. **显式变量(`+var`)**
|
|
148
|
-
2. **别名(`*alias`)**
|
|
147
|
+
1. **显式变量(`+var`)与别名(`*alias`)**
|
|
149
148
|
3. **计算值(`*computed`)**
|
|
150
149
|
4. **字段变量(`field$value`)**
|
|
151
150
|
5. **全局变量(通过 `render` 的 `global` 参数传入)**
|
|
@@ -180,9 +179,9 @@ render(store, layouts, app);
|
|
|
180
179
|
#### 嵌套循环
|
|
181
180
|
|
|
182
181
|
```html
|
|
183
|
-
<div !enum="outerArray" *outerLen="$
|
|
182
|
+
<div !enum="outerArray" *outerLen="$size">
|
|
184
183
|
<div !enum="innerArray">
|
|
185
|
-
<span !text="outerLen + ' + ' + $
|
|
184
|
+
<span !text="outerLen + ' + ' + $size"></span> <!-- 外层长度 + 内层长度 -->
|
|
186
185
|
</div>
|
|
187
186
|
</div>
|
|
188
187
|
```
|
|
@@ -286,8 +285,7 @@ render(store, layouts, app);
|
|
|
286
285
|
1. 条件: `!if` `!else`
|
|
287
286
|
1. 子属性: `!value`
|
|
288
287
|
1. 枚举: `!enum`
|
|
289
|
-
1.
|
|
290
|
-
1. 显式变量: `+变量`
|
|
288
|
+
1. 别名、计算名与显式变量: `*别名` `*计算名` `+变量`
|
|
291
289
|
1. 片段与模板调用: `!fragment`
|
|
292
290
|
1. 属性与事件: `:绑定属性` `@事件` `普通属性` `!bind`
|
|
293
291
|
1. 子内容: `!text` `!html`
|
|
@@ -302,7 +300,7 @@ render(store, layouts, app);
|
|
|
302
300
|
- `$null` 只读 是否为空元素
|
|
303
301
|
- `$index` 只读 当前项的索引
|
|
304
302
|
- `$no` 只读 数组项目的序号
|
|
305
|
-
- `$
|
|
303
|
+
- `$size` 只读 数组的长度、对象的成员数
|
|
306
304
|
- `$creatable` 只读 值是否可创建(`$new` 为 `true` 时,字段只读)
|
|
307
305
|
- `$immutable` 只读 值是否不可改变(`$new` 为 `false` 时,字段只读)
|
|
308
306
|
- `$new` 只读 是否新建项
|
|
@@ -345,8 +343,13 @@ render(store, layouts, app);
|
|
|
345
343
|
- `$upMove()` 上移当前项
|
|
346
344
|
- `$downMove()` 下移当前项
|
|
347
345
|
1. 上下文隐式变量
|
|
348
|
-
-
|
|
349
|
-
-
|
|
346
|
+
- `$store` 只读 当前表单存储实例。
|
|
347
|
+
- `$root` 只读 根上下文对象。
|
|
348
|
+
1. `enum` 上下文新增的变量
|
|
349
|
+
- `$$count` 枚举上下文的数量
|
|
350
|
+
- `$$key` 枚举上下文的当前项的键
|
|
351
|
+
- `$$index` 枚举上下文当前项的索引
|
|
352
|
+
- `$$item` 枚举上下文当前项
|
|
350
353
|
1. 当前范围及组件范围的所有字段(数组字段的成员除外,因为数组字段成员索引为数字,不符合标识符命名规则)都存在 `field$value` 及 `field$$value` 形式的变量
|
|
351
354
|
1. 如果别名为字段的别名(如 `*alias="v"`),则也存在 `alias$value` 形式的变量
|
|
352
355
|
1. 当存在同名变量时,则会按照变量来源类型决定优先级,从高到低依次为:
|
|
@@ -355,7 +358,6 @@ render(store, layouts, app);
|
|
|
355
358
|
1. 全局变量,此部分由 `render` 的参数传入
|
|
356
359
|
1. 字段声明,包括 `field$value` 及 `field$$value` 形式的变量
|
|
357
360
|
1. 在同一来源类型重复的变量名,再按照作用域处理
|
|
358
|
-
1. 同一作用域下的别名(或计算名)与显式变量重名时,由于会先处理别名,所以,显式变量会覆盖别名。
|
|
359
361
|
|
|
360
362
|
### 示例代码
|
|
361
363
|
|
package/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @neeloong/form v0.
|
|
2
|
+
* @neeloong/form v0.12.0
|
|
3
3
|
* (c) 2024-2025 Fierflame
|
|
4
4
|
* @license Apache-2.0
|
|
5
5
|
*/
|
|
@@ -11,17 +11,9 @@ export { Signal } from 'signal-polyfill';
|
|
|
11
11
|
* 解析模板内容
|
|
12
12
|
* @param {string} source 输入源字符串
|
|
13
13
|
* @param {Layout.Options} [options] 解析选项
|
|
14
|
-
* @returns {
|
|
14
|
+
* @returns {Layout.Child[]}
|
|
15
15
|
*/
|
|
16
|
-
declare function parse(source: string, { createCalc, createInit, createEvent, simpleTag, enableHTML, }?: Options):
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 将模板转为字符串
|
|
20
|
-
* @param {Layout.Node | (Layout.Node |string)[]} value 要转换的节点或节点数组
|
|
21
|
-
* @param {boolean} [formable] 是否对代码进行格式化
|
|
22
|
-
* @returns {string}
|
|
23
|
-
*/
|
|
24
|
-
declare function stringify(value: Node | (Node | string)[], formable?: boolean): string;
|
|
16
|
+
declare function parse(source: string, { createCalc, createInit, createEvent, simpleTag, enableHTML, }?: Options): Child[];
|
|
25
17
|
|
|
26
18
|
/**
|
|
27
19
|
* 增强信息
|
|
@@ -73,6 +65,12 @@ type Options = {
|
|
|
73
65
|
* 布局节点
|
|
74
66
|
*/
|
|
75
67
|
type Node = {
|
|
68
|
+
/**
|
|
69
|
+
* 局部变量/别名/计算名
|
|
70
|
+
*/
|
|
71
|
+
vars?: Variable<unknown>[] | null | undefined;
|
|
72
|
+
templates?: Record<string, Template> | undefined;
|
|
73
|
+
type?: null | undefined;
|
|
76
74
|
/**
|
|
77
75
|
* 标签名
|
|
78
76
|
*/
|
|
@@ -83,10 +81,6 @@ type Node = {
|
|
|
83
81
|
* 属性
|
|
84
82
|
*/
|
|
85
83
|
attrs: Record<string, Node.Name | Node.Calc | Node.Value>;
|
|
86
|
-
/**
|
|
87
|
-
* 模板参数定义
|
|
88
|
-
*/
|
|
89
|
-
params: Record<string, Node.Name | Node.Calc | Node.Value>;
|
|
90
84
|
/**
|
|
91
85
|
* 类名
|
|
92
86
|
*/
|
|
@@ -99,54 +93,14 @@ type Node = {
|
|
|
99
93
|
* 事件
|
|
100
94
|
*/
|
|
101
95
|
events: Record<string, Node.Name | Node.Event>;
|
|
102
|
-
/**
|
|
103
|
-
* 局部变量
|
|
104
|
-
*/
|
|
105
|
-
vars: Record<string, Node.Name | Node.Calc | Node.Value>;
|
|
106
|
-
/**
|
|
107
|
-
* 别名/计算名
|
|
108
|
-
*/
|
|
109
|
-
aliases: Record<string, Node.Name | Node.Calc | Node.Value>;
|
|
110
96
|
/**
|
|
111
97
|
* 增强
|
|
112
98
|
*/
|
|
113
99
|
enhancements: Record<string, Enhancement$1>;
|
|
114
|
-
/**
|
|
115
|
-
* 模板定义的名称
|
|
116
|
-
*/
|
|
117
|
-
template?: string | undefined;
|
|
118
|
-
/**
|
|
119
|
-
* 是否为片段或模板调用
|
|
120
|
-
*/
|
|
121
|
-
fragment?: string | boolean | undefined;
|
|
122
|
-
/**
|
|
123
|
-
* 分歧条件
|
|
124
|
-
*/
|
|
125
|
-
if?: Node.Name | Node.Calc | Node.Value<any> | undefined;
|
|
126
|
-
/**
|
|
127
|
-
* 否定
|
|
128
|
-
*/
|
|
129
|
-
else?: boolean | undefined;
|
|
130
|
-
/**
|
|
131
|
-
* 值关联
|
|
132
|
-
*/
|
|
133
|
-
value?: string | undefined;
|
|
134
|
-
/**
|
|
135
|
-
* 列表属性枚举
|
|
136
|
-
*/
|
|
137
|
-
enum?: Node.Name | Node.Calc | Node.Value<any> | undefined;
|
|
138
100
|
/**
|
|
139
101
|
* 绑定内容
|
|
140
102
|
*/
|
|
141
103
|
bind?: string | boolean | undefined;
|
|
142
|
-
/**
|
|
143
|
-
* 文本渲染
|
|
144
|
-
*/
|
|
145
|
-
text?: Node.Name | Node.Calc | Node.Value<any> | undefined;
|
|
146
|
-
/**
|
|
147
|
-
* HTML 渲染
|
|
148
|
-
*/
|
|
149
|
-
html?: Node.Name | Node.Calc | Node.Value<any> | undefined;
|
|
150
104
|
/**
|
|
151
105
|
* 注释
|
|
152
106
|
*/
|
|
@@ -154,7 +108,7 @@ type Node = {
|
|
|
154
108
|
/**
|
|
155
109
|
* 子元素
|
|
156
110
|
*/
|
|
157
|
-
children:
|
|
111
|
+
children: Child[];
|
|
158
112
|
};
|
|
159
113
|
declare namespace Node {
|
|
160
114
|
/**
|
|
@@ -194,6 +148,187 @@ declare namespace Node {
|
|
|
194
148
|
event?: undefined;
|
|
195
149
|
};
|
|
196
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* 分歧
|
|
153
|
+
*/
|
|
154
|
+
type Child = Divergent | Select | Enum | Content | CallTemplate | Fragment | Node | string;
|
|
155
|
+
/**
|
|
156
|
+
* 变量定义
|
|
157
|
+
*/
|
|
158
|
+
type Variable<T = unknown> = {
|
|
159
|
+
variable: string;
|
|
160
|
+
name?: string | undefined;
|
|
161
|
+
calc?: Calc | undefined;
|
|
162
|
+
value?: T | undefined;
|
|
163
|
+
/**
|
|
164
|
+
* 是否普通变量
|
|
165
|
+
*/
|
|
166
|
+
init?: boolean | undefined;
|
|
167
|
+
/**
|
|
168
|
+
* 注释
|
|
169
|
+
*/
|
|
170
|
+
comment?: string | undefined;
|
|
171
|
+
};
|
|
172
|
+
type Template = {
|
|
173
|
+
/**
|
|
174
|
+
* 局部变量/别名/计算名
|
|
175
|
+
*/
|
|
176
|
+
vars?: Variable<unknown>[] | null | undefined;
|
|
177
|
+
templates?: Record<string, Template> | undefined;
|
|
178
|
+
/**
|
|
179
|
+
* 模板参数定义
|
|
180
|
+
*/
|
|
181
|
+
params: Record<string, Node.Name | Node.Calc | Node.Value>;
|
|
182
|
+
/**
|
|
183
|
+
* 子元素
|
|
184
|
+
*/
|
|
185
|
+
children: Child[];
|
|
186
|
+
/**
|
|
187
|
+
* 注释
|
|
188
|
+
*/
|
|
189
|
+
comment?: string | undefined;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* 分歧项
|
|
193
|
+
*/
|
|
194
|
+
type DivergentChildren = {
|
|
195
|
+
/**
|
|
196
|
+
* 局部变量/别名/计算名
|
|
197
|
+
*/
|
|
198
|
+
vars?: Variable<unknown>[] | null | undefined;
|
|
199
|
+
templates?: Record<string, Template> | undefined;
|
|
200
|
+
/**
|
|
201
|
+
* 子元素
|
|
202
|
+
*/
|
|
203
|
+
children: Child[];
|
|
204
|
+
/**
|
|
205
|
+
* 注释
|
|
206
|
+
*/
|
|
207
|
+
comment?: string | undefined;
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* 分歧
|
|
211
|
+
*/
|
|
212
|
+
type Divergent = {
|
|
213
|
+
/**
|
|
214
|
+
* 局部变量/别名/计算名
|
|
215
|
+
*/
|
|
216
|
+
vars?: Variable<unknown>[] | null | undefined;
|
|
217
|
+
templates?: Record<string, Template> | undefined;
|
|
218
|
+
type: "divergent";
|
|
219
|
+
children: [children: DivergentChildren, condition?: Node.Name | Node.Calc | Node.Value | null][];
|
|
220
|
+
/**
|
|
221
|
+
* 注释
|
|
222
|
+
*/
|
|
223
|
+
comment?: string | undefined;
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* 选值
|
|
227
|
+
*/
|
|
228
|
+
type Select = {
|
|
229
|
+
/**
|
|
230
|
+
* 局部变量/别名/计算名
|
|
231
|
+
*/
|
|
232
|
+
vars?: Variable<unknown>[] | null | undefined;
|
|
233
|
+
templates?: Record<string, Template> | undefined;
|
|
234
|
+
type: "value";
|
|
235
|
+
name: string;
|
|
236
|
+
/**
|
|
237
|
+
* 子元素
|
|
238
|
+
*/
|
|
239
|
+
children: Child[];
|
|
240
|
+
/**
|
|
241
|
+
* 注释
|
|
242
|
+
*/
|
|
243
|
+
comment?: string | undefined;
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* 枚举
|
|
247
|
+
*/
|
|
248
|
+
type Enum = {
|
|
249
|
+
/**
|
|
250
|
+
* 局部变量/别名/计算名
|
|
251
|
+
*/
|
|
252
|
+
vars?: Variable<unknown>[] | null | undefined;
|
|
253
|
+
templates?: Record<string, Template> | undefined;
|
|
254
|
+
type: "enum";
|
|
255
|
+
value: Node.Name | Node.Calc | Node.Value;
|
|
256
|
+
/**
|
|
257
|
+
* 子元素
|
|
258
|
+
*/
|
|
259
|
+
children: Child[];
|
|
260
|
+
/**
|
|
261
|
+
* 注释
|
|
262
|
+
*/
|
|
263
|
+
comment?: string | undefined;
|
|
264
|
+
};
|
|
265
|
+
/**
|
|
266
|
+
* 内容填充
|
|
267
|
+
*/
|
|
268
|
+
type Content = {
|
|
269
|
+
/**
|
|
270
|
+
* 局部变量/别名/计算名
|
|
271
|
+
*/
|
|
272
|
+
vars?: Variable<unknown>[] | null | undefined;
|
|
273
|
+
templates?: Record<string, Template> | undefined;
|
|
274
|
+
type: "content";
|
|
275
|
+
value: Node.Name | Node.Calc | Node.Value;
|
|
276
|
+
html?: boolean | undefined;
|
|
277
|
+
/**
|
|
278
|
+
* 注释
|
|
279
|
+
*/
|
|
280
|
+
comment?: string | undefined;
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
283
|
+
* 模板调用
|
|
284
|
+
*/
|
|
285
|
+
type CallTemplate = {
|
|
286
|
+
/**
|
|
287
|
+
* 局部变量/别名/计算名
|
|
288
|
+
*/
|
|
289
|
+
vars?: Variable<unknown>[] | null | undefined;
|
|
290
|
+
templates?: Record<string, Template> | undefined;
|
|
291
|
+
type: "template";
|
|
292
|
+
/**
|
|
293
|
+
* 模板名
|
|
294
|
+
*/
|
|
295
|
+
template: string;
|
|
296
|
+
/**
|
|
297
|
+
* 属性
|
|
298
|
+
*/
|
|
299
|
+
attrs: Record<string, Node.Name | Node.Calc | Node.Value>;
|
|
300
|
+
/**
|
|
301
|
+
* 绑定内容
|
|
302
|
+
*/
|
|
303
|
+
bind?: string | boolean | undefined;
|
|
304
|
+
/**
|
|
305
|
+
* 子元素
|
|
306
|
+
*/
|
|
307
|
+
children: Child[];
|
|
308
|
+
/**
|
|
309
|
+
* 注释
|
|
310
|
+
*/
|
|
311
|
+
comment?: string | undefined;
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
* 片段
|
|
315
|
+
*/
|
|
316
|
+
type Fragment = {
|
|
317
|
+
/**
|
|
318
|
+
* 局部变量/别名/计算名
|
|
319
|
+
*/
|
|
320
|
+
vars?: Variable<unknown>[] | null | undefined;
|
|
321
|
+
templates?: Record<string, Template> | undefined;
|
|
322
|
+
type: "fragment";
|
|
323
|
+
/**
|
|
324
|
+
* 子元素
|
|
325
|
+
*/
|
|
326
|
+
children: Child[];
|
|
327
|
+
/**
|
|
328
|
+
* 注释
|
|
329
|
+
*/
|
|
330
|
+
comment?: string | undefined;
|
|
331
|
+
};
|
|
197
332
|
/**
|
|
198
333
|
* 计算函数
|
|
199
334
|
*/
|
|
@@ -204,13 +339,22 @@ type Calc = (env: Record<string, any>) => any;
|
|
|
204
339
|
type EventListener = ($event: any, env: Record<string, any>) => void;
|
|
205
340
|
|
|
206
341
|
type index_d_Calc = Calc;
|
|
342
|
+
type index_d_CallTemplate = CallTemplate;
|
|
343
|
+
type index_d_Child = Child;
|
|
344
|
+
type index_d_Content = Content;
|
|
345
|
+
type index_d_Divergent = Divergent;
|
|
346
|
+
type index_d_DivergentChildren = DivergentChildren;
|
|
347
|
+
type index_d_Enum = Enum;
|
|
207
348
|
type index_d_EventListener = EventListener;
|
|
349
|
+
type index_d_Fragment = Fragment;
|
|
208
350
|
declare const index_d_Node: typeof Node;
|
|
209
351
|
type index_d_Options = Options;
|
|
352
|
+
type index_d_Select = Select;
|
|
353
|
+
type index_d_Template = Template;
|
|
354
|
+
type index_d_Variable<T = unknown> = Variable<T>;
|
|
210
355
|
declare const index_d_parse: typeof parse;
|
|
211
|
-
declare const index_d_stringify: typeof stringify;
|
|
212
356
|
declare namespace index_d {
|
|
213
|
-
export { type index_d_Calc as Calc, type Enhancement$1 as Enhancement, type index_d_EventListener as EventListener, index_d_Node as Node, type index_d_Options as Options,
|
|
357
|
+
export { type index_d_Calc as Calc, type index_d_CallTemplate as CallTemplate, type index_d_Child as Child, type index_d_Content as Content, type index_d_Divergent as Divergent, type index_d_DivergentChildren as DivergentChildren, type Enhancement$1 as Enhancement, type index_d_Enum as Enum, type index_d_EventListener as EventListener, type index_d_Fragment as Fragment, index_d_Node as Node, type index_d_Options as Options, type index_d_Select as Select, type index_d_Template as Template, type index_d_Variable as Variable, index_d_parse as parse };
|
|
214
358
|
}
|
|
215
359
|
|
|
216
360
|
type VerifyError = any;
|
|
@@ -324,12 +468,12 @@ declare namespace Component {
|
|
|
324
468
|
*/
|
|
325
469
|
type Getter = (path: string[], next?: ((path: string[]) => Component | null) | undefined) => Component | null;
|
|
326
470
|
}
|
|
327
|
-
type Schema = Record<string, Schema.Field
|
|
471
|
+
type Schema<M = any> = Record<string, Schema.Field<M>>;
|
|
328
472
|
declare namespace Schema {
|
|
329
473
|
/**
|
|
330
474
|
* 字段定义
|
|
331
475
|
*/
|
|
332
|
-
type Field = (Schema.Object | Schema.Type) & Schema.Attr
|
|
476
|
+
type Field<M_1 = any> = (Schema.Object<M_1> | Schema.Type) & Schema.Attr<M_1>;
|
|
333
477
|
/**
|
|
334
478
|
* 可选值
|
|
335
479
|
*/
|
|
@@ -388,11 +532,11 @@ declare namespace Schema {
|
|
|
388
532
|
/**
|
|
389
533
|
* 对象类型定义
|
|
390
534
|
*/
|
|
391
|
-
type Object = {
|
|
535
|
+
type Object<M_1 = any> = {
|
|
392
536
|
/**
|
|
393
537
|
* 字段定义
|
|
394
538
|
*/
|
|
395
|
-
type: Record<string, Schema.Field
|
|
539
|
+
type: Record<string, Schema.Field<M_1>>;
|
|
396
540
|
/**
|
|
397
541
|
* 是否为数组
|
|
398
542
|
*/
|
|
@@ -436,11 +580,11 @@ declare namespace Schema {
|
|
|
436
580
|
*/
|
|
437
581
|
blur: Event;
|
|
438
582
|
};
|
|
439
|
-
type Attr = {
|
|
583
|
+
type Attr<M_1 = any> = {
|
|
440
584
|
/**
|
|
441
585
|
* 元信息
|
|
442
586
|
*/
|
|
443
|
-
meta?:
|
|
587
|
+
meta?: M_1 | undefined;
|
|
444
588
|
/**
|
|
445
589
|
* 自定义组件
|
|
446
590
|
*/
|
|
@@ -512,7 +656,7 @@ declare namespace Schema {
|
|
|
512
656
|
/**
|
|
513
657
|
* 可选值
|
|
514
658
|
*/
|
|
515
|
-
values?: (Schema.Value.Define | Schema.Value.Group.Define)[] | undefined;
|
|
659
|
+
values?: (Schema.Value.Define | Schema.Value.Group.Define)[] | ((store: Store) => (Schema.Value.Group.Define | Schema.Value.Define)[]) | undefined;
|
|
516
660
|
/**
|
|
517
661
|
* 监听函数
|
|
518
662
|
*/
|
|
@@ -636,17 +780,19 @@ type Ref = {
|
|
|
636
780
|
/**
|
|
637
781
|
* 管理单个表单字段的状态和行为
|
|
638
782
|
* @template [T=any]
|
|
783
|
+
* @template [M=any]
|
|
639
784
|
*/
|
|
640
|
-
declare class Store<T = any> {
|
|
785
|
+
declare class Store<T = any, M = any> {
|
|
641
786
|
/**
|
|
642
787
|
* 从数据结构模式创建存储
|
|
643
|
-
* @
|
|
788
|
+
* @template [M=any]
|
|
789
|
+
* @param {Schema<M>} schema 数据结构模式
|
|
644
790
|
* @param {object} [options] 选项
|
|
645
791
|
* @param {boolean} [options.new] 是否为新建环境
|
|
646
792
|
*/
|
|
647
|
-
static create(schema: Schema
|
|
793
|
+
static create<M_1 = any>(schema: Schema<M_1>, options?: {
|
|
648
794
|
new?: boolean | undefined;
|
|
649
|
-
}): Store<any>;
|
|
795
|
+
}): Store<any, any>;
|
|
650
796
|
/**
|
|
651
797
|
* 设置自定义类型的存储类
|
|
652
798
|
* @param {string} type
|
|
@@ -656,12 +802,12 @@ declare class Store<T = any> {
|
|
|
656
802
|
new (...p: ConstructorParameters<typeof Store>): Store;
|
|
657
803
|
}): void;
|
|
658
804
|
/**
|
|
659
|
-
* @param {Schema.Field} schema 字段的 Schema 定义
|
|
805
|
+
* @param {Schema.Field<M>} schema 字段的 Schema 定义
|
|
660
806
|
* @param {object} [options] 可选配置
|
|
661
807
|
* @param {*} [options.parent]
|
|
662
808
|
* @param {*} [options.state]
|
|
663
809
|
* @param {number | string | null} [options.index]
|
|
664
|
-
* @param {number | Signal.State<number> | Signal.Computed<number>} [options.
|
|
810
|
+
* @param {number | Signal.State<number> | Signal.Computed<number>} [options.size]
|
|
665
811
|
* @param {boolean} [options.null]
|
|
666
812
|
* @param {boolean} [options.new]
|
|
667
813
|
* @param {boolean} [options.hidden]
|
|
@@ -692,11 +838,11 @@ declare class Store<T = any> {
|
|
|
692
838
|
* @param {((value: T?, index: any, store: Store) => void)?} [options.onUpdate]
|
|
693
839
|
* @param {((value: T?, index: any, store: Store) => void)?} [options.onUpdateState]
|
|
694
840
|
*/
|
|
695
|
-
constructor(schema: Schema.Field
|
|
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 }?: {
|
|
696
842
|
parent?: any;
|
|
697
843
|
state?: any;
|
|
698
844
|
index?: string | number | null | undefined;
|
|
699
|
-
|
|
845
|
+
size?: number | Signal.State<number> | Signal.Computed<number> | undefined;
|
|
700
846
|
null?: boolean | undefined;
|
|
701
847
|
new?: boolean | undefined;
|
|
702
848
|
hidden?: boolean | undefined;
|
|
@@ -764,21 +910,21 @@ declare class Store<T = any> {
|
|
|
764
910
|
/** 存储类类别,继承的自定义类需要设置自定义的此只读属性 */
|
|
765
911
|
get kind(): string;
|
|
766
912
|
get ref(): Ref;
|
|
767
|
-
schema: Schema.Field
|
|
913
|
+
schema: Schema.Field<M>;
|
|
768
914
|
/** 存储对象自身 */
|
|
769
915
|
get store(): this;
|
|
770
916
|
/** 父级存储对象 */
|
|
771
|
-
get parent(): Store<any> | null;
|
|
917
|
+
get parent(): Store<any, any> | null;
|
|
772
918
|
/** 根节点的存储对象 */
|
|
773
|
-
get root(): Store<any>;
|
|
919
|
+
get root(): Store<any, any>;
|
|
774
920
|
/** 字段类型 */
|
|
775
921
|
get type(): any;
|
|
776
922
|
/** 字段元信息 */
|
|
777
|
-
get meta():
|
|
923
|
+
get meta(): void | M;
|
|
778
924
|
/** 自定义渲染组件信息 */
|
|
779
925
|
get component(): any;
|
|
780
926
|
/** 长度信息 */
|
|
781
|
-
get
|
|
927
|
+
get size(): number;
|
|
782
928
|
set index(v: string | number);
|
|
783
929
|
/** 索引信息 */
|
|
784
930
|
get index(): string | number;
|
|
@@ -913,7 +1059,7 @@ declare class Store<T = any> {
|
|
|
913
1059
|
|
|
914
1060
|
/**
|
|
915
1061
|
* @param {Store} store 存储实例
|
|
916
|
-
* @param {
|
|
1062
|
+
* @param {Layout.Child[]} layouts 布局信息
|
|
917
1063
|
* @param {Element} parent 渲染节点
|
|
918
1064
|
* @param {object} [options] 选项
|
|
919
1065
|
* @param {Record<string, Store | {get?(): any; set?(v: any): void; exec?(...p: any[]): any; calc?(...p: any[]): any }>} [options.global] 全局数据
|
|
@@ -922,8 +1068,8 @@ declare class Store<T = any> {
|
|
|
922
1068
|
* @param {Record<string, Enhancement>} [options.enhancements] 增强信息
|
|
923
1069
|
* @returns {() => void}
|
|
924
1070
|
*/
|
|
925
|
-
declare function
|
|
926
|
-
global?: Record<string, Store<any> | {
|
|
1071
|
+
declare function render(store: Store, layouts: Child[], parent: Element, { component, global, relate, enhancements }?: {
|
|
1072
|
+
global?: Record<string, Store<any, any> | {
|
|
927
1073
|
get?(): any;
|
|
928
1074
|
set?(v: any): void;
|
|
929
1075
|
exec?(...p: any[]): any;
|
|
@@ -951,4 +1097,4 @@ declare function watch<T>(getter: () => T, callback: (value: T) => void, immedia
|
|
|
951
1097
|
*/
|
|
952
1098
|
declare function effect(fn: () => void): () => void;
|
|
953
1099
|
|
|
954
|
-
export { type AsyncValidator, Component, Enhancement, index_d as Layout, type Ref, type Relatedness, Schema, Store, type Validator, type VerifyError, effect,
|
|
1100
|
+
export { type AsyncValidator, Component, Enhancement, index_d as Layout, type Ref, type Relatedness, Schema, Store, type Validator, type VerifyError, effect, render, watch };
|