From 9682cd9dd6cf0b5f52a4bedd0bef33847443195d Mon Sep 17 00:00:00 2001 From: harveyshao Date: Mon, 24 Oct 2022 17:38:03 +0800 Subject: [PATCH] opt state.js --- frame.js | 9 ++++----- lib/page.js | 2 +- panel/action.js | 9 ++++++--- plugin/local/code/inner/search.js | 24 +++++++++++++++++++++--- plugin/local/code/inner/syntax.js | 1 + plugin/local/code/vimer.js | 6 +++--- plugin/state.js | 12 ++++++------ 7 files changed, 42 insertions(+), 21 deletions(-) diff --git a/frame.js b/frame.js index 4c3dcc7b..0be9926a 100644 --- a/frame.js +++ b/frame.js @@ -166,10 +166,9 @@ Volcanos(chat.ONAPPEND, {help: "渲染引擎", _init: function(can, meta, list, Option: function(key, value) { return can.page.SelectArgs(can, option, key, value)[0] }, Update: function(event, cmds, cb, silent) { sub.onappend._output0(sub, sub.Conf(), event||{}, cmds||sub.Input(), cb, silent); return true }, Focus: function() { can.page.Select(can, option, html.INPUT_ARGS, function(item, index) { index == 0 && item.focus() }) }, - Input: function(cmds, silent) { + Input: function(cmds, save) { cmds = cmds && cmds.length > 0? cmds: can.page.SelectArgs(can, option, "").concat(can.page.SelectArgs(can, action, "")), cmds = can.base.trim(cmds) - silent || cmds[0] == ctx.ACTION || can.base.Eq(sub._history[sub._history.length-1], cmds) || sub._history.push(cmds) - return cmds + return !save || cmds[0] == ctx.ACTION || can.base.Eq(sub._history[sub._history.length-1], cmds) || sub._history.push(cmds), cmds }, Clone: function() { meta.args = can.page.SelectArgs(can, option, "") can.onappend._init(can, meta, list, function(sub) { can.base.isFunc(cb) && cb(sub, true) @@ -210,7 +209,7 @@ Volcanos(chat.ONAPPEND, {help: "渲染引擎", _init: function(can, meta, list, if (item._cb) { return item._cb(event) } if (msg.RunAction(event, can.core.Value(can, chat._OUTPUTS_CURRENT), cmds)) { return } if (msg.RunAction(event, input, cmds)) { return } - return can.Update(event, can.Input(cmds, silent), cb, silent) + return can.Update(event, can.Input(cmds, !silent), cb, silent) }, can._inputs[item.name] = input, input.sup = can can.core.ItemCB(input.onaction, function(key, cb) { input._target[key] = function(event) { cb(event, input) } }) @@ -290,7 +289,7 @@ Volcanos(chat.ONAPPEND, {help: "渲染引擎", _init: function(can, meta, list, }, [display, chat.PLUGIN_TABLE_JS], function(sub) { sub.Conf(can.Conf()) sub.run = function(event, cmds, cb, silent) { if (msg.RunAction(can.request(event), sub, cmds)) { return } - return can.Update(event, can.Input(cmds, silent), cb, silent) + return can.Update(event, can.Input(cmds, !silent), cb, silent) }, can._outputs && can._outputs.push(sub), sub.sup = can, sub._root = can._root sub._index = can._index, sub._msg = msg, sub.Conf(sub._args = can.base.ParseURL(display)), sub.Mode(can.Mode()), diff --git a/lib/page.js b/lib/page.js index 207fcc97..75035b29 100644 --- a/lib/page.js +++ b/lib/page.js @@ -313,7 +313,7 @@ Volcanos("page", {help: "用户界面", ClassList: { } }, replace: function(can, text, key, value) { - return can.base.replaceAll(text, "<", "<", ">", ">", key, value) + return can.base.replaceAll(text, "<", "<", ">", ">", key, value) }, Color: function(text) { if (typeof text != lang.STRING) { return "" } if (text.indexOf("http://") == 0 || text.indexOf("https://") == 0 || text.indexOf("ftp://") == 0) { diff --git a/panel/action.js b/panel/action.js index ebe348f6..671d9f88 100644 --- a/panel/action.js +++ b/panel/action.js @@ -35,8 +35,8 @@ Volcanos(chat.ONIMPORT, {_init: function(can, msg) { can.onmotion.clear(can) can.setHeaderMenu(can.base.Obj(can.Conf(chat.MENUS)||msg.Option(chat.MENUS), can.onaction._menus), function(event, button, list) { can.core.CallFunc([can.onaction, list[0]], [can, button]) }) - can.page.Select(can, can._root.Header._output, "action", function(target) { - can.onmotion.hidden(can, can._header_tabs = can.page.Append(can, target, ["tabs"]).first) + can.page.Select(can, can._root.Header._output, html.ACTION, function(target) { + can.onmotion.hidden(can, can._header_tabs = can.page.Append(can, target, [html.TABS]).first) }) }, }) @@ -179,7 +179,10 @@ Volcanos(chat.ONLAYOUT, { }) }, _plugin: function(can, button) { - can.core.List(can._plugins, function(sub) { sub.onaction._resize(sub, button == "" || button == "free" || button == "flow", can.ConfHeight(), can.ConfWidth()) }) + can.core.List(can._plugins, function(sub) { + sub.onaction._resize(sub, button == "" || button == "free" || button == "flow", can.ConfHeight(), can.ConfWidth()) + button == "" && can.page.style(can, sub._output, html.MAX_HEIGHT, "") + }) }, }) Volcanos(chat.ONEXPORT, { diff --git a/plugin/local/code/inner/search.js b/plugin/local/code/inner/search.js index 41328b65..98834fd0 100644 --- a/plugin/local/code/inner/search.js +++ b/plugin/local/code/inner/search.js @@ -1,5 +1,17 @@ -Volcanos(chat.ONPLUGIN, {help: "导入数据", _init: function(can, sub, cb) { const SEARCH = "can.code.inner.search"; var history = [] - function show(msg, word) { if (!msg) { return } history.push(msg); var sub = can.ui.search +Volcanos(chat.ONPLUGIN, {_init: function(can, _sub, cb) { const SEARCH = "can.code.inner.search"; var history = [] + function highlight(value) { var sub = can.ui.search + can.page.Select(can, sub._output, "tbody>tr", function(tr) { + can.page.ClassList.set(can, tr, html.HIDDEN, can.page.Select(can, tr, "td", function(td) { td._text = td._text||td.innerText + if (td.innerText.indexOf(value) > -1) { + td.innerHTML = td._text.replaceAll(value, ""+value+"") + return td + } else { + td.innerText = td._text + } + }).length == 0) + }) + } + function show(msg, word) { if (!msg) { return } history.push(msg); var sub = can.ui.search; sub.Option("main", word) sub.onimport.size(sub, can.ConfHeight()/4, can.ConfWidth()-can.ui.project.offsetWidth, true) sub.onmotion.clear(sub), sub.onappend.table(sub, msg, function(value, key, index, line) { return {text: ["", html.TD], list: [{text: [can.base.trimPrefix(value, nfs.PWD), html.DIV]}], onclick: function(event) { if (!line.line) { return } @@ -7,10 +19,16 @@ Volcanos(chat.ONPLUGIN, {help: "导入数据", _init: function(can, sub, cb) { c }} }, sub._output), sub.onappend.board(sub, msg.Result()), sub.onappend._status(sub, msg.Option(ice.MSG_STATUS)) !sub.page.ClassList.has(sub, sub._legend, html.SELECT) && sub.select(), sub.Focus(), sub.Option("word", word||msg._word||"") + can.onmotion.delay(can, function() { + highlight(word) + }) } can.onengine.plugin(can, SEARCH, shy("搜索", {}, [ {type: "text", name: "main"}, - "filter", "grep:button", "make", "history", "last"], function(can, msg, cmds, cb) { can.misc.runAction(can, msg, cmds, cb, kit.Dict( + {type: "text", name: "filter", _init: function(target) { + target.onkeyup = function(event) { highlight(event.target.value) } + }}, + "grep:button", "make", "history", "last"], function(can, msg, cmds, cb) { can.misc.runAction(can, msg, cmds, cb, kit.Dict( "replace", function(cmds) { can.runAction(msg, nfs.GREP, [cmds[0]], function(msg) { show(msg, cmds[0]) }) }, nfs.GREP, function(cmds) { can.runAction(msg, nfs.GREP, [cmds[0]], function(msg) { show(msg, cmds[0]) }) }, "history", function(cmds) { can.core.List(can.history, function(item) { msg.PushRecord(item) }), show(msg) }, diff --git a/plugin/local/code/inner/syntax.js b/plugin/local/code/inner/syntax.js index 8d8d3ca0..63449e6c 100644 --- a/plugin/local/code/inner/syntax.js +++ b/plugin/local/code/inner/syntax.js @@ -299,6 +299,7 @@ Volcanos(chat.ONSYNTAX, {help: "语法高亮", "window": code.KEYWORD, "location": code.KEYWORD, "document": code.KEYWORD, + "history": code.KEYWORD, "null": code.CONSTANT, "true": code.CONSTANT, diff --git a/plugin/local/code/vimer.js b/plugin/local/code/vimer.js index 29218e17..54c9739e 100644 --- a/plugin/local/code/vimer.js +++ b/plugin/local/code/vimer.js @@ -340,7 +340,7 @@ Volcanos(chat.ONACTION, {help: "控件交互", "百度": function(event, can) { window.openurl("https://baidu.com") }, "查找": function(event, can) { var ui = can.page.Append(can, can._output, [{view: "vimer find float", list: [html.ACTION, html.OUTPUT], - style: {position: "absolute", left: can.ui.project.offsetWidth+can.ui.content.offsetWidth/2, top: can.base.Min(can.current.line.offsetTop-can.ui.content.scrollTop, 100)+57+28}}]) + style: {position: "absolute", left: can.ui.project.offsetWidth+can.ui.content.offsetWidth/2, top: can.base.Max(can.base.Min(can.current.line.offsetTop-can.ui.content.scrollTop, 100), can.ConfHeight()/2)+57+28}}]) can.onmotion.delay(can, function() { can.page.style(can, ui.first, html.LEFT, can.ui.project.offsetWidth+can.ui.content.offsetWidth/2-ui.first.offsetWidth/2) }, 10) can.onmotion.move(can, ui.first) @@ -379,8 +379,8 @@ Volcanos(chat.ONACTION, {help: "控件交互", ], ui.action, { find: function() { find(last+1, from.value) }, grep: function() { - can.onimport.exts(can, "inner/search.js"), can.onmotion.delay(can, function() { meta.close() - can.ui.search.runAction(event, nfs.GREP, [from.value]) + can.onimport.exts(can, "inner/search.js", function(sub) { meta.close() + sub.runAction(event, nfs.GREP, [from.value]) }) }, replace: function() { diff --git a/plugin/state.js b/plugin/state.js index 31c9a550..672ce52c 100644 --- a/plugin/state.js +++ b/plugin/state.js @@ -76,7 +76,7 @@ Volcanos(chat.ONIMPORT, {_process: function(can, msg) { size: function(can, height, width, auto, mode) { if (auto) { - can.page.style(can, can._output, html.HEIGHT, "", html.WIDTH, "", html.MAX_HEIGHT, "", html.MAX_WIDTH, can.ConfWidth(width)) + can.page.style(can, can._output, html.HEIGHT, "", html.WIDTH, "", html.MAX_HEIGHT, can.ConfHeight(height), html.MAX_WIDTH, can.ConfWidth(width)) } else { can.page.style(can, can._output, html.HEIGHT, can.ConfHeight(height), html.WIDTH, can.ConfWidth(width), html.MAX_HEIGHT, "", html.MAX_WIDTH, "") } @@ -87,7 +87,7 @@ Volcanos(chat.ONIMPORT, {_process: function(can, msg) { change: function(event, can, name, value, cb) { return can.page.SelectArgs(can, can._option, "", function(input) { if (input.name != name || value == input.value) { return } - return input.value = value, can.Update(event, can.Input(), cb), input + return input.value = value, can.Update(event, can.Input([], true), cb), input }) }, title: function(can, title) { can.isCmdMode() && can.user.title(title) }, @@ -98,7 +98,7 @@ Volcanos(chat.ONACTION, {list: [ "查看文档", "查看脚本", "查看源码", "查看配置", "删除配置", "删除工具", ], ], - _engine: function(event, can, button) { can.Update(event, [ctx.ACTION, button].concat(can.Input([], true))) }, + _engine: function(event, can, button) { can.Update(event, [ctx.ACTION, button].concat(can.Input())) }, _switch: function(can, sub, mode, save, load) { if (can.page.ClassList.neg(can, can._target, mode)) { (can._mode_list = can._mode_list||[]).push(kit.Dict( @@ -119,7 +119,7 @@ Volcanos(chat.ONACTION, {list: [ _output: function(can, msg) {}, "刷新界面": function(event, can, button, sub) { sub.onlayout._init(sub) }, - "刷新数据": function(event, can) { can.Update(event, can.Input([], true)) }, + "刷新数据": function(event, can) { can.Update(event, can.Input()) }, "切换浮动": function(event, can, button, sub) { can.onaction._switch(can, sub, chat.FLOAT, function() { can.onmotion.hidden(can, can._action), can.onmotion.hidden(can, can._status) can.ConfHeight(can.page.height()/2-2*html.ACTION_HEIGHT-can.onexport.statusHeight(can)), html.WIDTH, can.ConfWidth(can.page.width()/(can.user.isMobile? 1: 2)) @@ -132,13 +132,13 @@ Volcanos(chat.ONACTION, {list: [ }) }, "共享工具": function(event, can) { var meta = can.Conf() - can.onmotion.share(event, can, [{name: chat.TITLE, value: meta.name}, {name: chat.TOPIC, values: [can.getHeader(chat.TOPIC), cli.WHITE, cli.BLACK]}], [mdb.NAME, meta.index, mdb.TEXT, JSON.stringify(can.Input([], true))]) + can.onmotion.share(event, can, [{name: chat.TITLE, value: meta.name}, {name: chat.TOPIC, values: [can.getHeader(chat.TOPIC), cli.WHITE, cli.BLACK]}], [mdb.NAME, meta.index, mdb.TEXT, JSON.stringify(can.Input())]) }, "远程控制": function(event, can) { can.onaction.keyboard(event, can) }, "打开链接": function(event, can) { can.user.open(can.onexport.link(can)) }, "生成链接": function(event, can) { can.onmotion.share(event, can, [], [mdb.LINK, can.user.copy(event, can, can.onexport.link(can))]) }, "生成脚本": function(event, can) { var conf = can.Conf() - var args = can.Input("", true).join(ice.SP), list = [ + var args = can.Input().join(ice.SP), list = [ "export ctx_dev="+location.origin+"; ctx_temp=$(mktemp); curl -o $ctx_temp -fsSL $ctx_dev;"+" source $ctx_temp "+(conf.index||"")+ice.SP+args, "ish_sys_dev_run_command "+args, "ish_sys_dev_run_action", "ish_sys_dev_run_source", ]