mirror of
https://shylinux.com/x/volcanos
synced 2025-04-25 08:48:06 +08:00
opt vimer
This commit is contained in:
parent
1cdc59fc65
commit
90ecceda72
53
frame.js
53
frame.js
@ -429,29 +429,6 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta,
|
||||
})
|
||||
return (code.scrollBy && code.scrollBy(0, 10000)), code
|
||||
},
|
||||
|
||||
_parse: function(can, text) { var stack = [{_deep: -1, list: []}]
|
||||
can.core.List(can.core.Split(text, ice.NL, ice.NL, ice.NL), function(line) { if (line == "") { return }
|
||||
var deep = 0; for (var i = 0; i < line.length; i++) { if (line[i] == ice.SP) { deep++ } else if (line[i] == ice.TB) { deep += 4 } else { break } }
|
||||
for (var i = stack.length-1; i > 0; i--) { if (deep <= stack[i]._deep) { stack.pop() } }
|
||||
|
||||
var item = {_deep: deep, list: []}; var list = stack[stack.length-1]; list.list.push(item); if (deep > list._deep) { stack.push(item) }
|
||||
var ls = can.core.Split(line); switch (ls[0]) {
|
||||
case html.HEAD:
|
||||
case html.LEFT:
|
||||
case html.MAIN:
|
||||
case html.FOOT:
|
||||
case html.TABS:
|
||||
case "username":
|
||||
case html.MENU: item.type = ls[0]; break
|
||||
default: item.name = ls[0]; break
|
||||
}
|
||||
for (var i = 1; i < ls.length; i += 2) { can.core.Value(item, ls[i], ls[i+1])
|
||||
if (ls[i] == ctx.INDEX) { item.type = item.type||html.PLUGIN }
|
||||
}
|
||||
})
|
||||
return {type: "demo", style: {height: can.ConfHeight()||window.innerHeight}, list: stack[0].list}
|
||||
},
|
||||
parse: function(can, list, target, keys, data, type) { target = target||can._output, data = data||{}
|
||||
if (!list) { return } else if (can.base.isArray(list)) {
|
||||
return can.core.List(list, function(meta, index) {
|
||||
@ -540,7 +517,7 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta,
|
||||
case "username":
|
||||
can.page.Append(can, target, [
|
||||
can.base.Copy({view: ["username", "div"], onclick: function(event) {
|
||||
}, list: [{view: ["some", html.DIV, can.user.info.usernick]}, {img: "/share/local/avatar"}]})])
|
||||
}, list: [{view: ["some", html.DIV, can.user.info.usernick]}, {img: can.user.info.avatar}]})])
|
||||
return
|
||||
}
|
||||
|
||||
@ -564,10 +541,10 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta,
|
||||
}
|
||||
if ((type||subtype) == html.ITEM) { item.view = item.view||html.LIST
|
||||
if (meta.action == "auto") {
|
||||
meta.init = meta.init||function(item) { can.core.Timer(10, function() { item.click() }) }
|
||||
meta.init = meta.init||function(item) { can.core.Timer(100, function() { item.click() }) }
|
||||
}
|
||||
if (decodeURIComponent(location.hash) == "#"+can.core.Keys(keys, item.name)) {
|
||||
meta.init = meta.init||function(item) { can.core.Timer(30, function() { item.click() }) }
|
||||
meta.init = meta.init||function(item) { can.core.Timer(300, function() { item.click() }) }
|
||||
}
|
||||
|
||||
var _item = can.page.Append(can, target, [can.base.Copy({view: [html.ITEM, html.DIV, meta.name||meta], onclick: function(event) {
|
||||
@ -621,6 +598,28 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta,
|
||||
}
|
||||
return can.page.Append(can, target, [item]).first
|
||||
},
|
||||
_parse: function(can, text) { var stack = [{_deep: -1, list: []}]
|
||||
can.core.List(can.core.Split(text, ice.NL, ice.NL, ice.NL), function(line) { if (line == "") { return }
|
||||
var deep = 0; for (var i = 0; i < line.length; i++) { if (line[i] == ice.SP) { deep++ } else if (line[i] == ice.TB) { deep += 4 } else { break } }
|
||||
for (var i = stack.length-1; i > 0; i--) { if (deep <= stack[i]._deep) { stack.pop() } }
|
||||
|
||||
var item = {_deep: deep, list: []}; var list = stack[stack.length-1]; list.list.push(item); if (deep > list._deep) { stack.push(item) }
|
||||
var ls = can.core.Split(line); switch (ls[0]) {
|
||||
case html.HEAD:
|
||||
case html.LEFT:
|
||||
case html.MAIN:
|
||||
case html.FOOT:
|
||||
case html.TABS:
|
||||
case "username":
|
||||
case html.MENU: item.type = ls[0]; break
|
||||
default: item.name = ls[0]; break
|
||||
}
|
||||
for (var i = 1; i < ls.length; i += 2) { can.core.Value(item, ls[i], ls[i+1])
|
||||
if (ls[i] == ctx.INDEX) { item.type = item.type||html.PLUGIN }
|
||||
}
|
||||
})
|
||||
return {type: "demo", style: {height: can.ConfHeight()||window.innerHeight}, list: stack[0].list}
|
||||
},
|
||||
|
||||
_plugin: function(can, value, meta, cb, target) {
|
||||
meta.feature = can.base.getValid(meta.feature, can.base.Obj(value.meta))||{}
|
||||
@ -1159,7 +1158,7 @@ Volcanos("onkeymap", {help: "键盘交互", list: [], _focus: [], _init: functio
|
||||
input: function(event, can) { if (event.metakey) { return } var target = event.target
|
||||
target._keys = can.onkeymap._parse(event, can, event.ctrlKey? "insert_ctrl": mdb.INSERT, target._keys, target)
|
||||
},
|
||||
prevent: function(event) { event.stopPropagation(), event.preventDefault() },
|
||||
prevent: function(event) { event.stopPropagation(), event.preventDefault(); return true },
|
||||
deleteText: function(target, start, count) { var end = count? start+count: target.value.length
|
||||
var cut = target.value.slice(start, end)
|
||||
target.value = target.value.substring(0, start)+target.value.substring(end, target.value.length)
|
||||
|
@ -176,6 +176,9 @@ Volcanos("base", {help: "数据类型", Int: function(val, def) { return parseIn
|
||||
return res + (n > 0? ice.PT+parseInt(n/10): "") + "s"
|
||||
},
|
||||
|
||||
mod: function(index, total) {
|
||||
return (index+total) % total
|
||||
},
|
||||
getValid: function() {
|
||||
for (var i = 0; i < arguments.length; i++) { var v = arguments[i]
|
||||
if (typeof v == lang.OBJECT) {
|
||||
@ -208,6 +211,12 @@ Volcanos("base", {help: "数据类型", Int: function(val, def) { return parseIn
|
||||
return str
|
||||
},
|
||||
|
||||
count: function(str, s) { var n = 0
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
if (str[i] == s) { n++ }
|
||||
}
|
||||
return n
|
||||
},
|
||||
random: function(max, min) { min = min||0, parseInt(Math.random()*(max-min))+min },
|
||||
isNight: function() { var now = new Date(); return now.getHours() < 7 || now.getHours() > 17 },
|
||||
beginWith: function(str, begin) { return str.trim().indexOf(begin) == 0 },
|
||||
|
@ -82,6 +82,11 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg
|
||||
for (var i = 0; i < arguments.length; i++) { msg.result.push(arguments[i]) }
|
||||
return msg._hand = true, msg
|
||||
},
|
||||
Dump: function(can) {
|
||||
can.onmotion.clear(can)
|
||||
can.onappend.table(can, msg)
|
||||
can.onappend.board(can, msg)
|
||||
},
|
||||
}
|
||||
return can.misc.proto(msg, proto)
|
||||
},
|
||||
|
@ -43,6 +43,7 @@ Volcanos("page", {help: "用户界面", ClassList: {
|
||||
Modify: shy("修改节点", function(can, target, value) { target = target||{}
|
||||
target = can.base.isObject(target)? target: document.querySelector(target); if (!target) { return }
|
||||
can.base.isString(value)? (target.innerHTML = value): can.core.Item(value, function(key, val) {
|
||||
key == "className" && can.base.isArray(val) && (val = val.join(ice.SP))
|
||||
!can.base.isObject(val)? (target[key] = val): can.core.Item(val, function(k, v) {
|
||||
var size = {
|
||||
"height": true, "max-height": true, "min-height": true,
|
||||
|
@ -1,4 +1,4 @@
|
||||
Volcanos("user", {help: "用户操作", agent: {
|
||||
Volcanos("user", {help: "用户操作", info: {}, agent: {
|
||||
scanQRCode: function(cb, can) {
|
||||
can.user.input(event, can, [{type: html.TEXTAREA, name: "text", text: ""}], function(ev, button, data, list, args) {
|
||||
cb(list[0], can.base.ParseJSON(list[0]))
|
||||
@ -84,7 +84,10 @@ Volcanos("user", {help: "用户操作", agent: {
|
||||
"label": "标签", "exec": "执行",
|
||||
}[text]||text
|
||||
},
|
||||
toastProcess: function(can, title) { return can.user.toast(can, ice.PROCESS, title) },
|
||||
toastConfirm: function(can, title, content, action) {
|
||||
return can.user.toast(can, {title: title, content: content, action: action||[cli.CLOSE], duration: -1, width: -300})
|
||||
},
|
||||
toastProcess: function(can, title) { return can.user.toast(can, ice.PROCESS, title, -1) },
|
||||
toastSuccess: function(can, title) { return can.user.toast(can, ice.SUCCESS, title) },
|
||||
toast: function(can, content, title, duration, progress) {
|
||||
var meta = can.base.isObject(content)? content: {content: content, title: title||can._help, duration: duration, progress: progress}
|
||||
@ -238,7 +241,6 @@ Volcanos("user", {help: "用户操作", agent: {
|
||||
can.page.Modify(can, ui._target, {style: {left: event.clientX, top: event.clientY}})
|
||||
},
|
||||
|
||||
info: {},
|
||||
input: function(event, can, form, cb, button) { if (!form || form.length == 0) { return cb() }
|
||||
var msg = can.request(event)
|
||||
var ui = can.page.Append(can, document.body, [{view: [html.INPUT], style: {left: 0, top: 0}, list: [
|
||||
|
@ -1,6 +1,7 @@
|
||||
Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, cb, target) {
|
||||
can.Conf(aaa.USERNICK, msg.Option(aaa.USERNICK)||msg.Option(ice.MSG_USERNICK)||msg.Option(ice.MSG_USERNAME)||can.Conf(aaa.USERNICK))
|
||||
can.user.info.usernick = can.Conf(aaa.USERNICK)
|
||||
can.user.info.avatar = msg.Option(aaa.AVATAR)
|
||||
can.ondaemon._init(can)
|
||||
|
||||
can.onengine.plugin(can, "topic", shy("主题", {
|
||||
|
@ -73,7 +73,7 @@ fieldset.inner>div.output td.content>div.tabs { display:none; }
|
||||
fieldset.inner>div.output td.content>div.path { display:none; }
|
||||
|
||||
body.simple fieldset.inner>div.output td.content>div.tabs { background:#546E7A; padding:0px; height:38px; overflow:auto; display:block; }
|
||||
body.simple fieldset.inner>div.output td.content>div.tabs div.tabs { background:#B0BEC5; color:white; font-size:1rem; padding:10px; float:left; }
|
||||
body.simple fieldset.inner>div.output td.content>div.tabs div.tabs { background:#69818d; color:white; font-size:1rem; padding:10px; float:left; }
|
||||
body.simple fieldset.inner>div.output td.content>div.tabs div.tabs.select { background:#455A64; box-shadow:0px 0px 5px 1px grey; }
|
||||
body.simple fieldset.inner>div.output td.content>div.path {
|
||||
background:#455A64; color:white; padding:4px 10px;
|
||||
|
@ -52,7 +52,12 @@ Volcanos("onimport", {help: "导入数据", _init: function(can, msg, cb, target
|
||||
})
|
||||
})
|
||||
})
|
||||
can.onimport.tabview(can, can.Option(nfs.PATH), can.Option(nfs.FILE), can.Option(nfs.LINE))
|
||||
if (location.hash) {
|
||||
can.onimport.tabview(can, can.Option(nfs.PATH), decodeURIComponent(location.hash).slice(1), 1)
|
||||
} else {
|
||||
can.onimport.tabview(can, can.Option(nfs.PATH), can.Option(nfs.FILE), can.Option(nfs.LINE))
|
||||
}
|
||||
|
||||
can.user.isMobile && !can.user.isLandscape() && can.onmotion.hidden(can, can.ui.project)
|
||||
},
|
||||
_simple: function(can, target) {
|
||||
@ -184,6 +189,7 @@ Volcanos("onimport", {help: "导入数据", _init: function(can, msg, cb, target
|
||||
}, project.plugin)
|
||||
},
|
||||
tabview: function(can, path, file, line, cb, skip, skip2) { var key = can.onexport.keys(can, file, path)
|
||||
if (can.user.mod.isCmd) { location.hash = file }
|
||||
if (!skip && can.tabview[key]) { can.user.mod.isCmd && can.user.title(path+file)
|
||||
can._msg && can._msg.Option(nfs.LINE, can.Option(nfs.LINE)), can._msg = can.tabview[key]
|
||||
can.Option({path: path, file: file, line: line||can._msg.Option(nfs.LINE)||1})
|
||||
@ -273,12 +279,18 @@ Volcanos("onimport", {help: "导入数据", _init: function(can, msg, cb, target
|
||||
if (!height || height > window.innerHeight) { height = window.innerHeight - 200 }
|
||||
if (can.user.isMobile && can.user.isLandscape() && height < 200) { height = 400 }
|
||||
|
||||
var rest = can.ui.display.offsetHeight+can.ui._path.offsetHeight+can.ui._tabs.offsetHeight+5
|
||||
if (can.user.mod.isCmd) { can.page.styleHeight(can, can.ui.project, height+2*html.ACTION_HEIGHT)
|
||||
can.page.styleHeight(can, can.ui.content, (can.ui.project.offsetHeight||height)-rest)
|
||||
can.page.styleHeight(can, can.ui.profile_output, (can.ui.project.offsetHeight||height)-rest+html.ACTION_HEIGHT+6)
|
||||
// can.page.styleHeight(can, can.ui.profile_output, can.ui.project.offsetHeight-html.ACTION_HEIGHT-2)
|
||||
if (can.ui.project.offsetHeight) {
|
||||
var rest = can.ui.display.offsetHeight+can.ui._path.offsetHeight+can.ui._tabs.offsetHeight+5
|
||||
can.page.styleHeight(can, can.ui.content, can.ui.project.offsetHeight-rest)
|
||||
can.page.styleHeight(can, can.ui.profile_output, can.ui.project.offsetHeight-rest+html.ACTION_HEIGHT+6)
|
||||
} else {
|
||||
var rest = can.ui.display.offsetHeight+5
|
||||
can.page.styleHeight(can, can.ui.content, height-8)
|
||||
can.page.styleHeight(can, can.ui.profile_output, height+html.ACTION_HEIGHT+6-8)
|
||||
}
|
||||
} else {
|
||||
var rest = can.ui.display.offsetHeight+can.ui._path.offsetHeight+can.ui._tabs.offsetHeight+5
|
||||
can.page.style(can, can.ui.content, can.user.mod.isCmd || can.user.isMobile? html.HEIGHT: html.MAX_HEIGHT, height)
|
||||
can.page.styleHeight(can, can.ui.project, can.ui.content.offsetHeight+rest)
|
||||
if (can.page.ClassList.has(can, can._fields, "full")) {
|
||||
|
@ -3,22 +3,21 @@ fieldset.vimer>div.output input.current {
|
||||
padding:0; padding-left:11px; border:none; outline:none; margin:0; margin-top:-1px;
|
||||
height:22px; position:absolute;
|
||||
}
|
||||
fieldset.vimer>div.output div.complete.insert {
|
||||
display:block;
|
||||
}
|
||||
fieldset.vimer>div.output input.current.normal { caret-color:gray; }
|
||||
fieldset.vimer>div.output input.current.insert { caret-color:yellow; }
|
||||
|
||||
fieldset.vimer>div.output div.complete {
|
||||
height:20px; position:absolute; left:32px; margin-top:20px;
|
||||
display:none;
|
||||
}
|
||||
fieldset.vimer>div.output div.complete.insert {
|
||||
display:block;
|
||||
}
|
||||
fieldset.vimer>div.output div.complete div.pre {
|
||||
font-size:1.1rem; margin-left:5px; float:left;
|
||||
color:#f0f8ff00;
|
||||
font-size:1.1rem; color:#f0f8ff00; margin-left:5px; float:left;
|
||||
}
|
||||
fieldset.vimer>div.output div.complete table {
|
||||
background:lightblue; float:left;
|
||||
max-height:200px;
|
||||
display:block;
|
||||
overflow:auto;
|
||||
background:lightblue; max-height:400px; max-width:600px; overflow:auto; display:block; float:left;
|
||||
}
|
||||
fieldset.vimer>div.output div.complete table.content th {
|
||||
display:none;
|
||||
@ -26,8 +25,6 @@ fieldset.vimer>div.output div.complete table.content th {
|
||||
fieldset.vimer>div.output div.complete table.content td {
|
||||
font-size:1.1rem;
|
||||
}
|
||||
fieldset.vimer>div.output input.current.insert { caret-color:black; }
|
||||
fieldset.vimer>div.output input.current.normal { caret-color:lightgray; }
|
||||
|
||||
body.simple fieldset.vimer>div.output div.complete div.pre {
|
||||
font-size:1rem;
|
||||
@ -35,3 +32,6 @@ body.simple fieldset.vimer>div.output div.complete div.pre {
|
||||
body.simple fieldset.vimer>div.output div.complete table.content td {
|
||||
font-size:1rem;
|
||||
}
|
||||
|
||||
body.white fieldset.vimer>div.output input.current.insert { caret-color:black; }
|
||||
body.white fieldset.vimer>div.output input.current.normal { caret-color:lightgray; }
|
||||
|
@ -1,57 +1,45 @@
|
||||
Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, cb, target) {
|
||||
can.undo = [], can.redo = []
|
||||
can.require(["inner.js"], function(can) { can.onimport.inner_init(can, msg, function() {
|
||||
can.page.ClassList.add(can, can._fields, "inner")
|
||||
can.require(["inner.js"], function(can) { can.onimport.inner_init(can, msg, function() { can.undo = [], can.redo = []
|
||||
can.onkeymap._build(can), can.onimport._input(can), can.onkeymap._plugin({}, can), can.base.isFunc(cb) && cb(msg)
|
||||
|
||||
}, target) }, function(can, name, sub) { name == chat.ONIMPORT && (can.onimport.inner_init = sub._init)
|
||||
if (name == chat.ONACTION) { can._trans = can.base.Copy(can._trans||{}, sub._trans) }
|
||||
if (name == chat.ONKEYMAP) {
|
||||
can.base.Copy(can.onkeymap._mode, sub._mode)
|
||||
can.core.Item(can.onkeymap._mode.normal, function(k, v) {
|
||||
if (!sub._mode.plugin[k]) { sub._mode.plugin[k] = v }
|
||||
})
|
||||
can.core.Item(sub._mode.plugin, function(k, v) {
|
||||
if (!can.onkeymap._mode.normal[k]) { can.onkeymap._mode.normal[k] = v }
|
||||
})
|
||||
if (name == chat.ONKEYMAP) { can.base.Copy(can.onkeymap._mode, sub._mode)
|
||||
can.core.Item(can.onkeymap._mode.normal, function(k, v) { sub._mode.plugin[k] || (sub._mode.plugin[k] = v) })
|
||||
can.core.Item(sub._mode.plugin, function(k, v) { can.onkeymap._mode.normal[k] || (can.onkeymap._mode.normal[k] = v) })
|
||||
}
|
||||
})
|
||||
},
|
||||
_input: function(can) {
|
||||
var ui = can.page.Append(can, can.ui.content.parentNode, [
|
||||
{view: ["current", html.INPUT], spellcheck: false, onkeydown: function(event) { if (event.metaKey) { return }
|
||||
can.misc.Debug("key", event.key)
|
||||
if (event.ctrlKey && can.onaction._complete(event, can)) { return }
|
||||
can._keylist = can.onkeymap._parse(event, can, can.mode+(event.ctrlKey? "_ctrl": ""), can._keylist, can.ui.current)
|
||||
can.mode == "insert" && can.core.Timer(10, function() { can.current.text(can.ui.current.value) })
|
||||
can.mode == "normal" && can.Status("按键", can._keylist.join(""))
|
||||
can.mode == "normal" && can.onkeymap.prevent(event)
|
||||
}, onkeyup: function(event) { can.onaction._complete(event, can, can.ui.complete)
|
||||
}, onkeyup: function(event) { can.onaction._complete(event, can)
|
||||
|
||||
}, onfocus: function(event) { can.onaction._complete(event, can, can.ui.complete)
|
||||
can.page.styleWidth(can, can.ui.current, can.ui.content.style.width)
|
||||
}, onclick: function(event) { can.onkeymap._insert(event, can)
|
||||
|
||||
}, ondblclick: function(event) { var target = event.target
|
||||
return
|
||||
can.onaction.searchLine(event, can, target.value.slice(target.selectionStart, target.selectionEnd))
|
||||
},
|
||||
}, {view: ["complete"]},
|
||||
}}, {view: ["complete"]},
|
||||
]); can.ui.current = ui.current, can.ui.complete = ui.complete
|
||||
},
|
||||
}, [""])
|
||||
Volcanos("onkeymap", {help: "键盘交互", list: [],
|
||||
_model: function(can, value) { can.Status("模式", can.mode = value)
|
||||
can.page.Modify(can, can.ui.complete, {className: "complete"+ice.SP+can.mode}), value
|
||||
return can.page.Modify(can, can.ui.current, {className: "current"+ice.SP+can.mode}), value
|
||||
can.page.Modify(can, can.ui.current, {className: ["current", can.mode]}), value
|
||||
can.page.Modify(can, can.ui.complete, {className: ["complete", can.mode]}), value
|
||||
},
|
||||
_plugin: function(event, can) { can.onkeymap._model(can, "plugin")
|
||||
can.ui.current.blur()
|
||||
},
|
||||
_normal: function(event, can) { can.onkeymap._model(can, "normal")
|
||||
can.ui.current.focus(), can.ui.content.scrollLeft -= 10000
|
||||
can.ui.current.focus()
|
||||
},
|
||||
_insert: function(event, can) { can.onkeymap._model(can, "insert")
|
||||
can.ui.current.focus(), can.ui.content.scrollLeft -= 10000
|
||||
can.onkeymap.prevent(event)
|
||||
can.ui.current.focus(), can.onkeymap.prevent(event)
|
||||
can._keylist = []
|
||||
},
|
||||
|
||||
_mode: {
|
||||
@ -78,8 +66,7 @@ Volcanos("onkeymap", {help: "键盘交互", list: [],
|
||||
var next = can.current.next(); if (!next) { return }
|
||||
var line = can.current.line, text = can.current.text()
|
||||
var rest = can.page.Select(can, next, "td.text")[0].innerText
|
||||
can.current.text(text.trimRight()+" "+rest.trimLeft()), can.onaction.deleteLine(can, next)
|
||||
|
||||
can.current.text(text.trimRight()+ice.SP+rest.trimLeft()), can.onaction.deleteLine(can, next)
|
||||
can.undo.push(function() { can.onaction.modifyLine(can, line, text), can.onaction.insertLine(can, rest, line.nextSibling) })
|
||||
},
|
||||
H: function(event, can, target) { can.onkeymap.cursorMove(can, target, 0, 0) },
|
||||
@ -131,24 +118,35 @@ Volcanos("onkeymap", {help: "键盘交互", list: [],
|
||||
c: function(event, can) { can.onaction.compile(event, can, "compile") },
|
||||
},
|
||||
insert: {
|
||||
jk: function(event, can, target) { can.onkeymap._normal(event, can),
|
||||
can.onkeymap.deleteText(target, target.selectionStart-1, 1)
|
||||
jk: function(event, can, target) { can.onkeymap._normal(event, can)
|
||||
can.onkeymap.deleteText(target, target.selectionStart-1, 1)
|
||||
can.current.text(can.ui.current.value)
|
||||
},
|
||||
Escape: function(event, can) { can.onkeymap._normal(event, can) },
|
||||
Tab: function(event, can) {
|
||||
Escape: function(event, can) {
|
||||
if (event.key != "Escape") { return }
|
||||
can.onkeymap._normal(event, can)
|
||||
},
|
||||
Tab: function(event, can) {
|
||||
if (event.key != "Tab") { return }
|
||||
can.onkeymap.insertText(can.ui.current, "\t")
|
||||
can.onkeymap.prevent(event)
|
||||
},
|
||||
|
||||
Enter: function(event, can, target) {
|
||||
if (event.key != "Enter") { return }
|
||||
var rest = can.onkeymap.deleteText(target, target.selectionEnd), text = can.ui.current.value
|
||||
var indent = (text.substr(0, text.indexOf(text.trimLeft()))+(text.endsWith("}")?"\t":""))||(text.trimRight() == ""? text: "")
|
||||
var line = can.onaction.insertLine(can, indent+rest.trimLeft(), can.current.next())
|
||||
var left = text.substr(0, text.indexOf(text.trimLeft()))||(text.trimRight() == ""? text: "")
|
||||
if (text.endsWith("{")) { can.onaction.insertLine(can, left+"}", can.current.next()), left += "\t" }
|
||||
if (text.endsWith("[")) { can.onaction.insertLine(can, left+"]", can.current.next()), left += "\t" }
|
||||
if (text.endsWith("(")) { can.onaction.insertLine(can, left+")", can.current.next()), left += "\t" }
|
||||
if (text.endsWith("`") && can.base.count(text, "`")%2==1) { can.onaction.insertLine(can, left+"`", can.current.next()) }
|
||||
|
||||
var line = can.onaction.insertLine(can, left+rest.trimLeft(), can.current.next())
|
||||
can.current.text(text.trimRight()||text), can.onaction.selectLine(event, can, line)
|
||||
can.onkeymap.cursorMove(can, can.ui.current, indent.length, 0)
|
||||
can.onkeymap.cursorMove(can, can.ui.current, left.length, 0)
|
||||
},
|
||||
Backspace: function(event, can, target) {
|
||||
if (event.key != "Backspace") { return }
|
||||
if (target.selectionStart > 0) { return }
|
||||
if (!can.current.prev()) { return }
|
||||
can.onkeymap.prevent(event)
|
||||
@ -161,123 +159,148 @@ Volcanos("onkeymap", {help: "键盘交互", list: [],
|
||||
can.ui.current.value = can.current.text()+rest
|
||||
can.onkeymap.cursorMove(can, can.ui.current, 0, pos)
|
||||
},
|
||||
ArrowUp: function(event, can) { can.onaction.selectLine(event, can, can.current.prev()) },
|
||||
ArrowDown: function(event, can) { can.onaction.selectLine(event, can, can.current.next()) },
|
||||
ArrowUp: function(event, can) {
|
||||
if (event.key != "ArrowUp") { return }
|
||||
can.onaction.selectLine(event, can, can.current.prev())
|
||||
},
|
||||
ArrowDown: function(event, can) {
|
||||
if (event.key != "ArrowDown") { return }
|
||||
can.onaction.selectLine(event, can, can.current.next())
|
||||
},
|
||||
},
|
||||
}, _engine: {},
|
||||
})
|
||||
Volcanos("onaction", {help: "控件交互", list: [nfs.SAVE, code.AUTOGEN, code.COMPILE, "script", chat.WEBSITE, "dream", "publish"],
|
||||
save: function(event, can) { var msg = can.request(event, {content: can.onexport.content(can)})
|
||||
can.run(event, [ctx.ACTION, nfs.SAVE, can.parse, can.Option(nfs.FILE), can.Option(nfs.PATH)], function(msg) {
|
||||
can.onimport.project(can, can.Option(nfs.PATH))
|
||||
can.user.toastSuccess(can)
|
||||
}, true)
|
||||
},
|
||||
autogen: function(event, can, button) { var meta = can.Conf(), msg = can.request(event, {_handle: ice.TRUE})
|
||||
can.user.input(event, can, meta.feature[button], function(ev, btn, data, list, args) {
|
||||
can.run(event, [ctx.ACTION, button].concat(args), function(msg) {
|
||||
can.onimport.tabview(can, can.Option(nfs.PATH), msg.Option(nfs.FILE))
|
||||
can.onimport.project(can, can.Option(nfs.PATH))
|
||||
}, true)
|
||||
Volcanos("onaction", {help: "控件交互", list: [nfs.SAVE, code.AUTOGEN, code.COMPILE, nfs.SCRIPT, chat.WEBSITE, web.DREAM, code.PUBLISH],
|
||||
_run: function(event, can, button, args, cb) {
|
||||
can.runAction(event, button, args, cb||function(msg) {
|
||||
can.onimport.tabview(can, can.Option(nfs.PATH), msg.Option(nfs.FILE))
|
||||
can.onimport.project(can, can.Option(nfs.PATH)), can.user.toastSuccess(can, button)
|
||||
})
|
||||
},
|
||||
compile: function(event, can, button) { var msg = can.ui.search.request(event, {_handle: ice.TRUE, _toast: "编译中..."}, can.Option())
|
||||
can.run(event, [ctx.ACTION, button], function(msg) {
|
||||
if (msg.Length() == 0) { var toast = can.user.toast(can, "重启中...", "", -1)
|
||||
can.core.Timer(5000, function() { toast.close(), can.onaction["展示"]({}, can) })
|
||||
} else {
|
||||
can.ui.search._show(msg)
|
||||
}
|
||||
}, true)
|
||||
},
|
||||
_complete: function(event, can, target) {
|
||||
var pre = event.target.value.slice(0, event.target.selectionStart)
|
||||
var end = event.target.value.slice(event.target.selectionStart)
|
||||
var key = can.core.Split(pre, "\t ", "\t ").pop()||""
|
||||
var word = can.core.Split(key, "\t ", ".").pop()||""
|
||||
key = can.base.trimSuffix(key, word)
|
||||
key = can.base.trimSuffix(key, ".")
|
||||
|
||||
function update(target) { can.request(event, {pre: pre, end: end, key: key, word: word, file: can.Option(nfs.FILE)})
|
||||
can.run(event, [ctx.ACTION, "complete"], function(msg) {
|
||||
can.page.Appends(can, target, [{view: ["pre", html.DIV, pre]}])
|
||||
msg.Length() == 0 && pre == "" && can.core.List(can.core.Value(can.onsyntax[can.parse], "prepare.keyword"), function(k) {
|
||||
msg.Push(mdb.NAME, k)
|
||||
})
|
||||
can.onappend.table(can, msg, function(value, key, index) {
|
||||
return {text: [value, html.TD], onclick: function(event) {
|
||||
var left = can.ui.current.value.slice(0, event.target.selectionStart)+value
|
||||
can.ui.current.value = can.current.text(left+can.ui.current.value.slice(event.target.selectionEnd))
|
||||
can.ui.current.setSelectionRange(left.length, left.length)
|
||||
can.ui.current.focus(), can.ui.content.scrollBy(-10000, 0)
|
||||
}}
|
||||
}, target)
|
||||
}, true)
|
||||
}
|
||||
function select() {
|
||||
return can.page.Select(can, target, html.TR, function(tr) {
|
||||
if (!can.page.ClassList.set(can, tr, html.HIDE, can.page.Select(can, tr, html.TD, function(td) {
|
||||
if (td.innerText.indexOf(word) > -1) { return td }
|
||||
}).length == 0)) { return tr }
|
||||
}).length > 0
|
||||
}
|
||||
|
||||
switch (event.key) {
|
||||
case "Enter": can.onmotion.clear(can, target); break
|
||||
case ice.TB: update(target); break
|
||||
case ice.SP: update(target); break
|
||||
default: select() || update(target); break
|
||||
}
|
||||
},
|
||||
script: function(event, can, button) { var meta = can.Conf()
|
||||
can.request(event, {_handle: ice.TRUE, action: button, file: "hi/hi.js", text: `Volcanos("onimport", {help: "导入数据", list:[], _init: function(can, msg, cb, target) {
|
||||
msg.Echo("hello world")
|
||||
can.onappend.table(can, msg)
|
||||
can.onappend.board(can, msg)
|
||||
}})`}, can.Option())
|
||||
_runs: function(event, can, button) { var meta = can.Conf(); can.request(event, {action: button})
|
||||
can.user.input(event, can, meta.feature[button], function(ev, btn, data, list, args) {
|
||||
can.run(event, [ctx.ACTION, button].concat(args), function(msg) {
|
||||
can.onimport.tabview(can, can.Option(nfs.PATH), msg.Option(nfs.FILE))
|
||||
can.onimport.project(can, can.Option(nfs.PATH))
|
||||
}, true)
|
||||
can.onaction._run(event, can, button, args)
|
||||
})
|
||||
},
|
||||
website: function(event, can, button) { var meta = can.Conf()
|
||||
can.request(event, {_handle: ice.TRUE, action: button, file: "hi.zml", text: `
|
||||
left
|
||||
username
|
||||
系统
|
||||
命令 index cli.system
|
||||
共享 index cli.qrcode
|
||||
代码
|
||||
趋势 index web.code.git.trend args icebergs action auto
|
||||
状态 index web.code.git.status args icebergs
|
||||
main
|
||||
|
||||
`.trim()}, can.Option())
|
||||
can.user.input(event, can, meta.feature[button], function(ev, btn, data, list, args) {
|
||||
can.run(event, [ctx.ACTION, button].concat(args), function(msg) {
|
||||
can.onimport.tabview(can, can.Option(nfs.PATH), msg.Option(nfs.FILE))
|
||||
can.onimport.project(can, can.Option(nfs.PATH))
|
||||
}, true)
|
||||
save: function(event, can, button) { can.request(event, {file: can.Option(nfs.FILE), content: can.onexport.content(can)})
|
||||
can.runAction(event, nfs.SAVE, [can.parse, can.Option(nfs.FILE), can.Option(nfs.PATH)], function() {
|
||||
can.user.toastSuccess(can, button)
|
||||
})
|
||||
},
|
||||
autogen: function(event, can, button) { can.onaction._runs(event, can, button) },
|
||||
compile: function(event, can, button) { var toast0 = can.user.toastProcess(can, "编译中...")
|
||||
can.runAction(event, button, [], function(msg) { toast0.close()
|
||||
if (msg.Length() == 0) { var toast1 = can.user.toastProcess(can, "重启中...")
|
||||
can.core.Timer(3000, function() { toast1.close(), can.onaction["展示"]({}, can) })
|
||||
} else { can.ui.search._show(msg) }
|
||||
})
|
||||
},
|
||||
script: function(event, can, button) {
|
||||
can.request(event, {file: "hi/hi.js"})
|
||||
can.onaction._runs(event, can, button)
|
||||
},
|
||||
website: function(event, can, button) {
|
||||
can.request(event, {file: "hi.zml"})
|
||||
can.onaction._runs(event, can, button)
|
||||
},
|
||||
publish: function(event, can, button) {
|
||||
can.run(event, [ctx.ACTION, button], function(msg) {
|
||||
can.user.toast(can, {
|
||||
title: "发布应用", duration: -1, width: -300,
|
||||
content: msg.Result(), action: [cli.CLOSE],
|
||||
can.runAction(event, button, [], function(msg) { can.user.toastConfirm(can, button, msg.Result()) })
|
||||
},
|
||||
|
||||
listTags: function(event, can, button) { var list = []
|
||||
can.core.Item(can.request(event), function(key, value) { if (key.indexOf("_") == 0) { return }
|
||||
list.push({zone: "msg", type: typeof value, name: key, text: can.base.isObject(value)? "": (value+"").split(ice.NL)[0],
|
||||
path: "usr/volcanos/", file: "lib/misc.js", line: 1,
|
||||
})
|
||||
})
|
||||
can.core.List([can.base, can.core, can.misc, can.page, can.user, can.onengine, can.ondaemon, can.onappend, can.onlayout, can.onmotion, can.onkeymap], function(lib) {
|
||||
can.core.Item(lib, function(key, value) { if (key.indexOf("_") == 0 || !lib.hasOwnProperty(key)) { return }
|
||||
list.push({zone: lib._name, type: typeof value, name: key, text: can.base.isObject(value)? "": (value+"").split(ice.NL)[0],
|
||||
path: "usr/volcanos/", file: lib._path, line: 1,
|
||||
})
|
||||
})
|
||||
})
|
||||
can.request(event, {text: can.base.Format(list)})
|
||||
can.runAction(event, button)
|
||||
},
|
||||
_complete: function(event, can, target) { target = target||can.ui.complete
|
||||
if (event == undefined || event.target == undefined || event.target.value == undefined) { return }
|
||||
var pre = event.target.value.slice(0, event.target.selectionStart)
|
||||
var end = event.target.value.slice(event.target.selectionStart)
|
||||
var type = can.core.Split(pre).pop()||""
|
||||
var name = can.core.Split(type, "", ice.PT).pop()||""
|
||||
type = can.base.trimSuffix(type, name)
|
||||
type = can.base.trimSuffix(type, ice.PT)
|
||||
const PRE = "pre"
|
||||
|
||||
function update(target) { can.request(event, {pre: pre, end: end, type: type, name: name, file: can.Option(nfs.FILE)})
|
||||
can.runAction(event, "complete", [], function(msg) { can.ui.complete._msg = msg
|
||||
if (msg.Length() == 0 && can.base.Ext(can.Option(nfs.FILE)) == nfs.JS) {
|
||||
can.core.Item(can.core.Value(window, type), function(k, v) { msg.Push(mdb.NAME, k)
|
||||
try { msg.Push(mdb.TEXT, v) } catch (e) { msg.Push(mdb.TEXT, "") }
|
||||
})
|
||||
}
|
||||
msg.Length() == 0 && pre.trim() == "" && can.core.Item(can.core.Value(can.onsyntax[can.parse], code.KEYWORD), function(k) {
|
||||
msg.Push(mdb.NAME, k)
|
||||
})
|
||||
|
||||
can.page.Appends(can, target, [{view: [PRE, html.DIV, pre]}])
|
||||
can.onappend.table(can, msg, function(value, key, index) { return {text: [value, html.TD], onclick: function(event) {
|
||||
var left = can.ui.current.value.slice(0, event.target.selectionStart)+value
|
||||
can.current.text(can.ui.current.value = left+can.ui.current.value.slice(event.target.selectionEnd))
|
||||
can.ui.current.focus(), can.ui.content.scrollLeft -= 10000, can.ui.current.setSelectionRange(left.length, left.length)
|
||||
}} }, target)
|
||||
})
|
||||
}
|
||||
|
||||
function filter() {
|
||||
return can.page.Select(can, target, [html.TBODY, html.TR], function(tr) {
|
||||
if (!can.page.ClassList.set(can, tr, html.HIDE, can.page.Select(can, tr, html.TD, function(td) {
|
||||
if (td.innerText.toLowerCase().indexOf(can.base.trimSuffix((name == ice.PT? type: name).toLowerCase(), "(")) == 0) { return td }
|
||||
}).length == 0)) { return tr }
|
||||
}).length > (name == ice.PT? 1: 0)
|
||||
}
|
||||
|
||||
function select(index, total) { index = (index+(total+1))%(total+1)
|
||||
if (index == total) { can.current.text(can.ui.current.value = can.ui.complete._msg.Option(PRE)) }
|
||||
can.page.Select(can, target, [html.TBODY, "tr:not(.hide)"], function(tr, i) { if (can.page.ClassList.set(can, tr, html.SELECT, i == index)) {
|
||||
can.current.text(can.ui.current.value = can.ui.complete._msg.Option(PRE)+can.page.Select(can, tr, html.TD)[0].innerText)
|
||||
} })
|
||||
return index
|
||||
}
|
||||
|
||||
if (event.ctrlKey) {
|
||||
if (event.type == "keyup") {
|
||||
var total = can.page.Select(can, target, [html.TBODY, "tr:not(.hide)"]).length
|
||||
switch (event.key) {
|
||||
case "n": can.ui.complete._index = select(can.ui.complete._index+1, total); break
|
||||
case "p": can.ui.complete._index = select(can.ui.complete._index-1, total); break
|
||||
default: return false
|
||||
}
|
||||
return can.onkeymap.prevent(event)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
can.current.line.appendChild(can.ui.complete), can.page.style(can, can.ui.complete, html.LEFT, can.ui.current.offsetLeft-1, html.MARGIN_TOP, can.ui.current.offsetHeight+4)
|
||||
can.page.Select(can, target, "div.pre", function(item) { item.innerText = can.ui.complete._msg.Option(PRE)||pre })
|
||||
if (pre == "") { return update(target) }
|
||||
|
||||
switch (event.key) {
|
||||
case html.ENTER: update(target); break
|
||||
case ice.TB: update(target); break
|
||||
case ice.PT: update(target); break
|
||||
case ice.SP: update(target); break
|
||||
default: filter() || update(target); break
|
||||
} can.ui.complete._index = -1
|
||||
},
|
||||
|
||||
_selectLine: function(event, can) {
|
||||
can.page.Select(can, can.current.line, "td.text", function(td) {
|
||||
can.current.line.appendChild(can.ui.current), can.page.Modify(can, can.ui.current, {style: kit.Dict(html.LEFT, td.offsetLeft-1, html.WIDTH, td.offsetWidth-12), value: td.innerText})
|
||||
can.current.line.appendChild(can.ui.complete), can.page.Modify(can, can.ui.complete, {style: kit.Dict(html.LEFT, td.offsetLeft-1, "margin-top", can.ui.current.offsetHeight+4)})
|
||||
can.page.Select(can, can.current.line, "td.text", function(td) { can.ui.current.value = td.innerText
|
||||
can.current.line.appendChild(can.ui.current), can.page.style(can, can.ui.current, html.LEFT, td.offsetLeft-1, html.WIDTH, can.ui.content.style.width)
|
||||
if (event) { if (can.mode == "plugin") { can.onkeymap._insert(event, can) }
|
||||
can.ui.current.focus(), can.onkeymap.cursorMove(can, can.ui.current, 0, (event.offsetX)/13-1)
|
||||
can.ui.content.scrollLeft -= 10000
|
||||
can.ui.current.focus(), can.ui.content.scrollLeft -= 10000
|
||||
can.onkeymap.cursorMove(can, can.ui.current, 0, (event.offsetX)/12-1)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
@ -227,19 +227,6 @@ Volcanos("onaction", {help: "交互操作", list: [
|
||||
can.Update(event, [ctx.ACTION, "prev", can.Status("total")||0, can.Option("limit")||can.Action("limit")||"", can.Option("offend")||can.Action("offend")||""])
|
||||
},
|
||||
|
||||
listTags: function(event, can, button) { var list = []
|
||||
can.core.List([can.base, can.core, can.misc, can.page, can.user,
|
||||
can.onengine, can.ondaemon, can.onappend, can.onlayout, can.onmotion, can.onkeymap,
|
||||
], function(lib) {
|
||||
can.core.Item(lib, function(key, value) { if (key.indexOf("_") == 0 || !lib.hasOwnProperty(key)) { return }
|
||||
list.push({zone: lib._name, type: typeof value, name: key, text: can.base.isObject(value)? "": (value+"").split(ice.NL)[0],
|
||||
path: "usr/volcanos/", file: lib._path, line: 1,
|
||||
})
|
||||
})
|
||||
})
|
||||
var msg = can.request(event, {_handle: true, text: can.base.Format(list)})
|
||||
can.run(event, [ctx.ACTION, button], function() { can.user.toastSuccess(can) })
|
||||
},
|
||||
getClipboardData: function(event, can, button) {
|
||||
function add(text) {
|
||||
can.run(event, can.base.Simple(ctx.ACTION, button, can.base.ParseJSON(text)), function(msg) {
|
||||
|
16
proto.js
16
proto.js
@ -74,6 +74,7 @@ var cli = {
|
||||
}
|
||||
var web = {
|
||||
SHARE: "share", SPACE: "space",
|
||||
DREAM: "dream",
|
||||
}
|
||||
var aaa = {
|
||||
PASSWORD: "password", USERNAME: "username", USERNICK: "usernick", BACKGROUND: "background", AVATAR: "avatar",
|
||||
@ -109,6 +110,7 @@ var nfs = {
|
||||
DIR: "dir", CAT: "cat", DEFS: "defs", TRASH: "trash",
|
||||
DIR_ROOT: "dir_root",
|
||||
SAVE: "save", LOAD: "load", TAGS: "tags", FIND: "find", GREP: "grep",
|
||||
SCRIPT: "script",
|
||||
}
|
||||
var tcp = {
|
||||
HOST: "host", PORT: "port",
|
||||
@ -120,6 +122,7 @@ var lex = {
|
||||
var code = {
|
||||
VIMER: "vimer", INNER: "inner", FAVOR: "favor",
|
||||
AUTOGEN: "autogen", COMPILE: "compile", BINPACK: "binpack", WEBPACK: "webpack", PUBLISH: "publish",
|
||||
KEYWORD: "keyword",
|
||||
}
|
||||
var wiki = {
|
||||
TITLE: "title", BRIEF: "brief", REFER: "refer", SPARK: "spark",
|
||||
@ -225,7 +228,7 @@ var html = {
|
||||
INPUT: "input", TEXT: "text", TEXTAREA: "textarea", SELECT: "select", BUTTON: "button",
|
||||
FORM: "form", FILE: "file", SPACE: "space", CLICK: "click", SUBMIT: "submit", CANCEL: "cancel",
|
||||
DIV: "div", IMG: "img", CODE: "code", SPAN: "span", VIDEO: "video",
|
||||
TABLE: "table", TR: "tr", TH: "th", TD: "td", BR: "br", UL: "ul", LI: "li",
|
||||
TABLE: "table", TBODY: "tbody", TR: "tr", TH: "th", TD: "td", BR: "br", UL: "ul", LI: "li",
|
||||
A: "a", LABEL: "label", INNER: "inner", TITLE: "title",
|
||||
H1: "h1", H2: "h2", H3: "h3",
|
||||
|
||||
@ -235,7 +238,7 @@ var html = {
|
||||
OPACITY: "opacity",
|
||||
STROKE_WIDTH: "stroke-width", STROKE: "stroke", FILL: "fill", FONT_SIZE: "font-size", MONOSPACE: "monospace",
|
||||
SCROLL: "scroll", HEIGHT: "height", WIDTH: "width", LEFT: "left", TOP: "top", RIGHT: "right", BOTTOM: "bottom",
|
||||
MIN_HEIGHT: "min-height", MAX_HEIGHT: "max-height", MAX_WIDTH: "max-width", MARGIN_X: "margin-x", MARGIN_Y: "margin-y",
|
||||
MIN_HEIGHT: "min-height", MAX_HEIGHT: "max-height", MAX_WIDTH: "max-width", MARGIN_TOP: "margin-top", MARGIN_X: "margin-x", MARGIN_Y: "margin-y",
|
||||
PLUGIN_MARGIN: 10, ACTION_HEIGHT: 29, ACTION_MARGIN: 200,
|
||||
TOGGLE: "toggle",
|
||||
|
||||
@ -258,6 +261,8 @@ var html = {
|
||||
DIV_LAYOUT_HEAD: "div.layout.head",
|
||||
DIV_LAYOUT_LEFT: "div.layout.left",
|
||||
DIV_LAYOUT_FOOT: "div.layout.foot",
|
||||
|
||||
ESCAPE: "Escape", ENTER: "Enter", TAB: "Tab",
|
||||
}
|
||||
var lang = {
|
||||
UNDEFINED: "undefined",
|
||||
@ -363,6 +368,13 @@ var Volcanos = shy("火山架", {iceberg: "/chat/", volcano: "/frame.js", args:
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user