1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-26 09:14:06 +08:00
This commit is contained in:
shaoying 2019-10-03 22:59:54 +08:00
parent d5aa37ab1a
commit 7976a90397
20 changed files with 315 additions and 244 deletions

View File

@ -736,6 +736,9 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
for cur := now; cur.Before(nature); cur = cur.AddDate(0, 1, 0) { for cur := now; cur.Before(nature); cur = cur.AddDate(0, 1, 0) {
n++ n++
} }
if now.Day() > nature.Day() {
n++
}
} }
cur := now cur := now

View File

@ -7,5 +7,5 @@ var version = struct {
self int self int
}{ }{
[]string{"2017-11-01 01:02:03", "2019-07-13 18:02:21"}, []string{"2017-11-01 01:02:03", "2019-07-13 18:02:21"},
`2019-10-01 22:57:21`, `mac`, 631, `2019-10-03 22:53:09`, `mac`, 637,
} }

View File

@ -583,14 +583,15 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
return return
} }
p := path.Join("src/plugin", m.Option("plugin"), arg[0]) file := path.Join(arg...)
p := path.Join("src/plugin", m.Option("plugin"), file)
if _, e := os.Stat(p); e == nil { if _, e := os.Stat(p); e == nil {
m.Echo(p) m.Echo(p)
return e return e
} }
m.Confm("pwd", func(index int, value string) bool { m.Confm("pwd", func(index int, value string) bool {
p := path.Join(value, arg[0]) p := path.Join(value, file)
if _, e := os.Stat(p); e == nil { if _, e := os.Stat(p); e == nil {
m.Echo(p) m.Echo(p)
return true return true

View File

@ -372,24 +372,27 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
m.Push("name", value["name"]) m.Push("name", value["name"])
m.Push("help", value["help"]) m.Push("help", value["help"])
if kit.Right(value["init"]) { m.Push("init", value["init"])
script := m.Cmdx("nfs.load", path.Join(m.Conf("cli.project", "plugin.path"), arg[0], kit.Format(value["init"])), -1) m.Push("view", value["view"])
if script == "" {
script = m.Cmdx("nfs.load", path.Join("usr/librarys/plugin", kit.Format(value["init"])), -1) // if kit.Right(value["init"]) {
} // script := m.Cmdx("nfs.load", path.Join(m.Conf("cli.project", "plugin.path"), arg[0], kit.Format(value["init"])), -1)
m.Push("init", script) // if script == "" {
} else { // script = m.Cmdx("nfs.load", path.Join("usr/librarys/plugin", kit.Format(value["init"])), -1)
m.Push("init", "") // }
} // m.Push("init", script)
if kit.Right(value["view"]) { // } else {
script := m.Cmdx("nfs.load", path.Join(m.Conf("cli.project", "plugin.path"), arg[0], kit.Format(value["view"])), -1) // m.Push("init", "")
if script == "" { // }
script = m.Cmdx("nfs.load", path.Join("usr/librarys/plugin", kit.Format(value["view"])), -1) // if kit.Right(value["view"]) {
} // script := m.Cmdx("nfs.load", path.Join(m.Conf("cli.project", "plugin.path"), arg[0], kit.Format(value["view"])), -1)
m.Push("view", script) // if script == "" {
} else { // script = m.Cmdx("nfs.load", path.Join("usr/librarys/plugin", kit.Format(value["view"])), -1)
m.Push("view", "") // }
} // m.Push("view", script)
// } else {
// m.Push("view", "")
// }
m.Push("inputs", kit.Format(value["inputs"])) m.Push("inputs", kit.Format(value["inputs"]))
m.Push("feature", kit.Format(value["feature"])) m.Push("feature", kit.Format(value["feature"]))
m.Push("exports", kit.Format(value["exports"])) m.Push("exports", kit.Format(value["exports"]))

View File

@ -875,6 +875,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
tmpl.ParseGlob(path.Join(m.Conf("route", "template_dir"), m.Cap("route"), "/*.tmpl")) tmpl.ParseGlob(path.Join(m.Conf("route", "template_dir"), m.Cap("route"), "/*.tmpl"))
} }
m.Option("title", m.Conf("runtime", "boot.hostname"))
// 响应数据 // 响应数据
group, order := m.Option("group", kit.Select(m.Conf("route", "componet_index"), m.Option("group"))), m.Option("names") group, order := m.Option("group", kit.Select(m.Conf("route", "componet_index"), m.Option("group"))), m.Option("names")
list := []interface{}{} list := []interface{}{}
@ -1046,6 +1047,18 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
} }
return return
}}, }},
"/require/": &ctx.Command{Name: "/require/", Help: "加载脚本", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
r := m.Optionv("request").(*http.Request)
w := m.Optionv("response").(http.ResponseWriter)
file := strings.TrimPrefix(key, "/require/")
if p := m.Cmdx("nfs.path", m.Conf("cli.project", "plugin.path"), file); p != "" {
m.Log("info", "download %s direct", p)
http.ServeFile(w, r, p)
return
}
return
}},
"/proxy/": &ctx.Command{Name: "/proxy/which/method/url", Help: "服务代理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { "/proxy/": &ctx.Command{Name: "/proxy/which/method/url", Help: "服务代理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
fields := strings.Split(key, "/") fields := strings.Split(key, "/")
m.Cmdy("web.get", "which", fields[2], "method", fields[3], strings.Join(fields, "/")) m.Cmdy("web.get", "which", fields[2], "method", fields[3], strings.Join(fields, "/"))

View File

@ -31,7 +31,7 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
"login": &ctx.Config{Name: "login", Value: map[string]interface{}{"check": false, "local": true, "expire": "720h"}, Help: "默认组件"}, "login": &ctx.Config{Name: "login", Value: map[string]interface{}{"check": false, "local": true, "expire": "720h"}, Help: "默认组件"},
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{ "componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
"index": []interface{}{ "index": []interface{}{
map[string]interface{}{"name": "chat", map[string]interface{}{"name": "head",
"tmpl": "head", "metas": []interface{}{map[string]interface{}{ "tmpl": "head", "metas": []interface{}{map[string]interface{}{
"name": "viewport", "content": "width=device-width, initial-scale=0.7, user-scalable=no", "name": "viewport", "content": "width=device-width, initial-scale=0.7, user-scalable=no",
}}, "favicon": "favicon.ico", "styles": []interface{}{ }}, "favicon": "favicon.ico", "styles": []interface{}{

View File

@ -1,4 +1,5 @@
{init: function(page, pane, field, option, output) { Script["context/index.js"] = function(field, option, output) {
kit.Log("hello world") return {
}} }
}

View File

@ -53,7 +53,6 @@ kit dir "目录" private "ssh._route" _ "nfs.dir" _ time size line path \
text "usr/script" name dir imports plugin_dir action auto view long \ text "usr/script" name dir imports plugin_dir action auto view long \
button "浏览" action auto \ button "浏览" action auto \
button "返回" cb Last \ button "返回" cb Last \
feature display "editor" \
exports dir "" dir exports dir "" dir
kit git "版本" private "ssh._route" _ "nfs.git" __ \ kit git "版本" private "ssh._route" _ "nfs.git" __ \

View File

@ -1,7 +1,7 @@
{init: function(run, field, option, output) { {init: function(field, option, output) {
return { return {
Run: function(event, args, cb) { share: function() {var plugin = field.Plugin
run(event, ["share", args[0]], function(msg) { plugin.Run(event, ["share", args[0]], function(msg) {
kit.AppendChilds(output, [{img: [msg.result.join("")]}]) kit.AppendChilds(output, [{img: [msg.result.join("")]}])
typeof cb == "function" && cb({}) typeof cb == "function" && cb({})
}) })

View File

@ -1,4 +1,4 @@
{init: function(run, field, option, output) { {init: function(field, option, output) {
return { return {
Record: function() { Record: function() {
if (confirm("run script "+option.mac.value)) { if (confirm("run script "+option.mac.value)) {

View File

@ -1,20 +1,19 @@
{init: function(run, field, option, output) { Script["love/index.js"] = function(field, option, output) {return {
return {
data: function(event) {var plugin = field.Plugin data: function(event) {var plugin = field.Plugin
run(event, [option.table.value], function(msg) { plugin.Run(event, [option.table.value], function(msg) {
plugin.msg = msg, plugin.display("table") plugin.ondaemon(msg)
}) })
}, },
show: function(event) {var plugin = field.Plugin show: function(event) {var plugin = field.Plugin
plugin.Check(undefined, function(msg) { plugin.Check(undefined, function(msg) {
run(event, [option.table.value], function(msg) { plugin.Run(event, [option.table.value], function(msg) {
kit.List(ctx.Table(msg), function(line) { kit.List(ctx.Table(msg), function(line) {
kit.Selector(output, ".s"+line.when.split(" ")[0].split("-").join(""), function(item) { kit.Selector(output, ".s"+line.when.split(" ")[0].split("-").join(""), function(item) {
kit.classList.add(item.parentNode, "select") kit.classList.add(item.parentNode, "select")
item.parentNode.title = line.what item.parentNode.title = line.what
}) })
}, 200) }, 200)
}) }, true)
}) })
}, },
show_after: function(msg) { show_after: function(msg) {
@ -37,7 +36,7 @@ return {
break break
case "detail": case "detail":
plugin.Change(event.target, function(value) { plugin.Change(event.target, function(value) {
run(event, ["update", option.table.value, option.index.value, line.key, value], function(msg) { plugin.Run(event, ["update", option.table.value, option.index.value, line.key, value], function(msg) {
kit.Log("ok") kit.Log("ok")
}) })
}) })
@ -75,4 +74,4 @@ return {
}) })
}) })
}, },
}}} }}

View File

@ -1,4 +1,4 @@
{init: function(run, field, option, output) { Script["love/maps.js"] = function(field, option, output) {
var id var id
return { return {
initMap: function() {var plugin = field.Plugin initMap: function() {var plugin = field.Plugin
@ -37,13 +37,13 @@ return {
return parseInt(value*len)/parseFloat(len) return parseInt(value*len)/parseFloat(len)
} }
var l = map.getCenter() var l = map.getCenter()
run(event, [option.table.value, option.when.value, option.what.value, option.city.value, option.where.value, plugin.Run(event, [option.table.value, option.when.value, option.what.value, option.city.value, option.where.value,
"longitude", trunc(l.lng), "latitude", trunc(l.lat), "scale", map.getZoom()], function(msg) { "longitude", trunc(l.lng), "latitude", trunc(l.lat), "scale", map.getZoom()], function(msg) {
plugin.msg = msg, plugin.display("table") plugin.msg = msg, plugin.display("table")
}) })
}, },
Flashs: function() {var plugin = field.Plugin Flashs: function() {var plugin = field.Plugin
plugin.initMap(), run(event, [option.table.value], function(msg) { plugin.initMap(), plugin.Run(event, [option.table.value], function(msg) {
kit.List(ctx.Table(msg), plugin.place, 1000) kit.List(ctx.Table(msg), plugin.place, 1000)
}) })
}, },
@ -61,5 +61,5 @@ return {
plugin.initMap(), plugin.place(line) plugin.initMap(), plugin.place(line)
return line.id return line.id
}}, }},
}}} }}

View File

@ -1,5 +1,4 @@
{init: function(run, field, option, output) { Script["love/pics.js"] = function(field, option, output) {return {
return {
onexport: {"": function(value, name, line) {var plugin = field.Plugin onexport: {"": function(value, name, line) {var plugin = field.Plugin
kit.AppendChilds(output, [{img: ["/download/"+line.hash], data: {width: output.clientWidth, onclick: function() { kit.AppendChilds(output, [{img: ["/download/"+line.hash], data: {width: output.clientWidth, onclick: function() {
plugin.display("table") plugin.display("table")
@ -26,5 +25,5 @@ return {
}) })
}, },
}}} }}

View File

@ -1,4 +1,4 @@
{init: function(run, field, option, output) {return { {init: function(field, option, output) {return {
ondaemon: { ondaemon: {
table: function(msg, cb) {if (msg.event && msg.event.type == "blur") {return} table: function(msg, cb) {if (msg.event && msg.event.type == "blur") {return}
var plugin = field.Plugin var plugin = field.Plugin

View File

@ -1,4 +1,4 @@
{init: function(run, field, option, output) { {init: function(field, option, output) {
kit.Log("hello world") kit.Log("hello world")
return {} return {}
}} }}

View File

@ -251,7 +251,7 @@ ctx = context = {__proto__: kit,
try { try {
var res = JSON.parse(xhr.responseText||'[{"result":[]}]') var res = JSON.parse(xhr.responseText||'[{"result":[]}]')
res = res[0] && res[0] res.length > 0 && res[0] && (res = res[0])
} catch (e) { } catch (e) {
var res = {"result": [xhr.responseText]} var res = {"result": [xhr.responseText]}
} }
@ -261,13 +261,13 @@ ctx = context = {__proto__: kit,
res[item] && (msg[item] = res[item]) res[item] && (msg[item] = res[item])
}) })
// if (msg.download_file) { if (msg.download_file) {
// window.open(msg.download_file.join("")) window.open(msg.download_file.join(""))
// } else if (msg.page_redirect) { } else if (msg.page_redirect) {
// location.href = msg.page_redirect.join("") location.href = msg.page_redirect.join("")
// } else if (msg.page_refresh) { } else if (msg.page_refresh) {
// location.reload() location.reload()
// } }
typeof cb == "function" && cb(msg || {}) typeof cb == "function" && cb(msg || {})
} }

View File

@ -99,7 +99,7 @@ fieldset>div.output table td {
/* word-break:break-word; */ /* word-break:break-word; */
} }
fieldset>div.output table td.when { fieldset>div.output table td.when {
word-break:break-word; /* word-break:break-word; */
text-align:center; text-align:center;
} }
fieldset>div.output table.edit { fieldset>div.output table.edit {
@ -251,6 +251,8 @@ fieldset.item.select {
border:solid 2px red; border:solid 2px red;
} }
fieldset.item>div.output { fieldset.item>div.output {
margin-top:2px;
border-top:solid 2px gray;
overflow:auto; overflow:auto;
} }
fieldset.item>div.output>canvas { fieldset.item>div.output>canvas {

View File

@ -1,3 +1,4 @@
Script = {}
function Meta(target, obj) { function Meta(target, obj) {
var a = obj var a = obj
for (var i = 2; i < arguments.length; i++) { for (var i = 2; i < arguments.length; i++) {
@ -7,10 +8,8 @@ function Meta(target, obj) {
var id = 1 var id = 1
var conf = {}, conf_cb = {} var conf = {}, conf_cb = {}
var sync = {} var sync = {}
var cache = [] var cache = {}
return { return {__proto__: obj, target: target,
__proto__: obj,
target: target,
ID: function() {return id++}, ID: function() {return id++},
Conf: function(key, value, cb) { Conf: function(key, value, cb) {
if (key == undefined) {return conf} if (key == undefined) {return conf}
@ -33,7 +32,7 @@ function Meta(target, obj) {
get: function() {return data}, get: function() {return data},
set: function(value, force) { set: function(value, force) {
if (value == undefined) {return} if (value == undefined) {return}
if (value == data && !force) {return value} if (value == data && !force) {return}
old_value = data, data = value old_value = data, data = value
meta && kit.Log("key", meta, value, old_value) meta && kit.Log("key", meta, value, old_value)
@ -82,7 +81,6 @@ function Meta(target, obj) {
{text: [text.name+"("+text.help+")", "legend"]}, {text: [text.name+"("+text.help+")", "legend"]},
{view: ["option", "form", "", "option"], list: [{type: "input", style: {"display": "none"}}]}, {view: ["option", "form", "", "option"], list: [{type: "input", style: {"display": "none"}}]},
{view: ["output", "div", "", "output"]}, {view: ["output", "div", "", "output"]},
text.view?{styles: text.view}:null, text.init?{script: ""+id+".Script = "+text.init}:null,
]}) ]})
break break
} }
@ -98,6 +96,8 @@ function Meta(target, obj) {
return ui return ui
}, },
Save: function(name, output) { Save: function(name, output) {
if (name === "") {return cache = {}}
var temp = document.createDocumentFragment() var temp = document.createDocumentFragment()
while (output.childNodes.length>0) { while (output.childNodes.length>0) {
var item = output.childNodes[0] var item = output.childNodes[0]
@ -124,11 +124,27 @@ function Meta(target, obj) {
src.length == 1? cb(event): page.Include(src.slice(1), cb) src.length == 1? cb(event): page.Include(src.slice(1), cb)
}]}]) }]}])
}, },
Require: function(file, cb) {
if (!file || Script[file]) {return kit._call(cb, [Script[file]])}
file.endsWith(".css")? kit.AppendChild(document.body, [{require: ["/require/"+file, function(event) {
return Script[file] = file, kit._call(cb, [Script[file]])
}]}]): kit.AppendChild(document.body, [{data: {what: id++}, include: ["/require/"+file, function(event) {
return kit._call(cb, [Script[file]])
}]}])
},
History: shy("操作历史", {}, [], function(value, target) {
var list = arguments.callee.list, item
return value == undefined? (item = list.pop()) && (item.target.value = item.value):
list.push({value: value, target: target})
}),
} }
} }
function Page(page) { function Page(page) {
var script = {}, record = "" var script = {}, record = ""
var carte = document.querySelector("fieldset.carte") var carte = document.querySelector("fieldset.carte")
carte.onmouseleave = function(event) {
kit.ModifyView(carte, {display: "none"})
}
page = Meta(document.body, page, {__proto__: ctx, page = Meta(document.body, page, {__proto__: ctx,
onload: function() { onload: function() {
// Event入口 0 // Event入口 0
@ -564,13 +580,18 @@ function Pane(page, field) {
var index = list.length, ui = pane.View(output, type, line, key, function(event, cmds, cbs) { var index = list.length, ui = pane.View(output, type, line, key, function(event, cmds, cbs) {
(type != "plugin" && type != "field") && pane.Select(index, line[which]) (type != "plugin" && type != "field") && pane.Select(index, line[which])
page.script("record", [name, line[key[0]]]) page.script("record", [name, line[key[0]]])
typeof cb == "function" && cb(line, index, event, cmds, cbs) kit._call(cb, [line, index, event, cmds, cbs])
}) })
list.push(ui.last), field.scrollBy(0, field.scrollHeight+100) list.push(ui.last), field.scrollBy(0, field.scrollHeight+100)
key && key.length > 0 && (member[line[which]] = member[line[key[0]]] = {index:index, key:line[which]}); key && key.length > 0 && (member[line[which]] = member[line[key[0]]] = {index:index, key:line[which]});
(type == "plugin" && line.name || type == "field") && pane.Plugin(page, pane, ui.field, function(event, cmds, cbs) {
typeof cb == "function" && cb(line, index, event, cmds, cbs) (type == "plugin" && line.name || type == "field") && page.Require(line.init? line.group+"/"+line.init: "", function(init) {
page.Require(line.view? line.group+"/"+line.view: "", function(view) {
pane.Plugin(page, pane, ui.field, init, function(event, cmds, cbs) {
kit._call(cb, [line, index, event, cmds, cbs])
})
})
}) })
return ui return ui
}, },
@ -583,7 +604,7 @@ function Pane(page, field) {
first && index == 0 && ui.first.click() first && index == 0 && ui.first.click()
} }
if (index == msg[msg.append[0]].length-1) { if (index == msg[msg.append[0]].length-1) {
typeof cbs == "function" && cbs(msg) kit._call(cbs, [msg])
} }
}) })
}, },
@ -725,7 +746,7 @@ function Pane(page, field) {
kit.Log("init", "pane", name, pane) kit.Log("init", "pane", name, pane)
return page[name] = field, pane.Field = field, field.Pane = pane return page[name] = field, pane.Field = field, field.Pane = pane
} }
function Plugin(page, pane, field, runs) { function Plugin(page, pane, field, inits, runs) {
var option = field.querySelector("form.option") var option = field.querySelector("form.option")
var action = field.querySelector("div.action") var action = field.querySelector("div.action")
var output = field.querySelector("div.output") var output = field.querySelector("div.output")
@ -736,17 +757,11 @@ function Plugin(page, pane, field, runs) {
var inputs = JSON.parse(meta.inputs || "[]") var inputs = JSON.parse(meta.inputs || "[]")
var feature = JSON.parse(meta.feature||'{}') var feature = JSON.parse(meta.feature||'{}')
var display = JSON.parse(meta.display||'{}') var display = JSON.parse(meta.display||'{}')
var exports = JSON.parse(meta.exports||'["",""]')
var deal = (feature && feature.display) || "table" var deal = (feature && feature.display) || "table"
kit.classList.add(field, meta.group, name, feature.style) kit.classList.add(field, meta.group, name, feature.style)
var history = [] var plugin = Meta(field, (inits || function() {
var run = function(event, cmds, cbs) { })(field, option, output)||{}, {Inputs: {},
ctx.Event(event, null, {name: name, Plugin: plugin})
runs(event, cmds, cbs)
}
var plugin = Meta(field, (field.Script && field.Script.init || function() {
})(run, field, option, output)||{}, {Inputs: {},
Appends: function() { Appends: function() {
var name = "args"+kit.Selector(option, "input.args.temp").length var name = "args"+kit.Selector(option, "input.args.temp").length
plugin.Append({type: "text", name: name, className: "args temp"}).focus() plugin.Append({type: "text", name: name, className: "args temp"}).focus()
@ -765,20 +780,10 @@ function Plugin(page, pane, field, runs) {
}}]).last.focus() }}]).last.focus()
}, },
Append: shy("添加控件", function(item, name, value) { Append: shy("添加控件", function(item, name, value) {
kit.Item(plugin.onaction, function(k, cb) {
item[k] == undefined && (item[k] = typeof cb == "function"? function(event) {
cb(event, action, item.type, input.name, item)
}: cb)
});
item.value = plugin.onformat(item.init)(item.value)||""
!item.title && item.name && (item.title = item.name)
!item.placeholder && item.title && (item.placeholder = item.title)
var input = {type: "input", name: name || item.name || "input", data: item} var input = {type: "input", name: name || item.name || "input", data: item}
switch (item.type) { switch (item.type) {
case "button": case "button":
input.name = item.name || item.value || name input.name = name || item.name || item.value
break break
case "upfile": case "upfile":
item.type = "file" item.type = "file"
@ -788,7 +793,7 @@ function Plugin(page, pane, field, runs) {
input.type = "select", input.list = item.values.map(function(value) { input.type = "select", input.list = item.values.map(function(value) {
return {type: "option", value: value, inner: value} return {type: "option", value: value, inner: value}
}) })
input.value = item.value input.value = item.value || item.values[0]
break break
case "textarea": case "textarea":
kit.classList.add(item, "args") kit.classList.add(item, "args")
@ -802,21 +807,8 @@ function Plugin(page, pane, field, runs) {
args && count < args.length && (item.value = value||args[count++]||item.value||""); args && count < args.length && (item.value = value||args[count++]||item.value||"");
break break
} }
item.plug = meta.name, item.name = input.name
var ui = kit.AppendChild(option, [{view: [item.view||""], list: [{type: "label", inner: item.label||""}, input]}]) return Inputs(plugin, item, kit.AppendChild(option, [{view: [item.view||""], list: [{type: "label", inner: item.label||""}, input]}])[input.name]).target
var action = Meta(ui[input.name] || {}, item, plugin);
(typeof item.imports == "object"? item.imports: typeof item.imports == "string"? [item.imports]: []).forEach(function(imports) {
page.Sync(imports).change(function(value) {
history.push({target: action.target, value: action.target.value});
(action.target.value = value) && item.action == "auto" && plugin.Runs(document.createEvent("Event"))
})
})
item.type == "button" && item.action == "auto" && action.target.click()
item.which = plugin.Sync(input.name)
plugin.Inputs[input.name] = ui[input.name]
return action.target
}), }),
Remove: function() { Remove: function() {
var list = option.querySelectorAll("input.temp") var list = option.querySelectorAll("input.temp")
@ -826,11 +818,14 @@ function Plugin(page, pane, field, runs) {
field.previousSibling.Plugin.Select() field.previousSibling.Plugin.Select()
field.parentNode.removeChild(field) field.parentNode.removeChild(field)
}, },
Select: function(silent) { Select: function(target) {
page.plugin && (kit.classList.del(page.plugin, "select")) page.plugin && (kit.classList.del(page.plugin, "select"))
page.plugin = field, kit.classList.add(field, "select") page.plugin = field, kit.classList.add(field, "select")
!silent && (option.querySelectorAll("input")[1].focus()) pane.which.set(name)
name && pane.which.set(name)
page.input = target || option.querySelectorAll("input")[1]
plugin.which.set(page.input.name)
page.input.focus()
}, },
Reveal: function(msg) { Reveal: function(msg) {
return msg.append && msg.append[0]? ["table", JSON.stringify(ctx.Tables(msg))]: ["code", msg.result? msg.result.join(""): ""] return msg.append && msg.append[0]? ["table", JSON.stringify(ctx.Tables(msg))]: ["code", msg.result? msg.result.join(""): ""]
@ -842,7 +837,7 @@ function Plugin(page, pane, field, runs) {
}, },
Clone: function() { Clone: function() {
return pane.Append("field", {text: plugin.Format()}, [], "", function(line, index, event, cmds, cbs) { return pane.Append("field", {text: plugin.Format()}, [], "", function(line, index, event, cmds, cbs) {
run(event, cmds, cbs) plugin.Run(event, cmds, cbs, true)
}).field.Plugin }).field.Plugin
}, },
@ -850,14 +845,13 @@ function Plugin(page, pane, field, runs) {
var x = parseFloat(option.x.value) var x = parseFloat(option.x.value)
var y = parseFloat(option.y.value) var y = parseFloat(option.y.value)
page.getLocation && page.getLocation(function(res) { page.getLocation && page.getLocation(function(res) {
plugin.msg = { plugin.ondaemon({
append: ["longitude", "latitude", "accuracy", "speed"], append: ["longitude", "latitude", "accuracy", "speed"],
longitude: [res.longitude+x+""], longitude: [res.longitude+x+""],
latitude: [res.latitude+y+""], latitude: [res.latitude+y+""],
accuracy: [res.accuracy+""], accuracy: [res.accuracy+""],
speed: [res.speed+""], speed: [res.speed+""],
} })
plugin.display("table")
}) })
}, },
openLocation: function(event) { openLocation: function(event) {
@ -914,7 +908,7 @@ function Plugin(page, pane, field, runs) {
return option[key]? option[key].value: "" return option[key]? option[key].value: ""
}, },
Check: function(target, cb) { Check: function(target, cb) {
plugin.Select(true), kit.Selector(option, ".args", function(item, index, list) { kit.Selector(option, ".args", function(item, index, list) {
target == undefined && index == list.length-1 && plugin.Runs(window.event, cb) target == undefined && index == list.length-1 && plugin.Runs(window.event, cb)
item == target && (index == list.length-1? plugin.Runs(window.event, cb): page.plugin == field && list[index+1].focus()) item == target && (index == list.length-1? plugin.Runs(window.event, cb): page.plugin == field && list[index+1].focus())
return item return item
@ -927,33 +921,26 @@ function Plugin(page, pane, field, runs) {
}, time) }, time)
}, },
Last: function() { Last: function() {
var list = history.pop() plugin.History() != undefined && plugin.Check()
list? (list.target.value = list.value): inputs.map(function(item) {
option[item.name].value = item.value
}), plugin.Check()
}, },
Runs: function(event, cb) { Runs: function(event, cb) {
plugin.Run(event, kit.Selector(option, ".args", function(item, index) {return item.value}), cb) plugin.Run(event, kit.Selector(option, ".args", function(item, index) {return item.value}), cb)
}, },
Run: function(event, args, cb) { Run: function(event, args, cb, silent) {
page.script("record", ["action", name].concat(args)) page.script("record", ["action", name].concat(args))
var show = true var show = true
setTimeout(function() { setTimeout(function() {
show && page.ontoast(kit.Format(args||["running..."]), meta.name, -1) show && page.ontoast(kit.Format(args||["running..."]), meta.name, -1)
}, 1000) }, 1000)
event.Plugin = plugin, run(event, args, function(msg) { event.Plugin = plugin, runs(event, args, function(msg) {
page.footer.Pane.State("ncmd", kit.History.get("cmd").length) page.footer.Pane.State("ncmd", kit.History.get("cmd").length)
plugin.msg = msg, plugin.display(deal, cb) silent? kit._call(cb, [msg]): plugin.ondaemon(msg, cb)
show = false, page.ontoast("") show = false, page.ontoast("")
}) })
}, },
clear: function() { clear: function() {
output.innerHTML = "" output.innerHTML = ""
}, },
display: function(arg, cb) {
plugin.ondaemon[(deal = arg)||"table"](plugin.msg, cb), plugin.show_after(plugin.msg)
},
show_after: function(msg) {},
Download: function() { Download: function() {
var text = kit.Selector(output, "tr", function(tr) { var text = kit.Selector(output, "tr", function(tr) {
return kit.Selector(tr, "td,th", function(td) { return kit.Selector(tr, "td,th", function(td) {
@ -976,108 +963,85 @@ function Plugin(page, pane, field, runs) {
}) })
}, },
exports: JSON.parse(meta.exports||'["",""]'),
ontoast: page.ontoast, ontoast: page.ontoast,
onreveal: shy("数据菜单", { onformat: shy("数据转换", {
"下载": "Download", none: function(value) {return value||""},
"清空": "clear", date: function(value) {return kit.format_date(new Date())},
"返回": "Last", }, function(which, value) {var meta = arguments.callee.meta
}, ["下载", "清空", "返回"], function(value, meta, event) { return (meta[which||"none"]||meta["none"])(value)
}),
ondaemon: shy("接收数据", function(msg, cb) {
plugin.msg = msg, plugin.Save(""), plugin.onfigure.meta.type = "", plugin.onfigure(deal, msg, cb)
}),
onfigure: shy("显示数据", {type: "",
max: function(output) {
output.style.maxWidth = pane.target.clientWidth-30+"px"
output.style.maxHeight = pane.target.clientHeight-60+"px"
},
}, function(type, msg, cb) {var meta = arguments.callee.meta
meta.type && plugin.Save(meta.type, output), meta.type = type
!plugin.Back(type, output) && Output(plugin, type, msg, cb, output, option)
}),
onchoice: shy("菜单列表", {
"添加": "Clone",
"删除": "Delete",
"加参": "Appends",
"减参": "Remove",
}, ["添加", "删除", "加参", "减参"], function(value, meta, event) {
kit._call(plugin, plugin[meta[value]]) kit._call(plugin, plugin[meta[value]])
return true return true
}), }),
onformat: Wrap(function(which) { onaction: shy("事件列表", {
var meta = arguments.callee oncontextmenu: function(event) {
return meta[which]||meta["none"] page.oncarte(event, plugin.onchoice)
}, { },
none: function(value) {return value}, }, function() {
date: function(value) {return kit.format_date(new Date())}, kit.Item(arguments.callee.meta, function(k, cb) {field[k] = function(event) {
cb(event)
}})
}), }),
onexport: { })
"": function(value, name, line) {
return value
},
see: function(value, name, line) {
return value.split("/")[0]
},
you: function(value, name, line) {
var event = window.event
event.Plugin = plugin
line.you && name == "status" && (line.status == "start"? function() { plugin.onaction()
plugin.Delay(3000, event, line.you+" stop...") && field.Run(event, [option.pod.value, line.you, "stop"]) plugin.which = plugin.Sync("input")
}(): field.Run(event, [option.pod.value, line.you], function(msg) { page[field.id] = pane[field.id] = pane[name] = field, field.Plugin = plugin
plugin.Delay(3000, event, line.you+" start...") inputs.map(function(item) {plugin.Append(item)})
})) kit.Log("init", "plugin", name, plugin)
return name == "status" || line.status == "stop" ? undefined: line.you return plugin
}
function Inputs(plugin, item, target) {
var plug = item.plug, name = item.name, type = item.type
var input = Meta(target, item, {
onimport: shy("导入数据", {}, [item.imports], function() {
kit.List(arguments.callee.list, function(imports) {
page.Sync(imports).change(function(value) {
plugin.History(target.value, target), target.value = value
item.action == "auto" && plugin.Runs(document.createEvent("Event"))
})
}), item.type == "button" && item.action == "auto" && target.click()
}),
onaction: shy("事件列表", {
onfocus: function(event) {plugin.Select(target)},
onblur: function(event) {input.which.set(target.value)},
onclick: function(event) {
// Event入口 2.0
type == "button" && input.Event(event) && kit.Value(input[item.cb], plugin[item.cb], function() {
plugin.Check()
})(event, input)
}, },
pod: function(value, name, line) { onchange: function(event) {
return (option[exports[0]].value? option[exports[0]].value+".": "")+line.pod // Event入口 2.1
type == "select" && ctx.Event(event) && plugin.Check(item.action == "auto"? undefined: target)
}, },
dir: function(value, name, line) { ondblclick: function(event) {
name != "path" && (value = line.path) var txt = kit.History.get("txt", -1)
return value type == "text" && txt && (target.value = txt.data.trim())
}, },
tip: function(value, name, line) { oncontextmenu: function(event) {
return option.tip.value + value
},
},
ondaemon: {
inner: function(msg, cb) {
output.style.maxWidth = pane.target.clientWidth-20+"px"
output.style.maxHeight = pane.target.clientHeight-60+"px"
output.innerHTML = "", msg.append? kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), exports[1]||"", function(event, value, name, line) {
page.Sync("plugin_"+exports[0]).set(plugin.onexport[exports[2]||""](value, name, line))
}): (output.innerHTML = msg.result.join(""))
typeof cb == "function" && cb(msg)
},
table: function(msg, cb) {
output.innerHTML = ""
!display.hide_append && msg.append && kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), exports[1]||"", function(event, value, name, line) {
page.Sync("plugin_"+exports[0]).set(plugin.onexport[exports[2]||""](value, name, line))
});
(display.show_result || !msg.append) && msg.result && kit.OrderCode(kit.AppendChild(output, [{view: ["code", "div", msg.Results()]}]).first)
typeof cb == "function" && cb(msg)
},
editor: function(msg, cb) {
(output.innerHTML = "", Editor(run, plugin, option, output, output.clientWidth-40, 400, 10, msg))
},
canvas: function(msg, cb) {
typeof cb == "function" && !cb(msg) || (output.innerHTML = "", Canvas(plugin, option, output, pane.target.clientWidth-45, pane.target.clientHeight-175, 10, msg))
},
},
onaction: {
onfocus: function(event, action, type, name, item) {
plugin.Select(true)
page.input = event.target, plugin.which.set(name)
},
onblur: function(event, action, type, name, item) {
item.which.set(action.target.value)
},
onclick: function(event, action, type, name, item) {
switch (type) {
case "button":
// Event入口 2.0
ctx.Event(event, {}, {name: meta.name+"."+name})
kit.Value(action[item.cb], plugin[item.cb], function() {
plugin.Check()
})(event, item, option, field)
break
case "text":
event.ctrlKey && (action.target.value = kit.History.get("txt", -1).data.trim())
break
}
},
ondblclick: function(event, action, type, name, item) {
type == "text" && (action.target.value = kit.History.get("txt", -1).data.trim())
},
oncontextmenu: function(event, action, type, name, item) {
type == "text" && event.stopPropagation() type == "text" && event.stopPropagation()
}, },
onchange: function(event, action, type, name, item) { onkeydown: function(event) {
type == "select" && ctx.Event(event, {}, {name: meta.name+"."+name}) && plugin.Check(item.action == "auto"? undefined: action)
},
onkeydown: function(event, action, type, name, item) {
switch (event.key) { switch (event.key) {
case " ": case " ":
event.stopPropagation() event.stopPropagation()
@ -1101,15 +1065,15 @@ function Plugin(page, pane, field, runs) {
prev && prev.Plugin.Select() prev && prev.Plugin.Select()
break break
case "c": case "c":
output.innerHTML = "" plugin.clear()
break break
case "r": case "r":
output.innerHTML = "" plugin.clear()
case "j": case "j":
plugin.Runs(event) plugin.Runs(event)
break break
case "l": case "l":
page.action.scrollTo(0, field.offsetTop) target.scrollTo(0, plugin.target.offsetTop)
break break
case "b": case "b":
plugin.Appends() plugin.Appends()
@ -1122,15 +1086,14 @@ function Plugin(page, pane, field, runs) {
} }
return true return true
}) })
if (item.type != "textarea" && event.key == "Enter") {
if (event.key == "Enter" && (event.ctrlKey || item.type == "text")) {
// Event入口 2.1 // Event入口 2.1
ctx.Event(event, {}, {name: meta.name+"."+name, pane: pane, plugin: plugin, input: item}) input.which.set(target.value) != undefined && plugin.History(target.value, target)
item.which.set(action.target.value) input.Event(event) && plugin.Check(target)
history.push({target: action.target, value: action.target.value});
plugin.Check(action.target)
} }
}, },
onkeyup: function(event, action, type, name, item) { onkeyup: function(event) {
switch (event.key) { switch (event.key) {
case " ": case " ":
event.stopPropagation() event.stopPropagation()
@ -1148,27 +1111,106 @@ function Plugin(page, pane, field, runs) {
return true return true
}) })
}, },
}, }, function() {
onchoice: shy("插件菜单", { kit.Item(arguments.callee.meta, function(k, cb) {target[k] = function(event) {
"添加": "Clone", cb(event)
"删除": "Delete", }})
"加参": "Appends", }),
"减参": "Remove", Event: shy("事件入口", {name: plug+"."+name}, function(event, msg) {
}, ["添加", "删除", "加参", "减参"], function(value, meta, event) { return ctx.Event(event, msg||{}, arguments.callee.meta)
}),
which: plugin.Sync(name),
}, plugin)
input.onaction()
input.onimport()
target.value = plugin.onformat(item.init, item.value)
plugin.Inputs[item.name] = target, target.Input = input
!target.placeholder && item.name && (target.placeholder = item.name)
!target.title && item.placeholder && (target.title = item.placeholder)
kit.Log("init", "input", plug+"."+name, input)
return input
}
function Output(plugin, type, msg, cb, target, option) {
var exports = plugin.target.Meta.exports
var output = Meta(target, {
onexport: shy("导出数据", {
"": function(value, name, line) {
return value
},
see: function(value, name, line) {
return value.split("/")[0]
},
you: function(value, name, line) {
var event = window.event
event.Plugin = plugin
line.you && name == "status" && (line.status == "start"? function() {
plugin.Delay(3000, event, line.you+" stop...") && field.Run(event, [option.pod.value, line.you, "stop"])
}(): field.Run(event, [option.pod.value, line.you], function(msg) {
plugin.Delay(3000, event, line.you+" start...")
}))
return name == "status" || line.status == "stop" ? undefined: line.you
},
pod: function(value, name, line, list) {
return (option[list[0]].value? option[list[0]].value+".": "")+line.pod
},
dir: function(value, name, line) {
name != "path" && (value = line.path)
return value
},
tip: function(value, name, line) {
return option.tip.value + value
},
}, JSON.parse(exports||'["",""]'), function(event, value, name, line) {
var meta = arguments.callee.meta
var list = arguments.callee.list
;(!list[1] || list[1] == name) && page.Sync("plugin_"+list[0]).set(meta[list[2]||""](value, name, line))
}),
onimport: shy("导入数据", {
_table: function(msg, list) {
return list && list.length > 0 && kit.OrderTable(kit.AppendTable(kit.AppendChild(target, "table"), ctx.Table(msg), list), "", output.onexport)
},
_code: function(msg) {
return msg.result && msg.result.length > 0 && kit.OrderCode(kit.AppendChild(target, [{view: ["code", "div", msg.Results()]}]).first)
},
inner: function(msg, cb) {
target.innerHTML = "", plugin.onfigure.meta.max(target)
output.onimport.meta._table(msg, msg.append) || (target.innerHTML = msg.result.join(""))
typeof cb == "function" && cb(msg)
},
table: function(msg, cb) {
target.innerHTML = ""
output.onimport.meta._table(msg, msg.append) || output.onimport.meta._code(msg)
typeof cb == "function" && cb(msg)
},
editor: function(msg, cb) {
(target.innerHTML = "", Editor(plugin.Run, plugin, option, target, target.clientWidth-40, 400, 10, msg))
},
canvas: function(msg, cb) {
typeof cb == "function" && !cb(msg) || (target.innerHTML = "", Canvas(plugin, option, target, target.parentNode.clientWidth-45, target.parentNode.clientHeight-175, 10, msg))
},
}, function(type, msg, cb) {var meta = arguments.callee.meta
meta[type](msg, cb)
}),
onchoice: shy("菜单列表", {
"返回": "Last",
"清空": "clear",
"下载": "Download",
}, ["返回", "清空", "下载"], function(value, meta, event) {
kit._call(plugin, plugin[meta[value]]) kit._call(plugin, plugin[meta[value]])
return true return true
}), }),
}) onaction: shy("事件列表", {
field.oncontextmenu = function(event) { oncontextmenu: function(event) {
page.oncarte(event, plugin.onchoice) page.oncarte(event, output.onchoice)
} },
output.oncontextmenu = function(event) { }, function() {
page.oncarte(event, plugin.onreveal) kit.Item(arguments.callee.meta, function(k, cb) {target[k] = function(event) {
} cb(event)
}})
plugin.which = plugin.Sync("input") }),
page[field.id] = pane[field.id] = pane[name] = field, field.Plugin = plugin }, plugin)
inputs.map(function(item) {plugin.Append(item)}) output.onaction()
kit.Log("init", "plugin", name, plugin) output.onimport(type, msg, cb)
return plugin return output
} }

View File

@ -339,10 +339,15 @@ kit = toolkit = {__proto__: document,
} else if (child.require) { } else if (child.require) {
child.data["href"] = child.require[0] child.data["href"] = child.require[0]
child.data["rel"] = child.require.length > 1? child.require[1]: "stylesheet" child.data["rel"] = "stylesheet"
child.data["type"] = child.require.length > 2? child.require[2]: "text/css" child.data["type"] = "text/css"
child.require.length > 1 && (child.data["onload"] = child.require[1])
child.type = "link" child.type = "link"
// child.data["rel"] = child.require.length > 1? child.require[1]: "stylesheet"
// child.data["type"] = child.require.length > 2? child.require[2]: "text/css"
// child.require.length > 1 && (child.data["onload"] = child.require[1])
//
} else if (child.styles) { } else if (child.styles) {
var str = [] var str = []
if (typeof child.styles == "string") { if (typeof child.styles == "string") {
@ -517,6 +522,7 @@ kit = toolkit = {__proto__: document,
kit.CopyText() kit.CopyText()
}) })
} }
return true
}, },
// HTML显示文本 // HTML显示文本
@ -649,6 +655,9 @@ kit = toolkit = {__proto__: document,
obj.length > 0 && setTimeout(function() {loop(0)}, interval/4) obj.length > 0 && setTimeout(function() {loop(0)}, interval/4)
return obj return obj
} }
obj = typeof obj == "string"? [obj]: (obj || [])
var list = [] var list = []
for (var i = 0; i < obj.length; i++) { for (var i = 0; i < obj.length; i++) {
list.push(typeof cb == "function"? cb(obj[i], i, obj): obj[i]) list.push(typeof cb == "function"? cb(obj[i], i, obj): obj[i])

View File

@ -6,7 +6,7 @@
<meta name="{{index $meta "name"}}" content="{{index $meta "content"}}"> <meta name="{{index $meta "name"}}" content="{{index $meta "content"}}">
{{end}} {{end}}
<title>{{options . "name"}}</title> <title>{{options . "title"}}</title>
<link rel="shortcut icon" type="image/ico" href="/static/librarys/{{options . "favicon"}}"> <link rel="shortcut icon" type="image/ico" href="/static/librarys/{{options . "favicon"}}">
{{range $index, $lib := option . "styles"}} {{range $index, $lib := option . "styles"}}
<link rel="stylesheet" type="text/css" href="/static/librarys/{{$lib}}"></link> <link rel="stylesheet" type="text/css" href="/static/librarys/{{$lib}}"></link>