efront 3.19.0 → 3.20.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.
@@ -6,10 +6,12 @@ function isFile(a) {
6
6
  }
7
7
  }
8
8
  var base = null, location_href = null;
9
+ var encrypt = null;
9
10
  // ///// 1 ////////// 2 /////// 3 //// 4 //
10
11
  var domainReg = /^(?:(https?)\:)?\/\/(.*?)(?:\/(.*?))?([\?#].*)?$/i;
11
12
  var setHost = function (host) {
12
13
  base = host;
14
+ if (encrypt) encrypt = getCode.call(this);
13
15
  };
14
16
  var HeadersKeys = ["Content-Type"];
15
17
  var cors_hosts = [];
@@ -26,7 +28,7 @@ function isChildPath(relative, path) {
26
28
  return relative.replace(/^(.*\/)[^\/]*$/, path);
27
29
  }
28
30
 
29
- var getCrossUrl = function (domain, headers) {
31
+ var getCrossUrl = function (domain, headers, encrypt) {
30
32
  if (notCross(domain)) return domain;
31
33
  var originDomain = getDomainPath(domain);
32
34
  var _cookies = getCookies(originDomain);
@@ -37,9 +39,13 @@ var getCrossUrl = function (domain, headers) {
37
39
  extend(_headers, headers);
38
40
  _headers = serialize(_headers);
39
41
  if (_headers) _headers = "," + _headers;
40
- return domain
42
+ var b = encrypt ? "!" : `*`;
43
+ domain = domain
41
44
  .replace(/^(s?)(\/\/)/i, "http$1:$2")
42
- .replace(domainReg, base + `*${/^(https\:|s\/\/)/i.test(domain) ? "*" : ""}$2${_headers}/$3$4`);
45
+ .replace(domainReg, `$2${_headers}/$3$4`)
46
+ if (/^(https\:|s\/\/)/i.test(domain)) domain = b + domain;
47
+ if (encrypt) domain = encode62.timeencode(domain);
48
+ return base + b + domain;
43
49
  };
44
50
  function noop() { }
45
51
  function toResponse() {
@@ -113,7 +119,7 @@ function cross_(jsonp, digest = noop, method, url, headers) {
113
119
  }
114
120
  else {
115
121
  var nocross = notCross(url);
116
- var callback = function () {
122
+ var callback = async function () {
117
123
  var exposeHeaders = !nocross && xhr.getResponseHeader("access-control-expose-headers");
118
124
  var exposeMap = {};
119
125
  if (exposeHeaders) exposeHeaders.split(",").forEach(h => exposeMap[h.toLowerCase()] = true);
@@ -124,6 +130,13 @@ function cross_(jsonp, digest = noop, method, url, headers) {
124
130
  addCookie(cookie, originDomain);
125
131
  }
126
132
  }
133
+ if (isencrypt && xhr.response) {
134
+ xhr = {
135
+ status: xhr.status,
136
+ response: encode62.safedecode(xhr.response || xhr.responseText, xhr.encrypt),
137
+ };
138
+ xhr.responseText = xhr.response;
139
+ };
127
140
  switch (xhr.status) {
128
141
  case 0:
129
142
  if (!xhr.response) {
@@ -167,6 +180,10 @@ function cross_(jsonp, digest = noop, method, url, headers) {
167
180
  var xhr = cross(callback, onerror);
168
181
  var send = xhr.send;
169
182
  xhr.toString = toResponse;
183
+ var isencrypt = /^[夏商周秦xszq]/i.test(method);
184
+ if (isencrypt) method = method.slice(1);
185
+ if (isencrypt && !encrypt) encrypt = cross.getCode();
186
+ xhr.encrypt = encrypt;
170
187
  xhr.json = xhr.data = xhr.send = function (data, value) {
171
188
  if (!jsondata && !(isEmpty(data) && isEmpty(value))) jsondata = data instanceof Array ? [] : {};
172
189
  if (FormData && data instanceof FormData) {
@@ -202,8 +219,9 @@ function cross_(jsonp, digest = noop, method, url, headers) {
202
219
  datas = serialize(jsondata, "&", "=");
203
220
  }
204
221
  };
205
-
206
- var fire = function () {
222
+ var fire = async function () {
223
+ var code = await xhr.encrypt;
224
+ xhr.encrypt = code;
207
225
  var isform = /^f/i.test(method);
208
226
  if (isform) {
209
227
  if (method === 'form') method = 'post';
@@ -236,12 +254,12 @@ function cross_(jsonp, digest = noop, method, url, headers) {
236
254
  extend(realHeaders, _headers);
237
255
  xhr.open(method, url);
238
256
  } else {
239
- xhr.open(method, getCrossUrl(url, _headers));
257
+ xhr.open(method, getCrossUrl(url, _headers, isencrypt));
240
258
  }
241
259
  if (is_gb2312) xhr.overrideMimeType("text/plain; charset=gb2312");
242
260
 
243
261
  Object.keys(realHeaders).forEach(key => setRequestHeader.call(xhr, key, realHeaders[key]));
244
- if (!isEmpty(datas)) send.call(xhr, datas);
262
+ if (!isEmpty(datas)) send.call(xhr, nocross || !isencrypt ? datas : encode62.safeencode(datas, code));
245
263
  else send.call(xhr);
246
264
  digest();
247
265
  };
@@ -323,9 +341,17 @@ function reform(r, info, fire, cancel, e) {
323
341
  function addReform(r) {
324
342
  if (isFunction(r)) reforms.push(r);
325
343
  }
344
+ function getCode() {
345
+ return new Promise((ok, oh) => {
346
+ this('get', base + "!").then((xhr) => { return ok(encode62.timedecode(xhr.response || xhr.responseText)) }, () => {
347
+ return oh('未连接到可加密的服务器!');
348
+ });
349
+ });
350
+ }
326
351
  var bind = cross_.bind;
327
352
  cross_.bind = function () {
328
353
  var cross_ = bind.apply(this, arguments);
354
+ arguments[0].getCode = getCode.bind(cross_);
329
355
  extend(cross_, {
330
356
  requests,
331
357
  abortAll() {
@@ -0,0 +1,40 @@
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 instanceof Array || /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
+ throw errors;
38
+ }
39
+ return params;
40
+ }
@@ -6,5 +6,13 @@ function valid(field, data) {
6
6
  }
7
7
  return;
8
8
  }
9
+ if (field.valid instanceof Function) {
10
+ var e = field.valid(data[field.key]);
11
+ if (e) return e;
12
+ }
13
+ if (field.options instanceof Function) {
14
+ var e = field.options(data[field.key]);
15
+ if (e) return e;
16
+ }
9
17
  return error;
10
18
  }
@@ -28,13 +28,20 @@ Object.assign(encode62, {
28
28
  src,
29
29
  map,
30
30
  time_delta: parseInt("zzzzz", 36),
31
+ safeencode(string, sign, offset) {
32
+ string = encodeURIComponent(string).replace(/\./g, '..').replace(/[\!'\(\)~]/g, a => escape(a)).replace(/%/g, '.');
33
+ return this.encode62(string, sign, offset);
34
+ },
35
+ safedecode(string, sign, offset) {
36
+ string = this.decode62(string, sign, offset).replace(/\.\.?/g, a => a === '.' ? "%" : ".");
37
+ return decodeURIComponent(string);
38
+ },
31
39
  timedecode(string) {
32
40
  var { time_delta } = this;
33
41
  var time_rest = string.slice(string.length - time_delta.toString(36).length, string.length);
34
42
  var time_start = parseInt((new Date() - parseInt(time_rest, 36)) / time_delta) * time_delta;
35
43
  var time_stamp = time_start + parseInt(time_rest, 36);
36
- string = this.decode62(string.slice(0, string.length - time_delta.toString(36).length), time_stamp.toString(36)).replace(/\.\.?/g, a => a === '.' ? "%" : ".");
37
- return decodeURIComponent(string);
44
+ return this.safedecode(string.slice(0, string.length - time_delta.toString(36).length), time_stamp.toString(36));
38
45
  },
39
46
  timeencode(string) {
40
47
  var { time_delta } = this;
@@ -43,8 +50,7 @@ Object.assign(encode62, {
43
50
  var time_rest = time_stamp % time_delta;
44
51
  var time_rest_str = time_rest.toString(36);
45
52
  var time_delta_str = time_delta.toString(36);
46
- string = encodeURIComponent(string).replace(/\./g, '..').replace(/[\!'\(\)~]/g, a => escape(a)).replace(/%/g, '.');
47
- return this.encode62(string, time_stamp.toString(36)) + repeat("0", time_delta_str.length - time_rest_str.length) + time_rest_str;
53
+ return this.safeencode(string, time_stamp.toString(36)) + repeat("0", time_delta_str.length - time_rest_str.length) + time_rest_str;
48
54
  },
49
55
  timeupdate(string) {
50
56
  var { time_delta } = this;
@@ -57,7 +63,7 @@ Object.assign(encode62, {
57
63
  return this.timeencode(this.timedecode(string));
58
64
  }
59
65
  },
60
- encode62(data, sign) {
66
+ encode62(data, sign, offset = 0) {
61
67
  if (!sign) return data;
62
68
  var result = String(data);
63
69
  sign = String(sign);
@@ -65,7 +71,7 @@ Object.assign(encode62, {
65
71
  var result = result.replace(/\w/g, function (w, cx) {
66
72
  var code = map[w];
67
73
  if (typeof code !== "number") return w;
68
- var s = code ^ (sign.charCodeAt(cx % sign.length) % src.length);
74
+ var s = code ^ (sign.charCodeAt((offset + cx) % sign.length) % src.length);
69
75
  if (s >= src.length) return w;
70
76
  return src[s];
71
77
  });
@@ -146,5 +146,4 @@ drag.on = function (target, actionTarget = target.dragTarget) {
146
146
  on("drop")(actionTarget || target, setZIndex);
147
147
  onmousedown(target, _mousedrag);
148
148
  ontouchstart(target, _touchdrag);
149
- move.bindPosition(actionTarget || target);
150
149
  };
@@ -18,13 +18,20 @@ var encode62 = {
18
18
  }
19
19
  return buff.join('');
20
20
  },
21
+ safeencode(string, sign, offset) {
22
+ string = encodeURIComponent(string).replace(/\./g, '..').replace(/[\!'\(\)~]/g, a => escape(a)).replace(/%/g, '.');
23
+ return this.encode(string, sign, offset);
24
+ },
25
+ safedecode(string, sign, offset) {
26
+ string = this.encode(string, sign, offset).replace(/\.\.?/g, a => a === '.' ? "%" : ".");
27
+ return decodeURIComponent(string);
28
+ },
21
29
  timedecode(string) {
22
30
  var { time_delta } = this;
23
31
  var time_rest = string.slice(string.length - time_delta.toString(36).length, string.length);
24
32
  var time_start = parseInt((new Date() - parseInt(time_rest, 36)) / time_delta) * time_delta;
25
33
  var time_stamp = time_start + parseInt(time_rest, 36);
26
- string = this.encode(string.slice(0, string.length - time_delta.toString(36).length), time_stamp.toString(36)).replace(/\.\.?/g, a => a === '.' ? "%" : ".");
27
- return decodeURIComponent(string);
34
+ return this.safedecode(string.slice(0, string.length - time_delta.toString(36).length), time_stamp.toString(36));
28
35
  },
29
36
  timeencode(string) {
30
37
  var { time_delta } = this;
@@ -35,8 +42,7 @@ var encode62 = {
35
42
  var time_rest = time_stamp % time_delta;
36
43
  var time_rest_str = time_rest.toString(36);
37
44
  var time_delta_str = time_delta.toString(36);
38
- string = encodeURIComponent(string).replace(/\./g, '..').replace(/[\!'\(\)~]/g, a => escape(a)).replace(/%/g, '.');
39
- return this.encode(string, time_stamp.toString(36)) + repeat("0", time_delta_str.length - time_rest_str.length) + time_rest_str;
45
+ return this.safeencode(string, time_stamp.toString(36)) + repeat("0", time_delta_str.length - time_rest_str.length) + time_rest_str;
40
46
  },
41
47
  timeupdate(string) {
42
48
  var { time_delta } = this;
@@ -50,7 +56,7 @@ var encode62 = {
50
56
  return this.timeencode(this.timedecode(string));
51
57
  }
52
58
  },
53
- encode(data, sign) {
59
+ encode(data, sign, offset = 0) {
54
60
  if (!sign) return data;
55
61
  var result = String(data);
56
62
  sign = String(sign);
@@ -58,7 +64,7 @@ var encode62 = {
58
64
  var result = result.replace(/\w/g, function (w, cx) {
59
65
  var code = map[w];
60
66
  if (!isNumber(code)) return w;
61
- var s = code ^ (sign.charCodeAt(cx % sign.length) % src.length);
67
+ var s = code ^ (sign.charCodeAt((offset + cx) % sign.length) % src.length);
62
68
  if (s >= src.length) return w;
63
69
  return src[s];
64
70
  });
@@ -30,6 +30,8 @@ function main(elem) {
30
30
  case "empty":
31
31
  scope.error = `${f.name}是必填字段!`;
32
32
  break;
33
+ default:
34
+ scope.error = (f.name) + error;
33
35
  }
34
36
  }
35
37
  else {
@@ -152,30 +152,12 @@ var fixPosition = move.fixPosition = function (target) {
152
152
  };
153
153
  move.coordIn = coordIn;
154
154
  move.trimCoord = trimCoord;
155
- var resizingTargets = [];
156
- on('resize')(window, function () {
157
- resizingTargets.forEach(fixPosition);
158
- });
159
- var off;
160
- var resizeTarget = function () {
161
- var target = this;
162
- var index = resizingTargets.indexOf(target);
163
- if (index < 0) index = resizingTargets.push(target);
164
- return index;
155
+ var fixTarget = function () {
156
+ fixPosition(this);
165
157
  };
166
- var removeResize = function () {
167
- removeFromList(resizingTargets, this);
168
- };
169
-
170
158
  move.bindPosition = function (target, position) {
171
- if (position) {
159
+ oncemount(target, function () {
172
160
  setPosition(target, position);
173
- }
174
- var index = resizingTargets.indexOf(target);
175
- if (index >= 0) return;
176
- on("append")(target, resizeTarget);
177
- on("remove")(target, removeResize);
178
- if (isMounted(target)) {
179
- resizeTarget.call(target);
180
- }
161
+ });
162
+ on("resize")(target, fixTarget);
181
163
  }
@@ -3,5 +3,5 @@ function oncemount(target, handle) {
3
3
  handle.call(target);
4
4
  return;
5
5
  }
6
- once("append")(target, handle);
6
+ once("mounted")(target, handle);
7
7
  }
@@ -213,27 +213,40 @@ var createRepeat = function (search, id = 0) {
213
213
  once("append")(this, initialComment.bind(this, renders, "repeat", expression));
214
214
  }
215
215
  };
216
+ var comment = function (elements) {
217
+ for (var cx = elements.length - 2; cx > 1; cx -= 2) {
218
+ var e = elements[cx];
219
+ if (e.previousSibling === this) var c = this;
220
+ else {
221
+ var c = document.createComment('else' + (cx < elements.length - 2 ? "if .." : ''));
222
+ e.parentNode.insertBefore(c, e);
223
+ }
224
+ elements.splice(cx, 0, c);
225
+ remove(e);
226
+ }
227
+ };
228
+ var initIf = function (ifs) {
229
+ for (var s of ifs) {
230
+ comment(s);
231
+ if (s.parent) {
232
+ initialComment.call(s[0], s.renders, "if", s.comment);
233
+ } else {
234
+ once("append")(s[0], initialComment.bind(s[0], s.renders, "if", s.comment));
235
+ }
236
+ }
237
+ };
216
238
  var createIf = function (search, id = 0) {
217
239
  // 懒渲染
218
240
  var getter = createGetter(search).bind(this);
219
241
  var element = this;
220
- var p = element;
221
- if (p.parentNode) {
222
- p = p.parentNode;
223
- for (var cx = 0, dx = if_top.length; cx < dx; cx++) {
224
- if (if_top[cx].parent === p) {
225
- break;
226
- }
227
- }
228
- }
229
- cx++;
230
- if (cx > 0) if_top.splice(cx, if_top.length - cx);
231
242
  var elements = [element, getter];
232
243
  if_top.push(elements);
233
244
  var savedValue;
234
- var renders = [function () {
245
+ elements.parent = this.parentNode;
246
+ elements.comment = search[1];
247
+ elements.renders = [function () {
235
248
  var shouldMount = -1;
236
- for (var cx = 0, dx = elements.length; cx < dx; cx += 2) {
249
+ for (var cx = 0, dx = elements.length; cx < dx; cx += 3) {
237
250
  var getter = elements[cx + 1];
238
251
  if (!getter || getter()) {
239
252
  shouldMount = cx;
@@ -242,10 +255,10 @@ var createIf = function (search, id = 0) {
242
255
  }
243
256
  if (savedValue === shouldMount) return;
244
257
  savedValue = shouldMount;
245
- for (var cx = 0, dx = elements.length; cx < dx; cx += 2) {
258
+ for (var cx = 0, dx = elements.length; cx < dx; cx += 3) {
246
259
  var element = elements[cx];
247
260
  if (cx === shouldMount) {
248
- appendChild.before(this, element);
261
+ appendChild.after(cx > 0 ? elements[cx - 1] : this, element);
249
262
  if (element.renderid < 0) {
250
263
  element.renderid = id;
251
264
  elements[cx] = render(element, this.$scope, this.$parentScopes);
@@ -257,12 +270,6 @@ var createIf = function (search, id = 0) {
257
270
  }
258
271
 
259
272
  }];
260
- if (this.parentNode) {
261
- elements.parent = this.parentNode;
262
- initialComment.call(this, renders, "if", search[1]);
263
- } else {
264
- once("append")(this, initialComment.bind(this, renders, "if", search[1]));
265
- }
266
273
  };
267
274
  var parseIfWithRepeat = function (ifExpression, repeatExpression) {
268
275
  var repeater = parseRepeat(repeatExpression);
@@ -356,15 +363,18 @@ var structures = {
356
363
  createIf.call(this, search);
357
364
  },
358
365
  "else"(search) {
359
- var top = if_top[if_top.length - 1];
360
- if (!top || top.parent !== this.parentNode) {
366
+ for (var cx = if_top.length - 1; cx >= 0; cx--) {
367
+ if (if_top[cx].parent === this.parentNode) break;
368
+ }
369
+ if (cx < 0) {
361
370
  throw new Error("else/elseif前缺少同级if!");
362
371
  }
372
+ initIf(if_top.splice(cx + 1, if_top.length - cx - 1));
373
+ var top = if_top[cx];
363
374
  if (search && search[1]) {
364
375
  var getter = createGetter(search).bind(this);
365
376
  }
366
377
  top.push(this, getter);
367
- remove(this);
368
378
  },
369
379
  repeat(search) {
370
380
  createRepeat.call(this, search);
@@ -853,7 +863,7 @@ function render(element, scope, parentScopes, lazy = true) {
853
863
  renderlock = false;
854
864
  eagermount = false;
855
865
  }
856
- if (if_top_length < if_top.length) if_top.splice(if_top_length, if_top.length - if_top_length);
866
+ if (if_top_length < if_top.length) initIf(if_top.splice(if_top_length, if_top.length - if_top_length));
857
867
  return e;
858
868
  }
859
869
  var digest = lazy(refresh, -{});
@@ -121,11 +121,8 @@ var handle = {
121
121
  }
122
122
  });
123
123
  var rect = dragging.rect;
124
- move.call(rect, isFinite(style.left) ? style.left : rect.offsetLeft, isFinite(style.top) ? style.top : rect.offsetTop);
125
- delete style.left;
126
- delete style.top;
127
- Object.keys(style).forEach(k => style[k] = fromOffset(style[k]));
128
124
  css(dragging.rect, style);
125
+ move.call(rect, isFinite(style.left) ? style.left : rect.offsetLeft, isFinite(style.top) ? style.top : rect.offsetTop);
129
126
  dispatch(dragging.rect, 'resize');
130
127
  resizingList.forEach(a => {
131
128
  if (getTargetIn(dragging.rect, a)) {
@@ -1,41 +1,8 @@
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
- }
1
+ function submit() {
2
+ try {
3
+ return submit_.apply(this, arguments);
4
+ } catch (e) {
5
+ alert(String(e), 'warn');
6
+ throw e;
25
7
  }
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
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "3.19.0",
3
+ "version": "3.20.0",
4
4
  "description": "一个开发工具,开放源代码,自带组件库和编译环境,可以用来开发web组件,web应用或nodejs模块,或做为已有代码的加密工具,也可以做为静态页面服务器或跨域中转服务器使用",
5
5
  "main": "public/efront.js",
6
6
  "directories": {