@tarojs/shared 3.8.0-canary.0 → 4.0.0-alpha.10
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/LICENSE +11 -4
- package/dist/components.d.ts +20 -0
- package/dist/components.js +337 -0
- package/dist/components.js.map +1 -0
- package/dist/constants.d.ts +24 -0
- package/dist/constants.js +28 -0
- package/dist/constants.js.map +1 -0
- package/dist/event-channel.d.ts +14 -0
- package/dist/event-channel.js +48 -0
- package/dist/event-channel.js.map +1 -0
- package/dist/event-emitter.d.ts +12 -0
- package/dist/event-emitter.js +97 -0
- package/dist/event-emitter.js.map +1 -0
- package/dist/index.cjs.js +1338 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +9 -291
- package/dist/index.js +9 -1279
- package/dist/index.js.map +1 -1
- package/dist/is.d.ts +10 -0
- package/dist/is.js +29 -0
- package/dist/is.js.map +1 -0
- package/dist/native-apis.d.ts +34 -0
- package/dist/native-apis.js +362 -0
- package/dist/native-apis.js.map +1 -0
- package/dist/runtime-hooks.d.ts +143 -0
- package/dist/runtime-hooks.js +179 -0
- package/dist/runtime-hooks.js.map +1 -0
- package/dist/shared.esm.js +78 -19
- package/dist/shared.esm.js.map +1 -1
- package/dist/shortcuts.d.ts +10 -0
- package/dist/shortcuts.js +16 -0
- package/dist/shortcuts.js.map +1 -0
- package/dist/template.d.ts +31 -27
- package/dist/template.js +57 -33
- package/dist/template.js.map +1 -1
- package/dist/utils.d.ts +56 -0
- package/dist/utils.js +220 -0
- package/dist/utils.js.map +1 -0
- package/package.json +16 -12
- package/dist/shared.esm.d.ts +0 -291
package/dist/template.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
const DEFAULT_EMPTY_ARRAY = '[]';
|
|
6
4
|
const NO_DEFAULT_VALUE = '';
|
|
7
5
|
const DEFAULT_TRUE = '!0';
|
|
@@ -43,12 +41,8 @@ const Progress = {
|
|
|
43
41
|
const RichText = {
|
|
44
42
|
nodes: DEFAULT_EMPTY_ARRAY
|
|
45
43
|
};
|
|
46
|
-
const Text = {
|
|
47
|
-
|
|
48
|
-
space: NO_DEFAULT_VALUE,
|
|
49
|
-
decode: DEFAULT_FALSE
|
|
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);
|
|
44
|
+
const Text = Object.assign({ selectable: DEFAULT_FALSE, space: NO_DEFAULT_VALUE, decode: DEFAULT_FALSE }, touchEvents);
|
|
45
|
+
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
46
|
const Checkbox = {
|
|
53
47
|
value: NO_DEFAULT_VALUE,
|
|
54
48
|
disabled: NO_DEFAULT_VALUE,
|
|
@@ -88,10 +82,7 @@ const Input = {
|
|
|
88
82
|
bindConfirm: NO_DEFAULT_VALUE,
|
|
89
83
|
name: NO_DEFAULT_VALUE
|
|
90
84
|
};
|
|
91
|
-
const Label = {
|
|
92
|
-
for: NO_DEFAULT_VALUE,
|
|
93
|
-
name: NO_DEFAULT_VALUE
|
|
94
|
-
};
|
|
85
|
+
const Label = Object.assign({ for: NO_DEFAULT_VALUE, name: NO_DEFAULT_VALUE }, touchEvents);
|
|
95
86
|
const Picker = {
|
|
96
87
|
mode: singleQuote('selector'),
|
|
97
88
|
disabled: NO_DEFAULT_VALUE,
|
|
@@ -254,6 +245,7 @@ const Slot = {
|
|
|
254
245
|
const NativeSlot = {
|
|
255
246
|
name: NO_DEFAULT_VALUE
|
|
256
247
|
};
|
|
248
|
+
const Script = {};
|
|
257
249
|
const internalComponents = {
|
|
258
250
|
View,
|
|
259
251
|
Icon,
|
|
@@ -295,6 +287,7 @@ const internalComponents = {
|
|
|
295
287
|
Slot,
|
|
296
288
|
SlotView,
|
|
297
289
|
NativeSlot,
|
|
290
|
+
Script,
|
|
298
291
|
};
|
|
299
292
|
const focusComponents = new Set([
|
|
300
293
|
'input',
|
|
@@ -329,7 +322,7 @@ const nestElements = new Map([
|
|
|
329
322
|
['form', 4],
|
|
330
323
|
['scroll-view', 4],
|
|
331
324
|
['swiper', 4],
|
|
332
|
-
['swiper-item', 4]
|
|
325
|
+
['swiper-item', 4],
|
|
333
326
|
]);
|
|
334
327
|
|
|
335
328
|
function isString(o) {
|
|
@@ -345,6 +338,20 @@ function isBooleanStringLiteral(o) {
|
|
|
345
338
|
return o === 'true' || o === 'false';
|
|
346
339
|
}
|
|
347
340
|
|
|
341
|
+
// 字符串简写
|
|
342
|
+
exports.Shortcuts = void 0;
|
|
343
|
+
(function (Shortcuts) {
|
|
344
|
+
Shortcuts["Container"] = "container";
|
|
345
|
+
Shortcuts["Childnodes"] = "cn";
|
|
346
|
+
Shortcuts["Text"] = "v";
|
|
347
|
+
Shortcuts["NodeType"] = "nt";
|
|
348
|
+
Shortcuts["NodeName"] = "nn";
|
|
349
|
+
// Attrtibutes
|
|
350
|
+
Shortcuts["Style"] = "st";
|
|
351
|
+
Shortcuts["Class"] = "cl";
|
|
352
|
+
Shortcuts["Src"] = "src";
|
|
353
|
+
})(exports.Shortcuts || (exports.Shortcuts = {}));
|
|
354
|
+
|
|
348
355
|
var PLATFORM_TYPE;
|
|
349
356
|
(function (PLATFORM_TYPE) {
|
|
350
357
|
PLATFORM_TYPE["MINI"] = "mini";
|
|
@@ -368,7 +375,7 @@ var PLATFORM_TYPE;
|
|
|
368
375
|
},
|
|
369
376
|
quickapp: {
|
|
370
377
|
type: PLATFORM_TYPE.QUICK
|
|
371
|
-
}
|
|
378
|
+
},
|
|
372
379
|
});
|
|
373
380
|
|
|
374
381
|
class Events {
|
|
@@ -489,7 +496,7 @@ const defaultMiniLifecycle = {
|
|
|
489
496
|
'onReachBottom',
|
|
490
497
|
'onPageScroll',
|
|
491
498
|
'onResize',
|
|
492
|
-
'defer:onTabItemTap',
|
|
499
|
+
'defer:onTabItemTap', // defer: 需要等页面组件挂载后再调用
|
|
493
500
|
'onTitleClick',
|
|
494
501
|
'onOptionMenuClick',
|
|
495
502
|
'onPopMenuClick',
|
|
@@ -576,6 +583,7 @@ new TaroHooks({
|
|
|
576
583
|
return this.call('getMiniLifecycle', defaultMiniLifecycle);
|
|
577
584
|
}),
|
|
578
585
|
getLifecycle: TaroHook(HOOK_TYPE.SINGLE, (instance, lifecycle) => instance[lifecycle]),
|
|
586
|
+
modifyRecursiveComponentConfig: TaroHook(HOOK_TYPE.SINGLE, (defaultConfig) => defaultConfig),
|
|
579
587
|
getPathIndex: TaroHook(HOOK_TYPE.SINGLE, indexOfNode => `[${indexOfNode}]`),
|
|
580
588
|
getEventCenter: TaroHook(HOOK_TYPE.SINGLE, Events => new Events()),
|
|
581
589
|
isBubbleEvents: TaroHook(HOOK_TYPE.SINGLE, eventName => {
|
|
@@ -607,6 +615,7 @@ new TaroHooks({
|
|
|
607
615
|
createPullDownComponent: TaroHook(HOOK_TYPE.SINGLE),
|
|
608
616
|
getDOMNode: TaroHook(HOOK_TYPE.SINGLE),
|
|
609
617
|
modifyHydrateData: TaroHook(HOOK_TYPE.SINGLE),
|
|
618
|
+
transferHydrateData: TaroHook(HOOK_TYPE.SINGLE),
|
|
610
619
|
modifySetAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
|
|
611
620
|
modifyRmAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
|
|
612
621
|
onAddEvent: TaroHook(HOOK_TYPE.SINGLE),
|
|
@@ -629,9 +638,13 @@ new TaroHooks({
|
|
|
629
638
|
node.dispatchEvent(e);
|
|
630
639
|
}),
|
|
631
640
|
dispatchTaroEventFinish: TaroHook(HOOK_TYPE.MULTI),
|
|
641
|
+
modifyTaroEventReturn: TaroHook(HOOK_TYPE.SINGLE, () => undefined),
|
|
632
642
|
modifyDispatchEvent: TaroHook(HOOK_TYPE.MULTI),
|
|
633
643
|
initNativeApi: TaroHook(HOOK_TYPE.MULTI),
|
|
634
|
-
patchElement: TaroHook(HOOK_TYPE.MULTI)
|
|
644
|
+
patchElement: TaroHook(HOOK_TYPE.MULTI),
|
|
645
|
+
modifyAddEventListener: TaroHook(HOOK_TYPE.SINGLE),
|
|
646
|
+
modifyRemoveEventListener: TaroHook(HOOK_TYPE.SINGLE),
|
|
647
|
+
getMemoryLevel: TaroHook(HOOK_TYPE.SINGLE),
|
|
635
648
|
});
|
|
636
649
|
|
|
637
650
|
function toDashed(s) {
|
|
@@ -750,6 +763,7 @@ class BaseTemplate {
|
|
|
750
763
|
this.exportExpr = 'module.exports =';
|
|
751
764
|
this.thirdPartyPatcher = {};
|
|
752
765
|
this.supportXS = false;
|
|
766
|
+
this.isXMLSupportRecursiveReference = true;
|
|
753
767
|
this.Adapter = weixinAdapter;
|
|
754
768
|
/** 组件列表 */
|
|
755
769
|
this.internalComponents = internalComponents;
|
|
@@ -759,28 +773,32 @@ class BaseTemplate {
|
|
|
759
773
|
this.voidElements = voidElements;
|
|
760
774
|
/** 可以递归调用自身的组件 */
|
|
761
775
|
this.nestElements = nestElements;
|
|
762
|
-
this.buildPageTemplate = (baseTempPath) => {
|
|
776
|
+
this.buildPageTemplate = (baseTempPath, _page) => {
|
|
763
777
|
const template = `<import src="${baseTempPath}"/>
|
|
764
778
|
<template is="taro_tmpl" data="{{${this.dataKeymap('root:root')}}}" />`;
|
|
765
779
|
return template;
|
|
766
780
|
};
|
|
767
781
|
this.buildBaseComponentTemplate = (ext) => {
|
|
768
782
|
const data = !this.isSupportRecursive && this.supportXS
|
|
769
|
-
? this.dataKeymap(
|
|
783
|
+
? this.dataKeymap(`i:i,c:1,l:xs.f('',i.${"nn" /* Shortcuts.NodeName */})`)
|
|
770
784
|
: this.isSupportRecursive
|
|
771
785
|
? this.dataKeymap('i:i')
|
|
772
786
|
: this.dataKeymap('i:i,c:1');
|
|
787
|
+
// 此处需要重新引入 xs 函数,否则会出现 ws.f() 在 comp.wxml 和 custom-wrapper.wxml 中永远返回 undefined 的问题 #14599
|
|
773
788
|
return `<import src="./base${ext}" />
|
|
789
|
+
${this.buildXsTemplate()}
|
|
774
790
|
<template is="{{'tmpl_0_' + i.nn}}" data="{{${data}}}" />`;
|
|
775
791
|
};
|
|
776
792
|
this.buildCustomComponentTemplate = (ext) => {
|
|
777
793
|
const Adapter = this.Adapter;
|
|
778
794
|
const data = !this.isSupportRecursive && this.supportXS
|
|
779
|
-
? `${this.dataKeymap(
|
|
795
|
+
? `${this.dataKeymap(`i:item,c:1,l:xs.f('',item.${"nn" /* Shortcuts.NodeName */})`)}`
|
|
780
796
|
: this.isSupportRecursive
|
|
781
797
|
? this.dataKeymap('i:item')
|
|
782
798
|
: this.dataKeymap('i:item,c:1');
|
|
799
|
+
// 此处需要重新引入 xs 函数,否则会出现 ws.f() 在 comp.wxml 和 custom-wrapper.wxml 中永远返回 undefined 的问题 #14599
|
|
783
800
|
return `<import src="./base${ext}" />
|
|
801
|
+
${this.buildXsTemplate()}
|
|
784
802
|
<block ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="sid">
|
|
785
803
|
<template is="{{'tmpl_0_' + item.nn}}" data="{{${data}}}" />
|
|
786
804
|
</block>`;
|
|
@@ -908,7 +926,7 @@ class BaseTemplate {
|
|
|
908
926
|
buildBaseTemplate() {
|
|
909
927
|
const Adapter = this.Adapter;
|
|
910
928
|
const data = !this.isSupportRecursive && this.supportXS
|
|
911
|
-
? `${this.dataKeymap(
|
|
929
|
+
? `${this.dataKeymap(`i:item,c:1,l:xs.f('',item.${"nn" /* Shortcuts.NodeName */})`)}`
|
|
912
930
|
: this.isSupportRecursive
|
|
913
931
|
? this.dataKeymap('i:item')
|
|
914
932
|
: this.dataKeymap('i:item,c:1');
|
|
@@ -933,10 +951,10 @@ class BaseTemplate {
|
|
|
933
951
|
if (value.indexOf('-') > -1) {
|
|
934
952
|
value = `:${value}`;
|
|
935
953
|
}
|
|
936
|
-
return str + `bind${value}="eh"
|
|
954
|
+
return str + ` bind${value}="eh"`;
|
|
937
955
|
}
|
|
938
956
|
else if (attr.startsWith('bind')) {
|
|
939
|
-
return str +
|
|
957
|
+
return str + ` ${attr}="eh"`;
|
|
940
958
|
}
|
|
941
959
|
else if (attr.startsWith('on')) {
|
|
942
960
|
// react, vue3
|
|
@@ -945,22 +963,22 @@ class BaseTemplate {
|
|
|
945
963
|
// 兼容如 vant 某些组件的 bind:a-b 这类属性
|
|
946
964
|
value = `:${value}`;
|
|
947
965
|
}
|
|
948
|
-
return str + `bind${value}="eh"
|
|
966
|
+
return str + ` bind${value}="eh"`;
|
|
949
967
|
}
|
|
950
968
|
else if (attr === 'class') {
|
|
951
|
-
return str + `class="{{i.${"cl" /* Shortcuts.Class */}}}"
|
|
969
|
+
return str + ` class="{{i.${"cl" /* Shortcuts.Class */}}}"`;
|
|
952
970
|
}
|
|
953
971
|
else if (attr === 'style') {
|
|
954
|
-
return str + `style="{{i.${"st" /* Shortcuts.Style */}}}"
|
|
972
|
+
return str + ` style="{{i.${"st" /* Shortcuts.Style */}}}"`;
|
|
955
973
|
}
|
|
956
974
|
const patchValue = patcher[attr];
|
|
957
975
|
if (isBooleanStringLiteral(patchValue) || isNumber(patchValue) || isString(patchValue)) {
|
|
958
976
|
const propValue = this.supportXS
|
|
959
977
|
? `xs.b(i.${toCamelCase(attr)},${patchValue})`
|
|
960
978
|
: `i.${toCamelCase(attr)}===undefined?${patchValue}:i.${toCamelCase(attr)}`;
|
|
961
|
-
return str +
|
|
979
|
+
return str + ` ${attr}="{{${propValue}}}"`;
|
|
962
980
|
}
|
|
963
|
-
return str +
|
|
981
|
+
return str + ` ${attr}="{{i.${toCamelCase(attr)}}}"`;
|
|
964
982
|
}, '');
|
|
965
983
|
}
|
|
966
984
|
buildComponentTemplate(comp, level) {
|
|
@@ -984,6 +1002,8 @@ class BaseTemplate {
|
|
|
984
1002
|
}
|
|
985
1003
|
else {
|
|
986
1004
|
const data = isUseXs
|
|
1005
|
+
// TODO: 此处直接 c+1,不是最优解,变量 c 的作用是监测组件嵌套的层级是否大于 baselevel
|
|
1006
|
+
// 但目前的监测方法用于所有组件嵌套的总和,应该分开组件计算,单个组件嵌套层级大于 baselevel 时,再进入 comp 组件中进行新的嵌套
|
|
987
1007
|
? `${this.dataKeymap(`i:item,c:c+1,l:xs.f(l,item.${"nn" /* Shortcuts.NodeName */})`)}`
|
|
988
1008
|
: this.isSupportRecursive
|
|
989
1009
|
? `${this.dataKeymap('i:item')}`
|
|
@@ -1106,13 +1126,16 @@ class BaseTemplate {
|
|
|
1106
1126
|
if (isFunction(this.modifyThirdPartyLoopBody)) {
|
|
1107
1127
|
child = this.modifyThirdPartyLoopBody(child, compName);
|
|
1108
1128
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1129
|
+
const children = this.voidElements.has(compName)
|
|
1130
|
+
? ''
|
|
1131
|
+
: `
|
|
1112
1132
|
<block ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="sid">
|
|
1113
1133
|
${child}
|
|
1114
1134
|
</block>
|
|
1115
|
-
|
|
1135
|
+
`;
|
|
1136
|
+
template += `
|
|
1137
|
+
<template name="tmpl_${level}_${compName}">
|
|
1138
|
+
<${compName} ${this.buildThirdPartyAttr(attrs, this.thirdPartyPatcher[compName] || {})} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">${children}</${compName}>
|
|
1116
1139
|
</template>
|
|
1117
1140
|
`;
|
|
1118
1141
|
}
|
|
@@ -1142,7 +1165,7 @@ class BaseTemplate {
|
|
|
1142
1165
|
getAttrValue(value, _key, _nodeName) {
|
|
1143
1166
|
return `{${value}}`;
|
|
1144
1167
|
}
|
|
1145
|
-
buildXsTemplate() {
|
|
1168
|
+
buildXsTemplate(_filePath) {
|
|
1146
1169
|
return '';
|
|
1147
1170
|
}
|
|
1148
1171
|
mergeComponents(ctx, patch) {
|
|
@@ -1269,6 +1292,7 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
1269
1292
|
const listA = Array.from(isLoopCompsSet).map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
|
|
1270
1293
|
const listB = hasMaxComps.map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
|
|
1271
1294
|
const containerLevel = this.baseLevel - 1;
|
|
1295
|
+
// l >= containerLevel 是为了避免 baselevel 倒数两三层几层组件恰好不是 listA 中的组件,而最后一个组件又刚好是 listA 的组件,导致出现 l >= baselevel 却没有走入新的嵌套循环的问题 #14883
|
|
1272
1296
|
return `function (l, n, s) {
|
|
1273
1297
|
var a = ${JSON.stringify(listA)}
|
|
1274
1298
|
var b = ${JSON.stringify(listB)}
|
|
@@ -1283,7 +1307,7 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
1283
1307
|
}
|
|
1284
1308
|
l = depth
|
|
1285
1309
|
}
|
|
1286
|
-
if (l
|
|
1310
|
+
if (l >= ${containerLevel}) {
|
|
1287
1311
|
return 'tmpl_${containerLevel}_${"container" /* Shortcuts.Container */}'
|
|
1288
1312
|
}
|
|
1289
1313
|
return 'tmpl_' + l + '_' + n
|