efront 3.3.5 → 3.4.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.
@@ -1,19 +1,43 @@
1
1
  function main(elem) {
2
- var result = elem;
3
- if (isElement(elem) && elem.hasAttribute("ng-src")) {
4
- elem = option(elem);
5
- care(elem, function (p) {
6
- var [f, data] = p;
7
- elem.innerHTML = field;
8
- render(elem, {
9
- model,
10
- data,
11
- field: f
12
- });
13
- }, false);
14
- } else {
15
- result = option.apply(null, arguments);
16
- }
17
- result.removeAttribute("tabindex");
18
- return result;
2
+ elem = option.apply(null, arguments);
3
+ var scope = {};
4
+ care(elem, function (p) {
5
+ if (elem.childNodes.length) return;
6
+ var [f, data] = p;
7
+ elem.innerHTML = field;
8
+ render(elem, scope = {
9
+ model,
10
+ data,
11
+ error: null,
12
+ field: f
13
+ });
14
+ elem.oldValue = data[f.key];
15
+ elem.setAttribute("field", f.key);
16
+ }, false);
17
+ elem.setAttribute("field", '');
18
+ elem.renders = [function () {
19
+ if (!this.src) return;
20
+ var [f, data] = this.src;
21
+ if (!f || !data) return;
22
+ var v = data[f.key];
23
+ if (!this.checked) if (v === this.oldValue || isEmpty(this.oldValue) && isEmpty(v)) return;
24
+ this.checked = false;
25
+ this.setAttribute("dirty", '');
26
+ var error = valid(f, data);
27
+ if (error) {
28
+ this.setAttribute("error", error);
29
+ switch (error) {
30
+ case "empty":
31
+ scope.error = `${f.name}是必填字段!`;
32
+ break;
33
+ }
34
+ }
35
+ else {
36
+ this.removeAttribute('error');
37
+ scope.error = null;
38
+ }
39
+ this.oldValue = data[f.key];
40
+ }]
41
+ elem.removeAttribute("tabindex");
42
+ return elem;
19
43
  }
@@ -32,4 +32,23 @@
32
32
 
33
33
  .input {
34
34
  width: 100%;
35
+ }
36
+
37
+ .required {
38
+ color: #c24;
39
+ display: inline-block;
40
+ }
41
+
42
+ &.error,
43
+ &[error] {
44
+ background: #f322;
45
+
46
+ model>* {
47
+ background: #f322;
48
+ border-color: #f32;
49
+ outline: 1px solid #f32;
50
+ }
51
+ .error{
52
+ color:#c32;
53
+ }
35
54
  }
@@ -2,5 +2,13 @@ function form(elem) {
2
2
  if (!elem) {
3
3
  elem = document.createElement("form");
4
4
  }
5
+ if (/form/i.test(elem.tagName)) {
6
+ on("submit")(elem, function (event) {
7
+ event.preventDefault();
8
+ var fields = elem.querySelectorAll(".field");
9
+ for (var f of fields) f.checked = true;
10
+ render.refresh();
11
+ });
12
+ }
5
13
  return elem;
6
14
  }
@@ -1,8 +1,8 @@
1
1
  function getChanges(current_props, previous_props) {
2
2
  if (!isObject(current_props) && !isObject(previous_props)) return !deepEqual.shallow(current_props, previous_props);
3
- if (!isObject(current_props)) return true;
4
- if (!isObject(previous_props)) return current_props;
5
3
  var changes = null;
4
+ if (!isObject(current_props)) current_props = Object.create(null), changes = {};
5
+ if (!isObject(previous_props)) previous_props = Object.create(null), changes = {};
6
6
  keys(previous_props, current_props).forEach(function (key) {
7
7
  if (!deepEqual.shallow(current_props[key], previous_props[key])) {
8
8
  if (!changes) changes = {};
@@ -38,6 +38,7 @@ var constructors = {
38
38
  input,
39
39
  raw: input,
40
40
  row: textarea,
41
+ password,
41
42
  text: textarea,
42
43
  date() {
43
44
  var elem = document.createElement("input");
@@ -71,7 +71,7 @@ var createGetter = function (search, isprop = true) {
71
71
  });
72
72
  }
73
73
  if (isprop) {
74
- return new Function('event', `try{${withContext}with(this.$scope){${ret}${searchContext}}}catch(e){/*console.warn(String(e))*/}`);
74
+ return new Function('event', `${withContext}with(this.$scope){${ret}${searchContext}}`);
75
75
  }
76
76
  return new Function("event", `${withContext}with(this.$scope){${/([\=\(\+\-])/.test(searchContext) ? ret + searchContext : `${ret}${searchContext}.call(this.$scope,event)`}}`);
77
77
  };
@@ -346,13 +346,42 @@ var structures = {
346
346
  };
347
347
  structures["else-if"] = structures.elseif = structures.else;
348
348
  structures["for-each"] = structures.foreach = structures.for = structures.each = structures.repeat;
349
- var changed = function () {
350
- if (!this.dirty) this.dirty = true, this.setAttribute('dirty', '');
351
- };
349
+ var createBinder = function (binder) {
350
+ return function (search) {
351
+ var getter = createGetter(search).bind(this);
352
+ var oldValue;
353
+ this.renders.push(function () {
354
+ var value = getter();
355
+ if (deepEqual.shallow(value, oldValue)) return;
356
+ oldValue = value;
357
+ if (isNode(value) || isArray(value)) {
358
+ if (value !== this.firstChild) {
359
+ remove(this.childNodes);
360
+ appendChild(this, value);
361
+ }
362
+ } else {
363
+ if (isEmpty(value)) value = '';
364
+ if (binder(this) !== value) binder(this, value);
365
+ }
366
+ });
367
+
368
+ }
369
+ }
352
370
  var directives = {
371
+ bind: createBinder(text),
372
+ html: createBinder(html),
373
+ hide: createBinder(function (elem, value) {
374
+ if (arguments.length === 1) return elem.style.display === 'none';
375
+ elem.style.display = value ? 'none' : '';
376
+ }),
377
+ show: createBinder(function (elem, value) {
378
+ if (arguments.length === 1) return elem.style.display !== 'none';
379
+ elem.style.display = value ? '' : 'none';
380
+ }),
381
+ style: createBinder(css),
353
382
  src(search) {
354
383
  var getter = createGetter(search).bind(this);
355
- var savedValue, savedOrigin, pending;
384
+ var savedValue, pending;
356
385
  var refresh = function () {
357
386
  that.src = savedValue;
358
387
  removeClass(that, "pending");
@@ -372,10 +401,8 @@ var directives = {
372
401
  }
373
402
  var changes = getChanges(temp, savedValue);
374
403
  if (!changes) return;
375
- savedOrigin = origin;
376
404
  savedValue = temp;
377
405
  if (/^img$/i.test(this.tagName)) {
378
- // this.setAttribute("src", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYV2NgAAIAAAUAAarVyFEAAAAASUVORK5CYII=");
379
406
  if (!isString(origin)) {
380
407
  return;
381
408
  }
@@ -394,23 +421,6 @@ var directives = {
394
421
  }
395
422
  });
396
423
  },
397
- bind(search) {
398
- var getter = createGetter(search).bind(this);
399
- var oldValue;
400
- this.renders.push(function () {
401
- var value = getter();
402
- if (deepEqual(value, oldValue)) return;
403
- oldValue = value;
404
- if (isNode(value) || isArray(value)) {
405
- if (value !== this.firstChild) {
406
- remove(this.childNodes);
407
- appendChild(this, value);
408
- }
409
- } else {
410
- if (text(this) !== value) text(this, value);
411
- }
412
- });
413
- },
414
424
  model(search) {
415
425
  var getter = createGetter(search).bind(this);
416
426
  var oldValue;
@@ -462,35 +472,6 @@ var directives = {
462
472
  }
463
473
  var onchange = change;
464
474
  eventsHandlers.map(on => on(this, onchange));
465
- eventsHandlers.map(on => on(this, changed));
466
- },
467
- hide(search) {
468
- var getter = createGetter(search).bind(this);
469
- var oldValue;
470
- this.renders.push(function () {
471
- var value = !!getter();
472
- if (deepEqual(oldValue, value)) return;
473
- oldValue = value;
474
- if (value) {
475
- this.style.display = "none";
476
- } else {
477
- this.style.display = "";
478
- }
479
- });
480
- },
481
- show(search) {
482
- var getter = createGetter(search).bind(this);
483
- var oldValue;
484
- this.renders.push(function () {
485
- var value = !!getter();
486
- if (deepEqual(oldValue, value)) return;
487
- oldValue = value;
488
- if (value) {
489
- this.style.display = "";
490
- } else {
491
- this.style.display = "none";
492
- }
493
- });
494
475
  },
495
476
 
496
477
  "class"(search) {
@@ -528,16 +509,6 @@ var directives = {
528
509
  }
529
510
  });
530
511
  },
531
- style(search) {
532
- var getter = createGetter(search).bind(this);
533
- var oldValue;
534
- this.renders.push(function () {
535
- var stylesheet = getter();
536
- if (deepEqual(oldValue, stylesheet)) return;
537
- oldValue = stylesheet;
538
- css(this, stylesheet);
539
- });
540
- }
541
512
  };
542
513
  // property binder
543
514
  var binders = {
@@ -38,4 +38,5 @@ extend(renderDefaults, {
38
38
  swap,
39
39
  password,
40
40
  table,
41
+ form,
41
42
  });
@@ -0,0 +1,41 @@
1
+ function submit(fields, data) {
2
+ var params = {};
3
+ var inputs = [];
4
+ var select = [];
5
+ var checks = [];
6
+ var id = 0;
7
+ for (var f of fields) {
8
+ var error = valid(f, data);
9
+ if (error === "empty") {
10
+ if (f.options || /date|time|range|switch|swap|radio/i.test(f.type)) {
11
+ if (!select.id) select.id = ++id;
12
+ select.push(f);
13
+ }
14
+ else {
15
+ if (!inputs.id) inputs.id = ++id;
16
+ inputs.push(f);
17
+ }
18
+ }
19
+ else if (error) {
20
+ checks.push(f);
21
+ }
22
+ else {
23
+ params[f.key] = data[f.key];
24
+ }
25
+ }
26
+ if (checks.length + select.length + inputs.length) {
27
+ var errors = [];
28
+ if (inputs.length) errors.push("请输入" + inputs.map(f => f.name).join("、"));
29
+ if (select.length) errors.push("请选择" + select.map(f => f.name).join("、"));
30
+ if (select.id < inputs.id) {
31
+ errors = errors.reverse();
32
+ }
33
+ if (checks.length) {
34
+ errors.push(checks.map(f => f.name).join("、") + "格式错误");
35
+ }
36
+ errors = errors.join(",") + "!";
37
+ alert(errors, 'error');
38
+ throw new Error(errors);
39
+ }
40
+ return params;
41
+ }
@@ -94,11 +94,6 @@ var init = function () {
94
94
  function view(element) {
95
95
  var window = isNode(element) ? element : document.createElement("form");
96
96
  init();
97
- if (/form/i.test(window.tagName)) {
98
- on("submit")(window, function (event) {
99
- event.preventDefault();
100
- });
101
- }
102
97
  extend(window, prototype);
103
98
  if (window !== element) {
104
99
  extend(window, element);
@@ -13,13 +13,15 @@ body>& {
13
13
  -ms-user-select: none;
14
14
  -moz-user-select: none;
15
15
  -webkit-user-select: none;
16
+ border: 1px solid #0006;
16
17
  }
17
18
 
18
19
  &[dragable] {
19
20
  position: absolute;
20
21
  }
21
22
 
22
- &>.body {
23
+ &>.body,
24
+ >[body] {
23
25
  padding: 6px 0;
24
26
  background: #f2f4f6;
25
27
  display: block;
@@ -42,7 +44,8 @@ body>& {
42
44
  }
43
45
 
44
46
 
45
- &>.head {
47
+ &>.head,
48
+ >[head] {
46
49
  z-index: 2;
47
50
  background: #fffc;
48
51
  position: relative;
@@ -83,12 +86,14 @@ body>& {
83
86
  }
84
87
  }
85
88
 
86
- &>.foot {
89
+ &>.foot,
90
+ >[foot] {
87
91
  white-space: nowrap;
88
92
  overflow: auto;
89
93
  }
90
94
 
91
- &>.foot {
95
+ &>.foot,
96
+ >[foot] {
92
97
  z-index: 1;
93
98
  text-align: right;
94
99
  line-height: 1;
@@ -101,13 +106,14 @@ body>& {
101
106
  bottom: 0;
102
107
  margin-top: -42px;
103
108
 
104
- .button {
105
- padding: 0 20px;
106
- min-width: 60px;
107
- vertical-align: middle;
109
+ }
108
110
 
109
- &+.button {
110
- margin-left: 10px;
111
- }
111
+ .button {
112
+ padding: 0 20px;
113
+ min-width: 60px;
114
+ vertical-align: middle;
115
+
116
+ &+.button {
117
+ margin-left: 10px;
112
118
  }
113
119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "3.3.5",
3
+ "version": "3.4.0",
4
4
  "description": "一个开发工具,开放源代码,自带组件库和编译环境,可以用来开发web组件,web应用或nodejs模块,或做为已有代码的加密工具,也可以做为静态页面服务器或跨域中转服务器使用",
5
5
  "main": "public/efront.js",
6
6
  "directories": {