dalila 1.9.2 → 1.9.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.
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @module dalila/runtime
8
8
  */
9
+ import type { Component } from './component.js';
9
10
  export interface BindOptions {
10
11
  /**
11
12
  * Event types to bind (default: click, input, change, submit, keydown, keyup)
@@ -25,6 +26,10 @@ export interface BindOptions {
25
26
  /** Time-to-live (ms) per plan, refreshed on hit (0 disables cache). */
26
27
  ttlMs?: number;
27
28
  };
29
+ /** Component registry — accepts map `{ tag: component }` or array `[component]` */
30
+ components?: Record<string, Component> | Component[];
31
+ /** Error policy for component `ctx.onMount()` callbacks. Default: 'log'. */
32
+ onMountError?: 'log' | 'throw';
28
33
  /**
29
34
  * Internal flag — set by fromHtml for router/template rendering.
30
35
  * Skips HMR context registration but KEEPS d-ready/d-loading lifecycle.
@@ -41,7 +46,36 @@ export interface BindOptions {
41
46
  export interface BindContext {
42
47
  [key: string]: unknown;
43
48
  }
49
+ /**
50
+ * Convenience alias: any object whose values are `unknown`.
51
+ * Use the generic parameter on `bind<T>()` / `autoBind<T>()` / `fromHtml<T>()`
52
+ * to preserve the concrete type at call sites while still satisfying internal
53
+ * look-ups that index by string key.
54
+ */
55
+ export type BindData<T extends Record<string, unknown> = Record<string, unknown>> = T;
44
56
  export type DisposeFunction = () => void;
57
+ export interface BindHandle {
58
+ (): void;
59
+ getRef(name: string): Element | null;
60
+ getRefs(): Readonly<Record<string, Element>>;
61
+ }
62
+ /**
63
+ * Set global defaults for all `bind()` / `mount()` calls.
64
+ *
65
+ * Options set here are merged with per-call options (per-call wins).
66
+ * Call with an empty object to reset.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * import { configure } from 'dalila/runtime';
71
+ *
72
+ * configure({
73
+ * components: [FruitPicker],
74
+ * onMountError: 'log',
75
+ * });
76
+ * ```
77
+ */
78
+ export declare function configure(config: BindOptions): void;
45
79
  /**
46
80
  * Bind a DOM tree to a reactive context.
47
81
  *
@@ -65,7 +99,7 @@ export type DisposeFunction = () => void;
65
99
  * dispose();
66
100
  * ```
67
101
  */
68
- export declare function bind(root: Element, ctx: BindContext, options?: BindOptions): DisposeFunction;
102
+ export declare function bind<T extends Record<string, unknown> = BindContext>(root: Element | string, ctx: T, options?: BindOptions): BindHandle;
69
103
  /**
70
104
  * Automatically bind when DOM is ready.
71
105
  * Useful for simple pages without a build step.
@@ -78,4 +112,15 @@ export declare function bind(root: Element, ctx: BindContext, options?: BindOpti
78
112
  * </script>
79
113
  * ```
80
114
  */
81
- export declare function autoBind(selector: string, ctx: BindContext, options?: BindOptions): Promise<DisposeFunction>;
115
+ export declare function autoBind<T extends Record<string, unknown> = BindContext>(selector: string, ctx: T, options?: BindOptions): Promise<BindHandle>;
116
+ /**
117
+ * Mount a component imperatively, or bind a selector to a view-model.
118
+ *
119
+ * Overload 1 — `mount(selector, vm, options?)`:
120
+ * Shorthand for `bind(selector, vm, options)`.
121
+ *
122
+ * Overload 2 — `mount(component, target, props?)`:
123
+ * Mount a component created with defineComponent() into a target element.
124
+ */
125
+ export declare function mount<T extends object>(selector: string, vm: T, options?: BindOptions): BindHandle;
126
+ export declare function mount(component: Component, target: Element, props?: Record<string, unknown>): BindHandle;