From a261df7e757e0daa53949a63be1d743f14d326da Mon Sep 17 00:00:00 2001 From: shy Date: Fri, 1 Jul 2022 21:32:20 +0800 Subject: [PATCH] opt some --- LICENSE | 2 +- frame.js | 31 +++++++------- page/index.js | 2 +- proto.js | 75 +++++++++++++++------------------- publish/client/nodejs/proto.js | 29 +++++++++++++ 5 files changed, 80 insertions(+), 59 deletions(-) diff --git a/LICENSE b/LICENSE index 81259a6c..2d2a2469 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 码神 +Copyright (c) 2020 码神 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/frame.js b/frame.js index 316b2e32..7192f74b 100644 --- a/frame.js +++ b/frame.js @@ -12,18 +12,6 @@ Volcanos("onengine", {help: "搜索引擎", list: [], _init: function(can, meta, can.page.Select(can, target, html.IFRAME, function(item) { can.page.Remove(can, item) }) if (can.user.isExtension) { Volcanos.meta.args = can.base.Obj(localStorage.getItem(ctx.ARGS), {}) } - can.onengine.listen(can, chat.ONSEARCH, function(msg, word) { if (word[0] == ctx.COMMAND || word[1] != "") { var meta = can.onengine.plugin.meta - var list = word[1] == ""? meta: meta[word[1]]? kit.Dict(word[1], meta[word[1]]): {} - can.core.Item(list, function(name, command) { name = can.base.trimPrefix(name, "can.") - can.core.List(msg.Option(ice.MSG_FIELDS).split(ice.FS), function(item) { - msg.Push(item, kit.Dict(ice.CTX, "onengine", ice.CMD, "command", - mdb.TYPE, "can", mdb.NAME, name, mdb.TEXT, command.help, - ctx.CONTEXT, "can", ctx.COMMAND, name - )[item]||"") - }) - }) - } }) - can.core.Next(list, function(item, next) { item.type = chat.PANEL can.onappend._init(can, can.base.Copy(item, can.core.Value(can._root, [chat.RIVER, item.name])), item.list, function(panel) { panel.run = function(event, cmds, cb) { var msg = panel.request(event); cmds = cmds||[] @@ -35,10 +23,22 @@ Volcanos("onengine", {help: "搜索引擎", list: [], _init: function(can, meta, }), can.core.CallFunc([panel.onaction, "_init"], {can: panel, cb: next, target: panel._target}) }, target) }, function() { can.misc.Log(can.user.title(), ice.RUN, can) - can.require([can.volcano], null, function(can, name, sub) { can[name] = sub }) + can.require([can.volcano], null, function(can, key, sub) { can[key] = sub }) can.onlayout.topic(can), can.onmotion._init(can, target), can.onkeymap._init(can) can.onengine.signal(can, chat.ONMAIN, can.request()), can.base.isFunc(cb) && cb() }) + + can.onengine.listen(can, chat.ONSEARCH, function(msg, word) { if (word[0] == ctx.COMMAND || word[1] != "") { var meta = can.onengine.plugin.meta + var list = word[1] == ""? meta: meta[word[1]]? kit.Dict(word[1], meta[word[1]]): {} + can.core.Item(list, function(name, command) { name = can.base.trimPrefix(name, "can.") + can.core.List(msg.Option(ice.MSG_FIELDS).split(ice.FS), function(item) { + msg.Push(item, kit.Dict(ice.CTX, "onengine", ice.CMD, "command", + mdb.TYPE, "can", mdb.NAME, name, mdb.TEXT, command.help, + ctx.CONTEXT, "can", ctx.COMMAND, name + )[item]||"") + }) + }) + } }) }, _search: function(event, can, msg, panel, cmds, cb) { var sub, mod = can, fun = can, key = ""; can.core.List(cmds[1].split(ice.PT), function(value) { @@ -163,7 +163,7 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, meta.inputs && sub.onappend._option(sub, meta, sub._option, meta.msg) if (meta.msg) { var msg = sub.request(); msg.Copy(can.base.Obj(meta.msg)), sub.onappend._output(sub, msg, msg.Option(ice.MSG_DISPLAY)||meta.feature.display) } - can.page.Modify(can, sub._legend, kit.Dict(can.Conf("legend_event")||"onmouseenter", function(event) { + can.page.Modify(can, sub._legend, kit.Dict(can.Conf("legend_event")||html.ONMOUSEENTER, function(event) { can.user.carte(event, sub, sub.onaction, sub.onaction.list.concat([["所有"].concat(can.core.Item(meta.feature._trans))]), function(event, item, meta) { var cb = can.core.Value(sub, ["_outputs.-1.onaction", item]) if (can.base.isFunc(cb)) { return cb(event, can.core.Value(sub, "_outputs.-1"), item) } @@ -1185,5 +1185,4 @@ Volcanos("onkeymap", {help: "键盘交互", list: [], _focus: [], _init: functio cursorMove: function(can, target, count, begin) { begin != undefined && target.setSelectionRange(begin, begin) target.setSelectionRange(target.selectionStart+count, target.selectionStart+count) }, -}) -_can_name = "" +}); _can_name = "" diff --git a/page/index.js b/page/index.js index 1740fe82..66978095 100644 --- a/page/index.js +++ b/page/index.js @@ -4,7 +4,7 @@ Volcanos({name: "chat", panels: [ {name: "Action", help: "工作台", pos: chat.MAIN}, {name: "Footer", help: "状态条", pos: chat.FOOT, state: ["ncmd"]}, {name: "Search", help: "搜索框", pos: chat.AUTO}, - ], main: {name: "Header", list: ["/publish/order.js"]}, river: { + ], main: {name: "Header", list: []}, river: { product: {name: "产品群", storm: { office: {name: "办公 office", list: [ {name: "feel", help: "影音媒体", index: "web.wiki.feel"}, diff --git a/proto.js b/proto.js index 62f813d3..780c9017 100644 --- a/proto.js +++ b/proto.js @@ -1,8 +1,7 @@ var kit = { Dict: function() { var res = {} - for (var i = 0; i < arguments.length; i += 2) { - res[arguments[i]] = arguments[i+1] - } return res + for (var i = 0; i < arguments.length; i += 2) { res[arguments[i]] = arguments[i+1] } + return res } } var ice = { @@ -154,9 +153,8 @@ var chat = { ONSIZE: "onsize", ONTOAST: "ontoast", ONREMOTE: "onremote", ONKEYDOWN: "onkeydown", - WEBSITE: "website", HEAD: "head", LEFT: "left", MAIN: "main", AUTO: "auto", HIDE: "hide", FOOT: "foot", - HEADER: "header", FOOTER: "footer", + HEADER: "header", FOOTER: "footer", WEBSITE: "website", ACTION_LAYOUT_FMT: " fieldset.Action.grid>div.output fieldset.plugin { width:_width; height:_height; } fieldset.Action.grid>div.output fieldset.plugin>div.output { width:_width; height:_height; } ", PLUGIN_STATE_JS: "/plugin/state.js", @@ -184,9 +182,7 @@ var chat = { "/plugin/local/wiki/draw/path.js", "/plugin/local/wiki/draw.js", "/plugin/local/wiki/word.js", - "/plugin/local/chat/div.js", "/plugin/local/team/plan.js", - "/plugin/input/province.js", ], } var team = { @@ -254,6 +250,7 @@ var html = { DIV_LAYOUT_FOOT: "div.layout.foot", ESCAPE: "Escape", ENTER: "Enter", TAB: "Tab", + ONMOUSEENTER: "onmouseenter", } var lang = { UNDEFINED: "undefined", @@ -288,12 +285,12 @@ var Volcanos = shy("火山架", {iceberg: "/chat/", volcano: "/frame.js", args: // 根模块 _can_name = "", name = Config.name||"chat", cb = can||function(can) { can.onengine._init(can, can.Conf(Config), Config.panels, Config._init, can._target) - } - can = {_follow: name, _target: Config.target||meta.target}, can._root = can + }, can = {_follow: name, _target: Config.target||meta.target}, can._root = can for (var k in Config) { can[k] = Config[k] } } - var proto = {__proto__: meta, _path: _can_path, _name: name, _load: function(name, each) { // 加载缓存 + var proto = {__proto__: meta, _path: _can_path, _name: name, _load: function(name, each) { + // 加载缓存 var cache = meta.cache[name]||[]; for (list.reverse(); list.length > 0; list) { var sub = list.pop(); sub != can && cache.push(sub) }; meta.cache[name] = cache @@ -312,12 +309,13 @@ var Volcanos = shy("火山架", {iceberg: "/chat/", volcano: "/frame.js", args: } // 无效地址 - if (!libs[0]) { return can.require(libs.slice(1), cb, each) } + if (libs[0] == undefined) { return can.require(libs.slice(1), cb, each) } - // 补全地址 if (libs[0] == "") { + // 样式地址 libs[0] = can._name.replace(".js", ".css") } else if (libs[0][0] != ice.PS && libs[0].indexOf(ice.HTTP) != 0) { + // 相对地址 libs[0] = can._name.slice(0, can._name.lastIndexOf(ice.PS)+1)+libs[0] } @@ -327,17 +325,24 @@ var Volcanos = shy("火山架", {iceberg: "/chat/", volcano: "/frame.js", args: 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||{} + request: function(event) { event = event||{} var msg = event._msg||can.misc.Message(event, can); event._msg = msg function set(key, value) { msg.Option(key) || value == "" || msg.Option(key, value) } + // 添加参数 can.core.List(arguments, function(option, index) { if (!option || index == 0) { return } can.base.isFunc(option.Option)? can.core.List(option.Option(), function(key) { set(key, option.Option(key)) }): can.core.Item(can.base.isFunc(option)? option(): option, set) }); return msg }, + actions: function(event, button) { can.run(event, [ctx.ACTION, button], null, true) }, + runAction: function(event, action, args, cb) { can.request(event, {_handle: ice.TRUE}, can.Option()) + can.run(event, can.misc.concat(can, [ctx.ACTION, action], args), cb||function(msg) { + can.user.toastSuccess(can, action) + }, true) + }, search: function(event, cmds, cb) { if (cmds && typeof cmds == lang.OBJECT && cmds.length > 0 && typeof cmds[0] == lang.OBJECT && cmds[0].length > 0 ) { @@ -353,19 +358,12 @@ var Volcanos = shy("火山架", {iceberg: "/chat/", volcano: "/frame.js", args: var msg = can.request({}, {trans: can.onaction._trans}) return can._menu = can.search(msg._event, [["Header", chat.ONIMPORT, "menu"], can._name].concat(list), cb) }, - setRiver: function(key, value) { return can.set("River", key, value) }, setHeader: function(key, value) { return can.set("Header", key, value) }, getHeader: function(key, cb) { return can.get("Header", key, cb) }, + setRiver: function(key, value) { return can.set("River", key, value) }, getAction: function(key, cb) { return can.get("Action", key, cb) }, getActionSize: function(cb) { return can.get("Action", "size", cb) }, - runAction: function(event, action, args, cb) { - can.request(event, {_handle: ice.TRUE}, can.Option()) - can.run(event, can.misc.concat(can, [ctx.ACTION, action], args), cb||function(msg) { - can.user.toastSuccess(can, action) - }, true) - }, - ConfHeight: function(value) { return can.Conf(html.HEIGHT, value) }, ConfWidth: function(value) { return can.Conf(html.WIDTH, value) }, Conf: function(key, value) { var res = can._conf @@ -381,9 +379,7 @@ var Volcanos = shy("火山架", {iceberg: "/chat/", volcano: "/frame.js", args: } return res }, _conf: {}, - } - - can = can||{}, can.__proto__ = proto + }; can = can||{}, can.__proto__ = proto if (_can_name) { // 加入缓存 meta.cache[_can_name] = meta.cache[_can_name]||[], meta.cache[_can_name].push(can) @@ -405,29 +401,13 @@ var Volcanos = shy("火山架", {iceberg: "/chat/", volcano: "/frame.js", args: } return can.require(libs, cb), can }) -Volcanos.meta._load = function(url, cb) { - switch (url.split("?")[0].split(ice.PT).pop().toLowerCase()) { - case nfs.CSS: - var item = document.createElement(mdb.LINK) - item.rel = "stylesheet", item.type = "text/css" - item.href = url, item.onload = cb - return (document.head||document.body).appendChild(item), item - case nfs.JS: - var item = document.createElement(nfs.SCRIPT) - item.src = url, item.onload = cb, item.onerror = cb - return document.body.appendChild(item), item - } -} function can(tool) { Volcanos({name: "chat", panels: [ - {name: "Header", help: "标题栏", pos: chat.HIDE, state: ["time", "usernick", "avatar"]}, + {name: "Header", help: "标题栏", pos: chat.HIDE, state: ["usernick"]}, {name: "Action", help: "工作台", pos: chat.MAIN, tool: tool}, {name: "Search", help: "搜索框", pos: chat.AUTO}, ]}) } -function _can(tool) { - Volcanos({name: "chat", panels: [{name: "Action", help: "工作台", pos: chat.MAIN, tool: tool}]}) -} try { if (typeof(global) == lang.OBJECT) { global.kit = kit, global.ice = ice @@ -456,5 +436,18 @@ try { if (typeof(global) == lang.OBJECT) { }) }) } else { + Volcanos.meta._load = function(url, cb) { + switch (url.split("?")[0].split(ice.PT).pop().toLowerCase()) { + case nfs.CSS: + var item = document.createElement(mdb.LINK) + item.rel = "stylesheet", item.type = "text/css" + item.href = url, item.onload = cb + return document.head.appendChild(item), item + case nfs.JS: + var item = document.createElement(nfs.SCRIPT) + item.src = url, item.onload = cb, item.onerror = cb + return document.body.appendChild(item), item + } + } Volcanos.meta.target = document.body } } catch (e) { console.log(e) } diff --git a/publish/client/nodejs/proto.js b/publish/client/nodejs/proto.js index 92d591b7..c0591c9a 100644 --- a/publish/client/nodejs/proto.js +++ b/publish/client/nodejs/proto.js @@ -32,3 +32,32 @@ Volcanos("onappend", {help: "渲染引擎", list: [], }, }) +try { if (typeof(global) == lang.OBJECT) { + global.kit = kit, global.ice = ice + global.ctx = ctx, global.cli = cli, global.web = web, global.aaa = aaa + global.mdb = mdb, global.ssh = ssh, global.nfs = nfs, global.tcp = tcp + global.code = code, global.wiki = wiki, global.chat = chat, global.team = team, global.mall = mall + global.svg = svg, global.html = html, global.lang = lang + global.shy = shy, global.Volcanos = Volcanos + + Volcanos.meta._load = function(url, cb) { + setTimeout(function() { if (Volcanos.meta.cache[url]) { return cb(Volcanos.meta.cache[url]) } + switch (url.split("?")[0].split(ice.PT).pop().toLowerCase()) { + case nfs.JS: require(_can_name = url), cb(Volcanos.meta.cache[url]); break + } + }, 100) + } + + Volcanos.meta._load(global.plugin, function(cache) { + Volcanos.meta.volcano = "./frame.js", Volcanos({libs: [ + "./lib/base.js", "./lib/core.js", "./lib/misc.js", "./lib/page.js", // "./lib/user.js", + ], panels: [], plugin: []}, function(can) { can.core.List(cache, function(item) { can[item._name] = item }) + Volcanos.meta._load("./publish/client/nodejs/proto.js", function(cache) { + can.core.List(cache, function(item) { can.base.Copy(can[item._name]||{}, item) }) + can.onimport._init(can, can.request(), function(msg) { console.log(ice.NL) }, null) + }) + }) + }) +} else { + Volcanos.meta.target = document.body +} } catch (e) { console.log(e) }