mirror of
https://github.com/unraid/webgui.git
synced 2026-04-24 02:58:57 -05:00
repo reorg
This commit is contained in:
+58
@@ -0,0 +1,58 @@
|
||||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
mod(require("../../lib/codemirror"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
CodeMirror.defineOption("placeholder", "", function(cm, val, old) {
|
||||
var prev = old && old != CodeMirror.Init;
|
||||
if (val && !prev) {
|
||||
cm.on("blur", onBlur);
|
||||
cm.on("change", onChange);
|
||||
onChange(cm);
|
||||
} else if (!val && prev) {
|
||||
cm.off("blur", onBlur);
|
||||
cm.off("change", onChange);
|
||||
clearPlaceholder(cm);
|
||||
var wrapper = cm.getWrapperElement();
|
||||
wrapper.className = wrapper.className.replace(" CodeMirror-empty", "");
|
||||
}
|
||||
|
||||
if (val && !cm.hasFocus()) onBlur(cm);
|
||||
});
|
||||
|
||||
function clearPlaceholder(cm) {
|
||||
if (cm.state.placeholder) {
|
||||
cm.state.placeholder.parentNode.removeChild(cm.state.placeholder);
|
||||
cm.state.placeholder = null;
|
||||
}
|
||||
}
|
||||
function setPlaceholder(cm) {
|
||||
clearPlaceholder(cm);
|
||||
var elt = cm.state.placeholder = document.createElement("pre");
|
||||
elt.style.cssText = "height: 0; overflow: visible";
|
||||
elt.className = "CodeMirror-placeholder";
|
||||
elt.appendChild(document.createTextNode(cm.getOption("placeholder")));
|
||||
cm.display.lineSpace.insertBefore(elt, cm.display.lineSpace.firstChild);
|
||||
}
|
||||
|
||||
function onBlur(cm) {
|
||||
if (isEmpty(cm)) setPlaceholder(cm);
|
||||
}
|
||||
function onChange(cm) {
|
||||
var wrapper = cm.getWrapperElement(), empty = isEmpty(cm);
|
||||
wrapper.className = wrapper.className.replace(" CodeMirror-empty", "") + (empty ? " CodeMirror-empty" : "");
|
||||
|
||||
if (empty) setPlaceholder(cm);
|
||||
else clearPlaceholder(cm);
|
||||
}
|
||||
|
||||
function isEmpty(cm) {
|
||||
return (cm.lineCount() === 1) && (cm.getLine(0) === "");
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,149 @@
|
||||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
mod(require("../../lib/codemirror"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
|
||||
function doFold(cm, pos, options, force) {
|
||||
if (options && options.call) {
|
||||
var finder = options;
|
||||
options = null;
|
||||
} else {
|
||||
var finder = getOption(cm, options, "rangeFinder");
|
||||
}
|
||||
if (typeof pos == "number") pos = CodeMirror.Pos(pos, 0);
|
||||
var minSize = getOption(cm, options, "minFoldSize");
|
||||
|
||||
function getRange(allowFolded) {
|
||||
var range = finder(cm, pos);
|
||||
if (!range || range.to.line - range.from.line < minSize) return null;
|
||||
var marks = cm.findMarksAt(range.from);
|
||||
for (var i = 0; i < marks.length; ++i) {
|
||||
if (marks[i].__isFold && force !== "fold") {
|
||||
if (!allowFolded) return null;
|
||||
range.cleared = true;
|
||||
marks[i].clear();
|
||||
}
|
||||
}
|
||||
return range;
|
||||
}
|
||||
|
||||
var range = getRange(true);
|
||||
if (getOption(cm, options, "scanUp")) while (!range && pos.line > cm.firstLine()) {
|
||||
pos = CodeMirror.Pos(pos.line - 1, 0);
|
||||
range = getRange(false);
|
||||
}
|
||||
if (!range || range.cleared || force === "unfold") return;
|
||||
|
||||
var myWidget = makeWidget(cm, options);
|
||||
CodeMirror.on(myWidget, "mousedown", function(e) {
|
||||
myRange.clear();
|
||||
CodeMirror.e_preventDefault(e);
|
||||
});
|
||||
var myRange = cm.markText(range.from, range.to, {
|
||||
replacedWith: myWidget,
|
||||
clearOnEnter: true,
|
||||
__isFold: true
|
||||
});
|
||||
myRange.on("clear", function(from, to) {
|
||||
CodeMirror.signal(cm, "unfold", cm, from, to);
|
||||
});
|
||||
CodeMirror.signal(cm, "fold", cm, range.from, range.to);
|
||||
}
|
||||
|
||||
function makeWidget(cm, options) {
|
||||
var widget = getOption(cm, options, "widget");
|
||||
if (typeof widget == "string") {
|
||||
var text = document.createTextNode(widget);
|
||||
widget = document.createElement("span");
|
||||
widget.appendChild(text);
|
||||
widget.className = "CodeMirror-foldmarker";
|
||||
}
|
||||
return widget;
|
||||
}
|
||||
|
||||
// Clumsy backwards-compatible interface
|
||||
CodeMirror.newFoldFunction = function(rangeFinder, widget) {
|
||||
return function(cm, pos) { doFold(cm, pos, {rangeFinder: rangeFinder, widget: widget}); };
|
||||
};
|
||||
|
||||
// New-style interface
|
||||
CodeMirror.defineExtension("foldCode", function(pos, options, force) {
|
||||
doFold(this, pos, options, force);
|
||||
});
|
||||
|
||||
CodeMirror.defineExtension("isFolded", function(pos) {
|
||||
var marks = this.findMarksAt(pos);
|
||||
for (var i = 0; i < marks.length; ++i)
|
||||
if (marks[i].__isFold) return true;
|
||||
});
|
||||
|
||||
CodeMirror.commands.toggleFold = function(cm) {
|
||||
cm.foldCode(cm.getCursor());
|
||||
};
|
||||
CodeMirror.commands.fold = function(cm) {
|
||||
cm.foldCode(cm.getCursor(), null, "fold");
|
||||
};
|
||||
CodeMirror.commands.unfold = function(cm) {
|
||||
cm.foldCode(cm.getCursor(), null, "unfold");
|
||||
};
|
||||
CodeMirror.commands.foldAll = function(cm) {
|
||||
cm.operation(function() {
|
||||
for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++)
|
||||
cm.foldCode(CodeMirror.Pos(i, 0), null, "fold");
|
||||
});
|
||||
};
|
||||
CodeMirror.commands.unfoldAll = function(cm) {
|
||||
cm.operation(function() {
|
||||
for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++)
|
||||
cm.foldCode(CodeMirror.Pos(i, 0), null, "unfold");
|
||||
});
|
||||
};
|
||||
|
||||
CodeMirror.registerHelper("fold", "combine", function() {
|
||||
var funcs = Array.prototype.slice.call(arguments, 0);
|
||||
return function(cm, start) {
|
||||
for (var i = 0; i < funcs.length; ++i) {
|
||||
var found = funcs[i](cm, start);
|
||||
if (found) return found;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.registerHelper("fold", "auto", function(cm, start) {
|
||||
var helpers = cm.getHelpers(start, "fold");
|
||||
for (var i = 0; i < helpers.length; i++) {
|
||||
var cur = helpers[i](cm, start);
|
||||
if (cur) return cur;
|
||||
}
|
||||
});
|
||||
|
||||
var defaultOptions = {
|
||||
rangeFinder: CodeMirror.fold.auto,
|
||||
widget: "\u2194",
|
||||
minFoldSize: 0,
|
||||
scanUp: false
|
||||
};
|
||||
|
||||
CodeMirror.defineOption("foldOptions", null);
|
||||
|
||||
function getOption(cm, options, name) {
|
||||
if (options && options[name] !== undefined)
|
||||
return options[name];
|
||||
var editorOptions = cm.options.foldOptions;
|
||||
if (editorOptions && editorOptions[name] !== undefined)
|
||||
return editorOptions[name];
|
||||
return defaultOptions[name];
|
||||
}
|
||||
|
||||
CodeMirror.defineExtension("foldOption", function(options, name) {
|
||||
return getOption(this, options, name);
|
||||
});
|
||||
});
|
||||
+377
@@ -0,0 +1,377 @@
|
||||
function getLibvirtSchema() {
|
||||
|
||||
var root = {};
|
||||
|
||||
root.domain = {
|
||||
"!attrs": {
|
||||
type: ["kvm"],
|
||||
"xmlns:qemu": ["http://libvirt.org/schemas/domain/qemu/1.0"]
|
||||
}
|
||||
};
|
||||
|
||||
root.domain.name = {
|
||||
"!value": ""
|
||||
};
|
||||
|
||||
root.domain.description = {
|
||||
"!value": ""
|
||||
};
|
||||
|
||||
root.domain.maxMemory = {
|
||||
"!attrs": {
|
||||
slots: null,
|
||||
unit: ["MiB", "KiB", "GiB"]
|
||||
},
|
||||
"!value": 512
|
||||
};
|
||||
|
||||
root.domain.memory = {
|
||||
"!attrs": {
|
||||
unit: ["MiB", "KiB", "GiB"]
|
||||
},
|
||||
"!value": 512
|
||||
};
|
||||
|
||||
root.domain.currentMemory = {
|
||||
"!attrs": {
|
||||
unit: ["MiB", "KiB", "GiB"]
|
||||
},
|
||||
"!value": 512
|
||||
};
|
||||
|
||||
root.domain.memoryBacking = {};
|
||||
root.domain.memoryBacking.hugepages = {};
|
||||
root.domain.memoryBacking.hugepages.page = {
|
||||
"!attrs": {
|
||||
size: [2, 1],
|
||||
unit: ["M", "G", "K"],
|
||||
nodeset: null
|
||||
},
|
||||
"!novalue": 1
|
||||
};
|
||||
root.domain.memoryBacking.nosharepages = {
|
||||
"!novalue": 1
|
||||
};
|
||||
root.domain.memoryBacking.locked = {
|
||||
"!novalue": 1
|
||||
};
|
||||
|
||||
root.domain.numatune = {};
|
||||
root.domain.numatune.memory = {
|
||||
"!attrs": {
|
||||
mode: ["strict", "preferred", "interleave"],
|
||||
nodeset: null,
|
||||
placement: ["static", "auto"]
|
||||
},
|
||||
"!novalue": 1
|
||||
};
|
||||
root.domain.numatune.memnode = {
|
||||
"!attrs": {
|
||||
cellid: null,
|
||||
mode: ["strict", "preferred", "interleave"],
|
||||
nodeset: null
|
||||
},
|
||||
"!novalue": 1
|
||||
};
|
||||
|
||||
root.domain.vcpu = {
|
||||
"!attrs": {
|
||||
placement: ["static"]
|
||||
},
|
||||
"!value": 1
|
||||
};
|
||||
|
||||
root.domain.cputune = {};
|
||||
root.domain.cputune.vcpupin = {
|
||||
"!attrs": {
|
||||
vcpu: null,
|
||||
cpuset: null
|
||||
},
|
||||
"!novalue": 1
|
||||
};
|
||||
root.domain.cputune.emulatorpin = {
|
||||
"!attrs": {
|
||||
cpuset: null
|
||||
},
|
||||
"!novalue": 1
|
||||
};
|
||||
root.domain.cputune.iothreadpin = {
|
||||
"!attrs": {
|
||||
iothread: null,
|
||||
cpuset: null
|
||||
},
|
||||
"!novalue": 1
|
||||
};
|
||||
root.domain.cputune.shares = {
|
||||
"!value": null
|
||||
};
|
||||
root.domain.cputune.period = {
|
||||
"!value": null
|
||||
};
|
||||
root.domain.cputune.quota = {
|
||||
"!value": null
|
||||
};
|
||||
root.domain.cputune.emulator_period = {
|
||||
"!value": null
|
||||
};
|
||||
root.domain.cputune.emulator_quota = {
|
||||
"!value": null
|
||||
};
|
||||
root.domain.cputune.vcpusched = {
|
||||
"!attrs": {
|
||||
vcpus: null,
|
||||
scheduler: ["batch", "idle", "fifo", "rr"],
|
||||
priority: null
|
||||
},
|
||||
"!novalue": 1
|
||||
};
|
||||
root.domain.cputune.iothreadsched = {
|
||||
"!attrs": {
|
||||
iothreads: null,
|
||||
scheduler: ["batch", "idle", "fifo", "rr"]
|
||||
},
|
||||
"!novalue": 1
|
||||
};
|
||||
|
||||
root.domain.cpu = {
|
||||
"!attrs": {
|
||||
match: ["exact", "minimum", "strict"],
|
||||
mode: ["host-passthrough", "host-model", "custom"]
|
||||
}
|
||||
};
|
||||
root.domain.cpu.model = {
|
||||
"!value": ""
|
||||
};
|
||||
root.domain.cpu.topology = {
|
||||
"!attrs": {
|
||||
sockets: null,
|
||||
dies: null,
|
||||
cores: null,
|
||||
threads: null
|
||||
}
|
||||
};
|
||||
|
||||
root.domain.os = {};
|
||||
root.domain.os.type = {
|
||||
"!attrs": {
|
||||
arch: ["x86_64"],
|
||||
machine: ["pc", "q35"]
|
||||
},
|
||||
"!value": "hvm"
|
||||
};
|
||||
root.domain.os.loader = {
|
||||
"!attrs": {
|
||||
readonly: ["yes"],
|
||||
type: ["pflash"]
|
||||
},
|
||||
"!value": "/usr/share/qemu/ovmf-x64/OVMF_CODE-pure-efi.fd"
|
||||
};
|
||||
root.domain.os.nvram = {
|
||||
"!value": "/etc/libvirt/qemu/nvram/{{UUID}}_VARS-pure-efi.fd"
|
||||
};
|
||||
|
||||
root.domain.features = {};
|
||||
root.domain.features.acpi = {
|
||||
"!novalue": 1
|
||||
};
|
||||
root.domain.features.apic = {
|
||||
"!novalue": 1
|
||||
};
|
||||
root.domain.features.hyperv = {};
|
||||
root.domain.features.hyperv.relaxed = {
|
||||
"!attrs": {
|
||||
state: ["on", "off"]
|
||||
}
|
||||
};
|
||||
root.domain.features.hyperv.vapic = {
|
||||
"!attrs": {
|
||||
state: ["on", "off"]
|
||||
}
|
||||
};
|
||||
root.domain.features.hyperv.spinlocks = {
|
||||
"!attrs": {
|
||||
state: ["on", "off"],
|
||||
retries: null
|
||||
}
|
||||
};
|
||||
root.domain.features.pae = {
|
||||
"!novalue": 1
|
||||
};
|
||||
|
||||
root.domain.clock = {
|
||||
"!attrs": {
|
||||
offset: ["localtime", "utc"]
|
||||
}
|
||||
};
|
||||
root.domain.clock.timer = {
|
||||
"!attrs": {
|
||||
name: ["hypervclock", "hpet", "rtc", "pit"],
|
||||
tickpolicy: ["catchup", "delay"],
|
||||
present: ["no", "yes"]
|
||||
}
|
||||
};
|
||||
|
||||
root.domain.on_poweroff = {
|
||||
"!value": "destroy"
|
||||
};
|
||||
|
||||
root.domain.on_reboot = {
|
||||
"!value": "restart"
|
||||
};
|
||||
|
||||
root.domain.on_crash = {
|
||||
"!value": "destroy"
|
||||
};
|
||||
|
||||
root.domain.devices = {};
|
||||
|
||||
root.domain.devices.emulator = {
|
||||
"!value": "/usr/bin/qemu-system-x86_64"
|
||||
};
|
||||
|
||||
root.domain.devices.disk = {
|
||||
"!attrs": {
|
||||
type: ["file"],
|
||||
device: ["disk", "cdrom"]
|
||||
}
|
||||
};
|
||||
root.domain.devices.disk.driver = {
|
||||
"!attrs": {
|
||||
name: ["qemu"],
|
||||
type: ["raw", "bochs", "qcow2", "qed"],
|
||||
error_policy: ["report", "stop", "ignore", "enospace"],
|
||||
rerror_policy: ["report", "stop", "ignore"],
|
||||
cache: ["writeback", "default", "directsync", "none", "writethrough", "unsafe"],
|
||||
io: ["native", "threads"],
|
||||
ioeventfd: ["on", "off"],
|
||||
event_idx: ["on", "off"],
|
||||
copy_on_read: ["off", "on"],
|
||||
discard: ["ignore", "unmap"],
|
||||
iothread: null
|
||||
}
|
||||
};
|
||||
root.domain.devices.disk.source = {
|
||||
"!attrs": {
|
||||
file: null
|
||||
}
|
||||
};
|
||||
root.domain.devices.disk.backingStore = {
|
||||
"!novalue": 1
|
||||
};
|
||||
root.domain.devices.disk.target = {
|
||||
"!attrs": {
|
||||
dev: null,
|
||||
bus: ["ide", "sata", "scsi", "virtio", "usb"]
|
||||
}
|
||||
};
|
||||
root.domain.devices.disk.readonly = {
|
||||
"!novalue": 1
|
||||
};
|
||||
root.domain.devices.disk.boot = {
|
||||
"!attrs": {
|
||||
order: null
|
||||
}
|
||||
};
|
||||
|
||||
root.domain.devices.interface = {
|
||||
"!attrs": {
|
||||
type: ["bridge"]
|
||||
}
|
||||
};
|
||||
root.domain.devices.interface.mac = {
|
||||
"!attrs": {
|
||||
address: null
|
||||
}
|
||||
};
|
||||
root.domain.devices.interface.source = {
|
||||
"!attrs": {
|
||||
bridge: null
|
||||
}
|
||||
};
|
||||
root.domain.devices.interface.model = {
|
||||
"!attrs": {
|
||||
type: ["virtio", "virtio-net"]
|
||||
}
|
||||
};
|
||||
|
||||
root.domain.devices.input = {
|
||||
"!attrs": {
|
||||
type: ["tablet", "mouse", "keyboard"],
|
||||
bus: ["usb", "ps2"]
|
||||
}
|
||||
};
|
||||
|
||||
root.domain.devices.graphics = {
|
||||
"!attrs": {
|
||||
type: ["vnc", "spice"],
|
||||
port: ["-1"],
|
||||
autoport: ["yes", "no"],
|
||||
websocket: ["-1"],
|
||||
listen: ["0.0.0.0"],
|
||||
keymap: ["en-us", "en-gb", "ar", "hr", "cz", "da", "nl", "es", "et", "fo",
|
||||
"fi", "fr", "bepo", "fr-be", "fr-ca", "fr-ch", "de-ch", "hu", "is", "it",
|
||||
"ja", "lv", "lt", "mk", "no", "pl", "pt-br", "ru", "sl", "sv", "th", "tr"]
|
||||
}
|
||||
};
|
||||
|
||||
root.domain.devices.graphics.listen = {
|
||||
"!attrs": {
|
||||
type: ["address"],
|
||||
address: ["0.0.0.0"]
|
||||
}
|
||||
};
|
||||
|
||||
root.domain.devices.hostdev = {
|
||||
"!attrs": {
|
||||
mode: ["subsystem"],
|
||||
type: ["pci", "usb"],
|
||||
managed: ["yes", "no"]
|
||||
}
|
||||
};
|
||||
root.domain.devices.hostdev.driver = {
|
||||
"!attrs": {
|
||||
name: ["vfio"]
|
||||
}
|
||||
};
|
||||
root.domain.devices.hostdev.source = {};
|
||||
root.domain.devices.hostdev.source.address = {
|
||||
"!attrs": {
|
||||
domain: null,
|
||||
bus: null,
|
||||
slot: null,
|
||||
function: null
|
||||
}
|
||||
};
|
||||
root.domain.devices.hostdev.source.vendor = {
|
||||
"!attrs": {
|
||||
id: null
|
||||
}
|
||||
};
|
||||
root.domain.devices.hostdev.source.product = {
|
||||
"!attrs": {
|
||||
id: null
|
||||
}
|
||||
};
|
||||
|
||||
root.domain.devices.memballoon = {
|
||||
"!attrs": {
|
||||
model: ["virtio", "none"]
|
||||
}
|
||||
};
|
||||
root.domain.devices.memballoon.alias = {
|
||||
"!attrs": {
|
||||
name: ["balloon0"]
|
||||
}
|
||||
};
|
||||
|
||||
root.domain['qemu:commandline'] = {};
|
||||
root.domain['qemu:commandline']['qemu:arg'] = {
|
||||
"!attrs": {
|
||||
value: null
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return root;
|
||||
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
.CodeMirror-hints {
|
||||
position: absolute;
|
||||
z-index: 10;
|
||||
overflow: hidden;
|
||||
list-style: none;
|
||||
|
||||
margin: 0;
|
||||
padding: 2px;
|
||||
|
||||
-webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
-moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
border-radius: 3px;
|
||||
border: 1px solid silver;
|
||||
|
||||
background: white;
|
||||
font-size: 90%;
|
||||
font-family: bitstream,monospace;
|
||||
|
||||
max-height: 20em;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.CodeMirror-hint {
|
||||
margin: 0;
|
||||
padding: 0 4px;
|
||||
border-radius: 2px;
|
||||
max-width: 19em;
|
||||
overflow: hidden;
|
||||
white-space: pre;
|
||||
color: black;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
li.CodeMirror-hint-active {
|
||||
background: #08f;
|
||||
color: white;
|
||||
}
|
||||
+389
@@ -0,0 +1,389 @@
|
||||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
mod(require("../../lib/codemirror"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
|
||||
var HINT_ELEMENT_CLASS = "CodeMirror-hint";
|
||||
var ACTIVE_HINT_ELEMENT_CLASS = "CodeMirror-hint-active";
|
||||
|
||||
// This is the old interface, kept around for now to stay
|
||||
// backwards-compatible.
|
||||
CodeMirror.showHint = function(cm, getHints, options) {
|
||||
if (!getHints) return cm.showHint(options);
|
||||
if (options && options.async) getHints.async = true;
|
||||
var newOpts = {hint: getHints};
|
||||
if (options) for (var prop in options) newOpts[prop] = options[prop];
|
||||
return cm.showHint(newOpts);
|
||||
};
|
||||
|
||||
CodeMirror.defineExtension("showHint", function(options) {
|
||||
// We want a single cursor position.
|
||||
if (this.listSelections().length > 1 || this.somethingSelected()) return;
|
||||
|
||||
if (this.state.completionActive) this.state.completionActive.close();
|
||||
var completion = this.state.completionActive = new Completion(this, options);
|
||||
var getHints = completion.options.hint;
|
||||
if (!getHints) return;
|
||||
|
||||
CodeMirror.signal(this, "startCompletion", this);
|
||||
if (getHints.async)
|
||||
getHints(this, function(hints) { completion.showHints(hints); }, completion.options);
|
||||
else
|
||||
return completion.showHints(getHints(this, completion.options));
|
||||
});
|
||||
|
||||
function Completion(cm, options) {
|
||||
this.cm = cm;
|
||||
this.options = this.buildOptions(options);
|
||||
this.widget = this.onClose = null;
|
||||
}
|
||||
|
||||
Completion.prototype = {
|
||||
close: function() {
|
||||
if (!this.active()) return;
|
||||
this.cm.state.completionActive = null;
|
||||
|
||||
if (this.widget) this.widget.close();
|
||||
if (this.onClose) this.onClose();
|
||||
CodeMirror.signal(this.cm, "endCompletion", this.cm);
|
||||
},
|
||||
|
||||
active: function() {
|
||||
return this.cm.state.completionActive == this;
|
||||
},
|
||||
|
||||
pick: function(data, i) {
|
||||
var completion = data.list[i];
|
||||
if (completion.hint) completion.hint(this.cm, data, completion);
|
||||
else this.cm.replaceRange(getText(completion), completion.from || data.from,
|
||||
completion.to || data.to, "complete");
|
||||
CodeMirror.signal(data, "pick", completion);
|
||||
this.close();
|
||||
},
|
||||
|
||||
showHints: function(data) {
|
||||
if (!data || !data.list.length || !this.active()) return this.close();
|
||||
|
||||
if (this.options.completeSingle && data.list.length == 1)
|
||||
this.pick(data, 0);
|
||||
else
|
||||
this.showWidget(data);
|
||||
},
|
||||
|
||||
showWidget: function(data) {
|
||||
this.widget = new Widget(this, data);
|
||||
CodeMirror.signal(data, "shown");
|
||||
|
||||
var debounce = 0, completion = this, finished;
|
||||
var closeOn = this.options.closeCharacters;
|
||||
var startPos = this.cm.getCursor(), startLen = this.cm.getLine(startPos.line).length;
|
||||
|
||||
var requestAnimationFrame = window.requestAnimationFrame || function(fn) {
|
||||
return setTimeout(fn, 1000/60);
|
||||
};
|
||||
var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout;
|
||||
|
||||
function done() {
|
||||
if (finished) return;
|
||||
finished = true;
|
||||
completion.close();
|
||||
completion.cm.off("cursorActivity", activity);
|
||||
if (data) CodeMirror.signal(data, "close");
|
||||
}
|
||||
|
||||
function update() {
|
||||
if (finished) return;
|
||||
CodeMirror.signal(data, "update");
|
||||
var getHints = completion.options.hint;
|
||||
if (getHints.async)
|
||||
getHints(completion.cm, finishUpdate, completion.options);
|
||||
else
|
||||
finishUpdate(getHints(completion.cm, completion.options));
|
||||
}
|
||||
function finishUpdate(data_) {
|
||||
data = data_;
|
||||
if (finished) return;
|
||||
if (!data || !data.list.length) return done();
|
||||
if (completion.widget) completion.widget.close();
|
||||
completion.widget = new Widget(completion, data);
|
||||
}
|
||||
|
||||
function clearDebounce() {
|
||||
if (debounce) {
|
||||
cancelAnimationFrame(debounce);
|
||||
debounce = 0;
|
||||
}
|
||||
}
|
||||
|
||||
function activity() {
|
||||
clearDebounce();
|
||||
var pos = completion.cm.getCursor(), line = completion.cm.getLine(pos.line);
|
||||
if (pos.line != startPos.line || line.length - pos.ch != startLen - startPos.ch ||
|
||||
pos.ch < startPos.ch || completion.cm.somethingSelected() ||
|
||||
(pos.ch && closeOn.test(line.charAt(pos.ch - 1)))) {
|
||||
completion.close();
|
||||
} else {
|
||||
debounce = requestAnimationFrame(update);
|
||||
if (completion.widget) completion.widget.close();
|
||||
}
|
||||
}
|
||||
this.cm.on("cursorActivity", activity);
|
||||
this.onClose = done;
|
||||
},
|
||||
|
||||
buildOptions: function(options) {
|
||||
var editor = this.cm.options.hintOptions;
|
||||
var out = {};
|
||||
for (var prop in defaultOptions) out[prop] = defaultOptions[prop];
|
||||
if (editor) for (var prop in editor)
|
||||
if (editor[prop] !== undefined) out[prop] = editor[prop];
|
||||
if (options) for (var prop in options)
|
||||
if (options[prop] !== undefined) out[prop] = options[prop];
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
function getText(completion) {
|
||||
if (typeof completion == "string") return completion;
|
||||
else return completion.text;
|
||||
}
|
||||
|
||||
function buildKeyMap(completion, handle) {
|
||||
var baseMap = {
|
||||
Up: function() {handle.moveFocus(-1);},
|
||||
Down: function() {handle.moveFocus(1);},
|
||||
PageUp: function() {handle.moveFocus(-handle.menuSize() + 1, true);},
|
||||
PageDown: function() {handle.moveFocus(handle.menuSize() - 1, true);},
|
||||
Home: function() {handle.setFocus(0);},
|
||||
End: function() {handle.setFocus(handle.length - 1);},
|
||||
Enter: handle.pick,
|
||||
Tab: handle.pick,
|
||||
Esc: handle.close
|
||||
};
|
||||
var custom = completion.options.customKeys;
|
||||
var ourMap = custom ? {} : baseMap;
|
||||
function addBinding(key, val) {
|
||||
var bound;
|
||||
if (typeof val != "string")
|
||||
bound = function(cm) { return val(cm, handle); };
|
||||
// This mechanism is deprecated
|
||||
else if (baseMap.hasOwnProperty(val))
|
||||
bound = baseMap[val];
|
||||
else
|
||||
bound = val;
|
||||
ourMap[key] = bound;
|
||||
}
|
||||
if (custom)
|
||||
for (var key in custom) if (custom.hasOwnProperty(key))
|
||||
addBinding(key, custom[key]);
|
||||
var extra = completion.options.extraKeys;
|
||||
if (extra)
|
||||
for (var key in extra) if (extra.hasOwnProperty(key))
|
||||
addBinding(key, extra[key]);
|
||||
return ourMap;
|
||||
}
|
||||
|
||||
function getHintElement(hintsElement, el) {
|
||||
while (el && el != hintsElement) {
|
||||
if (el.nodeName.toUpperCase() === "LI" && el.parentNode == hintsElement) return el;
|
||||
el = el.parentNode;
|
||||
}
|
||||
}
|
||||
|
||||
function Widget(completion, data) {
|
||||
this.completion = completion;
|
||||
this.data = data;
|
||||
var widget = this, cm = completion.cm;
|
||||
|
||||
var hints = this.hints = document.createElement("ul");
|
||||
hints.className = "CodeMirror-hints";
|
||||
this.selectedHint = data.selectedHint || 0;
|
||||
|
||||
var completions = data.list;
|
||||
for (var i = 0; i < completions.length; ++i) {
|
||||
var elt = hints.appendChild(document.createElement("li")), cur = completions[i];
|
||||
var className = HINT_ELEMENT_CLASS + (i != this.selectedHint ? "" : " " + ACTIVE_HINT_ELEMENT_CLASS);
|
||||
if (cur.className != null) className = cur.className + " " + className;
|
||||
elt.className = className;
|
||||
if (cur.render) cur.render(elt, data, cur);
|
||||
else elt.appendChild(document.createTextNode(cur.displayText || getText(cur)));
|
||||
elt.hintId = i;
|
||||
}
|
||||
|
||||
var pos = cm.cursorCoords(completion.options.alignWithWord ? data.from : null);
|
||||
var left = pos.left, top = pos.bottom, below = true;
|
||||
hints.style.left = left + "px";
|
||||
hints.style.top = top + "px";
|
||||
// If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
|
||||
var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
|
||||
var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
|
||||
(completion.options.container || document.body).appendChild(hints);
|
||||
var box = hints.getBoundingClientRect(), overlapY = box.bottom - winH;
|
||||
if (overlapY > 0) {
|
||||
var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top);
|
||||
if (curTop - height > 0) { // Fits above cursor
|
||||
hints.style.top = (top = pos.top - height) + "px";
|
||||
below = false;
|
||||
} else if (height > winH) {
|
||||
hints.style.height = (winH - 5) + "px";
|
||||
hints.style.top = (top = pos.bottom - box.top) + "px";
|
||||
var cursor = cm.getCursor();
|
||||
if (data.from.ch != cursor.ch) {
|
||||
pos = cm.cursorCoords(cursor);
|
||||
hints.style.left = (left = pos.left) + "px";
|
||||
box = hints.getBoundingClientRect();
|
||||
}
|
||||
}
|
||||
}
|
||||
var overlapX = box.right - winW;
|
||||
if (overlapX > 0) {
|
||||
if (box.right - box.left > winW) {
|
||||
hints.style.width = (winW - 5) + "px";
|
||||
overlapX -= (box.right - box.left) - winW;
|
||||
}
|
||||
hints.style.left = (left = pos.left - overlapX) + "px";
|
||||
}
|
||||
|
||||
cm.addKeyMap(this.keyMap = buildKeyMap(completion, {
|
||||
moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); },
|
||||
setFocus: function(n) { widget.changeActive(n); },
|
||||
menuSize: function() { return widget.screenAmount(); },
|
||||
length: completions.length,
|
||||
close: function() { completion.close(); },
|
||||
pick: function() { widget.pick(); },
|
||||
data: data
|
||||
}));
|
||||
|
||||
if (completion.options.closeOnUnfocus) {
|
||||
var closingOnBlur;
|
||||
cm.on("blur", this.onBlur = function() { closingOnBlur = setTimeout(function() { completion.close(); }, 100); });
|
||||
cm.on("focus", this.onFocus = function() { clearTimeout(closingOnBlur); });
|
||||
}
|
||||
|
||||
var startScroll = cm.getScrollInfo();
|
||||
cm.on("scroll", this.onScroll = function() {
|
||||
var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect();
|
||||
var newTop = top + startScroll.top - curScroll.top;
|
||||
var point = newTop - (window.pageYOffset || (document.documentElement || document.body).scrollTop);
|
||||
if (!below) point += hints.offsetHeight;
|
||||
if (point <= editor.top || point >= editor.bottom) return completion.close();
|
||||
hints.style.top = newTop + "px";
|
||||
hints.style.left = (left + startScroll.left - curScroll.left) + "px";
|
||||
});
|
||||
|
||||
CodeMirror.on(hints, "dblclick", function(e) {
|
||||
var t = getHintElement(hints, e.target || e.srcElement);
|
||||
if (t && t.hintId != null) {widget.changeActive(t.hintId); widget.pick();}
|
||||
});
|
||||
|
||||
CodeMirror.on(hints, "click", function(e) {
|
||||
var t = getHintElement(hints, e.target || e.srcElement);
|
||||
if (t && t.hintId != null) {
|
||||
widget.changeActive(t.hintId);
|
||||
if (completion.options.completeOnSingleClick) widget.pick();
|
||||
}
|
||||
});
|
||||
|
||||
CodeMirror.on(hints, "mousedown", function() {
|
||||
setTimeout(function(){cm.focus();}, 20);
|
||||
});
|
||||
|
||||
CodeMirror.signal(data, "select", completions[0], hints.firstChild);
|
||||
return true;
|
||||
}
|
||||
|
||||
Widget.prototype = {
|
||||
close: function() {
|
||||
if (this.completion.widget != this) return;
|
||||
this.completion.widget = null;
|
||||
this.hints.parentNode.removeChild(this.hints);
|
||||
this.completion.cm.removeKeyMap(this.keyMap);
|
||||
|
||||
var cm = this.completion.cm;
|
||||
if (this.completion.options.closeOnUnfocus) {
|
||||
cm.off("blur", this.onBlur);
|
||||
cm.off("focus", this.onFocus);
|
||||
}
|
||||
cm.off("scroll", this.onScroll);
|
||||
},
|
||||
|
||||
pick: function() {
|
||||
this.completion.pick(this.data, this.selectedHint);
|
||||
},
|
||||
|
||||
changeActive: function(i, avoidWrap) {
|
||||
if (i >= this.data.list.length)
|
||||
i = avoidWrap ? this.data.list.length - 1 : 0;
|
||||
else if (i < 0)
|
||||
i = avoidWrap ? 0 : this.data.list.length - 1;
|
||||
if (this.selectedHint == i) return;
|
||||
var node = this.hints.childNodes[this.selectedHint];
|
||||
node.className = node.className.replace(" " + ACTIVE_HINT_ELEMENT_CLASS, "");
|
||||
node = this.hints.childNodes[this.selectedHint = i];
|
||||
node.className += " " + ACTIVE_HINT_ELEMENT_CLASS;
|
||||
if (node.offsetTop < this.hints.scrollTop)
|
||||
this.hints.scrollTop = node.offsetTop - 3;
|
||||
else if (node.offsetTop + node.offsetHeight > this.hints.scrollTop + this.hints.clientHeight)
|
||||
this.hints.scrollTop = node.offsetTop + node.offsetHeight - this.hints.clientHeight + 3;
|
||||
CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node);
|
||||
},
|
||||
|
||||
screenAmount: function() {
|
||||
return Math.floor(this.hints.clientHeight / this.hints.firstChild.offsetHeight) || 1;
|
||||
}
|
||||
};
|
||||
|
||||
CodeMirror.registerHelper("hint", "auto", function(cm, options) {
|
||||
var helpers = cm.getHelpers(cm.getCursor(), "hint"), words;
|
||||
if (helpers.length) {
|
||||
for (var i = 0; i < helpers.length; i++) {
|
||||
var cur = helpers[i](cm, options);
|
||||
if (cur && cur.list.length) return cur;
|
||||
}
|
||||
} else if (words = cm.getHelper(cm.getCursor(), "hintWords")) {
|
||||
if (words) return CodeMirror.hint.fromList(cm, {words: words});
|
||||
} else if (CodeMirror.hint.anyword) {
|
||||
return CodeMirror.hint.anyword(cm, options);
|
||||
}
|
||||
});
|
||||
|
||||
CodeMirror.registerHelper("hint", "fromList", function(cm, options) {
|
||||
var cur = cm.getCursor(), token = cm.getTokenAt(cur);
|
||||
var found = [];
|
||||
for (var i = 0; i < options.words.length; i++) {
|
||||
var word = options.words[i];
|
||||
if (word.slice(0, token.string.length) == token.string)
|
||||
found.push(word);
|
||||
}
|
||||
|
||||
if (found.length) return {
|
||||
list: found,
|
||||
from: CodeMirror.Pos(cur.line, token.start),
|
||||
to: CodeMirror.Pos(cur.line, token.end)
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.commands.autocomplete = CodeMirror.showHint;
|
||||
|
||||
var defaultOptions = {
|
||||
hint: CodeMirror.hint.auto,
|
||||
completeSingle: true,
|
||||
alignWithWord: true,
|
||||
closeCharacters: /[\s()\[\]{};:>,]/,
|
||||
closeOnUnfocus: true,
|
||||
completeOnSingleClick: false,
|
||||
container: null,
|
||||
customKeys: null,
|
||||
extraKeys: null
|
||||
};
|
||||
|
||||
CodeMirror.defineOption("hintOptions", null);
|
||||
});
|
||||
@@ -0,0 +1,135 @@
|
||||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
mod(require("../../lib/codemirror"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
|
||||
var Pos = CodeMirror.Pos;
|
||||
|
||||
function getHints(cm, options) {
|
||||
var tags = options && options.schemaInfo;
|
||||
var quote = (options && options.quoteChar) || '"';
|
||||
if (!tags) return;
|
||||
var cur = cm.getCursor(), token = cm.getTokenAt(cur);
|
||||
if (token.end > cur.ch) {
|
||||
token.end = cur.ch;
|
||||
token.string = token.string.slice(0, cur.ch - token.start);
|
||||
}
|
||||
var inner = CodeMirror.innerMode(cm.getMode(), token.state);
|
||||
if (inner.mode.name != "xml") return;
|
||||
var result = [], replaceToken = false, prefix;
|
||||
var tag = /\btag\b/.test(token.type) && !/>$/.test(token.string);
|
||||
var tagName = tag && /^\w/.test(token.string), tagStart;
|
||||
var tagType = null;
|
||||
|
||||
if (tagName) {
|
||||
var before = cm.getLine(cur.line).slice(Math.max(0, token.start - 2), token.start);
|
||||
tagType = /<\/$/.test(before) ? "close" : /<$/.test(before) ? "open" : null;
|
||||
if (tagType) tagStart = token.start - (tagType == "close" ? 2 : 1);
|
||||
} else if (tag && token.string == "<") {
|
||||
tagType = "open";
|
||||
} else if (tag && token.string == "</") {
|
||||
tagType = "close";
|
||||
}
|
||||
|
||||
var cx = inner.state.context;
|
||||
|
||||
var localtags = tags;
|
||||
var topattrs = tags["!attrs"];
|
||||
|
||||
if (cx && cx.tagName) {
|
||||
var nodepath = [cx.tagName];
|
||||
var prevnode = cx.prev;
|
||||
while (prevnode) {
|
||||
nodepath.push(prevnode.tagName);
|
||||
prevnode = prevnode.prev;
|
||||
}
|
||||
for (var i = nodepath.length - 1; i >= 0; i--) {
|
||||
if (! localtags[nodepath[i]]) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (localtags["!attrs"]) {
|
||||
topattrs = localtags["!attrs"];
|
||||
}
|
||||
|
||||
localtags = localtags[nodepath[i]];
|
||||
}
|
||||
}
|
||||
|
||||
if (!tag && !inner.state.tagName || tagType) {
|
||||
if (tagName)
|
||||
prefix = token.string;
|
||||
replaceToken = tagType;
|
||||
if (tagType != "close") {
|
||||
for (var name in localtags) {
|
||||
if (localtags.hasOwnProperty(name) && name != "!top" && name != "!attrs" && name != "!value" && (!prefix || name.lastIndexOf(prefix, 0) === 0)) {
|
||||
if (localtags[name]["!attrs"]) {
|
||||
result.push("<" + name);
|
||||
} else {
|
||||
if (Object.keys(localtags[name]).length === 1 && localtags[name].hasOwnProperty("!novalue")) {
|
||||
result.push("<" + name + "/>");
|
||||
} else if (Object.keys(localtags[name]).length === 1 && localtags[name].hasOwnProperty("!value")) {
|
||||
result.push("<" + name + ">");
|
||||
} else {
|
||||
result.push("<" + name + ">");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cx && (!prefix || tagType == "close" && cx.tagName.lastIndexOf(prefix, 0) === 0)) {
|
||||
result.push("</" + cx.tagName + ">");
|
||||
}
|
||||
} else {
|
||||
// Attribute completion
|
||||
var attrs = localtags && localtags[inner.state.tagName] && localtags[inner.state.tagName]["!attrs"];
|
||||
if (!attrs) return;
|
||||
if (token.type == "string" || token.string == "=") { // A value
|
||||
var before = cm.getRange(Pos(cur.line, Math.max(0, cur.ch - 60)),
|
||||
Pos(cur.line, token.type == "string" ? token.start : token.end));
|
||||
var atName = before.match(/([^\s\u00a0=<>\"\']+)=$/), atValues;
|
||||
if (!atName || !attrs.hasOwnProperty(atName[1]) || !(atValues = attrs[atName[1]])) return;
|
||||
if (typeof atValues == 'function') atValues = atValues.call(this, cm); // Functions can be used to supply values for autocomplete widget
|
||||
if (token.type == "string") {
|
||||
prefix = token.string;
|
||||
var n = 0;
|
||||
if (/['"]/.test(token.string.charAt(0))) {
|
||||
quote = token.string.charAt(0);
|
||||
prefix = token.string.slice(1);
|
||||
n++;
|
||||
}
|
||||
var len = token.string.length;
|
||||
if (/['"]/.test(token.string.charAt(len - 1))) {
|
||||
quote = token.string.charAt(len - 1);
|
||||
prefix = token.string.substr(n, len - 2);
|
||||
}
|
||||
replaceToken = true;
|
||||
}
|
||||
for (var i = 0; i < atValues.length; ++i) if (!prefix || atValues[i].lastIndexOf(prefix, 0) === 0)
|
||||
result.push(quote + atValues[i] + quote);
|
||||
} else { // An attribute name
|
||||
if (token.type == "attribute") {
|
||||
prefix = token.string;
|
||||
replaceToken = true;
|
||||
}
|
||||
for (var attr in attrs) if (attrs.hasOwnProperty(attr) && (!prefix || attr.lastIndexOf(prefix, 0) === 0))
|
||||
result.push(attr);
|
||||
}
|
||||
}
|
||||
return {
|
||||
list: result,
|
||||
from: replaceToken ? Pos(cur.line, tagStart == null ? token.start : tagStart) : cur,
|
||||
to: replaceToken ? Pos(cur.line, token.end) : cur
|
||||
};
|
||||
}
|
||||
|
||||
CodeMirror.registerHelper("hint", "xml", getHints);
|
||||
});
|
||||
Reference in New Issue
Block a user