@tarojs/shared 3.5.0-beta.0 → 3.5.0-beta.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/event-emitter.d.ts +27 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +311 -28
- package/dist/index.js.map +1 -1
- package/dist/runtime-hooks.d.ts +119 -0
- package/dist/shared.esm.js +306 -27
- package/dist/shared.esm.js.map +1 -1
- package/dist/template.d.ts +6 -2
- package/dist/template.js +331 -25
- package/dist/template.js.map +1 -1
- package/dist/utils.d.ts +5 -4
- 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,
|
|
@@ -328,6 +328,9 @@ const nestElements = new Map([
|
|
|
328
328
|
['swiper-item', 4]
|
|
329
329
|
]);
|
|
330
330
|
|
|
331
|
+
function isString(o) {
|
|
332
|
+
return typeof o === 'string';
|
|
333
|
+
}
|
|
331
334
|
function isFunction(o) {
|
|
332
335
|
return typeof o === 'function';
|
|
333
336
|
}
|
|
@@ -338,6 +341,239 @@ function isBooleanStringLiteral(o) {
|
|
|
338
341
|
return o === 'true' || o === 'false';
|
|
339
342
|
}
|
|
340
343
|
|
|
344
|
+
class Events {
|
|
345
|
+
constructor(opts) {
|
|
346
|
+
var _a;
|
|
347
|
+
this.callbacks = (_a = opts === null || opts === void 0 ? void 0 : opts.callbacks) !== null && _a !== void 0 ? _a : {};
|
|
348
|
+
}
|
|
349
|
+
on(eventName, callback, context) {
|
|
350
|
+
let event, node, tail, list;
|
|
351
|
+
if (!callback) {
|
|
352
|
+
return this;
|
|
353
|
+
}
|
|
354
|
+
eventName = eventName.split(Events.eventSplitter);
|
|
355
|
+
this.callbacks || (this.callbacks = {});
|
|
356
|
+
const calls = this.callbacks;
|
|
357
|
+
while ((event = eventName.shift())) {
|
|
358
|
+
list = calls[event];
|
|
359
|
+
node = list ? list.tail : {};
|
|
360
|
+
node.next = tail = {};
|
|
361
|
+
node.context = context;
|
|
362
|
+
node.callback = callback;
|
|
363
|
+
calls[event] = {
|
|
364
|
+
tail,
|
|
365
|
+
next: list ? list.next : node
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
return this;
|
|
369
|
+
}
|
|
370
|
+
once(events, callback, context) {
|
|
371
|
+
const wrapper = (...args) => {
|
|
372
|
+
callback.apply(this, args);
|
|
373
|
+
this.off(events, wrapper, context);
|
|
374
|
+
};
|
|
375
|
+
this.on(events, wrapper, context);
|
|
376
|
+
return this;
|
|
377
|
+
}
|
|
378
|
+
off(events, callback, context) {
|
|
379
|
+
let event, calls, node, tail, cb, ctx;
|
|
380
|
+
if (!(calls = this.callbacks)) {
|
|
381
|
+
return this;
|
|
382
|
+
}
|
|
383
|
+
if (!(events || callback || context)) {
|
|
384
|
+
delete this.callbacks;
|
|
385
|
+
return this;
|
|
386
|
+
}
|
|
387
|
+
events = events ? events.split(Events.eventSplitter) : Object.keys(calls);
|
|
388
|
+
while ((event = events.shift())) {
|
|
389
|
+
node = calls[event];
|
|
390
|
+
delete calls[event];
|
|
391
|
+
if (!node || !(callback || context)) {
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
tail = node.tail;
|
|
395
|
+
while ((node = node.next) !== tail) {
|
|
396
|
+
cb = node.callback;
|
|
397
|
+
ctx = node.context;
|
|
398
|
+
if ((callback && cb !== callback) || (context && ctx !== context)) {
|
|
399
|
+
this.on(event, cb, ctx);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return this;
|
|
404
|
+
}
|
|
405
|
+
trigger(events) {
|
|
406
|
+
let event, node, calls, tail;
|
|
407
|
+
if (!(calls = this.callbacks)) {
|
|
408
|
+
return this;
|
|
409
|
+
}
|
|
410
|
+
events = events.split(Events.eventSplitter);
|
|
411
|
+
const rest = [].slice.call(arguments, 1);
|
|
412
|
+
while ((event = events.shift())) {
|
|
413
|
+
if ((node = calls[event])) {
|
|
414
|
+
tail = node.tail;
|
|
415
|
+
while ((node = node.next) !== tail) {
|
|
416
|
+
node.callback.apply(node.context || this, rest);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return this;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
Events.eventSplitter = /\s+/;
|
|
424
|
+
|
|
425
|
+
var HOOK_TYPE;
|
|
426
|
+
(function (HOOK_TYPE) {
|
|
427
|
+
HOOK_TYPE[HOOK_TYPE["SINGLE"] = 0] = "SINGLE";
|
|
428
|
+
HOOK_TYPE[HOOK_TYPE["MULTI"] = 1] = "MULTI";
|
|
429
|
+
HOOK_TYPE[HOOK_TYPE["WATERFALL"] = 2] = "WATERFALL";
|
|
430
|
+
})(HOOK_TYPE || (HOOK_TYPE = {}));
|
|
431
|
+
const defaultMiniLifecycle = {
|
|
432
|
+
app: [
|
|
433
|
+
'onLaunch',
|
|
434
|
+
'onShow',
|
|
435
|
+
'onHide'
|
|
436
|
+
],
|
|
437
|
+
page: [
|
|
438
|
+
'onLoad',
|
|
439
|
+
'onUnload',
|
|
440
|
+
'onReady',
|
|
441
|
+
'onShow',
|
|
442
|
+
'onHide',
|
|
443
|
+
[
|
|
444
|
+
'onPullDownRefresh',
|
|
445
|
+
'onReachBottom',
|
|
446
|
+
'onPageScroll',
|
|
447
|
+
'onResize',
|
|
448
|
+
'onTabItemTap',
|
|
449
|
+
'onTitleClick',
|
|
450
|
+
'onOptionMenuClick',
|
|
451
|
+
'onPopMenuClick',
|
|
452
|
+
'onPullIntercept',
|
|
453
|
+
'onAddToFavorites'
|
|
454
|
+
]
|
|
455
|
+
]
|
|
456
|
+
};
|
|
457
|
+
function TaroHook(type, initial) {
|
|
458
|
+
return {
|
|
459
|
+
type,
|
|
460
|
+
initial: initial || null
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
class TaroHooks extends Events {
|
|
464
|
+
constructor(hooks, opts) {
|
|
465
|
+
super(opts);
|
|
466
|
+
this.hooks = hooks;
|
|
467
|
+
for (const hookName in hooks) {
|
|
468
|
+
const { initial } = hooks[hookName];
|
|
469
|
+
if (isFunction(initial)) {
|
|
470
|
+
this.on(hookName, initial);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
tapOneOrMany(hookName, callback) {
|
|
475
|
+
const list = isFunction(callback) ? [callback] : callback;
|
|
476
|
+
list.forEach(cb => this.on(hookName, cb));
|
|
477
|
+
}
|
|
478
|
+
tap(hookName, callback) {
|
|
479
|
+
const hooks = this.hooks;
|
|
480
|
+
const { type, initial } = hooks[hookName];
|
|
481
|
+
if (type === HOOK_TYPE.SINGLE) {
|
|
482
|
+
this.off(hookName);
|
|
483
|
+
this.on(hookName, isFunction(callback) ? callback : callback[callback.length - 1]);
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
initial && this.off(hookName, initial);
|
|
487
|
+
this.tapOneOrMany(hookName, callback);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
call(hookName, ...rest) {
|
|
491
|
+
var _a;
|
|
492
|
+
const hook = this.hooks[hookName];
|
|
493
|
+
if (!hook)
|
|
494
|
+
return;
|
|
495
|
+
const { type } = hook;
|
|
496
|
+
const calls = this.callbacks;
|
|
497
|
+
if (!calls)
|
|
498
|
+
return;
|
|
499
|
+
const list = calls[hookName];
|
|
500
|
+
if (list) {
|
|
501
|
+
const tail = list.tail;
|
|
502
|
+
let node = list.next;
|
|
503
|
+
let args = rest;
|
|
504
|
+
let res;
|
|
505
|
+
while (node !== tail) {
|
|
506
|
+
res = (_a = node.callback) === null || _a === void 0 ? void 0 : _a.apply(node.context || this, args);
|
|
507
|
+
if (type === HOOK_TYPE.WATERFALL) {
|
|
508
|
+
const params = [res];
|
|
509
|
+
args = params;
|
|
510
|
+
}
|
|
511
|
+
node = node.next;
|
|
512
|
+
}
|
|
513
|
+
return res;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
isExist(hookName) {
|
|
517
|
+
var _a;
|
|
518
|
+
return Boolean((_a = this.callbacks) === null || _a === void 0 ? void 0 : _a[hookName]);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
new TaroHooks({
|
|
522
|
+
getMiniLifecycle: TaroHook(HOOK_TYPE.SINGLE, defaultConfig => defaultConfig),
|
|
523
|
+
getMiniLifecycleImpl: TaroHook(HOOK_TYPE.SINGLE, function () {
|
|
524
|
+
return this.call('getMiniLifecycle', defaultMiniLifecycle);
|
|
525
|
+
}),
|
|
526
|
+
getLifecycle: TaroHook(HOOK_TYPE.SINGLE, (instance, lifecycle) => instance[lifecycle]),
|
|
527
|
+
getPathIndex: TaroHook(HOOK_TYPE.SINGLE, indexOfNode => `[${indexOfNode}]`),
|
|
528
|
+
getEventCenter: TaroHook(HOOK_TYPE.SINGLE, Events => new Events()),
|
|
529
|
+
isBubbleEvents: TaroHook(HOOK_TYPE.SINGLE, eventName => {
|
|
530
|
+
/**
|
|
531
|
+
* 支持冒泡的事件, 除 支付宝小程序外,其余的可冒泡事件都和微信保持一致
|
|
532
|
+
* 详见 见 https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/event.html
|
|
533
|
+
*/
|
|
534
|
+
const BUBBLE_EVENTS = new Set([
|
|
535
|
+
'touchstart',
|
|
536
|
+
'touchmove',
|
|
537
|
+
'touchcancel',
|
|
538
|
+
'touchend',
|
|
539
|
+
'touchforcechange',
|
|
540
|
+
'tap',
|
|
541
|
+
'longpress',
|
|
542
|
+
'longtap',
|
|
543
|
+
'transitionend',
|
|
544
|
+
'animationstart',
|
|
545
|
+
'animationiteration',
|
|
546
|
+
'animationend'
|
|
547
|
+
]);
|
|
548
|
+
return BUBBLE_EVENTS.has(eventName);
|
|
549
|
+
}),
|
|
550
|
+
getSpecialNodes: TaroHook(HOOK_TYPE.SINGLE, () => ['view', 'text', 'image']),
|
|
551
|
+
onRemoveAttribute: TaroHook(HOOK_TYPE.SINGLE),
|
|
552
|
+
batchedEventUpdates: TaroHook(HOOK_TYPE.SINGLE),
|
|
553
|
+
mergePageInstance: TaroHook(HOOK_TYPE.SINGLE),
|
|
554
|
+
modifyPageObject: TaroHook(HOOK_TYPE.SINGLE),
|
|
555
|
+
createPullDownComponent: TaroHook(HOOK_TYPE.SINGLE),
|
|
556
|
+
getDOMNode: TaroHook(HOOK_TYPE.SINGLE),
|
|
557
|
+
modifyHydrateData: TaroHook(HOOK_TYPE.SINGLE),
|
|
558
|
+
modifySetAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
|
|
559
|
+
modifyRmAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
|
|
560
|
+
onAddEvent: TaroHook(HOOK_TYPE.SINGLE),
|
|
561
|
+
modifyMpEvent: TaroHook(HOOK_TYPE.MULTI),
|
|
562
|
+
modifyMpEventImpl: TaroHook(HOOK_TYPE.SINGLE, function (e) {
|
|
563
|
+
try {
|
|
564
|
+
// 有些小程序的事件对象的某些属性只读
|
|
565
|
+
this.call('modifyMpEvent', e);
|
|
566
|
+
}
|
|
567
|
+
catch (error) {
|
|
568
|
+
console.warn('[Taro modifyMpEvent hook Error]: ', error);
|
|
569
|
+
}
|
|
570
|
+
}),
|
|
571
|
+
modifyTaroEvent: TaroHook(HOOK_TYPE.MULTI),
|
|
572
|
+
modifyDispatchEvent: TaroHook(HOOK_TYPE.MULTI),
|
|
573
|
+
initNativeApi: TaroHook(HOOK_TYPE.MULTI),
|
|
574
|
+
patchElement: TaroHook(HOOK_TYPE.MULTI)
|
|
575
|
+
});
|
|
576
|
+
|
|
341
577
|
function toDashed(s) {
|
|
342
578
|
return s.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
343
579
|
}
|
|
@@ -364,6 +600,45 @@ function capitalize(s) {
|
|
|
364
600
|
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
365
601
|
const hasOwn = (val, key) => hasOwnProperty.call(val, key);
|
|
366
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
|
+
}
|
|
367
642
|
function indent(str, size) {
|
|
368
643
|
return str.split('\n')
|
|
369
644
|
.map((line, index) => {
|
|
@@ -408,6 +683,7 @@ class BaseTemplate {
|
|
|
408
683
|
constructor() {
|
|
409
684
|
this.exportExpr = 'module.exports =';
|
|
410
685
|
this.supportXS = false;
|
|
686
|
+
this.thirdPartyPatcher = {};
|
|
411
687
|
this.Adapter = weixinAdapter;
|
|
412
688
|
/** 组件列表 */
|
|
413
689
|
this.internalComponents = internalComponents;
|
|
@@ -461,7 +737,7 @@ class BaseTemplate {
|
|
|
461
737
|
.map(k => `${k}="${k.startsWith('bind') || k.startsWith('on') || k.startsWith('catch') ? attrs[k] : `{${this.getAttrValue(attrs[k], k, nodeName)}}`}" `)
|
|
462
738
|
.join('');
|
|
463
739
|
}
|
|
464
|
-
replacePropName(name, value, _componentName) {
|
|
740
|
+
replacePropName(name, value, _componentName, _componentAlias) {
|
|
465
741
|
if (value === 'eh')
|
|
466
742
|
return name.toLowerCase();
|
|
467
743
|
return name;
|
|
@@ -473,6 +749,7 @@ class BaseTemplate {
|
|
|
473
749
|
let component = components[key];
|
|
474
750
|
const compName = toDashed(key);
|
|
475
751
|
const newComp = Object.create(null);
|
|
752
|
+
const componentAlias = this.componentsAlias[compName];
|
|
476
753
|
if (isFunction(this.modifyCompProps)) {
|
|
477
754
|
component = this.modifyCompProps(compName, component);
|
|
478
755
|
}
|
|
@@ -483,17 +760,23 @@ class BaseTemplate {
|
|
|
483
760
|
propValue = 'eh';
|
|
484
761
|
}
|
|
485
762
|
else if (propValue === '') {
|
|
486
|
-
|
|
763
|
+
const propInCamelCase = toCamelCase(prop);
|
|
764
|
+
const propAlias = componentAlias[propInCamelCase] || propInCamelCase;
|
|
765
|
+
propValue = `i.${propAlias}`;
|
|
487
766
|
}
|
|
488
767
|
else if (isBooleanStringLiteral(propValue) || isNumber(+propValue)) {
|
|
768
|
+
const propInCamelCase = toCamelCase(prop);
|
|
769
|
+
const propAlias = componentAlias[propInCamelCase] || propInCamelCase;
|
|
489
770
|
propValue = this.supportXS
|
|
490
|
-
? `xs.b(i.${
|
|
491
|
-
: `i.${
|
|
771
|
+
? `xs.b(i.${propAlias},${propValue})`
|
|
772
|
+
: `i.${propAlias}===undefined?${propValue}:i.${propAlias}`;
|
|
492
773
|
}
|
|
493
774
|
else {
|
|
494
|
-
|
|
775
|
+
const propInCamelCase = toCamelCase(prop);
|
|
776
|
+
const propAlias = componentAlias[propInCamelCase] || propInCamelCase;
|
|
777
|
+
propValue = `i.${propAlias}||${propValue || singleQuote('')}`;
|
|
495
778
|
}
|
|
496
|
-
prop = this.replacePropName(prop, propValue, compName);
|
|
779
|
+
prop = this.replacePropName(prop, propValue, compName, componentAlias);
|
|
497
780
|
newComp[prop] = propValue;
|
|
498
781
|
}
|
|
499
782
|
}
|
|
@@ -553,7 +836,7 @@ class BaseTemplate {
|
|
|
553
836
|
</template>
|
|
554
837
|
`;
|
|
555
838
|
}
|
|
556
|
-
buildThirdPartyAttr(attrs) {
|
|
839
|
+
buildThirdPartyAttr(attrs, patcher = {}) {
|
|
557
840
|
return Array.from(attrs).reduce((str, attr) => {
|
|
558
841
|
if (attr.startsWith('@')) {
|
|
559
842
|
// vue2
|
|
@@ -581,6 +864,13 @@ class BaseTemplate {
|
|
|
581
864
|
else if (attr === 'style') {
|
|
582
865
|
return str + `style="{{i.${"st" /* Style */}}}" `;
|
|
583
866
|
}
|
|
867
|
+
const patchValue = patcher[attr];
|
|
868
|
+
if (isBooleanStringLiteral(patchValue) || isNumber(patchValue) || isString(patchValue)) {
|
|
869
|
+
const propValue = this.supportXS
|
|
870
|
+
? `xs.b(i.${toCamelCase(attr)},${patchValue})`
|
|
871
|
+
: `i.${toCamelCase(attr)}===undefined?${patchValue}:i.${toCamelCase(attr)}`;
|
|
872
|
+
return str + `${attr}="{{${propValue}}}" `;
|
|
873
|
+
}
|
|
584
874
|
return str + `${attr}="{{i.${toCamelCase(attr)}}}" `;
|
|
585
875
|
}, '');
|
|
586
876
|
}
|
|
@@ -615,31 +905,34 @@ class BaseTemplate {
|
|
|
615
905
|
}
|
|
616
906
|
buildFocusComponentTemplte(comp, level) {
|
|
617
907
|
const children = this.getChildren(comp, level);
|
|
908
|
+
const nodeName = comp.nodeName;
|
|
909
|
+
const nodeAlias = comp.nodeAlias;
|
|
618
910
|
const attrs = Object.assign({}, comp.attributes);
|
|
619
911
|
const templateName = this.supportXS
|
|
620
912
|
? `xs.c(i, 'tmpl_${level}_')`
|
|
621
|
-
: `i.focus ? 'tmpl_${level}_${
|
|
913
|
+
: `i.focus ? 'tmpl_${level}_${nodeAlias}_focus' : 'tmpl_${level}_${nodeAlias}_blur'`;
|
|
622
914
|
delete attrs.focus;
|
|
623
915
|
let res = `
|
|
624
|
-
<template name="tmpl_${level}_${
|
|
916
|
+
<template name="tmpl_${level}_${nodeAlias}">
|
|
625
917
|
<template is="{{${templateName}}}" data="{{${this.dataKeymap('i:i')}${children ? ',cid:cid' : ''}}}" />
|
|
626
918
|
</template>
|
|
627
919
|
|
|
628
|
-
<template name="tmpl_${level}_${
|
|
629
|
-
<${
|
|
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}>
|
|
630
922
|
</template>
|
|
631
923
|
|
|
632
|
-
<template name="tmpl_${level}_${
|
|
633
|
-
<${
|
|
924
|
+
<template name="tmpl_${level}_${nodeAlias}_blur">
|
|
925
|
+
<${nodeName} ${this.buildAttribute(attrs, nodeName)} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">${children}</${nodeName}>
|
|
634
926
|
</template>
|
|
635
927
|
`;
|
|
636
928
|
if (isFunction(this.modifyTemplateResult)) {
|
|
637
|
-
res = this.modifyTemplateResult(res,
|
|
929
|
+
res = this.modifyTemplateResult(res, nodeName, level, children);
|
|
638
930
|
}
|
|
639
931
|
return res;
|
|
640
932
|
}
|
|
641
933
|
buildStandardComponentTemplate(comp, level) {
|
|
642
934
|
const children = this.getChildren(comp, level);
|
|
935
|
+
const nodeAlias = comp.nodeAlias;
|
|
643
936
|
let nodeName = '';
|
|
644
937
|
switch (comp.nodeName) {
|
|
645
938
|
case 'slot':
|
|
@@ -660,7 +953,7 @@ class BaseTemplate {
|
|
|
660
953
|
break;
|
|
661
954
|
}
|
|
662
955
|
let res = `
|
|
663
|
-
<template name="tmpl_${level}_${
|
|
956
|
+
<template name="tmpl_${level}_${nodeAlias}">
|
|
664
957
|
<${nodeName} ${this.buildAttribute(comp.attributes, comp.nodeName)} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">${children}</${nodeName}>
|
|
665
958
|
</template>
|
|
666
959
|
`;
|
|
@@ -671,7 +964,7 @@ class BaseTemplate {
|
|
|
671
964
|
}
|
|
672
965
|
buildPlainTextTemplate(level) {
|
|
673
966
|
return `
|
|
674
|
-
<template name="tmpl_${level}_#text">
|
|
967
|
+
<template name="tmpl_${level}_${this.componentsAlias['#text']._num}">
|
|
675
968
|
<block>{{i.${"v" /* Text */}}}</block>
|
|
676
969
|
</template>
|
|
677
970
|
`;
|
|
@@ -703,7 +996,7 @@ class BaseTemplate {
|
|
|
703
996
|
}
|
|
704
997
|
template += `
|
|
705
998
|
<template name="tmpl_${level}_${compName}">
|
|
706
|
-
<${compName} ${this.buildThirdPartyAttr(attrs)} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">
|
|
999
|
+
<${compName} ${this.buildThirdPartyAttr(attrs, this.thirdPartyPatcher[compName] || {})} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">
|
|
707
1000
|
<block ${Adapter.for}="{{i.${"cn" /* Childnodes */}}}" ${Adapter.key}="sid">
|
|
708
1001
|
${child}
|
|
709
1002
|
</block>
|
|
@@ -756,6 +1049,9 @@ class BaseTemplate {
|
|
|
756
1049
|
mergeComponents(ctx, patch) {
|
|
757
1050
|
ctx.helper.recursiveMerge(this.internalComponents, patch);
|
|
758
1051
|
}
|
|
1052
|
+
mergeThirdPartyComponents(patch) {
|
|
1053
|
+
this.thirdPartyPatcher = patch;
|
|
1054
|
+
}
|
|
759
1055
|
buildXSTmplName() {
|
|
760
1056
|
return `function (l, n) {
|
|
761
1057
|
return 'tmpl_' + l + '_' + n
|
|
@@ -778,6 +1074,7 @@ class RecursiveTemplate extends BaseTemplate {
|
|
|
778
1074
|
this.buildTemplate = (componentConfig) => {
|
|
779
1075
|
let template = this.buildBaseTemplate();
|
|
780
1076
|
if (!this.miniComponents) {
|
|
1077
|
+
this.componentsAlias = getComponentsAlias(this.internalComponents);
|
|
781
1078
|
this.miniComponents = this.createMiniComponents(this.internalComponents);
|
|
782
1079
|
}
|
|
783
1080
|
const ZERO_FLOOR = 0;
|
|
@@ -785,7 +1082,8 @@ class RecursiveTemplate extends BaseTemplate {
|
|
|
785
1082
|
.filter(c => componentConfig.includes.size && !componentConfig.includeAll ? componentConfig.includes.has(c) : true);
|
|
786
1083
|
template = components.reduce((current, nodeName) => {
|
|
787
1084
|
const attributes = this.miniComponents[nodeName];
|
|
788
|
-
|
|
1085
|
+
const nodeAlias = this.componentsAlias[nodeName]._num;
|
|
1086
|
+
return current + this.buildComponentTemplate({ nodeName, nodeAlias, attributes }, ZERO_FLOOR);
|
|
789
1087
|
}, template);
|
|
790
1088
|
template += this.buildPlainTextTemplate(ZERO_FLOOR);
|
|
791
1089
|
template += this.buildThirdPartyTemplate(ZERO_FLOOR, componentConfig);
|
|
@@ -802,6 +1100,7 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
802
1100
|
this.buildTemplate = (componentConfig) => {
|
|
803
1101
|
this.componentConfig = componentConfig;
|
|
804
1102
|
if (!this.miniComponents) {
|
|
1103
|
+
this.componentsAlias = getComponentsAlias(this.internalComponents);
|
|
805
1104
|
this.miniComponents = this.createMiniComponents(this.internalComponents);
|
|
806
1105
|
}
|
|
807
1106
|
const components = Object.keys(this.miniComponents)
|
|
@@ -826,7 +1125,8 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
826
1125
|
return this.buildContainerTemplate(level, restart);
|
|
827
1126
|
let template = components.reduce((current, nodeName) => {
|
|
828
1127
|
const attributes = this.miniComponents[nodeName];
|
|
829
|
-
|
|
1128
|
+
const nodeAlias = this.componentsAlias[nodeName]._num;
|
|
1129
|
+
return current + this.buildComponentTemplate({ nodeName, nodeAlias, attributes }, level);
|
|
830
1130
|
}, '');
|
|
831
1131
|
template += this.buildPlainTextTemplate(level);
|
|
832
1132
|
template += this.buildThirdPartyTemplate(level, this.componentConfig);
|
|
@@ -851,7 +1151,8 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
851
1151
|
}
|
|
852
1152
|
}
|
|
853
1153
|
const attributes = this.miniComponents[nodeName];
|
|
854
|
-
|
|
1154
|
+
const nodeAlias = this.componentsAlias[nodeName]._num;
|
|
1155
|
+
return current + this.buildComponentTemplate({ nodeName, nodeAlias, attributes }, level);
|
|
855
1156
|
}, '');
|
|
856
1157
|
if (level === 0)
|
|
857
1158
|
template += this.buildPlainTextTemplate(level);
|
|
@@ -874,9 +1175,12 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
874
1175
|
isLoopCompsSet.delete(comp);
|
|
875
1176
|
}
|
|
876
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; });
|
|
877
1181
|
return `function (l, n, s) {
|
|
878
|
-
var a = ${JSON.stringify(
|
|
879
|
-
var b = ${JSON.stringify(
|
|
1182
|
+
var a = ${JSON.stringify(listA)}
|
|
1183
|
+
var b = ${JSON.stringify(listB)}
|
|
880
1184
|
if (a.indexOf(n) === -1) {
|
|
881
1185
|
l = 0
|
|
882
1186
|
}
|
|
@@ -897,8 +1201,10 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
897
1201
|
if (max > 1)
|
|
898
1202
|
hasMaxComps.push(comp);
|
|
899
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; });
|
|
900
1206
|
return `f: function (l, n) {
|
|
901
|
-
var b = ${JSON.stringify(
|
|
1207
|
+
var b = ${JSON.stringify(listA)}
|
|
902
1208
|
if (b.indexOf(n) > -1) {
|
|
903
1209
|
if (l) l += ','
|
|
904
1210
|
l += n
|