efront 3.11.4 → 3.12.3

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,12 +1,17 @@
1
1
  var singleClick = function () {
2
2
  var node = this.parentNode;
3
3
  if (node.activeNode === this) return;
4
- if (node.activeNode) node.activeNode.removeAttribute("selected");
4
+ if (node.activeNode) {
5
+ if (node.activeNode.origin) node.activeNode.origin.selected = false;
6
+ node.activeNode.removeAttribute("selected");
7
+ }
5
8
  this.setAttribute("selected", "");
9
+
6
10
  node.activeNode = this;
7
11
  if (node.value === this.value) return;
8
12
  node.value = this.value;
9
13
  node.name = this.name;
14
+ if (this.origin) this.origin.selected = true;
10
15
  dispatch(node, "change");
11
16
  };
12
17
  var multipleClick = function () {
@@ -20,13 +25,33 @@ var multipleClick = function () {
20
25
  values.splice(index, 1);
21
26
  this.removeAttribute("selected");
22
27
  }
28
+ if (this.origin) this.origin.selected = true;
23
29
  dispatch(node, "change");
24
30
  };
25
31
 
26
- function main(children, multiple, addable) {
27
- var page = div();
32
+
33
+ function main() {
34
+ var children, multiple, addable, generator, page;
35
+ for (let a of arguments) {
36
+ if (a instanceof Array) children = a;
37
+ switch (typeof a) {
38
+ case "function":
39
+ generator = a;
40
+ break;
41
+ case "boolean":
42
+ if (multiple === void 0) multiple = a;
43
+ else addable = a;
44
+ case "object":
45
+ if (isNode(a)) {
46
+ page = a;
47
+ if (!generator) generator = getGenerator(page);
48
+ }
49
+ else if (a.length) children = a;
50
+
51
+ }
52
+ }
53
+ if (!page) page = div();
28
54
  page.value = multiple ? [] : "";
29
- var firstValue = false;
30
55
  var clicker = multiple ? multipleClick : singleClick;
31
56
  var itemMap = Object.create(null);
32
57
  function createItem(option) {
@@ -36,6 +61,7 @@ function main(children, multiple, addable) {
36
61
  item.setAttribute("item", '');
37
62
  item.innerHTML = option.innerHTML || option.name;
38
63
  item.name = option.name || option.innerHTML;
64
+ item.origin = option;
39
65
  var icon = option.getAttribute ? option.getAttribute("icon") : option.icon;
40
66
  if (icon) {
41
67
  if (!hasIcon) {
@@ -50,10 +76,10 @@ function main(children, multiple, addable) {
50
76
  if (multiple) {
51
77
  item.setAttribute("selected", "");
52
78
  page.value.push(option.value);
53
- } else if (!firstValue) {
79
+ }
80
+ else {
54
81
  item.setAttribute("selected", "");
55
82
  page.activeNode = item;
56
- firstValue = true;
57
83
  page.value = option.value
58
84
  }
59
85
  }
@@ -61,18 +87,28 @@ function main(children, multiple, addable) {
61
87
  item.setAttribute('disabled', '');
62
88
  } else {
63
89
  onclick(item, clicker);
90
+ on("mouseenter")(item, mouseenter);
64
91
  }
65
92
  return item;
66
93
 
67
94
  }
95
+ var mouseenter = function () {
96
+ if (!mouse) return;
97
+ focus = this.index;
98
+ setFocus();
99
+ };
100
+
101
+
68
102
  var hasIcon = false, iconed = '';
69
103
  var page = list(page, function (i) {
70
104
  if (i < 0 || i >= children.length) return;
71
- return createItem(children[i]);
105
+ return createItem(generator ? generator(i) : children[i]);
72
106
  });
73
- on("append")(page, function () {
107
+ once("append")(page, function () {
108
+ var index = 0;
109
+ for (var cx = 0, dx = children.length; cx < dx; cx++)if (children[cx].selected) index = cx;
74
110
  page.clean();
75
- page.go(0);
111
+ page.go(index);
76
112
  if (adder) {
77
113
  remove(adder);
78
114
  appendChild(page, adder);
@@ -129,6 +165,60 @@ function main(children, multiple, addable) {
129
165
  adder.setAttribute("adder", '');
130
166
  }
131
167
  page.icon = iconed;
168
+ var focus = 0, focused, mouse = false;
169
+ var setFocus = function () {
170
+ var e = page.getIndexedElement(focus);
171
+ if (e === focused) return;
172
+ if (focused) removeClass(focused, 'focus');
173
+ focused = e;
174
+ if (e) addClass(e, 'focus');
175
+ mouse = false;
176
+ };
177
+ var setMouse = function () {
178
+ mouse = true;
179
+ }
180
+ onmousemove(page, setMouse);
181
+ onmousewheel(page, setMouse);
182
+ var moveFocus = function (delta) {
183
+ focus += delta;
184
+ if (focus < 0) focus = 0;
185
+ if (focus >= children.length) focus = children.length - 1;
186
+ page.scrollIfNotCover(focus);
187
+ setFocus();
188
+ };
189
+ bind('keydown.up')(page, function () {
190
+ moveFocus(-1);
191
+ });
192
+ bind('keydown.down')(page, function () {
193
+ moveFocus(1);
194
+ });
195
+ bind('keydown.tab')(page, function (event) {
196
+ if (document.activeElement === page.target) event.preventDefault();
197
+ moveFocus(event.shiftKey ? -1 : 1);
198
+ });
199
+ bind("keydown.home")(page, function (e) {
200
+ moveFocus(-focus);
201
+ });
202
+ bind("keydown.end")(page, function (e) {
203
+ moveFocus(children.length - 1 - focus);
204
+ });
205
+ bind("keydown.pagedown")(page, function (e) {
206
+ page.scrollBy(page.clientHeight);
207
+ focus = page.index() | 0;
208
+ moveFocus(0);
209
+ })
210
+ bind("keydown.pageup")(page, function (e) {
211
+ page.scrollBy(-page.clientHeight);
212
+ focus = page.index() | 0;
213
+ moveFocus(0);
214
+ })
215
+ var enter = function (e) {
216
+ e.preventDefault();
217
+ var e = page.getIndexedElement(focus);
218
+ if (e) e.click();
219
+ };
220
+ bind('keydown.enter')(page, enter);
221
+ bind('keydown.space')(page, enter);
132
222
  on('mousedown')(page, e => e.preventDefault());
133
223
  return page;
134
224
  }
@@ -15,10 +15,10 @@
15
15
  padding: 0 16px;
16
16
 
17
17
  &[selected] {
18
- color: #26f;
18
+ color: #29e;
19
19
  }
20
20
 
21
- &:hover {
21
+ &.focus {
22
22
  background-color: #2ca2f9;
23
23
  color: #fff;
24
24
  }
@@ -2,9 +2,13 @@
2
2
  <option>选项一</option>
3
3
  <option>选项二</option>
4
4
  <option>选项三</option>
5
+ <option selected>简单选项</option>
5
6
  </select>
6
7
  <select>
7
- <option>选项一</option>
8
- <option>选项二</option>
9
- <option>选项三</option>
8
+ <option -repeat="(o,i) in options600" -text="'选项'+o">选项</option>
9
+ <option selected>600个选项</option>
10
10
  </select>
11
+ <select -src="(o,i) in options6000">
12
+ <option -text="'选项'+o">选项</option>
13
+ <option insert selected>60000个选项</option>
14
+ </select>
@@ -1,8 +1,14 @@
1
1
  var page = div();
2
2
  page.innerHTML = selectList_test;
3
- render(page,{
4
- select
5
- })
3
+ render(page, {
4
+ select,
5
+ select2() {
6
+ var sel = document.createElement("select");
7
+ return sel;
8
+ },
9
+ options600: new Array(600).fill(0).map((_, a) => a),
10
+ options6000: new Array(60000).fill(0).map((_, a) => a)
11
+ });
6
12
  function main() {
7
13
  return page;
8
14
  }
@@ -1,7 +1,7 @@
1
- var listY = list(function (data, index) {
1
+ var listY = list(function (index) {
2
2
  var item = div();
3
3
  css(item, `width:100%;height:${Math.random() * 110 + 30}px;border:1px solid;`);
4
- text(item, data);
4
+ text(item, index);
5
5
  return item;
6
6
  }, "Y");
7
7
  onappend(listY, function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "3.11.4",
3
+ "version": "3.12.3",
4
4
  "description": "一个开发工具,开放源代码,自带组件库和编译环境,可以用来开发web组件,web应用或nodejs模块,或做为已有代码的加密工具,也可以做为静态页面服务器或跨域中转服务器使用",
5
5
  "main": "public/efront.js",
6
6
  "directories": {