@lynx-js/react 0.111.1 → 0.111.2
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/CHANGELOG.md +52 -0
- package/components/lib/DeferredListItem.d.ts +3 -1
- package/components/lib/DeferredListItem.jsx +4 -2
- package/components/lib/DeferredListItem.jsx.map +1 -1
- package/components/src/DeferredListItem.tsx +5 -3
- package/package.json +6 -1
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/debug/index.cjs +8 -0
- package/runtime/debug/index.d.ts +4 -0
- package/runtime/debug/index.js +5 -0
- package/runtime/lib/alog/index.d.ts +1 -0
- package/runtime/lib/alog/index.js +8 -0
- package/runtime/lib/alog/index.js.map +1 -0
- package/runtime/lib/alog/render.d.ts +1 -0
- package/runtime/lib/alog/render.js +19 -0
- package/runtime/lib/alog/render.js.map +1 -0
- package/runtime/lib/backgroundSnapshot.d.ts +1 -0
- package/runtime/lib/backgroundSnapshot.js +31 -17
- package/runtime/lib/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/debug/component-stack.d.ts +33 -0
- package/runtime/lib/debug/component-stack.js +145 -0
- package/runtime/lib/debug/component-stack.js.map +1 -0
- package/runtime/lib/debug/formatPatch.d.ts +2 -0
- package/runtime/lib/debug/formatPatch.js +27 -0
- package/runtime/lib/debug/formatPatch.js.map +1 -0
- package/runtime/lib/debug/printSnapshot.d.ts +1 -1
- package/runtime/lib/debug/printSnapshot.js +0 -4
- package/runtime/lib/debug/printSnapshot.js.map +1 -1
- package/runtime/lib/debug/profile.js +1 -3
- package/runtime/lib/debug/profile.js.map +1 -1
- package/runtime/lib/hydrate.js +11 -7
- package/runtime/lib/hydrate.js.map +1 -1
- package/runtime/lib/lifecycle/patch/commit.js +1 -1
- package/runtime/lib/lifecycle/patch/commit.js.map +1 -1
- package/runtime/lib/lifecycle/patch/snapshotPatch.d.ts +4 -0
- package/runtime/lib/lifecycle/patch/snapshotPatch.js +28 -0
- package/runtime/lib/lifecycle/patch/snapshotPatch.js.map +1 -1
- package/runtime/lib/lynx.js +9 -0
- package/runtime/lib/lynx.js.map +1 -1
- package/runtime/lib/pendingListUpdates.d.ts +2 -1
- package/runtime/lib/pendingListUpdates.js +16 -4
- package/runtime/lib/pendingListUpdates.js.map +1 -1
- package/runtime/lib/renderToOpcodes/constants.d.ts +2 -0
- package/runtime/lib/renderToOpcodes/constants.js +2 -0
- package/runtime/lib/renderToOpcodes/constants.js.map +1 -1
- package/runtime/lib/root.d.ts +6 -0
- package/runtime/lib/root.js +4 -0
- package/runtime/lib/root.js.map +1 -1
- package/runtime/lib/snapshot/platformInfo.js +5 -3
- package/runtime/lib/snapshot/platformInfo.js.map +1 -1
- package/runtime/lib/snapshot/ref.d.ts +2 -2
- package/runtime/lib/snapshot/spread.js +3 -1
- package/runtime/lib/snapshot/spread.js.map +1 -1
- package/runtime/lib/snapshot.js +13 -7
- package/runtime/lib/snapshot.js.map +1 -1
- package/runtime/lib/utils.d.ts +2 -0
- package/runtime/lib/utils.js +23 -2
- package/runtime/lib/utils.js.map +1 -1
- package/testing-library/dist/env/vitest.js +12 -4
- package/types/react.d.ts +13 -1
- package/runtime/src/backgroundSnapshot.ts +0 -501
- package/runtime/src/compat/componentIs.ts +0 -30
- package/runtime/src/compat/initData.ts +0 -150
- package/runtime/src/compat/lynxComponent.ts +0 -79
- package/runtime/src/debug/debug.ts +0 -9
- package/runtime/src/debug/printSnapshot.ts +0 -28
- package/runtime/src/debug/profile.ts +0 -55
- package/runtime/src/document.ts +0 -84
- package/runtime/src/gesture/processGesture.ts +0 -89
- package/runtime/src/gesture/processGestureBagkround.ts +0 -19
- package/runtime/src/gesture/types.ts +0 -44
- package/runtime/src/hooks/react.ts +0 -62
- package/runtime/src/hooks/useLynxGlobalEventListener.ts +0 -59
- package/runtime/src/hydrate.ts +0 -368
- package/runtime/src/index.ts +0 -94
- package/runtime/src/internal.ts +0 -63
- package/runtime/src/legacy-react-runtime/index.ts +0 -42
- package/runtime/src/lifecycle/destroy.ts +0 -34
- package/runtime/src/lifecycle/event/delayEvents.ts +0 -11
- package/runtime/src/lifecycle/event/delayLifecycleEvents.ts +0 -15
- package/runtime/src/lifecycle/event/jsReady.ts +0 -34
- package/runtime/src/lifecycle/pass.ts +0 -14
- package/runtime/src/lifecycle/patch/commit.ts +0 -214
- package/runtime/src/lifecycle/patch/error.ts +0 -61
- package/runtime/src/lifecycle/patch/isMainThreadHydrationFinished.ts +0 -13
- package/runtime/src/lifecycle/patch/snapshotPatch.ts +0 -65
- package/runtime/src/lifecycle/patch/snapshotPatchApply.ts +0 -145
- package/runtime/src/lifecycle/patch/updateMainThread.ts +0 -64
- package/runtime/src/lifecycle/ref/delay.ts +0 -99
- package/runtime/src/lifecycle/reload.ts +0 -97
- package/runtime/src/lifecycle/render.ts +0 -54
- package/runtime/src/lifecycleConstant.ts +0 -21
- package/runtime/src/list.ts +0 -307
- package/runtime/src/listUpdateInfo.ts +0 -221
- package/runtime/src/lynx/calledByNative.ts +0 -160
- package/runtime/src/lynx/component.ts +0 -113
- package/runtime/src/lynx/dynamic-js.ts +0 -36
- package/runtime/src/lynx/env.ts +0 -109
- package/runtime/src/lynx/injectLepusMethods.ts +0 -53
- package/runtime/src/lynx/lazy-bundle.ts +0 -175
- package/runtime/src/lynx/performance.ts +0 -148
- package/runtime/src/lynx/runWithForce.ts +0 -67
- package/runtime/src/lynx/tt.ts +0 -215
- package/runtime/src/lynx-api.ts +0 -455
- package/runtime/src/lynx.ts +0 -58
- package/runtime/src/opcodes.ts +0 -155
- package/runtime/src/pendingListUpdates.ts +0 -18
- package/runtime/src/renderToOpcodes/constants.ts +0 -24
- package/runtime/src/renderToOpcodes/index.ts +0 -306
- package/runtime/src/root.ts +0 -23
- package/runtime/src/snapshot/dynamicPartType.ts +0 -16
- package/runtime/src/snapshot/event.ts +0 -33
- package/runtime/src/snapshot/gesture.ts +0 -30
- package/runtime/src/snapshot/list.ts +0 -36
- package/runtime/src/snapshot/platformInfo.ts +0 -62
- package/runtime/src/snapshot/ref.ts +0 -139
- package/runtime/src/snapshot/spread.ts +0 -330
- package/runtime/src/snapshot/workletEvent.ts +0 -35
- package/runtime/src/snapshot/workletRef.ts +0 -88
- package/runtime/src/snapshot.ts +0 -634
- package/runtime/src/snapshotInstanceHydrationMap.ts +0 -17
- package/runtime/src/utils.ts +0 -44
- package/runtime/src/worklet/ctx.ts +0 -22
- package/runtime/src/worklet/destroy.ts +0 -16
- package/runtime/src/worklet/execMap.ts +0 -51
- package/runtime/src/worklet/functionCall.ts +0 -42
- package/runtime/src/worklet/functionality.ts +0 -29
- package/runtime/src/worklet/hmr.ts +0 -34
- package/runtime/src/worklet/indexMap.ts +0 -23
- package/runtime/src/worklet/runOnBackground.ts +0 -147
- package/runtime/src/worklet/runOnMainThread.ts +0 -50
- package/runtime/src/worklet/transformToWorklet.ts +0 -26
- package/runtime/src/worklet/workletRef.ts +0 -231
- package/runtime/src/worklet/workletRefPool.ts +0 -29
package/runtime/src/hydrate.ts
DELETED
|
@@ -1,368 +0,0 @@
|
|
|
1
|
-
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
-
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
-
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
|
|
5
|
-
import { componentAtIndexFactory, enqueueComponentFactory } from './list.js';
|
|
6
|
-
import { __pendingListUpdates } from './pendingListUpdates.js';
|
|
7
|
-
import { DynamicPartType } from './snapshot/dynamicPartType.js';
|
|
8
|
-
import { unref } from './snapshot/ref.js';
|
|
9
|
-
import type { SnapshotInstance } from './snapshot.js';
|
|
10
|
-
import { isEmptyObject } from './utils.js';
|
|
11
|
-
|
|
12
|
-
export interface DiffResult<K> {
|
|
13
|
-
$$diff: true;
|
|
14
|
-
// insert No.j to new
|
|
15
|
-
i: Record<number, K>;
|
|
16
|
-
// remove No.i from old
|
|
17
|
-
r: number[];
|
|
18
|
-
// move No.i from old to No.j of new
|
|
19
|
-
m: Record<number, number>;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface Typed {
|
|
23
|
-
type: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function isEmptyDiffResult<K>(diffResult: DiffResult<K>): boolean {
|
|
27
|
-
const hasChanged = !isEmptyObject(diffResult.i)
|
|
28
|
-
|| !isEmptyObject(diffResult.m) || diffResult.r.length > 0;
|
|
29
|
-
return !hasChanged;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function diffArrayLepus<A extends Typed, B extends Typed>(
|
|
33
|
-
before: A[],
|
|
34
|
-
after: B[],
|
|
35
|
-
isSameType: (a: A, b: B) => boolean,
|
|
36
|
-
onDiffChildren: (a: A, b: B, oldIndex: number, newIndex: number) => void,
|
|
37
|
-
): DiffResult<B> {
|
|
38
|
-
let lastPlacedIndex = 0;
|
|
39
|
-
const result: DiffResult<B> = {
|
|
40
|
-
$$diff: true,
|
|
41
|
-
i: {},
|
|
42
|
-
r: [],
|
|
43
|
-
m: {},
|
|
44
|
-
};
|
|
45
|
-
const beforeMap: Record<string, Set<[A, number]>> = {};
|
|
46
|
-
|
|
47
|
-
for (let i = 0; i < before.length; i++) {
|
|
48
|
-
const node = before[i]!;
|
|
49
|
-
(beforeMap[node.type] ??= new Set()).add([node, i]);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
for (let i = 0; i < after.length; i++) {
|
|
53
|
-
const afterNode = after[i]!;
|
|
54
|
-
const beforeNodes = beforeMap[afterNode.type];
|
|
55
|
-
let beforeNode: [A, number];
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
beforeNodes
|
|
59
|
-
&& beforeNodes.size > 0
|
|
60
|
-
// @ts-expect-error TS does not know about iterator :)
|
|
61
|
-
&& (([beforeNode] = beforeNodes), beforeNode)
|
|
62
|
-
&& isSameType(beforeNode[0], afterNode)
|
|
63
|
-
) {
|
|
64
|
-
// Reuse old node
|
|
65
|
-
beforeNodes.delete(beforeNode);
|
|
66
|
-
|
|
67
|
-
const oldIndex = beforeNode[1];
|
|
68
|
-
onDiffChildren(beforeNode[0], afterNode, oldIndex, i);
|
|
69
|
-
if (oldIndex < lastPlacedIndex) {
|
|
70
|
-
result.m[oldIndex] = i;
|
|
71
|
-
continue;
|
|
72
|
-
} else {
|
|
73
|
-
lastPlacedIndex = oldIndex;
|
|
74
|
-
}
|
|
75
|
-
} else {
|
|
76
|
-
// Create new node
|
|
77
|
-
result.i[i] = afterNode;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
// Delete
|
|
81
|
-
for (const k in beforeMap) {
|
|
82
|
-
for (const [, i] of beforeMap[k]!) {
|
|
83
|
-
result.r.push(i);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return result;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// export function diffIterableLepus<A extends Typed, B extends Typed>(
|
|
91
|
-
// before: A[],
|
|
92
|
-
// after: Iterable<B>,
|
|
93
|
-
// isSameType: (a: A, b: B) => boolean,
|
|
94
|
-
// onDiffChildren: (a: A, b: B) => void
|
|
95
|
-
// ): DiffResult<B> {
|
|
96
|
-
// let returnResult = EMPTY_DIFF_RESULT as DiffResult<B>;
|
|
97
|
-
// let lastPlacedIndex = 0;
|
|
98
|
-
// const result: DiffResult<B> = {
|
|
99
|
-
// $$diff: true,
|
|
100
|
-
// i: {},
|
|
101
|
-
// r: [],
|
|
102
|
-
// m: {},
|
|
103
|
-
// };
|
|
104
|
-
// const beforeMap: Record<string, Set<[A, number]>> = {};
|
|
105
|
-
|
|
106
|
-
// for (let i = 0; i < before.length; i++) {
|
|
107
|
-
// let node = before[i];
|
|
108
|
-
// (beforeMap[node.type] ??= new Set()).add([node, i]);
|
|
109
|
-
// }
|
|
110
|
-
|
|
111
|
-
// let i = 0;
|
|
112
|
-
// for (const afterNode of after) {
|
|
113
|
-
// const beforeNodes = beforeMap[afterNode.type];
|
|
114
|
-
// let beforeNode: [A, number];
|
|
115
|
-
|
|
116
|
-
// if (beforeNodes && (([beforeNode] = beforeNodes), beforeNode) && isSameType(beforeNode[0], afterNode)) {
|
|
117
|
-
// // Reuse old node
|
|
118
|
-
// beforeNodes.delete(beforeNode);
|
|
119
|
-
|
|
120
|
-
// const oldIndex = beforeNode[1];
|
|
121
|
-
// onDiffChildren(beforeNode[0], afterNode);
|
|
122
|
-
// if (oldIndex < lastPlacedIndex) {
|
|
123
|
-
// result.m[oldIndex] = i;
|
|
124
|
-
// returnResult = result;
|
|
125
|
-
// i++;
|
|
126
|
-
// continue;
|
|
127
|
-
// } else {
|
|
128
|
-
// lastPlacedIndex = oldIndex;
|
|
129
|
-
// }
|
|
130
|
-
// } else {
|
|
131
|
-
// // Create new node
|
|
132
|
-
// result.i[i] = afterNode;
|
|
133
|
-
// returnResult = result;
|
|
134
|
-
// }
|
|
135
|
-
// i++;
|
|
136
|
-
// }
|
|
137
|
-
// // delete
|
|
138
|
-
// for (const k in beforeMap) {
|
|
139
|
-
// for (const [, i] of beforeMap[k]) {
|
|
140
|
-
// result.r.push(i);
|
|
141
|
-
// returnResult = result;
|
|
142
|
-
// }
|
|
143
|
-
// }
|
|
144
|
-
|
|
145
|
-
// return result;
|
|
146
|
-
// }
|
|
147
|
-
|
|
148
|
-
export function diffArrayAction<T, K>(
|
|
149
|
-
before: T[],
|
|
150
|
-
diffResult: DiffResult<K>,
|
|
151
|
-
onInsert: (node: K, target: T | undefined) => T,
|
|
152
|
-
onRemove: (node: T) => void,
|
|
153
|
-
onMove: (node: T, target: T | undefined) => void,
|
|
154
|
-
): T[] {
|
|
155
|
-
if (isEmptyDiffResult(diffResult)) {
|
|
156
|
-
return before;
|
|
157
|
-
}
|
|
158
|
-
const deleteSet = new Set(diffResult.r);
|
|
159
|
-
const { i: insertMap, m: placementMap } = diffResult;
|
|
160
|
-
const moveTempMap = new Map<number, T>();
|
|
161
|
-
let old: T | undefined;
|
|
162
|
-
let k = 0;
|
|
163
|
-
old = before[k];
|
|
164
|
-
// let current: T | null | undefined = null;
|
|
165
|
-
const result: T[] = [];
|
|
166
|
-
let i = 0; // index of the old list
|
|
167
|
-
let j = 0; // index of the new list
|
|
168
|
-
let remain = Object.keys(insertMap).length;
|
|
169
|
-
while (old || remain > 0) {
|
|
170
|
-
let keep = false;
|
|
171
|
-
if (old && deleteSet.has(j)) {
|
|
172
|
-
// delete
|
|
173
|
-
onRemove(old);
|
|
174
|
-
} else if (old && placementMap[j] !== undefined) {
|
|
175
|
-
// save node to re-use
|
|
176
|
-
moveTempMap.set(placementMap[j]!, old);
|
|
177
|
-
remain++;
|
|
178
|
-
} else {
|
|
179
|
-
// insert node
|
|
180
|
-
let newNode = old;
|
|
181
|
-
if (moveTempMap.has(i)) {
|
|
182
|
-
// insert re-used node
|
|
183
|
-
newNode = moveTempMap.get(i)!;
|
|
184
|
-
keep = true;
|
|
185
|
-
onMove(newNode, old);
|
|
186
|
-
remain--;
|
|
187
|
-
} else if (insertMap[i] !== undefined) {
|
|
188
|
-
// insert new node
|
|
189
|
-
newNode = onInsert(insertMap[i]!, old);
|
|
190
|
-
keep = true;
|
|
191
|
-
remain--;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
result.push(newNode!);
|
|
195
|
-
i++;
|
|
196
|
-
}
|
|
197
|
-
if (old && !keep) {
|
|
198
|
-
old = before[++k];
|
|
199
|
-
j++;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return result;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export interface HydrationOptions {
|
|
207
|
-
skipUnRef?: boolean;
|
|
208
|
-
swap?: Record<number, number>;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export function hydrate(before: SnapshotInstance, after: SnapshotInstance, options?: HydrationOptions): void {
|
|
212
|
-
after.__elements = before.__elements;
|
|
213
|
-
after.__element_root = before.__element_root;
|
|
214
|
-
|
|
215
|
-
if (!(options?.skipUnRef)) {
|
|
216
|
-
unref(before, false);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
let swap;
|
|
220
|
-
if ((swap = options?.swap)) {
|
|
221
|
-
swap[before.__id] = after.__id;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
after.__values?.forEach((value, index) => {
|
|
225
|
-
const old = before.__values![index];
|
|
226
|
-
if (value !== old) {
|
|
227
|
-
after.__values![index] = old;
|
|
228
|
-
after.setAttribute(index, value);
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
const { slot } = after.__snapshot_def;
|
|
233
|
-
|
|
234
|
-
if (!slot) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const beforeChildNodes = before.childNodes;
|
|
239
|
-
const afterChildNodes = after.childNodes;
|
|
240
|
-
|
|
241
|
-
slot.forEach(([type, elementIndex], index) => {
|
|
242
|
-
switch (type) {
|
|
243
|
-
case DynamicPartType.Slot:
|
|
244
|
-
case DynamicPartType.MultiChildren: {
|
|
245
|
-
// TODO: the following null assertions are not 100% safe
|
|
246
|
-
const v1 = beforeChildNodes[index]!;
|
|
247
|
-
const v2 = afterChildNodes[index]!;
|
|
248
|
-
hydrate(v1, v2, options);
|
|
249
|
-
break;
|
|
250
|
-
}
|
|
251
|
-
case DynamicPartType.Children: {
|
|
252
|
-
const diffResult = diffArrayLepus(
|
|
253
|
-
beforeChildNodes,
|
|
254
|
-
afterChildNodes,
|
|
255
|
-
(a, b) => a.type === b.type,
|
|
256
|
-
(a, b) => {
|
|
257
|
-
hydrate(a, b, options);
|
|
258
|
-
},
|
|
259
|
-
);
|
|
260
|
-
diffArrayAction(
|
|
261
|
-
beforeChildNodes,
|
|
262
|
-
diffResult,
|
|
263
|
-
(node, target) => {
|
|
264
|
-
node.ensureElements();
|
|
265
|
-
__InsertElementBefore(
|
|
266
|
-
before.__elements![elementIndex]!,
|
|
267
|
-
node.__element_root!,
|
|
268
|
-
target?.__element_root,
|
|
269
|
-
);
|
|
270
|
-
return node;
|
|
271
|
-
},
|
|
272
|
-
node => {
|
|
273
|
-
__RemoveElement(
|
|
274
|
-
before.__elements![elementIndex]!,
|
|
275
|
-
node.__element_root!,
|
|
276
|
-
);
|
|
277
|
-
},
|
|
278
|
-
(node, target) => {
|
|
279
|
-
__RemoveElement(
|
|
280
|
-
before.__elements![elementIndex]!,
|
|
281
|
-
node.__element_root!,
|
|
282
|
-
);
|
|
283
|
-
__InsertElementBefore(
|
|
284
|
-
before.__elements![elementIndex]!,
|
|
285
|
-
node.__element_root!,
|
|
286
|
-
target?.__element_root,
|
|
287
|
-
);
|
|
288
|
-
},
|
|
289
|
-
);
|
|
290
|
-
break;
|
|
291
|
-
}
|
|
292
|
-
case DynamicPartType.ListChildren: {
|
|
293
|
-
const removals: number[] = [];
|
|
294
|
-
const insertions: number[] = [];
|
|
295
|
-
const updateAction: any[] = [];
|
|
296
|
-
|
|
297
|
-
const diffResult = diffArrayLepus(
|
|
298
|
-
beforeChildNodes,
|
|
299
|
-
afterChildNodes,
|
|
300
|
-
(a, b) => a.type === b.type,
|
|
301
|
-
(a, b, oldIndex, newIndex) => {
|
|
302
|
-
if (
|
|
303
|
-
JSON.stringify(a.__listItemPlatformInfo)
|
|
304
|
-
!== JSON.stringify(b.__listItemPlatformInfo)
|
|
305
|
-
) {
|
|
306
|
-
updateAction.push({
|
|
307
|
-
...b.__listItemPlatformInfo,
|
|
308
|
-
from: newIndex,
|
|
309
|
-
to: newIndex,
|
|
310
|
-
// no flush
|
|
311
|
-
flush: false,
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
// Mark list-item which is rendered (has `__elements`) as DELETE
|
|
316
|
-
// so list platform will call `enqueueComponent` on it
|
|
317
|
-
// and will call `componentAtIndex` on the inserted one
|
|
318
|
-
// In this way:
|
|
319
|
-
// 1. we make sure `<list/>` for hydrate is like a leaf node
|
|
320
|
-
// 2. we avoid hydrate so modifying recycleMap can be avoid
|
|
321
|
-
// 3. the delete list-item is recycled for later use, so no waste
|
|
322
|
-
if (a.__elements) {
|
|
323
|
-
removals.push(oldIndex);
|
|
324
|
-
insertions.push(newIndex);
|
|
325
|
-
}
|
|
326
|
-
},
|
|
327
|
-
);
|
|
328
|
-
|
|
329
|
-
for (const i of diffResult.r) {
|
|
330
|
-
removals.push(i);
|
|
331
|
-
}
|
|
332
|
-
for (const i in diffResult.i) {
|
|
333
|
-
insertions.push(Number(i));
|
|
334
|
-
}
|
|
335
|
-
for (const i in diffResult.m) {
|
|
336
|
-
removals.push(Number(i));
|
|
337
|
-
insertions.push(diffResult.m[i]!);
|
|
338
|
-
}
|
|
339
|
-
insertions.sort((a, b) => a - b);
|
|
340
|
-
removals.sort((a, b) => a - b);
|
|
341
|
-
|
|
342
|
-
const info = {
|
|
343
|
-
insertAction: insertions.map((it) => ({
|
|
344
|
-
position: it,
|
|
345
|
-
type: afterChildNodes[it]!.type,
|
|
346
|
-
...afterChildNodes[it]!.__listItemPlatformInfo,
|
|
347
|
-
})),
|
|
348
|
-
removeAction: removals,
|
|
349
|
-
updateAction,
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
const listElement = before.__elements![elementIndex]!;
|
|
353
|
-
__SetAttribute(listElement, 'update-list-info', info);
|
|
354
|
-
const [componentAtIndex, componentAtIndexes] = componentAtIndexFactory(afterChildNodes, hydrate);
|
|
355
|
-
__UpdateListCallbacks(
|
|
356
|
-
listElement,
|
|
357
|
-
componentAtIndex,
|
|
358
|
-
enqueueComponentFactory(),
|
|
359
|
-
componentAtIndexes,
|
|
360
|
-
);
|
|
361
|
-
|
|
362
|
-
// The `before` & `after` target to the same list element, so we need to
|
|
363
|
-
// avoid the newly created list's (behind snapshot instance `after`) "update-list-info" being recorded.
|
|
364
|
-
delete __pendingListUpdates.values[after.__id];
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
}
|
package/runtime/src/index.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
-
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
-
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
|
|
5
|
-
import './lynx.js';
|
|
6
|
-
import './lynx/component.js';
|
|
7
|
-
import {
|
|
8
|
-
Children,
|
|
9
|
-
Component,
|
|
10
|
-
Fragment,
|
|
11
|
-
PureComponent,
|
|
12
|
-
Suspense,
|
|
13
|
-
lazy as backgroundLazy,
|
|
14
|
-
cloneElement,
|
|
15
|
-
createContext,
|
|
16
|
-
createElement,
|
|
17
|
-
createRef,
|
|
18
|
-
forwardRef,
|
|
19
|
-
isValidElement,
|
|
20
|
-
memo,
|
|
21
|
-
useSyncExternalStore,
|
|
22
|
-
} from 'preact/compat';
|
|
23
|
-
|
|
24
|
-
import {
|
|
25
|
-
useCallback,
|
|
26
|
-
useContext,
|
|
27
|
-
useDebugValue,
|
|
28
|
-
useEffect,
|
|
29
|
-
useImperativeHandle,
|
|
30
|
-
useLayoutEffect,
|
|
31
|
-
useMemo,
|
|
32
|
-
useReducer,
|
|
33
|
-
useRef,
|
|
34
|
-
useState,
|
|
35
|
-
} from './hooks/react.js';
|
|
36
|
-
import { loadLazyBundle, mainThreadLazy } from './lynx/lazy-bundle.js';
|
|
37
|
-
|
|
38
|
-
export { Component, createContext } from 'preact';
|
|
39
|
-
export { PureComponent } from 'preact/compat';
|
|
40
|
-
export * from './hooks/react.js';
|
|
41
|
-
|
|
42
|
-
const lazy: typeof import('preact/compat').lazy = /*#__PURE__*/ (() => {
|
|
43
|
-
lynx.loadLazyBundle = loadLazyBundle;
|
|
44
|
-
return __LEPUS__
|
|
45
|
-
? mainThreadLazy
|
|
46
|
-
: backgroundLazy;
|
|
47
|
-
})();
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @internal
|
|
51
|
-
*/
|
|
52
|
-
export default {
|
|
53
|
-
// hooks
|
|
54
|
-
useState,
|
|
55
|
-
useReducer,
|
|
56
|
-
useEffect,
|
|
57
|
-
useLayoutEffect,
|
|
58
|
-
useRef,
|
|
59
|
-
useImperativeHandle,
|
|
60
|
-
useMemo,
|
|
61
|
-
useCallback,
|
|
62
|
-
useContext,
|
|
63
|
-
useDebugValue,
|
|
64
|
-
useSyncExternalStore,
|
|
65
|
-
|
|
66
|
-
createContext,
|
|
67
|
-
createRef,
|
|
68
|
-
Fragment,
|
|
69
|
-
isValidElement,
|
|
70
|
-
Children,
|
|
71
|
-
Component,
|
|
72
|
-
PureComponent,
|
|
73
|
-
memo,
|
|
74
|
-
forwardRef,
|
|
75
|
-
Suspense,
|
|
76
|
-
lazy,
|
|
77
|
-
createElement,
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export {
|
|
81
|
-
Children,
|
|
82
|
-
createRef,
|
|
83
|
-
Fragment,
|
|
84
|
-
isValidElement,
|
|
85
|
-
memo,
|
|
86
|
-
forwardRef,
|
|
87
|
-
Suspense,
|
|
88
|
-
lazy,
|
|
89
|
-
createElement,
|
|
90
|
-
cloneElement,
|
|
91
|
-
useSyncExternalStore,
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export * from './lynx-api.js';
|
package/runtime/src/internal.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
-
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
-
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
|
|
5
|
-
import { Suspense, createElement, lazy } from 'preact/compat';
|
|
6
|
-
import type { FC } from 'react';
|
|
7
|
-
|
|
8
|
-
import './lynx.js';
|
|
9
|
-
|
|
10
|
-
import { factory as factory2 } from './compat/componentIs.js';
|
|
11
|
-
import { useMemo } from './hooks/react.js';
|
|
12
|
-
import { loadLazyBundle } from './lynx/lazy-bundle.js';
|
|
13
|
-
import { __root } from './root.js';
|
|
14
|
-
import { DynamicPartType } from './snapshot/dynamicPartType.js';
|
|
15
|
-
import { snapshotCreateList } from './snapshot/list.js';
|
|
16
|
-
import { SnapshotInstance, __page, __pageId, createSnapshot, snapshotManager } from './snapshot.js';
|
|
17
|
-
|
|
18
|
-
export { __page, __pageId, __root };
|
|
19
|
-
|
|
20
|
-
export { SnapshotInstance, snapshotCreateList, createSnapshot, snapshotManager };
|
|
21
|
-
|
|
22
|
-
export const __DynamicPartSlot: DynamicPartType = DynamicPartType.Slot;
|
|
23
|
-
export const __DynamicPartMultiChildren: DynamicPartType = DynamicPartType.MultiChildren;
|
|
24
|
-
export const __DynamicPartChildren: DynamicPartType = DynamicPartType.Children;
|
|
25
|
-
export const __DynamicPartListChildren: DynamicPartType = DynamicPartType.ListChildren;
|
|
26
|
-
export const __DynamicPartChildren_0: [DynamicPartType, number][] = [[DynamicPartType.Children, 0]];
|
|
27
|
-
|
|
28
|
-
export { updateSpread } from './snapshot/spread.js';
|
|
29
|
-
export { updateEvent } from './snapshot/event.js';
|
|
30
|
-
export { updateRef, transformRef } from './snapshot/ref.js';
|
|
31
|
-
export { updateWorkletEvent } from './snapshot/workletEvent.js';
|
|
32
|
-
export { updateWorkletRef } from './snapshot/workletRef.js';
|
|
33
|
-
export { updateGesture } from './snapshot/gesture.js';
|
|
34
|
-
export { updateListItemPlatformInfo } from './snapshot/platformInfo.js';
|
|
35
|
-
|
|
36
|
-
export {
|
|
37
|
-
options,
|
|
38
|
-
// Component is not an internal API, but refresh needs it from 'react/internal'
|
|
39
|
-
Component,
|
|
40
|
-
} from 'preact';
|
|
41
|
-
export type { Options } from 'preact';
|
|
42
|
-
|
|
43
|
-
export { loadDynamicJS, __dynamicImport } from './lynx/dynamic-js.js';
|
|
44
|
-
|
|
45
|
-
export { withInitDataInState } from './compat/initData.js';
|
|
46
|
-
|
|
47
|
-
export { wrapWithLynxComponent } from './compat/lynxComponent.js';
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @internal a polyfill for <component is=? />
|
|
51
|
-
*/
|
|
52
|
-
export const __ComponentIsPolyfill: FC<{ is: string }> = /* @__PURE__ */ factory2(
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
54
|
-
{ Suspense, lazy, createElement, useMemo } as any,
|
|
55
|
-
loadLazyBundle,
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
export { loadLazyBundle } from './lynx/lazy-bundle.js';
|
|
59
|
-
|
|
60
|
-
export { transformToWorklet } from './worklet/transformToWorklet.js';
|
|
61
|
-
export { registerWorkletOnBackground } from './worklet/hmr.js';
|
|
62
|
-
|
|
63
|
-
export { loadWorkletRuntime } from '@lynx-js/react/worklet-runtime/bindings';
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
-
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
-
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import { createContext, createRef } from 'preact';
|
|
5
|
-
import { lazy } from 'preact/compat';
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
ComponentFromReactRuntime as Component,
|
|
9
|
-
ComponentFromReactRuntime as PureComponent,
|
|
10
|
-
} from '../compat/lynxComponent.js';
|
|
11
|
-
import { useCallback, useEffect, useMemo, useReducer, useRef, useState } from '../hooks/react.js';
|
|
12
|
-
|
|
13
|
-
/* v8 ignore next 3 */
|
|
14
|
-
function __runInJS<T>(value: T): T | undefined | null {
|
|
15
|
-
return value;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// should mirror @lynx-js/react-runtime's exports
|
|
19
|
-
export { ComponentFromReactRuntime as Component } from '../compat/lynxComponent.js';
|
|
20
|
-
export { ComponentFromReactRuntime as PureComponent } from '../compat/lynxComponent.js';
|
|
21
|
-
export { createContext } from 'preact';
|
|
22
|
-
export { lazy } from 'preact/compat';
|
|
23
|
-
export { useState, useReducer, useEffect, useMemo, useCallback /*, useInstance */ } from '../hooks/react.js';
|
|
24
|
-
export { __runInJS };
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @internal
|
|
28
|
-
*/
|
|
29
|
-
export default {
|
|
30
|
-
Component,
|
|
31
|
-
PureComponent,
|
|
32
|
-
createContext,
|
|
33
|
-
createRef,
|
|
34
|
-
lazy,
|
|
35
|
-
useState,
|
|
36
|
-
useReducer,
|
|
37
|
-
useRef,
|
|
38
|
-
useEffect,
|
|
39
|
-
useMemo,
|
|
40
|
-
useCallback,
|
|
41
|
-
__runInJS,
|
|
42
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
-
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
-
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import { render } from 'preact';
|
|
5
|
-
|
|
6
|
-
import { __root } from '../root.js';
|
|
7
|
-
import { delayedEvents } from './event/delayEvents.js';
|
|
8
|
-
import { delayedLifecycleEvents } from './event/delayLifecycleEvents.js';
|
|
9
|
-
import { globalCommitTaskMap } from './patch/commit.js';
|
|
10
|
-
|
|
11
|
-
function destroyBackground(): void {
|
|
12
|
-
if (__PROFILE__) {
|
|
13
|
-
console.profile('destroyBackground');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
17
|
-
render(null, __root as any);
|
|
18
|
-
|
|
19
|
-
globalCommitTaskMap.forEach(task => {
|
|
20
|
-
task();
|
|
21
|
-
});
|
|
22
|
-
globalCommitTaskMap.clear();
|
|
23
|
-
// Clear delayed events which should not be executed after destroyed.
|
|
24
|
-
// This is important when the page is performing a reload.
|
|
25
|
-
delayedLifecycleEvents.length = 0;
|
|
26
|
-
if (delayedEvents) {
|
|
27
|
-
delayedEvents.length = 0;
|
|
28
|
-
}
|
|
29
|
-
if (__PROFILE__) {
|
|
30
|
-
console.profileEnd();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export { destroyBackground };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// Copyright 2025 The Lynx Authors. All rights reserved.
|
|
2
|
-
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
-
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
let delayedEvents: [handlerName: string, data: unknown][] | undefined;
|
|
5
|
-
|
|
6
|
-
function delayedPublishEvent(handlerName: string, data: unknown): void {
|
|
7
|
-
delayedEvents ??= [];
|
|
8
|
-
delayedEvents.push([handlerName, data]);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { delayedPublishEvent, delayedEvents };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// Copyright 2025 The Lynx Authors. All rights reserved.
|
|
2
|
-
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
-
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import type { LifecycleConstant } from '../../lifecycleConstant.js';
|
|
5
|
-
|
|
6
|
-
const delayedLifecycleEvents: [type: LifecycleConstant, data: unknown][] = [];
|
|
7
|
-
|
|
8
|
-
function delayLifecycleEvent(type: LifecycleConstant, data: unknown): void {
|
|
9
|
-
delayedLifecycleEvents.push([type, data]);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
export { delayLifecycleEvent, delayedLifecycleEvents };
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// Copyright 2025 The Lynx Authors. All rights reserved.
|
|
2
|
-
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
-
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import { LifecycleConstant } from '../../lifecycleConstant.js';
|
|
5
|
-
import { __root } from '../../root.js';
|
|
6
|
-
|
|
7
|
-
let isJSReady: boolean;
|
|
8
|
-
let jsReadyEventIdSwap: Record<string | number, number>;
|
|
9
|
-
|
|
10
|
-
function jsReady(): void {
|
|
11
|
-
isJSReady = true;
|
|
12
|
-
__OnLifecycleEvent([
|
|
13
|
-
LifecycleConstant.firstScreen, /* FIRST_SCREEN */
|
|
14
|
-
{
|
|
15
|
-
root: JSON.stringify(__root),
|
|
16
|
-
jsReadyEventIdSwap,
|
|
17
|
-
},
|
|
18
|
-
]);
|
|
19
|
-
jsReadyEventIdSwap = {};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function clearJSReadyEventIdSwap(): void {
|
|
23
|
-
jsReadyEventIdSwap = {};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function resetJSReady(): void {
|
|
27
|
-
isJSReady = false;
|
|
28
|
-
jsReadyEventIdSwap = {};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @internal
|
|
33
|
-
*/
|
|
34
|
-
export { jsReady, isJSReady, jsReadyEventIdSwap, clearJSReadyEventIdSwap, resetJSReady };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
-
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
-
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
let reloadVersion = 0;
|
|
5
|
-
|
|
6
|
-
function getReloadVersion(): number {
|
|
7
|
-
return reloadVersion;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function increaseReloadVersion(): number {
|
|
11
|
-
return ++reloadVersion;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export { getReloadVersion, increaseReloadVersion };
|