diff --git a/frame.js b/frame.js index fd56b003..ad3e4abc 100644 --- a/frame.js +++ b/frame.js @@ -67,12 +67,18 @@ var can = Volcanos("chat", { if (width > 0) {field.style.width = width + "px"; field.style.left = (document.body.offsetWidth - width) / 2 + "px"; } + if (width === "") { + field.style.width = "" + } if (height > 0) {field.style.height = height + "px"; field.style.top = (document.body.offsetHeight - height) / 2 + (offset||0) + "px"; } if (height < 0) {field.style.top = -height / 2 + (offset||0) + "px"; field.style.height = (document.body.offsetHeight + height) + "px"; } + if (height === "") { + field.style.height = "" + } var cb = pane.onimport["show"]; typeof cb == "function" && cb(event, can, width, "show", pane.output) return field; @@ -225,6 +231,10 @@ var can = Volcanos("chat", { Export: function(event, value, key, index) {can.Report(event, value, key, index)}, run: function(event, cmd, cb, silent) { + var msg = can.Event(event); + can.page.Select(can, option, "input,select", function(item) { + item.name && item.value && msg.Option(item.name, item.value) + }); (output[cmd[1]] || can[cmd[1]] || can.Run)(event, cmd, cb, silent); }, }, Config.libs.concat(["plugin/"+type]), function(output) { diff --git a/lib/page.js b/lib/page.js index 096e1f13..42e452f2 100644 --- a/lib/page.js +++ b/lib/page.js @@ -136,7 +136,15 @@ Volcanos("page", {help: "网页模块", Appends: shy("添加节点", function(can, target, key, value) { return target.innerHTML = "", can.page.Append(can, target, key, value) }), + Remove: shy("删除节点", function(can, target, key, value) { + target.parentNode.removeChild(target) + }), + CopySub: shy("复制节点", function(can, target, source) { + while (source.children.length > 0) { + target.appendChild(source.children[0]) + } + }), AppendItem: shy("添加插件", function(can, target, list, click, cb, cbs) { can.core.List(list, function(line, index) { var item = can.page.Append(can, target, [{view: ["item k"+line.key], list: [{text: [line.nick||line.name||line.key]}], click: function(event) { @@ -227,6 +235,15 @@ Volcanos("page", {help: "网页模块", tbody.appendChild(list[i]) } }, + OrderTable: function(can, table) { + can.page.Select(can, table, "th", function(th, index) { + table.onclick = function(event) { + var dataset = event.target.dataset; + dataset["sort_asc"] = (dataset["sort_asc"] == "1") ? 0: 1; + can.page.RangeTable(can, table, index, dataset["sort_asc"] == "1"); + } + }) + }, Display: function(text) { if (text.startsWith("http")) {return ""+text+""} diff --git a/order.js b/order.js index e86356e1..e7bd5bc7 100644 --- a/order.js +++ b/order.js @@ -1,7 +1,7 @@ var Config = {context: "/chat/", main: "chat", list: ["page/chat", - "pane/Toast", "pane/Carte", "pane/Debug", - "pane/Tutor", "pane/Favor", "pane/Login", + "pane/Toast", "pane/Tutor", "pane/Debug", + "pane/Carte", "pane/Favor", "pane/Login", "pane/Header", "pane/Ocean", "pane/River", "pane/Storm", "pane/Steam", @@ -13,17 +13,18 @@ var Config = {context: "/chat/", libs: ["lib/base", "lib/core", "lib/misc", "lib/page", "lib/user"], pane: [ {group: "index", name: "Toast", pos: "dialog", duration: 3000}, - {group: "index", name: "Carte", pos: "dialog"}, - {group: "index", name: "Debug", pos: "dialog"}, - {group: "index", name: "Login", pos: "dialog"}, - {group: "index", name: "Favor", pos: "dialog"}, {group: "index", name: "Tutor", pos: "dialog"}, + {group: "index", name: "Debug", pos: "dialog"}, + {group: "index", name: "Carte", pos: "dialog"}, + {group: "index", name: "Favor", pos: "dialog"}, + {group: "index", name: "Login", pos: "dialog"}, {group: "index", name: "Header", pos: "head", state: ["time", "user", "link"], title: "github.com/shylinux/context"}, {group: "index", name: "Ocean", pos: "dialog", def_name: "meet"}, {group: "index", name: "River", pos: "left"}, {group: "index", name: "Storm", pos: "right"}, {group: "index", name: "Steam", pos: "dialog", def_name: "miss"}, + {group: "index", name: "Target", pos: "top"}, {group: "index", name: "Source", pos: "center"}, {group: "index", name: "Action", pos: "bottom"}, diff --git a/pane/Action.js b/pane/Action.js index 07767d4b..32e1f826 100644 --- a/pane/Action.js +++ b/pane/Action.js @@ -8,6 +8,11 @@ Volcanos("onimport", {help: "导入数据", list: [], }, size: function(event, can, value, cmd, output) { }, + layout: function(event, can, value, cmd, output) {can.layout = value; + can.page.Select(can, can.action, "select.layout", function(item) { + item.value = value + }) + }, river: function(event, can, value, cmd, output) { if (value == "update") {return} can.Conf("temp_river", value) @@ -23,6 +28,15 @@ Volcanos("onimport", {help: "导入数据", list: [], }) } }, + favor: function(event, can, msg, cmd, output) {var key = msg.detail[0]; + if (msg._hand) {return} + var cb = can.onaction[key]; if (typeof cb == "function") {cb(event, can, msg, cmd, output); return msg.Echo(can._name, " onaction ", key), msg._hand = true} + var cb = can.onchoice[key]; if (typeof cb == "function") {cb(event, can, msg, cmd, output); return msg.Echo(can._name, " onchoice ", key), msg._hand = true} + + var sub = can[key]; if (sub && sub.Select) {sub.Select(event, null, true); return msg.Echo(can._name, " select ", sub._name), msg._hand = true} + + can._plugin && can._plugin.Import(event, msg, cmd) + }, pod: function(event, can, value, cmd, output) { can.page.Select(can, can.action, "input."+cmd, function(item) { item.value = value @@ -33,20 +47,6 @@ Volcanos("onimport", {help: "导入数据", list: [], document.title = item.value = value; }) }, - layout: function(event, can, value, cmd, output) {can.layout = value; - can.page.Select(can, can.action, "select.layout", function(item) { - item.value = value - }) - }, - favor: function(event, can, msg, cmd, output) {var key = msg.detail[0]; - if (msg._hand) {return} - var cb = can.onaction[key]; if (typeof cb == "function") {cb(event, can, msg, cmd, output); return msg.Echo(can._name, " onaction ", key), msg._hand = true} - var cb = can.onchoice[key]; if (typeof cb == "function") {cb(event, can, msg, cmd, output); return msg.Echo(can._name, " onchoice ", key), msg._hand = true} - - var sub = can[key]; if (sub && sub.Select) {sub.Select(event, null, true); return msg.Echo(can._name, " select ", sub._name), msg._hand = true} - - can._plugin && can._plugin.Import(event, msg, cmd) - }, }) Volcanos("onaction", {help: "组件交互", list: [["layout", "工作", "办公", "聊天"], "清屏", "刷新", "串行", "并行", {input: "pod"}, {input: "you"}], @@ -68,6 +68,9 @@ Volcanos("onaction", {help: "组件交互", list: [["layout", "工作", "办公" can.page.Select(can, output, "fieldset.item>div.output", function(item) { item.innerHTML = ""; }) + can.run(event, [can.Conf("river"), can.Conf("storm")], function(msg) { + can.onimport.init(event, can, msg, cmd, output) + }) }, }) Volcanos("onchoice", {help: "组件菜单", list: [["layout", "工作", "办公", "聊天"]], diff --git a/pane/Ocean.js b/pane/Ocean.js index 0df638e6..e9d92724 100644 --- a/pane/Ocean.js +++ b/pane/Ocean.js @@ -5,28 +5,31 @@ Volcanos("onimport", {help: "导入数据", list: [], {button: ["创建群聊", function(event) { if (!ui.name.value) {ui.name.focus(); can.user.toast("请输入群名"); return} - var list = can.page.Select(can, ui.list, "tr", function(item) { + var list = can.page.Select(can, ui.list, "tr", function(item, index) {if (index > 0) { return item.dataset.user - }) + }}) if (list.length == 0) {can.user.toast("请添加组员"); return} - can.run(event, ["spawn", "", ui.name.value].concat(list), function(msg) { + can.run(event, ["spawn", ui.name.value].concat(list), function(msg) { can.Hide(), can.Export(event, "update", "river"); }) - }]}, {name: "list", view: ["list", "table"], list: [{text: ["2. 已选用户列表", "caption"]}]}, + }]}, {name: "list", view: ["list", "table"], list: [ + {text: ["2. 已选用户列表", "caption"]}, + {row: ["username", "usernode"], sub: "th"}, + ]}, ]}]) can.ui = ui }, init: function(event, can, msg, key, output) {output.innerHTML = ""; var table = can.page.Append(can, output, "table"); - can.page.Append(can, table, [{text: ["1. 选择用户节点 ->", "caption"]}]) + can.page.Appends(can, table, [{text: ["1. 选择用户节点 ->", "caption"]}]) - can.page.AppendTable(can, table, msg, ["key", "user.route"], function(event, value, key, index, tr, td) {tr.className = "hidden"; + can.page.AppendTable(can, table, msg, ["username", "usernode"], function(event, value, key, index, tr, td) {tr.className = "hidden"; var uis = can.page.Append(can, can.ui.list, [{type: "tr", list: [ - {text: [value, "td"]}, - {text: [msg["user.route"][index], "td"]}, + {text: [msg["username"][index], "td"]}, + {text: [msg["usernode"][index], "td"]}, ], dataset: {user: value}, click: function(event) { - tr.className = "normal", uis.last.parentNode.removeChild(uis.last) + tr.className = "normal", can.page.Remove(can, uis.tr) }}]) }) }, diff --git a/pane/Steam.js b/pane/Steam.js index 85237697..14c8e6c9 100644 --- a/pane/Steam.js +++ b/pane/Steam.js @@ -6,17 +6,20 @@ Volcanos("onimport", {help: "导入数据", list: [], if (!ui.name.value) {ui.name.focus(); can.user.toast("请输入群名"); return} var list = [] - can.page.Select(can, ui.list, "tr", function(item) { + can.page.Select(can, ui.list, "tr", function(item, index) {if (index > 0) { list.push(item.dataset.pod) - list.push(item.dataset.group) + list.push(item.dataset.key) list.push(item.dataset.index) list.push(item.dataset.name) - }) + }}) can.run(event, [can.Conf("river"), "spawn", ui.name.value].concat(list), function(msg) { can.Hide(), can.Export(event, "update", "storm"); }) - }]}, {name: "list", view: ["list", "table"], list: [{text: ["3. 已选命令列表", "caption"]}]}, + }]}, {name: "list", view: ["list", "table"], list: [ + {text: ["3. 已选命令列表", "caption"]}, + {row: ["ctx", "cmd", "name", "help"], sub: "th"}, + ]}, ]}]) can.device = device can.ui = ui @@ -31,13 +34,13 @@ Volcanos("onimport", {help: "导入数据", list: [], can.page.ClassList.add(can, tr, "select") var node = msg.node[index]; - can.run(event, [can.Conf("river"), msg.user[index], node], function(com) { + can.run(event, [can.Conf("river"), msg.user[index], node], function(com) {var list = com.Table() can.page.Appends(can, can.device, [{text: ["2. 选择模块命令 ->", "caption"]}]) var table = can.page.AppendTable(can, can.device, com, ["key", "index", "name", "help"], function(event, value, key, index, tr, td) { - + var line = list[index]; + line.pod = node; var last = can.page.Append(can, can.ui.list, [{ - row: [com.key[index], com.index[index], com.name[index], com.help[index]], - dataset: {pod: node, group: com.key[index], index: com.index[index], name: com.name[index]}, + row: [line.key, line.index, line.name, line.help], dataset: line, click: function(event) {last.parentNode.removeChild(last)}, }]).first diff --git a/pane/Storm.js b/pane/Storm.js index 88c7bf26..97059523 100644 --- a/pane/Storm.js +++ b/pane/Storm.js @@ -49,9 +49,18 @@ Volcanos("onchoice", {help: "组件菜单", list: ["创建", "刷新"], }) }, }) -Volcanos("ondetail", {help: "组件详情", list: ["保存", "恢复", "删除"], +Volcanos("ondetail", {help: "组件详情", list: ["保存", "恢复", "重命名", "删除"], + "重命名": function(event, can, line, value, cmd, item) { + can.user.prompt("输入新名:", function(name) { + can.run(event, [can.Conf("river"), value, "rename", name], function(msg) { + can.run(event, [can.Conf("river")], function(msg) { + can.onimport.init(event, can, msg, cmd, can.output) + }) + }) + }) + }, "删除": function(event, can, line, value, cmd, item) { - can.run(event, [can.Conf("river"), "delete", value], function(msg) { + can.run(event, [can.Conf("river"), value, "remove"], function(msg) { can.run(event, [can.Conf("river")], function(msg) { can.onimport.init(event, can, msg, cmd, can.output) }) diff --git a/pane/Toast.css b/pane/Toast.css index 615c1705..76300c23 100644 --- a/pane/Toast.css +++ b/pane/Toast.css @@ -1,23 +1,23 @@ -fieldset.dialog.Toast { +fieldset.Toast { border:solid 2px red; - background-color:#ffffff; + background-color:rgba(100,100,100,0.8); position:absolute; display:none; z-index:200; } -fieldset.dialog.Toast>div.action { +fieldset.Toast>div.action { padding:0 0px; } -fieldset.dialog.Toast>div.output { +fieldset.Toast>div.output { padding:0 10px; text-align:center; } -fieldset.dialog.Toast>div.output>div.title { +fieldset.Toast>div.output>div.title { font-size:12px; text-align:center; color:gray; } -fieldset.dialog.Toast>div.output>div.content { +fieldset.Toast>div.output>div.content { word-break:break-word; white-space:pre-wrap; text-align:center; @@ -25,7 +25,16 @@ fieldset.dialog.Toast>div.output>div.content { padding:2px; font-size:16px; } -fieldset.dialog.Toast>div.output>div.tick { +fieldset.Toast>div.output table { + color:yellow +} +fieldset.Toast>div.output table th { + background:red; +} +fieldset.Toast>div.output table td { + white-space:pre; +} +fieldset.Toast>div.output>div.tick { font-size:12px; color:gray; } diff --git a/pane/Toast.js b/pane/Toast.js index 95eac1b2..06e5e5c7 100644 --- a/pane/Toast.js +++ b/pane/Toast.js @@ -18,8 +18,8 @@ Volcanos("onimport", {help: "导入数据", list: [], var toast = can.page.Appends(can, output, list) var width = text.width||text.text.length*10+100 - width = width>400?400:width - can.Show(event, width, text.height||80) + width = width>800?800:width + can.Show(event, text.width==undefined? width: text.width, text.height==undefined? 80: text.height) var begin = can.base.Time().split(" ")[1] var timer = can.Timer({value: 1000, length: text.duration > 0? text.duration/1000: text.duration}, function(t, i) { diff --git a/plugin/inner.js b/plugin/inner.js index e654de17..e275549e 100644 --- a/plugin/inner.js +++ b/plugin/inner.js @@ -1,5 +1,30 @@ Volcanos("onimport", {help: "导入数据", list: [], init: function(can, msg, cb, output, option) {output.innerHTML = msg.Result(); + can.page.Select(can, output, "table", function(table) { + can.page.OrderTable(can, table) + }) + can.page.Select(can, output, ".story", function(story) {var data = story.dataset||{}; + story.oncontextmenu = function(event) { + can.user.carte(event, shy("", can.ondetail, can.feature.detail || can.ondetail.list, function(event, cmd, meta) {var cb = meta[cmd]; + + typeof cb == "function"? cb(event, can, msg, cmd, story): + can.run(event, ["story", typeof cb == "string"? cb: cmd, data.type, data.name, data.text], function(msg) { + var timer = msg.Result()? can.user.toast(msg.Result()): can.user.toast({ + duration: -1, text: cmd, width: 800, height: 400, + list: [{type: "table", list: [{row: msg.append, sub: "th"}].concat(msg.Table(function(line, index) { + return {row: can.core.List(msg.append, function(key) {return msg[key][index]})} + }))}, {button: ["关闭", function(event) {timer.stop = true}]}], + }) + }, true) + })) + } + }) + return + can.page.Select(can, output, "ul.premenu", function(pre) { + can.page.Select(can, output, "ul.endmenu", function(end) { + can.page.CopySub(can, pre, end) + }) + }) can.page.Select(can, output, "svg", function(svg) { svg.onclick = function(event) {var item = event.target; switch (event.target.tagName) { @@ -54,7 +79,7 @@ Volcanos("onchoice", {help: "组件菜单", list: ["返回", "清空", "复制", Volcanos("ondetail", {help: "组件详情", list: ["选择", "修改", "复制"], "选择": "select", "删除": "delete", - "复制": function(event, can, msg, key, svg) { + "复制": function(event, can, msg, cmd, target) { can.user.toast(can.page.CopyText(can, svg.innerHTML), "复制成功") }, }) diff --git a/plugin/input.js b/plugin/input.js index ccb859c4..861e47c7 100644 --- a/plugin/input.js +++ b/plugin/input.js @@ -1,6 +1,7 @@ Volcanos("onimport", {help: "导入数据", list: [], init: shy("添加控件", function(can, item, name, value, option) { var input = {type: "input", name: name, data: item}; + item.type = item.type || item._type; switch (item.type) { case "upfile": item.type = "file"; break case "select": diff --git a/plugin/table.js b/plugin/table.js index b0e02aba..b7569c3d 100644 --- a/plugin/table.js +++ b/plugin/table.js @@ -78,7 +78,7 @@ Volcanos("ondetail", {help: "组件详情", list: ["选择", "编辑", "删除", var text = td.innerHTML; can.page.Appends(can, td, [{type: "input", style: {width: td.clientWidth+"px"}, data: {onkeydown: function(event) { if (event.key != "Enter") {return} - can.run(event, [msg.Ids(index), "modify", key == "value" && msg.key? msg[key][index]: key, event.target.value,], function(msg) { + can.run(event, [msg.Ids(index), "modify", key == "value" && msg.key? msg[key][index]: key, event.target.value, text], function(msg) { td.innerHTML = event.target.value; can.user.toast("修改成功") }, true) diff --git a/proto.js b/proto.js index 518853ac..ddc17c23 100644 --- a/proto.js +++ b/proto.js @@ -111,7 +111,7 @@ function Volcanos(name, can, libs, cb, msg) { // 封装模块 return can.core.List(msg[max], function(value, index, array) {var one = {}, res; can.core.List(msg.append, function(key) {one[key] = msg[key][index]||""}) - return typeof cb == "function" && (res = cb(one, index, array)) && res != undefined || one + return typeof cb == "function" && (res = cb(one, index, array)) && res != undefined && res || one }) }), Result: function() { diff --git a/style.css b/style.css index aa38b582..1aebac62 100644 --- a/style.css +++ b/style.css @@ -83,23 +83,6 @@ fieldset>div.output div.item.select { background-color:red; border:ridge 2px yellow; } -fieldset>div.output div.code { - color:white; - font-size:14px; - font-family:monospace; - background-color:#272822; - white-space:pre; - padding:10px; - overflow:auto; - border:solid 3px green; - max-height:640px; -} -fieldset>div.output div.code span.red { - color:red; -} -fieldset>div.output div.code span.green { - color:green; -} fieldset>div.output table td { /* word-break:break-word; */ } @@ -194,11 +177,6 @@ fieldset.item>div.output>div.status>input.cmd { font-size:16px; width:250px; } -fieldset.item>div.output>div.code { -} -fieldset.item>div.output>div.code div.number { - float:left; -} fieldset table { font-size:14px; @@ -244,3 +222,21 @@ fieldset table td:hover { fieldset table td.select { background-color:red; } + +fieldset div.code { + color:white; + font-size:14px; + font-family:monospace; + background-color:#272822; + white-space:pre; + padding:10px; + overflow:auto; + border:solid 3px green; + max-height:640px; +} +fieldset div.code span.red { + color:red; +} +fieldset div.code span.green { + color:green; +}