@italone/solace 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/dist/devtools.cjs +8 -0
- package/dist/devtools.d.ts +54 -0
- package/dist/devtools.js +1 -0
- package/dist/h-B1loyNPC.js +53 -0
- package/dist/h-CSqpvOof.cjs +56 -0
- package/dist/index-CkECgTuy.js +91 -0
- package/dist/index-rtpmWox-.cjs +96 -0
- package/dist/index.cjs +1414 -0
- package/dist/index.d.ts +115 -0
- package/dist/index.js +1394 -0
- package/dist/jsx-dev-runtime.cjs +13 -0
- package/dist/jsx-dev-runtime.d.ts +7 -0
- package/dist/jsx-dev-runtime.js +9 -0
- package/dist/jsx-runtime.cjs +40 -0
- package/dist/jsx-runtime.d.ts +24 -0
- package/dist/jsx-runtime.js +37 -0
- package/dist/vnode-zJOgBYFm.d.ts +43 -0
- package/docs/api.md +302 -0
- package/docs/architecture.md +80 -0
- package/docs/devtools.md +145 -0
- package/docs/examples.md +78 -0
- package/docs/package-usage.md +96 -0
- package/docs/performance.md +230 -0
- package/docs/release.md +67 -0
- package/package.json +87 -0
- package/readme.md +632 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1394 @@
|
|
|
1
|
+
import { h as hasDevtoolsListeners, e as emitDevtoolsEvent } from './index-CkECgTuy.js';
|
|
2
|
+
import { S as ShapeFlags, h, F as Fragment } from './h-B1loyNPC.js';
|
|
3
|
+
|
|
4
|
+
const targetMap = new WeakMap();
|
|
5
|
+
let activeEffect;
|
|
6
|
+
class ReactiveEffect {
|
|
7
|
+
constructor(fn, scheduler) {
|
|
8
|
+
this.fn = fn;
|
|
9
|
+
this.scheduler = scheduler;
|
|
10
|
+
this.active = true;
|
|
11
|
+
this.deps = [];
|
|
12
|
+
}
|
|
13
|
+
run() {
|
|
14
|
+
if (!this.active) {
|
|
15
|
+
return this.fn();
|
|
16
|
+
}
|
|
17
|
+
return runEffect(this);
|
|
18
|
+
}
|
|
19
|
+
stop() {
|
|
20
|
+
if (!this.active) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
cleanupEffect(this);
|
|
24
|
+
this.active = false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function runEffect(reactiveEffect) {
|
|
28
|
+
const parentEffect = activeEffect;
|
|
29
|
+
cleanupEffect(reactiveEffect);
|
|
30
|
+
activeEffect = reactiveEffect;
|
|
31
|
+
try {
|
|
32
|
+
return reactiveEffect.fn();
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
activeEffect = parentEffect;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function cleanupEffect(reactiveEffect) {
|
|
39
|
+
reactiveEffect.deps.forEach((dep) => {
|
|
40
|
+
dep.delete(reactiveEffect);
|
|
41
|
+
});
|
|
42
|
+
reactiveEffect.deps.length = 0;
|
|
43
|
+
}
|
|
44
|
+
function effect(fn) {
|
|
45
|
+
const reactiveEffect = new ReactiveEffect(fn);
|
|
46
|
+
reactiveEffect.run();
|
|
47
|
+
return reactiveEffect.run.bind(reactiveEffect);
|
|
48
|
+
}
|
|
49
|
+
function track(target, key) {
|
|
50
|
+
if (activeEffect === undefined) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
let depsMap = targetMap.get(target);
|
|
54
|
+
if (depsMap === undefined) {
|
|
55
|
+
depsMap = new Map();
|
|
56
|
+
targetMap.set(target, depsMap);
|
|
57
|
+
}
|
|
58
|
+
let dep = depsMap.get(key);
|
|
59
|
+
if (dep === undefined) {
|
|
60
|
+
dep = new Set();
|
|
61
|
+
depsMap.set(key, dep);
|
|
62
|
+
}
|
|
63
|
+
if (dep.has(activeEffect)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
dep.add(activeEffect);
|
|
67
|
+
activeEffect.deps.push(dep);
|
|
68
|
+
}
|
|
69
|
+
function trigger(target, key) {
|
|
70
|
+
const dep = targetMap.get(target)?.get(key);
|
|
71
|
+
if (dep === undefined) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const effects = new Set(dep);
|
|
75
|
+
let scheduledEffects = 0;
|
|
76
|
+
let runEffects = 0;
|
|
77
|
+
effects.forEach((reactiveEffect) => {
|
|
78
|
+
if (!reactiveEffect.active) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (reactiveEffect.scheduler !== undefined) {
|
|
82
|
+
scheduledEffects += 1;
|
|
83
|
+
reactiveEffect.scheduler();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
runEffects += 1;
|
|
87
|
+
reactiveEffect.run();
|
|
88
|
+
});
|
|
89
|
+
emitReactivityTriggerDevtoolsEvent(target, key, scheduledEffects, runEffects);
|
|
90
|
+
}
|
|
91
|
+
function emitReactivityTriggerDevtoolsEvent(target, key, scheduledEffects, runEffects) {
|
|
92
|
+
if (!hasDevtoolsListeners()) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
emitDevtoolsEvent({
|
|
96
|
+
type: "reactivity:trigger",
|
|
97
|
+
targetType: getDevtoolsTargetType(target),
|
|
98
|
+
keyType: typeof key,
|
|
99
|
+
effectCount: scheduledEffects + runEffects,
|
|
100
|
+
scheduledEffects,
|
|
101
|
+
runEffects,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function getDevtoolsTargetType(target) {
|
|
105
|
+
if (Array.isArray(target)) {
|
|
106
|
+
return "array";
|
|
107
|
+
}
|
|
108
|
+
return typeof target;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function computed(getter) {
|
|
112
|
+
let dirty = true;
|
|
113
|
+
let value;
|
|
114
|
+
const computedRef = {
|
|
115
|
+
get value() {
|
|
116
|
+
if (dirty) {
|
|
117
|
+
value = reactiveEffect.run();
|
|
118
|
+
dirty = false;
|
|
119
|
+
}
|
|
120
|
+
track(computedRef, "value");
|
|
121
|
+
return value;
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
const reactiveEffect = new ReactiveEffect(getter, () => {
|
|
125
|
+
if (!dirty) {
|
|
126
|
+
dirty = true;
|
|
127
|
+
trigger(computedRef, "value");
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
return computedRef;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const queue = [];
|
|
134
|
+
const queuedJobs = new Set();
|
|
135
|
+
const resolvedPromise = Promise.resolve();
|
|
136
|
+
let currentFlushPromise = null;
|
|
137
|
+
let dedupedJobs = 0;
|
|
138
|
+
function queueJob(job) {
|
|
139
|
+
if (queuedJobs.has(job)) {
|
|
140
|
+
if (hasDevtoolsListeners()) {
|
|
141
|
+
dedupedJobs += 1;
|
|
142
|
+
}
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
queuedJobs.add(job);
|
|
146
|
+
queue.push(job);
|
|
147
|
+
queueFlush();
|
|
148
|
+
}
|
|
149
|
+
function nextTick(callback) {
|
|
150
|
+
const promise = currentFlushPromise ?? resolvedPromise;
|
|
151
|
+
return callback === undefined ? promise : promise.then(callback);
|
|
152
|
+
}
|
|
153
|
+
function queueFlush() {
|
|
154
|
+
currentFlushPromise ?? (currentFlushPromise = resolvedPromise.then(flushJobs));
|
|
155
|
+
}
|
|
156
|
+
function flushJobs() {
|
|
157
|
+
const shouldEmitDevtoolsEvent = hasDevtoolsListeners();
|
|
158
|
+
const startedAt = shouldEmitDevtoolsEvent ? now() : 0;
|
|
159
|
+
let flushedJobs = 0;
|
|
160
|
+
try {
|
|
161
|
+
for (let index = 0; index < queue.length; index += 1) {
|
|
162
|
+
const job = queue[index];
|
|
163
|
+
job();
|
|
164
|
+
flushedJobs += 1;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
finally {
|
|
168
|
+
if (shouldEmitDevtoolsEvent) {
|
|
169
|
+
emitDevtoolsEvent({
|
|
170
|
+
type: "scheduler:flush",
|
|
171
|
+
queuedJobs: flushedJobs,
|
|
172
|
+
dedupedJobs,
|
|
173
|
+
durationMs: Math.max(0, now() - startedAt),
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
queue.length = 0;
|
|
177
|
+
queuedJobs.clear();
|
|
178
|
+
dedupedJobs = 0;
|
|
179
|
+
currentFlushPromise = null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function now() {
|
|
183
|
+
return globalThis.performance?.now() ?? Date.now();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
let currentInstance = null;
|
|
187
|
+
function setCurrentInstance(instance) {
|
|
188
|
+
currentInstance = instance;
|
|
189
|
+
}
|
|
190
|
+
function getCurrentInstance() {
|
|
191
|
+
return currentInstance;
|
|
192
|
+
}
|
|
193
|
+
function onMounted(hook) {
|
|
194
|
+
injectHook("mounted", hook);
|
|
195
|
+
}
|
|
196
|
+
function onUpdated(hook) {
|
|
197
|
+
injectHook("updated", hook);
|
|
198
|
+
}
|
|
199
|
+
function onUnmounted(hook) {
|
|
200
|
+
injectHook("unmounted", hook);
|
|
201
|
+
}
|
|
202
|
+
function callHooks(hooks) {
|
|
203
|
+
for (const hook of hooks) {
|
|
204
|
+
hook();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function injectHook(type, hook) {
|
|
208
|
+
if (currentInstance === null) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
currentInstance[type].push(hook);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function initProps(instance, rawProps) {
|
|
215
|
+
instance.props = normalizeProps(rawProps);
|
|
216
|
+
}
|
|
217
|
+
function updateProps(instance, rawProps) {
|
|
218
|
+
const nextProps = normalizeProps(rawProps);
|
|
219
|
+
for (const key of Object.keys(instance.props)) {
|
|
220
|
+
if (!(key in nextProps)) {
|
|
221
|
+
delete instance.props[key];
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
for (const [key, value] of Object.entries(nextProps)) {
|
|
225
|
+
instance.props[key] = value;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function normalizeProps(rawProps) {
|
|
229
|
+
if (rawProps === null) {
|
|
230
|
+
return {};
|
|
231
|
+
}
|
|
232
|
+
const props = {};
|
|
233
|
+
for (const [key, value] of Object.entries(rawProps)) {
|
|
234
|
+
if (key !== "key") {
|
|
235
|
+
props[key] = value;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return props;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
let nextComponentDevtoolsId = 1;
|
|
242
|
+
function createComponentInstance(vnode, parent = null, appProvides = parent?.appProvides ?? null) {
|
|
243
|
+
const instance = {
|
|
244
|
+
vnode,
|
|
245
|
+
type: vnode.type,
|
|
246
|
+
parent,
|
|
247
|
+
appProvides,
|
|
248
|
+
props: {},
|
|
249
|
+
provides: new Map(),
|
|
250
|
+
slots: {},
|
|
251
|
+
setupState: {},
|
|
252
|
+
subTree: null,
|
|
253
|
+
devtoolsId: nextComponentDevtoolsId,
|
|
254
|
+
isMounted: false,
|
|
255
|
+
isUnmounted: false,
|
|
256
|
+
isUpdateQueued: false,
|
|
257
|
+
render: () => {
|
|
258
|
+
throw new Error("Component render function called before setup");
|
|
259
|
+
},
|
|
260
|
+
effect: null,
|
|
261
|
+
update: null,
|
|
262
|
+
emit: () => undefined,
|
|
263
|
+
mounted: [],
|
|
264
|
+
updated: [],
|
|
265
|
+
unmounted: [],
|
|
266
|
+
};
|
|
267
|
+
nextComponentDevtoolsId += 1;
|
|
268
|
+
instance.emit = emit.bind(null, instance);
|
|
269
|
+
return instance;
|
|
270
|
+
}
|
|
271
|
+
function getComponentDevtoolsName(instance) {
|
|
272
|
+
return instance.type.name || "AnonymousComponent";
|
|
273
|
+
}
|
|
274
|
+
function setupComponent(instance) {
|
|
275
|
+
initProps(instance, instance.vnode.props);
|
|
276
|
+
initSlots(instance, instance.vnode.children);
|
|
277
|
+
let resolvedRender = null;
|
|
278
|
+
let hasResolvedSetup = false;
|
|
279
|
+
const setupContext = {
|
|
280
|
+
emit: instance.emit,
|
|
281
|
+
slots: instance.slots,
|
|
282
|
+
};
|
|
283
|
+
instance.render = () => {
|
|
284
|
+
if (resolvedRender !== null) {
|
|
285
|
+
return resolvedRender();
|
|
286
|
+
}
|
|
287
|
+
const setupResult = runComponentSetup(instance, setupContext, hasResolvedSetup);
|
|
288
|
+
hasResolvedSetup = true;
|
|
289
|
+
if (typeof setupResult === "function") {
|
|
290
|
+
resolvedRender = setupResult;
|
|
291
|
+
return resolvedRender();
|
|
292
|
+
}
|
|
293
|
+
return setupResult;
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
function updateComponentProps(instance, nextVNode) {
|
|
297
|
+
instance.vnode = nextVNode;
|
|
298
|
+
updateProps(instance, nextVNode.props);
|
|
299
|
+
initSlots(instance, nextVNode.children);
|
|
300
|
+
}
|
|
301
|
+
function runComponentSetup(instance, setupContext, hasResolvedSetup) {
|
|
302
|
+
if (hasResolvedSetup) {
|
|
303
|
+
return instance.type(instance.props, setupContext);
|
|
304
|
+
}
|
|
305
|
+
setCurrentInstance(instance);
|
|
306
|
+
try {
|
|
307
|
+
return instance.type(instance.props, setupContext);
|
|
308
|
+
}
|
|
309
|
+
finally {
|
|
310
|
+
setCurrentInstance(null);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function initSlots(instance, children) {
|
|
314
|
+
for (const key of Object.keys(instance.slots)) {
|
|
315
|
+
delete instance.slots[key];
|
|
316
|
+
}
|
|
317
|
+
if (children === null) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (isVNodeSlots(children)) {
|
|
321
|
+
for (const [name, slot] of Object.entries(children)) {
|
|
322
|
+
if (typeof slot === "function") {
|
|
323
|
+
instance.slots[name] = slot;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
instance.slots.default = () => children;
|
|
329
|
+
}
|
|
330
|
+
function emit(instance, event, ...args) {
|
|
331
|
+
const handler = resolveEmitHandler(instance.vnode.props, event);
|
|
332
|
+
emitComponentEmitDevtoolsEvent(instance, event, handler);
|
|
333
|
+
if (typeof handler === "function") {
|
|
334
|
+
handler(...args);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (Array.isArray(handler)) {
|
|
338
|
+
for (const item of handler) {
|
|
339
|
+
if (typeof item === "function") {
|
|
340
|
+
item(...args);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
function emitComponentEmitDevtoolsEvent(instance, event, handler) {
|
|
346
|
+
if (!hasDevtoolsListeners()) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
emitDevtoolsEvent({
|
|
350
|
+
type: "component:emit",
|
|
351
|
+
id: instance.devtoolsId,
|
|
352
|
+
name: getComponentDevtoolsName(instance),
|
|
353
|
+
event,
|
|
354
|
+
handlerCount: countEmitHandlers(handler),
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
function countEmitHandlers(handler) {
|
|
358
|
+
if (typeof handler === "function") {
|
|
359
|
+
return 1;
|
|
360
|
+
}
|
|
361
|
+
if (Array.isArray(handler)) {
|
|
362
|
+
return handler.filter((item) => typeof item === "function").length;
|
|
363
|
+
}
|
|
364
|
+
return 0;
|
|
365
|
+
}
|
|
366
|
+
function resolveEmitHandler(props, event) {
|
|
367
|
+
if (props === null) {
|
|
368
|
+
return undefined;
|
|
369
|
+
}
|
|
370
|
+
return props[toHandlerKey(camelize(event))] ?? props[toHandlerKey(event)];
|
|
371
|
+
}
|
|
372
|
+
function toHandlerKey(event) {
|
|
373
|
+
return `on${event.charAt(0).toUpperCase()}${event.slice(1)}`;
|
|
374
|
+
}
|
|
375
|
+
function camelize(value) {
|
|
376
|
+
return value.replace(/-(\w)/g, (_, character) => character.toUpperCase());
|
|
377
|
+
}
|
|
378
|
+
function isVNodeSlots(children) {
|
|
379
|
+
return (children !== null &&
|
|
380
|
+
typeof children === "object" &&
|
|
381
|
+
!Array.isArray(children) &&
|
|
382
|
+
!("type" in children));
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function isEventProp(key) {
|
|
386
|
+
return /^on[A-Z]/.test(key);
|
|
387
|
+
}
|
|
388
|
+
function patchEvent(el, key, previousValue, nextValue) {
|
|
389
|
+
const invokers = getInvokers(el);
|
|
390
|
+
const existingInvoker = invokers[key];
|
|
391
|
+
const nextEventValue = normalizeEventValue(nextValue);
|
|
392
|
+
if (existingInvoker !== undefined && nextEventValue !== null) {
|
|
393
|
+
existingInvoker.value = nextEventValue;
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
const eventName = key.slice(2).toLowerCase();
|
|
397
|
+
if (nextEventValue !== null) {
|
|
398
|
+
const invoker = createInvoker(nextEventValue);
|
|
399
|
+
invokers[key] = invoker;
|
|
400
|
+
el.addEventListener(eventName, invoker);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
if (existingInvoker !== undefined) {
|
|
404
|
+
el.removeEventListener(eventName, existingInvoker);
|
|
405
|
+
invokers[key] = undefined;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function removeEvents(el) {
|
|
409
|
+
const invokers = el._vei;
|
|
410
|
+
if (invokers === undefined) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
for (const [key, invoker] of Object.entries(invokers)) {
|
|
414
|
+
if (invoker !== undefined) {
|
|
415
|
+
el.removeEventListener(key.slice(2).toLowerCase(), invoker);
|
|
416
|
+
invokers[key] = undefined;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
function getInvokers(el) {
|
|
421
|
+
const element = el;
|
|
422
|
+
element._vei ?? (element._vei = {});
|
|
423
|
+
return element._vei;
|
|
424
|
+
}
|
|
425
|
+
function createInvoker(initialValue) {
|
|
426
|
+
const invoker = ((event) => {
|
|
427
|
+
invoker.value(event);
|
|
428
|
+
});
|
|
429
|
+
invoker.value = initialValue;
|
|
430
|
+
return invoker;
|
|
431
|
+
}
|
|
432
|
+
function normalizeEventValue(value) {
|
|
433
|
+
return typeof value === "function" ? value : null;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function createElement(type) {
|
|
437
|
+
return document.createElement(type);
|
|
438
|
+
}
|
|
439
|
+
function insert(child, parent, anchor = null) {
|
|
440
|
+
parent.insertBefore(child, anchor);
|
|
441
|
+
}
|
|
442
|
+
function setText(node, text) {
|
|
443
|
+
node.textContent = text;
|
|
444
|
+
}
|
|
445
|
+
function remove(child) {
|
|
446
|
+
if (child instanceof Element) {
|
|
447
|
+
removeEvents(child);
|
|
448
|
+
}
|
|
449
|
+
child.parentNode?.removeChild(child);
|
|
450
|
+
}
|
|
451
|
+
function patchProp(el, key, previousValue, nextValue) {
|
|
452
|
+
if (isEventProp(key)) {
|
|
453
|
+
patchEvent(el, key, previousValue, nextValue);
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (nextValue === null || nextValue === undefined || nextValue === false) {
|
|
457
|
+
el.removeAttribute(key);
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
el.setAttribute(key, String(nextValue));
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
function patch(n1, n2, container, anchor = null, parentComponent = null, appProvides = parentComponent?.appProvides ?? null) {
|
|
464
|
+
if (n1 !== null && !isSameVNodeType(n1, n2)) {
|
|
465
|
+
const nextAnchor = n1.el?.nextSibling ?? anchor;
|
|
466
|
+
unmount(n1);
|
|
467
|
+
patch(null, n2, container, nextAnchor, parentComponent, appProvides);
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
if (n2.shapeFlag & ShapeFlags.ELEMENT) {
|
|
471
|
+
if (n1 === null) {
|
|
472
|
+
mountElement(n2, container, anchor, parentComponent, appProvides);
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
patchElement(n1, n2, parentComponent, appProvides);
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
if (n2.shapeFlag & ShapeFlags.FRAGMENT) {
|
|
479
|
+
if (n1 === null) {
|
|
480
|
+
mountFragment(n2, container, anchor, parentComponent, appProvides);
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
patchChildren(n1, n2, container, parentComponent, appProvides);
|
|
484
|
+
n2.el = getFragmentRoot(n2);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
if (n2.shapeFlag & ShapeFlags.COMPONENT) {
|
|
488
|
+
if (n1 === null) {
|
|
489
|
+
mountComponent(n2, container, anchor, parentComponent, appProvides);
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
updateComponent(n1, n2);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
function mountFragment(vnode, container, anchor, parentComponent, appProvides) {
|
|
496
|
+
if (vnode.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
|
|
497
|
+
const children = vnode.children;
|
|
498
|
+
if (canBatchMountFragment(children)) {
|
|
499
|
+
const fragment = document.createDocumentFragment();
|
|
500
|
+
for (const child of children) {
|
|
501
|
+
patch(null, child, fragment, null, parentComponent, appProvides);
|
|
502
|
+
}
|
|
503
|
+
insert(fragment, container, anchor);
|
|
504
|
+
vnode.el = getFragmentRoot(vnode);
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
for (const child of children) {
|
|
508
|
+
patch(null, child, container, anchor, parentComponent, appProvides);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
vnode.el = getFragmentRoot(vnode);
|
|
512
|
+
}
|
|
513
|
+
function canBatchMountFragment(children) {
|
|
514
|
+
return children.length > 0;
|
|
515
|
+
}
|
|
516
|
+
function mountElement(vnode, container, anchor, parentComponent, appProvides) {
|
|
517
|
+
const el = createElement(vnode.type);
|
|
518
|
+
vnode.el = el;
|
|
519
|
+
if (vnode.props) {
|
|
520
|
+
mountInitialProps(el, vnode.props);
|
|
521
|
+
}
|
|
522
|
+
if (vnode.shapeFlag & ShapeFlags.TEXT_CHILDREN) {
|
|
523
|
+
setText(el, vnode.children);
|
|
524
|
+
}
|
|
525
|
+
else if (vnode.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
|
|
526
|
+
mountChildren(vnode.children, el, parentComponent, appProvides);
|
|
527
|
+
}
|
|
528
|
+
insert(el, container, anchor);
|
|
529
|
+
emitRendererElementDevtoolsEvent("mount", vnode.type);
|
|
530
|
+
}
|
|
531
|
+
function mountComponent(vnode, container, anchor, parentComponent, appProvides) {
|
|
532
|
+
const instance = createComponentInstance(vnode, parentComponent, appProvides);
|
|
533
|
+
vnode.component = instance;
|
|
534
|
+
setupComponent(instance);
|
|
535
|
+
const componentUpdate = () => {
|
|
536
|
+
try {
|
|
537
|
+
if (instance.isUnmounted) {
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
if (!instance.isMounted) {
|
|
541
|
+
const subTree = instance.render();
|
|
542
|
+
instance.subTree = subTree;
|
|
543
|
+
patch(null, subTree, container, anchor, instance, instance.appProvides);
|
|
544
|
+
vnode.el = subTree.el;
|
|
545
|
+
instance.isMounted = true;
|
|
546
|
+
callHooks(instance.mounted);
|
|
547
|
+
emitComponentDevtoolsEvent("component:mount", instance);
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
const nextTree = instance.render();
|
|
551
|
+
const previousTree = instance.subTree;
|
|
552
|
+
patch(previousTree, nextTree, container, anchor, instance, instance.appProvides);
|
|
553
|
+
instance.subTree = nextTree;
|
|
554
|
+
instance.vnode.el = nextTree.el;
|
|
555
|
+
callHooks(instance.updated);
|
|
556
|
+
emitComponentDevtoolsEvent("component:update", instance);
|
|
557
|
+
}
|
|
558
|
+
finally {
|
|
559
|
+
instance.isUpdateQueued = false;
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
const reactiveEffect = new ReactiveEffect(componentUpdate, () => {
|
|
563
|
+
if (instance.update === null || instance.isUpdateQueued) {
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
instance.isUpdateQueued = true;
|
|
567
|
+
queueJob(instance.update);
|
|
568
|
+
});
|
|
569
|
+
instance.effect = reactiveEffect;
|
|
570
|
+
instance.update = reactiveEffect.run.bind(reactiveEffect);
|
|
571
|
+
instance.update();
|
|
572
|
+
}
|
|
573
|
+
function mountChildren(children, container, parentComponent, appProvides) {
|
|
574
|
+
if (canBatchMountChildren(children, 0, children.length - 1)) {
|
|
575
|
+
const fragment = document.createDocumentFragment();
|
|
576
|
+
for (const child of children) {
|
|
577
|
+
patch(null, child, fragment, null, parentComponent, appProvides);
|
|
578
|
+
}
|
|
579
|
+
insert(fragment, container, null);
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
for (const child of children) {
|
|
583
|
+
patch(null, child, container, null, parentComponent, appProvides);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
function updateComponent(n1, n2) {
|
|
587
|
+
const instance = n1.component;
|
|
588
|
+
n2.component = instance;
|
|
589
|
+
if (!shouldUpdateComponent(n1, n2)) {
|
|
590
|
+
instance.vnode = n2;
|
|
591
|
+
n2.el = n1.el;
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
updateComponentProps(instance, n2);
|
|
595
|
+
instance.update?.();
|
|
596
|
+
n2.el = instance.subTree?.el ?? null;
|
|
597
|
+
}
|
|
598
|
+
function shouldUpdateComponent(n1, n2) {
|
|
599
|
+
if (n1.children !== n2.children) {
|
|
600
|
+
return true;
|
|
601
|
+
}
|
|
602
|
+
return havePropsChanged(n1.props, n2.props);
|
|
603
|
+
}
|
|
604
|
+
function havePropsChanged(oldProps, newProps) {
|
|
605
|
+
if (oldProps === newProps) {
|
|
606
|
+
return false;
|
|
607
|
+
}
|
|
608
|
+
if (oldProps === null) {
|
|
609
|
+
return hasPatchableProps(newProps);
|
|
610
|
+
}
|
|
611
|
+
if (newProps === null) {
|
|
612
|
+
return hasPatchableProps(oldProps);
|
|
613
|
+
}
|
|
614
|
+
for (const key in oldProps) {
|
|
615
|
+
if (!hasOwnProp(oldProps, key) || key === "key") {
|
|
616
|
+
continue;
|
|
617
|
+
}
|
|
618
|
+
if (!hasOwnProp(newProps, key) || oldProps[key] !== newProps[key]) {
|
|
619
|
+
return true;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
for (const key in newProps) {
|
|
623
|
+
if (!hasOwnProp(newProps, key) || key === "key") {
|
|
624
|
+
continue;
|
|
625
|
+
}
|
|
626
|
+
if (!hasOwnProp(oldProps, key)) {
|
|
627
|
+
return true;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
return false;
|
|
631
|
+
}
|
|
632
|
+
function hasPatchableProps(props) {
|
|
633
|
+
if (props === null) {
|
|
634
|
+
return false;
|
|
635
|
+
}
|
|
636
|
+
for (const key in props) {
|
|
637
|
+
if (hasOwnProp(props, key) && key !== "key") {
|
|
638
|
+
return true;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
return false;
|
|
642
|
+
}
|
|
643
|
+
function hasOwnProp(props, key) {
|
|
644
|
+
return Object.prototype.hasOwnProperty.call(props, key);
|
|
645
|
+
}
|
|
646
|
+
function mountInitialProps(el, props) {
|
|
647
|
+
for (const key in props) {
|
|
648
|
+
if (!hasOwnProp(props, key) || key === "key") {
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
const value = props[key];
|
|
652
|
+
if (value === null || value === undefined || value === false) {
|
|
653
|
+
continue;
|
|
654
|
+
}
|
|
655
|
+
if (key === "class") {
|
|
656
|
+
mountInitialClass(el, value);
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
if (mightBeEventProp(key)) {
|
|
660
|
+
patchProp(el, key, null, value);
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
el.setAttribute(key, String(value));
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
function mountInitialClass(el, value) {
|
|
667
|
+
if (el instanceof HTMLElement) {
|
|
668
|
+
el.className = String(value);
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
el.setAttribute("class", String(value));
|
|
672
|
+
}
|
|
673
|
+
function mightBeEventProp(key) {
|
|
674
|
+
return key.length > 2 && key[0] === "o" && key[1] === "n" && isEventProp(key);
|
|
675
|
+
}
|
|
676
|
+
function patchElement(n1, n2, parentComponent, appProvides) {
|
|
677
|
+
const el = n1.el;
|
|
678
|
+
n2.el = el;
|
|
679
|
+
const propsChanged = havePropsChanged(n1.props, n2.props);
|
|
680
|
+
const childrenChanged = haveElementChildrenChanged(n1, n2);
|
|
681
|
+
if (!propsChanged && !childrenChanged) {
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
if (propsChanged) {
|
|
685
|
+
patchProps(el, n1.props, n2.props);
|
|
686
|
+
}
|
|
687
|
+
if (childrenChanged) {
|
|
688
|
+
patchChildren(n1, n2, el, parentComponent, appProvides);
|
|
689
|
+
}
|
|
690
|
+
emitRendererElementDevtoolsEvent("update", n2.type);
|
|
691
|
+
}
|
|
692
|
+
function haveElementChildrenChanged(n1, n2) {
|
|
693
|
+
const oldShapeFlag = n1.shapeFlag;
|
|
694
|
+
const newShapeFlag = n2.shapeFlag;
|
|
695
|
+
const oldHasTextChildren = Boolean(oldShapeFlag & ShapeFlags.TEXT_CHILDREN);
|
|
696
|
+
const newHasTextChildren = Boolean(newShapeFlag & ShapeFlags.TEXT_CHILDREN);
|
|
697
|
+
const oldHasArrayChildren = Boolean(oldShapeFlag & ShapeFlags.ARRAY_CHILDREN);
|
|
698
|
+
const newHasArrayChildren = Boolean(newShapeFlag & ShapeFlags.ARRAY_CHILDREN);
|
|
699
|
+
if (oldHasTextChildren || newHasTextChildren) {
|
|
700
|
+
return !oldHasTextChildren || !newHasTextChildren || n1.children !== n2.children;
|
|
701
|
+
}
|
|
702
|
+
if (oldHasArrayChildren || newHasArrayChildren) {
|
|
703
|
+
return !oldHasArrayChildren || !newHasArrayChildren || n1.children !== n2.children;
|
|
704
|
+
}
|
|
705
|
+
return false;
|
|
706
|
+
}
|
|
707
|
+
function patchProps(el, oldProps, newProps) {
|
|
708
|
+
const previousProps = oldProps ?? {};
|
|
709
|
+
const nextProps = newProps ?? {};
|
|
710
|
+
for (const [key, nextValue] of Object.entries(nextProps)) {
|
|
711
|
+
if (key === "key") {
|
|
712
|
+
continue;
|
|
713
|
+
}
|
|
714
|
+
const previousValue = previousProps[key];
|
|
715
|
+
if (previousValue !== nextValue) {
|
|
716
|
+
patchProp(el, key, previousValue, nextValue);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
for (const key of Object.keys(previousProps)) {
|
|
720
|
+
if (key !== "key" && !(key in nextProps)) {
|
|
721
|
+
patchProp(el, key, previousProps[key], null);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
function patchChildren(n1, n2, container, parentComponent, appProvides) {
|
|
726
|
+
const oldChildren = n1.children;
|
|
727
|
+
const newChildren = n2.children;
|
|
728
|
+
const oldShapeFlag = n1.shapeFlag;
|
|
729
|
+
const newShapeFlag = n2.shapeFlag;
|
|
730
|
+
if (newShapeFlag & ShapeFlags.TEXT_CHILDREN) {
|
|
731
|
+
if (oldShapeFlag & ShapeFlags.ARRAY_CHILDREN) {
|
|
732
|
+
unmountChildren(oldChildren);
|
|
733
|
+
}
|
|
734
|
+
if (oldChildren !== newChildren) {
|
|
735
|
+
setText(container, newChildren);
|
|
736
|
+
}
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
if (newShapeFlag & ShapeFlags.ARRAY_CHILDREN) {
|
|
740
|
+
const nextChildren = newChildren;
|
|
741
|
+
if (oldShapeFlag & ShapeFlags.TEXT_CHILDREN) {
|
|
742
|
+
setText(container, "");
|
|
743
|
+
mountChildren(nextChildren, container, parentComponent, appProvides);
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
if (oldShapeFlag & ShapeFlags.ARRAY_CHILDREN) {
|
|
747
|
+
patchArrayChildren(oldChildren, nextChildren, container, parentComponent, appProvides);
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
mountChildren(nextChildren, container, parentComponent, appProvides);
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
if (oldShapeFlag & ShapeFlags.ARRAY_CHILDREN) {
|
|
754
|
+
unmountChildren(oldChildren);
|
|
755
|
+
}
|
|
756
|
+
else if (oldShapeFlag & ShapeFlags.TEXT_CHILDREN) {
|
|
757
|
+
setText(container, "");
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
function patchArrayChildren(oldChildren, newChildren, container, parentComponent, appProvides) {
|
|
761
|
+
if (hasUniqueKeys(oldChildren) && hasUniqueKeys(newChildren)) {
|
|
762
|
+
patchKeyedChildren(oldChildren, newChildren, container, parentComponent, appProvides);
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
patchUnkeyedChildren(oldChildren, newChildren, container, parentComponent, appProvides);
|
|
766
|
+
}
|
|
767
|
+
function patchUnkeyedChildren(oldChildren, newChildren, container, parentComponent, appProvides) {
|
|
768
|
+
const commonLength = Math.min(oldChildren.length, newChildren.length);
|
|
769
|
+
for (let index = 0; index < commonLength; index += 1) {
|
|
770
|
+
patch(oldChildren[index], newChildren[index], container, null, parentComponent, appProvides);
|
|
771
|
+
}
|
|
772
|
+
if (newChildren.length > oldChildren.length) {
|
|
773
|
+
mountNewChildren(newChildren, commonLength, newChildren.length - 1, container, null, parentComponent, appProvides);
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
unmountChildrenRange(oldChildren, commonLength, oldChildren.length - 1);
|
|
777
|
+
}
|
|
778
|
+
function patchKeyedChildren(oldChildren, newChildren, container, parentComponent, appProvides) {
|
|
779
|
+
let oldStart = 0;
|
|
780
|
+
let newStart = 0;
|
|
781
|
+
let oldEnd = oldChildren.length - 1;
|
|
782
|
+
let newEnd = newChildren.length - 1;
|
|
783
|
+
while (oldStart <= oldEnd &&
|
|
784
|
+
newStart <= newEnd &&
|
|
785
|
+
isSameVNodeType(oldChildren[oldStart], newChildren[newStart])) {
|
|
786
|
+
patch(oldChildren[oldStart], newChildren[newStart], container, null, parentComponent, appProvides);
|
|
787
|
+
oldStart += 1;
|
|
788
|
+
newStart += 1;
|
|
789
|
+
}
|
|
790
|
+
while (oldStart <= oldEnd &&
|
|
791
|
+
newStart <= newEnd &&
|
|
792
|
+
isSameVNodeType(oldChildren[oldEnd], newChildren[newEnd])) {
|
|
793
|
+
patch(oldChildren[oldEnd], newChildren[newEnd], container, null, parentComponent, appProvides);
|
|
794
|
+
oldEnd -= 1;
|
|
795
|
+
newEnd -= 1;
|
|
796
|
+
}
|
|
797
|
+
if (oldStart > oldEnd) {
|
|
798
|
+
const anchor = getAnchor(newChildren, newEnd + 1);
|
|
799
|
+
mountNewChildren(newChildren, newStart, newEnd, container, anchor, parentComponent, appProvides);
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
if (newStart > newEnd) {
|
|
803
|
+
unmountChildrenRange(oldChildren, oldStart, oldEnd);
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
const oldKeyedChildren = new Map();
|
|
807
|
+
const newIndexToOldIndexMap = new Array(newEnd - newStart + 1).fill(0);
|
|
808
|
+
const usedOldChildren = new Set();
|
|
809
|
+
for (let index = oldStart; index <= oldEnd; index += 1) {
|
|
810
|
+
const oldChild = oldChildren[index];
|
|
811
|
+
if (oldChild.key !== null) {
|
|
812
|
+
oldKeyedChildren.set(oldChild.key, {
|
|
813
|
+
vnode: oldChild,
|
|
814
|
+
index,
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
for (let index = newStart; index <= newEnd; index += 1) {
|
|
819
|
+
const newChild = newChildren[index];
|
|
820
|
+
const oldRecord = oldKeyedChildren.get(newChild.key) ?? null;
|
|
821
|
+
if (oldRecord !== null) {
|
|
822
|
+
usedOldChildren.add(oldRecord.vnode);
|
|
823
|
+
newIndexToOldIndexMap[index - newStart] = oldRecord.index + 1;
|
|
824
|
+
patch(oldRecord.vnode, newChild, container, null, parentComponent, appProvides);
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
unmountUnusedKeyedChildren(oldChildren, oldStart, oldEnd, usedOldChildren);
|
|
828
|
+
const stablePositions = getIncreasingSubsequence(newIndexToOldIndexMap);
|
|
829
|
+
let stableIndex = stablePositions.length - 1;
|
|
830
|
+
for (let index = newEnd; index >= newStart; index -= 1) {
|
|
831
|
+
if (newIndexToOldIndexMap[index - newStart] === 0) {
|
|
832
|
+
const runStart = getNewRunStart(newIndexToOldIndexMap, newStart, index);
|
|
833
|
+
if (runStart < index && canBatchMountChildren(newChildren, runStart, index)) {
|
|
834
|
+
mountNewChildren(newChildren, runStart, index, container, getAnchor(newChildren, index + 1), parentComponent, appProvides);
|
|
835
|
+
index = runStart;
|
|
836
|
+
continue;
|
|
837
|
+
}
|
|
838
|
+
patch(null, newChildren[index], container, getAnchor(newChildren, index + 1), parentComponent, appProvides);
|
|
839
|
+
continue;
|
|
840
|
+
}
|
|
841
|
+
const childEl = newChildren[index].el;
|
|
842
|
+
if (childEl === null) {
|
|
843
|
+
continue;
|
|
844
|
+
}
|
|
845
|
+
if (stableIndex >= 0 && index - newStart === stablePositions[stableIndex]) {
|
|
846
|
+
stableIndex -= 1;
|
|
847
|
+
continue;
|
|
848
|
+
}
|
|
849
|
+
insert(childEl, container, getAnchor(newChildren, index + 1));
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
function getNewRunStart(newIndexToOldIndexMap, newStart, index) {
|
|
853
|
+
let start = index;
|
|
854
|
+
while (start > newStart && newIndexToOldIndexMap[start - 1 - newStart] === 0) {
|
|
855
|
+
start -= 1;
|
|
856
|
+
}
|
|
857
|
+
return start;
|
|
858
|
+
}
|
|
859
|
+
function unmountUnusedKeyedChildren(children, start, end, usedChildren) {
|
|
860
|
+
let index = start;
|
|
861
|
+
while (index <= end) {
|
|
862
|
+
if (usedChildren.has(children[index])) {
|
|
863
|
+
index += 1;
|
|
864
|
+
continue;
|
|
865
|
+
}
|
|
866
|
+
const runStart = index;
|
|
867
|
+
while (index <= end && !usedChildren.has(children[index])) {
|
|
868
|
+
index += 1;
|
|
869
|
+
}
|
|
870
|
+
unmountChildrenRange(children, runStart, index - 1);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
function mountNewChildren(children, start, end, container, anchor, parentComponent, appProvides) {
|
|
874
|
+
if (canBatchMountChildren(children, start, end)) {
|
|
875
|
+
const fragment = document.createDocumentFragment();
|
|
876
|
+
for (let index = start; index <= end; index += 1) {
|
|
877
|
+
patch(null, children[index], fragment, null, parentComponent, appProvides);
|
|
878
|
+
}
|
|
879
|
+
insert(fragment, container, anchor);
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
for (let index = start; index <= end; index += 1) {
|
|
883
|
+
patch(null, children[index], container, anchor, parentComponent, appProvides);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
function canBatchMountChildren(children, start, end) {
|
|
887
|
+
return start <= end;
|
|
888
|
+
}
|
|
889
|
+
function unmountChildrenRange(children, start, end) {
|
|
890
|
+
if (canBatchRemoveChildren(children, start, end)) {
|
|
891
|
+
const fragment = document.createDocumentFragment();
|
|
892
|
+
for (let index = start; index <= end; index += 1) {
|
|
893
|
+
fragment.appendChild(children[index].el);
|
|
894
|
+
}
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
for (let index = start; index <= end; index += 1) {
|
|
898
|
+
unmount(children[index]);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
function canBatchRemoveChildren(children, start, end) {
|
|
902
|
+
if (start > end || hasDevtoolsListeners()) {
|
|
903
|
+
return false;
|
|
904
|
+
}
|
|
905
|
+
let parent = null;
|
|
906
|
+
for (let index = start; index <= end; index += 1) {
|
|
907
|
+
const child = children[index];
|
|
908
|
+
if (!(child.shapeFlag & ShapeFlags.ELEMENT) ||
|
|
909
|
+
child.shapeFlag & ShapeFlags.ARRAY_CHILDREN ||
|
|
910
|
+
child.el === null ||
|
|
911
|
+
hasEventProps(child.props)) {
|
|
912
|
+
return false;
|
|
913
|
+
}
|
|
914
|
+
parent ?? (parent = child.el.parentNode);
|
|
915
|
+
if (parent === null || child.el.parentNode !== parent) {
|
|
916
|
+
return false;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
return true;
|
|
920
|
+
}
|
|
921
|
+
function hasEventProps(props) {
|
|
922
|
+
if (props === null) {
|
|
923
|
+
return false;
|
|
924
|
+
}
|
|
925
|
+
return Object.keys(props).some(isEventProp);
|
|
926
|
+
}
|
|
927
|
+
function getAnchor(children, index) {
|
|
928
|
+
return children[index]?.el ?? null;
|
|
929
|
+
}
|
|
930
|
+
function getIncreasingSubsequence(source) {
|
|
931
|
+
const predecessors = source.slice();
|
|
932
|
+
const result = [];
|
|
933
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
934
|
+
const value = source[index];
|
|
935
|
+
if (value === 0) {
|
|
936
|
+
continue;
|
|
937
|
+
}
|
|
938
|
+
const lastResultIndex = result[result.length - 1];
|
|
939
|
+
if (result.length === 0 || source[lastResultIndex] < value) {
|
|
940
|
+
if (result.length > 0) {
|
|
941
|
+
predecessors[index] = lastResultIndex;
|
|
942
|
+
}
|
|
943
|
+
result.push(index);
|
|
944
|
+
continue;
|
|
945
|
+
}
|
|
946
|
+
let start = 0;
|
|
947
|
+
let end = result.length - 1;
|
|
948
|
+
while (start < end) {
|
|
949
|
+
const middle = Math.floor((start + end) / 2);
|
|
950
|
+
if (source[result[middle]] < value) {
|
|
951
|
+
start = middle + 1;
|
|
952
|
+
}
|
|
953
|
+
else {
|
|
954
|
+
end = middle;
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
if (value < source[result[start]]) {
|
|
958
|
+
if (start > 0) {
|
|
959
|
+
predecessors[index] = result[start - 1];
|
|
960
|
+
}
|
|
961
|
+
result[start] = index;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
if (result.length === 0) {
|
|
965
|
+
return [];
|
|
966
|
+
}
|
|
967
|
+
let current = result[result.length - 1];
|
|
968
|
+
for (let index = result.length - 1; index >= 0; index -= 1) {
|
|
969
|
+
result[index] = current;
|
|
970
|
+
current = predecessors[current];
|
|
971
|
+
}
|
|
972
|
+
return result;
|
|
973
|
+
}
|
|
974
|
+
function hasUniqueKeys(children) {
|
|
975
|
+
const keys = new Set();
|
|
976
|
+
for (const child of children) {
|
|
977
|
+
if (child.key === null || keys.has(child.key)) {
|
|
978
|
+
return false;
|
|
979
|
+
}
|
|
980
|
+
keys.add(child.key);
|
|
981
|
+
}
|
|
982
|
+
return children.length > 0;
|
|
983
|
+
}
|
|
984
|
+
function isSameVNodeType(n1, n2) {
|
|
985
|
+
return n1.type === n2.type && n1.key === n2.key;
|
|
986
|
+
}
|
|
987
|
+
function unmountChildren(children) {
|
|
988
|
+
for (const child of children) {
|
|
989
|
+
unmount(child);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
function unmount(vnode) {
|
|
993
|
+
if (vnode.shapeFlag & ShapeFlags.COMPONENT) {
|
|
994
|
+
const instance = vnode.component;
|
|
995
|
+
if (instance === null) {
|
|
996
|
+
return;
|
|
997
|
+
}
|
|
998
|
+
instance.isUnmounted = true;
|
|
999
|
+
instance.isMounted = false;
|
|
1000
|
+
instance.effect?.stop();
|
|
1001
|
+
instance.effect = null;
|
|
1002
|
+
instance.update = null;
|
|
1003
|
+
if (instance.subTree !== null) {
|
|
1004
|
+
unmount(instance.subTree);
|
|
1005
|
+
}
|
|
1006
|
+
callHooks(instance.unmounted);
|
|
1007
|
+
emitComponentDevtoolsEvent("component:unmount", instance);
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
1010
|
+
if (vnode.shapeFlag & ShapeFlags.FRAGMENT) {
|
|
1011
|
+
if (vnode.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
|
|
1012
|
+
unmountChildren(vnode.children);
|
|
1013
|
+
}
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
if (vnode.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
|
|
1017
|
+
unmountChildren(vnode.children);
|
|
1018
|
+
}
|
|
1019
|
+
if (vnode.el !== null) {
|
|
1020
|
+
remove(vnode.el);
|
|
1021
|
+
emitRendererElementDevtoolsEvent("unmount", vnode.type);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
function getFragmentRoot(vnode) {
|
|
1025
|
+
if (!(vnode.shapeFlag & ShapeFlags.ARRAY_CHILDREN)) {
|
|
1026
|
+
return null;
|
|
1027
|
+
}
|
|
1028
|
+
return vnode.children[0]?.el ?? null;
|
|
1029
|
+
}
|
|
1030
|
+
function emitComponentDevtoolsEvent(type, instance) {
|
|
1031
|
+
if (!hasDevtoolsListeners()) {
|
|
1032
|
+
return;
|
|
1033
|
+
}
|
|
1034
|
+
emitDevtoolsEvent({
|
|
1035
|
+
type,
|
|
1036
|
+
id: instance.devtoolsId,
|
|
1037
|
+
name: getComponentDevtoolsName(instance),
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
function emitRendererElementDevtoolsEvent(operation, tag) {
|
|
1041
|
+
if (!hasDevtoolsListeners()) {
|
|
1042
|
+
return;
|
|
1043
|
+
}
|
|
1044
|
+
emitDevtoolsEvent({
|
|
1045
|
+
type: "renderer:element",
|
|
1046
|
+
operation,
|
|
1047
|
+
tag,
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
function render(source, container, appProvides = null) {
|
|
1052
|
+
const renderContainer = container;
|
|
1053
|
+
if (typeof source === "function") {
|
|
1054
|
+
renderReactiveSource(source, renderContainer, appProvides);
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
stopReactiveRender(renderContainer);
|
|
1058
|
+
renderVNode(source, renderContainer, appProvides);
|
|
1059
|
+
}
|
|
1060
|
+
function renderReactiveSource(source, container, appProvides) {
|
|
1061
|
+
stopReactiveRender(container);
|
|
1062
|
+
const update = () => {
|
|
1063
|
+
renderVNode(source(), container, appProvides);
|
|
1064
|
+
};
|
|
1065
|
+
const reactiveEffect = new ReactiveEffect(update, () => {
|
|
1066
|
+
queueJob(job);
|
|
1067
|
+
});
|
|
1068
|
+
const runner = reactiveEffect.run.bind(reactiveEffect);
|
|
1069
|
+
const job = () => {
|
|
1070
|
+
if (container._solaceRenderEffect === reactiveEffect) {
|
|
1071
|
+
runner();
|
|
1072
|
+
}
|
|
1073
|
+
};
|
|
1074
|
+
container._solaceRenderEffect = reactiveEffect;
|
|
1075
|
+
runner();
|
|
1076
|
+
}
|
|
1077
|
+
function stopReactiveRender(container) {
|
|
1078
|
+
container._solaceRenderEffect?.stop();
|
|
1079
|
+
container._solaceRenderEffect = undefined;
|
|
1080
|
+
}
|
|
1081
|
+
function renderVNode(vnode, container, appProvides) {
|
|
1082
|
+
patch(container._solaceVNode ?? null, vnode, container, null, null, appProvides);
|
|
1083
|
+
container._solaceVNode = vnode;
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
function createApp(rootComponent) {
|
|
1087
|
+
const installedPlugins = new Set();
|
|
1088
|
+
const appProvides = new Map();
|
|
1089
|
+
const app = {
|
|
1090
|
+
mount(container) {
|
|
1091
|
+
const vnode = typeof rootComponent === "function" ? h(rootComponent) : rootComponent;
|
|
1092
|
+
render(vnode, container, appProvides);
|
|
1093
|
+
},
|
|
1094
|
+
provide(key, value) {
|
|
1095
|
+
appProvides.set(key, value);
|
|
1096
|
+
return app;
|
|
1097
|
+
},
|
|
1098
|
+
use(plugin, ...options) {
|
|
1099
|
+
if (installedPlugins.has(plugin)) {
|
|
1100
|
+
return app;
|
|
1101
|
+
}
|
|
1102
|
+
installedPlugins.add(plugin);
|
|
1103
|
+
if (typeof plugin === "function") {
|
|
1104
|
+
plugin(app, ...options);
|
|
1105
|
+
}
|
|
1106
|
+
else {
|
|
1107
|
+
plugin.install(app, ...options);
|
|
1108
|
+
}
|
|
1109
|
+
return app;
|
|
1110
|
+
},
|
|
1111
|
+
};
|
|
1112
|
+
return app;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
function hasChanged(value, oldValue) {
|
|
1116
|
+
return !Object.is(value, oldValue);
|
|
1117
|
+
}
|
|
1118
|
+
function isObject(value) {
|
|
1119
|
+
return value !== null && typeof value === "object";
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
function reactive(target) {
|
|
1123
|
+
if (!isObject(target)) {
|
|
1124
|
+
return target;
|
|
1125
|
+
}
|
|
1126
|
+
return new Proxy(target, {
|
|
1127
|
+
get(target, key, receiver) {
|
|
1128
|
+
const result = Reflect.get(target, key, receiver);
|
|
1129
|
+
track(target, key);
|
|
1130
|
+
return result;
|
|
1131
|
+
},
|
|
1132
|
+
set(target, key, value, receiver) {
|
|
1133
|
+
const oldValue = Reflect.get(target, key, receiver);
|
|
1134
|
+
const result = Reflect.set(target, key, value, receiver);
|
|
1135
|
+
if (hasChanged(value, oldValue)) {
|
|
1136
|
+
trigger(target, key);
|
|
1137
|
+
}
|
|
1138
|
+
return result;
|
|
1139
|
+
},
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
function ref(value) {
|
|
1144
|
+
const refObject = {
|
|
1145
|
+
get value() {
|
|
1146
|
+
track(refObject, "value");
|
|
1147
|
+
return value;
|
|
1148
|
+
},
|
|
1149
|
+
set value(newValue) {
|
|
1150
|
+
if (!hasChanged(newValue, value)) {
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
value = newValue;
|
|
1154
|
+
trigger(refObject, "value");
|
|
1155
|
+
},
|
|
1156
|
+
};
|
|
1157
|
+
return refObject;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
function watch(source, callback) {
|
|
1161
|
+
let oldValue;
|
|
1162
|
+
const job = () => {
|
|
1163
|
+
const newValue = reactiveEffect.run();
|
|
1164
|
+
callback(newValue, oldValue);
|
|
1165
|
+
oldValue = newValue;
|
|
1166
|
+
};
|
|
1167
|
+
const reactiveEffect = new ReactiveEffect(source, job);
|
|
1168
|
+
oldValue = reactiveEffect.run();
|
|
1169
|
+
return () => {
|
|
1170
|
+
reactiveEffect.stop();
|
|
1171
|
+
};
|
|
1172
|
+
}
|
|
1173
|
+
function watchEffect(effect) {
|
|
1174
|
+
const reactiveEffect = new ReactiveEffect(effect);
|
|
1175
|
+
reactiveEffect.run();
|
|
1176
|
+
return () => {
|
|
1177
|
+
reactiveEffect.stop();
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
function defineAsyncComponent(source) {
|
|
1182
|
+
const options = normalizeAsyncComponentOptions(source);
|
|
1183
|
+
let resolvedComponent = null;
|
|
1184
|
+
let pendingRequest = null;
|
|
1185
|
+
let loadError = null;
|
|
1186
|
+
let isLoadingVisible = getDelay(options) <= 0;
|
|
1187
|
+
let failedAttempts = 0;
|
|
1188
|
+
let activeAttemptId = 0;
|
|
1189
|
+
let delayTimer = null;
|
|
1190
|
+
let timeoutTimer = null;
|
|
1191
|
+
let retryTimer = null;
|
|
1192
|
+
return (props, { slots }) => {
|
|
1193
|
+
const instance = getCurrentInstance();
|
|
1194
|
+
const update = instance?.update ?? null;
|
|
1195
|
+
return () => {
|
|
1196
|
+
const children = normalizeSlotChildren(slots.default?.());
|
|
1197
|
+
if (resolvedComponent !== null) {
|
|
1198
|
+
return renderComponent(resolvedComponent, props, children);
|
|
1199
|
+
}
|
|
1200
|
+
if (loadError !== null) {
|
|
1201
|
+
return options.errorComponent
|
|
1202
|
+
? renderComponent(options.errorComponent, props, children)
|
|
1203
|
+
: h(Fragment, null, []);
|
|
1204
|
+
}
|
|
1205
|
+
if (pendingRequest === null && retryTimer === null && loadError === null) {
|
|
1206
|
+
startLoad(update);
|
|
1207
|
+
}
|
|
1208
|
+
return options.loadingComponent && isLoadingVisible
|
|
1209
|
+
? renderComponent(options.loadingComponent, props, children)
|
|
1210
|
+
: h(Fragment, null, []);
|
|
1211
|
+
};
|
|
1212
|
+
};
|
|
1213
|
+
function startLoad(update) {
|
|
1214
|
+
const attemptId = activeAttemptId + 1;
|
|
1215
|
+
activeAttemptId = attemptId;
|
|
1216
|
+
clearAttemptTimers();
|
|
1217
|
+
startDelayTimer(options, () => {
|
|
1218
|
+
if (attemptId !== activeAttemptId) {
|
|
1219
|
+
return;
|
|
1220
|
+
}
|
|
1221
|
+
isLoadingVisible = true;
|
|
1222
|
+
update?.();
|
|
1223
|
+
});
|
|
1224
|
+
startTimeoutTimer(options, () => {
|
|
1225
|
+
handleLoadFailure(new Error("Async component timed out"), attemptId, update);
|
|
1226
|
+
});
|
|
1227
|
+
pendingRequest = options
|
|
1228
|
+
.loader()
|
|
1229
|
+
.then((component) => {
|
|
1230
|
+
if (attemptId !== activeAttemptId || loadError !== null) {
|
|
1231
|
+
return;
|
|
1232
|
+
}
|
|
1233
|
+
clearAsyncTimers();
|
|
1234
|
+
pendingRequest = null;
|
|
1235
|
+
resolvedComponent = component;
|
|
1236
|
+
update?.();
|
|
1237
|
+
})
|
|
1238
|
+
.catch((error) => {
|
|
1239
|
+
handleLoadFailure(error, attemptId, update);
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
function handleLoadFailure(error, attemptId, update) {
|
|
1243
|
+
if (attemptId !== activeAttemptId || resolvedComponent !== null || loadError !== null) {
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
clearAttemptTimers();
|
|
1247
|
+
pendingRequest = null;
|
|
1248
|
+
failedAttempts += 1;
|
|
1249
|
+
if (failedAttempts <= getRetry(options)) {
|
|
1250
|
+
const retryDelay = getRetryDelay(options);
|
|
1251
|
+
if (retryDelay <= 0) {
|
|
1252
|
+
startLoad(update);
|
|
1253
|
+
return;
|
|
1254
|
+
}
|
|
1255
|
+
retryTimer = setTimeout(() => {
|
|
1256
|
+
retryTimer = null;
|
|
1257
|
+
startLoad(update);
|
|
1258
|
+
}, retryDelay);
|
|
1259
|
+
return;
|
|
1260
|
+
}
|
|
1261
|
+
loadError = error;
|
|
1262
|
+
update?.();
|
|
1263
|
+
}
|
|
1264
|
+
function startDelayTimer(currentOptions, onDelay) {
|
|
1265
|
+
const delay = getDelay(currentOptions);
|
|
1266
|
+
if (delay <= 0) {
|
|
1267
|
+
isLoadingVisible = true;
|
|
1268
|
+
return;
|
|
1269
|
+
}
|
|
1270
|
+
isLoadingVisible = false;
|
|
1271
|
+
delayTimer = setTimeout(onDelay, delay);
|
|
1272
|
+
}
|
|
1273
|
+
function startTimeoutTimer(currentOptions, onTimeout) {
|
|
1274
|
+
if (currentOptions.timeout === undefined) {
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
timeoutTimer = setTimeout(onTimeout, currentOptions.timeout);
|
|
1278
|
+
}
|
|
1279
|
+
function clearAsyncTimers() {
|
|
1280
|
+
clearAttemptTimers();
|
|
1281
|
+
if (retryTimer !== null) {
|
|
1282
|
+
clearTimeout(retryTimer);
|
|
1283
|
+
retryTimer = null;
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
function clearAttemptTimers() {
|
|
1287
|
+
if (delayTimer !== null) {
|
|
1288
|
+
clearTimeout(delayTimer);
|
|
1289
|
+
delayTimer = null;
|
|
1290
|
+
}
|
|
1291
|
+
if (timeoutTimer !== null) {
|
|
1292
|
+
clearTimeout(timeoutTimer);
|
|
1293
|
+
timeoutTimer = null;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
function normalizeAsyncComponentOptions(source) {
|
|
1298
|
+
return typeof source === "function" ? { loader: source } : source;
|
|
1299
|
+
}
|
|
1300
|
+
function renderComponent(component, props, children) {
|
|
1301
|
+
return h(component, props, children);
|
|
1302
|
+
}
|
|
1303
|
+
function normalizeSlotChildren(children) {
|
|
1304
|
+
return children ?? null;
|
|
1305
|
+
}
|
|
1306
|
+
function getDelay(options) {
|
|
1307
|
+
return options.delay ?? 0;
|
|
1308
|
+
}
|
|
1309
|
+
function getRetry(options) {
|
|
1310
|
+
return options.retry ?? 0;
|
|
1311
|
+
}
|
|
1312
|
+
function getRetryDelay(options) {
|
|
1313
|
+
return options.retryDelay ?? 0;
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
function defineComponent(component) {
|
|
1317
|
+
return component;
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
function provide(key, value) {
|
|
1321
|
+
const instance = getCurrentInstance();
|
|
1322
|
+
if (instance === null) {
|
|
1323
|
+
return;
|
|
1324
|
+
}
|
|
1325
|
+
instance.provides.set(key, value);
|
|
1326
|
+
}
|
|
1327
|
+
function inject(key, defaultValue) {
|
|
1328
|
+
const instance = getCurrentInstance();
|
|
1329
|
+
if (instance === null) {
|
|
1330
|
+
return defaultValue;
|
|
1331
|
+
}
|
|
1332
|
+
let parent = instance.parent;
|
|
1333
|
+
while (parent !== null) {
|
|
1334
|
+
if (parent.provides.has(key)) {
|
|
1335
|
+
return parent.provides.get(key);
|
|
1336
|
+
}
|
|
1337
|
+
parent = parent.parent;
|
|
1338
|
+
}
|
|
1339
|
+
if (instance.appProvides?.has(key)) {
|
|
1340
|
+
return instance.appProvides.get(key);
|
|
1341
|
+
}
|
|
1342
|
+
return defaultValue;
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
function createStore(options) {
|
|
1346
|
+
const state = reactive(options.state());
|
|
1347
|
+
const getterRefs = {};
|
|
1348
|
+
const getters = {};
|
|
1349
|
+
const context = {
|
|
1350
|
+
state,
|
|
1351
|
+
getters,
|
|
1352
|
+
};
|
|
1353
|
+
const actions = {};
|
|
1354
|
+
for (const [key, getter] of Object.entries(options.getters ?? {})) {
|
|
1355
|
+
getterRefs[key] = computed(() => getter({ state }));
|
|
1356
|
+
Object.defineProperty(getters, key, {
|
|
1357
|
+
enumerable: true,
|
|
1358
|
+
get: () => getterRefs[key]?.value,
|
|
1359
|
+
});
|
|
1360
|
+
}
|
|
1361
|
+
for (const [key, action] of Object.entries(options.actions ?? {})) {
|
|
1362
|
+
const runAction = action;
|
|
1363
|
+
actions[key] = ((...args) => {
|
|
1364
|
+
if (!hasDevtoolsListeners()) {
|
|
1365
|
+
return runAction(context, ...args);
|
|
1366
|
+
}
|
|
1367
|
+
const startedAt = performance.now();
|
|
1368
|
+
try {
|
|
1369
|
+
const result = runAction(context, ...args);
|
|
1370
|
+
emitStoreActionDevtoolsEvent(String(key), "success", startedAt);
|
|
1371
|
+
return result;
|
|
1372
|
+
}
|
|
1373
|
+
catch (error) {
|
|
1374
|
+
emitStoreActionDevtoolsEvent(String(key), "error", startedAt);
|
|
1375
|
+
throw error;
|
|
1376
|
+
}
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
return {
|
|
1380
|
+
state,
|
|
1381
|
+
getters,
|
|
1382
|
+
actions,
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
1385
|
+
function emitStoreActionDevtoolsEvent(name, status, startedAt) {
|
|
1386
|
+
emitDevtoolsEvent({
|
|
1387
|
+
type: "store:action",
|
|
1388
|
+
name,
|
|
1389
|
+
status,
|
|
1390
|
+
durationMs: performance.now() - startedAt,
|
|
1391
|
+
});
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
export { Fragment, computed, createApp, createStore, defineAsyncComponent, defineComponent, effect, h, inject, nextTick, onMounted, onUnmounted, onUpdated, provide, reactive, ref, render, watch, watchEffect };
|