feeles-ide
Version:
The hackable and serializable IDE to make learning material
98 lines (86 loc) • 2.46 kB
JavaScript
import _Array$from from 'babel-runtime/core-js/array/from';
import _Object$freeze from 'babel-runtime/core-js/object/freeze';
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _createClass from 'babel-runtime/helpers/createClass';
import { Pos } from 'codemirror';
import { separate } from '../File/';
var Snippet = function () {
function Snippet(props) {
_classCallCheck(this, Snippet);
this.key = getUniqueId();
this.props = _Object$freeze(props);
this._separate = separate(props.name);
}
_createClass(Snippet, [{
key: 'render',
value: function render(element) {
element.textContent = this.props.prefix + ' ' + this.props.description;
return element;
}
}, {
key: 'hint',
value: function hint(instance, self, data) {
var from = self.asset ? new Pos(self.from.line + 1, 0) : self.from;
var to = self.asset ? from : self.to;
var text = self.asset ? data.text + '\n' : data.text;
instance.replaceRange(text, from, to, 'complete');
var length = text.split('\n').length + (self.asset ? -1 : 0);
_Array$from({ length: length }).forEach(function (v, i) {
return instance.indentLine(i + from.line);
});
var endLine = from.line + length - 1;
var endCh = instance.getLine(endLine).length;
return {
from: from,
to: new Pos(endLine, endCh)
};
}
}, {
key: 'text',
get: function get() {
return this.props.body.replace(/\\n/g, '\n').replace(/\\t/g, '\t');
}
}, {
key: 'prefix',
get: function get() {
return this.props.prefix || '';
}
}, {
key: 'description',
get: function get() {
return this.props.description;
}
}, {
key: 'descriptionMoreURL',
get: function get() {
return this.props.descriptionMoreURL;
}
}, {
key: 'leftLabel',
get: function get() {
return this.props.leftLabelHTML || this.props.leftLabel || '';
}
}, {
key: 'rightLabel',
get: function get() {
return this.props.rightLabelHTML || this.props.rightLabel || '';
}
}, {
key: 'plane',
get: function get() {
return this._separate.plane;
}
}, {
key: 'fileKey',
get: function get() {
return this.props.fileKey;
}
}]);
return Snippet;
}();
export default Snippet;
var getUniqueId = function (id) {
return function () {
return 'Snippet__' + ++id;
};
}(0);