@neeloong/form 0.1.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.d.mts +312 -0
- package/index.js +3658 -0
- package/index.min.js +60 -0
- package/index.min.mjs +60 -0
- package/index.mjs +3076 -0
- package/package.json +36 -0
package/index.d.mts
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @neeloong/form v0.1.0
|
|
3
|
+
* (c) 2024-2025 Fierflame
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export { Signal } from 'signal-polyfill';
|
|
8
|
+
|
|
9
|
+
type VerifyError = any;
|
|
10
|
+
type Component = {
|
|
11
|
+
tag: string | ((ctx: any) => Element);
|
|
12
|
+
is?: string | undefined;
|
|
13
|
+
attrs?: Record<string, Component.Attr> | undefined;
|
|
14
|
+
events?: Record<string, Component.Event> | undefined;
|
|
15
|
+
};
|
|
16
|
+
declare namespace Component {
|
|
17
|
+
type Attr = {
|
|
18
|
+
type: string;
|
|
19
|
+
/**
|
|
20
|
+
* // TODO: 可否计算,可否关联
|
|
21
|
+
*/
|
|
22
|
+
isProp?: boolean | undefined;
|
|
23
|
+
bind?: [event: string, set: ($event: any, global: any) => any, (boolean | undefined)?] | "hidden" | "clearable" | "readonly" | "disabled" | "required" | undefined;
|
|
24
|
+
default?: any;
|
|
25
|
+
immutable?: boolean | undefined;
|
|
26
|
+
};
|
|
27
|
+
type Handler = {
|
|
28
|
+
set: (name: string, value: any) => void;
|
|
29
|
+
addEvent: (event: string, listener: ($event: any, global: any) => any) => void;
|
|
30
|
+
destroy: () => void;
|
|
31
|
+
tag: any;
|
|
32
|
+
init: () => void;
|
|
33
|
+
};
|
|
34
|
+
type Context = {
|
|
35
|
+
props?: Set<string> | null | undefined;
|
|
36
|
+
events: [string, ($event: any) => void, AddEventListenerOptions][];
|
|
37
|
+
tagAttrs: Record<string, any>;
|
|
38
|
+
watchAttr: (name: any, fn: (value: any, old: any, name: string) => void) => () => void;
|
|
39
|
+
destroyed: boolean;
|
|
40
|
+
init: boolean;
|
|
41
|
+
listen: <K extends keyof Component.Context.Events>(event: K, listener: (...p: Component.Context.Events[K]) => void) => () => void;
|
|
42
|
+
};
|
|
43
|
+
namespace Context {
|
|
44
|
+
type Events = {
|
|
45
|
+
init: [value: {
|
|
46
|
+
events: [string, ($event: any) => void, AddEventListenerOptions][];
|
|
47
|
+
}];
|
|
48
|
+
destroy: [];
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
type Event = {
|
|
52
|
+
/**
|
|
53
|
+
* 过滤器
|
|
54
|
+
*/
|
|
55
|
+
filters: Record<string, (($event: any, param: string[], env: any) => boolean | null | void) | string>;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
type ComponentGetter = (path: string[], next?: ((path: string[]) => Component | null) | undefined) => Component | null;
|
|
59
|
+
type Schema = Record<string, Schema.Field>;
|
|
60
|
+
declare namespace Schema {
|
|
61
|
+
type Field = (Schema.Object | Schema.Type) & Schema.Attr;
|
|
62
|
+
type Value = {
|
|
63
|
+
label: string;
|
|
64
|
+
value: string | number;
|
|
65
|
+
};
|
|
66
|
+
namespace Value {
|
|
67
|
+
type Group = {
|
|
68
|
+
label: string;
|
|
69
|
+
value?: string | number | undefined;
|
|
70
|
+
children: (Schema.Value.Group | Schema.Value | string | number)[];
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
type Object = {
|
|
74
|
+
type?: null | undefined;
|
|
75
|
+
props?: Record<string, Schema.Field> | undefined;
|
|
76
|
+
array?: boolean | undefined;
|
|
77
|
+
meta?: any;
|
|
78
|
+
};
|
|
79
|
+
type Type = {
|
|
80
|
+
type: string;
|
|
81
|
+
props?: null | undefined;
|
|
82
|
+
array?: boolean | undefined;
|
|
83
|
+
meta?: any;
|
|
84
|
+
};
|
|
85
|
+
type Attr = {
|
|
86
|
+
immutable?: boolean | undefined;
|
|
87
|
+
creatable?: boolean | undefined;
|
|
88
|
+
hidden?: boolean | ((store: Store) => boolean) | null | undefined;
|
|
89
|
+
clearable?: boolean | ((store: Store) => boolean) | null | undefined;
|
|
90
|
+
required?: boolean | ((store: Store) => boolean) | null | undefined;
|
|
91
|
+
disabled?: boolean | ((store: Store) => boolean) | null | undefined;
|
|
92
|
+
readonly?: boolean | ((store: Store) => boolean) | null | undefined;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** @import { Schema } from '../types.mjs' */
|
|
97
|
+
/**
|
|
98
|
+
* @template [T=any]
|
|
99
|
+
*/
|
|
100
|
+
declare class Store<T = any> {
|
|
101
|
+
/**
|
|
102
|
+
* @param {Schema} schema
|
|
103
|
+
* @param {object} [options]
|
|
104
|
+
* @param {boolean} [options.new]
|
|
105
|
+
*/
|
|
106
|
+
static create(schema: Schema, options?: {
|
|
107
|
+
new?: boolean | undefined;
|
|
108
|
+
}): ObjectStore;
|
|
109
|
+
/**
|
|
110
|
+
* @param {Schema.Field} schema
|
|
111
|
+
* @param {object} options
|
|
112
|
+
* @param {*} [options.parent]
|
|
113
|
+
* @param {*} [options.state]
|
|
114
|
+
* @param {number | string | null} [options.index]
|
|
115
|
+
* @param {number} [options.length]
|
|
116
|
+
* @param {boolean} [options.null]
|
|
117
|
+
* @param {boolean} [options.new]
|
|
118
|
+
* @param {boolean} [options.hidden]
|
|
119
|
+
* @param {boolean} [options.clearable]
|
|
120
|
+
* @param {boolean} [options.required]
|
|
121
|
+
* @param {boolean} [options.readonly]
|
|
122
|
+
* @param {boolean} [options.disabled]
|
|
123
|
+
* @param {((value: any) => any)?} [options.setValue]
|
|
124
|
+
* @param {((value: any) => any)?} [options.setState]
|
|
125
|
+
* @param {((value: any, state: any) => [value: any, state: any])?} [options.convert]
|
|
126
|
+
* @param {((value: T?, index: any) => void)?} [options.onUpdate]
|
|
127
|
+
* @param {((value: T?, index: any) => void)?} [options.onUpdateState]
|
|
128
|
+
*/
|
|
129
|
+
constructor(schema: Schema.Field, { null: isNull, state, setValue, setState, convert, onUpdate, onUpdateState, index, length, new: isNew, parent: parentNode, hidden, clearable, required, disabled, readonly, }: {
|
|
130
|
+
parent?: any;
|
|
131
|
+
state?: any;
|
|
132
|
+
index?: string | number | null | undefined;
|
|
133
|
+
length?: number | undefined;
|
|
134
|
+
null?: boolean | undefined;
|
|
135
|
+
new?: boolean | undefined;
|
|
136
|
+
hidden?: boolean | undefined;
|
|
137
|
+
clearable?: boolean | undefined;
|
|
138
|
+
required?: boolean | undefined;
|
|
139
|
+
readonly?: boolean | undefined;
|
|
140
|
+
disabled?: boolean | undefined;
|
|
141
|
+
setValue?: ((value: any) => any) | null | undefined;
|
|
142
|
+
setState?: ((value: any) => any) | null | undefined;
|
|
143
|
+
convert?: ((value: any, state: any) => [value: any, state: any]) | null | undefined;
|
|
144
|
+
onUpdate?: ((value: T | null, index: any) => void) | null | undefined;
|
|
145
|
+
onUpdateState?: ((value: T | null, index: any) => void) | null | undefined;
|
|
146
|
+
});
|
|
147
|
+
get null(): boolean;
|
|
148
|
+
schema: Schema.Field;
|
|
149
|
+
get parent(): Store<any> | null;
|
|
150
|
+
get root(): Store<any>;
|
|
151
|
+
set length(v: number);
|
|
152
|
+
get length(): number;
|
|
153
|
+
set index(v: string | number);
|
|
154
|
+
get index(): string | number;
|
|
155
|
+
get no(): string | number;
|
|
156
|
+
get creatable(): boolean;
|
|
157
|
+
get immutable(): boolean;
|
|
158
|
+
set selfNew(v: boolean);
|
|
159
|
+
get selfNew(): boolean;
|
|
160
|
+
set new(v: boolean);
|
|
161
|
+
get new(): boolean;
|
|
162
|
+
get editable(): boolean;
|
|
163
|
+
set selfHidden(v: boolean | null);
|
|
164
|
+
get selfHidden(): boolean | null;
|
|
165
|
+
set hidden(v: boolean);
|
|
166
|
+
get hidden(): boolean;
|
|
167
|
+
set selfClearable(v: boolean | null);
|
|
168
|
+
get selfClearable(): boolean | null;
|
|
169
|
+
set clearable(v: boolean);
|
|
170
|
+
get clearable(): boolean;
|
|
171
|
+
set selfRequired(v: boolean | null);
|
|
172
|
+
get selfRequired(): boolean | null;
|
|
173
|
+
set required(v: boolean);
|
|
174
|
+
get required(): boolean;
|
|
175
|
+
set selfDisabled(v: boolean | null);
|
|
176
|
+
get selfDisabled(): boolean | null;
|
|
177
|
+
set disabled(v: boolean);
|
|
178
|
+
get disabled(): boolean;
|
|
179
|
+
set selfReadonly(v: boolean | null);
|
|
180
|
+
get selfReadonly(): boolean | null;
|
|
181
|
+
set readonly(v: boolean);
|
|
182
|
+
get readonly(): boolean;
|
|
183
|
+
/**
|
|
184
|
+
*
|
|
185
|
+
* @param {string | number} key
|
|
186
|
+
* @returns {Store?}
|
|
187
|
+
*/
|
|
188
|
+
child(key: string | number): Store | null;
|
|
189
|
+
get changed(): boolean;
|
|
190
|
+
get saved(): boolean;
|
|
191
|
+
set value(v: T | null);
|
|
192
|
+
get value(): T | null;
|
|
193
|
+
set state(v: any);
|
|
194
|
+
get state(): any;
|
|
195
|
+
get destroyed(): boolean;
|
|
196
|
+
destroy(): void;
|
|
197
|
+
/** @returns {IterableIterator<[key: string | number, value: Store]>} */
|
|
198
|
+
[Symbol.iterator](): IterableIterator<[key: string | number, value: Store]>;
|
|
199
|
+
#private;
|
|
200
|
+
}
|
|
201
|
+
declare class ObjectStore extends Store<any> {
|
|
202
|
+
/**
|
|
203
|
+
* @param {Schema.Field} schema
|
|
204
|
+
* @param {object} [options]
|
|
205
|
+
* @param {Store?} [options.parent]
|
|
206
|
+
* @param {string | number} [options.index]
|
|
207
|
+
* @param {boolean} [options.new]
|
|
208
|
+
* @param {(value: any, index: any) => void} [options.onUpdate]
|
|
209
|
+
* @param {(value: any, index: any) => void} [options.onUpdateState]
|
|
210
|
+
*/
|
|
211
|
+
constructor(schema: Schema.Field, { parent, index, new: isNew, onUpdate, onUpdateState }?: {
|
|
212
|
+
parent?: Store<any> | null | undefined;
|
|
213
|
+
index?: string | number | undefined;
|
|
214
|
+
new?: boolean | undefined;
|
|
215
|
+
onUpdate?: ((value: any, index: any) => void) | undefined;
|
|
216
|
+
onUpdateState?: ((value: any, index: any) => void) | undefined;
|
|
217
|
+
});
|
|
218
|
+
[Symbol.iterator](): Generator<[string, Store<any>], void, unknown>;
|
|
219
|
+
#private;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
*
|
|
224
|
+
* @param {string} source
|
|
225
|
+
* @param {Layout.Options} [options]
|
|
226
|
+
* @returns {(Layout.Node | string)[]}
|
|
227
|
+
*/
|
|
228
|
+
declare function parse(source: string, { creteCalc, creteEvent, simpleTag, }?: Options): (Node | string)[];
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
*
|
|
232
|
+
* @param {Layout.Node | (Layout.Node |string)[]} value
|
|
233
|
+
* @param {boolean} [formable]
|
|
234
|
+
* @returns {string}
|
|
235
|
+
*/
|
|
236
|
+
declare function toString(value: Node | (Node | string)[], formable?: boolean): string;
|
|
237
|
+
|
|
238
|
+
type Directives = {
|
|
239
|
+
fragment?: boolean | undefined;
|
|
240
|
+
if?: string | Function | undefined;
|
|
241
|
+
else?: boolean | undefined;
|
|
242
|
+
/**
|
|
243
|
+
* 值关联(关联为列表)
|
|
244
|
+
*/
|
|
245
|
+
value?: string | undefined;
|
|
246
|
+
/**
|
|
247
|
+
* 列表属性枚举
|
|
248
|
+
*/
|
|
249
|
+
enum?: boolean | undefined;
|
|
250
|
+
bind?: string | undefined;
|
|
251
|
+
text?: string | Function | undefined;
|
|
252
|
+
html?: string | Function | undefined;
|
|
253
|
+
/**
|
|
254
|
+
* 注释
|
|
255
|
+
*/
|
|
256
|
+
comment?: string | Function | undefined;
|
|
257
|
+
};
|
|
258
|
+
type Options = {
|
|
259
|
+
creteCalc?: ((t: string) => (vars: Record<string, any>) => any) | undefined;
|
|
260
|
+
creteEvent?: ((t: string) => ($event: any, vars: Record<string, any>) => any) | undefined;
|
|
261
|
+
simpleTag?: Set<string> | undefined;
|
|
262
|
+
};
|
|
263
|
+
type Node = {
|
|
264
|
+
name: string;
|
|
265
|
+
is?: string | null | undefined;
|
|
266
|
+
id?: string | undefined;
|
|
267
|
+
attrs: Record<string, string | {
|
|
268
|
+
name: string;
|
|
269
|
+
} | ((global: any) => void)>;
|
|
270
|
+
classes: Record<string, string | boolean | ((global: any) => void)>;
|
|
271
|
+
styles: Record<string, string | ((global: any) => void)>;
|
|
272
|
+
events: Record<string, string | (($event: any, global: any) => void)>;
|
|
273
|
+
vars: Record<string, string | ((global: any) => void)>;
|
|
274
|
+
aliases: Record<string, string | Function>;
|
|
275
|
+
directives: Directives;
|
|
276
|
+
children: (Node | string)[];
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
type index_d_Directives = Directives;
|
|
280
|
+
type index_d_Node = Node;
|
|
281
|
+
type index_d_Options = Options;
|
|
282
|
+
declare const index_d_parse: typeof parse;
|
|
283
|
+
declare namespace index_d {
|
|
284
|
+
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 };
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* @overload
|
|
289
|
+
* @param {Store} store
|
|
290
|
+
* @param {(Layout.Node | string)[]} layouts
|
|
291
|
+
* @param {Element} parent
|
|
292
|
+
* @param {Record<string, Store | {get?(): any; set?(v: any): void; exec?(...p: any[]): any; calc?(...p: any[]): any }>} [global]
|
|
293
|
+
* @param {(path: string[]) => Component?} [components]
|
|
294
|
+
* @returns {() => void}
|
|
295
|
+
*/
|
|
296
|
+
declare function _default(store: Store, layouts: (Node | string)[], parent: Element, global?: Record<string, Store<any> | {
|
|
297
|
+
get?(): any;
|
|
298
|
+
set?(v: any): void;
|
|
299
|
+
exec?(...p: any[]): any;
|
|
300
|
+
calc?(...p: any[]): any;
|
|
301
|
+
}> | undefined, components?: ((path: string[]) => Component | null) | undefined): () => void;
|
|
302
|
+
/**
|
|
303
|
+
* @overload
|
|
304
|
+
* @param {Store} store
|
|
305
|
+
* @param {(Layout.Node | string)[]} layouts
|
|
306
|
+
* @param {Element} parent
|
|
307
|
+
* @param {((path: string[]) => Component?)?} [components]
|
|
308
|
+
* @returns {() => void}
|
|
309
|
+
*/
|
|
310
|
+
declare function _default(store: Store, layouts: (Node | string)[], parent: Element, components?: ((path: string[]) => Component | null) | null | undefined): () => void;
|
|
311
|
+
|
|
312
|
+
export { Component, type ComponentGetter, index_d as Layout, Schema, Store, type VerifyError, _default as render };
|