efront 4.22.1 → 4.22.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/coms/basic/refilm_decode.js +20 -9
- package/coms/zimoli/field.html +2 -2
- package/coms/zimoli/field.js +60 -55
- package/coms/zimoli/field.less +20 -2
- package/coms/zimoli/grid.js +1 -0
- package/coms/zimoli/image.html +2 -2
- package/coms/zimoli/image.js +9 -14
- package/coms/zimoli/menuList.js +2 -1
- package/coms/zimoli/model.js +21 -2
- package/coms/zimoli/render.js +154 -98
- package/package.json +1 -1
- package/public/efront.js +1 -1
package/coms/zimoli/render.js
CHANGED
|
@@ -141,17 +141,17 @@ function rebuild(element, isFirstRender) {
|
|
|
141
141
|
var variableReg = /([^\:\,\+\=\-\!%\^\|\/\&\*\!\;\?\>\<~\{\}\s\[\]\(\)]|\?\s*\.(?=[^\d])|\s*\.\s*)+/g;
|
|
142
142
|
var variableOnlyReg = new RegExp(`^${variableReg.source}$`);
|
|
143
143
|
var getScopeList = function (element) {
|
|
144
|
-
|
|
144
|
+
var scopes = (element.$parentScopes || []).concat();
|
|
145
|
+
if (element.$scope) scopes.push(element.$scope);
|
|
146
|
+
return scopes;
|
|
145
147
|
};
|
|
146
148
|
var createGetter = function (target, search, isprop = true) {
|
|
147
149
|
if (!search) return function () { };
|
|
148
150
|
if (/^\{/.test(search)) search = `(${search})`;
|
|
149
151
|
search = renderExpress(search);
|
|
150
|
-
var
|
|
151
|
-
if (
|
|
152
|
-
else
|
|
153
|
-
else getter = $$eval.bind(target, search, scopes);
|
|
154
|
-
getter.scopes = scopes;
|
|
152
|
+
if (isprop) var getter = $$eval.bind(target, search, getScopeList(target));
|
|
153
|
+
else if (variableOnlyReg.test(search)) getter = $$eval.bind(target, search + "(event)");
|
|
154
|
+
else getter = $$eval.bind(target, search);
|
|
155
155
|
return getter;
|
|
156
156
|
};
|
|
157
157
|
var createComment = function (renders, type, expression) {
|
|
@@ -242,6 +242,18 @@ var parseRepeat = function (expression) {
|
|
|
242
242
|
srcName
|
|
243
243
|
);
|
|
244
244
|
};
|
|
245
|
+
var getClonedElements = function (clones, repsrc) {
|
|
246
|
+
var newmap = [];
|
|
247
|
+
var inc = 0;
|
|
248
|
+
clones.forEach((c, i) => {
|
|
249
|
+
var m = c.$scope.$item;
|
|
250
|
+
switch (m) {
|
|
251
|
+
case repsrc[inc]: delete clones[i]; newmap[inc++] = c; break;
|
|
252
|
+
case repsrc[inc + 1]: delete clones[i]; inc++; newmap[inc++] = c; break;
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
return newmap;
|
|
256
|
+
}
|
|
245
257
|
var createRepeat = function (search, id = 0) {
|
|
246
258
|
// 懒渲染
|
|
247
259
|
// throw new Error("repeat is not supported! use list component instead");
|
|
@@ -272,25 +284,42 @@ var createRepeat = function (search, id = 0) {
|
|
|
272
284
|
if (element.$scope) {
|
|
273
285
|
$parentScopes = $parentScopes.slice(), $parentScopes.push(element.$scope);
|
|
274
286
|
}
|
|
275
|
-
var clonedElements1 = Object.create(null);
|
|
287
|
+
var clonedElements1 = isArrayResult ? [] : Object.create(null);
|
|
288
|
+
if (isArrayResult && !trackBy && clonedElements instanceof Array) {
|
|
289
|
+
clonedElements1 = getClonedElements(clonedElements, result);
|
|
290
|
+
}
|
|
276
291
|
var cloned = keys.map(function (key, cx) {
|
|
277
292
|
var k = isArrayResult ? cx : key;
|
|
278
293
|
var $scope = repeater.createScope(result[k], k, cx);
|
|
279
294
|
if (trackBy) {
|
|
280
295
|
k = seek($scope, trackBy);
|
|
281
296
|
if (clonedElements[k]) {
|
|
282
|
-
clonedElements[k].$
|
|
297
|
+
Object.assign(clonedElements[k].$repeat, $scope)
|
|
283
298
|
return clonedElements1[k] = clonedElements[k];
|
|
284
299
|
}
|
|
285
300
|
}
|
|
286
301
|
else {
|
|
287
|
-
|
|
288
|
-
|
|
302
|
+
if (isArrayResult) {
|
|
303
|
+
var c = clonedElements1[k];
|
|
304
|
+
if (c) {
|
|
305
|
+
Object.assign(c.$repeat, $scope);
|
|
306
|
+
return c;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
var c = changes[k];
|
|
311
|
+
if (!c) c = clonedElements[k];
|
|
312
|
+
else c = null;
|
|
313
|
+
if (c) {
|
|
314
|
+
Object.assign(c.$repeat, $scope);
|
|
315
|
+
return clonedElements1[k] = c;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
289
318
|
}
|
|
290
319
|
var clone = element.cloneNode();
|
|
291
320
|
clone.innerHTML = element.innerHTML;
|
|
292
321
|
clone.$renderid = id;
|
|
293
|
-
clone.$scope = $scope;
|
|
322
|
+
clone.$repeat = clone.$scope = $scope;
|
|
294
323
|
clone.$parentScopes = $parentScopes;
|
|
295
324
|
clone.$struct = $struct;
|
|
296
325
|
clonedElements1[k] = clone;
|
|
@@ -323,46 +352,49 @@ var initIf = function (ifs) {
|
|
|
323
352
|
initialComment(s[0]);
|
|
324
353
|
}
|
|
325
354
|
};
|
|
355
|
+
|
|
356
|
+
var ifget = function () {
|
|
357
|
+
var elements = this.$elements;
|
|
358
|
+
var shouldMount = -1;
|
|
359
|
+
for (var cx = 0, dx = elements.length; cx < dx; cx += 2) {
|
|
360
|
+
var getter = elements[cx + 1];
|
|
361
|
+
if (!getter || getter(this)) {
|
|
362
|
+
shouldMount = cx;
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return shouldMount;
|
|
367
|
+
}
|
|
368
|
+
var ifset = function (shouldMount) {
|
|
369
|
+
var elements = this.$elements;
|
|
370
|
+
for (var cx = 0, dx = elements.length; cx < dx; cx += 2) {
|
|
371
|
+
var c = elements[cx];
|
|
372
|
+
if (cx === shouldMount) {
|
|
373
|
+
var e = c.$template;
|
|
374
|
+
if (c.nextSibling !== e) appendChild.after(c, e);
|
|
375
|
+
if (e.$renderid < 0) {
|
|
376
|
+
e.$renderid = this.$id;
|
|
377
|
+
e = c.$template = render(e);
|
|
378
|
+
e.$comment = c;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
remove(c.$template);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
};
|
|
326
386
|
var createIf = function (search, id = 0) {
|
|
327
387
|
// 懒渲染
|
|
328
388
|
var getter = createGetter(this, search);
|
|
329
389
|
var element = this;
|
|
330
390
|
var elements = [element, getter];
|
|
331
391
|
if_top.push(elements);
|
|
332
|
-
var savedValue;
|
|
333
392
|
elements.parent = this.parentNode;
|
|
334
|
-
elements.comment = search;
|
|
335
393
|
if (this.$struct.repeat) id = -3;
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
var getter = elements[cx + 1];
|
|
341
|
-
if (!getter || getter(this)) {
|
|
342
|
-
shouldMount = cx;
|
|
343
|
-
break;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
if (savedValue === shouldMount) return;
|
|
347
|
-
savedValue = shouldMount;
|
|
348
|
-
for (var cx = 0, dx = elements.length; cx < dx; cx += 2) {
|
|
349
|
-
var c = elements[cx];
|
|
350
|
-
if (cx === shouldMount) {
|
|
351
|
-
var e = c.$template;
|
|
352
|
-
appendChild.after(c, e);
|
|
353
|
-
if (e.$renderid < 0) {
|
|
354
|
-
e.$renderid = id;
|
|
355
|
-
e = c.$template = render(e, this.$scope, this.$parentScopes);
|
|
356
|
-
e.$comment = c;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
else {
|
|
360
|
-
remove(c.$template);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
}];
|
|
365
|
-
return elements[0] = createComment.call(element, elements.$renders, 'if', elements.comment);
|
|
394
|
+
var comment = elements[0] = createComment.call(element, [new Binder2(ifget, ifset)], 'if', search);
|
|
395
|
+
comment.$id = id;
|
|
396
|
+
comment.$elements = elements;
|
|
397
|
+
return comment;
|
|
366
398
|
};
|
|
367
399
|
var parseIfWithRepeat = function (ifExpression, repeatExpression) {
|
|
368
400
|
var repeater = parseRepeat(repeatExpression);
|
|
@@ -475,9 +507,7 @@ var structures = {
|
|
|
475
507
|
}
|
|
476
508
|
initIf(if_top.splice(cx + 1, if_top.length - cx - 1));
|
|
477
509
|
var top = if_top[cx];
|
|
478
|
-
if (search
|
|
479
|
-
var getter = createGetter(this, search);
|
|
480
|
-
}
|
|
510
|
+
if (search) var getter = createGetter(this, search);
|
|
481
511
|
var comment = createComment.call(this, undefined, search ? 'elseif' : 'else', search);
|
|
482
512
|
top.push(comment, getter);
|
|
483
513
|
},
|
|
@@ -538,7 +568,7 @@ class Binder2 {
|
|
|
538
568
|
var createBinder2 = function (write, read) {
|
|
539
569
|
return function (search) {
|
|
540
570
|
var getter = createGetter(this, search);
|
|
541
|
-
var oldValue = isFunction(read) ? read(this) : undefined;
|
|
571
|
+
var oldValue = isFunction(read) ? read.call(this) : undefined;
|
|
542
572
|
this.$renders.push(new Binder2(getter, write, oldValue));
|
|
543
573
|
};
|
|
544
574
|
}
|
|
@@ -574,19 +604,26 @@ class Model {
|
|
|
574
604
|
var getValue = target.getValue;
|
|
575
605
|
var setValue = target.setValue;
|
|
576
606
|
if (getValue && setValue);
|
|
577
|
-
else if (
|
|
578
|
-
if (!getValue) getValue = gtValue;
|
|
607
|
+
else if ('value' in target) {
|
|
579
608
|
if (!setValue) setValue = stValue;
|
|
580
|
-
|
|
609
|
+
if (!getValue) getValue = gtValue;
|
|
610
|
+
}
|
|
611
|
+
else if (/^input$/i.test(target.tagName) && /^checkbox$/i.test(target.type) || /^checkbox$/i.test(target.tagName)) {
|
|
581
612
|
if (!getValue) getValue = gtChecked;
|
|
582
613
|
if (!setValue) setValue = stChecked;
|
|
583
|
-
}
|
|
614
|
+
}
|
|
615
|
+
else if (/^(select|input|textarea)$/i.test(target.tagName) || "value" in target) {
|
|
584
616
|
if (!getValue) getValue = gtValue;
|
|
585
617
|
if (!setValue) setValue = stValue;
|
|
586
|
-
}
|
|
618
|
+
}
|
|
619
|
+
else if (String(target.contentEditable) === "true") {
|
|
587
620
|
if (!getValue) getValue = gtHtml;
|
|
588
621
|
if (!setValue) setValue = stHtml;
|
|
589
622
|
}
|
|
623
|
+
else {
|
|
624
|
+
if (!getValue) getValue = gtValue;
|
|
625
|
+
if (!setValue) setValue = stValue;
|
|
626
|
+
}
|
|
590
627
|
this.gv = getValue;
|
|
591
628
|
this.sv = setValue;
|
|
592
629
|
this.target = target;
|
|
@@ -599,6 +636,9 @@ class Model {
|
|
|
599
636
|
this.ss.call(this.target, value);
|
|
600
637
|
this.value = value;
|
|
601
638
|
this.bd.value = this.gs.call(this.target, value);
|
|
639
|
+
if (isFunction(this.emit?.call)) {
|
|
640
|
+
this.emit.call(this.target);
|
|
641
|
+
}
|
|
602
642
|
userChanged = true;
|
|
603
643
|
}
|
|
604
644
|
hook(elem, emit) {
|
|
@@ -606,9 +646,10 @@ class Model {
|
|
|
606
646
|
elem.$renders.push(binder);
|
|
607
647
|
binder.call(elem);
|
|
608
648
|
this.bd = binder;
|
|
609
|
-
if (emit) {
|
|
649
|
+
if (emit !== false) {
|
|
650
|
+
this.emit = emit;
|
|
651
|
+
this.value = this.gv.call(this.target);
|
|
610
652
|
eventsBinders.forEach(on => on(this.target, this, true));
|
|
611
|
-
this.value = this.gv.call(elem);
|
|
612
653
|
this.target = elem;
|
|
613
654
|
}
|
|
614
655
|
return binder;
|
|
@@ -664,7 +705,7 @@ var directives = {
|
|
|
664
705
|
var getter = createGetter(this, search);
|
|
665
706
|
var setter = createSetter(this, search);
|
|
666
707
|
var model = new Model(getter, setter, target);
|
|
667
|
-
model.hook(this, change !== false
|
|
708
|
+
model.hook(this, change !== false);
|
|
668
709
|
},
|
|
669
710
|
value(search, target) {
|
|
670
711
|
directives.model.call(this, search, target, false);
|
|
@@ -712,12 +753,56 @@ var binders = {
|
|
|
712
753
|
}
|
|
713
754
|
};
|
|
714
755
|
var reject = function (e) { digest(); throw e };
|
|
756
|
+
class Emitter {
|
|
757
|
+
constructor(emit, scopes) {
|
|
758
|
+
this.emit = emit;
|
|
759
|
+
this.scopes = scopes;
|
|
760
|
+
}
|
|
761
|
+
call(elem, e) {
|
|
762
|
+
digest();
|
|
763
|
+
var scopes = this.scopes;
|
|
764
|
+
var parsedSrc = elem.$src;
|
|
765
|
+
if (parsedSrc instanceof Repeater) {
|
|
766
|
+
if (e.active || e.currentTarget) var target = e.active || (e.currentTarget === elem ? e.target || e.srcElem || e.currentTarget : e.currentTarget);
|
|
767
|
+
else var target = e.target;
|
|
768
|
+
if (target === elem) {
|
|
769
|
+
scope = parsedSrc.createScope();
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
let scopes = target && target.$parentScopes;
|
|
773
|
+
if (scopes) {
|
|
774
|
+
var scope = null;
|
|
775
|
+
for (var cx = scopes.length - 1; cx >= 0; cx--) {
|
|
776
|
+
var s = scopes[cx];
|
|
777
|
+
if (s === elem.$scope) {
|
|
778
|
+
scope = scopes[cx + 1];
|
|
779
|
+
break;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
if (!scope && target.$scope !== elem.$scope) scope = target.$scope;
|
|
785
|
+
}
|
|
786
|
+
var res;
|
|
787
|
+
if (scope) {
|
|
788
|
+
scopes.push(scope);
|
|
789
|
+
res = this.emit(scopes, elem, e);
|
|
790
|
+
scopes.pop();
|
|
791
|
+
}
|
|
792
|
+
else {
|
|
793
|
+
res = this.emit(scopes, elem, e);
|
|
794
|
+
}
|
|
795
|
+
if (res && isFunction(res.then)) res.then(digest, reject);
|
|
796
|
+
return res;
|
|
797
|
+
|
|
798
|
+
}
|
|
799
|
+
}
|
|
715
800
|
var createEmiter = function (on) {
|
|
716
801
|
return function (target, key, search) {
|
|
717
802
|
/**
|
|
718
803
|
* @type {Repeater}
|
|
719
804
|
*/
|
|
720
|
-
var
|
|
805
|
+
var emit = createGetter(this, search, false);
|
|
721
806
|
var onkey;
|
|
722
807
|
if (key === 'mounted' || key === 'mount') {
|
|
723
808
|
onkey = on === once ? oncemount : onmounted;
|
|
@@ -728,42 +813,7 @@ var createEmiter = function (on) {
|
|
|
728
813
|
else {
|
|
729
814
|
onkey = on(key);
|
|
730
815
|
}
|
|
731
|
-
onkey(target,
|
|
732
|
-
digest();
|
|
733
|
-
var parsedSrc = this.$src;
|
|
734
|
-
if (parsedSrc instanceof Repeater) {
|
|
735
|
-
if (e.active || e.currentTarget) var target = e.active || (e.currentTarget === this ? e.target || e.srcElem || e.currentTarget : e.currentTarget);
|
|
736
|
-
else var target = e.target;
|
|
737
|
-
if (target === this) {
|
|
738
|
-
scope = parsedSrc.createScope();
|
|
739
|
-
}
|
|
740
|
-
else {
|
|
741
|
-
var scopes = target && target.$parentScopes;
|
|
742
|
-
if (scopes) {
|
|
743
|
-
var scope = null;
|
|
744
|
-
for (var cx = scopes.length - 1; cx >= 0; cx--) {
|
|
745
|
-
var s = scopes[cx];
|
|
746
|
-
if (s === this.$scope) {
|
|
747
|
-
scope = scopes[cx + 1];
|
|
748
|
-
break;
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
if (!scope && target.$scope !== this.$scope) scope = target.$scope;
|
|
754
|
-
}
|
|
755
|
-
var res;
|
|
756
|
-
if (scope) {
|
|
757
|
-
getter.scopes.push(scope);
|
|
758
|
-
res = getter(this, e);
|
|
759
|
-
getter.scopes.pop();
|
|
760
|
-
}
|
|
761
|
-
else {
|
|
762
|
-
res = getter(this, e);
|
|
763
|
-
}
|
|
764
|
-
if (res && isFunction(res.then)) res.then(digest, reject);
|
|
765
|
-
return res;
|
|
766
|
-
});
|
|
816
|
+
onkey(target, new Emitter(emit, getScopeList(target)));
|
|
767
817
|
};
|
|
768
818
|
};
|
|
769
819
|
var emiters = {
|
|
@@ -936,19 +986,25 @@ function renderElement(element, scope = element.$scope, parentScopes = element.$
|
|
|
936
986
|
}
|
|
937
987
|
return element;
|
|
938
988
|
}
|
|
939
|
-
var
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
989
|
+
var deepcontexts = [];
|
|
990
|
+
var getDeepContext = function (deep) {
|
|
991
|
+
var length = deep;
|
|
992
|
+
var deepL = deepcontexts.length;
|
|
993
|
+
while (deep-- > deepL) {
|
|
994
|
+
deepcontexts[deep] = `with($parentScopes[${deep}])`;
|
|
943
995
|
}
|
|
944
|
-
return
|
|
996
|
+
return deepcontexts.slice(0, length).join('');
|
|
997
|
+
}
|
|
998
|
+
var createEval = function (deep) {
|
|
999
|
+
return new Function("$parentScopes", "code", "event", `${getDeepContext(deep)}return eval(code)`);
|
|
945
1000
|
};
|
|
1001
|
+
|
|
946
1002
|
var evalcontexts = [createEval(0)];
|
|
947
1003
|
|
|
948
1004
|
function $$eval(search, scopes, target = this, event) {
|
|
949
1005
|
var length = scopes.length;
|
|
950
|
-
if (!evalcontexts[length]) evalcontexts[length] = createEval(length);
|
|
951
1006
|
var eval2 = evalcontexts[length];
|
|
1007
|
+
if (!eval2) eval2 = evalcontexts[length] = createEval(length);
|
|
952
1008
|
var res = eval2.call(target, scopes, search, event);
|
|
953
1009
|
return res;
|
|
954
1010
|
}
|