1
0
forked from x/volcanos

opt onmotion.modify

This commit is contained in:
shaoying 2020-09-10 20:58:53 +08:00
parent 1d9c794362
commit 03efbdc570
6 changed files with 83 additions and 59 deletions

View File

@ -189,17 +189,16 @@ Volcanos("onengine", {help: "解析引擎", list: [], _init: function(can, meta,
"project": {name: "研发群", storm: { "project": {name: "研发群", storm: {
"studio": {name: "研发 studio", action: [ "studio": {name: "研发 studio", action: [
{name: "route", help: "路由器", index: "web.route"}, {name: "route", help: "路由器", index: "web.route"},
{name: "shell", help: "命令行", index: "ssh.listen"},
{name: "inner", help: "编辑器", index: "web.code.inner", args: ["src/", "main.go"]}, {name: "inner", help: "编辑器", index: "web.code.inner", args: ["src/", "main.go"]},
{name: "status", help: "代码状态", index: "web.code.git.status"}, {name: "repos", help: "代码库", index: "web.code.git.status"},
{name: "total", help: "代码统计", index: "web.code.git.total"}, {name: "total", help: "统计量", index: "web.code.git.total"},
{name: "paste", help: "粘贴板", index: "web.code.tmux.text"},
{name: "contexts", help: "上下文", index: "web.wiki.word", args: ["src/main.shy"]}, {name: "contexts", help: "上下文", index: "web.wiki.word", args: ["src/main.shy"]},
]}, ]},
"cli": {name: "命令 cli", action: [ "cli": {name: "命令 cli", action: [
{name: "vim", help: "编辑器", index: "web.wiki.word", args: ["usr/icebergs/misc/vim/vim.shy"]}, {name: "ssh", help: "命令行", index: "web.wiki.word", args: ["usr/icebergs/base/ssh/ssh.shy"]},
{name: "git", help: "代码库", index: "web.wiki.word", args: ["usr/icebergs/misc/git/git.shy"]},
{name: "tmux", help: "命令行", index: "web.wiki.word", args: ["usr/icebergs/misc/tmux/tmux.shy"]}, {name: "tmux", help: "命令行", index: "web.wiki.word", args: ["usr/icebergs/misc/tmux/tmux.shy"]},
{name: "git", help: "代码库", index: "web.wiki.word", args: ["usr/icebergs/misc/git/git.shy"]},
{name: "vim", help: "编辑器", index: "web.wiki.word", args: ["usr/icebergs/misc/vim/vim.shy"]},
{name: "zsh", help: "命令行", index: "web.wiki.word", args: ["usr/icebergs/misc/zsh/zsh.shy"]}, {name: "zsh", help: "命令行", index: "web.wiki.word", args: ["usr/icebergs/misc/zsh/zsh.shy"]},
]}, ]},
"web": {name: "网页 web", action: [ "web": {name: "网页 web", action: [
@ -709,6 +708,24 @@ Volcanos("onkeypop", {help: "键盘交互", list: [], _init: function(can) {
}}) }})
Volcanos("onmotion", {help: "动态交互", list: [], _init: function(can) { Volcanos("onmotion", {help: "动态交互", list: [], _init: function(can) {
}, },
modifys: function(can, target, cb) { var back = target.innerHTML
var ui = can.page.Appends(can, target, [{type: "textarea", value: back, style: {height: "80px"}, onkeydown: function(event) {
switch (event.key) {
case "Enter":
if (event.ctrlKey) { target.innerHTML = event.target.value
if (event.target.value != back) {
cb(event, event.target.value, back)
}
}
break
case "Escape":
td.innerHTML = back
break
}
}, onkeyup: function(event) {
}}]); ui.first.focus(), ui.first.setSelectionRange(0, -1)
},
modify: function(can, target, cb) { var back = target.innerHTML modify: function(can, target, cb) { var back = target.innerHTML
var ui = can.page.Appends(can, target, [{type: "input", value: back, onkeydown: function(event) { var ui = can.page.Appends(can, target, [{type: "input", value: back, onkeydown: function(event) {
switch (event.key) { switch (event.key) {
@ -724,7 +741,7 @@ Volcanos("onmotion", {help: "动态交互", list: [], _init: function(can) {
} }
}, onkeyup: function(event) { }, onkeyup: function(event) {
}}]); ui.input.focus(), ui.input.setSelectionRange(0, -1) }}]); ui.first.focus(), ui.first.setSelectionRange(0, -1)
}, },
show: function(can, target, time, cb) { time = time || {value: 100, length: 30} show: function(can, target, time, cb) { time = time || {value: 100, length: 30}
can.page.Modify(can, target, {style: {opacity: 0}}) can.page.Modify(can, target, {style: {opacity: 0}})

View File

@ -108,32 +108,30 @@ var user = Volcanos("user", {help: "用户模块",
if (item.button) { button = can.core.List(item.button, function(item) { if (item.button) { button = can.core.List(item.button, function(item) {
return {button: typeof item == "object"? item: [item, function(event) { cbs(event, item) }]} return {button: typeof item == "object"? item: [item, function(event) { cbs(event, item) }]}
}); return } }); return }
function _init(target) { var pval = ""
if (item.value && item.value.indexOf("@") == 0) {
var pkey = item.value.slice(1).split("=")[0]
if (item.value.indexOf("=") > 0) {
var pval = item.value.slice(1).split("=")[1]
}
can.require(["/plugin/input/"+pkey], function(can) {
can.core.Item(can.onfigure[pkey], function(key, value) { if (key.startsWith("on")) {
target[key] = function(event) { value(event, can, item, target) }
} })
target.type != "button" && (target.value = pval)
})
can.page.Modify(can, target, {autocomplete: "off"})
}
}
return {type: ["tr"], list: [ return {type: ["tr"], list: [
{type: "td", list: [{text: typeof item == "string"? item: item.length > 0? item[0]: item.name || ""}]}, {type: "td", list: [{text: typeof item == "string"? item: item.length > 0? item[0]: item.name || ""}]},
{type: "td", list: [typeof item == "string"? /* input */ {input: item, data: {autofocus: true}}: {type: "td", list: [typeof item == "string"? /* input */ {input: item, data: {autofocus: true}}:
item.length > 0? /* select */ {select: [item]}: item.length > 0? /* select */ {select: [item]}:
item._input == "textarea"? /* textarea */ {type: "textarea", data: item}: item._input == "textarea"? /* textarea */ {type: "textarea", data: item, _init: _init}:
item._input == "select"? /* select */ {select: [[item.name].concat(item.values)], data: item}: item._input == "select"? /* select */ {select: [[item.name].concat(item.values)], data: item}:
item._input? /* input */ {type: "input", data: (item.type = item._input, item), _init: function(target) { item._input? /* input */ {type: "input", data: (item.type = item._input, item), _init: _init}: /* other */ item,
var pval = ""
if (item.value && item.value.indexOf("@") == 0) {
var pkey = item.value.slice(1).split("=")[0]
if (item.value.indexOf("=") > 0) {
var pval = item.value.slice(1).split("=")[1]
}
}
if (item._input == "text" && item.value && item.value.startsWith("@")) {
can.require(["/plugin/input/"+pkey], function(can) {
can.core.Item(can.onfigure[pkey], function(key, value) { if (key.startsWith("on")) {
target[key] = function(event) { value(event, can, item, target) }
} })
target.type != "button" && (target.value = pval)
})
can.page.Modify(can, target, {autocomplete: "off"})
}
}}: /* other */ item,
]}, ]},
]} ]}
})}, })},

View File

@ -6,24 +6,25 @@ Volcanos("onaction", {help: "交互操作", list: [], _init: function(can, msg,
can.onexport._init(can, msg, list, cb, target) can.onexport._init(can, msg, list, cb, target)
}, },
_progress: function(can, msg) { _process: function(can, sub, conf, msg, cmds, cb, silent) {
if (msg.Option("_progress")) { var p = can.onaction[msg.Option("_process")]
if (msg.Append("count") != msg.Append("total")) { typeof p == "function"? p(can, sub, conf, msg, cmds, cb, silent): typeof cb == "function" && cb(msg)
can.user.toast(can, { can.run(msg._event, ["search", "Footer.onaction.ncmd"])
text: "执行进度: "+msg.Append("count")+"/"+msg.Append("total")+"\n"+msg.Append("name"), },
title: value.name, _progress: function(can, sub, conf, msg, cmds, cb, silent) {
duration: 1100, if (msg.Append("size") != "" && msg.Append("size") == msg.Append("total")) {
progress: parseInt(msg.Append("count"))*100/parseInt(msg.Append("total")), return typeof cb == "function" && cb(msg)
})
can.Timer(1000, function() {
var res = can.request({})
res.Option("_action", _action)
res.Option("_progress", msg.Option("_progress"))
sub.run(res._event, cmds, cb, silent)
})
return
}
} }
can.user.toast(can, {
width: 400,
title: conf.name+" "+msg.Append("step")+"% ", duration: 1100,
text: "执行进度: "+can.base.Size(msg.Append("size")||0)+"/"+can.base.Size(msg.Append("total")||"1000")+"\n"+msg.Append("name"),
progress: parseInt(msg.Append("step")),
})
can.Timer(1000, function() {
var res = sub.request({})
sub.run(res._event, cmds, cb, silent)
})
}, },
add_plugin: function(can, river, storm, value) { add_plugin: function(can, river, storm, value) {
if (can.user.Search(can, "river") == river && can.user.Search(can, "storm") == storm && can.user.Search(can, "active") == value.name) { if (can.user.Search(can, "river") == river && can.user.Search(can, "storm") == storm && can.user.Search(can, "active") == value.name) {
@ -44,12 +45,9 @@ Volcanos("onaction", {help: "交互操作", list: [], _init: function(can, msg,
can.Conf("action", value.name) can.Conf("action", value.name)
can.Conf("current", sub) can.Conf("current", sub)
// 插件回调 // 插件回调
var toast = can.user.toast(can, "执行中...", value.name)
return can.run(event, can.onengine[cmds[0]]? cmds: [river, storm, value.action].concat(cmds), function(msg) { return can.run(event, can.onengine[cmds[0]]? cmds: [river, storm, value.action].concat(cmds), function(msg) {
toast.Close(), can.user.toast(can, "执行成功", value.name, 400) // return typeof cb == "function" && cb(msg)
can.run(msg._event, ["search", "Footer.onaction.ncmd"]) can.onaction._process(can, sub, value, msg, cmds, cb, silent)
can.onaction._progress(can, msg)
typeof cb == "function" && cb(msg)
}, silent) }, silent)
} }
sub._target.oncontextmenu = function(event) { sub._target.oncontextmenu = function(event) {

View File

@ -2,7 +2,9 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, conf,
}, },
}) })
Volcanos("onaction", {help: "控件交互", list: [], Volcanos("onaction", {help: "控件交互", list: [],
"关闭": function(event, can) { can.page.Remove(can, can.sup._target) },
"上传": function(event, can) { can.user.upload(event, can) }, "上传": function(event, can) { can.user.upload(event, can) },
"刷新": function(event, can) { can.run(event) },
"查看": function(event, can) { can.run(event) }, "查看": function(event, can) { can.run(event) },
"返回": function(event, can) { "返回": function(event, can) {
can.sup._history.pop(); var his = can.sup._history.pop(); if (his) { can.sup._history.pop(); var his = can.sup._history.pop(); if (his) {
@ -16,6 +18,10 @@ Volcanos("onaction", {help: "控件交互", list: [],
onchange: function(event, can) { onchange: function(event, can) {
if (event.target.tagName == "SELECT") { can.run(event) } if (event.target.tagName == "SELECT") { can.run(event) }
}, },
ondblclick: function(event, can) {
if (can.Conf("type") == "textarea") { event.target.setSelectionRange(0, -1) }
if (can.Conf("type") == "text") { event.target.setSelectionRange(0, -1) }
},
onclick: function(event, can) { var msg = can.sup.request(event) onclick: function(event, can) { var msg = can.sup.request(event)
// 插件回调 // 插件回调
var name = can.Conf("name") var name = can.Conf("name")
@ -37,7 +43,6 @@ Volcanos("onaction", {help: "控件交互", list: [],
// 通用回调 // 通用回调
if (can.Conf("type") == "button") { can.run(event, [name].concat(can.sup.Pack())) } if (can.Conf("type") == "button") { can.run(event, [name].concat(can.sup.Pack())) }
if (event.target.tagName == "INPUT") { event.target.setSelectionRange(0, -1) }
}, },
onkeydown: function(event, can) { onkeydown: function(event, can) {
can.onkeypop.show(event, can) can.onkeypop.show(event, can)

View File

@ -1,3 +1,6 @@
body.white fieldset.plugin.editor {
background-color:#173d4000;
}
fieldset.editor>div.action>div.file { fieldset.editor>div.action>div.file {
border:solid 2px red; padding:2px; border:solid 2px red; padding:2px;
float:left; margin:2px 0; float:left; margin:2px 0;
@ -15,7 +18,7 @@ fieldset.editor>form.option div.item input.args[name=line] {
} }
fieldset.editor>div.output { fieldset.editor>div.output {
background-color:black; background-color:#173d40cc;
} }
fieldset.editor>div.output div.project { fieldset.editor>div.output div.project {
max-height:400px; overflow:auto; max-height:400px; overflow:auto;
@ -39,7 +42,8 @@ fieldset.editor>div.output div.preview {
} }
fieldset.editor>div.output div.preview>div.item { fieldset.editor>div.output div.preview>div.item {
text-align:right; padding:0 4px; margin:0; text-align:right; padding:0 4px; margin:0;
height:20px; border:solid 1px black; height:20px;
border:solid 1px #173d4000;
color:white; color:white;
} }
fieldset.editor>div.output div.preview>div.item:hover { fieldset.editor>div.output div.preview>div.item:hover {
@ -59,11 +63,10 @@ fieldset.editor>div.output div.content {
float:left; float:left;
} }
fieldset.editor>div.output div.content>pre.item { fieldset.editor>div.output div.content>pre.item {
text-align:left; text-align:left; height:20px;
height:20px; border:solid 1px black; border:solid 1px #173d4000;
padding:0; margin:0; padding:0; margin:0;
padding-left:10px; padding-left:10px;
background-color:black;
color:white; color:white;
} }
fieldset.editor>div.output div.content>pre.item.select { fieldset.editor>div.output div.content>pre.item.select {

View File

@ -15,14 +15,15 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg,
return typeof cb == "function" && cb(msg) return typeof cb == "function" && cb(msg)
}, },
_process: function(can, msg) { _process: function(can, msg) {
return
var process = msg.Option("_process") || can.Conf("feature")["_process"] var process = msg.Option("_process") || can.Conf("feature")["_process"]
var cb = can.onaction[process]; typeof cb == "function" && cb(can, msg) var cb = can.onaction[process]; typeof cb == "function" && cb(can, msg)
return
if (can.onimport._progress(can, msg)) { if (can.onimport._progress(can, msg)) {
return true return true
}; can.onimport._refresh(can, msg) }; can.onimport._refresh(can, msg)
}, },
_progress: function(can, msg) { _progress: function(can, msg) {
return
var progress = msg.Option("_progress") || can.Conf("feature")["_progress"] var progress = msg.Option("_progress") || can.Conf("feature")["_progress"]
if (progress) { if (progress) {
can.page.Select(can, can._output, "td", function(td) { can.page.Select(can, can._output, "td", function(td) {
@ -42,7 +43,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg,
_table: function(can, value, key, index, line, array) { _table: function(can, value, key, index, line, array) {
return {type: "td", inner: value, click: function(event) { return {type: "td", inner: value, click: function(event) {
var target = event.target; if (target.tagName == "INPUT" && target.type == "button") { var target = event.target; if (target.tagName == "INPUT" && target.type == "button") {
var msg = can.sup.request(event); msg.Option(line) var msg = can.sup.request(event); msg.Option(can.Option()), msg.Option(line)
var cb = can.onaction[target.value]; return typeof cb == "function"? cb(event, can, target.value): var cb = can.onaction[target.value]; return typeof cb == "function"? cb(event, can, target.value):
can.sup.onaction.input(event, can.sup, target.value, function(msg) { can.run({}) }) can.sup.onaction.input(event, can.sup, target.value, function(msg) { can.run({}) })
} }
@ -51,7 +52,9 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg,
}) })
}, ondblclick: function(event) { }, ondblclick: function(event) {
can.onmotion.modify(can, event.target, function(event, value, old) { can.onmotion[value.indexOf("\n") >= 0 || event.ctrlKey? "modifys": "modify"](can, event.target, function(event, value, old) {
var msg = can.sup.request(event); msg.Option(can.Option()), msg.Option(line)
if (key == "value") { key = line.key }
can.run(event, ["action", "编辑", key, value], function(msg) { can.run({}) }, true) can.run(event, ["action", "编辑", key, value], function(msg) { can.run({}) }, true)
}) })
}, onmouseover: function(event) { }, onmouseover: function(event) {