efront 4.11.1 → 4.11.2
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/coms/compile/Program.js +9 -2
- package/coms/compile//347/264/240/351/246/250.js +25 -19
- package/coms/compile//347/264/240/351/246/250_test.js +1 -0
- package/coms/docs/codetext.xht +1 -0
- package/coms/frame/chat.js +1 -1
- package/coms/kugou/api.js +1 -1
- package/coms/kugou/player.js +3 -0
- package/coms/zimoli/addClass.js +19 -16
- package/coms/zimoli/css.js +12 -1
- package/coms/zimoli/getGenerator.js +9 -15
- package/coms/zimoli/menuList.js +29 -23
- package/coms/zimoli/on.js +8 -0
- package/coms/zimoli/removeClass.js +4 -6
- package/coms/zimoli/render.js +122 -64
- package/coms/zimoli/table.js +2 -0
- package/coms/zimoli/vbox.js +2 -1
- package/package.json +1 -1
- package/public/efront.js +1 -1
package/coms/zimoli/render.js
CHANGED
|
@@ -155,11 +155,11 @@ class Repeater {
|
|
|
155
155
|
this.trackBy = trackBy;
|
|
156
156
|
this.srcName = srcName;
|
|
157
157
|
}
|
|
158
|
-
createScope(item, k, i) {
|
|
158
|
+
createScope(item, k, i, wraped) {
|
|
159
159
|
var scope = {
|
|
160
160
|
$key: k,
|
|
161
|
-
$item: item,
|
|
162
|
-
$index: i
|
|
161
|
+
$item: wraped || item,
|
|
162
|
+
$index: i,
|
|
163
163
|
};
|
|
164
164
|
if (this.keyName !== "$key") {
|
|
165
165
|
scope[this.keyName] = k;
|
|
@@ -389,6 +389,13 @@ var parseIfWithRepeat = function (ifExpression, repeatExpression) {
|
|
|
389
389
|
};
|
|
390
390
|
};
|
|
391
391
|
|
|
392
|
+
var mountElementIds = function (element) {
|
|
393
|
+
var scope = element.$scope;
|
|
394
|
+
for (var id of element.$struct.ids) {
|
|
395
|
+
if (scope[id] && scope[id] !== element) throw new Error(i18n`同一个id不能使用两次:` + id);
|
|
396
|
+
scope[id] = element;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
392
399
|
var renderStructure = function (element) {
|
|
393
400
|
var $struct = element.$struct;
|
|
394
401
|
if ($struct.if) var { name: ifkey, key, value: ifexp } = $struct.if;
|
|
@@ -462,6 +469,37 @@ var createBinder = function (binder) {
|
|
|
462
469
|
|
|
463
470
|
}
|
|
464
471
|
}
|
|
472
|
+
var createMapper = function (write, mapper) {
|
|
473
|
+
return function (search) {
|
|
474
|
+
var getter = isArray(search) ? search.map(s => createGetter(this, s)) : createGetter(this, search);
|
|
475
|
+
var oldValue = mapper();
|
|
476
|
+
this.$renders.push(function () {
|
|
477
|
+
var value = mapper(isArray(getter) ? getter.map(g => g(this)) : getter(this));
|
|
478
|
+
var changes = getChanges(value, oldValue);
|
|
479
|
+
if (!changes) return;
|
|
480
|
+
oldValue = value;
|
|
481
|
+
var targetValue = Object.create(null);
|
|
482
|
+
for (var k in changes) {
|
|
483
|
+
targetValue[k] = !isHandled(value[k]) ? "" : value[k];
|
|
484
|
+
}
|
|
485
|
+
write(this, targetValue);
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
var createBinder2 = function (write, read) {
|
|
490
|
+
return function (search) {
|
|
491
|
+
var getter = createGetter(this, search);
|
|
492
|
+
var oldValue = isFunction(read) ? read(this) : undefined;
|
|
493
|
+
this.$renders.push(function () {
|
|
494
|
+
var value = getter(this);
|
|
495
|
+
if (shallowEqual(value, oldValue)) return;
|
|
496
|
+
var oldv = oldValue;
|
|
497
|
+
oldValue = value;
|
|
498
|
+
if (!isHandled(value)) value = '';
|
|
499
|
+
write(this, value, oldv);
|
|
500
|
+
});
|
|
501
|
+
};
|
|
502
|
+
}
|
|
465
503
|
|
|
466
504
|
var src2 = function (search) {
|
|
467
505
|
var getter = createGetter(this, search);
|
|
@@ -481,28 +519,41 @@ var src2 = function (search) {
|
|
|
481
519
|
cast(this, origin);
|
|
482
520
|
});
|
|
483
521
|
}
|
|
522
|
+
|
|
484
523
|
var directives = {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
hide: createBinder(function (elem, value) {
|
|
488
|
-
if (arguments.length === 1) return elem.style.display === 'none';
|
|
489
|
-
elem.style.display = value ? 'none' : '';
|
|
524
|
+
text: createBinder2(function (elem, value) {
|
|
525
|
+
elem.innerText = value;
|
|
490
526
|
}),
|
|
491
|
-
|
|
492
|
-
if (
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
for (var k in changed) {
|
|
501
|
-
targetValue[k] = isEmpty(value[k]) ? "" : value[k];
|
|
527
|
+
bind: createBinder2(function (elem, value) {
|
|
528
|
+
if (isNode(value) || isArray(value)) {
|
|
529
|
+
if (value !== elem.firstChild) {
|
|
530
|
+
remove(elem.childNodes);
|
|
531
|
+
appendChild(elem, value);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
elem.innerText = value;
|
|
502
536
|
}
|
|
503
|
-
value = targetValue;
|
|
504
|
-
css(elem, value);
|
|
505
537
|
}),
|
|
538
|
+
html: createBinder2(function (elem, value) {
|
|
539
|
+
elem.innerHTML = value;
|
|
540
|
+
}),
|
|
541
|
+
hide: createBinder2(function (elem, value) {
|
|
542
|
+
var display = value ? 'none' : '';
|
|
543
|
+
var style = elem.style;
|
|
544
|
+
if (style.display !== display) style.display = display;
|
|
545
|
+
}, function (elem) {
|
|
546
|
+
return elem.style.display === 'none';
|
|
547
|
+
}),
|
|
548
|
+
show: createBinder2(function (elem, value) {
|
|
549
|
+
var display = value ? '' : 'none';
|
|
550
|
+
var style = elem.style;
|
|
551
|
+
if (style.display !== display) style.display = display;
|
|
552
|
+
}, function (elem) {
|
|
553
|
+
return elem.style.display === 'none';
|
|
554
|
+
}),
|
|
555
|
+
style: createMapper(css, css.styleToMap),
|
|
556
|
+
class: createMapper(addClass, addClass.classToMap),
|
|
506
557
|
src(src) {
|
|
507
558
|
var parsedSrc = this.$src;
|
|
508
559
|
return src2.call(this, parsedSrc && /[\{\[\s]/.test(src) ? parsedSrc.srcName : src);
|
|
@@ -558,43 +609,7 @@ var directives = {
|
|
|
558
609
|
eventsBinders.forEach(on => on(target, onchange, true));
|
|
559
610
|
},
|
|
560
611
|
|
|
561
|
-
"class"(search) {
|
|
562
|
-
var getter = createGetter(this, search);
|
|
563
|
-
var generatedClassNames = {};
|
|
564
|
-
var oldValue;
|
|
565
|
-
this.$renders.push(function () {
|
|
566
|
-
var className = getter(this);
|
|
567
|
-
if (deepEqual(oldValue, className)) return;
|
|
568
|
-
oldValue = className;
|
|
569
|
-
var originalClassNames = [];
|
|
570
|
-
this.className.split(/\s+/).map(function (k) {
|
|
571
|
-
if (k && !hasOwnProperty.call(generatedClassNames, k) && !hasOwnProperty.call(originalClassNames, k)) {
|
|
572
|
-
if (!/^\d+$/.test(k)) originalClassNames.push(originalClassNames[k] = k);
|
|
573
|
-
}
|
|
574
|
-
});
|
|
575
|
-
var deltaClassNames = [];
|
|
576
|
-
if (isString(className)) {
|
|
577
|
-
className.split(/\s+/).map(function (k) {
|
|
578
|
-
if (!hasOwnProperty.call(originalClassNames, k)) {
|
|
579
|
-
if (!/^\d+$/.test(k)) deltaClassNames.push(deltaClassNames[k] = k);
|
|
580
|
-
}
|
|
581
|
-
});
|
|
582
|
-
} else if (isObject(className)) {
|
|
583
|
-
for (var k in className) {
|
|
584
|
-
if (!hasOwnProperty.call(originalClassNames, k) && className[k]) {
|
|
585
|
-
if (!/^\d+$/.test(k)) deltaClassNames.push(deltaClassNames[k] = k);
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
var destClassName = originalClassNames.concat(deltaClassNames).join(" ");
|
|
590
|
-
generatedClassNames = deltaClassNames;
|
|
591
|
-
if (this.className !== destClassName) {
|
|
592
|
-
this.className = destClassName;
|
|
593
|
-
}
|
|
594
|
-
});
|
|
595
|
-
},
|
|
596
612
|
};
|
|
597
|
-
directives.text = directives.bind;
|
|
598
613
|
// property binder
|
|
599
614
|
var binders = {
|
|
600
615
|
_(attr, search) {
|
|
@@ -762,15 +777,12 @@ function renderElement(element, scope = element.$scope, parentScopes = element.$
|
|
|
762
777
|
if (isEmpty(s.once)) s.once = once;
|
|
763
778
|
element.$eval = $eval;
|
|
764
779
|
}
|
|
780
|
+
mountElementIds(element);
|
|
765
781
|
if (element.$renderid <= -1) element = renderStructure(element);
|
|
766
782
|
if (!element) return;
|
|
767
783
|
if (!element || element.$renderid < 0 || element.nodeType !== 1) {
|
|
768
784
|
return element;
|
|
769
785
|
}
|
|
770
|
-
for (var id of element.$struct.ids) {
|
|
771
|
-
if (scope[id] && scope[id] !== element) throw new Error(i18n`同一个id不能使用两次:` + id);
|
|
772
|
-
scope[id] = element;
|
|
773
|
-
}
|
|
774
786
|
var isFirstRender = !element.$renderid;
|
|
775
787
|
|
|
776
788
|
if (isFirstRender) {
|
|
@@ -795,6 +807,7 @@ function renderElement(element, scope = element.$scope, parentScopes = element.$
|
|
|
795
807
|
if (!replacer.$parentScopes) replacer.$parentScopes = parentScopes;
|
|
796
808
|
if (isElement(replacer) && !replacer.$renderid) {
|
|
797
809
|
createStructure(replacer);
|
|
810
|
+
replacer.$struct = mergeStruct(element.$struct, replacer.$struct);
|
|
798
811
|
if (replacer.children && replacer.children.length) renderElement(replacer.children, replacer.$scope, replacer.$parentScopes, once);
|
|
799
812
|
renderRest(replacer, replacer.$struct);
|
|
800
813
|
replacer.$struct.ons.forEach(([on, key, value]) => on.call(replacer, replacer, key, value));
|
|
@@ -866,6 +879,44 @@ function $eval(search, scope, event) {
|
|
|
866
879
|
return $$eval.call(this, search, scope, this, event);
|
|
867
880
|
}
|
|
868
881
|
|
|
882
|
+
var merge = function (dst, src) {
|
|
883
|
+
if (!isHandled(src)) return dst;
|
|
884
|
+
if (!isHandled(dst)) return src;
|
|
885
|
+
if (isArray(dst)) {
|
|
886
|
+
return dst.concat(src);
|
|
887
|
+
}
|
|
888
|
+
if (isObject(dst)) return Object.assign(dst, src);
|
|
889
|
+
return src;
|
|
890
|
+
};
|
|
891
|
+
var pushb = function (dist, b) {
|
|
892
|
+
if (isArray(b)) dist.push(...b);
|
|
893
|
+
else if (isHandled(b)) dist.push(b);
|
|
894
|
+
};
|
|
895
|
+
var mergeStruct = function (struct1, struct2) {
|
|
896
|
+
if (!isObject(struct1)) return struct2;
|
|
897
|
+
if (!isObject(struct2)) return struct1;
|
|
898
|
+
for (var k in struct2) if (k !== 'binds') {
|
|
899
|
+
struct1[k] = merge(struct1[k], struct2[k]);
|
|
900
|
+
}
|
|
901
|
+
var binds1 = struct1.binds;
|
|
902
|
+
var binds2 = struct2.binds;
|
|
903
|
+
for (var k in binds2) {
|
|
904
|
+
if (/^(class|style)$/.test(k)) {
|
|
905
|
+
var dist = [];
|
|
906
|
+
pushb(dist, binds1[k]);
|
|
907
|
+
pushb(dist, binds2[k]);
|
|
908
|
+
if (dist.length) {
|
|
909
|
+
if (dist.length === 1) dist = dist[0];
|
|
910
|
+
binds1[k] = dist;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
else {
|
|
914
|
+
binds1[k] = binds2[k];
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
return struct1;
|
|
918
|
+
}
|
|
919
|
+
|
|
869
920
|
class Struct {
|
|
870
921
|
constructor(ons, types, copys, binds, attrs, props, ids, once) {
|
|
871
922
|
this.ons = ons;
|
|
@@ -881,6 +932,12 @@ class Struct {
|
|
|
881
932
|
}
|
|
882
933
|
|
|
883
934
|
|
|
935
|
+
var pushid = function (ids, name) {
|
|
936
|
+
ids.push(name);
|
|
937
|
+
var name1 = name.replace(/\-([a-z])/ig, (_, a) => a.toUpperCase());
|
|
938
|
+
if (name1 !== name) ids.push(name1);
|
|
939
|
+
};
|
|
940
|
+
|
|
884
941
|
function createStructure(element) {
|
|
885
942
|
if (isArrayLike(element)) return Array.prototype.map.call(element, createStructure);
|
|
886
943
|
if (element.$struct) return element.$struct;
|
|
@@ -904,11 +961,11 @@ function createStructure(element) {
|
|
|
904
961
|
var { name, value } = attr;
|
|
905
962
|
if (/^\$/.test(name)) continue;
|
|
906
963
|
if (name === 'elementid' || name === 'renderid' || name === 'id') {
|
|
907
|
-
ids
|
|
964
|
+
pushid(ids, value);
|
|
908
965
|
continue;
|
|
909
966
|
}
|
|
910
967
|
if (/^#/.test(name)) {
|
|
911
|
-
ids
|
|
968
|
+
pushid(ids, name.slice(1));
|
|
912
969
|
element.removeAttribute(name);
|
|
913
970
|
continue;
|
|
914
971
|
};
|
|
@@ -1034,4 +1091,5 @@ render.register = function (key, name) {
|
|
|
1034
1091
|
}
|
|
1035
1092
|
};
|
|
1036
1093
|
render.getFromScopes = getFromScopes;
|
|
1037
|
-
render.struct = createStructure;
|
|
1094
|
+
render.struct = createStructure;
|
|
1095
|
+
render.mergeStruct = mergeStruct;
|
package/coms/zimoli/table.js
CHANGED
|
@@ -307,6 +307,7 @@ var setFixedColumn = function (remark) {
|
|
|
307
307
|
markRowTds(tr, remark);
|
|
308
308
|
});
|
|
309
309
|
if (!isTableRow(thead)) thead = thead.querySelector('tr');
|
|
310
|
+
if (!thead) return;
|
|
310
311
|
var children = Array.prototype.slice.call(thead.children);
|
|
311
312
|
var lastChild = children[children.length - 1];
|
|
312
313
|
var lastFieldChild = children[children.length - 2];
|
|
@@ -573,6 +574,7 @@ function table(elem) {
|
|
|
573
574
|
pagination
|
|
574
575
|
};
|
|
575
576
|
render(this, $scope, this.$parentScopes.concat(this.$scope));
|
|
577
|
+
if (isMounted(table)) setFixedColumn.call(table);
|
|
576
578
|
$scope.data = Table.from(fields, await data);
|
|
577
579
|
$scope.data.callback = function () {
|
|
578
580
|
render.digest();
|
package/coms/zimoli/vbox.js
CHANGED
|
@@ -148,8 +148,9 @@ function ybox(generator) {
|
|
|
148
148
|
wheelTime = event.timeStamp;
|
|
149
149
|
return;
|
|
150
150
|
}
|
|
151
|
-
var deltay = -event.deltaY;
|
|
152
151
|
if (event.moveLocked) return;
|
|
152
|
+
var deltay = -event.deltaY;
|
|
153
|
+
if (!deltay && _box.bindX) deltay = -event.deltaX;
|
|
153
154
|
event.moveLocked = true;
|
|
154
155
|
var box;
|
|
155
156
|
if (deltay > 0) {
|