efront 3.18.0 → 3.18.1

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.
@@ -14,6 +14,9 @@ async function link(id, page) {
14
14
  if (removed) break;
15
15
  xhr = data.from("care", { id }, function (data) {
16
16
  page.$scope.msglist.push.apply(page.$scope.msglist, data);
17
+ var { msglist } = page.$scope;
18
+ var chat = page.querySelector("chat");
19
+ chat.go(msglist.length ? msglist.length - 1 : 0);
17
20
  });
18
21
  await xhr;
19
22
  }
@@ -1,11 +1,9 @@
1
- <btn @click="chat()">新建连接</btn>
2
- <div>
3
- 自动刷新<swap -model="autoreload"></swap>
4
- </div>
5
1
  <div class="clusters">
6
2
  <a -repeat="(c,i) in clusters" ng-class="{current:i===index.index}" @click="active(i,c)">
7
3
  <span -text="c"></span>
8
4
  </a>
5
+ 自动刷新<swap -model="autoreload"></swap>
6
+ <btn @click="chat()">新建连接</btn>
9
7
  </div>
10
8
  <lattice -src="c in clients">
11
9
  <padding>
@@ -4,7 +4,7 @@ function main() {
4
4
  page.innerHTML = template;
5
5
  renderWithDefaults(page, {
6
6
  load: lazy(async function () {
7
- this.clusters = data.asyncInstance("cluster", { opt: "list" });
7
+ this.clusters = data.lazyInstance("cluster", { opt: "list" });
8
8
  await this.clusters;
9
9
  this.active();
10
10
  }, -1000),
@@ -1,9 +1,14 @@
1
1
  .clusters a {
2
2
  display: inline-block;
3
- margin-right: 20px;
4
3
  padding: 0 6px;
5
4
  }
6
-
5
+ .clusters>*{
6
+ vertical-align: top;
7
+ margin-right: 12px;
8
+ }
9
+ .clusters{
10
+ padding-left: 6px;
11
+ }
7
12
  .time {
8
13
  color: #bbb;
9
14
  }
@@ -1,13 +1,19 @@
1
- <div head -html="title">
1
+ <div head>
2
+ <template -src="title">
3
+ </template>
4
+ <close @click="remove()"></close>
2
5
  </div>
3
- <grid body>
6
+ <grid body #body>
4
7
  <chat -src="m in msglist">
5
- <msg class="msg" -src="m"></msg>
8
+ <padding>
9
+ <msg class="msg"></msg>
10
+ <div style="clear: both;"></div>
11
+ </padding>
6
12
  </chat>
7
- <div textarea>
8
- <div contenteditable="true" -model="text"></div>
13
+ <div textarea @mousedown="this.firstChild.focus()">
14
+ <div @input="resize(body)" @keydown.alt.enter="send()" contenteditable="true" -model="text"></div>
9
15
  </div>
10
16
  </grid>
11
17
  <div foot>
12
- <btn @click="send()">发送</btn>
18
+ <btn @click="send();">发送</btn>
13
19
  </div>
@@ -1,16 +1,18 @@
1
1
 
2
- function msg(elem) {
3
- care(elem, function (data) {
4
- if (!data) return;
5
- var m = JSAM.parse(data);
6
- if (m) switch (m.type) {
7
- case "html":
8
- elem.innerHTML = m.content;
9
- break;
10
- default:
11
- elem.innerText = data;
12
- }
13
- })
2
+ function msg(elem, { m: data }, parentScopes) {
3
+ if (!data) return;
4
+ data = encode62.timedecode(data);
5
+ var m = JSAM.parse(data);
6
+ if (m.sender === parentScopes[parentScopes.length - 1].localid) {
7
+ elem.setAttribute("self", "");
8
+ }
9
+ if (m) switch (m.type) {
10
+ case "html":
11
+ elem.innerHTML = m.content;
12
+ break;
13
+ default:
14
+ elem.innerText = data;
15
+ }
14
16
  }
15
17
  function chat(title = '会话窗口') {
16
18
  var page = view();
@@ -25,13 +27,32 @@ function chat(title = '会话窗口') {
25
27
  text: '',
26
28
  localid: Math.random(),
27
29
  msg,
30
+ remove() {
31
+ remove(page);
32
+ },
33
+ resize(body) {
34
+ var textarea = body.querySelector("[textarea]");
35
+ var lastElementChild = textarea.lastElementChild;
36
+ var targetHeight = Math.min(textarea.scrollHeight, body.clientHeight * .6, lastElementChild.offsetTop + lastElementChild.offsetHeight);
37
+ if (Math.abs(targetHeight - textarea.clientHeight) < 2) return;
38
+
39
+ body.resizeCell(textarea, 'top', textarea.clientHeight - targetHeight - 2);
40
+ },
28
41
  send() {
29
42
  if (!this.text) return;
30
- cast(page, "send", JSAM.stringify({
43
+ var data = JSAM.stringify({
31
44
  type: 'html',
32
45
  sender: this.localid,
33
46
  content: this.text,
34
- }));
47
+ });
48
+
49
+ data = encode62.timeencode(data);
50
+ if (this.text.length > 2000) {
51
+ alert("信息太长,无法发送!");
52
+ return;
53
+ }
54
+ cast(page, "send", data);
55
+ this.body.lastElementChild.focus();
35
56
  this.text = '';
36
57
  }
37
58
  });
@@ -1,5 +1,5 @@
1
- @height: 320px;
2
- @width: 360px;
1
+ @height: 420px;
2
+ @width: 480px;
3
3
  @margin-top: -160px;
4
4
  @margin-left: -180px;
5
5
 
@@ -18,9 +18,56 @@
18
18
  max-height: 100%;
19
19
  }
20
20
 
21
+ padding {
22
+ display: block;
23
+ position: relative;
24
+
25
+ &:after {
26
+ display: "";
27
+ display: block;
28
+ clear: both;
29
+ }
30
+ }
21
31
 
22
32
  msg {
23
33
  display: block;
34
+ border-radius: 4px;
35
+ padding: 6px 12px;
36
+ line-height: 20px;
37
+ white-space: normal;
38
+ word-break: break-all;
39
+ background: #fff;
40
+ position: relative;
41
+ margin: 0 10px;
42
+ float: left;
43
+
44
+ &:before {
45
+ content: "";
46
+ display: block;
47
+ position: absolute;
48
+ border: 6px solid transparent;
49
+ top: 22px;
50
+ margin: -12px;
51
+ }
52
+
53
+ &:not([self]):before {
54
+ display: block;
55
+ left: 0;
56
+ border-right-color: #fff;
57
+ }
58
+
59
+ &[self] {
60
+ &:before {
61
+ right: 0;
62
+ border-left-color: #77ddaa;
63
+ }
64
+
65
+ margin-left: 20px;
66
+
67
+ float: right;
68
+ background-color: #77ddaa;
69
+ color: #333;
70
+ }
24
71
  }
25
72
 
26
73
 
@@ -67,14 +114,17 @@ chat {
67
114
  border: none;
68
115
  outline: none;
69
116
  border-top: 1px solid #000;
117
+ border-bottom: 30px solid transparent;
70
118
  ime-mode: active;
119
+ overflow: auto;
71
120
 
72
121
  >div {
73
- height: 100%;
122
+ height: auto;
123
+ min-height: 49px;
74
124
  width: 100%;
75
125
  vertical-align: top;
76
- padding: 6px 16px 30px;
77
- overflow: auto;
126
+ padding: 6px 16px;
127
+ box-sizing: border-box;
78
128
  outline: none;
79
129
  }
80
130
  }
@@ -104,10 +154,12 @@ chat {
104
154
  .editor-height(36px);
105
155
 
106
156
  [textarea] {
107
- border: none;
157
+ border-bottom: none;
108
158
  outline: none;
109
- >div{
110
- padding-right: 80px;
159
+
160
+ >div {
161
+ min-height: 30px;
162
+ padding-right: 110px;
111
163
  }
112
164
  }
113
165
  }
@@ -41,6 +41,7 @@ var filterKey = function (event) {
41
41
  if (c === s) break;
42
42
  }
43
43
  if (keyCode === 8) {
44
+ if (!s) return;
44
45
  event.preventDefault();
45
46
  if (s.nextSibling) {
46
47
  if (s.nextSibling.innerText === '_') {
@@ -7,7 +7,7 @@
7
7
  min-height: 100px;
8
8
  padding: 0 0 10px 16px;
9
9
  font-family: 宋体;
10
- width: 422px;
10
+ width: 438px;
11
11
 
12
12
  >a {
13
13
  display: inline-block;
@@ -32,7 +32,7 @@
32
32
  &:before {
33
33
  position: relative;
34
34
  white-space: nowrap;
35
- box-sizing: border-box;
35
+ box-sizing: content-box;
36
36
  color: #ccc;
37
37
  word-spacing: 2px;
38
38
  font-size: inherit;
@@ -11,6 +11,7 @@ var gosrc = function () {
11
11
  }
12
12
  };
13
13
  function container(element) {
14
+ element = document.createComment('container');
14
15
  care(element, change);
15
16
  element.renders = [gosrc];
16
17
  return element;
@@ -202,6 +202,21 @@ var resizeView = function (event) {
202
202
  }
203
203
  grid.reshape();
204
204
  };
205
+ var clearResizer = function (grid) {
206
+ var target = grid.editting.target;
207
+ if (target) target.style.zIndex = null;
208
+ var { clientX, clientY } = grid.editting;
209
+ if (clientX) {
210
+ clientX[1].forEach(e => removeClass(e, 'border-right'));
211
+ clientX[2].forEach(e => removeClass(e, 'border-left'));
212
+ }
213
+ if (clientY) {
214
+ clientY[1].forEach(e => removeClass(e, "border-bottom"));
215
+ clientY[2].forEach(e => removeClass(e, "border-top"));
216
+ }
217
+ grid.editting = null;
218
+ };
219
+
205
220
  var resizer = function (event) {
206
221
  var grid = this;
207
222
  if (!grid.direction) return;
@@ -227,24 +242,7 @@ var resizer = function (event) {
227
242
  //右边
228
243
  generateResizeParameters.call(grid, "x", "left", "right", "width", area.right, event, 1, resize);
229
244
  }
230
- grid.editting = resize;
231
- var cancelup = onmouseup(window, function () {
232
- var target = grid.editting.target;
233
- if (target) target.style.zIndex = null;
234
- var { clientX, clientY } = resize;
235
- resize = null;
236
- if (clientX) {
237
- clientX[1].forEach(e => removeClass(e, 'border-right'));
238
- clientX[2].forEach(e => removeClass(e, 'border-left'));
239
- }
240
- if (clientY) {
241
- clientY[1].forEach(e => removeClass(e, "border-bottom"));
242
- clientY[2].forEach(e => removeClass(e, "border-top"));
243
- }
244
- grid.editting = null;
245
-
246
- cancelup();
247
- });
245
+ return grid.editting = resize;
248
246
  };
249
247
  var gridListener = function () {
250
248
  var grid = this;
@@ -261,7 +259,14 @@ var gridListener = function () {
261
259
  /**
262
260
  * 指针按下
263
261
  */
264
- var offmousedown = onmousedown(grid, resizer);
262
+ var offmousedown = onmousedown(grid, function (event) {
263
+ if (!resizer.call(this, event)) return;
264
+ var that = this;
265
+ var cancelup = onmouseup(window, function () {
266
+ clearResizer(that);
267
+ cancelup();
268
+ });
269
+ });
265
270
 
266
271
  var offremove = onremove(grid, function () {
267
272
  offremove();
@@ -359,6 +364,51 @@ var bindToOrderedSpliters = function (split_points, target, value, side) {
359
364
  return split_points;
360
365
  };
361
366
  var grid_prototype = {
367
+ resizeCell(cell, side, delta) {
368
+ side = side.toLowerCase();
369
+ var { left, top, right, bottom } = getScreenPosition(cell);
370
+ var clientX, clientY, targetX, targetY;
371
+ var direction;
372
+ switch (side.toLowerCase()[0]) {
373
+ case "l":
374
+ case "w":
375
+ direction = 'w';
376
+ clientX = left;
377
+ targetX = left + delta;
378
+ targetY = clientY = top + bottom >> 1;
379
+ break;
380
+ case "t":
381
+ case "n":
382
+ direction = 'n';
383
+ clientY = top;
384
+ targetY = top + delta;
385
+ targetX = clientX = left + right >> 1;
386
+ break;
387
+ case "r":
388
+ case "e":
389
+ direction = 'e';
390
+ clientX = right;
391
+ targetX = right + delta;
392
+ targetY = clientY = left + right >> 1;
393
+
394
+ break;
395
+ case "b":
396
+ case "s":
397
+ direction = 's';
398
+ clientX = bottom;
399
+ targetY = bottom + delta;
400
+ targetX = clientX = left + right >> 1;
401
+ break;
402
+ default:
403
+ throw new Error("参数不支持", side);
404
+ }
405
+ this.direction = direction;
406
+ var e = resizer.call(this, { clientX, clientY, target: cell });
407
+ if (!e) return;
408
+ resizeView.call(this, { clientX: targetX, clientY: targetY, target: cell });
409
+ clearResizer(this);
410
+ this.direction = '';
411
+ },
362
412
  setGrid(breakpoints, bounds) {
363
413
  var grid = this;
364
414
  if (!bounds) {
@@ -48,19 +48,20 @@ var getArrayNodes = function (elem) {
48
48
  var nodeName = node.children.length > 1 ? node.children[0].innerHTML : node.innerHTML;
49
49
  deep++;
50
50
  if (nodeName) {
51
- nodes.push({
51
+ nodes.push(new Item({
52
52
  name: nodeName,
53
53
  tab: deep,
54
54
  href: node.getAttribute("path") || node.getAttribute("href"),
55
55
  class: node.className,
56
56
  closed: true
57
- });
57
+ }));
58
58
  }
59
59
  var index = nodes.length - 1;
60
60
  if (node.children.length > 1) {
61
61
  [].forEach.call(node.children[1].children, run);
62
62
  }
63
- nodes[index].children = nodes.splice(index + 1, nodes.length - index);
63
+ nodes[index].push.apply(nodes[index], nodes.splice(index + 1, nodes.length - index));
64
+ nodes[index].children = nodes[index];
64
65
  deep--;
65
66
  };
66
67
  [].forEach.call(elem.children, run);
@@ -93,7 +94,7 @@ var getTreeNodes = function (elem) {
93
94
  var emitEvent = function (item, event) {
94
95
  event.preventDefault(true);
95
96
  if (item.disabled) return;
96
- active(this, item, item, createItemTarget.call(this, item));
97
+ active(this, item, item, this.$src ? createItemTarget.call(this, item) : this);
97
98
  }
98
99
  function bindGlobalkey(elem, keymap, emit) {
99
100
  if (elem.keymap) {
@@ -194,8 +195,8 @@ function main(elem, mode) {
194
195
  case "y":
195
196
  case "vertical":
196
197
  if (!direction) mode = "vertical", direction = 'y';
197
- var emit = function (item) {
198
- active(elem, item.value, item, createItemTarget.call(elem, item.value));
198
+ var emit = function (item, target) {
199
+ active(elem, item.value, item, elem.$src ? createItemTarget.call(elem, item.value) : target);
199
200
  };
200
201
  if ("$src" in elem) {
201
202
  getGenerator(elem, 'menu-item');
@@ -17,7 +17,7 @@ function main(elem, scope, hasIcon) {
17
17
  else {
18
18
  item.removeAttribute("disabled");
19
19
  }
20
- render(item.children, scope, hasIcon instanceof Array ? hasIcon : [{ useIcon: hasIcon, hasIcon, name, icon }], false);
20
+ render(item.children, scope, hasIcon instanceof Array ? hasIcon : [{ useIcon: hasIcon, hasIcon, name, icon }], 0);
21
21
  if (scope.line) item.setAttribute("line", ''), on("click")(item, preventDefault);
22
22
  if (scope.hotkey) bindAccesskey(item, scope.hotkey);
23
23
  return item;
@@ -286,6 +286,7 @@ function main(page, items, active, direction = 'y') {
286
286
  };
287
287
  var $scope = {
288
288
  "menu-item"(e, s) {
289
+ if (s === e.$scope) s = itemName ? s[itemName] : s.menu;
289
290
  var a = button(
290
291
  menuItem(e, s.value, this.hasIcon)
291
292
  );
@@ -293,7 +294,7 @@ function main(page, items, active, direction = 'y') {
293
294
  page.firstMenu = a;
294
295
  page.total = items.length;
295
296
  }
296
- a.menu = s.menu;
297
+ a.menu = s;
297
298
  return a;
298
299
  },
299
300
  menus: items,
@@ -1,17 +1,26 @@
1
1
  var hasOwnProperty = {}.hasOwnProperty;
2
2
  var renderElements = Object.create(null);
3
3
  var presets = Object.create(null);
4
+ var createTemplateNodes = function (text) {
5
+ var node = document.createElement(this.parentNode.tagName || "div");
6
+ node.innerHTML = text;
7
+ remove(this.with);
8
+ this.with = [].slice.call(node.childNodes, 0);
9
+ appendChild.after(this, this.with);
10
+ renderElement(this.with, this.$scope, this.$parentScopes, this.renderid === 9);
11
+ };
4
12
  presets.template = function (t) {
5
13
  var comment = document.createComment('template');
6
14
  comment.$scope = t.$scope;
7
15
  comment.$parentScopes = t.$parentScopes;
8
- once("append")(comment, function () {
9
- var node = document.createElement(comment.parentNode.tagName || "div");
10
- node.innerHTML = t.innerHTML;
11
- comment.with = [].slice.call(node.childNodes, 0);
12
- appendChild.after(comment, comment.with);
13
- renderElement(comment.with, comment.$scope, comment.$parentScopes, this.renderid === 9);
14
- });
16
+ if (!t.innerHTML) {
17
+ care(comment, createTemplateNodes)
18
+ }
19
+ else {
20
+ once("append")(comment, function () {
21
+ createTemplateNodes.call(comment, t.innerHTML);
22
+ });
23
+ }
15
24
  return comment;
16
25
  };
17
26
  window.renderElements = renderElements;
@@ -224,7 +224,7 @@ function tree() {
224
224
  _div.refresh();
225
225
  onclick(_div, function (event) {
226
226
  var isClosed = com.isClosed();
227
- if (!active(banner, com.value, com, element.$src ? createItemTarget.call(element, com.value) : _div)) {
227
+ if (!active(banner, com.value, com, banner.$src ? createItemTarget.call(banner, com.value) : _div)) {
228
228
  return;
229
229
  }
230
230
  if (isClosed === com.isClosed() && com.length) {
@@ -594,7 +594,7 @@ function addGlobal(element, name = null, isDestroy) {
594
594
  }
595
595
  global[name] = element;
596
596
  } else if (isNode(name)) {
597
- if (isDestroy) appendChild.insert(name, element);
597
+ if (isDestroy || name.nodeType !== 1) appendChild.insert(name, element);
598
598
  else appendChild(name, element);
599
599
  } else if (isFunction(name)) {
600
600
  name(element);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "3.18.0",
3
+ "version": "3.18.1",
4
4
  "description": "一个开发工具,开放源代码,自带组件库和编译环境,可以用来开发web组件,web应用或nodejs模块,或做为已有代码的加密工具,也可以做为静态页面服务器或跨域中转服务器使用",
5
5
  "main": "public/efront.js",
6
6
  "directories": {