@difizen/libro-code-editor 0.0.0-snapshot-20241017072317
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/es/code-editor-info-manager.d.ts +8 -0
- package/es/code-editor-info-manager.d.ts.map +1 -0
- package/es/code-editor-info-manager.js +32 -0
- package/es/code-editor-manager.d.ts +60 -0
- package/es/code-editor-manager.d.ts.map +1 -0
- package/es/code-editor-manager.js +126 -0
- package/es/code-editor-model.d.ts +80 -0
- package/es/code-editor-model.d.ts.map +1 -0
- package/es/code-editor-model.js +108 -0
- package/es/code-editor-protocol.d.ts +475 -0
- package/es/code-editor-protocol.d.ts.map +1 -0
- package/es/code-editor-protocol.js +113 -0
- package/es/code-editor-settings.d.ts +34 -0
- package/es/code-editor-settings.d.ts.map +1 -0
- package/es/code-editor-settings.js +225 -0
- package/es/code-editor-state-manager.d.ts +14 -0
- package/es/code-editor-state-manager.d.ts.map +1 -0
- package/es/code-editor-state-manager.js +82 -0
- package/es/code-editor-view.d.ts +123 -0
- package/es/code-editor-view.d.ts.map +1 -0
- package/es/code-editor-view.js +420 -0
- package/es/index.d.ts +9 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +8 -0
- package/es/language-specs.d.ts +38 -0
- package/es/language-specs.d.ts.map +1 -0
- package/es/language-specs.js +58 -0
- package/es/mimetype.d.ts +33 -0
- package/es/mimetype.d.ts.map +1 -0
- package/es/mimetype.js +11 -0
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +10 -0
- package/package.json +60 -0
- package/src/code-editor-info-manager.ts +25 -0
- package/src/code-editor-manager.ts +71 -0
- package/src/code-editor-model.ts +120 -0
- package/src/code-editor-protocol.ts +681 -0
- package/src/code-editor-settings.ts +214 -0
- package/src/code-editor-state-manager.ts +54 -0
- package/src/code-editor-view.tsx +434 -0
- package/src/index.spec.ts +10 -0
- package/src/index.ts +8 -0
- package/src/language-specs.ts +69 -0
- package/src/mimetype.ts +37 -0
- package/src/module.ts +22 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _descriptor3;
|
|
3
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
4
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
7
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
8
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
9
|
+
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
|
|
10
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
12
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
14
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
15
|
+
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
|
16
|
+
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
17
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
18
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
19
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
20
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
21
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
22
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
23
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
24
|
+
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
|
|
25
|
+
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
|
|
26
|
+
import { inject, transient, Emitter, BaseView, ThemeService, view, ViewOption } from '@difizen/mana-app';
|
|
27
|
+
import { forwardRef, memo } from 'react';
|
|
28
|
+
import { CodeEditorInfoManager } from "./code-editor-info-manager.js";
|
|
29
|
+
import { CodeEditorSettings } from "./code-editor-settings.js";
|
|
30
|
+
import { CodeEditorStateManager } from "./code-editor-state-manager.js";
|
|
31
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
32
|
+
export var CodeEditorRender = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (props, ref) {
|
|
33
|
+
return /*#__PURE__*/_jsx("div", {
|
|
34
|
+
tabIndex: 0,
|
|
35
|
+
ref: ref
|
|
36
|
+
});
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The class name added to an editor widget that has a primary selection.
|
|
41
|
+
*/
|
|
42
|
+
var HAS_SELECTION_CLASS = 'jp-mod-has-primary-selection';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The class name added to an editor widget that has a cursor/selection
|
|
46
|
+
* within the whitespace at the beginning of a line
|
|
47
|
+
*/
|
|
48
|
+
var HAS_IN_LEADING_WHITESPACE_CLASS = 'jp-mod-in-leading-whitespace';
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A class used to indicate a drop target.
|
|
52
|
+
*/
|
|
53
|
+
var DROP_TARGET_CLASS = 'jp-mod-dropTarget';
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* RegExp to test for leading whitespace
|
|
57
|
+
*/
|
|
58
|
+
var leadingWhitespaceRe = /^\s+$/;
|
|
59
|
+
/**
|
|
60
|
+
* A widget which hosts a code editor.
|
|
61
|
+
*/
|
|
62
|
+
export var CodeEditorView = (_dec = transient(), _dec2 = view('code-editor-view'), _dec3 = inject(ThemeService), _dec4 = inject(CodeEditorSettings), _dec5 = inject(CodeEditorStateManager), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_BaseView) {
|
|
63
|
+
_inherits(CodeEditorView, _BaseView);
|
|
64
|
+
var _super = _createSuper(CodeEditorView);
|
|
65
|
+
/**
|
|
66
|
+
* Construct a new code editor widget.
|
|
67
|
+
*/
|
|
68
|
+
function CodeEditorView(options, codeEditorInfoManager) {
|
|
69
|
+
var _this;
|
|
70
|
+
_classCallCheck(this, CodeEditorView);
|
|
71
|
+
_this = _super.call(this);
|
|
72
|
+
_initializerDefineProperty(_this, "themeService", _descriptor, _assertThisInitialized(_this));
|
|
73
|
+
_initializerDefineProperty(_this, "codeEditorSettings", _descriptor2, _assertThisInitialized(_this));
|
|
74
|
+
_initializerDefineProperty(_this, "codeEditorStateManager", _descriptor3, _assertThisInitialized(_this));
|
|
75
|
+
_this.view = CodeEditorRender;
|
|
76
|
+
_this.classlist = [];
|
|
77
|
+
_this.modalChangeEmitter = new Emitter();
|
|
78
|
+
_this.editorStatus = 'init';
|
|
79
|
+
_this.editorStatusChangeEmitter = new Emitter();
|
|
80
|
+
_this.onEditorStatusChange = _this.editorStatusChangeEmitter.event;
|
|
81
|
+
_this.removeChildNodes = function (parent) {
|
|
82
|
+
while (parent.firstChild) {
|
|
83
|
+
parent.removeChild(parent.firstChild);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
_this.onViewUnmount = function () {
|
|
87
|
+
var _this$editorHostRef2;
|
|
88
|
+
if (_this.editor.hasFocus()) {
|
|
89
|
+
var _this$editorHostRef;
|
|
90
|
+
// 保存编辑器状态
|
|
91
|
+
var editorState = _this.editor.getState();
|
|
92
|
+
_this.codeEditorStateManager.updateEditorState(_this.options.uuid, editorState);
|
|
93
|
+
// focus 到 host 避免进入命令模式
|
|
94
|
+
_this.editorHostRef = _this.getEditorHost();
|
|
95
|
+
(_this$editorHostRef = _this.editorHostRef) === null || _this$editorHostRef === void 0 || (_this$editorHostRef = _this$editorHostRef.current) === null || _this$editorHostRef === void 0 || _this$editorHostRef.focus();
|
|
96
|
+
}
|
|
97
|
+
_this.editor.dispose();
|
|
98
|
+
var prevState = _this.editorStatus;
|
|
99
|
+
_this.editorStatus = 'disposed';
|
|
100
|
+
_this.editorStatusChangeEmitter.fire({
|
|
101
|
+
status: 'disposed',
|
|
102
|
+
prevState: prevState
|
|
103
|
+
});
|
|
104
|
+
var node = (_this$editorHostRef2 = _this.editorHostRef) === null || _this$editorHostRef2 === void 0 ? void 0 : _this$editorHostRef2.current;
|
|
105
|
+
if (node) {
|
|
106
|
+
node.removeEventListener('focus', _this.onViewActive);
|
|
107
|
+
node.removeEventListener('dragenter', _this._evtDragEnter);
|
|
108
|
+
node.removeEventListener('dragleave', _this._evtDragLeave);
|
|
109
|
+
node.removeEventListener('dragover', _this._evtDragOver);
|
|
110
|
+
node.removeEventListener('drop', _this._evtDrop);
|
|
111
|
+
_this.removeChildNodes(node);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
_this.onViewActive = function () {
|
|
115
|
+
_this.editor.focus();
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Handle the `'lm-dragenter'` event for the widget.
|
|
119
|
+
*/
|
|
120
|
+
_this._evtDragEnter = function (event) {
|
|
121
|
+
if (_this.editor.getOption('readOnly') === true) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
var data = findTextData(event);
|
|
125
|
+
if (data === undefined) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
event.preventDefault();
|
|
129
|
+
event.stopPropagation();
|
|
130
|
+
_this.addClass('jp-mod-dropTarget');
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Handle the `'lm-dragleave'` event for the widget.
|
|
134
|
+
*/
|
|
135
|
+
_this._evtDragLeave = function (event) {
|
|
136
|
+
_this.removeClass(DROP_TARGET_CLASS);
|
|
137
|
+
if (_this.editor.getOption('readOnly') === true) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
var data = findTextData(event);
|
|
141
|
+
if (data === undefined) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
event.preventDefault();
|
|
145
|
+
event.stopPropagation();
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Handle the `'lm-dragover'` event for the widget.
|
|
149
|
+
*/
|
|
150
|
+
_this._evtDragOver = function (event) {
|
|
151
|
+
_this.removeClass(DROP_TARGET_CLASS);
|
|
152
|
+
if (_this.editor.getOption('readOnly') === true) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
var data = findTextData(event);
|
|
156
|
+
if (data === undefined) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
event.stopPropagation();
|
|
161
|
+
event.dataTransfer.dropEffect = 'copy';
|
|
162
|
+
_this.addClass(DROP_TARGET_CLASS);
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Handle the `'lm-drop'` event for the widget.
|
|
166
|
+
*/
|
|
167
|
+
_this._evtDrop = function (event) {
|
|
168
|
+
if (_this.editor.getOption('readOnly') === true) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
var data = findTextData(event);
|
|
172
|
+
if (data === undefined) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
var coordinate = {
|
|
176
|
+
top: event.y,
|
|
177
|
+
bottom: event.y,
|
|
178
|
+
left: event.x,
|
|
179
|
+
right: event.x,
|
|
180
|
+
x: event.x,
|
|
181
|
+
y: event.y,
|
|
182
|
+
width: 0,
|
|
183
|
+
height: 0
|
|
184
|
+
};
|
|
185
|
+
var position = _this.editor.getPositionForCoordinate(coordinate);
|
|
186
|
+
if (position === null) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
_this.removeClass(DROP_TARGET_CLASS);
|
|
190
|
+
event.preventDefault();
|
|
191
|
+
event.stopPropagation();
|
|
192
|
+
// if (event.proposedAction === 'none') {
|
|
193
|
+
// event.dropAction = 'none';
|
|
194
|
+
// return;
|
|
195
|
+
// }
|
|
196
|
+
// const offset = this.editor.getOffsetAt(position);
|
|
197
|
+
// this.model.value.insert(offset, data);
|
|
198
|
+
};
|
|
199
|
+
_this.options = options;
|
|
200
|
+
_this.codeEditorInfoManager = codeEditorInfoManager;
|
|
201
|
+
return _this;
|
|
202
|
+
}
|
|
203
|
+
CodeEditorView = inject(CodeEditorInfoManager)(CodeEditorView, undefined, 1) || CodeEditorView;
|
|
204
|
+
CodeEditorView = inject(ViewOption)(CodeEditorView, undefined, 0) || CodeEditorView;
|
|
205
|
+
_createClass(CodeEditorView, [{
|
|
206
|
+
key: "onModalChange",
|
|
207
|
+
get: function get() {
|
|
208
|
+
return this.modalChangeEmitter.event;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Get the editor wrapped by the widget.
|
|
213
|
+
*/
|
|
214
|
+
}, {
|
|
215
|
+
key: "getEditorHost",
|
|
216
|
+
value: function getEditorHost() {
|
|
217
|
+
var editorHostId = this.options.editorHostId;
|
|
218
|
+
var editorHostRef = editorHostId ? this.codeEditorInfoManager.getEditorHostRef(editorHostId) : undefined;
|
|
219
|
+
return editorHostRef && editorHostRef.current ? editorHostRef : this.container;
|
|
220
|
+
}
|
|
221
|
+
}, {
|
|
222
|
+
key: "onViewMount",
|
|
223
|
+
value: function () {
|
|
224
|
+
var _onViewMount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
225
|
+
var _this$editorHostRef3,
|
|
226
|
+
_this2 = this;
|
|
227
|
+
var state, settings, cursorPosition, selections, prevState;
|
|
228
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
229
|
+
while (1) switch (_context.prev = _context.next) {
|
|
230
|
+
case 0:
|
|
231
|
+
_context.next = 2;
|
|
232
|
+
return this.codeEditorStateManager.getOrCreateEditorState({
|
|
233
|
+
uuid: this.options.uuid,
|
|
234
|
+
model: this.options.model
|
|
235
|
+
});
|
|
236
|
+
case 2:
|
|
237
|
+
state = _context.sent;
|
|
238
|
+
settings = this.codeEditorSettings.getUserEditorSettings();
|
|
239
|
+
this.editorHostRef = this.getEditorHost();
|
|
240
|
+
if (!((_this$editorHostRef3 = this.editorHostRef) !== null && _this$editorHostRef3 !== void 0 && _this$editorHostRef3.current && this.options.factory)) {
|
|
241
|
+
_context.next = 25;
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
this.editor = this.options.factory(_objectSpread(_objectSpread({}, this.options), {}, {
|
|
245
|
+
host: this.editorHostRef.current,
|
|
246
|
+
model: this.options.model,
|
|
247
|
+
uuid: this.options.uuid,
|
|
248
|
+
config: _objectSpread(_objectSpread({}, settings), this.options.config),
|
|
249
|
+
selectionStyle: this.options.selectionStyle,
|
|
250
|
+
tooltipProvider: this.options.tooltipProvider,
|
|
251
|
+
completionProvider: this.options.completionProvider
|
|
252
|
+
}), state);
|
|
253
|
+
_context.next = 9;
|
|
254
|
+
return this.editor.editorReady;
|
|
255
|
+
case 9:
|
|
256
|
+
cursorPosition = state.cursorPosition, selections = state.selections;
|
|
257
|
+
prevState = this.editorStatus;
|
|
258
|
+
this.editorStatus = 'ready';
|
|
259
|
+
this.editorStatusChangeEmitter.fire({
|
|
260
|
+
status: 'ready',
|
|
261
|
+
prevState: prevState
|
|
262
|
+
});
|
|
263
|
+
if (cursorPosition) {
|
|
264
|
+
this.editor.setCursorPosition(cursorPosition);
|
|
265
|
+
}
|
|
266
|
+
if (selections) {
|
|
267
|
+
this.editor.setSelections(selections);
|
|
268
|
+
}
|
|
269
|
+
this.editor.onModalChange(function (val) {
|
|
270
|
+
return _this2.modalChangeEmitter.fire(val);
|
|
271
|
+
});
|
|
272
|
+
// this.editor.model.selections.changed(this._onSelectionsChanged);
|
|
273
|
+
|
|
274
|
+
if (this.options.autoFocus) {
|
|
275
|
+
this.editor.focus();
|
|
276
|
+
}
|
|
277
|
+
if (this.editorHostRef.current) {
|
|
278
|
+
_context.next = 19;
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
return _context.abrupt("return");
|
|
282
|
+
case 19:
|
|
283
|
+
this.editorHostRef.current.addEventListener('focus', this.onViewActive);
|
|
284
|
+
this.editorHostRef.current.addEventListener('dragenter', this._evtDragEnter);
|
|
285
|
+
this.editorHostRef.current.addEventListener('dragleave', this._evtDragLeave);
|
|
286
|
+
this.editorHostRef.current.addEventListener('dragover', this._evtDragOver);
|
|
287
|
+
this.editorHostRef.current.addEventListener('drop', this._evtDrop);
|
|
288
|
+
this.toDispose.push(this.codeEditorSettings.onCodeEditorSettingsChange(function (e) {
|
|
289
|
+
_this2.editor.setOption(e.key, e.value);
|
|
290
|
+
}));
|
|
291
|
+
case 25:
|
|
292
|
+
case "end":
|
|
293
|
+
return _context.stop();
|
|
294
|
+
}
|
|
295
|
+
}, _callee, this);
|
|
296
|
+
}));
|
|
297
|
+
function onViewMount() {
|
|
298
|
+
return _onViewMount.apply(this, arguments);
|
|
299
|
+
}
|
|
300
|
+
return onViewMount;
|
|
301
|
+
}()
|
|
302
|
+
}, {
|
|
303
|
+
key: "onViewResize",
|
|
304
|
+
value: function onViewResize() {
|
|
305
|
+
var _this$editor;
|
|
306
|
+
(_this$editor = this.editor) === null || _this$editor === void 0 || _this$editor.resizeToFit();
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Get the model used by the widget.
|
|
311
|
+
*/
|
|
312
|
+
}, {
|
|
313
|
+
key: "model",
|
|
314
|
+
get: function get() {
|
|
315
|
+
return this.editor.model;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Dispose of the resources held by the widget.
|
|
320
|
+
*/
|
|
321
|
+
}, {
|
|
322
|
+
key: "dispose",
|
|
323
|
+
value: function dispose() {
|
|
324
|
+
if (this.isDisposed) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
_get(_getPrototypeOf(CodeEditorView.prototype), "dispose", this).call(this);
|
|
328
|
+
this.editor.dispose();
|
|
329
|
+
}
|
|
330
|
+
}, {
|
|
331
|
+
key: "onResize",
|
|
332
|
+
value:
|
|
333
|
+
/**
|
|
334
|
+
* A message handler invoked on a `'resize'` message.
|
|
335
|
+
*/
|
|
336
|
+
function onResize() {
|
|
337
|
+
if (this.isVisible) {
|
|
338
|
+
this.editor.resizeToFit();
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}, {
|
|
342
|
+
key: "addClass",
|
|
343
|
+
value: function addClass(classname) {
|
|
344
|
+
this.classlist.push(classname);
|
|
345
|
+
}
|
|
346
|
+
}, {
|
|
347
|
+
key: "removeClass",
|
|
348
|
+
value: function removeClass(classname) {
|
|
349
|
+
var index = this.classlist.indexOf(classname);
|
|
350
|
+
if (index >= 0) {
|
|
351
|
+
this.classlist.splice(index, 1);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Handle a change in model selections.
|
|
357
|
+
*/
|
|
358
|
+
}, {
|
|
359
|
+
key: "_onSelectionsChanged",
|
|
360
|
+
value: function _onSelectionsChanged() {
|
|
361
|
+
var _this$editor$getSelec = this.editor.getSelection(),
|
|
362
|
+
start = _this$editor$getSelec.start,
|
|
363
|
+
end = _this$editor$getSelec.end;
|
|
364
|
+
if (start.column !== end.column || start.line !== end.line) {
|
|
365
|
+
// a selection was made
|
|
366
|
+
this.addClass(HAS_SELECTION_CLASS);
|
|
367
|
+
this.removeClass(HAS_IN_LEADING_WHITESPACE_CLASS);
|
|
368
|
+
} else {
|
|
369
|
+
// the cursor was placed
|
|
370
|
+
this.removeClass(HAS_SELECTION_CLASS);
|
|
371
|
+
if (this.editor.getLine(end.line).slice(0, end.column).match(leadingWhitespaceRe)) {
|
|
372
|
+
this.addClass(HAS_IN_LEADING_WHITESPACE_CLASS);
|
|
373
|
+
} else {
|
|
374
|
+
this.removeClass(HAS_IN_LEADING_WHITESPACE_CLASS);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}]);
|
|
379
|
+
return CodeEditorView;
|
|
380
|
+
}(BaseView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "themeService", [_dec3], {
|
|
381
|
+
configurable: true,
|
|
382
|
+
enumerable: true,
|
|
383
|
+
writable: true,
|
|
384
|
+
initializer: null
|
|
385
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "codeEditorSettings", [_dec4], {
|
|
386
|
+
configurable: true,
|
|
387
|
+
enumerable: true,
|
|
388
|
+
writable: true,
|
|
389
|
+
initializer: null
|
|
390
|
+
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "codeEditorStateManager", [_dec5], {
|
|
391
|
+
configurable: true,
|
|
392
|
+
enumerable: true,
|
|
393
|
+
writable: true,
|
|
394
|
+
initializer: null
|
|
395
|
+
})), _class2)) || _class) || _class);
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* The namespace for the `CodeEditorWrapper` statics.
|
|
399
|
+
*/
|
|
400
|
+
/**
|
|
401
|
+
* The options used to initialize a code editor widget.
|
|
402
|
+
*/
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Given a MimeData instance, extract the first text data, if any.
|
|
406
|
+
*/
|
|
407
|
+
function findTextData(event) {
|
|
408
|
+
var _event$dataTransfer;
|
|
409
|
+
var items = (_event$dataTransfer = event.dataTransfer) === null || _event$dataTransfer === void 0 ? void 0 : _event$dataTransfer.items;
|
|
410
|
+
if (!items) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
var textTypeItem = Array.from(items).find(function (t) {
|
|
414
|
+
return t.type.indexOf('text') === 0;
|
|
415
|
+
});
|
|
416
|
+
if (textTypeItem === undefined) {
|
|
417
|
+
return undefined;
|
|
418
|
+
}
|
|
419
|
+
return event.dataTransfer.getData(textTypeItem.type);
|
|
420
|
+
}
|
package/es/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './code-editor-manager.js';
|
|
2
|
+
export * from './code-editor-model.js';
|
|
3
|
+
export * from './code-editor-protocol.js';
|
|
4
|
+
export * from './code-editor-settings.js';
|
|
5
|
+
export * from './code-editor-view.js';
|
|
6
|
+
export * from './mimetype.js';
|
|
7
|
+
export * from './module.js';
|
|
8
|
+
export * from './language-specs.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC"}
|
package/es/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./code-editor-manager.js";
|
|
2
|
+
export * from "./code-editor-model.js";
|
|
3
|
+
export * from "./code-editor-protocol.js";
|
|
4
|
+
export * from "./code-editor-settings.js";
|
|
5
|
+
export * from "./code-editor-view.js";
|
|
6
|
+
export * from "./mimetype.js";
|
|
7
|
+
export * from "./module.js";
|
|
8
|
+
export * from "./language-specs.js";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Contribution } from '@difizen/mana-app';
|
|
2
|
+
import { ApplicationContribution } from '@difizen/mana-app';
|
|
3
|
+
import { Syringe } from '@difizen/mana-app';
|
|
4
|
+
export declare const LanguageSpecContribution: Syringe.DefinedToken;
|
|
5
|
+
export interface LanguageSpecContribution {
|
|
6
|
+
registerLanguageSpec: (register: LanguageSpecRegistry) => void;
|
|
7
|
+
}
|
|
8
|
+
export interface LanguageSpec {
|
|
9
|
+
/**
|
|
10
|
+
* language name
|
|
11
|
+
*/
|
|
12
|
+
name: string;
|
|
13
|
+
/**
|
|
14
|
+
* https://code.visualstudio.com/docs/languages/identifiers
|
|
15
|
+
*/
|
|
16
|
+
language: string;
|
|
17
|
+
/**
|
|
18
|
+
* https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
19
|
+
*/
|
|
20
|
+
mime: string;
|
|
21
|
+
/**
|
|
22
|
+
* file extension
|
|
23
|
+
*/
|
|
24
|
+
ext: string[];
|
|
25
|
+
}
|
|
26
|
+
export declare class LanguageSpecRegistry implements ApplicationContribution {
|
|
27
|
+
get languageSpecs(): LanguageSpec[];
|
|
28
|
+
protected languageSpecsData: LanguageSpec[];
|
|
29
|
+
protected readonly languageSpecProvider: Contribution.Provider<LanguageSpecContribution>;
|
|
30
|
+
constructor(languageSpecProvider: Contribution.Provider<LanguageSpecContribution>);
|
|
31
|
+
initialize(): void;
|
|
32
|
+
/**
|
|
33
|
+
* 注册语言元信息,代码编辑器根据这些信息来设置语言;使用代码编辑器的cell一般需要注册语言元信息
|
|
34
|
+
*/
|
|
35
|
+
registerLanguageSpec(spec: LanguageSpec): void;
|
|
36
|
+
hasLanguage(spec: LanguageSpec): boolean;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=language-specs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-specs.d.ts","sourceRoot":"","sources":["../src/language-specs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAsB,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEhE,eAAO,MAAM,wBAAwB,sBAAkD,CAAC;AACxF,MAAM,WAAW,wBAAwB;IACvC,oBAAoB,EAAE,CAAC,QAAQ,EAAE,oBAAoB,KAAK,IAAI,CAAC;CAChE;AACD,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,GAAG,EAAE,MAAM,EAAE,CAAC;CACf;AAED,qBACa,oBAAqB,YAAW,uBAAuB;IAClE,IAAI,aAAa,IAAI,YAAY,EAAE,CAElC;IACD,SAAS,CAAC,iBAAiB,EAAE,YAAY,EAAE,CAAM;IAEjD,SAAS,CAAC,QAAQ,CAAC,oBAAoB,EAAE,YAAY,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAAC;gBAIvF,oBAAoB,EAAE,YAAY,CAAC,QAAQ,CAAC,wBAAwB,CAAC;IAKvE,UAAU;IAMV;;OAEG;IACH,oBAAoB,CAAC,IAAI,EAAE,YAAY;IAWvC,WAAW,CAAC,IAAI,EAAE,YAAY;CAK/B"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
var _dec, _class;
|
|
3
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
5
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
import { ApplicationContribution } from '@difizen/mana-app';
|
|
9
|
+
import { contrib, singleton, Syringe } from '@difizen/mana-app';
|
|
10
|
+
export var LanguageSpecContribution = Syringe.defineToken('LanguageSpecContribution');
|
|
11
|
+
export var LanguageSpecRegistry = (_dec = singleton({
|
|
12
|
+
contrib: [ApplicationContribution]
|
|
13
|
+
}), _dec(_class = /*#__PURE__*/function () {
|
|
14
|
+
function LanguageSpecRegistry(languageSpecProvider) {
|
|
15
|
+
_classCallCheck(this, LanguageSpecRegistry);
|
|
16
|
+
this.languageSpecsData = [];
|
|
17
|
+
this.languageSpecProvider = languageSpecProvider;
|
|
18
|
+
}
|
|
19
|
+
LanguageSpecRegistry = contrib(LanguageSpecContribution)(LanguageSpecRegistry, undefined, 0) || LanguageSpecRegistry;
|
|
20
|
+
_createClass(LanguageSpecRegistry, [{
|
|
21
|
+
key: "languageSpecs",
|
|
22
|
+
get: function get() {
|
|
23
|
+
return this.languageSpecsData;
|
|
24
|
+
}
|
|
25
|
+
}, {
|
|
26
|
+
key: "initialize",
|
|
27
|
+
value: function initialize() {
|
|
28
|
+
var _this = this;
|
|
29
|
+
this.languageSpecProvider.getContributions().forEach(function (item) {
|
|
30
|
+
item.registerLanguageSpec(_this);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 注册语言元信息,代码编辑器根据这些信息来设置语言;使用代码编辑器的cell一般需要注册语言元信息
|
|
36
|
+
*/
|
|
37
|
+
}, {
|
|
38
|
+
key: "registerLanguageSpec",
|
|
39
|
+
value: function registerLanguageSpec(spec) {
|
|
40
|
+
var index = this.languageSpecsData.findIndex(function (item) {
|
|
41
|
+
return item.language === spec.language;
|
|
42
|
+
});
|
|
43
|
+
if (index >= 0) {
|
|
44
|
+
this.languageSpecsData.splice(index, 1, spec);
|
|
45
|
+
} else {
|
|
46
|
+
this.languageSpecsData.push(spec);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
50
|
+
key: "hasLanguage",
|
|
51
|
+
value: function hasLanguage(spec) {
|
|
52
|
+
return this.languageSpecsData.findIndex(function (item) {
|
|
53
|
+
return item.language === spec.language;
|
|
54
|
+
}) > 0;
|
|
55
|
+
}
|
|
56
|
+
}]);
|
|
57
|
+
return LanguageSpecRegistry;
|
|
58
|
+
}()) || _class);
|
package/es/mimetype.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ILanguageInfoMetadata } from '@difizen/libro-common';
|
|
2
|
+
/**
|
|
3
|
+
* The mime type service of a code editor.
|
|
4
|
+
*/
|
|
5
|
+
export interface IEditorMimeTypeService {
|
|
6
|
+
/**
|
|
7
|
+
* Get a mime type for the given language info.
|
|
8
|
+
*
|
|
9
|
+
* @param info - The language information.
|
|
10
|
+
*
|
|
11
|
+
* @returns A valid mimetype.
|
|
12
|
+
*
|
|
13
|
+
* #### Notes
|
|
14
|
+
* If a mime type cannot be found returns the default mime type `text/plain`, never `null`.
|
|
15
|
+
*/
|
|
16
|
+
getMimeTypeByLanguage: (info: ILanguageInfoMetadata) => string;
|
|
17
|
+
/**
|
|
18
|
+
* Get a mime type for the given file path.
|
|
19
|
+
*
|
|
20
|
+
* @param filePath - The full path to the file.
|
|
21
|
+
*
|
|
22
|
+
* @returns A valid mimetype.
|
|
23
|
+
*
|
|
24
|
+
* #### Notes
|
|
25
|
+
* If a mime type cannot be found returns the default mime type `text/plain`, never `null`.
|
|
26
|
+
*/
|
|
27
|
+
getMimeTypeByFilePath: (filePath: string) => string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The default mime type.
|
|
31
|
+
*/
|
|
32
|
+
export declare const defaultMimeType = "text/plain";
|
|
33
|
+
//# sourceMappingURL=mimetype.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mimetype.d.ts","sourceRoot":"","sources":["../src/mimetype.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;;;;;OASG;IACH,qBAAqB,EAAE,CAAC,IAAI,EAAE,qBAAqB,KAAK,MAAM,CAAC;IAC/D;;;;;;;;;OASG;IACH,qBAAqB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;CACrD;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,eAAe,CAAC"}
|
package/es/mimetype.js
ADDED
package/es/module.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAW/C,eAAO,MAAM,gBAAgB,YAUoC,CAAC"}
|
package/es/module.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ManaModule } from '@difizen/mana-app';
|
|
2
|
+
import { CodeEditorInfoManager } from "./code-editor-info-manager.js";
|
|
3
|
+
import { CodeEditorManager } from "./code-editor-manager.js";
|
|
4
|
+
import { Model } from "./code-editor-model.js";
|
|
5
|
+
import { CodeEditorContribution } from "./code-editor-protocol.js";
|
|
6
|
+
import { CodeEditorSettings } from "./code-editor-settings.js";
|
|
7
|
+
import { CodeEditorStateManager } from "./code-editor-state-manager.js";
|
|
8
|
+
import { CodeEditorView } from "./code-editor-view.js";
|
|
9
|
+
import { LanguageSpecContribution, LanguageSpecRegistry } from "./language-specs.js";
|
|
10
|
+
export var CodeEditorModule = ManaModule.create().register(CodeEditorInfoManager, CodeEditorView, CodeEditorManager, Model, CodeEditorSettings, CodeEditorStateManager, LanguageSpecRegistry).contribution(CodeEditorContribution, LanguageSpecContribution);
|