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/dist/components.js
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import { h } from './h.js';
|
|
2
|
-
import { signal, effect, untrack, __DEV__ } from './reactive.js';
|
|
3
|
-
export function memo(Component, areEqual) {
|
|
4
|
-
const compare = areEqual || shallowEqual;
|
|
5
|
-
function MemoWrapper(props) {
|
|
6
|
-
const ctx = _getCurrentComponent?.();
|
|
7
|
-
if (ctx && ctx._memoResult !== undefined) {
|
|
8
|
-
if (props === ctx._memoPropsRef) {
|
|
9
|
-
} else if (compare(ctx._memoProps, props)) {
|
|
10
|
-
ctx._memoPropsRef = props;
|
|
11
|
-
return ctx._memoResult;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
if (ctx) {
|
|
15
|
-
ctx._memoPropsRef = props;
|
|
16
|
-
ctx._memoProps = { ...props };
|
|
17
|
-
}
|
|
18
|
-
const result = Component(props);
|
|
19
|
-
if (ctx) ctx._memoResult = result;
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
MemoWrapper.displayName = `Memo(${Component.name || 'Anonymous'})`;
|
|
23
|
-
return MemoWrapper;
|
|
24
|
-
}
|
|
25
|
-
let _getCurrentComponent = null;
|
|
26
|
-
export function _injectGetCurrentComponent(fn) { _getCurrentComponent = fn; }
|
|
27
|
-
export function shallowEqual(a, b) {
|
|
28
|
-
if (a === b) return true;
|
|
29
|
-
const keysA = Object.keys(a);
|
|
30
|
-
const keysB = Object.keys(b);
|
|
31
|
-
if (keysA.length !== keysB.length) return false;
|
|
32
|
-
for (const key of keysA) {
|
|
33
|
-
if (!Object.is(a[key], b[key])) return false;
|
|
34
|
-
}
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
export function lazy(loader) {
|
|
38
|
-
let Component = null;
|
|
39
|
-
let loadPromise = null;
|
|
40
|
-
let loadError = null;
|
|
41
|
-
const listeners = new Set();
|
|
42
|
-
function LazyWrapper(props) {
|
|
43
|
-
if (loadError) throw loadError;
|
|
44
|
-
if (Component) return h(Component, props);
|
|
45
|
-
if (!loadPromise) {
|
|
46
|
-
loadPromise = loader()
|
|
47
|
-
.then(mod => {
|
|
48
|
-
Component = mod.default || mod;
|
|
49
|
-
listeners.forEach(fn => fn());
|
|
50
|
-
listeners.clear();
|
|
51
|
-
})
|
|
52
|
-
.catch(err => { loadError = err; });
|
|
53
|
-
}
|
|
54
|
-
throw loadPromise;
|
|
55
|
-
}
|
|
56
|
-
LazyWrapper.displayName = 'Lazy';
|
|
57
|
-
LazyWrapper._lazy = true;
|
|
58
|
-
LazyWrapper._onLoad = (fn) => {
|
|
59
|
-
if (Component) fn();
|
|
60
|
-
else listeners.add(fn);
|
|
61
|
-
};
|
|
62
|
-
return LazyWrapper;
|
|
63
|
-
}
|
|
64
|
-
export function Suspense({ fallback, children }) {
|
|
65
|
-
const loading = signal(false);
|
|
66
|
-
const pendingPromises = new Set();
|
|
67
|
-
const boundary = {
|
|
68
|
-
_suspense: true,
|
|
69
|
-
onSuspend(promise) {
|
|
70
|
-
loading.set(true);
|
|
71
|
-
pendingPromises.add(promise);
|
|
72
|
-
promise.finally(() => {
|
|
73
|
-
pendingPromises.delete(promise);
|
|
74
|
-
if (pendingPromises.size === 0) {
|
|
75
|
-
loading.set(false);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
return {
|
|
81
|
-
tag: '__suspense',
|
|
82
|
-
props: { boundary, fallback, loading },
|
|
83
|
-
children: Array.isArray(children) ? children : [children],
|
|
84
|
-
_vnode: true,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
export function ErrorBoundary({ fallback, children, onError }) {
|
|
88
|
-
const errorState = signal(null);
|
|
89
|
-
const handleError = (error) => {
|
|
90
|
-
errorState.set(error);
|
|
91
|
-
if (onError) {
|
|
92
|
-
try {
|
|
93
|
-
onError(error);
|
|
94
|
-
} catch (e) {
|
|
95
|
-
console.error('Error in onError handler:', e);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
const reset = () => errorState.set(null);
|
|
100
|
-
return {
|
|
101
|
-
tag: '__errorBoundary',
|
|
102
|
-
props: { errorState, handleError, fallback, reset },
|
|
103
|
-
children: Array.isArray(children) ? children : [children],
|
|
104
|
-
_vnode: true,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
export function reportError(error, startCtx) {
|
|
108
|
-
let ctx = startCtx || _getCurrentComponent?.();
|
|
109
|
-
while (ctx) {
|
|
110
|
-
if (ctx._errorBoundary) {
|
|
111
|
-
ctx._errorBoundary(error);
|
|
112
|
-
return true;
|
|
113
|
-
}
|
|
114
|
-
ctx = ctx._parentCtx;
|
|
115
|
-
}
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
export function Show({ when, fallback = null, children }) {
|
|
119
|
-
const condition = typeof when === 'function' ? when() : when;
|
|
120
|
-
return condition ? children : fallback;
|
|
121
|
-
}
|
|
122
|
-
export function For({ each, fallback = null, children }) {
|
|
123
|
-
const list = typeof each === 'function' ? each() : each;
|
|
124
|
-
if (!list || list.length === 0) return fallback;
|
|
125
|
-
const renderFn = Array.isArray(children) ? children[0] : children;
|
|
126
|
-
if (typeof renderFn !== 'function') {
|
|
127
|
-
console.warn('[what] For: children must be a render function, e.g. <For each={items}>{(item) => ...}</For>');
|
|
128
|
-
return fallback;
|
|
129
|
-
}
|
|
130
|
-
return list.map((item, index) => {
|
|
131
|
-
const vnode = renderFn(item, index);
|
|
132
|
-
if (vnode && typeof vnode === 'object' && vnode.key == null) {
|
|
133
|
-
if (item != null && typeof item === 'object') {
|
|
134
|
-
if (item.id != null) vnode.key = item.id;
|
|
135
|
-
else if (item.key != null) vnode.key = item.key;
|
|
136
|
-
} else if (typeof item === 'string' || typeof item === 'number') {
|
|
137
|
-
vnode.key = item;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return vnode;
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
export function Switch({ fallback = null, children }) {
|
|
144
|
-
const kids = Array.isArray(children) ? children : [children];
|
|
145
|
-
for (const child of kids) {
|
|
146
|
-
if (child && child.tag === Match) {
|
|
147
|
-
const condition = typeof child.props.when === 'function'
|
|
148
|
-
? child.props.when()
|
|
149
|
-
: child.props.when;
|
|
150
|
-
if (condition) {
|
|
151
|
-
return child.children;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return fallback;
|
|
156
|
-
}
|
|
157
|
-
export function Match({ when, children }) {
|
|
158
|
-
return { tag: Match, props: { when }, children, _vnode: true };
|
|
159
|
-
}
|
|
160
|
-
export function Island({ component: Component, mode, mediaQuery, ...props }) {
|
|
161
|
-
const placeholder = h('div', { 'data-island': Component.name || 'Island', 'data-hydrate': mode });
|
|
162
|
-
const wrapper = signal(null);
|
|
163
|
-
const hydrated = signal(false);
|
|
164
|
-
function doHydrate() {
|
|
165
|
-
if (hydrated()) return;
|
|
166
|
-
hydrated.set(true);
|
|
167
|
-
wrapper.set(h(Component, props));
|
|
168
|
-
}
|
|
169
|
-
function scheduleHydration(el) {
|
|
170
|
-
switch (mode) {
|
|
171
|
-
case 'load':
|
|
172
|
-
queueMicrotask(doHydrate);
|
|
173
|
-
break;
|
|
174
|
-
case 'idle':
|
|
175
|
-
if (typeof requestIdleCallback !== 'undefined') {
|
|
176
|
-
requestIdleCallback(doHydrate);
|
|
177
|
-
} else {
|
|
178
|
-
setTimeout(doHydrate, 200);
|
|
179
|
-
}
|
|
180
|
-
break;
|
|
181
|
-
case 'visible': {
|
|
182
|
-
const observer = new IntersectionObserver((entries) => {
|
|
183
|
-
if (entries[0].isIntersecting) {
|
|
184
|
-
observer.disconnect();
|
|
185
|
-
doHydrate();
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
observer.observe(el);
|
|
189
|
-
break;
|
|
190
|
-
}
|
|
191
|
-
case 'interaction': {
|
|
192
|
-
const hydrate = () => {
|
|
193
|
-
el.removeEventListener('click', hydrate);
|
|
194
|
-
el.removeEventListener('focus', hydrate);
|
|
195
|
-
el.removeEventListener('mouseenter', hydrate);
|
|
196
|
-
doHydrate();
|
|
197
|
-
};
|
|
198
|
-
el.addEventListener('click', hydrate, { once: true });
|
|
199
|
-
el.addEventListener('focus', hydrate, { once: true });
|
|
200
|
-
el.addEventListener('mouseenter', hydrate, { once: true });
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
case 'media': {
|
|
204
|
-
if (!mediaQuery) { doHydrate(); break; }
|
|
205
|
-
const mq = window.matchMedia(mediaQuery);
|
|
206
|
-
if (mq.matches) {
|
|
207
|
-
queueMicrotask(doHydrate);
|
|
208
|
-
} else {
|
|
209
|
-
const checkMedia = () => {
|
|
210
|
-
if (mq.matches) {
|
|
211
|
-
mq.removeEventListener('change', checkMedia);
|
|
212
|
-
doHydrate();
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
mq.addEventListener('change', checkMedia);
|
|
216
|
-
}
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
default:
|
|
220
|
-
queueMicrotask(doHydrate);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
const refCallback = (el) => {
|
|
224
|
-
if (el) scheduleHydration(el);
|
|
225
|
-
};
|
|
226
|
-
return h('div', { 'data-island': Component.name || 'Island', 'data-hydrate': mode, ref: refCallback },
|
|
227
|
-
hydrated() ? wrapper() : null
|
|
228
|
-
);
|
|
229
|
-
}
|