zero-query 0.6.3 → 0.7.5
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 +6 -6
- package/cli/commands/build.js +3 -3
- package/cli/commands/bundle.js +286 -8
- package/cli/commands/dev/index.js +2 -2
- package/cli/commands/dev/overlay.js +51 -2
- package/cli/commands/dev/server.js +34 -5
- package/cli/commands/dev/watcher.js +33 -0
- package/cli/scaffold/index.html +1 -0
- package/cli/scaffold/scripts/app.js +15 -22
- package/cli/scaffold/scripts/components/contacts/contacts.css +0 -7
- package/cli/scaffold/scripts/components/contacts/contacts.html +3 -3
- package/cli/scaffold/styles/styles.css +1 -0
- package/cli/utils.js +111 -6
- package/dist/zquery.dist.zip +0 -0
- package/dist/zquery.js +379 -27
- package/dist/zquery.min.js +3 -16
- package/index.d.ts +127 -1290
- package/package.json +5 -5
- package/src/component.js +11 -1
- package/src/core.js +305 -10
- package/src/router.js +49 -2
- package/tests/component.test.js +304 -0
- package/tests/core.test.js +726 -0
- package/tests/diff.test.js +194 -0
- package/tests/errors.test.js +162 -0
- package/tests/expression.test.js +334 -0
- package/tests/http.test.js +181 -0
- package/tests/reactive.test.js +191 -0
- package/tests/router.test.js +332 -0
- package/tests/store.test.js +253 -0
- package/tests/utils.test.js +353 -0
- package/types/collection.d.ts +368 -0
- package/types/component.d.ts +210 -0
- package/types/errors.d.ts +103 -0
- package/types/http.d.ts +81 -0
- package/types/misc.d.ts +166 -0
- package/types/reactive.d.ts +76 -0
- package/types/router.d.ts +132 -0
- package/types/ssr.d.ts +49 -0
- package/types/store.d.ts +107 -0
- package/types/utils.d.ts +142 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZQueryCollection — chainable DOM element wrapper.
|
|
3
|
+
*
|
|
4
|
+
* Returned by `$()`, `$.all()`, `$.create()`, and many traversal methods.
|
|
5
|
+
* Similar to a jQuery object: wraps an array of elements with fluent methods.
|
|
6
|
+
*
|
|
7
|
+
* @module collection
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Chainable wrapper around an array of DOM elements, similar to a jQuery object.
|
|
12
|
+
* Returned by `$.all()` and many traversal / filtering methods.
|
|
13
|
+
*/
|
|
14
|
+
export class ZQueryCollection {
|
|
15
|
+
/** Number of elements in the collection. */
|
|
16
|
+
readonly length: number;
|
|
17
|
+
|
|
18
|
+
/** Access element by numeric index. */
|
|
19
|
+
readonly [index: number]: Element;
|
|
20
|
+
|
|
21
|
+
constructor(elements: Element | Element[]);
|
|
22
|
+
|
|
23
|
+
// -- Iteration -----------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Iterate over each element. `this` inside the callback is the element.
|
|
27
|
+
* @returns The collection (for chaining).
|
|
28
|
+
*/
|
|
29
|
+
each(fn: (this: Element, index: number, element: Element) => void): this;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Map over elements and return a plain array.
|
|
33
|
+
*/
|
|
34
|
+
map<T>(fn: (this: Element, index: number, element: Element) => T): T[];
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Iterate elements with Array-style `forEach`. Returns `this` for chaining.
|
|
38
|
+
*/
|
|
39
|
+
forEach(fn: (element: Element, index: number, elements: Element[]) => void): this;
|
|
40
|
+
|
|
41
|
+
/** First raw element, or `null`. */
|
|
42
|
+
first(): Element | null;
|
|
43
|
+
|
|
44
|
+
/** Last raw element, or `null`. */
|
|
45
|
+
last(): Element | null;
|
|
46
|
+
|
|
47
|
+
/** New collection containing only the element at `index`. */
|
|
48
|
+
eq(index: number): ZQueryCollection;
|
|
49
|
+
|
|
50
|
+
/** Convert to a plain `Element[]`. */
|
|
51
|
+
toArray(): Element[];
|
|
52
|
+
|
|
53
|
+
/** Iterable protocol — works with `for...of` and spread. */
|
|
54
|
+
[Symbol.iterator](): IterableIterator<Element>;
|
|
55
|
+
|
|
56
|
+
// -- Traversal -----------------------------------------------------------
|
|
57
|
+
|
|
58
|
+
/** Descendants matching `selector`. */
|
|
59
|
+
find(selector: string): ZQueryCollection;
|
|
60
|
+
|
|
61
|
+
/** Unique parent elements. */
|
|
62
|
+
parent(): ZQueryCollection;
|
|
63
|
+
|
|
64
|
+
/** Nearest ancestor matching `selector`. */
|
|
65
|
+
closest(selector: string): ZQueryCollection;
|
|
66
|
+
|
|
67
|
+
/** Direct children, optionally filtered by `selector`. */
|
|
68
|
+
children(selector?: string): ZQueryCollection;
|
|
69
|
+
|
|
70
|
+
/** All sibling elements. */
|
|
71
|
+
siblings(): ZQueryCollection;
|
|
72
|
+
|
|
73
|
+
/** Next sibling of each element, optionally filtered by selector. */
|
|
74
|
+
next(selector?: string): ZQueryCollection;
|
|
75
|
+
|
|
76
|
+
/** Previous sibling of each element, optionally filtered by selector. */
|
|
77
|
+
prev(selector?: string): ZQueryCollection;
|
|
78
|
+
|
|
79
|
+
/** All following siblings, optionally filtered by selector. */
|
|
80
|
+
nextAll(selector?: string): ZQueryCollection;
|
|
81
|
+
|
|
82
|
+
/** Following siblings up to (but not including) the element matching `selector`. */
|
|
83
|
+
nextUntil(selector?: string, filter?: string): ZQueryCollection;
|
|
84
|
+
|
|
85
|
+
/** All preceding siblings, optionally filtered by selector. */
|
|
86
|
+
prevAll(selector?: string): ZQueryCollection;
|
|
87
|
+
|
|
88
|
+
/** Preceding siblings up to (but not including) the element matching `selector`. */
|
|
89
|
+
prevUntil(selector?: string, filter?: string): ZQueryCollection;
|
|
90
|
+
|
|
91
|
+
/** All ancestor elements, optionally filtered by selector (deduplicated). */
|
|
92
|
+
parents(selector?: string): ZQueryCollection;
|
|
93
|
+
|
|
94
|
+
/** Ancestors up to (but not including) the element matching `selector`. */
|
|
95
|
+
parentsUntil(selector?: string, filter?: string): ZQueryCollection;
|
|
96
|
+
|
|
97
|
+
/** All child nodes including text and comment nodes. */
|
|
98
|
+
contents(): ZQueryCollection;
|
|
99
|
+
|
|
100
|
+
// -- Filtering -----------------------------------------------------------
|
|
101
|
+
|
|
102
|
+
/** Keep elements matching a CSS selector or predicate. */
|
|
103
|
+
filter(selector: string): ZQueryCollection;
|
|
104
|
+
filter(fn: (element: Element, index: number) => boolean): ZQueryCollection;
|
|
105
|
+
|
|
106
|
+
/** Remove elements matching a CSS selector or predicate. */
|
|
107
|
+
not(selector: string): ZQueryCollection;
|
|
108
|
+
not(fn: (this: Element, index: number, element: Element) => boolean): ZQueryCollection;
|
|
109
|
+
|
|
110
|
+
/** Keep elements that have a descendant matching `selector`. */
|
|
111
|
+
has(selector: string): ZQueryCollection;
|
|
112
|
+
|
|
113
|
+
/** Check if any element matches the selector or predicate. */
|
|
114
|
+
is(selector: string): boolean;
|
|
115
|
+
is(fn: (this: Element, index: number, element: Element) => boolean): boolean;
|
|
116
|
+
|
|
117
|
+
/** Return a subset of the collection. */
|
|
118
|
+
slice(start: number, end?: number): ZQueryCollection;
|
|
119
|
+
|
|
120
|
+
/** Add elements to the collection, returning a new combined collection. */
|
|
121
|
+
add(selector: string, context?: Element | Document): ZQueryCollection;
|
|
122
|
+
add(element: Element): ZQueryCollection;
|
|
123
|
+
add(collection: ZQueryCollection): ZQueryCollection;
|
|
124
|
+
|
|
125
|
+
/** Retrieve a raw DOM element by index (supports negative). No args → array of all elements. */
|
|
126
|
+
get(): Element[];
|
|
127
|
+
get(index: number): Element | undefined;
|
|
128
|
+
|
|
129
|
+
/** Position of the first element among its siblings, or index of a given element/selector in the collection. */
|
|
130
|
+
index(selector?: string | Element): number;
|
|
131
|
+
|
|
132
|
+
// -- Classes -------------------------------------------------------------
|
|
133
|
+
|
|
134
|
+
/** Add one or more classes (space-separated strings accepted). */
|
|
135
|
+
addClass(...names: string[]): this;
|
|
136
|
+
|
|
137
|
+
/** Remove one or more classes. */
|
|
138
|
+
removeClass(...names: string[]): this;
|
|
139
|
+
|
|
140
|
+
/** Toggle one or more classes (space-separated strings accepted). Optional trailing `force` boolean. */
|
|
141
|
+
toggleClass(...names: Array<string | boolean>): this;
|
|
142
|
+
|
|
143
|
+
/** Check whether the first element has the given class. */
|
|
144
|
+
hasClass(name: string): boolean;
|
|
145
|
+
|
|
146
|
+
// -- Attributes & Properties ---------------------------------------------
|
|
147
|
+
|
|
148
|
+
/** Get attribute value of the first element. */
|
|
149
|
+
attr(name: string): string | null;
|
|
150
|
+
/** Set attribute on all elements. */
|
|
151
|
+
attr(name: string, value: string): this;
|
|
152
|
+
|
|
153
|
+
/** Remove attribute from all elements. */
|
|
154
|
+
removeAttr(name: string): this;
|
|
155
|
+
|
|
156
|
+
/** Get JS property of the first element. */
|
|
157
|
+
prop(name: string): any;
|
|
158
|
+
/** Set JS property on all elements. */
|
|
159
|
+
prop(name: string, value: any): this;
|
|
160
|
+
|
|
161
|
+
/** Get data attribute value (JSON auto-parsed). No key → full dataset. */
|
|
162
|
+
data(): DOMStringMap;
|
|
163
|
+
data(key: string): any;
|
|
164
|
+
/** Set data attribute on all elements. Objects are JSON-stringified. */
|
|
165
|
+
data(key: string, value: any): this;
|
|
166
|
+
|
|
167
|
+
// -- CSS & Dimensions ----------------------------------------------------
|
|
168
|
+
|
|
169
|
+
/** Get computed style property of the first element, or `undefined` if empty. */
|
|
170
|
+
css(property: string): string | undefined;
|
|
171
|
+
/** Set inline styles on all elements. */
|
|
172
|
+
css(props: Partial<CSSStyleDeclaration>): this;
|
|
173
|
+
|
|
174
|
+
/** First element's width (from `getBoundingClientRect`). */
|
|
175
|
+
width(): number | undefined;
|
|
176
|
+
|
|
177
|
+
/** First element's height. */
|
|
178
|
+
height(): number | undefined;
|
|
179
|
+
|
|
180
|
+
/** Position relative to the document. */
|
|
181
|
+
offset(): { top: number; left: number; width: number; height: number } | null;
|
|
182
|
+
|
|
183
|
+
/** Position relative to the offset parent. */
|
|
184
|
+
position(): { top: number; left: number } | null;
|
|
185
|
+
|
|
186
|
+
/** Get vertical scroll position of the first element. */
|
|
187
|
+
scrollTop(): number | undefined;
|
|
188
|
+
/** Set vertical scroll position on all elements. */
|
|
189
|
+
scrollTop(value: number): this;
|
|
190
|
+
|
|
191
|
+
/** Get horizontal scroll position of the first element. */
|
|
192
|
+
scrollLeft(): number | undefined;
|
|
193
|
+
/** Set horizontal scroll position on all elements. */
|
|
194
|
+
scrollLeft(value: number): this;
|
|
195
|
+
|
|
196
|
+
/** Width including padding (clientWidth). */
|
|
197
|
+
innerWidth(): number | undefined;
|
|
198
|
+
|
|
199
|
+
/** Height including padding (clientHeight). */
|
|
200
|
+
innerHeight(): number | undefined;
|
|
201
|
+
|
|
202
|
+
/** Width including padding + border. Pass `true` to include margin. */
|
|
203
|
+
outerWidth(includeMargin?: boolean): number | undefined;
|
|
204
|
+
|
|
205
|
+
/** Height including padding + border. Pass `true` to include margin. */
|
|
206
|
+
outerHeight(includeMargin?: boolean): number | undefined;
|
|
207
|
+
|
|
208
|
+
// -- Content -------------------------------------------------------------
|
|
209
|
+
|
|
210
|
+
/** Get `innerHTML` of the first element, or `undefined` if empty. */
|
|
211
|
+
html(): string | undefined;
|
|
212
|
+
/** Set `innerHTML` on all elements. */
|
|
213
|
+
html(content: string): this;
|
|
214
|
+
|
|
215
|
+
/** Get `textContent` of the first element, or `undefined` if empty. */
|
|
216
|
+
text(): string | undefined;
|
|
217
|
+
/** Set `textContent` on all elements. */
|
|
218
|
+
text(content: string): this;
|
|
219
|
+
|
|
220
|
+
/** Get value of the first input/select/textarea, or `undefined` if empty. */
|
|
221
|
+
val(): string | undefined;
|
|
222
|
+
/** Set value on all inputs. */
|
|
223
|
+
val(value: string): this;
|
|
224
|
+
|
|
225
|
+
// -- DOM Manipulation ----------------------------------------------------
|
|
226
|
+
|
|
227
|
+
/** Insert content at the end of each element. */
|
|
228
|
+
append(content: string | Node | ZQueryCollection): this;
|
|
229
|
+
|
|
230
|
+
/** Insert content at the beginning of each element. */
|
|
231
|
+
prepend(content: string | Node): this;
|
|
232
|
+
|
|
233
|
+
/** Insert content after each element. */
|
|
234
|
+
after(content: string | Node): this;
|
|
235
|
+
|
|
236
|
+
/** Insert content before each element. */
|
|
237
|
+
before(content: string | Node): this;
|
|
238
|
+
|
|
239
|
+
/** Wrap each element with the given HTML string or Node. */
|
|
240
|
+
wrap(wrapper: string | Node): this;
|
|
241
|
+
|
|
242
|
+
/** Remove all elements from the DOM. */
|
|
243
|
+
remove(): this;
|
|
244
|
+
|
|
245
|
+
/** Clear `innerHTML` of all elements. */
|
|
246
|
+
empty(): this;
|
|
247
|
+
|
|
248
|
+
/** Clone elements (default: deep clone). */
|
|
249
|
+
clone(deep?: boolean): ZQueryCollection;
|
|
250
|
+
|
|
251
|
+
/** Replace elements with new content. */
|
|
252
|
+
replaceWith(content: string | Node): this;
|
|
253
|
+
|
|
254
|
+
/** Insert every element in the collection at the end of the target. */
|
|
255
|
+
appendTo(target: string | Element | ZQueryCollection): this;
|
|
256
|
+
|
|
257
|
+
/** Insert every element in the collection at the beginning of the target. */
|
|
258
|
+
prependTo(target: string | Element | ZQueryCollection): this;
|
|
259
|
+
|
|
260
|
+
/** Insert every element in the collection after the target. */
|
|
261
|
+
insertAfter(target: string | Element | ZQueryCollection): this;
|
|
262
|
+
|
|
263
|
+
/** Insert every element in the collection before the target. */
|
|
264
|
+
insertBefore(target: string | Element | ZQueryCollection): this;
|
|
265
|
+
|
|
266
|
+
/** Replace the target elements with the collection's elements. */
|
|
267
|
+
replaceAll(target: string | Element | ZQueryCollection): this;
|
|
268
|
+
|
|
269
|
+
/** Remove the parent of each element, optionally only if it matches `selector`. */
|
|
270
|
+
unwrap(selector?: string): this;
|
|
271
|
+
|
|
272
|
+
/** Wrap all elements together in a single wrapper. */
|
|
273
|
+
wrapAll(wrapper: string | Element): this;
|
|
274
|
+
|
|
275
|
+
/** Wrap the inner contents of each element with the given wrapper. */
|
|
276
|
+
wrapInner(wrapper: string | Element): this;
|
|
277
|
+
|
|
278
|
+
/** Remove all elements from the DOM (alias for `remove`). */
|
|
279
|
+
detach(): this;
|
|
280
|
+
|
|
281
|
+
// -- Visibility ----------------------------------------------------------
|
|
282
|
+
|
|
283
|
+
/** Show elements. Optional display value (default: `''`). */
|
|
284
|
+
show(display?: string): this;
|
|
285
|
+
|
|
286
|
+
/** Set `display: none` on all elements. */
|
|
287
|
+
hide(): this;
|
|
288
|
+
|
|
289
|
+
/** Toggle visibility. */
|
|
290
|
+
toggle(display?: string): this;
|
|
291
|
+
|
|
292
|
+
// -- Events --------------------------------------------------------------
|
|
293
|
+
|
|
294
|
+
/** Attach event handler. Space-separated events accepted. */
|
|
295
|
+
on(events: string, handler: (event: Event) => void): this;
|
|
296
|
+
/** Delegated event handler. */
|
|
297
|
+
on(events: string, selector: string, handler: (this: Element, event: Event) => void): this;
|
|
298
|
+
|
|
299
|
+
/** Remove event handler. */
|
|
300
|
+
off(events: string, handler: (event: Event) => void): this;
|
|
301
|
+
|
|
302
|
+
/** One-time event handler. */
|
|
303
|
+
one(event: string, handler: (event: Event) => void): this;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Dispatch a `CustomEvent` with optional detail payload.
|
|
307
|
+
* Bubbles by default.
|
|
308
|
+
*/
|
|
309
|
+
trigger(event: string, detail?: any): this;
|
|
310
|
+
|
|
311
|
+
/** Attach click handler, or trigger a click when called with no arguments. */
|
|
312
|
+
click(fn?: (event: Event) => void): this;
|
|
313
|
+
|
|
314
|
+
/** Attach submit handler, or trigger submit when called with no arguments. */
|
|
315
|
+
submit(fn?: (event: Event) => void): this;
|
|
316
|
+
|
|
317
|
+
/** Focus the first element. */
|
|
318
|
+
focus(): this;
|
|
319
|
+
|
|
320
|
+
/** Blur the first element. */
|
|
321
|
+
blur(): this;
|
|
322
|
+
|
|
323
|
+
/** Bind mouseenter and mouseleave handlers. If only one function is provided, it's used for both. */
|
|
324
|
+
hover(enterFn: (event: Event) => void, leaveFn?: (event: Event) => void): this;
|
|
325
|
+
|
|
326
|
+
// -- Animation -----------------------------------------------------------
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* CSS transition animation.
|
|
330
|
+
* @param props CSS properties to animate to.
|
|
331
|
+
* @param duration Duration in ms (default 300).
|
|
332
|
+
* @param easing CSS easing function (default `'ease'`).
|
|
333
|
+
*/
|
|
334
|
+
animate(
|
|
335
|
+
props: Partial<CSSStyleDeclaration>,
|
|
336
|
+
duration?: number,
|
|
337
|
+
easing?: string,
|
|
338
|
+
): Promise<ZQueryCollection>;
|
|
339
|
+
|
|
340
|
+
/** Fade in (opacity 0→1). Default 300 ms. */
|
|
341
|
+
fadeIn(duration?: number): Promise<ZQueryCollection>;
|
|
342
|
+
|
|
343
|
+
/** Fade out (opacity 1→0) then hide. Default 300 ms. */
|
|
344
|
+
fadeOut(duration?: number): Promise<ZQueryCollection>;
|
|
345
|
+
|
|
346
|
+
/** Toggle fade in/out. Default 300 ms. */
|
|
347
|
+
fadeToggle(duration?: number): Promise<ZQueryCollection>;
|
|
348
|
+
|
|
349
|
+
/** Fade to a specific opacity. */
|
|
350
|
+
fadeTo(duration: number, opacity: number): Promise<ZQueryCollection>;
|
|
351
|
+
|
|
352
|
+
/** Slide down (reveal). Default 300 ms. */
|
|
353
|
+
slideDown(duration?: number): this;
|
|
354
|
+
|
|
355
|
+
/** Slide up (hide). Default 300 ms. */
|
|
356
|
+
slideUp(duration?: number): this;
|
|
357
|
+
|
|
358
|
+
/** Toggle height with a slide animation. Default 300 ms. */
|
|
359
|
+
slideToggle(duration?: number): this;
|
|
360
|
+
|
|
361
|
+
// -- Form Helpers --------------------------------------------------------
|
|
362
|
+
|
|
363
|
+
/** URL-encoded form data string. */
|
|
364
|
+
serialize(): string;
|
|
365
|
+
|
|
366
|
+
/** Form data as key/value object. Duplicate keys become arrays. */
|
|
367
|
+
serializeObject(): Record<string, string | string[]>;
|
|
368
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component system — define, mount, and manage reactive components.
|
|
3
|
+
*
|
|
4
|
+
* @module component
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ReactiveProxy } from './reactive';
|
|
8
|
+
import type { NavigationContext } from './router';
|
|
9
|
+
|
|
10
|
+
/** Item in a `pages` config — either a string id or an `{ id, label }` object. */
|
|
11
|
+
export type PageItem = string | { id: string; label?: string };
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Declarative multi-page configuration for a component.
|
|
15
|
+
*
|
|
16
|
+
* Pages are **lazy-loaded**: only the active page is fetched on first render.
|
|
17
|
+
* Remaining pages are prefetched in the background for instant navigation.
|
|
18
|
+
*/
|
|
19
|
+
export interface PagesConfig {
|
|
20
|
+
/** Directory containing the page HTML files (resolved relative to `base`). */
|
|
21
|
+
dir?: string;
|
|
22
|
+
/** Route parameter name to read (e.g. `'section'` for `/docs/:section`). */
|
|
23
|
+
param?: string;
|
|
24
|
+
/** Default page id when the param is absent. */
|
|
25
|
+
default?: string;
|
|
26
|
+
/** File extension appended to each page id (default `'.html'`). */
|
|
27
|
+
ext?: string;
|
|
28
|
+
/** List of page ids and/or `{ id, label }` objects. */
|
|
29
|
+
items?: PageItem[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The object passed to `$.component()` to define a component. */
|
|
33
|
+
export interface ComponentDefinition {
|
|
34
|
+
/**
|
|
35
|
+
* Initial reactive state.
|
|
36
|
+
* A function form is recommended so each instance gets its own copy.
|
|
37
|
+
*/
|
|
38
|
+
state?: Record<string, any> | (() => Record<string, any>);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Returns an HTML string. Called on every state change.
|
|
42
|
+
* `this` is the component instance.
|
|
43
|
+
*/
|
|
44
|
+
render?(this: ComponentInstance): string;
|
|
45
|
+
|
|
46
|
+
/** CSS string — scoped to the component root on first render. */
|
|
47
|
+
styles?: string;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* URL (or array / object map of URLs) to external HTML template file(s).
|
|
51
|
+
* If `render()` is also defined, `render()` takes priority.
|
|
52
|
+
*/
|
|
53
|
+
templateUrl?: string | string[] | Record<string, string>;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* URL (or array of URLs) to external CSS file(s).
|
|
57
|
+
* Fetched and auto-scoped on first mount; merged with `styles` if both present.
|
|
58
|
+
*/
|
|
59
|
+
styleUrl?: string | string[];
|
|
60
|
+
|
|
61
|
+
/** High-level multi-page configuration shorthand. */
|
|
62
|
+
pages?: PagesConfig;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Override the base path for resolving relative `templateUrl`, `styleUrl`,
|
|
66
|
+
* and `pages.dir` paths. Normally auto-detected from the calling file.
|
|
67
|
+
*/
|
|
68
|
+
base?: string;
|
|
69
|
+
|
|
70
|
+
/** Called before first render (during construction). */
|
|
71
|
+
init?(this: ComponentInstance): void;
|
|
72
|
+
|
|
73
|
+
/** Called once after first render and DOM insertion. */
|
|
74
|
+
mounted?(this: ComponentInstance): void;
|
|
75
|
+
|
|
76
|
+
/** Called after every subsequent re-render. */
|
|
77
|
+
updated?(this: ComponentInstance): void;
|
|
78
|
+
|
|
79
|
+
/** Called when the component is destroyed. Clean up subscriptions here. */
|
|
80
|
+
destroyed?(this: ComponentInstance): void;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Computed properties — lazy getters derived from state.
|
|
84
|
+
* Each function receives the raw state as its argument.
|
|
85
|
+
* Access via `this.computed.name` in methods and templates.
|
|
86
|
+
*/
|
|
87
|
+
computed?: Record<string, (state: Record<string, any>) => any>;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Watch state keys for changes.
|
|
91
|
+
* Keys support dot-path notation (e.g. `'user.name'`).
|
|
92
|
+
* Handler receives `(newValue, oldValue)`.
|
|
93
|
+
*/
|
|
94
|
+
watch?: Record<
|
|
95
|
+
string,
|
|
96
|
+
| ((this: ComponentInstance, newVal: any, oldVal: any) => void)
|
|
97
|
+
| { handler: (this: ComponentInstance, newVal: any, oldVal: any) => void }
|
|
98
|
+
>;
|
|
99
|
+
|
|
100
|
+
/** Additional keys become instance methods (bound to the instance). */
|
|
101
|
+
[method: string]: any;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The runtime instance of a mounted component. */
|
|
105
|
+
export interface ComponentInstance {
|
|
106
|
+
/** Reactive state proxy. Mutating triggers re-render. */
|
|
107
|
+
state: Record<string, any> & ReactiveProxy;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Frozen props passed from parent / router.
|
|
111
|
+
* When mounted by the router, includes `$route`, `$query`, and `$params`.
|
|
112
|
+
*/
|
|
113
|
+
readonly props: Readonly<
|
|
114
|
+
Record<string, any> & {
|
|
115
|
+
$route?: NavigationContext;
|
|
116
|
+
$query?: Record<string, string>;
|
|
117
|
+
$params?: Record<string, string>;
|
|
118
|
+
}
|
|
119
|
+
>;
|
|
120
|
+
|
|
121
|
+
/** Map of `z-ref` name → DOM element. Populated after each render. */
|
|
122
|
+
refs: Record<string, Element>;
|
|
123
|
+
|
|
124
|
+
/** Keyed template map (when using multi-`templateUrl` or `pages`). */
|
|
125
|
+
templates: Record<string, string>;
|
|
126
|
+
|
|
127
|
+
/** Normalized page metadata (when using `pages` config). */
|
|
128
|
+
pages: Array<{ id: string; label: string }>;
|
|
129
|
+
|
|
130
|
+
/** Active page id derived from route param (when using `pages` config). */
|
|
131
|
+
activePage: string;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Computed properties — lazy getters derived from state.
|
|
135
|
+
* Defined via `computed` in the component definition.
|
|
136
|
+
*/
|
|
137
|
+
readonly computed: Record<string, any>;
|
|
138
|
+
|
|
139
|
+
/** Merge partial state (triggers re-render). */
|
|
140
|
+
setState(partial: Record<string, any>): void;
|
|
141
|
+
|
|
142
|
+
/** Dispatch a bubbling `CustomEvent` from the component root. */
|
|
143
|
+
emit(name: string, detail?: any): void;
|
|
144
|
+
|
|
145
|
+
/** Teardown: removes listeners, scoped styles, clears DOM. */
|
|
146
|
+
destroy(): void;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Manually queue a re-render (microtask-batched).
|
|
150
|
+
* Safe to call from anywhere — state mutations during render are coalesced.
|
|
151
|
+
*/
|
|
152
|
+
_scheduleUpdate(): void;
|
|
153
|
+
|
|
154
|
+
/** Any user-defined methods from the component definition. */
|
|
155
|
+
[method: string]: any;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Register a new component.
|
|
160
|
+
* @param name Must contain a hyphen (Web Component convention).
|
|
161
|
+
* @param definition Component definition object.
|
|
162
|
+
*/
|
|
163
|
+
export function component(name: string, definition: ComponentDefinition): void;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Mount a registered component into a target element.
|
|
167
|
+
* @returns The component instance.
|
|
168
|
+
*/
|
|
169
|
+
export function mount(
|
|
170
|
+
target: string | Element,
|
|
171
|
+
componentName: string,
|
|
172
|
+
props?: Record<string, any>,
|
|
173
|
+
): ComponentInstance;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Scan `root` for elements whose tag matches a registered component and mount them.
|
|
177
|
+
* @param root Defaults to `document.body`.
|
|
178
|
+
*/
|
|
179
|
+
export function mountAll(root?: Element): void;
|
|
180
|
+
|
|
181
|
+
/** Get the component instance mounted on `target`. */
|
|
182
|
+
export function getInstance(target: string | Element): ComponentInstance | null;
|
|
183
|
+
|
|
184
|
+
/** Destroy the component at the given target. */
|
|
185
|
+
export function destroy(target: string | Element): void;
|
|
186
|
+
|
|
187
|
+
/** Returns an object of all registered component definitions (for debugging). */
|
|
188
|
+
export function getRegistry(): Record<string, ComponentDefinition>;
|
|
189
|
+
|
|
190
|
+
/** Handle returned by `$.style()`. */
|
|
191
|
+
export interface StyleHandle {
|
|
192
|
+
/** Remove all injected `<link>` elements. */
|
|
193
|
+
remove(): void;
|
|
194
|
+
/** Resolves when all stylesheets have loaded. */
|
|
195
|
+
ready: Promise<void>;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Options for `$.style()`. */
|
|
199
|
+
export interface StyleOptions {
|
|
200
|
+
/** Hide page until loaded to prevent FOUC (default `true`). */
|
|
201
|
+
critical?: boolean;
|
|
202
|
+
/** Background color while hidden during critical load (default `'#0d1117'`). */
|
|
203
|
+
bg?: string;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Dynamically load global (unscoped) stylesheet file(s) into `<head>`.
|
|
208
|
+
* Relative paths resolve relative to the calling file.
|
|
209
|
+
*/
|
|
210
|
+
export function style(urls: string | string[], opts?: StyleOptions): StyleHandle;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured error handling — error codes, error class, and global handler.
|
|
3
|
+
*
|
|
4
|
+
* @module errors
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** All structured error codes used by zQuery. */
|
|
8
|
+
export declare const ErrorCode: {
|
|
9
|
+
// Reactive
|
|
10
|
+
readonly REACTIVE_CALLBACK: 'ZQ_REACTIVE_CALLBACK';
|
|
11
|
+
readonly SIGNAL_CALLBACK: 'ZQ_SIGNAL_CALLBACK';
|
|
12
|
+
readonly EFFECT_EXEC: 'ZQ_EFFECT_EXEC';
|
|
13
|
+
|
|
14
|
+
// Expression parser
|
|
15
|
+
readonly EXPR_PARSE: 'ZQ_EXPR_PARSE';
|
|
16
|
+
readonly EXPR_EVAL: 'ZQ_EXPR_EVAL';
|
|
17
|
+
readonly EXPR_UNSAFE_ACCESS: 'ZQ_EXPR_UNSAFE_ACCESS';
|
|
18
|
+
|
|
19
|
+
// Component
|
|
20
|
+
readonly COMP_INVALID_NAME: 'ZQ_COMP_INVALID_NAME';
|
|
21
|
+
readonly COMP_NOT_FOUND: 'ZQ_COMP_NOT_FOUND';
|
|
22
|
+
readonly COMP_MOUNT_TARGET: 'ZQ_COMP_MOUNT_TARGET';
|
|
23
|
+
readonly COMP_RENDER: 'ZQ_COMP_RENDER';
|
|
24
|
+
readonly COMP_LIFECYCLE: 'ZQ_COMP_LIFECYCLE';
|
|
25
|
+
readonly COMP_RESOURCE: 'ZQ_COMP_RESOURCE';
|
|
26
|
+
readonly COMP_DIRECTIVE: 'ZQ_COMP_DIRECTIVE';
|
|
27
|
+
|
|
28
|
+
// Router
|
|
29
|
+
readonly ROUTER_LOAD: 'ZQ_ROUTER_LOAD';
|
|
30
|
+
readonly ROUTER_GUARD: 'ZQ_ROUTER_GUARD';
|
|
31
|
+
readonly ROUTER_RESOLVE: 'ZQ_ROUTER_RESOLVE';
|
|
32
|
+
|
|
33
|
+
// Store
|
|
34
|
+
readonly STORE_ACTION: 'ZQ_STORE_ACTION';
|
|
35
|
+
readonly STORE_MIDDLEWARE: 'ZQ_STORE_MIDDLEWARE';
|
|
36
|
+
readonly STORE_SUBSCRIBE: 'ZQ_STORE_SUBSCRIBE';
|
|
37
|
+
|
|
38
|
+
// HTTP
|
|
39
|
+
readonly HTTP_REQUEST: 'ZQ_HTTP_REQUEST';
|
|
40
|
+
readonly HTTP_TIMEOUT: 'ZQ_HTTP_TIMEOUT';
|
|
41
|
+
readonly HTTP_INTERCEPTOR: 'ZQ_HTTP_INTERCEPTOR';
|
|
42
|
+
readonly HTTP_PARSE: 'ZQ_HTTP_PARSE';
|
|
43
|
+
|
|
44
|
+
// General
|
|
45
|
+
readonly INVALID_ARGUMENT: 'ZQ_INVALID_ARGUMENT';
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** Union of all error code string values. */
|
|
49
|
+
export type ErrorCodeValue = (typeof ErrorCode)[keyof typeof ErrorCode];
|
|
50
|
+
|
|
51
|
+
/** Structured error class used throughout zQuery. */
|
|
52
|
+
export class ZQueryError extends Error {
|
|
53
|
+
readonly name: 'ZQueryError';
|
|
54
|
+
/** Machine-readable error code (e.g. `'ZQ_COMP_RENDER'`). */
|
|
55
|
+
readonly code: ErrorCodeValue;
|
|
56
|
+
/** Extra contextual data (component name, expression string, etc.). */
|
|
57
|
+
readonly context: Record<string, any>;
|
|
58
|
+
/** Original error that caused this one, if any. */
|
|
59
|
+
readonly cause?: Error;
|
|
60
|
+
|
|
61
|
+
constructor(
|
|
62
|
+
code: ErrorCodeValue,
|
|
63
|
+
message: string,
|
|
64
|
+
context?: Record<string, any>,
|
|
65
|
+
cause?: Error,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Error handler callback type. */
|
|
70
|
+
export type ZQueryErrorHandler = (error: ZQueryError) => void;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Register a global error handler. Called whenever zQuery catches an
|
|
74
|
+
* error internally. Pass `null` to remove.
|
|
75
|
+
*/
|
|
76
|
+
export function onError(handler: ZQueryErrorHandler | null): void;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Report an error through the global handler and console.
|
|
80
|
+
* Non-throwing — used for recoverable errors in callbacks, lifecycle hooks, etc.
|
|
81
|
+
*/
|
|
82
|
+
export function reportError(
|
|
83
|
+
code: ErrorCodeValue,
|
|
84
|
+
message: string,
|
|
85
|
+
context?: Record<string, any>,
|
|
86
|
+
cause?: Error,
|
|
87
|
+
): void;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Wrap a callback so that thrown errors are caught, reported via `reportError`,
|
|
91
|
+
* and don't crash the current execution context.
|
|
92
|
+
*/
|
|
93
|
+
export function guardCallback<T extends (...args: any[]) => any>(
|
|
94
|
+
fn: T,
|
|
95
|
+
code: ErrorCodeValue,
|
|
96
|
+
context?: Record<string, any>,
|
|
97
|
+
): (...args: Parameters<T>) => ReturnType<T> | undefined;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Validate a required value is defined and of the expected type.
|
|
101
|
+
* Throws `ZQueryError` with `INVALID_ARGUMENT` on failure.
|
|
102
|
+
*/
|
|
103
|
+
export function validate(value: any, name: string, expectedType?: string): void;
|