@tarojs/shared 3.8.0-canary.0 → 4.0.0-alpha.2
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/LICENSE +14 -0
- package/dist/components.d.ts +21 -0
- package/dist/components.js +342 -0
- package/dist/components.js.map +1 -0
- package/dist/constants.d.ts +25 -0
- package/dist/constants.js +28 -0
- package/dist/constants.js.map +1 -0
- package/dist/event-emitter.d.ts +13 -0
- package/dist/event-emitter.js +97 -0
- package/dist/event-emitter.js.map +1 -0
- package/dist/index.cjs.d.ts +307 -0
- package/dist/index.cjs.js +1298 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +8 -291
- package/dist/index.js +8 -1279
- package/dist/index.js.map +1 -1
- package/dist/is.d.ts +11 -0
- package/dist/is.js +29 -0
- package/dist/is.js.map +1 -0
- package/dist/native-apis.d.ts +34 -0
- package/dist/native-apis.js +362 -0
- package/dist/native-apis.js.map +1 -0
- package/dist/runtime-hooks.d.ts +262 -0
- package/dist/runtime-hooks.js +179 -0
- package/dist/runtime-hooks.js.map +1 -0
- package/dist/shared.esm.d.ts +23 -7
- package/dist/shared.esm.js +28 -8
- package/dist/shared.esm.js.map +1 -1
- package/dist/shortcuts.d.ts +11 -0
- package/dist/shortcuts.js +16 -0
- package/dist/shortcuts.js.map +1 -0
- package/dist/template.d.ts +7 -3
- package/dist/template.js +51 -22
- package/dist/template.js.map +1 -1
- package/dist/utils.d.ts +57 -0
- package/dist/utils.js +220 -0
- package/dist/utils.js.map +1 -0
- package/package.json +11 -5
package/dist/template.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
const DEFAULT_EMPTY_ARRAY = '[]';
|
|
6
4
|
const NO_DEFAULT_VALUE = '';
|
|
7
5
|
const DEFAULT_TRUE = '!0';
|
|
@@ -48,7 +46,7 @@ const Text = {
|
|
|
48
46
|
space: NO_DEFAULT_VALUE,
|
|
49
47
|
decode: DEFAULT_FALSE
|
|
50
48
|
};
|
|
51
|
-
const Button = Object.assign({ size: singleQuote('default'), type: NO_DEFAULT_VALUE, plain: DEFAULT_FALSE, disabled: NO_DEFAULT_VALUE, loading: DEFAULT_FALSE, 'form-type': NO_DEFAULT_VALUE, 'open-type': NO_DEFAULT_VALUE, 'hover-class': singleQuote('button-hover'), 'hover-stop-propagation': DEFAULT_FALSE, 'hover-start-time': '20', 'hover-stay-time': '70', name: NO_DEFAULT_VALUE }, touchEvents);
|
|
49
|
+
const Button = Object.assign({ size: singleQuote('default'), type: NO_DEFAULT_VALUE, plain: DEFAULT_FALSE, disabled: NO_DEFAULT_VALUE, loading: DEFAULT_FALSE, 'form-type': NO_DEFAULT_VALUE, 'open-type': NO_DEFAULT_VALUE, 'hover-class': singleQuote('button-hover'), 'hover-stop-propagation': DEFAULT_FALSE, 'hover-start-time': '20', 'hover-stay-time': '70', name: NO_DEFAULT_VALUE, bindagreeprivacyauthorization: NO_DEFAULT_VALUE }, touchEvents);
|
|
52
50
|
const Checkbox = {
|
|
53
51
|
value: NO_DEFAULT_VALUE,
|
|
54
52
|
disabled: NO_DEFAULT_VALUE,
|
|
@@ -345,6 +343,20 @@ function isBooleanStringLiteral(o) {
|
|
|
345
343
|
return o === 'true' || o === 'false';
|
|
346
344
|
}
|
|
347
345
|
|
|
346
|
+
// 字符串简写
|
|
347
|
+
exports.Shortcuts = void 0;
|
|
348
|
+
(function (Shortcuts) {
|
|
349
|
+
Shortcuts["Container"] = "container";
|
|
350
|
+
Shortcuts["Childnodes"] = "cn";
|
|
351
|
+
Shortcuts["Text"] = "v";
|
|
352
|
+
Shortcuts["NodeType"] = "nt";
|
|
353
|
+
Shortcuts["NodeName"] = "nn";
|
|
354
|
+
// Attrtibutes
|
|
355
|
+
Shortcuts["Style"] = "st";
|
|
356
|
+
Shortcuts["Class"] = "cl";
|
|
357
|
+
Shortcuts["Src"] = "src";
|
|
358
|
+
})(exports.Shortcuts || (exports.Shortcuts = {}));
|
|
359
|
+
|
|
348
360
|
var PLATFORM_TYPE;
|
|
349
361
|
(function (PLATFORM_TYPE) {
|
|
350
362
|
PLATFORM_TYPE["MINI"] = "mini";
|
|
@@ -368,7 +380,7 @@ var PLATFORM_TYPE;
|
|
|
368
380
|
},
|
|
369
381
|
quickapp: {
|
|
370
382
|
type: PLATFORM_TYPE.QUICK
|
|
371
|
-
}
|
|
383
|
+
},
|
|
372
384
|
});
|
|
373
385
|
|
|
374
386
|
class Events {
|
|
@@ -576,6 +588,7 @@ new TaroHooks({
|
|
|
576
588
|
return this.call('getMiniLifecycle', defaultMiniLifecycle);
|
|
577
589
|
}),
|
|
578
590
|
getLifecycle: TaroHook(HOOK_TYPE.SINGLE, (instance, lifecycle) => instance[lifecycle]),
|
|
591
|
+
modifyRecursiveComponentConfig: TaroHook(HOOK_TYPE.SINGLE, (defaultConfig) => defaultConfig),
|
|
579
592
|
getPathIndex: TaroHook(HOOK_TYPE.SINGLE, indexOfNode => `[${indexOfNode}]`),
|
|
580
593
|
getEventCenter: TaroHook(HOOK_TYPE.SINGLE, Events => new Events()),
|
|
581
594
|
isBubbleEvents: TaroHook(HOOK_TYPE.SINGLE, eventName => {
|
|
@@ -607,6 +620,7 @@ new TaroHooks({
|
|
|
607
620
|
createPullDownComponent: TaroHook(HOOK_TYPE.SINGLE),
|
|
608
621
|
getDOMNode: TaroHook(HOOK_TYPE.SINGLE),
|
|
609
622
|
modifyHydrateData: TaroHook(HOOK_TYPE.SINGLE),
|
|
623
|
+
transferHydrateData: TaroHook(HOOK_TYPE.SINGLE),
|
|
610
624
|
modifySetAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
|
|
611
625
|
modifyRmAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
|
|
612
626
|
onAddEvent: TaroHook(HOOK_TYPE.SINGLE),
|
|
@@ -629,9 +643,13 @@ new TaroHooks({
|
|
|
629
643
|
node.dispatchEvent(e);
|
|
630
644
|
}),
|
|
631
645
|
dispatchTaroEventFinish: TaroHook(HOOK_TYPE.MULTI),
|
|
646
|
+
modifyTaroEventReturn: TaroHook(HOOK_TYPE.SINGLE, () => undefined),
|
|
632
647
|
modifyDispatchEvent: TaroHook(HOOK_TYPE.MULTI),
|
|
633
648
|
initNativeApi: TaroHook(HOOK_TYPE.MULTI),
|
|
634
|
-
patchElement: TaroHook(HOOK_TYPE.MULTI)
|
|
649
|
+
patchElement: TaroHook(HOOK_TYPE.MULTI),
|
|
650
|
+
modifyAddEventListener: TaroHook(HOOK_TYPE.SINGLE),
|
|
651
|
+
modifyRemoveEventListener: TaroHook(HOOK_TYPE.SINGLE),
|
|
652
|
+
getMemoryLevel: TaroHook(HOOK_TYPE.SINGLE),
|
|
635
653
|
});
|
|
636
654
|
|
|
637
655
|
function toDashed(s) {
|
|
@@ -750,6 +768,7 @@ class BaseTemplate {
|
|
|
750
768
|
this.exportExpr = 'module.exports =';
|
|
751
769
|
this.thirdPartyPatcher = {};
|
|
752
770
|
this.supportXS = false;
|
|
771
|
+
this.isXMLSupportRecursiveReference = true;
|
|
753
772
|
this.Adapter = weixinAdapter;
|
|
754
773
|
/** 组件列表 */
|
|
755
774
|
this.internalComponents = internalComponents;
|
|
@@ -759,28 +778,32 @@ class BaseTemplate {
|
|
|
759
778
|
this.voidElements = voidElements;
|
|
760
779
|
/** 可以递归调用自身的组件 */
|
|
761
780
|
this.nestElements = nestElements;
|
|
762
|
-
this.buildPageTemplate = (baseTempPath) => {
|
|
781
|
+
this.buildPageTemplate = (baseTempPath, _page) => {
|
|
763
782
|
const template = `<import src="${baseTempPath}"/>
|
|
764
783
|
<template is="taro_tmpl" data="{{${this.dataKeymap('root:root')}}}" />`;
|
|
765
784
|
return template;
|
|
766
785
|
};
|
|
767
786
|
this.buildBaseComponentTemplate = (ext) => {
|
|
768
787
|
const data = !this.isSupportRecursive && this.supportXS
|
|
769
|
-
? this.dataKeymap(
|
|
788
|
+
? this.dataKeymap(`i:i,c:1,l:xs.f('',i.${"nn" /* Shortcuts.NodeName */})`)
|
|
770
789
|
: this.isSupportRecursive
|
|
771
790
|
? this.dataKeymap('i:i')
|
|
772
791
|
: this.dataKeymap('i:i,c:1');
|
|
792
|
+
// 此处需要重新引入 xs 函数,否则会出现 ws.f() 在 comp.wxml 和 custom-wrapper.wxml 中永远返回 undefined 的问题 #14599
|
|
773
793
|
return `<import src="./base${ext}" />
|
|
794
|
+
${this.buildXsTemplate()}
|
|
774
795
|
<template is="{{'tmpl_0_' + i.nn}}" data="{{${data}}}" />`;
|
|
775
796
|
};
|
|
776
797
|
this.buildCustomComponentTemplate = (ext) => {
|
|
777
798
|
const Adapter = this.Adapter;
|
|
778
799
|
const data = !this.isSupportRecursive && this.supportXS
|
|
779
|
-
? `${this.dataKeymap(
|
|
800
|
+
? `${this.dataKeymap(`i:item,c:1,l:xs.f('',item.${"nn" /* Shortcuts.NodeName */})`)}`
|
|
780
801
|
: this.isSupportRecursive
|
|
781
802
|
? this.dataKeymap('i:item')
|
|
782
803
|
: this.dataKeymap('i:item,c:1');
|
|
804
|
+
// 此处需要重新引入 xs 函数,否则会出现 ws.f() 在 comp.wxml 和 custom-wrapper.wxml 中永远返回 undefined 的问题 #14599
|
|
783
805
|
return `<import src="./base${ext}" />
|
|
806
|
+
${this.buildXsTemplate()}
|
|
784
807
|
<block ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="sid">
|
|
785
808
|
<template is="{{'tmpl_0_' + item.nn}}" data="{{${data}}}" />
|
|
786
809
|
</block>`;
|
|
@@ -908,7 +931,7 @@ class BaseTemplate {
|
|
|
908
931
|
buildBaseTemplate() {
|
|
909
932
|
const Adapter = this.Adapter;
|
|
910
933
|
const data = !this.isSupportRecursive && this.supportXS
|
|
911
|
-
? `${this.dataKeymap(
|
|
934
|
+
? `${this.dataKeymap(`i:item,c:1,l:xs.f('',item.${"nn" /* Shortcuts.NodeName */})`)}`
|
|
912
935
|
: this.isSupportRecursive
|
|
913
936
|
? this.dataKeymap('i:item')
|
|
914
937
|
: this.dataKeymap('i:item,c:1');
|
|
@@ -933,10 +956,10 @@ class BaseTemplate {
|
|
|
933
956
|
if (value.indexOf('-') > -1) {
|
|
934
957
|
value = `:${value}`;
|
|
935
958
|
}
|
|
936
|
-
return str + `bind${value}="eh"
|
|
959
|
+
return str + ` bind${value}="eh"`;
|
|
937
960
|
}
|
|
938
961
|
else if (attr.startsWith('bind')) {
|
|
939
|
-
return str +
|
|
962
|
+
return str + ` ${attr}="eh"`;
|
|
940
963
|
}
|
|
941
964
|
else if (attr.startsWith('on')) {
|
|
942
965
|
// react, vue3
|
|
@@ -945,22 +968,22 @@ class BaseTemplate {
|
|
|
945
968
|
// 兼容如 vant 某些组件的 bind:a-b 这类属性
|
|
946
969
|
value = `:${value}`;
|
|
947
970
|
}
|
|
948
|
-
return str + `bind${value}="eh"
|
|
971
|
+
return str + ` bind${value}="eh"`;
|
|
949
972
|
}
|
|
950
973
|
else if (attr === 'class') {
|
|
951
|
-
return str + `class="{{i.${"cl" /* Shortcuts.Class */}}}"
|
|
974
|
+
return str + ` class="{{i.${"cl" /* Shortcuts.Class */}}}"`;
|
|
952
975
|
}
|
|
953
976
|
else if (attr === 'style') {
|
|
954
|
-
return str + `style="{{i.${"st" /* Shortcuts.Style */}}}"
|
|
977
|
+
return str + ` style="{{i.${"st" /* Shortcuts.Style */}}}"`;
|
|
955
978
|
}
|
|
956
979
|
const patchValue = patcher[attr];
|
|
957
980
|
if (isBooleanStringLiteral(patchValue) || isNumber(patchValue) || isString(patchValue)) {
|
|
958
981
|
const propValue = this.supportXS
|
|
959
982
|
? `xs.b(i.${toCamelCase(attr)},${patchValue})`
|
|
960
983
|
: `i.${toCamelCase(attr)}===undefined?${patchValue}:i.${toCamelCase(attr)}`;
|
|
961
|
-
return str +
|
|
984
|
+
return str + ` ${attr}="{{${propValue}}}"`;
|
|
962
985
|
}
|
|
963
|
-
return str +
|
|
986
|
+
return str + ` ${attr}="{{i.${toCamelCase(attr)}}}"`;
|
|
964
987
|
}, '');
|
|
965
988
|
}
|
|
966
989
|
buildComponentTemplate(comp, level) {
|
|
@@ -984,6 +1007,8 @@ class BaseTemplate {
|
|
|
984
1007
|
}
|
|
985
1008
|
else {
|
|
986
1009
|
const data = isUseXs
|
|
1010
|
+
// TODO: 此处直接 c+1,不是最优解,变量 c 的作用是监测组件嵌套的层级是否大于 baselevel
|
|
1011
|
+
// 但目前的监测方法用于所有组件嵌套的总和,应该分开组件计算,单个组件嵌套层级大于 baselevel 时,再进入 comp 组件中进行新的嵌套
|
|
987
1012
|
? `${this.dataKeymap(`i:item,c:c+1,l:xs.f(l,item.${"nn" /* Shortcuts.NodeName */})`)}`
|
|
988
1013
|
: this.isSupportRecursive
|
|
989
1014
|
? `${this.dataKeymap('i:item')}`
|
|
@@ -1106,13 +1131,16 @@ class BaseTemplate {
|
|
|
1106
1131
|
if (isFunction(this.modifyThirdPartyLoopBody)) {
|
|
1107
1132
|
child = this.modifyThirdPartyLoopBody(child, compName);
|
|
1108
1133
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1134
|
+
const children = this.voidElements.has(compName)
|
|
1135
|
+
? ''
|
|
1136
|
+
: `
|
|
1112
1137
|
<block ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="sid">
|
|
1113
1138
|
${child}
|
|
1114
1139
|
</block>
|
|
1115
|
-
|
|
1140
|
+
`;
|
|
1141
|
+
template += `
|
|
1142
|
+
<template name="tmpl_${level}_${compName}">
|
|
1143
|
+
<${compName} ${this.buildThirdPartyAttr(attrs, this.thirdPartyPatcher[compName] || {})} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">${children}</${compName}>
|
|
1116
1144
|
</template>
|
|
1117
1145
|
`;
|
|
1118
1146
|
}
|
|
@@ -1142,7 +1170,7 @@ class BaseTemplate {
|
|
|
1142
1170
|
getAttrValue(value, _key, _nodeName) {
|
|
1143
1171
|
return `{${value}}`;
|
|
1144
1172
|
}
|
|
1145
|
-
buildXsTemplate() {
|
|
1173
|
+
buildXsTemplate(_filePath) {
|
|
1146
1174
|
return '';
|
|
1147
1175
|
}
|
|
1148
1176
|
mergeComponents(ctx, patch) {
|
|
@@ -1269,6 +1297,7 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
1269
1297
|
const listA = Array.from(isLoopCompsSet).map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
|
|
1270
1298
|
const listB = hasMaxComps.map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
|
|
1271
1299
|
const containerLevel = this.baseLevel - 1;
|
|
1300
|
+
// l >= containerLevel 是为了避免 baselevel 倒数两三层几层组件恰好不是 listA 中的组件,而最后一个组件又刚好是 listA 的组件,导致出现 l >= baselevel 却没有走入新的嵌套循环的问题 #14883
|
|
1272
1301
|
return `function (l, n, s) {
|
|
1273
1302
|
var a = ${JSON.stringify(listA)}
|
|
1274
1303
|
var b = ${JSON.stringify(listB)}
|
|
@@ -1283,7 +1312,7 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
1283
1312
|
}
|
|
1284
1313
|
l = depth
|
|
1285
1314
|
}
|
|
1286
|
-
if (l
|
|
1315
|
+
if (l >= ${containerLevel}) {
|
|
1287
1316
|
return 'tmpl_${containerLevel}_${"container" /* Shortcuts.Container */}'
|
|
1288
1317
|
}
|
|
1289
1318
|
return 'tmpl_' + l + '_' + n
|