@simpreact/simpreact 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +1 -1
- package/compat/context.d.ts +4 -4
- package/compat/context.js +3 -2
- package/compat/core.d.ts +4 -0
- package/compat/core.js +9 -5
- package/compat/dom.d.ts +4 -5
- package/compat/dom.js +3 -2
- package/compat/hooks.d.ts +16 -13
- package/compat/hooks.js +19 -15
- package/compat/index.d.ts +10 -9
- package/compat/renderRuntime.d.ts +2 -0
- package/compat/renderRuntime.js +14 -0
- package/component/index.d.ts +16 -0
- package/component/index.js +164 -0
- package/context/index.d.ts +12 -5
- package/context/index.js +62 -57
- package/core/createElement.d.ts +29 -20
- package/core/createElement.js +159 -133
- package/core/hostAdapter.d.ts +8 -12
- package/core/hostAdapter.js +1 -4
- package/core/hostOperations.d.ts +5 -0
- package/core/hostOperations.js +15 -0
- package/core/index.d.ts +29 -6
- package/core/internal.d.ts +3 -0
- package/core/internal.js +3 -0
- package/core/lifecycleEventBus.d.ts +15 -6
- package/core/lifecycleEventBus.js +16 -2
- package/core/memo.d.ts +0 -2
- package/core/memo.js +1 -3
- package/core/mounting.d.ts +7 -9
- package/core/mounting.js +221 -79
- package/core/patching.d.ts +7 -8
- package/core/patching.js +235 -252
- package/core/patchingChildren.d.ts +6 -0
- package/core/patchingChildren.js +330 -0
- package/core/portal.d.ts +1 -1
- package/core/portal.js +17 -7
- package/core/processStack.d.ts +69 -0
- package/core/processStack.js +63 -0
- package/core/ref.d.ts +4 -3
- package/core/rerender.d.ts +4 -14
- package/core/rerender.js +67 -112
- package/core/runtime.d.ts +17 -0
- package/core/runtime.js +2 -0
- package/core/unmounting.d.ts +11 -6
- package/core/unmounting.js +81 -40
- package/core/utils.d.ts +10 -0
- package/core/utils.js +143 -0
- package/dom/attach-element-to-dom.d.ts +4 -3
- package/dom/attach-element-to-dom.js +12 -7
- package/dom/domAdapter.js +22 -25
- package/dom/events.d.ts +5 -5
- package/dom/events.js +33 -16
- package/dom/index.d.ts +16 -5
- package/dom/index.js +4 -3
- package/dom/props/controlled/index.d.ts +3 -3
- package/dom/props/controlled/index.js +8 -8
- package/dom/props/controlled/input.d.ts +3 -3
- package/dom/props/controlled/input.js +57 -34
- package/dom/props/controlled/select.d.ts +3 -3
- package/dom/props/controlled/select.js +39 -26
- package/dom/props/controlled/textarea.d.ts +3 -3
- package/dom/props/controlled/textarea.js +57 -34
- package/dom/props/dangerInnerHTML.d.ts +2 -2
- package/dom/props/dangerInnerHTML.js +3 -2
- package/dom/props/props.d.ts +4 -4
- package/dom/props/props.js +24 -21
- package/dom/render.d.ts +4 -5
- package/dom/render.js +38 -34
- package/hooks/index.d.ts +15 -13
- package/hooks/index.js +153 -157
- package/jsx-runtime/index.d.ts +2 -1
- package/package.json +9 -1
- package/shared/index.d.ts +10 -0
- package/shared/index.js +4 -7
- package/shared/utils.js +4 -4
- package/shared/EventBus.d.ts +0 -18
- package/shared/EventBus.js +0 -28
package/core/mounting.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type { Maybe, Nullable } from '../shared/index.js';
|
|
2
|
-
import type
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function mountArrayChildren(children: SimpElement[], reference: Nullable<HostReference>, nextReference: Nullable<HostReference>, context: unknown, parentElement: SimpElement, hostNamespace: Maybe<string>): void;
|
|
10
|
-
export declare function mountPortal(element: SimpElement, parentReference: Nullable<HostReference>, nextReference: Nullable<HostReference>, context: unknown): void;
|
|
2
|
+
import { type SimpElement } from './createElement.js';
|
|
3
|
+
import { type MountFrame, type MountFrameMeta } from './processStack.js';
|
|
4
|
+
import { type SimpRenderRuntime } from './runtime.js';
|
|
5
|
+
export declare function mount(element: SimpElement, parentReference: unknown, rightSibling: Nullable<SimpElement>, context: unknown, hostNamespace: Maybe<string>, renderRuntime: SimpRenderRuntime): void;
|
|
6
|
+
export declare function _mount(frame: MountFrame): void;
|
|
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,75 +1,134 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { createTextElement, normalizeRoot } from './createElement.js';
|
|
4
|
-
import { applyRef } from './ref.js';
|
|
1
|
+
import { createTextElement, normalizeRoot, SIMP_ELEMENT_CHILD_FLAG_ELEMENT, SIMP_ELEMENT_CHILD_FLAG_LIST, SIMP_ELEMENT_CHILD_FLAG_TEXT, } from './createElement.js';
|
|
2
|
+
import { _pushHostOperationPlaceElement } from './hostOperations.js';
|
|
5
3
|
import { lifecycleEventBus } from './lifecycleEventBus.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
mountFunctionalElement(element, parentReference, nextReference, context, hostNamespace);
|
|
15
|
-
}
|
|
16
|
-
else if (element.flag === 'FRAGMENT') {
|
|
17
|
-
mountFragment(element, parentReference, nextReference, context, hostNamespace);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
mountPortal(element, parentReference, nextReference, context);
|
|
4
|
+
import { MOUNT_ENTER, MOUNT_EXIT, processStack } from './processStack.js';
|
|
5
|
+
import { applyRef } from './ref.js';
|
|
6
|
+
import { MOUNTING_PHASE } from './runtime.js';
|
|
7
|
+
import { bitScanForwardIndex } from './utils.js';
|
|
8
|
+
const mountHandlers = [_mountHostElement, _mountFunctionalElement, _mountTextElement, _mountPortal, _mountFragment];
|
|
9
|
+
export function mount(element, parentReference, rightSibling, context, hostNamespace, renderRuntime) {
|
|
10
|
+
if (renderRuntime.renderStack.length !== 0) {
|
|
11
|
+
throw new Error('Cannot mount while rendering.');
|
|
21
12
|
}
|
|
13
|
+
_pushMountEnterFrame(element, {
|
|
14
|
+
parentReference,
|
|
15
|
+
rightSibling,
|
|
16
|
+
context,
|
|
17
|
+
hostNamespace,
|
|
18
|
+
renderRuntime,
|
|
19
|
+
placeHolderElement: null,
|
|
20
|
+
});
|
|
21
|
+
processStack(renderRuntime);
|
|
22
22
|
}
|
|
23
|
-
export function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
export function _mount(frame) {
|
|
24
|
+
mountHandlers[bitScanForwardIndex(frame.node.flag)](frame);
|
|
25
|
+
}
|
|
26
|
+
export function _pushMountEnterFrame(element, meta) {
|
|
27
|
+
meta.renderRuntime.renderStack.push({
|
|
28
|
+
node: element,
|
|
29
|
+
kind: MOUNT_ENTER,
|
|
30
|
+
meta,
|
|
31
|
+
});
|
|
28
32
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
function _pushMountExitFrame(element, meta) {
|
|
34
|
+
meta.renderRuntime.renderStack.push({
|
|
35
|
+
node: element,
|
|
36
|
+
kind: MOUNT_EXIT,
|
|
37
|
+
meta,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export function _pushMountArrayChildrenFrame(element, meta) {
|
|
35
41
|
const children = element.children;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
mount(children, hostReference, null, context, hostNamespaces?.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 });
|
|
42
47
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
}
|
|
49
|
+
function _mountHostElement(frame) {
|
|
50
|
+
const element = frame.node;
|
|
51
|
+
const { parentReference, rightSibling, context, hostNamespace, renderRuntime } = frame.meta;
|
|
52
|
+
if (frame.kind === MOUNT_EXIT) {
|
|
53
|
+
if (element.childFlag === SIMP_ELEMENT_CHILD_FLAG_TEXT) {
|
|
54
|
+
renderRuntime.hostAdapter.setTextContent(element.reference, element.props.children);
|
|
48
55
|
}
|
|
56
|
+
if (element.props) {
|
|
57
|
+
renderRuntime.hostAdapter.mountProps(element.reference, element, renderRuntime, hostNamespace);
|
|
58
|
+
}
|
|
59
|
+
if (element.className) {
|
|
60
|
+
renderRuntime.hostAdapter.setClassname(element.reference, element.className, hostNamespace);
|
|
61
|
+
}
|
|
62
|
+
if (parentReference) {
|
|
63
|
+
_pushHostOperationPlaceElement(element, {
|
|
64
|
+
renderRuntime,
|
|
65
|
+
rightSibling,
|
|
66
|
+
parentReference,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
applyRef(element);
|
|
70
|
+
return;
|
|
49
71
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
72
|
+
const hostNamespaces = renderRuntime.hostAdapter.getHostNamespaces(element, hostNamespace);
|
|
73
|
+
const hostReference = (element.reference = renderRuntime.hostAdapter.createReference(element.type, hostNamespaces?.self));
|
|
74
|
+
renderRuntime.hostAdapter.attachElementToReference(element, hostReference, renderRuntime);
|
|
75
|
+
_pushMountExitFrame(element, {
|
|
76
|
+
renderRuntime,
|
|
77
|
+
hostNamespace: hostNamespaces?.self,
|
|
78
|
+
rightSibling,
|
|
79
|
+
context,
|
|
80
|
+
parentReference,
|
|
81
|
+
placeHolderElement: null,
|
|
82
|
+
});
|
|
83
|
+
switch (element.childFlag) {
|
|
84
|
+
case SIMP_ELEMENT_CHILD_FLAG_LIST: {
|
|
85
|
+
_pushMountArrayChildrenFrame(element, {
|
|
86
|
+
renderRuntime,
|
|
87
|
+
hostNamespace: hostNamespaces?.children,
|
|
88
|
+
rightSibling: null,
|
|
89
|
+
context,
|
|
90
|
+
parentReference: hostReference,
|
|
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
|
+
}
|
|
55
106
|
}
|
|
56
|
-
applyRef(element);
|
|
57
107
|
}
|
|
58
|
-
|
|
108
|
+
function _mountFunctionalElement(frame) {
|
|
109
|
+
const element = frame.node;
|
|
110
|
+
const { parentReference, rightSibling, context, hostNamespace, renderRuntime } = frame.meta;
|
|
111
|
+
if (frame.kind === MOUNT_EXIT) {
|
|
112
|
+
lifecycleEventBus.publish({ type: 'mounted', element, renderRuntime });
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
59
115
|
if (context) {
|
|
60
116
|
element.context = context;
|
|
61
117
|
}
|
|
62
118
|
if (element.unmounted) {
|
|
63
119
|
element.unmounted = false;
|
|
64
120
|
}
|
|
65
|
-
element.store = { latestElement:
|
|
121
|
+
element.store = { latestElement: null, hostNamespace: null, forceRerender: false };
|
|
122
|
+
element.store.latestElement = element;
|
|
66
123
|
if (hostNamespace) {
|
|
67
124
|
element.store.hostNamespace = hostNamespace;
|
|
68
125
|
}
|
|
69
|
-
// FC element always has Maybe<SimpElement> children due to normalization process.
|
|
126
|
+
// FC element always has Maybe<SimpElement> children due to a normalization process.
|
|
70
127
|
let children;
|
|
71
128
|
let triedToRerenderUnsubscribe;
|
|
72
129
|
try {
|
|
130
|
+
renderRuntime.renderPhase = MOUNTING_PHASE;
|
|
131
|
+
renderRuntime.currentRenderingFCElement = element;
|
|
73
132
|
let triedToRerender = false;
|
|
74
133
|
let rerenderCounter = 0;
|
|
75
134
|
triedToRerenderUnsubscribe = lifecycleEventBus.subscribe(event => {
|
|
@@ -82,47 +141,130 @@ export function mountFunctionalElement(element, parentReference, nextReference,
|
|
|
82
141
|
if (++rerenderCounter >= 25) {
|
|
83
142
|
throw new Error('Too many re-renders.');
|
|
84
143
|
}
|
|
85
|
-
lifecycleEventBus.publish({
|
|
86
|
-
|
|
87
|
-
|
|
144
|
+
lifecycleEventBus.publish({
|
|
145
|
+
type: 'beforeRender',
|
|
146
|
+
element,
|
|
147
|
+
renderRuntime,
|
|
148
|
+
});
|
|
149
|
+
children = renderRuntime.renderer(element.type, element, renderRuntime);
|
|
150
|
+
lifecycleEventBus.publish({
|
|
151
|
+
type: 'afterRender',
|
|
152
|
+
element,
|
|
153
|
+
renderRuntime,
|
|
154
|
+
});
|
|
88
155
|
} while (triedToRerender);
|
|
89
|
-
|
|
156
|
+
normalizeRoot(element, children, false);
|
|
90
157
|
}
|
|
91
158
|
catch (error) {
|
|
92
|
-
|
|
159
|
+
const event = {
|
|
160
|
+
type: 'errored',
|
|
161
|
+
element,
|
|
162
|
+
error,
|
|
163
|
+
handled: false,
|
|
164
|
+
renderRuntime,
|
|
165
|
+
};
|
|
166
|
+
lifecycleEventBus.publish(event);
|
|
167
|
+
if (!event.handled) {
|
|
168
|
+
throw new Error('Error occurred during rendering a component', { cause: event.error });
|
|
169
|
+
}
|
|
93
170
|
return;
|
|
94
171
|
}
|
|
95
172
|
finally {
|
|
96
173
|
triedToRerenderUnsubscribe();
|
|
174
|
+
renderRuntime.renderPhase = null;
|
|
175
|
+
renderRuntime.currentRenderingFCElement = null;
|
|
97
176
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
177
|
+
_pushMountExitFrame(element, {
|
|
178
|
+
renderRuntime,
|
|
179
|
+
hostNamespace: null,
|
|
180
|
+
rightSibling: null,
|
|
181
|
+
context: null,
|
|
182
|
+
parentReference: null,
|
|
183
|
+
placeHolderElement: null,
|
|
184
|
+
});
|
|
185
|
+
if (element.children) {
|
|
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
|
+
});
|
|
101
196
|
}
|
|
102
|
-
lifecycleEventBus.publish({ type: 'mounted', element });
|
|
103
197
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
198
|
+
function _mountTextElement(frame) {
|
|
199
|
+
const { renderRuntime, parentReference } = frame.meta;
|
|
200
|
+
frame.node.reference = renderRuntime.hostAdapter.createTextReference(frame.node.children);
|
|
201
|
+
_pushHostOperationPlaceElement(frame.node, {
|
|
202
|
+
renderRuntime,
|
|
203
|
+
rightSibling: frame.meta.rightSibling,
|
|
204
|
+
parentReference,
|
|
205
|
+
});
|
|
113
206
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
207
|
+
function _mountPortal(frame) {
|
|
208
|
+
const element = frame.node;
|
|
209
|
+
const { parentReference, rightSibling, context, renderRuntime } = frame.meta;
|
|
210
|
+
if (frame.kind === MOUNT_EXIT) {
|
|
211
|
+
element.reference = frame.meta.placeHolderElement.reference;
|
|
212
|
+
return;
|
|
118
213
|
}
|
|
119
|
-
|
|
120
|
-
|
|
214
|
+
const placeHolderElement = createTextElement('');
|
|
215
|
+
_pushMountExitFrame(element, {
|
|
216
|
+
renderRuntime,
|
|
217
|
+
rightSibling: null,
|
|
218
|
+
context: null,
|
|
219
|
+
parentReference: null,
|
|
220
|
+
hostNamespace: null,
|
|
221
|
+
placeHolderElement,
|
|
222
|
+
});
|
|
121
223
|
if (element.children) {
|
|
122
|
-
|
|
123
|
-
|
|
224
|
+
const child = element.children;
|
|
225
|
+
child.parent = element;
|
|
226
|
+
_pushMountEnterFrame(child, {
|
|
227
|
+
renderRuntime,
|
|
228
|
+
rightSibling: null,
|
|
229
|
+
context,
|
|
230
|
+
parentReference: element.ref,
|
|
231
|
+
hostNamespace: renderRuntime.hostAdapter.getHostNamespaces(child, undefined)?.self,
|
|
232
|
+
placeHolderElement: null,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
_pushMountEnterFrame(placeHolderElement, {
|
|
236
|
+
renderRuntime,
|
|
237
|
+
rightSibling,
|
|
238
|
+
context: null,
|
|
239
|
+
parentReference,
|
|
240
|
+
hostNamespace: null,
|
|
241
|
+
placeHolderElement: null,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
function _mountFragment(frame) {
|
|
245
|
+
const element = frame.node;
|
|
246
|
+
const { parentReference, hostNamespace, context, renderRuntime, rightSibling } = frame.meta;
|
|
247
|
+
switch (element.childFlag) {
|
|
248
|
+
case SIMP_ELEMENT_CHILD_FLAG_LIST:
|
|
249
|
+
_pushMountArrayChildrenFrame(element, {
|
|
250
|
+
renderRuntime,
|
|
251
|
+
hostNamespace,
|
|
252
|
+
rightSibling,
|
|
253
|
+
context,
|
|
254
|
+
parentReference,
|
|
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
|
+
});
|
|
124
269
|
}
|
|
125
|
-
const placeHolderElement = createTextElement('');
|
|
126
|
-
mountTextElement(placeHolderElement, parentReference, nextReference);
|
|
127
|
-
element.reference = placeHolderElement.reference;
|
|
128
270
|
}
|
package/core/patching.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { Maybe, Nullable } from '../shared/index.js';
|
|
2
|
-
import type
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function findHostReferenceFromElement(element: SimpElement): Nullable<HostReference>;
|
|
2
|
+
import { type SimpElement } from './createElement.js';
|
|
3
|
+
import { type PatchFrame, type PatchFrameMeta } from './processStack.js';
|
|
4
|
+
import { type SimpRenderRuntime } from './runtime.js';
|
|
5
|
+
export declare function patch(prevElement: SimpElement, nextElement: SimpElement, parentReference: unknown, rightSibling: Nullable<SimpElement>, context: unknown, hostNamespace: Maybe<string>, renderRuntime: SimpRenderRuntime): void;
|
|
6
|
+
export declare function _pushPatchEnterFrame(element: SimpElement, meta: PatchFrameMeta): void;
|
|
7
|
+
export declare function _pushPatchExitFrame(element: SimpElement, meta: PatchFrameMeta): void;
|
|
8
|
+
export declare function _patch(frame: PatchFrame): void;
|