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
@@ -0,0 +1,263 @@
1
+ // What Framework - Diagnostics channel
2
+ //
3
+ // One coded stream for everything the runtime notices in development: every
4
+ // check reports here, and devtools, the MCP bridge, what-framework/testing and
5
+ // the console all read from here. Messages and fixes come from ERROR_CODES, so
6
+ // what an agent reads over MCP, in a test failure and in the console is the
7
+ // same text.
8
+ //
9
+ // This module never reads the dev flag. Every call site is written as
10
+ // `if (__DEV__) report(...)`, so once __DEV__ is a build-time constant the
11
+ // call, this module and the catalogue it imports all drop out of production
12
+ // bundles. It also must not import reactive.js: the engine reports into this
13
+ // channel, and the import would be a cycle.
14
+ //
15
+ // Event shape (serializable; never holds a live node):
16
+ // { seq, firstSeq, code, severity, message, fix, owner, loc, subject, data, count }
17
+ // owner component/computation path, root first: ['<App>', '<TodoRow>', 'effect "sync"'].
18
+ // A call site that does not pass one gets the scope the report was
19
+ // made in, from the engine (see _setOwnerSource).
20
+ // loc 'src/TodoRow.jsx:18:3' when the compiler supplied one, else null.
21
+ // subject { kind: 'signal'|'effect'|'component'|..., id?, name? } or null.
22
+ // count repeats of the same code on the same subject, folded into one event.
23
+ // A repeat moves the event to the newest seq, so a cursor read sees it,
24
+ // and the event then describes that latest repeat: message, data,
25
+ // owner and loc are the newest report's. firstSeq is the first one's.
26
+
27
+ import { getErrorDefinition } from './errors.js';
28
+
29
+ // Kept equal to packages/core/package.json by scripts/bump-version.mjs and
30
+ // checked by core/test/diagnostics.test.js. Pins the console docs link to the
31
+ // release the app is running, never to a branch.
32
+ export const VERSION = '0.15.0';
33
+
34
+ const SKILL_PATH = 'node_modules/what-framework/skills/what-diagnostics/SKILL.md';
35
+ const MAX_EVENTS = 500;
36
+
37
+ let seq = 0;
38
+ let dropped = 0;
39
+ // Insertion order is seq order: a repeat is deleted and re-inserted.
40
+ const events = new Map();
41
+ const listeners = new Set();
42
+ // Deliveries waiting for the listener loop. A listener that reports from inside
43
+ // its callback queues the new event behind the current one instead of
44
+ // delivering it first, so every listener sees events in seq order.
45
+ const pending = [];
46
+ let delivering = false;
47
+ const captures = new Set();
48
+ const pointed = new Set();
49
+
50
+ // Installed by the engine in development: the owner path of the scope running
51
+ // now, an array of strings with a `loc` property (reactive.js __ownerPath).
52
+ /** @type {(() => string[] & { loc: string | null }) | null} */
53
+ let ownerSource = null;
54
+
55
+ /** @internal The engine names the scope a report is made in. */
56
+ export function _setOwnerSource(fn) {
57
+ ownerSource = fn;
58
+ }
59
+
60
+ function interpolate(template, data) {
61
+ return template.replace(/\{\{(\w+)\}\}/g, (_, key) => (data[key] === undefined ? '(unknown)' : String(data[key])));
62
+ }
63
+
64
+ function docsUrl(code) {
65
+ return `https://github.com/CelsianJs/what-framework/blob/v${VERSION}/docs/ERRORS.md#${code.toLowerCase().replace(/_/g, '-')}`;
66
+ }
67
+
68
+ function fixLine(code) {
69
+ return ` fix: what_fix({ error: "${code}" }) · ${SKILL_PATH} · ${docsUrl(code)}`;
70
+ }
71
+
72
+ function print(ev) {
73
+ for (const c of captures) if (c.quiet) return;
74
+ const lines = [`[what] ${ev.code} ${ev.message}`];
75
+ if (ev.owner.length) lines.push(` in ${ev.owner.join(' › ')}`);
76
+ if (ev.loc) lines.push(` at ${ev.loc}`);
77
+ if (!pointed.has(ev.code)) {
78
+ pointed.add(ev.code);
79
+ lines.push(fixLine(ev.code));
80
+ }
81
+ if (typeof console === 'undefined') return;
82
+ (ev.severity === 'error' ? console.error : console.warn)(lines.join('\n'));
83
+ }
84
+
85
+ /**
86
+ * @internal Development: the message of an error what-core throws with a
87
+ * catalogue code, in the shape the console prints a reported one: the code
88
+ * after `[what]`, then the line that says where its fix is. A throw site
89
+ * writes `__DEV__ ? _thrownMessage(code, text) : shortText`, so the production
90
+ * tier keeps its short text and none of this.
91
+ * @param {string} code ERR_* code from ERROR_CODES
92
+ * @param {string} message
93
+ */
94
+ export function _thrownMessage(code, message) {
95
+ return `[what] ${code} ${message.replace(/^\[what\] /, '')}\n${fixLine(code)}`;
96
+ }
97
+
98
+ /**
99
+ * Report a diagnostic. `data` fills the catalogue template and travels with the
100
+ * event; `owner` and `loc` come from the engine and compiler when they know them.
101
+ * Returns the event, so a throwing site can reuse its message.
102
+ * @param {string} code ERR_* code from ERROR_CODES
103
+ * @param {{ data?: Record<string, any>, subject?: { kind: string, id?: any, name?: string } | null, owner?: string[], loc?: string | null }} [detail]
104
+ */
105
+ export function report(code, detail = {}) {
106
+ const known = getErrorDefinition(code);
107
+ const def = known || getErrorDefinition('ERR_UNKNOWN');
108
+ const data = known ? (detail.data || {}) : { ...detail.data, errorCode: code };
109
+ const subject = detail.subject || null;
110
+ const message = interpolate(def.template, data);
111
+ const key = subject
112
+ ? `${def.code}|${subject.kind}|${subject.id ?? subject.name}`
113
+ : `${def.code}|${message}`;
114
+ const where = ownerSource !== null && (detail.owner == null || detail.loc == null) ? ownerSource() : null;
115
+ const owner = detail.owner || (where !== null ? [...where] : []);
116
+ const loc = detail.loc || (where !== null ? where.loc : null);
117
+
118
+ let ev = events.get(key);
119
+ if (ev) {
120
+ events.delete(key);
121
+ ev.count++;
122
+ ev.seq = ++seq;
123
+ ev.message = message;
124
+ ev.data = data;
125
+ ev.owner = owner;
126
+ ev.loc = loc;
127
+ events.set(key, ev);
128
+ } else {
129
+ const at = ++seq;
130
+ ev = {
131
+ seq: at,
132
+ firstSeq: at,
133
+ code: def.code,
134
+ severity: def.severity,
135
+ message,
136
+ fix: def.suggestion,
137
+ owner,
138
+ loc,
139
+ subject,
140
+ data,
141
+ count: 1,
142
+ };
143
+ events.set(key, ev);
144
+ if (events.size > MAX_EVENTS) {
145
+ events.delete(events.keys().next().value);
146
+ dropped++;
147
+ }
148
+ print(ev);
149
+ }
150
+
151
+ for (const c of captures) c.record(key, ev);
152
+ deliver(ev);
153
+ return ev;
154
+ }
155
+
156
+ function copy(ev) {
157
+ return { ...ev, owner: [...ev.owner], subject: ev.subject && { ...ev.subject }, data: { ...ev.data } };
158
+ }
159
+
160
+ function deliver(ev) {
161
+ if (listeners.size === 0) return;
162
+ pending.push(Object.freeze(copy(ev)));
163
+ if (delivering) return;
164
+ delivering = true;
165
+ try {
166
+ for (let i = 0; i < pending.length; i++) {
167
+ for (const fn of listeners) {
168
+ try { fn(pending[i]); } catch { /* a broken listener must not break the app */ }
169
+ }
170
+ }
171
+ } finally {
172
+ pending.length = 0;
173
+ delivering = false;
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Listen to every report, repeats included, in seq order. Each delivery is a
179
+ * frozen copy taken when the report was made. Returns an unsubscribe function.
180
+ * @param {(event: any) => void} fn
181
+ */
182
+ export function subscribe(fn) {
183
+ listeners.add(fn);
184
+ return () => { listeners.delete(fn); };
185
+ }
186
+
187
+ /**
188
+ * Collect the reports made from now until stop(), folded by code and subject
189
+ * with counts local to this capture. `quiet: true` keeps them off the console
190
+ * while the capture is open.
191
+ * @param {{ quiet?: boolean }} [options]
192
+ */
193
+ export function capture({ quiet = false } = {}) {
194
+ const byKey = new Map();
195
+ const collected = [];
196
+ const sink = {
197
+ quiet,
198
+ record(key, ev) {
199
+ const mine = byKey.get(key);
200
+ if (mine) {
201
+ Object.assign(mine, copy(ev), { firstSeq: mine.firstSeq, count: mine.count + 1 });
202
+ return;
203
+ }
204
+ const own = { ...copy(ev), firstSeq: ev.seq, count: 1 };
205
+ byKey.set(key, own);
206
+ collected.push(own);
207
+ },
208
+ };
209
+ captures.add(sink);
210
+ return {
211
+ events: collected,
212
+ clear() {
213
+ byKey.clear();
214
+ collected.length = 0;
215
+ },
216
+ stop() {
217
+ captures.delete(sink);
218
+ return collected;
219
+ },
220
+ };
221
+ }
222
+
223
+ /**
224
+ * Cursor read: events with a seq greater than `since`, oldest first. Pass the
225
+ * returned `seq` back as `since` to read only what happened after this call.
226
+ * `dropped` counts events evicted from the bounded buffer since startup.
227
+ * @param {{ since?: number }} [options]
228
+ */
229
+ export function getDiagnostics({ since = 0 } = {}) {
230
+ const out = [];
231
+ for (const ev of events.values()) if (ev.seq > since) out.push(copy(ev));
232
+ return { events: out, seq, dropped };
233
+ }
234
+
235
+ /** Forget buffered events and console pointers. The sequence keeps counting. */
236
+ export function clearDiagnostics() {
237
+ events.clear();
238
+ pointed.clear();
239
+ dropped = 0;
240
+ }
241
+
242
+ // Internal renderer annotations. Every caller is behind the development flag.
243
+
244
+ /** @type {{ name: string, binding: Node } | null} */
245
+ export let nextBinding = null;
246
+
247
+ // The renderer pairs this with its immediately following effect(() => …).
248
+ // The effect takes the annotation before the first run, so nesting is safe.
249
+ export function setNextBinding(binding, name) {
250
+ nextBinding = { binding, name };
251
+ }
252
+
253
+ export function clearNextBinding() {
254
+ nextBinding = null;
255
+ }
256
+
257
+ export function recordObservation(hooks, type, subject, state) {
258
+ if (!hooks?.onRecord) return;
259
+ try { hooks.onRecord(type, subject, state); }
260
+ catch (error) {
261
+ try { console.error('[what] devtools hook onRecord threw:', error); } catch { /* no console */ }
262
+ }
263
+ }