efront 4.17.0 → 4.18.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.
- package/#/345/233/275/351/231/205/345/214/226.yml +30 -0
- package/apps/kugou/home.less +0 -14
- package/apps/pivot/api.yml +7 -0
- package/apps/pivot/db/config.xht +37 -0
- package/apps/pivot/db/edit.xht +47 -0
- package/apps/pivot/db/list.xht +63 -0
- package/apps/pivot/home/welcome.html +8 -0
- package/apps/pivot/home/welcome.js +12 -1
- package/apps/pivot/home/welcome.less +3 -0
- package/apps/pivot/main.js +0 -3
- package/apps/pivot/wow/root.js +7 -10
- package/coms/basic/color.js +1 -0
- package/coms/basic/data.js +6 -4
- package/coms/basic/refilm_decode.js +14 -6
- package/coms/basic/submit_.js +12 -5
- package/coms/compile/Program.js +1 -1
- package/coms/compile/downLevel.js +4 -3
- package/coms/docs/markdown.js +5 -0
- package/coms/explorer/Explorer.js +2 -1
- package/coms/explorer/context.js +2 -0
- package/coms/explorer/edit.html +2 -1
- package/coms/explorer/edit.js +6 -4
- package/coms/frame/route.js +3 -3
- package/coms/kugou/parseSongsList.js +1 -1
- package/coms/reptile/readRequestAsJson.js +26 -0
- package/coms/zimoli/back.xht +22 -3
- package/coms/zimoli/button.js +12 -2
- package/coms/zimoli/confirm.js +3 -2
- package/coms/zimoli/confirm.less +1 -2
- package/coms/zimoli/field.html +2 -1
- package/coms/zimoli/field.js +4 -0
- package/coms/zimoli/getCursorPosition.js +21 -0
- package/coms/zimoli/model.js +97 -95
- package/coms/zimoli/on.js +9 -1
- package/coms/zimoli/progbar.xht +59 -0
- package/coms/zimoli/prompt.js +81 -35
- package/coms/zimoli/prompt.less +23 -3
- package/coms/zimoli/render.js +34 -20
- package/coms/zimoli/select.js +1 -1
- package/coms/zimoli/selectList.js +8 -6
- package/coms/zimoli/selectListEdit.html +1 -1
- package/coms/zimoli/selectListEdit.js +1 -0
- package/coms/zimoli/view.js +3 -0
- package/coms/zimoli/zimoli.js +6 -5
- package/coms//350/214/250/350/217/260//347/274/226/350/276/221/346/241/206.xht +1 -1
- package/docs/mark.xht +8 -0
- package/package.json +1 -1
- package/public/efront.js +1 -1
- /package/coms/{zimoli → basic}/checkroles.js +0 -0
package/coms/zimoli/back.xht
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
<back onclick="history.back()">
|
|
2
|
+
<div class="track"></div>
|
|
2
3
|
<i></i><span>${i18n`返回`}</span>
|
|
3
4
|
</back>
|
|
5
|
+
<!--
|
|
6
|
+
中国共产党有多臭, 中国足球就有多臭。
|
|
7
|
+
这是垄断的必然结果,权力的核心被拉拢腐蚀只是结果,而不是原因。
|
|
8
|
+
只惩办被拉拢腐蚀的人员,而不从局势着眼,不修改制度,是本末倒置。
|
|
9
|
+
一台制造腐败分子的机器长期运转的结果,就是生产更多的腐败分子。
|
|
10
|
+
-->
|
|
4
11
|
<style>
|
|
5
12
|
i:before {
|
|
6
13
|
content: "‹";
|
|
7
14
|
font-size: 26px;
|
|
8
15
|
font-family: Arial, Helvetica, sans-serif;
|
|
9
16
|
}
|
|
10
|
-
|
|
17
|
+
|
|
11
18
|
i {
|
|
12
19
|
font-style: normal;
|
|
13
20
|
margin-top: -12px;
|
|
14
21
|
}
|
|
15
|
-
|
|
22
|
+
|
|
16
23
|
span {
|
|
17
24
|
text-transform: capitalize;
|
|
18
25
|
font-size: 14px;
|
|
@@ -20,6 +27,18 @@
|
|
|
20
27
|
margin-top: -10px;
|
|
21
28
|
}
|
|
22
29
|
|
|
30
|
+
& {
|
|
31
|
+
left: 0;
|
|
32
|
+
top: 0;
|
|
33
|
+
height: 100%;
|
|
34
|
+
border-radius: inherit;
|
|
35
|
+
position: absolute;
|
|
36
|
+
width: 60px;
|
|
37
|
+
box-shadow: none;
|
|
38
|
+
background: transparent;
|
|
39
|
+
color: inherit;
|
|
40
|
+
}
|
|
41
|
+
|
|
23
42
|
span,
|
|
24
43
|
i {
|
|
25
44
|
position: absolute;
|
|
@@ -31,5 +50,5 @@
|
|
|
31
50
|
}
|
|
32
51
|
</style>
|
|
33
52
|
<script>
|
|
34
|
-
|
|
53
|
+
button(this);
|
|
35
54
|
</script>
|
package/coms/zimoli/button.js
CHANGED
|
@@ -96,9 +96,9 @@ function button(texter, type) {
|
|
|
96
96
|
if (!type) {
|
|
97
97
|
texter = texter.replace(/#\w*/, function (w) {
|
|
98
98
|
if (/^#([a-f\d]{3,4}){1,2}$/.test(w)) {
|
|
99
|
-
type =
|
|
99
|
+
type = w;
|
|
100
100
|
}
|
|
101
|
-
type = w.slice(1);
|
|
101
|
+
else type = w.slice(1);
|
|
102
102
|
return '';
|
|
103
103
|
}).trim();
|
|
104
104
|
}
|
|
@@ -139,6 +139,16 @@ function button(texter, type) {
|
|
|
139
139
|
var size = isFinite(type) ? type + "px" : type;
|
|
140
140
|
css(button, `height:${size};`);
|
|
141
141
|
}
|
|
142
|
+
else if (color.isColor(type)) {
|
|
143
|
+
var c = color.format(type);
|
|
144
|
+
if (button.getAttribute('type') === 'anchor' || button.tagName === 'A') {
|
|
145
|
+
css(button, { color: c })
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
var b = color.pair(c);
|
|
149
|
+
css(button, { background: c, color: b });
|
|
150
|
+
}
|
|
151
|
+
}
|
|
142
152
|
else if (isString(type)) button.setAttribute("type", type);
|
|
143
153
|
}
|
|
144
154
|
return button;
|
package/coms/zimoli/confirm.js
CHANGED
|
@@ -94,10 +94,11 @@ function confirm() {
|
|
|
94
94
|
element.setAttribute("locked", '');
|
|
95
95
|
this.setAttribute("loading", "");
|
|
96
96
|
res.then((res) => {
|
|
97
|
-
element.result = res;
|
|
98
|
-
remove(element);
|
|
99
97
|
element.removeAttribute('locked');
|
|
100
98
|
this.removeAttribute('loading');
|
|
99
|
+
if (res === false) return;
|
|
100
|
+
element.result = res;
|
|
101
|
+
remove(element);
|
|
101
102
|
}, () => {
|
|
102
103
|
this.removeAttribute('loading');
|
|
103
104
|
element.removeAttribute('locked');
|
package/coms/zimoli/confirm.less
CHANGED
package/coms/zimoli/field.html
CHANGED
package/coms/zimoli/field.js
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var cursor = document.createElement("span");
|
|
2
|
+
var getCursorPosition = function () {
|
|
3
|
+
var selection = document.getSelection();
|
|
4
|
+
var { anchorNode, anchorOffset, focusNode, focusOffset } = selection;
|
|
5
|
+
if (!focusNode) return;
|
|
6
|
+
var position;
|
|
7
|
+
if (focusNode.nodeType === 1) {
|
|
8
|
+
focusNode.insertBefore(cursor, focusNode.childNodes[focusOffset]);
|
|
9
|
+
position = getScreenPosition(cursor);
|
|
10
|
+
}
|
|
11
|
+
else if (focusNode.nodeType === 3) {
|
|
12
|
+
var nodeValue = focusNode.nodeValue;
|
|
13
|
+
focusNode.nodeValue = nodeValue.slice(0, focusOffset);
|
|
14
|
+
focusNode.parentNode.insertBefore(cursor, focusNode.nextSibling);
|
|
15
|
+
position = getScreenPosition(cursor);
|
|
16
|
+
cursor.parentNode.removeChild(cursor);
|
|
17
|
+
focusNode.nodeValue = nodeValue;
|
|
18
|
+
}
|
|
19
|
+
selection.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset)
|
|
20
|
+
return position;
|
|
21
|
+
};
|
package/coms/zimoli/model.js
CHANGED
|
@@ -166,6 +166,7 @@ var constructors = {
|
|
|
166
166
|
var { field, data } = _;
|
|
167
167
|
elem.value = data[field.key];
|
|
168
168
|
var o = field.options?.[0];
|
|
169
|
+
elem.editable = field.editable;
|
|
169
170
|
if (field.holder) _.innerHTML = `<span -if="isEmpty(data[field.key])" class="placeholder">${field.holder}</span>`;
|
|
170
171
|
if (!isEmpty(o?.key)) {
|
|
171
172
|
field.options.unshift({
|
|
@@ -307,114 +308,115 @@ var markEditer = function (editers) {
|
|
|
307
308
|
editers[k].isediter = true;
|
|
308
309
|
}
|
|
309
310
|
};
|
|
310
|
-
function
|
|
311
|
-
var
|
|
312
|
-
|
|
311
|
+
var build = function () {
|
|
312
|
+
var elem = this;
|
|
313
|
+
var { data, readonly, field } = elem;
|
|
313
314
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
else if (!isEmpty(e)) {
|
|
345
|
-
elem.innerHTML = e;
|
|
346
|
-
}
|
|
347
|
-
return;
|
|
315
|
+
if (!field || !data) return;
|
|
316
|
+
var run = function () {
|
|
317
|
+
var function_type = "function";
|
|
318
|
+
if (data !== elem.data || field !== elem.field || readonly !== elem.readonly) return;
|
|
319
|
+
var field_type = field.type || field.editor, field_editor = field.editor || field.type;
|
|
320
|
+
if (field_editor instanceof Function && field_type === field_editor) {
|
|
321
|
+
field_type = function_type;
|
|
322
|
+
}
|
|
323
|
+
if (!(field_editor instanceof Function)) {
|
|
324
|
+
field_editor = null;
|
|
325
|
+
}
|
|
326
|
+
if (/\?/.test(field_type)) {
|
|
327
|
+
var [field_type, field_ref] = field_type.split("?");
|
|
328
|
+
}
|
|
329
|
+
var type = elem.getAttribute('type');
|
|
330
|
+
if (type !== field_type) {
|
|
331
|
+
elem.setAttribute("type", field_type);
|
|
332
|
+
}
|
|
333
|
+
remove(elem.children);
|
|
334
|
+
if (isString(field_type)) field_type = field_type.replace(/\:[\d+\.]+$/, '');
|
|
335
|
+
if (readonly || field.readonly) {
|
|
336
|
+
if (field_type === "function") {
|
|
337
|
+
field_editor(elem);
|
|
338
|
+
} else {
|
|
339
|
+
var create = findReaderForElement(field_type, elem) || readonly_types[field_type];
|
|
340
|
+
if (create) {
|
|
341
|
+
var e = create(elem, data, field_ref);
|
|
342
|
+
if (isNode(e)) {
|
|
343
|
+
if (e !== elem) appendChild(elem, e);
|
|
348
344
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
value = getName(map[value]);
|
|
345
|
+
else if (!isEmpty(e)) {
|
|
346
|
+
elem.innerHTML = e;
|
|
347
|
+
}
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
elem.innerHTML = '<span ng-bind=get()></span>';
|
|
351
|
+
render(elem, {
|
|
352
|
+
get() {
|
|
353
|
+
if (isEmpty(field.key)) return;
|
|
354
|
+
var value = seek(data, field.key);
|
|
355
|
+
if (field.options) {
|
|
356
|
+
if (!field.optionsMap) {
|
|
357
|
+
var map = Object.create(null);
|
|
358
|
+
for (var o of field.options) {
|
|
359
|
+
var v = getValue(o);
|
|
360
|
+
map[v] = o;
|
|
366
361
|
}
|
|
362
|
+
field.optionsMap = map;
|
|
363
|
+
}
|
|
364
|
+
var map = field.optionsMap;
|
|
365
|
+
if (value in map) {
|
|
366
|
+
value = getName(map[value]);
|
|
367
367
|
}
|
|
368
|
-
return value;
|
|
369
368
|
}
|
|
369
|
+
return value;
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
} else {
|
|
374
|
+
var create = field_type === "function" ? field_editor : findEditerForElement(field_type, elem) || constructors[field_type];
|
|
375
|
+
var ipt = create ? create(elem, field_ref) : field.key ? input(function () {
|
|
376
|
+
var input = document.createElement('input');
|
|
377
|
+
input.setAttribute('type', field.type);
|
|
378
|
+
return input;
|
|
379
|
+
}()) : null;
|
|
380
|
+
if (ipt) {
|
|
381
|
+
if (ipt !== elem) appendChild.insert(elem, ipt);
|
|
382
|
+
if (!ipt.$scope) {
|
|
383
|
+
renderModel.call(ipt, field, data);
|
|
384
|
+
var saved_sataus;
|
|
385
|
+
ipt.$renders.push(function () {
|
|
386
|
+
var { valid, status } = this;
|
|
387
|
+
if (elem.valid !== valid) elem.valid = valid;
|
|
388
|
+
if (saved_sataus === status) return;
|
|
389
|
+
saved_sataus = status;
|
|
390
|
+
elem.setAttribute('status', saved_sataus);
|
|
391
|
+
});
|
|
392
|
+
} else {
|
|
393
|
+
on("change")(ipt, function () {
|
|
394
|
+
data[field.key] = getValue.call(this);
|
|
370
395
|
});
|
|
396
|
+
setValue.call(ipt, data[field.key]);
|
|
371
397
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
return input;
|
|
378
|
-
}()) : null;
|
|
379
|
-
if (ipt) {
|
|
380
|
-
if (ipt !== elem) appendChild.insert(elem, ipt);
|
|
381
|
-
if (!ipt.$scope) {
|
|
382
|
-
renderModel.call(ipt, field, data);
|
|
383
|
-
var saved_sataus;
|
|
384
|
-
ipt.$renders.push(function () {
|
|
385
|
-
var { valid, status } = this;
|
|
386
|
-
if (elem.valid !== valid) elem.valid = valid;
|
|
387
|
-
if (saved_sataus === status) return;
|
|
388
|
-
saved_sataus = status;
|
|
389
|
-
elem.setAttribute('status', saved_sataus);
|
|
390
|
-
});
|
|
391
|
-
} else {
|
|
392
|
-
on("change")(ipt, function () {
|
|
393
|
-
data[field.key] = getValue.call(this);
|
|
394
|
-
});
|
|
395
|
-
setValue.call(ipt, data[field.key]);
|
|
396
|
-
}
|
|
397
|
-
if ("option_to" in field) {
|
|
398
|
-
on("change")(ipt, copyOptionData);
|
|
399
|
-
}
|
|
400
|
-
if ("options_from" in field) {
|
|
401
|
-
ipt.$renders.push(rebuildOptions);
|
|
402
|
-
}
|
|
398
|
+
if ("option_to" in field) {
|
|
399
|
+
on("change")(ipt, copyOptionData);
|
|
400
|
+
}
|
|
401
|
+
if ("options_from" in field) {
|
|
402
|
+
ipt.$renders.push(rebuildOptions);
|
|
403
403
|
}
|
|
404
404
|
}
|
|
405
|
-
};
|
|
406
|
-
if (data.loading_promise || field.loading_promise) {
|
|
407
|
-
Promise.all([
|
|
408
|
-
data.loading_promise,
|
|
409
|
-
field.loading_promise
|
|
410
|
-
]).then(run);
|
|
411
|
-
} else {
|
|
412
|
-
run();
|
|
413
405
|
}
|
|
414
406
|
};
|
|
407
|
+
if (data.loading_promise || field.loading_promise) {
|
|
408
|
+
Promise.all([
|
|
409
|
+
data.loading_promise,
|
|
410
|
+
field.loading_promise
|
|
411
|
+
]).then(run);
|
|
412
|
+
} else {
|
|
413
|
+
run();
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
function main(elem) {
|
|
415
417
|
on("changes")(elem, function ({ changes }) {
|
|
416
418
|
if (changes.data || changes.field || changes.readonly) {
|
|
417
|
-
build();
|
|
419
|
+
build.call(this);
|
|
418
420
|
}
|
|
419
421
|
});
|
|
420
422
|
return elem;
|
package/coms/zimoli/on.js
CHANGED
|
@@ -167,6 +167,7 @@ class EventNeed {
|
|
|
167
167
|
stop = false;
|
|
168
168
|
capture = false;
|
|
169
169
|
self = false;
|
|
170
|
+
singly = false;
|
|
170
171
|
prevent = false;
|
|
171
172
|
passive = false;
|
|
172
173
|
keyNeed = [];
|
|
@@ -250,15 +251,21 @@ function checkKeyNeed(eventtypes, e) {
|
|
|
250
251
|
var pendingid = 0;
|
|
251
252
|
function pending(h, event) {
|
|
252
253
|
if (h instanceof Function) {
|
|
254
|
+
h.pending = true;
|
|
253
255
|
var res = h.call(this, event);
|
|
254
256
|
if (res && isFunction(res.then) && this.setAttribute) {
|
|
255
|
-
var id = ++pendingid
|
|
257
|
+
var id = ++pendingid;
|
|
258
|
+
pendingid &= 0x7fffffff;
|
|
256
259
|
this.setAttribute('pending', id);
|
|
257
260
|
var removePending = () => {
|
|
261
|
+
if (h.pending) setTimeout(function () {
|
|
262
|
+
h.pending = false;
|
|
263
|
+
}, 120)
|
|
258
264
|
if (+this.getAttribute('pending') === id) this.removeAttribute('pending');
|
|
259
265
|
};
|
|
260
266
|
res.then(removePending, removePending);
|
|
261
267
|
}
|
|
268
|
+
else h.pending = false
|
|
262
269
|
return res;
|
|
263
270
|
}
|
|
264
271
|
return h;
|
|
@@ -305,6 +312,7 @@ var broadcast = function (k, hk, event) {
|
|
|
305
312
|
if (eventtypes.stop) event.stopPropagation();
|
|
306
313
|
if (eventtypes.passive && !preventPassive) event.preventDefault = function () { };
|
|
307
314
|
if (eventtypes.prevent) event.preventDefault();
|
|
315
|
+
if (eventtypes.singly && handler.pending) continue;
|
|
308
316
|
if (handler instanceof Array) {
|
|
309
317
|
for (var h of handler) {
|
|
310
318
|
h.call(context, event);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<style>
|
|
2
|
+
& {
|
|
3
|
+
display: inline-block;
|
|
4
|
+
min-width: 60px;
|
|
5
|
+
height: 12px;
|
|
6
|
+
color: #3ae;
|
|
7
|
+
border: 2px double;
|
|
8
|
+
background: #f2f2f2;
|
|
9
|
+
position: relative;
|
|
10
|
+
border-radius: 2px;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
&[danger] {
|
|
14
|
+
color: #c24;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
>div {
|
|
18
|
+
position: relative;
|
|
19
|
+
border: 4px solid;
|
|
20
|
+
border-left: none;
|
|
21
|
+
border-right: none;
|
|
22
|
+
height: 100%;
|
|
23
|
+
}
|
|
24
|
+
</style>
|
|
25
|
+
<div>
|
|
26
|
+
<div -style="{width:value}"></div>
|
|
27
|
+
</div>
|
|
28
|
+
<script>
|
|
29
|
+
var { total, current } = this;
|
|
30
|
+
var calc = function () {
|
|
31
|
+
var v = (current / total * 10000 + .5) | 0;
|
|
32
|
+
if (v < 0) v = 0;
|
|
33
|
+
if (v > 10000) v = 10000;
|
|
34
|
+
return v / 100 + "%";
|
|
35
|
+
};
|
|
36
|
+
var value = calc();
|
|
37
|
+
Object.defineProperties(this, {
|
|
38
|
+
total: {
|
|
39
|
+
set(v) {
|
|
40
|
+
if (total === v) return;
|
|
41
|
+
total = v;
|
|
42
|
+
value = calc();
|
|
43
|
+
},
|
|
44
|
+
get() {
|
|
45
|
+
return total;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
current: {
|
|
49
|
+
set(v) {
|
|
50
|
+
if (current === v) return;
|
|
51
|
+
current = v;
|
|
52
|
+
value = calc();
|
|
53
|
+
},
|
|
54
|
+
get() {
|
|
55
|
+
return current;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
</script>
|
package/coms/zimoli/prompt.js
CHANGED
|
@@ -1,41 +1,81 @@
|
|
|
1
|
+
var settip = function (tip, res) {
|
|
2
|
+
if (isEmpty(res)) valid = true;
|
|
3
|
+
else if (typeof res === 'boolean') valid = res;
|
|
4
|
+
else if (isNode(res)) remove(tip.childNodes), appendChild(tip, res);
|
|
5
|
+
else html(tip, res), valid = false;
|
|
6
|
+
if (valid) html(tip, '');
|
|
7
|
+
return valid;
|
|
8
|
+
}
|
|
1
9
|
var validate = function (text, checker, tip) {
|
|
2
10
|
var valid;
|
|
3
11
|
if (checker instanceof RegExp) {
|
|
4
12
|
valid = checker.test(text);
|
|
5
13
|
}
|
|
6
14
|
if (isFunction(checker)) {
|
|
7
|
-
|
|
8
|
-
if (isEmpty(res)) valid = true;
|
|
9
|
-
else if (typeof res === 'boolean') valid = res;
|
|
10
|
-
else if (isNode(res)) remove(tip.childNodes), appendChild(tip, res);
|
|
11
|
-
else html(tip, res), valid = false;
|
|
15
|
+
valid = checker(text);
|
|
12
16
|
}
|
|
13
|
-
|
|
17
|
+
valid = settip(tip, valid);
|
|
14
18
|
return valid;
|
|
15
19
|
};
|
|
16
20
|
function prompt() {
|
|
17
|
-
var msg =
|
|
21
|
+
var msg = i18n`请输入`, check, ipt;
|
|
22
|
+
var opts = [];
|
|
23
|
+
var submit = null;
|
|
24
|
+
var wrap = false;
|
|
18
25
|
for (var arg of arguments) {
|
|
19
26
|
if (isNode(arg)) ipt = arg;
|
|
20
27
|
else if (typeof arg === 'string') msg = arg;
|
|
28
|
+
else if (isArray(arg)) opts = arg;
|
|
21
29
|
else if (isFunction(arg) || arg instanceof RegExp) check = arg;
|
|
30
|
+
else if (isObject(arg)) {
|
|
31
|
+
if (isFunction(arg.test)) check = arg;
|
|
32
|
+
if (isFunction(arg.submit)) submit = arg;
|
|
33
|
+
if (isString(arg.msg || arg.title)) msg = arg.msg || arg.title;
|
|
34
|
+
if (arg.multiple || arg.wrap) wrap = true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (!ipt) {
|
|
38
|
+
if (wrap) {
|
|
39
|
+
ipt = document.createElement('div');
|
|
40
|
+
ipt.setAttribute('textarea', '');
|
|
41
|
+
ipt.contentEditable = true;
|
|
42
|
+
}
|
|
43
|
+
else ipt = input();
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
ipt.setAttribute('textarea', '');
|
|
22
47
|
}
|
|
23
|
-
var ipt = input();
|
|
24
48
|
var tip = document.createElement("tip");
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
if (!oked && !ohed) return;
|
|
29
|
-
if (oked) oks.forEach(o => o(ipt.value));
|
|
30
|
-
if (ohed) ohs.forEach(o => o(ipt.value));
|
|
31
|
-
oks.splice(0, oks.length);
|
|
32
|
-
ohs.splice(0, ohs.length);
|
|
33
|
-
};
|
|
34
|
-
var buttons = [button("确认"), button("取消", 'white')];
|
|
35
|
-
if (isFunction(check)) {
|
|
49
|
+
var buttons = [isNode(opts[0]) ? opts[0] : button(opts[0] || i18n`确认`), isNode(opts[1]) ? opts[1] : button(opts[1] || i18n`取消`, 'white')];
|
|
50
|
+
var getValue = () => isFunction(ipt.getValue) ? ipt.getValue() : ipt.value;
|
|
51
|
+
if (isFunction(check) || wrap) {
|
|
36
52
|
var setDisable = function (event) {
|
|
37
|
-
|
|
38
|
-
|
|
53
|
+
var bd = c.body;
|
|
54
|
+
if (wrap && bd) {
|
|
55
|
+
if (p) move.setPosition(c, p);
|
|
56
|
+
var cp = getCursorPosition();
|
|
57
|
+
var bp = getScreenPosition(bd);
|
|
58
|
+
var s = getComputedStyle(ipt);
|
|
59
|
+
var pl = parseFloat(s.paddingLeft) * 2 + ipt.clientLeft + ipt.offsetLeft;
|
|
60
|
+
var pr = parseFloat(s.borderRightWidth) + parseFloat(s.paddingRight) * 2 + (bd.scrollWidth - ipt.offsetLeft - ipt.offsetWidth);
|
|
61
|
+
var pt = parseFloat(s.paddingTop) * 2 + ipt.clientTop + ipt.offsetTop;
|
|
62
|
+
var pb = parseFloat(s.borderBottomWidth) + parseFloat(s.paddingBottom) * 2 + (bd.scrollHeight - ipt.offsetTop - ipt.offsetHeight);
|
|
63
|
+
|
|
64
|
+
if (cp.left < bp.left + pl) {
|
|
65
|
+
bd.scrollLeft -= bp.left + pl - cp.left;
|
|
66
|
+
}
|
|
67
|
+
if (cp.right > bp.right - pr) {
|
|
68
|
+
bd.scrollLeft += cp.right + pr - bp.right;
|
|
69
|
+
}
|
|
70
|
+
if (cp.top < bp.top + pt) {
|
|
71
|
+
bd.scrollTop -= bp.top + pt - cp.top;
|
|
72
|
+
}
|
|
73
|
+
if (cp.bottom > bp.bottom - pb) {
|
|
74
|
+
bd.scrollTop += cp.bottom + pb - cp.bottom;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (!check) return;
|
|
78
|
+
var valid = validate(getValue(), check, tip);
|
|
39
79
|
if (event) attr(body, "error", !valid);
|
|
40
80
|
attr(buttons[0], 'disabled', !valid);
|
|
41
81
|
};
|
|
@@ -45,17 +85,17 @@ function prompt() {
|
|
|
45
85
|
on('paste')(ipt, setDisable);
|
|
46
86
|
on('input')(ipt, setDisable);
|
|
47
87
|
}
|
|
48
|
-
var body = div
|
|
88
|
+
var body = document.createElement("div");
|
|
49
89
|
appendChild(body, [ipt, tip]);
|
|
50
|
-
var c = confirm(msg, body, buttons, function (_) {
|
|
51
|
-
if (oked || ohed) return;
|
|
90
|
+
var c = confirm(msg, body, buttons, async function (_) {
|
|
52
91
|
if (_ === buttons[0]) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
92
|
+
var value = getValue();
|
|
93
|
+
if (check && !validate(value, check, tip)) return false;
|
|
94
|
+
if (submit) {
|
|
95
|
+
var res = await submit.submit(value);
|
|
96
|
+
if (!settip(tip, res)) return false;
|
|
97
|
+
}
|
|
57
98
|
}
|
|
58
|
-
fire();
|
|
59
99
|
});
|
|
60
100
|
on('mounted')(ipt, function () {
|
|
61
101
|
if (setDisable) setDisable();
|
|
@@ -64,15 +104,21 @@ function prompt() {
|
|
|
64
104
|
});
|
|
65
105
|
})
|
|
66
106
|
on("mousedown")(c, e => e.target !== ipt && e.preventDefault() | ipt.focus());
|
|
67
|
-
on("keydown.enter")(c, function (event) {
|
|
107
|
+
on(wrap ? "keydown.ctrl.enter" : "keydown.enter")(c, function (event) {
|
|
68
108
|
if (event.defaultPrevented) return;
|
|
69
109
|
event.preventDefault();
|
|
70
110
|
buttons[0].click();
|
|
71
111
|
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
112
|
+
var p = null;
|
|
113
|
+
if (wrap) {
|
|
114
|
+
oncemount(c, function () {
|
|
115
|
+
requestAnimationFrame(function () {
|
|
116
|
+
p = move.getPosition(c);
|
|
117
|
+
});
|
|
118
|
+
once('dragend')(c, function () {
|
|
119
|
+
p = move.getPosition(c);
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
}
|
|
77
123
|
return c;
|
|
78
124
|
}
|
package/coms/zimoli/prompt.less
CHANGED
|
@@ -12,12 +12,32 @@ tip {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
[body],
|
|
16
|
+
.body {
|
|
17
|
+
>div {
|
|
18
|
+
height: 100%;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
textarea,
|
|
23
|
+
[textarea] {
|
|
16
24
|
width: 100%;
|
|
17
|
-
height: 100%;
|
|
18
25
|
resize: none;
|
|
19
26
|
}
|
|
20
27
|
|
|
28
|
+
>[body],
|
|
29
|
+
>.body {
|
|
30
|
+
max-height: 360px;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
[textarea] {
|
|
34
|
+
min-height: 80px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
& {
|
|
38
|
+
min-height: 130px;
|
|
39
|
+
}
|
|
40
|
+
|
|
21
41
|
input {
|
|
22
42
|
width: 100%;
|
|
23
|
-
}
|
|
43
|
+
}
|