@simpreact/simpreact 0.0.0-alpha.dd6f145 → 0.0.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/core/context.d.ts +18 -0
- package/core/context.js +18 -0
- package/core/createElement.d.ts +25 -16
- package/core/createElement.js +99 -28
- package/core/fragment.d.ts +1 -1
- package/core/fragment.js +1 -2
- package/core/hostAdapter.d.ts +20 -9
- package/core/hostAdapter.js +4 -1
- package/core/index.d.ts +68 -2
- package/core/index.js +6 -2
- package/core/internal.d.ts +11 -7
- package/core/internal.js +11 -7
- package/core/lifecycleEventBus.d.ts +26 -0
- package/core/lifecycleEventBus.js +2 -0
- package/core/mounting.d.ts +13 -9
- package/core/mounting.js +108 -38
- package/core/patching.d.ts +10 -7
- package/core/patching.js +186 -160
- 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 +12 -1
- package/core/rerender.js +67 -3
- package/core/unmounting.d.ts +6 -8
- 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 +49 -117
- package/dom/events.d.ts +19 -0
- package/dom/events.js +129 -0
- package/dom/index.d.ts +1733 -1
- package/dom/index.js +3 -1
- 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 +4 -4
- package/dom/render.js +32 -18
- package/hooks/index.d.ts +23 -10
- package/hooks/index.js +126 -32
- package/jsx-runtime/index.d.ts +248 -5
- package/jsx-runtime/index.js +3 -6
- package/package.json +22 -14
- 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.js';
|
|
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,
|
|
2
|
-
import type { HostReference } from './hostAdapter';
|
|
3
|
-
|
|
4
|
-
export type
|
|
1
|
+
import type { Many, Maybe, Nullable, SimpText } from '../shared/index.js';
|
|
2
|
+
import type { HostReference } from './hostAdapter.js';
|
|
3
|
+
import type { SimpContextMap } from './context.js';
|
|
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 {
|
|
2
|
-
import { Fragment } from './fragment';
|
|
1
|
+
import { isSimpText } from '../shared/index.js';
|
|
2
|
+
import { Fragment } from './fragment.js';
|
|
3
|
+
import { isConsumer, isProvider } from './context.js';
|
|
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,54 @@ export function createElement(type, props, ...children) {
|
|
|
44
52
|
if (key) {
|
|
45
53
|
element.key = key;
|
|
46
54
|
}
|
|
47
|
-
if ((definedChildren
|
|
55
|
+
if (isSimpText(definedChildren)) {
|
|
56
|
+
if (definedChildren !== '') {
|
|
57
|
+
(newProps ||= {}).children = definedChildren.toString();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else if ((definedChildren = normalizeChildren(definedChildren, false))) {
|
|
48
61
|
element.children = definedChildren;
|
|
49
62
|
}
|
|
50
63
|
if (newProps) {
|
|
51
64
|
element.props = newProps;
|
|
52
65
|
}
|
|
66
|
+
if (ref) {
|
|
67
|
+
element.ref = ref;
|
|
68
|
+
}
|
|
53
69
|
return element;
|
|
54
70
|
}
|
|
55
71
|
else if (type === Fragment) {
|
|
56
72
|
const element = {
|
|
57
73
|
flag: 'FRAGMENT',
|
|
74
|
+
parent: null,
|
|
75
|
+
};
|
|
76
|
+
if ((definedChildren = normalizeChildren(definedChildren || (props != null ? props.children : null), false))) {
|
|
77
|
+
element.children = definedChildren;
|
|
78
|
+
}
|
|
79
|
+
if (props != null && props.key) {
|
|
80
|
+
element.key = props?.key;
|
|
81
|
+
}
|
|
82
|
+
return element;
|
|
83
|
+
}
|
|
84
|
+
else if (isProvider(type)) {
|
|
85
|
+
const element = { flag: 'PROVIDER', type, props: { value: props.value }, parent: null };
|
|
86
|
+
if ((definedChildren = normalizeChildren(definedChildren || props.children, false))) {
|
|
87
|
+
element.children = definedChildren;
|
|
88
|
+
}
|
|
89
|
+
if (props != null && props.key) {
|
|
90
|
+
element.key = props?.key;
|
|
91
|
+
}
|
|
92
|
+
return element;
|
|
93
|
+
}
|
|
94
|
+
else if (isConsumer(type)) {
|
|
95
|
+
const element = {
|
|
96
|
+
flag: 'CONSUMER',
|
|
97
|
+
type,
|
|
98
|
+
props: { children: definedChildren || (props != null ? props.children : null) },
|
|
99
|
+
parent: null,
|
|
58
100
|
};
|
|
59
|
-
element.children = normalizeChildren(definedChildren || (props != null ? props.children : null));
|
|
60
101
|
if (props != null && props.key) {
|
|
61
|
-
element.key = props
|
|
102
|
+
element.key = props?.key;
|
|
62
103
|
}
|
|
63
104
|
return element;
|
|
64
105
|
}
|
|
@@ -74,16 +115,17 @@ export function createElement(type, props, ...children) {
|
|
|
74
115
|
}
|
|
75
116
|
}
|
|
76
117
|
else {
|
|
77
|
-
(newProps
|
|
118
|
+
(newProps ||= {})[propName] = props[propName];
|
|
78
119
|
}
|
|
79
120
|
}
|
|
80
121
|
}
|
|
81
122
|
if (definedChildren !== undefined) {
|
|
82
|
-
(newProps
|
|
123
|
+
(newProps ||= {})['children'] = definedChildren;
|
|
83
124
|
}
|
|
84
125
|
const element = {
|
|
85
126
|
flag: 'FC',
|
|
86
127
|
type,
|
|
128
|
+
parent: null,
|
|
87
129
|
};
|
|
88
130
|
if (key) {
|
|
89
131
|
element.key = key;
|
|
@@ -97,48 +139,77 @@ export function createElement(type, props, ...children) {
|
|
|
97
139
|
export function createTextElement(text) {
|
|
98
140
|
return {
|
|
99
141
|
flag: 'TEXT',
|
|
100
|
-
children: text
|
|
142
|
+
children: text.toString(),
|
|
143
|
+
parent: null,
|
|
101
144
|
};
|
|
102
145
|
}
|
|
103
|
-
export function normalizeChildren(children) {
|
|
104
|
-
if (
|
|
146
|
+
export function normalizeChildren(children, skipIgnoredCheck) {
|
|
147
|
+
if (!skipIgnoredCheck && isIgnoredNode(children)) {
|
|
105
148
|
return;
|
|
106
149
|
}
|
|
107
150
|
const result = [];
|
|
108
|
-
normalizeNode(children, result);
|
|
151
|
+
normalizeNode(children, result, undefined, true);
|
|
109
152
|
if (result.length === 0) {
|
|
110
153
|
return;
|
|
111
154
|
}
|
|
112
155
|
return result.length === 1 ? result[0] : result;
|
|
113
156
|
}
|
|
114
|
-
function normalizeNode(child, result) {
|
|
115
|
-
if (
|
|
157
|
+
function normalizeNode(child, result, currentKey = '', skipIgnoredCheck) {
|
|
158
|
+
if (!skipIgnoredCheck && isIgnoredNode(child)) {
|
|
116
159
|
return;
|
|
117
160
|
}
|
|
118
|
-
if (
|
|
119
|
-
|
|
161
|
+
if (isSimpText(child)) {
|
|
162
|
+
child = createTextElement(child);
|
|
163
|
+
child.key =
|
|
164
|
+
currentKey ||
|
|
165
|
+
// Hack to treat a single child as a one-item list for more consistent reconciliation.
|
|
166
|
+
'.0';
|
|
167
|
+
result.push(child);
|
|
120
168
|
return;
|
|
121
169
|
}
|
|
122
|
-
if (isArray(child)) {
|
|
123
|
-
for (
|
|
124
|
-
normalizeNode(
|
|
170
|
+
if (Array.isArray(child)) {
|
|
171
|
+
for (let i = 0; i < child.length; i++) {
|
|
172
|
+
normalizeNode(child[i], result, currentKey + '.' + i, false);
|
|
125
173
|
}
|
|
126
174
|
return;
|
|
127
175
|
}
|
|
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);
|
|
176
|
+
if (child.key) {
|
|
177
|
+
currentKey = currentKey.slice(0, -2) + child.key;
|
|
134
178
|
}
|
|
179
|
+
child.key =
|
|
180
|
+
currentKey ||
|
|
181
|
+
// Hack to treat a single child as a one-item list for more consistent reconciliation.
|
|
182
|
+
'.0';
|
|
183
|
+
result.push(child);
|
|
135
184
|
}
|
|
136
|
-
export function normalizeRoot(node) {
|
|
137
|
-
if (
|
|
185
|
+
export function normalizeRoot(node, skipIgnoredCheck) {
|
|
186
|
+
if (!skipIgnoredCheck && isIgnoredNode(node)) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (isSimpText(node)) {
|
|
138
190
|
return createTextElement(node);
|
|
139
191
|
}
|
|
140
|
-
if (isArray(node)) {
|
|
192
|
+
if (!Array.isArray(node)) {
|
|
193
|
+
return node;
|
|
194
|
+
}
|
|
195
|
+
node = normalizeChildren(node, true);
|
|
196
|
+
if (Array.isArray(node)) {
|
|
141
197
|
return createElement(Fragment, { children: node });
|
|
142
198
|
}
|
|
143
199
|
return node;
|
|
144
200
|
}
|
|
201
|
+
function isIgnoredNode(node) {
|
|
202
|
+
if (node == null || typeof node === 'boolean' || node === '') {
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
if (Array.isArray(node)) {
|
|
206
|
+
return node.length === 0;
|
|
207
|
+
}
|
|
208
|
+
if (isSimpText(node)) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
if (node.flag === 'FRAGMENT' || node.flag === 'PROVIDER' || node.flag === 'PORTAL') {
|
|
212
|
+
return node.children == null;
|
|
213
|
+
}
|
|
214
|
+
return false;
|
|
215
|
+
}
|
package/core/fragment.d.ts
CHANGED
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/index.js';
|
|
2
|
+
import type { SimpElement } from './createElement.js';
|
|
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
|
-
|
|
9
|
-
|
|
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;
|
|
11
|
+
setTextContent(reference: HostRef, text: string, referenceHasOnlyTextElement?: boolean): 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/index.js';
|
|
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.js';
|
|
2
|
+
import { Fragment } from './fragment.js';
|
|
3
|
+
import { createContext } from './context.js';
|
|
4
|
+
import { createPortal } from './portal.js';
|
|
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 './
|
|
2
|
-
export * from './createElement';
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './mounting';
|
|
7
|
-
export * from './patching';
|
|
1
|
+
export * from './context.js';
|
|
2
|
+
export * from './createElement.js';
|
|
3
|
+
export * from './fragment.js';
|
|
4
|
+
export * from './hostAdapter.js';
|
|
5
|
+
export * from './lifecycleEventBus.js';
|
|
6
|
+
export * from './mounting.js';
|
|
7
|
+
export * from './patching.js';
|
|
8
|
+
export * from './portal.js';
|
|
9
|
+
export * from './ref.js';
|
|
10
|
+
export * from './rerender.js';
|
|
11
|
+
export * from './unmounting.js';
|
package/core/internal.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './createElement';
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './mounting';
|
|
7
|
-
export * from './patching';
|
|
1
|
+
export * from './context.js';
|
|
2
|
+
export * from './createElement.js';
|
|
3
|
+
export * from './fragment.js';
|
|
4
|
+
export * from './hostAdapter.js';
|
|
5
|
+
export * from './lifecycleEventBus.js';
|
|
6
|
+
export * from './mounting.js';
|
|
7
|
+
export * from './patching.js';
|
|
8
|
+
export * from './portal.js';
|
|
9
|
+
export * from './ref.js';
|
|
10
|
+
export * from './rerender.js';
|
|
11
|
+
export * from './unmounting.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { EventBus } from '../shared/index.js';
|
|
2
|
+
import type { SimpElement } from './createElement.js';
|
|
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';
|
|
2
|
-
import type { HostReference } from './hostAdapter';
|
|
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
|
|
1
|
+
import type { Maybe, Nullable } from '../shared/index.js';
|
|
2
|
+
import type { HostReference } from './hostAdapter.js';
|
|
3
|
+
import type { SimpElement } from './createElement.js';
|
|
4
|
+
import type { SimpContextMap } from './context.js';
|
|
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;
|