nuclo 0.2.23 → 0.2.25
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 +20 -18
- package/dist/element/attributes.d.ts.map +1 -1
- package/dist/element/event-attributes.d.ts +5 -0
- package/dist/element/event-attributes.d.ts.map +1 -0
- package/dist/element/events.d.ts +2 -2
- package/dist/element/events.d.ts.map +1 -1
- package/dist/element/modifiers.d.ts +1 -1
- package/dist/element/modifiers.d.ts.map +1 -1
- package/dist/list/template.d.ts +1 -1
- package/dist/list/template.d.ts.map +1 -1
- package/dist/nuclo.cjs +1 -1
- package/dist/nuclo.cjs.map +1 -1
- package/dist/nuclo.mjs +1 -1
- package/dist/nuclo.mjs.map +1 -1
- package/dist/nuclo.umd.js +1 -1
- package/dist/nuclo.umd.js.map +1 -1
- package/dist/when/runtime.d.ts +1 -1
- package/dist/when/runtime.d.ts.map +1 -1
- package/package.json +2 -2
- package/types/core/base.d.ts +30 -11
- package/types/core/events.d.ts +223 -0
- package/types/features/on.d.ts +8 -10
- package/types/features/when.d.ts +8 -7
- package/types/index.d.ts +8 -2
package/dist/when/runtime.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { UpdateScope } from "../update/scope";
|
|
2
2
|
export type WhenCondition = boolean | (() => boolean);
|
|
3
|
-
export type WhenContent<TTagName extends ElementTagName = ElementTagName> =
|
|
3
|
+
export type WhenContent<TTagName extends ElementTagName = ElementTagName> = NodeModLike<TTagName>;
|
|
4
4
|
export interface WhenGroup<TTagName extends ElementTagName = ElementTagName> {
|
|
5
5
|
condition: WhenCondition;
|
|
6
6
|
content: WhenContent<TTagName>[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/when/runtime.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAKnD,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC;AACtD,MAAM,MAAM,WAAW,CAAC,QAAQ,SAAS,cAAc,GAAG,cAAc,IACtE,
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/when/runtime.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAKnD,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC;AACtD,MAAM,MAAM,WAAW,CAAC,QAAQ,SAAS,cAAc,GAAG,cAAc,IACtE,WAAW,CAAC,QAAQ,CAAC,CAAC;AAExB,MAAM,WAAW,SAAS,CAAC,QAAQ,SAAS,cAAc,GAAG,cAAc;IACzE,SAAS,EAAE,aAAa,CAAC;IACzB,OAAO,EAAE,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;CAClC;AAED,MAAM,WAAW,WAAW,CAAC,QAAQ,SAAS,cAAc,GAAG,cAAc;IAC3E,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC9B,WAAW,EAAE,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;IACrC;;;;;OAKG;IACH,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,IAAI,IAAI,CAAC;CAChB;AAmBD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,SAAS,cAAc,EACrE,MAAM,EAAE,aAAa,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,EAC1C,WAAW,EAAE,aAAa,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,GAChD,MAAM,GAAG,IAAI,CAOf;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,SAAS,cAAc,EAC/D,OAAO,EAAE,WAAW,CAAC,QAAQ,CAAC,GAC7B,IAAI,CAoBN;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,SAAS,cAAc,EACjE,OAAO,EAAE,WAAW,CAAC,QAAQ,CAAC,GAC7B,IAAI,CAKN;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,CAAC,EAAE,WAAW,GAAG,IAAI,CA0C5D;AA8BD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,SAAS,cAAc,EAChE,KAAK,EAAE,aAAa,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,EAC3C,IAAI,EAAE,eAAe,CAAC,QAAQ,CAAC,EAC/B,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,OAAO,GACjB,IAAI,EAAE,CASR"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuclo",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.25",
|
|
5
5
|
"description": "Lightweight, type-safe DOM library with plain mutable state and explicit updates — global tag builders, SSR, hydration, and typed CSS, no virtual DOM, no compiler.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Danilo Celestino de Castro (https://github.com/dan2dev)",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"@eslint/markdown": "^8.0.3",
|
|
69
69
|
"@types/node": "^25.9.5",
|
|
70
70
|
"@vitest/coverage-v8": "4.1.7",
|
|
71
|
-
"eslint": "^10.8.
|
|
71
|
+
"eslint": "^10.8.1",
|
|
72
72
|
"globals": "^17.9.0",
|
|
73
73
|
"jiti": "^2.7.0",
|
|
74
74
|
"jsdom": "^29.1.1",
|
package/types/core/base.d.ts
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
|
+
import "./events";
|
|
1
2
|
|
|
3
|
+
declare const anyParentNodeModifierTag: unique symbol;
|
|
4
|
+
|
|
5
|
+
type NativeElementAttributes<TTagName extends ElementTagName> = {
|
|
6
|
+
[K in keyof HTMLElementTagNameMap[TTagName] as K extends `on${string}` ? never : K]?:
|
|
7
|
+
K extends "style"
|
|
8
|
+
? ValueOrFactory<CSSStyleObject>
|
|
9
|
+
: ValueOrFactory<HTMLElementTagNameMap[TTagName][K]>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type LowercaseEventAttributes<TTagName extends ElementTagName> = {
|
|
13
|
+
[K in Extract<keyof HTMLElementTagNameMap[TTagName], `on${string}`>]?: never;
|
|
14
|
+
};
|
|
2
15
|
|
|
3
16
|
declare global {
|
|
4
17
|
export type Primitive = string | number | bigint | boolean | symbol | null | undefined;
|
|
@@ -27,22 +40,27 @@ declare global {
|
|
|
27
40
|
// Core element attribute types
|
|
28
41
|
export type ExpandedElementAttributes<
|
|
29
42
|
TTagName extends ElementTagName = ElementTagName,
|
|
30
|
-
> =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
[key: string]: ValueOrFactory<unknown>;
|
|
38
|
-
};
|
|
43
|
+
> = NativeElementAttributes<TTagName>
|
|
44
|
+
& CamelCaseEventAttributes<TTagName>
|
|
45
|
+
& LowercaseEventAttributes<TTagName>
|
|
46
|
+
& {
|
|
47
|
+
// Allow custom attributes (data-*, aria-*, etc.)
|
|
48
|
+
[key: string]: ValueOrFactory<unknown>;
|
|
49
|
+
};
|
|
39
50
|
|
|
40
51
|
export type DetachedExpandedElementFactory<
|
|
41
52
|
TTagName extends ElementTagName = ElementTagName,
|
|
42
53
|
> = NodeModFn<TTagName> & ((
|
|
43
54
|
parent?: ExpandedElement<TTagName>,
|
|
44
55
|
index?: number,
|
|
45
|
-
) => ExpandedElement<TTagName>)
|
|
56
|
+
) => ExpandedElement<TTagName>) & {
|
|
57
|
+
readonly [anyParentNodeModifierTag]: true;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** Type-only marker for modifiers whose runtime accepts any parent tag. */
|
|
61
|
+
export type AnyParentNodeModifier = {
|
|
62
|
+
readonly [anyParentNodeModifierTag]: true;
|
|
63
|
+
};
|
|
46
64
|
|
|
47
65
|
// Core element type
|
|
48
66
|
export type ExpandedElement<
|
|
@@ -72,7 +90,8 @@ declare global {
|
|
|
72
90
|
|
|
73
91
|
export type NodeModLike<TTagName extends ElementTagName = ElementTagName> =
|
|
74
92
|
| NodeMod<TTagName>
|
|
75
|
-
| NodeModFn<TTagName
|
|
93
|
+
| NodeModFn<TTagName>
|
|
94
|
+
| AnyParentNodeModifier;
|
|
76
95
|
|
|
77
96
|
export type InferExpandedElement<TValue> =
|
|
78
97
|
TValue extends ExpandedElement<infer TTagName>
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
export type TypedEventListener<
|
|
3
|
+
TElement extends EventTarget,
|
|
4
|
+
TEvent extends Event = Event,
|
|
5
|
+
> = (this: TElement, event: TEvent & { currentTarget: TElement }) => unknown;
|
|
6
|
+
|
|
7
|
+
/** Public camel-cased attribute name to native DOM event name. */
|
|
8
|
+
export interface HTMLElementEventAttributeNameMap {
|
|
9
|
+
onAbort: "abort";
|
|
10
|
+
onAnimationCancel: "animationcancel";
|
|
11
|
+
onAnimationEnd: "animationend";
|
|
12
|
+
onAnimationIteration: "animationiteration";
|
|
13
|
+
onAnimationStart: "animationstart";
|
|
14
|
+
onAuxClick: "auxclick";
|
|
15
|
+
onBeforeInput: "beforeinput";
|
|
16
|
+
onBeforeMatch: "beforematch";
|
|
17
|
+
onBeforeToggle: "beforetoggle";
|
|
18
|
+
onBlur: "blur";
|
|
19
|
+
onCancel: "cancel";
|
|
20
|
+
onCanPlay: "canplay";
|
|
21
|
+
onCanPlayThrough: "canplaythrough";
|
|
22
|
+
onChange: "change";
|
|
23
|
+
onClick: "click";
|
|
24
|
+
onClose: "close";
|
|
25
|
+
onCommand: "command";
|
|
26
|
+
onCompositionEnd: "compositionend";
|
|
27
|
+
onCompositionStart: "compositionstart";
|
|
28
|
+
onCompositionUpdate: "compositionupdate";
|
|
29
|
+
onContextLost: "contextlost";
|
|
30
|
+
onContextMenu: "contextmenu";
|
|
31
|
+
onContextRestored: "contextrestored";
|
|
32
|
+
onCopy: "copy";
|
|
33
|
+
onCueChange: "cuechange";
|
|
34
|
+
onCut: "cut";
|
|
35
|
+
onDblClick: "dblclick";
|
|
36
|
+
onDoubleClick: "dblclick";
|
|
37
|
+
onDrag: "drag";
|
|
38
|
+
onDragEnd: "dragend";
|
|
39
|
+
onDragEnter: "dragenter";
|
|
40
|
+
onDragLeave: "dragleave";
|
|
41
|
+
onDragOver: "dragover";
|
|
42
|
+
onDragStart: "dragstart";
|
|
43
|
+
onDrop: "drop";
|
|
44
|
+
onDurationChange: "durationchange";
|
|
45
|
+
onEmptied: "emptied";
|
|
46
|
+
onEnded: "ended";
|
|
47
|
+
onError: "error";
|
|
48
|
+
onFocus: "focus";
|
|
49
|
+
onFocusIn: "focusin";
|
|
50
|
+
onFocusOut: "focusout";
|
|
51
|
+
onFormData: "formdata";
|
|
52
|
+
onFullscreenChange: "fullscreenchange";
|
|
53
|
+
onFullscreenError: "fullscreenerror";
|
|
54
|
+
onGotPointerCapture: "gotpointercapture";
|
|
55
|
+
onInput: "input";
|
|
56
|
+
onInvalid: "invalid";
|
|
57
|
+
onKeyDown: "keydown";
|
|
58
|
+
onKeyPress: "keypress";
|
|
59
|
+
onKeyUp: "keyup";
|
|
60
|
+
onLoad: "load";
|
|
61
|
+
onLoadedData: "loadeddata";
|
|
62
|
+
onLoadedMetadata: "loadedmetadata";
|
|
63
|
+
onLoadStart: "loadstart";
|
|
64
|
+
onLostPointerCapture: "lostpointercapture";
|
|
65
|
+
onMouseDown: "mousedown";
|
|
66
|
+
onMouseEnter: "mouseenter";
|
|
67
|
+
onMouseLeave: "mouseleave";
|
|
68
|
+
onMouseMove: "mousemove";
|
|
69
|
+
onMouseOut: "mouseout";
|
|
70
|
+
onMouseOver: "mouseover";
|
|
71
|
+
onMouseUp: "mouseup";
|
|
72
|
+
onPaste: "paste";
|
|
73
|
+
onPause: "pause";
|
|
74
|
+
onPlay: "play";
|
|
75
|
+
onPlaying: "playing";
|
|
76
|
+
onPointerCancel: "pointercancel";
|
|
77
|
+
onPointerDown: "pointerdown";
|
|
78
|
+
onPointerEnter: "pointerenter";
|
|
79
|
+
onPointerLeave: "pointerleave";
|
|
80
|
+
onPointerMove: "pointermove";
|
|
81
|
+
onPointerOut: "pointerout";
|
|
82
|
+
onPointerOver: "pointerover";
|
|
83
|
+
onPointerRawUpdate: "pointerrawupdate";
|
|
84
|
+
onPointerUp: "pointerup";
|
|
85
|
+
onProgress: "progress";
|
|
86
|
+
onRateChange: "ratechange";
|
|
87
|
+
onReset: "reset";
|
|
88
|
+
onResize: "resize";
|
|
89
|
+
onScroll: "scroll";
|
|
90
|
+
onScrollEnd: "scrollend";
|
|
91
|
+
onSecurityPolicyViolation: "securitypolicyviolation";
|
|
92
|
+
onSeeked: "seeked";
|
|
93
|
+
onSeeking: "seeking";
|
|
94
|
+
onSelect: "select";
|
|
95
|
+
onSelectionChange: "selectionchange";
|
|
96
|
+
onSelectStart: "selectstart";
|
|
97
|
+
onSlotChange: "slotchange";
|
|
98
|
+
onStalled: "stalled";
|
|
99
|
+
onSubmit: "submit";
|
|
100
|
+
onSuspend: "suspend";
|
|
101
|
+
onTimeUpdate: "timeupdate";
|
|
102
|
+
onToggle: "toggle";
|
|
103
|
+
onTouchCancel: "touchcancel";
|
|
104
|
+
onTouchEnd: "touchend";
|
|
105
|
+
onTouchMove: "touchmove";
|
|
106
|
+
onTouchStart: "touchstart";
|
|
107
|
+
onTransitionCancel: "transitioncancel";
|
|
108
|
+
onTransitionEnd: "transitionend";
|
|
109
|
+
onTransitionRun: "transitionrun";
|
|
110
|
+
onTransitionStart: "transitionstart";
|
|
111
|
+
onVolumeChange: "volumechange";
|
|
112
|
+
onWaiting: "waiting";
|
|
113
|
+
onWebkitAnimationEnd: "webkitanimationend";
|
|
114
|
+
onWebkitAnimationIteration: "webkitanimationiteration";
|
|
115
|
+
onWebkitAnimationStart: "webkitanimationstart";
|
|
116
|
+
onWebkitTransitionEnd: "webkittransitionend";
|
|
117
|
+
onWheel: "wheel";
|
|
118
|
+
onEncrypted: "encrypted";
|
|
119
|
+
onWaitingForKey: "waitingforkey";
|
|
120
|
+
onEnterPictureInPicture: "enterpictureinpicture";
|
|
121
|
+
onLeavePictureInPicture: "leavepictureinpicture";
|
|
122
|
+
onAfterPrint: "afterprint";
|
|
123
|
+
onBeforePrint: "beforeprint";
|
|
124
|
+
onBeforeUnload: "beforeunload";
|
|
125
|
+
onGamepadConnected: "gamepadconnected";
|
|
126
|
+
onGamepadDisconnected: "gamepaddisconnected";
|
|
127
|
+
onHashChange: "hashchange";
|
|
128
|
+
onLanguageChange: "languagechange";
|
|
129
|
+
onMessage: "message";
|
|
130
|
+
onMessageError: "messageerror";
|
|
131
|
+
onOffline: "offline";
|
|
132
|
+
onOnline: "online";
|
|
133
|
+
onPageHide: "pagehide";
|
|
134
|
+
onPageReveal: "pagereveal";
|
|
135
|
+
onPageShow: "pageshow";
|
|
136
|
+
onPageSwap: "pageswap";
|
|
137
|
+
onPopState: "popstate";
|
|
138
|
+
onRejectionHandled: "rejectionhandled";
|
|
139
|
+
onStorage: "storage";
|
|
140
|
+
onUnhandledRejection: "unhandledrejection";
|
|
141
|
+
onUnload: "unload";
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
type EventMapForElement<TElement> =
|
|
147
|
+
TElement extends HTMLVideoElement
|
|
148
|
+
? HTMLVideoElementEventMap
|
|
149
|
+
: TElement extends HTMLMediaElement
|
|
150
|
+
? HTMLMediaElementEventMap
|
|
151
|
+
: TElement extends HTMLBodyElement
|
|
152
|
+
? HTMLBodyElementEventMap
|
|
153
|
+
: HTMLElementEventMap;
|
|
154
|
+
|
|
155
|
+
type NativeHTMLElementEventName =
|
|
156
|
+
| keyof HTMLElementEventMap
|
|
157
|
+
| keyof HTMLMediaElementEventMap
|
|
158
|
+
| keyof HTMLVideoElementEventMap
|
|
159
|
+
| keyof HTMLBodyElementEventMap;
|
|
160
|
+
|
|
161
|
+
type NativeHTMLElementTagNameForEvent<TEventName extends NativeHTMLElementEventName> =
|
|
162
|
+
TEventName extends keyof HTMLElementEventMap
|
|
163
|
+
? ElementTagName
|
|
164
|
+
: TEventName extends keyof HTMLMediaElementEventMap
|
|
165
|
+
? "audio" | "video"
|
|
166
|
+
: TEventName extends keyof HTMLVideoElementEventMap
|
|
167
|
+
? "video"
|
|
168
|
+
: TEventName extends keyof HTMLBodyElementEventMap
|
|
169
|
+
? "body"
|
|
170
|
+
: never;
|
|
171
|
+
|
|
172
|
+
type NativeHTMLElementEventForName<TEventName extends NativeHTMLElementEventName> =
|
|
173
|
+
TEventName extends keyof HTMLElementEventMap
|
|
174
|
+
? HTMLElementEventMap[TEventName]
|
|
175
|
+
: TEventName extends keyof HTMLMediaElementEventMap
|
|
176
|
+
? HTMLMediaElementEventMap[TEventName]
|
|
177
|
+
: TEventName extends keyof HTMLVideoElementEventMap
|
|
178
|
+
? HTMLVideoElementEventMap[TEventName]
|
|
179
|
+
: TEventName extends keyof HTMLBodyElementEventMap
|
|
180
|
+
? HTMLBodyElementEventMap[TEventName]
|
|
181
|
+
: never;
|
|
182
|
+
|
|
183
|
+
type EventForAttribute<
|
|
184
|
+
TElement,
|
|
185
|
+
TAttribute extends keyof HTMLElementEventAttributeNameMap,
|
|
186
|
+
> = HTMLElementEventAttributeNameMap[TAttribute] extends infer TEventName extends keyof EventMapForElement<TElement>
|
|
187
|
+
? EventMapForElement<TElement>[TEventName]
|
|
188
|
+
: never;
|
|
189
|
+
|
|
190
|
+
type EventAttributeValue<
|
|
191
|
+
TElement extends EventTarget,
|
|
192
|
+
TAttribute extends keyof HTMLElementEventAttributeNameMap,
|
|
193
|
+
> = [EventForAttribute<TElement, TAttribute>] extends [never]
|
|
194
|
+
? never
|
|
195
|
+
: EventForAttribute<TElement, TAttribute> extends infer TEvent extends Event
|
|
196
|
+
? TypedEventListener<TElement, TEvent>
|
|
197
|
+
: never;
|
|
198
|
+
|
|
199
|
+
declare global {
|
|
200
|
+
/** Every standard event name exposed by an HTML element event map. */
|
|
201
|
+
export type NucloHTMLElementEventName = NativeHTMLElementEventName;
|
|
202
|
+
|
|
203
|
+
/** HTML tag names on which a standard event is available. */
|
|
204
|
+
export type NucloHTMLElementTagNameForEvent<
|
|
205
|
+
TEventName extends NucloHTMLElementEventName,
|
|
206
|
+
> = NativeHTMLElementTagNameForEvent<TEventName>;
|
|
207
|
+
|
|
208
|
+
/** The native event object inferred from a standard event name. */
|
|
209
|
+
export type NucloHTMLElementEventForName<
|
|
210
|
+
TEventName extends NucloHTMLElementEventName,
|
|
211
|
+
> = NativeHTMLElementEventForName<TEventName>;
|
|
212
|
+
|
|
213
|
+
export type CamelCaseEventAttributes<
|
|
214
|
+
TTagName extends keyof HTMLElementTagNameMap = keyof HTMLElementTagNameMap,
|
|
215
|
+
> = {
|
|
216
|
+
[TAttribute in keyof HTMLElementEventAttributeNameMap]?: EventAttributeValue<
|
|
217
|
+
HTMLElementTagNameMap[TTagName],
|
|
218
|
+
TAttribute
|
|
219
|
+
>;
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export {};
|
package/types/features/on.d.ts
CHANGED
|
@@ -5,22 +5,17 @@
|
|
|
5
5
|
* button(
|
|
6
6
|
* "Click me",
|
|
7
7
|
* on("click", (e) => {
|
|
8
|
-
* // e
|
|
8
|
+
* // e and currentTarget come from the native event map
|
|
9
9
|
* // example: console.log(e.clientX);
|
|
10
10
|
* })
|
|
11
11
|
* );
|
|
12
12
|
*
|
|
13
13
|
* Overloads:
|
|
14
|
-
* 1. DOM standard events (strongly typed via
|
|
14
|
+
* 1. DOM standard events (strongly typed via the tag's native event map)
|
|
15
15
|
* 2. Custom / arbitrary event names with user-specified event type
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
declare global {
|
|
19
|
-
export type TypedEventListener<
|
|
20
|
-
TElement extends EventTarget,
|
|
21
|
-
TEvent extends Event = Event,
|
|
22
|
-
> = (this: TElement, ev: TEvent & { currentTarget: TElement }) => unknown;
|
|
23
|
-
|
|
24
19
|
/**
|
|
25
20
|
* Add a strongly typed DOM event listener as a View Craft modifier.
|
|
26
21
|
*
|
|
@@ -31,11 +26,14 @@ declare global {
|
|
|
31
26
|
* @param options Native addEventListener options.
|
|
32
27
|
*/
|
|
33
28
|
function on<
|
|
34
|
-
K extends
|
|
35
|
-
TTagName extends
|
|
29
|
+
K extends NucloHTMLElementEventName,
|
|
30
|
+
TTagName extends NucloHTMLElementTagNameForEvent<K> = NucloHTMLElementTagNameForEvent<K>,
|
|
36
31
|
>(
|
|
37
32
|
type: K,
|
|
38
|
-
listener: TypedEventListener<
|
|
33
|
+
listener: TypedEventListener<
|
|
34
|
+
HTMLElementTagNameMap[TTagName],
|
|
35
|
+
NucloHTMLElementEventForName<K>
|
|
36
|
+
>,
|
|
39
37
|
options?: boolean | AddEventListenerOptions
|
|
40
38
|
): NodeModFn<TTagName>;
|
|
41
39
|
|
package/types/features/when.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
declare global {
|
|
2
2
|
// When/conditional rendering types
|
|
3
3
|
export type WhenCondition = boolean | (() => boolean);
|
|
4
|
-
export type WhenContent<TTagName extends ElementTagName = ElementTagName> =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export interface WhenBuilder<TTagName extends ElementTagName = ElementTagName>
|
|
4
|
+
export type WhenContent<TTagName extends ElementTagName = ElementTagName> =
|
|
5
|
+
NodeModLike<TTagName>;
|
|
6
|
+
|
|
7
|
+
export interface WhenBuilder<TTagName extends ElementTagName = ElementTagName>
|
|
8
|
+
extends NodeModFn<TTagName>, AnyParentNodeModifier {
|
|
8
9
|
when(condition: WhenCondition, ...content: WhenContent<TTagName>[]): WhenBuilder<TTagName>;
|
|
9
10
|
else(...content: WhenContent<TTagName>[]): WhenBuilder<TTagName>;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
+
|
|
12
13
|
export function when<TTagName extends ElementTagName = ElementTagName>(
|
|
13
|
-
condition: WhenCondition,
|
|
14
|
+
condition: WhenCondition,
|
|
14
15
|
...content: WhenContent<TTagName>[]
|
|
15
16
|
): WhenBuilder<TTagName>;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
export {};
|
|
19
|
+
export {};
|
package/types/index.d.ts
CHANGED
|
@@ -74,9 +74,15 @@ export function hydrate<TTagName extends ElementTagName = ElementTagName>(
|
|
|
74
74
|
): ExpandedElement<TTagName>;
|
|
75
75
|
|
|
76
76
|
// on() helper (same overloads as the global)
|
|
77
|
-
export function on<
|
|
77
|
+
export function on<
|
|
78
|
+
K extends NucloHTMLElementEventName,
|
|
79
|
+
TTagName extends NucloHTMLElementTagNameForEvent<K> = NucloHTMLElementTagNameForEvent<K>,
|
|
80
|
+
>(
|
|
78
81
|
type: K,
|
|
79
|
-
listener: TypedEventListener<
|
|
82
|
+
listener: TypedEventListener<
|
|
83
|
+
HTMLElementTagNameMap[TTagName],
|
|
84
|
+
NucloHTMLElementEventForName<K>
|
|
85
|
+
>,
|
|
80
86
|
options?: boolean | AddEventListenerOptions
|
|
81
87
|
): NodeModFn<TTagName>;
|
|
82
88
|
export function on<K extends string, E extends Event = Event, TTagName extends ElementTagName = ElementTagName>(
|