@tarojs/shared 4.0.7-alpha.3 → 4.0.7-alpha.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/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],
@@ -325,6 +326,33 @@ const nestElements = new Map([
325
326
  ['swiper-item', 4],
326
327
  ]);
327
328
 
329
+ var PLATFORM_TYPE;
330
+ (function (PLATFORM_TYPE) {
331
+ PLATFORM_TYPE["MINI"] = "mini";
332
+ PLATFORM_TYPE["WEB"] = "web";
333
+ PLATFORM_TYPE["RN"] = "rn";
334
+ PLATFORM_TYPE["HARMONY"] = "harmony";
335
+ PLATFORM_TYPE["QUICK"] = "quickapp";
336
+ })(PLATFORM_TYPE || (PLATFORM_TYPE = {}));
337
+ const COMPILE_MODE_IDENTIFIER_PREFIX = 'f';
338
+ ({
339
+ h5: {
340
+ type: PLATFORM_TYPE.WEB
341
+ },
342
+ harmony: {
343
+ type: PLATFORM_TYPE.HARMONY
344
+ },
345
+ mini: {
346
+ type: PLATFORM_TYPE.MINI
347
+ },
348
+ rn: {
349
+ type: PLATFORM_TYPE.RN
350
+ },
351
+ quickapp: {
352
+ type: PLATFORM_TYPE.QUICK
353
+ },
354
+ });
355
+
328
356
  function isString(o) {
329
357
  return typeof o === 'string';
330
358
  }
@@ -352,37 +380,12 @@ exports.Shortcuts = void 0;
352
380
  Shortcuts["NodeType"] = "nt";
353
381
  Shortcuts["NodeName"] = "nn";
354
382
  // Attrtibutes
383
+ Shortcuts["Sid"] = "sid";
355
384
  Shortcuts["Style"] = "st";
356
385
  Shortcuts["Class"] = "cl";
357
386
  Shortcuts["Src"] = "src";
358
387
  })(exports.Shortcuts || (exports.Shortcuts = {}));
359
388
 
360
- var PLATFORM_TYPE;
361
- (function (PLATFORM_TYPE) {
362
- PLATFORM_TYPE["MINI"] = "mini";
363
- PLATFORM_TYPE["WEB"] = "web";
364
- PLATFORM_TYPE["RN"] = "rn";
365
- PLATFORM_TYPE["HARMONY"] = "harmony";
366
- PLATFORM_TYPE["QUICK"] = "quickapp";
367
- })(PLATFORM_TYPE || (PLATFORM_TYPE = {}));
368
- ({
369
- h5: {
370
- type: PLATFORM_TYPE.WEB
371
- },
372
- harmony: {
373
- type: PLATFORM_TYPE.HARMONY
374
- },
375
- mini: {
376
- type: PLATFORM_TYPE.MINI
377
- },
378
- rn: {
379
- type: PLATFORM_TYPE.RN
380
- },
381
- quickapp: {
382
- type: PLATFORM_TYPE.QUICK
383
- },
384
- });
385
-
386
389
  class Events {
387
390
  constructor(opts) {
388
391
  var _a;
@@ -687,12 +690,13 @@ function getComponentsAlias(origin) {
687
690
  StaticImage: origin.Image,
688
691
  StaticText: origin.Text,
689
692
  PureView: viewAttrs,
690
- CatchView: viewAttrs
693
+ CatchView: viewAttrs,
694
+ ClickView: viewAttrs,
691
695
  };
692
696
  origin = Object.assign(Object.assign({}, origin), extraList);
693
697
  Object.keys(origin)
694
698
  .sort((a, b) => {
695
- const reg = /^(Static|Pure|Catch)*(View|Image|Text)$/;
699
+ const reg = /^(Static|Pure|Catch|Click)*(View|Image|Text)$/;
696
700
  const isACommonly = reg.test(a);
697
701
  const isBCommonly = reg.test(b);
698
702
  if (isACommonly && isBCommonly) {
@@ -765,6 +769,8 @@ const weixinAdapter = {
765
769
  class BaseTemplate {
766
770
  constructor() {
767
771
  this._baseLevel = 0;
772
+ this._isUseXS = true;
773
+ this._isUseCompileMode = false;
768
774
  this.exportExpr = 'module.exports =';
769
775
  this.thirdPartyPatcher = {};
770
776
  this.supportXS = false;
@@ -784,29 +790,26 @@ class BaseTemplate {
784
790
  return template;
785
791
  };
786
792
  this.buildBaseComponentTemplate = (ext) => {
787
- const data = !this.isSupportRecursive && this.supportXS
793
+ const data = !this.isSupportRecursive && this.isUseXS
788
794
  ? this.dataKeymap(`i:i,c:1,l:xs.f('',i.${"nn" /* Shortcuts.NodeName */})`)
789
795
  : this.isSupportRecursive
790
796
  ? this.dataKeymap('i:i')
791
797
  : this.dataKeymap('i:i,c:1');
792
798
  // 此处需要重新引入 xs 函数,否则会出现 ws.f() 在 comp.wxml 和 custom-wrapper.wxml 中永远返回 undefined 的问题 #14599
793
799
  return `<import src="./base${ext}" />
794
- ${this.buildXsTemplate()}
795
- <template is="{{'tmpl_0_' + i.nn}}" data="{{${data}}}" />`;
800
+ ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + i.${"nn" /* Shortcuts.NodeName */}}}" data="{{${data}}}" />`;
796
801
  };
797
802
  this.buildCustomComponentTemplate = (ext) => {
798
803
  const Adapter = this.Adapter;
799
- const data = !this.isSupportRecursive && this.supportXS
804
+ const data = !this.isSupportRecursive && this.isUseXS
800
805
  ? `${this.dataKeymap(`i:item,c:1,l:xs.f('',item.${"nn" /* Shortcuts.NodeName */})`)}`
801
806
  : this.isSupportRecursive
802
807
  ? this.dataKeymap('i:item')
803
808
  : this.dataKeymap('i:item,c:1');
804
809
  // 此处需要重新引入 xs 函数,否则会出现 ws.f() 在 comp.wxml 和 custom-wrapper.wxml 中永远返回 undefined 的问题 #14599
805
810
  return `<import src="./base${ext}" />
806
- ${this.buildXsTemplate()}
807
- <block ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="sid">
808
- <template is="{{'tmpl_0_' + item.nn}}" data="{{${data}}}" />
809
- </block>`;
811
+ ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + item.${"nn" /* Shortcuts.NodeName */}}}" data="{{${data}}}" ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="${"sid" /* Shortcuts.Sid */}" />
812
+ `;
810
813
  };
811
814
  this.buildXScript = () => {
812
815
  return `${this.exportExpr} {
@@ -831,6 +834,18 @@ ${this.buildXsTemplate()}
831
834
  get baseLevel() {
832
835
  return this._baseLevel;
833
836
  }
837
+ set isUseCompileMode(isUse) {
838
+ this._isUseCompileMode = isUse;
839
+ }
840
+ get isUseCompileMode() {
841
+ return this._isUseCompileMode;
842
+ }
843
+ set isUseXS(isUse) {
844
+ this._isUseXS = this.supportXS && isUse;
845
+ }
846
+ get isUseXS() {
847
+ return this._isUseXS;
848
+ }
834
849
  buildAttribute(attrs, nodeName) {
835
850
  return Object.keys(attrs)
836
851
  .map(k => `${k}="${k.startsWith('bind') || k.startsWith('on') || k.startsWith('catch') ? attrs[k] : `{${this.getAttrValue(attrs[k], k, nodeName)}}`}" `)
@@ -868,12 +883,12 @@ ${this.buildXsTemplate()}
868
883
  if (prop === 'cursor') {
869
884
  propValue = `i.${componentAlias.value}?i.${componentAlias.value}.length:-1`;
870
885
  }
871
- propValue = this.supportXS
886
+ propValue = this.isUseXS
872
887
  ? `xs.b(i.${propAlias},${propValue})`
873
888
  : `i.${propAlias}===undefined?${propValue}:i.${propAlias}`;
874
889
  }
875
890
  else if (isObjectStringLiteral(propValue)) {
876
- propValue = this.supportXS
891
+ propValue = this.isUseXS
877
892
  ? `xs.d(i.${propAlias})`
878
893
  : `i.${propAlias}===undefined?${propValue}:i.${propAlias}`;
879
894
  }
@@ -915,6 +930,11 @@ ${this.buildXsTemplate()}
915
930
  style: comp.style,
916
931
  class: comp.class
917
932
  };
933
+ result['click-view'] = {
934
+ style: comp.style,
935
+ class: comp.class,
936
+ bindtap: 'eh'
937
+ };
918
938
  }
919
939
  }
920
940
  if (compName === 'slot' || compName === 'slot-view') {
@@ -934,21 +954,18 @@ ${this.buildXsTemplate()}
934
954
  }
935
955
  buildBaseTemplate() {
936
956
  const Adapter = this.Adapter;
937
- const data = !this.isSupportRecursive && this.supportXS
957
+ const data = !this.isSupportRecursive && this.isUseXS
938
958
  ? `${this.dataKeymap(`i:item,c:1,l:xs.f('',item.${"nn" /* Shortcuts.NodeName */})`)}`
939
959
  : this.isSupportRecursive
940
960
  ? this.dataKeymap('i:item')
941
961
  : this.dataKeymap('i:item,c:1');
942
- const xs = this.supportXS
962
+ const xs = this.isUseXS
943
963
  ? (this.isSupportRecursive
944
964
  ? `xs.a(0, item.${"nn" /* Shortcuts.NodeName */})`
945
965
  : `xs.a(0, item.${"nn" /* Shortcuts.NodeName */}, '')`)
946
- : "'tmpl_0_' + item.nn";
947
- return `${this.buildXsTemplate()}
948
- <template name="taro_tmpl">
949
- <block ${Adapter.for}="{{root.cn}}" ${Adapter.key}="sid">
950
- <template is="{{${xs}}}" data="{{${data}}}" />
951
- </block>
966
+ : `'tmpl_0_' + item.${"nn" /* Shortcuts.NodeName */}`;
967
+ return `${this.buildXsImportTemplate()}<template name="taro_tmpl">
968
+ <template is="{{${xs}}}" data="{{${data}}}" ${Adapter.for}="{{root.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="${"sid" /* Shortcuts.Sid */}" />
952
969
  </template>
953
970
  `;
954
971
  }
@@ -983,7 +1000,7 @@ ${this.buildXsTemplate()}
983
1000
  const patchValue = patcher[attr];
984
1001
  if (isBooleanStringLiteral(patchValue) || isNumber(patchValue) || isString(patchValue)) {
985
1002
  let propValue = '';
986
- if (this.supportXS) {
1003
+ if (this.isUseXS) {
987
1004
  if (isObjectStringLiteral(patchValue)) {
988
1005
  propValue = `xs.d(i.${toCamelCase(attr)})`;
989
1006
  }
@@ -1003,21 +1020,22 @@ ${this.buildXsTemplate()}
1003
1020
  : this.buildStandardComponentTemplate(comp, level);
1004
1021
  }
1005
1022
  getChildrenTemplate(level) {
1006
- const { isSupportRecursive, supportXS } = this;
1023
+ const { isSupportRecursive, isUseXS, Adapter, isUseCompileMode = true } = this;
1007
1024
  const isLastRecursiveComp = !isSupportRecursive && level + 1 === this.baseLevel;
1008
- const isUseXs = !this.isSupportRecursive && this.supportXS;
1025
+ const isUnRecursiveXs = !this.isSupportRecursive && isUseXS;
1026
+ const forAttribute = `${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="${"sid" /* Shortcuts.Sid */}"`;
1009
1027
  if (isLastRecursiveComp) {
1010
- const data = isUseXs
1028
+ const data = isUnRecursiveXs
1011
1029
  ? `${this.dataKeymap('i:item,c:c,l:l')}`
1012
1030
  : this.isSupportRecursive
1013
1031
  ? this.dataKeymap('i:item')
1014
1032
  : this.dataKeymap('i:item,c:c');
1015
- return supportXS
1016
- ? `<template is="{{xs.e(${level})}}" data="{{${data}}}" />`
1017
- : `<template is="tmpl_${level}_${"container" /* Shortcuts.Container */}" data="{{${data}}}" />`;
1033
+ return isUseXS
1034
+ ? `<template is="{{xs.e(${level})}}" data="{{${data}}}" ${forAttribute} />`
1035
+ : `<template is="tmpl_${level}_${"container" /* Shortcuts.Container */}" data="{{${data}}}" ${forAttribute} />`;
1018
1036
  }
1019
1037
  else {
1020
- const data = isUseXs
1038
+ const data = isUnRecursiveXs
1021
1039
  // TODO: 此处直接 c+1,不是最优解,变量 c 的作用是监测组件嵌套的层级是否大于 baselevel
1022
1040
  // 但目前的监测方法用于所有组件嵌套的总和,应该分开组件计算,单个组件嵌套层级大于 baselevel 时,再进入 comp 组件中进行新的嵌套
1023
1041
  ? `${this.dataKeymap(`i:item,c:c+1,l:xs.f(l,item.${"nn" /* Shortcuts.NodeName */})`)}`
@@ -1027,15 +1045,17 @@ ${this.buildXsTemplate()}
1027
1045
  const xs = !this.isSupportRecursive
1028
1046
  ? `xs.a(c, item.${"nn" /* Shortcuts.NodeName */}, l)`
1029
1047
  : `xs.a(0, item.${"nn" /* Shortcuts.NodeName */})`;
1030
- return supportXS
1031
- ? `<template is="{{${xs}}}" data="{{${data}}}" />`
1048
+ return isUseXS
1049
+ ? `<template is="{{${xs}}}" data="{{${data}}}" ${forAttribute} />`
1032
1050
  : isSupportRecursive
1033
- ? `<template is="{{'tmpl_0_' + item.nn}}" data="{{${data}}}" />`
1034
- : `<template is="{{'tmpl_' + c + '_' + item.nn}}" data="{{${data}}}" />`;
1051
+ ? `<template is="{{'tmpl_0_' + item.${"nn" /* Shortcuts.NodeName */}}}" data="{{${data}}}" ${forAttribute} />`
1052
+ : isUseCompileMode
1053
+ ? `<template is="{{'tmpl_' + (item.${"nn" /* Shortcuts.NodeName */}[0]==='${COMPILE_MODE_IDENTIFIER_PREFIX}' ? 0 : c) + '_' + item.${"nn" /* Shortcuts.NodeName */}}}" data="{{${data}}}" ${forAttribute} />`
1054
+ : `<template is="{{'tmpl_' + c + '_' + item.${"nn" /* Shortcuts.NodeName */}}}" data="{{${data}}}" ${forAttribute} />`;
1035
1055
  }
1036
1056
  }
1037
1057
  getChildren(comp, level) {
1038
- const { isSupportRecursive, Adapter } = this;
1058
+ const { isSupportRecursive } = this;
1039
1059
  const nextLevel = isSupportRecursive ? 0 : level + 1;
1040
1060
  let child = this.getChildrenTemplate(nextLevel);
1041
1061
  if (isFunction(this.modifyLoopBody)) {
@@ -1044,9 +1064,7 @@ ${this.buildXsTemplate()}
1044
1064
  let children = this.voidElements.has(comp.nodeName)
1045
1065
  ? ''
1046
1066
  : `
1047
- <block ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="sid">
1048
- ${indent(child, 6)}
1049
- </block>
1067
+ ${indent(child, 6)}
1050
1068
  `;
1051
1069
  if (isFunction(this.modifyLoopContainer)) {
1052
1070
  children = this.modifyLoopContainer(children, comp.nodeName);
@@ -1058,7 +1076,7 @@ ${this.buildXsTemplate()}
1058
1076
  const nodeName = comp.nodeName;
1059
1077
  const nodeAlias = comp.nodeAlias;
1060
1078
  const attrs = Object.assign({}, comp.attributes);
1061
- const templateName = this.supportXS
1079
+ const templateName = this.isUseXS
1062
1080
  ? `xs.c(i, 'tmpl_${level}_')`
1063
1081
  : `i.focus ? 'tmpl_${level}_${nodeAlias}_focus' : 'tmpl_${level}_${nodeAlias}_blur'`;
1064
1082
  delete attrs.focus;
@@ -1088,6 +1106,7 @@ ${this.buildXsTemplate()}
1088
1106
  case 'slot':
1089
1107
  case 'slot-view':
1090
1108
  case 'catch-view':
1109
+ case 'click-view':
1091
1110
  case 'static-view':
1092
1111
  case 'pure-view':
1093
1112
  nodeName = 'view';
@@ -1123,20 +1142,20 @@ ${this.buildXsTemplate()}
1123
1142
  `;
1124
1143
  }
1125
1144
  buildThirdPartyTemplate(level, componentConfig) {
1126
- const { Adapter, isSupportRecursive, supportXS, nestElements } = this;
1145
+ const { isSupportRecursive, isUseXS, nestElements } = this;
1127
1146
  const nextLevel = isSupportRecursive ? 0 : level + 1;
1128
1147
  let template = '';
1129
1148
  componentConfig.thirdPartyComponents.forEach((attrs, compName) => {
1130
1149
  if (compName === 'custom-wrapper') {
1131
1150
  template += `
1132
1151
  <template name="tmpl_${level}_${compName}">
1133
- <${compName} i="{{i}}" l="{{l}}" id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">
1152
+ <${compName} i="{{i}}" ${!isSupportRecursive && isUseXS ? 'l="{{l}}"' : ''} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">
1134
1153
  </${compName}>
1135
1154
  </template>
1136
1155
  `;
1137
1156
  }
1138
1157
  else {
1139
- if (!isSupportRecursive && supportXS && nestElements.has(compName) && level + 1 > nestElements.get(compName))
1158
+ if (!isSupportRecursive && isUseXS && nestElements.has(compName) && level + 1 > nestElements.get(compName))
1140
1159
  return;
1141
1160
  let child = this.getChildrenTemplate(nextLevel);
1142
1161
  if (isFunction(this.modifyThirdPartyLoopBody)) {
@@ -1145,9 +1164,7 @@ ${this.buildXsTemplate()}
1145
1164
  const children = this.voidElements.has(compName)
1146
1165
  ? ''
1147
1166
  : `
1148
- <block ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="sid">
1149
- ${child}
1150
- </block>
1167
+ ${child}
1151
1168
  `;
1152
1169
  template += `
1153
1170
  <template name="tmpl_${level}_${compName}">
@@ -1164,7 +1181,7 @@ ${this.buildXsTemplate()}
1164
1181
  <template is="tmpl_0_${this.componentsAlias['#text']._num}" data="{{${this.dataKeymap('i:i')}}}" />
1165
1182
  </block>
1166
1183
  <block ${this.Adapter.else}>
1167
- ${!this.isSupportRecursive && this.supportXS ? '<comp i="{{i}}" l="{{l}}" />' : '<comp i="{{i}}" />'}
1184
+ ${!this.isSupportRecursive && this.isUseXS ? '<comp i="{{i}}" l="{{l}}" />' : '<comp i="{{i}}" />'}
1168
1185
  </block>`;
1169
1186
  return `
1170
1187
  <template name="tmpl_${level}_${"container" /* Shortcuts.Container */}">
@@ -1184,6 +1201,9 @@ ${this.buildXsTemplate()}
1184
1201
  buildXsTemplate(_filePath) {
1185
1202
  return '';
1186
1203
  }
1204
+ buildXsImportTemplate(_filePath) {
1205
+ return this.isUseXS ? this.buildXsTemplate(_filePath) + '\n' : '';
1206
+ }
1187
1207
  mergeComponents(ctx, patch) {
1188
1208
  ctx.helper.recursiveMerge(this.internalComponents, patch);
1189
1209
  }
@@ -1244,7 +1264,7 @@ class UnRecursiveTemplate extends BaseTemplate {
1244
1264
  .filter(c => componentConfig.includes.size && !componentConfig.includeAll ? componentConfig.includes.has(c) : true);
1245
1265
  let template = this.buildBaseTemplate();
1246
1266
  for (let i = 0; i < this.baseLevel; i++) {
1247
- template += this.supportXS
1267
+ template += this.isUseXS
1248
1268
  ? this.buildOptimizeFloor(i, components, this.baseLevel === i + 1)
1249
1269
  : this.buildFloor(i, components, this.baseLevel === i + 1);
1250
1270
  }