diff --git a/frame.js b/frame.js index ae3600bf..3dfd5e46 100644 --- a/frame.js +++ b/frame.js @@ -380,6 +380,7 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, input: function(can, item, value, target) { switch (item.type) { case "space": return can.page.Append(can, target, [{view: "item space"}]) + case "": return can.page.Append(can, target, [item]) } var input = {type: "input", name: item.name, data: item, dataset: {}} @@ -416,8 +417,12 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, return can.page.Append(can, target, [{view: ["item "+item.type], list: [input]}])[item.name] }, table: function(can, msg, cb, target, list) { - var table = can.page.AppendTable(can, msg, target||can._output, msg.append, cb||function(value) { - return {text: [value, "td"]} + var table = can.page.AppendTable(can, msg, target||can._output, msg.append, cb||function(value, key) { + return {text: [value, "td"], onclick: function(event) { + can.sup.onaction.change(event, can.sup, key, value, function(msg) { + can.onimport._init(can, msg, list, cb, can._output) + }) + }} }); table && can.page.Modify(can, table, {className: "content"}) list && can.page.RangeTable(can, table, list) return table @@ -455,7 +460,7 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, meta.name = meta.name||value.name||"story" meta.help = meta.help||value.help||"story" meta.width = meta.width||can.Conf("width") - meta.height = meta.width||can.Conf("height") + meta.height = meta.height||can.Conf("height") meta.type = meta.type||"story" can.onappend._init(can, meta, ["/plugin/state.js"], function(sub) { diff --git a/lib/core.js b/lib/core.js index a5f3348d..f3b71c36 100644 --- a/lib/core.js +++ b/lib/core.js @@ -50,7 +50,7 @@ Volcanos("core", {help: "核心模块", function next(list, cb, index) { list && list.length > 0? typeof cb == "function" && cb(list[0], function() { list.length > 0 && next(list.slice(1), cb, index+1) - }, index): typeof cbs == "function" && cbs() + }, index, obj): typeof cbs == "function" && cbs() } next(obj, cb, 0) }), diff --git a/page/index.css b/page/index.css index d4375528..67ad0f4c 100644 --- a/page/index.css +++ b/page/index.css @@ -322,7 +322,7 @@ div.toast { position:fixed; overflow:auto; padding:5px; - z-index:20; + z-index:100; } div.toast div.title { font-size:14px; diff --git a/pane/Action.js b/pane/Action.js index 002dfdc2..906019c2 100644 --- a/pane/Action.js +++ b/pane/Action.js @@ -8,14 +8,16 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg) can.onappend.plugin(can, item, function(sub, meta) { can.onimport._plugin(can, river, storm, sub, meta), next() + sub._option.dataset.id = item.id }) }) }, _plugin: function(can, river, storm, sub, item) { - sub.run = function(event, cmds, cb) { var msg = sub.request(event) var toast = msg.Option("_toast") && can.user.toast(can, msg.Option("_toast"), "", 1000000) return can.run(event, (can.onengine[cmds[0]]? []: [river, storm, item.id||item.index||item.key+"."+item.name]).concat(cmds), function(msg) { + console.log(sub) + console.log(item) toast && toast.Close(), typeof cb == "function" && cb(msg) }) }, can._plugins = (can._plugins||[]).concat([sub]) @@ -129,9 +131,9 @@ Volcanos("onaction", {help: "交互操作", list: [], _init: function(can, msg, }) Volcanos("onexport", {help: "导出数据", list: [], args: function(can, msg, list, cb, target) { - can.core.Next(can.page.Select(can, target, "fieldset.plugin>form.option"), function(item, next) { + can.core.Next(can.page.Select(can, target, "fieldset.plugin>form.option"), function(item, next, index, array) { var list = can.page.Select(can, item, '.args', function(item) { return item.value||"" }) - item.dataset.args = JSON.stringify(list), cb(item, next) + item.dataset.args = JSON.stringify(list), cb(item, next, index, array) }) }, plugin: function(can, msg, word) { diff --git a/pane/River.js b/pane/River.js index 278b92b6..50081901 100644 --- a/pane/River.js +++ b/pane/River.js @@ -172,9 +172,10 @@ Volcanos("ondetail", {help: "菜单交互", list: ["共享群组", "添加用户 }) }, "保存参数": function(event, can, button, river, storm) { - can.run(event, ["search", "Action.onexport.args"], function(item, next) { + can.run(event, ["search", "Action.onexport.args"], function(item, next, index, array) { var msg = can.request({}, {hash: storm, id: item.dataset.id}) can.run(msg._event, [river, "tool", "action", "modify", "arg", item.dataset.args], function(msg) { + can.user.toast(can, "保存"+(index+1)+"/"+array.length) next() }) }) diff --git a/plugin/local/team/plan.js b/plugin/local/team/plan.js index b6ae0578..808fa8ac 100644 --- a/plugin/local/team/plan.js +++ b/plugin/local/team/plan.js @@ -4,6 +4,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, typeof cb == "function" && cb(msg) can.onmotion.hidden(can, can._action) can.onimport[can.Option("scale")||"week"](can, msg) + can.page.Modify(can, can.ui.profile, {style: {display: "block"}}) }, _content: function(can, msg, head, list, key, get, set) { var hash = {}; msg.Table(function(value, index) { diff --git a/plugin/local/wiki/draw.js b/plugin/local/wiki/draw.js index fd0761b9..416828df 100644 --- a/plugin/local/wiki/draw.js +++ b/plugin/local/wiki/draw.js @@ -1,83 +1,55 @@ -Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, list, cb, target) { can._output.innerHTML = "" - can.ui = can.onlayout.project(can) +Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, list, cb, target) { + can.onmotion.clear(can) + can.ui = can.onlayout.profile(can) + typeof cb == "function" && cb(msg) can.onmotion.hidden(can, can._action) // 交互数据 - can.point = [], can.keys = [] can.svg = null, can.group = null can.last = null, can.temp = null - can.current = null + can.point = [], can.current = null // 加载绘图 can.page.Modify(can, can.ui.content, msg.Result()||can.onexport.content(can)) - can.page.Select(can, can.ui.content, "svg", function(svg) { can.svg = can.group = svg - can.onimport.block(can, svg), can.onimport.group(can, svg).click() + can.page.Select(can, can.ui.content, "svg", function(svg) { can.page.Select(can, svg, "*", function(item, index) { - can.onimport.block(can, item); if (item.tagName == "g" && item.Value("class") != "") { - can.onimport.group(can, item) - } + item.tagName == "g"? can.onimport._group(can, item): can.onimport._block(can, item) }) + can.core.Item(can.onimport, function(key, value) { + key.indexOf("on") == 0 && (svg[key] = function(event) { value(event, can) }) + }) + can.svg = can.group = svg, can.onimport._group(can, svg).click() }) - // 加载事件 - can.core.Item(can.onaction, function(key, value) { - if (key.indexOf("on") == -1 || !can.onaction.hasOwnProperty(key)) { return } - can.svg[key] = can.ui.content[key] || function(event) { - value(event, can) - } - }) - - can.core.Timer(10, function() { - // 默认参数 - can.core.Item({ - "font-size": "24", - "stroke-width": 2, - "stroke": "yellow", - "fill": "purple", - "shape": "rect", - "grid": "10", - "go": "run", - }, function(key, value) { - can.svg.Value(key, can.Action(key, can.svg.Value(key)||value)) - }) - }) - return typeof cb == "function" && cb(msg) + // 默认参数 + can.core.Timer(10, function() { can.core.Item({ + "stroke-width": 2, "stroke": "yellow", "fill": "purple", "font-size": "24", + "shape": "rect", "grid": "10", "go": "run", + }, function(key, value) { can.svg.Value(key, can.Action(key, can.svg.Value(key)||value)) }) }) }, - group: function(can, target) { var name = target.Groups() || "svg" - return can.onappend.item(can, "item", {name: name}, function(event) { - can.group = target, can.core.List(["font-size", "storke-width", "stroke", "fill"], function(key) { + _group: function(can, target) { can.onimport._block(can, target) + function show(event) { can.group = target, can.ondetail["显示"](event, can) + can.core.List(["stroke-width", "stroke", "fill", "font-size"], function(key) { can.Action(key, target.Value(key)||can.Action(key)) - }), can.onmotion.show(can, 10, null, target) - }, function(event) { - can.user.carte(event, can, can.onaction||{}, ["隐藏", "显示", "添加", "删除", "清空"], function(ev, item, meta) { - switch (item) { - case "显示": - can.page.Select(can, can.ui.content, "g."+name, function(item) { - can.onmotion.show(can, 10, null, target) - }); break - case "隐藏": - can.page.Select(can, can.ui.content, "g."+name, function(item) { - can.onmotion.hide(can, {value: 100, length: 10}, null, target) - }); break - default: - can.onaction[item](event, can, item) - } }) + } + return can.onappend.item(can, "item", {name: target.Groups()}, show, function(event) { show(event) + can.user.carte(event, can, can.ondetail, ["隐藏", "显示", "添加", "删除", "清空"]) }, can.ui.project) }, - block: function(can, target) { + _block: function(can, target) { target.Val = function(key, value) { return parseInt(target.Value(key, value == undefined? value: parseInt(value)||0)) || 0 } - target.Value = function(key, value) { + target.Value = function(key, value) { if (typeof key == undefined) { return } if (typeof key == "object") { can.core.Item(key, target.Value); return } var figure = can.onfigure._get(can, target) - key && (key = figure && figure.data && figure.data.size && figure.data.size[key] || key) - + key = figure && figure.data && figure.data.size && figure.data.size[key] || key if (figure && figure.data && typeof figure.data[key] == "function") { - return figure.data[key](event, can, value, key, target) + return figure.data[key](can, value, key, target) } + if (key == "inner") { return value != undefined && (target.innerHTML = value), target.innerHTML } @@ -89,124 +61,69 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, || target[key]&&target[key].baseVal || "" } target.Group = function() { var item = target - while (item) { if (["svg", "g"].indexOf(item.tagName) > -1) { - return item - }; item = item.parentNode } + while (item) { if (["svg", "g"].indexOf(item.tagName) > -1) { return item }; item = item.parentNode } return can.svg } target.Groups = function() { var item = target - var list = [] - while (item && item.tagName != "svg") { - item.tagName == "g" && list.push(item.Value("class")) + var list = []; while (item && item.tagName != "svg") { + item.tagName == "g" && item.Value("class") && list.push(item.Value("class")) item = item.parentNode } return list.reverse().join(".") } - target.ondblclick = function(event) { - if (can.Action("go") == "run") { return } - can.ondetail["标签"](event, can) - event.stopPropagation() - event.preventDefault() - } return target }, - + _point: function(event, can) { + var p = can.svg.getBoundingClientRect() + var point = {x: event.clientX-p.x, y: event.clientY-p.y} + point.x = point.x - point.x % parseInt(can.Action("grid")) + point.y = point.y - point.y % parseInt(can.Action("grid")) + return can.Status("坐标", point.x+","+point.y), point + }, + _figure: function(event, can, points, target) { + can.temp && can.page.Remove(can, can.temp) && delete(can.temp) + can.temp = can.onaction._mode[can.Action("mode")](event, can, points, target) + can.point.length == 0 && delete(can.temp) + }, draw: function(event, can, value) { 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 }) return can.onfigure._push(can, data, value.shape, can.group||can.svg) }, - keydown: function(event, can, value) { - if (["Control", "Shift", "Meta", "Alt"].indexOf(value) > -1 ) {return} - can.keys.push((event.ctrlKey? "C-": "") + (event.shiftKey? value.toUpperCase(): value)) - if (value == "Escape") { - can.point = [], delete(can.temp) - return - } - var list = { - g: {prefix: ["go", "go"], - r: {list: ["run"]}, - a: {list: ["auto"]}, - m: {list: ["manual"]}, - }, - a: {prefix: ["mode", "mode"], - d: {list: ["draw"]}, - r: {list: ["resize"]}, - }, - s: {prefix: ["shape", "shape"], - s: {list: ["line"]}, - r: {list: ["rect"]}, - c: {list: ["circle"]}, - e: {list: ["ellipse"]}, - l: {list: ["line"]}, - p: {list: ["path"]}, - }, - c: {prefix: ["stroke", "stroke"], - r: {list: ["red"]}, - b: {list: ["blue"]}, - g: {list: ["green"]}, - y: {list: ["yellow"]}, - p: {list: ["purple"]}, - c: {list: ["cyan"]}, - h: {list: ["black"]}, - w: {list: ["white"]}, - }, - f: {prefix: ["fill", "fill"], - r: {list: ["red"]}, - b: {list: ["blue"]}, - g: {list: ["green"]}, - y: {list: ["yellow"]}, - p: {list: ["purple"]}, - c: {list: ["cyan"]}, - h: {list: ["black"]}, - w: {list: ["white"]}, - }, - } - - var prefix = [] - can.core.List(can.keys, function(key) { - if (!list) { - // 查找失败 - return can.keys = [], can.Status("按键", can.keys) - } - - // 查找递进 - prefix = prefix.concat(can.core.List(list.prefix)) - list = list[key] - }) - - if (!list || !list.list) { - // 等待输入 - return can.Status("按键", can.keys+"("+can.core.Item(list).join(",")+")") - } - - function call(cmds) { - cmds && can.onaction[cmds[0]] && can.onaction[cmds[0]].apply(can, [event, can].concat(cmds.slice(1))) - } - - // 执行命令 - call(prefix.concat(list.list)) - return can.keys = [], can.Status("按键", can.keys) + ondblclick: function(event, can) { + if (can.Action("go") == "run") { return } + can.ondetail["标签"](event, can) }, + onclick: function(event, can) { var point = can.onimport._point(event, can) + if (can.Action("go") == "run") { return can.onaction._mode.run(event, can) } + can.onimport._figure(event, can, can.point = can.point.concat(point), event.target) + }, + onmousemove: function(event, can) { var point = can.onimport._point(event, can) + if (can.Action("go") == "run") { return can.page.Modify(can, event.target, {style: {cursor: ""}}) } + if (can.Action("go") == "auto") { can.onaction._auto(can, event.target) } + can.onimport._figure(event, can, can.point.concat(point)) + }, + onmouseover: function(event, can) { can.onexport._show(can, event.target) }, + oncontextmenu: function(event, can) { can.onexport._show(can, event.target) }, }, ["/plugin/local/wiki/draw.css"]) Volcanos("onfigure", {help: "图形绘制", list: [], _get: function(can, item, name) { return can.onfigure[name]||can.onfigure[item.getAttribute("name")]||can.onfigure[item.tagName] }, + _ship: function(can, target, value) { + return target.Value("ship", target.Value("ship").concat([value])) + }, _push: function(can, data, cmd, target) { var rect = document.createElementNS("http://www.w3.org/2000/svg", cmd) - target.appendChild(can.onimport.block(can, rect)) + target.appendChild(can.onimport._block(can, rect)) rect.Value(data); if (can.point.length == 0) { var pid = "p"+can.svg.Val("count", can.svg.Val("count")+1) rect.Value("class", (rect.Value("class") + " " + rect.Value("pid", pid)).trim()) } return can.last = rect }, - _ship: function(can, target, value) { - return target.Value("ship", target.Value("ship").concat([value])) - }, _copy: function(event, can, target) { var figure = can.onfigure._get(can, target).data @@ -222,30 +139,29 @@ Volcanos("onfigure", {help: "图形绘制", list: [], return p }, - svg: { - data: { - size: {}, - }, // - show: function(can, target) { - return target.Val("width") +","+ target.Val("height") - }, + svg: { // + data: {size: {}, copy: []}, + show: function(can, target) { return target.Val("width") +","+ target.Val("height") }, }, - rect: { - data: { size: {x: "x", y: "y"}, rx: 4, ry: 4, - copy: ["width", "height", "rx", "ry"], - }, // + text: { // hi + data: {size: {x: "x", y: "y"}, copy: ["inner"]}, + draw: function(event, can, point, style) { if (point.length < 1 || event.type == "mousemove") { return } + var p0 = point[0]; var data = {"x": p0.x, "y": p0.y, "inner": style&&style.inner || can.user.prompt("text")} + return can.point = [], data + }, + show: function(can, target) { return ": (" + target.Val("x") + "," + target.Val("y")+ ")" } + }, + rect: { // + data: {rx: 4, ry: 4, size: {x: "x", y: "y"}, copy: ["width", "height", "rx", "ry"]}, draw: function(event, can, point) { if (point.length < 2) { return } var p0 = point[0], p1 = point[1]; var data = { - "x": p0.x > p1.x? p1.x: p0.x, - "y": p0.y > p1.y? p1.y: p0.y, - "width": Math.abs(p0.x-p1.x), - "height": Math.abs(p0.y-p1.y), - "rx": this.data.rx, - "ry": this.data.ry, + "rx": this.data.rx, "ry": this.data.ry, + "x": p0.x > p1.x? p1.x: p0.x, "y": p0.y > p1.y? p1.y: p0.y, + "width": Math.abs(p0.x-p1.x), "height": Math.abs(p0.y-p1.y), } return event.type == "click" && point.length == 2 && (can.point = []), data }, - text: function(can, target, data) { + text: function(can, data, target) { data.x = target.Val("x")+target.Val("width")/2 data.y = target.Val("y")+target.Val("height")/2 return data @@ -255,59 +171,41 @@ Volcanos("onfigure", {help: "图形绘制", list: [], + " + (" + target.Val("width") + "," + target.Val("height") + ")" }, }, - text: { - data: { size: {x: "x", y: "y"}, copy: ["inner"], - }, // hi - draw: function(event, can, point, style) { if (point.length < 1 || event.type == "mousemove") { return } - var p0 = point[0]; var data = { - "x": p0.x, "y": p0.y, - "inner": style&&style.inner || can.user.prompt("text"), - } - return can.point = [], data - }, - show: function(can, target) { - return ": (" + target.Val("x") + "," + target.Val("y")+ ")" - } - }, - line: { - data: { size: {}, copy: ["x1", "y1", "x2", "y2"], - x: function(event, can, value, cmd, target) { + line: { // + data: {size: {}, copy: ["x1", "y1", "x2", "y2"], + x: function(can, value, cmd, target) { if (value != undefined) { var offset = value - target.Val("xx") target.Val("x1", target.Val("x1") + offset) - // target.Val("x2", target.Val("x2") + offset) + target.Val("x2", target.Val("x2") + offset) target.Val("xx", value) } return target.Val("xx") }, - y: function(event, can, value, cmd, target) { + y: function(can, value, cmd, target) { if (value != undefined) { var offset = value - target.Val("yy") target.Val("y1", target.Val("y1") + offset) - // target.Val("y2", target.Val("y2") + offset) + target.Val("y2", target.Val("y2") + offset) target.Val("yy", value) } return target.Val("yy") }, - width: function(event, can, value, cmd, target) { + width: function(can, value, cmd, target) { return value != undefined && target.Val("x2", target.Val("x1") + parseInt(value)), target.Val("x2") - target.Val("x1") }, - height: function(event, can, value, cmd, target) { + height: function(can, value, cmd, target) { return value != undefined && target.Val("y2", target.Val("y1") + parseInt(value)), target.Val("y2") - target.Val("y1") }, - }, // - grid: function(event, can, point) {var target = event.target - if (target == can.svg) {return} - var p = point[point.length-1] - var pos = can.page.Prepos(event, target) + }, + grid: function(event, can, point) { var target = event.target + if (target == can.svg) { return } + var p = point[point.length-1], pos = can.page.Prepos(event, target) target.Val && can.page.Anchor(event, target, pos, p) return p.target = target, p.anchor = pos, point }, draw: function(event, can, point) { if (point.length < 2) { return } - var p0 = point[0], p1 = point[1]; var data = { - "x1": p0.x, "y1": p0.y, - "x2": p1.x, "y2": p1.y, - } + var p0 = point[0], p1 = point[1]; var data = {"x1": p0.x, "y1": p0.y, "x2": p1.x, "y2": p1.y} return event.type == "click" && point.length == 2 && (can.point = []), data }, text: function(can, target, data) { @@ -320,216 +218,34 @@ Volcanos("onfigure", {help: "图形绘制", list: [], + " - (" + target.Val("x2") + "," + target.Val("y2") + ")" }, }, - path: { - data: { size: {}, copy: ["d", "name", "meta", "tt", "xx", "yy"], - x: function(event, can, value, cmd, target) { - var tt = JSON.parse(target.Value("tt")||'{"tx":0, "ty":0}') - if (value != undefined) { - tt.tx = value-target.Val("xx") - target.Value("tt", JSON.stringify(tt)) - target.Value("transform", "translate("+tt.tx+","+tt.ty+")") - } - return target.Val("xx")+tt.tx - }, - y: function(event, can, value, cmd, target) { - var tt = JSON.parse(target.Value("tt")||'{"tx":0, "ty":0}') - if (value != undefined) { - tt.ty = value-target.Val("yy") - target.Value("tt", JSON.stringify(tt)) - target.Value("transform", "translate("+tt.tx+","+tt.ty+")") - } - return target.Val("yy")+tt.ty - }, - }, // - draw: function(event, can, point, style) { - if (style && style.d) { return style } - if (point.length == 1) { can._temp = {} } - if (point.length < 2) {return} - - if (can.keys && can.keys.length > 0) { var k; - k = can._temp[point.length-1] = can.keys[0] - switch (k.toUpperCase()) { - case "C": can._temp[point.length+1] = "," - case "Q": can._temp[point.length] = ","; break - default: - } - can.keys = can.keys.slice(1) - } - - var skip = 0 - var end = false - var data = { - d: can.core.List(point, function(p, i) { var k = p.k - if (i < skip) {return} - switch (i) { - case 0: k = "M"; break - default: k = can._temp[i] || p.k || "L"; break - } - if (end) {return} - - k = k.toUpperCase() - switch (k) { - case "Z": return can.point = [], can._temp = {}, k - case "L": return k+" " + p.x + " " + p.y - case "M": return k+" " + p.x + " " + p.y - case "H": return k+" " + p.x - case "V": return k+" " + p.y - case "A": - switch (point.length - i) { - case 1: end = true - return k+" " + (point[i-1].x+p.x)/2 + " " + (point[i-1].y+p.y)/2 + " 0 0 0 " + p.x + " " + p.y - case 2: end = true - var r = Math.sqrt(Math.pow(point[i+1].x - p.x, 2) + Math.pow(point[i+1].y - p.y, 2)) - return k+" " + r + " " + r + " 0 0 0 " + p.x + " " + p.y - case 3: - if (!p.done) { - var r = Math.sqrt(Math.pow(point[i+1].x - p.x, 2) + Math.pow(point[i+1].y - p.y, 2)) - var temp = point[i] - p = point[i] = point[i+1] - point[i+1] = temp - var temp = can.point[i] - p = can.point[i] = can.point[i+1] - can.point[i+1] = temp - p.x = r - p.y = r - p.done = true - p.arg = " 0 0 0 " - } - default: - skip = i + 2 - return k+" " + p.x + " " + p.y + " 0 0 0 " + point[i+1].x + " " + point[i+1].y - } - break - case "C": - switch (point.length - i) { - case 1: end = true - return k+" " + (point[i-1].x+p.x)/2 + " " + (point[i-1].y+p.y)/2 + "," + (point[i-1].x+p.x)/2 + " " + (point[i-1].y+p.y)/2 + "," + p.x + " " + p.y - case 2: end = true - return k+" " + point[i+1].x + " " + point[i+1].y + "," + (point[i-1].x+p.x)/2 + " " + (point[i-1].y+p.y)/2 + "," + p.x + " " + p.y - case 3: - return k+" " + point[i+1].x + " " + point[i+1].y + "," + point[i+2].x + " " + point[i+2].y + "," + p.x + " " + p.y - case 4: - if (!p.done) { - var temp = point[i] - p = point[i] = point[i+1] - point[i+1] = temp - - var temp = point[i+1] - point[i+1] = point[i+2] - point[i+2] = temp - p.done = true - } - default: - return k+" " + p.x + " " + p.y - } - case "Q": - switch (point.length - i) { - case 1: end = true - return k+" " + (point[i-1].x+p.x)/2 + " " + (point[i-1].y+p.y)/2 + "," + p.x + " " + p.y - case 2: end = true - return k+" " + point[i+1].x + " " + point[i+1].y + "," + p.x + " " + p.y - case 3: - if (!p.done) { - var temp = point[i] - p = point[i] = point[i+1] - point[i+1] = temp - p.done = true - } - default: - return k+" " + p.x + " " + p.y - } - default: return k+" " + p.x + " " + p.y - } - }).join(" ") - } - return data - }, - text: function(can, target, data) { - data.x = (target.x1.baseVal.value + target.x2.baseVal.value) / 2 - data.y = (target.y1.baseVal.value + target.y2.baseVal.value) / 2 - return data - }, - show: function(can, target) { - return target.tagName + " " + target.Value("d") - }, - }, - circle: { - data: { size: {x: "cx", y: "cy", width: "r", height: "r"}, copy: ["r"], - }, // + circle: { // + data: {size: {x: "cx", y: "cy", width: "r", height: "r"}, copy: ["r"]}, draw: function(event, can, point) { if (point.length < 2) { return } - var p0 = point[0], p1 = point[1]; var data = { - "cx": p0.x, "cy": p0.y, - "r": Math.sqrt(Math.pow(p0.x-p1.x, 2)+Math.pow(p0.y-p1.y, 2)), - } + var p0 = point[0], p1 = point[1]; var data = {"cx": p0.x, "cy": p0.y, "r": Math.sqrt(Math.pow(p0.x-p1.x, 2)+Math.pow(p0.y-p1.y, 2))} return event.type == "click" && point.length == 2 && (can.point = []), data }, - text: function(can, target, data) { - data.x = target.Val("cx") - data.y = target.Val("cy") - return data - }, - show: function(can, target) { - return ": (" + target.Val("cx") + "," + target.Val("cy") + ")" - + " > (" + parseInt(target.Val("r")) + ")" - }, + text: function(can, target, data) { return data.x = target.Val("cx"), data.y = target.Val("cy"), data }, + show: function(can, target) { return ": (" + target.Val("cx") + "," + target.Val("cy") + ")" + " > (" + parseInt(target.Val("r")) + ")" }, }, - ellipse: { - data: { size: {x: "cx", y: "cy", width: "rx", height: "ry"}, copy: ["rx", "ry"], - }, // + ellipse: { // + data: {size: {x: "cx", y: "cy", width: "rx", height: "ry"}, copy: ["rx", "ry"]}, draw: function(event, can, point) { if (point.length < 2) { return } - var p0 = point[0], p1 = point[1]; var data = { - "cx": p0.x, "cy": p0.y, - "rx": Math.abs(p0.x - p1.x), "ry": Math.abs(p0.y - p1.y), - } + var p0 = point[0], p1 = point[1]; var data = {"cx": p0.x, "cy": p0.y, "rx": Math.abs(p0.x - p1.x), "ry": Math.abs(p0.y - p1.y)} return event.type == "click" && point.length == 2 && (can.point = []), data }, - text: function(can, target, data) { - data.x = target.Val("cx") - data.y = target.Val("cy") - return data - }, - show: function(can, target) { - return ": (" + target.Val("cx") + "," + target.Val("cy") + ")" - + " > (" + target.Val("rx") + "," + target.Val("ry") + ")" - }, + text: function(can, target, data) { return data.x = target.Val("cx"), data.y = target.Val("cy"), data }, + show: function(can, target) { return ": (" + target.Val("cx") + "," + target.Val("cy") + ")" + " > (" + target.Val("rx") + "," + target.Val("ry") + ")" }, }, - block: { - data: { size: {x: "x", y: "y"}, rx: 4, ry: 4, copy: ["width", "height", "rx", "ry"], - }, // + + block: { // + data: {rx: 4, ry: 4, size: {x: "x", y: "y"}, copy: ["width", "height", "rx", "ry"]}, draw: function(event, can, point) { if (point.length < 2) { return } this._temp && can.page.Remove(can, this._temp) && delete(this._temp) this._temp = can.onfigure._push(can, {}, "g", can.group||can.svg) - var temp = this._temp - var rect = can.onfigure._push(can, can.onfigure.rect.draw(event, can, point), "rect", temp) - if (event.type == "click" && point.length == 2) { var point = can.onfigure.rect.text(can, rect, {}) - can.require(["/plugin/input/key"]) - can.run(event, ["action", "plugin"], function(msg) { - var ui = can.user.input(event, can, [ - {name: "zone", select: [["zone"].concat(msg.append), function(event, value) { - can.page.Appends(can, ui.type, can.core.List(msg[value], function(item) { - return {type: "option", value: item, inner: item} - })) - }]}, - {name: "type", select: [["type"].concat(msg[msg.append[0]]), function(event, value) { - - }]}, - - {name: "name", type: "input", onclick: function(event) { - can.onfigure.key.onclick(event, can, {name: "name", zone: ui.zone.value, type: ui.type.value}, event.target) - }, autocomplete: "off"}, - {name: "text", type: "input", onclick: function(event) { - can.onfigure.key.onclick(event, can, {name: "text", zone: ui.zone.value, type: ui.type.value}, event.target) - }, autocomplete: "off"}, - ], function(event, button, data, list) { - var text = can.onfigure._push(can, can.onfigure.text.draw(event, can, [point], {inner: data.name}), "text", temp) - rect.Value(data) - text.Value(data) - return true - }) - }, true) - delete(this._temp) - } + var rect = can.onfigure._push(can, can.onfigure.rect.draw(event, can, point), "rect", this._temp) + if (event.type != "click" && point.length != 2) { return } + delete(this._temp) }, text: function(can, target, data) { data.x = target.Val("x")+target.Val("width")/2 @@ -543,58 +259,59 @@ Volcanos("onfigure", {help: "图形绘制", list: [], }, }, []) Volcanos("onaction", {help: "组件菜单", list: [ - ["grid", 1, 2, 3, 4, 5, 10, 20], ["stroke-width", 1, 2, 3, 4, 5], + ["stroke", "red", "yellow", "green", "purple", "blue", "cyan", "white", "black"], + ["fill", "red", "yellow", "green", "purple", "blue", "cyan", "white", "black", "#0000"], ["font-size", 12, 16, 18, 24, 32], - {text: [" c:", "div", "item"]}, ["stroke", "red", "yellow", "green", "purple", "blue", "cyan", "white", "black"], - {text: [" f:", "div", "item"]}, ["fill", "red", "yellow", "green", "purple", "blue", "cyan", "white", "black", "#0000"], - {text: [" g:", "div", "item"]}, ["go", "run", "auto", "manual"], - {text: [" a:", "div", "item"]}, ["mode", "translate", "draw", "resize", "delete"], - {text: [" s:", "div", "item"]}, ["shape", "block", "rect", "text", "line", "path", "circle", "ellipse", "heart"], + + ["shape", "text", "rect", "line", "circle", "ellipse", "block"], + ["mode", "translate", "draw", "resize", "delete"], + ["grid", 1, 2, 3, 4, 5, 10, 20], + ["go", "run", "auto", "manual"], ], "编辑": function(event, can, key) { can.Action("go", "auto") }, "save": function(event, can, key) { - var msg = can.request(event); msg.Option("content", can.onexport.content(can, can.svg)) - can.run(event, ["action", "save", can.Option("path"), can.Option("file")], function() { + var msg = can.request(event, {content: can.onexport.content(can, can.svg)}) + can.run(event, ["action", "save", can.Option("path"), can.Option("file")], function(msg) { can.user.toast(can, "保存成功") }, true) }, - "项目": function(event, can, key) { - can.page.Modify(can, can.ui.project, {style: {display: can.ui.project.style.display=="none"? "block": "none"}}) - }, - "变参": function(event, can, key) { - can.page.Modify(can, can._action, {style: {display: can._action.style.display=="none"? "": "none"}}) - }, - "清空": function(event, can) { - can.group.innerHTML = "", can.point = [], can.keys = [], delete(can.temp) - }, - "删除": function(event, can) { if (can.group == can.svg) { return } - can.page.Remove(can, event.target) - can.page.Remove(can, can.group), can.page.Select(can, can.action, "option[value="+can.group.Value("class")+"]", function(item) { - can.page.Remove(can, item) - }) - can.Action("group", "svg") - }, - "添加": function(event, can) { - can.user.prompt("add group", function(name) { - var group = document.createElementNS('http://www.w3.org/2000/svg', 'g') - can.group.append(can.onimport.block(can, group)) - group.Value("class", name), can.core.List(["font-size", "stroke-width", "stroke", "fill"], function(name) { - group.Value(name, can.Action(name)) - }) - - can.onimport.group(can, group).click() - }) - }, + "项目": function(event, can) { can.page.Toggle(can, can.ui.project) }, "font-size": function(event, can, key, value) { can.Action(key, value), can.group.Value(key, value) }, "stroke-width": function(event, can, key, value) { can.Action(key, value), can.group.Value(key, value) }, stroke: function(event, can, key, value) { can.Action(key, value), can.group.Value(key, value) }, fill: function(event, can, key, value) { can.Action(key, value), can.group.Value(key, value) }, + shape: function(event, can, key, value) { can.Action(key, value) }, mode: function(event, can, key, value) { can.Action(key, value) }, go: function(event, can, key, value) { can.Action(key, value) }, + _auto: function(can, target) { + if (can.point.length > 0) { return } + var pos = can.page.Prepos(event, event.target) + if (target.tagName == "text") { + + } else if (target == can.svg) { + if (pos == 5) { + can.Action("mode", "draw") + can.Action("shape", "rect") + can.page.Modify(can, can.svg, {style: {cursor: "crosshair"}}) + } else { + can.Action("mode", "resize") + } + } else { + switch (pos) { + case 5: + case 9: + can.Action("mode", "resize") + break + default: + can.Action("mode", "draw") + can.Action("shape", "line") + } + } + }, _mode: { run: function(event, can) { var target = event.target event.type == "click" && target.Value("type") && can.run(event, ["action", "run", target.Value("zone"), target.Value("type"), target.Value("name"), target.Value("text")], function(msg) { @@ -667,7 +384,7 @@ Volcanos("onaction", {help: "组件菜单", list: [ can.core.List(can.current.begin, function(item) { var figure = can.onfigure._get(can, item.target) can.page.Resizes(event, item.target, item, point[0], point[1], can.current.pos) can.page.Select(can, can.svg, "."+item.target.Value("text"), function(text) { - text.Value(figure.text(can, item.target, {})) + text.Value(figure.text(can, {}, item.target)) }) can.core.List(item.ship, function(ship) { var p = can.page.Anchor(event, item.target, ship.anchor, {}) @@ -686,81 +403,33 @@ Volcanos("onaction", {help: "组件菜单", list: [ can.point = [], event.target != can.svg && can.page.Remove(can, event.target) }, }, - _action: function(event, can, points, target) { - can.temp && can.page.Remove(can, can.temp) && delete(can.temp) - can.temp = can.onaction._mode[can.Action("mode")](event, can, points, target) - can.point.length == 0 && delete(can.temp) - }, - _point: function(event, can) { - var p = can.svg.getBoundingClientRect() - var point = {x: event.clientX-p.x, y: event.clientY-p.y} - if (can.Action("mode") == "view") { return point } - point.x = point.x - point.x % parseInt(can.Action("grid")) - point.y = point.y - point.y % parseInt(can.Action("grid")) - return point - }, - _show: function(can, target) { var figure = can.onfigure._get(can, target) - can.Status("分组", target.Groups() || can.group.Value("class") ) - can.Status("图形", target.tagName + " " + ( - figure? figure.show(can, target): "")) - }, - _auto: function(can, target, pos) { - if (target.tagName == "text") { - - } else if (target == can.svg) { - if (pos == 5) { - can.Action("mode", "draw") - can.Action("shape", "rect") - can.page.Modify(can, can.svg, {style: {cursor: "crosshair"}}) - } else { - can.Action("mode", "resize") - } - } else { - switch (pos) { - case 5: - case 9: - can.Action("mode", "resize") - break - default: - can.Action("mode", "draw") - can.Action("shape", "line") - } - } - }, - - onclick: function(event, can) { - if (can.Action("go") == "run") { - can.onaction._mode.run(event, can) - return - } - var target = event.target - if (event.altKey) { - target = can.onfigure._copy(event, can, event.target) - can.Action("mode", "resize") - } - if (event.target == can._target) { return } - var point = can.onaction._point(event, can) - can.onaction._action(event, can, can.point = can.point.concat(point), target) - }, - onmousemove: function(event, can) { - var point = can.onaction._point(event, can) - can.Status("坐标", point.x+","+point.y) - if (can.Action("go") == "run") { return can.page.Modify(can, event.target, {style: {cursor: ""}}) } - - var pos = can.page.Prepos(event, event.target) - if (can.Action("go") == "auto" && can.point.length == 0) { - can.onaction._auto(can, event.target, pos) - } - can.onaction._action(event, can, can.point.concat(point)) - }, - onmouseover: function(event, can) { - can.onaction._show(can, event.target) - }, - oncontextmenu: function(event, can) { - can.onaction._show(can, event.target) - }, }) Volcanos("ondetail", {help: "组件详情", list: ["复制", "标签", "编辑", "删除"], + "显示": function(event, can) { can.onmotion.show(can, 10, null, event.target) }, + "隐藏": function(event, can) { can.onmotion.show(can, {value:100, length: 10}, null, event.target) }, + "添加": function(event, can) { + can.user.prompt("add group", function(name) { + var group = document.createElementNS('http://www.w3.org/2000/svg', 'g') + can.group.append(can.onimport._block(can, group)) + group.Value("class", name), can.core.List(["font-size", "stroke-width", "stroke", "fill"], function(name) { + group.Value(name, can.Action(name)) + }) + + can.onimport._group(can, group).click() + }) + }, + "清空": function(event, can) { + can.group.innerHTML = "", can.point = [], delete(can.temp) + }, + "删除": function(event, can) { if (can.group == can.svg) { return } + can.page.Remove(can, event.target) + can.page.Remove(can, can.group), can.page.Select(can, can.action, "option[value="+can.group.Value("class")+"]", function(item) { + can.page.Remove(can, item) + }) + can.Action("group", "svg") + }, + + "复制": function(event, can) { can.onfigure._copy(event, can, event.target) }, @@ -778,11 +447,12 @@ Volcanos("ondetail", {help: "组件详情", list: ["复制", "标签", "编辑", } var figure = can.onfigure._get(can, target) - var data = figure.text(can, target, {inner: text}) + var data = figure.text(can, {inner: text}, target) var obj = can.onfigure._push(can, data, "text", target.Group()) target.Value("text", obj.Value("pid")) }, def) }, + "编辑": function(event, can) { var target = event.target var figure = can.onfigure._get(can, target) can.user.input(event, can, can.core.List(["x", "y", "transform", "translate_x", "translate_y"].concat(figure.data.copy||[]), function(item) { @@ -805,11 +475,16 @@ Volcanos("ondetail", {help: "组件详情", list: ["复制", "标签", "编辑", can.page.Remove(can, event.target) }, }) -Volcanos("onexport", {help: "导出数据", list: ["坐标", "分组", "图形", "按键"], +Volcanos("onexport", {help: "导出数据", list: ["分组", "图形", "坐标", "按键"], + _show: function(can, target) { var figure = can.onfigure._get(can, target) + can.Status("分组", target.Groups() || can.group.Value("class") ) + can.Status("图形", target.tagName + " " + (figure? figure.show(can, target): "")) + }, + content: function(can, svg) { return [' 0? show(--order): show(order = can.list.length-1) }, - "下一个": function(event) { order < can.list.length-1? show(++order): show(order = 0) }, + "上一个": function(event) { order > 0? show(--order): can.user.toast(can, "已经是第一张啦!") }, + "下一个": function(event) { order < can.list.length-1? show(++order): can.user.toast(can, "已经是最后一张啦!") }, "设置背景": function(event) { var msg = can.request(event, {url: can.onimport._file(can, can.list[order].path)}) sub.run(event, ["search", "Header.onimport.background"]) }, @@ -83,8 +70,7 @@ Volcanos("onfigure", {help: "组件菜单", list: [], onmouseover: function(event) { can.Status("file", path) }, } }, - video: function(can, path) { var auto = true, loop = true, total = 0 - function cb(event) { } + video: function(can, path) { var auto = true, loop = true, total = 0; function cb(event) { } return {className: "preview", type: "video", style: {height: can.height}, data: {src: path, controls: "controls", autoplay: auto, loop: loop, playbackRate: can.rate}, oncontextmenu: cb, onplay: cb, onpause: cb, onended: cb, @@ -105,12 +91,6 @@ Volcanos("onaction", {help: "组件菜单", list: [ ["高度", 100, 200, 400, 600, 800], ["倍速", 0.1, 0.2, 0.5, 1, 2, 3, 5, 10], ], - chooseImage: function(event, can) { var msg = can.request(event) - can.user.agent.chooseImage(function(list) { can.core.List(list, function(item) { - can.page.Append(can, can._output, [{img: item, height: 200}]) - }) }) - }, - upload: function(event, can) { can.user.upload(event, can) }, "上一页": function(event, can, key, value) { can.begin > 0 && (can.begin -= can.limit, can.onimport._page(can, can.list, can.begin, can.limit)) }, @@ -118,9 +98,6 @@ Volcanos("onaction", {help: "组件菜单", list: [ can.begin + can.limit < can.list.length && (can.begin += can.limit, can.onimport._page(can, can.list, can.begin, can.limit)) }, - "参数": function(event, can) { - can.page.Toggle(can, can._action) - }, "数量": function(event, can, key, value) { can.limit = parseInt(value), can.onimport._page(can, can.list, can.begin, can.limit) }, @@ -130,6 +107,12 @@ Volcanos("onaction", {help: "组件菜单", list: [ "倍速": function(event, can, key, value) { can.rate = parseInt(value), can.onimport._page(can, can.list, can.begin, can.limit) }, + + chooseImage: function(event, can) { var msg = can.request(event) + can.user.agent.chooseImage(function(list) { can.core.List(list, function(item) { + can.page.Append(can, can._output, [{img: item, height: 200}]) + }) }) + }, }) Volcanos("onexport", {help: "导出数据", list: ["begin", "limit", "total", "position", "file"], position: function(can, index, total) { total = total || can.max diff --git a/plugin/state.js b/plugin/state.js index b35d68cd..bd63d0dd 100644 --- a/plugin/state.js +++ b/plugin/state.js @@ -54,6 +54,7 @@ Volcanos("onaction", {help: "交互操作", list: [], _init: function(can, msg, } }) }, + upload: function(event, can) { can.user.upload(event, can) }, getLocation: function(event, can, cmd) { var msg = can.request(can) can.user.agent.getLocation(function(res) { @@ -74,6 +75,7 @@ Volcanos("onaction", {help: "交互操作", list: [], _init: function(can, msg, }) }, + "参数": function(event, can) { can.page.Toggle(can, can._action) }, "清空": function(event, can, name) { can._output.innerHTML = "" }, "结束": function(event, can, name) { can.user.confirm("确定结束?") && can.run(event, ["action", name], function(msg) { can.run({})