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.
- package/LICENSE +21 -0
- package/README.md +64 -38
- package/a11y.d.ts +128 -0
- package/data.d.ts +294 -0
- package/dist/a11y.js +510 -0
- package/dist/a11y.min.js +413 -0
- package/dist/actions.js +158 -0
- package/dist/actions.min.js +112 -0
- package/dist/animation.js +481 -0
- package/dist/animation.min.js +295 -0
- package/dist/async.js +180 -0
- package/dist/async.min.js +134 -0
- package/dist/components.js +577 -0
- package/dist/components.min.js +413 -0
- package/dist/data.js +1212 -0
- package/dist/data.min.js +918 -0
- package/dist/diagnostics.js +187 -0
- package/dist/diagnostics.min.js +134 -0
- package/dist/dom.js +796 -0
- package/dist/dom.min.js +603 -0
- package/dist/entries/a11y.js +43 -0
- package/dist/entries/a11y.min.js +43 -0
- package/dist/entries/data.js +29 -0
- package/dist/entries/data.min.js +29 -0
- package/dist/entries/dom.js +45 -0
- package/dist/entries/dom.min.js +45 -0
- package/dist/entries/form.js +31 -0
- package/dist/entries/form.min.js +31 -0
- package/dist/entries/internal.js +123 -0
- package/dist/entries/internal.min.js +123 -0
- package/dist/entries/motion.js +23 -0
- package/dist/entries/motion.min.js +23 -0
- package/dist/entries/ui.js +25 -0
- package/dist/entries/ui.min.js +25 -0
- package/dist/env.js +5 -0
- package/dist/env.min.js +5 -0
- package/dist/errors.js +1518 -0
- package/dist/errors.min.js +548 -0
- package/dist/form.js +936 -0
- package/dist/form.min.js +703 -0
- package/dist/guardrails.js +84 -0
- package/dist/guardrails.min.js +55 -0
- package/dist/h.js +232 -0
- package/dist/h.min.js +171 -0
- package/dist/head.js +241 -0
- package/dist/head.min.js +207 -0
- package/dist/helpers.js +126 -0
- package/dist/helpers.min.js +98 -0
- package/dist/hooks.js +255 -0
- package/dist/hooks.min.js +153 -0
- package/dist/hot.js +215 -0
- package/dist/hot.min.js +24 -0
- package/dist/hydration-data.js +495 -0
- package/dist/hydration-data.min.js +371 -0
- package/dist/import-changes.js +273 -0
- package/dist/import-changes.min.js +272 -0
- package/dist/index.js +95 -0
- package/dist/index.min.js +95 -227
- package/dist/jsx-dev-runtime.js +10 -0
- package/dist/jsx-dev-runtime.min.js +10 -1
- package/dist/jsx-runtime.js +27 -0
- package/dist/jsx-runtime.min.js +15 -1
- package/dist/live.js +54 -0
- package/dist/live.min.js +49 -0
- package/dist/markup-rules.js +250 -0
- package/dist/markup-rules.min.js +213 -0
- package/dist/reactive.js +3334 -0
- package/dist/reactive.min.js +2033 -0
- package/dist/render.js +4746 -0
- package/dist/render.min.js +2797 -1
- package/dist/scheduler.js +225 -0
- package/dist/scheduler.min.js +162 -0
- package/dist/selector.js +11 -0
- package/dist/selector.min.js +10 -0
- package/dist/server-context.js +148 -0
- package/dist/server-context.min.js +121 -0
- package/dist/skeleton.js +342 -0
- package/dist/skeleton.min.js +310 -0
- package/dist/store.js +72 -0
- package/dist/store.min.js +50 -0
- package/dist/testing.js +720 -0
- package/dist/testing.min.js +458 -1
- package/dist/vnode-adoption.js +19 -0
- package/dist/vnode-adoption.min.js +19 -0
- package/dist/vnode-renderer.js +61 -0
- package/dist/vnode-renderer.min.js +47 -0
- package/dom.d.ts +44 -0
- package/form.d.ts +218 -0
- package/hot.d.ts +35 -0
- package/index.d.ts +421 -736
- package/internal.d.ts +284 -0
- package/jsx-runtime.d.ts +160 -137
- package/markup-rules.d.ts +83 -0
- package/motion.d.ts +156 -0
- package/package.json +117 -3
- package/render.d.ts +278 -29
- package/src/a11y.js +64 -59
- package/src/actions.js +226 -0
- package/src/animation.js +105 -57
- package/src/async.js +259 -0
- package/src/components.js +495 -144
- package/src/data.js +1410 -1159
- package/src/diagnostics.js +263 -0
- package/src/dom.js +1159 -872
- package/src/entries/a11y.js +24 -0
- package/src/entries/data.js +17 -0
- package/src/entries/dom.js +29 -0
- package/src/entries/form.js +16 -0
- package/src/entries/internal.js +63 -0
- package/src/entries/motion.js +13 -0
- package/src/entries/ui.js +13 -0
- package/src/env-development.js +12 -0
- package/src/env.js +33 -0
- package/src/errors.js +1144 -168
- package/src/form.js +723 -225
- package/src/guardrails.js +38 -126
- package/src/h.js +227 -152
- package/src/head.js +189 -19
- package/src/helpers.js +47 -75
- package/src/hooks.js +233 -248
- package/src/hot.js +316 -0
- package/src/hydration-data.js +859 -16
- package/src/import-changes.js +156 -0
- package/src/index.js +38 -188
- package/src/jsx-dev-runtime.js +7 -14
- package/src/jsx-runtime.js +25 -9
- package/src/live.js +80 -0
- package/src/markup-rules.js +387 -0
- package/src/reactive.js +4400 -862
- package/src/render.js +6502 -2570
- package/src/scheduler.js +56 -21
- package/src/selector.js +31 -0
- package/src/server-context.js +252 -22
- package/src/skeleton.js +22 -12
- package/src/store.js +17 -31
- package/src/testing.js +389 -63
- package/src/vnode-adoption.js +48 -0
- package/src/vnode-renderer.js +114 -0
- package/testing.d.ts +81 -1
- package/ui.d.ts +20 -0
- package/dist/chunk-6YOUZ6T4.min.js +0 -1
- package/dist/chunk-FN6HXME3.min.js +0 -11
- package/dist/chunk-VKZY7JPN.min.js +0 -1
- package/src/agent-context.js +0 -127
- package/src/warnings.js +0 -193
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
// src/hooks.js
|
|
2
|
+
import { signal, computed, effect, untrack, getOwner, onCleanup as onOwnerCleanup, _userEffect, _currentComponent, _contextOf, _devAsyncWork, _devCallSite, _devStackLoc, _asyncComputed, _asyncStatus, _asyncError, _refresh, _setAsyncValue, _installSeedOps } from "./reactive.js";
|
|
3
|
+
import { getServerContext, isServerRender } from "./server-context.js";
|
|
4
|
+
import { getLoaderData as _getLoaderData, getResource as _getResource, getResourceError as _getResourceError, _seedFor, _errorFromRecord } from "./hydration-data.js";
|
|
5
|
+
import { computed as asyncComputed } from "./async.js";
|
|
6
|
+
import { _enableSuspense } from "./render.js";
|
|
7
|
+
import { _isLiveProp } from "./dom.js";
|
|
8
|
+
import { report, _thrownMessage } from "./diagnostics.js";
|
|
9
|
+
function useLoaderData() {
|
|
10
|
+
if (isServerRender()) {
|
|
11
|
+
const ctx = getServerContext();
|
|
12
|
+
return ctx ? ctx.loaderData : void 0;
|
|
13
|
+
}
|
|
14
|
+
return _getLoaderData();
|
|
15
|
+
}
|
|
16
|
+
function getCtx(hookName) {
|
|
17
|
+
const ctx = _currentComponent();
|
|
18
|
+
if (!ctx) {
|
|
19
|
+
throw Object.assign(new Error((process.env.NODE_ENV !== "production") ? _thrownMessage("ERR_HOOK_OUTSIDE_COMPONENT", `${hookName || "Hook"}() can only be called inside a component function. Did you call it outside of a component or in an async callback? If you need reactive state outside a component, use signal() directly.`) : `[what] ${hookName || "Hook"}() can only be called inside a component function.`), { code: "ERR_HOOK_OUTSIDE_COMPONENT" });
|
|
20
|
+
}
|
|
21
|
+
return ctx;
|
|
22
|
+
}
|
|
23
|
+
function getHook(ctx) {
|
|
24
|
+
if (ctx.hooks === null) ctx.hooks = [];
|
|
25
|
+
const index = ctx.hookIndex++;
|
|
26
|
+
return { index, exists: index < ctx.hooks.length };
|
|
27
|
+
}
|
|
28
|
+
function useState(initial, debugName) {
|
|
29
|
+
const ctx = getCtx("useState");
|
|
30
|
+
const { index, exists } = getHook(ctx);
|
|
31
|
+
if (!exists) {
|
|
32
|
+
const s2 = signal(typeof initial === "function" ? initial() : initial, debugName);
|
|
33
|
+
ctx.hooks[index] = s2;
|
|
34
|
+
}
|
|
35
|
+
const s = ctx.hooks[index];
|
|
36
|
+
return [s, s.set];
|
|
37
|
+
}
|
|
38
|
+
function useSignal(initial, debugName) {
|
|
39
|
+
const ctx = getCtx("useSignal");
|
|
40
|
+
const { index, exists } = getHook(ctx);
|
|
41
|
+
if (!exists) {
|
|
42
|
+
ctx.hooks[index] = signal(typeof initial === "function" ? initial() : initial, debugName);
|
|
43
|
+
}
|
|
44
|
+
return ctx.hooks[index];
|
|
45
|
+
}
|
|
46
|
+
function useComputed(fn) {
|
|
47
|
+
const ctx = getCtx("useComputed");
|
|
48
|
+
const { index, exists } = getHook(ctx);
|
|
49
|
+
if (!exists) {
|
|
50
|
+
ctx.hooks[index] = asyncComputed(fn);
|
|
51
|
+
}
|
|
52
|
+
return ctx.hooks[index];
|
|
53
|
+
}
|
|
54
|
+
function reportPlainDeps(deps, ctx, at) {
|
|
55
|
+
const subject = { kind: "component", name: ctx.Component?.displayName || ctx.Component?.name || "anonymous" };
|
|
56
|
+
let loc;
|
|
57
|
+
const where = () => loc === void 0 ? loc = at ?? _devStackLoc(useEffect) : loc;
|
|
58
|
+
for (let i = 0; i < deps.length; i++) {
|
|
59
|
+
const dep = deps[i];
|
|
60
|
+
if (dep == null) continue;
|
|
61
|
+
if (typeof dep !== "function") report("ERR_EFFECT_DEP_NOT_FUNCTION", { data: { index: i }, subject: { ...subject, id: `${subject.name}#${i}` }, loc: where() });
|
|
62
|
+
else if (!dep._signal && dep.length === 0) report("ERR_EFFECT_DEP_NOT_SIGNAL", { data: { index: i }, subject: { ...subject, id: `${subject.name}#${i}` }, loc: where() });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function devLoc(meta) {
|
|
66
|
+
const at = typeof meta === "string" ? meta.indexOf("@") : -1;
|
|
67
|
+
return at === -1 ? null : meta.slice(at + 1);
|
|
68
|
+
}
|
|
69
|
+
function cleanupOf(result, ctx, mounting) {
|
|
70
|
+
if (typeof result === "function") return result;
|
|
71
|
+
if ((process.env.NODE_ENV !== "production") && result != null && typeof result.then === "function") {
|
|
72
|
+
_devAsyncWork(ctx, result);
|
|
73
|
+
if (!mounting) report("ERR_ASYNC_EFFECT", { data: { effectName: "useEffect" } });
|
|
74
|
+
}
|
|
75
|
+
return void 0;
|
|
76
|
+
}
|
|
77
|
+
function useEffect(fn, deps, debugName) {
|
|
78
|
+
const ctx = getCtx("useEffect");
|
|
79
|
+
getHook(ctx);
|
|
80
|
+
const at = (process.env.NODE_ENV !== "production") ? devLoc(debugName) : null;
|
|
81
|
+
if ((process.env.NODE_ENV !== "production") && Array.isArray(deps)) reportPlainDeps(deps, ctx, at);
|
|
82
|
+
if (isServerRender()) return;
|
|
83
|
+
let run;
|
|
84
|
+
if (deps === void 0) {
|
|
85
|
+
run = () => cleanupOf(fn(), ctx);
|
|
86
|
+
} else if (deps.length === 0) {
|
|
87
|
+
run = () => cleanupOf(untrack(fn), ctx);
|
|
88
|
+
} else {
|
|
89
|
+
run = () => {
|
|
90
|
+
for (let i = 0; i < deps.length; i++) {
|
|
91
|
+
const dep = deps[i];
|
|
92
|
+
if (typeof dep === "function" && dep._signal) dep();
|
|
93
|
+
}
|
|
94
|
+
return cleanupOf(untrack(fn), ctx);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if ((process.env.NODE_ENV !== "production")) {
|
|
98
|
+
run.inner = fn;
|
|
99
|
+
const name = fn.name || "useEffect";
|
|
100
|
+
_userEffect(run, at !== null ? `${name}@${at}` : _devCallSite(name, useEffect));
|
|
101
|
+
} else {
|
|
102
|
+
_userEffect(run);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function useMemo(fn, _deps) {
|
|
106
|
+
const ctx = getCtx("useMemo");
|
|
107
|
+
const { index, exists } = getHook(ctx);
|
|
108
|
+
if (!exists) {
|
|
109
|
+
ctx.hooks[index] = { computed: computed((process.env.NODE_ENV !== "production") ? devMemo(fn) : fn) };
|
|
110
|
+
}
|
|
111
|
+
return ctx.hooks[index].computed;
|
|
112
|
+
}
|
|
113
|
+
function devMemo(fn) {
|
|
114
|
+
const memo = () => {
|
|
115
|
+
const value = fn();
|
|
116
|
+
if (value != null && typeof value.then === "function") report("ERR_ASYNC_MEMO");
|
|
117
|
+
return value;
|
|
118
|
+
};
|
|
119
|
+
memo.inner = fn;
|
|
120
|
+
return memo;
|
|
121
|
+
}
|
|
122
|
+
function useCallback(fn, _deps) {
|
|
123
|
+
const ctx = getCtx("useCallback");
|
|
124
|
+
const { index, exists } = getHook(ctx);
|
|
125
|
+
if (!exists) {
|
|
126
|
+
ctx.hooks[index] = { callback: fn };
|
|
127
|
+
}
|
|
128
|
+
return ctx.hooks[index].callback;
|
|
129
|
+
}
|
|
130
|
+
function useRef(initial) {
|
|
131
|
+
const ctx = getCtx("useRef");
|
|
132
|
+
const { index, exists } = getHook(ctx);
|
|
133
|
+
if (!exists) {
|
|
134
|
+
ctx.hooks[index] = { current: initial };
|
|
135
|
+
}
|
|
136
|
+
return ctx.hooks[index];
|
|
137
|
+
}
|
|
138
|
+
function useContext(context) {
|
|
139
|
+
const map = _contextOf(context);
|
|
140
|
+
if (map !== null) {
|
|
141
|
+
const val = map.get(context);
|
|
142
|
+
return val && val._signal ? val() : val;
|
|
143
|
+
}
|
|
144
|
+
if ((process.env.NODE_ENV !== "production")) {
|
|
145
|
+
if (!_currentComponent()) {
|
|
146
|
+
report("ERR_HOOK_OUTSIDE_COMPONENT", { data: { hookName: "useContext", context: context?.displayName || "Context" } });
|
|
147
|
+
} else if (!context._hasDefault) {
|
|
148
|
+
report("ERR_CONTEXT_NOT_PROVIDED", { data: { context: context.displayName || "Context" } });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return context._defaultValue;
|
|
152
|
+
}
|
|
153
|
+
function createContext(defaultValue) {
|
|
154
|
+
function context(props) {
|
|
155
|
+
const ctx = getCtx("Context.Provider");
|
|
156
|
+
const values = ctx.context || (ctx.context = /* @__PURE__ */ new Map());
|
|
157
|
+
const current = values.get(context);
|
|
158
|
+
if (current !== void 0) provide(current, props.value);
|
|
159
|
+
else {
|
|
160
|
+
const held = signal(props.value);
|
|
161
|
+
values.set(context, held);
|
|
162
|
+
if (_isLiveProp(props, "value")) effect(() => provide(held, props.value), (process.env.NODE_ENV !== "production") ? { name: "context value" } : void 0);
|
|
163
|
+
}
|
|
164
|
+
return props.children;
|
|
165
|
+
}
|
|
166
|
+
context._defaultValue = defaultValue;
|
|
167
|
+
context._hasDefault = arguments.length > 0;
|
|
168
|
+
context.Provider = context;
|
|
169
|
+
context.Consumer = ({ children }) => {
|
|
170
|
+
const value = useContext(context);
|
|
171
|
+
return typeof children === "function" ? children(value) : children;
|
|
172
|
+
};
|
|
173
|
+
context._deferChildren = true;
|
|
174
|
+
return context;
|
|
175
|
+
}
|
|
176
|
+
function provide(held, value) {
|
|
177
|
+
held.set(typeof value === "function" ? () => value : value);
|
|
178
|
+
}
|
|
179
|
+
function useReducer(reducer, initialState, init) {
|
|
180
|
+
const ctx = getCtx("useReducer");
|
|
181
|
+
const { index, exists } = getHook(ctx);
|
|
182
|
+
if (!exists) {
|
|
183
|
+
const initial = init ? init(initialState) : initialState;
|
|
184
|
+
const s = signal(initial);
|
|
185
|
+
const dispatch = (action) => {
|
|
186
|
+
s.set((prev) => reducer(prev, action));
|
|
187
|
+
};
|
|
188
|
+
ctx.hooks[index] = { signal: s, dispatch };
|
|
189
|
+
}
|
|
190
|
+
const hook = ctx.hooks[index];
|
|
191
|
+
return [hook.signal, hook.dispatch];
|
|
192
|
+
}
|
|
193
|
+
function onMount(fn) {
|
|
194
|
+
const ctx = getCtx("onMount");
|
|
195
|
+
if (isServerRender()) return;
|
|
196
|
+
_userEffect(() => {
|
|
197
|
+
cleanupOf(untrack(fn), ctx, true);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
function onCleanup(fn) {
|
|
201
|
+
if (getOwner() !== null) onOwnerCleanup(fn);
|
|
202
|
+
else if ((process.env.NODE_ENV !== "production")) report("ERR_CLEANUP_WITHOUT_OWNER");
|
|
203
|
+
}
|
|
204
|
+
function createResource(fetcher, options = {}) {
|
|
205
|
+
_enableSuspense();
|
|
206
|
+
_installSeedOps();
|
|
207
|
+
let source = options.source;
|
|
208
|
+
const ctx = isServerRender() ? getServerContext() : null;
|
|
209
|
+
const keyed = options.key != null;
|
|
210
|
+
let seed;
|
|
211
|
+
if (ctx !== null) {
|
|
212
|
+
seed = _seedFor(options.key, false);
|
|
213
|
+
} else if (keyed) {
|
|
214
|
+
const value = options.initialValue != null ? options.initialValue : _getResource(options.key);
|
|
215
|
+
const record = value === void 0 ? _getResourceError(options.key) : void 0;
|
|
216
|
+
seed = value !== void 0 ? { value, track: false } : record ? { error: _errorFromRecord(record), track: false } : null;
|
|
217
|
+
} else {
|
|
218
|
+
seed = _seedFor(null, false);
|
|
219
|
+
if (options.initialValue != null) seed = { value: options.initialValue, track: false };
|
|
220
|
+
}
|
|
221
|
+
const data = _asyncComputed(({ signal: signal2 }) => untrack(() => ctx !== null ? fetcher(source ?? true, { signal: ctx.signal, request: ctx.request }) : fetcher(source, { signal: signal2 })), seed);
|
|
222
|
+
if (ctx !== null && _asyncStatus(data) === "unresolved") data();
|
|
223
|
+
const loading = () => {
|
|
224
|
+
const status = _asyncStatus(data);
|
|
225
|
+
return status === "unresolved" || status === "pending";
|
|
226
|
+
};
|
|
227
|
+
const error = () => {
|
|
228
|
+
_asyncStatus(data);
|
|
229
|
+
return _asyncError(data);
|
|
230
|
+
};
|
|
231
|
+
const refetch = (next) => {
|
|
232
|
+
source = next;
|
|
233
|
+
return _refresh(data).then(() => void 0, () => void 0);
|
|
234
|
+
};
|
|
235
|
+
const mutate = (value) => {
|
|
236
|
+
_setAsyncValue(data, typeof value === "function" ? value(data.peek()) : value);
|
|
237
|
+
};
|
|
238
|
+
return [data, { loading, error, refetch, mutate }];
|
|
239
|
+
}
|
|
240
|
+
export {
|
|
241
|
+
createContext,
|
|
242
|
+
createResource,
|
|
243
|
+
onCleanup,
|
|
244
|
+
onMount,
|
|
245
|
+
useCallback,
|
|
246
|
+
useComputed,
|
|
247
|
+
useContext,
|
|
248
|
+
useEffect,
|
|
249
|
+
useLoaderData,
|
|
250
|
+
useMemo,
|
|
251
|
+
useReducer,
|
|
252
|
+
useRef,
|
|
253
|
+
useSignal,
|
|
254
|
+
useState
|
|
255
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// src/hooks.js
|
|
2
|
+
import { signal as _, computed as R, effect as v, untrack as d, getOwner as D, onCleanup as N, _userEffect as y, _currentComponent as S, _contextOf as T, _devStackLoc as Y, _asyncComputed as V, _asyncStatus as p, _asyncError as b, _refresh as M, _setAsyncValue as P, _installSeedOps as w } from "./reactive.min.js";
|
|
3
|
+
import { getServerContext as O, isServerRender as x } from "./server-context.min.js";
|
|
4
|
+
import { getLoaderData as A, getResource as F, getResourceError as I, _seedFor as g, _errorFromRecord as L } from "./hydration-data.min.js";
|
|
5
|
+
import { computed as $ } from "./async.min.js";
|
|
6
|
+
import { _enableSuspense as H } from "./render.min.js";
|
|
7
|
+
import { _isLiveProp as U } from "./dom.min.js";
|
|
8
|
+
function Q() {
|
|
9
|
+
if (x()) {
|
|
10
|
+
let t = O();
|
|
11
|
+
return t ? t.loaderData : void 0;
|
|
12
|
+
}
|
|
13
|
+
return A();
|
|
14
|
+
}
|
|
15
|
+
function i(t) {
|
|
16
|
+
let e = S();
|
|
17
|
+
if (!e)
|
|
18
|
+
throw Object.assign(new Error(`[what] ${t || "Hook"}() can only be called inside a component function.`), { code: "ERR_HOOK_OUTSIDE_COMPONENT" });
|
|
19
|
+
return e;
|
|
20
|
+
}
|
|
21
|
+
function a(t) {
|
|
22
|
+
t.hooks === null && (t.hooks = []);
|
|
23
|
+
let e = t.hookIndex++;
|
|
24
|
+
return { index: e, exists: e < t.hooks.length };
|
|
25
|
+
}
|
|
26
|
+
function Z(t, e) {
|
|
27
|
+
let n = i("useState"), { index: o, exists: u } = a(n);
|
|
28
|
+
if (!u) {
|
|
29
|
+
let r = _(typeof t == "function" ? t() : t, e);
|
|
30
|
+
n.hooks[o] = r;
|
|
31
|
+
}
|
|
32
|
+
let s = n.hooks[o];
|
|
33
|
+
return [s, s.set];
|
|
34
|
+
}
|
|
35
|
+
function ee(t, e) {
|
|
36
|
+
let n = i("useSignal"), { index: o, exists: u } = a(n);
|
|
37
|
+
return u || (n.hooks[o] = _(typeof t == "function" ? t() : t, e)), n.hooks[o];
|
|
38
|
+
}
|
|
39
|
+
function te(t) {
|
|
40
|
+
let e = i("useComputed"), { index: n, exists: o } = a(e);
|
|
41
|
+
return o || (e.hooks[n] = $(t)), e.hooks[n];
|
|
42
|
+
}
|
|
43
|
+
function l(t, e, n) {
|
|
44
|
+
if (typeof t == "function") return t;
|
|
45
|
+
}
|
|
46
|
+
function ne(t, e, n) {
|
|
47
|
+
let o = i("useEffect");
|
|
48
|
+
a(o);
|
|
49
|
+
let u = null;
|
|
50
|
+
if (x()) return;
|
|
51
|
+
let s;
|
|
52
|
+
e === void 0 ? s = () => l(t(), o) : e.length === 0 ? s = () => l(d(t), o) : s = () => {
|
|
53
|
+
for (let r = 0; r < e.length; r++) {
|
|
54
|
+
let f = e[r];
|
|
55
|
+
typeof f == "function" && f._signal && f();
|
|
56
|
+
}
|
|
57
|
+
return l(d(t), o);
|
|
58
|
+
}, y(s);
|
|
59
|
+
}
|
|
60
|
+
function oe(t, e) {
|
|
61
|
+
let n = i("useMemo"), { index: o, exists: u } = a(n);
|
|
62
|
+
return u || (n.hooks[o] = { computed: R(t) }), n.hooks[o].computed;
|
|
63
|
+
}
|
|
64
|
+
function re(t, e) {
|
|
65
|
+
let n = i("useCallback"), { index: o, exists: u } = a(n);
|
|
66
|
+
return u || (n.hooks[o] = { callback: t }), n.hooks[o].callback;
|
|
67
|
+
}
|
|
68
|
+
function se(t) {
|
|
69
|
+
let e = i("useRef"), { index: n, exists: o } = a(e);
|
|
70
|
+
return o || (e.hooks[n] = { current: t }), e.hooks[n];
|
|
71
|
+
}
|
|
72
|
+
function j(t) {
|
|
73
|
+
let e = T(t);
|
|
74
|
+
if (e !== null) {
|
|
75
|
+
let n = e.get(t);
|
|
76
|
+
return n && n._signal ? n() : n;
|
|
77
|
+
}
|
|
78
|
+
return t._defaultValue;
|
|
79
|
+
}
|
|
80
|
+
function ue(t) {
|
|
81
|
+
function e(n) {
|
|
82
|
+
let o = i("Context.Provider"), u = o.context || (o.context = /* @__PURE__ */ new Map()), s = u.get(e);
|
|
83
|
+
if (s !== void 0) C(s, n.value);
|
|
84
|
+
else {
|
|
85
|
+
let r = _(n.value);
|
|
86
|
+
u.set(e, r), U(n, "value") && v(() => C(r, n.value), void 0);
|
|
87
|
+
}
|
|
88
|
+
return n.children;
|
|
89
|
+
}
|
|
90
|
+
return e._defaultValue = t, e._hasDefault = arguments.length > 0, e.Provider = e, e.Consumer = ({ children: n }) => {
|
|
91
|
+
let o = j(e);
|
|
92
|
+
return typeof n == "function" ? n(o) : n;
|
|
93
|
+
}, e._deferChildren = !0, e;
|
|
94
|
+
}
|
|
95
|
+
function C(t, e) {
|
|
96
|
+
t.set(typeof e == "function" ? () => e : e);
|
|
97
|
+
}
|
|
98
|
+
function ce(t, e, n) {
|
|
99
|
+
let o = i("useReducer"), { index: u, exists: s } = a(o);
|
|
100
|
+
if (!s) {
|
|
101
|
+
let f = n ? n(e) : e, m = _(f), E = (k) => {
|
|
102
|
+
m.set((c) => t(c, k));
|
|
103
|
+
};
|
|
104
|
+
o.hooks[u] = { signal: m, dispatch: E };
|
|
105
|
+
}
|
|
106
|
+
let r = o.hooks[u];
|
|
107
|
+
return [r.signal, r.dispatch];
|
|
108
|
+
}
|
|
109
|
+
function ie(t) {
|
|
110
|
+
let e = i("onMount");
|
|
111
|
+
x() || y(() => {
|
|
112
|
+
l(d(t), e, !0);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function ae(t) {
|
|
116
|
+
D() !== null && N(t);
|
|
117
|
+
}
|
|
118
|
+
function fe(t, e = {}) {
|
|
119
|
+
H(), w();
|
|
120
|
+
let n = e.source, o = x() ? O() : null, u = e.key != null, s;
|
|
121
|
+
if (o !== null)
|
|
122
|
+
s = g(e.key, !1);
|
|
123
|
+
else if (u) {
|
|
124
|
+
let c = e.initialValue != null ? e.initialValue : F(e.key), h = c === void 0 ? I(e.key) : void 0;
|
|
125
|
+
s = c !== void 0 ? { value: c, track: !1 } : h ? { error: L(h), track: !1 } : null;
|
|
126
|
+
} else
|
|
127
|
+
s = g(null, !1), e.initialValue != null && (s = { value: e.initialValue, track: !1 });
|
|
128
|
+
let r = V(({ signal: c }) => d(() => o !== null ? t(n ?? !0, { signal: o.signal, request: o.request }) : t(n, { signal: c })), s);
|
|
129
|
+
return o !== null && p(r) === "unresolved" && r(), [r, { loading: () => {
|
|
130
|
+
let c = p(r);
|
|
131
|
+
return c === "unresolved" || c === "pending";
|
|
132
|
+
}, error: () => (p(r), b(r)), refetch: (c) => (n = c, M(r).then(() => {
|
|
133
|
+
}, () => {
|
|
134
|
+
})), mutate: (c) => {
|
|
135
|
+
P(r, typeof c == "function" ? c(r.peek()) : c);
|
|
136
|
+
} }];
|
|
137
|
+
}
|
|
138
|
+
export {
|
|
139
|
+
ue as createContext,
|
|
140
|
+
fe as createResource,
|
|
141
|
+
ae as onCleanup,
|
|
142
|
+
ie as onMount,
|
|
143
|
+
re as useCallback,
|
|
144
|
+
te as useComputed,
|
|
145
|
+
j as useContext,
|
|
146
|
+
ne as useEffect,
|
|
147
|
+
Q as useLoaderData,
|
|
148
|
+
oe as useMemo,
|
|
149
|
+
ce as useReducer,
|
|
150
|
+
se as useRef,
|
|
151
|
+
ee as useSignal,
|
|
152
|
+
Z as useState
|
|
153
|
+
};
|
package/dist/hot.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// src/hot.js
|
|
2
|
+
import { __devtools } from "./reactive.js";
|
|
3
|
+
import { _installHot, _hotSwap, _hotState } from "./render.js";
|
|
4
|
+
import { report, recordObservation } from "./diagnostics.js";
|
|
5
|
+
var HOT = /* @__PURE__ */ Symbol("what.hot");
|
|
6
|
+
var changed = /* @__PURE__ */ new Set();
|
|
7
|
+
var updated = /* @__PURE__ */ new Set();
|
|
8
|
+
var seen = /* @__PURE__ */ new Map();
|
|
9
|
+
var installed = false;
|
|
10
|
+
function recordOf(Component) {
|
|
11
|
+
return Component[HOT];
|
|
12
|
+
}
|
|
13
|
+
var identityOf = null;
|
|
14
|
+
function stable(value) {
|
|
15
|
+
if (typeof value !== "function") return value;
|
|
16
|
+
if (value[HOT] !== void 0) return value[HOT];
|
|
17
|
+
const known = identityOf !== null ? identityOf(value) : void 0;
|
|
18
|
+
return known === void 0 ? value : known;
|
|
19
|
+
}
|
|
20
|
+
function _hotIdentity(of) {
|
|
21
|
+
if ((process.env.NODE_ENV !== "production")) identityOf = of;
|
|
22
|
+
}
|
|
23
|
+
function sameDeps(a, b) {
|
|
24
|
+
if (a === null || b === null || a.length !== b.length) return false;
|
|
25
|
+
for (let i = 0; i < a.length; i++) if (!Object.is(a[i], b[i])) return false;
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
function readDeps(deps) {
|
|
29
|
+
try {
|
|
30
|
+
return deps().map(stable);
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
var INERT = {
|
|
36
|
+
accept() {
|
|
37
|
+
},
|
|
38
|
+
component: (_name, fn) => fn,
|
|
39
|
+
state: (_site, init) => init(),
|
|
40
|
+
fn() {
|
|
41
|
+
},
|
|
42
|
+
keep: (_name, _sig, _deps, init) => init(),
|
|
43
|
+
done() {
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
function _$hot(hot, accepts, file) {
|
|
47
|
+
return (process.env.NODE_ENV !== "production") && hot != null ? hotModule(hot, accepts, file) : INERT;
|
|
48
|
+
}
|
|
49
|
+
function hotModule(hot, accepts, file) {
|
|
50
|
+
if (!installed) {
|
|
51
|
+
installed = true;
|
|
52
|
+
_installHot(recordOf);
|
|
53
|
+
}
|
|
54
|
+
const listen = (event, fn) => {
|
|
55
|
+
if (!seen.has(event)) seen.set(event, /* @__PURE__ */ new WeakSet());
|
|
56
|
+
const handled = (
|
|
57
|
+
/** @type {WeakSet<object>} */
|
|
58
|
+
seen.get(event)
|
|
59
|
+
);
|
|
60
|
+
hot.on(event, (payload) => {
|
|
61
|
+
if (payload !== null && typeof payload === "object") {
|
|
62
|
+
if (handled.has(payload)) return;
|
|
63
|
+
handled.add(payload);
|
|
64
|
+
}
|
|
65
|
+
fn(payload);
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
listen("vite:beforeUpdate", () => updated.clear());
|
|
69
|
+
listen("vite:afterUpdate", flush);
|
|
70
|
+
listen("vite:error", (payload) => compileFailed(payload && payload.err));
|
|
71
|
+
const prev = hot.data.what;
|
|
72
|
+
const next = { records: /* @__PURE__ */ new Map(), values: /* @__PURE__ */ new Map(), fns: /* @__PURE__ */ new Map(), verdict: "accept" };
|
|
73
|
+
const registered = [];
|
|
74
|
+
return {
|
|
75
|
+
/** The callback of `import.meta.hot.accept()`: the verdict of the version that ran. */
|
|
76
|
+
accept(module) {
|
|
77
|
+
if (module === void 0) return;
|
|
78
|
+
const verdict = hot.data.what ? hot.data.what.verdict : "accept";
|
|
79
|
+
if (verdict === "invalidate") hot.invalidate("an export changed; its importers update");
|
|
80
|
+
},
|
|
81
|
+
/**
|
|
82
|
+
* `key`: the name it is exported under, else its own. `state`: its state
|
|
83
|
+
* signature; null (or left out) keeps none.
|
|
84
|
+
*/
|
|
85
|
+
component(key, fn, sig, deps, state = null) {
|
|
86
|
+
let record = prev ? prev.records.get(key) : void 0;
|
|
87
|
+
if (record === void 0) record = { name: fn.name || key, file, impl: fn, sig, deps: null, state, slots: /* @__PURE__ */ new Set() };
|
|
88
|
+
try {
|
|
89
|
+
Object.defineProperty(fn, HOT, { value: record, configurable: true });
|
|
90
|
+
} catch {
|
|
91
|
+
}
|
|
92
|
+
if (fn.name === "") Object.defineProperty(fn, "name", { value: key, configurable: true });
|
|
93
|
+
next.records.set(key, record);
|
|
94
|
+
registered.push({ record, fn, sig, deps, state });
|
|
95
|
+
return fn;
|
|
96
|
+
},
|
|
97
|
+
state: _hotState,
|
|
98
|
+
fn(name, sig, deps) {
|
|
99
|
+
next.fns.set(name, { sig, deps, read: (
|
|
100
|
+
/** @type {any[] | null} */
|
|
101
|
+
null
|
|
102
|
+
) });
|
|
103
|
+
},
|
|
104
|
+
keep(name, sig, deps, init) {
|
|
105
|
+
const was = prev ? prev.values.get(name) : void 0;
|
|
106
|
+
const read = readDeps(deps);
|
|
107
|
+
if (was !== void 0 && sig !== null && was.sig === sig && read !== null && sameDeps(was.deps, read)) {
|
|
108
|
+
next.values.set(name, { sig, deps: read, value: was.value, same: true });
|
|
109
|
+
return was.value;
|
|
110
|
+
}
|
|
111
|
+
let value;
|
|
112
|
+
try {
|
|
113
|
+
value = init();
|
|
114
|
+
} catch (error) {
|
|
115
|
+
runFailed(error, file, `running ${name}'s initializer`);
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
next.values.set(name, { sig, deps: read, value, same: was === void 0 });
|
|
119
|
+
return value;
|
|
120
|
+
},
|
|
121
|
+
/**
|
|
122
|
+
* The module ran to its end: decide each component's update, and what
|
|
123
|
+
* the old version's accept callback does. `exported` names the module's
|
|
124
|
+
* own exports that are not components.
|
|
125
|
+
* @param {string[]} exported
|
|
126
|
+
*/
|
|
127
|
+
done(exported) {
|
|
128
|
+
for (const { record, fn, sig, deps, state } of registered) {
|
|
129
|
+
const read = readDeps(deps);
|
|
130
|
+
if (record.impl === fn) {
|
|
131
|
+
record.deps = read;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (sig !== null && sig === record.sig && read !== null && sameDeps(read, record.deps)) continue;
|
|
135
|
+
record.was = { impl: record.impl, name: record.name, sig: record.sig, deps: record.deps, state: record.state };
|
|
136
|
+
record.impl = fn;
|
|
137
|
+
record.name = fn.name;
|
|
138
|
+
record.sig = sig;
|
|
139
|
+
record.deps = read;
|
|
140
|
+
record.state = state;
|
|
141
|
+
changed.add(record);
|
|
142
|
+
}
|
|
143
|
+
for (const entry of next.fns.values()) entry.read = readDeps(entry.deps);
|
|
144
|
+
if (prev) {
|
|
145
|
+
for (const name of exported) {
|
|
146
|
+
const value = next.values.get(name);
|
|
147
|
+
if (value !== void 0 ? !value.same : fnChanged(prev.fns.get(name), next.fns.get(name))) next.verdict = "invalidate";
|
|
148
|
+
}
|
|
149
|
+
if (!accepts) next.verdict = "invalidate";
|
|
150
|
+
}
|
|
151
|
+
hot.data.what = next;
|
|
152
|
+
updated.add(file);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function fnChanged(was, now) {
|
|
157
|
+
if (was === void 0) return false;
|
|
158
|
+
if (now === void 0 || now.sig === null || was.sig !== now.sig) return true;
|
|
159
|
+
return was.read === null || now.read === null || !sameDeps(was.read, now.read);
|
|
160
|
+
}
|
|
161
|
+
function flush(payload) {
|
|
162
|
+
if (changed.size === 0 && updated.size === 0) return;
|
|
163
|
+
const records = [...changed];
|
|
164
|
+
changed.clear();
|
|
165
|
+
const files = payload && Array.isArray(payload.updates) ? payload.updates.map((u) => u.path) : [...updated];
|
|
166
|
+
updated.clear();
|
|
167
|
+
const started = performance.now();
|
|
168
|
+
const { swapped, kept, failed } = _hotSwap(records);
|
|
169
|
+
const ms = Math.round((performance.now() - started) * 10) / 10;
|
|
170
|
+
for (const { record, error } of failed) {
|
|
171
|
+
Object.assign(record, record.was);
|
|
172
|
+
runFailed(error, record.file, `rendering <${record.name}>`);
|
|
173
|
+
}
|
|
174
|
+
if (__devtools) {
|
|
175
|
+
recordObservation(__devtools, "hmr:update", null, {
|
|
176
|
+
files,
|
|
177
|
+
components: records.map((r) => r.name),
|
|
178
|
+
instances: swapped,
|
|
179
|
+
kept,
|
|
180
|
+
ms,
|
|
181
|
+
...failed.length ? { failed: failed.map(({ record, error }) => ({ component: record.name, message: messageOf(error) })) } : {}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function _hotUpdated(record) {
|
|
186
|
+
if ((process.env.NODE_ENV !== "production") && __devtools) recordObservation(__devtools, "hmr:update", null, { kind: "refresh", ...record });
|
|
187
|
+
}
|
|
188
|
+
function messageOf(error) {
|
|
189
|
+
return error instanceof Error ? error.message : String(error);
|
|
190
|
+
}
|
|
191
|
+
function runFailed(error, file, phase) {
|
|
192
|
+
report("ERR_HOT_UPDATE_FAILED", { data: { file, phase, message: messageOf(error) }, subject: { kind: "module", name: file, id: file } });
|
|
193
|
+
console.error(`[what] The edit to ${file} was not applied: ${phase} threw.`, error);
|
|
194
|
+
const Overlay = typeof customElements !== "undefined" ? customElements.get("vite-error-overlay") : void 0;
|
|
195
|
+
if (Overlay === void 0) return;
|
|
196
|
+
for (const open of document.querySelectorAll("vite-error-overlay")) open.close();
|
|
197
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
198
|
+
document.body.appendChild(new Overlay({
|
|
199
|
+
message: `${phase} threw: ${err.message}
|
|
200
|
+
The page keeps running the code it had. Save a fix to apply it in place.`,
|
|
201
|
+
stack: err.stack || "",
|
|
202
|
+
id: file,
|
|
203
|
+
plugin: "what-hot"
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
206
|
+
function compileFailed(err) {
|
|
207
|
+
if (err == null) return;
|
|
208
|
+
const file = err.id || err.loc?.file || "";
|
|
209
|
+
report("ERR_HOT_UPDATE_FAILED", { data: { file, phase: "compiling it", message: String(err.message || "").split("\n")[0] }, subject: { kind: "module", name: file, id: file } });
|
|
210
|
+
}
|
|
211
|
+
export {
|
|
212
|
+
_$hot,
|
|
213
|
+
_hotIdentity,
|
|
214
|
+
_hotUpdated
|
|
215
|
+
};
|
package/dist/hot.min.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/hot.js
|
|
2
|
+
function s(e) {
|
|
3
|
+
}
|
|
4
|
+
var i = {
|
|
5
|
+
accept() {
|
|
6
|
+
},
|
|
7
|
+
component: (e, t) => t,
|
|
8
|
+
state: (e, t) => t(),
|
|
9
|
+
fn() {
|
|
10
|
+
},
|
|
11
|
+
keep: (e, t, n, r) => r(),
|
|
12
|
+
done() {
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
function o(e, t, n) {
|
|
16
|
+
return i;
|
|
17
|
+
}
|
|
18
|
+
function a(e) {
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
o as _$hot,
|
|
22
|
+
s as _hotIdentity,
|
|
23
|
+
a as _hotUpdated
|
|
24
|
+
};
|