mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 17:46:28 +08:00
ui-default: init
将ui-default合并至主存储库便于维护
This commit is contained in:
1 parent
6317c9057f
commit
5faa54c7ca
564 files changed
+23083
-14
No files matched your search
@@ -0,0 +1,66 @@
|
||||
import _ from 'lodash';
|
||||
import DOMAttachedObject from 'vj/components/DOMAttachedObject';
|
||||
|
||||
export default class CmEditor extends DOMAttachedObject {
|
||||
static DOMAttachKey = 'vjCmEditorInstance';
|
||||
|
||||
constructor($dom, options = {}) {
|
||||
super($dom);
|
||||
this.editor = null;
|
||||
this.options = options;
|
||||
this.init();
|
||||
}
|
||||
|
||||
async init() {
|
||||
const { default: VjCmEditor } = await import('./vjcmeditor');
|
||||
|
||||
const hasFocus = this.$dom.is(':focus');
|
||||
const srcHeight = this.$dom.outerHeight();
|
||||
|
||||
this.editor = new VjCmEditor({
|
||||
...this.options,
|
||||
element: this.$dom.get(0),
|
||||
});
|
||||
this.moveToEnd();
|
||||
|
||||
const $editor = $(this.editor.wrapper);
|
||||
$editor.css('height', srcHeight);
|
||||
$editor.addClass('toolbar--visible');
|
||||
|
||||
if (hasFocus) {
|
||||
this.focus();
|
||||
}
|
||||
}
|
||||
|
||||
isValid() {
|
||||
return (this.editor !== null);
|
||||
}
|
||||
|
||||
ensureValid() {
|
||||
if (!this.isValid()) {
|
||||
throw new Error('VjCmEditor is not loaded');
|
||||
}
|
||||
}
|
||||
|
||||
value(...argv) {
|
||||
this.ensureValid();
|
||||
const ret = this.editor.value(...argv);
|
||||
if (argv.length > 0) {
|
||||
this.moveToEnd();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
focus() {
|
||||
this.ensureValid();
|
||||
this.editor.codemirror.focus();
|
||||
}
|
||||
|
||||
moveToEnd() {
|
||||
this.ensureValid();
|
||||
const cm = this.editor.codemirror;
|
||||
cm.setCursor(cm.lineCount(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
_.assign(CmEditor, DOMAttachedObject);
|
||||
Reference in new issue
Block a user