@tempots/dom 32.0.0 → 33.1.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tempots/dom",
3
- "version": "32.0.0",
3
+ "version": "33.1.0",
4
4
  "type": "module",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
@@ -1,5 +1,30 @@
1
1
  import { Renderable, SplitNValue } from '../types/domain';
2
2
  import { Value } from '../std/value';
3
+ /**
4
+ * Creates a renderable for an HTML attribute with the specified name and value.
5
+ *
6
+ * This is the functional equivalent of using `attr[name](value)` with a dynamic attribute name.
7
+ *
8
+ * The `class` attribute is special and can be used multiple times on the same element.
9
+ * Multiple class values will be merged together.
10
+ *
11
+ * @param name - The name of the attribute.
12
+ * @param value - The value of the attribute (can be a literal or Signal).
13
+ * @returns A renderable that sets the attribute.
14
+ * @example
15
+ * ```ts
16
+ * const button = html.button(
17
+ * Attr('type', 'button'),
18
+ * Attr('disabled', disabledSignal),
19
+ * // Multiple class attributes
20
+ * Attr('class', 'btn btn-primary'),
21
+ * Attr('class', 'active'), // Both classes will be applied
22
+ * // ...
23
+ * )
24
+ * ```
25
+ * @public
26
+ */
27
+ export declare const Attr: (name: string, value: unknown) => Renderable;
3
28
  /**
4
29
  * The `attr` object allows to create any HTML attribute. Either a literal value
5
30
  * or `Signal<?>` can be passed as a value. The type of the value is inferred
@@ -162,9 +187,24 @@ export declare const attr: {
162
187
  innerText: (value: SplitNValue<string>) => Renderable;
163
188
  innerHTML: (value: SplitNValue<string>) => Renderable;
164
189
  outerHTML: (value: SplitNValue<string>) => Renderable;
165
- } & {
166
- set: (name: string, value: SplitNValue<string>) => Renderable;
167
190
  };
191
+ /**
192
+ * Creates a renderable for a data attribute with the specified name and value.
193
+ *
194
+ * This is the functional equivalent of using `dataAttr[name](value)` with a dynamic attribute name.
195
+ *
196
+ * @param name - The name of the data attribute (without the 'data-' prefix).
197
+ * @param value - The value of the attribute (can be a literal or Signal).
198
+ * @returns A renderable that sets the data attribute.
199
+ * @example
200
+ * ```ts
201
+ * const button = html.button(
202
+ * DataAttr('myinfo', 'something'), // maps to the `data-myinfo` attribute
203
+ * )
204
+ * ```
205
+ * @public
206
+ */
207
+ export declare const DataAttr: (name: string, value: unknown) => Renderable;
168
208
  /**
169
209
  * The `data` object allows to create any `data-` attributes. Either a literal value
170
210
  * or `Signal<string>` can be passed as a value.
@@ -179,9 +219,25 @@ export declare const attr: {
179
219
  */
180
220
  export declare const dataAttr: {
181
221
  [x: string]: (value: Value<string>) => Renderable;
182
- } & {
183
- set: (name: string, value: Value<string>) => Renderable;
184
222
  };
223
+ /**
224
+ * Creates a renderable for an ARIA attribute with the specified name and value.
225
+ *
226
+ * This is the functional equivalent of using `aria[name](value)` with a dynamic attribute name.
227
+ *
228
+ * @param name - The name of the ARIA attribute (without the 'aria-' prefix).
229
+ * @param value - The value of the attribute (can be a literal or Signal).
230
+ * @returns A renderable that sets the ARIA attribute.
231
+ * @example
232
+ * ```ts
233
+ * const button = html.button(
234
+ * Aria('label', 'Click me!'), // maps to the `aria-label` attribute
235
+ * Aria('pressed', pressedSignal), // maps to the `aria-pressed` attribute
236
+ * )
237
+ * ```
238
+ * @public
239
+ */
240
+ export declare const Aria: (name: string, value: unknown) => Renderable;
185
241
  /**
186
242
  * An object that provides a convenient way to create mountable attributes for ARIA properties.
187
243
  *
@@ -251,9 +307,26 @@ export declare const aria: {
251
307
  valuemin: (value: SplitNValue<number>) => Renderable;
252
308
  valuenow: (value: SplitNValue<number>) => Renderable;
253
309
  valuetext: (value: SplitNValue<string>) => Renderable;
254
- } & {
255
- set: (name: string, value: Value<string>) => Renderable;
256
310
  };
311
+ /**
312
+ * Creates a renderable for an SVG attribute with the specified name and value.
313
+ *
314
+ * This is the functional equivalent of using `svgAttr[name](value)` with a dynamic attribute name.
315
+ *
316
+ * @param name - The name of the SVG attribute.
317
+ * @param value - The value of the attribute (can be a literal or Signal).
318
+ * @returns A renderable that sets the SVG attribute.
319
+ * @example
320
+ * ```ts
321
+ * const circle = svg.circle(
322
+ * SVGAttr('cx', 50),
323
+ * SVGAttr('cy', 50),
324
+ * SVGAttr('r', radiusSignal),
325
+ * )
326
+ * ```
327
+ * @public
328
+ */
329
+ export declare const SVGAttr: (name: string, value: unknown) => Renderable;
257
330
  /**
258
331
  * An object that provides a convenient way to create mountable attributes for
259
332
  * SVG elements.
@@ -542,9 +615,25 @@ export declare const svgAttr: {
542
615
  yChannelSelector: (value: SplitNValue<"R" | "G" | "B" | "A">) => Renderable;
543
616
  z: (value: SplitNValue<string | number>) => Renderable;
544
617
  zoomAndPan: (value: SplitNValue<"disable" | "magnify">) => Renderable;
545
- } & {
546
- set: (name: string, value: Value<string>) => Renderable;
547
618
  };
619
+ /**
620
+ * Creates a renderable for a MathML attribute with the specified name and value.
621
+ *
622
+ * This is the functional equivalent of using `mathAttr[name](value)`.
623
+ *
624
+ * @param name - The name of the MathML attribute.
625
+ * @param value - The value of the attribute (can be a literal or Signal).
626
+ * @returns A renderable that sets the MathML attribute.
627
+ * @example
628
+ * ```ts
629
+ * const mi = math.mi(
630
+ * MathAttr('mathvariant', 'bold'),
631
+ * MathAttr('mathsize', sizeSignal),
632
+ * )
633
+ * ```
634
+ * @public
635
+ */
636
+ export declare const MathAttr: (name: string, value: unknown) => Renderable;
548
637
  /**
549
638
  * An object that provides attribute functions for MathML tags.
550
639
  *
@@ -183,6 +183,15 @@ export declare const input: {
183
183
  week: (...children: TNode[]) => Renderable;
184
184
  "datetime-local": (...children: TNode[]) => Renderable;
185
185
  };
186
+ /**
187
+ * Creates a Renderable that represents an SVG element.
188
+ *
189
+ * @param tagName - The tag name of the SVG element.
190
+ * @param children - The child nodes of the SVG element.
191
+ * @returns A renderable function that creates and appends the SVG element to the DOM.
192
+ * @public
193
+ */
194
+ export declare const SVGEl: (tagName: string, ...children: TNode[]) => Renderable;
186
195
  /**
187
196
  * A convenience object to create Renderables for SVG elements.
188
197
  * @public
@@ -252,6 +261,15 @@ export declare const svg: {
252
261
  use: (...children: TNode[]) => Renderable;
253
262
  view: (...children: TNode[]) => Renderable;
254
263
  };
264
+ /**
265
+ * Creates a Renderable that represents a MathML element.
266
+ *
267
+ * @param tagName - The tag name of the MathML element.
268
+ * @param children - The child nodes of the MathML element.
269
+ * @returns A renderable function that creates and appends the MathML element to the DOM.
270
+ * @public
271
+ */
272
+ export declare const MathEl: (tagName: string, ...children: TNode[]) => Renderable;
255
273
  /**
256
274
  * A convenience object to create Renderables for MATH elements.
257
275
  * @public
package/std/signal.d.ts CHANGED
@@ -18,6 +18,12 @@ export type ListenerOptions = {
18
18
  skipInitial?: boolean;
19
19
  once?: boolean;
20
20
  abortSignal?: AbortSignal;
21
+ /**
22
+ * If true, the listener will not be automatically disposed when the current scope ends.
23
+ * Use this when you need explicit control over the listener lifecycle.
24
+ * @internal
25
+ */
26
+ noAutoDispose?: boolean;
21
27
  };
22
28
  /**
23
29
  * A reactive signal that holds a value and notifies listeners when the value changes.
@@ -153,8 +159,28 @@ export declare class Signal<T> {
153
159
  * The listener function will be immediately called with the current value of the signal.
154
160
  * Returns a function that can be called to unregister the listener.
155
161
  *
162
+ * When called within a DisposalScope (e.g., inside a renderable), the listener is
163
+ * automatically cleaned up when the scope is disposed. This prevents memory leaks
164
+ * when listening to outer-scope signals from inner scopes.
165
+ *
156
166
  * @param listener - The listener function to be called when the value of the signal changes.
157
167
  * @param options - Options for the listener.
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * // Automatic cleanup when scope disposes
172
+ * const MyComponent = () => {
173
+ * const outerSignal = prop(0)
174
+ *
175
+ * return html.div(
176
+ * When(someCondition, () => {
177
+ * // This listener is automatically cleaned up when the When() disposes
178
+ * outerSignal.on(value => console.log(value))
179
+ * return html.span('Inner content')
180
+ * })
181
+ * )
182
+ * }
183
+ * ```
158
184
  */
159
185
  readonly on: (listener: (value: T, previousValue: T | undefined) => void, options?: ListenerOptions) => () => void;
160
186
  /**
@@ -187,6 +213,7 @@ export declare class Signal<T> {
187
213
  readonly onDispose: (listener: () => void) => void;
188
214
  /**
189
215
  * Disposes the signal, releasing any resources associated with it.
216
+ * This clears all listeners, derivatives, and disposal callbacks.
190
217
  */
191
218
  readonly dispose: () => void;
192
219
  /**