@twobirds/microcomponents 0.2.0 → 0.2.2

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.
Files changed (38) hide show
  1. package/README.md +27 -38
  2. package/dist/MC.min.js +1 -1
  3. package/dist/autoload.min.js +1 -1
  4. package/dist/core/MC.d.ts +5 -2
  5. package/dist/core/MC.d.ts.map +1 -1
  6. package/dist/core/MC.js +52 -4
  7. package/dist/core/elements.d.ts +186 -100
  8. package/dist/core/elements.d.ts.map +1 -1
  9. package/dist/core/elements.js +186 -17
  10. package/dist/core/mcGuards.d.ts +1 -0
  11. package/dist/core/mcGuards.d.ts.map +1 -1
  12. package/dist/core/mcGuards.js +0 -10
  13. package/dist/elements.min.js +1 -1
  14. package/dist/events.min.js +1 -1
  15. package/dist/formValues.min.js +1 -1
  16. package/dist/microcomponents.d.ts +2 -2
  17. package/dist/microcomponents.d.ts.map +1 -1
  18. package/dist/microcomponents.js +2 -2
  19. package/dist/microcomponents.min.js +1 -1
  20. package/dist/observables.min.js +1 -1
  21. package/dist/state/formValues.d.ts +111 -66
  22. package/dist/state/formValues.d.ts.map +1 -1
  23. package/dist/state/formValues.js +132 -68
  24. package/dist/state/observables.d.ts +68 -83
  25. package/dist/state/observables.d.ts.map +1 -1
  26. package/dist/state/observables.js +124 -84
  27. package/dist/utils/autoload.d.ts.map +1 -0
  28. package/dist/{core → utils}/autoload.js +2 -2
  29. package/dist/{core → utils}/events.d.ts +22 -0
  30. package/dist/utils/events.d.ts.map +1 -0
  31. package/dist/{core → utils}/events.js +26 -1
  32. package/dist/utils/helpers.d.ts +105 -20
  33. package/dist/utils/helpers.d.ts.map +1 -1
  34. package/dist/utils/helpers.js +210 -25
  35. package/package.json +12 -11
  36. package/dist/core/autoload.d.ts.map +0 -1
  37. package/dist/core/events.d.ts.map +0 -1
  38. /package/dist/{core → utils}/autoload.d.ts +0 -0
@@ -1,70 +1,115 @@
1
1
  /**
2
- * @module Form Values
3
- *
4
- * This module exports a single function {@link formValues} that traverses a DOM element
5
- * (usually an HTMLFormElement), collecting all input fields and creating a two-way bound
6
- * observable inside the target object:
7
- * - When input values change, the observable object updates accordingly.
8
- * - When the observable property values change, the input field values update in the DOM.
9
- *
10
- * **Prerequisites:**
11
- * - Input fields must have a `name` attribute.
12
- * - Names must be unique within the form.
13
- *
14
- * @example
15
- * ```ts
16
- * import { DC } from '@twobirds/microcomponents';
17
- * import { formValues } from '@twobirds/microcomponents/formValues';
18
- *
19
- * class MyMC extends DC {
20
- * constructor(target: HTMLElement) {
21
- * super(target);
22
- * this.target.innerHTML = '<form><input name="textinput" value="" /></form>';
23
- *
24
- * // link the form property to the DOM input fields
25
- * formValues(this, 'form', this.target);
26
- *
27
- * // changing the form property updates the DOM automatically
28
- * this.form.textinput = 'Hello world!';
29
- * }
30
- * }
31
- * ```
32
- */
2
+ Two-way binding between DOM form controls (`input`, `select`, `textarea`) and an observable
3
+ object property. Reads reflect live DOM values; writes update the controls synchronously.
4
+ Most likely you will only need the the first variant mentioned in the examples below.
5
+
6
+ @module Form Values
7
+
8
+ @example Plugin — chainable instance method on DC components
9
+ ```ts
10
+ import { DC, defineCE, formValuePlugin } from '@twobirds/microcomponents';
11
+
12
+ formValuePlugin(DC);
13
+
14
+ class CheckoutForm extends DC {
15
+ static assets = ['targetHtml'];
16
+
17
+ oneAssets() {
18
+ this
19
+ .formValues(this.target, 'formData')
20
+ .subscribe('formData', (data) => console.log(data))
21
+ .bind('formData', this.target);
22
+ }
23
+ }
24
+
25
+ defineCE('checkout-form', CheckoutForm);
26
+ ```
27
+
28
+ @example Standalone function — bind a plain object to a form in the DOM
29
+ ```ts
30
+ import { formValues } from '@twobirds/microcomponents/formValues';
31
+
32
+ const state = {};
33
+ formValues(state, 'formData', document.getElementById('myForm'));
34
+ console.log(state.formData.username); // reads <input name="username"> value
35
+ state.formData.role = 'admin'; // writes back to the <select> control
36
+ ```
37
+ */
33
38
  /**
34
- * Attaches a form-values observable to a target object property, allowing two-way binding
35
- * between the DOM form controls and the object's state.
36
- *
37
- * @param targetObject - The object to which the form values will be attached as an observable.
38
- * @param propertyName - The name of the property on the target object that will hold the form data.
39
- * @param dom - The DOM element or shadow root (typically a form) whose inputs should be observed and bound.
40
- *
41
- * @example
42
- * ```html
43
- * <form id="myForm">
44
- * <input type="text" name="username" value="">
45
- * <select name="role"><option value="admin">Admin</option><option value="user">User</option></select>
46
- * <textarea name="bio"></textarea>
47
- * <input type="checkbox" name="active">
48
- * <input type="radio" name="gender" value="male"> Male
49
- * <input type="radio" name="gender" value="female"> Female
50
- * </form>
51
- * ```
52
- *
53
- * ```ts
54
- * import { formValues } from '@twobirds/microcomponents/formValues';
55
- *
56
- * const state = {};
57
- * formValues(state, 'formData', document.getElementById('myForm'));
58
- *
59
- * // Read values from the form
60
- * console.log(state.formData.username); // string
61
- * console.log(state.formData.role); // "admin" or "user"
62
- * console.log(state.formData.active); // boolean
63
- *
64
- * // Write values to the form (updates DOM automatically)
65
- * state.formData.username = 'john_doe';
66
- * state.formData.gender = 'male';
67
- * ```
68
- */
39
+ Attaches a form-values observable to a target object property, enabling two-way binding
40
+ between DOM form controls and the object's state.
41
+
42
+ Scans the given DOM subtree for `input`, `select`, and `textarea` elements with a `name`
43
+ attribute and creates live getters/setters on the resulting observable. Input events trigger
44
+ automatic notifications so subscribers react to user changes.
45
+
46
+ @param targetObject - The object that will receive the form-data property.
47
+ @param propertyName - The property name under which the bound form data is stored.
48
+ @param dom - HTMLElement or ShadowRoot containing the form controls.
49
+
50
+ @example Bind a plain object to an HTML form element
51
+ ```ts
52
+ import { formValues } from '@twobirds/microcomponents/formValues';
53
+
54
+ const state = {};
55
+ formValues(state, 'formData', document.getElementById('myForm'));
56
+ console.log(state.formData.username); // reads <input name="username"> value
57
+ state.formData.role = 'admin'; // writes back to the <select> control
58
+ ```
59
+
60
+ @example Subscribe to form changes inside a component
61
+ ```ts
62
+ import { DC, defineCE, formValues } from '@twobirds/microcomponents';
63
+
64
+ class MyForm extends DC {
65
+ static assets = ['targetHtml'];
66
+
67
+ oneAssets() {
68
+ formValues(this, 'formData', this.target);
69
+ this.formData.subscribe((data) => console.log('form changed:', data));
70
+ }
71
+ }
72
+
73
+ defineCE('my-form', MyForm);
74
+ ```
75
+ */
69
76
  export declare function formValues<T extends object>(targetObject: T, propertyName: keyof T & string, dom: HTMLElement | ShadowRoot): void;
77
+ /**
78
+ Attaches a convenience method `formValues()` to the prototype of a microcomponent class so that
79
+ form controls can be bound directly on the instance without importing the standalone function.
80
+
81
+ This plugin also pulls in all observable methods from {@link observePlugin} — `notify()`,
82
+ `subscribe()`, and `bind()` — so you can chain them fluently after binding form data.
83
+
84
+ Call it once at module level before defining any component classes. The plugin is idempotent —
85
+ subsequent calls are no-ops.
86
+
87
+ @param Class - A constructor function whose prototype chain includes {@link McBase}.
88
+
89
+ @example
90
+ ```ts
91
+ import { DC, defineCE, formValuePlugin } from '@twobirds/microcomponents';
92
+
93
+ formValuePlugin(DC);
94
+
95
+ class CheckoutForm extends DC {
96
+ static assets = ['targetHtml'];
97
+
98
+ oneAssets() {
99
+ this
100
+ .formValues(this.target, 'formData')
101
+ .subscribe('formData', (data) => console.log(data))
102
+ .bind('formData', this.target);
103
+ }
104
+ }
105
+
106
+ defineCE('checkout-form', CheckoutForm);
107
+ ```
108
+ */
109
+ export declare function formValuePlugin(Class: any): void;
110
+ declare module '../core/MC' {
111
+ interface McBase<TTarget extends object = object> {
112
+ formValues(target: object, propName: string): this;
113
+ }
114
+ }
70
115
  //# sourceMappingURL=formValues.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"formValues.d.ts","sourceRoot":"","sources":["../../src/state/formValues.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AA4SH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAC1C,YAAY,EAAE,CAAC,EACf,YAAY,EAAE,MAAM,CAAC,GAAG,MAAM,EAC9B,GAAG,EAAE,WAAW,GAAG,UAAU,QAuB7B"}
1
+ {"version":3,"file":"formValues.d.ts","sourceRoot":"","sources":["../../src/state/formValues.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoCE;AA8SF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCE;AACF,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAC1C,YAAY,EAAE,CAAC,EACf,YAAY,EAAE,MAAM,CAAC,GAAG,MAAM,EAC9B,GAAG,EAAE,WAAW,GAAG,UAAU,QAuB7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+BE;AACF,wBAAgB,eAAe,CAAC,KAAK,EAAE,GAAG,QA2BzC;AAED,OAAO,QAAQ,YAAY,CAAC;IAC3B,UAAiB,MAAM,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM;QACtD,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;KACnD;CACD"}
@@ -1,38 +1,44 @@
1
1
  /**
2
- * @module Form Values
3
- *
4
- * This module exports a single function {@link formValues} that traverses a DOM element
5
- * (usually an HTMLFormElement), collecting all input fields and creating a two-way bound
6
- * observable inside the target object:
7
- * - When input values change, the observable object updates accordingly.
8
- * - When the observable property values change, the input field values update in the DOM.
9
- *
10
- * **Prerequisites:**
11
- * - Input fields must have a `name` attribute.
12
- * - Names must be unique within the form.
13
- *
14
- * @example
15
- * ```ts
16
- * import { DC } from '@twobirds/microcomponents';
17
- * import { formValues } from '@twobirds/microcomponents/formValues';
18
- *
19
- * class MyMC extends DC {
20
- * constructor(target: HTMLElement) {
21
- * super(target);
22
- * this.target.innerHTML = '<form><input name="textinput" value="" /></form>';
23
- *
24
- * // link the form property to the DOM input fields
25
- * formValues(this, 'form', this.target);
26
- *
27
- * // changing the form property updates the DOM automatically
28
- * this.form.textinput = 'Hello world!';
29
- * }
30
- * }
31
- * ```
32
- */
2
+ Two-way binding between DOM form controls (`input`, `select`, `textarea`) and an observable
3
+ object property. Reads reflect live DOM values; writes update the controls synchronously.
4
+ Most likely you will only need the the first variant mentioned in the examples below.
5
+
6
+ @module Form Values
7
+
8
+ @example Plugin — chainable instance method on DC components
9
+ ```ts
10
+ import { DC, defineCE, formValuePlugin } from '@twobirds/microcomponents';
11
+
12
+ formValuePlugin(DC);
13
+
14
+ class CheckoutForm extends DC {
15
+ static assets = ['targetHtml'];
16
+
17
+ oneAssets() {
18
+ this
19
+ .formValues(this.target, 'formData')
20
+ .subscribe('formData', (data) => console.log(data))
21
+ .bind('formData', this.target);
22
+ }
23
+ }
24
+
25
+ defineCE('checkout-form', CheckoutForm);
26
+ ```
27
+
28
+ @example Standalone function — bind a plain object to a form in the DOM
29
+ ```ts
30
+ import { formValues } from '@twobirds/microcomponents/formValues';
31
+
32
+ const state = {};
33
+ formValues(state, 'formData', document.getElementById('myForm'));
34
+ console.log(state.formData.username); // reads <input name="username"> value
35
+ state.formData.role = 'admin'; // writes back to the <select> control
36
+ ```
37
+ */
33
38
  import { DC } from '../core/MC.js';
34
39
  import { copyGettersSetters, isBrowser } from '../utils/helpers.js';
35
- import { observe } from './observables.js';
40
+ import { observe, observePlugin } from './observables.js';
41
+ observePlugin(DC);
36
42
  /**
37
43
  Extracts the lowercase tag name of an element (e.g., 'input', 'select', 'textarea').
38
44
  @param inputElement - The HTML element to extract the tag name from.
@@ -177,7 +183,7 @@ class SelectHandler extends InputBase {
177
183
  .forEach((o) => {
178
184
  ret.push(o.value);
179
185
  });
180
- return this.#multi ? ret.join(',') : ret[0];
186
+ return this.#multi ? ret : ret[0];
181
187
  }
182
188
  /**
183
189
  * Sets the selected option(s) by value.
@@ -279,41 +285,43 @@ const getInputHandlers = (e) => {
279
285
  return handlers;
280
286
  };
281
287
  /**
282
- * Attaches a form-values observable to a target object property, allowing two-way binding
283
- * between the DOM form controls and the object's state.
284
- *
285
- * @param targetObject - The object to which the form values will be attached as an observable.
286
- * @param propertyName - The name of the property on the target object that will hold the form data.
287
- * @param dom - The DOM element or shadow root (typically a form) whose inputs should be observed and bound.
288
- *
289
- * @example
290
- * ```html
291
- * <form id="myForm">
292
- * <input type="text" name="username" value="">
293
- * <select name="role"><option value="admin">Admin</option><option value="user">User</option></select>
294
- * <textarea name="bio"></textarea>
295
- * <input type="checkbox" name="active">
296
- * <input type="radio" name="gender" value="male"> Male
297
- * <input type="radio" name="gender" value="female"> Female
298
- * </form>
299
- * ```
300
- *
301
- * ```ts
302
- * import { formValues } from '@twobirds/microcomponents/formValues';
303
- *
304
- * const state = {};
305
- * formValues(state, 'formData', document.getElementById('myForm'));
306
- *
307
- * // Read values from the form
308
- * console.log(state.formData.username); // string
309
- * console.log(state.formData.role); // "admin" or "user"
310
- * console.log(state.formData.active); // boolean
311
- *
312
- * // Write values to the form (updates DOM automatically)
313
- * state.formData.username = 'john_doe';
314
- * state.formData.gender = 'male';
315
- * ```
316
- */
288
+ Attaches a form-values observable to a target object property, enabling two-way binding
289
+ between DOM form controls and the object's state.
290
+
291
+ Scans the given DOM subtree for `input`, `select`, and `textarea` elements with a `name`
292
+ attribute and creates live getters/setters on the resulting observable. Input events trigger
293
+ automatic notifications so subscribers react to user changes.
294
+
295
+ @param targetObject - The object that will receive the form-data property.
296
+ @param propertyName - The property name under which the bound form data is stored.
297
+ @param dom - HTMLElement or ShadowRoot containing the form controls.
298
+
299
+ @example Bind a plain object to an HTML form element
300
+ ```ts
301
+ import { formValues } from '@twobirds/microcomponents/formValues';
302
+
303
+ const state = {};
304
+ formValues(state, 'formData', document.getElementById('myForm'));
305
+ console.log(state.formData.username); // reads <input name="username"> value
306
+ state.formData.role = 'admin'; // writes back to the <select> control
307
+ ```
308
+
309
+ @example Subscribe to form changes inside a component
310
+ ```ts
311
+ import { DC, defineCE, formValues } from '@twobirds/microcomponents';
312
+
313
+ class MyForm extends DC {
314
+ static assets = ['targetHtml'];
315
+
316
+ oneAssets() {
317
+ formValues(this, 'formData', this.target);
318
+ this.formData.subscribe((data) => console.log('form changed:', data));
319
+ }
320
+ }
321
+
322
+ defineCE('my-form', MyForm);
323
+ ```
324
+ */
317
325
  export function formValues(targetObject, propertyName, dom) {
318
326
  /* v8 ignore next */
319
327
  if (!isBrowser())
@@ -332,3 +340,59 @@ export function formValues(targetObject, propertyName, dom) {
332
340
  });
333
341
  });
334
342
  }
343
+ /**
344
+ Attaches a convenience method `formValues()` to the prototype of a microcomponent class so that
345
+ form controls can be bound directly on the instance without importing the standalone function.
346
+
347
+ This plugin also pulls in all observable methods from {@link observePlugin} — `notify()`,
348
+ `subscribe()`, and `bind()` — so you can chain them fluently after binding form data.
349
+
350
+ Call it once at module level before defining any component classes. The plugin is idempotent —
351
+ subsequent calls are no-ops.
352
+
353
+ @param Class - A constructor function whose prototype chain includes {@link McBase}.
354
+
355
+ @example
356
+ ```ts
357
+ import { DC, defineCE, formValuePlugin } from '@twobirds/microcomponents';
358
+
359
+ formValuePlugin(DC);
360
+
361
+ class CheckoutForm extends DC {
362
+ static assets = ['targetHtml'];
363
+
364
+ oneAssets() {
365
+ this
366
+ .formValues(this.target, 'formData')
367
+ .subscribe('formData', (data) => console.log(data))
368
+ .bind('formData', this.target);
369
+ }
370
+ }
371
+
372
+ defineCE('checkout-form', CheckoutForm);
373
+ ```
374
+ */
375
+ export function formValuePlugin(Class) {
376
+ const McBaseProto = Object.getPrototypeOf(Class.prototype);
377
+ if (!Object.hasOwn(McBaseProto, 'formValues')) {
378
+ Object.assign(McBaseProto, {
379
+ /**
380
+ * Bind all named form controls inside a DOM subtree to an observable property on this instance.
381
+ * Ensures the property becomes observable and stays in sync with input changes.
382
+ * @param target - HTMLElement or ShadowRoot containing the form controls.
383
+ * @param propName - The name of the property that will hold the bound form data.
384
+ * @returns This instance for chaining.
385
+
386
+ @example
387
+ ```ts
388
+ this.formValues(this.target, 'formData');
389
+ // now this.formData.username reflects <input name="username"> live
390
+ ```
391
+ */
392
+ formValues: function (target, propName) {
393
+ formValues(this, propName, target);
394
+ return this; // chainable
395
+ },
396
+ });
397
+ }
398
+ }
@@ -1,104 +1,57 @@
1
1
  /**
2
- @module Observables
3
-
4
-
5
- This module provides reactive data binding capabilities using observables,
6
- enabling automatic DOM updates when underlying data changes.
7
-
8
- ## Overview
9
-
10
- The observable system allows you to make object properties "observable" so that
11
- registered callbacks are automatically invoked whenever those properties change.
12
- It's particularly designed for reactive templating and binding data to HTML elements.
13
- It can also handle simple object properties like strings, boolean and numbers.
14
-
15
- ## How `observe()` Works
2
+ Reactive data binding via observables — object properties trigger callbacks and update
3
+ DOM placeholders automatically when their values change. Supports primitives, nested objects,
4
+ and deep-change detection with debounced notifications. Most likely you will only need the first
5
+ variant of the examples below
16
6
 
17
- The main function is {@link observe}, which takes an object and makes its properties
18
- or a specific property observable.
19
-
20
- ### Simple properties
7
+ @module Observables
21
8
 
22
- javascript
23
- ```js
24
- let person = { name: "John", count: 0 };
9
+ @example Plugin — chainable instance methods on DC components
10
+ ```ts
11
+ import { DC, defineCE, observePlugin } from '@twobirds/microcomponents';
25
12
 
26
- observe( person ); // all properties inside are now observables
13
+ observePlugin(DC);
27
14
 
28
- person.name.subscribe( (name) => {
29
- console.log("Name changed:", name);
30
- });
15
+ class Counter extends DC {
16
+ data = { clicks: 1 };
31
17
 
32
- person.count.subscribe( (count) => {
33
- console.log("Count changed:", count);
34
- });
18
+ oneAssets() {
19
+ this
20
+ .subscribe('data', (v) => console.log('data →', v))
21
+ .bind('data', this.target);
22
+ }
23
+ }
35
24
 
36
- person.name = "Jane"; // > Name changed: Jane
37
- person.count += 10; // > Count changed: 10
25
+ defineCE('mc-counter', Counter);
38
26
  ```
39
27
 
40
- ### Deep Change Detection
41
-
42
- This means that if you modify any of the properties inside an observed object -> all callbacks are triggered.
43
-
44
- javascript
45
- ```js
46
- let obj = { data: { name: "John", count: 0 } };
47
-
48
- observe( obj, 'data' ); // make the data property observable
49
-
50
- obj.data.subscribe( (data) => {
51
- console.log("Data changed:", data);
52
- });
28
+ @example Basic observe + subscribe on a plain object
29
+ ```ts
30
+ import { observe } from '@twobirds/microcomponents';
53
31
 
54
- obj.data.name = "Jane"; // > { data: { name: "Jane", count: 0 } }
55
- obj.data.count += 10; // > { data: { name: "Jane", count: 10 } }
32
+ const state = observe({ count: 0, label: 'hi' });
33
+ state.count.subscribe((v) => console.log('count is now', v));
34
+ state.count++; // triggers the callback
56
35
  ```
57
36
 
58
- ### Debounced Notifications
59
-
60
- To prevent excessive updates, notifications are debounced briefly:
37
+ @example Deep change detection on a nested property
38
+ ```ts
39
+ import { observe } from '@twobirds/microcomponents';
61
40
 
62
- javascript
63
- ```js
64
- let obj = observe({ value: 1 });
65
- for (let i = 0; i < 100; i++) {
66
- obj.value++; // Only triggers one callback after all changes complete
67
- }
41
+ const state = observe({ data: { name: 'John', age: 30 } });
42
+ state.data.subscribe((d) => console.log('data changed:', d));
43
+ state.data.name = 'Jane'; // triggers callback with updated object
68
44
  ```
69
45
 
70
- ## DOM Binding with Placeholders
71
-
72
- The observables integrate tightly with placeholder-based templating:
73
-
74
- - Elements with `{placeholder}` syntax are scanned for observable data.
75
- - When observed data changes, matching placeholders in the DOM are updated automatically.
76
-
77
- @example
46
+ @example DOM binding — placeholder tokens update live
47
+ ```ts
48
+ import { observe } from '@twobirds/microcomponents';
78
49
 
79
- HTML
80
- ```html
81
- <div class="model {visibility}">
82
- Hello {name}! You have {count} messages.
83
- </div>
50
+ const state = observe({ user: { name: 'Alice', count: 0 } });
51
+ state.user.bind(document.querySelector('.model'));
52
+ // <span>{user.name}</span> updates automatically when state.user.name changes
84
53
  ```
85
54
 
86
- Javascript
87
- ```js
88
- const div = document.querySelector('.model');
89
-
90
- const model = observe({
91
- data: { name: "Alice", count: 0 },
92
- visibility: ''
93
- });
94
-
95
- if (div) {
96
- model.data.bind( div );
97
- }
98
-
99
- model.data.count++; // Automatically updates the DOM with new count value
100
- model.visibility = 'hidden'; // adds the hidden class to the DOM element
101
- ```
102
55
  */
103
56
  /**
104
57
  A callback invoked with the current observable value when notified.
@@ -273,4 +226,36 @@ state.count = 5; // plain assignment — the declared setter type permits it
273
226
  export declare function observe<T extends object, K extends keyof T>(target: T, propertyName: K): ObservedKey<T, K>;
274
227
  export declare function observe<T extends object>(target: T): Observed<T>;
275
228
  export declare function observe<S extends object>(target: Unobserved<S>): S;
229
+ /**
230
+ Attaches convenience methods `notify()`, `subscribe()`, and `bind()` to the prototype of a
231
+ microcomponent class so that observable properties can be controlled directly on the instance.
232
+
233
+ All three methods return the component instance, so you can chain them fluently.
234
+
235
+ Call it once at module level before defining any component classes. The plugin is idempotent —
236
+ subsequent calls are no-ops.
237
+
238
+ @param Class - A constructor function whose prototype chain includes {@link McBase}.
239
+
240
+ @example
241
+ ```ts
242
+ class Counter extends DC {
243
+ data = { clicks: 1 };
244
+
245
+ oneAssets() {
246
+ this
247
+ .subscribe('data', (v) => console.log('data →', v))
248
+ .bind('data', this.target);
249
+ }
250
+ }
251
+ ```
252
+ */
253
+ export declare function observePlugin(Class: any): void;
254
+ declare module '../core/MC' {
255
+ interface McBase<TTarget extends object = object> {
256
+ notify(propName: string): this;
257
+ subscribe(propName: string, callback: Function): this;
258
+ bind(propName: string, target: HTMLElement | ShadowRoot): this;
259
+ }
260
+ }
276
261
  //# sourceMappingURL=observables.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"observables.d.ts","sourceRoot":"","sources":["../../src/state/observables.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqGE;AAiBF;;;;;;;;EAQE;AACF,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAEvD;;;;;;;;;;;;EAYE;AACF,MAAM,MA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