@twobirds/microcomponents 0.3.0 → 0.4.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/README.md +91 -34
- package/dist/MC.min.js +1 -1
- package/dist/autoload.min.js +1 -1
- package/dist/cli/create.d.ts +53 -0
- package/dist/cli/create.d.ts.map +1 -0
- package/dist/cli/create.js +419 -0
- package/dist/cli/dispatch.d.ts +43 -0
- package/dist/cli/dispatch.d.ts.map +1 -0
- package/dist/cli/dispatch.js +287 -0
- package/dist/cli/index.d.ts +12 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +12 -0
- package/dist/cli/scaffold.d.ts +68 -0
- package/dist/cli/scaffold.d.ts.map +1 -0
- package/dist/cli/scaffold.js +109 -0
- package/dist/cli/writeScaffold.d.ts +66 -0
- package/dist/cli/writeScaffold.d.ts.map +1 -0
- package/dist/cli/writeScaffold.js +114 -0
- package/dist/core/MC.d.ts +50 -9
- package/dist/core/MC.d.ts.map +1 -1
- package/dist/core/MC.js +78 -33
- package/dist/core/elements.d.ts +11 -8
- package/dist/core/elements.d.ts.map +1 -1
- package/dist/core/elements.js +12 -7
- package/dist/core/mcGuards.d.ts +2 -2
- package/dist/elements.min.js +1 -1
- package/dist/formValues.min.js +1 -1
- package/dist/microcomponents.min.js +1 -1
- package/dist/observables.min.js +1 -1
- package/dist/state/formValues.d.ts +11 -5
- package/dist/state/formValues.d.ts.map +1 -1
- package/dist/state/formValues.js +18 -11
- package/dist/state/observables.d.ts +30 -13
- package/dist/state/observables.d.ts.map +1 -1
- package/dist/state/observables.js +64 -35
- package/dist/state/placeholders.d.ts.map +1 -1
- package/dist/state/placeholders.js +16 -11
- package/dist/types/mcTypes.d.ts +16 -7
- package/dist/types/mcTypes.d.ts.map +1 -1
- package/dist/utils/autoload.d.ts +6 -3
- package/dist/utils/autoload.d.ts.map +1 -1
- package/dist/utils/autoload.js +2 -2
- package/dist/utils/events.d.ts +21 -28
- package/dist/utils/events.d.ts.map +1 -1
- package/dist/utils/events.js +23 -29
- package/dist/utils/helpers.d.ts +19 -19
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/helpers.js +19 -19
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -2
- package/dist/utils/resolveComponentPath.d.ts +36 -0
- package/dist/utils/resolveComponentPath.d.ts.map +1 -0
- package/dist/utils/resolveComponentPath.js +39 -0
- package/package.json +19 -13
|
@@ -21,7 +21,6 @@ and returns them as an array of unique names (without braces).
|
|
|
21
21
|
@param target - The HTMLElement to scan for placeholders.
|
|
22
22
|
@returns An array of placeholder names found within the element's attributes and text content.
|
|
23
23
|
*/
|
|
24
|
-
/* v8 ignore start */
|
|
25
24
|
function getPlaceholders(target) {
|
|
26
25
|
const placeholders = new Set(), regEx = /\{[^\{\}]*\}/g;
|
|
27
26
|
// scan attributes
|
|
@@ -39,13 +38,14 @@ function getPlaceholders(target) {
|
|
|
39
38
|
childNode.nodeType === 3 && (childNode.nodeValue || '').match(regEx));
|
|
40
39
|
})
|
|
41
40
|
.forEach((childNode) => {
|
|
41
|
+
/* v8 ignore next -- the filter above matched nodeValue against the placeholder
|
|
42
|
+
pattern, so it is non-null and non-empty by the time we get here */
|
|
42
43
|
const textContent = childNode?.nodeValue || '';
|
|
43
44
|
const contentPlaceholders = textContent.match(regEx);
|
|
44
45
|
contentPlaceholders.forEach((textNodePlaceholder) => placeholders.add(textNodePlaceholder.replace(/[\{\}]/g, '')));
|
|
45
46
|
});
|
|
46
47
|
return [...placeholders];
|
|
47
48
|
}
|
|
48
|
-
/* v8 ignore end */
|
|
49
49
|
// Tag names instead of constructor references (HTMLInputElement etc.):
|
|
50
50
|
// evaluating those globals at module scope crashes any DOM-less import
|
|
51
51
|
// of the package (e.g. server-side use of MC).
|
|
@@ -80,10 +80,16 @@ class Placeholders extends DC {
|
|
|
80
80
|
const target = this.target;
|
|
81
81
|
let hide = false;
|
|
82
82
|
// scan attributes
|
|
83
|
-
|
|
83
|
+
/* v8 ignore next -- Placeholders is only ever constructed with an HTMLElement
|
|
84
|
+
(DC's constructor reads target.tagName), so the fragment/shadow-root guard
|
|
85
|
+
that getPlaceholders needs is dead here. */
|
|
86
|
+
const attrNames = target.getAttributeNames ? target.getAttributeNames() : [];
|
|
87
|
+
attrNames
|
|
84
88
|
.filter((attr) => target.getAttribute(attr)?.match(/\{[^\{\}]*\}/g)) // extract placeholder(s)
|
|
85
89
|
.forEach((attr) => {
|
|
86
90
|
const placeholders = new Set(target.getAttribute(attr)?.match(/\{[^\{\}]*\}/g));
|
|
91
|
+
/* v8 ignore next -- attr passed the filter above, so its value is a non-null string */
|
|
92
|
+
const attrTemplate = target.getAttribute(attr) ?? '';
|
|
87
93
|
// attach callback
|
|
88
94
|
this.data.subscribe(((template) => (data) => {
|
|
89
95
|
let result = template;
|
|
@@ -93,7 +99,7 @@ class Placeholders extends DC {
|
|
|
93
99
|
String(data[placeholder.replace(/[\{\}]/g, '')]));
|
|
94
100
|
});
|
|
95
101
|
target.setAttribute(attr, result);
|
|
96
|
-
})(
|
|
102
|
+
})(attrTemplate));
|
|
97
103
|
});
|
|
98
104
|
// scan children text nodes
|
|
99
105
|
[...target.childNodes]
|
|
@@ -104,11 +110,12 @@ class Placeholders extends DC {
|
|
|
104
110
|
})
|
|
105
111
|
.forEach((childNode) => {
|
|
106
112
|
hide = true;
|
|
107
|
-
|
|
113
|
+
/* v8 ignore next -- the filter above only admits text nodes with a non-empty
|
|
114
|
+
nodeValue, so the ?? fallback is unreachable */
|
|
115
|
+
const textTemplate = childNode.nodeValue ?? '';
|
|
116
|
+
const placeholders = new Set(textTemplate.match(/\{[^\{\}]*\}/g));
|
|
108
117
|
// attach callback
|
|
109
|
-
this.data.subscribe(
|
|
110
|
-
/* v8 ignore start */
|
|
111
|
-
((template) => (data) => {
|
|
118
|
+
this.data.subscribe(((template) => (data) => {
|
|
112
119
|
let result = template;
|
|
113
120
|
placeholders.forEach((placeholder) => {
|
|
114
121
|
result = result.replace(placeholder,
|
|
@@ -123,9 +130,7 @@ class Placeholders extends DC {
|
|
|
123
130
|
}
|
|
124
131
|
delete this.oldDisplay;
|
|
125
132
|
childNode.nodeValue = result;
|
|
126
|
-
})(
|
|
127
|
-
/* v8 ignore end */
|
|
128
|
-
);
|
|
133
|
+
})(textTemplate));
|
|
129
134
|
// hide for now
|
|
130
135
|
this.oldDisplay = target.getAttribute('style') || ''; // TBD allow null to indicate there was no old style attribute
|
|
131
136
|
if (hide && !inputTags.includes(target.tagName) && target.tagName !== 'FIELDSET') {
|
package/dist/types/mcTypes.d.ts
CHANGED
|
@@ -46,11 +46,13 @@ is in the component's event map (`EM` on `DC`) and let it be inferred.
|
|
|
46
46
|
@example
|
|
47
47
|
```ts
|
|
48
48
|
cart.on('CartUpdate', (ev: McEvent<{ count: number }>) => {
|
|
49
|
-
ev.detail.data.count;
|
|
50
|
-
ev.detail.control.stop();
|
|
49
|
+
console.log(ev.detail.data.count);
|
|
50
|
+
ev.detail.control.stop();
|
|
51
51
|
});
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
+
`ev.detail.data.count` is typed `number`; `ev.detail.control.stop()` halts further bubbling.
|
|
55
|
+
|
|
54
56
|
@template D - The payload type under `ev.detail.data`.
|
|
55
57
|
*/
|
|
56
58
|
export type McEvent<D = unknown> = CustomEvent<McDetail<D>>;
|
|
@@ -82,9 +84,12 @@ declare global {
|
|
|
82
84
|
|
|
83
85
|
const el = document.querySelector('form');
|
|
84
86
|
if (el && isMcHost(el, 'cart')) {
|
|
85
|
-
el._mc.cart.addItem(item);
|
|
87
|
+
el._mc.cart.addItem(item);
|
|
86
88
|
}
|
|
87
89
|
```
|
|
90
|
+
|
|
91
|
+
Inside the guard, `el._mc.cart` is typed as `Cart`.
|
|
92
|
+
|
|
88
93
|
*/
|
|
89
94
|
interface McRegistry {
|
|
90
95
|
}
|
|
@@ -127,10 +132,12 @@ Type-only — nothing exists at runtime.
|
|
|
127
132
|
@example
|
|
128
133
|
```ts
|
|
129
134
|
class Panel extends DC implements McNativeEventHandlers {
|
|
130
|
-
onClick(ev: MouseEvent) {}
|
|
131
|
-
// onClick(ev: KeyboardEvent) {} // ✗ wrong event type
|
|
135
|
+
onClick(ev: MouseEvent) {}
|
|
132
136
|
}
|
|
133
137
|
```
|
|
138
|
+
|
|
139
|
+
`onClick` is checked against the native `'click'` event type. Declaring
|
|
140
|
+
`onClick(ev: KeyboardEvent)` instead is a compile error.
|
|
134
141
|
*/
|
|
135
142
|
export type McNativeEventHandlers = {
|
|
136
143
|
[K in keyof GlobalEventHandlersEventMap as `on${Capitalize<K>}` | `one${Capitalize<K>}`]?: (ev: GlobalEventHandlersEventMap[K]) => void;
|
|
@@ -146,9 +153,11 @@ their entries into `R`.
|
|
|
146
153
|
@example
|
|
147
154
|
```ts
|
|
148
155
|
const withA = DC.add(form, 'a', { a: 0 });
|
|
149
|
-
withA._mc.a.a;
|
|
150
|
-
withA._mc.b; // ✗ never registered
|
|
156
|
+
console.log(withA._mc.a.a);
|
|
151
157
|
```
|
|
158
|
+
|
|
159
|
+
`withA._mc.a.a` is typed `number`. Accessing `withA._mc.b` is a compile error
|
|
160
|
+
because that key was never registered.
|
|
152
161
|
*/
|
|
153
162
|
export type McHost<T extends HTMLElement = HTMLElement, R extends Record<string, unknown> = Record<never, never>> = T & {
|
|
154
163
|
/** The hosted microcomponents: the controller API plus one entry per `add()` key. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcTypes.d.ts","sourceRoot":"","sources":["../../src/types/mcTypes.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AAEF,yGAAyG;AACzG,MAAM,WAAW,kBAAkB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,IAAI,IAAI,CAAC;CACb;AAED,gGAAgG;AAChG,MAAM,MAAM,eAAe,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAE9C;;;;EAIE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AAE,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,KAAK,CAAC;AAEtF;;;;;;;EAOE;AACF,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS;IAAE,GAAG,EAAE,YAAY,CAAA;CAAE,GAC7F;IAAE,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;CAAE,GACzB,OAAO,CAAC;AAOX,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,wBAAwB;QACjC,kFAAkF;QAClF,MAAM,CAAC,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC;KACpC;CACD"}
|
package/dist/utils/autoload.d.ts
CHANGED
|
@@ -16,10 +16,13 @@ set of microcomponent names currently loading via its `state` property.
|
|
|
16
16
|
```ts
|
|
17
17
|
import { autoload } from '@twobirds/microcomponents';
|
|
18
18
|
|
|
19
|
-
autoload(true);
|
|
20
|
-
console.log(autoload.state);
|
|
21
|
-
autoload(false);
|
|
19
|
+
autoload(true);
|
|
20
|
+
console.log(autoload.state);
|
|
21
|
+
autoload(false);
|
|
22
22
|
```
|
|
23
|
+
|
|
24
|
+
`autoload(true)` enables auto-loading, `autoload.state` is the set of component
|
|
25
|
+
names currently loading, and `autoload(false)` disables it again.
|
|
23
26
|
@group Autoload
|
|
24
27
|
*/
|
|
25
28
|
export interface Autoload {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autoload.d.ts","sourceRoot":"","sources":["../../src/utils/autoload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;EASE;
|
|
1
|
+
{"version":3,"file":"autoload.d.ts","sourceRoot":"","sources":["../../src/utils/autoload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;EASE;AAsJF;;;;;;;;;;;;;;;;EAgBE;AACF,MAAM,WAAW,QAAQ;IACxB;;;;;;;;;;;;;IAaG;IACH,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;IAC5B;;;;;IAKG;IACH,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACnB;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,MAAM;QACf,QAAQ,CAAC,EAAE,QAAQ,CAAC;KACpB;CACD;AAID,wBAAgB,QAAQ,CAAC,MAAM,GAAE,OAAc,GAAG,OAAO,CAuBxD;yBAvBe,QAAQ"}
|
package/dist/utils/autoload.js
CHANGED
|
@@ -10,6 +10,7 @@ importing `DC`/`MC` never pulls a DOM observer into the bundle unless
|
|
|
10
10
|
*/
|
|
11
11
|
import { DC } from '../core/MC.js';
|
|
12
12
|
import { isMcHost } from '../core/mcGuards.js';
|
|
13
|
+
import { resolveComponentPath } from './resolveComponentPath.js';
|
|
13
14
|
const loadingDCs = new Set();
|
|
14
15
|
/**
|
|
15
16
|
Creates a closure that attaches DOM elements with the specified tag name to
|
|
@@ -75,7 +76,7 @@ function makeLoadScript(element) {
|
|
|
75
76
|
if (loadingDCs.has(element))
|
|
76
77
|
return; // already loading
|
|
77
78
|
loadingDCs.add(element);
|
|
78
|
-
const fileName =
|
|
79
|
+
const fileName = resolveComponentPath(element);
|
|
79
80
|
const scriptElement = document.createElement('script');
|
|
80
81
|
scriptElement.setAttribute('src', fileName);
|
|
81
82
|
scriptElement.setAttribute('blocking', 'render');
|
|
@@ -156,5 +157,4 @@ export function autoload(enable = true) {
|
|
|
156
157
|
window.autoload ??= autoload;
|
|
157
158
|
return true;
|
|
158
159
|
}
|
|
159
|
-
;
|
|
160
160
|
autoload.state = loadingDCs;
|
package/dist/utils/events.d.ts
CHANGED
|
@@ -29,32 +29,24 @@ javascript:
|
|
|
29
29
|
```javascript
|
|
30
30
|
import { on, one, trigger, off } from '@twobirds/microcomponents/events';
|
|
31
31
|
|
|
32
|
-
// Attach listeners (querySelector may return null — guard first)
|
|
33
32
|
const grandParent = document.querySelector('.grandparent');
|
|
34
33
|
const parent = document.querySelector('.parent');
|
|
35
34
|
const child = document.querySelector('.child');
|
|
36
35
|
if (!grandParent || !parent || !child) throw new Error('example markup missing');
|
|
37
36
|
|
|
38
|
-
const grandParentHandler = on(
|
|
39
|
-
grandParent,
|
|
40
|
-
'dataReady',
|
|
41
|
-
(ev) => console.log(ev.detail.data)
|
|
42
|
-
);
|
|
37
|
+
const grandParentHandler = on(grandParent, 'dataReady', (ev) => console.log(ev.detail.data));
|
|
43
38
|
|
|
44
|
-
const parentHandler = on(
|
|
45
|
-
parent,
|
|
46
|
-
'dataReady',
|
|
47
|
-
(ev) => ev.detail.control.stop()
|
|
48
|
-
);
|
|
39
|
+
const parentHandler = on(parent, 'dataReady', (ev) => ev.detail.control.stop());
|
|
49
40
|
|
|
50
|
-
|
|
51
|
-
trigger( child, 'dataReady', { value: 42 }, 'u');
|
|
52
|
-
// ...but the 'dataReady' handler on grandParent will never be reached !!!
|
|
41
|
+
trigger(child, 'dataReady', { value: 42 }, 'u');
|
|
53
42
|
|
|
54
|
-
|
|
55
|
-
off(
|
|
56
|
-
off( grandParent, 'dataReady', grandParentHandler );
|
|
43
|
+
off(parent, 'dataReady', parentHandler);
|
|
44
|
+
off(grandParent, 'dataReady', grandParentHandler);
|
|
57
45
|
```
|
|
46
|
+
|
|
47
|
+
The `dataReady` event bubbles upward from the innermost `div`, but `parentHandler`
|
|
48
|
+
calls `ev.detail.control.stop()`, so the `grandParent` handler is never reached.
|
|
49
|
+
Handlers are detached with `off()` once they are no longer needed.
|
|
58
50
|
*/
|
|
59
51
|
import type { BubbleDirections, McBubbleController, McEventHandler } from '../types/mcTypes.js';
|
|
60
52
|
export type { BubbleDirections } from '../types/mcTypes.js';
|
|
@@ -68,7 +60,7 @@ export type { BubbleDirections } from '../types/mcTypes.js';
|
|
|
68
60
|
*
|
|
69
61
|
* @example
|
|
70
62
|
* ```ts
|
|
71
|
-
* getMcEventName('update');
|
|
63
|
+
* console.log(getMcEventName('update'));
|
|
72
64
|
* ```
|
|
73
65
|
*/
|
|
74
66
|
export declare function getMcEventName(eventName: string): string;
|
|
@@ -88,9 +80,13 @@ export declare function getMcEventName(eventName: string): string;
|
|
|
88
80
|
* @example
|
|
89
81
|
* ```ts
|
|
90
82
|
* const btn = document.createElement('button');
|
|
91
|
-
* trueEventName(btn, 'Click');
|
|
92
|
-
* trueEventName(btn, 'Update');
|
|
83
|
+
* console.log(trueEventName(btn, 'Click'));
|
|
84
|
+
* console.log(trueEventName(btn, 'Update'));
|
|
93
85
|
* ```
|
|
86
|
+
*
|
|
87
|
+
* `'Click'` resolves to the native `'click'` because the button has an `onclick` handler
|
|
88
|
+
* property; `'Update'` has no native counterpart, so it becomes the `_mc`-prefixed custom
|
|
89
|
+
* event name.
|
|
94
90
|
*/
|
|
95
91
|
export declare function trueEventName(target: HTMLElement, eventName: string): string;
|
|
96
92
|
/**
|
|
@@ -109,12 +105,12 @@ a CSS selector string, or `undefined` (which is silently ignored).
|
|
|
109
105
|
|
|
110
106
|
@example
|
|
111
107
|
```ts
|
|
112
|
-
// Pass an HTMLElement directly
|
|
113
108
|
const el: TargetSelect = document.getElementById('root');
|
|
114
|
-
|
|
115
|
-
// Or pass a selector string to match multiple elements
|
|
116
109
|
const allCards: TargetSelect = '.card';
|
|
117
110
|
```
|
|
111
|
+
|
|
112
|
+
A `TargetSelect` accepts an `HTMLElement` directly, or a selector string that matches
|
|
113
|
+
multiple elements.
|
|
118
114
|
@group Events
|
|
119
115
|
*/
|
|
120
116
|
export type TargetSelect = HTMLElement | QuerySelectorString | undefined | null;
|
|
@@ -137,7 +133,6 @@ export declare function one(target: TargetSelect, eventName: string, handler: Ev
|
|
|
137
133
|
* ```ts
|
|
138
134
|
* trigger(myElement, 'update', { value: 42 }, 'u');
|
|
139
135
|
*
|
|
140
|
-
* // inside a handler you can call ev.detail.control.stop() to halt propagation
|
|
141
136
|
* onUpdate(ev) {
|
|
142
137
|
* ev.detail.control.stop();
|
|
143
138
|
* }
|
|
@@ -156,7 +151,6 @@ export declare class BubbleController implements McBubbleController {
|
|
|
156
151
|
* ```ts
|
|
157
152
|
* trigger(myElement, 'update', { value: 42 }, 'u');
|
|
158
153
|
*
|
|
159
|
-
* // inside a handler you can call ev.detail.control.stop() to halt propagation
|
|
160
154
|
* onUpdate(ev) {
|
|
161
155
|
* ev.detail.control.stop();
|
|
162
156
|
* }
|
|
@@ -184,12 +178,11 @@ export declare class BubbleController implements McBubbleController {
|
|
|
184
178
|
*
|
|
185
179
|
* @example
|
|
186
180
|
* ```ts
|
|
187
|
-
* // Trigger a local event with data
|
|
188
181
|
* trigger(myElement, 'update', { value: 42 }, 'l');
|
|
189
|
-
*
|
|
190
|
-
* // Bubble up to ancestors
|
|
191
182
|
* trigger(myElement, 'dataReady', { ready: true }, 'u');
|
|
192
183
|
* ```
|
|
184
|
+
*
|
|
185
|
+
* The first dispatch fires locally only; the second bubbles upward to ancestor components.
|
|
193
186
|
*/
|
|
194
187
|
export declare function trigger<D = unknown>(target: HTMLElement | string | undefined | null, event: string, data?: D, bubble?: BubbleDirections, // direction of bubbling
|
|
195
188
|
controller?: BubbleController): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/utils/events.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/utils/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiDE;AAIF,OAAO,KAAK,EACX,gBAAgB,EAChB,kBAAkB,EAElB,cAAc,EACd,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAExD;AAED;;;;;;;;;;;;;;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AAiB,YAAW,kBAAkB;IAC1D,OAAO,UAAS;;IAEhB;;;;;;;;;;;;;;OAcG;IACH,IAAI;CAGJ;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,OAAO,CAAC,CAAC,GAAG,OAAO,EAClC,MAAM,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,EAC/C,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,CAAW,EACjB,MAAM,GAAE,gBAAsB,EAAE,wBAAwB;AACxD,UAAU,CAAC,EAAE,gBAAgB,QA+C7B"}
|
package/dist/utils/events.js
CHANGED
|
@@ -29,32 +29,24 @@ javascript:
|
|
|
29
29
|
```javascript
|
|
30
30
|
import { on, one, trigger, off } from '@twobirds/microcomponents/events';
|
|
31
31
|
|
|
32
|
-
// Attach listeners (querySelector may return null — guard first)
|
|
33
32
|
const grandParent = document.querySelector('.grandparent');
|
|
34
33
|
const parent = document.querySelector('.parent');
|
|
35
34
|
const child = document.querySelector('.child');
|
|
36
35
|
if (!grandParent || !parent || !child) throw new Error('example markup missing');
|
|
37
36
|
|
|
38
|
-
const grandParentHandler = on(
|
|
39
|
-
grandParent,
|
|
40
|
-
'dataReady',
|
|
41
|
-
(ev) => console.log(ev.detail.data)
|
|
42
|
-
);
|
|
37
|
+
const grandParentHandler = on(grandParent, 'dataReady', (ev) => console.log(ev.detail.data));
|
|
43
38
|
|
|
44
|
-
const parentHandler = on(
|
|
45
|
-
parent,
|
|
46
|
-
'dataReady',
|
|
47
|
-
(ev) => ev.detail.control.stop()
|
|
48
|
-
);
|
|
39
|
+
const parentHandler = on(parent, 'dataReady', (ev) => ev.detail.control.stop());
|
|
49
40
|
|
|
50
|
-
|
|
51
|
-
trigger( child, 'dataReady', { value: 42 }, 'u');
|
|
52
|
-
// ...but the 'dataReady' handler on grandParent will never be reached !!!
|
|
41
|
+
trigger(child, 'dataReady', { value: 42 }, 'u');
|
|
53
42
|
|
|
54
|
-
|
|
55
|
-
off(
|
|
56
|
-
off( grandParent, 'dataReady', grandParentHandler );
|
|
43
|
+
off(parent, 'dataReady', parentHandler);
|
|
44
|
+
off(grandParent, 'dataReady', grandParentHandler);
|
|
57
45
|
```
|
|
46
|
+
|
|
47
|
+
The `dataReady` event bubbles upward from the innermost `div`, but `parentHandler`
|
|
48
|
+
calls `ev.detail.control.stop()`, so the `grandParent` handler is never reached.
|
|
49
|
+
Handlers are detached with `off()` once they are no longer needed.
|
|
58
50
|
*/
|
|
59
51
|
'use strict';
|
|
60
52
|
/**
|
|
@@ -67,7 +59,7 @@ off( grandParent, 'dataReady', grandParentHandler );
|
|
|
67
59
|
*
|
|
68
60
|
* @example
|
|
69
61
|
* ```ts
|
|
70
|
-
* getMcEventName('update');
|
|
62
|
+
* console.log(getMcEventName('update'));
|
|
71
63
|
* ```
|
|
72
64
|
*/
|
|
73
65
|
export function getMcEventName(eventName) {
|
|
@@ -89,9 +81,13 @@ export function getMcEventName(eventName) {
|
|
|
89
81
|
* @example
|
|
90
82
|
* ```ts
|
|
91
83
|
* const btn = document.createElement('button');
|
|
92
|
-
* trueEventName(btn, 'Click');
|
|
93
|
-
* trueEventName(btn, 'Update');
|
|
84
|
+
* console.log(trueEventName(btn, 'Click'));
|
|
85
|
+
* console.log(trueEventName(btn, 'Update'));
|
|
94
86
|
* ```
|
|
87
|
+
*
|
|
88
|
+
* `'Click'` resolves to the native `'click'` because the button has an `onclick` handler
|
|
89
|
+
* property; `'Update'` has no native counterpart, so it becomes the `_mc`-prefixed custom
|
|
90
|
+
* event name.
|
|
95
91
|
*/
|
|
96
92
|
export function trueEventName(target, eventName) {
|
|
97
93
|
const lower = eventName.toLowerCase();
|
|
@@ -113,7 +109,7 @@ For communication between frontend microcomponents, use the `DC.off()` method in
|
|
|
113
109
|
@example
|
|
114
110
|
```ts
|
|
115
111
|
const handler = on(myElement, 'click', () => console.log('clicked'));
|
|
116
|
-
off(myElement, 'click', handler);
|
|
112
|
+
off(myElement, 'click', handler);
|
|
117
113
|
```
|
|
118
114
|
@group Events
|
|
119
115
|
*/
|
|
@@ -149,9 +145,9 @@ The handler receives a `CustomEvent<McDetail<D>>`: the payload sits under
|
|
|
149
145
|
@example
|
|
150
146
|
```ts
|
|
151
147
|
const handler = on<{ value: number }>(myElement, 'update', (ev) => {
|
|
152
|
-
console.log(ev.detail.data.value);
|
|
148
|
+
console.log(ev.detail.data.value);
|
|
153
149
|
});
|
|
154
|
-
|
|
150
|
+
off(myElement, 'update', handler);
|
|
155
151
|
```
|
|
156
152
|
@group Events
|
|
157
153
|
*/
|
|
@@ -187,8 +183,9 @@ For communication between frontend microcomponents, use the `DC.one()` method in
|
|
|
187
183
|
@example
|
|
188
184
|
```ts
|
|
189
185
|
one<{ ready: boolean }>(myElement, 'dataReady', (ev) => console.log('received:', ev.detail.data));
|
|
190
|
-
// fires only once then detaches automatically
|
|
191
186
|
```
|
|
187
|
+
|
|
188
|
+
The listener fires only once and detaches automatically.
|
|
192
189
|
@group Events
|
|
193
190
|
*/
|
|
194
191
|
export function one(target, eventName, handler) {
|
|
@@ -217,7 +214,6 @@ export function one(target, eventName, handler) {
|
|
|
217
214
|
* ```ts
|
|
218
215
|
* trigger(myElement, 'update', { value: 42 }, 'u');
|
|
219
216
|
*
|
|
220
|
-
* // inside a handler you can call ev.detail.control.stop() to halt propagation
|
|
221
217
|
* onUpdate(ev) {
|
|
222
218
|
* ev.detail.control.stop();
|
|
223
219
|
* }
|
|
@@ -236,7 +232,6 @@ export class BubbleController {
|
|
|
236
232
|
* ```ts
|
|
237
233
|
* trigger(myElement, 'update', { value: 42 }, 'u');
|
|
238
234
|
*
|
|
239
|
-
* // inside a handler you can call ev.detail.control.stop() to halt propagation
|
|
240
235
|
* onUpdate(ev) {
|
|
241
236
|
* ev.detail.control.stop();
|
|
242
237
|
* }
|
|
@@ -266,12 +261,11 @@ export class BubbleController {
|
|
|
266
261
|
*
|
|
267
262
|
* @example
|
|
268
263
|
* ```ts
|
|
269
|
-
* // Trigger a local event with data
|
|
270
264
|
* trigger(myElement, 'update', { value: 42 }, 'l');
|
|
271
|
-
*
|
|
272
|
-
* // Bubble up to ancestors
|
|
273
265
|
* trigger(myElement, 'dataReady', { ready: true }, 'u');
|
|
274
266
|
* ```
|
|
267
|
+
*
|
|
268
|
+
* The first dispatch fires locally only; the second bubbles upward to ancestor components.
|
|
275
269
|
*/
|
|
276
270
|
export function trigger(target, event, data = {}, bubble = 'l', // direction of bubbling
|
|
277
271
|
controller) {
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -34,10 +34,10 @@ export declare function isBrowser(): boolean;
|
|
|
34
34
|
*
|
|
35
35
|
* @example
|
|
36
36
|
* ```ts
|
|
37
|
-
* isNativeObject({});
|
|
38
|
-
* isNativeObject(new Object());
|
|
39
|
-
* isNativeObject([]);
|
|
40
|
-
* isNativeObject(null);
|
|
37
|
+
* console.log(isNativeObject({}));
|
|
38
|
+
* console.log(isNativeObject(new Object()));
|
|
39
|
+
* console.log(isNativeObject([]));
|
|
40
|
+
* console.log(isNativeObject(null));
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
43
|
export declare function isNativeObject(value: unknown): value is Record<string, unknown>;
|
|
@@ -49,7 +49,7 @@ export declare function isNativeObject(value: unknown): value is Record<string,
|
|
|
49
49
|
* @example
|
|
50
50
|
* ```ts
|
|
51
51
|
* const obj = { z: 1, a: { y: 2, b: 3 } };
|
|
52
|
-
* sortObject(obj);
|
|
52
|
+
* console.log(JSON.stringify(sortObject(obj)));
|
|
53
53
|
* ```
|
|
54
54
|
*/
|
|
55
55
|
export declare function sortObject<T extends Record<string, unknown>>(source: T): T;
|
|
@@ -63,7 +63,7 @@ export declare function sortObject<T extends Record<string, unknown>>(source: T)
|
|
|
63
63
|
* @example
|
|
64
64
|
* ```ts
|
|
65
65
|
* const obj = { user: { name: 'Alice', age: 30 } };
|
|
66
|
-
* flattenObject(obj);
|
|
66
|
+
* console.log(JSON.stringify(flattenObject(obj)));
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
69
|
export declare function flattenObject(source: object, doSort?: boolean): Record<string, unknown>;
|
|
@@ -80,10 +80,10 @@ export declare function flattenObject(source: object, doSort?: boolean): Record<
|
|
|
80
80
|
*
|
|
81
81
|
* @example
|
|
82
82
|
* ```ts
|
|
83
|
-
* deepEqual({ a: 1 }, { a: 1 });
|
|
84
|
-
* deepEqual({ a: { b: 2 } }, { a: {} });
|
|
85
|
-
* deepEqual({ a: NaN }, { a: NaN });
|
|
86
|
-
* deepEqual({ a: NaN }, { a: null });
|
|
83
|
+
* console.log(deepEqual({ a: 1 }, { a: 1 }));
|
|
84
|
+
* console.log(deepEqual({ a: { b: 2 } }, { a: {} }));
|
|
85
|
+
* console.log(deepEqual({ a: NaN }, { a: NaN }));
|
|
86
|
+
* console.log(deepEqual({ a: NaN }, { a: null }));
|
|
87
87
|
* ```
|
|
88
88
|
*/
|
|
89
89
|
export declare function deepEqual(a: unknown, b: unknown): boolean;
|
|
@@ -96,8 +96,8 @@ export declare function deepEqual(a: unknown, b: unknown): boolean;
|
|
|
96
96
|
* @example
|
|
97
97
|
* ```ts
|
|
98
98
|
* const data = { user: { profile: { name: 'Alice' } } };
|
|
99
|
-
* nameSpace('user.profile.name', data);
|
|
100
|
-
* nameSpace(['user', 'profile'], data);
|
|
99
|
+
* console.log(nameSpace('user.profile.name', data));
|
|
100
|
+
* console.log(nameSpace(['user', 'profile'], data));
|
|
101
101
|
* ```
|
|
102
102
|
*/
|
|
103
103
|
export declare function nameSpace(ns: string | string[], obj?: object): unknown;
|
|
@@ -112,9 +112,8 @@ export declare function nameSpace(ns: string | string[], obj?: object): unknown;
|
|
|
112
112
|
* @example
|
|
113
113
|
* ```ts
|
|
114
114
|
* const data = { user: { name: 'Alice' } };
|
|
115
|
-
* parse('Hello {user.name}!', data);
|
|
116
|
-
*
|
|
117
|
-
* parse(['Hi {user.name}', 'Bye {user.name}'], data); // ['Hi Alice', 'Bye Alice']
|
|
115
|
+
* console.log(parse('Hello {user.name}!', data));
|
|
116
|
+
* console.log(parse(['Hi {user.name}', 'Bye {user.name}'], data));
|
|
118
117
|
* ```
|
|
119
118
|
*/
|
|
120
119
|
export declare function parse<T = string | object | unknown[]>(template: T, parseThis: object, ...rest: unknown[]): T;
|
|
@@ -126,7 +125,7 @@ export declare function parse<T = string | object | unknown[]>(template: T, pars
|
|
|
126
125
|
*
|
|
127
126
|
* @example
|
|
128
127
|
* ```ts
|
|
129
|
-
* kebabToPascal('my-element');
|
|
128
|
+
* console.log(kebabToPascal('my-element'));
|
|
130
129
|
* ```
|
|
131
130
|
*/
|
|
132
131
|
export declare function kebabToPascal(str: string): string;
|
|
@@ -141,7 +140,8 @@ export declare function kebabToPascal(str: string): string;
|
|
|
141
140
|
* @example
|
|
142
141
|
* ```ts
|
|
143
142
|
* const log = debounce(() => console.log('called'), 300);
|
|
144
|
-
* log();
|
|
143
|
+
* log();
|
|
144
|
+
* log();
|
|
145
145
|
* ```
|
|
146
146
|
*/
|
|
147
147
|
export declare function debounce<A extends unknown[]>(func: (...args: A) => unknown, milliseconds: number): (...args: A) => void;
|
|
@@ -155,7 +155,7 @@ export declare function debounce<A extends unknown[]>(func: (...args: A) => unkn
|
|
|
155
155
|
* @example
|
|
156
156
|
* ```ts
|
|
157
157
|
* const elems = htmlToElements('<div>Hello</div><span>World</span>');
|
|
158
|
-
*
|
|
158
|
+
* console.log(elems.map((el) => el.tagName));
|
|
159
159
|
* ```
|
|
160
160
|
*/
|
|
161
161
|
export declare function htmlToElements(html: string): HTMLElement[];
|
|
@@ -171,7 +171,7 @@ export declare function htmlToElements(html: string): HTMLElement[];
|
|
|
171
171
|
* const src = { get name() { return 'Alice'; } };
|
|
172
172
|
* const tgt = {};
|
|
173
173
|
* copyGettersSetters(src, tgt);
|
|
174
|
-
* console.log(tgt.name);
|
|
174
|
+
* console.log(tgt.name);
|
|
175
175
|
* ```
|
|
176
176
|
*/
|
|
177
177
|
export declare function copyGettersSetters(source: object, target: object): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAE/E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAiB1E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,OAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAqB7F;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAiCzD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,GAAG,GAAE,MAAW,GAAG,OAAO,CAe1E;AAED
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,M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