@tarojs/shared 3.5.0-beta.1 → 3.5.0-beta.4
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 +69 -17
- package/dist/index.js.map +1 -1
- package/dist/runtime-hooks.d.ts +2 -2
- package/dist/shared.esm.js +68 -17
- package/dist/shared.esm.js.map +1 -1
- package/dist/template.d.ts +3 -1
- package/dist/template.js +82 -23
- package/dist/template.js.map +1 -1
- package/dist/utils.d.ts +4 -2
- package/package.json +2 -2
package/dist/template.js
CHANGED
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const DEFAULT_EMPTY_ARRAY = '[]';
|
|
6
6
|
const NO_DEFAULT_VALUE = '';
|
|
7
|
-
const DEFAULT_TRUE = '
|
|
8
|
-
const DEFAULT_FALSE = '
|
|
7
|
+
const DEFAULT_TRUE = '!0';
|
|
8
|
+
const DEFAULT_FALSE = '!1';
|
|
9
9
|
const touchEvents = {
|
|
10
10
|
bindTouchStart: NO_DEFAULT_VALUE,
|
|
11
11
|
bindTouchMove: NO_DEFAULT_VALUE,
|
|
@@ -600,6 +600,45 @@ function capitalize(s) {
|
|
|
600
600
|
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
601
601
|
const hasOwn = (val, key) => hasOwnProperty.call(val, key);
|
|
602
602
|
(new Date()).getTime().toString();
|
|
603
|
+
function getComponentsAlias(origin) {
|
|
604
|
+
const mapping = {};
|
|
605
|
+
const viewAttrs = origin.View;
|
|
606
|
+
const extraList = {
|
|
607
|
+
'#text': {},
|
|
608
|
+
StaticView: viewAttrs,
|
|
609
|
+
StaticImage: origin.Image,
|
|
610
|
+
StaticText: origin.Text,
|
|
611
|
+
PureView: viewAttrs,
|
|
612
|
+
CatchView: viewAttrs
|
|
613
|
+
};
|
|
614
|
+
origin = Object.assign(Object.assign({}, origin), extraList);
|
|
615
|
+
Object.keys(origin)
|
|
616
|
+
.sort((a, b) => {
|
|
617
|
+
const reg = /^(Static|Pure|Catch)*(View|Image|Text)$/;
|
|
618
|
+
if (reg.test(a)) {
|
|
619
|
+
return -1;
|
|
620
|
+
}
|
|
621
|
+
else if (reg.test(b)) {
|
|
622
|
+
return 1;
|
|
623
|
+
}
|
|
624
|
+
else {
|
|
625
|
+
return a >= b ? 1 : -1;
|
|
626
|
+
}
|
|
627
|
+
})
|
|
628
|
+
.forEach((key, num) => {
|
|
629
|
+
const obj = {
|
|
630
|
+
_num: String(num)
|
|
631
|
+
};
|
|
632
|
+
Object.keys(origin[key])
|
|
633
|
+
.filter(attr => !(/^bind/.test(attr)) && !['focus', 'blur'].includes(attr))
|
|
634
|
+
.sort()
|
|
635
|
+
.forEach((attr, index) => {
|
|
636
|
+
obj[toCamelCase(attr)] = 'p' + index;
|
|
637
|
+
});
|
|
638
|
+
mapping[toDashed(key)] = obj;
|
|
639
|
+
});
|
|
640
|
+
return mapping;
|
|
641
|
+
}
|
|
603
642
|
function indent(str, size) {
|
|
604
643
|
return str.split('\n')
|
|
605
644
|
.map((line, index) => {
|
|
@@ -698,7 +737,7 @@ class BaseTemplate {
|
|
|
698
737
|
.map(k => `${k}="${k.startsWith('bind') || k.startsWith('on') || k.startsWith('catch') ? attrs[k] : `{${this.getAttrValue(attrs[k], k, nodeName)}}`}" `)
|
|
699
738
|
.join('');
|
|
700
739
|
}
|
|
701
|
-
replacePropName(name, value, _componentName) {
|
|
740
|
+
replacePropName(name, value, _componentName, _componentAlias) {
|
|
702
741
|
if (value === 'eh')
|
|
703
742
|
return name.toLowerCase();
|
|
704
743
|
return name;
|
|
@@ -710,6 +749,7 @@ class BaseTemplate {
|
|
|
710
749
|
let component = components[key];
|
|
711
750
|
const compName = toDashed(key);
|
|
712
751
|
const newComp = Object.create(null);
|
|
752
|
+
const componentAlias = this.componentsAlias[compName];
|
|
713
753
|
if (isFunction(this.modifyCompProps)) {
|
|
714
754
|
component = this.modifyCompProps(compName, component);
|
|
715
755
|
}
|
|
@@ -720,17 +760,23 @@ class BaseTemplate {
|
|
|
720
760
|
propValue = 'eh';
|
|
721
761
|
}
|
|
722
762
|
else if (propValue === '') {
|
|
723
|
-
|
|
763
|
+
const propInCamelCase = toCamelCase(prop);
|
|
764
|
+
const propAlias = componentAlias[propInCamelCase] || propInCamelCase;
|
|
765
|
+
propValue = `i.${propAlias}`;
|
|
724
766
|
}
|
|
725
767
|
else if (isBooleanStringLiteral(propValue) || isNumber(+propValue)) {
|
|
768
|
+
const propInCamelCase = toCamelCase(prop);
|
|
769
|
+
const propAlias = componentAlias[propInCamelCase] || propInCamelCase;
|
|
726
770
|
propValue = this.supportXS
|
|
727
|
-
? `xs.b(i.${
|
|
728
|
-
: `i.${
|
|
771
|
+
? `xs.b(i.${propAlias},${propValue})`
|
|
772
|
+
: `i.${propAlias}===undefined?${propValue}:i.${propAlias}`;
|
|
729
773
|
}
|
|
730
774
|
else {
|
|
731
|
-
|
|
775
|
+
const propInCamelCase = toCamelCase(prop);
|
|
776
|
+
const propAlias = componentAlias[propInCamelCase] || propInCamelCase;
|
|
777
|
+
propValue = `i.${propAlias}||${propValue || singleQuote('')}`;
|
|
732
778
|
}
|
|
733
|
-
prop = this.replacePropName(prop, propValue, compName);
|
|
779
|
+
prop = this.replacePropName(prop, propValue, compName, componentAlias);
|
|
734
780
|
newComp[prop] = propValue;
|
|
735
781
|
}
|
|
736
782
|
}
|
|
@@ -859,31 +905,34 @@ class BaseTemplate {
|
|
|
859
905
|
}
|
|
860
906
|
buildFocusComponentTemplte(comp, level) {
|
|
861
907
|
const children = this.getChildren(comp, level);
|
|
908
|
+
const nodeName = comp.nodeName;
|
|
909
|
+
const nodeAlias = comp.nodeAlias;
|
|
862
910
|
const attrs = Object.assign({}, comp.attributes);
|
|
863
911
|
const templateName = this.supportXS
|
|
864
912
|
? `xs.c(i, 'tmpl_${level}_')`
|
|
865
|
-
: `i.focus ? 'tmpl_${level}_${
|
|
913
|
+
: `i.focus ? 'tmpl_${level}_${nodeAlias}_focus' : 'tmpl_${level}_${nodeAlias}_blur'`;
|
|
866
914
|
delete attrs.focus;
|
|
867
915
|
let res = `
|
|
868
|
-
<template name="tmpl_${level}_${
|
|
916
|
+
<template name="tmpl_${level}_${nodeAlias}">
|
|
869
917
|
<template is="{{${templateName}}}" data="{{${this.dataKeymap('i:i')}${children ? ',cid:cid' : ''}}}" />
|
|
870
918
|
</template>
|
|
871
919
|
|
|
872
|
-
<template name="tmpl_${level}_${
|
|
873
|
-
<${
|
|
920
|
+
<template name="tmpl_${level}_${nodeAlias}_focus">
|
|
921
|
+
<${nodeName} ${this.buildAttribute(comp.attributes, nodeName)} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">${children}</${nodeName}>
|
|
874
922
|
</template>
|
|
875
923
|
|
|
876
|
-
<template name="tmpl_${level}_${
|
|
877
|
-
<${
|
|
924
|
+
<template name="tmpl_${level}_${nodeAlias}_blur">
|
|
925
|
+
<${nodeName} ${this.buildAttribute(attrs, nodeName)} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">${children}</${nodeName}>
|
|
878
926
|
</template>
|
|
879
927
|
`;
|
|
880
928
|
if (isFunction(this.modifyTemplateResult)) {
|
|
881
|
-
res = this.modifyTemplateResult(res,
|
|
929
|
+
res = this.modifyTemplateResult(res, nodeName, level, children);
|
|
882
930
|
}
|
|
883
931
|
return res;
|
|
884
932
|
}
|
|
885
933
|
buildStandardComponentTemplate(comp, level) {
|
|
886
934
|
const children = this.getChildren(comp, level);
|
|
935
|
+
const nodeAlias = comp.nodeAlias;
|
|
887
936
|
let nodeName = '';
|
|
888
937
|
switch (comp.nodeName) {
|
|
889
938
|
case 'slot':
|
|
@@ -904,7 +953,7 @@ class BaseTemplate {
|
|
|
904
953
|
break;
|
|
905
954
|
}
|
|
906
955
|
let res = `
|
|
907
|
-
<template name="tmpl_${level}_${
|
|
956
|
+
<template name="tmpl_${level}_${nodeAlias}">
|
|
908
957
|
<${nodeName} ${this.buildAttribute(comp.attributes, comp.nodeName)} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">${children}</${nodeName}>
|
|
909
958
|
</template>
|
|
910
959
|
`;
|
|
@@ -915,7 +964,7 @@ class BaseTemplate {
|
|
|
915
964
|
}
|
|
916
965
|
buildPlainTextTemplate(level) {
|
|
917
966
|
return `
|
|
918
|
-
<template name="tmpl_${level}_#text">
|
|
967
|
+
<template name="tmpl_${level}_${this.componentsAlias['#text']._num}">
|
|
919
968
|
<block>{{i.${"v" /* Text */}}}</block>
|
|
920
969
|
</template>
|
|
921
970
|
`;
|
|
@@ -1025,6 +1074,7 @@ class RecursiveTemplate extends BaseTemplate {
|
|
|
1025
1074
|
this.buildTemplate = (componentConfig) => {
|
|
1026
1075
|
let template = this.buildBaseTemplate();
|
|
1027
1076
|
if (!this.miniComponents) {
|
|
1077
|
+
this.componentsAlias = getComponentsAlias(this.internalComponents);
|
|
1028
1078
|
this.miniComponents = this.createMiniComponents(this.internalComponents);
|
|
1029
1079
|
}
|
|
1030
1080
|
const ZERO_FLOOR = 0;
|
|
@@ -1032,7 +1082,8 @@ class RecursiveTemplate extends BaseTemplate {
|
|
|
1032
1082
|
.filter(c => componentConfig.includes.size && !componentConfig.includeAll ? componentConfig.includes.has(c) : true);
|
|
1033
1083
|
template = components.reduce((current, nodeName) => {
|
|
1034
1084
|
const attributes = this.miniComponents[nodeName];
|
|
1035
|
-
|
|
1085
|
+
const nodeAlias = this.componentsAlias[nodeName]._num;
|
|
1086
|
+
return current + this.buildComponentTemplate({ nodeName, nodeAlias, attributes }, ZERO_FLOOR);
|
|
1036
1087
|
}, template);
|
|
1037
1088
|
template += this.buildPlainTextTemplate(ZERO_FLOOR);
|
|
1038
1089
|
template += this.buildThirdPartyTemplate(ZERO_FLOOR, componentConfig);
|
|
@@ -1049,6 +1100,7 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
1049
1100
|
this.buildTemplate = (componentConfig) => {
|
|
1050
1101
|
this.componentConfig = componentConfig;
|
|
1051
1102
|
if (!this.miniComponents) {
|
|
1103
|
+
this.componentsAlias = getComponentsAlias(this.internalComponents);
|
|
1052
1104
|
this.miniComponents = this.createMiniComponents(this.internalComponents);
|
|
1053
1105
|
}
|
|
1054
1106
|
const components = Object.keys(this.miniComponents)
|
|
@@ -1073,7 +1125,8 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
1073
1125
|
return this.buildContainerTemplate(level, restart);
|
|
1074
1126
|
let template = components.reduce((current, nodeName) => {
|
|
1075
1127
|
const attributes = this.miniComponents[nodeName];
|
|
1076
|
-
|
|
1128
|
+
const nodeAlias = this.componentsAlias[nodeName]._num;
|
|
1129
|
+
return current + this.buildComponentTemplate({ nodeName, nodeAlias, attributes }, level);
|
|
1077
1130
|
}, '');
|
|
1078
1131
|
template += this.buildPlainTextTemplate(level);
|
|
1079
1132
|
template += this.buildThirdPartyTemplate(level, this.componentConfig);
|
|
@@ -1098,7 +1151,8 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
1098
1151
|
}
|
|
1099
1152
|
}
|
|
1100
1153
|
const attributes = this.miniComponents[nodeName];
|
|
1101
|
-
|
|
1154
|
+
const nodeAlias = this.componentsAlias[nodeName]._num;
|
|
1155
|
+
return current + this.buildComponentTemplate({ nodeName, nodeAlias, attributes }, level);
|
|
1102
1156
|
}, '');
|
|
1103
1157
|
if (level === 0)
|
|
1104
1158
|
template += this.buildPlainTextTemplate(level);
|
|
@@ -1121,9 +1175,12 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
1121
1175
|
isLoopCompsSet.delete(comp);
|
|
1122
1176
|
}
|
|
1123
1177
|
});
|
|
1178
|
+
const componentsAlias = this.componentsAlias;
|
|
1179
|
+
const listA = Array.from(isLoopCompsSet).map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
|
|
1180
|
+
const listB = hasMaxComps.map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
|
|
1124
1181
|
return `function (l, n, s) {
|
|
1125
|
-
var a = ${JSON.stringify(
|
|
1126
|
-
var b = ${JSON.stringify(
|
|
1182
|
+
var a = ${JSON.stringify(listA)}
|
|
1183
|
+
var b = ${JSON.stringify(listB)}
|
|
1127
1184
|
if (a.indexOf(n) === -1) {
|
|
1128
1185
|
l = 0
|
|
1129
1186
|
}
|
|
@@ -1144,8 +1201,10 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
1144
1201
|
if (max > 1)
|
|
1145
1202
|
hasMaxComps.push(comp);
|
|
1146
1203
|
});
|
|
1204
|
+
const componentsAlias = this.componentsAlias;
|
|
1205
|
+
const listA = hasMaxComps.map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
|
|
1147
1206
|
return `f: function (l, n) {
|
|
1148
|
-
var b = ${JSON.stringify(
|
|
1207
|
+
var b = ${JSON.stringify(listA)}
|
|
1149
1208
|
if (b.indexOf(n) > -1) {
|
|
1150
1209
|
if (l) l += ','
|
|
1151
1210
|
l += n
|