@simpreact/simpreact 0.0.6 → 0.0.7
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/compat/index.d.ts +2 -0
- package/compat/index.js +3 -0
- package/compat/renderRuntime.d.ts +4 -0
- package/compat/renderRuntime.js +3 -0
- package/context/index.js +1 -1
- package/core/index.d.ts +5 -14
- package/core/internal.d.ts +2 -0
- package/core/internal.js +2 -0
- package/core/mounting.d.ts +1 -2
- package/core/mounting.js +50 -101
- package/core/mountingChildren.d.ts +4 -0
- package/core/mountingChildren.js +47 -0
- package/core/patching.d.ts +1 -1
- package/core/patching.js +54 -44
- package/core/patchingChildren.d.ts +3 -3
- package/core/patchingChildren.js +104 -91
- package/core/processStack.d.ts +53 -16
- package/core/processStack.js +23 -11
- package/core/unmounting.d.ts +4 -8
- package/core/unmounting.js +45 -85
- package/core/unmountingChildren.d.ts +4 -0
- package/core/unmountingChildren.js +23 -0
- package/core/utils.d.ts +3 -2
- package/core/utils.js +28 -3
- package/dom/props/dangerInnerHTML.d.ts +5 -5
- package/dom/props/dangerInnerHTML.js +10 -16
- package/dom/props/props.js +5 -5
- package/hooks/index.js +1 -0
- package/package.json +1 -1
package/compat/index.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ export * from './core.js';
|
|
|
3
3
|
export * from './dom.js';
|
|
4
4
|
export * from './hooks.js';
|
|
5
5
|
export * from './jsx-runtime.js';
|
|
6
|
+
export * from './renderRuntime.js';
|
|
6
7
|
declare const _default: {
|
|
8
|
+
renderRuntime: import("../core/runtime.js").SimpRenderRuntime;
|
|
7
9
|
jsx: typeof import("../jsx-runtime/index.js").jsx;
|
|
8
10
|
jsxDEV: typeof import("../jsx-runtime/index.js").jsx;
|
|
9
11
|
jsxs: typeof import("../jsx-runtime/index.js").jsx;
|
package/compat/index.js
CHANGED
|
@@ -3,15 +3,18 @@ import coreDefault from './core.js';
|
|
|
3
3
|
import domDefault from './dom.js';
|
|
4
4
|
import hooksDefault from './hooks.js';
|
|
5
5
|
import jsxRuntimeDefault from './jsx-runtime.js';
|
|
6
|
+
import renderRuntimeDefault from './renderRuntime.js';
|
|
6
7
|
export * from './context.js';
|
|
7
8
|
export * from './core.js';
|
|
8
9
|
export * from './dom.js';
|
|
9
10
|
export * from './hooks.js';
|
|
10
11
|
export * from './jsx-runtime.js';
|
|
12
|
+
export * from './renderRuntime.js';
|
|
11
13
|
export default {
|
|
12
14
|
...contextDefault,
|
|
13
15
|
...coreDefault,
|
|
14
16
|
...domDefault,
|
|
15
17
|
...hooksDefault,
|
|
16
18
|
...jsxRuntimeDefault,
|
|
19
|
+
...renderRuntimeDefault,
|
|
17
20
|
};
|
package/compat/renderRuntime.js
CHANGED
package/context/index.js
CHANGED
|
@@ -18,7 +18,7 @@ export function createCreateContext(renderRuntime) {
|
|
|
18
18
|
if (!contextMap) {
|
|
19
19
|
currentElement.context = contextMap = new Map();
|
|
20
20
|
}
|
|
21
|
-
if (
|
|
21
|
+
else if (renderPhase === MOUNTING_PHASE) {
|
|
22
22
|
currentElement.context = contextMap = new Map(currentElement.context);
|
|
23
23
|
}
|
|
24
24
|
if (renderPhase === MOUNTING_PHASE) {
|
package/core/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { Nullable, SimpText } from '../shared/index.js';
|
|
2
|
+
import type { HostAdapter } from './hostAdapter.js';
|
|
3
3
|
|
|
4
4
|
export type ComponentType<P = {}> = FunctionalComponent<P>;
|
|
5
5
|
|
|
@@ -53,20 +53,11 @@ export interface SimpRuntimeFCRenderer {
|
|
|
53
53
|
(component: FC, element: SimpElement): SimpNode;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
export interface RenderMeta {
|
|
57
|
-
prevElement: Nullable<SimpElement>;
|
|
58
|
-
parentReference: HostReference;
|
|
59
|
-
parentAnchorReference: HostReference;
|
|
60
|
-
rightSibling: Nullable<SimpElement>;
|
|
61
|
-
context: unknown;
|
|
62
|
-
hostNamespace: Maybe<string>;
|
|
63
|
-
renderRuntime: SimpRenderRuntime;
|
|
64
|
-
placeHolderElement: Nullable<SimpElement>;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
56
|
export interface SimpRenderRuntime {
|
|
68
57
|
hostAdapter: HostAdapter;
|
|
69
58
|
renderer: SimpRuntimeFCRenderer;
|
|
70
|
-
renderStack:
|
|
59
|
+
renderStack: Array<{ node: SimpElement; kind: number; meta: any }>;
|
|
71
60
|
elementToHostMap: Map<unknown, SimpElement>;
|
|
61
|
+
currentRenderingFCElement: Nullable<SimpElement>;
|
|
62
|
+
renderPhase: Nullable<number>;
|
|
72
63
|
}
|
package/core/internal.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './hostAdapter.js';
|
|
|
4
4
|
export * from './lifecycleEventBus.js';
|
|
5
5
|
export * from './memo.js';
|
|
6
6
|
export * from './mounting.js';
|
|
7
|
+
export * from './mountingChildren.js';
|
|
7
8
|
export * from './patching.js';
|
|
8
9
|
export * from './patchingChildren.js';
|
|
9
10
|
export * from './portal.js';
|
|
@@ -12,3 +13,4 @@ export * from './ref.js';
|
|
|
12
13
|
export * from './rerender.js';
|
|
13
14
|
export * from './runtime.js';
|
|
14
15
|
export * from './unmounting.js';
|
|
16
|
+
export * from './unmountingChildren.js';
|
package/core/internal.js
CHANGED
|
@@ -4,6 +4,7 @@ export * from './hostAdapter.js';
|
|
|
4
4
|
export * from './lifecycleEventBus.js';
|
|
5
5
|
export * from './memo.js';
|
|
6
6
|
export * from './mounting.js';
|
|
7
|
+
export * from './mountingChildren.js';
|
|
7
8
|
export * from './patching.js';
|
|
8
9
|
export * from './patchingChildren.js';
|
|
9
10
|
export * from './portal.js';
|
|
@@ -12,3 +13,4 @@ export * from './ref.js';
|
|
|
12
13
|
export * from './rerender.js';
|
|
13
14
|
export * from './runtime.js';
|
|
14
15
|
export * from './unmounting.js';
|
|
16
|
+
export * from './unmountingChildren.js';
|
package/core/mounting.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { Maybe, Nullable } from '../shared/index.js';
|
|
|
2
2
|
import { type SimpElement } from './createElement.js';
|
|
3
3
|
import { type MountFrame, type MountFrameMeta } from './processStack.js';
|
|
4
4
|
import { type SimpRenderRuntime } from './runtime.js';
|
|
5
|
-
export declare function mount(element: SimpElement, parentReference: unknown,
|
|
5
|
+
export declare function mount(element: SimpElement, parentReference: unknown, subtreeRightBoundary: Nullable<SimpElement>, context: unknown, hostNamespace: Maybe<string>, renderRuntime: SimpRenderRuntime): void;
|
|
6
6
|
export declare function _mount(frame: MountFrame): void;
|
|
7
7
|
export declare function _pushMountEnterFrame(element: SimpElement, meta: MountFrameMeta): void;
|
|
8
|
-
export declare function _pushMountArrayChildrenFrame(element: SimpElement, meta: MountFrameMeta): void;
|
package/core/mounting.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { createTextElement, normalizeRoot,
|
|
1
|
+
import { createTextElement, normalizeRoot, SIMP_ELEMENT_CHILD_FLAG_TEXT, } from './createElement.js';
|
|
2
2
|
import { _pushHostOperationPlaceElement } from './hostOperations.js';
|
|
3
3
|
import { lifecycleEventBus } from './lifecycleEventBus.js';
|
|
4
|
+
import { _pushMountChildrenFrame } from './mountingChildren.js';
|
|
4
5
|
import { MOUNT_ENTER, MOUNT_EXIT, processStack } from './processStack.js';
|
|
5
6
|
import { applyRef } from './ref.js';
|
|
6
7
|
import { MOUNTING_PHASE } from './runtime.js';
|
|
7
8
|
import { bitScanForwardIndex } from './utils.js';
|
|
8
9
|
const mountHandlers = [_mountHostElement, _mountFunctionalElement, _mountTextElement, _mountPortal, _mountFragment];
|
|
9
|
-
export function mount(element, parentReference,
|
|
10
|
+
export function mount(element, parentReference, subtreeRightBoundary, context, hostNamespace, renderRuntime) {
|
|
10
11
|
if (renderRuntime.renderStack.length !== 0) {
|
|
11
12
|
throw new Error('Cannot mount while rendering.');
|
|
12
13
|
}
|
|
13
14
|
_pushMountEnterFrame(element, {
|
|
14
15
|
parentReference,
|
|
15
|
-
|
|
16
|
+
subtreeRightBoundary,
|
|
16
17
|
context,
|
|
17
18
|
hostNamespace,
|
|
18
19
|
renderRuntime,
|
|
@@ -37,18 +38,9 @@ function _pushMountExitFrame(element, meta) {
|
|
|
37
38
|
meta,
|
|
38
39
|
});
|
|
39
40
|
}
|
|
40
|
-
export function _pushMountArrayChildrenFrame(element, meta) {
|
|
41
|
-
const children = element.children;
|
|
42
|
-
for (let i = children.length - 1; i >= 0; i--) {
|
|
43
|
-
const child = children[i];
|
|
44
|
-
child.parent = element;
|
|
45
|
-
const rightSibling = children[child.index + 1] ?? meta.rightSibling;
|
|
46
|
-
_pushMountEnterFrame(child, { ...meta, rightSibling });
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
41
|
function _mountHostElement(frame) {
|
|
50
42
|
const element = frame.node;
|
|
51
|
-
const { parentReference,
|
|
43
|
+
const { parentReference, subtreeRightBoundary, context, hostNamespace, renderRuntime } = frame.meta;
|
|
52
44
|
if (frame.kind === MOUNT_EXIT) {
|
|
53
45
|
if (element.childFlag === SIMP_ELEMENT_CHILD_FLAG_TEXT) {
|
|
54
46
|
renderRuntime.hostAdapter.setTextContent(element.reference, element.props.children);
|
|
@@ -62,7 +54,7 @@ function _mountHostElement(frame) {
|
|
|
62
54
|
if (parentReference) {
|
|
63
55
|
_pushHostOperationPlaceElement(element, {
|
|
64
56
|
renderRuntime,
|
|
65
|
-
|
|
57
|
+
subtreeRightBoundary,
|
|
66
58
|
parentReference,
|
|
67
59
|
});
|
|
68
60
|
}
|
|
@@ -75,39 +67,23 @@ function _mountHostElement(frame) {
|
|
|
75
67
|
_pushMountExitFrame(element, {
|
|
76
68
|
renderRuntime,
|
|
77
69
|
hostNamespace: hostNamespaces?.self,
|
|
78
|
-
|
|
70
|
+
subtreeRightBoundary,
|
|
79
71
|
context,
|
|
80
72
|
parentReference,
|
|
81
73
|
placeHolderElement: null,
|
|
82
74
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
placeHolderElement: null,
|
|
92
|
-
});
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
case SIMP_ELEMENT_CHILD_FLAG_ELEMENT: {
|
|
96
|
-
element.children.parent = element;
|
|
97
|
-
_pushMountEnterFrame(element.children, {
|
|
98
|
-
renderRuntime,
|
|
99
|
-
hostNamespace: hostNamespaces?.children,
|
|
100
|
-
rightSibling: null,
|
|
101
|
-
context,
|
|
102
|
-
parentReference: hostReference,
|
|
103
|
-
placeHolderElement: null,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
75
|
+
_pushMountChildrenFrame(element, {
|
|
76
|
+
renderRuntime,
|
|
77
|
+
hostNamespace: hostNamespaces?.children,
|
|
78
|
+
subtreeRightBoundary,
|
|
79
|
+
context,
|
|
80
|
+
parentReference: hostReference,
|
|
81
|
+
children: element.children,
|
|
82
|
+
});
|
|
107
83
|
}
|
|
108
84
|
function _mountFunctionalElement(frame) {
|
|
109
85
|
const element = frame.node;
|
|
110
|
-
const { parentReference,
|
|
86
|
+
const { parentReference, subtreeRightBoundary, context, hostNamespace, renderRuntime } = frame.meta;
|
|
111
87
|
if (frame.kind === MOUNT_EXIT) {
|
|
112
88
|
lifecycleEventBus.publish({ type: 'mounted', element, renderRuntime });
|
|
113
89
|
return;
|
|
@@ -154,6 +130,7 @@ function _mountFunctionalElement(frame) {
|
|
|
154
130
|
});
|
|
155
131
|
} while (triedToRerender);
|
|
156
132
|
normalizeRoot(element, children, false);
|
|
133
|
+
children = element.children;
|
|
157
134
|
}
|
|
158
135
|
catch (error) {
|
|
159
136
|
const event = {
|
|
@@ -176,37 +153,28 @@ function _mountFunctionalElement(frame) {
|
|
|
176
153
|
}
|
|
177
154
|
_pushMountExitFrame(element, {
|
|
178
155
|
renderRuntime,
|
|
179
|
-
hostNamespace
|
|
180
|
-
|
|
181
|
-
context
|
|
182
|
-
parentReference
|
|
156
|
+
hostNamespace,
|
|
157
|
+
subtreeRightBoundary,
|
|
158
|
+
context,
|
|
159
|
+
parentReference,
|
|
183
160
|
placeHolderElement: null,
|
|
184
161
|
});
|
|
185
|
-
|
|
186
|
-
const child = element.children;
|
|
187
|
-
child.parent = element;
|
|
188
|
-
_pushMountEnterFrame(child, {
|
|
189
|
-
renderRuntime,
|
|
190
|
-
hostNamespace,
|
|
191
|
-
rightSibling,
|
|
192
|
-
context: element.context,
|
|
193
|
-
parentReference,
|
|
194
|
-
placeHolderElement: null,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
function _mountTextElement(frame) {
|
|
199
|
-
const { renderRuntime, parentReference } = frame.meta;
|
|
200
|
-
frame.node.reference = renderRuntime.hostAdapter.createTextReference(frame.node.children);
|
|
201
|
-
_pushHostOperationPlaceElement(frame.node, {
|
|
162
|
+
_pushMountChildrenFrame(element, {
|
|
202
163
|
renderRuntime,
|
|
203
|
-
|
|
164
|
+
hostNamespace,
|
|
165
|
+
children: children,
|
|
166
|
+
context: element.context,
|
|
204
167
|
parentReference,
|
|
168
|
+
subtreeRightBoundary,
|
|
205
169
|
});
|
|
206
170
|
}
|
|
171
|
+
function _mountTextElement(frame) {
|
|
172
|
+
frame.node.reference = frame.meta.renderRuntime.hostAdapter.createTextReference(frame.node.children);
|
|
173
|
+
_pushHostOperationPlaceElement(frame.node, frame.meta);
|
|
174
|
+
}
|
|
207
175
|
function _mountPortal(frame) {
|
|
208
176
|
const element = frame.node;
|
|
209
|
-
const { parentReference,
|
|
177
|
+
const { parentReference, subtreeRightBoundary, context, renderRuntime } = frame.meta;
|
|
210
178
|
if (frame.kind === MOUNT_EXIT) {
|
|
211
179
|
element.reference = frame.meta.placeHolderElement.reference;
|
|
212
180
|
return;
|
|
@@ -214,27 +182,23 @@ function _mountPortal(frame) {
|
|
|
214
182
|
const placeHolderElement = createTextElement('');
|
|
215
183
|
_pushMountExitFrame(element, {
|
|
216
184
|
renderRuntime,
|
|
217
|
-
|
|
185
|
+
subtreeRightBoundary,
|
|
218
186
|
context: null,
|
|
219
187
|
parentReference: null,
|
|
220
188
|
hostNamespace: null,
|
|
221
189
|
placeHolderElement,
|
|
222
190
|
});
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
hostNamespace: renderRuntime.hostAdapter.getHostNamespaces(child, undefined)?.self,
|
|
232
|
-
placeHolderElement: null,
|
|
233
|
-
});
|
|
234
|
-
}
|
|
191
|
+
_pushMountChildrenFrame(element, {
|
|
192
|
+
renderRuntime,
|
|
193
|
+
hostNamespace: renderRuntime.hostAdapter.getHostNamespaces(element.children, undefined)?.self,
|
|
194
|
+
subtreeRightBoundary,
|
|
195
|
+
context,
|
|
196
|
+
parentReference: element.ref,
|
|
197
|
+
children: element.children,
|
|
198
|
+
});
|
|
235
199
|
_pushMountEnterFrame(placeHolderElement, {
|
|
236
200
|
renderRuntime,
|
|
237
|
-
|
|
201
|
+
subtreeRightBoundary,
|
|
238
202
|
context: null,
|
|
239
203
|
parentReference,
|
|
240
204
|
hostNamespace: null,
|
|
@@ -243,28 +207,13 @@ function _mountPortal(frame) {
|
|
|
243
207
|
}
|
|
244
208
|
function _mountFragment(frame) {
|
|
245
209
|
const element = frame.node;
|
|
246
|
-
const { parentReference, hostNamespace, context, renderRuntime,
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
placeHolderElement: null,
|
|
256
|
-
});
|
|
257
|
-
break;
|
|
258
|
-
case SIMP_ELEMENT_CHILD_FLAG_ELEMENT:
|
|
259
|
-
const child = element.children;
|
|
260
|
-
child.parent = element;
|
|
261
|
-
_pushMountEnterFrame(child, {
|
|
262
|
-
renderRuntime,
|
|
263
|
-
hostNamespace,
|
|
264
|
-
rightSibling,
|
|
265
|
-
context,
|
|
266
|
-
parentReference,
|
|
267
|
-
placeHolderElement: null,
|
|
268
|
-
});
|
|
269
|
-
}
|
|
210
|
+
const { parentReference, hostNamespace, context, renderRuntime, subtreeRightBoundary } = frame.meta;
|
|
211
|
+
_pushMountChildrenFrame(element, {
|
|
212
|
+
renderRuntime,
|
|
213
|
+
hostNamespace,
|
|
214
|
+
children: element.children,
|
|
215
|
+
parentReference,
|
|
216
|
+
context,
|
|
217
|
+
subtreeRightBoundary: subtreeRightBoundary,
|
|
218
|
+
});
|
|
270
219
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type SimpElement } from './createElement.js';
|
|
2
|
+
import { type MountChildrenFrame, type MountChildrenFrameMeta } from './processStack.js';
|
|
3
|
+
export declare function _pushMountChildrenFrame(parent: SimpElement, meta: MountChildrenFrameMeta): void;
|
|
4
|
+
export declare function _mountChildren(frame: MountChildrenFrame): void;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SIMP_ELEMENT_CHILD_FLAG_ELEMENT, SIMP_ELEMENT_CHILD_FLAG_LIST } from './createElement.js';
|
|
2
|
+
import { _pushMountEnterFrame } from './mounting.js';
|
|
3
|
+
import { MOUNT_CHILDREN_ENTER } from './processStack.js';
|
|
4
|
+
import { isHostLike } from './utils.js';
|
|
5
|
+
export function _pushMountChildrenFrame(parent, meta) {
|
|
6
|
+
meta.renderRuntime.renderStack.push({
|
|
7
|
+
node: parent,
|
|
8
|
+
kind: MOUNT_CHILDREN_ENTER,
|
|
9
|
+
meta,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export function _mountChildren(frame) {
|
|
13
|
+
const parentElement = frame.node;
|
|
14
|
+
const { parentReference, hostNamespace, renderRuntime, context } = frame.meta;
|
|
15
|
+
const subtreeRightBoundary = isHostLike(parentElement.flag) ? null : frame.meta.subtreeRightBoundary;
|
|
16
|
+
switch (parentElement.childFlag) {
|
|
17
|
+
case SIMP_ELEMENT_CHILD_FLAG_ELEMENT: {
|
|
18
|
+
const children = frame.meta.children;
|
|
19
|
+
children.parent = parentElement;
|
|
20
|
+
_pushMountEnterFrame(children, {
|
|
21
|
+
renderRuntime,
|
|
22
|
+
hostNamespace,
|
|
23
|
+
subtreeRightBoundary,
|
|
24
|
+
context,
|
|
25
|
+
parentReference,
|
|
26
|
+
placeHolderElement: null,
|
|
27
|
+
});
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
case SIMP_ELEMENT_CHILD_FLAG_LIST: {
|
|
31
|
+
const children = frame.meta.children;
|
|
32
|
+
for (let i = children.length - 1; i >= 0; i--) {
|
|
33
|
+
const child = children[i];
|
|
34
|
+
child.parent = parentElement;
|
|
35
|
+
const rightSibling = children[child.index + 1] || subtreeRightBoundary;
|
|
36
|
+
_pushMountEnterFrame(child, {
|
|
37
|
+
renderRuntime,
|
|
38
|
+
parentReference,
|
|
39
|
+
context,
|
|
40
|
+
hostNamespace,
|
|
41
|
+
subtreeRightBoundary: rightSibling,
|
|
42
|
+
placeHolderElement: null,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
package/core/patching.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Maybe, Nullable } from '../shared/index.js';
|
|
|
2
2
|
import { type SimpElement } from './createElement.js';
|
|
3
3
|
import { type PatchFrame, type PatchFrameMeta } from './processStack.js';
|
|
4
4
|
import { type SimpRenderRuntime } from './runtime.js';
|
|
5
|
-
export declare function patch(prevElement: SimpElement, nextElement: SimpElement, parentReference: unknown,
|
|
5
|
+
export declare function patch(prevElement: SimpElement, nextElement: SimpElement, parentReference: unknown, subtreeRightBoundary: Nullable<SimpElement>, context: unknown, hostNamespace: Maybe<string>, renderRuntime: SimpRenderRuntime): void;
|
|
6
6
|
export declare function _pushPatchEnterFrame(element: SimpElement, meta: PatchFrameMeta): void;
|
|
7
7
|
export declare function _pushPatchExitFrame(element: SimpElement, meta: PatchFrameMeta): void;
|
|
8
8
|
export declare function _patch(frame: PatchFrame): void;
|
package/core/patching.js
CHANGED
|
@@ -7,10 +7,10 @@ import { _pushPatchChildrenFrame } from './patchingChildren.js';
|
|
|
7
7
|
import { PATCH_ENTER, PATCH_EXIT, processStack } from './processStack.js';
|
|
8
8
|
import { applyRef } from './ref.js';
|
|
9
9
|
import { UPDATING_PHASE } from './runtime.js';
|
|
10
|
-
import {
|
|
11
|
-
import { bitScanForwardIndex } from './utils.js';
|
|
10
|
+
import { _pushUnmountEnterFrame } from './unmounting.js';
|
|
11
|
+
import { _clearElementHostReference, bitScanForwardIndex } from './utils.js';
|
|
12
12
|
const patchHandlers = [_patchHostElement, _patchFunctionalComponent, _patchTextElement, _patchPortal, _patchFragment];
|
|
13
|
-
export function patch(prevElement, nextElement, parentReference,
|
|
13
|
+
export function patch(prevElement, nextElement, parentReference, subtreeRightBoundary, context, hostNamespace, renderRuntime) {
|
|
14
14
|
if (renderRuntime.renderStack.length !== 0) {
|
|
15
15
|
throw new Error('Cannot patch while rendering.');
|
|
16
16
|
}
|
|
@@ -18,10 +18,9 @@ export function patch(prevElement, nextElement, parentReference, rightSibling, c
|
|
|
18
18
|
prevElement,
|
|
19
19
|
parentReference,
|
|
20
20
|
renderRuntime,
|
|
21
|
-
|
|
21
|
+
subtreeRightBoundary,
|
|
22
22
|
context,
|
|
23
23
|
hostNamespace,
|
|
24
|
-
placeHolderElement: null,
|
|
25
24
|
});
|
|
26
25
|
processStack(renderRuntime);
|
|
27
26
|
}
|
|
@@ -52,7 +51,7 @@ export function _patch(frame) {
|
|
|
52
51
|
function _replaceWithNewElement(frame) {
|
|
53
52
|
const nextElement = frame.node;
|
|
54
53
|
const { prevElement, parentReference, context, hostNamespace, renderRuntime } = frame.meta;
|
|
55
|
-
_pushUnmountEnterFrame(prevElement,
|
|
54
|
+
_pushUnmountEnterFrame(prevElement, frame.meta);
|
|
56
55
|
nextElement.parent = prevElement.parent;
|
|
57
56
|
if ((nextElement.flag & SIMP_ELEMENT_FLAG_HOST) !== 0 && (prevElement.flag & SIMP_ELEMENT_FLAG_HOST) !== 0) {
|
|
58
57
|
_pushHostOperationReplaceElement(nextElement, renderRuntime, {
|
|
@@ -64,14 +63,14 @@ function _replaceWithNewElement(frame) {
|
|
|
64
63
|
hostNamespace,
|
|
65
64
|
renderRuntime,
|
|
66
65
|
parentReference: null,
|
|
67
|
-
|
|
66
|
+
subtreeRightBoundary: null,
|
|
68
67
|
placeHolderElement: null,
|
|
69
68
|
});
|
|
70
69
|
}
|
|
71
70
|
else {
|
|
72
71
|
_clearElementHostReference(prevElement, parentReference, renderRuntime);
|
|
73
72
|
_pushMountEnterFrame(nextElement, {
|
|
74
|
-
|
|
73
|
+
subtreeRightBoundary: frame.meta.subtreeRightBoundary,
|
|
75
74
|
renderRuntime,
|
|
76
75
|
hostNamespace,
|
|
77
76
|
context,
|
|
@@ -82,7 +81,7 @@ function _replaceWithNewElement(frame) {
|
|
|
82
81
|
}
|
|
83
82
|
function _patchHostElement(frame) {
|
|
84
83
|
const nextElement = frame.node;
|
|
85
|
-
const { prevElement, context, hostNamespace, renderRuntime } = frame.meta;
|
|
84
|
+
const { prevElement, context, hostNamespace, renderRuntime, subtreeRightBoundary, parentReference } = frame.meta;
|
|
86
85
|
if (frame.kind === PATCH_EXIT) {
|
|
87
86
|
renderRuntime.hostAdapter.patchProps(nextElement.reference, prevElement, nextElement, renderRuntime, hostNamespace);
|
|
88
87
|
if (prevElement.className !== nextElement.className) {
|
|
@@ -98,31 +97,33 @@ function _patchHostElement(frame) {
|
|
|
98
97
|
prevElement,
|
|
99
98
|
renderRuntime,
|
|
100
99
|
hostNamespace,
|
|
101
|
-
|
|
102
|
-
context
|
|
103
|
-
parentReference
|
|
104
|
-
placeHolderElement: null,
|
|
100
|
+
subtreeRightBoundary,
|
|
101
|
+
context,
|
|
102
|
+
parentReference,
|
|
105
103
|
});
|
|
106
104
|
_pushPatchChildrenFrame(nextElement, {
|
|
107
|
-
prevElement,
|
|
108
|
-
|
|
105
|
+
prevParentElement: prevElement,
|
|
106
|
+
nextChildren: nextElement.children,
|
|
107
|
+
prevChildren: prevElement.children,
|
|
108
|
+
nextParentChildFlag: nextElement.childFlag,
|
|
109
|
+
prevParentChildFlag: prevElement.childFlag,
|
|
110
|
+
subtreeRightBoundary,
|
|
109
111
|
hostNamespace: renderRuntime.hostAdapter.getHostNamespaces(nextElement, hostNamespace)?.children,
|
|
110
|
-
rightSibling: null,
|
|
111
112
|
context,
|
|
112
113
|
parentReference: nextElement.reference,
|
|
113
|
-
|
|
114
|
+
renderRuntime,
|
|
114
115
|
});
|
|
115
116
|
}
|
|
116
117
|
function _patchFunctionalComponent(frame) {
|
|
117
118
|
const nextElement = frame.node;
|
|
118
|
-
const { prevElement, context, renderRuntime, hostNamespace,
|
|
119
|
+
const { prevElement, context, renderRuntime, hostNamespace, subtreeRightBoundary, parentReference } = frame.meta;
|
|
119
120
|
if (frame.kind === PATCH_EXIT) {
|
|
120
121
|
lifecycleEventBus.publish({ type: 'updated', element: nextElement, renderRuntime });
|
|
121
122
|
return;
|
|
122
123
|
}
|
|
123
124
|
if (prevElement.unmounted) {
|
|
124
125
|
_pushMountEnterFrame(nextElement, {
|
|
125
|
-
|
|
126
|
+
subtreeRightBoundary,
|
|
126
127
|
renderRuntime,
|
|
127
128
|
hostNamespace,
|
|
128
129
|
context,
|
|
@@ -176,6 +177,7 @@ function _patchFunctionalComponent(frame) {
|
|
|
176
177
|
});
|
|
177
178
|
} while (triedToRerender);
|
|
178
179
|
normalizeRoot(nextElement, nextChildren, false);
|
|
180
|
+
nextChildren = nextElement.children;
|
|
179
181
|
}
|
|
180
182
|
catch (error) {
|
|
181
183
|
const parentChildren = prevElement.parent?.children;
|
|
@@ -196,7 +198,8 @@ function _patchFunctionalComponent(frame) {
|
|
|
196
198
|
prevElement.parent.childFlag = SIMP_ELEMENT_CHILD_FLAG_EMPTY;
|
|
197
199
|
prevElement.parent.children = null;
|
|
198
200
|
}
|
|
199
|
-
|
|
201
|
+
_clearElementHostReference(prevElement, parentReference, renderRuntime);
|
|
202
|
+
_pushUnmountEnterFrame(prevElement, frame.meta);
|
|
200
203
|
const event = {
|
|
201
204
|
type: 'errored',
|
|
202
205
|
element: nextElement,
|
|
@@ -219,19 +222,21 @@ function _patchFunctionalComponent(frame) {
|
|
|
219
222
|
prevElement,
|
|
220
223
|
renderRuntime,
|
|
221
224
|
hostNamespace,
|
|
222
|
-
|
|
223
|
-
context
|
|
224
|
-
parentReference
|
|
225
|
-
placeHolderElement: null,
|
|
225
|
+
subtreeRightBoundary,
|
|
226
|
+
context,
|
|
227
|
+
parentReference,
|
|
226
228
|
});
|
|
227
229
|
_pushPatchChildrenFrame(nextElement, {
|
|
228
|
-
|
|
230
|
+
subtreeRightBoundary,
|
|
231
|
+
prevParentChildFlag: prevElementSnapshot.childFlag,
|
|
232
|
+
nextParentChildFlag: nextElement.childFlag,
|
|
233
|
+
prevChildren: prevElementSnapshot.children,
|
|
234
|
+
nextChildren: nextChildren,
|
|
229
235
|
renderRuntime,
|
|
230
236
|
hostNamespace,
|
|
231
|
-
rightSibling,
|
|
232
|
-
context,
|
|
233
237
|
parentReference,
|
|
234
|
-
|
|
238
|
+
context,
|
|
239
|
+
prevParentElement: prevElementSnapshot,
|
|
235
240
|
});
|
|
236
241
|
}
|
|
237
242
|
function _patchTextElement(frame) {
|
|
@@ -244,7 +249,7 @@ function _patchTextElement(frame) {
|
|
|
244
249
|
}
|
|
245
250
|
function _patchPortal(frame) {
|
|
246
251
|
const nextElement = frame.node;
|
|
247
|
-
const { prevElement, renderRuntime, context } = frame.meta;
|
|
252
|
+
const { prevElement, renderRuntime, context, subtreeRightBoundary, hostNamespace, parentReference } = frame.meta;
|
|
248
253
|
const prevContainer = prevElement.ref;
|
|
249
254
|
const nextContainer = nextElement.ref;
|
|
250
255
|
const nextChildren = nextElement.children;
|
|
@@ -258,33 +263,38 @@ function _patchPortal(frame) {
|
|
|
258
263
|
_pushPatchExitFrame(nextElement, {
|
|
259
264
|
prevElement,
|
|
260
265
|
renderRuntime,
|
|
261
|
-
hostNamespace
|
|
262
|
-
|
|
263
|
-
context
|
|
264
|
-
parentReference
|
|
265
|
-
placeHolderElement: null,
|
|
266
|
+
hostNamespace,
|
|
267
|
+
subtreeRightBoundary,
|
|
268
|
+
context,
|
|
269
|
+
parentReference,
|
|
266
270
|
});
|
|
267
271
|
}
|
|
268
272
|
_pushPatchChildrenFrame(nextElement, {
|
|
269
|
-
prevElement,
|
|
270
|
-
renderRuntime,
|
|
271
|
-
hostNamespace: renderRuntime.hostAdapter.getHostNamespaces(nextChildren, undefined)?.self,
|
|
272
|
-
rightSibling: null,
|
|
273
|
+
prevParentElement: prevElement,
|
|
273
274
|
context,
|
|
274
275
|
parentReference: nextContainer,
|
|
275
|
-
|
|
276
|
+
hostNamespace: renderRuntime.hostAdapter.getHostNamespaces(nextChildren, undefined)?.self,
|
|
277
|
+
renderRuntime,
|
|
278
|
+
prevChildren: prevElement.children,
|
|
279
|
+
nextChildren,
|
|
280
|
+
nextParentChildFlag: nextElement.childFlag,
|
|
281
|
+
prevParentChildFlag: prevElement.childFlag,
|
|
282
|
+
subtreeRightBoundary,
|
|
276
283
|
});
|
|
277
284
|
}
|
|
278
285
|
function _patchFragment(frame) {
|
|
279
286
|
const nextElement = frame.node;
|
|
280
|
-
const { prevElement, renderRuntime, context, parentReference, hostNamespace,
|
|
287
|
+
const { prevElement, renderRuntime, context, parentReference, hostNamespace, subtreeRightBoundary } = frame.meta;
|
|
281
288
|
_pushPatchChildrenFrame(nextElement, {
|
|
282
|
-
|
|
283
|
-
parentReference,
|
|
284
|
-
rightSibling,
|
|
289
|
+
subtreeRightBoundary,
|
|
285
290
|
context,
|
|
291
|
+
parentReference,
|
|
292
|
+
prevParentChildFlag: prevElement.childFlag,
|
|
293
|
+
nextParentChildFlag: nextElement.childFlag,
|
|
294
|
+
nextChildren: nextElement.children,
|
|
295
|
+
prevChildren: prevElement.children,
|
|
286
296
|
renderRuntime,
|
|
287
297
|
hostNamespace,
|
|
288
|
-
|
|
298
|
+
prevParentElement: prevElement,
|
|
289
299
|
});
|
|
290
300
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type SimpElement } from './createElement.js';
|
|
2
|
-
import { type PatchChildrenFrame, type
|
|
3
|
-
export declare function _pushPatchChildrenFrame(
|
|
4
|
-
export declare function _pushPatchKeyedChildrenFrame(element: SimpElement, meta:
|
|
2
|
+
import { type PatchChildrenFrame, type PatchChildrenFrameMeta } from './processStack.js';
|
|
3
|
+
export declare function _pushPatchChildrenFrame(parent: SimpElement, meta: PatchChildrenFrameMeta): void;
|
|
4
|
+
export declare function _pushPatchKeyedChildrenFrame(element: SimpElement, meta: PatchChildrenFrameMeta): void;
|
|
5
5
|
export declare function _patchChildren(frame: PatchChildrenFrame): void;
|
|
6
6
|
export declare function _patchKeyedChildren(frame: PatchChildrenFrame): void;
|