efront 3.4.6 → 3.5.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.
@@ -55,7 +55,7 @@ var variableReg = /([^\:\,\+\=\-\!%\^\|\/\&\*\!\;\?\>\<~\{\}\s]|\?\s*\.(?=[^\d])
55
55
  var createGetter = function (search, isprop = true) {
56
56
  var [withContext, searchContext] = search;
57
57
  if (!searchContext) return function () { };
58
- var ret = /\;|(\d\.|[^\{\.\+\:\?\-\=\*\/\?\\,~!<>%\^&\}\s])\s*([\r\n\u2028\u2029])\s*(\.\d|[^\.\+\-\=\*\/\?\\,~!<>%\^&\[\}\(\?\:\s])/.test(searchContext) ? "" : "return ";
58
+ var ret = /\;/.test(searchContext) ? "" : "return ";
59
59
  if (/\?\s*\.(?=[^\d])/.test(searchContext)) {
60
60
  searchContext = searchContext.replace(variableReg, function (context) {
61
61
  var dist;
@@ -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 || isEmpty(origin) && isEmpty(this.src)) 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) {
@@ -551,6 +537,7 @@ var emiters = {
551
537
  var res = getter.call(this, e);
552
538
  if (res && isFunction(res.then)) res.then(digest, digest);
553
539
  digest();
540
+ return res;
554
541
  });
555
542
  },
556
543
  once(key, search) {
@@ -559,6 +546,7 @@ var emiters = {
559
546
  var res = getter.call(this, e);
560
547
  if (res && isFunction(res.then)) res.then(digest, digest);
561
548
  digest();
549
+ return res;
562
550
  });
563
551
  }
564
552
  };
@@ -607,10 +595,14 @@ function renderElement(element, scope = element.$scope, parentScopes = element.$
607
595
  if (parentNode) {
608
596
  if (parentNode.renderid > 1 || parentNode.isMounted) element.renderid = 2;
609
597
  }
610
- var ons = [];
611
598
 
612
599
  if (isFirstRender) {
613
- var attrs = [].concat.apply([], element.attributes);
600
+ element.renders = element.renders ? [].concat(element.renders) : [];
601
+ var { ons, copys, attrs, props, binds, context: withContext } = element.$struct;
602
+ delete element.$struct;
603
+ if (binds.src) {
604
+ element.$src = parseRepeat(binds.src);
605
+ }
614
606
  var { tagName, parentNode, nextSibling } = element;
615
607
  // 替换元素
616
608
  var constructor = getFromScopes(tagName, scope, parentScopes);
@@ -623,13 +615,12 @@ function renderElement(element, scope = element.$scope, parentScopes = element.$
623
615
  constructor = getFromScopes(tagName, scope, parentScopes);
624
616
  }
625
617
  if (isFunction(constructor)) {
626
- var attrsMap = {};
627
618
  var replacer = constructor.call(scope, element, scope, parentScopes);
628
619
  if (isNode(replacer) && element !== replacer) {
629
620
  if (nextSibling) appendChild.before(nextSibling, replacer);
630
621
  else if (parentNode) appendChild(parentNode, replacer);
631
622
  if (element.parentNode === parentNode) remove(element);
632
- attrs.map(function (attr) {
623
+ copys.forEach(function (attr) {
633
624
  var { name, value } = attr;
634
625
  switch (name.toLowerCase()) {
635
626
  case "class":
@@ -643,62 +634,39 @@ function renderElement(element, scope = element.$scope, parentScopes = element.$
643
634
  replacer[name] = value;
644
635
  break;
645
636
  default:
646
- if (!/[\-@\:\._]/.test(name)) {
647
- replacer.setAttribute(name, value);
648
- } else {
649
- attrsMap[name] = attr;
650
- }
637
+ replacer.setAttribute(name, value);
651
638
  }
652
639
  });
653
640
  replacer.renderid = element.renderid;
641
+ replacer.renders = element.renders;
642
+ if (binds.src) replacer.$src = element.$src;
654
643
  element = replacer;
655
644
  element.$scope = scope;
656
645
  element.$parentScopes = parentScopes;
657
646
  }
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
647
  }
666
648
  }
667
649
  if (element.children.length) renderElement(element.children, scope, parentScopes);
668
650
  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
- }
651
+ for (var k in binds) {
652
+ if (directives.hasOwnProperty(k)) {
653
+ directives[k].call(element, [withContext, binds[k]])
697
654
  }
698
- });
699
- rebuild(element);
655
+ else {
656
+ binders._.call(element, k, [withContext, binds[k]]);
657
+ }
658
+ }
659
+ for (var k in attrs) {
660
+ binders[""].call(element, k, [withContext, attrs[k]]);
661
+ }
662
+ for (var k in props) {
663
+ try {
664
+ element[k] = props[k];
665
+ } catch (e) { }
666
+ }
700
667
  ons.forEach(([on, key, value]) => on.call(element, key, [withContext, value]));
701
668
  if (element.renders.length) {
669
+ rebuild(element);
702
670
  onappend(element, addRenderElement);
703
671
  onremove(element, removeRenderElement);
704
672
  if (element.isMounted || element.renderid > 1) addRenderElement.call(element);
@@ -720,11 +688,19 @@ function renderStructure(element, scope, parentScopes = []) {
720
688
  }
721
689
  var attrs = [].concat.apply([], element.attributes);
722
690
  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
691
  var types = {};
725
- if (attrs.length > 2) throw new Error(`请不要在同一元素上使用三次及以上的结构属性:${attrs.map(a => a.name)}`);
726
- attrs.map(function (attr) {
727
- var { name } = attr;
692
+ var emiter_reg = /^(?:(v|ng|on|once)\-|v\-on\:|@|once|on)/i;
693
+ var ons = [];
694
+ var copys = [];
695
+ var binds = {};
696
+ var attr1 = {};
697
+ var props = {};
698
+ for (var attr of attrs) {
699
+ var { name, value } = attr;
700
+ if (/^(?:class|style|src|\:|placeholder)$/i.test(name)) {
701
+ copys.push(attr);
702
+ continue;
703
+ }
728
704
  var key = name.replace(/^(ng|v|.*?)\-/i, "").toLowerCase();
729
705
  if (structures.hasOwnProperty(key) && isFunction(structures[key])) {
730
706
  if (element.renderid <= -2) {
@@ -747,9 +723,29 @@ function renderStructure(element, scope, parentScopes = []) {
747
723
  }
748
724
  if (!element.renderid) element.renderid = -1;
749
725
  else element.renderid = -2;
726
+ // element.removeAttribute(name);
727
+ }
728
+ if (element.$struct) continue;
729
+ var key = name.replace(/^(ng|v|.*?)\-|^[\:\_\.]|^v\-bind\:/i, "").toLowerCase();
730
+ if (directives.hasOwnProperty(key) || /^([\_\:\.]|v\-bind\:)/.test(name)) {
731
+ binds[key] = value;
750
732
  element.removeAttribute(name);
751
733
  }
752
- });
734
+ else if (emiter_reg.test(name)) {
735
+ var match = emiter_reg.exec(name);
736
+ var ngon = (match[1] || match[0]).toLowerCase() === 'once' ? 'once' : 'on';
737
+ element.removeAttribute(name);
738
+ ons.push([emiters[ngon], name.replace(emiter_reg, ''), value]);
739
+ }
740
+ else if (/[_@\:\.]$/.test(name)) {
741
+ attr1[name.replace(/[_@\:\.]$/, "")] = value;
742
+ element.removeAttribute(name);
743
+ }
744
+ else {
745
+ props[name.replace(/\-(\w)/g, (_, w) => w.toUpperCase())] = value === "" ? true : value;
746
+ }
747
+ }
748
+ if (!element.$struct) element.$struct = { ons, copys, binds, attrs: attr1, props, context: withContext };
753
749
  if (element.renderid <= -1) createStructure.call(element, types.if, types.repeat, withContext);
754
750
  }
755
751
  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.options" -repeat="o in f.options">
12
+ <span -text=o.name></span>
13
+ </a>
14
+ </td>
15
+ </tr>
16
+ </tbody>
@@ -91,6 +91,10 @@ var adaptTarget = function (event) {
91
91
  }
92
92
  if (target) target = getFirstSingleColCell(this, target.colend);
93
93
  if (target) {
94
+ if (position.right >= getSelection(this).right - 7) {
95
+ target = this;
96
+ return;
97
+ }
94
98
  css(this, { 'cursor': 'e-resize' });
95
99
  result = {
96
100
  target,
@@ -142,6 +146,7 @@ function table(elem) {
142
146
  var cellMatchManager = function (element) {
143
147
  if (!thead) [thead] = table.getElementsByTagName("thead");
144
148
  if (table.resizing) return false;
149
+ if (!getTargetIn(thead, element)) return false;
145
150
  if (!tdElementReg.test(element.tagName)) return false;
146
151
  var savedRowDeltas = [];
147
152
  [].map.call(thead.children, function (tr) {
@@ -153,10 +158,27 @@ function table(elem) {
153
158
  table.dragbox = function () {
154
159
  return thead;
155
160
  };
161
+ care(table, function ([fields, data]) {
162
+ this.innerHTML = template;
163
+ render(this, {
164
+ fields,
165
+ tbody: list,
166
+ data,
167
+ a: button,
168
+ }, this.$parentScopes.concat(this.$scope));
169
+ })
156
170
  autodragchildren(
157
171
  table,
158
- cellMatchManager,
172
+ function (a) {
173
+ console.log('match')
174
+ return cellMatchManager.apply(this, arguments);
175
+ },
159
176
  function (src, dst, rel, append, parentNode) {
177
+ if (table.src) {
178
+ var [fields] = table.src;
179
+ var [f] = fields.splice(src, 1);
180
+ fields.splice(dst, 0, f);
181
+ }
160
182
  var children = parentNode.children;
161
183
  var srcElement = children[src];
162
184
  var dstElement = children[rel];
@@ -1,15 +1,17 @@
1
- &.dragging {
2
- box-shadow: 0 0 20px -6px #00000033;
3
-
1
+ &[dragchildren] {
4
2
  >thead,
5
3
  >tbody,
6
4
  & {
7
5
  >tr {
8
6
 
9
7
  >th,
10
- >td {}
8
+ >td {
9
+ box-shadow: 1px 0 0 0 #00000033, -1px 0 0 0 #00000033;
10
+ }
11
+
11
12
  }
12
13
  }
14
+
13
15
  }
14
16
 
15
17
  thead,
@@ -17,10 +19,15 @@ tbody,
17
19
  th,
18
20
  td,
19
21
  tr,
20
- table {
22
+ table,
23
+ & {
21
24
  box-sizing: border-box;
22
25
  }
23
26
 
27
+ & {
28
+ outline: 1px solid #0006;
29
+ }
30
+
24
31
  .y-ing {
25
32
  &:before {
26
33
  content: "";
@@ -45,56 +52,67 @@ table {
45
52
  table-layout: fixed;
46
53
  white-space: nowrap;
47
54
 
48
- >thead {
49
- user-select: none;
50
- line-height: 36px;
55
+ }
51
56
 
52
- >tr {
57
+ >thead {
58
+ user-select: none;
59
+ line-height: 36px;
53
60
 
54
- >td,
55
- >th {
56
- padding: @cell-padding;
57
- position: relative;
58
- color: #fff;
59
- background-color: #999;
60
- }
61
+ >tr {
62
+
63
+ >td,
64
+ >th {
65
+ padding: @cell-padding;
66
+ position: relative;
67
+ color: #fff;
68
+ background-color: #999;
61
69
  }
62
70
  }
71
+ }
63
72
 
64
- >tbody {
65
- line-height: 32px;
73
+ >tbody {
74
+ line-height: 32px;
75
+ height: 100%;
76
+ min-height: 30px;
66
77
 
67
- >tr {
78
+ display: table-row-group;
68
79
 
69
- >td,
70
- >th {
71
- padding: @cell-padding;
72
- position: relative;
73
- }
80
+ >tr {
81
+
82
+ >td,
83
+ >th {
84
+ padding: @cell-padding;
85
+ position: relative;
86
+ }
74
87
 
75
- &:nth-child(even) {
88
+ &:nth-of-type(even) {
76
89
 
77
- >td,
78
- >th {
79
- background-color: #eee;
80
- }
90
+ >td,
91
+ >th {
92
+ background-color: #eee;
81
93
  }
94
+ }
82
95
 
83
- &:nth-child(odd) {
96
+ &:nth-of-type(odd) {
84
97
 
85
- >td,
86
- >th {
87
- background-color: #fff;
88
- }
98
+ >td,
99
+ >th {
100
+ background-color: #fff;
89
101
  }
102
+ }
90
103
 
91
- &:hover {
104
+ &:hover {
92
105
 
93
- >td,
94
- >th {
95
- background: #dddddd;
96
- }
106
+ >td,
107
+ >th {
108
+ background: #dddddd;
97
109
  }
98
110
  }
99
111
  }
112
+ }
113
+
114
+ .button {
115
+ margin-right: 10px;
116
+ vertical-align: middle;
117
+ display: inline-block;
100
118
  }
@@ -22,7 +22,8 @@ body>& {
22
22
 
23
23
  &>.body,
24
24
  >[body] {
25
- padding: 6px 0;
25
+ padding: 6px 20px 6px 6px;
26
+ margin-right: -20px;
26
27
  background: #f2f4f6;
27
28
  display: block;
28
29
  width: auto;
@@ -109,14 +110,14 @@ body>& {
109
110
  }
110
111
 
111
112
  .button {
112
- min-width: 60px;
113
113
  vertical-align: middle;
114
- margin-right: 10px;
115
114
  }
116
115
 
117
116
  >.foot,
118
117
  >[foot] {
119
118
  .button {
119
+ min-width: 60px;
120
120
  padding: 0 20px;
121
+ margin-right: 10px;
121
122
  }
122
123
  }
@@ -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.6",
3
+ "version": "3.5.2",
4
4
  "description": "一个开发工具,开放源代码,自带组件库和编译环境,可以用来开发web组件,web应用或nodejs模块,或做为已有代码的加密工具,也可以做为静态页面服务器或跨域中转服务器使用",
5
5
  "main": "public/efront.js",
6
6
  "directories": {