diff --git a/frame.js b/frame.js index 3f54351c..0848b49f 100644 --- a/frame.js +++ b/frame.js @@ -130,7 +130,7 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, sub.page.ClassList.add(sub, field, meta.style||meta.feature.style||"") sub.page.Modify(sub, sub._legend, {onmouseenter: function(event) { - sub.user.carte(event, sub, sub.onaction, sub.onaction.list.concat([["所有 ->"].concat(can.core.Item(meta.feature._trans))])) + sub.user.carte(event, sub, sub.onaction, sub.onaction.list.concat([["所有 ->"].concat(can.core.Item(meta.feature._trans))], ["close"])) }}) meta.inputs && sub.onappend._option(sub, meta, sub._option) @@ -157,7 +157,7 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, (item.action||meta.feature["inputs"]) && can.onappend.figure(input, item, input._target) }) - }; can.core.Next(can.base.Obj(meta.inputs, []), add) + }; can.core.Next(can.base.Obj(meta.inputs, []).concat(meta.type == chat.FLOAT? [{type: html.BUTTON, name: cli.CLOSE}]: []), add) }, _action: function(can, list, action, meta) { action = action||can._action, meta = meta||can.onaction can.core.List(list||can.onaction.list, function(item) { can.onappend.input(can, item == ""? /*空白*/ {type: html.SPACE}: @@ -249,7 +249,7 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, var title = !item.help || can.user.language(can) == "en"? name: name+"("+item.help.split(ice.SP)[0]+")" return can.page.Append(can, target||can._output, [{view: [can.base.join([type||"", item.name||"", item.pos||""]), html.FIELDSET], list: [ name && {text: [title, html.LEGEND]}, - can.user.mod.isCmd && type == chat.PLUGIN && {view: [html.LEGEND, html.DIV, title]}, + (can.user.mod.isCmd && type == chat.PLUGIN || type == chat.FLOAT) && {view: [html.LEGEND, html.DIV, title]}, {view: [html.OPTION, html.FORM]}, {view: [html.ACTION]}, {view: [html.OUTPUT]}, {view: [html.STATUS]}, ]}]) }, diff --git a/lib/base.js b/lib/base.js index 13913e18..ef6efb76 100644 --- a/lib/base.js +++ b/lib/base.js @@ -58,6 +58,13 @@ Volcanos("base", {help: "数据类型", } return res.join("&") }, + ParseURL: function(url) { var res = {link: url} + var list = url.split("?"); res["origin"] = list[0] + list[1] && list[1].split("&").forEach(function(item) { + var ls = item.split("="); res[decodeURIComponent(ls[0])] = decodeURIComponent(ls[1]) + }) + return res + }, MergeURL: function(url) { var args = {} var arg = url.split("?")[1]||"" arg && arg.split("&").forEach(function(item) { @@ -224,5 +231,11 @@ Volcanos("base", {help: "数据类型", isFunc: function(cb) { return typeof cb == "function" }, isUndefined: function(arg) { return arg == undefined }, isNull: function(arg) { return arg == null }, + joins: function(list) { + for (var i = 0; i < list.length; i++) { + list[i] = typeof list[i] == lang.STRING? list[i]: list[i].join(ice.FS) + } + return list.join(ice.SP) + }, }) diff --git a/lib/core.js b/lib/core.js index e98bcca9..d37d6ca2 100644 --- a/lib/core.js +++ b/lib/core.js @@ -182,13 +182,18 @@ Volcanos("core", {help: "数据结构", } return list }), - ItemCB: shy("迭代器", function(obj, cb) { var list = [] - for (var k in obj) { - if (k.indexOf("on") == 0 && typeof obj[k] == lang.FUNCTION) { - cb(k, obj[k]) + ItemCB: shy("迭代器", function(meta, cb, can, item) { var list = [] + for (var k in meta) { (function(k) { + if (k.indexOf("on") == 0 && typeof meta[k] == lang.FUNCTION) { + if (typeof cb == lang.FUNCTION) { + cb(k, meta[k]) + } else { + cb[k] = function(event) { meta[k](event, can, item) } + } list.push(k) } - } + })(k) } + return list }), }) diff --git a/page/index.css b/page/index.css index 0e54a833..31210f51 100644 --- a/page/index.css +++ b/page/index.css @@ -221,6 +221,15 @@ legend { fieldset { margin:0; border:0; padding:0; } +fieldset>div.legend { + float:left; padding:0 10px; margin-right:3px; + height:25px; font-size:18px; + background-color:darkcyan; + cursor:pointer; +} +fieldset>div.legend { + background-color:honeydew; +} fieldset>form.option { float:left; display:contents; diff --git a/panel/cmd.css b/panel/cmd.css index 60752364..7bb1aacf 100644 --- a/panel/cmd.css +++ b/panel/cmd.css @@ -1,3 +1,6 @@ +fieldset.panel.cmd>div.legend { + display:none; +} fieldset.panel.cmd>div.output>fieldset.plugin { margin:0; padding:0; } diff --git a/plugin/local/wiki/draw.js b/plugin/local/wiki/draw.js index aba01265..bdbc0910 100644 --- a/plugin/local/wiki/draw.js +++ b/plugin/local/wiki/draw.js @@ -109,7 +109,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, var figure = can.onfigure[value.shape] var data = figure.draw(event, can, value.point, value.style) can.core.Item(value.style, function(key, value) { data[key] = value }) - var item = can.onfigure._push(can, value.shape, data, can.group||can.svg) + var item = can.onfigure._push(can, figure.data.name||value.shape, data, can.group||can.svg) can.core.ItemCB(value, function(key, cb) { item[key] = cb }) can.onimport._block(can, item), can.onfigure._pid(can, item) return value._init && value._init(item), item diff --git a/plugin/local/wiki/draw/path.js b/plugin/local/wiki/draw/path.js index 2a5aad96..eda19c1f 100644 --- a/plugin/local/wiki/draw/path.js +++ b/plugin/local/wiki/draw/path.js @@ -1,5 +1,23 @@ Volcanos("onfigure", {help: "图形绘制", list: [], - path: { // + path2v: { // + data: {name: "path", size: {}, copy: []}, + draw: function(event, can, point) { + function line(p0, p1) { return can.base.joins([ + svg.M, [p0.x, p0.y], svg.Q, [p0.x, p0.y+(p1.y-p0.y)/3], [(p0.x+p1.x)/2, (p0.y+p1.y)/2], svg.T, [p1.x, p1.y] + ]) } + return {fill: html.NONE, d: line(point[0], point[1])} + }, + }, + path2h: { // + data: {name: "path", size: {}, copy: []}, + draw: function(event, can, point) { + function line(p0, p1) { return can.base.joins([ + svg.M, [p0.x, p0.y], svg.Q, [p0.x+(p1.x-p0.x)/3, p0.y], [(p0.x+p1.x)/2, (p0.y+p1.y)/2], svg.T, [p1.x, p1.y] + ]) } + return {fill: html.NONE, d: line(point[0], point[1])} + }, + }, + path: { // data: {size: {}, copy: ["d", "tt", "xx", "yy"], x: function(can, value, cmd, target) { var tt = JSON.parse(target.Value("tt")||'{"tx":0, "ty":0}') diff --git a/plugin/story/spide.js b/plugin/story/spide.js index c40633f6..b8a7d881 100644 --- a/plugin/story/spide.js +++ b/plugin/story/spide.js @@ -2,16 +2,17 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, can.onmotion.clear(can), can.base.isFunc(cb) && cb(msg) if (msg.Option("branch")) { return can.onappend.table(can, msg) } - can._tree = can.onimport._tree(can, msg.Table(), nfs.PATH, ice.PS) + can._args = can.base.Copy({root: "root", field: nfs.PATH, split: ice.PS}, can.base.ParseURL(can._display)) + can._tree = can.onimport._tree(can, msg.Table(), can._args.field, can._args.split) if (!can._tree[""]) { return } - can.dir_root = msg.Option(nfs.DIR_ROOT) - can._tree[""].name = can.dir_root.split(ice.PS).slice(-2)[0] + can.dir_root = msg.Option(nfs.DIR_ROOT)||can._args.root + can._tree[""].name = can.dir_root.split(can._args.split).slice(-2)[0] can.size = 30, can.margin = 30 can.require(["/plugin/local/wiki/draw.js", "/plugin/local/wiki/draw/path.js"], function() { can.page.ClassList.add(can, can._fields, "draw") can.onimport._show(can, msg), can.onmotion.hidden(can, can.ui.project) - var p = can.Action("view", can.sup.view||can.Action("view")) + var p = can.Action(ice.VIEW, can.sup.view||can.Action(ice.VIEW)) can.onaction[p](event, can, p) }) }, @@ -19,136 +20,104 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, _tree: function(can, list, field, split) { var node = {}; can.core.List(list, function(item) { item[field] && can.core.List(item[field].split(split), function(value, index, array) { - var last = array.slice(0, index).join(split) || "", name = array.slice(0, index+1).join(split) + var last = array.slice(0, index).join(split)||"", name = array.slice(0, index+1).join(split) if (!value || node[name]) { return } node[last] = node[last]||{name: last, meta: {}, list: []} node[last].list.push(node[name] = { name: value+(index==array.length-1? "": split), meta: item, list: [], last: last, - file: item[field], hide: true, + file: item[field]||item.file, hide: true, }) }) }) return node }, - _height: function(can, tree) { if (!tree) { return 0 } + _height: function(can, tree, deep) { if (!tree) { return 0 } + tree.deep = deep||0 if (tree.list.length == 0 || tree.hide) { return tree.height = 1 } var height = 0; can.core.List(tree.list, function(item) { - height += can.onimport._height(can, item) + height += can.onimport._height(can, item, (deep||0)+1) }) return tree.height = height }, - _width: function(can, tree) { if (!tree) { return 0 } + _width: function(can, tree, deep) { if (!tree) { return 0 } + tree.deep = deep||0 if (tree.list.length == 0 || tree.hide) { - tree.view = can.onimport.draw({}, can, { - shape: "text", point: [{x: 0, y: 0}], style: { - "stroke-width": 1, "text-anchor": "middle", inner: tree.name, - }, - }) + tree.view = can.onimport.draw({}, can, {shape: html.TEXT, point: [{x: 0, y: 0}], style: {inner: tree.name}}) return tree.width = tree.view.Val("textLength")+can.margin } var width = 0; can.core.List(tree.list, function(item) { - width += can.onimport._width(can, item) + width += can.onimport._width(can, item, (deep||0)+1) }) return tree.width = width }, + _color: function(can, tree) { + return tree.meta&&tree.meta.color || (tree.list == 0? cli.PURPLE: cli.YELLOW) + }, }, [""]) -Volcanos("onaction", {help: "用户操作", list: ["编辑", ["view", "横向", "纵向"]], +Volcanos("onaction", {help: "用户操作", list: ["编辑", [ice.VIEW, "横向", "纵向"]], "编辑": function(event, can) { can.onmotion.toggle(can, can._action) can.onmotion.toggle(can, can._status) }, - "横向": function(event, can, button) { - can.sup.view = button - can.onmotion.clear(can, can.svg) + "横向": function(event, can) { can.onimport._height(can, can._tree[""]) + can.sup.view = "横向", can.onmotion.clear(can, can.svg) can.svg.Val(chat.HEIGHT, can._tree[""].height*can.size+2*can.margin) can.width = 0, can.onaction._draw(can, can._tree[""], can.margin, can.margin) can.svg.Val(chat.WIDTH, can.width+can.margin) }, - "纵向": function(event, can, button) { - can.sup.view = button + "纵向": function(event, can) { can.onimport._width(can, can._tree[""]) - can.onmotion.clear(can, can.svg) + can.sup.view = "纵向", can.onmotion.clear(can, can.svg) can.svg.Val(chat.WIDTH, can._tree[""].width+2*can.margin) - can.svg.Value("font-family", "monospace") can.height = 0, can.onaction._draw_vertical(can, can._tree[""], can.margin, can.margin+can.size) can.svg.Val(chat.HEIGHT, can.height+can.margin) }, _draw_vertical: function(can, tree, x, y) { tree.x = x, tree.y = y - var color = tree.meta&&tree.meta.color||cli.YELLOW + var color = can.onimport._color(can, tree) tree.view = can.onimport.draw({}, can, { - shape: "text", point: [ - {x: x+tree.width/2, y: y} - ], style: { - "stroke-width": 1, "stroke": color, - "fill": color, "text-anchor": "middle", inner: tree.name, + shape: html.TEXT, point: [{x: x+tree.width/2, y: y}], style: { + stroke: color, fill: color, "text-anchor": "middle", inner: tree.name, }, - }) + }), can.core.ItemCB(can.ondetail, tree.view, can, tree) - can.core.ItemCB(can.ondetail, function(key, cb) { - tree.view[key] = function(event) { cb(event, can, tree) } - }) tree.height = can.size if (y+tree.height > can.height) { can.height = y+tree.height } if (tree.hide) { return } - function line(p0, p1) { - return "M "+p0.x+","+p0.y+" Q "+p0.x+","+(p0.y+(p1.y-p0.y)/3)+" "+(p0.x+p1.x)/2+","+(p0.y+p1.y)/2+" T "+p1.x+","+p1.y - } - var offset = 0; can.core.List(tree.list, function(item) { - can.onimport.draw({}, can, { - shape: "path", point: [], style: { - "stroke-width": 1, "stroke": cli.CYAN, "fill": html.NONE, d: line( - {x: x+tree.width/2, y: y+tree.height-can.margin/2}, - {x: x+offset+item.width/2, y: y+tree.height+can.margin/2}, - ), - }, - }) + can.onimport.draw({}, can, {shape: "path2v", point: [ + {x: x+tree.width/2, y: y+tree.height-can.margin/2}, + {x: x+offset+item.width/2, y: y+tree.height+can.margin/2}, + ], style: {stroke: cli.CYAN}}) can.onaction._draw_vertical(can, item, x+offset, y+tree.height+can.margin) offset += item.width }) }, - _draw: function(can, tree, x, y) { tree.x = x, tree.y = y - var color = tree.meta&&tree.meta.color||cli.YELLOW + var color = can.onimport._color(can, tree) tree.view = can.onimport.draw({}, can, { - shape: "text", point: [ - {x: x, y: y+tree.height*can.size/2} - ], style: { - "stroke-width": 1, "stroke": color, - "fill": color, "text-anchor": "start", inner: tree.name, + shape: html.TEXT, point: [{x: x, y: y+tree.height*can.size/2}], style: { + stroke: color, fill: color, "text-anchor": "start", inner: tree.name, }, - }) + }), can.core.ItemCB(can.ondetail, tree.view, can, tree) tree.width = tree.view.Val("textLength") if (x+tree.width > can.width) { can.width = x+tree.width } - - can.core.ItemCB(can.ondetail, function(key, cb) { - tree.view[key] = function(event) { cb(event, can, tree) } - }) if (tree.hide) { return } - function line(p0, p1) { - return "M "+p0.x+","+p0.y+" Q "+(p0.x+(p1.x-p0.x)/3)+","+p0.y+" "+(p0.x+p1.x)/2+","+(p0.y+p1.y)/2+" T "+p1.x+","+p1.y - } - var offset = 0; can.core.List(tree.list, function(item) { - can.onimport.draw({}, can, { - shape: "path", point: [], style: { - "stroke-width": 1, "stroke": cli.CYAN, "fill": html.NONE, d: line( - {x: x+tree.width+can.margin/8, y: y+tree.height*can.size/2}, - {x: x+tree.width+can.margin*2-2*can.margin/8, y: y+offset+item.height*can.size/2} - ), - }, - }) + can.onimport.draw({}, can, {shape: "path2h", point: [ + {x: x+tree.width+can.margin/8, y: y+tree.height*can.size/2}, + {x: x+tree.width+can.margin*2-2*can.margin/8, y: y+offset+item.height*can.size/2} + ], style: {stroke: cli.CYAN}}) can.onaction._draw(can, item, x+tree.width+2*can.margin, y+offset) offset += item.height*can.size @@ -158,63 +127,62 @@ Volcanos("onaction", {help: "用户操作", list: ["编辑", ["view", "横向", Volcanos("ondetail", {help: "用户交互", list: [], onmouseenter: function(event, can, tree) { var y = tree.y+tree.height*can.size/2 can.page.Remove(can, can.pos), can.pos = can.onimport.draw({}, can, { - shape: "rect", point: [ + shape: html.RECT, point: [ {x: tree.x-can.margin/4, y: y-can.size/2}, {x: tree.x+tree.width+can.margin/8, y: y+can.size/2}, - ], style: { - "stroke": cli.RED, "stroke-width": 2, "fill": html.NONE, - }, + ], style: {stroke: cli.RED, fill: html.NONE}, }), event.stopPropagation(), event.preventDefault() }, onclick: function(event, can, tree) { - if (tree.name.endsWith(ice.PS) || tree.tags) { - tree.hide = !tree.hide, can.onaction[can.Action("view")](event, can) - return + if (tree.list.length > 0 || tree.tags || tree.name.endsWith(can._args.split)) { + return tree.hide = !tree.hide, can.onaction[can.Action(ice.VIEW)](event, can) } - if (tree.name.endsWith(".go") || tree.name.endsWith(".c") || tree.name.endsWith(".h")) { - can.run(event, [can.Option(kit.MDB_NAME), tree.file], function(msg) { - msg.Table(function(value) { tree.tags = true - tree.list.push({type: "tags", file: value.file, line: value.line, name: value.name, last: tree, list: []}) - }) + can.run(event, (can._args.prefix? [can._args.prefix]: []).concat([can.Option(kit.MDB_NAME)||"", tree.file||"", tree.name]), function(msg) { + if (msg.Length() == 0) { + return can.ondetail.plugin(can, "web.code.inner", [can.dir_root, tree.file, tree.line], [ctx.ACTION, "inner"]) + } + if (msg.Append(kit.MDB_INDEX)) { msg.Table(function(value) { + can.ondetail.plugin(can, value.index, [], [ctx.ACTION, ice.RUN, value.index]) + }); return } - tree.hide = !tree.hide, can.onaction[can.Action("view")](event, can) - }, true) - return - } - - can.ondetail.plugin(event, can, [can.dir_root, tree.file, tree.line]) + msg.Table(function(value) { tree.tags = true + tree.list.push({type: "tags", file: value.file, line: value.line, name: value.name, last: tree, list: []}) + }), tree.hide = !tree.hide, can.onaction[can.Action(ice.VIEW)](event, can) + }, true) }, - plugin: function(event, can, args) { - can.onappend.plugin(can, {type: chat.FLOAT, index: "web.code.inner", args: args, _action: [cli.CLOSE]}, function(sub) { + plugin: function(can, index, args, prefix) { + can.onappend.plugin(can, {type: chat.FLOAT, index: index, args: args}, function(sub) { sub.run = function(event, cmds, cb) { - can.run(event, can.misc.Concat([ctx.ACTION, "inner"], cmds), function(msg) { - msg.Option(ice.MSG_ACTION, cli.CLOSE) - can.get("Action", "size", function(left, top, width, height) { left = left||0 - if (height > window.innerHeight) { height = window.innerHeight } - var top = 120, margin = 20; if (can.user.isMobile) { margin = 0 - if (can.user.isLandscape()) { - height += (can.user.mod.isCmd? -20: 200) - top = 24, sub.Conf(chat.HEIGHT, height-top) - } else { - height += (can.user.mod.isCmd? -80: 200) - top = 48, sub.Conf(chat.HEIGHT, height-top) - } - } else { - height += (can.user.mod.isCmd? 0: 300) - sub.Conf(chat.HEIGHT, height-top) - } - - var layout = {position: "fixed", left: left+margin, top: top} - can.onmotion.move(can, sub._target, layout) - can.page.Modify(can, sub._target, {style: layout}) - can.page.Modify(can, sub._output, {style: {"max-width": width-margin*2}}) - can.base.isFunc(cb) && cb(msg) - }) + can.run(event, can.misc.Concat(prefix, cmds), function(msg) { + can.ondetail.figure(can, sub, msg, cb) }, true) } }) }, + figure: function(can, sub, msg, cb) { + can.get("Action", "size", function(left, top, width, height) { left = left||0 + if (height > window.innerHeight) { height = window.innerHeight } + var top = 120, margin = 20; if (can.user.isMobile) { margin = 0 + if (can.user.isLandscape()) { + height += (can.user.mod.isCmd? -20: 200) + top = 24, sub.Conf(chat.HEIGHT, height-top) + } else { + height += (can.user.mod.isCmd? -80: 200) + top = 48, sub.Conf(chat.HEIGHT, height-top) + } + } else { + height += (can.user.mod.isCmd? 0: 300) + sub.Conf(chat.HEIGHT, height-top) + } + + var layout = {position: "fixed", left: left+margin, top: top} + can.onmotion.move(can, sub._target, layout) + can.page.Modify(can, sub._target, {style: layout}) + can.page.Modify(can, sub._output, {style: {"max-width": width-margin*2}}) + can.base.isFunc(cb) && cb(msg) + }) + }, }) diff --git a/proto.js b/proto.js index bcc3a592..4293ce0f 100644 --- a/proto.js +++ b/proto.js @@ -24,7 +24,7 @@ var ice = { TRUE: "true", SUCCESS: "success", FAILURE: "failure", PROCESS: "process", - AUTO: "auto", + AUTO: "auto", VIEW: "view", COPY: "copy", SHOW: "show", HIDE: "hide", MODE: "mode", SHIP: "ship", MSG_USERNAME: "user.name", @@ -60,7 +60,7 @@ var cli = { CLEAR: "clear", REFRESH: "refresh", RED: "red", GREEN: "green", BLUE: "blue", - YELLOW: "yellow", CYAN: "cyan", PURPLE: "purple", + YELLOW: "yellow", CYAN: "cyan", PURPLE: "purple", MAGENTA: "magenta", WHITE: "white", BLACK: "black", } var web = { @@ -130,6 +130,9 @@ var mall = { ASSET: "asset", SALARY: "salary", } +var svg = { + M: "M", Q: "Q", T: "T", +} var html = { FIELDSET: "fieldset", LEGEND: "legend", OPTION: "option", ACTION: "action", OUTPUT: "output", STATUS: "status", FORM_OPTION: "form.option", DIV_ACTION: "div.action", DIV_OUTPUT: "div.output", DIV_STATUS: "div.status", @@ -140,7 +143,7 @@ var html = { TABLE: "table", TR: "tr", TH: "th", TD: "td", BR: "br", DIV: "div", IMG: "img", CODE: "code", SPAN: "span", VIDEO: "video", - SVG: "svg", G: "g", X: "x", Y: "y", R: "r", + SVG: "svg", G: "g", X: "x", Y: "y", R: "r", RECT: "rect", LABEL: "label", INNER: "inner", CLASS: "class", BLOCK: "block", NONE: "none", @@ -202,12 +205,12 @@ var Volcanos = shy("火山架", {iceberg: "/chat/", volcano: "/frame.js", args: } if (!libs[0]) { return can.require(libs.slice(1), cb, each) } - libs[0] = libs[0].toLowerCase() // 请求模块 - function next() { can._load(libs[0], each), can.require(libs.slice(1), cb, each) } - meta.cache[libs[0]]? next(): meta._load(libs[0], next) + var name = libs[0].split("?")[0] + function next() { can._load(name, each), can.require(libs.slice(1), cb, each) } + meta.cache[name]? next(): (_can_path = libs[0], meta._load(name, next)) }, request: function(event, option) { event = event||{} var msg = event._msg||can.misc.Message(event, can); event._msg = msg @@ -260,7 +263,7 @@ var Volcanos = shy("火山架", {iceberg: "/chat/", volcano: "/frame.js", args: } return can.require(libs, cb), can }) -Volcanos.meta._load = function(url, cb) { _can_path = url +Volcanos.meta._load = function(url, cb) { switch (url.split("?")[0].split(ice.PT).pop().toLowerCase()) { case "css": var item = document.createElement(kit.MDB_LINK)