what-core 0.6.1 → 0.6.3
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 +2 -0
- package/compiler.d.ts +30 -0
- package/devtools.d.ts +2 -0
- package/dist/compiler.js +1787 -0
- package/dist/compiler.js.map +7 -0
- package/dist/compiler.min.js +2 -0
- package/dist/compiler.min.js.map +7 -0
- package/dist/devtools.js +10 -0
- package/dist/devtools.js.map +7 -0
- package/dist/devtools.min.js +2 -0
- package/dist/devtools.min.js.map +7 -0
- package/dist/index.js +331 -382
- package/dist/index.js.map +4 -4
- package/dist/index.min.js +62 -62
- package/dist/index.min.js.map +4 -4
- package/dist/render.js +263 -21
- package/dist/render.js.map +4 -4
- package/dist/render.min.js +58 -1
- package/dist/render.min.js.map +4 -4
- package/dist/testing.js +3 -0
- package/dist/testing.js.map +2 -2
- package/dist/testing.min.js +1 -1
- package/dist/testing.min.js.map +2 -2
- package/index.d.ts +176 -1
- package/jsx-runtime.d.ts +622 -0
- package/package.json +20 -2
- package/src/agent-context.js +1 -1
- package/src/compiler.js +18 -0
- package/src/components.js +73 -27
- package/src/devtools.js +4 -0
- package/src/dom.js +7 -0
- package/src/guardrails.js +3 -4
- package/src/hooks.js +0 -11
- package/src/index.js +5 -9
- package/src/render.js +94 -24
- package/dist/a11y.js +0 -440
- package/dist/animation.js +0 -548
- package/dist/components.js +0 -229
- package/dist/data.js +0 -638
- package/dist/dom.js +0 -439
- package/dist/form.js +0 -509
- package/dist/h.js +0 -152
- package/dist/head.js +0 -51
- package/dist/helpers.js +0 -140
- package/dist/hooks.js +0 -210
- package/dist/reactive.js +0 -432
- package/dist/scheduler.js +0 -246
- package/dist/skeleton.js +0 -363
- package/dist/store.js +0 -83
- package/dist/what.js +0 -117
package/index.d.ts
CHANGED
|
@@ -24,15 +24,59 @@ export interface Computed<T> {
|
|
|
24
24
|
_signal: true;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Create a reactive signal with an initial value.
|
|
29
|
+
* Read with `sig()`, write with `sig(newVal)` or `sig.set(newVal)`.
|
|
30
|
+
* @param initial - Initial value
|
|
31
|
+
* @param debugName - Optional name for devtools inspection
|
|
32
|
+
*/
|
|
33
|
+
export function signal<T>(initial: T, debugName?: string): Signal<T>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Create a derived (computed) signal. Lazy: only recomputes when a
|
|
37
|
+
* dependency changes AND the computed is read.
|
|
38
|
+
*/
|
|
28
39
|
export function computed<T>(fn: () => T): Computed<T>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Run a side-effect function that auto-tracks signal reads.
|
|
43
|
+
* Re-runs when any tracked signal changes.
|
|
44
|
+
* Return a cleanup function from `fn` to run before each re-execution.
|
|
45
|
+
* @returns Dispose function to stop the effect
|
|
46
|
+
*/
|
|
29
47
|
export function effect(fn: () => void | (() => void), opts?: { stable?: boolean }): () => void;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Eager computed that only propagates when the value actually changes.
|
|
51
|
+
* Alias: `signalMemo` (exported as `memo` from reactive, renamed to avoid
|
|
52
|
+
* collision with component `memo`).
|
|
53
|
+
*/
|
|
30
54
|
export function signalMemo<T>(fn: () => T): Computed<T>;
|
|
55
|
+
|
|
56
|
+
/** Group multiple signal writes; effects run once at the end. */
|
|
31
57
|
export function batch<T>(fn: () => T): T;
|
|
58
|
+
|
|
59
|
+
/** Read signals without subscribing to them. */
|
|
32
60
|
export function untrack<T>(fn: () => T): T;
|
|
61
|
+
|
|
62
|
+
/** Force all pending effects to run synchronously. Use sparingly. */
|
|
33
63
|
export function flushSync(): void;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Create an isolated reactive scope with ownership tree.
|
|
67
|
+
* All effects created inside are tracked and disposed together.
|
|
68
|
+
*/
|
|
34
69
|
export function createRoot<T>(fn: (dispose: () => void) => T): T;
|
|
35
70
|
|
|
71
|
+
/** Get the current owner context (for advanced async patterns). */
|
|
72
|
+
export function getOwner(): any;
|
|
73
|
+
|
|
74
|
+
/** Run a function within a specific owner context. */
|
|
75
|
+
export function runWithOwner<T>(owner: any, fn: () => T): T;
|
|
76
|
+
|
|
77
|
+
/** Register a cleanup function with the current owner/root. */
|
|
78
|
+
export function onRootCleanup(fn: () => void): void;
|
|
79
|
+
|
|
36
80
|
// --- Virtual DOM ---
|
|
37
81
|
|
|
38
82
|
export type PrimitiveChild = string | number | boolean | null | undefined;
|
|
@@ -62,8 +106,17 @@ export function html(strings: TemplateStringsArray, ...values: any[]): VNode | V
|
|
|
62
106
|
export function mount(vnode: VNodeChild, container: string | Element): () => void;
|
|
63
107
|
|
|
64
108
|
// Fine-grained rendering primitives
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @internal Compiler internal -- do NOT call directly in application code.
|
|
112
|
+
* Use JSX instead. The compiler transforms JSX into `_$template()` calls automatically.
|
|
113
|
+
* Direct use with untrusted input creates XSS vulnerabilities (innerHTML).
|
|
114
|
+
* @deprecated Use JSX. This export exists only for backward compatibility.
|
|
115
|
+
*/
|
|
65
116
|
export function template(html: string): () => Element;
|
|
117
|
+
/** @internal Compiler internal -- inserts reactive children into DOM. Emitted by the compiler. */
|
|
66
118
|
export function insert(parent: Node, child: any, marker?: Node | null): any;
|
|
119
|
+
/** @internal Compiler internal -- keyed list reconciliation. Emitted by the compiler for `<For>`. */
|
|
67
120
|
export function mapArray<T>(
|
|
68
121
|
source: () => T[],
|
|
69
122
|
mapFn: (item: T | Signal<T>, index: number) => Node,
|
|
@@ -163,6 +216,9 @@ export function Island(props: IslandProps): VNode;
|
|
|
163
216
|
|
|
164
217
|
export type DerivedFn<T> = ((state: any) => T) & { _isDerived: true };
|
|
165
218
|
export function derived<T>(fn: (state: any) => T): DerivedFn<T>;
|
|
219
|
+
/**
|
|
220
|
+
* @deprecated Use derived(fn) instead. storeComputed remains as a runtime alias for backward compatibility.
|
|
221
|
+
*/
|
|
166
222
|
export function storeComputed<T>(fn: (state: any) => T): DerivedFn<T>;
|
|
167
223
|
export type StoreDefinition = Record<string, any>;
|
|
168
224
|
export type Store<T extends StoreDefinition> = T;
|
|
@@ -505,3 +561,122 @@ export function ErrorMessage(props: {
|
|
|
505
561
|
errors?: Record<string, FieldError> | (() => Record<string, FieldError>);
|
|
506
562
|
render?: (args: { message?: string; type?: string }) => VNodeChild;
|
|
507
563
|
}): VNodeChild;
|
|
564
|
+
|
|
565
|
+
// --- Structured Error System ---
|
|
566
|
+
|
|
567
|
+
export interface ErrorCodeDefinition {
|
|
568
|
+
code: string;
|
|
569
|
+
severity: 'error' | 'warning';
|
|
570
|
+
template: string;
|
|
571
|
+
suggestion: string;
|
|
572
|
+
codeExample: string;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
export const ERROR_CODES: {
|
|
576
|
+
INFINITE_EFFECT: ErrorCodeDefinition;
|
|
577
|
+
MISSING_SIGNAL_READ: ErrorCodeDefinition;
|
|
578
|
+
HYDRATION_MISMATCH: ErrorCodeDefinition;
|
|
579
|
+
ORPHAN_EFFECT: ErrorCodeDefinition;
|
|
580
|
+
SIGNAL_WRITE_IN_RENDER: ErrorCodeDefinition;
|
|
581
|
+
MISSING_CLEANUP: ErrorCodeDefinition;
|
|
582
|
+
UNSAFE_INNERHTML: ErrorCodeDefinition;
|
|
583
|
+
MISSING_KEY: ErrorCodeDefinition;
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
export class WhatError extends Error {
|
|
587
|
+
code: string;
|
|
588
|
+
suggestion?: string;
|
|
589
|
+
file?: string;
|
|
590
|
+
line?: number;
|
|
591
|
+
component?: string;
|
|
592
|
+
signal?: string;
|
|
593
|
+
effect?: string;
|
|
594
|
+
constructor(opts: {
|
|
595
|
+
code: string;
|
|
596
|
+
message: string;
|
|
597
|
+
suggestion?: string;
|
|
598
|
+
file?: string;
|
|
599
|
+
line?: number;
|
|
600
|
+
component?: string;
|
|
601
|
+
signal?: string;
|
|
602
|
+
effect?: string;
|
|
603
|
+
});
|
|
604
|
+
toJSON(): Record<string, any>;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
export function createWhatError(
|
|
608
|
+
errorCode: string | ErrorCodeDefinition,
|
|
609
|
+
context?: Record<string, any>,
|
|
610
|
+
): WhatError;
|
|
611
|
+
|
|
612
|
+
export function classifyError(err: Error, context?: Record<string, any>): WhatError;
|
|
613
|
+
export function collectError(whatError: WhatError): void;
|
|
614
|
+
export function getCollectedErrors(since?: number): Array<Record<string, any>>;
|
|
615
|
+
export function clearCollectedErrors(): void;
|
|
616
|
+
|
|
617
|
+
// --- Agent Guardrails ---
|
|
618
|
+
|
|
619
|
+
export interface GuardrailConfig {
|
|
620
|
+
signalReadDetection: boolean;
|
|
621
|
+
effectCycleDetection: boolean;
|
|
622
|
+
componentNaming: boolean;
|
|
623
|
+
importValidation: boolean;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
export function configureGuardrails(overrides: Partial<GuardrailConfig>): void;
|
|
627
|
+
export function getGuardrailConfig(): GuardrailConfig;
|
|
628
|
+
export function installSignalReadGuardrail<T>(signalFn: Signal<T>, debugName?: string): Signal<T>;
|
|
629
|
+
export function checkComponentName(name: string): { code: string; name: string; suggestion: string } | null;
|
|
630
|
+
export function validateImports(importNames: string[]): Array<{ name: string; message: string; suggestion: string }>;
|
|
631
|
+
|
|
632
|
+
// --- Agent Context ---
|
|
633
|
+
|
|
634
|
+
export interface AgentHealthReport {
|
|
635
|
+
effectCycleRisk: boolean;
|
|
636
|
+
orphanEffects: number;
|
|
637
|
+
signalLeaks: number;
|
|
638
|
+
memoryPressure: 'low' | 'medium' | 'high';
|
|
639
|
+
recentErrorCount: number;
|
|
640
|
+
totalSignals: number;
|
|
641
|
+
totalComponents: number;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
export function installAgentContext(): void;
|
|
645
|
+
export function registerComponent(component: any): void;
|
|
646
|
+
export function unregisterComponent(component: any): void;
|
|
647
|
+
export function getMountedComponents(): any[];
|
|
648
|
+
export function registerSignal(sig: Signal<any>): void;
|
|
649
|
+
export function unregisterSignal(sig: Signal<any>): void;
|
|
650
|
+
export function getActiveSignals(): Signal<any>[];
|
|
651
|
+
export function getHealth(): AgentHealthReport;
|
|
652
|
+
|
|
653
|
+
// --- Hydration ---
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* Hydrate a vnode tree against existing server-rendered DOM in the container.
|
|
657
|
+
* Reuses existing DOM nodes instead of creating new ones. Attaches reactive
|
|
658
|
+
* bindings and event handlers to the server-rendered markup.
|
|
659
|
+
*
|
|
660
|
+
* In dev mode, logs warnings for every hydration mismatch (text, element,
|
|
661
|
+
* attribute). After hydration completes, logs a summary if mismatches occurred.
|
|
662
|
+
*
|
|
663
|
+
* @param vnode - The component tree (same tree used for SSR)
|
|
664
|
+
* @param container - The DOM element containing server-rendered HTML
|
|
665
|
+
* @returns The hydrated DOM node(s)
|
|
666
|
+
*/
|
|
667
|
+
export function hydrate(vnode: VNodeChild, container: Element): any;
|
|
668
|
+
|
|
669
|
+
/** Returns true if currently inside a hydration pass. */
|
|
670
|
+
export function isHydrating(): boolean;
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Returns the number of hydration mismatches from the most recent `hydrate()` call.
|
|
674
|
+
* Useful for testing and diagnostics.
|
|
675
|
+
*/
|
|
676
|
+
export function getHydrationMismatchCount(): number;
|
|
677
|
+
|
|
678
|
+
// --- SVG template helper ---
|
|
679
|
+
/**
|
|
680
|
+
* @internal Parse SVG content inside an SVG namespace container.
|
|
681
|
+
*/
|
|
682
|
+
export function svgTemplate(html: string): () => Element;
|