@simpreact/simpreact 0.0.5 → 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/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 +12 -9
- package/compat/index.js +3 -0
- package/compat/renderRuntime.d.ts +6 -0
- package/compat/renderRuntime.js +17 -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 +20 -6
- package/core/internal.d.ts +5 -0
- package/core/internal.js +5 -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 +6 -9
- package/core/mounting.js +177 -86
- package/core/mountingChildren.d.ts +4 -0
- package/core/mountingChildren.js +47 -0
- package/core/patching.d.ts +7 -8
- package/core/patching.js +245 -252
- package/core/patchingChildren.d.ts +6 -0
- package/core/patchingChildren.js +343 -0
- package/core/portal.d.ts +1 -1
- package/core/portal.js +17 -7
- package/core/processStack.d.ts +106 -0
- package/core/processStack.js +75 -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 +6 -5
- package/core/unmounting.js +58 -57
- package/core/unmountingChildren.d.ts +4 -0
- package/core/unmountingChildren.js +23 -0
- package/core/utils.d.ts +11 -0
- package/core/utils.js +168 -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 +5 -5
- package/dom/props/dangerInnerHTML.js +10 -15
- 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 +154 -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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Maybe } from '../../shared/index.js';
|
|
2
1
|
import type { SimpElement } from '../../core/internal.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}>, nextValue: Maybe<{
|
|
2
|
+
import type { Maybe } from '../../shared/index.js';
|
|
3
|
+
type DangerInnerHTMLValue = {
|
|
6
4
|
__html: string;
|
|
7
|
-
}
|
|
5
|
+
};
|
|
6
|
+
export declare function patchDangerInnerHTML(prevValue: Maybe<DangerInnerHTMLValue>, nextValue: Maybe<DangerInnerHTMLValue>, nextElement: SimpElement, dom: Element): void;
|
|
7
|
+
export {};
|
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const nextHTML = nextValue?.__html || '';
|
|
1
|
+
export function patchDangerInnerHTML(prevValue, nextValue, nextElement, dom) {
|
|
2
|
+
const prevHTML = prevValue?.__html;
|
|
3
|
+
const nextHTML = nextValue?.__html;
|
|
5
4
|
if (nextElement.children) {
|
|
6
|
-
console.warn('Avoid setting both children and props.dangerouslySetInnerHTML at the same time — this
|
|
5
|
+
console.warn('Avoid setting both children and props.dangerouslySetInnerHTML at the same time — this causes unpredictable behavior.');
|
|
7
6
|
}
|
|
8
|
-
if (prevHTML
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
dom.innerHTML = nextHTML;
|
|
17
|
-
}
|
|
7
|
+
if (prevHTML === nextHTML) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const nextInnerHTML = nextHTML ?? '';
|
|
11
|
+
if (!isSameInnerHTML(dom, nextInnerHTML)) {
|
|
12
|
+
dom.innerHTML = nextInnerHTML;
|
|
18
13
|
}
|
|
19
14
|
}
|
|
20
15
|
function isSameInnerHTML(dom, innerHTML) {
|
package/dom/props/props.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SimpElement } from '../../core/internal.js';
|
|
1
|
+
import type { SimpElement, SimpRenderRuntime } from '../../core/internal.js';
|
|
2
2
|
import type { Namespace } from '../namespace.js';
|
|
3
|
-
export declare function mountProps(dom: HTMLElement | SVGElement, element: SimpElement, namespace: Namespace): void;
|
|
4
|
-
export declare function unmountProps(dom: HTMLElement | SVGElement, element: SimpElement): void;
|
|
5
|
-
export declare function patchProps(dom: HTMLElement | SVGElement, prevElement: SimpElement, nextElement: SimpElement, namespace: Namespace): void;
|
|
3
|
+
export declare function mountProps(dom: HTMLElement | SVGElement, element: SimpElement, namespace: Namespace, renderRuntime: SimpRenderRuntime): void;
|
|
4
|
+
export declare function unmountProps(dom: HTMLElement | SVGElement, element: SimpElement, renderRuntime: SimpRenderRuntime): void;
|
|
5
|
+
export declare function patchProps(dom: HTMLElement | SVGElement, prevElement: SimpElement, nextElement: SimpElement, namespace: Namespace, renderRuntime: SimpRenderRuntime): void;
|
package/dom/props/props.js
CHANGED
|
@@ -1,36 +1,39 @@
|
|
|
1
1
|
import { emptyObject } from '../../shared/index.js';
|
|
2
|
+
import { isPropNameEventName, patchEvent } from '../events.js';
|
|
2
3
|
import { defaultNamespace } from '../namespace.js';
|
|
3
4
|
import { addControlledFormElementEventHandlers, isEventNameIgnored, isFormElementControlled, removeControlledFormElementEventHandlers, syncControlledFormElementPropsWithAttrs, } from './controlled/index.js';
|
|
4
|
-
import { isPropNameEventName, patchEvent } from '../events.js';
|
|
5
|
-
import { patchStyle } from './style.js';
|
|
6
5
|
import { patchDangerInnerHTML } from './dangerInnerHTML.js';
|
|
7
|
-
|
|
6
|
+
import { patchStyle } from './style.js';
|
|
7
|
+
export function mountProps(dom, element, namespace, renderRuntime) {
|
|
8
8
|
if (!isFormElement(element)) {
|
|
9
9
|
for (const propName in element.props) {
|
|
10
|
-
patchDefaultElementPropAndAttrs(propName, dom,
|
|
10
|
+
patchDefaultElementPropAndAttrs(propName, dom, element, null, element.props[propName], namespace, renderRuntime);
|
|
11
11
|
}
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
14
|
const isControlled = isFormElementControlled(element.props);
|
|
15
15
|
for (const propName in element.props) {
|
|
16
|
-
patchFormElementsPropAndAttrs(propName, dom, element, isControlled, null, element.props[propName]);
|
|
16
|
+
patchFormElementsPropAndAttrs(propName, dom, element, isControlled, null, element.props[propName], renderRuntime);
|
|
17
17
|
}
|
|
18
18
|
if (isControlled) {
|
|
19
|
-
addControlledFormElementEventHandlers(element);
|
|
19
|
+
addControlledFormElementEventHandlers(element, renderRuntime);
|
|
20
20
|
syncControlledFormElementPropsWithAttrs(element, element.props, true);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
export function unmountProps(dom, element) {
|
|
23
|
+
export function unmountProps(dom, element, renderRuntime) {
|
|
24
24
|
if (!element.props) {
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
|
+
if (isFormElement(element) && isFormElementControlled(element.props)) {
|
|
28
|
+
removeControlledFormElementEventHandlers(element, renderRuntime);
|
|
29
|
+
}
|
|
27
30
|
for (const propName in element.props) {
|
|
28
31
|
if (isPropNameEventName(propName)) {
|
|
29
|
-
patchEvent(propName, element.props[propName], null, dom);
|
|
32
|
+
patchEvent(propName, element.props[propName], null, dom, renderRuntime);
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
|
-
export function patchProps(dom, prevElement, nextElement, namespace) {
|
|
36
|
+
export function patchProps(dom, prevElement, nextElement, namespace, renderRuntime) {
|
|
34
37
|
const prevProps = prevElement.props || emptyObject;
|
|
35
38
|
const nextProps = nextElement.props || emptyObject;
|
|
36
39
|
if (!isFormElement(nextElement)) {
|
|
@@ -38,12 +41,12 @@ export function patchProps(dom, prevElement, nextElement, namespace) {
|
|
|
38
41
|
const prevValue = prevProps[propName];
|
|
39
42
|
const nextValue = nextProps[propName];
|
|
40
43
|
if (prevValue !== nextValue) {
|
|
41
|
-
patchDefaultElementPropAndAttrs(propName, dom,
|
|
44
|
+
patchDefaultElementPropAndAttrs(propName, dom, nextElement, prevValue, nextValue, namespace, renderRuntime);
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
for (const propName in prevProps) {
|
|
45
48
|
if (nextProps[propName] == null && prevProps[propName] != null) {
|
|
46
|
-
patchDefaultElementPropAndAttrs(propName, dom,
|
|
49
|
+
patchDefaultElementPropAndAttrs(propName, dom, nextElement, prevProps[propName], null, namespace, renderRuntime);
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
52
|
return;
|
|
@@ -54,25 +57,25 @@ export function patchProps(dom, prevElement, nextElement, namespace) {
|
|
|
54
57
|
const prevValue = prevProps[propName];
|
|
55
58
|
const nextValue = nextProps[propName];
|
|
56
59
|
if (prevValue !== nextValue) {
|
|
57
|
-
patchFormElementsPropAndAttrs(propName, dom, nextElement, isNextElementControlled, prevValue, nextValue);
|
|
60
|
+
patchFormElementsPropAndAttrs(propName, dom, nextElement, isNextElementControlled, prevValue, nextValue, renderRuntime);
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
for (const propName in prevProps) {
|
|
61
64
|
if (nextProps[propName] == null && prevProps[propName] != null) {
|
|
62
|
-
patchFormElementsPropAndAttrs(propName, dom, prevElement, isPrevElementControlled, prevProps[propName], null);
|
|
65
|
+
patchFormElementsPropAndAttrs(propName, dom, prevElement, isPrevElementControlled, prevProps[propName], null, renderRuntime);
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
if (!isPrevElementControlled && isNextElementControlled) {
|
|
66
|
-
addControlledFormElementEventHandlers(nextElement);
|
|
69
|
+
addControlledFormElementEventHandlers(nextElement, renderRuntime);
|
|
67
70
|
}
|
|
68
71
|
else if (isPrevElementControlled && !isNextElementControlled) {
|
|
69
|
-
removeControlledFormElementEventHandlers(prevElement);
|
|
72
|
+
removeControlledFormElementEventHandlers(prevElement, renderRuntime);
|
|
70
73
|
}
|
|
71
74
|
if (isNextElementControlled) {
|
|
72
75
|
syncControlledFormElementPropsWithAttrs(nextElement, nextProps);
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
|
-
function patchFormElementsPropAndAttrs(propName, dom, element, isControlled, prevValue, nextValue) {
|
|
78
|
+
function patchFormElementsPropAndAttrs(propName, dom, element, isControlled, prevValue, nextValue, renderRuntime) {
|
|
76
79
|
switch (propName) {
|
|
77
80
|
case 'children':
|
|
78
81
|
case 'className':
|
|
@@ -109,17 +112,17 @@ function patchFormElementsPropAndAttrs(propName, dom, element, isControlled, pre
|
|
|
109
112
|
default:
|
|
110
113
|
if (isPropNameEventName(propName)) {
|
|
111
114
|
if (isControlled && isEventNameIgnored(element, propName)) {
|
|
112
|
-
patchEvent(propName, prevValue, null, dom);
|
|
115
|
+
patchEvent(propName, prevValue, null, dom, renderRuntime);
|
|
113
116
|
break;
|
|
114
117
|
}
|
|
115
|
-
patchEvent(propName, prevValue, nextValue, dom);
|
|
118
|
+
patchEvent(propName, prevValue, nextValue, dom, renderRuntime);
|
|
116
119
|
}
|
|
117
120
|
else {
|
|
118
121
|
patchDomAttr(dom, nextValue, propName);
|
|
119
122
|
}
|
|
120
123
|
}
|
|
121
124
|
}
|
|
122
|
-
function patchDefaultElementPropAndAttrs(propName, dom,
|
|
125
|
+
function patchDefaultElementPropAndAttrs(propName, dom, nextElement, prevValue, nextValue, namespace, renderRuntime) {
|
|
123
126
|
switch (propName) {
|
|
124
127
|
case 'children':
|
|
125
128
|
case 'className':
|
|
@@ -150,11 +153,11 @@ function patchDefaultElementPropAndAttrs(propName, dom, prevElement, nextElement
|
|
|
150
153
|
patchStyle(prevValue, nextValue, dom);
|
|
151
154
|
break;
|
|
152
155
|
case 'dangerouslySetInnerHTML':
|
|
153
|
-
patchDangerInnerHTML(prevValue, nextValue,
|
|
156
|
+
patchDangerInnerHTML(prevValue, nextValue, nextElement, dom);
|
|
154
157
|
break;
|
|
155
158
|
default:
|
|
156
159
|
if (isPropNameEventName(propName)) {
|
|
157
|
-
patchEvent(propName, prevValue, nextValue, dom);
|
|
160
|
+
patchEvent(propName, prevValue, nextValue, dom, renderRuntime);
|
|
158
161
|
}
|
|
159
162
|
else {
|
|
160
163
|
patchDomAttr(dom, nextValue, propName, namespace);
|
package/dom/render.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { type SimpElement } from '../core/internal.js';
|
|
1
|
+
import { type SimpElement, type SimpRenderRuntime } from '../core/internal.js';
|
|
2
2
|
import type { Nullable } from '../shared/index.js';
|
|
3
|
-
export declare function
|
|
4
|
-
interface SimpRoot {
|
|
3
|
+
export declare function createRenderer(renderRuntime: SimpRenderRuntime): (element: Nullable<SimpElement>, container: Nullable<Element | DocumentFragment>) => void;
|
|
4
|
+
export interface SimpRoot {
|
|
5
5
|
render(element: SimpElement): void;
|
|
6
6
|
unmount(): void;
|
|
7
7
|
}
|
|
8
|
-
export declare function
|
|
9
|
-
export {};
|
|
8
|
+
export declare function createCreateRoot(renderRuntime: SimpRenderRuntime): (container: Element | DocumentFragment) => SimpRoot;
|
package/dom/render.js
CHANGED
|
@@ -1,41 +1,45 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (!container) {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
const currentRootElement = getElementFromDom(container);
|
|
10
|
-
renderingRerenderLocker.lock();
|
|
11
|
-
if (!currentRootElement) {
|
|
12
|
-
if (element) {
|
|
13
|
-
hostAdapter.clearNode(container);
|
|
14
|
-
attachElementToDom((element.parent = { flag: 'HOST', reference: container, children: element, parent: null }), container);
|
|
15
|
-
mount(element, container, null, null, hostAdapter.getHostNamespaces(element, undefined)?.self);
|
|
1
|
+
import { createElement, mount, patch, unmount } from '../core/internal.js';
|
|
2
|
+
export function createRenderer(renderRuntime) {
|
|
3
|
+
return (element, container) => {
|
|
4
|
+
if (!container) {
|
|
5
|
+
return;
|
|
16
6
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
const currentRootElement = renderRuntime.hostAdapter.getElementFromReference(container, renderRuntime);
|
|
8
|
+
if (!currentRootElement) {
|
|
9
|
+
if (element) {
|
|
10
|
+
renderRuntime.hostAdapter.clearNode(container);
|
|
11
|
+
element.parent = createElement('', null, element);
|
|
12
|
+
element.parent.type = null;
|
|
13
|
+
element.parent.reference = container;
|
|
14
|
+
renderRuntime.hostAdapter.attachElementToReference(element.parent, container, renderRuntime);
|
|
15
|
+
mount(element, container, null, null, renderRuntime.hostAdapter.getHostNamespaces(element, undefined)?.self, renderRuntime);
|
|
16
|
+
}
|
|
22
17
|
}
|
|
23
18
|
else {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
if (!element) {
|
|
20
|
+
unmount(currentRootElement.children, renderRuntime);
|
|
21
|
+
renderRuntime.hostAdapter.detachElementFromReference(container, renderRuntime);
|
|
22
|
+
renderRuntime.hostAdapter.clearNode(container);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const prevChildren = currentRootElement.children;
|
|
26
|
+
currentRootElement.children = element;
|
|
27
|
+
element.parent = currentRootElement;
|
|
28
|
+
patch(prevChildren, element, container, null, null, renderRuntime.hostAdapter.getHostNamespaces(element, undefined)?.self, renderRuntime);
|
|
29
|
+
}
|
|
28
30
|
}
|
|
29
|
-
}
|
|
30
|
-
renderingRerenderLocker.flush();
|
|
31
|
+
};
|
|
31
32
|
}
|
|
32
|
-
export function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
export function createCreateRoot(renderRuntime) {
|
|
34
|
+
const render = createRenderer(renderRuntime);
|
|
35
|
+
return (container) => {
|
|
36
|
+
return {
|
|
37
|
+
render(element) {
|
|
38
|
+
render(element, container);
|
|
39
|
+
},
|
|
40
|
+
unmount() {
|
|
41
|
+
render(null, container);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
40
44
|
};
|
|
41
45
|
}
|
package/hooks/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RefObject } from '../core/index.js';
|
|
1
|
+
import type { RefObject, SimpRenderRuntime } from '../core/index.js';
|
|
2
2
|
|
|
3
3
|
export type Cleanup = () => void;
|
|
4
4
|
export type Effect = () => void | Cleanup;
|
|
@@ -7,21 +7,23 @@ export type DependencyList = readonly unknown[];
|
|
|
7
7
|
export type Dispatch<A> = (value: A) => void;
|
|
8
8
|
export type SetStateAction<S> = S | ((prevState: S) => S);
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
export interface UseRef {
|
|
11
|
+
<T>(initialValue: T): RefObject<T>;
|
|
12
|
+
<T>(initialValue: T | null): RefObject<T | null>;
|
|
13
|
+
<T = undefined>(initialValue?: T): RefObject<T | undefined>;
|
|
14
|
+
}
|
|
15
|
+
declare function createUseRef(renderRuntime: SimpRenderRuntime): UseRef;
|
|
13
16
|
|
|
14
|
-
declare function
|
|
17
|
+
declare function createUseRerender(renderRuntime: SimpRenderRuntime): () => void;
|
|
15
18
|
|
|
16
|
-
export
|
|
17
|
-
|
|
19
|
+
export interface UseState {
|
|
20
|
+
<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>];
|
|
21
|
+
<S>(): [S | undefined, Dispatch<SetStateAction<S | undefined>>];
|
|
22
|
+
}
|
|
23
|
+
declare function createUseState(renderRuntime: SimpRenderRuntime): useState;
|
|
18
24
|
|
|
19
|
-
declare function
|
|
25
|
+
declare function createUseEffect(renderRuntime: SimpRenderRuntime): (effect: Effect, deps?: DependencyList) => void;
|
|
20
26
|
|
|
21
|
-
declare function
|
|
22
|
-
|
|
23
|
-
declare function useUnmounted(cleanup: Cleanup): void;
|
|
24
|
-
|
|
25
|
-
declare function useCatch(cb: (error: any) => void): void;
|
|
27
|
+
declare function createUseCatch(renderRuntime: SimpRenderRuntime): (cb: (error: any) => void) => void;
|
|
26
28
|
|
|
27
29
|
declare function areDepsEqual(nextDeps: DependencyList | undefined, prevDeps: DependencyList | undefined): boolean;
|