@brandup/ui 1.0.43 → 2.0.1

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/dist/types.d.ts CHANGED
@@ -1,50 +1,276 @@
1
- declare class EventEmitter {
1
+ /**
2
+ * Minimal event emitter with support for one-off listeners and cross-emitter listening.
3
+ *
4
+ * The optional `TEvents` type parameter is an event map (`{ eventName: (args) => void }`)
5
+ * that gives subclasses strongly-typed event names, callback signatures and `trigger` arguments.
6
+ * When omitted it defaults to a loose map, so untyped usage keeps working.
7
+ */
8
+ declare class EventEmitter<TEvents = EventMap> {
2
9
  private _events?;
3
10
  private _listenId?;
4
11
  private _listeningTo?;
5
- on(eventName: EventName, callback: EventCallbackFunc, context?: EventContextInit): this;
6
- once(eventName: EventName, callback: EventCallbackFunc, context?: EventContextInit): this;
7
- off(eventName?: EventName | null, callback?: EventCallbackFunc | null, context?: EventContextInit | null): this;
8
- protected listenTo(source: EventEmitter, eventName: EventName, callback: EventCallbackFunc): this;
9
- protected listenToOnce(source: EventEmitter, eventName: EventName, callback: EventCallbackFunc): this;
10
- protected stopListening(source?: EventEmitter, eventName?: EventName, callback?: EventCallbackFunc): this;
12
+ /**
13
+ * Subscribe to an event.
14
+ * @param eventName Event name, or `"all"` to receive every event.
15
+ * @param callback Handler invoked when the event is triggered.
16
+ * @param context Optional `this`/context bound to the handler and used for removal matching.
17
+ */
18
+ on<K extends keyof TEvents & string>(eventName: K, callback: TEvents[K], context?: EventContextInit): this;
19
+ on(eventName: "all", callback: EventCallbackFunc, context?: EventContextInit): this;
20
+ /**
21
+ * Subscribe to an event for a single invocation; the handler is removed after it fires once.
22
+ * @param eventName Event name, or `"all"` to receive every event.
23
+ * @param callback Handler invoked once when the event is triggered.
24
+ * @param context Optional `this`/context bound to the handler and used for removal matching.
25
+ */
26
+ once<K extends keyof TEvents & string>(eventName: K, callback: TEvents[K], context?: EventContextInit): this;
27
+ once(eventName: "all", callback: EventCallbackFunc, context?: EventContextInit): this;
28
+ /**
29
+ * Remove event subscriptions. At least one argument is required.
30
+ * Listeners matching all provided filters are removed; omitted filters match anything.
31
+ * @param eventName Event name to remove, or omit to match all events.
32
+ * @param callback Handler to remove, or omit to match all handlers.
33
+ * @param context Context to remove, or omit to match all contexts.
34
+ */
35
+ off<K extends keyof TEvents & string>(eventName?: K | "all" | null, callback?: TEvents[K] | EventCallbackFunc | null, context?: EventContextInit | null): this;
36
+ /**
37
+ * Listen to an event on another emitter, tracking the subscription so it can be released via `stopListening`.
38
+ * @param source Emitter to subscribe to.
39
+ * @param eventName Event name to listen for.
40
+ * @param callback Handler invoked when the event is triggered.
41
+ */
42
+ protected listenTo(source: EventEmitter<any>, eventName: string, callback: EventCallbackFunc): this;
43
+ /**
44
+ * Listen once to an event on another emitter; the subscription is tracked and auto-removed after it fires.
45
+ * @param source Emitter to subscribe to.
46
+ * @param eventName Event name to listen for.
47
+ * @param callback Handler invoked once when the event is triggered.
48
+ */
49
+ protected listenToOnce(source: EventEmitter<any>, eventName: string, callback: EventCallbackFunc): this;
50
+ /**
51
+ * Release subscriptions previously established with `listenTo`/`listenToOnce`.
52
+ * Omitted arguments broaden the match (e.g. no `source` releases all tracked emitters).
53
+ * @param source Limit to a specific emitter, or omit for all.
54
+ * @param eventName Limit to a specific event, or omit for all.
55
+ * @param callback Limit to a specific handler, or omit for all.
56
+ */
57
+ protected stopListening(source?: EventEmitter<any>, eventName?: string, callback?: EventCallbackFunc): this;
11
58
  private _addListeningTo;
59
+ /** Remove a single tracked subscription (matched by event + registered callback). @internal */
60
+ private _removeListeningSubscription;
12
61
  private stopAllListeners;
13
- protected trigger(eventName: string, ...args: any[]): this;
62
+ /**
63
+ * Trigger an event, invoking all matching handlers plus any `"all"` listeners.
64
+ * @param eventName Event name to trigger (`"all"` is reserved and not allowed).
65
+ * @param args Arguments forwarded to each handler.
66
+ */
67
+ protected trigger<K extends keyof TEvents & string>(eventName: K, ...args: TEvents[K] extends (...a: infer A) => any ? A : never): this;
14
68
  private _triggerEvent;
15
69
  private _getOrCreateEvents;
16
70
  private _getEvents;
71
+ /** Release every subscription: both events this emitter listens to and listeners registered on it. */
17
72
  protected stopEvents(): void;
18
73
  }
74
+ /** Map of event name to its handler signature; used as the `TEvents` parameter of {@link EventEmitter}. */
75
+ type EventMap = Record<string, (...args: any[]) => void>;
76
+ /** Event name; the special value `"all"` matches every triggered event. */
19
77
  type EventName = "all" | string;
78
+ /** Event handler signature; receives the arguments passed to `trigger`. */
20
79
  type EventCallbackFunc = (...args: any[]) => void;
80
+ /** Arbitrary context bound as `this` to a handler and used to match it on removal. */
21
81
  type EventContextInit = any;
22
82
 
23
- declare abstract class UIElement extends EventEmitter {
83
+ /** Key used to track iteration/length dependencies (object key enumeration, array growth). */
84
+ declare const ITERATE_KEY: unique symbol;
85
+ /**
86
+ * A reactive effect: a function whose reactive reads are tracked, so it re-runs
87
+ * whenever any of those reactive dependencies change.
88
+ */
89
+ declare class ReactiveEffect<T = any> {
90
+ private readonly __fn;
91
+ /** Dependency sets this effect is currently subscribed to. @internal */
92
+ readonly deps: Set<ReactiveEffect>[];
93
+ private __active;
94
+ /** Called instead of `run` when a dependency changes (used by `computed`). */
95
+ scheduler?: () => void;
96
+ /** Invoked once when the effect is stopped. */
97
+ onStop?: () => void;
98
+ constructor(__fn: () => T, scheduler?: () => void);
99
+ /** Whether the effect is still active (not stopped). */
100
+ get active(): boolean;
101
+ /** Run the effect, (re)collecting its dependencies. */
102
+ run(): T;
103
+ /** Stop the effect: remove its subscriptions and run `onStop`. */
104
+ stop(): void;
105
+ }
106
+ /** Record the active effect (if any) as depending on `target[key]`. @internal */
107
+ declare function track(target: object, key: PropertyKey): void;
108
+ /** Re-run (or schedule) every effect that depends on `target[key]`. @internal */
109
+ declare function trigger(target: object, key: PropertyKey): void;
110
+ /**
111
+ * Resolves after the currently pending batch of reactive effects has flushed.
112
+ * Effect re-runs (and the DOM updates they drive) are batched on the microtask queue,
113
+ * so await `nextTick()` to observe their results.
114
+ */
115
+ declare function nextTick(fn?: () => void): Promise<void>;
116
+ /**
117
+ * Execute `fn` without tracking any reactive reads.
118
+ * Use inside a reactive context when you want to read state without creating a dependency.
119
+ */
120
+ declare function untrack<T>(fn: () => T): T;
121
+ /** Create and immediately run a reactive effect. Returns the {@link ReactiveEffect}. */
122
+ declare function effect<T>(fn: () => T, scheduler?: () => void): ReactiveEffect<T>;
123
+ /** A disposable container that collects effects (and nested scopes) so they can be stopped together. */
124
+ declare class EffectScope {
125
+ private readonly __effects;
126
+ private readonly __scopes;
127
+ private __active;
128
+ /** Whether the scope is still active (not stopped). */
129
+ get active(): boolean;
130
+ /** @internal */
131
+ add(effect: ReactiveEffect): void;
132
+ /** @internal */
133
+ addScope(scope: EffectScope): void;
134
+ /** Run `fn` with this scope active; effects created during the call register to it. */
135
+ run<T>(fn: () => T): T;
136
+ /** Stop all effects and nested scopes collected by this scope. */
137
+ stop(): void;
138
+ }
139
+ /** Create a new {@link EffectScope}, nested in the current scope if one is active. */
140
+ declare function effectScope(): EffectScope;
141
+
142
+ /** Whether a value is a reactive proxy created by {@link reactive}. */
143
+ declare function isReactive(value: unknown): boolean;
144
+ /** Return the underlying raw (non-reactive) object behind a reactive proxy, or the value itself. */
145
+ declare function toRaw<T>(value: T): T;
146
+ /**
147
+ * Wrap an object or array in a deep reactive proxy. Reads are tracked and writes
148
+ * notify effects. Returns the same proxy for the same target, and non-objects unchanged.
149
+ */
150
+ declare function reactive<T extends object>(target: T): T;
151
+
152
+ /** A lazily-evaluated, cached reactive value derived from other reactive state. */
153
+ declare class ComputedRef<T = any> {
154
+ private __value;
155
+ private __dirty;
156
+ private readonly __effect;
157
+ constructor(getter: () => T);
158
+ /** The current value; recomputed on read only when its dependencies have changed. */
159
+ get value(): T;
160
+ }
161
+ /** Create a {@link ComputedRef} from a getter. */
162
+ declare function computed<T>(getter: () => T): ComputedRef<T>;
163
+
164
+ /** Built-in events triggered by every {@link UIElement}. */
165
+ interface UIElementEvents {
166
+ /** Triggered right before a command handler runs. */
167
+ command: (args: CommandEventArgs) => void;
168
+ /** Triggered after the element is bound by `setElement` and `_onRenderElement` has run. */
169
+ rendered: (sender: UIElement<any>) => void;
170
+ /** Triggered when the element is destroyed. */
171
+ destroy: (sender: UIElement<any>) => void;
172
+ }
173
+ /** Merge the built-in {@link UIElementEvents} with a subclass event map (built-in keys take precedence). */
174
+ type WithUIEvents<TEvents> = {
175
+ [K in keyof UIElementEvents | keyof TEvents]: K extends keyof UIElementEvents ? UIElementEvents[K] : K extends keyof TEvents ? TEvents[K] : never;
176
+ };
177
+ /**
178
+ * Wraps an `HTMLElement` and binds business logic, commands and events to it.
179
+ *
180
+ * The optional `TEvents` event map is merged with {@link UIElementEvents}, so subclasses
181
+ * can declare their own typed events in addition to the built-in `command`/`destroy`.
182
+ */
183
+ declare abstract class UIElement<TEvents = {}> extends EventEmitter<WithUIEvents<TEvents>> {
24
184
  private __element?;
25
185
  private __events?;
26
186
  private __commands?;
27
187
  private __destroyed?;
188
+ /** Unique type name of this UI element; also written to the element's data attribute. */
28
189
  abstract typeName: string;
190
+ /** The bound DOM element, or `undefined` until `setElement` is called. */
29
191
  get element(): HTMLElement | undefined;
192
+ /**
193
+ * Bind a DOM element to this instance and run render logic. Can be called only once.
194
+ * @param elem Element to bind; throws if already bound or owned by another `UIElement`.
195
+ */
30
196
  protected setElement(elem: HTMLElement): void;
197
+ /**
198
+ * Whether the given element is already bound to a `UIElement`.
199
+ * @param elem Element to test.
200
+ */
31
201
  static hasElement(elem: HTMLElement): boolean;
202
+ /**
203
+ * Register a handler for a command declared in markup via the `data-command` attribute.
204
+ * @param name Command name (case-insensitive); throws if already registered.
205
+ * @param execute Handler run when the command fires; may return a `Promise` for async commands.
206
+ * @param canExecute Optional predicate gating whether the command may run.
207
+ * @returns This instance for chaining.
208
+ */
32
209
  registerCommand(name: string, execute: CommandExecuteFunction, canExecute?: CommandCanExecuteFunction): this;
33
- hasCommand(name: string): boolean | undefined;
34
- /** @internal */
210
+ /**
211
+ * Whether a command with the given name is registered.
212
+ * @param name Command name (case-insensitive).
213
+ */
214
+ hasCommand(name: string): boolean;
215
+ /**
216
+ * Execute a registered command against a target element.
217
+ * @internal
218
+ */
35
219
  __execCommand(name: string, target: HTMLElement): CommandResult;
220
+ /**
221
+ * Hook invoked when an element is bound via `setElement`. Override to render or wire up the element.
222
+ * @param _elem The newly bound element.
223
+ */
224
+ /** Trigger a built-in event. Typed by {@link UIElementEvents}; bypasses the generic trigger overload internally. */
225
+ private __raise;
36
226
  protected _onRenderElement(_elem: HTMLElement): void;
227
+ /**
228
+ * Hook deciding whether a command may execute. Override to add element-wide gating.
229
+ * @param _name Command name being executed.
230
+ * @param _elem Target element of the command.
231
+ * @returns `true` to allow execution (default), `false` to disallow.
232
+ */
37
233
  protected _onCanExecCommand(_name: string, _elem: HTMLElement): boolean;
38
- onDestroy(callback: VoidFunction | UIElement | Element): void;
234
+ /**
235
+ * Create an {@link EffectScope} whose reactive effects are stopped automatically when
236
+ * this element is destroyed. Use it to scope `bind`/`effect` to the element's lifetime.
237
+ */
238
+ effectScope(): EffectScope;
239
+ /** Returns the `typeName` of this element. */
39
240
  toString(): string;
241
+ /** Destroy the element: trigger the `destroy` event, release events/commands and detach from the DOM element. */
40
242
  destroy(): void;
41
243
  }
244
+ /**
245
+ * A {@link UIElement} whose DOM element is bound in the constructor, so its `element`
246
+ * is always defined (typed `HTMLElement`, never `undefined`). Subclasses pass their
247
+ * `typeName` and the element to `super`.
248
+ *
249
+ * Use {@link UIElement} directly when the element is bound later (e.g. an application
250
+ * that binds its element on run).
251
+ */
252
+ declare abstract class UIElementBound<TEvents = {}> extends UIElement<TEvents> {
253
+ private __typeName;
254
+ /** @param typeName Unique type name of this element. @param elem Element to bind. */
255
+ constructor(typeName: string, elem: HTMLElement);
256
+ get typeName(): string;
257
+ /** The bound DOM element; always defined since it is set in the constructor. */
258
+ get element(): HTMLElement;
259
+ }
260
+ /** Remove the global click handler registered by brandup-ui. Call on app teardown or HMR disposal. */
261
+ declare function destroyUI(): void;
262
+ /** Command handler; returning a `Promise` marks the command as async (adds the `executing` CSS class while pending). */
42
263
  type CommandExecuteFunction = (context: CommandContext) => void | Promise<void | any>;
264
+ /** Predicate deciding whether a command may run for the given context. */
43
265
  type CommandCanExecuteFunction = (context: CommandContext) => boolean;
266
+ /** Arguments of the `command` event triggered before a command executes. */
44
267
  interface CommandEventArgs {
268
+ /** UIElement that owns the command. */
45
269
  element: UIElement;
270
+ /** Name of the command being executed. */
46
271
  name: string;
47
272
  }
273
+ /** Context passed to command execute/canExecute handlers. */
48
274
  interface CommandContext {
49
275
  /** HTMLElement on which the command is executed */
50
276
  target: HTMLElement;
@@ -53,27 +279,260 @@ interface CommandContext {
53
279
  /** Don't stop the click event chain of target. */
54
280
  transparent?: boolean;
55
281
  }
282
+ /** Outcome of an attempted command execution. */
56
283
  interface CommandResult {
284
+ /** Execution status. */
57
285
  status: CommandExecStatus;
286
+ /** Context the command ran with. */
58
287
  context: CommandContext;
59
288
  }
289
+ /** Command execution status: `disallow` (gated out), `already` (re-entrant call ignored) or `success`. */
60
290
  type CommandExecStatus = "disallow" | "already" | "success";
61
291
 
62
292
  declare global {
63
293
  interface HTMLElement {
294
+ /**
295
+ * Bind a `UIElement` to this element via the given factory and return the element for chaining.
296
+ * @param factory Callback that creates the `UIElement` for this element.
297
+ */
64
298
  ui(factory: (elem: HTMLElement) => UIElement): HTMLElement;
65
299
  }
66
300
  interface Node {
301
+ /** `UIElement` bound to this node, or `undefined` when none is bound. */
67
302
  readonly uielement: UIElement | undefined;
68
303
  }
69
304
  }
70
305
 
306
+ /** Value a reactive binding can render: text (`string`/`number`), an `Element` or {@link UIElement}, or `null`/`undefined`/`false` (rendered as nothing). */
307
+ type BindingValue = string | number | boolean | Element | UIElement<any> | null | undefined;
308
+ /**
309
+ * A reactive binding for use as a {@link tag} child. Its `compute` function is
310
+ * re-evaluated and re-rendered whenever the reactive state it reads changes.
311
+ */
312
+ declare class Binding {
313
+ readonly compute: () => BindingValue;
314
+ constructor(compute: () => BindingValue);
315
+ }
316
+ /**
317
+ * Create a reactive {@link Binding} that can be passed as a `tag` child. The
318
+ * compute function is tracked: it re-runs (updating the DOM in place) whenever
319
+ * any reactive value it reads changes.
320
+ *
321
+ * @example
322
+ * const state = reactive({ name: "Alice" });
323
+ * DOM.tag("div", null, "Hi, ", bind(() => state.name));
324
+ * state.name = "Bob"; // the text updates in place
325
+ */
326
+ declare function bind(compute: () => BindingValue): Binding;
327
+
328
+ /** A keyed-list binding produced by {@link bindEach}; handled by `appendChild` in `tag.ts`. */
329
+ declare class BindingEach<T = any> {
330
+ readonly getItems: () => T[];
331
+ readonly getKey: (item: T, index: number) => string | number;
332
+ readonly render: (item: T) => Element;
333
+ constructor(getItems: () => T[], getKey: (item: T, index: number) => string | number, render: (item: T) => Element);
334
+ }
335
+ /**
336
+ * Create a reactive keyed-list binding for use as a {@link tag} child.
337
+ *
338
+ * The `getItems` function is tracked; the list is reconciled whenever the array
339
+ * changes (push, splice, reassignment, etc.). Items are matched by `getKey` so
340
+ * unchanged nodes stay in place — only new, removed, or reordered nodes are touched.
341
+ *
342
+ * `render` is called **once per key** and runs **untracked**. Use `bind()` inside
343
+ * the render function for item properties that should update independently:
344
+ *
345
+ * ⚠️ The item object passed to `render` is captured at first render for that key.
346
+ * Mutate items in place (`item.name = "..."`) so `bind()` reactions fire. Replacing
347
+ * the array with **new objects that reuse the same keys** keeps the cached node bound
348
+ * to the *old* object, so per-item `bind()`s won't update — change the key, or mutate
349
+ * the existing item, when its identity should change.
350
+ *
351
+ * @example
352
+ * DOM.tag("ul", null,
353
+ * bindEach(() => state.users, u => u.id, u =>
354
+ * DOM.tag("li", null, bind(() => u.name))
355
+ * )
356
+ * );
357
+ */
358
+ declare function bindEach<T>(getItems: () => T[], getKey: (item: T, index: number) => string | number, render: (item: T) => Element): BindingEach<T>;
359
+ /**
360
+ * Mount a {@link BindingEach} into `container` and start tracking.
361
+ * Called by `appendChild` in `tag.ts`; not intended for direct use.
362
+ * @internal
363
+ */
364
+ declare function appendBindingEach<T>(container: HTMLElement, binding: BindingEach<T>): void;
365
+
366
+ /**
367
+ * Values that are unambiguously a {@link tag} child and never options.
368
+ * Passing one of these as the second argument to `tag` skips the options parameter.
369
+ * `null` and `undefined` are excluded — they serve as "no options" in position 2.
370
+ */
371
+ type TagFirstChild = Element | UIElement<any> | Binding | BindingEach<any> | Promise<TagChildrenPrimitive> | ((elem: HTMLElement) => TagChildrenPrimitive | TagChildrenPrimitive[] | void) | string | number | boolean | Array<TagChildrenLike>;
372
+ /** Options used to configure an element created by {@link tag}. Recognized keys (`id`, `class`, `command`, `dataset`, `events`, `styles`) are handled specially; any other key is applied as a plain attribute. */
373
+ interface ElementOptions {
374
+ /** Value for the element's `id` attribute. */
375
+ id?: string;
376
+ /** CSS class(es) to add to the element. */
377
+ class?: CssClass;
378
+ /** Sets the `data-command` attribute (shortcut for `dataset.command`). */
379
+ command?: string;
380
+ /** Custom `data-*` attributes to set on the element. */
381
+ dataset?: ElementData;
382
+ /** Event listeners to attach, keyed by lower-case event name. */
383
+ events?: ElementEvents;
384
+ /** Inline styles to apply to `element.style`. */
385
+ styles?: ElementStyles;
386
+ /** Any other key is set as a plain attribute. `null` sets an empty attribute, objects are JSON-stringified, other values are coerced to string. `undefined` is ignored. */
387
+ [name: string]: string | number | boolean | object | null | undefined;
388
+ }
389
+ /** One or more CSS class names: a space-separated string or an array of class names. */
390
+ type CssClass = string | string[];
391
+ /** Map of custom `data-*` attribute names to their string values. */
392
+ interface ElementData {
393
+ [name: string]: string | undefined;
394
+ }
395
+ /** Map of DOM event handlers keyed by lower-case event name (e.g. `click`, `mouseover`), strongly typed to the matching `HTMLElementEventMap` event. */
396
+ type ElementEvents = {
397
+ [Name in keyof HTMLElementEventMap as `${Lowercase<string & Name>}`]?: (e: HTMLElementEventMap[Name]) => void;
398
+ };
399
+ /** Inline style declaration: a partial set of writable `CSSStyleDeclaration` properties. */
400
+ type ElementStyles = Partial<CSSStyleDeclaration>;
401
+ /** A value accepted as a {@link tag} child: a primitive, a reactive {@link Binding}, a keyed-list {@link BindingEach}, a promise of one, a factory function receiving the container element, or a (possibly nested) array of any of these. */
402
+ type TagChildrenLike = TagChildrenPrimitive | Binding | BindingEach | Promise<TagChildrenPrimitive> | ((elem: HTMLElement) => Promise<TagChildrenPrimitive> | Promise<TagChildrenPrimitive[]> | TagChildrenPrimitive | TagChildrenPrimitive[] | void) | Array<TagChildrenLike>;
403
+ /** A single concrete child value: an existing `Element`, a {@link UIElement} (its bound element is appended), a string/number rendered as HTML, or `null`/`undefined` (ignored). */
404
+ type TagChildrenPrimitive = Element | UIElement<any> | string | number | null | undefined;
405
+
406
+ /**
407
+ * Finds an element by its `id` within the whole document.
408
+ * @param id The element id to look up.
409
+ * @returns The matching element, or `null` if none exists.
410
+ */
411
+ declare function getById<TElement extends HTMLElement = HTMLElement>(id: string): TElement | null;
412
+ /**
413
+ * Returns the first descendant of `container` that has the given class.
414
+ * @param container Element to search within.
415
+ * @param className Single class name to match.
416
+ * @returns The first matching element, or `null` if none found.
417
+ */
418
+ declare function getByClass<TElement extends HTMLElement = HTMLElement>(container: Element, className: string): TElement | null;
419
+ /**
420
+ * Returns the first element in the document with the given `name` attribute.
421
+ * @param name The `name` attribute value to look up.
422
+ * @returns The first matching element, or `null` if none found.
423
+ */
424
+ declare function getByName<TElement extends HTMLElement = HTMLElement>(name: string): TElement | null;
425
+ /**
426
+ * Returns the first descendant of `container` with the given tag name.
427
+ * @param container Element to search within.
428
+ * @param tagName Tag name to match (e.g. `"input"`).
429
+ * @returns The first matching element, or `null` if none found.
430
+ */
431
+ declare function getElementByTagName<TElement extends HTMLElement = HTMLElement>(container: Element, tagName: string): TElement | null;
432
+ /**
433
+ * Returns all descendants of `container` with the given tag name as a live collection.
434
+ * @param container Element to search within.
435
+ * @param tagName Tag name to match (e.g. `"li"`).
436
+ * @returns A live `HTMLCollection` of matching elements.
437
+ */
438
+ declare function getElementsByTagName(container: Element, tagName: string): HTMLCollectionOf<Element>;
439
+ /**
440
+ * Returns the first descendant of `container` matching the CSS selector.
441
+ * @param container Element to search within.
442
+ * @param query CSS selector.
443
+ * @returns The first matching element, or `null` if none found.
444
+ */
445
+ declare function queryElement<TElement extends HTMLElement = HTMLElement>(container: Element, query: string): TElement | null;
446
+ /**
447
+ * Returns all descendants of `container` matching the CSS selector.
448
+ * @param container Element to search within.
449
+ * @param query CSS selector.
450
+ * @returns A static `NodeList` of matching elements.
451
+ */
452
+ declare function queryElements<TElement extends HTMLElement = HTMLElement>(container: Element, query: string): NodeListOf<TElement>;
453
+ /**
454
+ * Walks forward through the following siblings of `current` and returns the first one that has the given class.
455
+ * @param current Element to start from.
456
+ * @param className Class name to match.
457
+ * @returns The first matching following sibling, or `null` if none found.
458
+ */
459
+ declare function nextElementByClass<TElement extends HTMLElement = HTMLElement>(current: Element, className: string): TElement | null;
460
+ /**
461
+ * Walks backward through the preceding siblings of `current` and returns the first one that has the given class.
462
+ * @param current Element to start from.
463
+ * @param className Class name to match.
464
+ * @returns The first matching preceding sibling, or `null` if none found.
465
+ */
466
+ declare function prevElementByClass<TElement extends HTMLElement = HTMLElement>(current: Element, className: string): TElement | null;
467
+ /**
468
+ * Returns the nearest preceding sibling element of `current`, skipping non-element nodes (e.g. text nodes).
469
+ * @param current Element to start from.
470
+ * @returns The previous sibling element, or `null` if none found.
471
+ */
472
+ declare function prevElement<TElement extends HTMLElement = HTMLElement>(current: Element): TElement | null;
473
+ /**
474
+ * Returns the nearest following sibling element of `current`, skipping non-element nodes (e.g. text nodes).
475
+ * @param current Element to start from.
476
+ * @returns The next sibling element, or `null` if none found.
477
+ */
478
+ declare function nextElement<TElement extends HTMLElement = HTMLElement>(current: Element): TElement | null;
479
+ /**
480
+ * Adds the given CSS class(es) to every descendant of `container` matching the selector. No-op when `container` or `cssClass` is falsy.
481
+ * @param container Element to search within (ignored when null/undefined).
482
+ * @param selectors CSS selector for the elements to modify.
483
+ * @param cssClass Class name(s) to add.
484
+ */
485
+ declare function addClass(container: Element | null | undefined, selectors: string, cssClass: CssClass): void;
486
+ /**
487
+ * Removes the given CSS class(es) from every descendant of `container` matching the selector. No-op when `container` or `cssClass` is falsy.
488
+ * @param container Element to search within (ignored when null/undefined).
489
+ * @param selectors CSS selector for the elements to modify.
490
+ * @param cssClass Class name(s) to remove.
491
+ */
492
+ declare function removeClass(container: Element | null | undefined, selectors: string, cssClass: CssClass): void;
493
+ /**
494
+ * Removes all child nodes from `container`, leaving it empty. No-op when `container` is null/undefined.
495
+ * @param container Element to clear.
496
+ */
497
+ declare function empty(container: Element | null | undefined): void;
498
+
499
+ declare function tag<T extends keyof HTMLElementTagNameMap>(tagName: T, firstChild: TagFirstChild, ...children: TagChildrenLike[]): HTMLElementTagNameMap[T];
500
+ declare function tag<T extends keyof HTMLElementTagNameMap>(tagName: T, options: ElementOptions | null, ...children: TagChildrenLike[]): HTMLElementTagNameMap[T];
501
+ declare function tag<T extends keyof HTMLElementTagNameMap>(tagName: T): HTMLElementTagNameMap[T];
502
+
503
+ /** Collection of DOM helper functions: element queries/traversal ({@link getById}, {@link queryElement}, {@link nextElement}, ...), class manipulation ({@link addClass}, {@link removeClass}), {@link empty}, and element creation via {@link tag}. */
504
+ declare const DOM: {
505
+ tag: typeof tag;
506
+ applyOptions: (elem: HTMLElement, options?: ElementOptions | CssClass | null) => void;
507
+ appendChild: (container: HTMLElement, children?: TagChildrenLike) => void;
508
+ getById: typeof getById;
509
+ getByClass: typeof getByClass;
510
+ getByName: typeof getByName;
511
+ getElementByTagName: typeof getElementByTagName;
512
+ getElementsByTagName: typeof getElementsByTagName;
513
+ queryElement: typeof queryElement;
514
+ queryElements: typeof queryElements;
515
+ nextElementByClass: typeof nextElementByClass;
516
+ prevElementByClass: typeof prevElementByClass;
517
+ prevElement: typeof prevElement;
518
+ nextElement: typeof nextElement;
519
+ addClass: typeof addClass;
520
+ removeClass: typeof removeClass;
521
+ empty: typeof empty;
522
+ };
523
+
524
+ /** Names of the DOM attributes, properties and CSS classes used by the library. */
71
525
  interface UiConstants {
526
+ /** `data-*` attribute name storing the `UIElement.typeName` on its element. */
72
527
  readonly ElemAttributeName: string;
528
+ /** Property name on the DOM element referencing its bound `UIElement` instance. */
73
529
  readonly ElemPropertyName: string;
530
+ /** `data-*` attribute name declaring a command name in markup. */
74
531
  readonly CommandAttributeName: string;
532
+ /** CSS class added to the target element while an async command is executing. */
75
533
  readonly CommandExecutingCssClassName: string;
76
534
  }
535
+ /** Default constant values used across the library. */
77
536
  declare const constants: UiConstants;
78
537
 
79
538
  type constants$1_UiConstants = UiConstants;
@@ -82,5 +541,5 @@ declare namespace constants$1 {
82
541
  export type { constants$1_UiConstants as UiConstants };
83
542
  }
84
543
 
85
- export { EventEmitter, constants$1 as UICONSTANTS, UIElement };
86
- export type { CommandCanExecuteFunction, CommandContext, CommandEventArgs, CommandExecStatus, CommandExecuteFunction, CommandResult, EventCallbackFunc, EventContextInit, EventName };
544
+ export { Binding, BindingEach, ComputedRef, DOM, EffectScope, EventEmitter, ITERATE_KEY, ReactiveEffect, constants$1 as UICONSTANTS, UIElement, UIElementBound, appendBindingEach, bind, bindEach, computed, destroyUI, effect, effectScope, isReactive, nextTick, reactive, toRaw, track, trigger, untrack };
545
+ export type { BindingValue, CommandCanExecuteFunction, CommandContext, CommandEventArgs, CommandExecStatus, CommandExecuteFunction, CommandResult, CssClass, ElementData, ElementEvents, ElementOptions, ElementStyles, EventCallbackFunc, EventContextInit, EventMap, EventName, TagChildrenLike, TagChildrenPrimitive, TagFirstChild, UIElementEvents };
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "email": "it@brandup.online"
23
23
  },
24
24
  "license": "Apache-2.0",
25
- "version": "1.0.43",
25
+ "version": "2.0.1",
26
26
  "main": "dist/cjs/index.js",
27
27
  "module": "dist/mjs/index.js",
28
28
  "types": "dist/types.d.ts",