mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-26 01:04:06 +08:00
opt code.tmpl
This commit is contained in:
parent
4ea1e963de
commit
5c5ea7d85e
@ -968,6 +968,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
}
|
||||
}
|
||||
}
|
||||
msg.Log("fuck", "what %v", msg.Option("componet_name"))
|
||||
|
||||
// 添加设备
|
||||
arg = arg[:0]
|
||||
|
@ -89,17 +89,21 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
"componet_group": &ctx.Config{Name: "component_group", Value: "index", Help: "默认组件"},
|
||||
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
|
||||
"login": []interface{}{
|
||||
map[string]interface{}{"name": "head", "template": "head"},
|
||||
map[string]interface{}{"name": "code", "template": "head", "metas": []interface{}{
|
||||
map[string]interface{}{"name": "viewport", "content": "width=device-width, initial-scale=0.7"},
|
||||
map[string]interface{}{"name": "user-scalable", "content": "no"},
|
||||
}, "favicon": "favicon.ico", "styles": []interface{}{"example.css", "code.css"}},
|
||||
map[string]interface{}{"name": "login", "help": "login", "template": "componet",
|
||||
"componet_ctx": "aaa", "componet_cmd": "auth", "arguments": []interface{}{"@sessid", "ship", "username", "@username", "password", "@password"},
|
||||
"inputs": []interface{}{
|
||||
"componet_ctx": "aaa", "componet_cmd": "auth", "arguments": []interface{}{"@sessid", "ship", "username", "@username", "password", "@password"}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "username", "label": "username", "value": ""},
|
||||
map[string]interface{}{"type": "password", "name": "password", "label": "password", "value": ""},
|
||||
map[string]interface{}{"type": "button", "value": "login"},
|
||||
},
|
||||
"display_append": "", "display_result": "",
|
||||
},
|
||||
map[string]interface{}{"name": "tail", "template": "tail"},
|
||||
map[string]interface{}{"name": "tail", "template": "tail",
|
||||
"scripts": []interface{}{"toolkit.js", "context.js", "example.js", "code.js"},
|
||||
},
|
||||
},
|
||||
"flash": []interface{}{
|
||||
map[string]interface{}{"name": "flash", "template": "head"},
|
||||
@ -121,7 +125,11 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
map[string]interface{}{"name": "tail", "template": "tail"},
|
||||
},
|
||||
"index": []interface{}{
|
||||
map[string]interface{}{"name": "code", "template": "head"},
|
||||
map[string]interface{}{"name": "code", "template": "head", "metas": []interface{}{
|
||||
map[string]interface{}{"name": "viewport", "content": "width=device-width, initial-scale=0.7"},
|
||||
map[string]interface{}{"name": "user-scalable", "content": "no"},
|
||||
}, "favicon": "favicon.ico", "styles": []interface{}{"example.css", "code.css"}},
|
||||
|
||||
map[string]interface{}{"name": "toolkit", "help": "Ctrl+B", "template": "toolkit",
|
||||
"componet_view": "KitList", "componet_init": "initKitList",
|
||||
},
|
||||
@ -138,7 +146,6 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
// "componet_ctx": "aaa", "componet_cmd": "login", "arguments": []interface{}{"@sessid"},
|
||||
// "pre_run": true,
|
||||
// },
|
||||
map[string]interface{}{"name": "clipboard", "help": "clipboard", "template": "clipboard"},
|
||||
map[string]interface{}{"name": "buffer", "help": "buffer", "template": "componet",
|
||||
"componet_ctx": "cli", "componet_cmd": "tmux", "arguments": []interface{}{"buffer"}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "limit", "label": "limit", "value": "3"},
|
||||
@ -211,7 +218,9 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
},
|
||||
},
|
||||
// map[string]interface{}{"name": "mp", "template": "mp"},
|
||||
map[string]interface{}{"name": "tail", "template": "tail"},
|
||||
map[string]interface{}{"name": "tail", "template": "tail",
|
||||
"scripts": []interface{}{"toolkit.js", "context.js", "example.js", "code.js"},
|
||||
},
|
||||
},
|
||||
}, Help: "组件列表"},
|
||||
"upgrade": &ctx.Config{Name: "upgrade", Value: map[string]interface{}{
|
||||
|
@ -1,119 +1,119 @@
|
||||
fieldset {
|
||||
margin-top:8px;
|
||||
}
|
||||
fieldset legend {
|
||||
font-size:16px;
|
||||
font-weight:bold;
|
||||
font-family:monospace;
|
||||
}
|
||||
fieldset form.option div {
|
||||
float:left;
|
||||
}
|
||||
fieldset form.option input {
|
||||
margin-right:10px;
|
||||
}
|
||||
fieldset form.option select {
|
||||
margin-right:10px;
|
||||
}
|
||||
fieldset form.option hr {
|
||||
clear:both;
|
||||
}
|
||||
/* ----- common ----- */
|
||||
fieldset {
|
||||
margin-top:8px;
|
||||
}
|
||||
fieldset legend {
|
||||
font-size:16px;
|
||||
font-weight:bold;
|
||||
font-family:monospace;
|
||||
}
|
||||
fieldset form.option div {
|
||||
float:left;
|
||||
}
|
||||
fieldset form.option input {
|
||||
margin-right:10px;
|
||||
}
|
||||
fieldset form.option input.cmd {
|
||||
color:white;
|
||||
background-color:#272822;
|
||||
padding-left:10px;
|
||||
width:600px;
|
||||
}
|
||||
fieldset form.option select {
|
||||
margin-right:10px;
|
||||
}
|
||||
fieldset form.option hr {
|
||||
clear:both;
|
||||
}
|
||||
|
||||
fieldset table.append {
|
||||
font-size:14px;
|
||||
overflow: auto;
|
||||
}
|
||||
fieldset table.append tr:hover {
|
||||
background-color:lightgreen;
|
||||
}
|
||||
fieldset table.append th {
|
||||
font-family:monospace;
|
||||
background-color:lightgreen;
|
||||
cursor:pointer;
|
||||
}
|
||||
fieldset table.append th.order {
|
||||
background-color:red;
|
||||
cursor:pointer;
|
||||
}
|
||||
fieldset table.append td {
|
||||
max-width:1200px;
|
||||
font-family:monospace;
|
||||
padding-left: 10px;
|
||||
padding-right: 20px;
|
||||
}
|
||||
fieldset table.append td.clip {
|
||||
background-color:red;
|
||||
}
|
||||
fieldset table.append td:hover {
|
||||
background-color:red;
|
||||
}
|
||||
fieldset code.result pre {
|
||||
color:white;
|
||||
font-size:14px;
|
||||
background-color:#272822;
|
||||
overflow:scroll;
|
||||
padding:5px;
|
||||
border:solid 2px green;
|
||||
border-left:solid 4px green;
|
||||
margin:0;
|
||||
}
|
||||
fieldset code.result pre.clipboard {
|
||||
height:2em;
|
||||
}
|
||||
fieldset table.append {
|
||||
font-size:14px;
|
||||
overflow: auto;
|
||||
}
|
||||
fieldset table.append tr:hover {
|
||||
background-color:lightgreen;
|
||||
}
|
||||
fieldset table.append th {
|
||||
font-family:monospace;
|
||||
background-color:lightgreen;
|
||||
cursor:pointer;
|
||||
}
|
||||
fieldset table.append th.order {
|
||||
background-color:red;
|
||||
cursor:pointer;
|
||||
}
|
||||
fieldset table.append td {
|
||||
max-width:1200px;
|
||||
font-family:monospace;
|
||||
padding-left: 10px;
|
||||
padding-right: 20px;
|
||||
}
|
||||
fieldset table.append td.clip {
|
||||
background-color:red;
|
||||
}
|
||||
fieldset table.append td:hover {
|
||||
background-color:red;
|
||||
}
|
||||
fieldset code.result pre {
|
||||
color:white;
|
||||
font-size:14px;
|
||||
background-color:#272822;
|
||||
overflow:scroll;
|
||||
padding:5px;
|
||||
border:solid 2px green;
|
||||
border-left:solid 4px green;
|
||||
margin:0;
|
||||
}
|
||||
fieldset code.result pre.clipboard {
|
||||
height:2em;
|
||||
}
|
||||
/* ----- FlashList ----- */
|
||||
fieldset.flasktext {
|
||||
}
|
||||
|
||||
fieldset.flasktext {
|
||||
}
|
||||
fieldset.flasklist div.detail {
|
||||
border:ridge 2px green;
|
||||
border-bottom:0px;
|
||||
margin-top:20px;
|
||||
padding:5px;
|
||||
}
|
||||
fieldset.flasklist div.action {
|
||||
border:ridge 2px green;
|
||||
border-top:0px;
|
||||
border-bottom:0px;
|
||||
}
|
||||
fieldset.flasklist code.output pre {
|
||||
border:ridge 2px green;
|
||||
margin:0px;
|
||||
padding:5px;
|
||||
border-top: 0px;
|
||||
}
|
||||
/* ----- KitList ----- */
|
||||
fieldset.KitList {
|
||||
color:#e6dd37;
|
||||
font-size:14px;
|
||||
font-family:monospace;
|
||||
background-color:#498bb1a8;
|
||||
border:solid 3px red;
|
||||
width:60px;
|
||||
height:20px;
|
||||
overflow:scroll;
|
||||
position:fixed;
|
||||
}
|
||||
fieldset.KitList:hover, fieldset.KitList.max {}
|
||||
fieldset.KitList div:hover, fieldset.KitList li li:hover {
|
||||
background-color:red;
|
||||
}
|
||||
fieldset.KitList div.stick, fieldset.KitList li li.stick {
|
||||
background-color:red;
|
||||
}
|
||||
fieldset.KitList li>label.result{
|
||||
background-color:rgba(0,0,0,0.2);
|
||||
padding:0 5px;
|
||||
border:2px solid green;
|
||||
margin-left: 10px;
|
||||
}
|
||||
fieldset.KitList li>input {
|
||||
background-color:rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
fieldset.flasklist div.detail {
|
||||
border:ridge 2px green;
|
||||
border-bottom:0px;
|
||||
margin-top:20px;
|
||||
padding:5px;
|
||||
}
|
||||
fieldset.flasklist div.action {
|
||||
border:ridge 2px green;
|
||||
border-top:0px;
|
||||
border-bottom:0px;
|
||||
}
|
||||
fieldset.flasklist code.output pre {
|
||||
border:ridge 2px green;
|
||||
margin:0px;
|
||||
padding:5px;
|
||||
border-top: 0px;
|
||||
}
|
||||
|
||||
|
||||
textarea.clipboard {
|
||||
color:white;
|
||||
background-color:#272822;
|
||||
width:600px;
|
||||
}
|
||||
|
||||
form.option label.keymap {
|
||||
color:red;
|
||||
display:none;
|
||||
}
|
||||
form.option label.keymap.show {
|
||||
display:inline;
|
||||
}
|
||||
form.option input.cmd {
|
||||
color:white;
|
||||
background-color:#272822;
|
||||
padding-left:10px;
|
||||
width:600px;
|
||||
}
|
||||
form.option input.file_cmd {
|
||||
color:white;
|
||||
background-color:#272822;
|
||||
padding-left:10px;
|
||||
width:400px;
|
||||
}
|
||||
form.option input.file_name {
|
||||
width:200px;
|
||||
}
|
||||
form.option.exec input {
|
||||
color:white;
|
||||
background-color:#272822;
|
||||
padding-left:10px;
|
||||
width:600px;
|
||||
}
|
||||
|
@ -7,11 +7,11 @@ var page = Page({
|
||||
initFlashList: function(page, field, option, append, result) {
|
||||
option.dataset.flash_index = ctx.Search("flash_index")
|
||||
option.onactions = function(msg) {
|
||||
page.onFlashShow(msg, field, option, append, result)
|
||||
page.showFlashList(msg, option, append, result)
|
||||
}
|
||||
ctx.Run(page, option.dataset, [], option.onactions)
|
||||
},
|
||||
onFlashShow: function(msg, field, option, append, result) {
|
||||
showFlashList: function(msg, option, append, result) {
|
||||
var page = this
|
||||
result.innerHTML = ""
|
||||
ctx.Table(msg, function(tip) {
|
||||
@ -81,243 +81,6 @@ var page = Page({
|
||||
return {"button": ["ctx", "shy", "web", "mdb"], "action": change, "table": {"names": change}}
|
||||
},
|
||||
|
||||
getCmdList: function(input, step, cmd) {
|
||||
var history = kit.History.get("cmd")
|
||||
var length = history.length
|
||||
var last = (parseInt(input.dataset["history_last"]||length)+step+length)%length
|
||||
if (0 <= last && last < length) {
|
||||
input.dataset["history_last"] = last
|
||||
cmd = history[last].data
|
||||
}
|
||||
return cmd
|
||||
},
|
||||
showCmdResult: function(page) {
|
||||
page.conf.show_result = !page.conf.show_result
|
||||
document.querySelectorAll("body>fieldset>code.result>pre").forEach(function(result) {
|
||||
result.style.height = (page.conf.show_result || result.innerText=="")? "": page.conf.show_height
|
||||
})
|
||||
},
|
||||
showCmdList: function(msg, option, append, result) {
|
||||
append.innerHTML = ""
|
||||
kit.AppendTable(append, ctx.Table(msg), msg.append)
|
||||
result.innerHTML = ""
|
||||
result.innerText = msg.result.join("")
|
||||
return
|
||||
},
|
||||
initCmdList: function(page, field, option, append, result) {
|
||||
option.dataset["componet_name_alias"] = "cmd"
|
||||
option.dataset["componet_name_order"] = 0
|
||||
option.onactions = function(msg) {
|
||||
page.showCmdList(msg, option, append, result)
|
||||
}
|
||||
|
||||
var cmd = option.querySelector("input[name=cmd]")
|
||||
cmd.onkeyup = function(event) {
|
||||
page.onCmdList("input", cmd, option, append, result, event)
|
||||
}
|
||||
|
||||
var action = bench_data.action
|
||||
if (action && action["cmd"]) {
|
||||
cmd.value = action["cmd"].cmd[1]
|
||||
ctx.Runs(page, option)
|
||||
page.History.add("cmd", cmd.value)
|
||||
}
|
||||
|
||||
var max = 0
|
||||
for (var k in action) {
|
||||
var order = parseInt(action[k].order)
|
||||
if (order > max) {
|
||||
max = order
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 1; i <= max; i++) {
|
||||
var ui = page.addCmdList("cmd", i)
|
||||
if (action["cmd"+i]) {
|
||||
ui.cmd.value = action["cmd"+i].cmd[1]
|
||||
ctx.Runs(page, ui.option)
|
||||
page.History.add("cmd", ui.cmd.value)
|
||||
}
|
||||
}
|
||||
page.conf.ncommand = i
|
||||
return
|
||||
},
|
||||
addCmdList: function(name, order) {
|
||||
var page = this
|
||||
var alias = name+order
|
||||
var ui = kit.AppendChild(document.querySelector("body"), [{"type": "fieldset", "data": {}, "list": [
|
||||
{"text": [alias, "legend"]},
|
||||
{"view": ["option "+alias, "form", "", "option"], "data": {"dataset": {
|
||||
"componet_group": "index", "componet_name": name, "componet_name_alias": alias, "componet_name_order": order,
|
||||
}, "onactions": function(msg) {
|
||||
page.showCmdList(msg, ui.option, ui.append, ui.result)
|
||||
}}, "list": [
|
||||
{"type": "input", "data": {"style": {"display": "none"}}},
|
||||
{"name": "cmd", "type": "input", "data": {"name": "cmd", "className": "cmd", "onkeyup": function(event) {
|
||||
page.onCmdList("input", ui.cmd, ui.option, ui.append, ui.result, event)
|
||||
}}},
|
||||
]},
|
||||
{"view": ["append "+alias, "table", "", "append"]},
|
||||
{"code": ["", "result", "result "+alias]},
|
||||
]}])
|
||||
page.OrderTable(ui.append)
|
||||
page.OrderCode(ui.code)
|
||||
ui.cmd.focus()
|
||||
return ui
|
||||
},
|
||||
delCmdList: function(name, order) {
|
||||
var option = document.querySelector("form.option.cmd"+order)
|
||||
option && document.body.removeChild(option.parentElement)
|
||||
|
||||
for (;order < page.conf.ncommand; order++) {
|
||||
var input = document.querySelector("form.option.cmd"+order+" input[name=cmd]")
|
||||
if (input) {
|
||||
input.focus()
|
||||
return
|
||||
}
|
||||
}
|
||||
for (;order >= 0; order--) {
|
||||
var input = document.querySelector("form.option.cmd"+(order? order: "")+" input[name=cmd]")
|
||||
page.conf.ncommand = order+1
|
||||
if (input) {
|
||||
input.focus()
|
||||
return
|
||||
}
|
||||
}
|
||||
},
|
||||
onCmdList: function(action, target, option, append, result, event) {
|
||||
var page = this
|
||||
var order = option.dataset.componet_name_order
|
||||
var prev_order = (parseInt(order)-1+page.conf.ncommand)%page.conf.ncommand||""
|
||||
var next_order = (parseInt(order)+1)%page.conf.ncommand||""
|
||||
|
||||
switch (action) {
|
||||
case "input":
|
||||
if (event.key == "Escape") {
|
||||
target.blur()
|
||||
|
||||
} else if (event.key == "Enter") {
|
||||
target.dataset.history_last = page.History.get("cmd").length
|
||||
page.History.add("cmd", target.value)
|
||||
ctx.Runs(page, option)
|
||||
|
||||
} else if (event.ctrlKey) {
|
||||
switch (event.key) {
|
||||
case "0":
|
||||
var pre_pre = document.querySelector("code.result.cmd"+(event.shiftKey? next_order: prev_order)+" pre")
|
||||
pre_pre && (target.value += pre_pre.innerText)
|
||||
break
|
||||
case "1":
|
||||
case "2":
|
||||
case "3":
|
||||
case "4":
|
||||
case "5":
|
||||
case "6":
|
||||
case "7":
|
||||
case "8":
|
||||
case "9":
|
||||
if (code.quick_txt) {
|
||||
var item = document.querySelectorAll("div.workflow>ul>li>ul.txt>li[data-text]")
|
||||
target.value += item[parseInt(event.key)-1].dataset["text"]
|
||||
} else {
|
||||
var item = document.querySelectorAll("table.append.cmd"+(event.shiftKey? next_order: prev_order)+" td")
|
||||
target.value += item[parseInt(event.key)-1].innerText
|
||||
}
|
||||
break
|
||||
case "p":
|
||||
target.value = page.getCmdList(target, -1, target.value)
|
||||
break
|
||||
case "n":
|
||||
target.value = page.getCmdList(target, 1, target.value)
|
||||
break
|
||||
case "g":
|
||||
var value = target.value.substr(0, target.selectionStart)
|
||||
var last = parseInt(target.dataset.search_last || kit.History.get("cmd").length-1)
|
||||
for (var i = last; i >= 0; i--) {
|
||||
var cmd = kit.History.get("cmd", i).data
|
||||
if (cmd.startsWith(value)) {
|
||||
target.value = cmd
|
||||
target.dataset.search_last = i-1
|
||||
target.setSelectionRange(value.length, cmd.length)
|
||||
break
|
||||
}
|
||||
}
|
||||
target.dataset.search_last = ""
|
||||
break
|
||||
case "a":
|
||||
case "e":
|
||||
case "f":
|
||||
case "b":
|
||||
case "h":
|
||||
case "d":
|
||||
break
|
||||
case "k":
|
||||
kit.DelText(target, target.selectionStart)
|
||||
break
|
||||
case "u":
|
||||
kit.DelText(target, 0, target.selectionEnd)
|
||||
break
|
||||
case "w":
|
||||
var start = target.selectionStart-2
|
||||
var end = target.selectionEnd-1
|
||||
for (var i = start; i >= 0; i--) {
|
||||
if (target.value[end] == " " && target.value[i] != " ") {
|
||||
break
|
||||
}
|
||||
if (target.value[end] != " " && target.value[i] == " ") {
|
||||
break
|
||||
}
|
||||
}
|
||||
kit.DelText(target, i+1, end-i)
|
||||
break
|
||||
case "c":
|
||||
append.innerHTML = ""
|
||||
result.innerHTML = ""
|
||||
break
|
||||
case "r":
|
||||
append.innerHTML = ""
|
||||
result.innerHTML = ""
|
||||
case "j":
|
||||
target.dataset.history_last = page.History.get("cmd").length
|
||||
page.History.add("cmd", target.value)
|
||||
ctx.Runs(page, option)
|
||||
break
|
||||
case "l":
|
||||
window.scrollTo(0, option.parentElement.offsetTop)
|
||||
break
|
||||
case "m":
|
||||
page.addCmdList("cmd", page.conf.ncommand++)
|
||||
break
|
||||
case "i":
|
||||
var input = document.querySelector("form.option.cmd"+next_order+" input[name=cmd]")
|
||||
input && input.focus()
|
||||
break
|
||||
case "o":
|
||||
var input = document.querySelector("form.option.cmd"+prev_order+" input[name=cmd]")
|
||||
input && input.focus()
|
||||
break
|
||||
case "x":
|
||||
result.style.height = result.style.height? "": page.conf.hide_height
|
||||
break
|
||||
case "z":
|
||||
result.style.height = result.style.height? "": page.conf.show_height
|
||||
break
|
||||
case "q":
|
||||
page.delCmdList("cmd", order)
|
||||
default:
|
||||
return
|
||||
}
|
||||
} else {
|
||||
kit.History.add("key", event.key)
|
||||
if (kit.HitText(target, "jk")) {
|
||||
kit.DelText(target, target.selectionStart-2, 2)
|
||||
target.blur()
|
||||
}
|
||||
}
|
||||
event.stopPropagation()
|
||||
}
|
||||
},
|
||||
|
||||
initKitList: function(page, field, option, append, result) {
|
||||
var ui = kit.AppendChild(field, [{"type": "ul", "list": [
|
||||
{"fork": ["粘贴板", [
|
||||
@ -334,7 +97,7 @@ var page = Page({
|
||||
{"fork": ["命令行", [
|
||||
{"leaf": ["+ 折叠命令行(Ctrl+Z)", function(event, target) {
|
||||
target.className = page.conf.show_result? "": "stick"
|
||||
page.showCmdResult(page)
|
||||
page.showResult(page)
|
||||
}]},
|
||||
{"leaf": ["+ 添加命令行(Ctrl+M)", function(event) {
|
||||
page.addCmdList("cmd", page.conf.ncommand++)
|
||||
@ -507,8 +270,237 @@ var page = Page({
|
||||
})
|
||||
return
|
||||
},
|
||||
initCmdList: function(page, field, option, append, result) {
|
||||
option.dataset["componet_name_alias"] = "cmd"
|
||||
option.dataset["componet_name_order"] = 0
|
||||
option.onactions = function(msg) {
|
||||
page.showCmdList(msg, option, append, result)
|
||||
}
|
||||
|
||||
onaction: function(action, target, event) {
|
||||
var cmd = option.querySelector("input[name=cmd]")
|
||||
cmd.onkeyup = function(event) {
|
||||
page.onCmdList(event, cmd, "input", option, append, result)
|
||||
}
|
||||
|
||||
var action = conf.bench_data.action
|
||||
if (action && action["cmd"]) {
|
||||
cmd.value = action["cmd"].cmd[1]
|
||||
ctx.Runs(page, option)
|
||||
page.History.add("cmd", cmd.value)
|
||||
}
|
||||
|
||||
var max = 0
|
||||
for (var k in action) {
|
||||
var order = parseInt(action[k].order)
|
||||
if (order > max) {
|
||||
max = order
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 1; i <= max; i++) {
|
||||
var ui = page.addCmdList("cmd", i)
|
||||
if (action["cmd"+i]) {
|
||||
ui.cmd.value = action["cmd"+i].cmd[1]
|
||||
ctx.Runs(page, ui.option)
|
||||
page.History.add("cmd", ui.cmd.value)
|
||||
}
|
||||
}
|
||||
page.conf.ncommand = i
|
||||
return
|
||||
},
|
||||
showCmdList: function(msg, option, append, result) {
|
||||
append.innerHTML = ""
|
||||
msg && msg.append && kit.AppendTable(append, ctx.Table(msg), msg.append)
|
||||
result.innerText = (msg && msg.result)? msg.result.join(""): ""
|
||||
return
|
||||
},
|
||||
getCmdList: function(input, step, cmd) {
|
||||
var history = kit.History.get("cmd")
|
||||
var length = history.length
|
||||
var last = (parseInt(input.dataset["history_last"]||length)+step+length)%length
|
||||
if (0 <= last && last < length) {
|
||||
input.dataset["history_last"] = last
|
||||
cmd = history[last].data
|
||||
}
|
||||
return cmd
|
||||
},
|
||||
addCmdList: function(name, order) {
|
||||
var page = this
|
||||
var alias = name+order
|
||||
var ui = kit.AppendChild(document.querySelector("body"), [{"type": "fieldset", "data": {}, "list": [
|
||||
{"text": [alias, "legend"]},
|
||||
{"view": ["option "+alias, "form", "", "option"], "data": {"dataset": {
|
||||
"componet_group": "index", "componet_name": name, "componet_name_alias": alias, "componet_name_order": order,
|
||||
}, "onactions": function(msg) {
|
||||
page.showCmdList(msg, ui.option, ui.append, ui.result)
|
||||
}}, "list": [
|
||||
{"type": "input", "data": {"style": {"display": "none"}}},
|
||||
{"name": "cmd", "type": "input", "data": {"name": "cmd", "className": "cmd", "onkeyup": function(event) {
|
||||
page.onCmdList(event, ui.cmd, "input", ui.option, ui.append, ui.result)
|
||||
}}},
|
||||
]},
|
||||
{"view": ["append "+alias, "table", "", "append"]},
|
||||
{"code": ["", "result", "result "+alias]},
|
||||
]}])
|
||||
page.OrderTable(ui.append)
|
||||
page.OrderCode(ui.code)
|
||||
ui.cmd.focus()
|
||||
return ui
|
||||
},
|
||||
delCmdList: function(name, order) {
|
||||
var option = document.querySelector("form.option.cmd"+order)
|
||||
option && document.body.removeChild(option.parentElement)
|
||||
|
||||
for (;order < page.conf.ncommand; order++) {
|
||||
var input = document.querySelector("form.option.cmd"+order+" input[name=cmd]")
|
||||
if (input) {
|
||||
input.focus()
|
||||
return
|
||||
}
|
||||
}
|
||||
for (;order >= 0; order--) {
|
||||
var input = document.querySelector("form.option.cmd"+(order? order: "")+" input[name=cmd]")
|
||||
page.conf.ncommand = order+1
|
||||
if (input) {
|
||||
input.focus()
|
||||
return
|
||||
}
|
||||
}
|
||||
},
|
||||
onCmdList: function(event, target, action, option, append, result) {
|
||||
var page = this
|
||||
var order = option.dataset.componet_name_order
|
||||
var prev_order = (parseInt(order)-1+page.conf.ncommand)%page.conf.ncommand||""
|
||||
var next_order = (parseInt(order)+1)%page.conf.ncommand||""
|
||||
|
||||
switch (action) {
|
||||
case "input":
|
||||
if (event.key == "Escape") {
|
||||
target.blur()
|
||||
|
||||
} else if (event.key == "Enter") {
|
||||
target.dataset.history_last = page.History.get("cmd").length
|
||||
page.History.add("cmd", target.value)
|
||||
ctx.Runs(page, option)
|
||||
|
||||
} else if (event.ctrlKey) {
|
||||
switch (event.key) {
|
||||
case "0":
|
||||
var pre_pre = document.querySelector("code.result.cmd"+(event.shiftKey? next_order: prev_order)+" pre")
|
||||
pre_pre && (target.value += pre_pre.innerText)
|
||||
break
|
||||
case "1":
|
||||
case "2":
|
||||
case "3":
|
||||
case "4":
|
||||
case "5":
|
||||
case "6":
|
||||
case "7":
|
||||
case "8":
|
||||
case "9":
|
||||
if (code.quick_txt) {
|
||||
var item = document.querySelectorAll("div.workflow>ul>li>ul.txt>li[data-text]")
|
||||
target.value += item[parseInt(event.key)-1].dataset["text"]
|
||||
} else {
|
||||
var item = document.querySelectorAll("table.append.cmd"+(event.shiftKey? next_order: prev_order)+" td")
|
||||
target.value += item[parseInt(event.key)-1].innerText
|
||||
}
|
||||
break
|
||||
case "p":
|
||||
target.value = page.getCmdList(target, -1, target.value)
|
||||
break
|
||||
case "n":
|
||||
target.value = page.getCmdList(target, 1, target.value)
|
||||
break
|
||||
case "g":
|
||||
var value = target.value.substr(0, target.selectionStart)
|
||||
var last = parseInt(target.dataset.search_last || kit.History.get("cmd").length-1)
|
||||
for (var i = last; i >= 0; i--) {
|
||||
var cmd = kit.History.get("cmd", i).data
|
||||
if (cmd.startsWith(value)) {
|
||||
target.value = cmd
|
||||
target.dataset.search_last = i-1
|
||||
target.setSelectionRange(value.length, cmd.length)
|
||||
break
|
||||
}
|
||||
}
|
||||
target.dataset.search_last = ""
|
||||
break
|
||||
case "a":
|
||||
case "e":
|
||||
case "f":
|
||||
case "b":
|
||||
case "h":
|
||||
case "d":
|
||||
break
|
||||
case "k":
|
||||
kit.DelText(target, target.selectionStart)
|
||||
break
|
||||
case "u":
|
||||
kit.DelText(target, 0, target.selectionEnd)
|
||||
break
|
||||
case "w":
|
||||
var start = target.selectionStart-2
|
||||
var end = target.selectionEnd-1
|
||||
for (var i = start; i >= 0; i--) {
|
||||
if (target.value[end] == " " && target.value[i] != " ") {
|
||||
break
|
||||
}
|
||||
if (target.value[end] != " " && target.value[i] == " ") {
|
||||
break
|
||||
}
|
||||
}
|
||||
kit.DelText(target, i+1, end-i)
|
||||
break
|
||||
case "c":
|
||||
append.innerHTML = ""
|
||||
result.innerHTML = ""
|
||||
break
|
||||
case "r":
|
||||
append.innerHTML = ""
|
||||
result.innerHTML = ""
|
||||
case "j":
|
||||
target.dataset.history_last = page.History.get("cmd").length
|
||||
page.History.add("cmd", target.value)
|
||||
ctx.Runs(page, option)
|
||||
break
|
||||
case "l":
|
||||
window.scrollTo(0, option.parentElement.offsetTop)
|
||||
break
|
||||
case "m":
|
||||
page.addCmdList("cmd", page.conf.ncommand++)
|
||||
break
|
||||
case "i":
|
||||
var input = document.querySelector("form.option.cmd"+next_order+" input[name=cmd]")
|
||||
input && input.focus()
|
||||
break
|
||||
case "o":
|
||||
var input = document.querySelector("form.option.cmd"+prev_order+" input[name=cmd]")
|
||||
input && input.focus()
|
||||
break
|
||||
case "x":
|
||||
result.style.height = result.style.height? "": page.conf.hide_height
|
||||
break
|
||||
case "z":
|
||||
result.style.height = result.style.height? "": page.conf.show_height
|
||||
break
|
||||
case "q":
|
||||
page.delCmdList("cmd", order)
|
||||
default:
|
||||
return
|
||||
}
|
||||
} else {
|
||||
kit.History.add("key", event.key)
|
||||
if (kit.HitText(target, "jk")) {
|
||||
kit.DelText(target, target.selectionStart-2, 2)
|
||||
target.blur()
|
||||
}
|
||||
}
|
||||
event.stopPropagation()
|
||||
}
|
||||
},
|
||||
|
||||
onaction: function(event, target, action) {
|
||||
var page = this
|
||||
switch (action) {
|
||||
case "scroll":
|
||||
@ -569,7 +561,7 @@ var page = Page({
|
||||
page.addCmdList("cmd", page.conf.ncommand++)
|
||||
return
|
||||
case "z":
|
||||
page.showCmdResult(page)
|
||||
page.showResult(page)
|
||||
return
|
||||
case "0":
|
||||
case "1":
|
||||
@ -587,14 +579,20 @@ var page = Page({
|
||||
}
|
||||
}
|
||||
},
|
||||
showResult: function(page, type) {
|
||||
page.conf.show_result = !page.conf.show_result
|
||||
document.querySelectorAll("body>fieldset>code.result>pre").forEach(function(result) {
|
||||
result.style.height = (page.conf.show_result || result.innerText=="")? "": page.conf.show_height
|
||||
})
|
||||
},
|
||||
init: function(exp) {
|
||||
var page = this
|
||||
var body = document.body
|
||||
body.onkeydown = function(event) {
|
||||
page.onaction("scroll", body, event)
|
||||
page.onaction(event, body, "scroll")
|
||||
}
|
||||
body.onkeyup = function(event) {
|
||||
page.onaction("keymap", body, event)
|
||||
page.onaction(event, body, "keymap")
|
||||
}
|
||||
|
||||
document.querySelectorAll("body>fieldset").forEach(function(field) {
|
||||
|
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 9.4 KiB |
@ -255,6 +255,11 @@ kit = toolkit = {
|
||||
case "button":
|
||||
input.onclick = function(event) {
|
||||
if (index == array.length-1) {
|
||||
if (input.value == "login") {
|
||||
form.onactions = function(msg) {
|
||||
page.reload()
|
||||
}
|
||||
}
|
||||
page.Runs(page, form)
|
||||
return
|
||||
}
|
||||
|
@ -1,88 +1,45 @@
|
||||
{{define "head"}}
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=0.7">
|
||||
<link rel="shortcut icon" type="image/ico" href="/favicon.ico">
|
||||
<title>{{option . "componet_name"}}</title>
|
||||
<link rel="stylesheet" type="text/css" href="/static/librarys/example.css"></link>
|
||||
<link rel="stylesheet" type="text/css" href="/static/librarys/code.css"></link>
|
||||
<style>
|
||||
{{$toolkit_view := conf . "route" "toolkit_view"}}
|
||||
fieldset.KitList {
|
||||
color:#e6dd37;
|
||||
font-size:14px;
|
||||
font-family:monospace;
|
||||
background-color:#498bb1a8;
|
||||
border:solid 3px red;
|
||||
width:60px;
|
||||
height:20px;
|
||||
overflow:scroll;
|
||||
position:fixed;
|
||||
top:{{index $toolkit_view "top"}}px;
|
||||
left:{{index $toolkit_view "left"}}px;
|
||||
}
|
||||
fieldset.KitList:hover, fieldset.KitList.max {
|
||||
width:{{index $toolkit_view "width"}}px;
|
||||
height:{{index $toolkit_view "height"}}px;
|
||||
}
|
||||
fieldset.KitList div:hover, fieldset.KitList li li:hover {
|
||||
background-color:red;
|
||||
}
|
||||
fieldset.KitList div.stick, fieldset.KitList li li.stick {
|
||||
background-color:red;
|
||||
}
|
||||
fieldset.KitList li>label.result{
|
||||
background-color:rgba(0,0,0,0.2);
|
||||
padding:0 5px;
|
||||
border:2px solid green;
|
||||
margin-left: 10px;
|
||||
}
|
||||
fieldset.KitList li>input {
|
||||
background-color:rgba(0,0,0,0.2);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var session ={{option . "session"}}
|
||||
var bench_data ={{option . "bench_data"}}
|
||||
</script>
|
||||
{{end}}
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
{{range $index, $meta := option . "metas"}}
|
||||
<meta name="{{index $meta "name"}}" content="{{index $meta "content"}}">
|
||||
{{end}}
|
||||
|
||||
{{define "clipboard"}}
|
||||
<fieldset><legend>clipboard</legend>
|
||||
<datalist id="clipstack"></datalist>
|
||||
<datalist id="clistack"></datalist>
|
||||
<textarea class="clipboard"></textarea>
|
||||
</fieldset>
|
||||
<title>{{option . "componet_name"|meta}}</title>
|
||||
<link rel="shortcut icon" type="image/ico" href="/static/librarys/{{option . "favicon"|meta}}">
|
||||
{{range $index, $lib := option . "styles"}}
|
||||
<link rel="stylesheet" type="text/css" href="/static/librarys/{{$lib}}"></link>
|
||||
{{end}}
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var conf = {
|
||||
toolkit_view: {{conf . "route" "toolkit_view"}},
|
||||
bench_data: {{option . "bench_data"}},
|
||||
}
|
||||
</script>
|
||||
{{end}}
|
||||
|
||||
{{define "toolkit"}}
|
||||
{{$bench_data := option . "bench_data"}}
|
||||
<fieldset class="{{option . "componet_view"|meta}}" data-init="{{option . "componet_init"|meta}}">
|
||||
<div>{{option .Meta "name"}}({{option .Meta "help"}})</div>
|
||||
</fieldset>
|
||||
<fieldset class="{{option . "componet_view"|meta}}" data-init="{{option . "componet_init"|meta}}">
|
||||
<div>{{option .Meta "name"}}({{option .Meta "help"}})</div>
|
||||
</fieldset>
|
||||
{{end}}
|
||||
|
||||
{{define "componet"}}
|
||||
<fieldset class="{{option . "componet_view"|meta}}" data-init="{{option . "componet_init"|meta}}">
|
||||
<legend title="{{option .Meta "help"}}">{{option .Meta "name"}}({{option .Meta "help"}})</legend>
|
||||
{{$msg := .}}
|
||||
{{$form_type := option . "form_type"|meta}}
|
||||
<fieldset class="{{option . "componet_view"|meta}}" data-init="{{option . "componet_init"|meta}}">
|
||||
<legend title="{{option .Meta "help"}}">{{option .Meta "name"}}({{option .Meta "help"}})</legend>
|
||||
{{$msg := .}} {{$form_type := option . "form_type"|meta}}
|
||||
|
||||
<form class="option {{option .Meta "componet_name"}}"
|
||||
data-componet_group="{{option . "componet_group"|meta}}"
|
||||
data-componet_name="{{option . "componet_name"|meta}}"
|
||||
{{if eq $form_type "upload"}}
|
||||
method="POST" action="/upload" enctype="multipart/form-data" target="_blank"
|
||||
{{end}}>
|
||||
<form class="option {{option .Meta "componet_name"}}"
|
||||
data-componet_group="{{option . "componet_group"|meta}}"
|
||||
data-componet_name="{{option . "componet_name"|meta}}"
|
||||
{{if eq $form_type "upload"}}
|
||||
method="POST" action="/upload" enctype="multipart/form-data" target="_blank"
|
||||
{{end}}>
|
||||
|
||||
<input style="display:none"></input>
|
||||
{{range $index, $input := option . "inputs"}}
|
||||
<div>
|
||||
{{$type := index $input "type"}}
|
||||
{{$value := index $input "value" | parse $msg}}
|
||||
<input style="display:none"></input>
|
||||
{{range $index, $input := option . "inputs"}}
|
||||
<div>{{$type := index $input "type"}} {{$value := index $input "value" | parse $msg}}
|
||||
{{if index $input "label"}}
|
||||
<label>{{index $input "label"}} : </label>
|
||||
{{end}}
|
||||
@ -93,11 +50,9 @@
|
||||
<input type="submit" value="{{$value}}">
|
||||
{{else if eq $type "file"}}
|
||||
<input type="file" name="{{index $input "name"}}">
|
||||
{{else if eq $type "choice"}}
|
||||
{{$default_value := index $input "value"}}
|
||||
{{else if eq $type "choice"}} {{$default_value := index $input "value"}}
|
||||
<select name="{{index $input "name"}}">
|
||||
{{range $index, $value := index $input "choice"}}
|
||||
{{$val := index $value "value"}}
|
||||
{{range $index, $value := index $input "choice"}} {{$val := index $value "value"}}
|
||||
{{if eq $default_value $val}}
|
||||
<option value="{{index $value "value"}}" selected>{{index $value "name"}}</option>
|
||||
{{else}}
|
||||
@ -112,58 +67,55 @@
|
||||
name="{{index $input "name"}}" class="{{index $input "class"}}">{{$value}}</textarea>
|
||||
{{else}}
|
||||
<input name="{{index $input "name"}}" value="{{$value}}" class="{{index $input "class"}}">
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
<hr/>
|
||||
</form>
|
||||
{{end}}</div>
|
||||
{{end}}
|
||||
<hr/>
|
||||
</form>
|
||||
|
||||
{{if index .Meta "display_append"}} {{option .Meta "display_append"}} {{else}}
|
||||
<table class="append {{option .Meta "componet_name"}}">
|
||||
{{$msg := .}}
|
||||
<tr>{{range $field := append .}}<th>{{$field}}</th>{{end}}</tr>
|
||||
{{range $line := table .}}
|
||||
<tr>{{range $field := append $msg}}<td>{{index $line $field|unescape}}</td>{{end}}</tr>
|
||||
{{end}}
|
||||
</table>
|
||||
{{end}}
|
||||
{{if index .Meta "display_result"}} {{option .Meta "display_result"}} {{else}}
|
||||
<code class="result {{option .Meta "componet_name"}}"><pre>{{result .Meta}}</pre></code>
|
||||
{{end}}
|
||||
{{if index .Meta "display_div"}} {{option .Meta "display_div"}} {{else}}
|
||||
<div class="result {{option .Meta "componet_name"}}"></div>
|
||||
{{end}}
|
||||
</fieldset>
|
||||
{{if index .Meta "display_append"}} {{option .Meta "display_append"}} {{else}}
|
||||
<table class="append {{option .Meta "componet_name"}}"> {{$msg := .}}
|
||||
<tr>{{range $field := append .}}<th>{{$field}}</th>{{end}}</tr>
|
||||
{{range $line := table .}}
|
||||
<tr>{{range $field := append $msg}}<td>{{index $line $field|unescape}}</td>{{end}}</tr>
|
||||
{{end}}
|
||||
</table>
|
||||
{{end}}
|
||||
|
||||
{{if index .Meta "display_result"}} {{option .Meta "display_result"}} {{else}}
|
||||
<code class="result {{option .Meta "componet_name"}}"><pre>{{result .Meta}}</pre></code>
|
||||
{{end}}
|
||||
|
||||
{{if index .Meta "display_div"}} {{option .Meta "display_div"}} {{else}}
|
||||
<div class="result {{option .Meta "componet_name"}}"></div>
|
||||
{{end}}
|
||||
</fieldset>
|
||||
{{end}}
|
||||
|
||||
{{define "mp"}}
|
||||
<script src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
|
||||
<script src="/static/librarys/wexin.js"></script>
|
||||
<script>
|
||||
{{$token := cmd . "context chat js_token"}}
|
||||
wx.config({
|
||||
debug: true,
|
||||
appId: {{append $token "appid"|meta}},
|
||||
timestamp: {{append $token "timestamp"|meta}},
|
||||
nonceStr: {{append $token "nonce"|meta}},
|
||||
signature: {{append $token "signature"|meta}},
|
||||
jsApiList: [
|
||||
"scanQRCode",
|
||||
"chooseImage",
|
||||
"closeWindow",
|
||||
"openAddress",
|
||||
],
|
||||
})
|
||||
wx.ready(function(){})
|
||||
wx.error(function(res){})
|
||||
</script>
|
||||
<script src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
|
||||
<script src="/static/librarys/wexin.js"></script>
|
||||
<script>
|
||||
{{$token := cmd . "context chat js_token"}}
|
||||
wx.config({
|
||||
debug: true,
|
||||
appId: {{append $token "appid"|meta}},
|
||||
timestamp: {{append $token "timestamp"|meta}},
|
||||
nonceStr: {{append $token "nonce"|meta}},
|
||||
signature: {{append $token "signature"|meta}},
|
||||
jsApiList: [
|
||||
"scanQRCode",
|
||||
"chooseImage",
|
||||
"closeWindow",
|
||||
"openAddress",
|
||||
],
|
||||
})
|
||||
wx.ready(function(){})
|
||||
wx.error(function(res){})
|
||||
</script>
|
||||
{{end}}
|
||||
|
||||
{{define "tail"}}
|
||||
<script src="/static/librarys/toolkit.js"></script>
|
||||
<script src="/static/librarys/context.js"></script>
|
||||
<script src="/static/librarys/example.js"></script>
|
||||
<script src="/static/librarys/code.js"></script>
|
||||
</body>
|
||||
{{range $index, $lib := option . "scripts"}}
|
||||
<script src="/static/librarys/{{$lib}}"></script>
|
||||
{{end}}
|
||||
</body>
|
||||
{{end}}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user