@neeloong/form 0.10.0 → 0.11.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 +2 -4
- package/index.d.mts +205 -61
- package/index.js +490 -388
- package/index.min.js +8 -8
- package/index.min.mjs +6 -6
- package/index.mjs +489 -387
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -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` 参数传入)**
|
|
@@ -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`
|
package/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @neeloong/form v0.
|
|
2
|
+
* @neeloong/form v0.11.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;
|
|
@@ -913,7 +1057,7 @@ declare class Store<T = any> {
|
|
|
913
1057
|
|
|
914
1058
|
/**
|
|
915
1059
|
* @param {Store} store 存储实例
|
|
916
|
-
* @param {
|
|
1060
|
+
* @param {Layout.Child[]} layouts 布局信息
|
|
917
1061
|
* @param {Element} parent 渲染节点
|
|
918
1062
|
* @param {object} [options] 选项
|
|
919
1063
|
* @param {Record<string, Store | {get?(): any; set?(v: any): void; exec?(...p: any[]): any; calc?(...p: any[]): any }>} [options.global] 全局数据
|
|
@@ -922,7 +1066,7 @@ declare class Store<T = any> {
|
|
|
922
1066
|
* @param {Record<string, Enhancement>} [options.enhancements] 增强信息
|
|
923
1067
|
* @returns {() => void}
|
|
924
1068
|
*/
|
|
925
|
-
declare function
|
|
1069
|
+
declare function render(store: Store, layouts: Child[], parent: Element, { component, global, relate, enhancements }?: {
|
|
926
1070
|
global?: Record<string, Store<any> | {
|
|
927
1071
|
get?(): any;
|
|
928
1072
|
set?(v: any): void;
|
|
@@ -951,4 +1095,4 @@ declare function watch<T>(getter: () => T, callback: (value: T) => void, immedia
|
|
|
951
1095
|
*/
|
|
952
1096
|
declare function effect(fn: () => void): () => void;
|
|
953
1097
|
|
|
954
|
-
export { type AsyncValidator, Component, Enhancement, index_d as Layout, type Ref, type Relatedness, Schema, Store, type Validator, type VerifyError, effect,
|
|
1098
|
+
export { type AsyncValidator, Component, Enhancement, index_d as Layout, type Ref, type Relatedness, Schema, Store, type Validator, type VerifyError, effect, render, watch };
|