@simpreact/simpreact 0.0.0-alpha.dd6f145 → 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/core/context.d.ts +18 -0
- package/core/context.js +18 -0
- package/core/createElement.d.ts +24 -15
- package/core/createElement.js +93 -27
- package/core/fragment.js +1 -2
- package/core/hostAdapter.d.ts +19 -8
- package/core/hostAdapter.js +4 -1
- package/core/index.d.ts +68 -2
- package/core/index.js +6 -2
- package/core/internal.d.ts +7 -3
- package/core/internal.js +7 -3
- package/core/lifecycleEventBus.d.ts +26 -0
- package/core/lifecycleEventBus.js +2 -0
- package/core/mounting.d.ts +11 -7
- package/core/mounting.js +104 -38
- package/core/patching.d.ts +8 -5
- package/core/patching.js +157 -161
- package/core/portal.d.ts +2 -0
- package/core/portal.js +9 -0
- package/core/ref.d.ts +17 -0
- package/core/ref.js +27 -0
- package/core/rerender.d.ts +11 -0
- package/core/rerender.js +61 -3
- package/core/unmounting.d.ts +4 -6
- package/core/unmounting.js +33 -39
- package/dom/attach-element-to-dom.d.ts +4 -0
- package/dom/attach-element-to-dom.js +9 -0
- package/dom/domAdapter.d.ts +3 -2
- package/dom/domAdapter.js +42 -115
- package/dom/events.d.ts +19 -0
- package/dom/events.js +129 -0
- package/dom/index.d.ts +1733 -1
- package/dom/index.js +2 -0
- package/dom/namespace.d.ts +2 -0
- package/dom/namespace.js +1 -0
- package/dom/props/controlled/index.d.ts +7 -0
- package/dom/props/controlled/index.js +51 -0
- package/dom/props/controlled/input.d.ts +7 -0
- package/dom/props/controlled/input.js +80 -0
- package/dom/props/controlled/select.d.ts +6 -0
- package/dom/props/controlled/select.js +76 -0
- package/dom/props/controlled/textarea.d.ts +6 -0
- package/dom/props/controlled/textarea.js +61 -0
- package/dom/props/dangerInnerHTML.d.ts +7 -0
- package/dom/props/dangerInnerHTML.js +24 -0
- package/dom/props/index.d.ts +1 -0
- package/dom/props/index.js +1 -0
- package/dom/props/props.d.ts +5 -0
- package/dom/props/props.js +197 -0
- package/dom/props/style.d.ts +1 -0
- package/dom/props/style.js +32 -0
- package/dom/render.d.ts +3 -3
- package/dom/render.js +31 -17
- package/hooks/index.d.ts +23 -10
- package/hooks/index.js +126 -32
- package/jsx-runtime/index.d.ts +247 -4
- package/jsx-runtime/index.js +3 -6
- package/package.json +22 -15
- package/shared/EventBus.js +1 -3
- package/shared/index.d.ts +19 -4
- package/shared/index.js +5 -4
- package/shared/lang.d.ts +3 -4
- package/shared/lang.js +3 -4
- package/shared/utils.d.ts +3 -3
- package/shared/utils.js +3 -7
- package/core/global.d.ts +0 -21
- package/core/global.js +0 -5
- package/core/jsx-runtime.d.ts +0 -2
- package/core/jsx-runtime.js +0 -2
- package/shared/types.d.ts +0 -8
- package/shared/types.js +0 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SimpNode } from './createElement';
|
|
2
|
+
type Provider<T = any> = (props: {
|
|
3
|
+
value: T;
|
|
4
|
+
children: SimpNode;
|
|
5
|
+
}) => SimpNode;
|
|
6
|
+
type Consumer<T = any> = (props: {
|
|
7
|
+
children: (value: T) => SimpNode;
|
|
8
|
+
}, contextMap: SimpContextMap) => SimpNode;
|
|
9
|
+
export interface SimpContext<T> {
|
|
10
|
+
defaultValue: T;
|
|
11
|
+
Provider: Provider<T>;
|
|
12
|
+
Consumer: Consumer<T>;
|
|
13
|
+
}
|
|
14
|
+
export type SimpContextMap = Map<SimpContext<any>, any>;
|
|
15
|
+
export declare function createContext<T>(defaultValue: T): SimpContext<T>;
|
|
16
|
+
export declare function isProvider(type: any): boolean;
|
|
17
|
+
export declare function isConsumer(type: any): boolean;
|
|
18
|
+
export {};
|
package/core/context.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function createContext(defaultValue) {
|
|
2
|
+
const context = {
|
|
3
|
+
defaultValue,
|
|
4
|
+
Provider: Object.create(null),
|
|
5
|
+
Consumer(props, contextMap) {
|
|
6
|
+
return props.children(contextMap.get(context) ?? defaultValue);
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(context.Consumer, 'isConsumer', { value: true });
|
|
10
|
+
Object.defineProperty(context.Provider, 'context', { value: context, enumerable: true });
|
|
11
|
+
return context;
|
|
12
|
+
}
|
|
13
|
+
export function isProvider(type) {
|
|
14
|
+
return type != null && type.context != null;
|
|
15
|
+
}
|
|
16
|
+
export function isConsumer(type) {
|
|
17
|
+
return type != null && type.isConsumer === true;
|
|
18
|
+
}
|
package/core/createElement.d.ts
CHANGED
|
@@ -1,24 +1,33 @@
|
|
|
1
|
-
import type { Many, Maybe,
|
|
1
|
+
import type { Many, Maybe, Nullable, SimpText } from '../shared';
|
|
2
2
|
import type { HostReference } from './hostAdapter';
|
|
3
|
-
|
|
4
|
-
export type
|
|
3
|
+
import type { SimpContextMap } from './context';
|
|
4
|
+
export type SimpNode = SimpElement | SimpText | Array<SimpNode> | boolean | null | undefined;
|
|
5
5
|
export type Key = string | number | bigint;
|
|
6
|
-
export interface FunctionComponent
|
|
7
|
-
(props:
|
|
6
|
+
export interface FunctionComponent {
|
|
7
|
+
(props: any): SimpNode;
|
|
8
8
|
}
|
|
9
|
-
export type FC
|
|
10
|
-
export type SimpElementFlag = 'FC' | 'HOST' | 'TEXT' | 'FRAGMENT';
|
|
11
|
-
export interface
|
|
9
|
+
export type FC = FunctionComponent;
|
|
10
|
+
export type SimpElementFlag = 'FC' | 'HOST' | 'TEXT' | 'FRAGMENT' | 'PROVIDER' | 'CONSUMER' | 'PORTAL';
|
|
11
|
+
export interface SimpElementStore {
|
|
12
|
+
latestElement?: Maybe<SimpElement>;
|
|
13
|
+
hostNamespace?: Maybe<string>;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
export interface SimpElement {
|
|
12
17
|
flag: SimpElementFlag;
|
|
18
|
+
parent: Nullable<SimpElement>;
|
|
13
19
|
key?: Maybe<Key>;
|
|
14
|
-
type?: Maybe<string | FunctionComponent
|
|
15
|
-
props?:
|
|
20
|
+
type?: Maybe<string | FunctionComponent>;
|
|
21
|
+
props?: any;
|
|
16
22
|
children?: Maybe<SimpNode>;
|
|
17
23
|
className?: Maybe<string>;
|
|
18
24
|
reference?: Maybe<HostReference>;
|
|
19
|
-
store?:
|
|
25
|
+
store?: SimpElementStore;
|
|
26
|
+
contextMap?: Maybe<SimpContextMap>;
|
|
27
|
+
ref?: any;
|
|
28
|
+
unmounted?: boolean;
|
|
20
29
|
}
|
|
21
|
-
export declare function createElement
|
|
22
|
-
export declare function createTextElement(text:
|
|
23
|
-
export declare function normalizeChildren(children: SimpNode): Maybe<Many<SimpElement>>;
|
|
24
|
-
export declare function normalizeRoot(node: SimpNode): SimpElement
|
|
30
|
+
export declare function createElement(type: string | FunctionComponent, props?: any, ...children: SimpNode[]): SimpElement;
|
|
31
|
+
export declare function createTextElement(text: SimpText): SimpElement;
|
|
32
|
+
export declare function normalizeChildren(children: SimpNode, skipIgnoredCheck: boolean): Maybe<Many<SimpElement>>;
|
|
33
|
+
export declare function normalizeRoot(node: SimpNode, skipIgnoredCheck: boolean): Maybe<SimpElement>;
|
package/core/createElement.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isSimpText } from '../shared';
|
|
2
2
|
import { Fragment } from './fragment';
|
|
3
|
+
import { isConsumer, isProvider } from './context';
|
|
3
4
|
export function createElement(type, props, ...children) {
|
|
4
5
|
let newProps;
|
|
5
6
|
let className;
|
|
@@ -16,6 +17,7 @@ export function createElement(type, props, ...children) {
|
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
if (typeof type === 'string') {
|
|
20
|
+
let ref;
|
|
19
21
|
if (props != null) {
|
|
20
22
|
for (const propName in props) {
|
|
21
23
|
if (propName === 'className') {
|
|
@@ -29,14 +31,20 @@ export function createElement(type, props, ...children) {
|
|
|
29
31
|
definedChildren = props[propName];
|
|
30
32
|
}
|
|
31
33
|
}
|
|
34
|
+
else if (propName === 'ref') {
|
|
35
|
+
ref = {
|
|
36
|
+
value: props[propName],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
32
39
|
else {
|
|
33
|
-
(newProps
|
|
40
|
+
(newProps ||= {})[propName] = props[propName];
|
|
34
41
|
}
|
|
35
42
|
}
|
|
36
43
|
}
|
|
37
44
|
const element = {
|
|
38
45
|
flag: 'HOST',
|
|
39
46
|
type,
|
|
47
|
+
parent: null,
|
|
40
48
|
};
|
|
41
49
|
if (className) {
|
|
42
50
|
element.className = className;
|
|
@@ -44,21 +52,49 @@ export function createElement(type, props, ...children) {
|
|
|
44
52
|
if (key) {
|
|
45
53
|
element.key = key;
|
|
46
54
|
}
|
|
47
|
-
if ((definedChildren = normalizeChildren(definedChildren))) {
|
|
55
|
+
if ((definedChildren = normalizeChildren(definedChildren, false))) {
|
|
48
56
|
element.children = definedChildren;
|
|
49
57
|
}
|
|
50
58
|
if (newProps) {
|
|
51
59
|
element.props = newProps;
|
|
52
60
|
}
|
|
61
|
+
if (ref) {
|
|
62
|
+
element.ref = ref;
|
|
63
|
+
}
|
|
53
64
|
return element;
|
|
54
65
|
}
|
|
55
66
|
else if (type === Fragment) {
|
|
56
67
|
const element = {
|
|
57
68
|
flag: 'FRAGMENT',
|
|
69
|
+
parent: null,
|
|
70
|
+
};
|
|
71
|
+
if ((definedChildren = normalizeChildren(definedChildren || (props != null ? props.children : null), false))) {
|
|
72
|
+
element.children = definedChildren;
|
|
73
|
+
}
|
|
74
|
+
if (props != null && props.key) {
|
|
75
|
+
element.key = props?.key;
|
|
76
|
+
}
|
|
77
|
+
return element;
|
|
78
|
+
}
|
|
79
|
+
else if (isProvider(type)) {
|
|
80
|
+
const element = { flag: 'PROVIDER', type, props: { value: props.value }, parent: null };
|
|
81
|
+
if ((definedChildren = normalizeChildren(definedChildren || props.children, false))) {
|
|
82
|
+
element.children = definedChildren;
|
|
83
|
+
}
|
|
84
|
+
if (props != null && props.key) {
|
|
85
|
+
element.key = props?.key;
|
|
86
|
+
}
|
|
87
|
+
return element;
|
|
88
|
+
}
|
|
89
|
+
else if (isConsumer(type)) {
|
|
90
|
+
const element = {
|
|
91
|
+
flag: 'CONSUMER',
|
|
92
|
+
type,
|
|
93
|
+
props: { children: definedChildren || (props != null ? props.children : null) },
|
|
94
|
+
parent: null,
|
|
58
95
|
};
|
|
59
|
-
element.children = normalizeChildren(definedChildren || (props != null ? props.children : null));
|
|
60
96
|
if (props != null && props.key) {
|
|
61
|
-
element.key = props
|
|
97
|
+
element.key = props?.key;
|
|
62
98
|
}
|
|
63
99
|
return element;
|
|
64
100
|
}
|
|
@@ -74,16 +110,17 @@ export function createElement(type, props, ...children) {
|
|
|
74
110
|
}
|
|
75
111
|
}
|
|
76
112
|
else {
|
|
77
|
-
(newProps
|
|
113
|
+
(newProps ||= {})[propName] = props[propName];
|
|
78
114
|
}
|
|
79
115
|
}
|
|
80
116
|
}
|
|
81
117
|
if (definedChildren !== undefined) {
|
|
82
|
-
(newProps
|
|
118
|
+
(newProps ||= {})['children'] = definedChildren;
|
|
83
119
|
}
|
|
84
120
|
const element = {
|
|
85
121
|
flag: 'FC',
|
|
86
122
|
type,
|
|
123
|
+
parent: null,
|
|
87
124
|
};
|
|
88
125
|
if (key) {
|
|
89
126
|
element.key = key;
|
|
@@ -97,48 +134,77 @@ export function createElement(type, props, ...children) {
|
|
|
97
134
|
export function createTextElement(text) {
|
|
98
135
|
return {
|
|
99
136
|
flag: 'TEXT',
|
|
100
|
-
children: text
|
|
137
|
+
children: text,
|
|
138
|
+
parent: null,
|
|
101
139
|
};
|
|
102
140
|
}
|
|
103
|
-
export function normalizeChildren(children) {
|
|
104
|
-
if (
|
|
141
|
+
export function normalizeChildren(children, skipIgnoredCheck) {
|
|
142
|
+
if (!skipIgnoredCheck && isIgnoredNode(children)) {
|
|
105
143
|
return;
|
|
106
144
|
}
|
|
107
145
|
const result = [];
|
|
108
|
-
normalizeNode(children, result);
|
|
146
|
+
normalizeNode(children, result, undefined, true);
|
|
109
147
|
if (result.length === 0) {
|
|
110
148
|
return;
|
|
111
149
|
}
|
|
112
150
|
return result.length === 1 ? result[0] : result;
|
|
113
151
|
}
|
|
114
|
-
function normalizeNode(child, result) {
|
|
115
|
-
if (
|
|
152
|
+
function normalizeNode(child, result, currentKey = '', skipIgnoredCheck) {
|
|
153
|
+
if (!skipIgnoredCheck && isIgnoredNode(child)) {
|
|
116
154
|
return;
|
|
117
155
|
}
|
|
118
|
-
if (
|
|
119
|
-
|
|
156
|
+
if (isSimpText(child)) {
|
|
157
|
+
child = createTextElement(child);
|
|
158
|
+
child.key =
|
|
159
|
+
currentKey ||
|
|
160
|
+
// Hack to treat a single child as a one-item list for more consistent reconciliation.
|
|
161
|
+
'.0';
|
|
162
|
+
result.push(child);
|
|
120
163
|
return;
|
|
121
164
|
}
|
|
122
|
-
if (isArray(child)) {
|
|
123
|
-
for (
|
|
124
|
-
normalizeNode(
|
|
165
|
+
if (Array.isArray(child)) {
|
|
166
|
+
for (let i = 0; i < child.length; i++) {
|
|
167
|
+
normalizeNode(child[i], result, currentKey + '.' + i, false);
|
|
125
168
|
}
|
|
126
169
|
return;
|
|
127
170
|
}
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
if (IS_DEVELOPMENT && typeof child.flag !== 'string') {
|
|
131
|
-
throw new TypeError(`Objects are not valid as a child: ${JSON.stringify(child)}.`);
|
|
132
|
-
}
|
|
133
|
-
result.push(child);
|
|
171
|
+
if (child.key) {
|
|
172
|
+
currentKey = currentKey.slice(0, -2) + child.key;
|
|
134
173
|
}
|
|
174
|
+
child.key =
|
|
175
|
+
currentKey ||
|
|
176
|
+
// Hack to treat a single child as a one-item list for more consistent reconciliation.
|
|
177
|
+
'.0';
|
|
178
|
+
result.push(child);
|
|
135
179
|
}
|
|
136
|
-
export function normalizeRoot(node) {
|
|
137
|
-
if (
|
|
180
|
+
export function normalizeRoot(node, skipIgnoredCheck) {
|
|
181
|
+
if (!skipIgnoredCheck && isIgnoredNode(node)) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (isSimpText(node)) {
|
|
138
185
|
return createTextElement(node);
|
|
139
186
|
}
|
|
140
|
-
if (isArray(node)) {
|
|
187
|
+
if (!Array.isArray(node)) {
|
|
188
|
+
return node;
|
|
189
|
+
}
|
|
190
|
+
node = normalizeChildren(node, true);
|
|
191
|
+
if (Array.isArray(node)) {
|
|
141
192
|
return createElement(Fragment, { children: node });
|
|
142
193
|
}
|
|
143
194
|
return node;
|
|
144
195
|
}
|
|
196
|
+
function isIgnoredNode(node) {
|
|
197
|
+
if (node == null || typeof node === 'boolean' || node === '') {
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
if (Array.isArray(node)) {
|
|
201
|
+
return node.length === 0;
|
|
202
|
+
}
|
|
203
|
+
if (isSimpText(node)) {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
if (node.flag === 'FRAGMENT' || node.flag === 'PROVIDER' || node.flag === 'PORTAL') {
|
|
207
|
+
return node.children == null;
|
|
208
|
+
}
|
|
209
|
+
return false;
|
|
210
|
+
}
|
package/core/fragment.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export const Fragment = EMPTY_OBJECT;
|
|
1
|
+
export const Fragment = Object.freeze(Object.create(null));
|
package/core/hostAdapter.d.ts
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
1
|
+
import type { Maybe, Nullable } from '../shared';
|
|
2
|
+
import type { SimpElement } from './createElement';
|
|
3
|
+
export type HostReference = any;
|
|
4
|
+
export interface HostAdapter<HostRef = any, HostTextRef = any, NS = string> {
|
|
5
|
+
createReference(type: string, namespace?: Maybe<NS>): HostRef;
|
|
5
6
|
createTextReference(text: string): HostTextRef;
|
|
6
|
-
mountProps(reference: HostRef,
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
mountProps(reference: HostRef, element: SimpElement, namespace?: Maybe<NS>): void;
|
|
8
|
+
patchProps(reference: HostRef, prevElement: SimpElement, nextElement: SimpElement, namespace?: Maybe<NS>): void;
|
|
9
|
+
unmountProps(reference: HostRef, element: SimpElement): void;
|
|
10
|
+
setClassname(reference: HostRef, className: Maybe<string>, namespace?: Maybe<NS>): void;
|
|
9
11
|
setTextContent(reference: HostRef, text: string): void;
|
|
10
12
|
appendChild(parent: HostRef, child: HostRef | HostTextRef): void;
|
|
11
13
|
removeChild(parent: HostRef, child: HostRef | HostTextRef): void;
|
|
12
|
-
replaceChild(parent: HostRef, replacer: HostRef | HostTextRef,
|
|
14
|
+
replaceChild(parent: HostRef, replacer: HostRef | HostTextRef, toBeReplaced: HostRef | HostTextRef): void;
|
|
13
15
|
insertBefore(parent: HostRef, child: HostRef | HostTextRef, before: Nullable<HostRef | HostTextRef>): void;
|
|
14
16
|
insertOrAppend(parent: HostRef, child: HostRef | HostTextRef, before: Nullable<HostRef | HostTextRef>): void;
|
|
15
17
|
findParentReference(reference: HostRef | HostTextRef): Nullable<HostRef>;
|
|
18
|
+
findNextSiblingReference(reference: HostRef | HostTextRef): Nullable<HostRef>;
|
|
19
|
+
clearNode(reference: HostRef | HostTextRef): void;
|
|
20
|
+
attachElementToReference(element: SimpElement, reference: HostRef | HostTextRef): void;
|
|
21
|
+
getHostNamespaces(element: SimpElement, currentNamespace: Maybe<NS>): Nullable<{
|
|
22
|
+
self: Nullable<NS>;
|
|
23
|
+
children: Nullable<NS>;
|
|
24
|
+
}>;
|
|
16
25
|
}
|
|
26
|
+
export declare let hostAdapter: HostAdapter;
|
|
27
|
+
export declare function provideHostAdapter(adapter: HostAdapter): void;
|
package/core/hostAdapter.js
CHANGED
package/core/index.d.ts
CHANGED
|
@@ -1,2 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { SimpText } from '../shared';
|
|
2
|
+
|
|
3
|
+
export type ComponentType<P = {}> = FunctionComponent<P>;
|
|
4
|
+
|
|
5
|
+
export type RefObject<T> = { current: T };
|
|
6
|
+
export type RefCallback<T> = {
|
|
7
|
+
bivarianceHack(instance: T | null): (() => void | undefined) | void;
|
|
8
|
+
}['bivarianceHack'];
|
|
9
|
+
export type Ref<T> = RefCallback<T> | RefObject<T> | null;
|
|
10
|
+
|
|
11
|
+
export type Key = string | number | bigint;
|
|
12
|
+
|
|
13
|
+
export interface Attributes {
|
|
14
|
+
key?: Key | null | undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface RefAttributes<T> extends Attributes {
|
|
18
|
+
ref?: Ref<T> | undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface SimpElement<P = unknown, T extends string | FunctionComponent<P> = string> {
|
|
22
|
+
type?: T;
|
|
23
|
+
props?: P;
|
|
24
|
+
key?: string | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type SimpNode = SimpElement | SimpText | Array<SimpNode> | boolean | null | undefined;
|
|
28
|
+
|
|
29
|
+
export interface ProviderProps<T> {
|
|
30
|
+
value: T;
|
|
31
|
+
children?: SimpNode | undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ConsumerProps<T> {
|
|
35
|
+
children: (value: T) => SimpNode;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type SimpContext<T> = {
|
|
39
|
+
Provider: Provider<T>;
|
|
40
|
+
Consumer: Consumer<T>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type ContextType<C extends SimpContext<any>> = C extends SimpContext<infer T> ? T : never;
|
|
44
|
+
|
|
45
|
+
export type Provider<T> = FunctionComponent<ProviderProps<T>>;
|
|
46
|
+
export type Consumer<T> = FunctionComponent<ConsumerProps<T>>;
|
|
47
|
+
|
|
48
|
+
declare function createElement<P extends {}, T>(
|
|
49
|
+
type: string,
|
|
50
|
+
props?: (RefAttributes<T> & P) | null,
|
|
51
|
+
...children: SimpNode[]
|
|
52
|
+
): SimpElement<P>;
|
|
53
|
+
declare function createElement<P extends {}>(
|
|
54
|
+
type: FunctionComponent<P>,
|
|
55
|
+
props?: (Attributes & P) | null,
|
|
56
|
+
...children: SimpNode[]
|
|
57
|
+
): SimpElement<P>;
|
|
58
|
+
|
|
59
|
+
declare function createPortal<HostRef = {}>(children: SimpNode, container: HostRef): SimpElement;
|
|
60
|
+
|
|
61
|
+
declare function createContext<T>(defaultValue: T): SimpContext<T>;
|
|
62
|
+
|
|
63
|
+
declare function Fragment(props: PropsWithChildren): SimpElement;
|
|
64
|
+
|
|
65
|
+
export type FunctionComponent<P = {}> = (props: P) => SimpNode;
|
|
66
|
+
export type FC<P = {}> = FunctionComponent<P>;
|
|
67
|
+
|
|
68
|
+
export type PropsWithChildren<P = {}> = P & { children?: SimpNode | undefined };
|
package/core/index.js
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { createElement } from './createElement';
|
|
2
|
+
import { Fragment } from './fragment';
|
|
3
|
+
import { createContext } from './context';
|
|
4
|
+
import { createPortal } from './portal';
|
|
5
|
+
export { createElement, Fragment, createContext, createPortal };
|
|
6
|
+
export default { createElement, Fragment, createContext, createPortal };
|
package/core/internal.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './context';
|
|
2
2
|
export * from './createElement';
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './global';
|
|
3
|
+
export * from './fragment';
|
|
5
4
|
export * from './hostAdapter';
|
|
5
|
+
export * from './lifecycleEventBus';
|
|
6
6
|
export * from './mounting';
|
|
7
7
|
export * from './patching';
|
|
8
|
+
export * from './portal';
|
|
9
|
+
export * from './ref';
|
|
10
|
+
export * from './rerender';
|
|
11
|
+
export * from './unmounting';
|
package/core/internal.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './context';
|
|
2
2
|
export * from './createElement';
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './global';
|
|
3
|
+
export * from './fragment';
|
|
5
4
|
export * from './hostAdapter';
|
|
5
|
+
export * from './lifecycleEventBus';
|
|
6
6
|
export * from './mounting';
|
|
7
7
|
export * from './patching';
|
|
8
|
+
export * from './portal';
|
|
9
|
+
export * from './ref';
|
|
10
|
+
export * from './rerender';
|
|
11
|
+
export * from './unmounting';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { EventBus } from '../shared';
|
|
2
|
+
import type { SimpElement } from './createElement';
|
|
3
|
+
export type LifecycleEvent = {
|
|
4
|
+
type: 'beforeRender';
|
|
5
|
+
element: SimpElement;
|
|
6
|
+
phase: 'mounting' | 'updating';
|
|
7
|
+
} | {
|
|
8
|
+
type: 'afterRender';
|
|
9
|
+
phase: 'mounting' | 'updating';
|
|
10
|
+
} | {
|
|
11
|
+
type: 'mounted';
|
|
12
|
+
element: SimpElement;
|
|
13
|
+
} | {
|
|
14
|
+
type: 'updated';
|
|
15
|
+
element: SimpElement;
|
|
16
|
+
} | {
|
|
17
|
+
type: 'unmounted';
|
|
18
|
+
element: SimpElement;
|
|
19
|
+
} | {
|
|
20
|
+
type: 'errored';
|
|
21
|
+
element: SimpElement;
|
|
22
|
+
error: any;
|
|
23
|
+
phase: 'mounting' | 'updating';
|
|
24
|
+
};
|
|
25
|
+
export type LifecycleEventBus = EventBus<LifecycleEvent>;
|
|
26
|
+
export declare const lifecycleEventBus: EventBus<LifecycleEvent>;
|
package/core/mounting.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import type { Nullable } from '../shared';
|
|
1
|
+
import type { Maybe, Nullable } from '../shared';
|
|
2
2
|
import type { HostReference } from './hostAdapter';
|
|
3
3
|
import type { SimpElement } from './createElement';
|
|
4
|
-
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function
|
|
4
|
+
import type { SimpContextMap } from './context';
|
|
5
|
+
export declare function mount(element: SimpElement, parentReference: Nullable<HostReference>, nextReference: Nullable<HostReference>, contextMap: Nullable<SimpContextMap>, hostNamespace: Maybe<string>): void;
|
|
6
|
+
export declare function mountTextElement(element: SimpElement, parentReference: Nullable<HostReference>, nextReference: Nullable<HostReference>): void;
|
|
7
|
+
export declare function mountHostElement(element: SimpElement, parentReference: Nullable<HostReference>, nextReference: Nullable<HostReference>, contextMap: Nullable<SimpContextMap>, hostNamespace: Maybe<string>): void;
|
|
8
|
+
export declare function mountFunctionalElement(element: SimpElement, parentReference: Nullable<HostReference>, nextReference: Nullable<HostReference>, contextMap: Nullable<SimpContextMap>, hostNamespace: Maybe<string>): void;
|
|
9
|
+
export declare function mountFragment(element: SimpElement, parentReference: Nullable<HostReference>, nextReference: Nullable<HostReference>, contextMap: Nullable<SimpContextMap>, hostNamespace: Maybe<string>): void;
|
|
10
|
+
export declare function mountArrayChildren(children: SimpElement[], reference: Nullable<HostReference>, nextReference: Nullable<HostReference>, contextMap: Nullable<SimpContextMap>, parentElement: SimpElement, hostNamespace: Maybe<string>): void;
|
|
11
|
+
export declare function mountProvider(element: SimpElement, parentReference: Nullable<HostReference>, nextReference: Nullable<HostReference>, contextMap: Nullable<SimpContextMap>, hostNamespace: Maybe<string>): void;
|
|
12
|
+
export declare function mountConsumer(element: SimpElement, parentReference: Nullable<HostReference>, nextReference: Nullable<HostReference>, contextMap: Nullable<SimpContextMap>, hostNamespace: Maybe<string>): void;
|
|
13
|
+
export declare function mountPortal(element: SimpElement, parentReference: Nullable<HostReference>, nextReference: Nullable<HostReference>, contextMap: Nullable<SimpContextMap>): void;
|