@tarojs/react 3.5.0-alpha.13 → 3.5.0-alpha.16
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/dist/index.js +296 -302
- package/dist/index.js.map +1 -1
- package/dist/react.esm.js +298 -302
- package/dist/react.esm.js.map +1 -1
- package/package.json +10 -11
package/dist/react.esm.js
CHANGED
|
@@ -1,314 +1,310 @@
|
|
|
1
|
+
import { isString, isObject, isFunction, capitalize, toCamelCase, internalComponents, isNumber, EMPTY_ARR, isBoolean, isUndefined, noop, ensure } from '@tarojs/shared';
|
|
2
|
+
import { FormElement, document } from '@tarojs/runtime';
|
|
1
3
|
import Reconciler from 'react-reconciler';
|
|
2
4
|
import * as scheduler from 'scheduler';
|
|
3
|
-
import { FormElement, document } from '@tarojs/runtime';
|
|
4
|
-
import { isString, isObject, isFunction, capitalize, toCamelCase, internalComponents, isNumber, EMPTY_ARR, isBoolean, isUndefined, noop, ensure } from '@tarojs/shared';
|
|
5
5
|
|
|
6
|
-
function isEventName(s) {
|
|
7
|
-
return s[0] === 'o' && s[1] === 'n';
|
|
8
|
-
}
|
|
9
|
-
const IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord/i;
|
|
10
|
-
function updateProps(dom, oldProps, newProps) {
|
|
11
|
-
let i;
|
|
12
|
-
for (i in oldProps) {
|
|
13
|
-
if (!(i in newProps)) {
|
|
14
|
-
setProperty(dom, i, null, oldProps[i]);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
const isFormElement = dom instanceof FormElement;
|
|
18
|
-
for (i in newProps) {
|
|
19
|
-
if (oldProps[i] !== newProps[i] || (isFormElement && i === 'value')) {
|
|
20
|
-
setProperty(dom, i, newProps[i], oldProps[i]);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
// function eventProxy (e: CommonEvent) {
|
|
25
|
-
// const el = document.getElementById(e.currentTarget.id)
|
|
26
|
-
// const handlers = el!.__handlers[e.type]
|
|
27
|
-
// handlers[0](e)
|
|
28
|
-
// }
|
|
29
|
-
function setEvent(dom, name, value, oldValue) {
|
|
30
|
-
const isCapture = name.endsWith('Capture');
|
|
31
|
-
let eventName = name.toLowerCase().slice(2);
|
|
32
|
-
if (isCapture) {
|
|
33
|
-
eventName = eventName.slice(0, -7);
|
|
34
|
-
}
|
|
35
|
-
const compName = capitalize(toCamelCase(dom.tagName.toLowerCase()));
|
|
36
|
-
if (eventName === 'click' && compName in internalComponents) {
|
|
37
|
-
eventName = 'tap';
|
|
38
|
-
}
|
|
39
|
-
if (isFunction(value)) {
|
|
40
|
-
if (
|
|
41
|
-
dom.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
dom.
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (name === '
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
oldValue
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
else if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
dom.
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
dom.setAttribute(name, value);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
6
|
+
function isEventName(s) {
|
|
7
|
+
return s[0] === 'o' && s[1] === 'n';
|
|
8
|
+
}
|
|
9
|
+
const IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord/i;
|
|
10
|
+
function updateProps(dom, oldProps, newProps) {
|
|
11
|
+
let i;
|
|
12
|
+
for (i in oldProps) {
|
|
13
|
+
if (!(i in newProps)) {
|
|
14
|
+
setProperty(dom, i, null, oldProps[i]);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const isFormElement = dom instanceof FormElement;
|
|
18
|
+
for (i in newProps) {
|
|
19
|
+
if (oldProps[i] !== newProps[i] || (isFormElement && i === 'value')) {
|
|
20
|
+
setProperty(dom, i, newProps[i], oldProps[i]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// function eventProxy (e: CommonEvent) {
|
|
25
|
+
// const el = document.getElementById(e.currentTarget.id)
|
|
26
|
+
// const handlers = el!.__handlers[e.type]
|
|
27
|
+
// handlers[0](e)
|
|
28
|
+
// }
|
|
29
|
+
function setEvent(dom, name, value, oldValue) {
|
|
30
|
+
const isCapture = name.endsWith('Capture');
|
|
31
|
+
let eventName = name.toLowerCase().slice(2);
|
|
32
|
+
if (isCapture) {
|
|
33
|
+
eventName = eventName.slice(0, -7);
|
|
34
|
+
}
|
|
35
|
+
const compName = capitalize(toCamelCase(dom.tagName.toLowerCase()));
|
|
36
|
+
if (eventName === 'click' && compName in internalComponents) {
|
|
37
|
+
eventName = 'tap';
|
|
38
|
+
}
|
|
39
|
+
if (isFunction(value)) {
|
|
40
|
+
if (oldValue) {
|
|
41
|
+
dom.removeEventListener(eventName, oldValue, false);
|
|
42
|
+
dom.addEventListener(eventName, value, { isCapture, sideEffect: false });
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
dom.addEventListener(eventName, value, isCapture);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
dom.removeEventListener(eventName, oldValue);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function setStyle(style, key, value) {
|
|
53
|
+
if (key[0] === '-') {
|
|
54
|
+
style.setProperty(key, value.toString());
|
|
55
|
+
}
|
|
56
|
+
style[key] =
|
|
57
|
+
isNumber(value) && IS_NON_DIMENSIONAL.test(key) === false
|
|
58
|
+
? value + 'px'
|
|
59
|
+
: value == null
|
|
60
|
+
? ''
|
|
61
|
+
: value;
|
|
62
|
+
}
|
|
63
|
+
function setProperty(dom, name, value, oldValue) {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
name = name === 'className' ? 'class' : name;
|
|
66
|
+
if (name === 'key' ||
|
|
67
|
+
name === 'children' ||
|
|
68
|
+
name === 'ref') ;
|
|
69
|
+
else if (name === 'style') {
|
|
70
|
+
const style = dom.style;
|
|
71
|
+
if (isString(value)) {
|
|
72
|
+
style.cssText = value;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
if (isString(oldValue)) {
|
|
76
|
+
style.cssText = '';
|
|
77
|
+
oldValue = null;
|
|
78
|
+
}
|
|
79
|
+
if (isObject(oldValue)) {
|
|
80
|
+
for (const i in oldValue) {
|
|
81
|
+
if (!(value && i in value)) {
|
|
82
|
+
setStyle(style, i, '');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (isObject(value)) {
|
|
87
|
+
for (const i in value) {
|
|
88
|
+
if (!oldValue || value[i] !== oldValue[i]) {
|
|
89
|
+
setStyle(style, i, value[i]);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else if (isEventName(name)) {
|
|
96
|
+
setEvent(dom, name, value, oldValue);
|
|
97
|
+
}
|
|
98
|
+
else if (name === 'dangerouslySetInnerHTML') {
|
|
99
|
+
const newHtml = (_a = value === null || value === void 0 ? void 0 : value.__html) !== null && _a !== void 0 ? _a : '';
|
|
100
|
+
const oldHtml = (_b = oldValue === null || oldValue === void 0 ? void 0 : oldValue.__html) !== null && _b !== void 0 ? _b : '';
|
|
101
|
+
if (newHtml || oldHtml) {
|
|
102
|
+
if (oldHtml !== newHtml) {
|
|
103
|
+
dom.innerHTML = newHtml;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else if (!isFunction(value)) {
|
|
108
|
+
if (value == null) {
|
|
109
|
+
dom.removeAttribute(name);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
dom.setAttribute(name, value);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
118
115
|
}
|
|
119
116
|
|
|
120
|
-
/* eslint-disable @typescript-eslint/indent */
|
|
121
|
-
const { unstable_now: now } = scheduler;
|
|
122
|
-
function returnFalse() {
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
const hostConfig = {
|
|
126
|
-
createInstance(type) {
|
|
127
|
-
return document.createElement(type);
|
|
128
|
-
},
|
|
129
|
-
createTextInstance(text) {
|
|
130
|
-
return document.createTextNode(text);
|
|
131
|
-
},
|
|
132
|
-
getPublicInstance(inst) {
|
|
133
|
-
return inst;
|
|
134
|
-
},
|
|
135
|
-
getRootHostContext() {
|
|
136
|
-
return {};
|
|
137
|
-
},
|
|
138
|
-
getChildHostContext() {
|
|
139
|
-
return {};
|
|
140
|
-
},
|
|
141
|
-
getCurrentEventPriority() {
|
|
142
|
-
// 因 @types/react-reconciler 未更新,ts会报错,这里直接返回16
|
|
143
|
-
return 16; // import { DefaultEventPriority } from 'react-reconciler/constants'
|
|
144
|
-
},
|
|
145
|
-
detachDeletedInstance() {
|
|
146
|
-
// noop
|
|
147
|
-
},
|
|
148
|
-
appendChild(parent, child) {
|
|
149
|
-
parent.appendChild(child);
|
|
150
|
-
},
|
|
151
|
-
appendInitialChild(parent, child) {
|
|
152
|
-
parent.appendChild(child);
|
|
153
|
-
},
|
|
154
|
-
appendChildToContainer(parent, child) {
|
|
155
|
-
parent.appendChild(child);
|
|
156
|
-
},
|
|
157
|
-
removeChild(parent, child) {
|
|
158
|
-
parent.removeChild(child);
|
|
159
|
-
},
|
|
160
|
-
removeChildFromContainer(parent, child) {
|
|
161
|
-
parent.removeChild(child);
|
|
162
|
-
},
|
|
163
|
-
insertBefore(parent, child, refChild) {
|
|
164
|
-
parent.insertBefore(child, refChild);
|
|
165
|
-
},
|
|
166
|
-
insertInContainerBefore(parent, child, refChild) {
|
|
167
|
-
parent.insertBefore(child, refChild);
|
|
168
|
-
},
|
|
169
|
-
commitTextUpdate(textInst, _, newText) {
|
|
170
|
-
textInst.nodeValue = newText;
|
|
171
|
-
},
|
|
172
|
-
finalizeInitialChildren(dom, _, props) {
|
|
173
|
-
updateProps(dom, {}, props);
|
|
174
|
-
return false;
|
|
175
|
-
},
|
|
176
|
-
prepareUpdate() {
|
|
177
|
-
return EMPTY_ARR;
|
|
178
|
-
},
|
|
179
|
-
commitUpdate(dom, _payload, _type, oldProps, newProps) {
|
|
180
|
-
updateProps(dom, oldProps, newProps);
|
|
181
|
-
},
|
|
182
|
-
hideInstance(instance) {
|
|
183
|
-
const style = instance.style;
|
|
184
|
-
style.setProperty('display', 'none');
|
|
185
|
-
},
|
|
186
|
-
unhideInstance(instance, props) {
|
|
187
|
-
const styleProp = props.style;
|
|
188
|
-
let display = (styleProp === null || styleProp === void 0 ? void 0 : styleProp.hasOwnProperty('display')) ? styleProp.display : null;
|
|
189
|
-
display = display == null || isBoolean(display) || display === '' ? '' : ('' + display).trim();
|
|
190
|
-
// eslint-disable-next-line dot-notation
|
|
191
|
-
instance.style['display'] = display;
|
|
192
|
-
},
|
|
193
|
-
clearContainer(element) {
|
|
194
|
-
if (element.childNodes.length > 0) {
|
|
195
|
-
element.textContent = '';
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
queueMicrotask: !isUndefined(Promise)
|
|
199
|
-
? callback => Promise.resolve(null)
|
|
200
|
-
.then(callback)
|
|
201
|
-
.catch(function (error) {
|
|
202
|
-
setTimeout(() => {
|
|
203
|
-
throw error;
|
|
204
|
-
});
|
|
205
|
-
})
|
|
206
|
-
: setTimeout,
|
|
207
|
-
shouldSetTextContent: returnFalse,
|
|
208
|
-
prepareForCommit(..._) { return null; },
|
|
209
|
-
resetAfterCommit: noop,
|
|
210
|
-
commitMount: noop,
|
|
211
|
-
now,
|
|
212
|
-
cancelTimeout: clearTimeout,
|
|
213
|
-
scheduleTimeout: setTimeout,
|
|
214
|
-
preparePortalMount: noop,
|
|
215
|
-
noTimeout: -1,
|
|
216
|
-
supportsMutation: true,
|
|
217
|
-
supportsPersistence: false,
|
|
218
|
-
isPrimaryRenderer: true,
|
|
219
|
-
supportsHydration: false
|
|
220
|
-
};
|
|
221
|
-
const TaroReconciler = Reconciler(hostConfig);
|
|
222
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
223
|
-
const foundDevTools = TaroReconciler.injectIntoDevTools({
|
|
224
|
-
bundleType: 1,
|
|
225
|
-
version: '18.0.0',
|
|
226
|
-
rendererPackageName: 'taro-react'
|
|
227
|
-
});
|
|
228
|
-
if (!foundDevTools) {
|
|
229
|
-
// eslint-disable-next-line no-console
|
|
230
|
-
console.info('%cDownload the React DevTools ' + 'for a better development experience: ' + 'https://reactjs.org/link/react-devtools', 'font-weight:bold');
|
|
231
|
-
}
|
|
117
|
+
/* eslint-disable @typescript-eslint/indent */
|
|
118
|
+
const { unstable_now: now } = scheduler;
|
|
119
|
+
function returnFalse() {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
const hostConfig = {
|
|
123
|
+
createInstance(type) {
|
|
124
|
+
return document.createElement(type);
|
|
125
|
+
},
|
|
126
|
+
createTextInstance(text) {
|
|
127
|
+
return document.createTextNode(text);
|
|
128
|
+
},
|
|
129
|
+
getPublicInstance(inst) {
|
|
130
|
+
return inst;
|
|
131
|
+
},
|
|
132
|
+
getRootHostContext() {
|
|
133
|
+
return {};
|
|
134
|
+
},
|
|
135
|
+
getChildHostContext() {
|
|
136
|
+
return {};
|
|
137
|
+
},
|
|
138
|
+
getCurrentEventPriority() {
|
|
139
|
+
// 因 @types/react-reconciler 未更新,ts会报错,这里直接返回16
|
|
140
|
+
return 16; // import { DefaultEventPriority } from 'react-reconciler/constants'
|
|
141
|
+
},
|
|
142
|
+
detachDeletedInstance() {
|
|
143
|
+
// noop
|
|
144
|
+
},
|
|
145
|
+
appendChild(parent, child) {
|
|
146
|
+
parent.appendChild(child);
|
|
147
|
+
},
|
|
148
|
+
appendInitialChild(parent, child) {
|
|
149
|
+
parent.appendChild(child);
|
|
150
|
+
},
|
|
151
|
+
appendChildToContainer(parent, child) {
|
|
152
|
+
parent.appendChild(child);
|
|
153
|
+
},
|
|
154
|
+
removeChild(parent, child) {
|
|
155
|
+
parent.removeChild(child);
|
|
156
|
+
},
|
|
157
|
+
removeChildFromContainer(parent, child) {
|
|
158
|
+
parent.removeChild(child);
|
|
159
|
+
},
|
|
160
|
+
insertBefore(parent, child, refChild) {
|
|
161
|
+
parent.insertBefore(child, refChild);
|
|
162
|
+
},
|
|
163
|
+
insertInContainerBefore(parent, child, refChild) {
|
|
164
|
+
parent.insertBefore(child, refChild);
|
|
165
|
+
},
|
|
166
|
+
commitTextUpdate(textInst, _, newText) {
|
|
167
|
+
textInst.nodeValue = newText;
|
|
168
|
+
},
|
|
169
|
+
finalizeInitialChildren(dom, _, props) {
|
|
170
|
+
updateProps(dom, {}, props);
|
|
171
|
+
return false;
|
|
172
|
+
},
|
|
173
|
+
prepareUpdate() {
|
|
174
|
+
return EMPTY_ARR;
|
|
175
|
+
},
|
|
176
|
+
commitUpdate(dom, _payload, _type, oldProps, newProps) {
|
|
177
|
+
updateProps(dom, oldProps, newProps);
|
|
178
|
+
},
|
|
179
|
+
hideInstance(instance) {
|
|
180
|
+
const style = instance.style;
|
|
181
|
+
style.setProperty('display', 'none');
|
|
182
|
+
},
|
|
183
|
+
unhideInstance(instance, props) {
|
|
184
|
+
const styleProp = props.style;
|
|
185
|
+
let display = (styleProp === null || styleProp === void 0 ? void 0 : styleProp.hasOwnProperty('display')) ? styleProp.display : null;
|
|
186
|
+
display = display == null || isBoolean(display) || display === '' ? '' : ('' + display).trim();
|
|
187
|
+
// eslint-disable-next-line dot-notation
|
|
188
|
+
instance.style['display'] = display;
|
|
189
|
+
},
|
|
190
|
+
clearContainer(element) {
|
|
191
|
+
if (element.childNodes.length > 0) {
|
|
192
|
+
element.textContent = '';
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
queueMicrotask: !isUndefined(Promise)
|
|
196
|
+
? callback => Promise.resolve(null)
|
|
197
|
+
.then(callback)
|
|
198
|
+
.catch(function (error) {
|
|
199
|
+
setTimeout(() => {
|
|
200
|
+
throw error;
|
|
201
|
+
});
|
|
202
|
+
})
|
|
203
|
+
: setTimeout,
|
|
204
|
+
shouldSetTextContent: returnFalse,
|
|
205
|
+
prepareForCommit(..._) { return null; },
|
|
206
|
+
resetAfterCommit: noop,
|
|
207
|
+
commitMount: noop,
|
|
208
|
+
now,
|
|
209
|
+
cancelTimeout: clearTimeout,
|
|
210
|
+
scheduleTimeout: setTimeout,
|
|
211
|
+
preparePortalMount: noop,
|
|
212
|
+
noTimeout: -1,
|
|
213
|
+
supportsMutation: true,
|
|
214
|
+
supportsPersistence: false,
|
|
215
|
+
isPrimaryRenderer: true,
|
|
216
|
+
supportsHydration: false
|
|
217
|
+
};
|
|
218
|
+
const TaroReconciler = Reconciler(hostConfig);
|
|
219
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
220
|
+
const foundDevTools = TaroReconciler.injectIntoDevTools({
|
|
221
|
+
bundleType: 1,
|
|
222
|
+
version: '18.0.0',
|
|
223
|
+
rendererPackageName: 'taro-react'
|
|
224
|
+
});
|
|
225
|
+
if (!foundDevTools) {
|
|
226
|
+
// eslint-disable-next-line no-console
|
|
227
|
+
console.info('%cDownload the React DevTools ' + 'for a better development experience: ' + 'https://reactjs.org/link/react-devtools', 'font-weight:bold');
|
|
228
|
+
}
|
|
232
229
|
}
|
|
233
230
|
|
|
234
|
-
const ContainerMap = new WeakMap();
|
|
235
|
-
class Root {
|
|
236
|
-
constructor(renderer, domContainer, isConcurrentRoot = false) {
|
|
237
|
-
this.renderer = renderer;
|
|
238
|
-
/** ConcurrentRoot & LegacyRoot: react-reconciler/src/ReactRootTags.js */
|
|
239
|
-
this.internalRoot = renderer.createContainer(domContainer, isConcurrentRoot ? 1 : 0, false, null);
|
|
240
|
-
}
|
|
241
|
-
render(children, cb) {
|
|
242
|
-
const { renderer, internalRoot } = this;
|
|
243
|
-
renderer.updateContainer(children, internalRoot, null, cb);
|
|
244
|
-
return renderer.getPublicRootInstance(internalRoot);
|
|
245
|
-
}
|
|
246
|
-
unmount(cb) {
|
|
247
|
-
this.renderer.updateContainer(null, this.internalRoot, null, cb);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
function render(element, domContainer, cb) {
|
|
251
|
-
const oldRoot = ContainerMap.get(domContainer);
|
|
252
|
-
if (oldRoot != null) {
|
|
253
|
-
return oldRoot.render(element, cb);
|
|
254
|
-
}
|
|
255
|
-
const root = new Root(TaroReconciler, domContainer);
|
|
256
|
-
ContainerMap.set(domContainer, root);
|
|
257
|
-
return root.render(element, cb);
|
|
258
|
-
}
|
|
259
|
-
function createRoot(domContainer) {
|
|
260
|
-
const oldRoot = ContainerMap.get(domContainer);
|
|
261
|
-
if (oldRoot != null) {
|
|
262
|
-
return oldRoot;
|
|
263
|
-
}
|
|
264
|
-
const root = new Root(TaroReconciler, domContainer, true);
|
|
265
|
-
ContainerMap.set(domContainer, root);
|
|
266
|
-
return root;
|
|
231
|
+
const ContainerMap = new WeakMap();
|
|
232
|
+
class Root {
|
|
233
|
+
constructor(renderer, domContainer, isConcurrentRoot = false) {
|
|
234
|
+
this.renderer = renderer;
|
|
235
|
+
/** ConcurrentRoot & LegacyRoot: react-reconciler/src/ReactRootTags.js */
|
|
236
|
+
this.internalRoot = renderer.createContainer(domContainer, isConcurrentRoot ? 1 : 0, false, null);
|
|
237
|
+
}
|
|
238
|
+
render(children, cb) {
|
|
239
|
+
const { renderer, internalRoot } = this;
|
|
240
|
+
renderer.updateContainer(children, internalRoot, null, cb);
|
|
241
|
+
return renderer.getPublicRootInstance(internalRoot);
|
|
242
|
+
}
|
|
243
|
+
unmount(cb) {
|
|
244
|
+
this.renderer.updateContainer(null, this.internalRoot, null, cb);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function render(element, domContainer, cb) {
|
|
248
|
+
const oldRoot = ContainerMap.get(domContainer);
|
|
249
|
+
if (oldRoot != null) {
|
|
250
|
+
return oldRoot.render(element, cb);
|
|
251
|
+
}
|
|
252
|
+
const root = new Root(TaroReconciler, domContainer);
|
|
253
|
+
ContainerMap.set(domContainer, root);
|
|
254
|
+
return root.render(element, cb);
|
|
255
|
+
}
|
|
256
|
+
function createRoot(domContainer) {
|
|
257
|
+
const oldRoot = ContainerMap.get(domContainer);
|
|
258
|
+
if (oldRoot != null) {
|
|
259
|
+
return oldRoot;
|
|
260
|
+
}
|
|
261
|
+
const root = new Root(TaroReconciler, domContainer, true);
|
|
262
|
+
ContainerMap.set(domContainer, root);
|
|
263
|
+
return root;
|
|
267
264
|
}
|
|
268
265
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
createPortal
|
|
266
|
+
const unstable_batchedUpdates = TaroReconciler.batchedUpdates;
|
|
267
|
+
function unmountComponentAtNode(dom) {
|
|
268
|
+
ensure(dom && [1, 8, 9, 11].includes(dom.nodeType), 'unmountComponentAtNode(...): Target container is not a DOM element.');
|
|
269
|
+
const root = ContainerMap.get(dom);
|
|
270
|
+
if (!root)
|
|
271
|
+
return false;
|
|
272
|
+
unstable_batchedUpdates(() => {
|
|
273
|
+
root.unmount(() => {
|
|
274
|
+
ContainerMap.delete(dom);
|
|
275
|
+
});
|
|
276
|
+
}, null);
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
function findDOMNode(comp) {
|
|
280
|
+
if (comp == null) {
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
const nodeType = comp.nodeType;
|
|
284
|
+
if (nodeType === 1 || nodeType === 3) {
|
|
285
|
+
return comp;
|
|
286
|
+
}
|
|
287
|
+
return TaroReconciler.findHostInstance(comp);
|
|
288
|
+
}
|
|
289
|
+
const portalType = isFunction(Symbol) && Symbol.for
|
|
290
|
+
? Symbol.for('react.portal')
|
|
291
|
+
: 0xeaca;
|
|
292
|
+
function createPortal(children, containerInfo, key) {
|
|
293
|
+
return {
|
|
294
|
+
$$typeof: portalType,
|
|
295
|
+
key: key == null ? null : String(key),
|
|
296
|
+
children,
|
|
297
|
+
containerInfo,
|
|
298
|
+
implementation: null
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
var index = {
|
|
302
|
+
render,
|
|
303
|
+
createRoot,
|
|
304
|
+
unstable_batchedUpdates,
|
|
305
|
+
unmountComponentAtNode,
|
|
306
|
+
findDOMNode,
|
|
307
|
+
createPortal
|
|
312
308
|
};
|
|
313
309
|
|
|
314
310
|
export { createPortal, createRoot, index as default, findDOMNode, render, unmountComponentAtNode, unstable_batchedUpdates };
|