@simpreact/simpreact 0.0.7 → 0.0.9
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/context.js +3 -3
- package/compat/core.js +105 -18
- package/compat/dom.js +5 -5
- package/compat/hooks.js +18 -3
- package/compat/index.d.ts +109 -45
- package/compat/jsx-runtime.js +4 -4
- package/compat/renderRuntime.js +47 -12
- package/component/index.d.ts +6 -7
- package/component/index.js +96 -94
- package/context/index.d.ts +5 -5
- package/context/index.js +27 -17
- package/core/createElement.js +14 -17
- package/core/flags.js +31 -0
- package/core/hostOperations.js +5 -13
- package/core/index.d.ts +48 -11
- package/core/index.js +4 -2
- package/core/internal.d.ts +136 -16
- package/core/internal.js +8 -16
- package/core/lifecycleEventBus.js +35 -16
- package/core/memo.js +4 -1
- package/core/mounting.js +70 -150
- package/core/mountingChildren.js +11 -29
- package/core/patching.js +122 -181
- package/core/patchingChildren.js +74 -145
- package/core/portal.js +1 -1
- package/core/processStack.js +115 -45
- package/core/ref.js +1 -0
- package/core/rerender.js +20 -22
- package/core/runtime.js +10 -2
- package/core/unmounting.js +41 -49
- package/core/unmountingChildren.js +9 -12
- package/core/utils.js +38 -16
- package/dom/attach-element-to-dom.js +16 -8
- package/dom/events.js +11 -15
- package/dom/index.d.ts +6 -5
- package/dom/props/attrMaps.js +90 -0
- package/dom/props/controlled/select.js +8 -10
- package/dom/props/props.js +13 -14
- package/hooks/index.d.ts +15 -10
- package/hooks/index.js +107 -84
- package/package.json +10 -5
- package/shared/index.d.ts +10 -6
- package/compat/context.d.ts +0 -8
- package/compat/core.d.ts +0 -47
- package/compat/dom.d.ts +0 -10
- package/compat/hooks.d.ts +0 -27
- package/compat/jsx-runtime.d.ts +0 -10
- package/compat/renderRuntime.d.ts +0 -6
- package/core/createElement.d.ts +0 -39
- package/core/fragment.d.ts +0 -5
- package/core/hostAdapter.d.ts +0 -23
- package/core/hostOperations.d.ts +0 -5
- package/core/lifecycleEventBus.d.ts +0 -39
- package/core/memo.d.ts +0 -8
- package/core/mounting.d.ts +0 -7
- package/core/mountingChildren.d.ts +0 -4
- package/core/patching.d.ts +0 -8
- package/core/patchingChildren.d.ts +0 -6
- package/core/portal.d.ts +0 -2
- package/core/processStack.d.ts +0 -106
- package/core/ref.d.ts +0 -18
- package/core/rerender.d.ts +0 -4
- package/core/runtime.d.ts +0 -17
- package/core/unmounting.d.ts +0 -7
- package/core/unmountingChildren.d.ts +0 -4
- package/core/utils.d.ts +0 -11
- package/dom/attach-element-to-dom.d.ts +0 -5
- package/dom/domAdapter.d.ts +0 -3
- package/dom/events.d.ts +0 -27
- package/dom/namespace.d.ts +0 -2
- package/dom/props/controlled/index.d.ts +0 -7
- package/dom/props/controlled/input.d.ts +0 -7
- package/dom/props/controlled/select.d.ts +0 -6
- package/dom/props/controlled/textarea.d.ts +0 -6
- package/dom/props/dangerInnerHTML.d.ts +0 -7
- package/dom/props/index.d.ts +0 -1
- package/dom/props/props.d.ts +0 -5
- package/dom/props/style.d.ts +0 -1
- package/dom/render.d.ts +0 -8
- package/shared/lang.d.ts +0 -3
- package/shared/utils.d.ts +0 -5
package/core/unmounting.js
CHANGED
|
@@ -1,69 +1,61 @@
|
|
|
1
1
|
import { noop } from '../shared/index.js';
|
|
2
|
-
import {
|
|
3
|
-
import { processStack, UNMOUNT_ENTER, UNMOUNT_EXIT } from './processStack.js';
|
|
2
|
+
import { getLifecycleEventBus } from './lifecycleEventBus.js';
|
|
3
|
+
import { acquireUnmountFrame, processStack, UNMOUNT_ENTER, UNMOUNT_EXIT, } from './processStack.js';
|
|
4
4
|
import { unmountRef } from './ref.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
_unmountFunctionalElement,
|
|
10
|
-
noop,
|
|
11
|
-
_unmountPortalElement,
|
|
12
|
-
_unmountFragmentElement,
|
|
13
|
-
];
|
|
5
|
+
import { pushUnmountChildrenFrame } from './unmountingChildren.js';
|
|
6
|
+
import { bitScanForwardIndex, clearElementHostReference } from './utils.js';
|
|
7
|
+
const unmountEnterHandlers = [unmountHostEnter, unmountFCEnter, noop, unmountPortalElement, unmountFragmentElement];
|
|
8
|
+
const unmountExitHandlers = [unmountHostExit, unmountFCExit, noop, noop, noop];
|
|
14
9
|
export function unmount(element, renderRuntime) {
|
|
15
10
|
if (renderRuntime.renderStack.length !== 0) {
|
|
16
11
|
throw new Error('Cannot unmount while rendering.');
|
|
17
12
|
}
|
|
18
|
-
|
|
13
|
+
pushUnmountEnterFrame(element, renderRuntime);
|
|
19
14
|
processStack(renderRuntime);
|
|
20
15
|
}
|
|
21
|
-
export function
|
|
22
|
-
|
|
16
|
+
export function unmountEnter(frame) {
|
|
17
|
+
unmountEnterHandlers[bitScanForwardIndex(frame.node.flag)](frame);
|
|
23
18
|
}
|
|
24
|
-
export function
|
|
25
|
-
|
|
26
|
-
node: element,
|
|
27
|
-
kind: UNMOUNT_ENTER,
|
|
28
|
-
meta,
|
|
29
|
-
});
|
|
19
|
+
export function unmountExit(frame) {
|
|
20
|
+
unmountExitHandlers[bitScanForwardIndex(frame.node.flag)](frame);
|
|
30
21
|
}
|
|
31
|
-
export function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
22
|
+
export function pushUnmountEnterFrame(element, renderRuntime) {
|
|
23
|
+
renderRuntime.renderStack.push(acquireUnmountFrame(renderRuntime, element, UNMOUNT_ENTER));
|
|
24
|
+
}
|
|
25
|
+
function pushUnmountExitFrame(element, renderRuntime) {
|
|
26
|
+
renderRuntime.renderStack.push(acquireUnmountFrame(renderRuntime, element, UNMOUNT_EXIT));
|
|
37
27
|
}
|
|
38
|
-
function
|
|
28
|
+
function unmountFCEnter(frame) {
|
|
39
29
|
const current = frame.node;
|
|
40
30
|
if (current.unmounted) {
|
|
41
31
|
return;
|
|
42
32
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
lifecycleEventBus.publish({ type: 'unmounted', element: current, renderRuntime: frame.meta.renderRuntime });
|
|
46
|
-
current.store = null;
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
_pushUnmountExitFrame(current, frame.meta);
|
|
50
|
-
_pushUnmountChildrenFrame(current, frame.meta);
|
|
33
|
+
pushUnmountExitFrame(current, frame.renderRuntime);
|
|
34
|
+
pushUnmountChildrenFrame(current, frame.renderRuntime);
|
|
51
35
|
}
|
|
52
|
-
function
|
|
36
|
+
function unmountFCExit(frame) {
|
|
53
37
|
const current = frame.node;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
38
|
+
current.unmounted = true;
|
|
39
|
+
getLifecycleEventBus(frame.renderRuntime).publish({
|
|
40
|
+
type: 'unmounted',
|
|
41
|
+
element: current,
|
|
42
|
+
renderRuntime: frame.renderRuntime,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function unmountHostEnter(frame) {
|
|
46
|
+
pushUnmountExitFrame(frame.node, frame.renderRuntime);
|
|
47
|
+
pushUnmountChildrenFrame(frame.node, frame.renderRuntime);
|
|
48
|
+
}
|
|
49
|
+
function unmountHostExit(frame) {
|
|
50
|
+
const current = frame.node;
|
|
51
|
+
unmountRef(current);
|
|
52
|
+
frame.renderRuntime.hostAdapter.unmountProps(current.reference, current, frame.renderRuntime);
|
|
53
|
+
frame.renderRuntime.hostAdapter.detachElementFromReference(current.reference, frame.renderRuntime);
|
|
62
54
|
}
|
|
63
|
-
function
|
|
64
|
-
|
|
65
|
-
|
|
55
|
+
function unmountPortalElement(frame) {
|
|
56
|
+
clearElementHostReference(frame.node.children, frame.node.ref, frame.renderRuntime);
|
|
57
|
+
pushUnmountChildrenFrame(frame.node, frame.renderRuntime);
|
|
66
58
|
}
|
|
67
|
-
function
|
|
68
|
-
|
|
59
|
+
function unmountFragmentElement(frame) {
|
|
60
|
+
pushUnmountChildrenFrame(frame.node, frame.renderRuntime);
|
|
69
61
|
}
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import { SIMP_ELEMENT_CHILD_FLAG_ELEMENT, SIMP_ELEMENT_CHILD_FLAG_LIST } from './createElement.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export function
|
|
5
|
-
|
|
6
|
-
node: parent,
|
|
7
|
-
kind: UNMOUNT_CHILDREN_ENTER,
|
|
8
|
-
meta,
|
|
9
|
-
});
|
|
2
|
+
import { acquireUnmountChildrenFrame } from './processStack.js';
|
|
3
|
+
import { pushUnmountEnterFrame } from './unmounting.js';
|
|
4
|
+
export function pushUnmountChildrenFrame(parent, renderRuntime) {
|
|
5
|
+
renderRuntime.renderStack.push(acquireUnmountChildrenFrame(renderRuntime, parent));
|
|
10
6
|
}
|
|
11
|
-
export function
|
|
7
|
+
export function unmountChildren(frame) {
|
|
12
8
|
switch (frame.node.childFlag) {
|
|
13
|
-
case SIMP_ELEMENT_CHILD_FLAG_LIST:
|
|
9
|
+
case SIMP_ELEMENT_CHILD_FLAG_LIST: {
|
|
14
10
|
const children = frame.node.children;
|
|
15
11
|
for (let i = children.length - 1; i >= 0; i -= 1) {
|
|
16
|
-
|
|
12
|
+
pushUnmountEnterFrame(children[i], frame.renderRuntime);
|
|
17
13
|
}
|
|
18
14
|
break;
|
|
15
|
+
}
|
|
19
16
|
case SIMP_ELEMENT_CHILD_FLAG_ELEMENT:
|
|
20
|
-
|
|
17
|
+
pushUnmountEnterFrame(frame.node.children, frame.renderRuntime);
|
|
21
18
|
break;
|
|
22
19
|
}
|
|
23
20
|
}
|
package/core/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SIMP_ELEMENT_CHILD_FLAG_ELEMENT, SIMP_ELEMENT_CHILD_FLAG_LIST, SIMP_ELEMENT_FLAG_FC, SIMP_ELEMENT_FLAG_FRAGMENT, SIMP_ELEMENT_FLAG_HOST, SIMP_ELEMENT_FLAG_PORTAL, SIMP_ELEMENT_FLAG_TEXT, } from './createElement.js';
|
|
1
|
+
import { SIMP_ELEMENT_CHILD_FLAG_ELEMENT, SIMP_ELEMENT_CHILD_FLAG_EMPTY, SIMP_ELEMENT_CHILD_FLAG_LIST, SIMP_ELEMENT_FLAG_FC, SIMP_ELEMENT_FLAG_FRAGMENT, SIMP_ELEMENT_FLAG_HOST, SIMP_ELEMENT_FLAG_PORTAL, SIMP_ELEMENT_FLAG_TEXT, } from './createElement.js';
|
|
2
2
|
export function bitScanForwardIndex(flag) {
|
|
3
3
|
const lsb = (flag & -flag) >>> 0;
|
|
4
4
|
return 31 - Math.clz32(lsb);
|
|
@@ -20,10 +20,9 @@ export function findParentReferenceFromElement(element) {
|
|
|
20
20
|
}
|
|
21
21
|
return null;
|
|
22
22
|
}
|
|
23
|
-
const placeStack = [];
|
|
24
23
|
export function placeElementBeforeAnchor(element, anchor, parentReference, renderRuntime) {
|
|
25
24
|
const { hostAdapter } = renderRuntime;
|
|
26
|
-
placeStack
|
|
25
|
+
const placeStack = [element];
|
|
27
26
|
let nextAnchor = anchor;
|
|
28
27
|
while (placeStack.length !== 0) {
|
|
29
28
|
const current = placeStack.pop();
|
|
@@ -98,24 +97,25 @@ function findNextLogicalElement(element) {
|
|
|
98
97
|
}
|
|
99
98
|
}
|
|
100
99
|
export function getLongestIncreasingSubsequenceIndexes(sequence) {
|
|
101
|
-
const
|
|
102
|
-
const
|
|
100
|
+
const n = sequence.length;
|
|
101
|
+
const predecessors = new Int32Array(n);
|
|
103
102
|
predecessors.fill(-1);
|
|
104
|
-
|
|
103
|
+
const result = new Int32Array(n);
|
|
104
|
+
let resultLen = 0;
|
|
105
|
+
for (let i = 0; i < n; i++) {
|
|
105
106
|
const value = sequence[i];
|
|
106
107
|
if (value === 0) {
|
|
107
108
|
continue;
|
|
108
109
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
predecessors[i] = lastResultIndex;
|
|
110
|
+
if (resultLen === 0 || sequence[result[resultLen - 1]] < value) {
|
|
111
|
+
if (resultLen > 0) {
|
|
112
|
+
predecessors[i] = result[resultLen - 1];
|
|
113
113
|
}
|
|
114
|
-
result
|
|
114
|
+
result[resultLen++] = i;
|
|
115
115
|
continue;
|
|
116
116
|
}
|
|
117
117
|
let start = 0;
|
|
118
|
-
let end =
|
|
118
|
+
let end = resultLen - 1;
|
|
119
119
|
while (start < end) {
|
|
120
120
|
const middle = (start + end) >> 1;
|
|
121
121
|
if (sequence[result[middle]] < value) {
|
|
@@ -132,8 +132,8 @@ export function getLongestIncreasingSubsequenceIndexes(sequence) {
|
|
|
132
132
|
result[start] = i;
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
|
-
let resultIndex =
|
|
136
|
-
let sequenceIndex = result[
|
|
135
|
+
let resultIndex = resultLen;
|
|
136
|
+
let sequenceIndex = resultLen > 0 ? result[resultLen - 1] : -1;
|
|
137
137
|
const indexes = new Int32Array(resultIndex);
|
|
138
138
|
while (resultIndex-- > 0) {
|
|
139
139
|
indexes[resultIndex] = sequenceIndex;
|
|
@@ -141,7 +141,29 @@ export function getLongestIncreasingSubsequenceIndexes(sequence) {
|
|
|
141
141
|
}
|
|
142
142
|
return indexes;
|
|
143
143
|
}
|
|
144
|
-
export function
|
|
144
|
+
export function detachElementFromParent(element) {
|
|
145
|
+
const parent = element.parent;
|
|
146
|
+
if (!parent)
|
|
147
|
+
return;
|
|
148
|
+
if (parent.childFlag === SIMP_ELEMENT_CHILD_FLAG_LIST) {
|
|
149
|
+
const list = parent.children;
|
|
150
|
+
list.splice(element.index, 1);
|
|
151
|
+
if (list.length === 1) {
|
|
152
|
+
parent.children = list[0];
|
|
153
|
+
parent.childFlag = SIMP_ELEMENT_CHILD_FLAG_ELEMENT;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
for (let i = element.index; i < list.length; i++) {
|
|
157
|
+
list[i].index = i;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
parent.childFlag = SIMP_ELEMENT_CHILD_FLAG_EMPTY;
|
|
163
|
+
parent.children = null;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
export function clearElementHostReference(element, parentHostReference, renderRuntime) {
|
|
145
167
|
while (element != null) {
|
|
146
168
|
if (isHostLike(element.flag)) {
|
|
147
169
|
renderRuntime.hostAdapter.removeChild(parentHostReference, element.reference);
|
|
@@ -157,7 +179,7 @@ export function _clearElementHostReference(element, parentHostReference, renderR
|
|
|
157
179
|
switch (childFlag) {
|
|
158
180
|
case SIMP_ELEMENT_CHILD_FLAG_LIST:
|
|
159
181
|
for (let i = 0, len = children.length; i < len; ++i) {
|
|
160
|
-
|
|
182
|
+
clearElementHostReference(children[i], parentHostReference, renderRuntime);
|
|
161
183
|
}
|
|
162
184
|
return;
|
|
163
185
|
case SIMP_ELEMENT_CHILD_FLAG_ELEMENT:
|
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isText } from '../core/internal.js';
|
|
2
|
+
const domElementMaps = new WeakMap();
|
|
3
|
+
function getDomMap(renderRuntime) {
|
|
4
|
+
let map = domElementMaps.get(renderRuntime);
|
|
5
|
+
if (!map) {
|
|
6
|
+
map = new Map();
|
|
7
|
+
domElementMaps.set(renderRuntime, map);
|
|
8
|
+
}
|
|
9
|
+
return map;
|
|
10
|
+
}
|
|
2
11
|
export function attachElementToDom(element, dom, renderRuntime) {
|
|
3
|
-
if ((element
|
|
4
|
-
renderRuntime.
|
|
12
|
+
if (!isText(element)) {
|
|
13
|
+
getDomMap(renderRuntime).set(dom, element);
|
|
5
14
|
}
|
|
6
15
|
}
|
|
7
16
|
export function getElementFromDom(target, renderRuntime) {
|
|
8
17
|
if (!target) {
|
|
9
18
|
return null;
|
|
10
19
|
}
|
|
11
|
-
|
|
20
|
+
const map = getDomMap(renderRuntime);
|
|
21
|
+
while (target && !map.has(target)) {
|
|
12
22
|
target = target.parentElement;
|
|
13
23
|
}
|
|
14
24
|
if (!target) {
|
|
15
25
|
return null;
|
|
16
26
|
}
|
|
17
|
-
return
|
|
27
|
+
return map.get(target);
|
|
18
28
|
}
|
|
19
29
|
export function detachElementFromDom(dom, renderRuntime) {
|
|
20
|
-
|
|
21
|
-
renderRuntime.elementToHostMap.delete(dom);
|
|
22
|
-
}
|
|
30
|
+
getDomMap(renderRuntime).delete(dom);
|
|
23
31
|
}
|
package/dom/events.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isHost } from '../core/internal.js';
|
|
2
2
|
const eventNameByTypes = {
|
|
3
3
|
click: 'onClick',
|
|
4
4
|
dblclick: 'onDblClick',
|
|
@@ -57,21 +57,17 @@ export class SyntheticEvent {
|
|
|
57
57
|
currentTarget = null;
|
|
58
58
|
isPropagationStopped = false;
|
|
59
59
|
_isDefaultPrevented = false;
|
|
60
|
-
button;
|
|
61
|
-
buttons;
|
|
62
|
-
pointerId;
|
|
63
|
-
altKey;
|
|
64
|
-
ctrlKey;
|
|
65
|
-
shiftKey;
|
|
66
|
-
metaKey;
|
|
67
60
|
constructor(event) {
|
|
68
61
|
this.nativeEvent = event;
|
|
69
|
-
this
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
62
|
+
return new Proxy(this, {
|
|
63
|
+
get(target, prop, receiver) {
|
|
64
|
+
if (prop in target) {
|
|
65
|
+
return Reflect.get(target, prop, receiver);
|
|
66
|
+
}
|
|
67
|
+
const val = event[prop];
|
|
68
|
+
return typeof val === 'function' ? val.bind(event) : val;
|
|
69
|
+
},
|
|
70
|
+
});
|
|
75
71
|
}
|
|
76
72
|
get target() {
|
|
77
73
|
return this.nativeEvent.target;
|
|
@@ -97,7 +93,7 @@ export function dispatchDelegatedEvent(event, renderRuntime) {
|
|
|
97
93
|
const bubbleHandlers = [];
|
|
98
94
|
let element = renderRuntime.hostAdapter.getElementFromReference(event.target, renderRuntime);
|
|
99
95
|
while (element) {
|
|
100
|
-
if ((element
|
|
96
|
+
if (isHost(element)) {
|
|
101
97
|
const captureHandler = element.props?.[eventNameByTypes[event.type] + 'Capture'];
|
|
102
98
|
const bubbleHandler = element.props?.[eventNameByTypes[event.type]];
|
|
103
99
|
if (captureHandler) {
|
package/dom/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { RefAttributes, SimpElement, SimpNode, SimpRenderRuntime } from '../core/index.js';
|
|
2
|
-
import type { HostAdapter } from '../core/internal.js';
|
|
1
|
+
import type { HostAdapter, RefAttributes, SimpElement, SimpNode, SimpRenderRuntime } from '../core/index.js';
|
|
3
2
|
import type { Nullable } from '../shared/index.js';
|
|
4
3
|
|
|
5
4
|
import type { PropertiesHyphen } from 'csstype';
|
|
@@ -17,15 +16,15 @@ export interface SimpRoot {
|
|
|
17
16
|
unmount(): void;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
declare function createCreateRoot(
|
|
19
|
+
export declare function createCreateRoot(
|
|
21
20
|
renderRuntime: SimpRenderRuntime
|
|
22
21
|
): (container: Element | DocumentFragment) => SimpRoot;
|
|
23
22
|
|
|
24
|
-
declare function createRenderer(
|
|
23
|
+
export declare function createRenderer(
|
|
25
24
|
renderRuntime: SimpRenderRuntime
|
|
26
25
|
): (element: SimpElement, parentReference: Nullable<HTMLElement>) => void;
|
|
27
26
|
|
|
28
|
-
declare const domAdapter: HostAdapter;
|
|
27
|
+
export declare const domAdapter: HostAdapter;
|
|
29
28
|
|
|
30
29
|
export interface SimpReactHTMLElement<T extends HTMLElement>
|
|
31
30
|
extends DetailedSimpReactHTMLElement<AllHTMLAttributes<T>, T> {}
|
|
@@ -659,6 +658,7 @@ export interface KeygenHTMLAttributes<T> extends HTMLAttributes<T> {
|
|
|
659
658
|
|
|
660
659
|
export interface LabelHTMLAttributes<T> extends HTMLAttributes<T> {
|
|
661
660
|
form?: string | undefined;
|
|
661
|
+
for?: string | undefined;
|
|
662
662
|
htmlFor?: string | undefined;
|
|
663
663
|
}
|
|
664
664
|
|
|
@@ -760,6 +760,7 @@ export interface OptionHTMLAttributes<T> extends HTMLAttributes<T> {
|
|
|
760
760
|
|
|
761
761
|
export interface OutputHTMLAttributes<T> extends HTMLAttributes<T> {
|
|
762
762
|
form?: string | undefined;
|
|
763
|
+
for?: string | undefined;
|
|
763
764
|
htmlFor?: string | undefined;
|
|
764
765
|
name?: string | undefined;
|
|
765
766
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export const htmlAttrAlias = {
|
|
2
|
+
class: 'className',
|
|
3
|
+
for: 'htmlFor',
|
|
4
|
+
};
|
|
5
|
+
export const svgCamelToHyphen = {
|
|
6
|
+
accentHeight: 'accent-height',
|
|
7
|
+
alignmentBaseline: 'alignment-baseline',
|
|
8
|
+
arabicForm: 'arabic-form',
|
|
9
|
+
baselineShift: 'baseline-shift',
|
|
10
|
+
capHeight: 'cap-height',
|
|
11
|
+
clipPath: 'clip-path',
|
|
12
|
+
clipRule: 'clip-rule',
|
|
13
|
+
colorInterpolation: 'color-interpolation',
|
|
14
|
+
colorInterpolationFilters: 'color-interpolation-filters',
|
|
15
|
+
colorProfile: 'color-profile',
|
|
16
|
+
colorRendering: 'color-rendering',
|
|
17
|
+
dominantBaseline: 'dominant-baseline',
|
|
18
|
+
enableBackground: 'enable-background',
|
|
19
|
+
fillOpacity: 'fill-opacity',
|
|
20
|
+
fillRule: 'fill-rule',
|
|
21
|
+
floodColor: 'flood-color',
|
|
22
|
+
floodOpacity: 'flood-opacity',
|
|
23
|
+
fontFamily: 'font-family',
|
|
24
|
+
fontSize: 'font-size',
|
|
25
|
+
fontSizeAdjust: 'font-size-adjust',
|
|
26
|
+
fontStretch: 'font-stretch',
|
|
27
|
+
fontStyle: 'font-style',
|
|
28
|
+
fontVariant: 'font-variant',
|
|
29
|
+
fontWeight: 'font-weight',
|
|
30
|
+
glyphName: 'glyph-name',
|
|
31
|
+
glyphOrientationHorizontal: 'glyph-orientation-horizontal',
|
|
32
|
+
glyphOrientationVertical: 'glyph-orientation-vertical',
|
|
33
|
+
horizAdvX: 'horiz-adv-x',
|
|
34
|
+
horizOriginX: 'horiz-origin-x',
|
|
35
|
+
imageRendering: 'image-rendering',
|
|
36
|
+
letterSpacing: 'letter-spacing',
|
|
37
|
+
lightingColor: 'lighting-color',
|
|
38
|
+
markerEnd: 'marker-end',
|
|
39
|
+
markerMid: 'marker-mid',
|
|
40
|
+
markerStart: 'marker-start',
|
|
41
|
+
overlinePosition: 'overline-position',
|
|
42
|
+
overlineThickness: 'overline-thickness',
|
|
43
|
+
paintOrder: 'paint-order',
|
|
44
|
+
panose1: 'panose-1',
|
|
45
|
+
pointerEvents: 'pointer-events',
|
|
46
|
+
renderingIntent: 'rendering-intent',
|
|
47
|
+
shapeRendering: 'shape-rendering',
|
|
48
|
+
stopColor: 'stop-color',
|
|
49
|
+
stopOpacity: 'stop-opacity',
|
|
50
|
+
strikethroughPosition: 'strikethrough-position',
|
|
51
|
+
strikethroughThickness: 'strikethrough-thickness',
|
|
52
|
+
strokeDasharray: 'stroke-dasharray',
|
|
53
|
+
strokeDashoffset: 'stroke-dashoffset',
|
|
54
|
+
strokeLinecap: 'stroke-linecap',
|
|
55
|
+
strokeLinejoin: 'stroke-linejoin',
|
|
56
|
+
strokeMiterlimit: 'stroke-miterlimit',
|
|
57
|
+
strokeOpacity: 'stroke-opacity',
|
|
58
|
+
strokeWidth: 'stroke-width',
|
|
59
|
+
textAnchor: 'text-anchor',
|
|
60
|
+
textDecoration: 'text-decoration',
|
|
61
|
+
textRendering: 'text-rendering',
|
|
62
|
+
underlinePosition: 'underline-position',
|
|
63
|
+
underlineThickness: 'underline-thickness',
|
|
64
|
+
unicodeBidi: 'unicode-bidi',
|
|
65
|
+
unicodeRange: 'unicode-range',
|
|
66
|
+
unitsPerEm: 'units-per-em',
|
|
67
|
+
vAlphabetic: 'v-alphabetic',
|
|
68
|
+
vHanging: 'v-hanging',
|
|
69
|
+
vIdeographic: 'v-ideographic',
|
|
70
|
+
vMathematical: 'v-mathematical',
|
|
71
|
+
vectorEffect: 'vector-effect',
|
|
72
|
+
vertAdvY: 'vert-adv-y',
|
|
73
|
+
vertOriginX: 'vert-origin-x',
|
|
74
|
+
vertOriginY: 'vert-origin-y',
|
|
75
|
+
wordSpacing: 'word-spacing',
|
|
76
|
+
writingMode: 'writing-mode',
|
|
77
|
+
xHeight: 'x-height',
|
|
78
|
+
};
|
|
79
|
+
export const svgAttrsNamespaces = {
|
|
80
|
+
'xlink:actuate': 'http://www.w3.org/1999/xlink',
|
|
81
|
+
'xlink:arcrole': 'http://www.w3.org/1999/xlink',
|
|
82
|
+
'xlink:href': 'http://www.w3.org/1999/xlink',
|
|
83
|
+
'xlink:role': 'http://www.w3.org/1999/xlink',
|
|
84
|
+
'xlink:show': 'http://www.w3.org/1999/xlink',
|
|
85
|
+
'xlink:title': 'http://www.w3.org/1999/xlink',
|
|
86
|
+
'xlink:type': 'http://www.w3.org/1999/xlink',
|
|
87
|
+
'xml:base': 'http://www.w3.org/XML/1998/namespace',
|
|
88
|
+
'xml:lang': 'http://www.w3.org/XML/1998/namespace',
|
|
89
|
+
'xml:space': 'http://www.w3.org/XML/1998/namespace',
|
|
90
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { hasElementChild, hasListChildren, withSyncRerender, } from '../../../core/internal.js';
|
|
2
2
|
import { emptyObject } from '../../../shared/index.js';
|
|
3
3
|
export function isEventNameIgnored(eventName) {
|
|
4
4
|
return eventName === 'onChange';
|
|
@@ -61,15 +61,13 @@ function updateOptions(element, value) {
|
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
const children = element.children;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
case SIMP_ELEMENT_CHILD_FLAG_ELEMENT:
|
|
72
|
-
updateOptions(children, value);
|
|
64
|
+
if (hasListChildren(element)) {
|
|
65
|
+
for (let i = 0, len = children.length; i < len; ++i) {
|
|
66
|
+
updateOptions(children[i], value);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (hasElementChild(element)) {
|
|
70
|
+
updateOptions(children, value);
|
|
73
71
|
}
|
|
74
72
|
}
|
|
75
73
|
function updateOption(element, value) {
|
package/dom/props/props.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { emptyObject } from '../../shared/index.js';
|
|
2
2
|
import { isPropNameEventName, patchEvent } from '../events.js';
|
|
3
3
|
import { defaultNamespace } from '../namespace.js';
|
|
4
|
+
import { htmlAttrAlias, svgAttrsNamespaces, svgCamelToHyphen } from './attrMaps.js';
|
|
4
5
|
import { addControlledFormElementEventHandlers, isEventNameIgnored, isFormElementControlled, removeControlledFormElementEventHandlers, syncControlledFormElementPropsWithAttrs, } from './controlled/index.js';
|
|
5
6
|
import { patchDangerInnerHTML } from './dangerInnerHTML.js';
|
|
6
7
|
import { patchStyle } from './style.js';
|
|
@@ -76,6 +77,7 @@ export function patchProps(dom, prevElement, nextElement, namespace, renderRunti
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
function patchFormElementsPropAndAttrs(propName, dom, element, isControlled, prevValue, nextValue, renderRuntime) {
|
|
80
|
+
propName = htmlAttrAlias[propName] ?? propName;
|
|
79
81
|
switch (propName) {
|
|
80
82
|
case 'children':
|
|
81
83
|
case 'className':
|
|
@@ -123,6 +125,7 @@ function patchFormElementsPropAndAttrs(propName, dom, element, isControlled, pre
|
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
127
|
function patchDefaultElementPropAndAttrs(propName, dom, nextElement, prevValue, nextValue, namespace, renderRuntime) {
|
|
128
|
+
propName = htmlAttrAlias[propName] ?? propName;
|
|
126
129
|
switch (propName) {
|
|
127
130
|
case 'children':
|
|
128
131
|
case 'className':
|
|
@@ -155,6 +158,9 @@ function patchDefaultElementPropAndAttrs(propName, dom, nextElement, prevValue,
|
|
|
155
158
|
case 'dangerouslySetInnerHTML':
|
|
156
159
|
patchDangerInnerHTML(prevValue, nextValue, nextElement, dom);
|
|
157
160
|
break;
|
|
161
|
+
case 'htmlFor':
|
|
162
|
+
patchDomAttr(dom, nextValue, 'for', namespace);
|
|
163
|
+
break;
|
|
158
164
|
default:
|
|
159
165
|
if (isPropNameEventName(propName)) {
|
|
160
166
|
patchEvent(propName, prevValue, nextValue, dom, renderRuntime);
|
|
@@ -175,26 +181,19 @@ function patchDomAttr(dom, value, propName, namespace = defaultNamespace) {
|
|
|
175
181
|
dom.removeAttribute(propName);
|
|
176
182
|
}
|
|
177
183
|
else {
|
|
178
|
-
if (namespace === 'http://www.w3.org/2000/svg'
|
|
179
|
-
|
|
184
|
+
if (namespace === 'http://www.w3.org/2000/svg') {
|
|
185
|
+
if (svgAttrsNamespaces[propName]) {
|
|
186
|
+
dom.setAttributeNS(svgAttrsNamespaces[propName], propName, value);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
dom.setAttribute(svgCamelToHyphen[propName] ?? propName, value);
|
|
190
|
+
}
|
|
180
191
|
}
|
|
181
192
|
else {
|
|
182
193
|
dom.setAttribute(propName, value);
|
|
183
194
|
}
|
|
184
195
|
}
|
|
185
196
|
}
|
|
186
|
-
const svgAttrsNamespaces = {
|
|
187
|
-
'xlink:actuate': 'http://www.w3.org/1999/xlink',
|
|
188
|
-
'xlink:arcrole': 'http://www.w3.org/1999/xlink',
|
|
189
|
-
'xlink:href': 'http://www.w3.org/1999/xlink',
|
|
190
|
-
'xlink:role': 'http://www.w3.org/1999/xlink',
|
|
191
|
-
'xlink:show': 'http://www.w3.org/1999/xlink',
|
|
192
|
-
'xlink:title': 'http://www.w3.org/1999/xlink',
|
|
193
|
-
'xlink:type': 'http://www.w3.org/1999/xlink',
|
|
194
|
-
'xml:base': 'http://www.w3.org/XML/1998/namespace',
|
|
195
|
-
'xml:lang': 'http://www.w3.org/XML/1998/namespace',
|
|
196
|
-
'xml:space': 'http://www.w3.org/XML/1998/namespace',
|
|
197
|
-
};
|
|
198
197
|
function isFormElement(element) {
|
|
199
198
|
return element.type === 'input' || element.type === 'textarea' || element.type === 'select';
|
|
200
199
|
}
|
package/hooks/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { RefObject, SimpRenderRuntime } from '../core/index.js';
|
|
2
|
-
|
|
3
|
-
export type Cleanup = () => void;
|
|
4
|
-
export type Effect = () => void | Cleanup;
|
|
5
|
-
export type DependencyList = readonly unknown[];
|
|
2
|
+
import type { DependencyList, Effect } from '../shared/index.js';
|
|
6
3
|
|
|
7
4
|
export type Dispatch<A> = (value: A) => void;
|
|
8
5
|
export type SetStateAction<S> = S | ((prevState: S) => S);
|
|
@@ -12,18 +9,26 @@ export interface UseRef {
|
|
|
12
9
|
<T>(initialValue: T | null): RefObject<T | null>;
|
|
13
10
|
<T = undefined>(initialValue?: T): RefObject<T | undefined>;
|
|
14
11
|
}
|
|
15
|
-
declare function createUseRef(renderRuntime: SimpRenderRuntime): UseRef;
|
|
12
|
+
export declare function createUseRef(renderRuntime: SimpRenderRuntime): UseRef;
|
|
16
13
|
|
|
17
|
-
declare function createUseRerender(renderRuntime: SimpRenderRuntime): () => void;
|
|
14
|
+
export declare function createUseRerender(renderRuntime: SimpRenderRuntime): () => void;
|
|
18
15
|
|
|
19
16
|
export interface UseState {
|
|
20
17
|
<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>];
|
|
21
18
|
<S>(): [S | undefined, Dispatch<SetStateAction<S | undefined>>];
|
|
19
|
+
<S = undefined>(
|
|
20
|
+
initialState: undefined | (() => undefined)
|
|
21
|
+
): [S | undefined, Dispatch<SetStateAction<S | undefined>>];
|
|
22
22
|
}
|
|
23
|
-
declare function createUseState(renderRuntime: SimpRenderRuntime):
|
|
23
|
+
export declare function createUseState(renderRuntime: SimpRenderRuntime): UseState;
|
|
24
24
|
|
|
25
|
-
declare function createUseEffect(
|
|
25
|
+
export declare function createUseEffect(
|
|
26
|
+
renderRuntime: SimpRenderRuntime
|
|
27
|
+
): (effect: Effect, deps?: DependencyList) => void;
|
|
26
28
|
|
|
27
|
-
declare function createUseCatch(renderRuntime: SimpRenderRuntime): (cb: (error: any) => void) => void;
|
|
29
|
+
export declare function createUseCatch(renderRuntime: SimpRenderRuntime): (cb: (error: any) => void) => void;
|
|
28
30
|
|
|
29
|
-
declare function areDepsEqual(
|
|
31
|
+
export declare function areDepsEqual(
|
|
32
|
+
nextDeps: DependencyList | undefined,
|
|
33
|
+
prevDeps: DependencyList | undefined
|
|
34
|
+
): boolean;
|