@tarojs/shared 3.7.0-canary.0 → 3.8.0-canary.0
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 +1 -1
- package/dist/index.js.map +1 -1
- package/dist/shared.esm.js +1 -1
- package/dist/shared.esm.js.map +1 -1
- package/dist/template.d.ts +7 -4
- package/dist/template.js +72 -55
- package/dist/template.js.map +1 -1
- package/package.json +1 -1
package/dist/template.js
CHANGED
|
@@ -489,7 +489,7 @@ const defaultMiniLifecycle = {
|
|
|
489
489
|
'onReachBottom',
|
|
490
490
|
'onPageScroll',
|
|
491
491
|
'onResize',
|
|
492
|
-
'onTabItemTap',
|
|
492
|
+
'defer:onTabItemTap',
|
|
493
493
|
'onTitleClick',
|
|
494
494
|
'onOptionMenuClick',
|
|
495
495
|
'onPopMenuClick',
|
|
@@ -746,6 +746,7 @@ const weixinAdapter = {
|
|
|
746
746
|
};
|
|
747
747
|
class BaseTemplate {
|
|
748
748
|
constructor() {
|
|
749
|
+
this._baseLevel = 0;
|
|
749
750
|
this.exportExpr = 'module.exports =';
|
|
750
751
|
this.thirdPartyPatcher = {};
|
|
751
752
|
this.supportXS = false;
|
|
@@ -765,19 +766,23 @@ class BaseTemplate {
|
|
|
765
766
|
};
|
|
766
767
|
this.buildBaseComponentTemplate = (ext) => {
|
|
767
768
|
const data = !this.isSupportRecursive && this.supportXS
|
|
768
|
-
? this.dataKeymap('i:i,l:l')
|
|
769
|
-
: this.
|
|
769
|
+
? this.dataKeymap('i:i,c:1,l:l')
|
|
770
|
+
: this.isSupportRecursive
|
|
771
|
+
? this.dataKeymap('i:i')
|
|
772
|
+
: this.dataKeymap('i:i,c:1');
|
|
770
773
|
return `<import src="./base${ext}" />
|
|
771
|
-
<template is="tmpl_0_
|
|
774
|
+
<template is="{{'tmpl_0_' + i.nn}}" data="{{${data}}}" />`;
|
|
772
775
|
};
|
|
773
776
|
this.buildCustomComponentTemplate = (ext) => {
|
|
774
777
|
const Adapter = this.Adapter;
|
|
775
778
|
const data = !this.isSupportRecursive && this.supportXS
|
|
776
|
-
? `${this.dataKeymap('i:item,l:\'\'')}`
|
|
777
|
-
: this.
|
|
779
|
+
? `${this.dataKeymap('i:item,c:1,l:\'\'')}`
|
|
780
|
+
: this.isSupportRecursive
|
|
781
|
+
? this.dataKeymap('i:item')
|
|
782
|
+
: this.dataKeymap('i:item,c:1');
|
|
778
783
|
return `<import src="./base${ext}" />
|
|
779
784
|
<block ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="sid">
|
|
780
|
-
<template is="
|
|
785
|
+
<template is="{{'tmpl_0_' + item.nn}}" data="{{${data}}}" />
|
|
781
786
|
</block>`;
|
|
782
787
|
};
|
|
783
788
|
this.buildXScript = () => {
|
|
@@ -787,9 +792,6 @@ class BaseTemplate {
|
|
|
787
792
|
return a === undefined ? b : a
|
|
788
793
|
},
|
|
789
794
|
c: ${this.buildXSTepFocus("nn" /* Shortcuts.NodeName */)},
|
|
790
|
-
d: function (i, v) {
|
|
791
|
-
return i === undefined ? v : i
|
|
792
|
-
},
|
|
793
795
|
e: function (n) {
|
|
794
796
|
return 'tmpl_' + n + '_${"container" /* Shortcuts.Container */}'
|
|
795
797
|
},
|
|
@@ -797,6 +799,12 @@ class BaseTemplate {
|
|
|
797
799
|
}`;
|
|
798
800
|
};
|
|
799
801
|
}
|
|
802
|
+
set baseLevel(lv) {
|
|
803
|
+
this._baseLevel = lv;
|
|
804
|
+
}
|
|
805
|
+
get baseLevel() {
|
|
806
|
+
return this._baseLevel;
|
|
807
|
+
}
|
|
800
808
|
buildAttribute(attrs, nodeName) {
|
|
801
809
|
return Object.keys(attrs)
|
|
802
810
|
.map(k => `${k}="${k.startsWith('bind') || k.startsWith('on') || k.startsWith('catch') ? attrs[k] : `{${this.getAttrValue(attrs[k], k, nodeName)}}`}" `)
|
|
@@ -900,12 +908,19 @@ class BaseTemplate {
|
|
|
900
908
|
buildBaseTemplate() {
|
|
901
909
|
const Adapter = this.Adapter;
|
|
902
910
|
const data = !this.isSupportRecursive && this.supportXS
|
|
903
|
-
? `${this.dataKeymap('i:item,l:\'\'')}`
|
|
904
|
-
: this.
|
|
911
|
+
? `${this.dataKeymap('i:item,c:1,l:\'\'')}`
|
|
912
|
+
: this.isSupportRecursive
|
|
913
|
+
? this.dataKeymap('i:item')
|
|
914
|
+
: this.dataKeymap('i:item,c:1');
|
|
915
|
+
const xs = this.supportXS
|
|
916
|
+
? (this.isSupportRecursive
|
|
917
|
+
? `xs.a(0, item.${"nn" /* Shortcuts.NodeName */})`
|
|
918
|
+
: `xs.a(0, item.${"nn" /* Shortcuts.NodeName */}, '')`)
|
|
919
|
+
: "'tmpl_0_' + item.nn";
|
|
905
920
|
return `${this.buildXsTemplate()}
|
|
906
921
|
<template name="taro_tmpl">
|
|
907
922
|
<block ${Adapter.for}="{{root.cn}}" ${Adapter.key}="sid">
|
|
908
|
-
<template is="
|
|
923
|
+
<template is="{{${xs}}}" data="{{${data}}}" />
|
|
909
924
|
</block>
|
|
910
925
|
</template>
|
|
911
926
|
`;
|
|
@@ -953,15 +968,40 @@ class BaseTemplate {
|
|
|
953
968
|
? this.buildFocusComponentTemplate(comp, level)
|
|
954
969
|
: this.buildStandardComponentTemplate(comp, level);
|
|
955
970
|
}
|
|
971
|
+
getChildrenTemplate(level) {
|
|
972
|
+
const { isSupportRecursive, supportXS } = this;
|
|
973
|
+
const isLastRecursiveComp = !isSupportRecursive && level + 1 === this.baseLevel;
|
|
974
|
+
const isUseXs = !this.isSupportRecursive && this.supportXS;
|
|
975
|
+
if (isLastRecursiveComp) {
|
|
976
|
+
const data = isUseXs
|
|
977
|
+
? `${this.dataKeymap('i:item,c:c,l:l')}`
|
|
978
|
+
: this.isSupportRecursive
|
|
979
|
+
? this.dataKeymap('i:item')
|
|
980
|
+
: this.dataKeymap('i:item,c:c');
|
|
981
|
+
return supportXS
|
|
982
|
+
? `<template is="{{xs.e(${level})}}" data="{{${data}}}" />`
|
|
983
|
+
: `<template is="tmpl_${level}_${"container" /* Shortcuts.Container */}" data="{{${data}}}" />`;
|
|
984
|
+
}
|
|
985
|
+
else {
|
|
986
|
+
const data = isUseXs
|
|
987
|
+
? `${this.dataKeymap(`i:item,c:c+1,l:xs.f(l,item.${"nn" /* Shortcuts.NodeName */})`)}`
|
|
988
|
+
: this.isSupportRecursive
|
|
989
|
+
? `${this.dataKeymap('i:item')}`
|
|
990
|
+
: `${this.dataKeymap('i:item,c:c+1')}`;
|
|
991
|
+
const xs = !this.isSupportRecursive
|
|
992
|
+
? `xs.a(c, item.${"nn" /* Shortcuts.NodeName */}, l)`
|
|
993
|
+
: `xs.a(0, item.${"nn" /* Shortcuts.NodeName */})`;
|
|
994
|
+
return supportXS
|
|
995
|
+
? `<template is="{{${xs}}}" data="{{${data}}}" />`
|
|
996
|
+
: isSupportRecursive
|
|
997
|
+
? `<template is="{{'tmpl_0_' + item.nn}}" data="{{${data}}}" />`
|
|
998
|
+
: `<template is="{{'tmpl_' + c + '_' + item.nn}}" data="{{${data}}}" />`;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
956
1001
|
getChildren(comp, level) {
|
|
957
|
-
const { isSupportRecursive, Adapter
|
|
1002
|
+
const { isSupportRecursive, Adapter } = this;
|
|
958
1003
|
const nextLevel = isSupportRecursive ? 0 : level + 1;
|
|
959
|
-
|
|
960
|
-
? `${this.dataKeymap('i:item,l:l')}`
|
|
961
|
-
: this.dataKeymap('i:item');
|
|
962
|
-
let child = supportXS
|
|
963
|
-
? `<template is="{{xs.e(${isSupportRecursive ? 0 : 'cid+1'})}}" data="{{${data}}}" />`
|
|
964
|
-
: `<template is="tmpl_${nextLevel}_${"container" /* Shortcuts.Container */}" data="{{${data}}}" />`;
|
|
1004
|
+
let child = this.getChildrenTemplate(nextLevel);
|
|
965
1005
|
if (isFunction(this.modifyLoopBody)) {
|
|
966
1006
|
child = this.modifyLoopBody(child, comp.nodeName);
|
|
967
1007
|
}
|
|
@@ -988,7 +1028,7 @@ class BaseTemplate {
|
|
|
988
1028
|
delete attrs.focus;
|
|
989
1029
|
let res = `
|
|
990
1030
|
<template name="tmpl_${level}_${nodeAlias}">
|
|
991
|
-
<template is="{{${templateName}}}" data="{{${this.dataKeymap('i:i')
|
|
1031
|
+
<template is="{{${templateName}}}" data="{{${this.isSupportRecursive ? this.dataKeymap('i:i') : this.dataKeymap('i:i,c:c')}}}" />
|
|
992
1032
|
</template>
|
|
993
1033
|
|
|
994
1034
|
<template name="tmpl_${level}_${nodeAlias}_focus">
|
|
@@ -1050,9 +1090,6 @@ class BaseTemplate {
|
|
|
1050
1090
|
const { Adapter, isSupportRecursive, supportXS, nestElements } = this;
|
|
1051
1091
|
const nextLevel = isSupportRecursive ? 0 : level + 1;
|
|
1052
1092
|
let template = '';
|
|
1053
|
-
const data = !isSupportRecursive && supportXS
|
|
1054
|
-
? `${this.dataKeymap('i:item,l:l')}`
|
|
1055
|
-
: this.dataKeymap('i:item');
|
|
1056
1093
|
componentConfig.thirdPartyComponents.forEach((attrs, compName) => {
|
|
1057
1094
|
if (compName === 'custom-wrapper') {
|
|
1058
1095
|
template += `
|
|
@@ -1065,9 +1102,7 @@ class BaseTemplate {
|
|
|
1065
1102
|
else {
|
|
1066
1103
|
if (!isSupportRecursive && supportXS && nestElements.has(compName) && level + 1 > nestElements.get(compName))
|
|
1067
1104
|
return;
|
|
1068
|
-
let child =
|
|
1069
|
-
? `<template is="{{xs.e(${isSupportRecursive ? 0 : 'cid+1'})}}" data="{{${data}}}" />`
|
|
1070
|
-
: `<template is="tmpl_${nextLevel}_${"container" /* Shortcuts.Container */}" data="{{${data}}}" />`;
|
|
1105
|
+
let child = this.getChildrenTemplate(nextLevel);
|
|
1071
1106
|
if (isFunction(this.modifyThirdPartyLoopBody)) {
|
|
1072
1107
|
child = this.modifyThirdPartyLoopBody(child, compName);
|
|
1073
1108
|
}
|
|
@@ -1084,27 +1119,14 @@ class BaseTemplate {
|
|
|
1084
1119
|
});
|
|
1085
1120
|
return template;
|
|
1086
1121
|
}
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
if
|
|
1090
|
-
|
|
1091
|
-
<template is="tmpl_0_#text" data="{{i:i}}" />
|
|
1122
|
+
// 最后一层的 comp 需要引用 container 进行重新的模版循环,其他情况不需要 container
|
|
1123
|
+
buildContainerTemplate(level) {
|
|
1124
|
+
const tmpl = `<block ${this.Adapter.if}="{{i.nn === '${this.componentsAlias['#text']._num}'}}">
|
|
1125
|
+
<template is="tmpl_0_${this.componentsAlias['#text']._num}" data="{{${this.dataKeymap('i:i')}}}" />
|
|
1092
1126
|
</block>
|
|
1093
1127
|
<block ${this.Adapter.else}>
|
|
1094
1128
|
${!this.isSupportRecursive && this.supportXS ? '<comp i="{{i}}" l="{{l}}" />' : '<comp i="{{i}}" />'}
|
|
1095
1129
|
</block>`;
|
|
1096
|
-
}
|
|
1097
|
-
else {
|
|
1098
|
-
const xs = !this.isSupportRecursive
|
|
1099
|
-
? `xs.a(${level}, i.${"nn" /* Shortcuts.NodeName */}, l)`
|
|
1100
|
-
: `xs.a(${level}, i.${"nn" /* Shortcuts.NodeName */})`;
|
|
1101
|
-
const data = !this.isSupportRecursive
|
|
1102
|
-
? `${this.dataKeymap(`i:i,cid:${level},l:xs.f(l,i.${"nn" /* Shortcuts.NodeName */})`)}`
|
|
1103
|
-
: `${this.dataKeymap('i:i')}`;
|
|
1104
|
-
tmpl = this.supportXS
|
|
1105
|
-
? `<template is="{{${xs}}}" data="{{${data}}}" />`
|
|
1106
|
-
: `<template is="{{'tmpl_${level}_' + i.${"nn" /* Shortcuts.NodeName */}}}" data="{{${this.dataKeymap('i:i')}}}" />`;
|
|
1107
|
-
}
|
|
1108
1130
|
return `
|
|
1109
1131
|
<template name="tmpl_${level}_${"container" /* Shortcuts.Container */}">
|
|
1110
1132
|
${tmpl}
|
|
@@ -1164,7 +1186,6 @@ class RecursiveTemplate extends BaseTemplate {
|
|
|
1164
1186
|
}, template);
|
|
1165
1187
|
template += this.buildPlainTextTemplate(ZERO_FLOOR);
|
|
1166
1188
|
template += this.buildThirdPartyTemplate(ZERO_FLOOR, componentConfig);
|
|
1167
|
-
template += this.buildContainerTemplate(ZERO_FLOOR);
|
|
1168
1189
|
return template;
|
|
1169
1190
|
};
|
|
1170
1191
|
}
|
|
@@ -1191,15 +1212,9 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
1191
1212
|
return template;
|
|
1192
1213
|
};
|
|
1193
1214
|
}
|
|
1194
|
-
set baseLevel(lv) {
|
|
1195
|
-
this._baseLevel = lv;
|
|
1196
|
-
}
|
|
1197
|
-
get baseLevel() {
|
|
1198
|
-
return this._baseLevel;
|
|
1199
|
-
}
|
|
1200
1215
|
buildFloor(level, components, restart = false) {
|
|
1201
1216
|
if (restart)
|
|
1202
|
-
return this.buildContainerTemplate(level
|
|
1217
|
+
return this.buildContainerTemplate(level);
|
|
1203
1218
|
let template = components.reduce((current, nodeName) => {
|
|
1204
1219
|
const attributes = this.miniComponents[nodeName];
|
|
1205
1220
|
const nodeAlias = this.componentsAlias[nodeName]._num;
|
|
@@ -1207,12 +1222,11 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
1207
1222
|
}, '');
|
|
1208
1223
|
template += this.buildPlainTextTemplate(level);
|
|
1209
1224
|
template += this.buildThirdPartyTemplate(level, this.componentConfig);
|
|
1210
|
-
template += this.buildContainerTemplate(level, restart);
|
|
1211
1225
|
return template;
|
|
1212
1226
|
}
|
|
1213
1227
|
buildOptimizeFloor(level, components, restart = false) {
|
|
1214
1228
|
if (restart)
|
|
1215
|
-
return this.buildContainerTemplate(level
|
|
1229
|
+
return this.buildContainerTemplate(level);
|
|
1216
1230
|
let template = components.reduce((current, nodeName) => {
|
|
1217
1231
|
if (level !== 0) {
|
|
1218
1232
|
if (!this.nestElements.has(nodeName)) {
|
|
@@ -1234,7 +1248,6 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
1234
1248
|
if (level === 0)
|
|
1235
1249
|
template += this.buildPlainTextTemplate(level);
|
|
1236
1250
|
template += this.buildThirdPartyTemplate(level, this.componentConfig);
|
|
1237
|
-
template += this.buildContainerTemplate(level);
|
|
1238
1251
|
return template;
|
|
1239
1252
|
}
|
|
1240
1253
|
buildXSTmplName() {
|
|
@@ -1255,6 +1268,7 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
1255
1268
|
const componentsAlias = this.componentsAlias;
|
|
1256
1269
|
const listA = Array.from(isLoopCompsSet).map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
|
|
1257
1270
|
const listB = hasMaxComps.map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
|
|
1271
|
+
const containerLevel = this.baseLevel - 1;
|
|
1258
1272
|
return `function (l, n, s) {
|
|
1259
1273
|
var a = ${JSON.stringify(listA)}
|
|
1260
1274
|
var b = ${JSON.stringify(listB)}
|
|
@@ -1269,6 +1283,9 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
1269
1283
|
}
|
|
1270
1284
|
l = depth
|
|
1271
1285
|
}
|
|
1286
|
+
if (l === ${containerLevel}) {
|
|
1287
|
+
return 'tmpl_${containerLevel}_${"container" /* Shortcuts.Container */}'
|
|
1288
|
+
}
|
|
1272
1289
|
return 'tmpl_' + l + '_' + n
|
|
1273
1290
|
}`;
|
|
1274
1291
|
}
|