@tarojs/react 4.0.0-beta.9 → 4.0.0-beta.91
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.d.ts +45 -0
- package/dist/index.js +161 -46
- package/dist/index.js.map +1 -1
- package/dist/react.esm.d.ts +45 -0
- package/dist/react.esm.js +160 -48
- package/dist/react.esm.js.map +1 -1
- package/package.json +6 -5
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import Reconciler from "react-reconciler";
|
|
2
|
+
import { OpaqueRoot } from "react-reconciler";
|
|
3
|
+
import { TaroElement, TaroText } from "@tarojs/runtime";
|
|
4
|
+
import { ReactNode } from "react";
|
|
5
|
+
declare const internalInstanceKey: string;
|
|
6
|
+
declare const TaroReconciler: Reconciler.Reconciler<TaroElement, TaroElement, TaroText, TaroElement, TaroElement>;
|
|
7
|
+
type Renderer = typeof TaroReconciler;
|
|
8
|
+
type CreateRootOptions = {
|
|
9
|
+
unstable_strictMode?: boolean;
|
|
10
|
+
unstable_concurrentUpdatesByDefault?: boolean;
|
|
11
|
+
unstable_transitionCallbacks?: any;
|
|
12
|
+
identifierPrefix?: string;
|
|
13
|
+
onRecoverableError?: (error: any) => void;
|
|
14
|
+
};
|
|
15
|
+
type Callback = () => void | null | undefined;
|
|
16
|
+
declare class Root {
|
|
17
|
+
private renderer;
|
|
18
|
+
internalRoot: OpaqueRoot;
|
|
19
|
+
constructor(renderer: Renderer, domContainer: TaroElement, options?: CreateRootOptions);
|
|
20
|
+
private initInternalRoot;
|
|
21
|
+
render(children: ReactNode, cb: Callback): TaroElement | import("react").Component<any, any, any> | null;
|
|
22
|
+
unmount(cb: Callback): void;
|
|
23
|
+
}
|
|
24
|
+
declare function render(element: ReactNode, domContainer: TaroElement, cb: Callback): TaroElement | import("react").Component<any, any, any> | null;
|
|
25
|
+
declare function createRoot(domContainer: TaroElement, options?: CreateRootOptions): Root;
|
|
26
|
+
declare const unstable_batchedUpdates: (fn: any, a: any) => any;
|
|
27
|
+
declare function unmountComponentAtNode(dom: TaroElement): boolean;
|
|
28
|
+
declare function findDOMNode(comp?: TaroElement | ReactNode): string | number | boolean | TaroElement | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactFragment | null;
|
|
29
|
+
declare function createPortal(children: ReactNode, containerInfo: TaroElement, key?: string): {
|
|
30
|
+
$$typeof: number | symbol;
|
|
31
|
+
key: string | null;
|
|
32
|
+
children: ReactNode;
|
|
33
|
+
containerInfo: TaroElement;
|
|
34
|
+
implementation: null;
|
|
35
|
+
};
|
|
36
|
+
declare const _default: {
|
|
37
|
+
render: typeof render;
|
|
38
|
+
createRoot: typeof createRoot;
|
|
39
|
+
unstable_batchedUpdates: (fn: any, a: any) => any;
|
|
40
|
+
unmountComponentAtNode: typeof unmountComponentAtNode;
|
|
41
|
+
findDOMNode: typeof findDOMNode;
|
|
42
|
+
createPortal: typeof createPortal;
|
|
43
|
+
internalInstanceKey: string;
|
|
44
|
+
};
|
|
45
|
+
export { _default as default, createPortal, createRoot, findDOMNode, internalInstanceKey, render, unmountComponentAtNode, unstable_batchedUpdates };
|
package/dist/index.js
CHANGED
|
@@ -142,6 +142,10 @@ function getFiberCurrentPropsFromNode(node) {
|
|
|
142
142
|
}
|
|
143
143
|
function updateFiberProps(node, props) {
|
|
144
144
|
node[internalPropsKey] = props;
|
|
145
|
+
if (process.env.TARO_PLATFORM === 'harmony') {
|
|
146
|
+
// @ts-ignore
|
|
147
|
+
node.updateTextNode();
|
|
148
|
+
}
|
|
145
149
|
}
|
|
146
150
|
|
|
147
151
|
// 从 props 中,更新 input 组件的 value 值
|
|
@@ -183,10 +187,10 @@ function setNodeValue(node, oldValue, value, type) {
|
|
|
183
187
|
|
|
184
188
|
if (value != null) {
|
|
185
189
|
if (type === 'number') {
|
|
186
|
-
if ((value === 0 && node.value === '')
|
|
190
|
+
if ((value === 0 && node.value === '')
|
|
187
191
|
// We explicitly want to coerce to number here if possible.
|
|
188
192
|
// eslint-disable-next-line
|
|
189
|
-
oldValue != value) {
|
|
193
|
+
|| oldValue != value) {
|
|
190
194
|
node.value = toString(value);
|
|
191
195
|
}
|
|
192
196
|
}
|
|
@@ -297,17 +301,30 @@ function isEventName(s) {
|
|
|
297
301
|
return s[0] === 'o' && s[1] === 'n';
|
|
298
302
|
}
|
|
299
303
|
function isEqual(obj1, obj2) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
304
|
+
// 首先检查引用是否相同
|
|
305
|
+
if (obj1 === obj2) {
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
// 如果两者中有一个不是对象,或者为 null,直接返回 false
|
|
309
|
+
if (typeof obj1 !== 'object' || obj1 === null || typeof obj2 !== 'object' || obj2 === null) {
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
// 获取两个对象键的数组
|
|
313
|
+
var keys1 = Object.keys(obj1);
|
|
314
|
+
var keys2 = Object.keys(obj2);
|
|
315
|
+
// 如果键的数量不相同,对象显然不相等
|
|
316
|
+
if (keys1.length !== keys2.length) {
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
// 遍历对象的每个键,比较两个对象同一键的值
|
|
320
|
+
for (var i = 0; i < keys1.length; i++) {
|
|
321
|
+
var key = keys1[i];
|
|
322
|
+
if (obj1[key] !== obj2[key]) {
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
// 如果所有键的值都相等,返回 true
|
|
327
|
+
return true;
|
|
311
328
|
}
|
|
312
329
|
function updateProps(dom, oldProps, newProps) {
|
|
313
330
|
var updatePayload = getUpdatePayload(dom, oldProps, newProps);
|
|
@@ -316,11 +333,31 @@ function updateProps(dom, oldProps, newProps) {
|
|
|
316
333
|
}
|
|
317
334
|
}
|
|
318
335
|
function updatePropsByPayload(dom, oldProps, updatePayload) {
|
|
319
|
-
|
|
336
|
+
var handlers = [];
|
|
337
|
+
var loop = function ( i ) {
|
|
338
|
+
// key, value 成对出现
|
|
320
339
|
var key = updatePayload[i];
|
|
321
340
|
var newProp = updatePayload[i + 1];
|
|
322
341
|
var oldProp = oldProps[key];
|
|
323
|
-
|
|
342
|
+
if (isHarmony) {
|
|
343
|
+
// 鸿蒙样式前置插入,防止覆盖style
|
|
344
|
+
if (key === '__hmStyle') {
|
|
345
|
+
handlers.splice(0, 0, function () { return setHarmonyStyle(dom, newProp, oldProp); });
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
handlers.push(function () { return setProperty(dom, key, newProp, oldProp); });
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
setProperty(dom, key, newProp, oldProp);
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
for (var i = 0; i < updatePayload.length; i += 2) loop( i );
|
|
357
|
+
if (isHarmony) {
|
|
358
|
+
for (var i$1 = 0; i$1 < handlers.length; i$1++) {
|
|
359
|
+
handlers[i$1]();
|
|
360
|
+
}
|
|
324
361
|
}
|
|
325
362
|
}
|
|
326
363
|
function getUpdatePayload(dom, oldProps, newProps) {
|
|
@@ -334,6 +371,9 @@ function getUpdatePayload(dom, oldProps, newProps) {
|
|
|
334
371
|
var isFormElement = dom instanceof runtime.FormElement;
|
|
335
372
|
for (i in newProps) {
|
|
336
373
|
if (oldProps[i] !== newProps[i] || (isFormElement && i === 'value')) {
|
|
374
|
+
// 如果都是 style,且 style 里面的值相等,则无需记录到 payload 中
|
|
375
|
+
if (i === 'style' && shared.isObject(oldProps[i]) && shared.isObject(newProps[i]) && isEqual(oldProps[i], newProps[i]))
|
|
376
|
+
{ continue; }
|
|
337
377
|
(updatePayload = updatePayload || []).push(i, newProps[i]);
|
|
338
378
|
}
|
|
339
379
|
}
|
|
@@ -368,29 +408,85 @@ function setEvent(dom, name, value, oldValue) {
|
|
|
368
408
|
}
|
|
369
409
|
}
|
|
370
410
|
function setStyle(style, key, value) {
|
|
371
|
-
if (key[0] === '-') {
|
|
372
|
-
// 适配鸿蒙
|
|
373
|
-
if (isHarmony) {
|
|
374
|
-
style.setProperty(key, value);
|
|
375
|
-
}
|
|
376
|
-
else {
|
|
377
|
-
style.setProperty(key, value.toString());
|
|
378
|
-
}
|
|
411
|
+
if (key[0] === '-' && !isHarmony) {
|
|
379
412
|
// css variables need not further judgment
|
|
413
|
+
style.setProperty(key, value.toString());
|
|
380
414
|
return;
|
|
381
415
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
416
|
+
style[key] =
|
|
417
|
+
shared.isNumber(value) && IS_NON_DIMENSIONAL.test(key) === false
|
|
418
|
+
? (isHarmony ? value + 'px' : runtime.convertNumber2PX(value))
|
|
419
|
+
: value === null
|
|
420
|
+
? ''
|
|
421
|
+
: value;
|
|
422
|
+
}
|
|
423
|
+
// 鸿蒙样式特殊处理,需要在插入顺序中前置插入,防止覆盖了style
|
|
424
|
+
function setHarmonyStyle(dom, value, oldValue) {
|
|
425
|
+
// @ts-ignore
|
|
426
|
+
var style = dom._st.hmStyle; // __hmStyle是已经被处理过的鸿蒙样式,可以直接塞进hmStyle对象内
|
|
427
|
+
if (shared.isObject(oldValue)) {
|
|
428
|
+
for (var i in oldValue) {
|
|
429
|
+
if (!(value && i in value)) {
|
|
430
|
+
// 鸿蒙伪类特殊处理
|
|
431
|
+
if (isHarmony) {
|
|
432
|
+
if (i === '::after' || i === '::before') {
|
|
433
|
+
setPseudo(dom, i, null);
|
|
434
|
+
}
|
|
435
|
+
else if (['::first-child', '::last-child', '::empty'].includes(i) || ("" + i).indexOf('::nth-child') === 0) {
|
|
436
|
+
// @ts-ignore
|
|
437
|
+
dom.set_pseudo_class(i, null);
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
if (i === 'position' && oldValue[i] === 'fixed') {
|
|
441
|
+
// @ts-ignore
|
|
442
|
+
dom.setLayer(0);
|
|
443
|
+
}
|
|
444
|
+
else if (i === 'animationName') {
|
|
445
|
+
// @ts-ignore
|
|
446
|
+
dom.setAnimation(false);
|
|
447
|
+
}
|
|
448
|
+
style[i] = '';
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
style[i] = '';
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
385
456
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
457
|
+
if (shared.isObject(value)) {
|
|
458
|
+
for (var i$1 in value) {
|
|
459
|
+
if (!oldValue || !isEqual(value[i$1], oldValue[i$1])) {
|
|
460
|
+
// 鸿蒙伪类特殊处理
|
|
461
|
+
if (isHarmony) {
|
|
462
|
+
if (i$1 === '::after' || i$1 === '::before') {
|
|
463
|
+
setPseudo(dom, i$1, value[i$1]);
|
|
464
|
+
}
|
|
465
|
+
else if (['::first-child', '::last-child', '::empty'].includes(i$1) || i$1.startsWith('::nth-child')) {
|
|
466
|
+
// @ts-ignore
|
|
467
|
+
dom.set_pseudo_class(i$1, value[i$1]);
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
if (i$1 === 'position') {
|
|
471
|
+
if (value[i$1] === 'fixed' || (value[i$1] !== 'fixed' && (oldValue === null || oldValue === void 0 ? void 0 : oldValue[i$1]))) {
|
|
472
|
+
// @ts-ignore
|
|
473
|
+
dom.setLayer(value[i$1] === 'fixed' ? 1 : 0);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
else if (i$1 === 'animationName') {
|
|
477
|
+
// @ts-ignore
|
|
478
|
+
dom.setAnimation(true);
|
|
479
|
+
}
|
|
480
|
+
style[i$1] = value[i$1];
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
style[i$1] = value[i$1];
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
393
488
|
}
|
|
489
|
+
dom.setAttribute('__hmStyle', value);
|
|
394
490
|
}
|
|
395
491
|
function setProperty(dom, name, value, oldValue) {
|
|
396
492
|
var _a, _b;
|
|
@@ -408,25 +504,29 @@ function setProperty(dom, name, value, oldValue) {
|
|
|
408
504
|
style.cssText = '';
|
|
409
505
|
oldValue = null;
|
|
410
506
|
}
|
|
411
|
-
var needUpdateAfterMoved = false;
|
|
412
507
|
if (shared.isObject(oldValue)) {
|
|
413
508
|
for (var i in oldValue) {
|
|
414
509
|
if (!(value && i in value)) {
|
|
415
|
-
|
|
416
|
-
if (
|
|
417
|
-
|
|
510
|
+
// Harmony特殊处理
|
|
511
|
+
if (isHarmony && i === 'position' && oldValue[i] === 'fixed') {
|
|
512
|
+
// @ts-ignore
|
|
513
|
+
dom.setLayer(0);
|
|
418
514
|
}
|
|
515
|
+
setStyle(style, i, '');
|
|
419
516
|
}
|
|
420
517
|
}
|
|
421
|
-
if (needUpdateAfterMoved) {
|
|
422
|
-
updateDOMInstance(dom);
|
|
423
|
-
}
|
|
424
518
|
}
|
|
425
519
|
if (shared.isObject(value)) {
|
|
426
520
|
for (var i$1 in value) {
|
|
427
521
|
if (!oldValue || !isEqual(value[i$1], oldValue[i$1])) {
|
|
522
|
+
// Harmony特殊处理
|
|
523
|
+
if (isHarmony && i$1 === 'position') {
|
|
524
|
+
if (value[i$1] === 'fixed' || (value[i$1] !== 'fixed' && (oldValue === null || oldValue === void 0 ? void 0 : oldValue[i$1]))) {
|
|
525
|
+
// @ts-ignore
|
|
526
|
+
dom.setLayer(value[i$1] === 'fixed' ? 1 : 0);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
428
529
|
setStyle(style, i$1, value[i$1]);
|
|
429
|
-
updateDOMInstance(dom);
|
|
430
530
|
}
|
|
431
531
|
}
|
|
432
532
|
}
|
|
@@ -447,14 +547,23 @@ function setProperty(dom, name, value, oldValue) {
|
|
|
447
547
|
else if (!shared.isFunction(value)) {
|
|
448
548
|
if (value == null) {
|
|
449
549
|
dom.removeAttribute(name);
|
|
450
|
-
updateDOMInstance(dom, name);
|
|
451
550
|
}
|
|
452
551
|
else {
|
|
453
552
|
dom.setAttribute(name, value);
|
|
454
|
-
updateDOMInstance(dom, name);
|
|
455
553
|
}
|
|
456
554
|
}
|
|
457
555
|
}
|
|
556
|
+
// 设置鸿蒙伪类属性(特殊设置)
|
|
557
|
+
function setPseudo(dom, name, value) {
|
|
558
|
+
if (name === '::after') {
|
|
559
|
+
// @ts-ignore
|
|
560
|
+
dom.set_pseudo_after(value);
|
|
561
|
+
}
|
|
562
|
+
else if (name === '::before') {
|
|
563
|
+
// @ts-ignore
|
|
564
|
+
dom.set_pseudo_before(value);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
458
567
|
|
|
459
568
|
/* eslint-disable @typescript-eslint/indent */
|
|
460
569
|
var hostConfig = {
|
|
@@ -537,8 +646,7 @@ var hostConfig = {
|
|
|
537
646
|
// Microtasks
|
|
538
647
|
// (optional)
|
|
539
648
|
// -------------------
|
|
540
|
-
|
|
541
|
-
supportsMicrotasks: process.env.TARO_PLATFORM !== 'harmony',
|
|
649
|
+
supportsMicrotasks: true,
|
|
542
650
|
scheduleMicrotask: shared.isUndefined(Promise)
|
|
543
651
|
? setTimeout
|
|
544
652
|
: function (callback) { return Promise.resolve(null)
|
|
@@ -563,6 +671,11 @@ var hostConfig = {
|
|
|
563
671
|
},
|
|
564
672
|
commitMount: shared.noop,
|
|
565
673
|
commitUpdate: function commitUpdate(dom, updatePayload, _, oldProps, newProps) {
|
|
674
|
+
if (!updatePayload)
|
|
675
|
+
{ return; }
|
|
676
|
+
// payload 只包含 children 的时候,不应该再继续触发后续的属性比较和更新的逻辑了
|
|
677
|
+
if (updatePayload.length === 2 && updatePayload.includes('children'))
|
|
678
|
+
{ return; }
|
|
566
679
|
updatePropsByPayload(dom, oldProps, updatePayload);
|
|
567
680
|
updateFiberProps(dom, newProps);
|
|
568
681
|
},
|
|
@@ -841,13 +954,15 @@ var index = {
|
|
|
841
954
|
unstable_batchedUpdates: unstable_batchedUpdates,
|
|
842
955
|
unmountComponentAtNode: unmountComponentAtNode,
|
|
843
956
|
findDOMNode: findDOMNode,
|
|
844
|
-
createPortal: createPortal
|
|
957
|
+
createPortal: createPortal,
|
|
958
|
+
internalInstanceKey: internalInstanceKey
|
|
845
959
|
};
|
|
846
960
|
|
|
847
961
|
exports.createPortal = createPortal;
|
|
848
962
|
exports.createRoot = createRoot;
|
|
849
963
|
exports["default"] = index;
|
|
850
964
|
exports.findDOMNode = findDOMNode;
|
|
965
|
+
exports.internalInstanceKey = internalInstanceKey;
|
|
851
966
|
exports.render = render;
|
|
852
967
|
exports.unmountComponentAtNode = unmountComponentAtNode;
|
|
853
968
|
exports.unstable_batchedUpdates = unstable_batchedUpdates;
|