what-core 0.14.0 → 0.15.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.
Files changed (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -38
  3. package/a11y.d.ts +128 -0
  4. package/data.d.ts +294 -0
  5. package/dist/a11y.js +510 -0
  6. package/dist/a11y.min.js +413 -0
  7. package/dist/actions.js +158 -0
  8. package/dist/actions.min.js +112 -0
  9. package/dist/animation.js +481 -0
  10. package/dist/animation.min.js +295 -0
  11. package/dist/async.js +180 -0
  12. package/dist/async.min.js +134 -0
  13. package/dist/components.js +577 -0
  14. package/dist/components.min.js +413 -0
  15. package/dist/data.js +1212 -0
  16. package/dist/data.min.js +918 -0
  17. package/dist/diagnostics.js +187 -0
  18. package/dist/diagnostics.min.js +134 -0
  19. package/dist/dom.js +796 -0
  20. package/dist/dom.min.js +603 -0
  21. package/dist/entries/a11y.js +43 -0
  22. package/dist/entries/a11y.min.js +43 -0
  23. package/dist/entries/data.js +29 -0
  24. package/dist/entries/data.min.js +29 -0
  25. package/dist/entries/dom.js +45 -0
  26. package/dist/entries/dom.min.js +45 -0
  27. package/dist/entries/form.js +31 -0
  28. package/dist/entries/form.min.js +31 -0
  29. package/dist/entries/internal.js +123 -0
  30. package/dist/entries/internal.min.js +123 -0
  31. package/dist/entries/motion.js +23 -0
  32. package/dist/entries/motion.min.js +23 -0
  33. package/dist/entries/ui.js +25 -0
  34. package/dist/entries/ui.min.js +25 -0
  35. package/dist/env.js +5 -0
  36. package/dist/env.min.js +5 -0
  37. package/dist/errors.js +1518 -0
  38. package/dist/errors.min.js +548 -0
  39. package/dist/form.js +936 -0
  40. package/dist/form.min.js +703 -0
  41. package/dist/guardrails.js +84 -0
  42. package/dist/guardrails.min.js +55 -0
  43. package/dist/h.js +232 -0
  44. package/dist/h.min.js +171 -0
  45. package/dist/head.js +241 -0
  46. package/dist/head.min.js +207 -0
  47. package/dist/helpers.js +126 -0
  48. package/dist/helpers.min.js +98 -0
  49. package/dist/hooks.js +255 -0
  50. package/dist/hooks.min.js +153 -0
  51. package/dist/hot.js +215 -0
  52. package/dist/hot.min.js +24 -0
  53. package/dist/hydration-data.js +495 -0
  54. package/dist/hydration-data.min.js +371 -0
  55. package/dist/import-changes.js +273 -0
  56. package/dist/import-changes.min.js +272 -0
  57. package/dist/index.js +95 -0
  58. package/dist/index.min.js +95 -227
  59. package/dist/jsx-dev-runtime.js +10 -0
  60. package/dist/jsx-dev-runtime.min.js +10 -1
  61. package/dist/jsx-runtime.js +27 -0
  62. package/dist/jsx-runtime.min.js +15 -1
  63. package/dist/live.js +54 -0
  64. package/dist/live.min.js +49 -0
  65. package/dist/markup-rules.js +250 -0
  66. package/dist/markup-rules.min.js +213 -0
  67. package/dist/reactive.js +3334 -0
  68. package/dist/reactive.min.js +2033 -0
  69. package/dist/render.js +4746 -0
  70. package/dist/render.min.js +2797 -1
  71. package/dist/scheduler.js +225 -0
  72. package/dist/scheduler.min.js +162 -0
  73. package/dist/selector.js +11 -0
  74. package/dist/selector.min.js +10 -0
  75. package/dist/server-context.js +148 -0
  76. package/dist/server-context.min.js +121 -0
  77. package/dist/skeleton.js +342 -0
  78. package/dist/skeleton.min.js +310 -0
  79. package/dist/store.js +72 -0
  80. package/dist/store.min.js +50 -0
  81. package/dist/testing.js +720 -0
  82. package/dist/testing.min.js +458 -1
  83. package/dist/vnode-adoption.js +19 -0
  84. package/dist/vnode-adoption.min.js +19 -0
  85. package/dist/vnode-renderer.js +61 -0
  86. package/dist/vnode-renderer.min.js +47 -0
  87. package/dom.d.ts +44 -0
  88. package/form.d.ts +218 -0
  89. package/hot.d.ts +35 -0
  90. package/index.d.ts +421 -736
  91. package/internal.d.ts +284 -0
  92. package/jsx-runtime.d.ts +160 -137
  93. package/markup-rules.d.ts +83 -0
  94. package/motion.d.ts +156 -0
  95. package/package.json +117 -3
  96. package/render.d.ts +278 -29
  97. package/src/a11y.js +64 -59
  98. package/src/actions.js +226 -0
  99. package/src/animation.js +105 -57
  100. package/src/async.js +259 -0
  101. package/src/components.js +495 -144
  102. package/src/data.js +1410 -1159
  103. package/src/diagnostics.js +263 -0
  104. package/src/dom.js +1159 -872
  105. package/src/entries/a11y.js +24 -0
  106. package/src/entries/data.js +17 -0
  107. package/src/entries/dom.js +29 -0
  108. package/src/entries/form.js +16 -0
  109. package/src/entries/internal.js +63 -0
  110. package/src/entries/motion.js +13 -0
  111. package/src/entries/ui.js +13 -0
  112. package/src/env-development.js +12 -0
  113. package/src/env.js +33 -0
  114. package/src/errors.js +1144 -168
  115. package/src/form.js +723 -225
  116. package/src/guardrails.js +38 -126
  117. package/src/h.js +227 -152
  118. package/src/head.js +189 -19
  119. package/src/helpers.js +47 -75
  120. package/src/hooks.js +233 -248
  121. package/src/hot.js +316 -0
  122. package/src/hydration-data.js +859 -16
  123. package/src/import-changes.js +156 -0
  124. package/src/index.js +38 -188
  125. package/src/jsx-dev-runtime.js +7 -14
  126. package/src/jsx-runtime.js +25 -9
  127. package/src/live.js +80 -0
  128. package/src/markup-rules.js +387 -0
  129. package/src/reactive.js +4400 -862
  130. package/src/render.js +6502 -2570
  131. package/src/scheduler.js +56 -21
  132. package/src/selector.js +31 -0
  133. package/src/server-context.js +252 -22
  134. package/src/skeleton.js +22 -12
  135. package/src/store.js +17 -31
  136. package/src/testing.js +389 -63
  137. package/src/vnode-adoption.js +48 -0
  138. package/src/vnode-renderer.js +114 -0
  139. package/testing.d.ts +81 -1
  140. package/ui.d.ts +20 -0
  141. package/dist/chunk-6YOUZ6T4.min.js +0 -1
  142. package/dist/chunk-FN6HXME3.min.js +0 -11
  143. package/dist/chunk-VKZY7JPN.min.js +0 -1
  144. package/src/agent-context.js +0 -127
  145. package/src/warnings.js +0 -193
package/src/guardrails.js CHANGED
@@ -3,14 +3,13 @@
3
3
  // Designed for AI agents: structured warnings with fix suggestions.
4
4
 
5
5
  import { __DEV__ } from './reactive.js';
6
- import { createWhatError, collectError } from './errors.js';
6
+ import { IMPORT_CHANGES } from './import-changes.js';
7
+ import * as rootEntry from './index.js';
7
8
 
8
9
  // --- Guardrail Registry ---
9
10
  // Each guardrail can be enabled/disabled independently.
10
11
 
11
12
  const guardrails = {
12
- signalReadDetection: true,
13
- componentNaming: true,
14
13
  importValidation: true,
15
14
  };
16
15
 
@@ -22,150 +21,63 @@ export function getGuardrailConfig() {
22
21
  return { ...guardrails };
23
22
  }
24
23
 
25
- // --- Guardrail 1: Signal Read Detection ---
26
- // Detect when a signal function reference is used where its value was intended.
27
- // This catches patterns like `Total: ${count}` or `count > 5` (should be count()).
28
- //
29
- // At runtime, we detect this when a signal is coerced to a string or number
30
- // (via toString/valueOf) and warn that it should be called.
31
- //
32
- // Wiring: what-devtools calls this for every signal it registers (dev only),
33
- // so any app with devtools installed gets the guardrail automatically.
34
- // It can also be called manually: installSignalReadGuardrail(sig, 'name').
35
-
36
- export function installSignalReadGuardrail(signalFn, debugName) {
37
- if (!__DEV__ || !guardrails.signalReadDetection) return signalFn;
38
-
39
- // Override toString to catch template literal coercion
40
- signalFn.toString = function () {
41
- const err = createWhatError('MISSING_SIGNAL_READ', {
42
- signalName: debugName || '(unnamed)',
43
- });
44
- console.warn(`[what] ${err.message}\n Suggestion: ${err.suggestion}`);
45
- collectError(err);
46
- // Still return the value so the app doesn't crash
47
- return String(signalFn());
48
- };
49
-
50
- // Override valueOf for numeric coercion contexts
51
- signalFn.valueOf = function () {
52
- const err = createWhatError('MISSING_SIGNAL_READ', {
53
- signalName: debugName || '(unnamed)',
54
- });
55
- console.warn(`[what] ${err.message}\n Suggestion: ${err.suggestion}`);
56
- collectError(err);
57
- return signalFn();
58
- };
59
-
60
- return signalFn;
61
- }
62
-
63
- // NOTE: an "effect cycle detection" guardrail (trackEffectSignalWrite /
64
- // checkEffectCycle) used to live here, exported but never called by anything
65
- // — it was removed in v0.11 rather than shipped as a dead API. Reviving it
66
- // requires hooks inside reactive.js: (1) a call on every signal WRITE while
67
- // an effect is the active listener (to attribute writes to effects), and
68
- // (2) a post-run callback with the effect's tracked read-set (to intersect
69
- // reads with writes). reactive.js already detects runaway cascades at flush
70
- // time (iteration cap), which covers the practical failure mode.
71
-
72
- // --- Guardrail 2: Component Naming ---
73
- // Warn if a component function is not PascalCase.
74
-
75
- export function checkComponentName(name) {
76
- if (!__DEV__ || !guardrails.componentNaming) return null;
77
- if (!name) return null;
78
-
79
- // PascalCase: starts with uppercase letter
80
- if (/^[A-Z]/.test(name)) return null;
81
-
82
- const suggestion = `Component "${name}" should use PascalCase (e.g., "${capitalize(name)}"). ` +
83
- 'PascalCase distinguishes components from HTML elements in JSX and is required by the What Framework compiler.';
84
-
85
- console.warn(`[what] ${suggestion}`);
86
- return { code: 'WARN_COMPONENT_NAMING', name, suggestion };
87
- }
88
-
89
- function capitalize(str) {
90
- return str.charAt(0).toUpperCase() + str.slice(1);
24
+ // --- Import Validation ---
25
+ // Verify that all named imports from 'what-framework' are valid exports. A name
26
+ // in import-changes.js gets the answer recorded there (where it went, or what
27
+ // replaces it), the one what-compiler's Vite plugin and the no-moved-imports
28
+ // lint rule give, instead of a guess.
29
+
30
+ /** @type {{ valid: Set<string>, changed: Map<string, any> } | null} */
31
+ let exportIndex = null;
32
+
33
+ function exportsIndex() {
34
+ if (exportIndex === null) {
35
+ // Keyed by the old name and by the new one, so `useTween` imported from
36
+ // the root entry is pointed at what-framework/motion too.
37
+ const changed = new Map();
38
+ for (const change of IMPORT_CHANGES) {
39
+ changed.set(change.name, change);
40
+ if (change.as) changed.set(change.as, change);
41
+ }
42
+ exportIndex = { valid: new Set(Object.keys(rootEntry)), changed };
43
+ }
44
+ return exportIndex;
91
45
  }
92
46
 
93
- // --- Guardrail 3: Import Validation ---
94
- // Verify that all named imports from 'what-framework' are valid exports.
95
-
96
- const VALID_EXPORTS = new Set([
97
- // Reactive primitives
98
- 'signal', 'computed', 'effect', 'signalMemo', 'batch', 'untrack', 'flushSync',
99
- 'createRoot', 'getOwner', 'runWithOwner', 'onRootCleanup', '__setDevToolsHooks',
100
- // Rendering
101
- 'template', '_template', 'svgTemplate', 'insert', 'mapArray', 'spread',
102
- 'setProp', 'delegateEvents', 'on', 'classList', 'hydrate', 'isHydrating',
103
- '_$createComponent',
104
- // JSX
105
- 'h', 'Fragment', 'html',
106
- // DOM
107
- 'mount',
108
- // Hooks
109
- 'useState', 'useSignal', 'useComputed', 'useEffect', 'useMemo', 'useCallback',
110
- 'useRef', 'useContext', 'useReducer', 'createContext', 'onMount', 'onCleanup',
111
- 'createResource',
112
- // Components
113
- 'memo', 'lazy', 'Suspense', 'ErrorBoundary', 'Show', 'For', 'Switch', 'Match', 'Island',
114
- // Store
115
- 'createStore', 'derived', 'storeComputed', 'atom',
116
- // Head
117
- 'Head', 'clearHead',
118
- // Utilities
119
- 'each', 'cls', 'style', 'debounce', 'throttle', 'useMediaQuery',
120
- 'useLocalStorage', 'useClickOutside', 'Portal', 'transition',
121
- // Scheduler
122
- 'scheduleRead', 'scheduleWrite', 'flushScheduler', 'measure', 'mutate',
123
- 'useScheduledEffect', 'nextFrame', 'raf', 'onResize', 'onIntersect', 'smoothScrollTo',
124
- // Text insertion hook (for external text engines)
125
- '_setTextInsertHook',
126
- // Animation
127
- 'spring', 'tween', 'easings', 'useTransition', 'useGesture', 'useAnimatedValue',
128
- 'createTransitionClasses', 'cssTransition',
129
- // Accessibility
130
- 'useFocus', 'useFocusRestore', 'useFocusTrap', 'FocusTrap', 'announce',
131
- 'announceAssertive', 'SkipLink', 'useAriaExpanded', 'useAriaSelected',
132
- 'useAriaChecked', 'useRovingTabIndex', 'VisuallyHidden', 'LiveRegion',
133
- 'useId', 'useIds', 'useDescribedBy', 'useLabelledBy', 'Keys', 'onKey', 'onKeys',
134
- // Skeleton
135
- 'Skeleton', 'SkeletonText', 'SkeletonAvatar', 'SkeletonCard', 'SkeletonTable',
136
- 'IslandSkeleton', 'useSkeleton', 'Placeholder', 'LoadingDots', 'Spinner',
137
- // Data fetching
138
- 'useFetch', 'useSWR', 'useQuery', 'useInfiniteQuery', 'invalidateQueries',
139
- 'prefetchQuery', 'setQueryData', 'getQueryData', 'clearCache', '__getCacheSnapshot',
140
- // Form
141
- 'useForm', 'useField', 'rules', 'simpleResolver', 'zodResolver', 'yupResolver',
142
- 'Input', 'Textarea', 'Select', 'Checkbox', 'Radio', 'ErrorMessage',
143
- ]);
144
-
145
47
  export function validateImports(importNames) {
146
48
  if (!__DEV__ || !guardrails.importValidation) return [];
147
49
 
50
+ const { valid, changed } = exportsIndex();
148
51
  const invalid = [];
149
52
  for (const name of importNames) {
150
- if (!VALID_EXPORTS.has(name)) {
53
+ if (valid.has(name)) continue;
54
+ const change = changed.get(name);
55
+ if (change) {
56
+ invalid.push({
57
+ name,
58
+ message: `"${name}" is not exported by what-framework.`,
59
+ suggestion: change.answer,
60
+ });
61
+ } else {
62
+ const closest = findClosest(name);
151
63
  invalid.push({
152
64
  name,
153
65
  message: `"${name}" is not a valid export from what-framework.`,
154
- suggestion: `Check the API reference. Did you mean: ${findClosest(name)}?`,
66
+ suggestion: closest ? `Check the API reference. Did you mean ${closest}?` : 'Check the API reference.',
155
67
  });
156
68
  }
157
69
  }
158
70
  return invalid;
159
71
  }
160
72
 
161
- // Simple Levenshtein-based closest match
73
+ // Simple Levenshtein-based closest match, or null when nothing is close.
162
74
  function findClosest(input) {
163
75
  const lower = input.toLowerCase();
164
76
  /** @type {string | null} */
165
77
  let best = null;
166
78
  let bestDist = Infinity;
167
79
 
168
- for (const name of VALID_EXPORTS) {
80
+ for (const name of exportsIndex().valid) {
169
81
  const dist = levenshtein(lower, name.toLowerCase());
170
82
  if (dist < bestDist) {
171
83
  bestDist = dist;
@@ -173,7 +85,7 @@ function findClosest(input) {
173
85
  }
174
86
  }
175
87
 
176
- return bestDist <= 3 ? best : '(no close match found)';
88
+ return bestDist <= 3 ? best : null;
177
89
  }
178
90
 
179
91
  function levenshtein(a, b) {