diff --git a/usr/librarys/chat.js b/usr/librarys/chat.js index a34bf13c..396fe0c6 100644 --- a/usr/librarys/chat.js +++ b/usr/librarys/chat.js @@ -545,6 +545,10 @@ var page = Page({check: true, "", "添加", "删除", "加参", "减参", "", "执行", "下载", "清空", "返回", ], + Choice: [ + "刷新", "清屏", "并行", "串行", + "", "聊天", "办公", "工作", + ], } }, initStorm: function(page, field, option, output) { @@ -589,6 +593,7 @@ var page = Page({check: true, }, }, Button: ["创建", "共享"], + Choice: ["创建", "共享"], } }, initSteam: function(page, field, option, output) { @@ -665,6 +670,10 @@ var page = Page({check: true, kit.AppendChilds(device, [{text: ["2. 选择模块命令 ->", "caption"]}]) kit.AppendTable(device, list, ["key", "index", "name", "help"], function(value, key, com, i, tr, event) { pane.Select(com, pod) + }, function(value, key, com, i, tr, event) { + page.oncarte(event, ["创建"], function(event, item) { + pane.Create(com.key) + }) }) }, Append: function(msg) {var pane = field.Pane @@ -677,7 +686,7 @@ var page = Page({check: true, }), table.querySelector("td").click() }, Create: function(name, list) { - field.Pane.Run([river, "spawn", name].concat(list), function(msg) { + field.Pane.Run([river, "spawn", name].concat(list||[]), function(msg) { field.Pane.Show(), page.storm.Pane.Show(name) }) }, diff --git a/usr/librarys/context.js b/usr/librarys/context.js index 78b6c6c6..30dee605 100644 --- a/usr/librarys/context.js +++ b/usr/librarys/context.js @@ -301,12 +301,12 @@ ctx = context = {__proto__: kit, }, }) - try { + // try { kit.Log(["wss", order].concat(msg.detail).concat([msg])) typeof cb == "function" && cb(msg) - } catch (e) { - msg.reply(kit.Log("err", e)) - } + // } catch (e) { + // msg.Reply(kit.Log("err", e)) + // } } s.onerror = function(event) { kit.Log("wss", "error", event) diff --git a/usr/librarys/example.css b/usr/librarys/example.css index f5d7751f..e41f3154 100644 --- a/usr/librarys/example.css +++ b/usr/librarys/example.css @@ -96,7 +96,7 @@ fieldset>div.output div.code span.green { color:green; } fieldset>div.output table td { - word-break:break-word; + /* word-break:break-word; */ } fieldset>div.output table td.when { word-break:break-word; @@ -129,6 +129,17 @@ fieldset>div.Help>div { overflow:auto; } +fieldset.carte { + border:solid 2px red; + background-color:#ffffff; + position:absolute; + display:none; + z-index:200; +} +fieldset.carte>div.output>div.line { + border:solid 1px gray; + margin-top:8px; +} fieldset.toast { border:solid 2px red; background-color:#ffffff; diff --git a/usr/librarys/example.js b/usr/librarys/example.js index 3459e98c..30512fe5 100644 --- a/usr/librarys/example.js +++ b/usr/librarys/example.js @@ -128,6 +128,7 @@ function Meta(target, obj) { } function Page(page) { var script = {}, record = "" + var carte = document.querySelector("fieldset.carte") page = Meta(document.body, page, {__proto__: ctx, onload: function() { // Event入口 0 @@ -180,6 +181,18 @@ function Page(page) { }, document.body.onmouseup = function(event) { } }, + oncarte: function(event, cb) { + kit.Selector(carte, "div.output", function(output) {if (!cb.list || cb.list.length == 0) {return} + kit.AppendChilds(output, kit.List(cb.list, function(item) { + return item === ""? {view: ["line"]}: {text: [item, "div", "item"], click: function(event) { + kit._call(cb, [item, cb.meta, event]) && kit.ModifyView(carte, {display: "none"}) + }} + })) + kit.ModifyView(carte, {display: "block", left: event.x, top: event.y}) + event.stopPropagation() + event.preventDefault() + }) + }, ontoast: function(text, title, duration) { // {text, title, duration, inputs, buttons} if (!text) {page.toast.style.display = "none"; return} @@ -690,16 +703,22 @@ function Pane(page, field) { for (var k in pane.Listen) { page.Sync(k).change(pane.Listen[k]) } + function call(value, event) { + // Event入口 1.1 + ctx.Event(event, {}, {name: name+"."+value}) + page.script("record", [name, value]) + typeof pane.Action == "function"? pane.Action(value, event): pane.Action[value](event, value) + } pane.Button && pane.Button.length > 0 && (kit.InsertChild(field, output, "div", pane.Button.map(function(value) { - function call(value, event) { - // Event入口 1.1 - ctx.Event(event, {}, {name: name+"."+value}) - page.script("record", [name, value]) - typeof pane.Action == "function"? pane.Action(value, event): pane.Action[value](event, value) - } return typeof value == "object"? {className: value[0], select: [value.slice(1), call]}: value == ""? {view: ["space"]} :value == "br"? {type: "br"}: {button: [value, call]} })).className="action") + field.oncontextmenu = function(event) { + page.oncarte(event, pane.Choice, function(event, value) { + call(value, event) + return true + }) && (event.stopPropagation(), event.preventDefault()) + } option.onsubmit = function(event) { event.preventDefault() }; @@ -727,9 +746,7 @@ function Plugin(page, pane, field, runs) { runs(event, cmds, cbs) } var plugin = Meta(field, (field.Script && field.Script.init || function() { - })(run, field, option, output)||{}, { - ontoast: page.ontoast, - Inputs: {}, + })(run, field, option, output)||{}, {Inputs: {}, Appends: function() { var name = "args"+kit.Selector(option, "input.args.temp").length plugin.Append({type: "text", name: name, className: "args temp"}).focus() @@ -747,13 +764,13 @@ function Plugin(page, pane, field, runs) { }, }}]).last.focus() }, - Append: 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.value = plugin.onformat(item.init)(item.value)||"" !item.title && item.name && (item.title = item.name) !item.placeholder && item.title && (item.placeholder = item.title) @@ -787,7 +804,7 @@ function Plugin(page, pane, field, runs) { } var ui = kit.AppendChild(option, [{view: [item.view||""], list: [{type: "label", inner: item.label||""}, input]}]) - var action = Meta(ui[input.name] || {}, item, plugin.onaction, plugin); + 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) { @@ -800,7 +817,7 @@ function Plugin(page, pane, field, runs) { item.which = plugin.Sync(input.name) plugin.Inputs[input.name] = ui[input.name] return action.target - }, + }), Remove: function() { var list = option.querySelectorAll("input.temp") list.length > 0 && (option.removeChild(list[list.length-1].parentNode)) @@ -828,12 +845,6 @@ function Plugin(page, pane, field, runs) { run(event, cmds, cbs) }).field.Plugin }, - Last: function() { - var list = history.pop() - list? (list.target.value = list.value): inputs.map(function(item) { - option[item.name].value = item.value - }), plugin.Check() - }, getLocation: function(event) { var x = parseFloat(option.x.value) @@ -896,11 +907,11 @@ function Plugin(page, pane, field, runs) { return kit._call(plugin.Runs, [event]) }, - Delay: function(time, event, text) { - page.ontoast(text, "", -1) - return setTimeout(function() { - plugin.Runs(event), page.ontoast("") - }, time) + Option: function(key, value) { + if (value != undefined) { + option[key] && (option[key].value = value) + } + return option[key]? option[key].value: "" }, Check: function(target, cb) { plugin.Select(true), kit.Selector(option, ".args", function(item, index, list) { @@ -909,6 +920,18 @@ function Plugin(page, pane, field, runs) { return item }).length == 0 && plugin.Runs(window.event, cb) }, + Delay: function(time, event, text) { + page.ontoast(text, "", -1) + return setTimeout(function() { + plugin.Runs(event), page.ontoast("") + }, time) + }, + Last: function() { + var list = history.pop() + list? (list.target.value = list.value): inputs.map(function(item) { + option[item.name].value = item.value + }), plugin.Check() + }, Runs: function(event, cb) { plugin.Run(event, kit.Selector(option, ".args", function(item, index) {return item.value}), cb) }, @@ -924,14 +947,13 @@ function Plugin(page, pane, field, runs) { show = false, page.ontoast("") }) }, - clear: function() { output.innerHTML = "" }, display: function(arg, cb) { - deal = arg, plugin.ondaemon[deal||"table"](plugin.msg, cb) - plugin.show_after(plugin.msg) + plugin.ondaemon[(deal = arg)||"table"](plugin.msg, cb), plugin.show_after(plugin.msg) }, + show_after: function(msg) {}, Download: function() { var text = kit.Selector(output, "tr", function(tr) { return kit.Selector(tr, "td,th", function(td) { @@ -945,13 +967,6 @@ function Plugin(page, pane, field, runs) { item.click() }) }, - show_after: function(msg) {}, - Option: function(key, value) { - if (value != undefined) { - option[key] && (option[key].value = value) - } - return option[key]? option[key].value: "" - }, upload: function(event) { ctx.Upload({river: meta.river, table: plugin.Option("table")}, option.upload.files[0], function(event, msg) { kit.OrderTable(kit.AppendTable(kit.AppendChilds(output, "table"), ctx.Table(msg), msg.append)) @@ -960,6 +975,17 @@ function Plugin(page, pane, field, runs) { page.ontoast(), page.ontoast("上传进度 "+parseInt(event.loaded*100/event.total)+"%") }) }, + + exports: JSON.parse(meta.exports||'["",""]'), + ontoast: page.ontoast, + onreveal: shy("数据菜单", { + "下载": "Download", + "清空": "clear", + "返回": "Last", + }, ["下载", "清空", "返回"], function(value, meta, event) { + kit._call(plugin, plugin[meta[value]]) + return true + }), onformat: Wrap(function(which) { var meta = arguments.callee return meta[which]||meta["none"] @@ -967,30 +993,6 @@ function Plugin(page, pane, field, runs) { none: function(value) {return value}, date: function(value) {return kit.format_date(new Date())}, }), - 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)) - }, - }, onexport: { "": function(value, name, line) { return value @@ -1020,6 +1022,30 @@ function Plugin(page, pane, field, runs) { 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) @@ -1027,27 +1053,27 @@ function Plugin(page, pane, field, runs) { }, onblur: function(event, action, type, name, item) { item.which.set(action.target.value) - // page.input = undefined }, onclick: function(event, action, type, name, item) { switch (type) { case "button": // Event入口 2.0 ctx.Event(event, {}, {name: meta.name+"."+name}) - - action[item.cb]? action[item.cb](event, item, option, field): - plugin[item.cb]? plugin[item.cb](event, item, option, field): plugin.Check() + kit.Value(action[item.cb], plugin[item.cb], function() { + plugin.Check() + })(event, item, option, field) break case "text": - if (event.ctrlKey) { - action.value = kit.History.get("txt", -1).data.trim() - } + 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() + }, onchange: function(event, action, type, name, item) { type == "select" && ctx.Event(event, {}, {name: meta.name+"."+name}) && plugin.Check(item.action == "auto"? undefined: action) }, @@ -1123,8 +1149,22 @@ function Plugin(page, pane, field, runs) { }) }, }, - exports: JSON.parse(meta.exports||'["",""]'), + onchoice: shy("插件菜单", { + "添加": "Clone", + "删除": "Delete", + "加参": "Appends", + "减参": "Remove", + }, ["添加", "删除", "加参", "减参"], function(value, meta, event) { + kit._call(plugin, plugin[meta[value]]) + return true + }), }) + field.oncontextmenu = function(event) { + page.oncarte(event, plugin.onchoice) + } + output.oncontextmenu = function(event) { + page.oncarte(event, plugin.onreveal) + } plugin.which = plugin.Sync("input") page[field.id] = pane[field.id] = pane[name] = field, field.Plugin = plugin diff --git a/usr/librarys/toolkit.js b/usr/librarys/toolkit.js index 34734888..b6886590 100644 --- a/usr/librarys/toolkit.js +++ b/usr/librarys/toolkit.js @@ -4,6 +4,23 @@ Wrap = function(cb, obj) { } return cb } +shy = function(help, meta, list, cb) { + var index = -1, value = "", type = "string", args = arguments + function next(check) { + if (++index >= args.length) {return false} + if (check && check != typeof args[index]) {index--; return false} + return value = args[index], type = typeof value, value + } + + var cb = arguments[arguments.length-1] || function() {} + cb.help = next("string") || "还没有写" + cb.meta = next("object") || {} + cb.list = next("object") || {} + cb.runs = function() { + } + return cb +} + kit = toolkit = {__proto__: document, meta: function(cb, obj) { for (var k in obj) { @@ -397,7 +414,7 @@ kit = toolkit = {__proto__: document, }) return kit.AppendChild(parent, result) }, - AppendTable: function(table, data, fields, cb) { + AppendTable: function(table, data, fields, cb, cbs) { if (!data || !fields) { return } @@ -411,16 +428,18 @@ kit = toolkit = {__proto__: document, tr.Meta = row fields.forEach(function(key, j) { var td = kit.AppendChild(tr, "td", kit.Color(row[key])) + if (key == "when") {td.className = "when"} if (row[key].startsWith("http")) { td.innerHTML = ""+row[key]+"" } - if (key == "when") {td.className = "when"} - - if (typeof cb == "function") { - td.onclick = function(event) { - cb(row[key], key, row, i, tr, event) - } - } + cb && (td.onclick = function(event) { + kit._call(cb, [row[key], key, row, i, tr, event]) + }) + cbs && (td.oncontextmenu = function(event) { + kit._call(cbs, [row[key], key, row, i, tr, event]) + event.stopPropagation() + event.preventDefault() + }) }) }) return table @@ -639,7 +658,8 @@ kit = toolkit = {__proto__: document, Item: function(obj, cb) { var list = [] for (var k in obj) { - list.push(typeof cb == "function"? cb(k, obj[k]): k) + var v = typeof cb == "function"? cb(k, obj[k]): k + v != undefined && list.push(v) } return list }, @@ -664,8 +684,17 @@ kit = toolkit = {__proto__: document, }, kit.Value(interval, 150)) }, // 数据类型转换 - Value: function(obj, value) { - return obj === undefined || obj === null || obj === "" ? value: obj + Value: function() { + for (var i = 0; i < arguments.length; i++) { + switch (arguments[i]) { + case undefined: + case null: + case "": + break + default: + return arguments[i] + } + } }, isSpace: function(c) { return c == " " || c == "Enter" @@ -773,21 +802,22 @@ kit = toolkit = {__proto__: document, obj.style.width = width+"px" obj.style.height = height+"px" }, - _call: function(cb, arg) { - var res - if (typeof cb != "function") {return} + type: function(obj, type) { + if (type == undefined) {return typeof obj} + return typeof obj == type? obj: null + }, + _call: function() {// obj, cb, arg + var index = 0, obj, cb, arg; + (obj = kit.type(arguments[index], "object")) && index++ + (cb = kit.type(arguments[index], "function")) && index++ + (arg = kit.type(arguments[index], "object")) && index++ - switch (arg.length) { - case 0: res = cb(); break - case 1: res = cb(arg[0]); break - case 2: res = cb(arg[0], arg[1]); break - case 3: res = cb(arg[0], arg[1], arg[2]); break - case 4: res = cb(arg[0], arg[1], arg[2], arg[3]); break - case 5: res = cb(arg[0], arg[1], arg[2], arg[3], arg[4]); break - case 6: res = cb(arg[0], arg[1], arg[2], arg[3], arg[4], arg[5]); break - case 7: res = cb(arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6]); break + arg = arg || [] + while (index < arguments.length) { + arg.push(arguments[index++]) } - return res || true + cb = cb || function(){} + return cb.apply(obj||window, arg||[]) }, } diff --git a/usr/template/common.tmpl b/usr/template/common.tmpl index 4136b86e..51b723ce 100644 --- a/usr/template/common.tmpl +++ b/usr/template/common.tmpl @@ -13,6 +13,10 @@ {{end}}
+