@tarojs/shared 3.7.0-canary.1 → 3.7.0-canary.3

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
@@ -48,7 +48,7 @@ const Text = {
48
48
  space: NO_DEFAULT_VALUE,
49
49
  decode: DEFAULT_FALSE
50
50
  };
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);
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, bindagreeprivacyauthorization: NO_DEFAULT_VALUE }, touchEvents);
52
52
  const Checkbox = {
53
53
  value: NO_DEFAULT_VALUE,
54
54
  disabled: NO_DEFAULT_VALUE,
@@ -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',
@@ -576,6 +576,7 @@ new TaroHooks({
576
576
  return this.call('getMiniLifecycle', defaultMiniLifecycle);
577
577
  }),
578
578
  getLifecycle: TaroHook(HOOK_TYPE.SINGLE, (instance, lifecycle) => instance[lifecycle]),
579
+ modifyRecursiveComponentConfig: TaroHook(HOOK_TYPE.SINGLE, (defaultConfig) => defaultConfig),
579
580
  getPathIndex: TaroHook(HOOK_TYPE.SINGLE, indexOfNode => `[${indexOfNode}]`),
580
581
  getEventCenter: TaroHook(HOOK_TYPE.SINGLE, Events => new Events()),
581
582
  isBubbleEvents: TaroHook(HOOK_TYPE.SINGLE, eventName => {
@@ -607,6 +608,7 @@ new TaroHooks({
607
608
  createPullDownComponent: TaroHook(HOOK_TYPE.SINGLE),
608
609
  getDOMNode: TaroHook(HOOK_TYPE.SINGLE),
609
610
  modifyHydrateData: TaroHook(HOOK_TYPE.SINGLE),
611
+ transferHydrateData: TaroHook(HOOK_TYPE.SINGLE),
610
612
  modifySetAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
611
613
  modifyRmAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
612
614
  onAddEvent: TaroHook(HOOK_TYPE.SINGLE),
@@ -631,7 +633,9 @@ new TaroHooks({
631
633
  dispatchTaroEventFinish: TaroHook(HOOK_TYPE.MULTI),
632
634
  modifyDispatchEvent: TaroHook(HOOK_TYPE.MULTI),
633
635
  initNativeApi: TaroHook(HOOK_TYPE.MULTI),
634
- patchElement: TaroHook(HOOK_TYPE.MULTI)
636
+ patchElement: TaroHook(HOOK_TYPE.MULTI),
637
+ modifyAddEventListener: TaroHook(HOOK_TYPE.SINGLE),
638
+ modifyRemoveEventListener: TaroHook(HOOK_TYPE.SINGLE),
635
639
  });
636
640
 
637
641
  function toDashed(s) {
@@ -759,24 +763,32 @@ class BaseTemplate {
759
763
  this.voidElements = voidElements;
760
764
  /** 可以递归调用自身的组件 */
761
765
  this.nestElements = nestElements;
762
- this.buildPageTemplate = (baseTempPath) => {
766
+ this.buildPageTemplate = (baseTempPath, _page) => {
763
767
  const template = `<import src="${baseTempPath}"/>
764
768
  <template is="taro_tmpl" data="{{${this.dataKeymap('root:root')}}}" />`;
765
769
  return template;
766
770
  };
767
771
  this.buildBaseComponentTemplate = (ext) => {
768
- const data = this.supportXS
769
- ? this.dataKeymap('i:i,l:l')
770
- : this.dataKeymap('i:i');
772
+ const data = !this.isSupportRecursive && this.supportXS
773
+ ? this.dataKeymap(`i:i,c:1,l:xs.f('',i.${"nn" /* Shortcuts.NodeName */})`)
774
+ : this.isSupportRecursive
775
+ ? this.dataKeymap('i:i')
776
+ : this.dataKeymap('i:i,c:1');
777
+ // 此处需要重新引入 xs 函数,否则会出现 ws.f() 在 comp.wxml 和 custom-wrapper.wxml 中永远返回 undefined 的问题 #14599
771
778
  return `<import src="./base${ext}" />
779
+ ${this.buildXsTemplate()}
772
780
  <template is="{{'tmpl_0_' + i.nn}}" data="{{${data}}}" />`;
773
781
  };
774
782
  this.buildCustomComponentTemplate = (ext) => {
775
783
  const Adapter = this.Adapter;
776
784
  const data = !this.isSupportRecursive && this.supportXS
777
- ? `${this.dataKeymap('i:item,l:\'\'')}`
778
- : this.dataKeymap('i:item');
785
+ ? `${this.dataKeymap(`i:item,c:1,l:xs.f('',item.${"nn" /* Shortcuts.NodeName */})`)}`
786
+ : this.isSupportRecursive
787
+ ? this.dataKeymap('i:item')
788
+ : this.dataKeymap('i:item,c:1');
789
+ // 此处需要重新引入 xs 函数,否则会出现 ws.f() 在 comp.wxml 和 custom-wrapper.wxml 中永远返回 undefined 的问题 #14599
779
790
  return `<import src="./base${ext}" />
791
+ ${this.buildXsTemplate()}
780
792
  <block ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="sid">
781
793
  <template is="{{'tmpl_0_' + item.nn}}" data="{{${data}}}" />
782
794
  </block>`;
@@ -904,10 +916,14 @@ class BaseTemplate {
904
916
  buildBaseTemplate() {
905
917
  const Adapter = this.Adapter;
906
918
  const data = !this.isSupportRecursive && this.supportXS
907
- ? `${this.dataKeymap('i:item,l:\'\'')}`
908
- : this.dataKeymap('i:item');
919
+ ? `${this.dataKeymap(`i:item,c:1,l:xs.f('',item.${"nn" /* Shortcuts.NodeName */})`)}`
920
+ : this.isSupportRecursive
921
+ ? this.dataKeymap('i:item')
922
+ : this.dataKeymap('i:item,c:1');
909
923
  const xs = this.supportXS
910
- ? `xs.a(0, item.${"nn" /* Shortcuts.NodeName */})`
924
+ ? (this.isSupportRecursive
925
+ ? `xs.a(0, item.${"nn" /* Shortcuts.NodeName */})`
926
+ : `xs.a(0, item.${"nn" /* Shortcuts.NodeName */}, '')`)
911
927
  : "'tmpl_0_' + item.nn";
912
928
  return `${this.buildXsTemplate()}
913
929
  <template name="taro_tmpl">
@@ -925,10 +941,10 @@ class BaseTemplate {
925
941
  if (value.indexOf('-') > -1) {
926
942
  value = `:${value}`;
927
943
  }
928
- return str + `bind${value}="eh" `;
944
+ return str + ` bind${value}="eh"`;
929
945
  }
930
946
  else if (attr.startsWith('bind')) {
931
- return str + `${attr}="eh" `;
947
+ return str + ` ${attr}="eh"`;
932
948
  }
933
949
  else if (attr.startsWith('on')) {
934
950
  // react, vue3
@@ -937,22 +953,22 @@ class BaseTemplate {
937
953
  // 兼容如 vant 某些组件的 bind:a-b 这类属性
938
954
  value = `:${value}`;
939
955
  }
940
- return str + `bind${value}="eh" `;
956
+ return str + ` bind${value}="eh"`;
941
957
  }
942
958
  else if (attr === 'class') {
943
- return str + `class="{{i.${"cl" /* Shortcuts.Class */}}}" `;
959
+ return str + ` class="{{i.${"cl" /* Shortcuts.Class */}}}"`;
944
960
  }
945
961
  else if (attr === 'style') {
946
- return str + `style="{{i.${"st" /* Shortcuts.Style */}}}" `;
962
+ return str + ` style="{{i.${"st" /* Shortcuts.Style */}}}"`;
947
963
  }
948
964
  const patchValue = patcher[attr];
949
965
  if (isBooleanStringLiteral(patchValue) || isNumber(patchValue) || isString(patchValue)) {
950
966
  const propValue = this.supportXS
951
967
  ? `xs.b(i.${toCamelCase(attr)},${patchValue})`
952
968
  : `i.${toCamelCase(attr)}===undefined?${patchValue}:i.${toCamelCase(attr)}`;
953
- return str + `${attr}="{{${propValue}}}" `;
969
+ return str + ` ${attr}="{{${propValue}}}"`;
954
970
  }
955
- return str + `${attr}="{{i.${toCamelCase(attr)}}}" `;
971
+ return str + ` ${attr}="{{i.${toCamelCase(attr)}}}"`;
956
972
  }, '');
957
973
  }
958
974
  buildComponentTemplate(comp, level) {
@@ -966,22 +982,30 @@ class BaseTemplate {
966
982
  const isUseXs = !this.isSupportRecursive && this.supportXS;
967
983
  if (isLastRecursiveComp) {
968
984
  const data = isUseXs
969
- ? `${this.dataKeymap('i:item,l:l')}`
970
- : this.dataKeymap('i:item');
985
+ ? `${this.dataKeymap('i:item,c:c,l:l')}`
986
+ : this.isSupportRecursive
987
+ ? this.dataKeymap('i:item')
988
+ : this.dataKeymap('i:item,c:c');
971
989
  return supportXS
972
990
  ? `<template is="{{xs.e(${level})}}" data="{{${data}}}" />`
973
991
  : `<template is="tmpl_${level}_${"container" /* Shortcuts.Container */}" data="{{${data}}}" />`;
974
992
  }
975
993
  else {
976
994
  const data = isUseXs
977
- ? `${this.dataKeymap(`i:item,l:xs.f(l,item.${"nn" /* Shortcuts.NodeName */})`)}`
978
- : `${this.dataKeymap('i:item')}`;
995
+ // TODO: 此处直接 c+1,不是最优解,变量 c 的作用是监测组件嵌套的层级是否大于 baselevel
996
+ // 但目前的监测方法用于所有组件嵌套的总和,应该分开组件计算,单个组件嵌套层级大于 baselevel 时,再进入 comp 组件中进行新的嵌套
997
+ ? `${this.dataKeymap(`i:item,c:c+1,l:xs.f(l,item.${"nn" /* Shortcuts.NodeName */})`)}`
998
+ : this.isSupportRecursive
999
+ ? `${this.dataKeymap('i:item')}`
1000
+ : `${this.dataKeymap('i:item,c:c+1')}`;
979
1001
  const xs = !this.isSupportRecursive
980
- ? `xs.a(${level}, item.${"nn" /* Shortcuts.NodeName */}, l)`
981
- : `xs.a(${level}, item.${"nn" /* Shortcuts.NodeName */})`;
1002
+ ? `xs.a(c, item.${"nn" /* Shortcuts.NodeName */}, l)`
1003
+ : `xs.a(0, item.${"nn" /* Shortcuts.NodeName */})`;
982
1004
  return supportXS
983
1005
  ? `<template is="{{${xs}}}" data="{{${data}}}" />`
984
- : `<template is="{{'tmpl_' + ${level} + '_' + item.nn}}" data="{{${data}}}" />`;
1006
+ : isSupportRecursive
1007
+ ? `<template is="{{'tmpl_0_' + item.nn}}" data="{{${data}}}" />`
1008
+ : `<template is="{{'tmpl_' + c + '_' + item.nn}}" data="{{${data}}}" />`;
985
1009
  }
986
1010
  }
987
1011
  getChildren(comp, level) {
@@ -1014,7 +1038,7 @@ class BaseTemplate {
1014
1038
  delete attrs.focus;
1015
1039
  let res = `
1016
1040
  <template name="tmpl_${level}_${nodeAlias}">
1017
- <template is="{{${templateName}}}" data="{{${this.dataKeymap('i:i')}}}" />
1041
+ <template is="{{${templateName}}}" data="{{${this.isSupportRecursive ? this.dataKeymap('i:i') : this.dataKeymap('i:i,c:c')}}}" />
1018
1042
  </template>
1019
1043
 
1020
1044
  <template name="tmpl_${level}_${nodeAlias}_focus">
@@ -1092,13 +1116,16 @@ class BaseTemplate {
1092
1116
  if (isFunction(this.modifyThirdPartyLoopBody)) {
1093
1117
  child = this.modifyThirdPartyLoopBody(child, compName);
1094
1118
  }
1095
- template += `
1096
- <template name="tmpl_${level}_${compName}">
1097
- <${compName} ${this.buildThirdPartyAttr(attrs, this.thirdPartyPatcher[compName] || {})} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">
1119
+ const children = this.voidElements.has(compName)
1120
+ ? ''
1121
+ : `
1098
1122
  <block ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="sid">
1099
1123
  ${child}
1100
1124
  </block>
1101
- </${compName}>
1125
+ `;
1126
+ template += `
1127
+ <template name="tmpl_${level}_${compName}">
1128
+ <${compName} ${this.buildThirdPartyAttr(attrs, this.thirdPartyPatcher[compName] || {})} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">${children}</${compName}>
1102
1129
  </template>
1103
1130
  `;
1104
1131
  }
@@ -1107,8 +1134,8 @@ class BaseTemplate {
1107
1134
  }
1108
1135
  // 最后一层的 comp 需要引用 container 进行重新的模版循环,其他情况不需要 container
1109
1136
  buildContainerTemplate(level) {
1110
- const tmpl = `<block ${this.Adapter.if}="{{i.nn === '#text'}}">
1111
- <template is="tmpl_0_#text" data="{{${this.dataKeymap('i:i')}}}" />
1137
+ const tmpl = `<block ${this.Adapter.if}="{{i.nn === '${this.componentsAlias['#text']._num}'}}">
1138
+ <template is="tmpl_0_${this.componentsAlias['#text']._num}" data="{{${this.dataKeymap('i:i')}}}" />
1112
1139
  </block>
1113
1140
  <block ${this.Adapter.else}>
1114
1141
  ${!this.isSupportRecursive && this.supportXS ? '<comp i="{{i}}" l="{{l}}" />' : '<comp i="{{i}}" />'}
@@ -1254,6 +1281,8 @@ class UnRecursiveTemplate extends BaseTemplate {
1254
1281
  const componentsAlias = this.componentsAlias;
1255
1282
  const listA = Array.from(isLoopCompsSet).map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
1256
1283
  const listB = hasMaxComps.map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
1284
+ const containerLevel = this.baseLevel - 1;
1285
+ // l >= containerLevel 是为了避免 baselevel 倒数两三层几层组件恰好不是 listA 中的组件,而最后一个组件又刚好是 listA 的组件,导致出现 l >= baselevel 却没有走入新的嵌套循环的问题 #14883
1257
1286
  return `function (l, n, s) {
1258
1287
  var a = ${JSON.stringify(listA)}
1259
1288
  var b = ${JSON.stringify(listB)}
@@ -1268,6 +1297,9 @@ class UnRecursiveTemplate extends BaseTemplate {
1268
1297
  }
1269
1298
  l = depth
1270
1299
  }
1300
+ if (l >= ${containerLevel}) {
1301
+ return 'tmpl_${containerLevel}_${"container" /* Shortcuts.Container */}'
1302
+ }
1271
1303
  return 'tmpl_' + l + '_' + n
1272
1304
  }`;
1273
1305
  }