sibujs 4.1.0 → 4.2.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/README.md +24 -0
- package/dist/browser.cjs +13 -21
- package/dist/browser.js +6 -6
- package/dist/build.cjs +278 -104
- package/dist/build.js +15 -15
- package/dist/cdn.dev.global.js +398 -0
- package/dist/cdn.global.js +10 -10
- package/dist/{chunk-DCDS2PQ6.js → chunk-2LOYNGBY.js} +2 -2
- package/dist/{chunk-VPP2FONR.js → chunk-2WLZ6757.js} +17 -10
- package/dist/{chunk-IM7N5WR4.js → chunk-3VTSPNC5.js} +2 -2
- package/dist/{chunk-TIRZCERI.js → chunk-5DXA2J44.js} +1 -1
- package/dist/{chunk-I3VI34DP.js → chunk-6ZGI3RBE.js} +149 -33
- package/dist/{chunk-D3SZ4LVS.js → chunk-7ALC7KGE.js} +5 -6
- package/dist/{chunk-PFTDGEPZ.js → chunk-7VEC3UD2.js} +3 -3
- package/dist/{chunk-KSOEJGFO.js → chunk-BMYYZWHX.js} +3 -3
- package/dist/{chunk-LOFZHP6V.js → chunk-BNKV4REK.js} +7 -8
- package/dist/{chunk-5GJ5RTHA.js → chunk-FOWBJZDL.js} +7 -8
- package/dist/{chunk-FB7KQXZI.js → chunk-GDUNQCCW.js} +4 -4
- package/dist/{chunk-UFSQEO7P.js → chunk-HECVW343.js} +7 -8
- package/dist/{chunk-SHDVWATN.js → chunk-HJEPKZ2O.js} +7 -8
- package/dist/{chunk-ANGSYNPX.js → chunk-HZEBO22J.js} +57 -37
- package/dist/{chunk-5INI7D2L.js → chunk-IXKSNWV5.js} +74 -11
- package/dist/{chunk-DAKLOMKS.js → chunk-KE4KWRDY.js} +3 -3
- package/dist/{chunk-AW6HPJ3L.js → chunk-KKLW7YWL.js} +1 -1
- package/dist/{chunk-BMSN6NWQ.js → chunk-NEYWS4EX.js} +6 -6
- package/dist/{chunk-HYCCIYNS.js → chunk-NIOYEGBQ.js} +13 -14
- package/dist/{chunk-4U7KD3RY.js → chunk-OUWAIXIK.js} +3 -3
- package/dist/{chunk-MRAMKDHQ.js → chunk-P3DHXBR6.js} +1 -1
- package/dist/{chunk-FMHIQNMP.js → chunk-QCFLDD7C.js} +5 -5
- package/dist/{chunk-DHDZ7IVN.js → chunk-QKRPLZ2V.js} +7 -8
- package/dist/{chunk-4RH6D7GR.js → chunk-QL4UREZO.js} +6 -6
- package/dist/{chunk-XIHMS2Y6.js → chunk-SF3TB4K6.js} +8 -8
- package/dist/{chunk-XSZRJW76.js → chunk-XZ2N525U.js} +6 -6
- package/dist/{customElement-CKLoO63w.d.ts → customElement-CNZxEB9G.d.cts} +77 -0
- package/dist/{customElement-CKLoO63w.d.cts → customElement-CNZxEB9G.d.ts} +77 -0
- package/dist/data.cjs +15 -24
- package/dist/data.js +9 -9
- package/dist/devtools.cjs +18 -22
- package/dist/devtools.d.cts +1 -1
- package/dist/devtools.d.ts +1 -1
- package/dist/devtools.js +8 -8
- package/dist/{dispose-4FZ6OFXR.js → dispose-46BOMMQJ.js} +2 -2
- package/dist/ecosystem.cjs +222 -67
- package/dist/ecosystem.js +11 -11
- package/dist/extras.cjs +243 -86
- package/dist/extras.d.cts +2 -2
- package/dist/extras.d.ts +2 -2
- package/dist/extras.js +25 -25
- package/dist/index.cjs +272 -98
- package/dist/index.d.cts +154 -33
- package/dist/index.d.ts +154 -33
- package/dist/index.js +15 -15
- package/dist/{introspect-RjLfIFpL.d.cts → introspect-D5xF-0Es.d.cts} +7 -0
- package/dist/{introspect-DOZfmC-4.d.ts → introspect-rSBIxEQi.d.ts} +7 -0
- package/dist/motion.cjs +13 -22
- package/dist/motion.js +5 -5
- package/dist/patterns.cjs +16 -24
- package/dist/patterns.d.cts +8 -0
- package/dist/patterns.d.ts +8 -0
- package/dist/patterns.js +7 -7
- package/dist/performance.cjs +16 -27
- package/dist/performance.js +9 -9
- package/dist/plugins.cjs +260 -86
- package/dist/plugins.d.cts +92 -0
- package/dist/plugins.d.ts +92 -0
- package/dist/plugins.js +18 -17
- package/dist/{ssr-JFP5535P.js → ssr-Y7XOEPEN.js} +5 -5
- package/dist/ssr.cjs +233 -79
- package/dist/ssr.js +12 -12
- package/dist/testing.cjs +11 -19
- package/dist/testing.js +5 -5
- package/dist/ui.cjs +98 -43
- package/dist/ui.d.cts +7 -1
- package/dist/ui.d.ts +7 -1
- package/dist/ui.js +10 -10
- package/dist/widgets.cjs +13 -21
- package/dist/widgets.d.cts +8 -0
- package/dist/widgets.d.ts +8 -0
- package/dist/widgets.js +9 -9
- package/package.json +5 -2
package/dist/index.d.cts
CHANGED
|
@@ -193,9 +193,15 @@ type RuntimeErrorHandler = (error: unknown, context: RuntimeErrorContext) => voi
|
|
|
193
193
|
* This is application/runtime-global state, NOT request-scoped: under SSR it is
|
|
194
194
|
* shared by every concurrent request in the process. Install it once at startup
|
|
195
195
|
* and derive any request-specific detail from the error/context instead.
|
|
196
|
+
*
|
|
197
|
+
* @returns The previously installed handler, so a caller can restore it.
|
|
196
198
|
*/
|
|
197
199
|
declare function setRuntimeErrorHandler(handler: RuntimeErrorHandler | null): RuntimeErrorHandler | null;
|
|
198
|
-
/**
|
|
200
|
+
/**
|
|
201
|
+
* Read the currently installed runtime error handler.
|
|
202
|
+
*
|
|
203
|
+
* @returns The installed handler, or `null` when none is set.
|
|
204
|
+
*/
|
|
199
205
|
declare function getRuntimeErrorHandler(): RuntimeErrorHandler | null;
|
|
200
206
|
/**
|
|
201
207
|
* Report an error the runtime caught and contained.
|
|
@@ -440,45 +446,30 @@ declare function __resetIdCounter(): void;
|
|
|
440
446
|
* Conditional rendering directive. Shows or hides an element reactively.
|
|
441
447
|
* Unlike `when()`, the element is always created — it just toggles display.
|
|
442
448
|
*
|
|
449
|
+
* Accepts the element either directly or as a thunk, so the same call shape
|
|
450
|
+
* works here and in {@link when}. Which one you pass changes nothing: `show`
|
|
451
|
+
* never rebuilds, so a thunk is invoked exactly once, immediately.
|
|
452
|
+
*
|
|
443
453
|
* @param condition Reactive getter returning boolean
|
|
444
|
-
* @param element The element to show/hide
|
|
445
|
-
* @returns The element with reactive display binding
|
|
454
|
+
* @param element The element to show/hide, or a function returning it
|
|
455
|
+
* @returns The element itself (not a wrapper), with a reactive display binding.
|
|
456
|
+
* The caller keeps the live node and can mutate it or attach listeners to it.
|
|
446
457
|
*
|
|
447
458
|
* @example
|
|
448
459
|
* ```ts
|
|
449
460
|
* const [visible, setVisible] = signal(true);
|
|
450
461
|
* div([show(() => visible(), span("I toggle!"))]);
|
|
462
|
+
* div([show(() => visible(), () => span("also fine"))]);
|
|
451
463
|
* ```
|
|
452
|
-
*/
|
|
453
|
-
declare function show<T extends Element>(condition: () => boolean, element: T): T;
|
|
454
|
-
/**
|
|
455
|
-
* Conditional rendering directive. Renders content only when condition is true.
|
|
456
|
-
* When false, renders nothing (comment placeholder). Re-evaluates reactively.
|
|
457
|
-
*
|
|
458
|
-
* @param condition Reactive getter returning boolean
|
|
459
|
-
* @param thenBranch Function returning element when true
|
|
460
|
-
* @param elseBranch Optional function returning element when false
|
|
461
|
-
* @returns A Comment anchor that manages the conditional content
|
|
462
464
|
*
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
*
|
|
468
|
-
* () => div("Please log in")
|
|
469
|
-
* );
|
|
470
|
-
* ```
|
|
471
|
-
*
|
|
472
|
-
* GOTCHA — branch factories rebuild only when `condition` changes. A signal
|
|
473
|
-
* read *eagerly* inside a branch is captured once and never updates:
|
|
474
|
-
* ```ts
|
|
475
|
-
* when(() => show(), () => div(`Count: ${count()}`)); // ✗ frozen at first count
|
|
476
|
-
* when(() => show(), () => div(() => `Count: ${count()}`)); // ✓ reactive text child
|
|
477
|
-
* ```
|
|
478
|
-
* Drive per-branch reactivity with a nested getter (or a reactive child), not a
|
|
479
|
-
* bare read in the factory body.
|
|
465
|
+
* TRAP — `show` keeps the element in the DOM and toggles `display`. Use
|
|
466
|
+
* {@link when} when the content must not exist at all while hidden (an
|
|
467
|
+
* expensive subtree, or one whose mere presence is observable). Note that
|
|
468
|
+
* `when` REBUILDS on every condition change, which discards focus and
|
|
469
|
+
* selection inside the branch — see the note on `when`.
|
|
480
470
|
*/
|
|
481
|
-
declare function
|
|
471
|
+
declare function show<T extends Element>(condition: () => boolean, element: T | (() => T)): T;
|
|
472
|
+
declare function when<T>(condition: () => T, thenBranch: NodeChild, elseBranch?: NodeChild): Comment;
|
|
482
473
|
/**
|
|
483
474
|
* Pattern matching directive. Renders content based on matching a reactive value
|
|
484
475
|
* against multiple cases. Similar to a switch statement.
|
|
@@ -504,8 +495,25 @@ declare function when<T>(condition: () => T, thenBranch: () => NodeChild, elseBr
|
|
|
504
495
|
* GOTCHA — like `when()`, a case factory rebuilds only when the matched key
|
|
505
496
|
* changes. A signal read eagerly inside a case is frozen at build time; use a
|
|
506
497
|
* nested getter (`() => div(() => label())`) for reactive per-case content.
|
|
498
|
+
*
|
|
499
|
+
* THIS IS THE KEYING PATTERN for subtrees that hold a live edit. Because the
|
|
500
|
+
* subtree is rebuilt only when the KEY changes — not on every read of every
|
|
501
|
+
* signal inside it — a form can update its contents through reactive attributes
|
|
502
|
+
* and text children while its inputs keep focus, selection and IME state:
|
|
503
|
+
*
|
|
504
|
+
* ```ts
|
|
505
|
+
* // Rebuilds only when the form's shape changes, not on every keystroke.
|
|
506
|
+
* match(
|
|
507
|
+
* () => `${entity()}:${mode()}`,
|
|
508
|
+
* { "user:edit": () => UserForm(), "user:view": () => UserCard() },
|
|
509
|
+
* );
|
|
510
|
+
* ```
|
|
511
|
+
*
|
|
512
|
+
* Cases and the fallback accept a bare element as well as a factory, matching
|
|
513
|
+
* {@link when} and {@link show}. A bare element is re-attached rather than
|
|
514
|
+
* rebuilt, so it keeps whatever state it accumulated.
|
|
507
515
|
*/
|
|
508
|
-
declare function match<T extends string | number>(value: () => T, cases: Record<string,
|
|
516
|
+
declare function match<T extends string | number>(value: () => T, cases: Record<string, NodeChild>, fallback?: NodeChild): Comment;
|
|
509
517
|
|
|
510
518
|
/**
|
|
511
519
|
* Safety ceiling on the **total number of teardowns a single drain may execute**.
|
|
@@ -582,7 +590,9 @@ declare function replaceChildrenSafely(parent: ParentNode, ...next: Node[]): voi
|
|
|
582
590
|
/**
|
|
583
591
|
* Check for potential binding leaks. Returns the number of active DOM bindings.
|
|
584
592
|
* In dev mode, logs a warning if the count exceeds the threshold.
|
|
585
|
-
* In production,
|
|
593
|
+
* In production, DEV is false so the counter is always 0.
|
|
594
|
+
*
|
|
595
|
+
* @returns Diagnostic counts of nodes still holding registered disposers.
|
|
586
596
|
*/
|
|
587
597
|
declare function checkLeaks(warnThreshold?: number): number;
|
|
588
598
|
|
|
@@ -699,6 +709,9 @@ declare function Fragment(nodes: NodeChildren[]): DocumentFragment;
|
|
|
699
709
|
* Templates are parsed once per call site and cached. Subsequent calls at the
|
|
700
710
|
* same source location skip parsing entirely and only replay the cached
|
|
701
711
|
* structure with fresh expression values.
|
|
712
|
+
*
|
|
713
|
+
* @returns The live DOM node (or fragment) the template describes — not a
|
|
714
|
+
* string, and not a virtual node.
|
|
702
715
|
*/
|
|
703
716
|
declare function html(strings: TemplateStringsArray, ...values: unknown[]): Element;
|
|
704
717
|
|
|
@@ -1004,6 +1017,15 @@ interface KeepAliveOptions {
|
|
|
1004
1017
|
*/
|
|
1005
1018
|
declare function KeepAlive(activeKey: () => string, cases: Record<string, () => Node>, options?: KeepAliveOptions): Comment;
|
|
1006
1019
|
|
|
1020
|
+
/**
|
|
1021
|
+
* Read and CLEAR an error stashed on a node by an async boundary.
|
|
1022
|
+
*
|
|
1023
|
+
* Consuming is the point: an error handed to one boundary must not also reach
|
|
1024
|
+
* an outer one, so this is deliberately not a plain getter.
|
|
1025
|
+
*
|
|
1026
|
+
* @param node Element the error was stashed on.
|
|
1027
|
+
* @returns The pending error, or `undefined` when there is none.
|
|
1028
|
+
*/
|
|
1007
1029
|
declare function takePendingError(node: Element): Error | undefined;
|
|
1008
1030
|
type Component = () => HTMLElement;
|
|
1009
1031
|
type LazyImport = () => Promise<{
|
|
@@ -1051,6 +1073,18 @@ interface SuspenseProps {
|
|
|
1051
1073
|
nodes: () => HTMLElement;
|
|
1052
1074
|
fallback: () => HTMLElement;
|
|
1053
1075
|
}
|
|
1076
|
+
/**
|
|
1077
|
+
* Render `fallback` until the async `nodes` factory resolves, then swap it for
|
|
1078
|
+
* the resolved content.
|
|
1079
|
+
*
|
|
1080
|
+
* @param props `nodes` is the async content factory; `fallback` builds the
|
|
1081
|
+
* placeholder shown while it is pending.
|
|
1082
|
+
* @returns The live container element, already holding the fallback.
|
|
1083
|
+
*
|
|
1084
|
+
* TRAP — the swap REPLACES the container's children, so focus and selection in
|
|
1085
|
+
* the fallback are discarded. That is usually harmless (a spinner rarely holds
|
|
1086
|
+
* focus) but matters for a skeleton form; see the note on `when`.
|
|
1087
|
+
*/
|
|
1054
1088
|
declare function Suspense({ nodes, fallback }: SuspenseProps): HTMLElement;
|
|
1055
1089
|
|
|
1056
1090
|
/**
|
|
@@ -1119,6 +1153,11 @@ declare function onCleanup(callback: CleanupFn, element: Node): void;
|
|
|
1119
1153
|
/**
|
|
1120
1154
|
* Mounts a root component into a DOM element.
|
|
1121
1155
|
* Supports both function components and pre-created HTMLElements.
|
|
1156
|
+
*
|
|
1157
|
+
* @param component Component function, or an already-built Element/Node.
|
|
1158
|
+
* @param container Element to mount into.
|
|
1159
|
+
* @returns `{ node, unmount }` — the live root node, and a teardown that
|
|
1160
|
+
* disposes the tree and removes it.
|
|
1122
1161
|
*/
|
|
1123
1162
|
declare function mount(component: (() => Element) | Element | Node, container: Element | null): {
|
|
1124
1163
|
node: Node;
|
|
@@ -1151,6 +1190,13 @@ declare function Portal(nodes: () => HTMLElement, target?: HTMLElement): Comment
|
|
|
1151
1190
|
|
|
1152
1191
|
type SlotFn = () => Element | string | number | null | undefined;
|
|
1153
1192
|
type Slots = Record<string, SlotFn>;
|
|
1193
|
+
/**
|
|
1194
|
+
* Look up a named slot factory.
|
|
1195
|
+
*
|
|
1196
|
+
* @param slots The slot map, which may be undefined.
|
|
1197
|
+
* @param name Slot name; defaults to `"default"`.
|
|
1198
|
+
* @returns The slot factory, or `undefined` when the slot was not provided.
|
|
1199
|
+
*/
|
|
1154
1200
|
declare function getSlot(slots: Slots | undefined, name?: string): SlotFn | undefined;
|
|
1155
1201
|
|
|
1156
1202
|
declare const __accessor: unique symbol;
|
|
@@ -1184,6 +1230,8 @@ interface SignalOptions<T = unknown> {
|
|
|
1184
1230
|
*
|
|
1185
1231
|
* @param initial Initial value
|
|
1186
1232
|
* @param options Optional config: `{ name: "count" }` for devtools labeling
|
|
1233
|
+
* @returns A `[getter, setter]` tuple. Calling the getter inside a reactive
|
|
1234
|
+
* context subscribes to the signal; the setter accepts a value or an updater.
|
|
1187
1235
|
*/
|
|
1188
1236
|
declare function signal<T>(initial: T, options?: SignalOptions<T>): StateTuple<T>;
|
|
1189
1237
|
/**
|
|
@@ -1298,6 +1346,14 @@ interface ArrayActions<T> {
|
|
|
1298
1346
|
/** Clear all items */
|
|
1299
1347
|
clear(): void;
|
|
1300
1348
|
}
|
|
1349
|
+
/**
|
|
1350
|
+
* A signal holding an array, plus mutation helpers that write a NEW array each
|
|
1351
|
+
* time so the signal actually notifies.
|
|
1352
|
+
*
|
|
1353
|
+
* @param initial Starting items; copied, so the caller's array is not aliased.
|
|
1354
|
+
* @returns A `[accessor, actions]` pair — `actions` carries `push`, `remove`,
|
|
1355
|
+
* `insert`, `move`, `clear` and friends.
|
|
1356
|
+
*/
|
|
1301
1357
|
declare function array<T>(initial?: T[]): [Accessor<T[]>, ArrayActions<T>];
|
|
1302
1358
|
/**
|
|
1303
1359
|
* Optimized reactive array hook. Uses in-place mutations with a version
|
|
@@ -1406,6 +1462,9 @@ interface AsyncDerivedContext {
|
|
|
1406
1462
|
* return r.json();
|
|
1407
1463
|
* }, []);
|
|
1408
1464
|
* ```
|
|
1465
|
+
*
|
|
1466
|
+
* @returns An accessor exposing the async result along with its loading and
|
|
1467
|
+
* error state.
|
|
1409
1468
|
*/
|
|
1410
1469
|
declare function asyncDerived<T>(factory: (context: AsyncDerivedContext) => Promise<T>, initial: T): AsyncDerivedState<T>;
|
|
1411
1470
|
|
|
@@ -1467,6 +1526,9 @@ declare function deepSignal<T>(initial: T): [Accessor<T>, (next: T | ((prev: T)
|
|
|
1467
1526
|
* That keeps the cheap boolean dirty flag AND makes `equals` actually stop
|
|
1468
1527
|
* propagation, with recomputation still fully lazy: `_validate` only ever runs
|
|
1469
1528
|
* when an effect is genuinely about to observe the value.
|
|
1529
|
+
*
|
|
1530
|
+
* @returns An accessor for the computed value. It recomputes lazily on read
|
|
1531
|
+
* after any dependency changes.
|
|
1470
1532
|
*/
|
|
1471
1533
|
declare function derived<T>(getter: () => T, options?: {
|
|
1472
1534
|
name?: string;
|
|
@@ -1522,6 +1584,9 @@ type EffectBody = (onCleanup: OnCleanup) => void;
|
|
|
1522
1584
|
* onCleanup(() => window.removeEventListener("resize", handler));
|
|
1523
1585
|
* });
|
|
1524
1586
|
* ```
|
|
1587
|
+
*
|
|
1588
|
+
* @returns A dispose function that stops the effect and releases its
|
|
1589
|
+
* dependencies. Idempotent.
|
|
1525
1590
|
*/
|
|
1526
1591
|
declare function effect(effectFn: EffectBody | (() => void), options?: EffectOptions): () => void;
|
|
1527
1592
|
|
|
@@ -1629,6 +1694,8 @@ declare function watch<T>(getter: () => T, callback: (value: T, prev: T | undefi
|
|
|
1629
1694
|
* lastName(); // "Smith"
|
|
1630
1695
|
* fullName(); // "Jane Smith"
|
|
1631
1696
|
* ```
|
|
1697
|
+
*
|
|
1698
|
+
* @returns A store handle with `subscribe`, `set` and `update`.
|
|
1632
1699
|
*/
|
|
1633
1700
|
declare function writable<T>(get: () => T, set: (value: T) => void, options?: {
|
|
1634
1701
|
name?: string;
|
|
@@ -2106,20 +2173,74 @@ declare function transition(): TransitionState;
|
|
|
2106
2173
|
declare function nextTick(): Promise<void>;
|
|
2107
2174
|
|
|
2108
2175
|
type Subscriber = () => void;
|
|
2176
|
+
/**
|
|
2177
|
+
* Stop recording dependency edges until the matching {@link resumeTracking}.
|
|
2178
|
+
* Nestable — the depth is counted, so an inner pair does not resume early.
|
|
2179
|
+
*
|
|
2180
|
+
* Prefer {@link untracked}, which pairs the two calls for you even when the
|
|
2181
|
+
* body throws. Reach for the raw pair only when the suspended region cannot be
|
|
2182
|
+
* expressed as a single function.
|
|
2183
|
+
*
|
|
2184
|
+
* @returns Nothing.
|
|
2185
|
+
*/
|
|
2109
2186
|
declare function suspendTracking(): void;
|
|
2187
|
+
/**
|
|
2188
|
+
* Undo one {@link suspendTracking}. Dependency recording resumes only when the
|
|
2189
|
+
* outermost pair closes.
|
|
2190
|
+
*
|
|
2191
|
+
* @returns Nothing.
|
|
2192
|
+
*/
|
|
2110
2193
|
declare function resumeTracking(): void;
|
|
2111
2194
|
/** Read the "tracking suspended" flag (used by derived's lazy path). */
|
|
2112
2195
|
declare function isTrackingSuspended(): boolean;
|
|
2196
|
+
/**
|
|
2197
|
+
* Run `fn` without recording anything it reads as a dependency.
|
|
2198
|
+
*
|
|
2199
|
+
* The suspension is released even if `fn` throws, which is the reason to prefer
|
|
2200
|
+
* this over a manual suspend/resume pair.
|
|
2201
|
+
*
|
|
2202
|
+
* @param fn Function to run outside dependency tracking.
|
|
2203
|
+
* @returns Whatever `fn` returns.
|
|
2204
|
+
*/
|
|
2113
2205
|
declare function untracked$1<T>(fn: () => T): T;
|
|
2114
2206
|
declare function retrack$1(effectFn: () => void, subscriber: Subscriber): void;
|
|
2115
2207
|
declare function track(effectFn: () => void, subscriber?: Subscriber): () => void;
|
|
2116
2208
|
declare function reactiveBinding(commit: () => void, ownerNode?: unknown): () => void;
|
|
2117
2209
|
declare function recordDependency(signal: ReactiveSignal): void;
|
|
2118
2210
|
declare function cleanup(subscriber: Subscriber): void;
|
|
2211
|
+
/**
|
|
2212
|
+
* Cap how many times one subscriber may re-run within a single drain before it
|
|
2213
|
+
* is quarantined as a runaway cycle. A safety valve, not a tuning knob.
|
|
2214
|
+
*
|
|
2215
|
+
* @param n New limit; ignored unless finite and positive.
|
|
2216
|
+
* @returns The previous limit, so a caller can restore it.
|
|
2217
|
+
*/
|
|
2119
2218
|
declare function setMaxSubscriberRepeats(n: number): number;
|
|
2219
|
+
/**
|
|
2220
|
+
* Cap how many passes one notification drain may make before giving up on a
|
|
2221
|
+
* self-refeeding update cycle.
|
|
2222
|
+
*
|
|
2223
|
+
* @param n New limit; ignored unless finite and positive.
|
|
2224
|
+
* @returns The previous limit, so a caller can restore it.
|
|
2225
|
+
*/
|
|
2120
2226
|
declare function setMaxDrainIterations$1(n: number): number;
|
|
2227
|
+
/**
|
|
2228
|
+
* Flush queued signal notifications, running every dirty subscriber.
|
|
2229
|
+
*
|
|
2230
|
+
* Re-entrant calls are ignored: a write performed from inside a subscriber adds
|
|
2231
|
+
* to the queue the current drain is already working through, rather than
|
|
2232
|
+
* starting a nested one.
|
|
2233
|
+
*
|
|
2234
|
+
* @returns Nothing.
|
|
2235
|
+
*/
|
|
2121
2236
|
declare function drainNotificationQueue(): void;
|
|
2122
2237
|
declare function queueSignalNotification(signal: ReactiveSignal): void;
|
|
2238
|
+
/**
|
|
2239
|
+
* Mark every subscriber of `signal` dirty and queue them for the next drain.
|
|
2240
|
+
*
|
|
2241
|
+
* @param signal The signal that changed.
|
|
2242
|
+
* @returns Nothing.
|
|
2243
|
+
*/
|
|
2123
2244
|
declare function notifySubscribers(signal: ReactiveSignal): void;
|
|
2124
2245
|
/** O(1) subscriber count for devtools / introspection. */
|
|
2125
2246
|
declare function getSubscriberCount(signal: ReactiveSignal): number;
|
package/dist/index.d.ts
CHANGED
|
@@ -193,9 +193,15 @@ type RuntimeErrorHandler = (error: unknown, context: RuntimeErrorContext) => voi
|
|
|
193
193
|
* This is application/runtime-global state, NOT request-scoped: under SSR it is
|
|
194
194
|
* shared by every concurrent request in the process. Install it once at startup
|
|
195
195
|
* and derive any request-specific detail from the error/context instead.
|
|
196
|
+
*
|
|
197
|
+
* @returns The previously installed handler, so a caller can restore it.
|
|
196
198
|
*/
|
|
197
199
|
declare function setRuntimeErrorHandler(handler: RuntimeErrorHandler | null): RuntimeErrorHandler | null;
|
|
198
|
-
/**
|
|
200
|
+
/**
|
|
201
|
+
* Read the currently installed runtime error handler.
|
|
202
|
+
*
|
|
203
|
+
* @returns The installed handler, or `null` when none is set.
|
|
204
|
+
*/
|
|
199
205
|
declare function getRuntimeErrorHandler(): RuntimeErrorHandler | null;
|
|
200
206
|
/**
|
|
201
207
|
* Report an error the runtime caught and contained.
|
|
@@ -440,45 +446,30 @@ declare function __resetIdCounter(): void;
|
|
|
440
446
|
* Conditional rendering directive. Shows or hides an element reactively.
|
|
441
447
|
* Unlike `when()`, the element is always created — it just toggles display.
|
|
442
448
|
*
|
|
449
|
+
* Accepts the element either directly or as a thunk, so the same call shape
|
|
450
|
+
* works here and in {@link when}. Which one you pass changes nothing: `show`
|
|
451
|
+
* never rebuilds, so a thunk is invoked exactly once, immediately.
|
|
452
|
+
*
|
|
443
453
|
* @param condition Reactive getter returning boolean
|
|
444
|
-
* @param element The element to show/hide
|
|
445
|
-
* @returns The element with reactive display binding
|
|
454
|
+
* @param element The element to show/hide, or a function returning it
|
|
455
|
+
* @returns The element itself (not a wrapper), with a reactive display binding.
|
|
456
|
+
* The caller keeps the live node and can mutate it or attach listeners to it.
|
|
446
457
|
*
|
|
447
458
|
* @example
|
|
448
459
|
* ```ts
|
|
449
460
|
* const [visible, setVisible] = signal(true);
|
|
450
461
|
* div([show(() => visible(), span("I toggle!"))]);
|
|
462
|
+
* div([show(() => visible(), () => span("also fine"))]);
|
|
451
463
|
* ```
|
|
452
|
-
*/
|
|
453
|
-
declare function show<T extends Element>(condition: () => boolean, element: T): T;
|
|
454
|
-
/**
|
|
455
|
-
* Conditional rendering directive. Renders content only when condition is true.
|
|
456
|
-
* When false, renders nothing (comment placeholder). Re-evaluates reactively.
|
|
457
|
-
*
|
|
458
|
-
* @param condition Reactive getter returning boolean
|
|
459
|
-
* @param thenBranch Function returning element when true
|
|
460
|
-
* @param elseBranch Optional function returning element when false
|
|
461
|
-
* @returns A Comment anchor that manages the conditional content
|
|
462
464
|
*
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
*
|
|
468
|
-
* () => div("Please log in")
|
|
469
|
-
* );
|
|
470
|
-
* ```
|
|
471
|
-
*
|
|
472
|
-
* GOTCHA — branch factories rebuild only when `condition` changes. A signal
|
|
473
|
-
* read *eagerly* inside a branch is captured once and never updates:
|
|
474
|
-
* ```ts
|
|
475
|
-
* when(() => show(), () => div(`Count: ${count()}`)); // ✗ frozen at first count
|
|
476
|
-
* when(() => show(), () => div(() => `Count: ${count()}`)); // ✓ reactive text child
|
|
477
|
-
* ```
|
|
478
|
-
* Drive per-branch reactivity with a nested getter (or a reactive child), not a
|
|
479
|
-
* bare read in the factory body.
|
|
465
|
+
* TRAP — `show` keeps the element in the DOM and toggles `display`. Use
|
|
466
|
+
* {@link when} when the content must not exist at all while hidden (an
|
|
467
|
+
* expensive subtree, or one whose mere presence is observable). Note that
|
|
468
|
+
* `when` REBUILDS on every condition change, which discards focus and
|
|
469
|
+
* selection inside the branch — see the note on `when`.
|
|
480
470
|
*/
|
|
481
|
-
declare function
|
|
471
|
+
declare function show<T extends Element>(condition: () => boolean, element: T | (() => T)): T;
|
|
472
|
+
declare function when<T>(condition: () => T, thenBranch: NodeChild, elseBranch?: NodeChild): Comment;
|
|
482
473
|
/**
|
|
483
474
|
* Pattern matching directive. Renders content based on matching a reactive value
|
|
484
475
|
* against multiple cases. Similar to a switch statement.
|
|
@@ -504,8 +495,25 @@ declare function when<T>(condition: () => T, thenBranch: () => NodeChild, elseBr
|
|
|
504
495
|
* GOTCHA — like `when()`, a case factory rebuilds only when the matched key
|
|
505
496
|
* changes. A signal read eagerly inside a case is frozen at build time; use a
|
|
506
497
|
* nested getter (`() => div(() => label())`) for reactive per-case content.
|
|
498
|
+
*
|
|
499
|
+
* THIS IS THE KEYING PATTERN for subtrees that hold a live edit. Because the
|
|
500
|
+
* subtree is rebuilt only when the KEY changes — not on every read of every
|
|
501
|
+
* signal inside it — a form can update its contents through reactive attributes
|
|
502
|
+
* and text children while its inputs keep focus, selection and IME state:
|
|
503
|
+
*
|
|
504
|
+
* ```ts
|
|
505
|
+
* // Rebuilds only when the form's shape changes, not on every keystroke.
|
|
506
|
+
* match(
|
|
507
|
+
* () => `${entity()}:${mode()}`,
|
|
508
|
+
* { "user:edit": () => UserForm(), "user:view": () => UserCard() },
|
|
509
|
+
* );
|
|
510
|
+
* ```
|
|
511
|
+
*
|
|
512
|
+
* Cases and the fallback accept a bare element as well as a factory, matching
|
|
513
|
+
* {@link when} and {@link show}. A bare element is re-attached rather than
|
|
514
|
+
* rebuilt, so it keeps whatever state it accumulated.
|
|
507
515
|
*/
|
|
508
|
-
declare function match<T extends string | number>(value: () => T, cases: Record<string,
|
|
516
|
+
declare function match<T extends string | number>(value: () => T, cases: Record<string, NodeChild>, fallback?: NodeChild): Comment;
|
|
509
517
|
|
|
510
518
|
/**
|
|
511
519
|
* Safety ceiling on the **total number of teardowns a single drain may execute**.
|
|
@@ -582,7 +590,9 @@ declare function replaceChildrenSafely(parent: ParentNode, ...next: Node[]): voi
|
|
|
582
590
|
/**
|
|
583
591
|
* Check for potential binding leaks. Returns the number of active DOM bindings.
|
|
584
592
|
* In dev mode, logs a warning if the count exceeds the threshold.
|
|
585
|
-
* In production,
|
|
593
|
+
* In production, DEV is false so the counter is always 0.
|
|
594
|
+
*
|
|
595
|
+
* @returns Diagnostic counts of nodes still holding registered disposers.
|
|
586
596
|
*/
|
|
587
597
|
declare function checkLeaks(warnThreshold?: number): number;
|
|
588
598
|
|
|
@@ -699,6 +709,9 @@ declare function Fragment(nodes: NodeChildren[]): DocumentFragment;
|
|
|
699
709
|
* Templates are parsed once per call site and cached. Subsequent calls at the
|
|
700
710
|
* same source location skip parsing entirely and only replay the cached
|
|
701
711
|
* structure with fresh expression values.
|
|
712
|
+
*
|
|
713
|
+
* @returns The live DOM node (or fragment) the template describes — not a
|
|
714
|
+
* string, and not a virtual node.
|
|
702
715
|
*/
|
|
703
716
|
declare function html(strings: TemplateStringsArray, ...values: unknown[]): Element;
|
|
704
717
|
|
|
@@ -1004,6 +1017,15 @@ interface KeepAliveOptions {
|
|
|
1004
1017
|
*/
|
|
1005
1018
|
declare function KeepAlive(activeKey: () => string, cases: Record<string, () => Node>, options?: KeepAliveOptions): Comment;
|
|
1006
1019
|
|
|
1020
|
+
/**
|
|
1021
|
+
* Read and CLEAR an error stashed on a node by an async boundary.
|
|
1022
|
+
*
|
|
1023
|
+
* Consuming is the point: an error handed to one boundary must not also reach
|
|
1024
|
+
* an outer one, so this is deliberately not a plain getter.
|
|
1025
|
+
*
|
|
1026
|
+
* @param node Element the error was stashed on.
|
|
1027
|
+
* @returns The pending error, or `undefined` when there is none.
|
|
1028
|
+
*/
|
|
1007
1029
|
declare function takePendingError(node: Element): Error | undefined;
|
|
1008
1030
|
type Component = () => HTMLElement;
|
|
1009
1031
|
type LazyImport = () => Promise<{
|
|
@@ -1051,6 +1073,18 @@ interface SuspenseProps {
|
|
|
1051
1073
|
nodes: () => HTMLElement;
|
|
1052
1074
|
fallback: () => HTMLElement;
|
|
1053
1075
|
}
|
|
1076
|
+
/**
|
|
1077
|
+
* Render `fallback` until the async `nodes` factory resolves, then swap it for
|
|
1078
|
+
* the resolved content.
|
|
1079
|
+
*
|
|
1080
|
+
* @param props `nodes` is the async content factory; `fallback` builds the
|
|
1081
|
+
* placeholder shown while it is pending.
|
|
1082
|
+
* @returns The live container element, already holding the fallback.
|
|
1083
|
+
*
|
|
1084
|
+
* TRAP — the swap REPLACES the container's children, so focus and selection in
|
|
1085
|
+
* the fallback are discarded. That is usually harmless (a spinner rarely holds
|
|
1086
|
+
* focus) but matters for a skeleton form; see the note on `when`.
|
|
1087
|
+
*/
|
|
1054
1088
|
declare function Suspense({ nodes, fallback }: SuspenseProps): HTMLElement;
|
|
1055
1089
|
|
|
1056
1090
|
/**
|
|
@@ -1119,6 +1153,11 @@ declare function onCleanup(callback: CleanupFn, element: Node): void;
|
|
|
1119
1153
|
/**
|
|
1120
1154
|
* Mounts a root component into a DOM element.
|
|
1121
1155
|
* Supports both function components and pre-created HTMLElements.
|
|
1156
|
+
*
|
|
1157
|
+
* @param component Component function, or an already-built Element/Node.
|
|
1158
|
+
* @param container Element to mount into.
|
|
1159
|
+
* @returns `{ node, unmount }` — the live root node, and a teardown that
|
|
1160
|
+
* disposes the tree and removes it.
|
|
1122
1161
|
*/
|
|
1123
1162
|
declare function mount(component: (() => Element) | Element | Node, container: Element | null): {
|
|
1124
1163
|
node: Node;
|
|
@@ -1151,6 +1190,13 @@ declare function Portal(nodes: () => HTMLElement, target?: HTMLElement): Comment
|
|
|
1151
1190
|
|
|
1152
1191
|
type SlotFn = () => Element | string | number | null | undefined;
|
|
1153
1192
|
type Slots = Record<string, SlotFn>;
|
|
1193
|
+
/**
|
|
1194
|
+
* Look up a named slot factory.
|
|
1195
|
+
*
|
|
1196
|
+
* @param slots The slot map, which may be undefined.
|
|
1197
|
+
* @param name Slot name; defaults to `"default"`.
|
|
1198
|
+
* @returns The slot factory, or `undefined` when the slot was not provided.
|
|
1199
|
+
*/
|
|
1154
1200
|
declare function getSlot(slots: Slots | undefined, name?: string): SlotFn | undefined;
|
|
1155
1201
|
|
|
1156
1202
|
declare const __accessor: unique symbol;
|
|
@@ -1184,6 +1230,8 @@ interface SignalOptions<T = unknown> {
|
|
|
1184
1230
|
*
|
|
1185
1231
|
* @param initial Initial value
|
|
1186
1232
|
* @param options Optional config: `{ name: "count" }` for devtools labeling
|
|
1233
|
+
* @returns A `[getter, setter]` tuple. Calling the getter inside a reactive
|
|
1234
|
+
* context subscribes to the signal; the setter accepts a value or an updater.
|
|
1187
1235
|
*/
|
|
1188
1236
|
declare function signal<T>(initial: T, options?: SignalOptions<T>): StateTuple<T>;
|
|
1189
1237
|
/**
|
|
@@ -1298,6 +1346,14 @@ interface ArrayActions<T> {
|
|
|
1298
1346
|
/** Clear all items */
|
|
1299
1347
|
clear(): void;
|
|
1300
1348
|
}
|
|
1349
|
+
/**
|
|
1350
|
+
* A signal holding an array, plus mutation helpers that write a NEW array each
|
|
1351
|
+
* time so the signal actually notifies.
|
|
1352
|
+
*
|
|
1353
|
+
* @param initial Starting items; copied, so the caller's array is not aliased.
|
|
1354
|
+
* @returns A `[accessor, actions]` pair — `actions` carries `push`, `remove`,
|
|
1355
|
+
* `insert`, `move`, `clear` and friends.
|
|
1356
|
+
*/
|
|
1301
1357
|
declare function array<T>(initial?: T[]): [Accessor<T[]>, ArrayActions<T>];
|
|
1302
1358
|
/**
|
|
1303
1359
|
* Optimized reactive array hook. Uses in-place mutations with a version
|
|
@@ -1406,6 +1462,9 @@ interface AsyncDerivedContext {
|
|
|
1406
1462
|
* return r.json();
|
|
1407
1463
|
* }, []);
|
|
1408
1464
|
* ```
|
|
1465
|
+
*
|
|
1466
|
+
* @returns An accessor exposing the async result along with its loading and
|
|
1467
|
+
* error state.
|
|
1409
1468
|
*/
|
|
1410
1469
|
declare function asyncDerived<T>(factory: (context: AsyncDerivedContext) => Promise<T>, initial: T): AsyncDerivedState<T>;
|
|
1411
1470
|
|
|
@@ -1467,6 +1526,9 @@ declare function deepSignal<T>(initial: T): [Accessor<T>, (next: T | ((prev: T)
|
|
|
1467
1526
|
* That keeps the cheap boolean dirty flag AND makes `equals` actually stop
|
|
1468
1527
|
* propagation, with recomputation still fully lazy: `_validate` only ever runs
|
|
1469
1528
|
* when an effect is genuinely about to observe the value.
|
|
1529
|
+
*
|
|
1530
|
+
* @returns An accessor for the computed value. It recomputes lazily on read
|
|
1531
|
+
* after any dependency changes.
|
|
1470
1532
|
*/
|
|
1471
1533
|
declare function derived<T>(getter: () => T, options?: {
|
|
1472
1534
|
name?: string;
|
|
@@ -1522,6 +1584,9 @@ type EffectBody = (onCleanup: OnCleanup) => void;
|
|
|
1522
1584
|
* onCleanup(() => window.removeEventListener("resize", handler));
|
|
1523
1585
|
* });
|
|
1524
1586
|
* ```
|
|
1587
|
+
*
|
|
1588
|
+
* @returns A dispose function that stops the effect and releases its
|
|
1589
|
+
* dependencies. Idempotent.
|
|
1525
1590
|
*/
|
|
1526
1591
|
declare function effect(effectFn: EffectBody | (() => void), options?: EffectOptions): () => void;
|
|
1527
1592
|
|
|
@@ -1629,6 +1694,8 @@ declare function watch<T>(getter: () => T, callback: (value: T, prev: T | undefi
|
|
|
1629
1694
|
* lastName(); // "Smith"
|
|
1630
1695
|
* fullName(); // "Jane Smith"
|
|
1631
1696
|
* ```
|
|
1697
|
+
*
|
|
1698
|
+
* @returns A store handle with `subscribe`, `set` and `update`.
|
|
1632
1699
|
*/
|
|
1633
1700
|
declare function writable<T>(get: () => T, set: (value: T) => void, options?: {
|
|
1634
1701
|
name?: string;
|
|
@@ -2106,20 +2173,74 @@ declare function transition(): TransitionState;
|
|
|
2106
2173
|
declare function nextTick(): Promise<void>;
|
|
2107
2174
|
|
|
2108
2175
|
type Subscriber = () => void;
|
|
2176
|
+
/**
|
|
2177
|
+
* Stop recording dependency edges until the matching {@link resumeTracking}.
|
|
2178
|
+
* Nestable — the depth is counted, so an inner pair does not resume early.
|
|
2179
|
+
*
|
|
2180
|
+
* Prefer {@link untracked}, which pairs the two calls for you even when the
|
|
2181
|
+
* body throws. Reach for the raw pair only when the suspended region cannot be
|
|
2182
|
+
* expressed as a single function.
|
|
2183
|
+
*
|
|
2184
|
+
* @returns Nothing.
|
|
2185
|
+
*/
|
|
2109
2186
|
declare function suspendTracking(): void;
|
|
2187
|
+
/**
|
|
2188
|
+
* Undo one {@link suspendTracking}. Dependency recording resumes only when the
|
|
2189
|
+
* outermost pair closes.
|
|
2190
|
+
*
|
|
2191
|
+
* @returns Nothing.
|
|
2192
|
+
*/
|
|
2110
2193
|
declare function resumeTracking(): void;
|
|
2111
2194
|
/** Read the "tracking suspended" flag (used by derived's lazy path). */
|
|
2112
2195
|
declare function isTrackingSuspended(): boolean;
|
|
2196
|
+
/**
|
|
2197
|
+
* Run `fn` without recording anything it reads as a dependency.
|
|
2198
|
+
*
|
|
2199
|
+
* The suspension is released even if `fn` throws, which is the reason to prefer
|
|
2200
|
+
* this over a manual suspend/resume pair.
|
|
2201
|
+
*
|
|
2202
|
+
* @param fn Function to run outside dependency tracking.
|
|
2203
|
+
* @returns Whatever `fn` returns.
|
|
2204
|
+
*/
|
|
2113
2205
|
declare function untracked$1<T>(fn: () => T): T;
|
|
2114
2206
|
declare function retrack$1(effectFn: () => void, subscriber: Subscriber): void;
|
|
2115
2207
|
declare function track(effectFn: () => void, subscriber?: Subscriber): () => void;
|
|
2116
2208
|
declare function reactiveBinding(commit: () => void, ownerNode?: unknown): () => void;
|
|
2117
2209
|
declare function recordDependency(signal: ReactiveSignal): void;
|
|
2118
2210
|
declare function cleanup(subscriber: Subscriber): void;
|
|
2211
|
+
/**
|
|
2212
|
+
* Cap how many times one subscriber may re-run within a single drain before it
|
|
2213
|
+
* is quarantined as a runaway cycle. A safety valve, not a tuning knob.
|
|
2214
|
+
*
|
|
2215
|
+
* @param n New limit; ignored unless finite and positive.
|
|
2216
|
+
* @returns The previous limit, so a caller can restore it.
|
|
2217
|
+
*/
|
|
2119
2218
|
declare function setMaxSubscriberRepeats(n: number): number;
|
|
2219
|
+
/**
|
|
2220
|
+
* Cap how many passes one notification drain may make before giving up on a
|
|
2221
|
+
* self-refeeding update cycle.
|
|
2222
|
+
*
|
|
2223
|
+
* @param n New limit; ignored unless finite and positive.
|
|
2224
|
+
* @returns The previous limit, so a caller can restore it.
|
|
2225
|
+
*/
|
|
2120
2226
|
declare function setMaxDrainIterations$1(n: number): number;
|
|
2227
|
+
/**
|
|
2228
|
+
* Flush queued signal notifications, running every dirty subscriber.
|
|
2229
|
+
*
|
|
2230
|
+
* Re-entrant calls are ignored: a write performed from inside a subscriber adds
|
|
2231
|
+
* to the queue the current drain is already working through, rather than
|
|
2232
|
+
* starting a nested one.
|
|
2233
|
+
*
|
|
2234
|
+
* @returns Nothing.
|
|
2235
|
+
*/
|
|
2121
2236
|
declare function drainNotificationQueue(): void;
|
|
2122
2237
|
declare function queueSignalNotification(signal: ReactiveSignal): void;
|
|
2238
|
+
/**
|
|
2239
|
+
* Mark every subscriber of `signal` dirty and queue them for the next drain.
|
|
2240
|
+
*
|
|
2241
|
+
* @param signal The signal that changed.
|
|
2242
|
+
* @returns Nothing.
|
|
2243
|
+
*/
|
|
2123
2244
|
declare function notifySubscribers(signal: ReactiveSignal): void;
|
|
2124
2245
|
/** O(1) subscriber count for devtools / introspection. */
|
|
2125
2246
|
declare function getSubscriberCount(signal: ReactiveSignal): number;
|