@tarojs/react 3.7.0-alpha.2 → 3.7.0-alpha.20
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 +407 -10
- package/dist/index.js.map +1 -1
- package/dist/react.esm.js +406 -13
- package/dist/react.esm.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -11,10 +11,290 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
11
11
|
|
|
12
12
|
var Reconciler__default = /*#__PURE__*/_interopDefaultLegacy(Reconciler);
|
|
13
13
|
|
|
14
|
+
var supportedInputTypes = {
|
|
15
|
+
color: true,
|
|
16
|
+
date: true,
|
|
17
|
+
datetime: true,
|
|
18
|
+
'datetime-local': true,
|
|
19
|
+
email: true,
|
|
20
|
+
month: true,
|
|
21
|
+
number: true,
|
|
22
|
+
password: true,
|
|
23
|
+
range: true,
|
|
24
|
+
search: true,
|
|
25
|
+
tel: true,
|
|
26
|
+
text: true,
|
|
27
|
+
time: true,
|
|
28
|
+
url: true,
|
|
29
|
+
week: true,
|
|
30
|
+
};
|
|
31
|
+
var SyncLane = 1;
|
|
32
|
+
var InputContinuousLane = 4;
|
|
33
|
+
var DefaultLane = 16;
|
|
34
|
+
var DiscreteEventPriority = SyncLane;
|
|
35
|
+
var ContinuousEventPriority = InputContinuousLane;
|
|
36
|
+
var DefaultEventPriority = DefaultLane;
|
|
37
|
+
function getEventPriority(domEventName) {
|
|
38
|
+
switch (domEventName) {
|
|
39
|
+
case 'cancel':
|
|
40
|
+
case 'click':
|
|
41
|
+
case 'close':
|
|
42
|
+
case 'contextmenu':
|
|
43
|
+
case 'copy':
|
|
44
|
+
case 'cut':
|
|
45
|
+
case 'dragend':
|
|
46
|
+
case 'dragstart':
|
|
47
|
+
case 'drop':
|
|
48
|
+
case 'input':
|
|
49
|
+
case 'paste':
|
|
50
|
+
case 'pause':
|
|
51
|
+
case 'play':
|
|
52
|
+
case 'pointercancel':
|
|
53
|
+
case 'pointerdown':
|
|
54
|
+
case 'pointerup':
|
|
55
|
+
case 'reset':
|
|
56
|
+
case 'resize':
|
|
57
|
+
case 'submit':
|
|
58
|
+
case 'touchcancel':
|
|
59
|
+
case 'touchend':
|
|
60
|
+
case 'touchstart':
|
|
61
|
+
case 'change':
|
|
62
|
+
case 'blur':
|
|
63
|
+
case 'focus':
|
|
64
|
+
case 'select':
|
|
65
|
+
case 'selectstart':
|
|
66
|
+
return DiscreteEventPriority;
|
|
67
|
+
case 'drag':
|
|
68
|
+
case 'dragenter':
|
|
69
|
+
case 'dragexit':
|
|
70
|
+
case 'dragleave':
|
|
71
|
+
case 'dragover':
|
|
72
|
+
case 'pointermove':
|
|
73
|
+
case 'pointerout':
|
|
74
|
+
case 'pointerover':
|
|
75
|
+
case 'scroll':
|
|
76
|
+
case 'toggle':
|
|
77
|
+
case 'touchmove':
|
|
78
|
+
case 'pointerenter':
|
|
79
|
+
case 'pointerleave':
|
|
80
|
+
return ContinuousEventPriority;
|
|
81
|
+
default:
|
|
82
|
+
return DefaultEventPriority;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
var randomKey = Math.random()
|
|
86
|
+
.toString(36)
|
|
87
|
+
.slice(2);
|
|
88
|
+
var internalPropsKey = '__reactProps$' + randomKey;
|
|
89
|
+
var internalInstanceKey = '__reactFiber$' + randomKey;
|
|
90
|
+
var internalContainerInstanceKey = '__reactContainer$' + randomKey;
|
|
91
|
+
// const internalEventHandlersKey = '__reactEvents$' + randomKey
|
|
92
|
+
// const internalEventHandlerListenersKey = '__reactListeners$' + randomKey
|
|
93
|
+
// const internalEventHandlesSetKey = '__reactHandles$' + randomKey
|
|
94
|
+
|
|
95
|
+
var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
|
|
96
|
+
var HostComponent = 5;
|
|
97
|
+
var HostText = 6;
|
|
98
|
+
var SuspenseComponent = 13;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 给 TaroElement 绑定 react fiber、react props 等属性
|
|
102
|
+
* 提供 fiber -> element、element -> fiber、element -> props 的方法
|
|
103
|
+
*/
|
|
104
|
+
function precacheFiberNode(hostInst, node) {
|
|
105
|
+
node[internalInstanceKey] = hostInst;
|
|
106
|
+
}
|
|
107
|
+
function markContainerAsRoot(hostRoot, node) {
|
|
108
|
+
node[internalContainerInstanceKey] = hostRoot;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Given a DOM node, return the ReactDOMComponent or ReactDOMTextComponent
|
|
112
|
+
* instance, or null if the node was not rendered by this React.
|
|
113
|
+
*/
|
|
114
|
+
function getInstanceFromNode(node) {
|
|
115
|
+
var inst = node[internalInstanceKey] || node[internalContainerInstanceKey];
|
|
116
|
+
if (inst) {
|
|
117
|
+
if (inst.tag === HostComponent ||
|
|
118
|
+
inst.tag === HostText ||
|
|
119
|
+
inst.tag === SuspenseComponent ||
|
|
120
|
+
inst.tag === HostRoot) {
|
|
121
|
+
return inst;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
|
|
131
|
+
* DOM node.
|
|
132
|
+
*/
|
|
133
|
+
function getNodeFromInstance(inst) {
|
|
134
|
+
if (inst.tag === HostComponent || inst.tag === HostText) {
|
|
135
|
+
// In Fiber this, is just the state node right now. We assume it will be
|
|
136
|
+
// a host component or host text.
|
|
137
|
+
return inst.stateNode;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function getFiberCurrentPropsFromNode(node) {
|
|
141
|
+
return node[internalPropsKey] || null;
|
|
142
|
+
}
|
|
143
|
+
function updateFiberProps(node, props) {
|
|
144
|
+
node[internalPropsKey] = props;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// 从 props 中,更新 input 组件的 value 值
|
|
148
|
+
function updateInputWrapper(element, oldValue, props) {
|
|
149
|
+
var node = element;
|
|
150
|
+
var checked = props.checked;
|
|
151
|
+
if (checked != null) {
|
|
152
|
+
console.warn('updateCheck 未实现', node);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
updateWrapper(element, oldValue, props);
|
|
156
|
+
updateNamedCousins(element, props);
|
|
157
|
+
}
|
|
158
|
+
// react 中原本处理 type=radio 的逻辑,这里留个空,暂时不处理
|
|
159
|
+
function updateNamedCousins(rootNode, props) {
|
|
160
|
+
var name = props.name;
|
|
161
|
+
if (props.type === 'radio' && name != null) {
|
|
162
|
+
console.warn('radio updateNamedCousins 未实现', rootNode, props);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function getToStringValue(value) {
|
|
166
|
+
var isEmptyType = typeof value === 'function' || typeof value === 'symbol';
|
|
167
|
+
return isEmptyType ? '' : value;
|
|
168
|
+
}
|
|
169
|
+
function toString(value) {
|
|
170
|
+
return '' + value;
|
|
171
|
+
}
|
|
172
|
+
function updateWrapper(element, oldValue, props) {
|
|
173
|
+
var node = element;
|
|
174
|
+
var value = getToStringValue(props.value);
|
|
175
|
+
var type = props.type;
|
|
176
|
+
setNodeValue(node, oldValue, value, type);
|
|
177
|
+
}
|
|
178
|
+
// oldValue 为 event.detail.value,value 为 fiber.props.value
|
|
179
|
+
// 如果 oldValue 和 value 不相等,代表受控组件需要更新
|
|
180
|
+
// 更新的原则为,fiber.props.value 永远为用户所需要的值,因此 node.value = toString(value)
|
|
181
|
+
function setNodeValue(node, oldValue, value, type) {
|
|
182
|
+
if ( type === void 0 ) type = 'string';
|
|
183
|
+
|
|
184
|
+
if (value != null) {
|
|
185
|
+
if (type === 'number') {
|
|
186
|
+
if ((value === 0 && node.value === '') ||
|
|
187
|
+
// We explicitly want to coerce to number here if possible.
|
|
188
|
+
// eslint-disable-next-line
|
|
189
|
+
oldValue != value) {
|
|
190
|
+
node.value = toString(value);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else if (oldValue !== toString(value)) {
|
|
194
|
+
node.value = toString(value);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else if (type === 'submit' || type === 'reset') {
|
|
198
|
+
// Submit/reset inputs need the attribute removed completely to avoid
|
|
199
|
+
// blank-text buttons.
|
|
200
|
+
node.removeAttribute('value');
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// 判断当前 TaroElement 是否为 supportedInputTypes input 或 textarea
|
|
204
|
+
function isTextInputElement(elem) {
|
|
205
|
+
var nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase();
|
|
206
|
+
if (nodeName === 'input') {
|
|
207
|
+
var type = elem.type;
|
|
208
|
+
return !type || !!supportedInputTypes[type];
|
|
209
|
+
}
|
|
210
|
+
if (nodeName === 'textarea') {
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
var ReactDOMTextareaRestoreControlledState = updateWrapper;
|
|
216
|
+
var ReactDOMInputRestoreControlledState = updateInputWrapper;
|
|
217
|
+
|
|
218
|
+
function isCheckable(elem) {
|
|
219
|
+
var type = elem.type;
|
|
220
|
+
var nodeName = elem.nodeName;
|
|
221
|
+
return (nodeName &&
|
|
222
|
+
nodeName.toLowerCase() === 'input' &&
|
|
223
|
+
(type === 'checkbox' || type === 'radio'));
|
|
224
|
+
}
|
|
225
|
+
function getTracker(node) {
|
|
226
|
+
return node._valueTracker;
|
|
227
|
+
}
|
|
228
|
+
function detachTracker(node) {
|
|
229
|
+
node._valueTracker = null;
|
|
230
|
+
}
|
|
231
|
+
// 之所以单独创建一个 tacker,是为了统一监听不同 type 的 input 值
|
|
232
|
+
// 比如 type=checkbox 或者 type=radio,就需要监听 checked,而不是 value
|
|
233
|
+
// 虽然目前还未实现 checkbox 和 radio 的 finishEventHandle,但后续不好说,所以先统一和 react 一样的写法
|
|
234
|
+
// 需要特别注意的是,tracker 初始化时的值为 node 的初始值,但后续会变更为事件的 detail.value 值
|
|
235
|
+
function trackValueOnNode(node) {
|
|
236
|
+
var valueField = isCheckable(node) ? 'checked' : 'value';
|
|
237
|
+
var descriptor = Object.getOwnPropertyDescriptor(node.constructor.prototype, valueField);
|
|
238
|
+
var currentValue = '' + node[valueField];
|
|
239
|
+
if (node.hasOwnProperty(valueField) ||
|
|
240
|
+
typeof descriptor === 'undefined' ||
|
|
241
|
+
typeof descriptor.get !== 'function' ||
|
|
242
|
+
typeof descriptor.set !== 'function') {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
var get = descriptor.get;
|
|
246
|
+
var set = descriptor.set;
|
|
247
|
+
Object.defineProperty(node, valueField, {
|
|
248
|
+
configurable: true,
|
|
249
|
+
enumerable: descriptor.enumerable,
|
|
250
|
+
get: function () {
|
|
251
|
+
return get.call(this);
|
|
252
|
+
},
|
|
253
|
+
set: function (value) {
|
|
254
|
+
currentValue = '' + value;
|
|
255
|
+
set.call(this, value);
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
var tracker = {
|
|
259
|
+
getValue: function getValue() {
|
|
260
|
+
return currentValue;
|
|
261
|
+
},
|
|
262
|
+
setValue: function setValue(value) {
|
|
263
|
+
currentValue = '' + value;
|
|
264
|
+
},
|
|
265
|
+
stopTracking: function stopTracking() {
|
|
266
|
+
detachTracker(node);
|
|
267
|
+
delete node[valueField];
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
return tracker;
|
|
271
|
+
}
|
|
272
|
+
function track(node) {
|
|
273
|
+
if (getTracker(node)) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
node._valueTracker = trackValueOnNode(node);
|
|
277
|
+
}
|
|
278
|
+
function updateValueIfChanged(node, nextValue) {
|
|
279
|
+
if (!node) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
var tracker = getTracker(node);
|
|
283
|
+
if (!tracker) {
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
var lastValue = tracker.getValue();
|
|
287
|
+
if (nextValue !== lastValue) {
|
|
288
|
+
tracker.setValue(nextValue);
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
|
|
14
294
|
function isEventName(s) {
|
|
15
295
|
return s[0] === 'o' && s[1] === 'n';
|
|
16
296
|
}
|
|
17
|
-
var IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;
|
|
297
|
+
var IS_NON_DIMENSIONAL = /aspect|acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;
|
|
18
298
|
function updateProps(dom, oldProps, newProps) {
|
|
19
299
|
var updatePayload = getUpdatePayload(dom, oldProps, newProps);
|
|
20
300
|
if (updatePayload) {
|
|
@@ -160,14 +440,20 @@ var hostConfig = {
|
|
|
160
440
|
return null;
|
|
161
441
|
},
|
|
162
442
|
resetAfterCommit: shared.noop,
|
|
163
|
-
createInstance: function createInstance(type) {
|
|
164
|
-
|
|
443
|
+
createInstance: function createInstance(type, props, _rootContainerInstance, _hostContext, internalInstanceHandle) {
|
|
444
|
+
var element = runtime.document.createElement(type);
|
|
445
|
+
precacheFiberNode(internalInstanceHandle, element);
|
|
446
|
+
updateFiberProps(element, props);
|
|
447
|
+
return element;
|
|
165
448
|
},
|
|
166
449
|
appendInitialChild: function appendInitialChild(parent, child) {
|
|
167
450
|
parent.appendChild(child);
|
|
168
451
|
},
|
|
169
|
-
finalizeInitialChildren: function finalizeInitialChildren(dom,
|
|
452
|
+
finalizeInitialChildren: function finalizeInitialChildren(dom, type, props) {
|
|
170
453
|
updateProps(dom, {}, props); // 提前执行更新属性操作,Taro 在 Page 初始化后会立即从 dom 读取必要信息
|
|
454
|
+
if (type === 'input' || type === 'textarea') {
|
|
455
|
+
track(dom);
|
|
456
|
+
}
|
|
171
457
|
return false;
|
|
172
458
|
},
|
|
173
459
|
prepareUpdate: function prepareUpdate(instance, _, oldProps, newProps) {
|
|
@@ -176,8 +462,10 @@ var hostConfig = {
|
|
|
176
462
|
shouldSetTextContent: function shouldSetTextContent() {
|
|
177
463
|
return false;
|
|
178
464
|
},
|
|
179
|
-
createTextInstance: function createTextInstance(text) {
|
|
180
|
-
|
|
465
|
+
createTextInstance: function createTextInstance(text, _rootContainerInstance, _hostContext, internalInstanceHandle) {
|
|
466
|
+
var textNode = runtime.document.createTextNode(text);
|
|
467
|
+
precacheFiberNode(internalInstanceHandle, textNode);
|
|
468
|
+
return textNode;
|
|
181
469
|
},
|
|
182
470
|
scheduleTimeout: setTimeout,
|
|
183
471
|
cancelTimeout: clearTimeout,
|
|
@@ -225,8 +513,9 @@ var hostConfig = {
|
|
|
225
513
|
textInst.nodeValue = newText;
|
|
226
514
|
},
|
|
227
515
|
commitMount: shared.noop,
|
|
228
|
-
commitUpdate: function commitUpdate(dom, updatePayload, _, oldProps) {
|
|
516
|
+
commitUpdate: function commitUpdate(dom, updatePayload, _, oldProps, newProps) {
|
|
229
517
|
updatePropsByPayload(dom, oldProps, updatePayload);
|
|
518
|
+
updateFiberProps(dom, newProps);
|
|
230
519
|
},
|
|
231
520
|
insertBefore: function insertBefore(parent, child, refChild) {
|
|
232
521
|
parent.insertBefore(child, refChild);
|
|
@@ -262,14 +551,14 @@ var hostConfig = {
|
|
|
262
551
|
if (element.childNodes.length > 0) {
|
|
263
552
|
element.textContent = '';
|
|
264
553
|
}
|
|
265
|
-
}
|
|
554
|
+
}
|
|
266
555
|
};
|
|
267
556
|
var TaroReconciler = Reconciler__default["default"](hostConfig);
|
|
268
557
|
if (process.env.NODE_ENV !== 'production') {
|
|
269
558
|
var foundDevTools = TaroReconciler.injectIntoDevTools({
|
|
270
559
|
bundleType: 1,
|
|
271
560
|
version: '18.0.0',
|
|
272
|
-
rendererPackageName: 'taro-react'
|
|
561
|
+
rendererPackageName: 'taro-react'
|
|
273
562
|
});
|
|
274
563
|
if (!foundDevTools) {
|
|
275
564
|
// eslint-disable-next-line no-console
|
|
@@ -279,6 +568,80 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
279
568
|
}
|
|
280
569
|
}
|
|
281
570
|
|
|
571
|
+
var restoreQueue = null;
|
|
572
|
+
// 对比 TaroElement tracker 下的 value 和事件下的 value,判断 element 的值是否存在更改
|
|
573
|
+
function getTargetInstForInputOrChangeEvent(e, node) {
|
|
574
|
+
var _a, _b;
|
|
575
|
+
var targetInst = getInstanceFromNode(node);
|
|
576
|
+
var domEventName = e.type;
|
|
577
|
+
if (!targetInst || !isTextInputElement(node))
|
|
578
|
+
{ return; }
|
|
579
|
+
if (domEventName === 'input' || domEventName === 'change') {
|
|
580
|
+
var nextValue = toString((_b = (_a = e.mpEvent) === null || _a === void 0 ? void 0 : _a.detail) === null || _b === void 0 ? void 0 : _b.value);
|
|
581
|
+
return getInstIfValueChanged(targetInst, nextValue);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
function getInstIfValueChanged(targetInst, nextValue) {
|
|
585
|
+
var targetNode = getNodeFromInstance(targetInst);
|
|
586
|
+
if (!targetNode)
|
|
587
|
+
{ return false; }
|
|
588
|
+
if (updateValueIfChanged(targetNode, nextValue)) {
|
|
589
|
+
return targetInst;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
// 把 target 塞入更新队列中
|
|
593
|
+
function enqueueStateRestore(target) {
|
|
594
|
+
if (restoreQueue) {
|
|
595
|
+
restoreQueue.push(target);
|
|
596
|
+
}
|
|
597
|
+
else {
|
|
598
|
+
restoreQueue = [target];
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
// 判断是否需要恢复 target(input、textarea) 的状态
|
|
602
|
+
function needsStateRestore() {
|
|
603
|
+
return restoreQueue !== null;
|
|
604
|
+
}
|
|
605
|
+
function finishEventHandler() {
|
|
606
|
+
var controlledComponentsHavePendingUpdates = needsStateRestore();
|
|
607
|
+
if (controlledComponentsHavePendingUpdates) {
|
|
608
|
+
TaroReconciler.flushSync();
|
|
609
|
+
restoreStateIfNeeded();
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
// 遍历 restoreQueue、restoreTarget,恢复其状态
|
|
613
|
+
function restoreStateIfNeeded() {
|
|
614
|
+
if (!restoreQueue) {
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
var queuedTargets = restoreQueue;
|
|
618
|
+
restoreQueue = null;
|
|
619
|
+
for (var i = 0; i < queuedTargets.length; i++) {
|
|
620
|
+
restoreStateOfTarget(queuedTargets[i]);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
function restoreImpl(domElement, tag, oldValue, props) {
|
|
624
|
+
switch (tag) {
|
|
625
|
+
case 'input':
|
|
626
|
+
ReactDOMInputRestoreControlledState(domElement, oldValue, props);
|
|
627
|
+
break;
|
|
628
|
+
case 'textarea':
|
|
629
|
+
ReactDOMTextareaRestoreControlledState(domElement, oldValue, props);
|
|
630
|
+
break;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
function restoreStateOfTarget(item) {
|
|
634
|
+
var internalInstance = getInstanceFromNode(item.target);
|
|
635
|
+
if (!internalInstance)
|
|
636
|
+
{ return; }
|
|
637
|
+
var stateNode = internalInstance.stateNode;
|
|
638
|
+
var type = internalInstance.type;
|
|
639
|
+
if (stateNode) {
|
|
640
|
+
var props = getFiberCurrentPropsFromNode(stateNode);
|
|
641
|
+
restoreImpl(stateNode, type, item.value, props);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
282
645
|
var ContainerMap = new WeakMap();
|
|
283
646
|
var Root = function Root(renderer, domContainer, options) {
|
|
284
647
|
this.renderer = renderer;
|
|
@@ -343,6 +706,7 @@ function render(element, domContainer, cb) {
|
|
|
343
706
|
function createRoot(domContainer, options) {
|
|
344
707
|
if ( options === void 0 ) options = {};
|
|
345
708
|
|
|
709
|
+
var _a;
|
|
346
710
|
var oldRoot = ContainerMap.get(domContainer);
|
|
347
711
|
if (oldRoot != null) {
|
|
348
712
|
return oldRoot;
|
|
@@ -350,10 +714,43 @@ function createRoot(domContainer, options) {
|
|
|
350
714
|
// options should be an object
|
|
351
715
|
var root = new Root(TaroReconciler, domContainer, options);
|
|
352
716
|
ContainerMap.set(domContainer, root);
|
|
717
|
+
markContainerAsRoot((_a = root === null || root === void 0 ? void 0 : root.internalRoot) === null || _a === void 0 ? void 0 : _a.current, domContainer);
|
|
718
|
+
runtime.hooks.tap('dispatchTaroEvent', function (e, node) {
|
|
719
|
+
var eventPriority = getEventPriority(e.type);
|
|
720
|
+
TaroReconciler.runWithPriority(eventPriority, function () {
|
|
721
|
+
node.dispatchEvent(e);
|
|
722
|
+
});
|
|
723
|
+
});
|
|
724
|
+
// 对比 event.detail.value 和 node.tracker.value,判断 value 值是否有变动,存在变动则塞入队列中
|
|
725
|
+
runtime.hooks.tap('modifyTaroEvent', function (e, node) {
|
|
726
|
+
var _a, _b;
|
|
727
|
+
var inst = getTargetInstForInputOrChangeEvent(e, node);
|
|
728
|
+
if (!inst)
|
|
729
|
+
{ return; }
|
|
730
|
+
// 这里塞入的是 event.detail.value,也就是事件的值,在受控组件中,你可以理解为需要被变更的值
|
|
731
|
+
// 后续会在 finishEventHandler 中,使用最新的 fiber.props.value 来与其比较
|
|
732
|
+
// 如果不一致,则表示需要更新,会执行 node.value = fiber.props.value 的更新操作
|
|
733
|
+
var nextValue = (_b = (_a = e.mpEvent) === null || _a === void 0 ? void 0 : _a.detail) === null || _b === void 0 ? void 0 : _b.value;
|
|
734
|
+
enqueueStateRestore({ target: node, value: nextValue });
|
|
735
|
+
});
|
|
353
736
|
return root;
|
|
354
737
|
}
|
|
355
738
|
|
|
356
|
-
var
|
|
739
|
+
var isInsideEventHandler = false;
|
|
740
|
+
// 重新包裹 batchedUpdates,使其可以在触发事件后执行 finishEventHandler
|
|
741
|
+
var unstable_batchedUpdates = function (fn, a) {
|
|
742
|
+
if (isInsideEventHandler) {
|
|
743
|
+
return fn(a);
|
|
744
|
+
}
|
|
745
|
+
isInsideEventHandler = true;
|
|
746
|
+
try {
|
|
747
|
+
return TaroReconciler.batchedUpdates(fn, a);
|
|
748
|
+
}
|
|
749
|
+
finally {
|
|
750
|
+
isInsideEventHandler = false;
|
|
751
|
+
finishEventHandler();
|
|
752
|
+
}
|
|
753
|
+
};
|
|
357
754
|
function unmountComponentAtNode(dom) {
|
|
358
755
|
shared.ensure(dom && [1, 8, 9, 11].includes(dom.nodeType), 'unmountComponentAtNode(...): Target container is not a DOM element.');
|
|
359
756
|
var root = ContainerMap.get(dom);
|