@neeloong/form 0.2.0 → 0.4.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 +10 -4
- package/index.d.mts +78 -69
- package/index.js +365 -201
- package/index.min.js +6 -6
- package/index.min.mjs +6 -6
- package/index.mjs +365 -201
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,12 +34,12 @@ const template = `
|
|
|
34
34
|
|
|
35
35
|
/** @type {Layout.Options} */
|
|
36
36
|
const layoutOptions = {
|
|
37
|
-
|
|
37
|
+
createCalc: value => {
|
|
38
38
|
const fn = new Function('globalThis', `with(globalThis) { return ${value} }`);
|
|
39
39
|
fn.toString = () => value;
|
|
40
40
|
return /** @type {*} */(fn);
|
|
41
41
|
},
|
|
42
|
-
|
|
42
|
+
createEvent: value => {
|
|
43
43
|
const fn = new Function('$event', 'globalThis', `with(globalThis) { ${value} }`);
|
|
44
44
|
fn.toString = () => value;
|
|
45
45
|
return /** @type {*} */(fn);
|
|
@@ -160,12 +160,13 @@ render(store, layouts, app);
|
|
|
160
160
|
|
|
161
161
|
优先级从高到低:
|
|
162
162
|
|
|
163
|
-
1.
|
|
163
|
+
1. 模板定义: `!template`
|
|
164
164
|
1. 条件: `!if` `!else`
|
|
165
165
|
1. 子属性: `!value`
|
|
166
166
|
1. 枚举: `!enum`
|
|
167
167
|
1. 别名与计算名: `*别名` `*计算名`
|
|
168
168
|
1. 显式变量: `+变量`
|
|
169
|
+
1. 片段与模板调用: `!fragment`
|
|
169
170
|
1. 属性与事件: `:绑定属性` `@事件` `普通属性` `!bind`
|
|
170
171
|
1. 子内容: `!text` `!html`
|
|
171
172
|
1. 注释: `!comment`
|
|
@@ -175,13 +176,14 @@ render(store, layouts, app);
|
|
|
175
176
|
1. 字段扩展隐式属性
|
|
176
177
|
- `$value`
|
|
177
178
|
- `$state`
|
|
179
|
+
- `$store` 只读属性
|
|
180
|
+
- `$schema` 只读属性
|
|
178
181
|
- `$null` 只读属性
|
|
179
182
|
- `$index` 只读属性
|
|
180
183
|
- `$no` 只读属性
|
|
181
184
|
- `$length` 只读属性
|
|
182
185
|
- `$creatable` 只读属性
|
|
183
186
|
- `$immutable` 只读属性
|
|
184
|
-
- `$schema` 只读属性
|
|
185
187
|
- `$new` 只读属性
|
|
186
188
|
- `$readonly` 只读属性
|
|
187
189
|
- `$hidden` 只读属性
|
|
@@ -208,9 +210,13 @@ render(store, layouts, app);
|
|
|
208
210
|
- `$remove()`
|
|
209
211
|
- `$upMove()`
|
|
210
212
|
- `$downMove()`
|
|
213
|
+
1. 上下文隐式变量
|
|
214
|
+
- '$store' 只读属性
|
|
215
|
+
- '$root' 只读属性
|
|
211
216
|
1. 当前范围及组件范围的所有字段(数组字段的成员除外,因为数组字段成员索引为数字,不符合标识符命名规则)都存在 `field$value` 及 `field$$value` 形式的变量
|
|
212
217
|
1. 如果别名为字段的别名,则也存在 `alias$value` 形式的变量
|
|
213
218
|
1. 当存在同名变量时,则会按照变量来源类型决定优先级,从高到低依次为:
|
|
219
|
+
1. 上下文隐式变量
|
|
214
220
|
1. 显式声明(如别名、计算名、显式变量),如果别名是字段的别名,则也包括 `alias$value` 形式的变量
|
|
215
221
|
1. 全局变量,此部分由 `render` 的参数传入
|
|
216
222
|
1. 字段声明,包括 `field$value` 及 `field$$value` 形式的变量
|
package/index.d.mts
CHANGED
|
@@ -1,11 +1,82 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @neeloong/form v0.
|
|
2
|
+
* @neeloong/form v0.4.0
|
|
3
3
|
* (c) 2024-2025 Fierflame
|
|
4
4
|
* @license Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
export { Signal } from 'signal-polyfill';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param {string} source
|
|
12
|
+
* @param {Layout.Options} [options]
|
|
13
|
+
* @returns {(Layout.Node | string)[]}
|
|
14
|
+
*/
|
|
15
|
+
declare function parse(source: string, { createCalc, createEvent, simpleTag, }?: Options): (Node | string)[];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param {Layout.Node | (Layout.Node |string)[]} value
|
|
20
|
+
* @param {boolean} [formable]
|
|
21
|
+
* @returns {string}
|
|
22
|
+
*/
|
|
23
|
+
declare function toString(value: Node | (Node | string)[], formable?: boolean): string;
|
|
24
|
+
|
|
25
|
+
type Directives = {
|
|
26
|
+
template?: string | undefined;
|
|
27
|
+
fragment?: string | boolean | undefined;
|
|
28
|
+
if?: string | Calc | undefined;
|
|
29
|
+
else?: boolean | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* 值关联(关联为列表)
|
|
32
|
+
*/
|
|
33
|
+
value?: string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* 列表属性枚举
|
|
36
|
+
*/
|
|
37
|
+
enum?: string | boolean | Calc | undefined;
|
|
38
|
+
bind?: string | boolean | undefined;
|
|
39
|
+
text?: string | Calc | undefined;
|
|
40
|
+
html?: string | Calc | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* 注释
|
|
43
|
+
*/
|
|
44
|
+
comment?: string | undefined;
|
|
45
|
+
};
|
|
46
|
+
type Options = {
|
|
47
|
+
createCalc?: ((t: string) => Calc) | undefined;
|
|
48
|
+
createEvent?: ((t: string) => EventListener) | undefined;
|
|
49
|
+
simpleTag?: Set<string> | undefined;
|
|
50
|
+
};
|
|
51
|
+
type Node = {
|
|
52
|
+
name: string;
|
|
53
|
+
is?: string | null | undefined;
|
|
54
|
+
id?: string | undefined;
|
|
55
|
+
attrs: Record<string, string | {
|
|
56
|
+
name: string;
|
|
57
|
+
} | Calc>;
|
|
58
|
+
params: Record<string, string | Calc>;
|
|
59
|
+
classes: Record<string, string | boolean | Calc>;
|
|
60
|
+
styles: Record<string, string | Calc>;
|
|
61
|
+
events: Record<string, string | EventListener>;
|
|
62
|
+
vars: Record<string, string | Calc>;
|
|
63
|
+
aliases: Record<string, string | Calc>;
|
|
64
|
+
directives: Directives;
|
|
65
|
+
children: (Node | string)[];
|
|
66
|
+
};
|
|
67
|
+
type Calc = (env: Record<string, any>) => any;
|
|
68
|
+
type EventListener = ($event: any, env: Record<string, any>) => void;
|
|
69
|
+
|
|
70
|
+
type index_d_Calc = Calc;
|
|
71
|
+
type index_d_Directives = Directives;
|
|
72
|
+
type index_d_EventListener = EventListener;
|
|
73
|
+
type index_d_Node = Node;
|
|
74
|
+
type index_d_Options = Options;
|
|
75
|
+
declare const index_d_parse: typeof parse;
|
|
76
|
+
declare namespace index_d {
|
|
77
|
+
export { type index_d_Calc as Calc, type index_d_Directives as Directives, type index_d_EventListener as EventListener, type index_d_Node as Node, type index_d_Options as Options, index_d_parse as parse, toString as stringify };
|
|
78
|
+
}
|
|
79
|
+
|
|
9
80
|
type VerifyError = any;
|
|
10
81
|
type Component = {
|
|
11
82
|
tag: string | ((ctx: any) => Element);
|
|
@@ -20,13 +91,13 @@ declare namespace Component {
|
|
|
20
91
|
* // TODO: 可否计算,可否关联
|
|
21
92
|
*/
|
|
22
93
|
isProp?: boolean | undefined;
|
|
23
|
-
bind?: [event: string, set:
|
|
94
|
+
bind?: [event: string, set: EventListener, (boolean | undefined)?] | "hidden" | "clearable" | "readonly" | "disabled" | "required" | undefined;
|
|
24
95
|
default?: any;
|
|
25
96
|
immutable?: boolean | undefined;
|
|
26
97
|
};
|
|
27
98
|
type Handler = {
|
|
28
99
|
set: (name: string, value: any) => void;
|
|
29
|
-
addEvent: (event: string, listener:
|
|
100
|
+
addEvent: (event: string, listener: EventListener) => void;
|
|
30
101
|
destroy: () => void;
|
|
31
102
|
tag: any;
|
|
32
103
|
init: () => void;
|
|
@@ -52,8 +123,11 @@ declare namespace Component {
|
|
|
52
123
|
/**
|
|
53
124
|
* 过滤器
|
|
54
125
|
*/
|
|
55
|
-
filters: Record<string,
|
|
126
|
+
filters: Record<string, Component.Event.Filter | string>;
|
|
56
127
|
};
|
|
128
|
+
namespace Event {
|
|
129
|
+
type Filter = ($event: any, param: string[], env: any) => boolean | null | void;
|
|
130
|
+
}
|
|
57
131
|
}
|
|
58
132
|
type ComponentGetter = (path: string[], next?: ((path: string[]) => Component | null) | undefined) => Component | null;
|
|
59
133
|
type Schema = Record<string, Schema.Field>;
|
|
@@ -308,71 +382,6 @@ declare class ObjectStore extends Store<any> {
|
|
|
308
382
|
#private;
|
|
309
383
|
}
|
|
310
384
|
|
|
311
|
-
/**
|
|
312
|
-
*
|
|
313
|
-
* @param {string} source
|
|
314
|
-
* @param {Layout.Options} [options]
|
|
315
|
-
* @returns {(Layout.Node | string)[]}
|
|
316
|
-
*/
|
|
317
|
-
declare function parse(source: string, { creteCalc, creteEvent, simpleTag, }?: Options): (Node | string)[];
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
*
|
|
321
|
-
* @param {Layout.Node | (Layout.Node |string)[]} value
|
|
322
|
-
* @param {boolean} [formable]
|
|
323
|
-
* @returns {string}
|
|
324
|
-
*/
|
|
325
|
-
declare function toString(value: Node | (Node | string)[], formable?: boolean): string;
|
|
326
|
-
|
|
327
|
-
type Directives = {
|
|
328
|
-
fragment?: boolean | undefined;
|
|
329
|
-
if?: string | Function | undefined;
|
|
330
|
-
else?: boolean | undefined;
|
|
331
|
-
/**
|
|
332
|
-
* 值关联(关联为列表)
|
|
333
|
-
*/
|
|
334
|
-
value?: string | undefined;
|
|
335
|
-
/**
|
|
336
|
-
* 列表属性枚举
|
|
337
|
-
*/
|
|
338
|
-
enum?: string | boolean | Function | undefined;
|
|
339
|
-
bind?: string | undefined;
|
|
340
|
-
text?: string | Function | undefined;
|
|
341
|
-
html?: string | Function | undefined;
|
|
342
|
-
/**
|
|
343
|
-
* 注释
|
|
344
|
-
*/
|
|
345
|
-
comment?: string | Function | undefined;
|
|
346
|
-
};
|
|
347
|
-
type Options = {
|
|
348
|
-
creteCalc?: ((t: string) => (vars: Record<string, any>) => any) | undefined;
|
|
349
|
-
creteEvent?: ((t: string) => ($event: any, vars: Record<string, any>) => any) | undefined;
|
|
350
|
-
simpleTag?: Set<string> | undefined;
|
|
351
|
-
};
|
|
352
|
-
type Node = {
|
|
353
|
-
name: string;
|
|
354
|
-
is?: string | null | undefined;
|
|
355
|
-
id?: string | undefined;
|
|
356
|
-
attrs: Record<string, string | {
|
|
357
|
-
name: string;
|
|
358
|
-
} | ((global: any) => void)>;
|
|
359
|
-
classes: Record<string, string | boolean | ((global: any) => void)>;
|
|
360
|
-
styles: Record<string, string | ((global: any) => void)>;
|
|
361
|
-
events: Record<string, string | (($event: any, global: any) => void)>;
|
|
362
|
-
vars: Record<string, string | ((global: any) => void)>;
|
|
363
|
-
aliases: Record<string, string | Function>;
|
|
364
|
-
directives: Directives;
|
|
365
|
-
children: (Node | string)[];
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
type index_d_Directives = Directives;
|
|
369
|
-
type index_d_Node = Node;
|
|
370
|
-
type index_d_Options = Options;
|
|
371
|
-
declare const index_d_parse: typeof parse;
|
|
372
|
-
declare namespace index_d {
|
|
373
|
-
export { type index_d_Directives as Directives, type index_d_Node as Node, type index_d_Options as Options, index_d_parse as parse, toString as stringify };
|
|
374
|
-
}
|
|
375
|
-
|
|
376
385
|
/**
|
|
377
386
|
* @overload
|
|
378
387
|
* @param {Store} store
|