@reckona/mreact-compat 0.0.1
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 +32 -0
- package/dist/class-component.d.ts +48 -0
- package/dist/class-component.d.ts.map +1 -0
- package/dist/class-component.js +186 -0
- package/dist/class-component.js.map +1 -0
- package/dist/context.d.ts +31 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +83 -0
- package/dist/context.js.map +1 -0
- package/dist/devtools.d.ts +5 -0
- package/dist/devtools.d.ts.map +1 -0
- package/dist/devtools.js +839 -0
- package/dist/devtools.js.map +1 -0
- package/dist/dom-children.d.ts +3 -0
- package/dist/dom-children.d.ts.map +1 -0
- package/dist/dom-children.js +23 -0
- package/dist/dom-children.js.map +1 -0
- package/dist/dom-props.d.ts +4 -0
- package/dist/dom-props.d.ts.map +1 -0
- package/dist/dom-props.js +266 -0
- package/dist/dom-props.js.map +1 -0
- package/dist/element.d.ts +94 -0
- package/dist/element.d.ts.map +1 -0
- package/dist/element.js +160 -0
- package/dist/element.js.map +1 -0
- package/dist/event-listeners.d.ts +12 -0
- package/dist/event-listeners.d.ts.map +1 -0
- package/dist/event-listeners.js +11 -0
- package/dist/event-listeners.js.map +1 -0
- package/dist/event-replay.d.ts +18 -0
- package/dist/event-replay.d.ts.map +1 -0
- package/dist/event-replay.js +94 -0
- package/dist/event-replay.js.map +1 -0
- package/dist/event-types.d.ts +19 -0
- package/dist/event-types.d.ts.map +1 -0
- package/dist/event-types.js +2 -0
- package/dist/event-types.js.map +1 -0
- package/dist/events.d.ts +6 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +306 -0
- package/dist/events.js.map +1 -0
- package/dist/fiber-child.d.ts +4 -0
- package/dist/fiber-child.d.ts.map +1 -0
- package/dist/fiber-child.js +262 -0
- package/dist/fiber-child.js.map +1 -0
- package/dist/fiber-commit.d.ts +4 -0
- package/dist/fiber-commit.d.ts.map +1 -0
- package/dist/fiber-commit.js +54 -0
- package/dist/fiber-commit.js.map +1 -0
- package/dist/fiber-flags.d.ts +15 -0
- package/dist/fiber-flags.d.ts.map +1 -0
- package/dist/fiber-flags.js +18 -0
- package/dist/fiber-flags.js.map +1 -0
- package/dist/fiber-host.d.ts +16 -0
- package/dist/fiber-host.d.ts.map +1 -0
- package/dist/fiber-host.js +892 -0
- package/dist/fiber-host.js.map +1 -0
- package/dist/fiber-lanes.d.ts +30 -0
- package/dist/fiber-lanes.d.ts.map +1 -0
- package/dist/fiber-lanes.js +71 -0
- package/dist/fiber-lanes.js.map +1 -0
- package/dist/fiber-reconciler.d.ts +8 -0
- package/dist/fiber-reconciler.d.ts.map +1 -0
- package/dist/fiber-reconciler.js +385 -0
- package/dist/fiber-reconciler.js.map +1 -0
- package/dist/fiber-scheduler.d.ts +37 -0
- package/dist/fiber-scheduler.d.ts.map +1 -0
- package/dist/fiber-scheduler.js +307 -0
- package/dist/fiber-scheduler.js.map +1 -0
- package/dist/fiber-work-loop.d.ts +21 -0
- package/dist/fiber-work-loop.d.ts.map +1 -0
- package/dist/fiber-work-loop.js +116 -0
- package/dist/fiber-work-loop.js.map +1 -0
- package/dist/fiber.d.ts +50 -0
- package/dist/fiber.d.ts.map +1 -0
- package/dist/fiber.js +73 -0
- package/dist/fiber.js.map +1 -0
- package/dist/flight-decoder.d.ts +8 -0
- package/dist/flight-decoder.d.ts.map +1 -0
- package/dist/flight-decoder.js +132 -0
- package/dist/flight-decoder.js.map +1 -0
- package/dist/flight-element-builder.d.ts +6 -0
- package/dist/flight-element-builder.d.ts.map +1 -0
- package/dist/flight-element-builder.js +56 -0
- package/dist/flight-element-builder.js.map +1 -0
- package/dist/flight-parser.d.ts +3 -0
- package/dist/flight-parser.d.ts.map +1 -0
- package/dist/flight-parser.js +508 -0
- package/dist/flight-parser.js.map +1 -0
- package/dist/flight-protocol.d.ts +11 -0
- package/dist/flight-protocol.d.ts.map +1 -0
- package/dist/flight-protocol.js +61 -0
- package/dist/flight-protocol.js.map +1 -0
- package/dist/flight-types.d.ts +98 -0
- package/dist/flight-types.d.ts.map +1 -0
- package/dist/flight-types.js +2 -0
- package/dist/flight-types.js.map +1 -0
- package/dist/flight.d.ts +26 -0
- package/dist/flight.d.ts.map +1 -0
- package/dist/flight.js +66 -0
- package/dist/flight.js.map +1 -0
- package/dist/hooks.d.ts +214 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +1296 -0
- package/dist/hooks.js.map +1 -0
- package/dist/hydration.d.ts +34 -0
- package/dist/hydration.d.ts.map +1 -0
- package/dist/hydration.js +164 -0
- package/dist/hydration.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +2 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +2 -0
- package/dist/internal.js.map +1 -0
- package/dist/jsx-dev-runtime.d.ts +19 -0
- package/dist/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/jsx-dev-runtime.js +6 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-runtime.d.ts +24 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +21 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/prop-comparison.d.ts +6 -0
- package/dist/prop-comparison.d.ts.map +1 -0
- package/dist/prop-comparison.js +28 -0
- package/dist/prop-comparison.js.map +1 -0
- package/dist/reconcile-types.d.ts +10 -0
- package/dist/reconcile-types.d.ts.map +1 -0
- package/dist/reconcile-types.js +2 -0
- package/dist/reconcile-types.js.map +1 -0
- package/dist/reconciler.d.ts +7 -0
- package/dist/reconciler.d.ts.map +1 -0
- package/dist/reconciler.js +318 -0
- package/dist/reconciler.js.map +1 -0
- package/dist/render.d.ts +7 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +4 -0
- package/dist/render.js.map +1 -0
- package/dist/root.d.ts +44 -0
- package/dist/root.d.ts.map +1 -0
- package/dist/root.js +278 -0
- package/dist/root.js.map +1 -0
- package/dist/scheduler.d.ts +30 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +90 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/suspense.d.ts +8 -0
- package/dist/suspense.d.ts.map +1 -0
- package/dist/suspense.js +164 -0
- package/dist/suspense.js.map +1 -0
- package/dist/thenable.d.ts +2 -0
- package/dist/thenable.d.ts.map +1 -0
- package/dist/thenable.js +6 -0
- package/dist/thenable.js.map +1 -0
- package/dist/url-safety.d.ts +2 -0
- package/dist/url-safety.d.ts.map +1 -0
- package/dist/url-safety.js +2 -0
- package/dist/url-safety.js.map +1 -0
- package/package.json +65 -0
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,1296 @@
|
|
|
1
|
+
import { scheduleCallback } from "./fiber-scheduler.js";
|
|
2
|
+
import { Activity, Fragment, FORWARD_REF_TYPE, MEMO_TYPE, Profiler, isReactCompatElement, } from "./element.js";
|
|
3
|
+
import { isReactCompatContext, isReactCompatConsumer, isReactCompatProvider, renderWithContextProvider, useContext, } from "./context.js";
|
|
4
|
+
import { isThenable } from "./thenable.js";
|
|
5
|
+
import { isDangerousHtmlAttribute, isDangerousHtmlOptIn } from "./url-safety.js";
|
|
6
|
+
import { escapeHtmlAttribute as escapeHtml } from "@reckona/mreact-shared/html-escape";
|
|
7
|
+
let currentRuntime;
|
|
8
|
+
let currentInstance;
|
|
9
|
+
let currentCacheScope;
|
|
10
|
+
const CACHE_SCOPE_SYMBOL = Symbol.for("modular.react.cache_scope");
|
|
11
|
+
const emptyCacheOwnerStack = [];
|
|
12
|
+
let syncVersion = 0;
|
|
13
|
+
let transitionVersion = 0;
|
|
14
|
+
let transitionDepth = 0;
|
|
15
|
+
let currentTransitionContext;
|
|
16
|
+
let transitionRerenderScheduled = false;
|
|
17
|
+
let eventBatchDepth = 0;
|
|
18
|
+
let currentEventPriority = "default";
|
|
19
|
+
let eventRerenderScheduled = false;
|
|
20
|
+
const queuedTransitionRerenders = new Map();
|
|
21
|
+
const queuedEventRerenders = new Set();
|
|
22
|
+
export const version = "19.2.6";
|
|
23
|
+
export function act(callback) {
|
|
24
|
+
const result = callback();
|
|
25
|
+
return (isThenable(result) ? Promise.resolve(result).then(() => undefined) : undefined);
|
|
26
|
+
}
|
|
27
|
+
export function createRootRuntime(rerender, options = {}) {
|
|
28
|
+
return {
|
|
29
|
+
instances: new Map(),
|
|
30
|
+
activeInstanceKeys: undefined,
|
|
31
|
+
activeProfilerPaths: undefined,
|
|
32
|
+
mountedProfilerPaths: new Set(),
|
|
33
|
+
profilerBaseDurations: new Map(),
|
|
34
|
+
pendingProfilerCommits: [],
|
|
35
|
+
pendingInsertionEffects: [],
|
|
36
|
+
pendingLayoutEffects: [],
|
|
37
|
+
pendingEffects: [],
|
|
38
|
+
externalStoreChecks: [],
|
|
39
|
+
portalContainers: new Set(),
|
|
40
|
+
idCounter: 0,
|
|
41
|
+
identifierPrefix: options.identifierPrefix ?? "",
|
|
42
|
+
idMode: options.idMode ?? "client",
|
|
43
|
+
strictModeDepth: 0,
|
|
44
|
+
profilerFlushDepth: 0,
|
|
45
|
+
rerender,
|
|
46
|
+
beginRender() {
|
|
47
|
+
this.activeInstanceKeys = new Set();
|
|
48
|
+
this.activeProfilerPaths = new Set();
|
|
49
|
+
this.pendingProfilerCommits = [];
|
|
50
|
+
this.pendingInsertionEffects = [];
|
|
51
|
+
this.pendingLayoutEffects = [];
|
|
52
|
+
this.pendingEffects = [];
|
|
53
|
+
this.externalStoreChecks = [];
|
|
54
|
+
},
|
|
55
|
+
endRender(committed = true) {
|
|
56
|
+
const profilerCommits = committed ? this.pendingProfilerCommits.splice(0) : [];
|
|
57
|
+
const activeProfilerPaths = this.activeProfilerPaths;
|
|
58
|
+
if (committed) {
|
|
59
|
+
cleanupInactiveInstances(this);
|
|
60
|
+
this.mountedProfilerPaths =
|
|
61
|
+
activeProfilerPaths === undefined ? new Set() : new Set(activeProfilerPaths);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
this.pendingProfilerCommits = [];
|
|
65
|
+
}
|
|
66
|
+
this.activeInstanceKeys = undefined;
|
|
67
|
+
this.activeProfilerPaths = undefined;
|
|
68
|
+
currentRuntime = undefined;
|
|
69
|
+
currentInstance = undefined;
|
|
70
|
+
if (committed) {
|
|
71
|
+
flushProfilerCommits(this, profilerCommits);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
flushEffects() {
|
|
75
|
+
this.profilerFlushDepth += 1;
|
|
76
|
+
try {
|
|
77
|
+
flushPendingEffects(this.pendingInsertionEffects);
|
|
78
|
+
const strictLayoutEffects = flushPendingEffects(this.pendingLayoutEffects);
|
|
79
|
+
const strictEffects = flushPendingEffects(this.pendingEffects);
|
|
80
|
+
const strictReplayEffects = [...strictLayoutEffects, ...strictEffects];
|
|
81
|
+
cleanupStrictEffects(strictReplayEffects);
|
|
82
|
+
replayStrictEffects(strictReplayEffects);
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
this.profilerFlushDepth -= 1;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
dispose() {
|
|
89
|
+
for (const instance of this.instances.values()) {
|
|
90
|
+
cleanupInstance(instance);
|
|
91
|
+
}
|
|
92
|
+
this.pendingLayoutEffects = [];
|
|
93
|
+
this.pendingInsertionEffects = [];
|
|
94
|
+
this.pendingEffects = [];
|
|
95
|
+
this.pendingProfilerCommits = [];
|
|
96
|
+
this.activeProfilerPaths = undefined;
|
|
97
|
+
this.mountedProfilerPaths.clear();
|
|
98
|
+
this.profilerBaseDurations.clear();
|
|
99
|
+
for (const container of this.portalContainers) {
|
|
100
|
+
container.replaceChildren();
|
|
101
|
+
}
|
|
102
|
+
this.portalContainers.clear();
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export function createCacheScope() {
|
|
107
|
+
return {
|
|
108
|
+
functionCaches: new WeakMap(),
|
|
109
|
+
controller: new AbortController(),
|
|
110
|
+
ownerStack: [],
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export function refreshCacheScope(scope) {
|
|
114
|
+
scope.controller.abort();
|
|
115
|
+
scope.functionCaches = new WeakMap();
|
|
116
|
+
scope.controller = new AbortController();
|
|
117
|
+
}
|
|
118
|
+
export function runWithCacheScope(scope, callback) {
|
|
119
|
+
const previousScope = currentCacheScope;
|
|
120
|
+
const previousGlobalScope = getGlobalCacheScope();
|
|
121
|
+
currentCacheScope = scope;
|
|
122
|
+
setGlobalCacheScope(scope);
|
|
123
|
+
try {
|
|
124
|
+
const result = callback();
|
|
125
|
+
if (isThenable(result)) {
|
|
126
|
+
return Promise.resolve(result).finally(() => {
|
|
127
|
+
currentCacheScope = previousScope;
|
|
128
|
+
setGlobalCacheScope(previousGlobalScope);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
currentCacheScope = previousScope;
|
|
132
|
+
setGlobalCacheScope(previousGlobalScope);
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
currentCacheScope = previousScope;
|
|
137
|
+
setGlobalCacheScope(previousGlobalScope);
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
export function renderWithProfiler(runtime, path, props, render) {
|
|
142
|
+
const startTime = getCurrentTime();
|
|
143
|
+
const phase = runtime.profilerFlushDepth > 0
|
|
144
|
+
? "nested-update"
|
|
145
|
+
: runtime.mountedProfilerPaths.has(path)
|
|
146
|
+
? "update"
|
|
147
|
+
: "mount";
|
|
148
|
+
try {
|
|
149
|
+
return render();
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
runtime.activeProfilerPaths?.add(path);
|
|
153
|
+
const onRender = props.onRender;
|
|
154
|
+
const id = props.id;
|
|
155
|
+
if (typeof onRender === "function" && typeof id === "string") {
|
|
156
|
+
const actualDuration = Math.max(0, getCurrentTime() - startTime);
|
|
157
|
+
const baseDuration = Math.max(runtime.profilerBaseDurations.get(path) ?? 0, actualDuration);
|
|
158
|
+
runtime.profilerBaseDurations.set(path, baseDuration);
|
|
159
|
+
runtime.pendingProfilerCommits.push({
|
|
160
|
+
id,
|
|
161
|
+
phase,
|
|
162
|
+
onRender: onRender,
|
|
163
|
+
actualDuration,
|
|
164
|
+
baseDuration,
|
|
165
|
+
startTime,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
export function renderWithRootRuntime(runtime, path, render) {
|
|
171
|
+
const previousRuntime = currentRuntime;
|
|
172
|
+
const previousInstance = currentInstance;
|
|
173
|
+
const instance = runtime.instances.get(path) ?? {
|
|
174
|
+
hooks: [],
|
|
175
|
+
hookIndex: 0,
|
|
176
|
+
dirty: false,
|
|
177
|
+
devToolsHooks: [],
|
|
178
|
+
devToolsHookTypes: [],
|
|
179
|
+
devToolsHookSuppressionDepth: 0,
|
|
180
|
+
};
|
|
181
|
+
runtime.instances.set(path, instance);
|
|
182
|
+
runtime.activeInstanceKeys?.add(path);
|
|
183
|
+
instance.hookIndex = 0;
|
|
184
|
+
instance.dirty = false;
|
|
185
|
+
instance.devToolsHooks = [];
|
|
186
|
+
instance.devToolsHookTypes = [];
|
|
187
|
+
instance.devToolsHookSuppressionDepth = 0;
|
|
188
|
+
currentRuntime = runtime;
|
|
189
|
+
currentInstance = instance;
|
|
190
|
+
try {
|
|
191
|
+
return render();
|
|
192
|
+
}
|
|
193
|
+
finally {
|
|
194
|
+
currentRuntime = previousRuntime;
|
|
195
|
+
currentInstance = previousInstance;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
export function getDevToolsHookState(runtime, path) {
|
|
199
|
+
const instance = runtime.instances.get(path);
|
|
200
|
+
if (instance === undefined) {
|
|
201
|
+
return undefined;
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
hooks: [...instance.devToolsHooks],
|
|
205
|
+
hookTypes: [...instance.devToolsHookTypes],
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
export function renderWithStrictMode(runtime, render) {
|
|
209
|
+
runtime.strictModeDepth += 1;
|
|
210
|
+
try {
|
|
211
|
+
return render();
|
|
212
|
+
}
|
|
213
|
+
finally {
|
|
214
|
+
runtime.strictModeDepth -= 1;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
export function takeRuntimeSnapshot(runtime) {
|
|
218
|
+
return {
|
|
219
|
+
instanceKeys: new Set(runtime.instances.keys()),
|
|
220
|
+
portalContainers: new Set(runtime.portalContainers),
|
|
221
|
+
pendingInsertionEffectsLength: runtime.pendingInsertionEffects.length,
|
|
222
|
+
pendingLayoutEffectsLength: runtime.pendingLayoutEffects.length,
|
|
223
|
+
pendingEffectsLength: runtime.pendingEffects.length,
|
|
224
|
+
pendingProfilerCommitsLength: runtime.pendingProfilerCommits.length,
|
|
225
|
+
profilerBaseDurations: new Map(runtime.profilerBaseDurations),
|
|
226
|
+
idCounter: runtime.idCounter,
|
|
227
|
+
identifierPrefix: runtime.identifierPrefix,
|
|
228
|
+
idMode: runtime.idMode,
|
|
229
|
+
strictModeDepth: runtime.strictModeDepth,
|
|
230
|
+
profilerFlushDepth: runtime.profilerFlushDepth,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
export function restoreRuntimeSnapshot(runtime, snapshot) {
|
|
234
|
+
runtime.pendingInsertionEffects.length = snapshot.pendingInsertionEffectsLength;
|
|
235
|
+
runtime.pendingLayoutEffects.length = snapshot.pendingLayoutEffectsLength;
|
|
236
|
+
runtime.pendingEffects.length = snapshot.pendingEffectsLength;
|
|
237
|
+
runtime.pendingProfilerCommits.length = snapshot.pendingProfilerCommitsLength;
|
|
238
|
+
runtime.profilerBaseDurations = new Map(snapshot.profilerBaseDurations);
|
|
239
|
+
runtime.idCounter = snapshot.idCounter;
|
|
240
|
+
runtime.identifierPrefix = snapshot.identifierPrefix;
|
|
241
|
+
runtime.idMode = snapshot.idMode;
|
|
242
|
+
runtime.strictModeDepth = snapshot.strictModeDepth;
|
|
243
|
+
runtime.profilerFlushDepth = snapshot.profilerFlushDepth;
|
|
244
|
+
for (const key of runtime.instances.keys()) {
|
|
245
|
+
if (!snapshot.instanceKeys.has(key)) {
|
|
246
|
+
runtime.instances.delete(key);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
for (const container of runtime.portalContainers) {
|
|
250
|
+
if (!snapshot.portalContainers.has(container)) {
|
|
251
|
+
container.replaceChildren();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
runtime.portalContainers.clear();
|
|
255
|
+
for (const container of snapshot.portalContainers) {
|
|
256
|
+
runtime.portalContainers.add(container);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
export function useState(initial) {
|
|
260
|
+
const runtime = requireRuntime();
|
|
261
|
+
const instance = requireInstance();
|
|
262
|
+
const index = instance.hookIndex;
|
|
263
|
+
instance.hookIndex += 1;
|
|
264
|
+
let slot = instance.hooks[index];
|
|
265
|
+
if (slot === undefined) {
|
|
266
|
+
slot = {
|
|
267
|
+
kind: "state",
|
|
268
|
+
value: typeof initial === "function" ? initial() : initial,
|
|
269
|
+
};
|
|
270
|
+
instance.hooks[index] = slot;
|
|
271
|
+
}
|
|
272
|
+
if (slot.kind !== "state") {
|
|
273
|
+
throw new Error("Hook order changed between renders.");
|
|
274
|
+
}
|
|
275
|
+
const setState = (value) => {
|
|
276
|
+
const nextValue = typeof value === "function"
|
|
277
|
+
? value(slot.value)
|
|
278
|
+
: value;
|
|
279
|
+
if (Object.is(slot.value, nextValue)) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
slot.value = nextValue;
|
|
283
|
+
scheduleInstanceUpdate(runtime, instance);
|
|
284
|
+
};
|
|
285
|
+
recordDevToolsHook("useState", {
|
|
286
|
+
kind: "state",
|
|
287
|
+
value: slot.value,
|
|
288
|
+
});
|
|
289
|
+
return [slot.value, setState];
|
|
290
|
+
}
|
|
291
|
+
export function useReducer(reducer, initialArg, init) {
|
|
292
|
+
const [state, setState] = runWithoutDevToolsHookTracking(() => useState(() => init === undefined ? initialArg : init(initialArg)));
|
|
293
|
+
const reducerRef = runWithoutDevToolsHookTracking(() => useRef(reducer));
|
|
294
|
+
const dispatchRef = runWithoutDevToolsHookTracking(() => useRef(undefined));
|
|
295
|
+
reducerRef.current = reducer;
|
|
296
|
+
if (dispatchRef.current === undefined) {
|
|
297
|
+
dispatchRef.current = (action) => {
|
|
298
|
+
setState((previousState) => reducerRef.current(previousState, action));
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
recordDevToolsHook("useReducer", {
|
|
302
|
+
kind: "reducer",
|
|
303
|
+
value: state,
|
|
304
|
+
});
|
|
305
|
+
return [state, dispatchRef.current];
|
|
306
|
+
}
|
|
307
|
+
export function useRef(initial) {
|
|
308
|
+
const instance = requireInstance();
|
|
309
|
+
const index = instance.hookIndex;
|
|
310
|
+
instance.hookIndex += 1;
|
|
311
|
+
let slot = instance.hooks[index];
|
|
312
|
+
if (slot === undefined) {
|
|
313
|
+
slot = { kind: "ref", value: { current: initial } };
|
|
314
|
+
instance.hooks[index] = slot;
|
|
315
|
+
}
|
|
316
|
+
if (slot.kind !== "ref") {
|
|
317
|
+
throw new Error("Hook order changed between renders.");
|
|
318
|
+
}
|
|
319
|
+
recordDevToolsHook("useRef", {
|
|
320
|
+
kind: "ref",
|
|
321
|
+
value: slot.value,
|
|
322
|
+
});
|
|
323
|
+
return slot.value;
|
|
324
|
+
}
|
|
325
|
+
export function useId() {
|
|
326
|
+
const runtime = requireRuntime();
|
|
327
|
+
const idRef = runWithoutDevToolsHookTracking(() => useRef(undefined));
|
|
328
|
+
if (idRef.current === undefined) {
|
|
329
|
+
const mode = runtime.idMode === "server" ? "R" : "r";
|
|
330
|
+
idRef.current = `_${runtime.identifierPrefix}${mode}_${runtime.idCounter}_`;
|
|
331
|
+
runtime.idCounter += 1;
|
|
332
|
+
}
|
|
333
|
+
recordDevToolsHook("useId", {
|
|
334
|
+
kind: "id",
|
|
335
|
+
value: idRef.current,
|
|
336
|
+
});
|
|
337
|
+
return idRef.current;
|
|
338
|
+
}
|
|
339
|
+
export function useImperativeHandle(ref, create, deps) {
|
|
340
|
+
const handle = runWithoutDevToolsHookTracking(() => useMemo(create, deps));
|
|
341
|
+
runWithoutDevToolsHookTracking(() => useInsertionEffect(() => {
|
|
342
|
+
assignRef(ref, handle);
|
|
343
|
+
return () => {
|
|
344
|
+
assignRef(ref, null);
|
|
345
|
+
};
|
|
346
|
+
}, [ref, handle]));
|
|
347
|
+
recordDevToolsHook("useImperativeHandle", deps === undefined
|
|
348
|
+
? { kind: "imperative-handle" }
|
|
349
|
+
: { kind: "imperative-handle", deps });
|
|
350
|
+
}
|
|
351
|
+
export function useMemo(factory, deps) {
|
|
352
|
+
const instance = requireInstance();
|
|
353
|
+
const index = instance.hookIndex;
|
|
354
|
+
instance.hookIndex += 1;
|
|
355
|
+
let slot = instance.hooks[index];
|
|
356
|
+
if (slot !== undefined && slot.kind !== "memo") {
|
|
357
|
+
throw new Error("Hook order changed between renders.");
|
|
358
|
+
}
|
|
359
|
+
if (slot === undefined ||
|
|
360
|
+
deps === undefined ||
|
|
361
|
+
slot.deps === undefined ||
|
|
362
|
+
!areHookInputsEqual(deps, slot.deps)) {
|
|
363
|
+
const value = factory();
|
|
364
|
+
slot =
|
|
365
|
+
deps === undefined
|
|
366
|
+
? { kind: "memo", value }
|
|
367
|
+
: { kind: "memo", value, deps };
|
|
368
|
+
instance.hooks[index] = slot;
|
|
369
|
+
}
|
|
370
|
+
recordDevToolsHook("useMemo", slot.deps === undefined
|
|
371
|
+
? { kind: "memo", value: slot.value }
|
|
372
|
+
: { kind: "memo", value: slot.value, deps: slot.deps });
|
|
373
|
+
return slot.value;
|
|
374
|
+
}
|
|
375
|
+
function assignRef(ref, value) {
|
|
376
|
+
if (typeof ref === "function") {
|
|
377
|
+
ref(value);
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
if (typeof ref === "object" && ref !== null && "current" in ref) {
|
|
381
|
+
ref.current = value;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
function recordDevToolsHook(type, value) {
|
|
385
|
+
const instance = currentInstance;
|
|
386
|
+
if (instance === undefined || instance.devToolsHookSuppressionDepth > 0) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
instance.devToolsHookTypes.push(type);
|
|
390
|
+
instance.devToolsHooks.push(value);
|
|
391
|
+
}
|
|
392
|
+
function runWithoutDevToolsHookTracking(callback) {
|
|
393
|
+
const instance = requireInstance();
|
|
394
|
+
instance.devToolsHookSuppressionDepth += 1;
|
|
395
|
+
try {
|
|
396
|
+
return callback();
|
|
397
|
+
}
|
|
398
|
+
finally {
|
|
399
|
+
instance.devToolsHookSuppressionDepth -= 1;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
export function useCallback(callback, deps) {
|
|
403
|
+
const value = runWithoutDevToolsHookTracking(() => useMemo(() => callback, deps));
|
|
404
|
+
recordDevToolsHook("useCallback", deps === undefined
|
|
405
|
+
? { kind: "callback", value }
|
|
406
|
+
: { kind: "callback", value, deps });
|
|
407
|
+
return value;
|
|
408
|
+
}
|
|
409
|
+
export function useDebugValue(_value, _format) {
|
|
410
|
+
const instance = requireInstance();
|
|
411
|
+
const index = instance.hookIndex;
|
|
412
|
+
instance.hookIndex += 1;
|
|
413
|
+
const value = _format === undefined ? _value : _format(_value);
|
|
414
|
+
let slot = instance.hooks[index];
|
|
415
|
+
if (slot !== undefined && slot.kind !== "debug") {
|
|
416
|
+
throw new Error("Hook order changed between renders.");
|
|
417
|
+
}
|
|
418
|
+
if (slot === undefined) {
|
|
419
|
+
slot = { kind: "debug", value };
|
|
420
|
+
instance.hooks[index] = slot;
|
|
421
|
+
recordDevToolsHook("useDebugValue", {
|
|
422
|
+
kind: "debug",
|
|
423
|
+
value,
|
|
424
|
+
});
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
slot.value = value;
|
|
428
|
+
recordDevToolsHook("useDebugValue", {
|
|
429
|
+
kind: "debug",
|
|
430
|
+
value,
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
export function useEffectEvent(callback) {
|
|
434
|
+
const ref = runWithoutDevToolsHookTracking(() => useRef(callback));
|
|
435
|
+
ref.current = callback;
|
|
436
|
+
const event = runWithoutDevToolsHookTracking(() => useCallback((...args) => ref.current(...args), []));
|
|
437
|
+
recordDevToolsHook("useEffectEvent", {
|
|
438
|
+
kind: "callback",
|
|
439
|
+
value: event,
|
|
440
|
+
deps: [],
|
|
441
|
+
});
|
|
442
|
+
return event;
|
|
443
|
+
}
|
|
444
|
+
export function useEffect(callback, deps) {
|
|
445
|
+
useEffectImpl("normal", callback, deps);
|
|
446
|
+
recordDevToolsHook("useEffect", deps === undefined
|
|
447
|
+
? { kind: "effect", effectKind: "normal" }
|
|
448
|
+
: { kind: "effect", effectKind: "normal", deps });
|
|
449
|
+
}
|
|
450
|
+
export function useInsertionEffect(callback, deps) {
|
|
451
|
+
useEffectImpl("insertion", callback, deps);
|
|
452
|
+
recordDevToolsHook("useInsertionEffect", deps === undefined
|
|
453
|
+
? { kind: "effect", effectKind: "insertion" }
|
|
454
|
+
: { kind: "effect", effectKind: "insertion", deps });
|
|
455
|
+
}
|
|
456
|
+
export function useLayoutEffect(callback, deps) {
|
|
457
|
+
useEffectImpl("layout", callback, deps);
|
|
458
|
+
recordDevToolsHook("useLayoutEffect", deps === undefined
|
|
459
|
+
? { kind: "effect", effectKind: "layout" }
|
|
460
|
+
: { kind: "effect", effectKind: "layout", deps });
|
|
461
|
+
}
|
|
462
|
+
export function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot = getSnapshot) {
|
|
463
|
+
const runtime = requireRuntime();
|
|
464
|
+
const instance = requireInstance();
|
|
465
|
+
const index = instance.hookIndex;
|
|
466
|
+
instance.hookIndex += 1;
|
|
467
|
+
let slot = instance.hooks[index];
|
|
468
|
+
if (slot === undefined) {
|
|
469
|
+
slot = { kind: "store", value: getServerSnapshot() };
|
|
470
|
+
instance.hooks[index] = slot;
|
|
471
|
+
}
|
|
472
|
+
if (slot.kind !== "store") {
|
|
473
|
+
throw new Error("Hook order changed between renders.");
|
|
474
|
+
}
|
|
475
|
+
const currentSnapshot = getSnapshot();
|
|
476
|
+
if (!Object.is(slot.value, currentSnapshot)) {
|
|
477
|
+
slot.value = currentSnapshot;
|
|
478
|
+
}
|
|
479
|
+
recordExternalStoreCheck(getSnapshot, currentSnapshot);
|
|
480
|
+
runWithoutDevToolsHookTracking(() => useEffect(() => {
|
|
481
|
+
const checkForUpdates = () => {
|
|
482
|
+
const nextSnapshot = getSnapshot();
|
|
483
|
+
if (!Object.is(slot.value, nextSnapshot)) {
|
|
484
|
+
slot.value = nextSnapshot;
|
|
485
|
+
runtime.rerender("sync");
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
checkForUpdates();
|
|
489
|
+
return subscribe(checkForUpdates);
|
|
490
|
+
}, [subscribe, getSnapshot]));
|
|
491
|
+
recordDevToolsHook("useSyncExternalStore", {
|
|
492
|
+
kind: "store",
|
|
493
|
+
value: slot.value,
|
|
494
|
+
});
|
|
495
|
+
return slot.value;
|
|
496
|
+
}
|
|
497
|
+
export function useActionState(action, initialState) {
|
|
498
|
+
const runtime = requireRuntime();
|
|
499
|
+
const instance = requireInstance();
|
|
500
|
+
const index = instance.hookIndex;
|
|
501
|
+
instance.hookIndex += 1;
|
|
502
|
+
let slot = instance.hooks[index];
|
|
503
|
+
if (slot !== undefined && slot.kind !== "action-state") {
|
|
504
|
+
throw new Error("Hook order changed between renders.");
|
|
505
|
+
}
|
|
506
|
+
if (slot === undefined) {
|
|
507
|
+
slot = {
|
|
508
|
+
kind: "action-state",
|
|
509
|
+
state: initialState,
|
|
510
|
+
pendingCount: 0,
|
|
511
|
+
action: action,
|
|
512
|
+
};
|
|
513
|
+
instance.hooks[index] = slot;
|
|
514
|
+
}
|
|
515
|
+
if ("error" in slot) {
|
|
516
|
+
throw slot.error;
|
|
517
|
+
}
|
|
518
|
+
slot.action = action;
|
|
519
|
+
if (slot.dispatch === undefined) {
|
|
520
|
+
slot.dispatch = (payload) => {
|
|
521
|
+
runActionStateDispatch(slot, runtime, instance, payload);
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
recordDevToolsHook("useActionState", {
|
|
525
|
+
kind: "state",
|
|
526
|
+
value: slot.state,
|
|
527
|
+
});
|
|
528
|
+
return [
|
|
529
|
+
slot.state,
|
|
530
|
+
slot.dispatch,
|
|
531
|
+
slot.pendingCount > 0,
|
|
532
|
+
];
|
|
533
|
+
}
|
|
534
|
+
export function useOptimistic(state, update) {
|
|
535
|
+
const runtime = requireRuntime();
|
|
536
|
+
const instance = requireInstance();
|
|
537
|
+
const index = instance.hookIndex;
|
|
538
|
+
instance.hookIndex += 1;
|
|
539
|
+
let slot = instance.hooks[index];
|
|
540
|
+
const updateFn = update === undefined
|
|
541
|
+
? (_current, payload) => payload
|
|
542
|
+
: update;
|
|
543
|
+
if (slot !== undefined && slot.kind !== "optimistic") {
|
|
544
|
+
throw new Error("Hook order changed between renders.");
|
|
545
|
+
}
|
|
546
|
+
if (slot === undefined) {
|
|
547
|
+
slot = {
|
|
548
|
+
kind: "optimistic",
|
|
549
|
+
baseState: state,
|
|
550
|
+
optimisticState: state,
|
|
551
|
+
update: updateFn,
|
|
552
|
+
};
|
|
553
|
+
instance.hooks[index] = slot;
|
|
554
|
+
}
|
|
555
|
+
slot.update = updateFn;
|
|
556
|
+
if (!Object.is(slot.baseState, state)) {
|
|
557
|
+
slot.baseState = state;
|
|
558
|
+
slot.optimisticState = state;
|
|
559
|
+
}
|
|
560
|
+
if (slot.dispatch === undefined) {
|
|
561
|
+
slot.dispatch = (payload) => {
|
|
562
|
+
slot.optimisticState = slot.update(slot.optimisticState, payload);
|
|
563
|
+
scheduleInstanceUpdate(runtime, instance);
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
recordDevToolsHook("useOptimistic", {
|
|
567
|
+
kind: "state",
|
|
568
|
+
value: slot.optimisticState,
|
|
569
|
+
});
|
|
570
|
+
return [slot.optimisticState, slot.dispatch];
|
|
571
|
+
}
|
|
572
|
+
export function use(usable) {
|
|
573
|
+
if (isReactCompatContext(usable)) {
|
|
574
|
+
return useContext(usable);
|
|
575
|
+
}
|
|
576
|
+
if (isThenable(usable)) {
|
|
577
|
+
return readThenable(usable);
|
|
578
|
+
}
|
|
579
|
+
return usable;
|
|
580
|
+
}
|
|
581
|
+
export function cache(callback) {
|
|
582
|
+
return (...args) => {
|
|
583
|
+
const scope = getCurrentCacheScope();
|
|
584
|
+
if (scope === undefined) {
|
|
585
|
+
return callback(...args);
|
|
586
|
+
}
|
|
587
|
+
const leaf = getCacheLeaf(scope, callback, args);
|
|
588
|
+
if (leaf.status === "fulfilled") {
|
|
589
|
+
return leaf.value;
|
|
590
|
+
}
|
|
591
|
+
if (leaf.status === "rejected") {
|
|
592
|
+
throw leaf.reason;
|
|
593
|
+
}
|
|
594
|
+
try {
|
|
595
|
+
const value = callback(...args);
|
|
596
|
+
leaf.status = "fulfilled";
|
|
597
|
+
leaf.value = value;
|
|
598
|
+
return value;
|
|
599
|
+
}
|
|
600
|
+
catch (error) {
|
|
601
|
+
leaf.status = "rejected";
|
|
602
|
+
leaf.reason = error;
|
|
603
|
+
throw error;
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
export function cacheSignal() {
|
|
608
|
+
return getCurrentCacheScope()?.controller.signal ?? null;
|
|
609
|
+
}
|
|
610
|
+
export function captureOwnerStack() {
|
|
611
|
+
const stack = getCurrentCacheScope()?.ownerStack ?? emptyCacheOwnerStack;
|
|
612
|
+
return stack.length === 0 ? null : stack.join("\n");
|
|
613
|
+
}
|
|
614
|
+
export function unstable_useCacheRefresh() {
|
|
615
|
+
return useCallback(() => undefined, []);
|
|
616
|
+
}
|
|
617
|
+
export function hasStableExternalStores(runtime) {
|
|
618
|
+
return runtime.externalStoreChecks.every((check) => Object.is(check.getSnapshot(), check.value));
|
|
619
|
+
}
|
|
620
|
+
export function renderToString(component, props, options = {}) {
|
|
621
|
+
const runtime = createRootRuntime(() => undefined, {
|
|
622
|
+
...options,
|
|
623
|
+
idMode: "server",
|
|
624
|
+
});
|
|
625
|
+
return runWithCacheScope(createCacheScope(), () => {
|
|
626
|
+
try {
|
|
627
|
+
const rendered = renderWithRootRuntime(runtime, "0", () => component(props));
|
|
628
|
+
return typeof rendered === "string"
|
|
629
|
+
? rendered
|
|
630
|
+
: renderNodeToString(rendered, runtime, "0");
|
|
631
|
+
}
|
|
632
|
+
finally {
|
|
633
|
+
runtime.dispose();
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
function renderNodeToString(node, runtime, path) {
|
|
638
|
+
if (node === null || node === undefined || typeof node === "boolean") {
|
|
639
|
+
return "";
|
|
640
|
+
}
|
|
641
|
+
if (typeof node === "string" || typeof node === "number") {
|
|
642
|
+
return escapeHtml(node);
|
|
643
|
+
}
|
|
644
|
+
if (Array.isArray(node)) {
|
|
645
|
+
return node.map((child, index) => renderNodeToString(child, runtime, `${path}.${index}`)).join("");
|
|
646
|
+
}
|
|
647
|
+
if (!isReactCompatElement(node)) {
|
|
648
|
+
return "";
|
|
649
|
+
}
|
|
650
|
+
return renderElementToString(node, runtime, path);
|
|
651
|
+
}
|
|
652
|
+
function renderElementToString(element, runtime, path) {
|
|
653
|
+
if (typeof element.type === "string") {
|
|
654
|
+
if (element.type === "textarea") {
|
|
655
|
+
return renderTextareaToString(element, runtime, path);
|
|
656
|
+
}
|
|
657
|
+
if (element.type === "select") {
|
|
658
|
+
return renderSelectToString(element, runtime, path);
|
|
659
|
+
}
|
|
660
|
+
const attributes = element.type === "input"
|
|
661
|
+
? renderInputAttributesToString(element.props)
|
|
662
|
+
: Object.entries(element.props)
|
|
663
|
+
.map(([name, value]) => renderHtmlAttribute(name, value))
|
|
664
|
+
.filter((attribute) => attribute !== "")
|
|
665
|
+
.join("");
|
|
666
|
+
if (voidHtmlElements.has(element.type)) {
|
|
667
|
+
return `<${element.type}${attributes}/>`;
|
|
668
|
+
}
|
|
669
|
+
return `<${element.type}${attributes}>${renderNodeToString(element.props.children, runtime, `${path}.children`)}</${element.type}>`;
|
|
670
|
+
}
|
|
671
|
+
if (element.type === Fragment) {
|
|
672
|
+
return renderNodeToString(element.props.children, runtime, `${path}.fragment`);
|
|
673
|
+
}
|
|
674
|
+
if (element.type === Activity) {
|
|
675
|
+
if (element.props.mode === "hidden") {
|
|
676
|
+
return "";
|
|
677
|
+
}
|
|
678
|
+
return `<!--&-->${renderNodeToString(element.props.children, runtime, `${path}.activity`)}<!--/&-->`;
|
|
679
|
+
}
|
|
680
|
+
if (element.type === Profiler) {
|
|
681
|
+
return renderNodeToString(element.props.children, runtime, `${path}.profiler`);
|
|
682
|
+
}
|
|
683
|
+
if (isReactCompatProvider(element.type)) {
|
|
684
|
+
return renderWithContextProvider(element.type, element.props.value, () => renderNodeToString(element.props.children, runtime, `${path}.provider`));
|
|
685
|
+
}
|
|
686
|
+
if (isReactCompatConsumer(element.type)) {
|
|
687
|
+
const children = element.props.children;
|
|
688
|
+
if (typeof children === "function") {
|
|
689
|
+
return renderNodeToString(children(useContext(element.type.context)), runtime, `${path}.consumer`);
|
|
690
|
+
}
|
|
691
|
+
return "";
|
|
692
|
+
}
|
|
693
|
+
if (isForwardRefType(element.type)) {
|
|
694
|
+
const forwardRefType = element.type;
|
|
695
|
+
return renderNodeToString(renderWithRootRuntime(runtime, `${path}.forwardRef`, () => forwardRefType.render(element.props, element.ref)), runtime, `${path}.forwardRef`);
|
|
696
|
+
}
|
|
697
|
+
if (isMemoType(element.type)) {
|
|
698
|
+
return renderNodeToString({
|
|
699
|
+
...element,
|
|
700
|
+
type: element.type.type,
|
|
701
|
+
}, runtime, `${path}.memo`);
|
|
702
|
+
}
|
|
703
|
+
if (isClassComponentType(element.type)) {
|
|
704
|
+
const instance = new element.type(element.props);
|
|
705
|
+
return renderNodeToString(renderWithRootRuntime(runtime, path, () => instance.render()), runtime, path);
|
|
706
|
+
}
|
|
707
|
+
if (typeof element.type === "function") {
|
|
708
|
+
const component = element.type;
|
|
709
|
+
return renderNodeToString(renderWithRootRuntime(runtime, path, () => component(element.props)), runtime, path);
|
|
710
|
+
}
|
|
711
|
+
return "";
|
|
712
|
+
}
|
|
713
|
+
function isClassComponentType(value) {
|
|
714
|
+
return (typeof value === "function" &&
|
|
715
|
+
typeof value.prototype?.render === "function");
|
|
716
|
+
}
|
|
717
|
+
function renderTextareaToString(element, runtime, path) {
|
|
718
|
+
const value = element.props.value ??
|
|
719
|
+
element.props.defaultValue ??
|
|
720
|
+
element.props.children;
|
|
721
|
+
const attributes = Object.entries(element.props)
|
|
722
|
+
.filter(([name]) => name !== "value" && name !== "defaultValue")
|
|
723
|
+
.map(([name, child]) => renderHtmlAttribute(name, child))
|
|
724
|
+
.filter((attribute) => attribute !== "")
|
|
725
|
+
.join("");
|
|
726
|
+
return `<textarea${attributes}>${renderNodeToString(value, runtime, `${path}.textarea`)}</textarea>`;
|
|
727
|
+
}
|
|
728
|
+
function renderSelectToString(element, runtime, path) {
|
|
729
|
+
const selectedValue = element.props.value ??
|
|
730
|
+
element.props.defaultValue;
|
|
731
|
+
const attributes = Object.entries(element.props)
|
|
732
|
+
.filter(([name]) => name !== "value" && name !== "defaultValue")
|
|
733
|
+
.map(([name, child]) => renderHtmlAttribute(name, child))
|
|
734
|
+
.filter((attribute) => attribute !== "")
|
|
735
|
+
.join("");
|
|
736
|
+
return `<select${attributes}>${renderSelectChildrenToString(element.props.children, selectedValue, runtime, `${path}.select`)}</select>`;
|
|
737
|
+
}
|
|
738
|
+
function renderSelectChildrenToString(children, selectedValue, runtime, path) {
|
|
739
|
+
const childArray = Array.isArray(children) ? children : [children];
|
|
740
|
+
return childArray.map((child, index) => {
|
|
741
|
+
if (!isReactCompatElement(child) || child.type !== "option") {
|
|
742
|
+
return renderNodeToString(child, runtime, `${path}.${index}`);
|
|
743
|
+
}
|
|
744
|
+
const optionValue = child.props.value ?? child.props.children;
|
|
745
|
+
const selected = selectedValue !== undefined && String(optionValue) === String(selectedValue);
|
|
746
|
+
const props = selected
|
|
747
|
+
? { ...child.props, selected: true }
|
|
748
|
+
: child.props;
|
|
749
|
+
return renderElementToString({ ...child, props }, runtime, `${path}.${index}`);
|
|
750
|
+
}).join("");
|
|
751
|
+
}
|
|
752
|
+
function renderInputAttributesToString(props) {
|
|
753
|
+
const hasValue = props.value !== undefined;
|
|
754
|
+
const hasChecked = props.checked !== undefined;
|
|
755
|
+
return Object.entries(props)
|
|
756
|
+
.filter(([name]) => !((name === "defaultValue" && hasValue) || (name === "defaultChecked" && hasChecked)))
|
|
757
|
+
.sort(([leftName], [rightName]) => Number(isInputValueAttribute(leftName)) - Number(isInputValueAttribute(rightName)))
|
|
758
|
+
.map(([name, value]) => renderHtmlAttribute(toInputHtmlAttributeName(name), value))
|
|
759
|
+
.filter((attribute) => attribute !== "")
|
|
760
|
+
.join("");
|
|
761
|
+
}
|
|
762
|
+
function renderHtmlAttribute(name, value) {
|
|
763
|
+
if (name === "children" ||
|
|
764
|
+
name === "key" ||
|
|
765
|
+
name === "ref" ||
|
|
766
|
+
/^on[A-Z]/.test(name) ||
|
|
767
|
+
value === null ||
|
|
768
|
+
value === undefined ||
|
|
769
|
+
value === false ||
|
|
770
|
+
typeof value === "function") {
|
|
771
|
+
return "";
|
|
772
|
+
}
|
|
773
|
+
if (name === "style") {
|
|
774
|
+
const style = renderStyleAttribute(value);
|
|
775
|
+
return style === "" ? "" : ` style="${escapeHtml(style)}"`;
|
|
776
|
+
}
|
|
777
|
+
const attributeName = toHtmlAttributeName(name);
|
|
778
|
+
if (isDangerousHtmlAttribute(attributeName)) {
|
|
779
|
+
return isDangerousHtmlOptIn(value)
|
|
780
|
+
? ` ${attributeName}="${escapeHtml(value.__html)}"`
|
|
781
|
+
: "";
|
|
782
|
+
}
|
|
783
|
+
if (typeof value === "object") {
|
|
784
|
+
return "";
|
|
785
|
+
}
|
|
786
|
+
if (value === true) {
|
|
787
|
+
return ` ${attributeName}=""`;
|
|
788
|
+
}
|
|
789
|
+
return ` ${attributeName}="${escapeHtml(value)}"`;
|
|
790
|
+
}
|
|
791
|
+
function isInputValueAttribute(name) {
|
|
792
|
+
return name === "value" || name === "defaultValue";
|
|
793
|
+
}
|
|
794
|
+
function toInputHtmlAttributeName(name) {
|
|
795
|
+
if (name === "defaultValue") {
|
|
796
|
+
return "value";
|
|
797
|
+
}
|
|
798
|
+
if (name === "defaultChecked") {
|
|
799
|
+
return "checked";
|
|
800
|
+
}
|
|
801
|
+
return name;
|
|
802
|
+
}
|
|
803
|
+
function toHtmlAttributeName(name) {
|
|
804
|
+
return HTML_ATTRIBUTE_ALIASES[name] ?? name;
|
|
805
|
+
}
|
|
806
|
+
const HTML_ATTRIBUTE_ALIASES = {
|
|
807
|
+
acceptCharset: "accept-charset",
|
|
808
|
+
autoFocus: "autofocus",
|
|
809
|
+
autoPlay: "autoplay",
|
|
810
|
+
charSet: "charset",
|
|
811
|
+
className: "class",
|
|
812
|
+
colSpan: "colspan",
|
|
813
|
+
contentEditable: "contenteditable",
|
|
814
|
+
crossOrigin: "crossorigin",
|
|
815
|
+
encType: "enctype",
|
|
816
|
+
formAction: "formaction",
|
|
817
|
+
frameBorder: "frameborder",
|
|
818
|
+
htmlFor: "for",
|
|
819
|
+
httpEquiv: "http-equiv",
|
|
820
|
+
maxLength: "maxlength",
|
|
821
|
+
minLength: "minlength",
|
|
822
|
+
noValidate: "novalidate",
|
|
823
|
+
playsInline: "playsinline",
|
|
824
|
+
readOnly: "readOnly",
|
|
825
|
+
rowSpan: "rowspan",
|
|
826
|
+
spellCheck: "spellcheck",
|
|
827
|
+
srcDoc: "srcdoc",
|
|
828
|
+
srcSet: "srcset",
|
|
829
|
+
tabIndex: "tabindex",
|
|
830
|
+
useMap: "usemap",
|
|
831
|
+
};
|
|
832
|
+
function renderStyleAttribute(value) {
|
|
833
|
+
if (typeof value !== "object" || value === null) {
|
|
834
|
+
return "";
|
|
835
|
+
}
|
|
836
|
+
return Object.entries(value)
|
|
837
|
+
.filter(([, propertyValue]) => propertyValue !== null &&
|
|
838
|
+
propertyValue !== undefined &&
|
|
839
|
+
typeof propertyValue !== "boolean" &&
|
|
840
|
+
propertyValue !== "")
|
|
841
|
+
.map(([name, propertyValue]) => `${toKebabCase(name)}:${renderCssValue(name, propertyValue)}`)
|
|
842
|
+
.join(";");
|
|
843
|
+
}
|
|
844
|
+
function renderCssValue(name, value) {
|
|
845
|
+
if (typeof value !== "number" || value === 0 || isUnitlessCssProperty(name)) {
|
|
846
|
+
return String(value);
|
|
847
|
+
}
|
|
848
|
+
return `${value}px`;
|
|
849
|
+
}
|
|
850
|
+
function toKebabCase(value) {
|
|
851
|
+
return value.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
852
|
+
}
|
|
853
|
+
function isUnitlessCssProperty(name) {
|
|
854
|
+
return (name === "flex" ||
|
|
855
|
+
name === "fontWeight" ||
|
|
856
|
+
name === "lineHeight" ||
|
|
857
|
+
name === "opacity" ||
|
|
858
|
+
name === "order" ||
|
|
859
|
+
name === "zIndex" ||
|
|
860
|
+
name === "zoom");
|
|
861
|
+
}
|
|
862
|
+
const voidHtmlElements = new Set([
|
|
863
|
+
"area",
|
|
864
|
+
"base",
|
|
865
|
+
"br",
|
|
866
|
+
"col",
|
|
867
|
+
"embed",
|
|
868
|
+
"hr",
|
|
869
|
+
"img",
|
|
870
|
+
"input",
|
|
871
|
+
"link",
|
|
872
|
+
"meta",
|
|
873
|
+
"param",
|
|
874
|
+
"source",
|
|
875
|
+
"track",
|
|
876
|
+
"wbr",
|
|
877
|
+
]);
|
|
878
|
+
function isForwardRefType(value) {
|
|
879
|
+
return (typeof value === "object" &&
|
|
880
|
+
value !== null &&
|
|
881
|
+
value.$$typeof === FORWARD_REF_TYPE);
|
|
882
|
+
}
|
|
883
|
+
function isMemoType(value) {
|
|
884
|
+
return (typeof value === "object" &&
|
|
885
|
+
value !== null &&
|
|
886
|
+
value.$$typeof === MEMO_TYPE);
|
|
887
|
+
}
|
|
888
|
+
function readThenable(thenable) {
|
|
889
|
+
const record = thenable;
|
|
890
|
+
if (record.status === "fulfilled") {
|
|
891
|
+
return record.value;
|
|
892
|
+
}
|
|
893
|
+
if (record.status === "rejected") {
|
|
894
|
+
throw record.reason;
|
|
895
|
+
}
|
|
896
|
+
if (record.status === undefined) {
|
|
897
|
+
record.status = "pending";
|
|
898
|
+
thenable.then((value) => {
|
|
899
|
+
if (record.status === "pending") {
|
|
900
|
+
record.status = "fulfilled";
|
|
901
|
+
record.value = value;
|
|
902
|
+
}
|
|
903
|
+
}, (reason) => {
|
|
904
|
+
if (record.status === "pending") {
|
|
905
|
+
record.status = "rejected";
|
|
906
|
+
record.reason = reason;
|
|
907
|
+
}
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
throw thenable;
|
|
911
|
+
}
|
|
912
|
+
export function startTransition(scope) {
|
|
913
|
+
const context = {
|
|
914
|
+
syncVersion,
|
|
915
|
+
transitionVersion: ++transitionVersion,
|
|
916
|
+
};
|
|
917
|
+
scheduleCallback("low", () => {
|
|
918
|
+
if (!isTransitionContextCurrent(context)) {
|
|
919
|
+
return;
|
|
920
|
+
}
|
|
921
|
+
runTransitionScope(scope, context);
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
export function runWithEventPriority(priority, callback) {
|
|
925
|
+
const previousPriority = currentEventPriority;
|
|
926
|
+
currentEventPriority = priority;
|
|
927
|
+
eventBatchDepth += 1;
|
|
928
|
+
try {
|
|
929
|
+
return callback();
|
|
930
|
+
}
|
|
931
|
+
finally {
|
|
932
|
+
eventBatchDepth -= 1;
|
|
933
|
+
currentEventPriority = previousPriority;
|
|
934
|
+
if (eventBatchDepth === 0) {
|
|
935
|
+
flushEventRerendersForPriority(priority);
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
export function flushSyncUpdates(callback) {
|
|
940
|
+
const previousEventBatchDepth = eventBatchDepth;
|
|
941
|
+
const previousEventPriority = currentEventPriority;
|
|
942
|
+
eventBatchDepth = 0;
|
|
943
|
+
currentEventPriority = "discrete";
|
|
944
|
+
try {
|
|
945
|
+
const value = callback();
|
|
946
|
+
flushQueuedEventRerenders();
|
|
947
|
+
return value;
|
|
948
|
+
}
|
|
949
|
+
finally {
|
|
950
|
+
eventBatchDepth = previousEventBatchDepth;
|
|
951
|
+
currentEventPriority = previousEventPriority;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
export function useTransition() {
|
|
955
|
+
const [pending, setPending] = runWithoutDevToolsHookTracking(() => useState(false));
|
|
956
|
+
const startTransitionWithPending = (scope) => {
|
|
957
|
+
setPending(true);
|
|
958
|
+
const context = {
|
|
959
|
+
syncVersion,
|
|
960
|
+
transitionVersion: ++transitionVersion,
|
|
961
|
+
};
|
|
962
|
+
scheduleCallback("low", () => {
|
|
963
|
+
if (!isTransitionContextCurrent(context)) {
|
|
964
|
+
setPending(false);
|
|
965
|
+
return;
|
|
966
|
+
}
|
|
967
|
+
runTransitionScope(() => {
|
|
968
|
+
scope();
|
|
969
|
+
setPending(false);
|
|
970
|
+
}, context);
|
|
971
|
+
});
|
|
972
|
+
};
|
|
973
|
+
recordDevToolsHook("useTransition", {
|
|
974
|
+
kind: "transition",
|
|
975
|
+
value: pending,
|
|
976
|
+
});
|
|
977
|
+
return [
|
|
978
|
+
pending,
|
|
979
|
+
startTransitionWithPending,
|
|
980
|
+
];
|
|
981
|
+
}
|
|
982
|
+
export function useDeferredValue(value) {
|
|
983
|
+
const [deferredValue, setDeferredValue] = runWithoutDevToolsHookTracking(() => useState(value));
|
|
984
|
+
runWithoutDevToolsHookTracking(() => useEffect(() => {
|
|
985
|
+
if (Object.is(deferredValue, value)) {
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
startTransition(() => {
|
|
989
|
+
setDeferredValue(value);
|
|
990
|
+
});
|
|
991
|
+
}, [value, deferredValue]));
|
|
992
|
+
const currentValue = Object.is(deferredValue, value) ? value : deferredValue;
|
|
993
|
+
recordDevToolsHook("useDeferredValue", {
|
|
994
|
+
kind: "deferred",
|
|
995
|
+
value: currentValue,
|
|
996
|
+
});
|
|
997
|
+
return currentValue;
|
|
998
|
+
}
|
|
999
|
+
function runTransitionScope(scope, context) {
|
|
1000
|
+
transitionDepth += 1;
|
|
1001
|
+
const previousContext = currentTransitionContext;
|
|
1002
|
+
currentTransitionContext = context;
|
|
1003
|
+
try {
|
|
1004
|
+
scope();
|
|
1005
|
+
}
|
|
1006
|
+
finally {
|
|
1007
|
+
currentTransitionContext = previousContext;
|
|
1008
|
+
transitionDepth -= 1;
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
function queueTransitionRerender(runtime, context) {
|
|
1012
|
+
queuedTransitionRerenders.set(runtime, context);
|
|
1013
|
+
if (transitionRerenderScheduled) {
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
transitionRerenderScheduled = true;
|
|
1017
|
+
scheduleCallback("low", flushQueuedTransitionRerenders);
|
|
1018
|
+
}
|
|
1019
|
+
function queueEventRerender(runtime) {
|
|
1020
|
+
queuedEventRerenders.add(runtime);
|
|
1021
|
+
}
|
|
1022
|
+
function flushEventRerendersForPriority(priority) {
|
|
1023
|
+
if (priority === "discrete") {
|
|
1024
|
+
flushQueuedEventRerenders("sync");
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
if (eventRerenderScheduled || queuedEventRerenders.size === 0) {
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
eventRerenderScheduled = true;
|
|
1031
|
+
scheduleCallback(priority === "continuous" ? "normal" : "low", () => {
|
|
1032
|
+
eventRerenderScheduled = false;
|
|
1033
|
+
flushQueuedEventRerenders(priority === "continuous" ? "continuous" : "sync");
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
function flushQueuedEventRerenders(priority = "sync") {
|
|
1037
|
+
const runtimes = Array.from(queuedEventRerenders);
|
|
1038
|
+
queuedEventRerenders.clear();
|
|
1039
|
+
for (const runtime of runtimes) {
|
|
1040
|
+
runtime.rerender(priority);
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
function flushQueuedTransitionRerenders() {
|
|
1044
|
+
transitionRerenderScheduled = false;
|
|
1045
|
+
const entries = Array.from(queuedTransitionRerenders.entries());
|
|
1046
|
+
queuedTransitionRerenders.clear();
|
|
1047
|
+
for (const [runtime, context] of entries) {
|
|
1048
|
+
if (isTransitionContextCurrent(context)) {
|
|
1049
|
+
runtime.rerender("transition");
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
function isTransitionContextCurrent(context) {
|
|
1054
|
+
return (context.syncVersion === syncVersion &&
|
|
1055
|
+
context.transitionVersion === transitionVersion);
|
|
1056
|
+
}
|
|
1057
|
+
function useEffectImpl(effectKind, callback, deps) {
|
|
1058
|
+
const runtime = requireRuntime();
|
|
1059
|
+
const instance = requireInstance();
|
|
1060
|
+
const index = instance.hookIndex;
|
|
1061
|
+
instance.hookIndex += 1;
|
|
1062
|
+
let slot = instance.hooks[index];
|
|
1063
|
+
if (slot !== undefined && slot.kind !== "effect") {
|
|
1064
|
+
throw new Error("Hook order changed between renders.");
|
|
1065
|
+
}
|
|
1066
|
+
const shouldRun = slot === undefined ||
|
|
1067
|
+
deps === undefined ||
|
|
1068
|
+
slot.deps === undefined ||
|
|
1069
|
+
!areHookInputsEqual(deps, slot.deps);
|
|
1070
|
+
if (slot === undefined) {
|
|
1071
|
+
slot =
|
|
1072
|
+
deps === undefined
|
|
1073
|
+
? { kind: "effect", effectKind, callback }
|
|
1074
|
+
: { kind: "effect", effectKind, callback, deps };
|
|
1075
|
+
instance.hooks[index] = slot;
|
|
1076
|
+
}
|
|
1077
|
+
else {
|
|
1078
|
+
slot.effectKind = effectKind;
|
|
1079
|
+
slot.callback = callback;
|
|
1080
|
+
slot.disposed = false;
|
|
1081
|
+
if (deps === undefined) {
|
|
1082
|
+
delete slot.deps;
|
|
1083
|
+
}
|
|
1084
|
+
else {
|
|
1085
|
+
slot.deps = deps;
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
slot.strictReplay =
|
|
1089
|
+
runtime.strictModeDepth > 0 && effectKind !== "insertion";
|
|
1090
|
+
if (shouldRun) {
|
|
1091
|
+
const queue = effectKind === "insertion"
|
|
1092
|
+
? runtime.pendingInsertionEffects
|
|
1093
|
+
: effectKind === "layout"
|
|
1094
|
+
? runtime.pendingLayoutEffects
|
|
1095
|
+
: runtime.pendingEffects;
|
|
1096
|
+
queue.push({ slot });
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
function recordExternalStoreCheck(getSnapshot, value) {
|
|
1100
|
+
currentRuntime?.externalStoreChecks.push({ getSnapshot, value });
|
|
1101
|
+
}
|
|
1102
|
+
function flushPendingEffects(queue) {
|
|
1103
|
+
const pending = queue.splice(0);
|
|
1104
|
+
const strictReplay = [];
|
|
1105
|
+
for (const { slot } of pending) {
|
|
1106
|
+
if (slot.disposed === true) {
|
|
1107
|
+
continue;
|
|
1108
|
+
}
|
|
1109
|
+
slot.cleanup?.();
|
|
1110
|
+
const shouldReplay = slot.strictReplay === true && slot.cleanup === undefined;
|
|
1111
|
+
const cleanup = slot.callback();
|
|
1112
|
+
if (typeof cleanup === "function") {
|
|
1113
|
+
slot.cleanup = cleanup;
|
|
1114
|
+
}
|
|
1115
|
+
else {
|
|
1116
|
+
delete slot.cleanup;
|
|
1117
|
+
}
|
|
1118
|
+
if (shouldReplay) {
|
|
1119
|
+
strictReplay.push({ slot });
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
return strictReplay;
|
|
1123
|
+
}
|
|
1124
|
+
function replayStrictEffects(effects) {
|
|
1125
|
+
for (const { slot } of effects) {
|
|
1126
|
+
if (slot.disposed === true) {
|
|
1127
|
+
continue;
|
|
1128
|
+
}
|
|
1129
|
+
const cleanup = slot.callback();
|
|
1130
|
+
if (typeof cleanup === "function") {
|
|
1131
|
+
slot.cleanup = cleanup;
|
|
1132
|
+
}
|
|
1133
|
+
else {
|
|
1134
|
+
delete slot.cleanup;
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
function flushProfilerCommits(runtime, commits) {
|
|
1139
|
+
if (commits.length === 0) {
|
|
1140
|
+
return;
|
|
1141
|
+
}
|
|
1142
|
+
const commitTime = getCurrentTime();
|
|
1143
|
+
runtime.profilerFlushDepth += 1;
|
|
1144
|
+
try {
|
|
1145
|
+
for (const commit of commits) {
|
|
1146
|
+
commit.onRender(commit.id, commit.phase, commit.actualDuration, commit.baseDuration, commit.startTime, commitTime);
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
finally {
|
|
1150
|
+
runtime.profilerFlushDepth -= 1;
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
function runActionStateDispatch(slot, runtime, instance, payload) {
|
|
1154
|
+
let result;
|
|
1155
|
+
try {
|
|
1156
|
+
result = slot.action(slot.state, payload);
|
|
1157
|
+
}
|
|
1158
|
+
catch (error) {
|
|
1159
|
+
slot.error = error;
|
|
1160
|
+
scheduleInstanceUpdate(runtime, instance);
|
|
1161
|
+
return;
|
|
1162
|
+
}
|
|
1163
|
+
if (!isThenable(result)) {
|
|
1164
|
+
slot.state = result;
|
|
1165
|
+
scheduleInstanceUpdate(runtime, instance);
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
slot.pendingCount += 1;
|
|
1169
|
+
scheduleInstanceUpdate(runtime, instance);
|
|
1170
|
+
result.then((nextState) => {
|
|
1171
|
+
slot.state = nextState;
|
|
1172
|
+
slot.pendingCount = Math.max(0, slot.pendingCount - 1);
|
|
1173
|
+
scheduleInstanceUpdate(runtime, instance);
|
|
1174
|
+
}, (error) => {
|
|
1175
|
+
slot.error = error;
|
|
1176
|
+
slot.pendingCount = Math.max(0, slot.pendingCount - 1);
|
|
1177
|
+
scheduleInstanceUpdate(runtime, instance);
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1180
|
+
function scheduleInstanceUpdate(runtime, instance) {
|
|
1181
|
+
instance.dirty = true;
|
|
1182
|
+
if (transitionDepth === 0) {
|
|
1183
|
+
syncVersion += 1;
|
|
1184
|
+
if (eventBatchDepth > 0) {
|
|
1185
|
+
queueEventRerender(runtime);
|
|
1186
|
+
return;
|
|
1187
|
+
}
|
|
1188
|
+
runtime.rerender("sync");
|
|
1189
|
+
return;
|
|
1190
|
+
}
|
|
1191
|
+
if (currentTransitionContext !== undefined) {
|
|
1192
|
+
queueTransitionRerender(runtime, currentTransitionContext);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
function getCacheLeaf(scope, callback, args) {
|
|
1196
|
+
let node = scope.functionCaches.get(callback);
|
|
1197
|
+
if (node === undefined) {
|
|
1198
|
+
node = createCacheTrieNode();
|
|
1199
|
+
scope.functionCaches.set(callback, node);
|
|
1200
|
+
}
|
|
1201
|
+
for (const arg of args) {
|
|
1202
|
+
node = getCacheChild(node, arg);
|
|
1203
|
+
}
|
|
1204
|
+
return node;
|
|
1205
|
+
}
|
|
1206
|
+
function getCacheChild(node, key) {
|
|
1207
|
+
if ((typeof key === "object" && key !== null) || typeof key === "function") {
|
|
1208
|
+
const objectKey = key;
|
|
1209
|
+
let child = node.objectChildren.get(objectKey);
|
|
1210
|
+
if (child === undefined) {
|
|
1211
|
+
child = createCacheTrieNode();
|
|
1212
|
+
node.objectChildren.set(objectKey, child);
|
|
1213
|
+
}
|
|
1214
|
+
return child;
|
|
1215
|
+
}
|
|
1216
|
+
let child = node.primitiveChildren.get(key);
|
|
1217
|
+
if (child === undefined) {
|
|
1218
|
+
child = createCacheTrieNode();
|
|
1219
|
+
node.primitiveChildren.set(key, child);
|
|
1220
|
+
}
|
|
1221
|
+
return child;
|
|
1222
|
+
}
|
|
1223
|
+
function createCacheTrieNode() {
|
|
1224
|
+
return {
|
|
1225
|
+
primitiveChildren: new Map(),
|
|
1226
|
+
objectChildren: new WeakMap(),
|
|
1227
|
+
};
|
|
1228
|
+
}
|
|
1229
|
+
function getCurrentCacheScope() {
|
|
1230
|
+
return currentCacheScope ?? getGlobalCacheScope();
|
|
1231
|
+
}
|
|
1232
|
+
function getGlobalCacheScope() {
|
|
1233
|
+
return globalThis[CACHE_SCOPE_SYMBOL];
|
|
1234
|
+
}
|
|
1235
|
+
function setGlobalCacheScope(scope) {
|
|
1236
|
+
if (scope === undefined) {
|
|
1237
|
+
delete globalThis[CACHE_SCOPE_SYMBOL];
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
globalThis[CACHE_SCOPE_SYMBOL] = scope;
|
|
1241
|
+
}
|
|
1242
|
+
function cleanupStrictEffects(effects) {
|
|
1243
|
+
for (const { slot } of effects) {
|
|
1244
|
+
if (slot.disposed !== true) {
|
|
1245
|
+
slot.cleanup?.();
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
function cleanupInactiveInstances(runtime) {
|
|
1250
|
+
const activeInstanceKeys = runtime.activeInstanceKeys;
|
|
1251
|
+
if (activeInstanceKeys === undefined) {
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
for (const [key, instance] of runtime.instances) {
|
|
1255
|
+
if (!activeInstanceKeys.has(key)) {
|
|
1256
|
+
cleanupInstance(instance);
|
|
1257
|
+
runtime.instances.delete(key);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
function cleanupInstance(instance) {
|
|
1262
|
+
for (const slot of instance.hooks) {
|
|
1263
|
+
if (slot?.kind === "effect") {
|
|
1264
|
+
slot.disposed = true;
|
|
1265
|
+
slot.cleanup?.();
|
|
1266
|
+
delete slot.cleanup;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
function requireRuntime() {
|
|
1271
|
+
if (currentRuntime === undefined) {
|
|
1272
|
+
throw new Error("Hooks can only be called while rendering.");
|
|
1273
|
+
}
|
|
1274
|
+
return currentRuntime;
|
|
1275
|
+
}
|
|
1276
|
+
function requireInstance() {
|
|
1277
|
+
if (currentInstance === undefined) {
|
|
1278
|
+
throw new Error("Hooks can only be called while rendering.");
|
|
1279
|
+
}
|
|
1280
|
+
return currentInstance;
|
|
1281
|
+
}
|
|
1282
|
+
function areHookInputsEqual(nextDeps, previousDeps) {
|
|
1283
|
+
if (nextDeps.length !== previousDeps.length) {
|
|
1284
|
+
return false;
|
|
1285
|
+
}
|
|
1286
|
+
for (let index = 0; index < nextDeps.length; index += 1) {
|
|
1287
|
+
if (!Object.is(nextDeps[index], previousDeps[index])) {
|
|
1288
|
+
return false;
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
return true;
|
|
1292
|
+
}
|
|
1293
|
+
function getCurrentTime() {
|
|
1294
|
+
return typeof performance === "undefined" ? Date.now() : performance.now();
|
|
1295
|
+
}
|
|
1296
|
+
//# sourceMappingURL=hooks.js.map
|