efront 4.0.41 → 4.0.48

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.
@@ -7,9 +7,7 @@ var RETURN = { type: STRAP, text: "@ret" };// return;
7
7
  var THROW = { type: STRAP, text: "@throw" };// return;
8
8
  var YIELD = { type: STRAP, text: "@yield" };// return;
9
9
  var NEXT = { type: STRAP, text: "@next" };// return;
10
- var _break = function (body, cx, result, iscontinue) {
11
- var re = result[result.length - 1];
12
- if (!result.length || re.ret_ && !re.await_ && re.ret_ !== -2) return;
10
+ var mount_break = function (body, cx, b1s, iscontinue) {
13
11
  var label;
14
12
  do {
15
13
  var o = body[++cx];
@@ -24,11 +22,11 @@ var _break = function (body, cx, result, iscontinue) {
24
22
  if (b.type === LABEL && b.text === label + ":") {
25
23
  if (!s) s = b;
26
24
  if (!b.breaks) b.breaks = [];
27
- var _b = scanner2('return []');
28
- _b.ret_ = -1;
29
- if (iscontinue) _b[1].continue = s, s.continue = true;
30
- b.breaks.push(_b[1]);
31
- pushstep(result, _b);
25
+ if (iscontinue) s.continue = true;
26
+ b1s.forEach(b1 => {
27
+ if (iscontinue) b1.continue = s
28
+ b.breaks.push(b1);
29
+ });
32
30
  break;
33
31
  }
34
32
  else {
@@ -41,16 +39,24 @@ var _break = function (body, cx, result, iscontinue) {
41
39
  var b = labels[cx];
42
40
  if (b.type !== LABEL && (!iscontinue || b.text !== 'switch')) {
43
41
  if (!b.breaks) b.breaks = [];
44
- var _b = scanner2("return []");
45
- _b.ret_ = -1;
46
- if (iscontinue) _b[1].continue = b, b.continue = true;
47
- b.breaks.push(_b[1]);
48
- pushstep(result, _b);
42
+ if (iscontinue) b.continue = true;
43
+ b1s.forEach(b1 => {
44
+ if (iscontinue) b1.continue = b;
45
+ b.breaks.push(b1);
46
+ })
49
47
  break;
50
48
  }
51
49
  }
52
50
  }
53
51
  return bx;
52
+ }
53
+ var _break = function (body, cx, result, iscontinue) {
54
+ var re = result[result.length - 1];
55
+ if (!result.length || re.ret_ && !re.await_ && re.ret_ !== -2) return;
56
+ var _b = scanner2('return []');
57
+ _b.ret_ = -1;
58
+ mount_break(body, cx, [_b[1]], iscontinue);
59
+ pushstep(result, _b);
54
60
  };
55
61
  var _try = function (body, cx, unblock, result, getname) {
56
62
  var o = body[cx];
@@ -140,11 +146,13 @@ var _switch = function (body, cx, unblock, result, getname) {
140
146
  var tmp = [];
141
147
  while (o[cy] !== m) cy++;
142
148
  var default_ = null, case_ = null;
149
+ var cbindex = 0, cblength = 0;
143
150
  while (cy < o.length) {
144
151
  var block = getblock(o, ++cy);
145
152
  cy += block.length;
146
153
  while (cy < o.length && o[cy].type & (SPACE | COMMENT)) cy++;
147
154
  cy++;
155
+ while (cy < o.length && o[cy].type & (SPACE | COMMENT)) cy++;
148
156
  var getnextname = function (deep) {
149
157
  return getname(deep + 1);
150
158
  };
@@ -152,18 +160,43 @@ var _switch = function (body, cx, unblock, result, getname) {
152
160
  for (var q of q) if (q.length) pushstep(result, q);
153
161
  var qe = q;
154
162
  if (qe.name) case_ = scanner2(`if(${qn}===${qe.name})return[]`), pushstep(result, case_);
155
- else default_ = case_ = scanner2(`return[]`), default_.ret_ = -1;
163
+ else default_ = case_ = scanner2(`return[]`), default_.ret_ = -2;
156
164
  var by = cy;
157
165
  m = o[cy];
158
166
  while (m && (m.type !== STRAP || !/^(default|case)$/i.test(m.text))) m = o[++cy];
159
- tmp.push(result.length - 1, case_[case_.length - 1], o.slice(by, cy));
167
+ var cbody = o.slice(by, cy);
168
+ var cb0 = cbody[0];
169
+ if (cb0 && cb0.type === STRAP && (cb0.text === "break" || cb0.text === 'continue')) {
170
+ if (!cblength) {
171
+ var brks = [case_[case_.length - 1]];
172
+ while (tmp.length > cbindex) {
173
+ tmp.pop();
174
+ brks.push(tmp.pop());
175
+ tmp.pop();
176
+ };
177
+ mount_break(cbody, 0, brks, cb0.text === 'continue');
178
+ cblength = 0;
179
+ cbindex = tmp.length;
180
+ continue;
181
+ }
182
+ cbindex = tmp.length + 3;
183
+ cblength = 0;
184
+ }
185
+ while (cbody.length) {
186
+ var cbe = cbody[cbody.length - 1];
187
+ if (cbe.type === SPACE) cbody.pop();
188
+ else if (cbe.type === STAMP && cbe.text === ';') cbody.pop();
189
+ else break;
190
+ }
191
+ cblength += cbody.length;
192
+ tmp.push(result.length - 1, case_[case_.length - 1], cbody);
160
193
  }
161
194
  if (!default_) {
162
- default_ = scanner2(`return[]`), default_.ret_ = -1;
163
- tmp.push(result.length - 1, default_[default_.length - 1], []);
195
+ default_ = scanner2(`return[]`), default_.ret_ = -2;
196
+ if (tmp.length) tmp.push(result.length - 1, default_[default_.length - 1], []);
164
197
  }
165
198
  var default_r = default_[default_.length - 1];
166
- pushstep(result, default_);
199
+ if (tmp.length) pushstep(result, default_);
167
200
  default_r.index = result.length - 1;
168
201
  while (tmp.length) {
169
202
  cy = tmp.shift();
@@ -441,7 +474,7 @@ var remove_end_comma = function (o) {
441
474
  };
442
475
  var ispropcall = function (o) {
443
476
  var n = o.next;
444
- if (!n || n.type !== SCOPED && n.entry !== '(') return false;
477
+ if (!n || n.type !== SCOPED || n.entry !== '(') return false;
445
478
  if (o.type === EXPRESS && snapExpressHead(o) !== o) return true;
446
479
  if (o.type === SCOPED && o.entry === '[' && snapExpressHead(o) !== o) return true;
447
480
  return false;
@@ -457,6 +490,7 @@ var _invoke = function (t, getname) {
457
490
  queue.name = t.name;
458
491
  var qname = t.name;
459
492
  var bx = 0;
493
+ var lastlink = false;
460
494
  for (var cx = 0; cx < t.length; cx++) {
461
495
  var o = t[cx];
462
496
  a: if (o.type === STRAP) {
@@ -482,6 +516,7 @@ var _invoke = function (t, getname) {
482
516
  }
483
517
  if (o.type === SCOPED && (o.entry === '[' || o.entry === "(")) {
484
518
  var _nameindex = nameindex;
519
+ nameindex += lastlink;
485
520
  remove_end_comma(o);
486
521
  var iseval = o.iseval = isEval(o);
487
522
  var constStart = 0;
@@ -532,16 +567,19 @@ var _invoke = function (t, getname) {
532
567
  for (var c of cache) pushstep(result, c);
533
568
  cache = [];
534
569
  var n = o.next;
535
- if (n && !needbreak(n) && !ispropcall(o)) {
536
- var h = snapExpressHead(o);
537
- var hx = t.lastIndexOf(h, cx);
538
- var fs = splice(t, hx, cx + 1 - hx, { type: EXPRESS, text: getname(nameindex) });
539
- fs.unshift(...scanner2(`${getname(nameindex)}=`));
540
- relink(fs);
541
- fs.name = getname(nameindex);
542
- pushstep(result, fs);
543
- nameindex++;
544
- cx = hx - 1;
570
+ if (n && !needbreak(n)) {
571
+ lastlink = n.type === SCOPED;
572
+ if (!ispropcall(o)) {
573
+ var h = snapExpressHead(o);
574
+ var hx = t.lastIndexOf(h, cx);
575
+ var fs = splice(t, hx, cx + 1 - hx, { type: EXPRESS, text: getname(nameindex) });
576
+ fs.unshift(...scanner2(`${getname(nameindex)}=`));
577
+ relink(fs);
578
+ fs.name = getname(nameindex);
579
+ pushstep(result, fs);
580
+ cx = hx - 1;
581
+ }
582
+ if (!lastlink) nameindex++;
545
583
  }
546
584
  }
547
585
  }
@@ -40,7 +40,7 @@ test('a * a && await b*c', "_ = a * a; if (!_) return [2, 0]; _ = b; return [_,
40
40
  test("await a", "_ = a; return [_, 1]", true);
41
41
  test("yield a", "return [a, 3]", true);
42
42
  test("!a.done&&(b=await a.value)", "_ = !a.done; if (!_) return [2, 0]; _ = a.value; return [_, 1];\r\n _ = @; b = _; (_)", true);
43
- test("a=1?2:3",`if (false) return [1, 0]; a = 2; return [2, 0];\r\n a = 3; return [1, 0]`)
43
+ test("a=1?2:3", `if (false) return [1, 0]; a = 2; return [2, 0];\r\n a = 3; return [1, 0]`)
44
44
  test("await a()", "_ = a(); return [_, 1]", true);
45
45
  test("yield a()", "_ = a(); return [_, 3]", true);
46
46
  test("a = await a()", "_ = a(); return [_, 1];\r\n _ = @; a = _", true);
@@ -77,9 +77,9 @@ test("do{await b}while(a)", "_ = b; return [_, 1];\r\n _ = @; if (a) return [-1,
77
77
  test("switch(a){case 1:}", "if (a === 1) return [1, 0]; return [1, 0]", true);
78
78
  test("switch(a){case 1: default:}", "if (a === 1) return [1, 0]; return [1, 0]", true);
79
79
  test("switch(a.a){case 1:}", "_ = a.a; if (_ === 1) return [1, 0]; return [1, 0]", true);
80
- test("switch(a){case 1:break;}", "if (a === 1) return [1, 0]; return [1, 0]", true);
81
- test("switch(a){case 1:break;case 2:break;}", "if (a === 1) return [1, 0]; if (a === 2) return [1, 0]; return [1, 0]", true);
82
- test("switch(a){case 1:case 2:break;}", "if (a === 1) return [1, 0]; if (a === 2) return [1, 0]; return [1, 0]", true);
80
+ test("switch(a){case 1:break;}", "if (a === 1) return [1, 0]", true);
81
+ test("switch(a){case 1:break;case 2:break;}", "if (a === 1) return [1, 0]; if (a === 2) return [1, 0]", true);
82
+ test("switch(a){case 1:case 2:break;}", "if (a === 1) return [1, 0]; if (a === 2) return [1, 0]", true);
83
83
  test("switch(a){case 1:case 2:x=1;}", "if (a === 1) return [1, 0]; if (a === 2) return [1, 0]; return [2, 0];\r\n x = 1; return [1, 0]", true);
84
84
  test("switch(a){case 1:case 2:x=1;}", "if (a === 1) return [1, 0]; if (a === 2) return [1, 0]; return [2, 0];\r\n x = 1; return [1, 0]", true);
85
85
  test("with(a){ a = 1}", `if (_ = with_("a", [a])) _.a = 1; else a = 1;`, true);
@@ -120,4 +120,12 @@ test("menus[0].name+='aaa'", "_ = menus[0]; _0 = _.name + 'aaa'; _.name = _0", t
120
120
  test("menus[a+b].name+='aaa'", "_ = a + b; _ = menus[_]; _0 = _.name + 'aaa'; _.name = _0", true);
121
121
  test("menus[a+b]()", "_ = a + b; menus[_]()", true);
122
122
  test(`switch(a){default: a;case 1:b;}`, 'if (a === 1) return [2, 0]; return [1, 0];\r\n a; return [1, 0];\r\n b; return [1, 0]', true);
123
- test("loop:{a=b;if(a) continue loop}", "a = b; if (a) return [0, 0]", true);
123
+ test("loop:{a=b;if(a) continue loop}", "a = b; if (a) return [0, 0]", true);
124
+ test("if(a)try{}finally{}else a;", 'if (!a) return [4, 0]; return [1, 8];\r\n return [0, 9];\r\n return [1, 9];\r\n return [2, 0];\r\n a; return [1, 0]')
125
+ test("if(a)try{}finally{}else;", 'if (!a) return [4, 0]; return [1, 8];\r\n return [0, 9];\r\n return [1, 9];\r\n return [1, 0]');
126
+ test("b:while(t){switch(a){case c:break b;}}", 'if (!t) return [1, 0]; if (a === c) return [1, 0]; return [0, 0]');
127
+ test("predef[key[1]](r.slice(key[0].length).trim())", '_ = key[1]; _0 = key[0].length; _0 = r.slice(_0); _0 = _0.trim(); predef[_](_0)');
128
+ test("predef[key[1]](r.slice())(r.slice())", '_ = key[1]; _0 = r.slice(); _ = predef[_](_0); _0 = r.slice(); _(_0)');
129
+ test("predef[key[1]][key[2]][key[3]]", '_ = key[1]; _ = predef[_]; _0 = key[2]; _ = _[_0]; _0 = key[3]; _[_0]');
130
+ test("[key[1]][key[2]][key[3]]", '_ = key[1]; _ = [_]; _0 = key[2]; _ = _[_0]; _0 = key[3]; _[_0]');
131
+ test("[key[1]][key[2]]+[key[3]][key[4]]", '_ = key[1]; _ = [_]; _0 = key[2]; _ = _[_0]; _0 = key[3]; _0 = [_0]; _1 = key[4]; _ + _0[_1]');
@@ -1,13 +1,22 @@
1
- function main(title, type, params, idkey = params.fields[0].key) {
1
+ function send(type, key, value, origin) {
2
+ return data.from(origin ? "edit" : "add", {
3
+ type,
4
+ key: encode62.timeencode(key),
5
+ value: encode62.timeencode(JSON.stringify(value)),
6
+ }).loading_promise;
7
+ }
8
+ function pedit(title, type, params, idkey = params.fields[0].key) {
2
9
  return frame$edit(title, {
3
10
  submit(a, fields) {
4
11
  a = submit(fields, a);
5
- return data.from(params.data ? "edit" : "add", {
6
- type,
7
- key: encode62.timeencode(a[idkey]),
8
- value: encode62.timeencode(JSON.stringify(a)),
9
- }).loading_promise;
12
+ return send(type, a[idkey], a, params.data);
10
13
  },
11
14
 
12
15
  }, params);
16
+ }
17
+ pedit.create = function (type, key, value) {
18
+ return send(type, key, value, false);
19
+ }
20
+ pedit.update = function (type, key, value) {
21
+ return send(type, key, value, true);
13
22
  }
@@ -0,0 +1,36 @@
1
+ var path = require("path");
2
+ var fs = require("fs").promises;
3
+ var str2array = require("../basic/str2array");
4
+ async function detectWithExtension(filenames, extensions = [""], folders = [""]) {
5
+ if (typeof filenames === 'string') filenames = str2array(filenames);
6
+ if (typeof extensions === 'string') extensions = str2array(extensions);
7
+ if (typeof folders === 'string') folders = str2array(folders);
8
+ if (extensions === null) {
9
+ extensions = [""];
10
+ }
11
+ if (folders === null) folders = [""];
12
+ extensions = [].concat(extensions);
13
+ filenames = filenames.map(f => efront$$split(f).join('/')).map(filename => {
14
+ var tempname = filename.replace(/[#\?][\s\S]*$/, '');
15
+ var params = filename.slice(tempname.length);
16
+ return [tempname, params];
17
+ });
18
+
19
+ var findedFolder = null;
20
+ for (var folder of folders) for (var [tempname, params] of filenames) for (var ext of extensions) {
21
+ var f = tempname + ext;
22
+ if (folder) f = path.join(folder, f);
23
+ f = path.normalize(f);
24
+ try {
25
+ var stats = await fs.stat(f);
26
+ if (stats.isFile()) {
27
+ f = await fs.realpath(f);
28
+ return f + params;
29
+ }
30
+ if (!findedFolder) findedFolder = f + params;
31
+ } catch { }
32
+ }
33
+ if (!findedFolder) throw new Error(`路径<gray>${filenames}</gray>不存在`);
34
+ return findedFolder;
35
+ }
36
+ module.exports = detectWithExtension;
@@ -936,7 +936,7 @@ var data = {
936
936
  var promise1 = instance.loading_promise;
937
937
  if (promise1) {
938
938
  var params = promise1.params;
939
- if (deepEqual.shallow(params1, params)) {
939
+ if (shallowEqual(params1, params)) {
940
940
  return instance;
941
941
  }
942
942
  }
@@ -1,11 +1,11 @@
1
1
  function getChanges(current_props, previous_props) {
2
- if (!isObject(current_props) && !isObject(previous_props)) return !deepEqual.shallow(current_props, previous_props);
2
+ if (!isObject(current_props) && !isObject(previous_props)) return !shallowEqual(current_props, previous_props);
3
3
  var changes = null;
4
4
  if (!isObject(current_props)) current_props = Object.create(null), changes = {};
5
5
  if (!isObject(previous_props)) previous_props = Object.create(null), changes = {};
6
6
  keys(previous_props, current_props).forEach(function (key) {
7
7
  if (key.charAt(0) === "$") return;
8
- if (!deepEqual.shallow(current_props[key], previous_props[key])) {
8
+ if (!shallowEqual(current_props[key], previous_props[key])) {
9
9
  if (!changes) changes = {};
10
10
  changes[key] = { previous: previous_props[key], current: current_props[key] };
11
11
  }
@@ -216,7 +216,7 @@ var createRepeat = function (search, id = 0) {
216
216
  var result = getter(this);
217
217
  var origin = result;
218
218
  result = extend(result instanceof Array ? [] : {}, result);
219
- if (savedOrigin === origin && deepEqual.shallow(savedValue, result)) return;
219
+ if (savedOrigin === origin && shallowEqual(savedValue, result)) return;
220
220
  var changes = getChanges(result, savedValue);
221
221
  if (!changes) return;
222
222
  savedValue = result;
@@ -442,7 +442,7 @@ var createBinder = function (binder) {
442
442
  var oldValue;
443
443
  this.renders.push(function () {
444
444
  var value = getter(this);
445
- if (deepEqual.shallow(value, oldValue)) return;
445
+ if (shallowEqual(value, oldValue)) return;
446
446
  var oldv = oldValue;
447
447
  oldValue = value;
448
448
  if (isNode(value) || isArray(value)) {
@@ -182,7 +182,7 @@ function select(target, list, removeOnSelect, direction) {
182
182
  }
183
183
  return o.selected;
184
184
  });
185
- if (deepEqual.shallow(lastSelected, selected)) return;
185
+ if (shallowEqual(lastSelected, selected)) return;
186
186
  lastSelected = selected;
187
187
  if (hasIcon) {
188
188
  var icon = selected.length === 1 && selected[0].getAttribute('icon');
@@ -198,7 +198,7 @@ function select(target, list, removeOnSelect, direction) {
198
198
  };
199
199
  var initList = function () {
200
200
  var allOptions = [].concat.apply([], target.querySelectorAll("option"));
201
- if (deepEqual.shallow(allOptions, savedOptions)) return;
201
+ if (shallowEqual(allOptions, savedOptions)) return;
202
202
  savedOptions = allOptions;
203
203
  list = selectList(allOptions, !!target.multiple, !!target.editable);
204
204
  setListValue();
@@ -2,8 +2,8 @@
2
2
  <tr inline-block #adapter thead @mounted="resizeT(this)">
3
3
  <td draggable="false" fixed row-index>${i18n`序号`}</td>
4
4
  <td fixed:="f.fixed" -repeat="f in fields track by f.id" :style="{width:f.width}" @dblclick="sort(f)"><i
5
- -if="f.icon" -class="f.icon"></i><span -if="f.name" -html="f.name"></span><template
6
- -else>&nbsp;</template>
5
+ -if="f.icon" -class="f.icon"></i><span -if="f.name" -html="f.name"
6
+ type@="typeof f.type==='string'?f.type:''"></span><template -else>&nbsp;</template>
7
7
  </td>
8
8
  <td style="min-width: 0;" draggable="false">&nbsp;</td>
9
9
  </tr>
@@ -527,7 +527,7 @@ function table(elem) {
527
527
  render(this, $scope, this.$parentScopes.concat(this.$scope));
528
528
  $scope.data = Table.from(fields, await data);
529
529
  $scope.data.callback = function () {
530
- if ($scope.tbody0) $scope.tbody0.go($scope.tbody0.index());
530
+ render.digest();
531
531
  };
532
532
  })
533
533
  autodragchildren(
@@ -142,6 +142,7 @@ thead {
142
142
  position: relative;
143
143
  color: #fff;
144
144
  background-color: #395268;
145
+ clear: both;
145
146
  }
146
147
  }
147
148
  }
@@ -188,6 +189,7 @@ thead {
188
189
  z-index: 1;
189
190
  background: #999;
190
191
  color: #fff;
192
+ clear: both;
191
193
  }
192
194
  }
193
195
 
@@ -212,4 +214,10 @@ thead {
212
214
  margin-right: 10px;
213
215
  vertical-align: middle;
214
216
  display: inline-block;
217
+ }
218
+
219
+ [type=money],
220
+ [type=number],
221
+ [type=price] {
222
+ float: right;
215
223
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "4.0.41",
3
+ "version": "4.0.48",
4
4
  "description": "简化前端开发,优化web性能",
5
5
  "main": "public/efront.js",
6
6
  "directories": {