@tempots/dom 28.6.3 → 29.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.
@@ -186,6 +186,40 @@ export declare const on: {
186
186
  waiting: (handler: (event: Event, ctx: DOMContext) => void) => Renderable;
187
187
  wheel: (handler: (event: WheelEvent, ctx: DOMContext) => void) => Renderable;
188
188
  };
189
+ /**
190
+ * Options for event handlers.
191
+ *
192
+ * @public
193
+ */
194
+ export type EmitOptions = {
195
+ preventDefault?: boolean;
196
+ stopPropagation?: boolean;
197
+ stopImmediatePropagation?: boolean;
198
+ };
199
+ /**
200
+ * Creates an event handler that calls the provided function with the event as an argument.
201
+ * @param fn - The function to call when the event is triggered.
202
+ * @returns An event handler function that can be used with event listeners.
203
+ * @public
204
+ */
205
+ export declare const emit: (fn: (event: Event) => void, options?: EmitOptions) => (event: Event) => void;
206
+ /**
207
+ * Creates an event handler that extracts and emits the target element from an event.
208
+ *
209
+ * @example
210
+ * ```typescript
211
+ * html.input(
212
+ * on.input(emitTarget((input) => {
213
+ * console.log('Input value:', input.value)
214
+ * }))
215
+ * )
216
+ * ```
217
+ *
218
+ * @param fn - Callback function that receives the target element
219
+ * @returns Event handler function that can be used with event listeners
220
+ * @public
221
+ */
222
+ export declare const emitTarget: <EL extends HTMLElement>(fn: (element: EL, event: Event) => void, options?: EmitOptions) => (event: Event) => void;
189
223
  /**
190
224
  * Creates an event handler that extracts and emits the string value from an input element.
191
225
  *
@@ -220,7 +254,7 @@ export declare const on: {
220
254
  * @returns Event handler function that can be used with event listeners
221
255
  * @public
222
256
  */
223
- export declare const emitValue: (fn: (text: string) => void) => (event: Event) => void;
257
+ export declare const emitValue: (fn: (text: string, event: Event) => void, options?: EmitOptions) => (event: Event) => void;
224
258
  /**
225
259
  * Creates an event handler that extracts and emits the numeric value from an input element.
226
260
  *
@@ -261,35 +295,35 @@ export declare const emitValue: (fn: (text: string) => void) => (event: Event) =
261
295
  * @returns Event handler function that can be used with event listeners
262
296
  * @public
263
297
  */
264
- export declare const emitValueAsNumber: (fn: (num: number) => void) => (event: Event) => void;
298
+ export declare const emitValueAsNumber: (fn: (num: number, event: Event) => void, options?: EmitOptions) => (event: Event) => void;
265
299
  /**
266
300
  * Converts the value of an HTML input element to a Date object and emits it using the provided callback function.
267
301
  * @param fn - The callback function to be called with the converted Date object.
268
302
  * @returns A function that can be used as an event handler for input events.
269
303
  * @public
270
304
  */
271
- export declare const emitValueAsDate: (fn: (date: Date) => void) => (event: Event) => void;
305
+ export declare const emitValueAsDate: (fn: (date: Date, event: Event) => void, options?: EmitOptions) => (event: Event) => void;
272
306
  /**
273
307
  * Converts the value of an HTML input element to a Date object or null and emits it using the provided callback function.
274
308
  * @param fn - The callback function to be called with the converted Date object or null.
275
309
  * @returns A function that can be used as an event handler for input events.
276
310
  * @public
277
311
  */
278
- export declare const emitValueAsNullableDate: (fn: (date: Date | null) => void) => (event: Event) => void;
312
+ export declare const emitValueAsNullableDate: (fn: (date: Date | null, event: Event) => void, options?: EmitOptions) => (event: Event) => void;
279
313
  /**
280
314
  * Emits the value of an HTMLInputElement as a Date object.
281
315
  * @param fn - The callback function to be called with the emitted Date object.
282
316
  * @returns The event handler function.
283
317
  * @public
284
318
  */
285
- export declare const emitValueAsDateTime: (fn: (date: Date) => void) => (event: Event) => void;
319
+ export declare const emitValueAsDateTime: (fn: (date: Date, event: Event) => void, options?: EmitOptions) => (event: Event) => void;
286
320
  /**
287
321
  * Emits the value of an HTMLInputElement as a Date object or null.
288
322
  * @param fn - The callback function to be called with the emitted Date object or null.
289
323
  * @returns The event handler function.
290
324
  * @public
291
325
  */
292
- export declare const emitValueAsNullableDateTime: (fn: (date: Date | null) => void) => (event: Event) => void;
326
+ export declare const emitValueAsNullableDateTime: (fn: (date: Date | null, event: Event) => void, options?: EmitOptions) => (event: Event) => void;
293
327
  /**
294
328
  * Creates an event handler that extracts and emits the checked state from a checkbox or radio input.
295
329
  *
@@ -342,25 +376,4 @@ export declare const emitValueAsNullableDateTime: (fn: (date: Date | null) => vo
342
376
  * @returns Event handler function that can be used with event listeners
343
377
  * @public
344
378
  */
345
- export declare const emitChecked: (fn: (checked: boolean) => void) => (event: Event) => void;
346
- /**
347
- * Wraps a function to prevent the default behavior of an event before invoking it.
348
- * @param fn - The function to be wrapped.
349
- * @returns A new function that prevents the default behavior of the event and then invokes the original function.
350
- * @public
351
- */
352
- export declare const emitPreventDefault: (fn: () => void) => (event: Event) => void;
353
- /**
354
- * Creates a new event handler that stops event propagation and invokes the provided function.
355
- * @param fn - The function to be invoked when the event is triggered.
356
- * @returns A new event handler function.
357
- * @public
358
- */
359
- export declare const emitStopPropagation: (fn: () => void) => (event: Event) => void;
360
- /**
361
- * Creates an event handler that stops immediate propagation of the event and invokes the provided function.
362
- * @param fn - The function to be invoked.
363
- * @returns The event handler function.
364
- * @public
365
- */
366
- export declare const emitStopImmediatePropagation: (fn: () => void) => (event: Event) => void;
379
+ export declare const emitChecked: (fn: (checked: boolean, event: Event) => void, options?: EmitOptions) => (event: Event) => void;
package/types/domain.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DOMContext } from '../dom/dom-context';
2
- import { Computed, Prop, Signal } from '../std/signal';
2
+ import { AnySignal, Computed, Prop, Signal } from '../std/signal';
3
3
  import { Value } from '../std/value';
4
4
  /**
5
5
  * A function that renders content into the DOM and returns a cleanup function.
@@ -149,13 +149,14 @@ export type Size = {
149
149
  */
150
150
  readonly height: number;
151
151
  };
152
- type WithNullish<X> = Value<X> | Value<X | null> | Value<X | undefined> | Value<X | null | undefined>;
153
152
  /**
154
153
  * Represents a nullable value or a signal of a nullable value.
155
154
  * @typeParam T - The type of the value.
156
155
  * @public
157
156
  */
158
- export type NValue<T> = WithNullish<T> | null | undefined;
157
+ export type NValue<T> = Value<NonNullable<T>> | AnySignal<T> | AnySignal<T | null> | AnySignal<T | undefined> | AnySignal<T | null | undefined> | null | undefined;
158
+ type TupleToUnion<T extends unknown[]> = T[number];
159
+ export type SplitNValue<T> = (T extends unknown ? TupleToUnion<NValue<T>[]> : never) | NValue<T>;
159
160
  /**
160
161
  * Gets the value type of a given Value type.
161
162
  * If the type is a `Signal`, it returns the inferred value type.