efront 3.35.4 → 3.35.6

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.
@@ -0,0 +1,7 @@
1
+ 图状数据序列化工具,与JSON语法一致
2
+ ```javascript
3
+ JSAM.stringify(obj);
4
+ JSAM.parse(str);
5
+ ```
6
+ 该工具已单独发布至[](https://www.npmjs.com/package/jsam),
7
+ 更多用法参考可参考该链接。
@@ -309,6 +309,7 @@ function cross_(jsonp, digest = noop, method, url, headers) {
309
309
  };
310
310
  var fire = async function (code) {
311
311
  if (!~requests.indexOf(xhr)) return;
312
+ prepareHeaders();
312
313
  xhr.method = method;
313
314
  xhr.url = url;
314
315
  xhr.encrypt = code;
@@ -365,25 +366,28 @@ function cross_(jsonp, digest = noop, method, url, headers) {
365
366
  }
366
367
  var setRequestHeader = xhr.setRequestHeader;
367
368
  var realHeaders = Object.create(null);
368
- var cookie_ = this.hostCookie(xhr);
369
- var _cookies = cookie_.getCookies(originDomain);
370
- var _headers = {};
371
- if (_cookies) {
372
- _headers.Cookie = _cookies;
373
- }
374
- var cookobj = null;
375
- for (var k in headers) {
376
- if (/^\$/.test(headers[k])) {
377
- var k2 = headers[k].slice(1);
378
- if (!cookobj) cookobj = _cookies ? parseKV(_cookies, ';') : {};
379
- if (k2 in cookobj) {
380
- _headers[k] = cookobj[k2];
381
- }
369
+ var cookie_;
370
+ var prepareHeaders = () => {
371
+ cookie_ = this.hostCookie(xhr);
372
+ var _cookies = cookie_.getCookies(originDomain);
373
+ if (_cookies) {
374
+ _headers.Cookie = _cookies;
382
375
  }
383
- else {
384
- _headers[k] = headers[k];
376
+ var cookobj = null;
377
+ for (var k in headers) {
378
+ if (/^\$/.test(headers[k])) {
379
+ var k2 = headers[k].slice(1);
380
+ if (!cookobj) cookobj = _cookies ? parseKV(_cookies, ';') : {};
381
+ if (k2 in cookobj) {
382
+ _headers[k] = cookobj[k2];
383
+ }
384
+ }
385
+ else {
386
+ _headers[k] = headers[k];
387
+ }
385
388
  }
386
- }
389
+ };
390
+ var _headers = {};
387
391
  if (/^[mc]/i.test(method)) {
388
392
  _headers["User-Agent"] = /^m/i.test(method)
389
393
  ? "efront/3.25 (iPhone) Safari/602.1"
@@ -0,0 +1 @@
1
+ `YAML`格式解析工具,目前尚不完善,解析个别数据可能出错。
@@ -0,0 +1,10 @@
1
+ 依次传入数组中的数据,执行可能生成Promise的函数,类似如下代码:
2
+ ```javascript
3
+ for await(func());
4
+ 或:
5
+ for (){await func();}
6
+ ```
7
+ 用法如下:
8
+ ```javascript
9
+ queue.call(数组,func,最大并发数);
10
+ ```
@@ -0,0 +1,4 @@
1
+ 键值对序列化工具
2
+ ```javascript
3
+ serialize({ k1: v1, k2: v2 }, 分隔符, 等号);
4
+ ```
@@ -0,0 +1,4 @@
1
+ 文件名排序工具
2
+ ```javascript
3
+ sortname(文件名数组)
4
+ ```
@@ -0,0 +1,7 @@
1
+ 等待一个函数的返回值为真。用法如下:
2
+ ```javascript
3
+ wait(function(){
4
+ return ...;
5
+ }, 超时时长, 每次检查的时间间隔)
6
+ ```
7
+ 其中两个时间参数可不传入,超时时长默认为80毫秒,时间间隔按超时时长动态生成,约为其1/16。
@@ -90,6 +90,7 @@ Html.prototype.createScoped = function (code) {
90
90
  dom.childNodes = childNodes;
91
91
  dom.children = children;
92
92
  var scriptNodes = [], styleNodes = [], tempNodes = [];
93
+ var inScript = false;
93
94
  for (var cx = 0, dx = code.length, c = code[0]; cx < dx; c = code[++cx])switch (c.type) {
94
95
  case LABEL:
95
96
  if (!/^(script|style|template)$/i.test(c.text)) {
@@ -100,6 +101,7 @@ Html.prototype.createScoped = function (code) {
100
101
  if (!c.isclose) {
101
102
  var node = new Node;
102
103
  node.tagName = c.text.toUpperCase();
104
+ if (node.tagName === 'SCRIPT' || node.tagName === 'STYLE') inScript = true;
103
105
  nodePath.push(node);
104
106
  node.childNodes = [];
105
107
  node.children = [];
@@ -132,8 +134,8 @@ Html.prototype.createScoped = function (code) {
132
134
  }
133
135
  if (childNodes1.length) node.innerStart = childNodes1[0].outerStart;
134
136
  else node.innerStart = innerEnd;
135
- if (node.tagName === "SCRIPT") scriptNodes.push(node), tempNodes.push(node), node.isScript = true;
136
- else if (node.tagName === "STYLE") styleNodes.push(node), tempNodes.push(node), node.isStyle = true;
137
+ if (node.tagName === "SCRIPT") scriptNodes.push(node), tempNodes.push(node), node.isScript = true, inScript = false;
138
+ else if (node.tagName === "STYLE") styleNodes.push(node), tempNodes.push(node), node.isStyle = true, inScript = false;
137
139
  nodePath.pop();
138
140
  node = nodePath[nodePath.length - 1];
139
141
  childNodes = node.childNodes;
@@ -169,6 +171,7 @@ Html.prototype.createScoped = function (code) {
169
171
  }
170
172
  break;
171
173
  case EXPRESS:
174
+ if (inScript) continue;
172
175
  var t = c.text;
173
176
  t = parseExpress(t);
174
177
  var envs = createScoped(t).envs;
@@ -41,7 +41,7 @@ Richcss.prototype.setType = function (o) {
41
41
  };
42
42
  Richcss.prototype.createScoped = function (code) {
43
43
  var run = function (o) {
44
- var props = Object.create(null);
44
+ var props = [];
45
45
  var values = null;
46
46
  loop: while (o) {
47
47
  switch (o.type) {
@@ -51,7 +51,10 @@ Richcss.prototype.createScoped = function (code) {
51
51
  p.push(o.text);
52
52
  o = o.next;
53
53
  }
54
- props[p.join(" ")] = values = [];
54
+ var pj = p.join(' ');
55
+ props.push({ p: pj, v: values = [] });
56
+ if (!props[pj]) props[pj] = [];
57
+ props[pj].push(values);
55
58
  if (!o) break loop;
56
59
  if (o.type === STAMP) break;
57
60
  continue;
@@ -65,15 +68,14 @@ Richcss.prototype.createScoped = function (code) {
65
68
  case SCOPED:
66
69
  var s = run(o.first);
67
70
  var vars = null, used = null;
68
- for (var k in s) {
69
- var v = s[k];
71
+ for (var { p: k, v } of s) {
70
72
  if (/^\-\-/.test(k)) {
71
73
  if (!vars) vars = {};
72
74
  vars[k] = v.join(" ");
73
75
  }
74
76
  else {
75
77
  if (!used) used = [];
76
- used[k] = v;
78
+ used.push({ p: k, v });
77
79
  }
78
80
  }
79
81
  values.used = used;
@@ -113,11 +115,13 @@ var fixBase = function (b, a) {
113
115
  function evalscoped(scoped, scopeNames, base = '') {
114
116
  var root = scoped[":root"], scope = scoped[":scope"];
115
117
  var vars = Object.create(null);
116
- if (root) extend(vars, root.vars);
117
- if (scope) extend(vars, scope.vars);
118
+ if (root) root.forEach(r => extend(vars, r.vars));
119
+ if (scope) scope.forEach(s => extend(vars, s.vars));
118
120
  scopeNames.forEach(s => {
119
121
  var ss = scoped[s];
120
- if (ss) extend(vars, ss.vars), ss.rooted = true;
122
+ if (ss) ss.forEach(s => {
123
+ extend(vars, s.vars), s.rooted = true;
124
+ })
121
125
  });
122
126
  var vlist = [vars];
123
127
  var mlist = [];
@@ -154,8 +158,7 @@ function evalscoped(scoped, scopeNames, base = '') {
154
158
  return q + getFromScopeList(b || a.trim(), vlist, m.slice(q.length));
155
159
  });
156
160
  };
157
- for (var k in props) {
158
- var p = props[k];
161
+ for (var { p: k, v: p } of props) {
159
162
  if (p.used) {
160
163
  var match = /^(@[^\s,]+)\s*\(\s*(@[^\s,]+\s*(?:,\s*@[^\s,]+\s*)*)?\)/.exec(k);
161
164
  if (!match) continue;
@@ -164,7 +167,8 @@ function evalscoped(scoped, scopeNames, base = '') {
164
167
  args = args.split(",").map(a => a.trim());
165
168
  p.args = args;
166
169
  p.reg = new RegExp(args.join("|"), 'g');
167
- methods[name] = function () {
170
+ if (!methods[name]) methods[name] = [];
171
+ methods[name].push(function () {
168
172
  var body = evalthis(this);
169
173
  var valueMap = {};
170
174
  this.args.forEach((a, i) => {
@@ -178,12 +182,12 @@ function evalscoped(scoped, scopeNames, base = '') {
178
182
  var body = body.map(replace);
179
183
  body.rest = rest;
180
184
  return body;
181
- }.bind(p);
182
- delete props[k];
185
+ }.bind(p));
186
+ p.isMethod = true;
183
187
  }
184
188
  }
185
- for (var k in props) {
186
- var p = props[k];
189
+ for (var { p: k, v: p } of props) {
190
+ if (p.isMethod) continue;
187
191
  if (p.used) {
188
192
  if (base && !p.rooted) p.base = fixBase(base, k);
189
193
  else p.base = k;
@@ -201,10 +205,12 @@ function evalscoped(scoped, scopeNames, base = '') {
201
205
  var [, name, params] = match;
202
206
  params = params.split(",").map(a => a.trim());
203
207
  var method = getFromScopeList(name, mlist);
204
- if (!isFunction(method)) throw `函数未定义:${name}`;
205
- var res = method.apply(null, params);
206
- if (res.rest.length) rest = rest.concat(res.rest);
207
- if (res.length) result = result.concat(res);
208
+ if (!isArray(method)) throw `函数未定义:${name}`;
209
+ method.forEach(m => {
210
+ var res = m.apply(null, params);
211
+ if (res.rest.length) rest = rest.concat(res.rest);
212
+ if (res.length) result = result.concat(res);
213
+ });
208
214
  }
209
215
  }
210
216
  mlist.pop();
@@ -70,8 +70,8 @@ function richtext(line) {
70
70
  line = line.trim();
71
71
  line = line.replace(/\[([\s\S]*?)\](?:\(([\s\S]*?)\))?|<(\w+)>[\s\S]*?<\/\3>/g, function (_, content, href) {
72
72
  if (/^\</.test(_)) return _;
73
- if (href) href = ` href=${strings.recode(href)}`;
74
- return `<a${href}>${content}</a>`;
73
+ if (href) var href1 = ` href=${strings.recode(href)}`;
74
+ return `<a${href1}>${content || href}</a>`;
75
75
  });
76
76
  var a;
77
77
  if (/^#/.test(line)) a = h(line);
@@ -34,7 +34,7 @@ var colorReg = /<(\/?)([a-z][\w]*)\>/ig;
34
34
  var renderColor = function (obj) {
35
35
  var colorpath = [];
36
36
  return String(obj).replace(colorReg, function (_, e, c) {
37
- if (!getColor(c)) return _;
37
+ if (!c || c.length < 3 || !getColor(c)) return _;
38
38
  if (e) {
39
39
  colorpath.pop();
40
40
  c = colorpath[colorpath.length - 1];
@@ -0,0 +1,12 @@
1
+ 替换已知函数中的方向属性(left,top,width,height,x,y等),生成转置函数。
2
+ 如:
3
+ ```javascript
4
+ var 水平方向操作 = function(elem,event){
5
+ var top = event.clientY - elem.offsetTop;
6
+ };
7
+ var 垂直方向操作 = function(elem,event){
8
+ var left = event.clientX - elem.offsetLeft;
9
+ };
10
+ 等同于:
11
+ var 垂直方向操作 = arriswise(水平方向操作,arguments);
12
+ ```
@@ -0,0 +1,12 @@
1
+ 子项拖拽工具,两种用法可配合使用
2
+ ```javascript
3
+ // 启用元素内的拖拽排序
4
+ autodragchildren(元素, 子项过滤器, function(fromIndex,toIndex){
5
+ // 此回调函数可用于处理数据,也可以什么都不做
6
+ // 如果返回false 元素位置将不被调换
7
+ });
8
+ // 对已捕获的事件启用拖拽
9
+ autodragchildren.hook(event, target/*用于向用户展示拖拽效果的元素*/,function (接收拖拽的元素/*此元素应具有 allowdrop 属性*/) {
10
+ });
11
+ ```
12
+ 更具体的用法可参考代码 [](https://github.com/yunxu1019/qfy/blob/master/page/home/edit.js)
@@ -59,7 +59,8 @@ cross.setHost = function (host) {
59
59
  host = (/^https/.test(location_href) ? "https://" : "http://") + host;
60
60
  cross_.setHost(host);
61
61
  };
62
- cross.hostCookie = function () {
62
+ cross.hostCookie = function (xhr) {
63
+ if (xhr.cookie) return xhr.cookie;
63
64
  return cookie;
64
65
  };
65
66
  cross.getCookies = function (dp) {
@@ -0,0 +1,25 @@
1
+ 网络请求工具
2
+ ```javascript
3
+ var xhr = await cross(请求方法,请求路径,头信息).send(数据);
4
+ console.log(xhr.response) // 已对不存在response属性的浏览器做兼容,可放心使用
5
+ ```
6
+ 默认会通过当前服务器转发请求,请求结果会附加跨域头信息,可以通过`cross.addDirect`指定免转发的服务器
7
+ 如:
8
+ ```javascript
9
+ cross.addDirect('efront.cc');
10
+ 或:
11
+ cross.addDirect(/efront\.cc$/);
12
+ ```
13
+ 对于无服务器项目或不使用efront做为服务器的项目,也可以通过`cross.setHost`指定用以转发的服务器,如:
14
+ ```javascript
15
+ cross.setHost('efront.cc');
16
+ ```
17
+ 可以用efront的编译开关区分生成环境和测试环境,如:
18
+ ```javascript
19
+ cross.setHost('efront.cc');
20
+ // <!--
21
+ // 这里的代码会在live命令中生效
22
+ // 会在build命令中移除
23
+ cross.setHost('localhost');
24
+ // -->
25
+ ```
@@ -0,0 +1,13 @@
1
+ 非线性减速插值工具,可用于用户的滚动或拖动操作平滑停止
2
+ ```javascript
3
+ var f = inertia(function(a){
4
+ // 一个参数或多个参数,都应为有限的数值,未对其他情况进行测试或排错
5
+ console.log(a);
6
+ });
7
+ f(2);
8
+ await new Promise(ok=>setTimeout(ok,20));
9
+ f(2);
10
+ f.smooth(function(){
11
+ // 结束时的回调,可不传入
12
+ }, 最小可用速度/*高维空间中参数向量的模,可不传入*/);
13
+ ```
@@ -0,0 +1,5 @@
1
+ 网格排列工具,每行元素最好有一样的高度,超出宽度后自动换行,其行为类似windows操作系统的文件管理窗口
2
+ ```html
3
+ <!-- 用法与list组件一致,增加一个 item-width 属性,可不设置 -->
4
+ <lattice efront-src="item in items" item-width=280 ></lattice>
5
+ ```
@@ -0,0 +1,10 @@
1
+ 列表工具,比ng-repeat或v-for的优势在于,它内置了大数据量的高效展示算法。
2
+ ```html
3
+ <!-- 语法与 ng-repeat 或 v-for 类似,前缀随意 -->
4
+ <list efront-src="item in items" >
5
+ <div>
6
+ <span -bind="item.name"></span>
7
+ <span -bind="item.silasiladi"></span>
8
+ </div>
9
+ </list>
10
+ ```
@@ -0,0 +1 @@
1
+ 一个地图展示的小工具,目前只有展示瓦片地图(OSM、百度、高德、谷歌等)的功能,无任何其他附加功能。如果您在开发地图类应用,建议使用`openlayers`等已基本成熟的地图框架,不要使用这个可能在未来大修大补的模块。
@@ -33,9 +33,10 @@ function prompt() {
33
33
  };
34
34
  var buttons = [button("确认"), button("取消", 'white')];
35
35
  if (isFunction(check)) {
36
- var setDisable = function () {
36
+ var setDisable = function (event) {
37
+ if (oked || ohed) return;
37
38
  var valid = validate(ipt.value, check, tip);
38
- attr(body, "error", !valid);
39
+ if (event) attr(body, "error", !valid);
39
40
  attr(buttons[0], 'disabled', !valid);
40
41
  };
41
42
  on('keyup')(ipt, setDisable);
@@ -49,7 +50,7 @@ function prompt() {
49
50
  var c = confirm(msg, body, buttons, function (_) {
50
51
  if (oked || ohed) return;
51
52
  if (_ === buttons[0]) {
52
- if (check && validate(ipt.value, check, tip)) return false;
53
+ if (check && !validate(ipt.value, check, tip)) return false;
53
54
  oked = true;
54
55
  } else {
55
56
  ohed = true;
@@ -65,11 +66,8 @@ function prompt() {
65
66
  on("mousedown")(c, e => e.target !== ipt && e.preventDefault() | ipt.focus());
66
67
  on("keydown.enter")(c, function (event) {
67
68
  if (event.defaultPrevented) return;
68
- if (check && check(ipt.value) === false) return;
69
69
  event.preventDefault();
70
- oked = true;
71
- remove(c);
72
- fire();
70
+ buttons[0].click();
73
71
  });
74
72
  c.then = function (ok, oh) {
75
73
  oks.push(ok);
@@ -648,7 +648,7 @@ var createEmiter = function (on) {
648
648
  digest();
649
649
  var parsedSrc = this.$src;
650
650
  if (parsedSrc instanceof Repeater) {
651
- if (e.active || e.currentTarget) var target = e.active || e.currentTarget;
651
+ if (e.active || e.currentTarget) var target = e.active || (e.currentTarget === this ? e.target || e.srcElem || e.currentTarget : e.currentTarget);
652
652
  else var target = e.target;
653
653
  if (target === this) {
654
654
  scope = parsedSrc.createScope();
@@ -906,7 +906,7 @@ function createStructure(element) {
906
906
  continue;
907
907
  }
908
908
  if (/^#/.test(name)) {
909
- ids.push(name.slice(1));
909
+ ids.push(name.slice(1), name.slice(1).replace(/\-([a-z])/ig, (_, a) => a.toUpperCase()));
910
910
  element.removeAttribute(name);
911
911
  continue;
912
912
  };
@@ -170,9 +170,10 @@ function main() {
170
170
  switch (target) {
171
171
  case this.children[0]:
172
172
  var a = prompt("请输入", a => {
173
+ if (!a) return false;
174
+ console.log(itemMap, a);
173
175
  if (a in itemMap) {
174
- alert(`选项 ${a} 已存在!`);
175
- return false;
176
+ return `选项 ${a} 已存在!`;
176
177
  }
177
178
  });
178
179
  page.with = a;
@@ -192,6 +193,7 @@ function main() {
192
193
  var edit = selectListEdit(options.slice(0));
193
194
  page.with = edit;
194
195
  on("remove")(edit, function () {
196
+ itemMap = Object.create(null);
195
197
  page.with = null;
196
198
  children.splice(0, children.length);
197
199
  children.push.apply(children, edit.$scope.options.map(o => ({ key: o.key || o.value, name: o.name || o.innerHTML })))
@@ -0,0 +1,7 @@
1
+ ```javascript
2
+ zimoli(pathname, params) // 跳转
3
+ zimoli.switch(historyName, targetElement, homePath) // 切换历史及目标挂载元素
4
+ zimoli() // 切换历史后初始化
5
+ zimoli.clearHistory() // 清空历史
6
+ zimoli.register(pathname) // 注册通用路由
7
+ ```
package/docs/main.xht CHANGED
@@ -123,6 +123,7 @@
123
123
  var helps = await init("docs$helps");
124
124
  var m = {
125
125
  name: "命令参考",
126
+ closed: true,
126
127
  children: [
127
128
  { name: "防御系", a: "f" },
128
129
  { name: "强攻系", a: "q" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "3.35.4",
3
+ "version": "3.35.6",
4
4
  "description": "简化前端开发,优化web性能",
5
5
  "main": "public/efront.js",
6
6
  "directories": {