1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 08:48:06 +08:00

opt debug.js

This commit is contained in:
shaoying 2019-10-08 10:22:36 +08:00
parent ab11ad2c12
commit c31710a834
5 changed files with 37 additions and 45 deletions

View File

@ -130,7 +130,6 @@ var page = Page({check: true,
},
},
initOcean: function(page, field, option, output) {
var table = kit.AppendChild(output, "table")
var ui = kit.AppendChild(field, [{view: ["create"], list: [
@ -584,7 +583,7 @@ var page = Page({check: true,
init: function(page) {
page.action.Pane.Layout(ctx.Search("layout")? ctx.Search("layout"): kit.device.isMobile? page.conf.first: page.conf.mobile)
page.footer.Pane.Order({"ncmd": "0", "ntxt": "0"}, ["ncmd", "ntxt"], function(event, item, value) {})
page.header.Pane.Order({"user": "", "title": "github.com/shylinux/context"}, ["user"], function(event, item, value) {
page.header.Pane.Order({"user": page.who.get(), "title": "github.com/shylinux/context"}, ["user"], function(event, item, value) {
page.onaction[item] && page.onaction[item](event, item, value, page)
})
page.river.Pane.Show()

View File

@ -159,10 +159,10 @@ ctx = context = (function(kit) {var ctx = {__proto__: kit,
}),
WSS: shy("响应后端", {order: 0, wssid: ""}, function(cb, onerror, onclose) {var meta = arguments.callee.meta
var s = new WebSocket(location.protocol.replace("http", "ws")+"//"+location.host+"/wss?wssid="+meta.wssid)
s.onopen = function(event) {kit.Tip("wss open"), kit.Log("wss", "open")}
s.onopen = function(event) {kit.Tip("wss open"), ctx.Event(event, {}, {name: [document.title, "wss", "open"]})}
s.onerror = function(event) {kit.Log("wss", "error", event), kit._call(onerror, [event])}
s.onclose = function(event) {kit.Tip("wss close"), kit.Log("wss", "close"), kit._call(onclose, [event])}
s.onmessage = function(event) {
s.onmessage = function(event) {var order = ++meta.order
try {
var msg = JSON.parse(event.data||'{}')
} catch (e) {
@ -170,13 +170,13 @@ ctx = context = (function(kit) {var ctx = {__proto__: kit,
}
// Event入口 -1.0
msg = ctx.Event(event, msg, {name: [document.title, "wss", msg.detail[0]], Order: ++meta.order, Reply: function(msg) {
kit.Log(["wss", msg.Order, "result"].concat(msg.result).concat([msg]))
msg = ctx.Event(event, msg, {name: [document.title, "wss", msg.detail[0]], Order: order, Reply: function(msg) {
kit.Log(["wss", order, "result"].concat(msg.result).concat([msg]))
delete(msg.event), s.send(JSON.stringify(msg))
}})
try {
kit.Log(["wss", msg.Order].concat(msg.detail).concat([msg]))
kit.Log(["wss", order].concat(msg.detail).concat([msg]))
kit._call(cb, [msg])
} catch (e) {
msg.Reply(kit.Log("err", e))

View File

@ -224,11 +224,14 @@ fieldset.dialog.Debug tr.hide {
display:none;
}
fieldset.dialog.Debug tr.event {
display:red;
background-color:red;
}
fieldset.dialog.Debug tr.run {
background-color:lightgreen;
}
fieldset.dialog.Debug tr.wss {
background-color:lightblue;
}
fieldset.dialog.Debug tr.key {
background-color:lightyellow;
}

View File

@ -142,7 +142,7 @@ function Page(page) {
document.querySelectorAll("body>fieldset").forEach(function(field) {
page.Pane(page, field)
}), page.check? page.login.Pane.Run(event, [], function(msg) {
msg.result && msg.result[0]? (page.init(page), page.who.set(msg.nickname[0]))
msg.result && msg.result[0]? (page.who.set(msg.nickname[0]), page.init(page))
:page.login.Pane.Dialog(1, 1)
}): page.init(page)
}
@ -448,7 +448,7 @@ function Page(page) {
initDebug: function(page, field, option, output) {
var table = kit.AppendChilds(output, "table")
var caption = kit.AppendChild(table, [{type: "caption"}]).last
var head = kit.AppendChild(table, [{type: "thead", list: [{row: ["time", "type", "order", "action", "target", "args"], sub: "th"}]}]).tr
var head = kit.AppendChild(table, [{type: "thead", list: [{row: ["index", "time", "type", "order", "action", "target", "args"], sub: "th"}]}]).tr
var list = kit.AppendChild(table, "tbody")
kit.OrderTable(table)
var last, types = {all: 0, event: 0, run: 0, key: 0}
@ -457,9 +457,8 @@ function Page(page) {
kit.Log.meta.call.push(function(time, type, order, action, target) {var Choice = field.Pane && field.Pane.Choice || []
if (kit.isNone(types[type])) {types[type] = 0, Choice.push(type)}
types[type]++
types.all++
last = kit.AppendChild(list, [{className: type, row: [time, type, order, action||"", target||"", kit.List(arguments, function(item) {
last = kit.AppendChild(list, [{className: type, row: [types.all++, time, type, order, action||"", target||"", kit.List(arguments, function(item) {
return typeof item == "object"? "{...}": item
}).slice(5).join(" ")]}]).last
field.Pane && field.Pane.Head()
@ -621,7 +620,6 @@ function Page(page) {
},
Pane: Pane,
}), page.which = page.Sync("layout"), page.who = page.Sync("username")
kit.Log("init", "page", page)
return window.onload = page.onload, page
}
@ -654,15 +652,16 @@ function Pane(page, field) {
var index = kit.Selector(output, itemkey).length
var ui = pane.View(output, type, line, key)
ui.item.onclick = function(event) {
if (!pane.which.set(line[which])) {return}
ui.item.onclick = function(event) { if (pane.which.get() == line[which]) {return}
page.script("record", [name, line[key[0]]])
pane.Event(event, {}, {name: pane.Zone("select", line[key[0]])})
kit.Selector(output, itemkeys, function(item) {kit.classList.del(item, "select")})
kit.Selector(output, itemkey, function(item, i) {i == index && kit.classList.add(item, "select")})
pane.Event(event, {}, {name: pane.Zone("select", line[key[0]])})
page.script("record", [name, line[key[0]]])
pane.which.set(line[which])
kit._call(cb, [line, index, event])
}
if (type == "plugin" && line.name || type == "field") {
ui.item.ondragstart = function(event) {
event.stopPropagation()
@ -689,7 +688,9 @@ function Pane(page, field) {
return ui
}),
Select: shy("选择列表", function(index) {
kit.Selector(output, itemkey, function(item, i) {i == index && item.click()})
kit.Selector(output, itemkey, function(item, i) {
i == index && item.Select()
})
}),
Show: function() {
@ -928,7 +929,6 @@ function Pane(page, field) {
_split: function(str) {return str.trim().split(" ")},
_cmd: function(arg) {
var args = typeof arg[1] == "string"? engine._split(arg[1]): arg[1];
kit.Log(["cmd"].concat(args))
page.script("record", args)
if (typeof meta[args[0]] == "function") {
@ -962,17 +962,18 @@ function Pane(page, field) {
_msg: function(msg) {
event.ctrlKey? kit._call(page.target.Pane.Send, msg.Format()):
event.shiftKey && page.target.Pane.Send("field", plugin.Reveal())
kit._call(cbs, [msg])
},
_run: function(msg) {
var meta = plugin && plugin.target && plugin.target.Meta || {}
pane.Run(event, [meta.river, meta.storm, meta.action].concat(args), function(msg) {
pane.Run(event, [Meta.river, Meta.storm, Meta.action].concat(args), function(msg) {
kit._call(cbs, [msg]), engine._msg(msg)
})
},
}
page.footer.Pane.State("ncmd", kit.History("cmd", -1, args))
var Meta = plugin && plugin.target && plugin.target.Meta || {}
kit.Log(["cmd"].concat(kit.List([Meta.river, Meta.storm, Meta.action])).concat(args[0] == "_cmd"? args[1]: args))
page.footer.Pane.State("ncmd", kit.History("cmd", -1, {args: args, meta: Meta}))
return args.length > 0 && meta[args[0]]? kit._call(cbs, [msg.Echo(meta[args[0]](args))]):
args.length > 0 && engine[args[0]]? kit._call(cbs, [msg.Echo(engine[args[0]](args))]):
event.shiftKey? engine._msg(msg): engine._run(msg)
@ -1005,10 +1006,9 @@ function Pane(page, field) {
Plugin: Plugin,
})
kit.Log("init", "pane", name, pane)
kit.AppendAction(action, pane.Button, pane.Check)
kit.Item(pane.Listen, function(key, cb) {page.Sync(key).change(cb)})
kit.Log("init", "pane", name, pane)
return page[name] = field, field.Pane = pane
}
function Plugin(page, pane, field, inits, runs) {
@ -1054,16 +1054,10 @@ function Plugin(page, pane, field, inits, runs) {
}
return Inputs(plugin, input, item, plugin.View(option, "input", input)[input.name]).target
}),
Select: shy("选择控件", function(target) {
page.plugin && (kit.classList.del(page.plugin, "select"))
page.plugin = field, kit.classList.add(field, "select")
pane.which.set(name)
if (kit.isNone(target)) {return}
page.input = target || option.querySelectorAll("input")[1]
Select: shy("选择控件", function(target, focus) {field.onclick(event)
page.input = target = target || option.querySelectorAll("input")[1]
plugin.which.set(page.input.name)
page.input.focus()
focus && page.input.focus()
}),
Remove: shy("删除控件", function() {
var list = option.querySelectorAll("input.temp")
@ -1196,10 +1190,9 @@ function Plugin(page, pane, field, inits, runs) {
}, function(event, key, cb) {cb(event)}),
})
plugin.Appends(inputs)
plugin.which = plugin.Sync("input")
kit.Log("init", "plugin", name, plugin)
plugin.which = plugin.Sync("input")
plugin.Appends(inputs)
return page[field.id] = pane[field.id] = pane[name] = field, field.Plugin = plugin
}
function Inputs(plugin, meta, item, target) {
@ -1261,8 +1254,7 @@ function Inputs(plugin, meta, item, target) {
onaction: shy("事件列表", {
onfocus: function(event) {plugin.Select(target)},
onblur: function(event) {type == "text" && input.which.set(target.value)},
onclick: function(event) {
type == "text"
onclick: function(event) {plugin.Select()
// Event入口 2.0
type == "button" && input.Event(event, {}) && kit.Value(input[item.cb], plugin[item.cb], function() {
plugin.Check(event)
@ -1350,13 +1342,13 @@ function Inputs(plugin, meta, item, target) {
}, function(event, key, cb) {cb(event)}),
which: plugin.Sync(name),
}, plugin)
kit.Log("init", "input", input.Zones(), input)
input.onimport()
target.value = input.onformat(item.init, item.value)
type == "text" && !target.placeholder && (target.placeholder = item.name)
type == "text" && !target.title && (target.title = item.placeholder || item.name || "")
kit.Log("init", "input", input.Zones(), input)
return plugin.Inputs[item.name] = target, target.Input = input
}
function Output(plugin, type, msg, cb, target, option) {
@ -1462,8 +1454,7 @@ function Output(plugin, type, msg, cb, target, option) {
},
}, function(event, key, cb) {cb(event)}),
}, plugin)
output.onimport(type, msg, cb)
kit.Log("init", "output", output.Zones(), output)
output.onimport(type, msg, cb)
return plugin.Outputs[type] = target, target.Output = output
}

View File

@ -33,7 +33,6 @@ kit = toolkit = (function() {var kit = {__proto__: document,
if (kit.isNone(data)) {var len = list.length
return list[(index+len)%len]
}
kit.Log("history", type, data)
return meta[type] = list, list.push({time: Date.now(), data: data})-1
}),
Debug: shy("调试断点", {why: true, msg: true}, function(key) {
@ -356,7 +355,7 @@ kit = toolkit = (function() {var kit = {__proto__: document,
if (target.tagName == "TH") {var dataset = target.dataset
dataset["sort_asc"] = (dataset["sort_asc"] == "1") ? 0: 1
kit.RangeTable(table, i, dataset["sort_asc"] == "1")
} else {var index = 0
} else if (target.tagName == "TD") {var index = 0
kit.Selector(table, "tr", function(item, i) {item == target.parentElement && (index = i)})
var name = target.parentElement.parentElement.querySelector("tr").childNodes[i].innerText
name.startsWith(field) && kit._call(cb, [event, item.innerText, name, item.parentNode.Meta, index])
@ -465,7 +464,7 @@ kit = toolkit = (function() {var kit = {__proto__: document,
},
// 数据容器迭代
Push: function(list, value, check) {list = list || []
Push: function(list, value) {list = list || []
return (kit.notNone||check)(value) && list.push(value), list
},
List: function(obj, cb, interval, cbs) {obj = typeof obj == "string"? [obj]: (obj || [])