4db93cb51f605ae8910b5efbc162a8e2103cbaf4.svn-base
4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _scheduler = require("scheduler");
var _reactReconciler = _interopRequireDefault(require("react-reconciler"));
var _dom = require("./dom");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const NO_CONTEXT = true;
const hostConfig = {
schedulePassiveEffects: _scheduler.unstable_scheduleCallback,
cancelPassiveEffects: _scheduler.unstable_cancelCallback,
now: Date.now,
getRootHostContext: () => NO_CONTEXT,
prepareForCommit: () => {},
resetAfterCommit: rootNode => {
rootNode.onRender();
},
getChildHostContext: () => NO_CONTEXT,
shouldSetTextContent: (type, props) => {
return typeof props.children === 'string' || typeof props.children === 'number';
},
createInstance: (type, newProps) => {
const node = (0, _dom.createNode)(type);
for (const [key, value] of Object.entries(newProps)) {
if (key === 'children') {
if (typeof value === 'string' || typeof value === 'number') {
if (type === 'div') {
// Text node must be wrapped in another node, so that text can be aligned within container
const textElement = (0, _dom.createNode)('div');
textElement.textContent = String(value);
(0, _dom.appendChildNode)(node, textElement);
}
if (type === 'span') {
node.textContent = String(value);
}
}
} else if (key === 'style') {
node.style = value;
} else if (key === 'unstable__transformChildren') {
node.unstable__transformChildren = value; // eslint-disable-line camelcase
} else if (key === 'unstable__static') {
node.unstable__static = true; // eslint-disable-line camelcase
} else {
(0, _dom.setAttribute)(node, key, value);
}
}
return node;
},
createTextInstance: _dom.createTextNode,
resetTextContent: node => {
if (node.textContent) {
node.textContent = '';
}
if (node.childNodes.length > 0) {
for (const childNode of node.childNodes) {
childNode.yogaNode.free();
(0, _dom.removeChildNode)(node, childNode);
}
}
},
getPublicInstance: instance => instance,
appendInitialChild: _dom.appendChildNode,
appendChild: _dom.appendChildNode,
insertBefore: _dom.insertBeforeNode,
finalizeInitialChildren: () => {},
supportsMutation: true,
appendChildToContainer: _dom.appendChildNode,
insertInContainerBefore: _dom.insertBeforeNode,
removeChildFromContainer: _dom.removeChildNode,
prepareUpdate: () => true,
commitUpdate: (node, updatePayload, type, oldProps, newProps) => {
for (const [key, value] of Object.entries(newProps)) {
if (key === 'children') {
if (typeof value === 'string' || typeof value === 'number') {
if (type === 'div') {
// Text node must be wrapped in another node, so that text can be aligned within container
// If there's no such node, a new one must be created
if (node.childNodes.length === 0) {
const textElement = (0, _dom.createNode)('div');
textElement.textContent = String(value);
(0, _dom.appendChildNode)(node, textElement);
} else {
node.childNodes[0].textContent = String(value);
}
}
if (type === 'span') {
node.textContent = String(value);
}
}
} else if (key === 'style') {
node.style = value;
} else if (key === 'unstable__transformChildren') {
node.unstable__transformChildren = value; // eslint-disable-line camelcase
} else if (key === 'unstable__static') {
node.unstable__static = true; // eslint-disable-line camelcase
} else {
(0, _dom.setAttribute)(node, key, value);
}
}
},
commitTextUpdate: (node, oldText, newText) => {
if (node.nodeName === '#text') {
node.nodeValue = newText;
} else {
node.textContent = newText;
}
},
removeChild: _dom.removeChildNode
};
var _default = (0, _reactReconciler.default)(hostConfig); // eslint-disable-line new-cap
exports.default = _default;