From c9c365e8b0c307ebd0724bb35bf046dacfc9d54d Mon Sep 17 00:00:00 2001 From: jingganjiaoyu Date: Fri, 26 Jul 2024 21:40:07 +0800 Subject: [PATCH] opt some --- const.js | 1 + frame.js | 15 ++++++++++----- lib/misc.js | 4 ++++ lib/page.js | 11 +++++++++++ lib/user.js | 5 ++++- panel/header.js | 2 +- plugin/input/key.js | 8 +++----- plugin/state.js | 16 +++++++++++++--- plugin/table.js | 21 +++++++++++++++------ proto.js | 9 +++------ 10 files changed, 65 insertions(+), 27 deletions(-) diff --git a/const.js b/const.js index 386e014a..6b901354 100644 --- a/const.js +++ b/const.js @@ -427,6 +427,7 @@ var html = { DIV_LAYOUT: "div.layout", DIV_LAYOUT_HEAD: "div.layout.head", DIV_LAYOUT_FOOT: "div.layout.foot", DIV_LAYOUT_LEFT: "div.layout.left", DIV_FLOAT: "div.float", DIV_TOAST: "div.toast", DIV_CARTE: "div.carte", DESKTOP: "desktop", DIV_DESKTOP: "div.desktop", DIV_EXPAND: "div.expand", + ITEM_CARD: "item.card", DIV_ITEM_TEXT: "div.item.text", DIV_ITEM_SELECT: "div.item.select", DIV_TABS_SELECT: "div.tabs.select", diff --git a/frame.js b/frame.js index 253eed6a..b8084fda 100644 --- a/frame.js +++ b/frame.js @@ -6,7 +6,8 @@ Volcanos(chat.ONENGINE, { sub.run = function(event, cmds, cb) { var msg = sub.request(event); cmds = cmds||[]; return (can.onengine[cmds[0]]||can.onengine._remote)(event, can, msg, sub, cmds, cb) } can.core.Item(sub.onplugin, function(key, cmd) { sub.onplugin.hasOwnProperty(key) && can.base.isFunc(cmd) && can.onengine.plugin(sub, can.core.Keys(ice.CAN, key), cmd) }) can.core.ItemCB(sub.onaction, function(key, cb) { can.onengine.listen(can, key, function(msg) { can.core.CallFunc(cb, {event: msg._event, can: sub, msg: msg}) }) }) - can.core.CallFunc([sub.onaction, chat._INIT], {can: sub, cb: next, target: sub._target}), delete(sub._history), delete(sub._conf.feature) + // can.core.CallFunc([sub.onaction, chat._INIT], {can: sub, cb: next, target: sub._target}), delete(sub._history), delete(sub._conf.feature) + next(), can.core.CallFunc([sub.onaction, chat._INIT], {can: sub, cb: function() {}, target: sub._target}), delete(sub._history), delete(sub._conf.feature) }, target) }, function() { can.onlayout._init(can, target), can.onmotion._init(can, target), can.onkeymap._init(can, target) can.onengine.signal(can, chat.ONMAIN, can.request()), can.base.isFunc(cb) && cb(can) @@ -343,11 +344,14 @@ Volcanos(chat.ONAPPEND, { var output_old = can._output; sub._target = sub._output = can._output = output = can.page.insertBefore(can, [html.OUTPUT], can._status) can.page.style(can, can._output, "visibility", "hidden", "position", "fixed") if (sub.Mode() == ice.MSG_RESULT) { can._output.innerHTML = output_old.innerHTML } + if (can.page.tagis(can._target, "fieldset.cmd.form.output")) { + can.page.ClassList.del(can, can._target, html.FORM), can.page.ClassList.del(can, can._target, html.OUTPUT) + } can.onexport._output(sub, msg) can.core.CallFunc([sub, chat.ONIMPORT, chat._INIT], {can: sub, msg: msg, cb: function(msg) { if (action !== false) { can.onkeymap._build(sub) var list = can.base.Obj(msg.Option(ice.MSG_ACTION)||can.Conf(ice.MSG_ACTION), [])||[] - can.onmotion.clear(can, can._action), sub.onappend._action(sub, list, action||can._action) + can.onmotion.clear(can, can._action), sub.onappend._action(sub, [{view: "_space"}].concat(list), action||can._action) sub.onappend._status(sub, sub.onexport&&sub.onexport.list||msg.Option(ice.MSG_STATUS), null, msg), can.user.isMobile || sub.onappend.tools(sub, msg) if (msg.Option("sess.online") == ice.TRUE) { can.ondaemon._online(can) } if (msg.Length() > 9 && !sub.ui.project && !can.user.isMobile) { can.onmotion.delay(can, function() { can.onappend._filter(can) }, 300) } @@ -361,8 +365,7 @@ Volcanos(chat.ONAPPEND, { } msg.Defer(), can.base.isFunc(cb) && cb(msg), can.page.style(can, can._target, "visibility", ""), can._output.scrollTop = output_old.scrollTop, can._output.scrollLeft = output_old.scrollLeft can.page.style(can, can._output, "visibility", "", "position", ""), can.page.Remove(can, output_old) - can.isCmdMode() && (can.user.agent.cmd = can), can.isCmdMode() && can.user.agent.init && can.user.agent.init(can) - can.page.Select(can, document.body, "div.loading", function(target) { can.onmotion.hidden(can, target) }) + can.isCmdMode() && can.user.agent.init(can, can.user.info.titles) }, target: output}), msg.Defer() }) }, @@ -433,7 +436,9 @@ Volcanos(chat.ONAPPEND, { can.page.icons(can, item.icons||item.icon||name, item.space||item._space), {text: title}, ]}, {view: [html.OPTION, html.FORM]}, html.ACTION, html.OUTPUT, html.STATUS]}]) }, - input: function(can, item, value, target, style) { if ([html.BR, html.HR].indexOf(item.type) > -1) { return can.page.Append(can, target, [item]) } + input: function(can, item, value, target, style) { + if (["_space"].indexOf(item.view) > -1) { return can.page.Append(can, target, [item]) } + if ([html.BR, html.HR].indexOf(item.type) > -1) { return can.page.Append(can, target, [item]) } var _icon = [], _item = can.base.Copy({className: "", type: "", name: ""}, item), input = can.page.input(can, _item, value) if (item.type == html.SELECT) { can.core.List(input.list, function(item) { item.inner = can.user.trans(can, item.inner, item._trans, html.INPUT) }) diff --git a/lib/misc.js b/lib/misc.js index d45bc5ad..eb310667 100644 --- a/lib/misc.js +++ b/lib/misc.js @@ -235,6 +235,7 @@ Volcanos("misc", { res.Option(ice.LOG_TRACEID, msg.Option(ice.LOG_TRACEID)) res.Option(ice.MSG_DEBUG, msg.Option(ice.MSG_DEBUG)) socket.send(JSON.stringify(res)) + msg.Option("space.noecho", ice.TRUE) }, msg.detail = data.detail||[], msg.Copy(data), msg[ice.MSG_TARGET] = data[ice.MSG_TARGET]||[] try { msg.Option(ice.LOG_DISABLE) != ice.TRUE && can.misc.Log(html.WSS, ice.MSG_DETAIL, msg.detail, msg, _msg) can.core.CallFunc(cb, {event: event, msg: msg, cmd: msg.detail[0], arg: msg.detail.slice(1), cb: function() { msg.Reply() }}) @@ -243,6 +244,9 @@ Volcanos("misc", { return socket }, ResourceFavicon: function(can, path, space) { return can.misc.Resource(can, path||can.user.info.favicon||nfs.SRC_MAIN_ICO, space) }, + ResourceIcons: function(can, path, space, serve) { + return can.misc.Resource(can, path||(can.page.isDark(can)? "usr/icons/volcanos.png": "usr/icons/icebergs.png"), space, serve) + }, Resource: function(can, path, space, serve) { if (!path) { return "" } if (!can.base.beginWith(path, web.HTTP, nfs.PS)) { path = nfs.P+path+(path.indexOf("usr/icons/") == -1? (space? can.core.Split(_version, "&")[0]: _version): "") diff --git a/lib/page.js b/lib/page.js index 37947073..c22d0fb6 100644 --- a/lib/page.js +++ b/lib/page.js @@ -338,6 +338,9 @@ Volcanos("page", { } }, tagClass: function(target) { return target.tagName.toLowerCase()+(target.className? nfs.PT+target.className.replaceAll(lex.SP, nfs.PT): "") }, + isDark: function(can) { + return can.page.tagis(document.body, "body.dark") + }, isDisplay: function(target) { return target && target.style.display != html.NONE && target.className.indexOf(html.HIDE) == -1 }, isSelect: function(target) { return target && target.className.indexOf(html.SELECT) > -1 }, isIconInput: function(can, name) { @@ -404,6 +407,14 @@ Volcanos("page", { } return _list }, + button: function(can, name, cb) { + var icon = can.Conf("_icons."+name) + if (icon) { return {icon: icon, onclick: cb||function(event) { can.Update(event, [ctx.ACTION, name]) }} } + return {view: [["item.button"]], list: [ + {type: html.INPUT, data: {type: html.BUTTON, name: name, value: can.user.trans(can, name)}, onclick: cb||function(event) { can.Update(event, [ctx.ACTION, name]) }}, + {text: name}, + ]} + }, input: function(can, item, value) { var input = {type: html.INPUT, name: item.name, data: item, style: item.style||{}, dataset: {}, _init: item._init} item.value == ice.AUTO && (item.value = "", item.action = ice.AUTO), item.action == ice.AUTO && (input.dataset.action = ice.AUTO) switch (item.type = item.type||html.TEXT) { diff --git a/lib/user.js b/lib/user.js index adcf7685..d261cd13 100644 --- a/lib/user.js +++ b/lib/user.js @@ -16,6 +16,9 @@ Volcanos("user", { connectWifi: function(can, ssid, password, cb, cbs) {}, getClipboard: function(can, cb) {}, enableDebug: function(can) {}, + init: function(can, content) { + can.user.agent.cmd = can, can.user.agent._init_content = content + }, _init_content: [], }, info: {}, isIPad: false, isTesla: navigator.userAgent.indexOf("Tesla") > -1, @@ -89,7 +92,7 @@ Volcanos("user", { }, toastProcess: function(can, content, title, progress) { return can.user.toast(can, {content: "🕑 "+(content||ice.PROCESS), title: title, duration: -1, progress: progress}) }, toastFailure: function(can, content, title) { return can.user.toast(can, {content: "❌ "+(content||ice.FAILURE), title: title, duration: -1}) }, - toastSuccess: function(can, content, title) { return can.user.toast(can, {content: "✅ "+(content||ice.SUCCESS), title: title, duration: 3000}) }, + toastSuccess: function(can, content, title, duration) { return can.user.toast(can, {content: "✅ "+(content||ice.SUCCESS), title: title, duration: duration||1000}) }, toast: function(can, content, title, duration, progress, hash) { can = can._fields? can.sup: can if (title == can.ConfIndex()) { title = can.user.trans(can, title, can.Conf("help")) } var meta = can.base.isObject(content)? content: {content: content, title: title, duration: duration, progress: progress, hash: hash} diff --git a/panel/header.js b/panel/header.js index 739fe1db..d71f24d0 100644 --- a/panel/header.js +++ b/panel/header.js @@ -111,7 +111,7 @@ Volcanos(chat.ONACTION, {_init: function(can) {}, msg.Option(nfs.SCRIPT) && can.require(can.base.Obj(msg.Option(nfs.SCRIPT)), function(can) { can.onaction.source(can, msg) }) var tool = can._root.Action._conf.tool if (can.Conf(aaa.USERNICK, (msg.Option(aaa.USERNICK)||msg.Option(ice.MSG_USERNICK)||msg.Option(ice.MSG_USERNAME)).slice(0, 8)) - || can.misc.Search(can, web.SHARE) || tool && can.base.isIn(can.user.info._cmd = tool[0]._command, "web.chat.oauth.client", web.PORTAL, aaa.OFFER, aaa.APPLY)) { return show(msg) } + || can.misc.Search(can, web.SHARE) || tool && can.base.isIn(can.user.info._cmd = tool[0]._command, "web.chat.oauth.client", web.PORTAL, aaa.OFFER, aaa.APPLY)) { return show(msg) } can.onlayout._init(can), can.user.login(can, function() { can.onengine.signal(can, chat.ONMAIN, msg) }, msg) }) }) diff --git a/plugin/input/key.js b/plugin/input/key.js index cd55ffc8..46e1c54e 100644 --- a/plugin/input/key.js +++ b/plugin/input/key.js @@ -11,9 +11,7 @@ Volcanos(chat.ONFIGURE, {key: { // msg.Option(ice.TABLE_CHECKBOX, "") if (msg.Option(ice.TABLE_CHECKBOX) == ice.TRUE) { target._hold = true can.onappend._action(can, [html.CANCEL, html.CONFIRM, msg.Length() > 5? html.FILTER: ""], can._action, { - cancel: function() { - can.onmotion.focus(can, target), can.onmotion.hidden(can, can._target) - }, + cancel: function() { can.onmotion.focus(can, target), can.onmotion.hidden(can, can._target) }, confirm: function() { var list = msg.Table() can.base.isFunc(cb) && cb(can, can.page.Select(can, can._output, html.TR, function(target) { if (can.page.ClassList.has(can, target, html.SELECT)) { @@ -49,8 +47,8 @@ Volcanos(chat.ONFIGURE, {key: { target.value = value, can.onmotion.hidden(can, can._target) } can.core.CallFunc([can.oninputs, "_show"], {event: event, can: can, msg: msg, target: target, name: name}) - var style = msg.Option(ice.MSG_DISPLAY)? can.base.ParseURL(msg.Option(ice.MSG_DISPLAY)).style||name: name - can.core.CallFunc([can.sup.sub, "oninputs", style], {event: event, can: can, msg: msg, target: target, name: name}) + var display = msg.Option(ice.MSG_DISPLAY)? can.base.ParseURL(msg.Option(ice.MSG_DISPLAY)): {name: name} + display.style && can.core.CallFunc([can.sup.sub, "oninputs", display.style], {event: event, can: can, msg: msg, target: target, name: display.name||name, title: display.title}) can.layout(msg) }, onfocus: function(event, can, meta, target, cbs, mod) { diff --git a/plugin/state.js b/plugin/state.js index 71b35b36..344e6449 100644 --- a/plugin/state.js +++ b/plugin/state.js @@ -15,7 +15,16 @@ Volcanos(chat.ONIMPORT, { _display: function(can, msg) { can.onappend._output(can, msg, msg.Option(ice.MSG_DISPLAY)) }, _clear: function(can, msg) { can.onmotion.clear(can) }, _inner: function(can, sub, msg) { sub = sub||can, can.onmotion.scrollIntoView(can, can.onappend.table(sub, msg)), can.onmotion.scrollIntoView(can, can.onappend.board(sub, msg)), can.onmotion.story.auto(sub) }, - _cookie: function(can, msg) { can.misc.Cookie(can, msg._arg[0], msg._arg[1]), can.Update() }, + _cookie: function(can, msg) { + // can.user.toast(can, stringify.JSON(msg._arg)) + can.misc.Cookie(can, msg._arg[0], msg._arg[1]) + debugger + if (msg._arg[2]) { + history.go(msg._arg[2]) + } else { + can.Update() + } + }, _session: function(can, msg) { can.misc.sessionStorage(can, msg._arg[0], msg._arg[1]), can.Update() }, _field: function(can, msg, cb) { can.page.style(can, can._target, "visibility", ""), can.page.style(can, can._output, "visibility", "") @@ -352,8 +361,9 @@ Volcanos(chat.ONEXPORT, { }, title: function(can, title) { if (!can.isCmdMode()) { return } var list = []; function push(p) { p && list.indexOf(p) == -1 && list.push(p) } - if (!can.base.isIn(can.ConfIndex(), web.PORTAL, code.VIMER, wiki.FEEL)) { push(can.user.trans(can, can.ConfIndex(), can.Conf("help"))) } - can.core.List(arguments, function(title, index) { index > 0 && push(title) }), push(can.ConfSpace()||can.misc.Search(can, ice.POD)) + if (!can.base.isIn(can.ConfIndex(), web.PORTAL, code.VIMER, wiki.FEEL)) { push(can.user.trans(can, can.ConfIndex().split(".").pop(), can.ConfHelp())) } + can.core.List(arguments, function(title, index) { index > 0 && push(title) }) + can.user.isMobile || push(can.user.info.titles||can.ConfSpace()||can.misc.Search(can, ice.POD)) can.user.title(list.join(" ")) }, args: function(can) { return can.Option() }, diff --git a/plugin/table.js b/plugin/table.js index ce0b363a..31be1198 100644 --- a/plugin/table.js +++ b/plugin/table.js @@ -1,7 +1,12 @@ Volcanos(chat.ONIMPORT, { _init: function(can, msg, target, cb) { if (msg.index && msg.meta && msg.list) { return cb && cb(msg), can.sup.onimport._field(can.sup, msg) } - if (can.isCmdMode() && can.Conf(ctx.STYLE) == html.FORM) { can.onappend.style(can, html.OUTPUT) } + can.page.ClassList.del(can, can._fields, html.FORM) + can.page.ClassList.del(can, can._fields, html.OUTPUT) + if (can.isCmdMode() && can.Conf(ctx.STYLE) == html.FORM) { + can.page.ClassList.add(can, can._fields, html.FORM) + can.onappend.style(can, html.OUTPUT) + } if (can.Mode() == html.ZONE) { return can.onimport._vimer_zone(can, msg, target), cb && cb(msg) } var cbs = can.onimport[can.Conf(ctx.STYLE)||msg.Option(ctx.STYLE)]; if (can.base.isFunc(cbs)) { can.onappend.style(can, can._args[ctx.STYLE], target), can.core.CallFunc(cbs, {can: can, msg: msg, target: target}) @@ -331,13 +336,17 @@ Volcanos(chat.ONKEYMAP, { }, _engine: {}, }) Volcanos(chat.ONINPUTS, { - _nameicon: function(event, can, msg, target, name) { + _nameicon: function(event, can, msg, target, name, title) { name = name||mdb.NAME can.page.Appends(can, can._output, msg.Table(function(value) { - return {view: html.ITEM, list: [{img: can.misc.Resource(can, value.icons)}, - {view: html.CONTAINER, list: [{view: [html.TITLE, "", value[name]||value[mdb.NAME]]}, - can.onappend.label(can, value, {version: icon.version, time: icon.compile}), + return {view: html.ITEM, list: [{img: can.misc.Resource(can, value.icons||"usr/icons/icebergs.png")}, + {view: html.CONTAINER, list: [{view: [html.TITLE, "", value[title]||value[name]||value[mdb.NAME]]}, + can.onappend.label(can, value, kit.Dict( + "version", icon.version, + "time", icon.compile, + name, icon.data, + )), ]}, - ], onclick: function(event) { can.showIcons(value[name]||value[mdb.NAME], value.icons) }} + ], onclick: function(event) { can.showIcons(value[name]||value[mdb.NAME], value.icons||"usr/icons/icebergs.png", value[title]) }} })) }, dream: function(event, can, msg, target, name) { can.sup.sub.oninputs._nameicon(event, can, msg, target, name) }, diff --git a/proto.js b/proto.js index 85b36cfe..7b5aa467 100644 --- a/proto.js +++ b/proto.js @@ -117,14 +117,11 @@ var Volcanos = shy({iceberg: "", volcano: "", frame: chat.FRAME_JS, _cache: {}, isAutoMode: function() { return can.Mode() == "" }, Mode: function(value) { return can.Conf(ice.MODE, value) }, ConfDefault: function(value) { can.core.Item(value, function(k, v) { can.Conf(k) || can.Conf(k, v) }) }, - ConfSpace: function(space) { - if (space) { can.Conf(web.SPACE, space) } - return can.Conf("_space")||can.Conf(web.SPACE)||"" }, - ConfIndex: function(index) { - if (index) { can.Conf(ctx.INDEX, index) } - return can.Conf("_command")||can.Conf(ctx.INDEX)||can.Conf("_index") }, + ConfSpace: function(space) { if (space) { can.Conf(web.SPACE, space) } return can.Conf("_space")||can.Conf(web.SPACE)||"" }, + ConfIndex: function(index) { if (index) { can.Conf(ctx.INDEX, index) } return can.Conf("_command")||can.Conf(ctx.INDEX)||can.Conf("_index") }, ConfHeight: function(value) { return can.Conf(html.HEIGHT, value) }, ConfWidth: function(value) { return can.Conf(html.WIDTH, value)||can._output.offsetWidth }, + ConfHelp: function() { return can.Conf("help") }, Conf: function(key, value) { var res = can._conf for (var i = 0; i < arguments.length; i += 2) { if (typeof key == code.OBJECT) { res = can.core.Value(can._conf, arguments[i]), i--; continue }