efront 3.4.4 → 3.5.0

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.
@@ -144,7 +144,10 @@ var createRepeat = function (search, id = 0) {
144
144
  throw new Error("数据量过大,取消绘制!");
145
145
  }
146
146
  var $parentScopes = element.$parentScopes || [];
147
- if (element.$scope) $parentScopes = $parentScopes.concat(element.$scope);
147
+ var $struct = element.$struct;
148
+ if (element.$scope) {
149
+ $struct = Object.assign({}, $struct, { context: $struct.context + `with(this.$parentScopes[${$parentScopes.length}])` }), $parentScopes = $parentScopes.concat(element.$scope);
150
+ }
148
151
  var clonedElements1 = Object.create(null);
149
152
  var cloned = keys.map(function (key, cx) {
150
153
  var k = isArrayResult ? cx : key;
@@ -161,6 +164,7 @@ var createRepeat = function (search, id = 0) {
161
164
  };
162
165
  clone.$scope = $scope;
163
166
  clone.$parentScopes = $parentScopes;
167
+ clone.$struct = $struct;
164
168
  clone = render(clone, $scope, clone.$parentScopes);
165
169
  clonedElements1[k] = clone;
166
170
  return clone;
@@ -302,19 +306,17 @@ var parseIfWithRepeat = function (ifExpression, repeatExpression) {
302
306
 
303
307
  var createStructure = function ({ name: ifkey, key, value: ifexp } = {}, { name: forkey, value: repeat } = {}, context) {
304
308
  var element = this;
305
- if (!ifkey) return structures.repeat.call(element, [context, repeat]);
306
- if (!repeat) return structures[key].call(element, [context, ifexp]);
309
+ if (!ifkey) return element.removeAttribute(forkey), structures.repeat.call(element, [context, repeat]);
310
+ if (!repeat) return element.removeAttribute(ifkey), structures[key].call(element, [context, ifexp]);
307
311
  if (!ifexp) {
308
312
  element.removeAttribute(ifkey);
309
313
  return structures[key].call(element, [context, ifexp]);
310
314
  }
311
315
  var { before, after } = parseIfWithRepeat(ifexp, repeat);
312
- if (!after.length) {
313
- element.removeAttribute(ifkey);
314
- } else {
315
- element.setAttribute(ifkey, after.join("&&"));
316
+ element.removeAttribute(ifkey);
317
+ if (after.length) {
318
+ element.setAttribute("a-if", after.join("&&"));
316
319
  }
317
-
318
320
  if (before.length > 0) {
319
321
  // 懒渲染
320
322
  createIf.call(element, [context, before.join("&&")], null);
@@ -367,6 +369,27 @@ var createBinder = function (binder) {
367
369
 
368
370
  }
369
371
  }
372
+
373
+ var src2 = function (search) {
374
+ var getter = createGetter(search).bind(this);
375
+ var savedValue;
376
+ this.renders.push(function () {
377
+ var origin = getter();
378
+ var temp = origin;
379
+ if (origin instanceof Array) {
380
+ temp = extend([], origin);
381
+ } else if (isObject(origin)) {
382
+ temp = extend({}, origin);
383
+ } else if (isEmpty(origin)) {
384
+ temp = "";
385
+ }
386
+ var changes = getChanges(temp, savedValue);
387
+ if (!changes) return;
388
+ savedValue = temp;
389
+ this.src = origin;
390
+ cast(this, origin);
391
+ });
392
+ }
370
393
  var directives = {
371
394
  bind: createBinder(text),
372
395
  html: createBinder(html),
@@ -379,47 +402,9 @@ var directives = {
379
402
  elem.style.display = value ? '' : 'none';
380
403
  }),
381
404
  style: createBinder(css),
382
- src(search) {
383
- var getter = createGetter(search).bind(this);
384
- var savedValue, pending;
385
- var refresh = function () {
386
- that.src = savedValue;
387
- removeClass(that, "pending");
388
- pending = 0;
389
- };
390
- var img = document.createElement("img");
391
- var that = this;
392
- this.renders.push(function () {
393
- var origin = getter();
394
- var temp = origin;
395
- if (origin instanceof Array) {
396
- temp = extend([], origin);
397
- } else if (isObject(origin)) {
398
- temp = extend({}, origin);
399
- } else if (isEmpty(origin)) {
400
- temp = "";
401
- }
402
- var changes = getChanges(temp, savedValue);
403
- if (!changes) return;
404
- savedValue = temp;
405
- if (/^img$/i.test(this.tagName)) {
406
- if (!isString(origin)) {
407
- return;
408
- }
409
- if (origin) {
410
- img.src = origin;
411
- if (img.complete) {
412
- this.src = origin;
413
- } else if (!pending) {
414
- addClass(this, "pending");
415
- pending = setTimeout(refresh);
416
- }
417
- }
418
- } else {
419
- this.src = origin;
420
- cast(this, origin);
421
- }
422
- });
405
+ src([s, src]) {
406
+ var parsedSrc = this.$src;
407
+ return src2.call(this, [s, parsedSrc ? parsedSrc.srcName : src]);
423
408
  },
424
409
  model(search) {
425
410
  var getter = createGetter(search).bind(this);
@@ -510,6 +495,7 @@ var directives = {
510
495
  });
511
496
  },
512
497
  };
498
+ directives.text = directives.bind;
513
499
  // property binder
514
500
  var binders = {
515
501
  _(attr, search) {
@@ -607,10 +593,14 @@ function renderElement(element, scope = element.$scope, parentScopes = element.$
607
593
  if (parentNode) {
608
594
  if (parentNode.renderid > 1 || parentNode.isMounted) element.renderid = 2;
609
595
  }
610
- var ons = [];
611
596
 
612
597
  if (isFirstRender) {
613
- var attrs = [].concat.apply([], element.attributes);
598
+ element.renders = element.renders ? [].concat(element.renders) : [];
599
+ var { ons, copys, attrs, props, binds, context: withContext } = element.$struct;
600
+ delete element.$struct;
601
+ if (binds.src) {
602
+ element.$src = parseRepeat(binds.src);
603
+ }
614
604
  var { tagName, parentNode, nextSibling } = element;
615
605
  // 替换元素
616
606
  var constructor = getFromScopes(tagName, scope, parentScopes);
@@ -623,13 +613,12 @@ function renderElement(element, scope = element.$scope, parentScopes = element.$
623
613
  constructor = getFromScopes(tagName, scope, parentScopes);
624
614
  }
625
615
  if (isFunction(constructor)) {
626
- var attrsMap = {};
627
616
  var replacer = constructor.call(scope, element, scope, parentScopes);
628
617
  if (isNode(replacer) && element !== replacer) {
629
618
  if (nextSibling) appendChild.before(nextSibling, replacer);
630
619
  else if (parentNode) appendChild(parentNode, replacer);
631
620
  if (element.parentNode === parentNode) remove(element);
632
- attrs.map(function (attr) {
621
+ copys.forEach(function (attr) {
633
622
  var { name, value } = attr;
634
623
  switch (name.toLowerCase()) {
635
624
  case "class":
@@ -643,62 +632,39 @@ function renderElement(element, scope = element.$scope, parentScopes = element.$
643
632
  replacer[name] = value;
644
633
  break;
645
634
  default:
646
- if (!/[\-@\:\._]/.test(name)) {
647
- replacer.setAttribute(name, value);
648
- } else {
649
- attrsMap[name] = attr;
650
- }
635
+ replacer.setAttribute(name, value);
651
636
  }
652
637
  });
653
638
  replacer.renderid = element.renderid;
639
+ replacer.renders = element.renders;
640
+ if (binds.src) replacer.$src = element.$src;
654
641
  element = replacer;
655
642
  element.$scope = scope;
656
643
  element.$parentScopes = parentScopes;
657
644
  }
658
- [].concat.apply([], element.attributes).forEach(attr => {
659
- if (attrsMap[attr.name]) {
660
- delete attrsMap[attr.name];
661
- }
662
- attrsMap[attr.name] = attr;
663
- });
664
- attrs = Object.keys(attrsMap).map(key => attrsMap[key]);
665
645
  }
666
646
  }
667
647
  if (element.children.length) renderElement(element.children, scope, parentScopes);
668
648
  if (!isFirstRender) return element;
669
- // 解析属性
670
- element.renders = element.renders ? [].concat(element.renders) : [];
671
- var withContext = parentScopes ? parentScopes.map((_, cx) => `with(this.$parentScopes[${cx}])`).join("") : '';
672
- var emiter_reg = /^(?:(v|ng|on|once)\-|v\-on\:|@|once|on)/i;
673
- attrs.map(function (attr) {
674
- var { name, value } = attr;
675
- if (/^(?:class|style|src|\:)$/i.test(name)) return;
676
- var key = name.replace(/^(ng|v|.*?)\-|^[\:\_\.]/i, "").toLowerCase();
677
- if (directives.hasOwnProperty(key) && isFunction(directives[key])) {
678
- directives[key].call(element, [withContext, value]);
679
- element.removeAttribute(name);
680
- } else if (emiter_reg.test(name)) {
681
- var match = emiter_reg.exec(name);
682
- var ngon = (match[1] || match[0]).toLowerCase() === 'once' ? 'once' : 'on';
683
- element.removeAttribute(name);
684
- ons.push([emiters[ngon], name.replace(emiter_reg, ''), value]);
685
- } else if (/^([\_\:\.]|v\-bind\:)/.test(name)) {
686
- binders._.call(element, name.replace(/^([\_\:\.]|v\-bind\:)/, ""), [withContext, value]);
687
- element.removeAttribute(name);
688
- } else if (/[_@\:\.]$/.test(name)) {
689
- binders[""].call(element, name.replace(/[_@\:\.]$/, ""), [withContext, value]);
690
- element.removeAttribute(name);
691
- } else {
692
- name = name.replace(/\-(\w)/g, (_, w) => w.toUpperCase());
693
- try {
694
- element[name] = value === '' ? true : value;
695
- } catch (e) {
696
- }
649
+ for (var k in binds) {
650
+ if (directives.hasOwnProperty(k)) {
651
+ directives[k].call(element, [withContext, binds[k]])
697
652
  }
698
- });
699
- rebuild(element);
653
+ else {
654
+ binders._.call(element, k, [withContext, binds[k]]);
655
+ }
656
+ }
657
+ for (var k in attrs) {
658
+ binders[""].call(element, k, [withContext, attrs[k]]);
659
+ }
660
+ for (var k in props) {
661
+ try {
662
+ element[k] = props[k];
663
+ } catch (e) { }
664
+ }
700
665
  ons.forEach(([on, key, value]) => on.call(element, key, [withContext, value]));
701
666
  if (element.renders.length) {
667
+ rebuild(element);
702
668
  onappend(element, addRenderElement);
703
669
  onremove(element, removeRenderElement);
704
670
  if (element.isMounted || element.renderid > 1) addRenderElement.call(element);
@@ -720,11 +686,19 @@ function renderStructure(element, scope, parentScopes = []) {
720
686
  }
721
687
  var attrs = [].concat.apply([], element.attributes);
722
688
  var withContext = parentScopes ? parentScopes.map((_, cx) => `with(this.$parentScopes[${cx}])`).join("") : '';
723
- attrs = attrs.filter(a => structures.hasOwnProperty(a.name.replace(/^(ng|V|.*?)\-/i, '').toLowerCase()));
724
689
  var types = {};
725
- if (attrs.length > 2) throw new Error(`请不要在同一元素上使用三次及以上的结构属性:${attrs.map(a => a.name)}`);
726
- attrs.map(function (attr) {
727
- var { name } = attr;
690
+ var emiter_reg = /^(?:(v|ng|on|once)\-|v\-on\:|@|once|on)/i;
691
+ var ons = [];
692
+ var copys = [];
693
+ var binds = {};
694
+ var attr1 = {};
695
+ var props = {};
696
+ for (var attr of attrs) {
697
+ var { name, value } = attr;
698
+ if (/^(?:class|style|src|\:|placeholder)$/i.test(name)) {
699
+ copys.push(attr);
700
+ continue;
701
+ }
728
702
  var key = name.replace(/^(ng|v|.*?)\-/i, "").toLowerCase();
729
703
  if (structures.hasOwnProperty(key) && isFunction(structures[key])) {
730
704
  if (element.renderid <= -2) {
@@ -747,9 +721,29 @@ function renderStructure(element, scope, parentScopes = []) {
747
721
  }
748
722
  if (!element.renderid) element.renderid = -1;
749
723
  else element.renderid = -2;
724
+ // element.removeAttribute(name);
725
+ }
726
+ if (element.$struct) continue;
727
+ var key = name.replace(/^(ng|v|.*?)\-|^[\:\_\.]|^v\-bind\:/i, "").toLowerCase();
728
+ if (directives.hasOwnProperty(key) || /^([\_\:\.]|v\-bind\:)/.test(name)) {
729
+ binds[key] = value;
750
730
  element.removeAttribute(name);
751
731
  }
752
- });
732
+ else if (emiter_reg.test(name)) {
733
+ var match = emiter_reg.exec(name);
734
+ var ngon = (match[1] || match[0]).toLowerCase() === 'once' ? 'once' : 'on';
735
+ element.removeAttribute(name);
736
+ ons.push([emiters[ngon], name.replace(emiter_reg, ''), value]);
737
+ }
738
+ else if (/[_@\:\.]$/.test(name)) {
739
+ attr1[name.replace(/[_@\:\.]$/, "")] = value;
740
+ element.removeAttribute(name);
741
+ }
742
+ else {
743
+ props[name.replace(/\-(\w)/g, (_, w) => w.toUpperCase())] = value === "" ? true : value;
744
+ }
745
+ }
746
+ if (!element.$struct) element.$struct = { ons, copys, binds, attrs: attr1, props, context: withContext };
753
747
  if (element.renderid <= -1) createStructure.call(element, types.if, types.repeat, withContext);
754
748
  }
755
749
  function render(element, scope, parentScopes) {
@@ -0,0 +1,16 @@
1
+ <thead>
2
+ <tr>
3
+ <td -repeat="f in fields"><i -if="f.icon" -class="f.icon"></i></span><span -if="f.name" -html="f.name"></span>
4
+ </td>
5
+ </tr>
6
+ </thead>
7
+ <tbody -src="d in data">
8
+ <tr>
9
+ <td -repeat="f in fields">
10
+ <span -if="f.key" -text="d[f.key]"></span>
11
+ <a on-click="o.do(d)" -if="f.type==='btn'" -repeat="o in f.options">
12
+ <span -text=o.name></span>
13
+ </a>
14
+ </td>
15
+ </tr>
16
+ </tbody>
@@ -153,10 +153,24 @@ function table(elem) {
153
153
  table.dragbox = function () {
154
154
  return thead;
155
155
  };
156
+ care(table, function ([fields, data]) {
157
+ this.innerHTML = template;
158
+ render(this, {
159
+ fields,
160
+ tbody: list,
161
+ data,
162
+ a: button,
163
+ }, this.$parentScopes.concat(this.$scope));
164
+ })
156
165
  autodragchildren(
157
166
  table,
158
167
  cellMatchManager,
159
168
  function (src, dst, rel, append, parentNode) {
169
+ if (table.src) {
170
+ var [fields] = table.src;
171
+ var [f] = fields.splice(src, 1);
172
+ fields.splice(dst, 0, f);
173
+ }
160
174
  var children = parentNode.children;
161
175
  var srcElement = children[src];
162
176
  var dstElement = children[rel];
@@ -45,56 +45,66 @@ table {
45
45
  table-layout: fixed;
46
46
  white-space: nowrap;
47
47
 
48
- >thead {
49
- user-select: none;
50
- line-height: 36px;
48
+ }
51
49
 
52
- >tr {
50
+ >thead {
51
+ user-select: none;
52
+ line-height: 36px;
53
53
 
54
- >td,
55
- >th {
56
- padding: @cell-padding;
57
- position: relative;
58
- color: #fff;
59
- background-color: #999;
60
- }
54
+ >tr {
55
+
56
+ >td,
57
+ >th {
58
+ padding: @cell-padding;
59
+ position: relative;
60
+ color: #fff;
61
+ background-color: #999;
61
62
  }
62
63
  }
64
+ }
63
65
 
64
- >tbody {
65
- line-height: 32px;
66
+ >tbody {
67
+ line-height: 32px;
68
+ height: 100%;
69
+ min-height: 30px;
66
70
 
67
- >tr {
71
+ display: table-row-group;
68
72
 
69
- >td,
70
- >th {
71
- padding: @cell-padding;
72
- position: relative;
73
- }
73
+ >tr {
74
74
 
75
- &:nth-child(even) {
75
+ >td,
76
+ >th {
77
+ padding: @cell-padding;
78
+ position: relative;
79
+ }
80
+
81
+ &:nth-child(even) {
76
82
 
77
- >td,
78
- >th {
79
- background-color: #eee;
80
- }
83
+ >td,
84
+ >th {
85
+ background-color: #eee;
81
86
  }
87
+ }
82
88
 
83
- &:nth-child(odd) {
89
+ &:nth-child(odd) {
84
90
 
85
- >td,
86
- >th {
87
- background-color: #fff;
88
- }
91
+ >td,
92
+ >th {
93
+ background-color: #fff;
89
94
  }
95
+ }
90
96
 
91
- &:hover {
97
+ &:hover {
92
98
 
93
- >td,
94
- >th {
95
- background: #dddddd;
96
- }
99
+ >td,
100
+ >th {
101
+ background: #dddddd;
97
102
  }
98
103
  }
99
104
  }
105
+ }
106
+ .button{
107
+ margin-right: 10px;
108
+ vertical-align: middle;
109
+ display: inline-block;
100
110
  }
@@ -109,11 +109,14 @@ body>& {
109
109
  }
110
110
 
111
111
  .button {
112
- padding: 0 20px;
113
112
  min-width: 60px;
114
113
  vertical-align: middle;
114
+ margin-right: 10px;
115
+ }
115
116
 
116
- &+.button {
117
- margin-left: 10px;
117
+ >.foot,
118
+ >[foot] {
119
+ .button {
120
+ padding: 0 20px;
118
121
  }
119
122
  }
@@ -576,11 +576,17 @@ function addGlobal(element, name = null, isDestroy) {
576
576
  }
577
577
  }
578
578
  var _switch = zimoli.switch = function (history_name = default_history, target_body = document.body, emptyState) {
579
- if (isString(history_name))
580
- current_history = history_name = history_name.replace(/\/$/, '') + "/";
581
- if (target_body)
582
- body = target_body;
583
- if (emptyState !== false && !history[history_name]) root_path = (history[history_name] = [].concat(emptyState || ":empty"))[0];
579
+ if (!arguments.length) {
580
+ current_history = default_history;
581
+ body = document.body;
582
+ }
583
+ else {
584
+ if (isString(history_name)) {
585
+ current_history = history_name = history_name.replace(/\/$/, '') + "/";
586
+ }
587
+ if (target_body) body = target_body;
588
+ }
589
+ if (emptyState !== false && !history[current_history]) root_path = (history[current_history] = [].concat(emptyState || ":empty"))[0];
584
590
  };
585
591
  popup.global = zimoli.global = addGlobal;
586
592
  popup.go = zimoli.go = go;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "3.4.4",
3
+ "version": "3.5.0",
4
4
  "description": "一个开发工具,开放源代码,自带组件库和编译环境,可以用来开发web组件,web应用或nodejs模块,或做为已有代码的加密工具,也可以做为静态页面服务器或跨域中转服务器使用",
5
5
  "main": "public/efront.js",
6
6
  "directories": {