@lark.js/mvc 0.0.3 → 0.0.4
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 +554 -786
- package/dist/{chunk-Y72BUONO.js → chunk-ANWA22AX.js} +94 -82
- package/dist/index.cjs +789 -649
- package/dist/index.d.cts +1672 -983
- package/dist/index.d.ts +1672 -983
- package/dist/index.js +788 -647
- package/dist/vite.cjs +94 -82
- package/dist/vite.js +1 -1
- package/dist/webpack.cjs +94 -82
- package/dist/webpack.js +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,876 +1,1633 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
/** Generic function type for event handlers and callbacks.
|
|
6
|
-
* Uses any[] to accept callbacks with specific parameter types
|
|
7
|
-
* (TypeScript function parameters are contravariant).
|
|
2
|
+
* Base View class.
|
|
3
|
+
* Views are created via View.extend() and mounted by Frame.
|
|
8
4
|
*/
|
|
9
|
-
|
|
10
|
-
/** A function that returns void. */
|
|
11
|
-
type VoidFunc = (...args: any[]) => void;
|
|
12
|
-
interface CacheEntry<T> {
|
|
13
|
-
/** Original key without prefix */
|
|
14
|
-
originalKey: string;
|
|
15
|
-
/** Cached value */
|
|
16
|
-
value: T | undefined;
|
|
17
|
-
/** Access frequency count */
|
|
18
|
-
frequency: number;
|
|
19
|
-
/** Last access timestamp */
|
|
20
|
-
lastTimestamp: number;
|
|
21
|
-
}
|
|
22
|
-
interface CacheOptions<T> {
|
|
23
|
-
/** Maximum cache size before eviction triggers (default: 20) */
|
|
24
|
-
maxSize?: number;
|
|
25
|
-
/** Buffer size for eviction (default: 5) */
|
|
26
|
-
bufferSize?: number;
|
|
27
|
-
/** Callback when entry is removed */
|
|
28
|
-
onRemove?: (key: string) => void;
|
|
29
|
-
/** Comparator for sorting entries */
|
|
30
|
-
sortComparator?: (a: CacheEntry<T>, b: CacheEntry<T>) => number;
|
|
31
|
-
}
|
|
32
|
-
interface EventListenerEntry {
|
|
33
|
-
/** Handler function */
|
|
34
|
-
handler: AnyFunc;
|
|
35
|
-
/** Whether currently executing (1 = executing, '' = done) */
|
|
36
|
-
executing: number | string;
|
|
37
|
-
}
|
|
38
|
-
interface ParsedUri {
|
|
39
|
-
/** Path portion (before ? or #) */
|
|
40
|
-
path: string;
|
|
41
|
-
/** Key-value params */
|
|
42
|
-
params: Record<string, string>;
|
|
43
|
-
}
|
|
44
|
-
interface Location {
|
|
45
|
-
/** Full href */
|
|
46
|
-
href: string;
|
|
47
|
-
/** Query string (before #) */
|
|
48
|
-
srcQuery: string;
|
|
49
|
-
/** Hash string (after #) */
|
|
50
|
-
srcHash: string;
|
|
51
|
-
/** Parsed query object */
|
|
52
|
-
query: ParsedUri;
|
|
53
|
-
/** Parsed hash object */
|
|
54
|
-
hash: ParsedUri;
|
|
55
|
-
/** Merged params from query and hash */
|
|
56
|
-
params: Record<string, string>;
|
|
57
|
-
/** Resolved view path */
|
|
58
|
-
view?: string;
|
|
59
|
-
/** Resolved path */
|
|
60
|
-
path?: string;
|
|
61
|
-
/** Get param by key with optional default */
|
|
62
|
-
get: (key: string, defaultValue?: string) => string;
|
|
63
|
-
}
|
|
64
|
-
interface ParamDiff {
|
|
65
|
-
from: string;
|
|
66
|
-
to: string;
|
|
67
|
-
}
|
|
68
|
-
interface LocationDiff {
|
|
69
|
-
/** Changed params (key -> {from, to}) */
|
|
70
|
-
params: Record<string, ParamDiff>;
|
|
71
|
-
/** Whether path changed */
|
|
72
|
-
path?: ParamDiff;
|
|
73
|
-
/** Whether view changed */
|
|
74
|
-
view?: ParamDiff;
|
|
75
|
-
/** Whether this is a first forced change */
|
|
76
|
-
force: boolean;
|
|
77
|
-
/** Whether anything changed */
|
|
78
|
-
changed: boolean;
|
|
79
|
-
}
|
|
80
|
-
interface VDomRef {
|
|
81
|
-
/** ID update list: [element, newId][] */
|
|
82
|
-
idUpdates: [Element, string][];
|
|
83
|
-
/** Views that need post-processing */
|
|
84
|
-
views: ViewInstance[];
|
|
85
|
-
/** DOM operation list: [opCode, parent, newChild?, oldChild?][] */
|
|
86
|
-
domOps: VDomOp[];
|
|
87
|
-
/** Whether anything changed */
|
|
88
|
-
hasChanged: number;
|
|
89
|
-
}
|
|
90
|
-
type VDomOp = [1, Element, Element] | [2, Element, Element] | [4, Element, Element, Element] | [8, Element, Element, Element];
|
|
91
|
-
type FrameChildrenMap = Record<string, string>;
|
|
92
|
-
type FrameReadyMap = Record<string, number>;
|
|
93
|
-
interface FrameInvokeEntry {
|
|
94
|
-
/** Method name */
|
|
95
|
-
name: string;
|
|
96
|
-
/** Method arguments */
|
|
97
|
-
args: unknown[];
|
|
98
|
-
/** Internal key for dedup */
|
|
99
|
-
key: string;
|
|
100
|
-
/** Whether removed (args match) */
|
|
101
|
-
removed?: boolean;
|
|
102
|
-
}
|
|
103
|
-
/** Mixin event handler with internal merge marker and handler list */
|
|
104
|
-
interface MixinEventHandler extends AnyFunc {
|
|
105
|
-
/** Merged handler list */ a?: AnyFunc[];
|
|
106
|
-
/** Mixin marker: 1 = this is a mixin function */ b?: number;
|
|
107
|
-
}
|
|
108
|
-
/** View event selector map entry: handler name list with selector presence tracking */
|
|
109
|
-
interface ViewEventSelectorEntry {
|
|
110
|
-
/** Selector name list */
|
|
111
|
-
selectors: string[];
|
|
112
|
-
/** Index signature for checking if selector is already registered */
|
|
113
|
-
[selector: string]: unknown;
|
|
114
|
-
}
|
|
115
|
-
/** View class internal markers (SPLITTER key) */
|
|
116
|
-
type ViewClassInternal = Record<string, AnyFunc[]>;
|
|
117
|
-
interface ViewLocationObserved {
|
|
118
|
-
/** Whether observing location */
|
|
119
|
-
flag: number;
|
|
120
|
-
/** Keys to observe */
|
|
121
|
-
keys: string[];
|
|
122
|
-
/** Whether observing path */
|
|
123
|
-
observePath: boolean;
|
|
124
|
-
}
|
|
125
|
-
interface ViewResourceEntry {
|
|
126
|
-
/** The resource entity */
|
|
127
|
-
entity: unknown;
|
|
128
|
-
/** Whether to destroy when render() is called */
|
|
129
|
-
destroyOnRender: boolean;
|
|
130
|
-
}
|
|
131
|
-
type ViewResourceMap = Record<string, ViewResourceEntry>;
|
|
132
|
-
type ViewEventSelectorMap = Record<string, ViewEventSelectorEntry>;
|
|
133
|
-
interface ViewGlobalEventEntry {
|
|
134
|
-
/** Handler function */
|
|
135
|
-
handler: AnyFunc;
|
|
136
|
-
/** Bound handler wrapper (for removeEventListener) */
|
|
137
|
-
boundHandler?: AnyFunc;
|
|
138
|
-
/** DOM element (window/document) */
|
|
139
|
-
element: EventTarget;
|
|
140
|
-
/** Event name */
|
|
141
|
-
eventName: string;
|
|
142
|
-
/** Modifiers */
|
|
143
|
-
modifiers: Record<string, boolean>;
|
|
144
|
-
}
|
|
145
|
-
type ViewEventObjectMap = Record<string, number>;
|
|
146
|
-
interface ViewInstance {
|
|
5
|
+
declare class View implements ViewInterface {
|
|
147
6
|
/** View ID (same as owner frame ID) */
|
|
148
7
|
id: string;
|
|
149
8
|
/** Owner frame */
|
|
150
|
-
owner:
|
|
9
|
+
owner: FrameInterface | number;
|
|
151
10
|
/** Updater instance */
|
|
152
|
-
updater:
|
|
11
|
+
updater: UpdaterInterface;
|
|
153
12
|
/** Signature: > 0 means active, incremented on render, 0 = destroyed */
|
|
154
13
|
signature: number;
|
|
155
14
|
/** Whether rendered at least once */
|
|
156
15
|
rendered?: boolean;
|
|
157
16
|
/** Whether view has template */
|
|
158
|
-
template?:
|
|
17
|
+
template?: (data: unknown, viewId: string, refData: unknown, ...rest: unknown[]) => string | string;
|
|
159
18
|
/** Location observation config */
|
|
160
19
|
locationObserved: ViewLocationObserved;
|
|
161
20
|
/** Observed state keys */
|
|
162
21
|
observedStateKeys?: string[];
|
|
163
22
|
/** Resource map */
|
|
164
|
-
resources:
|
|
165
|
-
/** Selector event map: eventType -> selector list */
|
|
166
|
-
eventSelectorMap: ViewEventSelectorMap;
|
|
167
|
-
/** Event object map: eventType -> bitmask */
|
|
168
|
-
eventObjectMap: ViewEventObjectMap;
|
|
169
|
-
/** Global event list */
|
|
170
|
-
globalEventList: ViewGlobalEventEntry[];
|
|
23
|
+
resources: Record<string, ViewResourceEntry>;
|
|
171
24
|
/** Assign method reference */
|
|
172
25
|
assignMethod?: AnyFunc;
|
|
173
|
-
/** Whether endUpdate
|
|
26
|
+
/** Whether endUpdate pending */
|
|
174
27
|
endUpdatePending?: number;
|
|
175
|
-
/**
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
/** Error handler */
|
|
300
|
-
error?: (error: Error) => void;
|
|
301
|
-
/** Extensions to load */
|
|
302
|
-
exts?: string[];
|
|
303
|
-
/** Init module to load */
|
|
304
|
-
ini?: string;
|
|
305
|
-
/** Rewrite function for routes */
|
|
306
|
-
rewrite?: (path: string, params: Record<string, string>, routes: Record<string, string>) => string;
|
|
307
|
-
/** Unmatched view (404) */
|
|
308
|
-
unmatchedView?: string;
|
|
309
|
-
/** Module require function */
|
|
310
|
-
require?: (names: string[], params?: Record<string, unknown>) => Promise<unknown> | undefined;
|
|
311
|
-
/** Skip view rendered check */
|
|
312
|
-
skipViewRendered?: boolean;
|
|
313
|
-
/** Remold function for event processing */
|
|
314
|
-
remold?: (target: HTMLElement, type: string, event: Event) => boolean;
|
|
315
|
-
/** Dynamic config access */
|
|
316
|
-
[key: string]: unknown;
|
|
317
|
-
}
|
|
318
|
-
interface RouteViewConfig {
|
|
319
|
-
/** View path */
|
|
320
|
-
view: string;
|
|
321
|
-
/** Additional properties merged into location */
|
|
322
|
-
[key: string]: unknown;
|
|
323
|
-
}
|
|
324
|
-
/** Element with VDOM diff cached compare key */
|
|
325
|
-
interface VdomElement extends Element {
|
|
326
|
-
/** Whether compare key is cached */
|
|
327
|
-
compareKeyCached?: number | undefined;
|
|
328
|
-
/** Cached compare key */
|
|
329
|
-
cachedCompareKey?: string | undefined;
|
|
330
|
-
/** Whether auto-generated ID */
|
|
331
|
-
autoId?: number;
|
|
332
|
-
}
|
|
333
|
-
/** Element with frame binding */
|
|
334
|
-
interface FrameBoundElement extends HTMLElement {
|
|
335
|
-
/** Frame instance bound to this element */
|
|
336
|
-
frame?: FrameLike;
|
|
337
|
-
/** Whether frame is bound (1 = bound) */
|
|
338
|
-
frameBound?: number;
|
|
339
|
-
/** View rendered flag */
|
|
340
|
-
viewRendered?: number;
|
|
341
|
-
/** Range frame ID */
|
|
342
|
-
rangeFrameId?: string;
|
|
343
|
-
/** Range element guid */
|
|
344
|
-
rangeElementGuid?: number;
|
|
28
|
+
/** Internal event storage */
|
|
29
|
+
private _events;
|
|
30
|
+
/**
|
|
31
|
+
* Event bitmask map: eventType -> bitmask (1=root, 2=selector).
|
|
32
|
+
* Read from prototype ($evtObjMap) set by View.prepare.
|
|
33
|
+
* Using a getter avoids ES6 class field shadowing the prototype value.
|
|
34
|
+
*/
|
|
35
|
+
get eventObjectMap(): Record<string, number>;
|
|
36
|
+
/**
|
|
37
|
+
* Selector event map: eventType -> selector list.
|
|
38
|
+
* Read from prototype ($selMap) set by View.prepare.
|
|
39
|
+
*/
|
|
40
|
+
get eventSelectorMap(): Record<string, ViewEventSelectorEntry>;
|
|
41
|
+
/**
|
|
42
|
+
* Global event list: [{handler, element, eventName, modifiers}].
|
|
43
|
+
* Read from prototype ($globalEvtList) set by View.prepare.
|
|
44
|
+
*/
|
|
45
|
+
get globalEventList(): ViewGlobalEventEntry[];
|
|
46
|
+
/**
|
|
47
|
+
* Initialize view (called by Frame when mounting).
|
|
48
|
+
*/
|
|
49
|
+
init(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Render view template (called by Frame after init).
|
|
52
|
+
* Wrapped by View.wrapMethod to manage signature + resources.
|
|
53
|
+
*/
|
|
54
|
+
render(): void;
|
|
55
|
+
on(event: string, handler: AnyFunc): this;
|
|
56
|
+
off(event: string, handler?: AnyFunc): this;
|
|
57
|
+
fire(event: string, data?: Record<string, unknown>, remove?: boolean, lastToFirst?: boolean): this;
|
|
58
|
+
/**
|
|
59
|
+
* Notify view that HTML update is about to begin.
|
|
60
|
+
* Unmounts child frames in the update zone.
|
|
61
|
+
*/
|
|
62
|
+
beginUpdate(id?: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* Notify view that HTML update has ended.
|
|
65
|
+
* Mounts child frames in the update zone and runs deferred invokes.
|
|
66
|
+
*/
|
|
67
|
+
endUpdate(id?: string, inner?: boolean): void;
|
|
68
|
+
/**
|
|
69
|
+
* Wrap an async callback to check view signature before executing.
|
|
70
|
+
* If the view has been re-rendered or destroyed, the callback is skipped.
|
|
71
|
+
*/
|
|
72
|
+
wrapAsync<Fn extends AnyFunc>(fn: Fn, context?: unknown): (...args: Parameters<Fn>) => ReturnType<Fn> | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Observe location parameters or path changes.
|
|
75
|
+
* When observed keys change, render() is called automatically.
|
|
76
|
+
*/
|
|
77
|
+
observeLocation(params: string | string[] | Record<string, unknown>, observePath?: boolean): void;
|
|
78
|
+
/**
|
|
79
|
+
* Observe State data keys for changes.
|
|
80
|
+
* When observed keys change via State.digest(), render() is called.
|
|
81
|
+
*/
|
|
82
|
+
observeState(observedKeys: string | string[]): void;
|
|
83
|
+
/**
|
|
84
|
+
* Capture (register) a resource under a key.
|
|
85
|
+
* If a resource already exists at that key, it's destroyed first.
|
|
86
|
+
* When destroyOnRender=true, the resource is destroyed on next render call.
|
|
87
|
+
*/
|
|
88
|
+
capture(key: string, resource?: unknown, destroyOnRender?: boolean): unknown;
|
|
89
|
+
/**
|
|
90
|
+
* Release a captured resource.
|
|
91
|
+
* If destroy=true, calls the resource's destroy() method.
|
|
92
|
+
*/
|
|
93
|
+
release(key: string, destroy?: boolean): unknown;
|
|
94
|
+
/**
|
|
95
|
+
* Set up a leave confirmation for route changes and page unload.
|
|
96
|
+
*/
|
|
97
|
+
leaveTip(message: string, condition: () => boolean): void;
|
|
98
|
+
/** Collected ctors from mixins */
|
|
99
|
+
static ctors?: AnyFunc[];
|
|
100
|
+
/**
|
|
101
|
+
* Prepare a View subclass by scanning its prototype for event method patterns.
|
|
102
|
+
* Pattern: `$?name<eventType1,eventType2>(&modifiers)`
|
|
103
|
+
*
|
|
104
|
+
* Only runs once per View subclass (guarded by ctors marker).
|
|
105
|
+
* Called from Frame.mountView before creating the view instance.
|
|
106
|
+
*/
|
|
107
|
+
static prepare(oView: typeof View): AnyFunc[];
|
|
108
|
+
/**
|
|
109
|
+
* Bind or unbind event delegation for a view instance.
|
|
110
|
+
* Called from Frame during mount/unmount.
|
|
111
|
+
*/
|
|
112
|
+
static delegateEvents(view: ViewInterface, destroy?: boolean): void;
|
|
113
|
+
/**
|
|
114
|
+
* Destroy all resources managed by a view.
|
|
115
|
+
* If lastly=true, destroy ALL resources; otherwise only destroyOnRender ones.
|
|
116
|
+
*/
|
|
117
|
+
static destroyAllResources(view: ViewInterface, lastly: boolean): void;
|
|
118
|
+
/**
|
|
119
|
+
* Process deferred invoke calls on a frame.
|
|
120
|
+
*/
|
|
121
|
+
static runInvokes(frame: FrameInterface): void;
|
|
122
|
+
/**
|
|
123
|
+
* Wrap a method on the prototype to add signature checking and resource cleanup.
|
|
124
|
+
*/
|
|
125
|
+
private static wrapMethod;
|
|
126
|
+
/**
|
|
127
|
+
* When two mixins define the same event method, merge them into
|
|
128
|
+
* a single function that calls both in sequence.
|
|
129
|
+
*/
|
|
130
|
+
private static processMixinsSameEvent;
|
|
131
|
+
/**
|
|
132
|
+
* Merge an array of mixin objects into the view prototype.
|
|
133
|
+
*/
|
|
134
|
+
private static mergeMixins;
|
|
135
|
+
/**
|
|
136
|
+
* Destroy a single resource entry.
|
|
137
|
+
*/
|
|
138
|
+
private static destroyResource;
|
|
139
|
+
/**
|
|
140
|
+
* Extend View to create a new View subclass.
|
|
141
|
+
*
|
|
142
|
+
* Supports:
|
|
143
|
+
* - props.make: constructor-like init (called with initParams + {node, deep})
|
|
144
|
+
* - props.mixins: array of mixin objects
|
|
145
|
+
* - Event method patterns: `'name<click>'` etc.
|
|
146
|
+
*/
|
|
147
|
+
static extend(props?: ThisType<ViewInterface> & Record<string, unknown>, statics?: Record<string, unknown>): typeof View;
|
|
148
|
+
/**
|
|
149
|
+
* Merge mixins into View prototype.
|
|
150
|
+
*/
|
|
151
|
+
static merge(this: typeof View, ...mixins: Record<string, unknown>[]): typeof View;
|
|
345
152
|
}
|
|
346
153
|
|
|
347
154
|
/**
|
|
348
|
-
*
|
|
155
|
+
* Multi-cast event emitter class.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* const emitter = new EventEmitter();
|
|
159
|
+
* emitter.on('change', (data) => console.log(data));
|
|
160
|
+
* emitter.fire('change', { key: 'value' });
|
|
349
161
|
*/
|
|
162
|
+
declare class EventEmitter<T = unknown> implements EventEmitterInterface<T> {
|
|
163
|
+
/** Event listeners: prefixed key -> listener array */
|
|
164
|
+
listeners: Map<string, EventListenerEntry[]>;
|
|
165
|
+
/**
|
|
166
|
+
* Bind event listener.
|
|
167
|
+
*/
|
|
168
|
+
on(event: string, handler: (this: T, e: ChangeEvent) => void): this;
|
|
169
|
+
/**
|
|
170
|
+
* Unbind event listener.
|
|
171
|
+
* If handler is provided, removes only that handler.
|
|
172
|
+
* If no handler, removes all handlers for the event.
|
|
173
|
+
*/
|
|
174
|
+
off(event: string, handler?: AnyFunc): this;
|
|
175
|
+
/**
|
|
176
|
+
* Fire event, execute all bound handlers.
|
|
177
|
+
* Supports executing state management: handlers removed during
|
|
178
|
+
* execution are safely handled.
|
|
179
|
+
*
|
|
180
|
+
* @param event - Event name
|
|
181
|
+
* @param data - Event data (type property added automatically)
|
|
182
|
+
* @param remove - Whether to remove all handlers after firing
|
|
183
|
+
* @param lastToFirst - Whether to execute handlers in reverse order
|
|
184
|
+
*/
|
|
185
|
+
fire(event: string, data?: Record<string, unknown>, remove?: boolean, lastToFirst?: boolean): this;
|
|
186
|
+
}
|
|
350
187
|
|
|
351
|
-
/** Check if value is a plain object (not null, not array, typeof object) */
|
|
352
|
-
declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
353
|
-
/** Check if value is an array */
|
|
354
|
-
declare const isArray: (arg: any) => arg is any[];
|
|
355
|
-
/** Check if value is primitive or function (not a complex object) */
|
|
356
|
-
declare function isPrimitiveOrFunc(value: unknown): boolean;
|
|
357
|
-
/** Check if value is primitive (not object, not function) */
|
|
358
|
-
declare function isPrimitive(value: unknown): boolean;
|
|
359
|
-
declare function generateId(prefix?: string): string;
|
|
360
|
-
/** Sync local counter with global counter */
|
|
361
|
-
declare function syncCounter(val: number): void;
|
|
362
|
-
declare function noop(): void;
|
|
363
|
-
/** Safe hasOwnProperty check */
|
|
364
|
-
declare function has<T extends object>(owner: T | undefined | null, prop: PropertyKey): boolean;
|
|
365
|
-
/** Get object keys (own enumerable) */
|
|
366
|
-
declare function keys<T extends object>(obj: T): string[];
|
|
367
|
-
/** Assign properties from sources to target (like Object.assign but safer) */
|
|
368
|
-
declare function assign<T extends object>(target: T, ...sources: Partial<T>[]): T;
|
|
369
188
|
/**
|
|
370
|
-
*
|
|
371
|
-
*
|
|
189
|
+
* Frame (View Frame) class for view lifecycle management.
|
|
190
|
+
* Each frame owns a view and manages child frames.
|
|
191
|
+
*
|
|
372
192
|
*/
|
|
373
|
-
declare
|
|
193
|
+
declare class Frame extends EventEmitter implements FrameInterface {
|
|
194
|
+
/** Frame ID (same as owner DOM element ID) */
|
|
195
|
+
readonly id: string;
|
|
196
|
+
/** Parent Frame ID */
|
|
197
|
+
private _parentId;
|
|
198
|
+
get parentId(): string | undefined;
|
|
199
|
+
/** Children map: id -> id */
|
|
200
|
+
childrenMap: Record<string, string>;
|
|
201
|
+
/** Children count */
|
|
202
|
+
childrenCount: number;
|
|
203
|
+
/** Ready count (children that have fired 'created') */
|
|
204
|
+
readyCount: number;
|
|
205
|
+
/** Ready map: id -> 1 */
|
|
206
|
+
readyMap: Record<string, number>;
|
|
207
|
+
/** View instance */
|
|
208
|
+
viewInstance?: ViewInterface;
|
|
209
|
+
/** Get view instance (read-only) */
|
|
210
|
+
get view(): ViewInterface | undefined;
|
|
211
|
+
/** Invoke list for deferred method calls */
|
|
212
|
+
invokeList: FrameInvokeEntry[];
|
|
213
|
+
/** Signature for async operation tracking */
|
|
214
|
+
signature: number;
|
|
215
|
+
/** Whether view has altered */
|
|
216
|
+
hasAltered: number;
|
|
217
|
+
/** Whether view is destroyed */
|
|
218
|
+
destroyed: number;
|
|
219
|
+
/** View path (v-lark attribute value) */
|
|
220
|
+
viewPath?: string;
|
|
221
|
+
/** Original template before mount */
|
|
222
|
+
originalTemplate?: string;
|
|
223
|
+
/** Hold fire created flag */
|
|
224
|
+
holdFireCreated: number;
|
|
225
|
+
/** Children created flag */
|
|
226
|
+
childrenCreated: number;
|
|
227
|
+
/** Children alter flag */
|
|
228
|
+
childrenAlter: number;
|
|
229
|
+
constructor(id: string, parentId?: string);
|
|
230
|
+
/**
|
|
231
|
+
* Mount a view to this frame.
|
|
232
|
+
*
|
|
233
|
+
* Complete flow:
|
|
234
|
+
* 1. Parse viewPath, translate query params from parent
|
|
235
|
+
* 2. Unmount current view
|
|
236
|
+
* 3. Load View class (via require or provided ViewClass)
|
|
237
|
+
* 4. View_Prepare (scan event methods)
|
|
238
|
+
* 5. Create View instance
|
|
239
|
+
* 6. View_DelegateEvents (bind DOM events)
|
|
240
|
+
* 7. Call view.init()
|
|
241
|
+
* 8. If view has template, call render via Updater
|
|
242
|
+
* 9. If no template, call endUpdate directly
|
|
243
|
+
*/
|
|
244
|
+
mountView(viewPath: string, viewInitParams?: Record<string, unknown>): void;
|
|
245
|
+
/**
|
|
246
|
+
* Internal: actually mount the view after class is loaded.
|
|
247
|
+
*/
|
|
248
|
+
doMountView(ViewClass: typeof View, params: Record<string, string>, node: HTMLElement, sign: number): void;
|
|
249
|
+
/**
|
|
250
|
+
* Unmount current view.
|
|
251
|
+
*/
|
|
252
|
+
unmountView(): void;
|
|
253
|
+
/**
|
|
254
|
+
* Mount a child frame.
|
|
255
|
+
*/
|
|
256
|
+
mountFrame(frameId: string, viewPath: string, viewInitParams?: Record<string, unknown>): FrameInterface;
|
|
257
|
+
/**
|
|
258
|
+
* Unmount a child frame.
|
|
259
|
+
*/
|
|
260
|
+
unmountFrame(id?: string, _inner?: boolean): void;
|
|
261
|
+
/**
|
|
262
|
+
* Mount all views in a zone.
|
|
263
|
+
*/
|
|
264
|
+
mountZone(zoneId?: string, _inner?: boolean): void;
|
|
265
|
+
/**
|
|
266
|
+
* Unmount all views in a zone.
|
|
267
|
+
*/
|
|
268
|
+
unmountZone(zoneId?: string, _inner?: boolean): void;
|
|
269
|
+
/**
|
|
270
|
+
* Get all child frame IDs.
|
|
271
|
+
*/
|
|
272
|
+
children(): string[];
|
|
273
|
+
/**
|
|
274
|
+
* Get parent frame at given level.
|
|
275
|
+
* @param level - How many levels up (default 1)
|
|
276
|
+
*/
|
|
277
|
+
parent(level?: number): Frame | undefined;
|
|
278
|
+
/**
|
|
279
|
+
* Invoke a method on the view.
|
|
280
|
+
*/
|
|
281
|
+
invoke(name: string, args?: unknown[]): unknown;
|
|
282
|
+
/** Get frame by ID */
|
|
283
|
+
static get(id: string): Frame | undefined;
|
|
284
|
+
/** Get all frames */
|
|
285
|
+
static getAll(): Map<string, Frame>;
|
|
286
|
+
/** Get or create root frame */
|
|
287
|
+
static root(rootId?: string): Frame;
|
|
288
|
+
/** Bind event listener (static) */
|
|
289
|
+
static on(event: string, handler: AnyFunc): typeof Frame;
|
|
290
|
+
/** Unbind event listener (static) */
|
|
291
|
+
static off(event: string, handler?: AnyFunc): typeof Frame;
|
|
292
|
+
/** Fire event (static) */
|
|
293
|
+
static fire(event: string, data?: Record<string, unknown>): void;
|
|
294
|
+
}
|
|
374
295
|
/**
|
|
375
|
-
*
|
|
376
|
-
*
|
|
296
|
+
* Register a View class for a given view path.
|
|
297
|
+
* Called after module loading completes.
|
|
377
298
|
*/
|
|
378
|
-
declare function
|
|
299
|
+
declare function registerViewClass(viewPath: string, ViewClass: typeof View): void;
|
|
300
|
+
|
|
379
301
|
/**
|
|
380
|
-
*
|
|
381
|
-
*
|
|
302
|
+
* Cache class with LFU-style eviction.
|
|
303
|
+
* Keys are prefixed with SPLITTER for namespace isolation.
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* const cache = new Cache({ maxSize: 20, bufferSize: 5 });
|
|
307
|
+
* cache.set('user', { name: 'Alice' });
|
|
308
|
+
* const user = cache.get('user');
|
|
309
|
+
* cache.has('user'); // true
|
|
310
|
+
* cache.del('user');
|
|
382
311
|
*/
|
|
383
|
-
declare
|
|
384
|
-
/**
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
|
|
312
|
+
declare class Cache<T = unknown> implements CacheInterface<T> {
|
|
313
|
+
/** Cache entries array */
|
|
314
|
+
private entries;
|
|
315
|
+
/** Fast lookup: prefixed key -> entry */
|
|
316
|
+
private lookup;
|
|
317
|
+
/** Buffer size for eviction */
|
|
318
|
+
private readonly bufferSize;
|
|
319
|
+
/** Maximum cache size */
|
|
320
|
+
private readonly maxSize;
|
|
321
|
+
/** Total capacity (maxSize + bufferSize) */
|
|
322
|
+
private readonly capacity;
|
|
323
|
+
/** Callback when entry is removed */
|
|
324
|
+
private readonly onRemove?;
|
|
325
|
+
/** Sort comparator */
|
|
326
|
+
private readonly comparator;
|
|
327
|
+
constructor(options?: CacheOptions<T>);
|
|
328
|
+
/** Prefix a key with SPLITTER for namespace isolation */
|
|
329
|
+
private prefixKey;
|
|
330
|
+
/**
|
|
331
|
+
* Get a cached value by key.
|
|
332
|
+
* Updates frequency and timestamp for cache sorting.
|
|
333
|
+
*/
|
|
334
|
+
get(key: string): T | undefined;
|
|
335
|
+
/**
|
|
336
|
+
* Iterate all cached values.
|
|
337
|
+
*/
|
|
338
|
+
forEach(callback: (value: T | undefined) => void): void;
|
|
339
|
+
/**
|
|
340
|
+
* Set or update a cached value.
|
|
341
|
+
* If key already exists, updates value and increments frequency.
|
|
342
|
+
* If cache exceeds capacity, triggers eviction.
|
|
343
|
+
*/
|
|
344
|
+
set(key: string, value: T): void;
|
|
345
|
+
/**
|
|
346
|
+
* Delete a cached entry.
|
|
347
|
+
*/
|
|
348
|
+
del(key: string): void;
|
|
349
|
+
/**
|
|
350
|
+
* Check if a key exists in cache.
|
|
351
|
+
*/
|
|
352
|
+
has(key: string): boolean;
|
|
353
|
+
/** Get current cache size */
|
|
354
|
+
get size(): number;
|
|
355
|
+
/** Clear all entries */
|
|
356
|
+
clear(): void;
|
|
357
|
+
/** Evict least-used entries from cache */
|
|
358
|
+
private evictEntries;
|
|
359
|
+
}
|
|
360
|
+
|
|
390
361
|
/**
|
|
391
|
-
*
|
|
392
|
-
*
|
|
362
|
+
* Lark framework type definitions.
|
|
363
|
+
* All shared types are defined here to eliminate type cheats across modules.
|
|
364
|
+
*
|
|
365
|
+
* Lark is a lightweight MVC frontend framework that provides:
|
|
366
|
+
* - View: base view class with extend/merge inheritance and mixin support
|
|
367
|
+
* - Router: hash-based two-phase route confirmation
|
|
368
|
+
* - State: cross-view observable global state management
|
|
369
|
+
* - Service: API request management with caching, queuing, and deduplication
|
|
370
|
+
* - Frame: view frame managing view mount/unmount lifecycle
|
|
371
|
+
* - Updater: view data binding and VDOM diff (in-memory real DOM diff) renderer
|
|
372
|
+
*
|
|
373
|
+
* Designed for single-page application (SPA) development.
|
|
393
374
|
*/
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
*
|
|
397
|
-
* e.g. "/xxx/?a=b&c=d" => { path: "/xxx/", params: { a: "b", c: "d" } }
|
|
375
|
+
/** Generic function type for event handlers and callbacks.
|
|
376
|
+
* Uses any[] to accept callbacks with specific parameter types
|
|
377
|
+
* (TypeScript function parameters are contravariant).
|
|
398
378
|
*/
|
|
399
|
-
|
|
379
|
+
type AnyFunc = (...args: any[]) => unknown;
|
|
380
|
+
interface CacheEntry<T> {
|
|
381
|
+
/** Original key without prefix */
|
|
382
|
+
originalKey: string;
|
|
383
|
+
/** Cached value */
|
|
384
|
+
value: T | undefined;
|
|
385
|
+
/** Access frequency count */
|
|
386
|
+
frequency: number;
|
|
387
|
+
/** Last access timestamp */
|
|
388
|
+
lastTimestamp: number;
|
|
389
|
+
}
|
|
390
|
+
interface CacheOptions<T> {
|
|
391
|
+
/** Maximum cache size before eviction triggers (default: 20) */
|
|
392
|
+
maxSize?: number;
|
|
393
|
+
/** Buffer size for eviction (default: 5) */
|
|
394
|
+
bufferSize?: number;
|
|
395
|
+
/** Callback when entry is removed */
|
|
396
|
+
onRemove?: (key: string) => void;
|
|
397
|
+
/** Comparator for sorting entries */
|
|
398
|
+
sortComparator?: (a: CacheEntry<T>, b: CacheEntry<T>) => number;
|
|
399
|
+
}
|
|
400
400
|
/**
|
|
401
|
-
*
|
|
402
|
-
*
|
|
401
|
+
* Cache interface providing LFU (Least Frequently Used) cache management.
|
|
402
|
+
* Cache keys use a special prefix internally for namespace isolation.
|
|
403
403
|
*/
|
|
404
|
-
|
|
404
|
+
interface CacheInterface<T = unknown> {
|
|
405
|
+
/**
|
|
406
|
+
* Set a cache resource. If the key exists, updates the value and increments frequency.
|
|
407
|
+
* Triggers LFU eviction when cache entries exceed capacity (maxSize + bufferSize).
|
|
408
|
+
* @param key Unique identifier for the cached resource
|
|
409
|
+
* @param resource The resource to cache
|
|
410
|
+
*/
|
|
411
|
+
set(key: string, resource: T): void;
|
|
412
|
+
/**
|
|
413
|
+
* Get a cached resource. Access increments frequency count and timestamp for LFU ranking.
|
|
414
|
+
* Returns undefined if the key does not exist.
|
|
415
|
+
* @param key Cache resource key
|
|
416
|
+
*/
|
|
417
|
+
get(key: string): T | undefined;
|
|
418
|
+
/**
|
|
419
|
+
* Remove a resource from cache by key. Triggers onRemove callback on deletion.
|
|
420
|
+
* @param key Cache resource key to remove
|
|
421
|
+
*/
|
|
422
|
+
del(key: string): void;
|
|
423
|
+
/**
|
|
424
|
+
* Check if cache contains a resource for the given key.
|
|
425
|
+
* @param key Cache resource key
|
|
426
|
+
*/
|
|
427
|
+
has(key: string): boolean;
|
|
428
|
+
/**
|
|
429
|
+
* Iterate over all cached resource values.
|
|
430
|
+
* @param callback Iteration callback receiving the cached value (may be undefined)
|
|
431
|
+
*/
|
|
432
|
+
forEach(callback: (value: T | undefined) => void): void;
|
|
433
|
+
/**
|
|
434
|
+
* Number of cache entries.
|
|
435
|
+
*/
|
|
436
|
+
readonly size: number;
|
|
437
|
+
/**
|
|
438
|
+
* Clear all cache entries. Triggers onRemove callback for each deleted entry.
|
|
439
|
+
*/
|
|
440
|
+
clear(): void;
|
|
441
|
+
}
|
|
442
|
+
interface EventListenerEntry {
|
|
443
|
+
/** Handler function */
|
|
444
|
+
handler: AnyFunc;
|
|
445
|
+
/** Whether currently executing (1 = executing, '' = done) */
|
|
446
|
+
executing: number | string;
|
|
447
|
+
}
|
|
405
448
|
/**
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
* For object arrays, uses specified key as map key.
|
|
449
|
+
* Parsed URL result containing path and parameters.
|
|
450
|
+
* Returned by `Router.parse()`, includes the path string and parsed key-value parameter pairs.
|
|
409
451
|
*/
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
|
|
452
|
+
interface ParsedUri {
|
|
453
|
+
/** Path portion (before ? or #), excluding query parameters */
|
|
454
|
+
path: string;
|
|
455
|
+
/** Key-value params parsed from the URL */
|
|
456
|
+
params: Record<string, string>;
|
|
457
|
+
}
|
|
415
458
|
/**
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
* it's a low-level framework utility for View.extend.
|
|
459
|
+
* Current URL parsing result interface.
|
|
460
|
+
* Returned by `Router.parse()`, includes both query (after ?) and hash (after #) sections.
|
|
419
461
|
*/
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
/**
|
|
430
|
-
|
|
431
|
-
/**
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
462
|
+
interface Location {
|
|
463
|
+
/** Full href, original href string */
|
|
464
|
+
href: string;
|
|
465
|
+
/** Query string (before #), raw query string (after ?, before #) */
|
|
466
|
+
srcQuery: string;
|
|
467
|
+
/** Hash string (after #), raw hash string (after #) */
|
|
468
|
+
srcHash: string;
|
|
469
|
+
/** Parsed query object, path and params parsed from srcQuery */
|
|
470
|
+
query: ParsedUri;
|
|
471
|
+
/** Parsed hash object, path and params parsed from srcHash */
|
|
472
|
+
hash: ParsedUri;
|
|
473
|
+
/**
|
|
474
|
+
* Merged params from query and hash,
|
|
475
|
+
* hash values take precedence when keys conflict.
|
|
476
|
+
*/
|
|
477
|
+
params: Record<string, string>;
|
|
478
|
+
/**
|
|
479
|
+
* Resolved view path for the current URL.
|
|
480
|
+
* May be undefined before framework boot.
|
|
481
|
+
*/
|
|
482
|
+
view?: string;
|
|
483
|
+
/**
|
|
484
|
+
* Resolved path computed from hash path and query path based on routing rules.
|
|
485
|
+
* May be undefined before framework boot.
|
|
486
|
+
*/
|
|
487
|
+
path?: string;
|
|
488
|
+
/**
|
|
489
|
+
* Get param by key with optional default value.
|
|
490
|
+
* Returns default value or empty string if key does not exist.
|
|
491
|
+
* @param key Parameter key name
|
|
492
|
+
* @param defaultValue Default value when key is missing, defaults to empty string
|
|
493
|
+
*/
|
|
494
|
+
get: (key: string, defaultValue?: string) => string;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* URL parameter change representing a parameter value transition from old to new.
|
|
498
|
+
* Used in `Router.diff()` return value to describe parameter changes.
|
|
435
499
|
*/
|
|
436
|
-
|
|
437
|
-
/**
|
|
438
|
-
|
|
439
|
-
/**
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
declare const CALL_BREAK_TIME = 48;
|
|
443
|
-
/** Increment global counter and return new value */
|
|
444
|
-
declare function nextCounter(): number;
|
|
445
|
-
|
|
500
|
+
interface ParamDiff {
|
|
501
|
+
/** Value before the change */
|
|
502
|
+
from: string;
|
|
503
|
+
/** Value after the change */
|
|
504
|
+
to: string;
|
|
505
|
+
}
|
|
446
506
|
/**
|
|
447
|
-
*
|
|
448
|
-
*
|
|
449
|
-
*
|
|
450
|
-
* @param styleIdOrPairs - Style ID string or array of [id, content] pairs
|
|
451
|
-
* @param css - CSS content string (only used when first arg is string)
|
|
452
|
-
* @returns Cleanup function to remove the styles
|
|
507
|
+
* URL route change object interface describing changes between two routing states.
|
|
508
|
+
* Returned by `Router.diff()`, includes changes in path, view, and other parameters.
|
|
453
509
|
*/
|
|
454
|
-
|
|
455
|
-
|
|
510
|
+
interface LocationDiff {
|
|
511
|
+
/**
|
|
512
|
+
* Changed params (key -> {from, to}),
|
|
513
|
+
* diff for all changed parameters
|
|
514
|
+
*/
|
|
515
|
+
params: Record<string, ParamDiff>;
|
|
516
|
+
/** Path diff when path has changed */
|
|
517
|
+
path?: ParamDiff;
|
|
518
|
+
/** View diff when rendered view has changed */
|
|
519
|
+
view?: ParamDiff;
|
|
520
|
+
/**
|
|
521
|
+
* Whether this is a first forced change during app initialization.
|
|
522
|
+
*/
|
|
523
|
+
force: boolean;
|
|
524
|
+
/** Whether any content has changed */
|
|
525
|
+
changed: boolean;
|
|
526
|
+
}
|
|
456
527
|
/**
|
|
457
|
-
*
|
|
458
|
-
*
|
|
459
|
-
*
|
|
460
|
-
* (e.g. view re-rendered), the checker returns false, preventing stale callbacks.
|
|
528
|
+
* Route pre-change event interface (change phase).
|
|
529
|
+
* Provides two-phase confirmation: triggers change (can be rejected), then changed.
|
|
530
|
+
* Can prevent, reject, or accept route changes through this event object.
|
|
461
531
|
*/
|
|
532
|
+
interface RouteChangeEvent extends ChangeEvent {
|
|
533
|
+
/**
|
|
534
|
+
* Reject the URL change, revert to previous URL.
|
|
535
|
+
*/
|
|
536
|
+
reject: () => void;
|
|
537
|
+
/**
|
|
538
|
+
* Accept the URL change, continue navigation.
|
|
539
|
+
*/
|
|
540
|
+
resolve: () => void;
|
|
541
|
+
/**
|
|
542
|
+
* Prevent the URL change, pause subsequent route processing.
|
|
543
|
+
*/
|
|
544
|
+
prevent: () => void;
|
|
545
|
+
}
|
|
462
546
|
/**
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
* @param host - Object to store mark state on (typically a view)
|
|
467
|
-
* @param key - Key to track (typically "render" or specific async operation)
|
|
468
|
-
* @returns Checker function that returns true if mark is still valid
|
|
547
|
+
* Route post-change event interface (changed phase).
|
|
548
|
+
* Carries route diff information. Triggered after route change is confirmed and URL is updated.
|
|
469
549
|
*/
|
|
470
|
-
|
|
550
|
+
type RouteChangedEvent = LocationDiff & ChangeEvent;
|
|
551
|
+
interface VDomRef {
|
|
552
|
+
/** ID update list: [element, newId][] */
|
|
553
|
+
idUpdates: [Element, string][];
|
|
554
|
+
/** Views that need post-processing */
|
|
555
|
+
views: ViewInterface[];
|
|
556
|
+
/** DOM operation list: [opCode, parent, newChild?, oldChild?][] */
|
|
557
|
+
domOps: VDomOp[];
|
|
558
|
+
/** Whether anything changed */
|
|
559
|
+
hasChanged: number;
|
|
560
|
+
}
|
|
561
|
+
type VDomOp = [1, Element, Element] | [2, Element, Element] | [4, Element, Element, Element] | [8, Element, Element, Element];
|
|
562
|
+
interface FrameInvokeEntry {
|
|
563
|
+
/** Method name */
|
|
564
|
+
name: string;
|
|
565
|
+
/** Method arguments */
|
|
566
|
+
args: unknown[];
|
|
567
|
+
/** Internal key */
|
|
568
|
+
key: string;
|
|
569
|
+
/** Whether removed (args match) */
|
|
570
|
+
removed?: boolean;
|
|
571
|
+
}
|
|
572
|
+
/** Mixin event handler with internal merge marker and handler list */
|
|
573
|
+
interface MixinEventHandler extends AnyFunc {
|
|
574
|
+
/** Merged handler list */
|
|
575
|
+
handlerList?: AnyFunc[];
|
|
576
|
+
/** Mixin marker: 1 = this is a mixin function */
|
|
577
|
+
marker?: number;
|
|
578
|
+
}
|
|
579
|
+
/** View event selector map entry: handler name list with selector presence tracking */
|
|
580
|
+
interface ViewEventSelectorEntry {
|
|
581
|
+
/** Selector name list */
|
|
582
|
+
selectors: string[];
|
|
583
|
+
/** Index signature for checking if selector is already registered */
|
|
584
|
+
[selector: string]: unknown;
|
|
585
|
+
}
|
|
586
|
+
interface ViewLocationObserved {
|
|
587
|
+
/** Whether observing location */
|
|
588
|
+
flag: number;
|
|
589
|
+
/** Keys to observe */
|
|
590
|
+
keys: string[];
|
|
591
|
+
/** Whether observing path */
|
|
592
|
+
observePath: boolean;
|
|
593
|
+
}
|
|
594
|
+
interface ViewResourceEntry {
|
|
595
|
+
/** The resource entity */
|
|
596
|
+
entity: unknown;
|
|
597
|
+
/** Whether to destroy when render() is called */
|
|
598
|
+
destroyOnRender: boolean;
|
|
599
|
+
}
|
|
600
|
+
interface ViewGlobalEventEntry {
|
|
601
|
+
/** Handler function */
|
|
602
|
+
handler: AnyFunc;
|
|
603
|
+
/** Bound handler wrapper (for removeEventListener) */
|
|
604
|
+
boundHandler?: AnyFunc;
|
|
605
|
+
/** DOM element (window/document) */
|
|
606
|
+
element: EventTarget;
|
|
607
|
+
/** Event name */
|
|
608
|
+
eventName: string;
|
|
609
|
+
/** Modifiers */
|
|
610
|
+
modifiers: Record<string, boolean>;
|
|
611
|
+
}
|
|
471
612
|
/**
|
|
472
|
-
*
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
* @param host - Object whose marks should be cleared
|
|
613
|
+
* Router interface providing URL parsing, navigation, diff, and event listening capabilities.
|
|
614
|
+
* Supports two-phase route confirmation mechanism: change (can reject) → changed.
|
|
615
|
+
* Hash-based implementation using #! as default hash prefix.
|
|
476
616
|
*/
|
|
477
|
-
|
|
478
|
-
|
|
617
|
+
interface RouterInterface extends EventEmitterInterface<RouterInterface> {
|
|
618
|
+
/**
|
|
619
|
+
* Parse href into Location object.
|
|
620
|
+
* Parses query and hash sections of href, returns structured routing information.
|
|
621
|
+
* Defaults to parsing current page `location.href`.
|
|
622
|
+
* @param href URL to parse, uses `location.href` if not specified
|
|
623
|
+
*/
|
|
624
|
+
parse(href?: string): Location;
|
|
625
|
+
/**
|
|
626
|
+
* Compute diff between current and previous location.
|
|
627
|
+
* Returns undefined if no routing changes have occurred yet.
|
|
628
|
+
*/
|
|
629
|
+
diff(): LocationDiff | undefined;
|
|
630
|
+
/**
|
|
631
|
+
* Navigate to new URL.
|
|
632
|
+
* Supports two calling modes:
|
|
633
|
+
* - `Router.to("/list", { page: 2 })` specify path and params
|
|
634
|
+
* - `Router.to({ page: 2 })` update params only, keep current path
|
|
635
|
+
* @param pathOrParams Path string or params object
|
|
636
|
+
* @param params Query params object (only used when first arg is path string)
|
|
637
|
+
* @param replace Whether to replace current history entry instead of adding new one
|
|
638
|
+
* @param silent Whether to silently update without triggering change event
|
|
639
|
+
*/
|
|
640
|
+
to(pathOrParams: string | Record<string, unknown>, params?: Record<string, unknown>, replace?: boolean, silent?: boolean): void;
|
|
641
|
+
/** Join path segments */
|
|
642
|
+
join(...paths: string[]): string;
|
|
643
|
+
/** Internal: bind hashchange (called by Framework.boot) */
|
|
644
|
+
_bind(): void;
|
|
645
|
+
/** Internal: set framework config */
|
|
646
|
+
_setConfig(cfg: FrameworkConfig): void;
|
|
647
|
+
/** Internal: notify hash change (for programmatic trigger) */
|
|
648
|
+
notify?(e?: Event): void;
|
|
649
|
+
/**
|
|
650
|
+
* Triggered when URL is about to change (change phase), can reject or prevent navigation via event object.
|
|
651
|
+
*/
|
|
652
|
+
onChange?: (e?: RouteChangeEvent) => void;
|
|
653
|
+
/**
|
|
654
|
+
* Triggered after URL has changed (changed phase), carries route diff information.
|
|
655
|
+
*/
|
|
656
|
+
onChanged?: (e?: RouteChangedEvent) => void;
|
|
657
|
+
}
|
|
479
658
|
/**
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
* In DEBUG mode, wraps data objects with Proxy to:
|
|
483
|
-
* 1. Warn when data is read from a different page than where it was set
|
|
484
|
-
* 2. Prevent direct mutation (forces use of State.set/digest)
|
|
485
|
-
* 3. Track access patterns for debugging
|
|
659
|
+
* Frame static event interface carrying associated Frame instance.
|
|
660
|
+
* Carried in Frame's add/remove static events.
|
|
486
661
|
*/
|
|
662
|
+
interface FrameStaticEvent extends ChangeEvent {
|
|
663
|
+
/**
|
|
664
|
+
* Associated Frame instance object.
|
|
665
|
+
*/
|
|
666
|
+
readonly frame: FrameInterface;
|
|
667
|
+
}
|
|
668
|
+
interface ViewInterface extends EventEmitterInterface<ViewInterface> {
|
|
669
|
+
/**
|
|
670
|
+
* View ID (same as owner frame ID),
|
|
671
|
+
* DOM node ID where current view resides.
|
|
672
|
+
*/
|
|
673
|
+
id: string;
|
|
674
|
+
/**
|
|
675
|
+
* Owner frame,
|
|
676
|
+
* Frame instance holding current view.
|
|
677
|
+
* May be numeric placeholder 0 before view initialization completes.
|
|
678
|
+
* TODO: Migrate numeric placeholder 0 to undefined or null
|
|
679
|
+
*/
|
|
680
|
+
owner: FrameInterface | number;
|
|
681
|
+
/**
|
|
682
|
+
* Updater instance managing view data binding and VDOM rendering.
|
|
683
|
+
*/
|
|
684
|
+
updater: UpdaterInterface;
|
|
685
|
+
/**
|
|
686
|
+
* Signature: > 0 means active, incremented on render, 0 = destroyed */
|
|
687
|
+
signature: number;
|
|
688
|
+
/** Whether rendered at least once */
|
|
689
|
+
rendered?: boolean;
|
|
690
|
+
/**
|
|
691
|
+
* View template supporting function or string template.
|
|
692
|
+
* Function template signature: `(data: unknown, viewId: string, refData: unknown, ...rest: unknown[]) => string`
|
|
693
|
+
*/
|
|
694
|
+
template?: (data: unknown, viewId: string, refData: unknown, ...rest: unknown[]) => string | string;
|
|
695
|
+
/**
|
|
696
|
+
* Mixin object array for extending view functionality.
|
|
697
|
+
* Framework merges properties and methods from mixins into view prototype.
|
|
698
|
+
* Event method conflicts are automatically merged into sequential calls.
|
|
699
|
+
*/
|
|
700
|
+
mixins?: Record<string, unknown>[];
|
|
701
|
+
/** Location observation config */
|
|
702
|
+
locationObserved: ViewLocationObserved;
|
|
703
|
+
/** Observed state keys */
|
|
704
|
+
observedStateKeys?: string[];
|
|
705
|
+
/** Resource map */
|
|
706
|
+
resources: Record<string, ViewResourceEntry>;
|
|
707
|
+
/** Selector event map: eventType -> selector list */
|
|
708
|
+
eventSelectorMap: Record<string, ViewEventSelectorEntry>;
|
|
709
|
+
/** Event object map: eventType -> bitmask */
|
|
710
|
+
eventObjectMap: Record<string, number>;
|
|
711
|
+
/** Global event list */
|
|
712
|
+
globalEventList: ViewGlobalEventEntry[];
|
|
713
|
+
/** Assign method reference */
|
|
714
|
+
assignMethod?: AnyFunc;
|
|
715
|
+
/** Whether endUpdate has been called (1 = pending) */
|
|
716
|
+
endUpdatePending?: number;
|
|
717
|
+
/** Render method (wrapped) */
|
|
718
|
+
render(): void;
|
|
719
|
+
/**
|
|
720
|
+
* Init method called after view is mounted.
|
|
721
|
+
* Used for initialization logic.
|
|
722
|
+
* Framework passes two arguments during actual invocation:
|
|
723
|
+
* - initParams: initialization parameter object
|
|
724
|
+
* - options: contains `node: Element` and `deep: boolean`
|
|
725
|
+
*/
|
|
726
|
+
init(): void;
|
|
727
|
+
/** Wrapped render method */
|
|
728
|
+
renderMethod?: AnyFunc;
|
|
729
|
+
/** endUpdate pending flag */
|
|
730
|
+
endUpdatePendingFlag?: number;
|
|
731
|
+
/**
|
|
732
|
+
* Notify view that HTML update is about to begin for a specific region.
|
|
733
|
+
* Framework unmounts child Frames in that region to prevent VDOM diff from operating on unmounted nodes.
|
|
734
|
+
* @param id Region node ID to update, defaults to current view
|
|
735
|
+
*/
|
|
736
|
+
beginUpdate: (id?: string) => void;
|
|
737
|
+
/**
|
|
738
|
+
* Notify view that HTML update has completed for a specific region.
|
|
739
|
+
* Framework mounts child Frames in that region and executes deferred invoke queue.
|
|
740
|
+
* @param id Region node ID that finished updating, defaults to current view
|
|
741
|
+
* @param inner Whether this is an internal framework call
|
|
742
|
+
*/
|
|
743
|
+
endUpdate: (id?: string, inner?: boolean) => void;
|
|
744
|
+
/**
|
|
745
|
+
* Wrap async callback to ensure it only executes if view is not destroyed.
|
|
746
|
+
* In SPAs, async callbacks (e.g., setTimeout, AJAX) may execute after view is destroyed,
|
|
747
|
+
* causing errors when manipulating DOM.
|
|
748
|
+
* After wrapping with `wrapAsync`, framework automatically checks view state and only executes callback if view is alive.
|
|
749
|
+
* @param fn Callback function to wrap
|
|
750
|
+
* @param context `this` binding for callback execution, defaults to view itself
|
|
751
|
+
*/
|
|
752
|
+
wrapAsync: <Fn extends AnyFunc>(fn: Fn, context?: unknown) => (...args: Parameters<Fn>) => ReturnType<Fn> | undefined;
|
|
753
|
+
/**
|
|
754
|
+
* Listen for URL bar changes, supports two calling modes:
|
|
755
|
+
* - `observeLocation("page,size", true)` pass parameter keys (comma-separated) and whether to observe path
|
|
756
|
+
* - `observeLocation({ params: ["page", "size"], path: true })` pass config object
|
|
757
|
+
* View automatically re-renders when observed parameters or path change.
|
|
758
|
+
* @param params Parameter keys to observe, supports comma-separated string, string array, or config object
|
|
759
|
+
* @param observePath Whether to observe path changes
|
|
760
|
+
*/
|
|
761
|
+
observeLocation: (params: string | string[] | Record<string, unknown>, observePath?: boolean) => void;
|
|
762
|
+
/**
|
|
763
|
+
* Observe data changes for specified keys in State.
|
|
764
|
+
* View automatically re-renders when observed keys are updated via `State.digest()`.
|
|
765
|
+
* @param keys Comma-separated key string or string array
|
|
766
|
+
*/
|
|
767
|
+
observeState: (keys: string | string[]) => void;
|
|
768
|
+
/**
|
|
769
|
+
* Hand over resource to current view for lifecycle management.
|
|
770
|
+
* Framework automatically calls resource's destroy method at appropriate time when view unmounts or re-renders.
|
|
771
|
+
* @param key Unique key for managed resource; if key already manages different resource, old resource is auto-destroyed
|
|
772
|
+
* @param resource Resource object to manage
|
|
773
|
+
* @param destroyOnRender Whether to auto-destroy resource when render method is called; Service instances typically need auto-destroy on render
|
|
774
|
+
*/
|
|
775
|
+
capture: (key: string, resource?: unknown, destroyOnRender?: boolean) => unknown;
|
|
776
|
+
/**
|
|
777
|
+
* Release managed resource, returns the resource object regardless of destruction state.
|
|
778
|
+
* @param key Managed resource key
|
|
779
|
+
* @param destroy Whether to destroy resource (call its destroy method), defaults to true
|
|
780
|
+
*/
|
|
781
|
+
release: (key: string, destroy?: boolean) => unknown;
|
|
782
|
+
/**
|
|
783
|
+
* Set leave prompt, e.g., when form has unsaved changes.
|
|
784
|
+
* Can prompt user to choose between leaving directly or saving before leaving.
|
|
785
|
+
* Framework calls condition function during route changes (change phase) and page unloads (beforeunload).
|
|
786
|
+
* Navigation is prevented if condition returns true.
|
|
787
|
+
* @param message Leave prompt message
|
|
788
|
+
* @param condition Function to determine whether to show leave prompt; returns true to prevent navigation
|
|
789
|
+
*/
|
|
790
|
+
leaveTip: (message: string, condition: () => boolean) => void;
|
|
791
|
+
/**
|
|
792
|
+
* Assign method for incremental DOM updates.
|
|
793
|
+
* Framework uses VDOM diff (in-memory real DOM diff) to update only changed portions,
|
|
794
|
+
* automatically handling child view mounting and unmounting.
|
|
795
|
+
* Returns true if DOM changed, undefined if no change.
|
|
796
|
+
* @param options Incremental update config, used internally by framework
|
|
797
|
+
*/
|
|
798
|
+
assign?: (options?: unknown) => boolean | undefined;
|
|
799
|
+
/**
|
|
800
|
+
* Triggered when view is destroyed.
|
|
801
|
+
*/
|
|
802
|
+
onDestroy?: (e?: ChangeEvent) => void;
|
|
803
|
+
/**
|
|
804
|
+
* Triggered when render method is called.
|
|
805
|
+
*/
|
|
806
|
+
onRender?: (e?: ChangeEvent) => void;
|
|
807
|
+
/**
|
|
808
|
+
* Inherit View to create new view subclass.
|
|
809
|
+
* Supports props.make constructor, props.mixins, and event methods (e.g., `'name<click>'`).
|
|
810
|
+
* @param props Prototype object containing init, render, and other methods
|
|
811
|
+
* @param statics Object of static methods or properties
|
|
812
|
+
*/
|
|
813
|
+
extend?<TProps = object, TStatics = object>(props?: ExtendThisType<TProps & ViewInterface>, statics?: TStatics): ViewInterface & TStatics;
|
|
814
|
+
/**
|
|
815
|
+
* Merge multiple mixin objects into View prototype.
|
|
816
|
+
* Existing properties are not overwritten; event method conflicts are automatically merged into sequential calls.
|
|
817
|
+
* @param args Mixin object list
|
|
818
|
+
*/
|
|
819
|
+
merge?(...args: ExtendThisType<ViewInterface>[]): ViewInterface;
|
|
820
|
+
}
|
|
821
|
+
type ExtendThisType<T> = Record<string, unknown> & ThisType<T>;
|
|
487
822
|
/**
|
|
488
|
-
*
|
|
489
|
-
*
|
|
490
|
-
*
|
|
491
|
-
* @param data - Data to wrap
|
|
492
|
-
* @param getter - Optional callback when properties are read
|
|
493
|
-
* @param setter - Optional callback when properties are written
|
|
494
|
-
* @param isRoot - Whether this is the root data object
|
|
495
|
-
* @returns Proxied data or original data if debug mode is off
|
|
823
|
+
* Minimal Frame interface needed by View.
|
|
824
|
+
* Frame (View Frame) is a view container managing view mount, unmount, and parent-child hierarchy.
|
|
825
|
+
* Each Frame corresponds to one DOM node, associated with view via v-lark attribute.
|
|
496
826
|
*/
|
|
497
|
-
|
|
498
|
-
|
|
827
|
+
interface FrameInterface extends EventEmitterInterface<FrameInterface> {
|
|
828
|
+
/**
|
|
829
|
+
* DOM node ID where Frame resides.
|
|
830
|
+
*/
|
|
831
|
+
id: string;
|
|
832
|
+
/**
|
|
833
|
+
* View module path currently rendered by this Frame, e.g., "app/views/default".
|
|
834
|
+
*/
|
|
835
|
+
readonly viewPath?: string;
|
|
836
|
+
/**
|
|
837
|
+
* Parent Frame ID, undefined if this is a top-level Frame.
|
|
838
|
+
*/
|
|
839
|
+
readonly parentId: string | undefined;
|
|
840
|
+
/**
|
|
841
|
+
* Mount view to current Frame.
|
|
842
|
+
* Framework loads view class, creates instance, and renders view.
|
|
843
|
+
* @param viewPath View module path, e.g., "app/views/default"
|
|
844
|
+
* @param viewInitParams Parameters passed during view initialization, accessible in view's init method
|
|
845
|
+
*/
|
|
846
|
+
mountView(viewPath: string, viewInitParams?: Record<string, unknown>): void;
|
|
847
|
+
/**
|
|
848
|
+
* Unmount view from current Frame, triggers view's destroy event and cleans up resources.
|
|
849
|
+
*/
|
|
850
|
+
unmountView(): void;
|
|
851
|
+
/**
|
|
852
|
+
* Mount child Frame on specified DOM node and render view.
|
|
853
|
+
* @param frameId DOM node ID for rendering
|
|
854
|
+
* @param viewPath View path
|
|
855
|
+
* @param viewInitParams Parameters passed during view initialization
|
|
856
|
+
*/
|
|
857
|
+
mountFrame: (frameId: string, viewPath: string, viewInitParams?: Record<string, unknown>) => FrameInterface;
|
|
858
|
+
/**
|
|
859
|
+
* Unmount child Frame from specified DOM node.
|
|
860
|
+
* @param id DOM node ID, defaults to current Frame if omitted
|
|
861
|
+
*/
|
|
862
|
+
unmountFrame: (id?: string, inner?: boolean) => void;
|
|
863
|
+
/**
|
|
864
|
+
* Render all child views under specified node (scans v-lark attributes and mounts).
|
|
865
|
+
* @param zoneId DOM node ID, defaults to current Frame
|
|
866
|
+
* @param inner Whether this is an internal framework call
|
|
867
|
+
*/
|
|
868
|
+
mountZone: (zoneId?: string, inner?: boolean) => void;
|
|
869
|
+
/**
|
|
870
|
+
* Unmount all child views under specified node.
|
|
871
|
+
* @param zoneId DOM node ID, defaults to current Frame
|
|
872
|
+
*/
|
|
873
|
+
unmountZone: (zoneId?: string, inner?: boolean) => void;
|
|
874
|
+
/**
|
|
875
|
+
* Get ancestor Frame, defaults to parent Frame (level=1).
|
|
876
|
+
* @param level Levels to traverse upward, defaults to 1
|
|
877
|
+
*/
|
|
878
|
+
parent(level?: number): FrameInterface | undefined;
|
|
879
|
+
/**
|
|
880
|
+
* Invoke specified method on view in current Frame.
|
|
881
|
+
* If view is not rendered yet, invocation is deferred until render completes.
|
|
882
|
+
* @param name Method name
|
|
883
|
+
* @param args Arguments array passed to method
|
|
884
|
+
*/
|
|
885
|
+
invoke: (name: string, args?: unknown[]) => unknown;
|
|
886
|
+
/**
|
|
887
|
+
* Triggered when all descendant views have been created.
|
|
888
|
+
*/
|
|
889
|
+
onCreated?: (e?: ChangeEvent) => void;
|
|
890
|
+
/**
|
|
891
|
+
* Triggered when descendant views change.
|
|
892
|
+
*/
|
|
893
|
+
onAlter?: (e?: ChangeEvent) => void;
|
|
894
|
+
/**
|
|
895
|
+
* Get Frame instance by ID, returns undefined if not exists.
|
|
896
|
+
* @param id Frame's DOM node ID
|
|
897
|
+
*/
|
|
898
|
+
get?(id: string): FrameInterface | undefined;
|
|
899
|
+
/**
|
|
900
|
+
* Get all Frame instances map for current page.
|
|
901
|
+
*/
|
|
902
|
+
getAll?(): Map<string, FrameInterface>;
|
|
903
|
+
/**
|
|
904
|
+
* Triggered when Frame is created and registered.
|
|
905
|
+
*/
|
|
906
|
+
onAdd?: (e?: FrameStaticEvent) => void;
|
|
907
|
+
/**
|
|
908
|
+
* Triggered when Frame is destroyed and unregistered.
|
|
909
|
+
*/
|
|
910
|
+
onRemove?: (e?: FrameStaticEvent) => void;
|
|
911
|
+
view: ViewInterface | undefined;
|
|
912
|
+
/**
|
|
913
|
+
* Get ID array of all child Frames for current Frame.
|
|
914
|
+
* Note: ID positions in array are not fixed.
|
|
915
|
+
*/
|
|
916
|
+
children: () => string[];
|
|
917
|
+
invokeList: FrameInvokeEntry[];
|
|
918
|
+
}
|
|
499
919
|
/**
|
|
500
|
-
*
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
* const cache = new Cache({ maxSize: 20, bufferSize: 5 });
|
|
505
|
-
* cache.set('user', { name: 'Alice' });
|
|
506
|
-
* const user = cache.get('user');
|
|
507
|
-
* cache.has('user'); // true
|
|
508
|
-
* cache.del('user');
|
|
920
|
+
* Minimal Updater interface needed by View.
|
|
921
|
+
* View updater responsible for view data binding and data/page updates.
|
|
922
|
+
* Each View instance has an Updater, triggering data/page updates via set/digest.
|
|
923
|
+
* Internally executes complete pipeline: template rendering → VDOM diff (in-memory real DOM diff) → DOM operations.
|
|
509
924
|
*/
|
|
510
|
-
|
|
511
|
-
/** Cache entries array */
|
|
512
|
-
private entries;
|
|
513
|
-
/** Fast lookup: prefixed key -> entry */
|
|
514
|
-
private lookup;
|
|
515
|
-
/** Buffer size for eviction */
|
|
516
|
-
private readonly bufferSize;
|
|
517
|
-
/** Maximum cache size */
|
|
518
|
-
private readonly maxSize;
|
|
519
|
-
/** Total capacity (maxSize + bufferSize) */
|
|
520
|
-
private readonly capacity;
|
|
521
|
-
/** Callback when entry is removed */
|
|
522
|
-
private readonly onRemove?;
|
|
523
|
-
/** Sort comparator */
|
|
524
|
-
private readonly comparator;
|
|
525
|
-
constructor(options?: CacheOptions<T>);
|
|
526
|
-
/** Prefix a key with SPLITTER for namespace isolation */
|
|
527
|
-
private prefixKey;
|
|
925
|
+
interface UpdaterInterface {
|
|
528
926
|
/**
|
|
529
|
-
* Get
|
|
530
|
-
*
|
|
927
|
+
* Get data that has been set.
|
|
928
|
+
* Returns complete data object if key is omitted, otherwise returns value for specified key.
|
|
929
|
+
* @param key Data key name, omitted returns complete data object
|
|
531
930
|
*/
|
|
532
|
-
get(key
|
|
931
|
+
get: <T = unknown>(key?: string) => T;
|
|
533
932
|
/**
|
|
534
|
-
*
|
|
933
|
+
* Set data and track changed keys.
|
|
934
|
+
* After set, must explicitly call `digest()` to commit changes to page.
|
|
935
|
+
* Returns this for chaining.
|
|
936
|
+
* @param data Data object, e.g., `{ a: 1, b: 2 }`
|
|
937
|
+
* @param excludes Set of keys to exclude from change tracking
|
|
535
938
|
*/
|
|
536
|
-
|
|
939
|
+
set: (data: Record<string, unknown>, excludes?: Set<string>) => UpdaterInterface;
|
|
537
940
|
/**
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
941
|
+
* Trigger page re-render.
|
|
942
|
+
* After set, must explicitly call `digest()` to commit changes to page.
|
|
943
|
+
* Internally executes complete pipeline: template rendering → VDOM diff (in-memory real DOM diff) → DOM operations.
|
|
944
|
+
* @param data Optional data object, if provided calls `set()` first to set data
|
|
945
|
+
* @param excludes Set of keys to exclude from change tracking
|
|
946
|
+
* @param callback Callback executed after render completes
|
|
541
947
|
*/
|
|
542
|
-
|
|
948
|
+
digest: (data?: Record<string, unknown>, excludes?: Set<string>, callback?: () => void) => void;
|
|
543
949
|
/**
|
|
544
|
-
*
|
|
950
|
+
* Save a snapshot of current data for altered() detection.
|
|
951
|
+
* Works with `altered()` method to detect whether data has changed.
|
|
545
952
|
*/
|
|
546
|
-
|
|
953
|
+
snapshot: () => UpdaterInterface;
|
|
547
954
|
/**
|
|
548
|
-
* Check if
|
|
955
|
+
* Check if data has changed since last snapshot.
|
|
956
|
+
* Returns undefined if `snapshot()` has not been called.
|
|
549
957
|
*/
|
|
550
|
-
|
|
551
|
-
/**
|
|
552
|
-
|
|
553
|
-
/**
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
958
|
+
altered: () => boolean | undefined;
|
|
959
|
+
/** Ref data for template rendering */
|
|
960
|
+
refData: Record<string, unknown>;
|
|
961
|
+
/**
|
|
962
|
+
* Translate raw reference data starting with @ symbol in template.
|
|
963
|
+
* Replaces `{{@refData}}` with actual value from refData.
|
|
964
|
+
* @param data Reference data to translate
|
|
965
|
+
*/
|
|
966
|
+
translate(data: unknown): unknown;
|
|
967
|
+
/**
|
|
968
|
+
* Parse expression string.
|
|
969
|
+
* @param expr Expression string to parse
|
|
970
|
+
*/
|
|
971
|
+
parse(expr: string): unknown;
|
|
557
972
|
}
|
|
558
|
-
|
|
559
973
|
/**
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
* @example
|
|
563
|
-
* const emitter = new EventEmitter();
|
|
564
|
-
* emitter.on('change', (data) => console.log(data));
|
|
565
|
-
* emitter.fire('change', { key: 'value' });
|
|
974
|
+
* Data payload interface wrapping API request response data, providing read/write methods.
|
|
975
|
+
* Payload instances are created internally by Service, developers access via all/one/save callbacks.
|
|
566
976
|
*/
|
|
567
|
-
|
|
568
|
-
/** Event listeners: prefixed key -> listener array */
|
|
569
|
-
private listeners;
|
|
977
|
+
interface PayloadInterface {
|
|
570
978
|
/**
|
|
571
|
-
*
|
|
979
|
+
* Get data from Payload by key.
|
|
980
|
+
* @param key Data key name
|
|
572
981
|
*/
|
|
573
|
-
|
|
982
|
+
get<T = unknown>(key: string): T;
|
|
574
983
|
/**
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
984
|
+
* Set data to Payload, supports three calling modes:
|
|
985
|
+
* - Key-value pair: `payload.set("name", "value")`
|
|
986
|
+
* - Data object: `payload.set({ name: "value" })`
|
|
987
|
+
* - Endpoint metadata object (for internal framework use)
|
|
988
|
+
* Returns this for chaining.
|
|
989
|
+
* @param keyOrData Key/value string, data object, or endpoint metadata object
|
|
990
|
+
* @param value Value when first parameter is a key
|
|
578
991
|
*/
|
|
579
|
-
|
|
992
|
+
set(keyOrData: string | Record<string, unknown> | ServiceMetaEntry, value?: unknown): PayloadInterface;
|
|
993
|
+
data: Record<string, unknown>;
|
|
994
|
+
cacheInfo?: ServiceCacheInfo;
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* Change event object.
|
|
998
|
+
*/
|
|
999
|
+
interface ChangeEvent {
|
|
580
1000
|
/**
|
|
581
|
-
*
|
|
582
|
-
* Supports executing state management: handlers removed during
|
|
583
|
-
* execution are safely handled.
|
|
584
|
-
*
|
|
585
|
-
* @param event - Event name
|
|
586
|
-
* @param data - Event data (type property added automatically)
|
|
587
|
-
* @param remove - Whether to remove all handlers after firing
|
|
588
|
-
* @param lastToFirst - Whether to execute handlers in reverse order
|
|
1001
|
+
* Event type.
|
|
589
1002
|
*/
|
|
590
|
-
|
|
1003
|
+
readonly type: string;
|
|
1004
|
+
/**
|
|
1005
|
+
* Set object of changed data keys, value 1 indicates key has changed.
|
|
1006
|
+
* TODO: Optimize to Set data structure.
|
|
1007
|
+
*/
|
|
1008
|
+
readonly keys?: Readonly<Record<string, 1>>;
|
|
591
1009
|
}
|
|
592
|
-
|
|
593
|
-
/** Mark framework as booted (called from Framework.boot) */
|
|
594
|
-
declare function markBooted(): void;
|
|
595
1010
|
/**
|
|
596
|
-
*
|
|
597
|
-
|
|
1011
|
+
* Event emitter interface providing on/off/fire methods for publish-subscribe pattern.
|
|
1012
|
+
*/
|
|
1013
|
+
interface EventEmitterInterface<T = unknown> {
|
|
1014
|
+
/**
|
|
1015
|
+
* Bind event listener, calls handler when event is triggered.
|
|
1016
|
+
* @param name Event name
|
|
1017
|
+
* @param fn Event handler function
|
|
1018
|
+
*/
|
|
1019
|
+
on(name: string, fn: (this: T, e?: ChangeEvent) => void): EventEmitterInterface<T>;
|
|
1020
|
+
/**
|
|
1021
|
+
* Unbind event listener, removes all handlers for event if no handler function is provided.
|
|
1022
|
+
* @param name Event name
|
|
1023
|
+
* @param fn Optional event handler function, if omitted removes all handlers
|
|
1024
|
+
*/
|
|
1025
|
+
off(name: string, fn?: AnyFunc): EventEmitterInterface<T>;
|
|
1026
|
+
/**
|
|
1027
|
+
* Fire event, executes all bound handlers, automatically adds type property to event data.
|
|
1028
|
+
* Supports removing all handlers after firing.
|
|
1029
|
+
* Supports executing handler list in reverse order.
|
|
1030
|
+
* @param name Event name
|
|
1031
|
+
* @param data Event data object
|
|
1032
|
+
* @param remove Whether to remove all handlers after firing
|
|
1033
|
+
* @param lastToFirst Whether to execute handler list in reverse order
|
|
1034
|
+
*/
|
|
1035
|
+
fire(name: string, data?: Record<string, unknown>, remove?: boolean, lastToFirst?: boolean): EventEmitterInterface<T>;
|
|
1036
|
+
}
|
|
1037
|
+
/**
|
|
1038
|
+
* Global state interface providing cross-view data sharing and data change notification capabilities.
|
|
1039
|
+
* State is a singleton object managing app-level state data via get/set/digest.
|
|
1040
|
+
* Supports `clean()` method to create a mixin for automatic cleanup on view destruction.
|
|
598
1041
|
*/
|
|
599
|
-
|
|
1042
|
+
interface StateInterface extends EventEmitterInterface<StateInterface> {
|
|
1043
|
+
/**
|
|
1044
|
+
* Get data from global state, returns complete state object if key is omitted.
|
|
1045
|
+
* @param key Data key name, omitted returns complete state object
|
|
1046
|
+
*/
|
|
600
1047
|
get<T = unknown>(key?: string): T;
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
1048
|
+
/**
|
|
1049
|
+
* Set global state data.
|
|
1050
|
+
* After set, must explicitly call `digest()` to dispatch changed event and notify views to update.
|
|
1051
|
+
* @param data Data object, e.g., `{ a: 1, b: 2 }`
|
|
1052
|
+
* @param excludes Set of keys to exclude from change tracking
|
|
1053
|
+
*/
|
|
1054
|
+
set(data: Record<string, unknown>, excludes?: Set<string>): this;
|
|
1055
|
+
/**
|
|
1056
|
+
* Clean data for specified keys in State, can only be used in view's mixins.
|
|
1057
|
+
* For example `mixins: [State.clean("a,b")]`.
|
|
1058
|
+
* Keys registered via this method are automatically cleaned when view is destroyed,
|
|
1059
|
+
* and corresponding key reference counts are decremented; data is auto-deleted when count reaches zero.
|
|
1060
|
+
* @param keys Comma-separated key string
|
|
1061
|
+
* @returns Object with make method, called by mixins mechanism
|
|
1062
|
+
*/
|
|
604
1063
|
clean(keys: string): {
|
|
605
1064
|
make: AnyFunc;
|
|
606
1065
|
};
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
/**
|
|
622
|
-
|
|
623
|
-
/**
|
|
624
|
-
|
|
625
|
-
/**
|
|
626
|
-
|
|
627
|
-
/**
|
|
628
|
-
|
|
629
|
-
/**
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
/**
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
/**
|
|
638
|
-
|
|
639
|
-
/**
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
1066
|
+
/**
|
|
1067
|
+
* Detect data changes and dispatch changed event.
|
|
1068
|
+
* After set, must explicitly call `digest()` to dispatch changed event and notify views to update.
|
|
1069
|
+
* @param data Optional data object, if provided calls `set()` first to set data
|
|
1070
|
+
* @param excludes Set of keys to exclude from change tracking
|
|
1071
|
+
*/
|
|
1072
|
+
digest(data?: Record<string, unknown>, excludes?: Set<string>): void;
|
|
1073
|
+
/**
|
|
1074
|
+
* Triggered when state data changes.
|
|
1075
|
+
*/
|
|
1076
|
+
diff: () => Readonly<Record<string, number>>;
|
|
1077
|
+
onChanged?: (e?: ChangeEvent) => void;
|
|
1078
|
+
}
|
|
1079
|
+
interface ServiceOptions {
|
|
1080
|
+
/** Request URL */
|
|
1081
|
+
url: string;
|
|
1082
|
+
/** Request params */
|
|
1083
|
+
params?: Record<string, unknown>;
|
|
1084
|
+
/** HTTP method */
|
|
1085
|
+
method?: "GET" | "POST" | "PUT" | "DELETE" | string;
|
|
1086
|
+
/** Cache: true for default, number for TTL */
|
|
1087
|
+
cache?: boolean | number;
|
|
1088
|
+
/** POST data */
|
|
1089
|
+
data?: unknown;
|
|
1090
|
+
}
|
|
1091
|
+
interface PayloadEntry {
|
|
1092
|
+
/** Payload data */
|
|
1093
|
+
data: Record<string, unknown>;
|
|
1094
|
+
}
|
|
1095
|
+
interface ServiceEntry {
|
|
1096
|
+
/** Service ID */
|
|
1097
|
+
id: string;
|
|
1098
|
+
/** Service URL */
|
|
1099
|
+
url: string;
|
|
1100
|
+
/** Cache time in ms, 0 = no cache */
|
|
1101
|
+
cacheTime: number;
|
|
1102
|
+
/** Payload instance */
|
|
1103
|
+
payload?: PayloadEntry;
|
|
1104
|
+
/** Whether loading */
|
|
1105
|
+
loading?: boolean;
|
|
1106
|
+
/** Error info */
|
|
1107
|
+
error?: Error;
|
|
1108
|
+
}
|
|
1109
|
+
/** Pending cache entry for deduplication (internal to Service) */
|
|
1110
|
+
interface PendingCacheEntry extends Array<unknown> {
|
|
1111
|
+
/** Reference to the pending Payload entity */
|
|
1112
|
+
entity?: unknown;
|
|
1113
|
+
}
|
|
645
1114
|
/**
|
|
646
|
-
*
|
|
647
|
-
*
|
|
648
|
-
*
|
|
1115
|
+
* Endpoint metadata configuration for registering an API endpoint with Service.
|
|
1116
|
+
* Each meta describes endpoint's URL, cache strategy, before/after interceptors, etc.
|
|
649
1117
|
*/
|
|
650
|
-
|
|
651
|
-
/**
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
/**
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
1118
|
+
interface ServiceMetaEntry {
|
|
1119
|
+
/**
|
|
1120
|
+
* Endpoint name,
|
|
1121
|
+
* Unique name for endpoint metadata, must be unique within same Service.
|
|
1122
|
+
*/
|
|
1123
|
+
name: string;
|
|
1124
|
+
/** Request URL, required. */
|
|
1125
|
+
url: string;
|
|
1126
|
+
/**
|
|
1127
|
+
* Cache TTL in ms, 0 = no cache.
|
|
1128
|
+
* Cache validity time in milliseconds.
|
|
1129
|
+
* 0 means no caching.
|
|
1130
|
+
* Greater than 0 means cache TTL, reuse cached data within this time range.
|
|
1131
|
+
*/
|
|
1132
|
+
cache?: number;
|
|
1133
|
+
/**
|
|
1134
|
+
* Before-fetch hook,
|
|
1135
|
+
* Hook function called before request is sent, can process request data.
|
|
1136
|
+
* `this` points to current Payload instance.
|
|
1137
|
+
* @param payload Data carrier for current request
|
|
1138
|
+
*/
|
|
1139
|
+
before?: (this: PayloadInterface, payload: PayloadInterface) => void;
|
|
1140
|
+
/**
|
|
1141
|
+
* After-fetch hook.
|
|
1142
|
+
* Hook function called after request succeeds, before data is passed to view.
|
|
1143
|
+
* Can process response data in this method.
|
|
1144
|
+
* `this` points to current Payload instance.
|
|
1145
|
+
* @param payload Data carrier for current request
|
|
1146
|
+
*/
|
|
1147
|
+
after?: (this: PayloadInterface, payload: PayloadInterface) => void;
|
|
1148
|
+
/** Clean keys on destroy,
|
|
1149
|
+
* Comma-separated endpoint name string for clearing other endpoints' cache.
|
|
1150
|
+
* For example, if an endpoint creates new data,
|
|
1151
|
+
* after successful call, should clear all data-fetching endpoints' cache,
|
|
1152
|
+
* otherwise new data cannot be retrieved.
|
|
1153
|
+
*/
|
|
1154
|
+
cleanKeys?: string;
|
|
1155
|
+
/** Additional properties */
|
|
1156
|
+
[key: string]: unknown;
|
|
1157
|
+
}
|
|
1158
|
+
/** Cache info attached to Payload entity */
|
|
1159
|
+
interface ServiceCacheInfo {
|
|
1160
|
+
/** Endpoint name */
|
|
1161
|
+
name: string;
|
|
1162
|
+
/** After-fetch hook */
|
|
1163
|
+
after?: AnyFunc | undefined;
|
|
1164
|
+
/** Clean keys */
|
|
1165
|
+
cleans?: string | undefined;
|
|
1166
|
+
/** Cache key */
|
|
1167
|
+
key: string;
|
|
1168
|
+
/** Timestamp when cached */
|
|
1169
|
+
time: number;
|
|
1170
|
+
}
|
|
1171
|
+
interface FrameworkInterface {
|
|
1172
|
+
/**
|
|
1173
|
+
* Get or update configuration.
|
|
1174
|
+
* - When passing config object: merges config and returns merged config
|
|
1175
|
+
* - When passing key name: returns config value for that key
|
|
1176
|
+
* - When no arguments: returns complete config object
|
|
1177
|
+
* @param cfg Config object or key name
|
|
1178
|
+
*/
|
|
1179
|
+
config<T extends object = Partial<FrameworkConfig>>(cfg?: Partial<FrameworkConfig> & T): FrameworkConfig & T;
|
|
1180
|
+
config(key: string): unknown;
|
|
1181
|
+
/**
|
|
1182
|
+
* App initialization entry point, starts framework and renders root view.
|
|
1183
|
+
* After invocation: merge config → bind route events → create root Frame → mount default view.
|
|
1184
|
+
* @param cfg Config object
|
|
1185
|
+
*/
|
|
1186
|
+
boot(cfg: FrameworkConfig): void;
|
|
1187
|
+
/**
|
|
1188
|
+
* Convert array to hash map object.
|
|
1189
|
+
* - Simple array: `Framework.toMap([1,2,3])` => `{1:1, 2:1, 3:1}`
|
|
1190
|
+
* - Object array: `Framework.toMap([{id:20},{id:30}], 'id')` => `{20:{id:20}, 30:{id:30}}`
|
|
1191
|
+
* @param list Source array
|
|
1192
|
+
* @param key Use object's key value from array as map key
|
|
1193
|
+
*/
|
|
1194
|
+
toMap<T>(list: T[] | null | undefined, key?: keyof T): Record<string, T | number>;
|
|
1195
|
+
/**
|
|
1196
|
+
* Execute methods in try-catch manner, catches exceptions.
|
|
1197
|
+
* Returns return value of last successfully executed method.
|
|
1198
|
+
* @param fns Function or function array
|
|
1199
|
+
* @param args Arguments array passed to functions
|
|
1200
|
+
* @param context `this` binding during function execution
|
|
1201
|
+
*/
|
|
1202
|
+
toTry(fns: AnyFunc | AnyFunc[], args?: unknown[], context?: unknown): unknown;
|
|
681
1203
|
/**
|
|
682
|
-
*
|
|
1204
|
+
* Convert path and params to URL string.
|
|
1205
|
+
* Example: `Framework.toUrl('/xxx/', {a:'b',c:'d'})` => `/xxx/?a=b&c=d`
|
|
1206
|
+
* @param path Path string
|
|
1207
|
+
* @param params Params object
|
|
1208
|
+
* @param keepEmpty Set of keys to keep empty values
|
|
683
1209
|
*/
|
|
684
|
-
|
|
1210
|
+
toUrl(path: string, params?: Record<string, unknown>, keepEmpty?: Record<string, number>): string;
|
|
685
1211
|
/**
|
|
686
|
-
*
|
|
687
|
-
*
|
|
688
|
-
*
|
|
689
|
-
* Default implementation calls updater.digest() which:
|
|
690
|
-
* 1. Executes the template function with current data
|
|
691
|
-
* 2. Runs VDOM diff against previous DOM
|
|
692
|
-
* 3. Applies DOM operations
|
|
693
|
-
* 4. Calls endUpdate to mount child frames
|
|
694
|
-
*
|
|
1212
|
+
* Parse URL string to path and params object.
|
|
1213
|
+
* Example: `Framework.parseUrl('/xxx/?a=b&c=d')` => `{path:'/xxx/', params:{a:'b',c:'d'}}`
|
|
1214
|
+
* @param url URL string
|
|
695
1215
|
*/
|
|
696
|
-
|
|
697
|
-
on(event: string, handler: AnyFunc): this;
|
|
698
|
-
off(event: string, handler?: AnyFunc): this;
|
|
699
|
-
fire(event: string, data?: Record<string, unknown>, remove?: boolean, lastToFirst?: boolean): this;
|
|
1216
|
+
parseUrl(url: string): ParsedUri;
|
|
700
1217
|
/**
|
|
701
|
-
*
|
|
702
|
-
*
|
|
1218
|
+
* Merge source object properties into target object.
|
|
1219
|
+
* @param target Target object
|
|
1220
|
+
* @param sources One or more source objects
|
|
703
1221
|
*/
|
|
704
|
-
|
|
1222
|
+
mix<T extends object>(target: T, ...sources: Partial<T>[]): T;
|
|
705
1223
|
/**
|
|
706
|
-
*
|
|
707
|
-
*
|
|
1224
|
+
* Check if object has specified own property (safe hasOwnProperty).
|
|
1225
|
+
* @param owner Object to check, supports undefined/null
|
|
1226
|
+
* @param prop Property key name
|
|
708
1227
|
*/
|
|
709
|
-
|
|
1228
|
+
has<T extends object>(owner: T | undefined | null, prop: PropertyKey): boolean;
|
|
710
1229
|
/**
|
|
711
|
-
*
|
|
712
|
-
*
|
|
1230
|
+
* Get enumerable property keys of object as array.
|
|
1231
|
+
* @param src Source object
|
|
713
1232
|
*/
|
|
714
|
-
|
|
1233
|
+
keys<T extends object>(src: T): string[];
|
|
715
1234
|
/**
|
|
716
|
-
*
|
|
717
|
-
*
|
|
1235
|
+
* Check if one DOM node is contained within another.
|
|
1236
|
+
* Returns true if both nodes are the same.
|
|
1237
|
+
* @param node Node or node ID
|
|
1238
|
+
* @param container Container node or node ID
|
|
718
1239
|
*/
|
|
719
|
-
|
|
1240
|
+
inside(node: HTMLElement | string, container: HTMLElement | string): boolean;
|
|
720
1241
|
/**
|
|
721
|
-
*
|
|
722
|
-
*
|
|
1242
|
+
* Shorthand for document.getElementById.
|
|
1243
|
+
* Returns directly if Element is passed.
|
|
1244
|
+
* @param id Node ID or Element object
|
|
723
1245
|
*/
|
|
724
|
-
|
|
1246
|
+
node(id: string | Element | null): Element | null;
|
|
725
1247
|
/**
|
|
726
|
-
*
|
|
727
|
-
*
|
|
728
|
-
*
|
|
1248
|
+
* Ensure DOM element has an ID, auto-generates one if missing.
|
|
1249
|
+
* Returns element's ID.
|
|
1250
|
+
* @param node DOM element object
|
|
729
1251
|
*/
|
|
730
|
-
|
|
1252
|
+
nodeId(node: HTMLElement): string;
|
|
731
1253
|
/**
|
|
732
|
-
*
|
|
733
|
-
*
|
|
1254
|
+
* Load modules using configured module loader.
|
|
1255
|
+
* @param names Module names, supports string or string array
|
|
1256
|
+
* @param callback Callback after modules are loaded
|
|
734
1257
|
*/
|
|
735
|
-
|
|
1258
|
+
use(names: string | string[], callback?: (...modules: unknown[]) => void): void;
|
|
736
1259
|
/**
|
|
737
|
-
*
|
|
1260
|
+
* Protect object from direct modification in debug mode.
|
|
1261
|
+
* Wraps data object with Proxy, intercepts read/write operations, warns to use State.set/digest for state management.
|
|
1262
|
+
* Only effective when `window.__lark_Debug` is true.
|
|
1263
|
+
* @param o Object to protect
|
|
738
1264
|
*/
|
|
739
|
-
|
|
740
|
-
/** Collected ctors from mixins */
|
|
741
|
-
static ctors?: AnyFunc[];
|
|
1265
|
+
guard<T extends object>(o: T): T;
|
|
742
1266
|
/**
|
|
743
|
-
*
|
|
744
|
-
*
|
|
745
|
-
*
|
|
746
|
-
* -
|
|
747
|
-
*
|
|
748
|
-
*
|
|
1267
|
+
* Dynamically inject CSS styles into page. Returns cleanup function to remove injected styles.
|
|
1268
|
+
* Supports single and batch injection.
|
|
1269
|
+
* - `Framework.applyStyle("my-style", "body { color: red; }")` single injection
|
|
1270
|
+
* - `Framework.applyStyle(["style1", "css1", "style2", "css2"])` batch injection
|
|
1271
|
+
* @param styleIdOrPairs Style unique key or [id1, css1, id2, css2, ...] batch array
|
|
1272
|
+
* @param cssText CSS style string (only used when first param is string)
|
|
749
1273
|
*/
|
|
750
|
-
|
|
1274
|
+
applyStyle(styleIdOrPairs: string | string[], cssText?: string): () => void;
|
|
751
1275
|
/**
|
|
752
|
-
*
|
|
1276
|
+
* Generate globally unique identifier (GUID).
|
|
1277
|
+
* @param prefix GUID prefix, defaults to "lark-"
|
|
1278
|
+
*/
|
|
1279
|
+
guid(prefix?: string): string;
|
|
1280
|
+
/**
|
|
1281
|
+
* Create async callback validity marker.
|
|
1282
|
+
* Returns a check function; if host object is unmarked (e.g., view re-rendered), check function returns false, preventing expired async callbacks from executing.
|
|
1283
|
+
* Typical usage: `const check = Framework.mark(this, 'render'); setTimeout(() => { if (check()) ... })`
|
|
1284
|
+
* @param host Host object (usually view instance)
|
|
1285
|
+
* @param key Marker key name (usually "render" or specific async operation identifier)
|
|
1286
|
+
*/
|
|
1287
|
+
mark(host: object, key: string): () => boolean;
|
|
1288
|
+
/**
|
|
1289
|
+
* Delay wait, Promise-based setTimeout wrapper.
|
|
1290
|
+
* @param time Delay time in milliseconds
|
|
1291
|
+
*/
|
|
1292
|
+
delay(time: number): Promise<void>;
|
|
1293
|
+
/**
|
|
1294
|
+
* Whether framework has booted
|
|
1295
|
+
*/
|
|
1296
|
+
isBooted(): boolean;
|
|
1297
|
+
/**
|
|
1298
|
+
* Invalidate (unmark) async callback markers for a host object.
|
|
1299
|
+
* Typically called when a view is re-rendered or destroyed.
|
|
1300
|
+
* @param host The host object whose markers should be invalidated
|
|
1301
|
+
*/
|
|
1302
|
+
unmark(host: object): void;
|
|
1303
|
+
/**
|
|
1304
|
+
* Fire a custom DOM event on a target element.
|
|
1305
|
+
* @param target Target element or EventTarget
|
|
1306
|
+
* @param eventType Event type string
|
|
1307
|
+
* @param eventInit CustomEvent init options
|
|
1308
|
+
*/
|
|
1309
|
+
dispatch(target: EventTarget, eventType: string, eventInit?: CustomEventInit): void;
|
|
1310
|
+
/**
|
|
1311
|
+
* Execute a function in try-catch with chunked scheduling.
|
|
1312
|
+
* @param fn Function to execute
|
|
1313
|
+
* @param args Arguments to pass
|
|
1314
|
+
* @param context `this` context
|
|
1315
|
+
*/
|
|
1316
|
+
task(fn: AnyFunc, args?: unknown[], context?: unknown): void;
|
|
1317
|
+
/**
|
|
1318
|
+
* Wait for all views in a zone to be rendered.
|
|
1319
|
+
* Returns WAIT_OK if rendered, WAIT_TIMEOUT_OR_NOT_FOUND if timeout or not found.
|
|
1320
|
+
* @param viewId Zone view ID
|
|
1321
|
+
* @param timeout Timeout in milliseconds (default: 30000)
|
|
1322
|
+
*/
|
|
1323
|
+
waitZoneViewsRendered(viewId: string, timeout?: number): Promise<number>;
|
|
1324
|
+
/** Wait result: views rendered successfully */
|
|
1325
|
+
WAIT_OK: number;
|
|
1326
|
+
/** Wait result: timeout or view not found */
|
|
1327
|
+
WAIT_TIMEOUT_OR_NOT_FOUND: number;
|
|
1328
|
+
/**
|
|
1329
|
+
* Base class with EventEmitter.
|
|
1330
|
+
* Inherits EventEmitter for use as a base class in the framework.
|
|
1331
|
+
*/
|
|
1332
|
+
Base: typeof EventEmitter;
|
|
1333
|
+
/**
|
|
1334
|
+
* View class.
|
|
1335
|
+
* Use `View.extend()` to create subclasses.
|
|
753
1336
|
*/
|
|
754
|
-
|
|
1337
|
+
View: typeof View;
|
|
1338
|
+
/**
|
|
1339
|
+
* Cache class.
|
|
1340
|
+
* Use `new Cache()` to create cache instances.
|
|
1341
|
+
*/
|
|
1342
|
+
Cache: typeof Cache;
|
|
1343
|
+
/**
|
|
1344
|
+
* Global state object.
|
|
1345
|
+
*/
|
|
1346
|
+
State: StateInterface;
|
|
1347
|
+
/**
|
|
1348
|
+
* Router object.
|
|
1349
|
+
*/
|
|
1350
|
+
Router: RouterInterface;
|
|
1351
|
+
/**
|
|
1352
|
+
* Frame class.
|
|
1353
|
+
* Frame tree for view lifecycle management. Do not extend or instantiate directly.
|
|
1354
|
+
*/
|
|
1355
|
+
Frame: typeof Frame;
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* Framework configuration interface, global config passed to app during `Framework.boot()`.
|
|
1359
|
+
* All config items can be accessed at runtime via `Framework.config('key')`.
|
|
1360
|
+
*/
|
|
1361
|
+
interface FrameworkConfig {
|
|
1362
|
+
/**
|
|
1363
|
+
* Root element ID.
|
|
1364
|
+
* DOM root node ID where root view resides, framework renders root view within this node.
|
|
1365
|
+
* This field is required, defaults to "root".
|
|
1366
|
+
*/
|
|
1367
|
+
rootId: string;
|
|
1368
|
+
/**
|
|
1369
|
+
* Default view path.
|
|
1370
|
+
* Default root view path to load when URL doesn't match any route.
|
|
1371
|
+
*/
|
|
1372
|
+
defaultView?: string;
|
|
1373
|
+
/**
|
|
1374
|
+
* Default path when no hash present,
|
|
1375
|
+
* Path used when URL hash is empty, defaults to "/".
|
|
1376
|
+
*/
|
|
1377
|
+
defaultPath?: string;
|
|
1378
|
+
/**
|
|
1379
|
+
* Route mapping: path -> view.
|
|
1380
|
+
* Mapping relationship between paths and views.
|
|
1381
|
+
* - Simple mapping: `{ "/home": "app/views/home" }`
|
|
1382
|
+
* - Config mapping: `{ "/detail": { view: "app/views/detail", title: "Detail" } }`
|
|
1383
|
+
* Use rewrite config item for path rewriting logic.
|
|
1384
|
+
*/
|
|
1385
|
+
routes?: Record<string, string | RouteViewConfig>;
|
|
1386
|
+
/** Hashbang prefix */
|
|
1387
|
+
hashbang?: string;
|
|
1388
|
+
/**
|
|
1389
|
+
* Error handler.
|
|
1390
|
+
* Global error handling function, framework uses try-catch to execute some core logic.
|
|
1391
|
+
* When errors are thrown, allows developers to catch them via this config item.
|
|
1392
|
+
* Note: Do not re-throw any errors in this method.
|
|
1393
|
+
*/
|
|
1394
|
+
error?: (error: Error) => void;
|
|
1395
|
+
/**
|
|
1396
|
+
* Extensions to load.
|
|
1397
|
+
* Array of extension view paths to load during app startup.
|
|
1398
|
+
* These extension views are loaded before app initialization.
|
|
1399
|
+
*/
|
|
1400
|
+
extensions?: string[];
|
|
1401
|
+
/** Init module to load */
|
|
1402
|
+
initModule?: string;
|
|
1403
|
+
/** Rewrite function for routes */
|
|
1404
|
+
rewrite?: (path: string, params: Record<string, string>, routes: Record<string, string>) => string;
|
|
1405
|
+
/**
|
|
1406
|
+
* Unmatched view (404).
|
|
1407
|
+
* View path to use when no matching view is found in routes, e.g., 404 page.
|
|
1408
|
+
*/
|
|
1409
|
+
unmatchedView?: string;
|
|
1410
|
+
/**
|
|
1411
|
+
* Module require function
|
|
1412
|
+
*/
|
|
1413
|
+
require?: (names: string[], params?: Record<string, unknown>) => Promise<unknown> | undefined;
|
|
1414
|
+
/** Skip view rendered check */
|
|
1415
|
+
skipViewRendered?: boolean;
|
|
1416
|
+
/** Dynamic config access, custom config items */
|
|
1417
|
+
[key: string]: unknown;
|
|
1418
|
+
}
|
|
1419
|
+
interface RouteViewConfig {
|
|
1420
|
+
/** View path */
|
|
1421
|
+
view: string;
|
|
1422
|
+
/** Additional properties merged into location */
|
|
1423
|
+
[key: string]: unknown;
|
|
1424
|
+
}
|
|
1425
|
+
/** Element with VDOM diff cached compare key */
|
|
1426
|
+
interface VdomElement extends Element {
|
|
1427
|
+
/** Whether compare key is cached */
|
|
1428
|
+
compareKeyCached?: number | undefined;
|
|
1429
|
+
/** Cached compare key */
|
|
1430
|
+
cachedCompareKey?: string | undefined;
|
|
1431
|
+
/** Whether auto-generated ID */
|
|
1432
|
+
autoId?: number;
|
|
1433
|
+
}
|
|
1434
|
+
/** Element with frame binding */
|
|
1435
|
+
interface FrameBoundElement extends HTMLElement {
|
|
1436
|
+
/** Frame instance bound to this element */
|
|
1437
|
+
frame?: FrameInterface;
|
|
1438
|
+
/** Whether frame is bound (1 = bound) */
|
|
1439
|
+
frameBound?: number;
|
|
1440
|
+
/** View rendered flag */
|
|
1441
|
+
viewRendered?: number;
|
|
1442
|
+
/** Range frame ID */
|
|
1443
|
+
rangeFrameId?: string;
|
|
1444
|
+
/** Range element guid */
|
|
1445
|
+
rangeElementGuid?: number;
|
|
1446
|
+
}
|
|
1447
|
+
/** Options for compileTemplate() */
|
|
1448
|
+
interface CompileOptions {
|
|
1449
|
+
/** Enable debug mode with line tracking (default: false) */
|
|
1450
|
+
debug?: boolean;
|
|
1451
|
+
/** Global variable names to destructure from $$ (refData) */
|
|
1452
|
+
globalVars?: string[];
|
|
1453
|
+
/** File path for debug error messages (default: undefined) */
|
|
1454
|
+
file?: string;
|
|
755
1455
|
}
|
|
756
1456
|
|
|
757
1457
|
/**
|
|
758
|
-
*
|
|
759
|
-
|
|
1458
|
+
* Lark framework utility functions.
|
|
1459
|
+
*/
|
|
1460
|
+
|
|
1461
|
+
/** Check if value is a plain object (not null, not array, typeof object) */
|
|
1462
|
+
declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
1463
|
+
/** Check if value is primitive or function (not a complex object) */
|
|
1464
|
+
declare function isPrimitiveOrFunc(value: unknown): boolean;
|
|
1465
|
+
/** Check if value is primitive (not object, not function) */
|
|
1466
|
+
declare function isPrimitive(value: unknown): boolean;
|
|
1467
|
+
declare function generateId(prefix?: string): string;
|
|
1468
|
+
/** Sync local counter with global counter */
|
|
1469
|
+
declare function syncCounter(val: number): void;
|
|
1470
|
+
declare function noop(): void;
|
|
1471
|
+
/** Safe hasOwnProperty check */
|
|
1472
|
+
declare function has<T extends object>(owner: T | undefined | null, prop: PropertyKey): boolean;
|
|
1473
|
+
/** Get object keys (own enumerable) */
|
|
1474
|
+
declare function keys<T extends object>(obj: T): string[];
|
|
1475
|
+
/** Assign properties from sources to target (like Object.assign but safer) */
|
|
1476
|
+
declare function assign<T extends object>(target: T, ...sources: Partial<T>[]): T;
|
|
1477
|
+
/**
|
|
1478
|
+
* Execute functions in try-catch, ignoring errors.
|
|
1479
|
+
* Returns the result of the last successfully executed function.
|
|
1480
|
+
*/
|
|
1481
|
+
declare function funcWithTry(fns: AnyFunc | AnyFunc[], args: unknown[], context: unknown, configError?: (e: unknown) => void): unknown;
|
|
1482
|
+
/**
|
|
1483
|
+
* Set newData into oldData, tracking changed keys.
|
|
1484
|
+
* Returns whether any value changed.
|
|
1485
|
+
*/
|
|
1486
|
+
declare function setData(newData: Record<string, unknown>, oldData: Record<string, unknown>, changedKeys: Record<string, number>, excludes: Set<string>): boolean;
|
|
1487
|
+
/**
|
|
1488
|
+
* Translate data references: if a value starts with SPLITTER, replace it
|
|
1489
|
+
* with the corresponding value from the data object.
|
|
1490
|
+
*/
|
|
1491
|
+
declare function translateData(data: object, value: unknown): unknown;
|
|
1492
|
+
/** Get element by ID, or return the element itself if already an element */
|
|
1493
|
+
declare function getById(id: string | Element | null): Element | null;
|
|
1494
|
+
/** Get attribute from element safely */
|
|
1495
|
+
declare function getAttribute(element: Element, attr: string): string;
|
|
1496
|
+
/** Ensure element has an ID, generating one if missing. Returns the ID. */
|
|
1497
|
+
declare function ensureElementId(element: HTMLElement): string;
|
|
1498
|
+
/**
|
|
1499
|
+
* Check if node A is inside node B (or is the same node).
|
|
1500
|
+
* Uses compareDocumentPosition for efficiency.
|
|
1501
|
+
*/
|
|
1502
|
+
declare function nodeInside(a: string | HTMLElement, b: string | HTMLElement): boolean;
|
|
1503
|
+
/**
|
|
1504
|
+
* Parse URI string into path and params object.
|
|
1505
|
+
* e.g. "/xxx/?a=b&c=d" => { path: "/xxx/", params: { a: "b", c: "d" } }
|
|
1506
|
+
*/
|
|
1507
|
+
declare function parseUri(uri: string): ParsedUri;
|
|
1508
|
+
/**
|
|
1509
|
+
* Convert path and params to URI string.
|
|
1510
|
+
* e.g. toUri("/xxx/", { a: "b", c: "d" }) => "/xxx/?a=b&c=d"
|
|
1511
|
+
*/
|
|
1512
|
+
declare function toUri(path: string, params: Record<string, unknown>, keepEmptyObject?: Record<string, number>): string;
|
|
1513
|
+
/**
|
|
1514
|
+
* Convert array to map/hash object.
|
|
1515
|
+
* For simple arrays, counts occurrences.
|
|
1516
|
+
* For object arrays, uses specified key as map key.
|
|
1517
|
+
*/
|
|
1518
|
+
declare function toMap<T>(list: T[] | null | undefined, key?: keyof T): Record<string, T | number>;
|
|
1519
|
+
/** Get current timestamp */
|
|
1520
|
+
declare function now(): number;
|
|
1521
|
+
/** Constructable function type */
|
|
1522
|
+
type Constructable = new (...args: never[]) => unknown;
|
|
1523
|
+
/**
|
|
1524
|
+
* Implement classical inheritance with prototype chain.
|
|
1525
|
+
* This is the only place where we touch constructor internals -
|
|
1526
|
+
* it's a low-level framework utility for View.extend.
|
|
1527
|
+
*/
|
|
1528
|
+
declare function classExtend<Proto extends object, Statics extends object>(make: Constructable, base: Constructable, props: Proto, statics: Statics): void;
|
|
1529
|
+
|
|
1530
|
+
/** Internal splitter character (invisible, used as namespace separator) */
|
|
1531
|
+
declare const SPLITTER = "\u001E";
|
|
1532
|
+
declare const ROUTER_EVENTS: {
|
|
1533
|
+
CHANGE: string;
|
|
1534
|
+
CHANGED: string;
|
|
1535
|
+
PAGE_UNLOAD: string;
|
|
1536
|
+
};
|
|
1537
|
+
/** Attribute name: v-lark */
|
|
1538
|
+
declare const LARK_VIEW = "v-lark";
|
|
1539
|
+
/** View event method regex: e.g. "app\x1eclickHandler(click)" or "clickHandler()"
|
|
1540
|
+
* Group 1: optional frame ID (before SPLITTER)
|
|
1541
|
+
* Group 2: handler name
|
|
1542
|
+
* Group 3: params string
|
|
1543
|
+
*/
|
|
1544
|
+
declare const EVENT_METHOD_REGEXP: RegExp;
|
|
1545
|
+
/** View event method name regex: e.g. "name<click,mousedown>" or "$selector<click>" */
|
|
1546
|
+
declare const VIEW_EVENT_METHOD_REGEXP: RegExp;
|
|
1547
|
+
/** Tag name regexp for I_GetNode */
|
|
1548
|
+
declare const TAG_NAME_REGEXP: RegExp;
|
|
1549
|
+
/** Async task break time (ms) */
|
|
1550
|
+
declare const CALL_BREAK_TIME = 48;
|
|
1551
|
+
/** Increment global counter and return new value */
|
|
1552
|
+
declare function nextCounter(): number;
|
|
1553
|
+
|
|
1554
|
+
/**
|
|
1555
|
+
* Dynamically inject CSS styles into the document head.
|
|
1556
|
+
* Returns a cleanup function to remove the injected styles.
|
|
1557
|
+
*
|
|
1558
|
+
* @param styleIdOrPairs - Style ID string or array of [id, content] pairs
|
|
1559
|
+
* @param css - CSS content string (only used when first arg is string)
|
|
1560
|
+
* @returns Cleanup function to remove the styles
|
|
1561
|
+
*/
|
|
1562
|
+
declare function applyStyle(styleIdOrPairs: string | string[], css?: string): () => void;
|
|
1563
|
+
|
|
1564
|
+
/**
|
|
1565
|
+
* Mark/Unmark: signature-based lifecycle tracking for async callbacks.
|
|
1566
|
+
*
|
|
1567
|
+
* mark() returns a validity checker function. If the host is "unmarked"
|
|
1568
|
+
* (e.g. view re-rendered), the checker returns false, preventing stale callbacks.
|
|
1569
|
+
*/
|
|
1570
|
+
/**
|
|
1571
|
+
* Create a mark for tracking async callback validity.
|
|
1572
|
+
* Returns a function that checks if the mark is still valid.
|
|
1573
|
+
*
|
|
1574
|
+
* @param host - Object to store mark state on (typically a view)
|
|
1575
|
+
* @param key - Key to track (typically "render" or specific async operation)
|
|
1576
|
+
* @returns Checker function that returns true if mark is still valid
|
|
1577
|
+
*/
|
|
1578
|
+
declare function mark$1(host: object, key: string): () => boolean;
|
|
1579
|
+
/**
|
|
1580
|
+
* Clear all marks for a host object, invalidating all existing checkers.
|
|
1581
|
+
* Called when a view re-renders or is destroyed.
|
|
1582
|
+
*
|
|
1583
|
+
* @param host - Object whose marks should be cleared
|
|
1584
|
+
*/
|
|
1585
|
+
declare function unmark$1(host: object): void;
|
|
1586
|
+
|
|
1587
|
+
/**
|
|
1588
|
+
* Safeguard: Proxy-based debug protection for data objects.
|
|
760
1589
|
*
|
|
1590
|
+
* In DEBUG mode, wraps data objects with Proxy to:
|
|
1591
|
+
* 1. Warn when data is read from a different page than where it was set
|
|
1592
|
+
* 2. Prevent direct mutation (forces use of State.set/digest)
|
|
1593
|
+
* 3. Track access patterns for debugging
|
|
761
1594
|
*/
|
|
762
|
-
declare class Frame extends EventEmitter implements FrameLike {
|
|
763
|
-
/** Frame ID (same as owner DOM element ID) */
|
|
764
|
-
readonly id: string;
|
|
765
|
-
/** Parent Frame ID */
|
|
766
|
-
private _parentId;
|
|
767
|
-
get parentId(): string | undefined;
|
|
768
|
-
/** Children map: id -> id */
|
|
769
|
-
childrenMap: FrameChildrenMap;
|
|
770
|
-
/** Children count */
|
|
771
|
-
childrenCount: number;
|
|
772
|
-
/** Ready count (children that have fired 'created') */
|
|
773
|
-
readyCount: number;
|
|
774
|
-
/** Ready map: id -> 1 */
|
|
775
|
-
readyMap: FrameReadyMap;
|
|
776
|
-
/** View instance */
|
|
777
|
-
viewInstance?: ViewInstance;
|
|
778
|
-
/** Get view instance (read-only) */
|
|
779
|
-
get view(): ViewInstance | undefined;
|
|
780
|
-
/** Invoke list for deferred method calls */
|
|
781
|
-
invokeList: FrameInvokeEntry[];
|
|
782
|
-
/** Signature for async operation tracking */
|
|
783
|
-
signature: number;
|
|
784
|
-
/** Whether view has altered */
|
|
785
|
-
hasAltered: number;
|
|
786
|
-
/** Whether view is destroyed */
|
|
787
|
-
destroyed: number;
|
|
788
|
-
/** View path (v-lark attribute value) */
|
|
789
|
-
viewPath?: string;
|
|
790
|
-
/** Original template before mount */
|
|
791
|
-
originalTemplate?: string;
|
|
792
|
-
/** Hold fire created flag */
|
|
793
|
-
holdFireCreated: number;
|
|
794
|
-
/** Children created flag */
|
|
795
|
-
childrenCreated: number;
|
|
796
|
-
/** Children alter flag */
|
|
797
|
-
childrenAlter: number;
|
|
798
|
-
constructor(id: string, parentId?: string);
|
|
799
|
-
/**
|
|
800
|
-
* Mount a view to this frame.
|
|
801
|
-
*
|
|
802
|
-
* Complete flow:
|
|
803
|
-
* 1. Parse viewPath, translate query params from parent
|
|
804
|
-
* 2. Unmount current view
|
|
805
|
-
* 3. Load View class (via require or provided ViewClass)
|
|
806
|
-
* 4. View_Prepare (scan event methods)
|
|
807
|
-
* 5. Create View instance
|
|
808
|
-
* 6. View_DelegateEvents (bind DOM events)
|
|
809
|
-
* 7. Call view.init()
|
|
810
|
-
* 8. If view has template, call render via Updater
|
|
811
|
-
* 9. If no template, call endUpdate directly
|
|
812
|
-
*/
|
|
813
|
-
mountView(viewPath: string, viewInitParams?: Record<string, unknown>): void;
|
|
814
|
-
/**
|
|
815
|
-
* Internal: actually mount the view after class is loaded.
|
|
816
|
-
*/
|
|
817
|
-
doMountView(ViewClass: typeof View, params: Record<string, string>, node: HTMLElement, sign: number): void;
|
|
818
|
-
/**
|
|
819
|
-
* Unmount current view.
|
|
820
|
-
*/
|
|
821
|
-
unmountView(): void;
|
|
822
|
-
/**
|
|
823
|
-
* Mount a child frame.
|
|
824
|
-
*/
|
|
825
|
-
mountFrame(frameId: string, viewPath: string, viewInitParams?: Record<string, unknown>): FrameLike;
|
|
826
|
-
/**
|
|
827
|
-
* Unmount a child frame.
|
|
828
|
-
*/
|
|
829
|
-
unmountFrame(id?: string, _inner?: boolean): void;
|
|
830
|
-
/**
|
|
831
|
-
* Mount all views in a zone.
|
|
832
|
-
*/
|
|
833
|
-
mountZone(zoneId?: string, _inner?: boolean): void;
|
|
834
|
-
/**
|
|
835
|
-
* Unmount all views in a zone.
|
|
836
|
-
*/
|
|
837
|
-
unmountZone(zoneId?: string, _inner?: boolean): void;
|
|
838
|
-
/**
|
|
839
|
-
* Get all child frame IDs.
|
|
840
|
-
*/
|
|
841
|
-
children(): string[];
|
|
842
|
-
/**
|
|
843
|
-
* Get parent frame at given level.
|
|
844
|
-
* @param level - How many levels up (default 1)
|
|
845
|
-
*/
|
|
846
|
-
parent(level?: number): Frame | undefined;
|
|
847
|
-
/**
|
|
848
|
-
* Invoke a method on the view.
|
|
849
|
-
*/
|
|
850
|
-
invoke(name: string, args?: unknown[]): unknown;
|
|
851
|
-
/** Get frame by ID */
|
|
852
|
-
static get(id: string): Frame | undefined;
|
|
853
|
-
/** Get all frames */
|
|
854
|
-
static getAll(): Map<string, Frame>;
|
|
855
|
-
/** Get or create root frame */
|
|
856
|
-
static root(rootId?: string): Frame;
|
|
857
|
-
/** Bind event listener (static) */
|
|
858
|
-
static on(event: string, handler: AnyFunc): typeof Frame;
|
|
859
|
-
/** Unbind event listener (static) */
|
|
860
|
-
static off(event: string, handler?: AnyFunc): typeof Frame;
|
|
861
|
-
/** Fire event (static) */
|
|
862
|
-
static fire(event: string, data?: Record<string, unknown>): void;
|
|
863
|
-
}
|
|
864
1595
|
/**
|
|
865
|
-
*
|
|
866
|
-
*
|
|
1596
|
+
* Wrap data with a Proxy for debug-mode protection.
|
|
1597
|
+
* Only active when window.__lark_Debug is true and Proxy is available.
|
|
1598
|
+
*
|
|
1599
|
+
* @param data - Data to wrap
|
|
1600
|
+
* @param getter - Optional callback when properties are read
|
|
1601
|
+
* @param setter - Optional callback when properties are written
|
|
1602
|
+
* @param isRoot - Whether this is the root data object
|
|
1603
|
+
* @returns Proxied data or original data if debug mode is off
|
|
867
1604
|
*/
|
|
868
|
-
declare function
|
|
1605
|
+
declare function safeguard<T>(data: T, getter?: ((key: string) => void) | null, setter?: ((path: string, value: unknown) => void) | null, isRoot?: boolean): T;
|
|
1606
|
+
|
|
1607
|
+
/** Mark framework as booted (called from Framework.boot) */
|
|
1608
|
+
declare function markBooted(): void;
|
|
1609
|
+
/**
|
|
1610
|
+
* Observable in-memory data object.
|
|
1611
|
+
* Provides get/set/digest/diff/clean methods for cross-view data sharing.
|
|
1612
|
+
*/
|
|
1613
|
+
declare const State: StateInterface;
|
|
1614
|
+
|
|
1615
|
+
/**
|
|
1616
|
+
* Hash-based router with two-phase change confirmation.
|
|
1617
|
+
*
|
|
1618
|
+
* @example
|
|
1619
|
+
* Router.to('/list', { page: 2 });
|
|
1620
|
+
* const loc = Router.parse();
|
|
1621
|
+
* const diff = Router.diff();
|
|
1622
|
+
*/
|
|
1623
|
+
declare const Router: RouterInterface;
|
|
1624
|
+
/** Mark framework as booted (called by Framework.boot) */
|
|
1625
|
+
declare function markRouterBooted(): void;
|
|
869
1626
|
|
|
870
1627
|
/**
|
|
871
1628
|
* Unmount frames within a DOM node.
|
|
872
1629
|
*/
|
|
873
|
-
declare function vdomUnmountFrames(frame:
|
|
1630
|
+
declare function vdomUnmountFrames(frame: FrameInterface, node: ChildNode): void;
|
|
874
1631
|
/**
|
|
875
1632
|
* Parse HTML string into a DOM element.
|
|
876
1633
|
* Handles special elements (table, SVG, MathML) with wrapper elements.
|
|
@@ -892,11 +1649,11 @@ declare function vdomSetAttributes(oldNode: Element, newNode: Element, ref: VDom
|
|
|
892
1649
|
/**
|
|
893
1650
|
* Set child nodes from new parent onto old parent using keyed diff algorithm.
|
|
894
1651
|
*/
|
|
895
|
-
declare function vdomSetChildNodes(oldParent: Element, newParent: Element, ref: VDomRef, frame:
|
|
1652
|
+
declare function vdomSetChildNodes(oldParent: Element, newParent: Element, ref: VDomRef, frame: FrameInterface, keys_?: Record<string, number>): void;
|
|
896
1653
|
/**
|
|
897
1654
|
* Diff two DOM nodes and apply changes.
|
|
898
1655
|
*/
|
|
899
|
-
declare function vdomSetNode(oldNode: ChildNode, newNode: ChildNode, oldParent: Element, ref: VDomRef, frame:
|
|
1656
|
+
declare function vdomSetNode(oldNode: ChildNode, newNode: ChildNode, oldParent: Element, ref: VDomRef, frame: FrameInterface, keys_?: Record<string, number>): void;
|
|
900
1657
|
/**
|
|
901
1658
|
* Create an empty VDomRef for tracking diff operations.
|
|
902
1659
|
*/
|
|
@@ -923,7 +1680,7 @@ declare function encodeQ(v: unknown): string;
|
|
|
923
1680
|
* Manages view-local data with change detection and VDOM diff triggering.
|
|
924
1681
|
*
|
|
925
1682
|
*/
|
|
926
|
-
declare class Updater implements
|
|
1683
|
+
declare class Updater implements UpdaterInterface {
|
|
927
1684
|
/** View ID (same as owner frame ID) */
|
|
928
1685
|
private viewId;
|
|
929
1686
|
/** Current data object */
|
|
@@ -988,257 +1745,199 @@ declare class Updater implements UpdaterLike {
|
|
|
988
1745
|
}
|
|
989
1746
|
|
|
990
1747
|
/**
|
|
991
|
-
*
|
|
1748
|
+
* Payload wraps API response data with convenient access methods.
|
|
992
1749
|
*/
|
|
993
|
-
declare class
|
|
994
|
-
/**
|
|
1750
|
+
declare class Payload implements PayloadInterface {
|
|
1751
|
+
/** Payload data */
|
|
995
1752
|
data: Record<string, unknown>;
|
|
996
1753
|
/** Internal cache info */
|
|
997
1754
|
cacheInfo?: ServiceCacheInfo;
|
|
998
1755
|
constructor(data?: Record<string, unknown>);
|
|
999
|
-
/** Get a value from
|
|
1756
|
+
/** Get a value from payload data */
|
|
1000
1757
|
get<T = unknown>(key: string): T;
|
|
1001
|
-
/** Set a value in
|
|
1002
|
-
set(keyOrData: string | Record<string, unknown> | ServiceMetaEntry, value?: unknown):
|
|
1758
|
+
/** Set a value in payload data */
|
|
1759
|
+
set(keyOrData: string | Record<string, unknown> | ServiceMetaEntry, value?: unknown): PayloadInterface;
|
|
1003
1760
|
}
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1761
|
+
/**
|
|
1762
|
+
* Minimal interface describing what serviceSend actually uses
|
|
1763
|
+
* from a service instance. This avoids coupling to the full
|
|
1764
|
+
* ServiceInterface which mixes instance and static methods.
|
|
1765
|
+
*/
|
|
1766
|
+
interface ServiceSendTarget {
|
|
1767
|
+
destroyed: number;
|
|
1768
|
+
busy: number;
|
|
1769
|
+
internals: {
|
|
1770
|
+
metaList: Record<string, ServiceMetaEntry>;
|
|
1771
|
+
payloadCache: Cache<Payload>;
|
|
1772
|
+
pendingCacheKeys: Record<string, PendingCacheEntry>;
|
|
1773
|
+
syncFn: (payload: Payload, callback: () => void) => void;
|
|
1774
|
+
staticEmitter: EventEmitter;
|
|
1012
1775
|
};
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
extend(newSyncFn: (bag: Bag, callback: () => void) => void, newCacheMax?: number, newCacheBuffer?: number): ServiceConstructor;
|
|
1019
|
-
_internals: ServiceInternals;
|
|
1020
|
-
}
|
|
1021
|
-
interface ServiceInstance {
|
|
1022
|
-
id: string;
|
|
1023
|
-
[key: string]: unknown;
|
|
1024
|
-
_emitter: EventEmitter;
|
|
1025
|
-
_internals: ServiceInternals;
|
|
1026
|
-
_type: ServiceStaticsInternal;
|
|
1027
|
-
all(attrs: string | Record<string, unknown> | (string | Record<string, unknown>)[], done: AnyFunc): ServiceInstance;
|
|
1028
|
-
one(attrs: string | Record<string, unknown> | (string | Record<string, unknown>)[], done: AnyFunc): ServiceInstance;
|
|
1029
|
-
save(attrs: string | Record<string, unknown> | (string | Record<string, unknown>)[], done: AnyFunc): ServiceInstance;
|
|
1030
|
-
enqueue(callback: AnyFunc): ServiceInstance;
|
|
1031
|
-
dequeue(...args: unknown[]): void;
|
|
1032
|
-
destroy(): void;
|
|
1033
|
-
on(event: string, handler: AnyFunc): ServiceInstance;
|
|
1034
|
-
off(event: string, handler?: AnyFunc): ServiceInstance;
|
|
1035
|
-
fire(event: string, data?: Record<string, unknown>): ServiceInstance;
|
|
1036
|
-
}
|
|
1037
|
-
interface ServiceInternals {
|
|
1038
|
-
metas: Record<string, ServiceMetaEntry>;
|
|
1039
|
-
bagCache: Cache<Bag>;
|
|
1040
|
-
pendingCacheKeys: Record<string, PendingCacheEntry>;
|
|
1041
|
-
syncFn: (bag: Bag, callback: () => void) => void;
|
|
1042
|
-
staticEmitter: EventEmitter;
|
|
1043
|
-
}
|
|
1044
|
-
/** Internal type for serviceType object (static methods) */
|
|
1045
|
-
interface ServiceStaticsInternal {
|
|
1046
|
-
add(attrs: ServiceMetaEntry | ServiceMetaEntry[]): void;
|
|
1047
|
-
meta(attrs: string | Record<string, unknown>): ServiceMetaEntry;
|
|
1048
|
-
create(attrs: Record<string, unknown>): Bag;
|
|
1049
|
-
get(attrs: Record<string, unknown>, createNew?: boolean): {
|
|
1050
|
-
entity: Bag;
|
|
1051
|
-
needsUpdate: boolean;
|
|
1776
|
+
type: {
|
|
1777
|
+
get(attrs: Record<string, unknown>, createNew?: boolean): {
|
|
1778
|
+
entity: Payload;
|
|
1779
|
+
needsUpdate: boolean;
|
|
1780
|
+
};
|
|
1052
1781
|
};
|
|
1053
|
-
|
|
1054
|
-
clear(names: string | string[]): void;
|
|
1055
|
-
on(event: string, handler: AnyFunc): void;
|
|
1056
|
-
off(event: string, handler?: AnyFunc): void;
|
|
1057
|
-
fire(event: string, data?: Record<string, unknown>): void;
|
|
1058
|
-
extend(newSyncFn: (bag: Bag, callback: () => void) => void, newCacheMax?: number, newCacheBuffer?: number): ServiceConstructor;
|
|
1782
|
+
enqueue(callback: AnyFunc): unknown;
|
|
1059
1783
|
}
|
|
1060
1784
|
/**
|
|
1061
|
-
*
|
|
1062
|
-
*
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
*
|
|
1068
|
-
*
|
|
1785
|
+
* Service: API request management with caching, deduplication, and queue.
|
|
1786
|
+
*
|
|
1787
|
+
* - Service.extend(syncFn, cacheMax?, cacheBuffer?): creates subclass with sync function
|
|
1788
|
+
* - Service.add(attrs): registers API endpoint metadata
|
|
1789
|
+
* - new Service().all(attrs, done): fetch all, use cache when available
|
|
1790
|
+
* - new Service().one(attrs, done): fetch all, callback on each completion
|
|
1791
|
+
* - new Service().save(attrs, done): fetch all, skip cache (always request)
|
|
1792
|
+
* - enqueue/dequeue: task queue for sequential async operations
|
|
1793
|
+
* - destroy: cancel pending requests
|
|
1069
1794
|
*
|
|
1795
|
+
* Per-type state (metaList, payloadCache, pendingCacheKeys, syncFn, staticEmitter)
|
|
1796
|
+
* is stored as static class properties. When extend() creates a subclass,
|
|
1797
|
+
* each subclass gets its own copies of these static properties, ensuring
|
|
1798
|
+
* isolation between different Service types.
|
|
1070
1799
|
*/
|
|
1071
|
-
declare
|
|
1072
|
-
/**
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
/**
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1800
|
+
declare class Service {
|
|
1801
|
+
/** Service instance ID */
|
|
1802
|
+
id: string;
|
|
1803
|
+
/** Whether service is busy (1 = busy) */
|
|
1804
|
+
busy: number;
|
|
1805
|
+
/** Whether service is destroyed (1 = destroyed) */
|
|
1806
|
+
destroyed: number;
|
|
1807
|
+
/** Task queue for sequential operations */
|
|
1808
|
+
taskQueue: AnyFunc[];
|
|
1809
|
+
/** Previous dequeue arguments */
|
|
1810
|
+
prevArgs: unknown[];
|
|
1811
|
+
/** Instance event emitter */
|
|
1812
|
+
private _emitter;
|
|
1813
|
+
constructor();
|
|
1814
|
+
/** Instance event emitter (public accessor) */
|
|
1815
|
+
get emitter(): EventEmitterInterface;
|
|
1080
1816
|
/**
|
|
1081
|
-
*
|
|
1817
|
+
* Get internals object for serviceSend compatibility.
|
|
1818
|
+
* References per-type static state from the current class.
|
|
1082
1819
|
*/
|
|
1083
|
-
|
|
1820
|
+
get internals(): ServiceSendTarget["internals"];
|
|
1084
1821
|
/**
|
|
1085
|
-
*
|
|
1822
|
+
* Get type reference (the constructor) for serviceSend compatibility.
|
|
1823
|
+
* Static methods like get/create are accessible via the constructor.
|
|
1086
1824
|
*/
|
|
1087
|
-
|
|
1825
|
+
get type(): ServiceSendTarget["type"];
|
|
1088
1826
|
/**
|
|
1089
|
-
*
|
|
1827
|
+
* Fetch all endpoints, callback when all complete.
|
|
1828
|
+
* Uses cache when available.
|
|
1090
1829
|
*/
|
|
1091
|
-
|
|
1092
|
-
};
|
|
1093
|
-
|
|
1094
|
-
/**
|
|
1095
|
-
* Queue a function for deferred, chunked execution.
|
|
1096
|
-
*
|
|
1097
|
-
* @param fn - Function to execute (wrapped in try-catch automatically)
|
|
1098
|
-
* @param args - Arguments array to pass to the function
|
|
1099
|
-
* @param context - `this` context for the function call
|
|
1100
|
-
*/
|
|
1101
|
-
declare function task(fn: AnyFunc, args?: unknown[], context?: unknown): void;
|
|
1102
|
-
/**
|
|
1103
|
-
* Fire a custom DOM event on a target element.
|
|
1104
|
-
*/
|
|
1105
|
-
declare function dispatchEvent(target: EventTarget, eventType: string, eventInit?: CustomEventInit): void;
|
|
1106
|
-
/**
|
|
1107
|
-
* Base class that can be extended by any object needing EventEmitter.
|
|
1108
|
-
*/
|
|
1109
|
-
declare class Base extends EventEmitter {
|
|
1110
|
-
}
|
|
1111
|
-
/**
|
|
1112
|
-
* Load modules via the configured require function.
|
|
1113
|
-
*/
|
|
1114
|
-
declare function use(names: string | string[], callback?: (...modules: unknown[]) => void): void;
|
|
1115
|
-
/**
|
|
1116
|
-
* Wait for all views in a zone to be rendered.
|
|
1117
|
-
*/
|
|
1118
|
-
declare function waitZoneViewsRendered(viewId: string, timeout?: number): Promise<number>;
|
|
1119
|
-
/**
|
|
1120
|
-
* Main framework object.
|
|
1121
|
-
* Provides boot, config, and all global utility methods.
|
|
1122
|
-
*/
|
|
1123
|
-
declare const Framework: {
|
|
1830
|
+
all(attrs: string | Record<string, unknown> | (string | Record<string, unknown>)[], done: AnyFunc): this;
|
|
1124
1831
|
/**
|
|
1125
|
-
*
|
|
1832
|
+
* Fetch all endpoints, callback on each completion.
|
|
1126
1833
|
*/
|
|
1127
|
-
|
|
1834
|
+
one(attrs: string | Record<string, unknown> | (string | Record<string, unknown>)[], done: AnyFunc): this;
|
|
1128
1835
|
/**
|
|
1129
|
-
*
|
|
1836
|
+
* Fetch all endpoints, skip cache (always request).
|
|
1130
1837
|
*/
|
|
1131
|
-
|
|
1132
|
-
/** Whether framework has booted */
|
|
1133
|
-
isBooted(): boolean;
|
|
1134
|
-
/** Mark async callback validity tracker */
|
|
1135
|
-
mark: typeof mark$1;
|
|
1136
|
-
/** Unmark (invalidate) async callbacks */
|
|
1137
|
-
unmark: typeof unmark$1;
|
|
1138
|
-
/** Fire a custom DOM event on a target */
|
|
1139
|
-
dispatch: typeof dispatchEvent;
|
|
1140
|
-
/** Execute function in try-catch, ignoring errors */
|
|
1141
|
-
task: typeof task;
|
|
1142
|
-
/** Promise-based setTimeout */
|
|
1143
|
-
delay(time: number): Promise<void>;
|
|
1144
|
-
/** Load modules via configured require */
|
|
1145
|
-
use: typeof use;
|
|
1146
|
-
/** Wait for zone views to be rendered */
|
|
1147
|
-
waitZoneViewsRendered: typeof waitZoneViewsRendered;
|
|
1148
|
-
WAIT_OK: number;
|
|
1149
|
-
WAIT_TIMEOUT_OR_UNFOUND: number;
|
|
1838
|
+
save(attrs: string | Record<string, unknown> | (string | Record<string, unknown>)[], done: AnyFunc): this;
|
|
1150
1839
|
/**
|
|
1151
|
-
*
|
|
1840
|
+
* Enqueue a task for sequential execution.
|
|
1152
1841
|
*/
|
|
1153
|
-
|
|
1842
|
+
enqueue(callback: AnyFunc): this;
|
|
1154
1843
|
/**
|
|
1155
|
-
*
|
|
1844
|
+
* Dequeue and execute the next task in queue.
|
|
1156
1845
|
*/
|
|
1157
|
-
|
|
1846
|
+
dequeue(...args: unknown[]): void;
|
|
1158
1847
|
/**
|
|
1159
|
-
*
|
|
1848
|
+
* Destroy the service instance.
|
|
1849
|
+
* After destruction, no new requests can be sent.
|
|
1160
1850
|
*/
|
|
1161
|
-
|
|
1851
|
+
destroy(): void;
|
|
1852
|
+
on(event: string, handler: AnyFunc): this;
|
|
1853
|
+
off(event: string, handler?: AnyFunc): this;
|
|
1854
|
+
fire(event: string, data?: Record<string, unknown>): this;
|
|
1855
|
+
/** Per-type metadata registry */
|
|
1856
|
+
static _metaList: Record<string, ServiceMetaEntry>;
|
|
1857
|
+
/** Per-type payload cache (LFU with frequency eviction) */
|
|
1858
|
+
static _payloadCache: Cache<Payload>;
|
|
1859
|
+
/** Per-type pending cache keys for deduplication */
|
|
1860
|
+
static _pendingCacheKeys: Record<string, PendingCacheEntry>;
|
|
1861
|
+
/** Per-type sync function */
|
|
1862
|
+
static _syncFn: (payload: Payload, callback: () => void) => void;
|
|
1863
|
+
/** Per-type static event emitter */
|
|
1864
|
+
static _staticEmitter: EventEmitter<unknown>;
|
|
1865
|
+
/** Per-type cache max size */
|
|
1866
|
+
static _cacheMax: number;
|
|
1867
|
+
/** Per-type cache buffer size */
|
|
1868
|
+
static _cacheBuffer: number;
|
|
1162
1869
|
/**
|
|
1163
|
-
*
|
|
1870
|
+
* Register API endpoint metadata.
|
|
1164
1871
|
*/
|
|
1165
|
-
|
|
1872
|
+
static add(attrs: ServiceMetaEntry | ServiceMetaEntry[]): void;
|
|
1166
1873
|
/**
|
|
1167
|
-
*
|
|
1874
|
+
* Get metadata for an API endpoint.
|
|
1168
1875
|
*/
|
|
1169
|
-
|
|
1876
|
+
static meta(attrs: string | Record<string, unknown>): ServiceMetaEntry;
|
|
1170
1877
|
/**
|
|
1171
|
-
*
|
|
1878
|
+
* Create a Payload for an API request.
|
|
1172
1879
|
*/
|
|
1173
|
-
|
|
1880
|
+
static create(attrs: Record<string, unknown>): Payload;
|
|
1174
1881
|
/**
|
|
1175
|
-
* Get
|
|
1882
|
+
* Get or create a Payload for an API request.
|
|
1176
1883
|
*/
|
|
1177
|
-
|
|
1884
|
+
static get(attrs: Record<string, unknown>, createNew?: boolean): {
|
|
1885
|
+
entity: Payload;
|
|
1886
|
+
needsUpdate: boolean;
|
|
1887
|
+
};
|
|
1178
1888
|
/**
|
|
1179
|
-
*
|
|
1889
|
+
* Get cached Payload if available and not expired.
|
|
1180
1890
|
*/
|
|
1181
|
-
|
|
1891
|
+
static cached(attrs: Record<string, unknown>): Payload | undefined;
|
|
1182
1892
|
/**
|
|
1183
|
-
*
|
|
1893
|
+
* Clear cached payloads by endpoint name.
|
|
1184
1894
|
*/
|
|
1185
|
-
|
|
1895
|
+
static clear(names: string | string[]): void;
|
|
1896
|
+
static on(event: string, handler: AnyFunc): void;
|
|
1897
|
+
static off(event: string, handler?: AnyFunc): void;
|
|
1898
|
+
static fire(event: string, data?: Record<string, unknown>): void;
|
|
1186
1899
|
/**
|
|
1187
|
-
*
|
|
1900
|
+
* Create a new Service subclass with a custom sync function.
|
|
1901
|
+
* Each subclass gets its own per-type state (metaList, cache, etc.)
|
|
1902
|
+
* to ensure isolation between different Service types.
|
|
1188
1903
|
*/
|
|
1189
|
-
|
|
1904
|
+
static extend(newSyncFn: (payload: Payload, callback: () => void) => void, newCacheMax?: number, newCacheBuffer?: number): typeof Service;
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
/**
|
|
1908
|
+
* DOM event delegation system.
|
|
1909
|
+
* Delegates events to document body for performance.
|
|
1910
|
+
*
|
|
1911
|
+
*/
|
|
1912
|
+
declare const EventDelegator: {
|
|
1190
1913
|
/**
|
|
1191
|
-
*
|
|
1914
|
+
* Bind a DOM event type to document body.
|
|
1192
1915
|
*/
|
|
1193
|
-
|
|
1916
|
+
bind(eventType: string, hasSelector?: boolean): void;
|
|
1194
1917
|
/**
|
|
1195
|
-
*
|
|
1918
|
+
* Unbind a DOM event type from document body.
|
|
1196
1919
|
*/
|
|
1197
|
-
|
|
1920
|
+
unbind(eventType: string, hasSelector?: boolean): void;
|
|
1198
1921
|
/**
|
|
1199
|
-
*
|
|
1922
|
+
* Clean up range events for a destroyed view.
|
|
1200
1923
|
*/
|
|
1201
|
-
|
|
1924
|
+
clearRangeEvents(viewId: string): void;
|
|
1202
1925
|
/**
|
|
1203
|
-
*
|
|
1926
|
+
* Set the frame getter function (called by Framework.boot).
|
|
1204
1927
|
*/
|
|
1205
|
-
|
|
1928
|
+
setFrameGetter(getter: (id: string) => FrameInterface | undefined): void;
|
|
1206
1929
|
/**
|
|
1207
|
-
*
|
|
1930
|
+
* Get next element GUID.
|
|
1208
1931
|
*/
|
|
1209
|
-
|
|
1210
|
-
/** Router module */
|
|
1211
|
-
Router: {
|
|
1212
|
-
parse(href?: string): Location;
|
|
1213
|
-
diff(): LocationDiff | undefined;
|
|
1214
|
-
to(pathOrParams: string | Record<string, unknown>, params?: Record<string, unknown>, replace?: boolean, silent?: boolean): void;
|
|
1215
|
-
join(...paths: string[]): string;
|
|
1216
|
-
on(event: string, handler: AnyFunc): typeof Router;
|
|
1217
|
-
off(event: string, handler?: AnyFunc): typeof Router;
|
|
1218
|
-
fire(event: string, data?: Record<string, unknown>, remove?: boolean): typeof Router;
|
|
1219
|
-
_bind(): void;
|
|
1220
|
-
_setConfig(cfg: FrameworkConfig): void;
|
|
1221
|
-
notify?(e?: Event): void;
|
|
1222
|
-
};
|
|
1223
|
-
/** State module */
|
|
1224
|
-
State: {
|
|
1225
|
-
get<T = unknown>(key?: string): T;
|
|
1226
|
-
set(data: Record<string, unknown>, excludes?: Set<string>): typeof State;
|
|
1227
|
-
digest(data?: Record<string, unknown>, excludes?: Set<string>): void;
|
|
1228
|
-
diff(): Readonly<Record<string, number>>;
|
|
1229
|
-
clean(keys: string): {
|
|
1230
|
-
make: AnyFunc;
|
|
1231
|
-
};
|
|
1232
|
-
on(event: string, handler: AnyFunc): typeof State;
|
|
1233
|
-
off(event: string, handler?: AnyFunc): typeof State;
|
|
1234
|
-
fire(event: string, data?: Record<string, unknown>, remove?: boolean): typeof State;
|
|
1235
|
-
};
|
|
1236
|
-
/** View class */
|
|
1237
|
-
View: typeof View;
|
|
1238
|
-
/** Frame class */
|
|
1239
|
-
Frame: typeof Frame;
|
|
1932
|
+
nextElementGuid(): number;
|
|
1240
1933
|
};
|
|
1241
1934
|
|
|
1935
|
+
/**
|
|
1936
|
+
* Main framework object.
|
|
1937
|
+
* Provides boot, config, and all global utility methods.
|
|
1938
|
+
*/
|
|
1939
|
+
declare const Framework: FrameworkInterface;
|
|
1940
|
+
|
|
1242
1941
|
/**
|
|
1243
1942
|
* @lark/framework Store
|
|
1244
1943
|
*
|
|
@@ -1252,8 +1951,6 @@ declare const Framework: {
|
|
|
1252
1951
|
* - cell/observeCell: lightweight standalone reactive cells
|
|
1253
1952
|
*/
|
|
1254
1953
|
|
|
1255
|
-
/** Reactive proxy object — all string keys map to unknown values */
|
|
1256
|
-
type ProxyObject = Record<string, unknown>;
|
|
1257
1954
|
interface Task {
|
|
1258
1955
|
cb: AnyFunc;
|
|
1259
1956
|
params?: Record<string, unknown>;
|
|
@@ -1304,10 +2001,10 @@ declare class Queue {
|
|
|
1304
2001
|
declare const isState: (target: unknown) => boolean;
|
|
1305
2002
|
declare const mark: (host: Record<string, unknown>, key: string) => (() => boolean);
|
|
1306
2003
|
declare const unmark: (host: Record<string, unknown>) => void;
|
|
1307
|
-
declare function createState(initialData: unknown, config?: StateConfig):
|
|
1308
|
-
declare function lazySet(target:
|
|
2004
|
+
declare function createState(initialData: unknown, config?: StateConfig): Record<string, unknown>;
|
|
2005
|
+
declare function lazySet(target: Record<string, unknown>, data: Record<string, unknown>): void;
|
|
1309
2006
|
/** Shallow set: only top-level properties are reactive */
|
|
1310
|
-
declare function shallowSet(target:
|
|
2007
|
+
declare function shallowSet(target: Record<string, unknown>, key: string, data: unknown): unknown;
|
|
1311
2008
|
declare const _storeName: unique symbol;
|
|
1312
2009
|
declare const _storeStatus: unique symbol;
|
|
1313
2010
|
declare const _storeScheduler: unique symbol;
|
|
@@ -1327,10 +2024,10 @@ declare abstract class BaseStore {
|
|
|
1327
2024
|
[_storeScheduler]: Scheduler;
|
|
1328
2025
|
[_originState]: Record<string, unknown>;
|
|
1329
2026
|
[_stateKeys]: string[];
|
|
1330
|
-
[_storeState]:
|
|
2027
|
+
[_storeState]: Record<string, unknown>;
|
|
1331
2028
|
[_storeDefScheduler]: () => Queue;
|
|
1332
2029
|
private [_outerStore];
|
|
1333
|
-
[_storeBoot]():
|
|
2030
|
+
[_storeBoot](): Record<string, unknown>;
|
|
1334
2031
|
[_storeDestroy](): void;
|
|
1335
2032
|
/**
|
|
1336
2033
|
*
|
|
@@ -1339,11 +2036,11 @@ declare abstract class BaseStore {
|
|
|
1339
2036
|
*/
|
|
1340
2037
|
[_storeCreate](body: Record<string, unknown>, excludeFns?: string[]): void;
|
|
1341
2038
|
constructor(name: string, config?: StoreConfig);
|
|
1342
|
-
[_innerStore]():
|
|
2039
|
+
[_innerStore](): Record<string, unknown>;
|
|
1343
2040
|
get status(): StoreStatus;
|
|
1344
2041
|
get storeName(): string;
|
|
1345
2042
|
get scheduler(): Scheduler;
|
|
1346
|
-
[_storeProxy](toOut?: boolean):
|
|
2043
|
+
[_storeProxy](toOut?: boolean): Record<string, unknown>;
|
|
1347
2044
|
}
|
|
1348
2045
|
interface LarkView {
|
|
1349
2046
|
updater: {
|
|
@@ -1384,7 +2081,7 @@ declare function getUseStore(name: string): AnyFunc | undefined;
|
|
|
1384
2081
|
declare function cloneStore(name: string, useStore: AnyFunc, config?: StoreConfig): unknown;
|
|
1385
2082
|
declare function isStoreActive(name: string): boolean;
|
|
1386
2083
|
declare function cell<T = unknown>(data: T): T;
|
|
1387
|
-
declare function observeCell(state:
|
|
2084
|
+
declare function observeCell(state: Record<string, unknown>, cb: AnyFunc, immediate?: boolean): () => void;
|
|
1388
2085
|
declare function multi<S = Record<string, unknown>>(useStore: LarkUseStore<S>): [LarkUseStore<S>, {
|
|
1389
2086
|
make: AnyFunc;
|
|
1390
2087
|
}];
|
|
@@ -1464,9 +2161,9 @@ declare function installFrameVisualizerBridge(): void;
|
|
|
1464
2161
|
* extractGlobalVars() (AST-based global var analysis via @babel/parser)
|
|
1465
2162
|
*
|
|
1466
2163
|
* - All template operators: = (escape), ! (raw), @ (ref lookup), : (binding)
|
|
1467
|
-
* - @event attribute processing with $
|
|
1468
|
-
* - $
|
|
1469
|
-
* - Debug mode with line tracking ($
|
|
2164
|
+
* - @event attribute processing with $splitter prefix + \x1e separator
|
|
2165
|
+
* - $strSafe (null-safe toString), $encHtml (HTML entity encode), $encUri (URI encode), $encQuote (quote encode), $refFn (ref lookup)
|
|
2166
|
+
* - Debug mode with line tracking ($dbgExpr/$dbgArt/$dbgLine) and try-catch error wrapper
|
|
1470
2167
|
* - View ID injection (\x1f → '+$viewId+')
|
|
1471
2168
|
* - Post-processing cleanup of empty concatenations
|
|
1472
2169
|
* - 0 configuration: auto-extract variables via AST analysis
|
|
@@ -1476,25 +2173,17 @@ declare function installFrameVisualizerBridge(): void;
|
|
|
1476
2173
|
* {{:variable}} → two-way binding (same as = for rendering)
|
|
1477
2174
|
* {{!variable}} → raw output (no HTML escaping)
|
|
1478
2175
|
* {{@variable}} → reference lookup for component data passing
|
|
1479
|
-
* {{
|
|
1480
|
-
* {{
|
|
1481
|
-
* {{
|
|
2176
|
+
* {{forOf list as item}} → loop
|
|
2177
|
+
* {{forOf list as item idx}} → loop with index
|
|
2178
|
+
* {{forIn obj as val key}} → object iteration
|
|
1482
2179
|
* {{for(let i=0;i<n;i++)}} → generic for loop
|
|
1483
2180
|
* {{if condition}} → conditional
|
|
1484
2181
|
* {{else if condition}} → else-if
|
|
1485
2182
|
* {{else}} → else
|
|
1486
|
-
* {{/if}} / {{/
|
|
2183
|
+
* {{/if}} / {{/forOf}} / {{/forIn}} / {{/for}} → close blocks
|
|
1487
2184
|
* {{set a = b}} → variable declaration
|
|
1488
2185
|
*/
|
|
1489
|
-
|
|
1490
|
-
interface CompileOptions {
|
|
1491
|
-
/** Enable debug mode with line tracking (default: false) */
|
|
1492
|
-
debug?: boolean;
|
|
1493
|
-
/** Global variable names to destructure from $$ (refData) */
|
|
1494
|
-
globalVars?: string[];
|
|
1495
|
-
/** File path for debug error messages (default: undefined) */
|
|
1496
|
-
file?: string;
|
|
1497
|
-
}
|
|
2186
|
+
|
|
1498
2187
|
/**
|
|
1499
2188
|
* Compile an HTML template string into a JS module string.
|
|
1500
2189
|
* This is the main entry point for both Vite and Webpack loaders.
|
|
@@ -1503,7 +2192,7 @@ interface CompileOptions {
|
|
|
1503
2192
|
* (data, selfId, refData) => string
|
|
1504
2193
|
*
|
|
1505
2194
|
* Internally it calls the compiled template function with the standard
|
|
1506
|
-
* signature: (
|
|
2195
|
+
* signature: ($data,$viewId,$refAlt,$encHtml,$strSafe,$encUri,$refFn,$encQuote)
|
|
1507
2196
|
*
|
|
1508
2197
|
* @param source - The raw HTML template content
|
|
1509
2198
|
* @param options - Compilation options
|
|
@@ -1528,4 +2217,4 @@ declare function compileTemplate(source: string, options?: CompileOptions): stri
|
|
|
1528
2217
|
*/
|
|
1529
2218
|
declare function extractGlobalVars(source: string): string[];
|
|
1530
2219
|
|
|
1531
|
-
export {
|
|
2220
|
+
export { CALL_BREAK_TIME, Cache, type CacheEntry, type CacheOptions, type CompileOptions, type Constructable, EVENT_METHOD_REGEXP, EventDelegator, EventEmitter, type EventListenerEntry, Frame, type FrameBoundElement, type FrameInterface, type FrameInvokeEntry, Framework, type FrameworkConfig, LARK_VIEW, type LarkUseStore, type Location, type LocationDiff, type MixinEventHandler, type NodeUseStore, type ObservePayload, type ParamDiff, type ParsedUri, Payload, type PayloadEntry, type PendingCacheEntry, Platform, ROUTER_EVENTS, type ReactUseStore, type RouteViewConfig, Router, SPLITTER, type SerializedFrameNode, type SerializedFrameTree, type SerializedViewInfo, Service, type ServiceCacheInfo, type ServiceEntry, type ServiceMetaEntry, type ServiceOptions, State, type StoreConfig, type StoreMethods, TAG_NAME_REGEXP, Updater, type UpdaterInterface, type VDomOp, type VDomRef, VIEW_EVENT_METHOD_REGEXP, type VdomElement, View, type ViewEventSelectorEntry, type ViewGlobalEventEntry, type ViewInterface, type ViewLocationObserved, type ViewResourceEntry, applyIdUpdates, applyStyle, applyVdomOps, assign, cell, classExtend, cloneData, cloneStore, compileTemplate, createState, createVdomRef, defineStore, delStore, encodeHTML, encodeQ, encodeSafe, encodeURIExtra, ensureElementId, extractGlobalVars, funcWithTry, generateId, getAttribute, getById, getPlatform, getStore, getUseStore, has, installFrameVisualizerBridge, isPlainObject, isPrimitive, isPrimitiveOrFunc, isState, isStoreActive, keys, lazySet, mark$1 as mark, markBooted, markRouterBooted, multi, nextCounter, nodeInside, noop, now, observeCell, parseUri, registerViewClass, safeguard, serializeFrameTree, setData, shallowSet, mark as storeMark, unmark as storeUnmark, syncCounter, toMap, toUri, translateData, unmark$1 as unmark, vdomGetCompareKey, vdomGetNode, vdomSetAttributes, vdomSetChildNodes, vdomSetNode, vdomSpecialDiff, vdomUnmountFrames };
|