@tarojs/shared 4.0.6 → 4.0.7-alpha.1

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/template.js CHANGED
@@ -310,6 +310,7 @@ const voidElements = new Set([
310
310
  const nestElements = new Map([
311
311
  ['view', -1],
312
312
  ['catch-view', -1],
313
+ ['click-view', -1],
313
314
  ['cover-view', -1],
314
315
  ['static-view', -1],
315
316
  ['pure-view', -1],
@@ -347,6 +348,7 @@ exports.Shortcuts = void 0;
347
348
  Shortcuts["NodeType"] = "nt";
348
349
  Shortcuts["NodeName"] = "nn";
349
350
  // Attrtibutes
351
+ Shortcuts["Sid"] = "sid";
350
352
  Shortcuts["Style"] = "st";
351
353
  Shortcuts["Class"] = "cl";
352
354
  Shortcuts["Src"] = "src";
@@ -682,12 +684,13 @@ function getComponentsAlias(origin) {
682
684
  StaticImage: origin.Image,
683
685
  StaticText: origin.Text,
684
686
  PureView: viewAttrs,
685
- CatchView: viewAttrs
687
+ CatchView: viewAttrs,
688
+ ClickView: viewAttrs,
686
689
  };
687
690
  origin = Object.assign(Object.assign({}, origin), extraList);
688
691
  Object.keys(origin)
689
692
  .sort((a, b) => {
690
- const reg = /^(Static|Pure|Catch)*(View|Image|Text)$/;
693
+ const reg = /^(Static|Pure|Catch|Click)*(View|Image|Text)$/;
691
694
  const isACommonly = reg.test(a);
692
695
  const isBCommonly = reg.test(b);
693
696
  if (isACommonly && isBCommonly) {
@@ -760,6 +763,7 @@ const weixinAdapter = {
760
763
  class BaseTemplate {
761
764
  constructor() {
762
765
  this._baseLevel = 0;
766
+ this._isUseXS = true;
763
767
  this.exportExpr = 'module.exports =';
764
768
  this.thirdPartyPatcher = {};
765
769
  this.supportXS = false;
@@ -779,29 +783,26 @@ class BaseTemplate {
779
783
  return template;
780
784
  };
781
785
  this.buildBaseComponentTemplate = (ext) => {
782
- const data = !this.isSupportRecursive && this.supportXS
786
+ const data = !this.isSupportRecursive && this.isUseXS
783
787
  ? this.dataKeymap(`i:i,c:1,l:xs.f('',i.${"nn" /* Shortcuts.NodeName */})`)
784
788
  : this.isSupportRecursive
785
789
  ? this.dataKeymap('i:i')
786
790
  : this.dataKeymap('i:i,c:1');
787
791
  // 此处需要重新引入 xs 函数,否则会出现 ws.f() 在 comp.wxml 和 custom-wrapper.wxml 中永远返回 undefined 的问题 #14599
788
792
  return `<import src="./base${ext}" />
789
- ${this.buildXsTemplate()}
790
- <template is="{{'tmpl_0_' + i.nn}}" data="{{${data}}}" />`;
793
+ ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + i.${"nn" /* Shortcuts.NodeName */}}}" data="{{${data}}}" />`;
791
794
  };
792
795
  this.buildCustomComponentTemplate = (ext) => {
793
796
  const Adapter = this.Adapter;
794
- const data = !this.isSupportRecursive && this.supportXS
797
+ const data = !this.isSupportRecursive && this.isUseXS
795
798
  ? `${this.dataKeymap(`i:item,c:1,l:xs.f('',item.${"nn" /* Shortcuts.NodeName */})`)}`
796
799
  : this.isSupportRecursive
797
800
  ? this.dataKeymap('i:item')
798
801
  : this.dataKeymap('i:item,c:1');
799
802
  // 此处需要重新引入 xs 函数,否则会出现 ws.f() 在 comp.wxml 和 custom-wrapper.wxml 中永远返回 undefined 的问题 #14599
800
803
  return `<import src="./base${ext}" />
801
- ${this.buildXsTemplate()}
802
- <block ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="sid">
803
- <template is="{{'tmpl_0_' + item.nn}}" data="{{${data}}}" />
804
- </block>`;
804
+ ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + item.${"nn" /* Shortcuts.NodeName */}}}" data="{{${data}}}" ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="${"sid" /* Shortcuts.Sid */}" />
805
+ `;
805
806
  };
806
807
  this.buildXScript = () => {
807
808
  return `${this.exportExpr} {
@@ -823,6 +824,12 @@ ${this.buildXsTemplate()}
823
824
  get baseLevel() {
824
825
  return this._baseLevel;
825
826
  }
827
+ set isUseXS(isUse) {
828
+ this._isUseXS = this.supportXS && isUse;
829
+ }
830
+ get isUseXS() {
831
+ return this._isUseXS;
832
+ }
826
833
  buildAttribute(attrs, nodeName) {
827
834
  return Object.keys(attrs)
828
835
  .map(k => `${k}="${k.startsWith('bind') || k.startsWith('on') || k.startsWith('catch') ? attrs[k] : `{${this.getAttrValue(attrs[k], k, nodeName)}}`}" `)
@@ -862,7 +869,7 @@ ${this.buildXsTemplate()}
862
869
  if (prop === 'cursor') {
863
870
  propValue = `i.${componentAlias.value}?i.${componentAlias.value}.length:-1`;
864
871
  }
865
- propValue = this.supportXS
872
+ propValue = this.isUseXS
866
873
  ? `xs.b(i.${propAlias},${propValue})`
867
874
  : `i.${propAlias}===undefined?${propValue}:i.${propAlias}`;
868
875
  }
@@ -906,6 +913,11 @@ ${this.buildXsTemplate()}
906
913
  style: comp.style,
907
914
  class: comp.class
908
915
  };
916
+ result['click-view'] = {
917
+ style: comp.style,
918
+ class: comp.class,
919
+ bindtap: 'eh'
920
+ };
909
921
  }
910
922
  }
911
923
  if (compName === 'slot' || compName === 'slot-view') {
@@ -925,21 +937,18 @@ ${this.buildXsTemplate()}
925
937
  }
926
938
  buildBaseTemplate() {
927
939
  const Adapter = this.Adapter;
928
- const data = !this.isSupportRecursive && this.supportXS
940
+ const data = !this.isSupportRecursive && this.isUseXS
929
941
  ? `${this.dataKeymap(`i:item,c:1,l:xs.f('',item.${"nn" /* Shortcuts.NodeName */})`)}`
930
942
  : this.isSupportRecursive
931
943
  ? this.dataKeymap('i:item')
932
944
  : this.dataKeymap('i:item,c:1');
933
- const xs = this.supportXS
945
+ const xs = this.isUseXS
934
946
  ? (this.isSupportRecursive
935
947
  ? `xs.a(0, item.${"nn" /* Shortcuts.NodeName */})`
936
948
  : `xs.a(0, item.${"nn" /* Shortcuts.NodeName */}, '')`)
937
- : "'tmpl_0_' + item.nn";
938
- return `${this.buildXsTemplate()}
939
- <template name="taro_tmpl">
940
- <block ${Adapter.for}="{{root.cn}}" ${Adapter.key}="sid">
941
- <template is="{{${xs}}}" data="{{${data}}}" />
942
- </block>
949
+ : `'tmpl_0_' + item.${"nn" /* Shortcuts.NodeName */}`;
950
+ return `${this.buildXsImportTemplate()}<template name="taro_tmpl">
951
+ <template is="{{${xs}}}" data="{{${data}}}" ${Adapter.for}="{{root.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="${"sid" /* Shortcuts.Sid */}" />
943
952
  </template>
944
953
  `;
945
954
  }
@@ -973,7 +982,7 @@ ${this.buildXsTemplate()}
973
982
  }
974
983
  const patchValue = patcher[attr];
975
984
  if (isBooleanStringLiteral(patchValue) || isNumber(patchValue) || isString(patchValue)) {
976
- const propValue = this.supportXS
985
+ const propValue = this.isUseXS
977
986
  ? `xs.b(i.${toCamelCase(attr)},${patchValue})`
978
987
  : `i.${toCamelCase(attr)}===undefined?${patchValue}:i.${toCamelCase(attr)}`;
979
988
  return str + ` ${attr}="{{${propValue}}}"`;
@@ -987,21 +996,22 @@ ${this.buildXsTemplate()}
987
996
  : this.buildStandardComponentTemplate(comp, level);
988
997
  }
989
998
  getChildrenTemplate(level) {
990
- const { isSupportRecursive, supportXS } = this;
999
+ const { isSupportRecursive, isUseXS, Adapter } = this;
991
1000
  const isLastRecursiveComp = !isSupportRecursive && level + 1 === this.baseLevel;
992
- const isUseXs = !this.isSupportRecursive && this.supportXS;
1001
+ const isUnRecursiveXs = !this.isSupportRecursive && isUseXS;
1002
+ const forAttribute = `${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="${"sid" /* Shortcuts.Sid */}"`;
993
1003
  if (isLastRecursiveComp) {
994
- const data = isUseXs
1004
+ const data = isUnRecursiveXs
995
1005
  ? `${this.dataKeymap('i:item,c:c,l:l')}`
996
1006
  : this.isSupportRecursive
997
1007
  ? this.dataKeymap('i:item')
998
1008
  : this.dataKeymap('i:item,c:c');
999
- return supportXS
1000
- ? `<template is="{{xs.e(${level})}}" data="{{${data}}}" />`
1001
- : `<template is="tmpl_${level}_${"container" /* Shortcuts.Container */}" data="{{${data}}}" />`;
1009
+ return isUseXS
1010
+ ? `<template is="{{xs.e(${level})}}" data="{{${data}}}" ${forAttribute} />`
1011
+ : `<template is="tmpl_${level}_${"container" /* Shortcuts.Container */}" data="{{${data}}}" ${forAttribute} />`;
1002
1012
  }
1003
1013
  else {
1004
- const data = isUseXs
1014
+ const data = isUnRecursiveXs
1005
1015
  // TODO: 此处直接 c+1,不是最优解,变量 c 的作用是监测组件嵌套的层级是否大于 baselevel
1006
1016
  // 但目前的监测方法用于所有组件嵌套的总和,应该分开组件计算,单个组件嵌套层级大于 baselevel 时,再进入 comp 组件中进行新的嵌套
1007
1017
  ? `${this.dataKeymap(`i:item,c:c+1,l:xs.f(l,item.${"nn" /* Shortcuts.NodeName */})`)}`
@@ -1011,15 +1021,15 @@ ${this.buildXsTemplate()}
1011
1021
  const xs = !this.isSupportRecursive
1012
1022
  ? `xs.a(c, item.${"nn" /* Shortcuts.NodeName */}, l)`
1013
1023
  : `xs.a(0, item.${"nn" /* Shortcuts.NodeName */})`;
1014
- return supportXS
1015
- ? `<template is="{{${xs}}}" data="{{${data}}}" />`
1024
+ return isUseXS
1025
+ ? `<template is="{{${xs}}}" data="{{${data}}}" ${forAttribute} />`
1016
1026
  : isSupportRecursive
1017
- ? `<template is="{{'tmpl_0_' + item.nn}}" data="{{${data}}}" />`
1018
- : `<template is="{{'tmpl_' + c + '_' + item.nn}}" data="{{${data}}}" />`;
1027
+ ? `<template is="{{'tmpl_0_' + item.${"nn" /* Shortcuts.NodeName */}}}" data="{{${data}}}" ${forAttribute} />`
1028
+ : `<template is="{{'tmpl_' + c + '_' + item.${"nn" /* Shortcuts.NodeName */}}}" data="{{${data}}}" ${forAttribute} />`;
1019
1029
  }
1020
1030
  }
1021
1031
  getChildren(comp, level) {
1022
- const { isSupportRecursive, Adapter } = this;
1032
+ const { isSupportRecursive } = this;
1023
1033
  const nextLevel = isSupportRecursive ? 0 : level + 1;
1024
1034
  let child = this.getChildrenTemplate(nextLevel);
1025
1035
  if (isFunction(this.modifyLoopBody)) {
@@ -1028,9 +1038,7 @@ ${this.buildXsTemplate()}
1028
1038
  let children = this.voidElements.has(comp.nodeName)
1029
1039
  ? ''
1030
1040
  : `
1031
- <block ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="sid">
1032
- ${indent(child, 6)}
1033
- </block>
1041
+ ${indent(child, 6)}
1034
1042
  `;
1035
1043
  if (isFunction(this.modifyLoopContainer)) {
1036
1044
  children = this.modifyLoopContainer(children, comp.nodeName);
@@ -1042,7 +1050,7 @@ ${this.buildXsTemplate()}
1042
1050
  const nodeName = comp.nodeName;
1043
1051
  const nodeAlias = comp.nodeAlias;
1044
1052
  const attrs = Object.assign({}, comp.attributes);
1045
- const templateName = this.supportXS
1053
+ const templateName = this.isUseXS
1046
1054
  ? `xs.c(i, 'tmpl_${level}_')`
1047
1055
  : `i.focus ? 'tmpl_${level}_${nodeAlias}_focus' : 'tmpl_${level}_${nodeAlias}_blur'`;
1048
1056
  delete attrs.focus;
@@ -1072,6 +1080,7 @@ ${this.buildXsTemplate()}
1072
1080
  case 'slot':
1073
1081
  case 'slot-view':
1074
1082
  case 'catch-view':
1083
+ case 'click-view':
1075
1084
  case 'static-view':
1076
1085
  case 'pure-view':
1077
1086
  nodeName = 'view';
@@ -1107,7 +1116,7 @@ ${this.buildXsTemplate()}
1107
1116
  `;
1108
1117
  }
1109
1118
  buildThirdPartyTemplate(level, componentConfig) {
1110
- const { Adapter, isSupportRecursive, supportXS, nestElements } = this;
1119
+ const { isSupportRecursive, isUseXS, nestElements } = this;
1111
1120
  const nextLevel = isSupportRecursive ? 0 : level + 1;
1112
1121
  let template = '';
1113
1122
  componentConfig.thirdPartyComponents.forEach((attrs, compName) => {
@@ -1120,7 +1129,7 @@ ${this.buildXsTemplate()}
1120
1129
  `;
1121
1130
  }
1122
1131
  else {
1123
- if (!isSupportRecursive && supportXS && nestElements.has(compName) && level + 1 > nestElements.get(compName))
1132
+ if (!isSupportRecursive && isUseXS && nestElements.has(compName) && level + 1 > nestElements.get(compName))
1124
1133
  return;
1125
1134
  let child = this.getChildrenTemplate(nextLevel);
1126
1135
  if (isFunction(this.modifyThirdPartyLoopBody)) {
@@ -1129,9 +1138,7 @@ ${this.buildXsTemplate()}
1129
1138
  const children = this.voidElements.has(compName)
1130
1139
  ? ''
1131
1140
  : `
1132
- <block ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="sid">
1133
- ${child}
1134
- </block>
1141
+ ${child}
1135
1142
  `;
1136
1143
  template += `
1137
1144
  <template name="tmpl_${level}_${compName}">
@@ -1148,7 +1155,7 @@ ${this.buildXsTemplate()}
1148
1155
  <template is="tmpl_0_${this.componentsAlias['#text']._num}" data="{{${this.dataKeymap('i:i')}}}" />
1149
1156
  </block>
1150
1157
  <block ${this.Adapter.else}>
1151
- ${!this.isSupportRecursive && this.supportXS ? '<comp i="{{i}}" l="{{l}}" />' : '<comp i="{{i}}" />'}
1158
+ ${!this.isSupportRecursive && this.isUseXS ? '<comp i="{{i}}" l="{{l}}" />' : '<comp i="{{i}}" />'}
1152
1159
  </block>`;
1153
1160
  return `
1154
1161
  <template name="tmpl_${level}_${"container" /* Shortcuts.Container */}">
@@ -1168,6 +1175,9 @@ ${this.buildXsTemplate()}
1168
1175
  buildXsTemplate(_filePath) {
1169
1176
  return '';
1170
1177
  }
1178
+ buildXsImportTemplate(_filePath) {
1179
+ return this.isUseXS ? this.buildXsTemplate(_filePath) + '\n' : '';
1180
+ }
1171
1181
  mergeComponents(ctx, patch) {
1172
1182
  ctx.helper.recursiveMerge(this.internalComponents, patch);
1173
1183
  }
@@ -1228,7 +1238,7 @@ class UnRecursiveTemplate extends BaseTemplate {
1228
1238
  .filter(c => componentConfig.includes.size && !componentConfig.includeAll ? componentConfig.includes.has(c) : true);
1229
1239
  let template = this.buildBaseTemplate();
1230
1240
  for (let i = 0; i < this.baseLevel; i++) {
1231
- template += this.supportXS
1241
+ template += this.isUseXS
1232
1242
  ? this.buildOptimizeFloor(i, components, this.baseLevel === i + 1)
1233
1243
  : this.buildFloor(i, components, this.baseLevel === i + 1);
1234
1244
  }