@difizen/libro-cofine-editor 0.1.2
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 +3 -0
- package/es/editor-contribution.d.ts +10 -0
- package/es/editor-contribution.d.ts.map +1 -0
- package/es/editor-contribution.js +31 -0
- package/es/index.d.ts +7 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +6 -0
- package/es/index.less +32 -0
- package/es/language/lsp/completion-provider.d.ts +13 -0
- package/es/language/lsp/completion-provider.d.ts.map +1 -0
- package/es/language/lsp/completion-provider.js +290 -0
- package/es/language/lsp/diagnostic-provider.d.ts +22 -0
- package/es/language/lsp/diagnostic-provider.d.ts.map +1 -0
- package/es/language/lsp/diagnostic-provider.js +161 -0
- package/es/language/lsp/format-provider.d.ts +9 -0
- package/es/language/lsp/format-provider.d.ts.map +1 -0
- package/es/language/lsp/format-provider.js +139 -0
- package/es/language/lsp/hover-provider.d.ts +8 -0
- package/es/language/lsp/hover-provider.d.ts.map +1 -0
- package/es/language/lsp/hover-provider.js +136 -0
- package/es/language/lsp/language-feature-provider.d.ts +17 -0
- package/es/language/lsp/language-feature-provider.d.ts.map +1 -0
- package/es/language/lsp/language-feature-provider.js +89 -0
- package/es/language/lsp/lsp-contribution.d.ts +25 -0
- package/es/language/lsp/lsp-contribution.d.ts.map +1 -0
- package/es/language/lsp/lsp-contribution.js +213 -0
- package/es/language/lsp/module.d.ts +2 -0
- package/es/language/lsp/module.d.ts.map +1 -0
- package/es/language/lsp/module.js +3 -0
- package/es/language/lsp/semantic-highlight-provider.d.ts +9 -0
- package/es/language/lsp/semantic-highlight-provider.d.ts.map +1 -0
- package/es/language/lsp/semantic-highlight-provider.js +41 -0
- package/es/language/lsp/signature-help-provider.d.ts +8 -0
- package/es/language/lsp/signature-help-provider.d.ts.map +1 -0
- package/es/language/lsp/signature-help-provider.js +108 -0
- package/es/language/lsp/type-concerters.d.ts +7 -0
- package/es/language/lsp/type-concerters.d.ts.map +1 -0
- package/es/language/lsp/type-concerters.js +37 -0
- package/es/language/python/data/MagicPython.tmLanguage.json +4213 -0
- package/es/language/python/data/MagicRegExp.tmLanguage.json +497 -0
- package/es/language/python/data/configurations/python.json +135 -0
- package/es/language/python/data/snippets/python.snippets.json +223 -0
- package/es/language/python/module.d.ts +2 -0
- package/es/language/python/module.d.ts.map +1 -0
- package/es/language/python/module.js +3 -0
- package/es/language/python/python-builtin.d.ts +86 -0
- package/es/language/python/python-builtin.d.ts.map +1 -0
- package/es/language/python/python-builtin.js +569 -0
- package/es/language/python/python-language-feature.d.ts +26 -0
- package/es/language/python/python-language-feature.d.ts.map +1 -0
- package/es/language/python/python-language-feature.js +174 -0
- package/es/language-specs.d.ts +33 -0
- package/es/language-specs.d.ts.map +1 -0
- package/es/language-specs.js +115 -0
- package/es/libro-e2-editor.d.ts +277 -0
- package/es/libro-e2-editor.d.ts.map +1 -0
- package/es/libro-e2-editor.js +720 -0
- package/es/libro-e2-preload.d.ts +5 -0
- package/es/libro-e2-preload.d.ts.map +1 -0
- package/es/libro-e2-preload.js +57 -0
- package/es/libro-sql-api.d.ts +8 -0
- package/es/libro-sql-api.d.ts.map +1 -0
- package/es/libro-sql-api.js +26 -0
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +44 -0
- package/es/placeholder.d.ts +31 -0
- package/es/placeholder.d.ts.map +1 -0
- package/es/placeholder.js +101 -0
- package/es/theme/data/jupyter_dark.json +406 -0
- package/es/theme/data/jupyter_hc_dark.json +385 -0
- package/es/theme/data/jupyter_hc_light.json +386 -0
- package/es/theme/data/jupyter_light.json +386 -0
- package/es/theme/data/libro_dark.json +186 -0
- package/es/theme/data/libro_light.json +170 -0
- package/es/theme/libro-python-theme-contribution.d.ts +6 -0
- package/es/theme/libro-python-theme-contribution.d.ts.map +1 -0
- package/es/theme/libro-python-theme-contribution.js +49 -0
- package/es/theme/module.d.ts +2 -0
- package/es/theme/module.d.ts.map +1 -0
- package/es/theme/module.js +3 -0
- package/es/types.d.ts +10 -0
- package/es/types.d.ts.map +1 -0
- package/es/types.js +3 -0
- package/package.json +67 -0
- package/src/editor-contribution.ts +30 -0
- package/src/index.less +32 -0
- package/src/index.spec.ts +8 -0
- package/src/index.ts +6 -0
- package/src/language/lsp/completion-provider.ts +214 -0
- package/src/language/lsp/diagnostic-provider.ts +148 -0
- package/src/language/lsp/format-provider.ts +87 -0
- package/src/language/lsp/hover-provider.ts +98 -0
- package/src/language/lsp/language-feature-provider.ts +69 -0
- package/src/language/lsp/lsp-contribution.ts +159 -0
- package/src/language/lsp/module.ts +5 -0
- package/src/language/lsp/semantic-highlight-provider.ts +26 -0
- package/src/language/lsp/signature-help-provider.ts +65 -0
- package/src/language/lsp/type-concerters.ts +72 -0
- package/src/language/python/data/MagicPython.tmLanguage.json +4213 -0
- package/src/language/python/data/MagicRegExp.tmLanguage.json +497 -0
- package/src/language/python/data/configurations/python.json +135 -0
- package/src/language/python/data/snippets/python.snippets.json +223 -0
- package/src/language/python/module.ts +5 -0
- package/src/language/python/python-builtin.ts +891 -0
- package/src/language/python/python-language-feature.ts +163 -0
- package/src/language-specs.ts +99 -0
- package/src/libro-e2-editor.ts +922 -0
- package/src/libro-e2-preload.ts +23 -0
- package/src/libro-sql-api.ts +20 -0
- package/src/module.ts +44 -0
- package/src/placeholder.ts +100 -0
- package/src/theme/data/jupyter_dark.json +406 -0
- package/src/theme/data/jupyter_hc_dark.json +385 -0
- package/src/theme/data/jupyter_hc_light.json +386 -0
- package/src/theme/data/jupyter_light.json +386 -0
- package/src/theme/data/libro_dark.json +186 -0
- package/src/theme/data/libro_light.json +170 -0
- package/src/theme/libro-python-theme-contribution.ts +36 -0
- package/src/theme/module.ts +5 -0
- package/src/types.ts +11 -0
|
@@ -0,0 +1,720 @@
|
|
|
1
|
+
var _dec, _dec2, _dec3, _class, _class2, _descriptor, _descriptor2;
|
|
2
|
+
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); }
|
|
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 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); } }
|
|
5
|
+
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); }); }; }
|
|
6
|
+
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 }); }
|
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
+
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); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
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; }
|
|
11
|
+
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.'); }
|
|
12
|
+
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; }
|
|
13
|
+
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; }
|
|
14
|
+
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; }
|
|
15
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
16
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
17
|
+
import { defaultConfig } from '@difizen/libro-code-editor';
|
|
18
|
+
import { EditorProvider, MonacoEnvironment } from '@difizen/libro-cofine-editor-core';
|
|
19
|
+
import { NotebookCommands } from '@difizen/libro-core';
|
|
20
|
+
import { CommandRegistry, inject, ThemeService, transient, watch } from '@difizen/mana-app';
|
|
21
|
+
import { Disposable, DisposableCollection, Emitter } from '@difizen/mana-app';
|
|
22
|
+
import { editor, Selection } from '@difizen/monaco-editor-core';
|
|
23
|
+
import 'resize-observer-polyfill';
|
|
24
|
+
import { v4 } from 'uuid';
|
|
25
|
+
import { LSPContribution } from "./language/lsp/lsp-contribution.js";
|
|
26
|
+
import { LanguageSpecRegistry } from "./language-specs.js";
|
|
27
|
+
import { PlaceholderContentWidget } from "./placeholder.js";
|
|
28
|
+
import { MonacoRange, MonacoUri } from "./types.js";
|
|
29
|
+
import "./index.less";
|
|
30
|
+
export var LibroE2EditorOptions = Symbol('LibroE2EditorOptions');
|
|
31
|
+
export var libroE2DefaultConfig = _objectSpread(_objectSpread({}, defaultConfig), {}, {
|
|
32
|
+
theme: {
|
|
33
|
+
dark: 'libro-dark',
|
|
34
|
+
light: 'libro-light',
|
|
35
|
+
hc: 'e2-hc'
|
|
36
|
+
},
|
|
37
|
+
scrollBarHeight: 12,
|
|
38
|
+
mode: 'null',
|
|
39
|
+
mimetype: 'text/x-python',
|
|
40
|
+
smartIndent: true,
|
|
41
|
+
electricChars: true,
|
|
42
|
+
keyMap: 'default',
|
|
43
|
+
// extraKeys: null,
|
|
44
|
+
gutters: [],
|
|
45
|
+
fixedGutter: true,
|
|
46
|
+
showCursorWhenSelecting: false,
|
|
47
|
+
coverGutterNextToScrollbar: false,
|
|
48
|
+
dragDrop: true,
|
|
49
|
+
lineSeparator: null,
|
|
50
|
+
scrollbarStyle: 'native',
|
|
51
|
+
lineWiseCopyCut: true,
|
|
52
|
+
scrollPastEnd: false,
|
|
53
|
+
styleActiveLine: false,
|
|
54
|
+
styleSelectedText: true,
|
|
55
|
+
selectionPointer: false,
|
|
56
|
+
handlePaste: true,
|
|
57
|
+
lineWrap: 'off',
|
|
58
|
+
lspEnabled: true,
|
|
59
|
+
//
|
|
60
|
+
highlightActiveLineGutter: false,
|
|
61
|
+
highlightSpecialChars: true,
|
|
62
|
+
history: true,
|
|
63
|
+
drawSelection: true,
|
|
64
|
+
dropCursor: true,
|
|
65
|
+
allowMultipleSelections: true,
|
|
66
|
+
autocompletion: true,
|
|
67
|
+
rectangularSelection: true,
|
|
68
|
+
crosshairCursor: true,
|
|
69
|
+
highlightSelectionMatches: true,
|
|
70
|
+
foldGutter: true,
|
|
71
|
+
syntaxHighlighting: true,
|
|
72
|
+
jupyterKernelCompletion: true,
|
|
73
|
+
indentationMarkers: true,
|
|
74
|
+
hyperLink: true,
|
|
75
|
+
jupyterKernelTooltip: true,
|
|
76
|
+
tabEditorFunction: true,
|
|
77
|
+
lspCompletion: true,
|
|
78
|
+
lspTooltip: true,
|
|
79
|
+
lspLint: true,
|
|
80
|
+
placeholder: ''
|
|
81
|
+
});
|
|
82
|
+
export var LibroE2EditorFactory = Symbol('LibroE2EditorFactory');
|
|
83
|
+
export var E2EditorClassname = 'libro-e2-editor';
|
|
84
|
+
export var LibroE2URIScheme = 'libro-e2';
|
|
85
|
+
export var LibroE2Editor = (_dec = transient(), _dec2 = inject(CommandRegistry), _dec3 = inject(LSPContribution), _dec(_class = (_class2 = /*#__PURE__*/function () {
|
|
86
|
+
function LibroE2Editor(options, themeService, languageSpecRegistry) {
|
|
87
|
+
var _this = this;
|
|
88
|
+
_classCallCheck(this, LibroE2Editor);
|
|
89
|
+
_initializerDefineProperty(this, "commandRegistry", _descriptor, this);
|
|
90
|
+
_initializerDefineProperty(this, "lspContribution", _descriptor2, this);
|
|
91
|
+
this.defaultLineHeight = 20;
|
|
92
|
+
this.toDispose = new DisposableCollection();
|
|
93
|
+
this.oldDeltaDecorations = [];
|
|
94
|
+
this._uuid = '';
|
|
95
|
+
this.isLayouting = false;
|
|
96
|
+
this.onThemeChange = function () {
|
|
97
|
+
var _this$monacoEditor;
|
|
98
|
+
(_this$monacoEditor = _this.monacoEditor) === null || _this$monacoEditor === void 0 || _this$monacoEditor.updateOptions({
|
|
99
|
+
theme: _this.theme
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
*
|
|
104
|
+
* @param option
|
|
105
|
+
* @param value
|
|
106
|
+
*/
|
|
107
|
+
this.setOption = function (option, value) {
|
|
108
|
+
if (value === null || value === undefined) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (option === 'theme') {
|
|
112
|
+
var _this$monacoEditor2;
|
|
113
|
+
_this._config.theme = value;
|
|
114
|
+
(_this$monacoEditor2 = _this.monacoEditor) === null || _this$monacoEditor2 === void 0 || _this$monacoEditor2.updateOptions({
|
|
115
|
+
theme: _this.theme
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (option === 'placeholder') {
|
|
119
|
+
_this._config.placeholder = value;
|
|
120
|
+
_this.placeholder.update(value);
|
|
121
|
+
}
|
|
122
|
+
if (option === 'lspEnabled') {
|
|
123
|
+
_this._config.lspEnabled = value;
|
|
124
|
+
}
|
|
125
|
+
var sizeKeys = ['fontFamily', 'fontSize', 'lineHeight', 'wordWrapColumn', 'lineWrap'];
|
|
126
|
+
var monacoOptionkeys = sizeKeys.concat(['readOnly', 'insertSpaces', 'tabSize']);
|
|
127
|
+
if (monacoOptionkeys.includes(option)) {
|
|
128
|
+
var _this$monacoEditor3;
|
|
129
|
+
_this._config = _objectSpread(_objectSpread({}, _this._config), {}, _defineProperty({}, option, value));
|
|
130
|
+
(_this$monacoEditor3 = _this.monacoEditor) === null || _this$monacoEditor3 === void 0 || _this$monacoEditor3.updateOptions(_this.toMonacoOptions(_this._config));
|
|
131
|
+
}
|
|
132
|
+
if (sizeKeys.includes(option)) {
|
|
133
|
+
_this.updateEditorSize();
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
this.getLine = function (line) {
|
|
137
|
+
var _this$monacoEditor4;
|
|
138
|
+
return (_this$monacoEditor4 = _this.monacoEditor) === null || _this$monacoEditor4 === void 0 || (_this$monacoEditor4 = _this$monacoEditor4.getModel()) === null || _this$monacoEditor4 === void 0 ? void 0 : _this$monacoEditor4.getLineContent(line);
|
|
139
|
+
};
|
|
140
|
+
this.getOffsetAt = function (position) {
|
|
141
|
+
var _this$monacoEditor5;
|
|
142
|
+
return ((_this$monacoEditor5 = _this.monacoEditor) === null || _this$monacoEditor5 === void 0 || (_this$monacoEditor5 = _this$monacoEditor5.getModel()) === null || _this$monacoEditor5 === void 0 ? void 0 : _this$monacoEditor5.getOffsetAt({
|
|
143
|
+
lineNumber: position.line,
|
|
144
|
+
column: position.column
|
|
145
|
+
})) || 0;
|
|
146
|
+
};
|
|
147
|
+
this.undo = function () {
|
|
148
|
+
var _this$monacoEditor6;
|
|
149
|
+
(_this$monacoEditor6 = _this.monacoEditor) === null || _this$monacoEditor6 === void 0 || _this$monacoEditor6.trigger('source', 'undo', {});
|
|
150
|
+
};
|
|
151
|
+
this.redo = function () {
|
|
152
|
+
var _this$monacoEditor7;
|
|
153
|
+
(_this$monacoEditor7 = _this.monacoEditor) === null || _this$monacoEditor7 === void 0 || _this$monacoEditor7.trigger('source', 'redo', {});
|
|
154
|
+
};
|
|
155
|
+
this.focus = function () {
|
|
156
|
+
var _this$monacoEditor8;
|
|
157
|
+
(_this$monacoEditor8 = _this.monacoEditor) === null || _this$monacoEditor8 === void 0 || _this$monacoEditor8.focus();
|
|
158
|
+
};
|
|
159
|
+
this.hasFocus = function () {
|
|
160
|
+
var _this$monacoEditor$ha, _this$monacoEditor9;
|
|
161
|
+
return (_this$monacoEditor$ha = (_this$monacoEditor9 = _this.monacoEditor) === null || _this$monacoEditor9 === void 0 ? void 0 : _this$monacoEditor9.hasWidgetFocus()) !== null && _this$monacoEditor$ha !== void 0 ? _this$monacoEditor$ha : false;
|
|
162
|
+
};
|
|
163
|
+
this.blur = function () {
|
|
164
|
+
document.documentElement.focus();
|
|
165
|
+
};
|
|
166
|
+
this.resizeToFit = function () {
|
|
167
|
+
var _this$monacoEditor10;
|
|
168
|
+
(_this$monacoEditor10 = _this.monacoEditor) === null || _this$monacoEditor10 === void 0 || _this$monacoEditor10.layout();
|
|
169
|
+
};
|
|
170
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
171
|
+
this.getPositionForCoordinate = function (coordinate) {
|
|
172
|
+
return null;
|
|
173
|
+
};
|
|
174
|
+
this.modalChangeEmitter = new Emitter();
|
|
175
|
+
this.getSelectionValue = function (range) {
|
|
176
|
+
var _this$monacoEditor11;
|
|
177
|
+
var selection = range !== null && range !== void 0 ? range : _this.getSelection();
|
|
178
|
+
return (_this$monacoEditor11 = _this.monacoEditor) === null || _this$monacoEditor11 === void 0 || (_this$monacoEditor11 = _this$monacoEditor11.getModel()) === null || _this$monacoEditor11 === void 0 ? void 0 : _this$monacoEditor11.getValueInRange(_this.toMonacoRange(selection));
|
|
179
|
+
};
|
|
180
|
+
this.getPositionAt = function (offset) {
|
|
181
|
+
var _this$monacoEditor12;
|
|
182
|
+
var position = (_this$monacoEditor12 = _this.monacoEditor) === null || _this$monacoEditor12 === void 0 || (_this$monacoEditor12 = _this$monacoEditor12.getModel()) === null || _this$monacoEditor12 === void 0 ? void 0 : _this$monacoEditor12.getPositionAt(offset);
|
|
183
|
+
return position ? {
|
|
184
|
+
line: position.lineNumber,
|
|
185
|
+
column: position.column
|
|
186
|
+
} : position;
|
|
187
|
+
};
|
|
188
|
+
this.replaceSelection = function (text, range) {
|
|
189
|
+
var _this$monacoEditor13, _this$monacoEditor14;
|
|
190
|
+
(_this$monacoEditor13 = _this.monacoEditor) === null || _this$monacoEditor13 === void 0 || _this$monacoEditor13.executeEdits(undefined, [{
|
|
191
|
+
range: _this.toMonacoRange(range),
|
|
192
|
+
text: text
|
|
193
|
+
}]);
|
|
194
|
+
(_this$monacoEditor14 = _this.monacoEditor) === null || _this$monacoEditor14 === void 0 || _this$monacoEditor14.pushUndoStop();
|
|
195
|
+
};
|
|
196
|
+
this.replaceSelections = function (edits) {
|
|
197
|
+
var _this$monacoEditor15, _this$monacoEditor16;
|
|
198
|
+
(_this$monacoEditor15 = _this.monacoEditor) === null || _this$monacoEditor15 === void 0 || _this$monacoEditor15.executeEdits(undefined, edits.map(function (item) {
|
|
199
|
+
return {
|
|
200
|
+
range: _this.toMonacoRange(item.range),
|
|
201
|
+
text: item.text
|
|
202
|
+
};
|
|
203
|
+
}));
|
|
204
|
+
(_this$monacoEditor16 = _this.monacoEditor) === null || _this$monacoEditor16 === void 0 || _this$monacoEditor16.pushUndoStop();
|
|
205
|
+
};
|
|
206
|
+
this.getCursorPosition = function () {
|
|
207
|
+
var _this$monacoEditor17, _this$monacoEditor18;
|
|
208
|
+
var position = {
|
|
209
|
+
line: ((_this$monacoEditor17 = _this.monacoEditor) === null || _this$monacoEditor17 === void 0 || (_this$monacoEditor17 = _this$monacoEditor17.getPosition()) === null || _this$monacoEditor17 === void 0 ? void 0 : _this$monacoEditor17.lineNumber) || 1,
|
|
210
|
+
column: ((_this$monacoEditor18 = _this.monacoEditor) === null || _this$monacoEditor18 === void 0 || (_this$monacoEditor18 = _this$monacoEditor18.getPosition()) === null || _this$monacoEditor18 === void 0 ? void 0 : _this$monacoEditor18.column) || 1
|
|
211
|
+
};
|
|
212
|
+
return position;
|
|
213
|
+
};
|
|
214
|
+
this.setCursorPosition = function (position) {
|
|
215
|
+
var _this$monacoEditor19;
|
|
216
|
+
(_this$monacoEditor19 = _this.monacoEditor) === null || _this$monacoEditor19 === void 0 || _this$monacoEditor19.setPosition({
|
|
217
|
+
column: position.column,
|
|
218
|
+
lineNumber: position.line
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
this.getSelection = function () {
|
|
222
|
+
var _this$monacoEditor20, _this$monacoEditor21, _this$monacoEditor22, _this$monacoEditor23;
|
|
223
|
+
var selection = {
|
|
224
|
+
start: {
|
|
225
|
+
line: ((_this$monacoEditor20 = _this.monacoEditor) === null || _this$monacoEditor20 === void 0 || (_this$monacoEditor20 = _this$monacoEditor20.getSelection()) === null || _this$monacoEditor20 === void 0 ? void 0 : _this$monacoEditor20.startLineNumber) || 1,
|
|
226
|
+
column: ((_this$monacoEditor21 = _this.monacoEditor) === null || _this$monacoEditor21 === void 0 || (_this$monacoEditor21 = _this$monacoEditor21.getSelection()) === null || _this$monacoEditor21 === void 0 ? void 0 : _this$monacoEditor21.startColumn) || 1
|
|
227
|
+
},
|
|
228
|
+
end: {
|
|
229
|
+
line: ((_this$monacoEditor22 = _this.monacoEditor) === null || _this$monacoEditor22 === void 0 || (_this$monacoEditor22 = _this$monacoEditor22.getSelection()) === null || _this$monacoEditor22 === void 0 ? void 0 : _this$monacoEditor22.endLineNumber) || 1,
|
|
230
|
+
column: ((_this$monacoEditor23 = _this.monacoEditor) === null || _this$monacoEditor23 === void 0 || (_this$monacoEditor23 = _this$monacoEditor23.getSelection()) === null || _this$monacoEditor23 === void 0 ? void 0 : _this$monacoEditor23.endColumn) || 1
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
return selection;
|
|
234
|
+
};
|
|
235
|
+
this.setSelection = function (selection) {
|
|
236
|
+
var _this$monacoEditor24;
|
|
237
|
+
(_this$monacoEditor24 = _this.monacoEditor) === null || _this$monacoEditor24 === void 0 || _this$monacoEditor24.setSelection(_this.toMonacoRange(selection));
|
|
238
|
+
};
|
|
239
|
+
this.getSelections = function () {
|
|
240
|
+
var _this$monacoEditor25;
|
|
241
|
+
var selections = [];
|
|
242
|
+
(_this$monacoEditor25 = _this.monacoEditor) === null || _this$monacoEditor25 === void 0 || (_this$monacoEditor25 = _this$monacoEditor25.getSelections()) === null || _this$monacoEditor25 === void 0 || _this$monacoEditor25.map(function (selection) {
|
|
243
|
+
return selections.push({
|
|
244
|
+
start: {
|
|
245
|
+
line: selection.startLineNumber || 1,
|
|
246
|
+
column: selection.startColumn || 1
|
|
247
|
+
},
|
|
248
|
+
end: {
|
|
249
|
+
line: selection.endLineNumber || 1,
|
|
250
|
+
column: selection.endColumn || 1
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
return selections;
|
|
255
|
+
};
|
|
256
|
+
this.setSelections = function (selections) {
|
|
257
|
+
var _this$monacoEditor26;
|
|
258
|
+
(_this$monacoEditor26 = _this.monacoEditor) === null || _this$monacoEditor26 === void 0 || _this$monacoEditor26.setSelections(selections.map(function (item) {
|
|
259
|
+
return new Selection(item.start.line, item.start.column, item.end.line, item.end.column);
|
|
260
|
+
}));
|
|
261
|
+
};
|
|
262
|
+
this.revealSelection = function (selection) {
|
|
263
|
+
var _this$monacoEditor27;
|
|
264
|
+
(_this$monacoEditor27 = _this.monacoEditor) === null || _this$monacoEditor27 === void 0 || _this$monacoEditor27.revealRange(_this.toMonacoRange(selection));
|
|
265
|
+
};
|
|
266
|
+
this.highlightMatches = function (matches, currentIndex) {
|
|
267
|
+
var _this$monacoEditor28;
|
|
268
|
+
var currentMatch;
|
|
269
|
+
var _matches = matches.map(function (item, index) {
|
|
270
|
+
if (index === currentIndex) {
|
|
271
|
+
currentMatch = item;
|
|
272
|
+
return {
|
|
273
|
+
range: item,
|
|
274
|
+
options: {
|
|
275
|
+
className: "currentFindMatch" // 当前高亮
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return {
|
|
281
|
+
range: item,
|
|
282
|
+
options: {
|
|
283
|
+
className: "findMatch" // 匹配高亮
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}).map(function (item) {
|
|
287
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
288
|
+
range: _this.toMonacoMatch(item.range).range
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
_this.oldDeltaDecorations = ((_this$monacoEditor28 = _this.monacoEditor) === null || _this$monacoEditor28 === void 0 ? void 0 : _this$monacoEditor28.deltaDecorations(_this.oldDeltaDecorations, _matches)) || [];
|
|
292
|
+
if (currentMatch) {
|
|
293
|
+
var start = _this.getPositionAt(currentMatch.position);
|
|
294
|
+
var end = _this.getPositionAt(currentMatch.position + currentMatch.text.length);
|
|
295
|
+
if (start && end) {
|
|
296
|
+
_this.revealSelection({
|
|
297
|
+
end: end,
|
|
298
|
+
start: start
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
this._isDisposed = false;
|
|
304
|
+
this.disposeResizeObserver = function () {
|
|
305
|
+
_this.resizeObserver.disconnect();
|
|
306
|
+
};
|
|
307
|
+
this.themeService = themeService;
|
|
308
|
+
this.languageSpecRegistry = languageSpecRegistry;
|
|
309
|
+
this.host = options.host;
|
|
310
|
+
this.host.classList.add('libro-e2-editor-container');
|
|
311
|
+
this._uuid = options.uuid || v4();
|
|
312
|
+
this._model = options.model;
|
|
313
|
+
var config = options.config || {};
|
|
314
|
+
var fullConfig = this._config = _objectSpread(_objectSpread(_objectSpread({}, libroE2DefaultConfig), config), {}, {
|
|
315
|
+
mimetype: options.model.mimeType
|
|
316
|
+
});
|
|
317
|
+
this.completionProvider = options.completionProvider;
|
|
318
|
+
this.tooltipProvider = options.tooltipProvider;
|
|
319
|
+
this.lspProvider = options.lspProvider;
|
|
320
|
+
this.editorHost = document.createElement('div');
|
|
321
|
+
this.host.append(this.editorHost);
|
|
322
|
+
this.createEditor(this.editorHost, fullConfig);
|
|
323
|
+
this.onMimeTypeChanged();
|
|
324
|
+
this.onCursorActivity();
|
|
325
|
+
this.toDispose.push(watch(this._model, 'mimeType', this.onMimeTypeChanged));
|
|
326
|
+
// this.toDispose.push(watch(this._model, 'source', this.onValueChange));
|
|
327
|
+
this.toDispose.push(watch(this._model, 'selections', this.onSelectionChange));
|
|
328
|
+
this.toDispose.push(this.themeService.onDidColorThemeChange(this.onThemeChange));
|
|
329
|
+
}
|
|
330
|
+
LibroE2Editor = inject(LanguageSpecRegistry)(LibroE2Editor, undefined, 2) || LibroE2Editor;
|
|
331
|
+
LibroE2Editor = inject(ThemeService)(LibroE2Editor, undefined, 1) || LibroE2Editor;
|
|
332
|
+
LibroE2Editor = inject(LibroE2EditorOptions)(LibroE2Editor, undefined, 0) || LibroE2Editor;
|
|
333
|
+
_createClass(LibroE2Editor, [{
|
|
334
|
+
key: "uuid",
|
|
335
|
+
get:
|
|
336
|
+
/**
|
|
337
|
+
* The uuid of this editor;
|
|
338
|
+
*/
|
|
339
|
+
function get() {
|
|
340
|
+
return this._uuid;
|
|
341
|
+
},
|
|
342
|
+
set: function set(value) {
|
|
343
|
+
this._uuid = value;
|
|
344
|
+
}
|
|
345
|
+
}, {
|
|
346
|
+
key: "model",
|
|
347
|
+
get:
|
|
348
|
+
/**
|
|
349
|
+
* Returns a model for this editor.
|
|
350
|
+
*/
|
|
351
|
+
function get() {
|
|
352
|
+
return this._model;
|
|
353
|
+
}
|
|
354
|
+
}, {
|
|
355
|
+
key: "editor",
|
|
356
|
+
get: function get() {
|
|
357
|
+
return this === null || this === void 0 ? void 0 : this._editor;
|
|
358
|
+
}
|
|
359
|
+
}, {
|
|
360
|
+
key: "monacoEditor",
|
|
361
|
+
get: function get() {
|
|
362
|
+
var _this$_editor;
|
|
363
|
+
return this === null || this === void 0 || (_this$_editor = this._editor) === null || _this$_editor === void 0 ? void 0 : _this$_editor.codeEditor;
|
|
364
|
+
}
|
|
365
|
+
}, {
|
|
366
|
+
key: "lineCount",
|
|
367
|
+
get: function get() {
|
|
368
|
+
var _this$monacoEditor29;
|
|
369
|
+
return ((_this$monacoEditor29 = this.monacoEditor) === null || _this$monacoEditor29 === void 0 || (_this$monacoEditor29 = _this$monacoEditor29.getModel()) === null || _this$monacoEditor29 === void 0 ? void 0 : _this$monacoEditor29.getLineCount()) || 0;
|
|
370
|
+
}
|
|
371
|
+
}, {
|
|
372
|
+
key: "languageSpec",
|
|
373
|
+
get: function get() {
|
|
374
|
+
var _this2 = this;
|
|
375
|
+
return this.languageSpecRegistry.languageSpecs.find(function (item) {
|
|
376
|
+
return item.mime === _this2.model.mimeType;
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}, {
|
|
380
|
+
key: "theme",
|
|
381
|
+
get: function get() {
|
|
382
|
+
var themetype = this.themeService.getActiveTheme().type;
|
|
383
|
+
return this._config.theme[themetype];
|
|
384
|
+
}
|
|
385
|
+
}, {
|
|
386
|
+
key: "toMonacoOptions",
|
|
387
|
+
value: function toMonacoOptions(editorConfig) {
|
|
388
|
+
var _editorConfig$lineHei, _editorConfig$fontSiz;
|
|
389
|
+
return {
|
|
390
|
+
minimap: {
|
|
391
|
+
enabled: false
|
|
392
|
+
},
|
|
393
|
+
lineHeight: (_editorConfig$lineHei = editorConfig.lineHeight) !== null && _editorConfig$lineHei !== void 0 ? _editorConfig$lineHei : this.defaultLineHeight,
|
|
394
|
+
fontSize: (_editorConfig$fontSiz = editorConfig.fontSize) !== null && _editorConfig$fontSiz !== void 0 ? _editorConfig$fontSiz : 13,
|
|
395
|
+
lineNumbers: editorConfig.lineNumbers ? 'on' : 'off',
|
|
396
|
+
folding: editorConfig.codeFolding,
|
|
397
|
+
wordWrap: editorConfig.lineWrap,
|
|
398
|
+
lineDecorationsWidth: 15,
|
|
399
|
+
lineNumbersMinChars: 3,
|
|
400
|
+
suggestSelection: 'first',
|
|
401
|
+
wordBasedSuggestions: false,
|
|
402
|
+
scrollBeyondLastLine: false,
|
|
403
|
+
/**
|
|
404
|
+
* 使用该选项可以让modal widget出现在正确的范围,而不是被遮挡,解决z-index问题,但是会导致hover组件之类的无法被选中
|
|
405
|
+
* 根据 https://github.com/microsoft/monaco-editor/issues/2156,0.34.x 版本修复了这个问题
|
|
406
|
+
* TODO: 当前0.31.1 无法开启此选项,升级 E2 3.x 可以解决(monaco 0.39)
|
|
407
|
+
*
|
|
408
|
+
* ```html
|
|
409
|
+
* <div id="monaco-editor-overflow-widgets-root" class="monaco-editor" style="z-index: 999;"></div>
|
|
410
|
+
* ```
|
|
411
|
+
*
|
|
412
|
+
*/
|
|
413
|
+
// overflowWidgetsDomNode: document.getElementById('monaco-editor-overflow-widgets-root')!,
|
|
414
|
+
// fixedOverflowWidgets: true,
|
|
415
|
+
suggest: {
|
|
416
|
+
snippetsPreventQuickSuggestions: false
|
|
417
|
+
},
|
|
418
|
+
autoClosingQuotes: editorConfig.autoClosingBrackets ? 'always' : 'never',
|
|
419
|
+
autoDetectHighContrast: false,
|
|
420
|
+
scrollbar: {
|
|
421
|
+
alwaysConsumeMouseWheel: false,
|
|
422
|
+
verticalScrollbarSize: 0
|
|
423
|
+
},
|
|
424
|
+
extraEditorClassName: E2EditorClassname,
|
|
425
|
+
renderLineHighlight: 'all',
|
|
426
|
+
renderLineHighlightOnlyWhenFocus: true,
|
|
427
|
+
readOnly: editorConfig.readOnly,
|
|
428
|
+
cursorWidth: 1,
|
|
429
|
+
tabSize: editorConfig.tabSize,
|
|
430
|
+
insertSpaces: editorConfig.insertSpaces,
|
|
431
|
+
matchBrackets: editorConfig.matchBrackets ? 'always' : 'never',
|
|
432
|
+
rulers: editorConfig.rulers,
|
|
433
|
+
wordWrapColumn: editorConfig.wordWrapColumn,
|
|
434
|
+
'semanticHighlighting.enabled': true
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
}, {
|
|
438
|
+
key: "createEditor",
|
|
439
|
+
value: function () {
|
|
440
|
+
var _createEditor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(host, config) {
|
|
441
|
+
var _this$languageSpec,
|
|
442
|
+
_this$languageSpec$be,
|
|
443
|
+
_this$monacoEditor$on,
|
|
444
|
+
_this$monacoEditor30,
|
|
445
|
+
_this3 = this,
|
|
446
|
+
_this$monacoEditor$on2,
|
|
447
|
+
_this$monacoEditor31,
|
|
448
|
+
_this$monacoEditor$on3,
|
|
449
|
+
_this$monacoEditor32,
|
|
450
|
+
_this$languageSpec2,
|
|
451
|
+
_this$languageSpec2$a;
|
|
452
|
+
var editorConfig, editorPorvider, uri, options, e2Editor;
|
|
453
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
454
|
+
while (1) switch (_context.prev = _context.next) {
|
|
455
|
+
case 0:
|
|
456
|
+
if (this.languageSpec) {
|
|
457
|
+
_context.next = 2;
|
|
458
|
+
break;
|
|
459
|
+
}
|
|
460
|
+
return _context.abrupt("return");
|
|
461
|
+
case 2:
|
|
462
|
+
editorConfig = _objectSpread(_objectSpread({}, config), this.languageSpec.editorConfig);
|
|
463
|
+
this._config = editorConfig;
|
|
464
|
+
// await this.languageSpec.loadModule()
|
|
465
|
+
_context.next = 6;
|
|
466
|
+
return MonacoEnvironment.init();
|
|
467
|
+
case 6:
|
|
468
|
+
_context.next = 8;
|
|
469
|
+
return (_this$languageSpec = this.languageSpec) === null || _this$languageSpec === void 0 || (_this$languageSpec$be = _this$languageSpec.beforeEditorInit) === null || _this$languageSpec$be === void 0 ? void 0 : _this$languageSpec$be.call(_this$languageSpec);
|
|
470
|
+
case 8:
|
|
471
|
+
editorPorvider = MonacoEnvironment.container.get(EditorProvider);
|
|
472
|
+
uri = MonacoUri.from({
|
|
473
|
+
scheme: LibroE2URIScheme,
|
|
474
|
+
path: "".concat(this.uuid).concat(this.languageSpec.ext[0])
|
|
475
|
+
});
|
|
476
|
+
options = _objectSpread(_objectSpread({}, this.toMonacoOptions(editorConfig)), {}, {
|
|
477
|
+
/**
|
|
478
|
+
* language ia an uri:
|
|
479
|
+
*/
|
|
480
|
+
language: this.languageSpec.language,
|
|
481
|
+
uri: uri,
|
|
482
|
+
theme: this.theme,
|
|
483
|
+
value: this.model.value
|
|
484
|
+
});
|
|
485
|
+
e2Editor = editorPorvider.create(host, options);
|
|
486
|
+
this._editor = e2Editor;
|
|
487
|
+
this.toDispose.push((_this$monacoEditor$on = (_this$monacoEditor30 = this.monacoEditor) === null || _this$monacoEditor30 === void 0 ? void 0 : _this$monacoEditor30.onDidChangeModelContent(function () {
|
|
488
|
+
var _this3$monacoEditor;
|
|
489
|
+
var value = (_this3$monacoEditor = _this3.monacoEditor) === null || _this3$monacoEditor === void 0 ? void 0 : _this3$monacoEditor.getValue();
|
|
490
|
+
_this3.model.value = value !== null && value !== void 0 ? value : '';
|
|
491
|
+
_this3.updateEditorSize();
|
|
492
|
+
})) !== null && _this$monacoEditor$on !== void 0 ? _this$monacoEditor$on : Disposable.NONE);
|
|
493
|
+
this.toDispose.push((_this$monacoEditor$on2 = (_this$monacoEditor31 = this.monacoEditor) === null || _this$monacoEditor31 === void 0 ? void 0 : _this$monacoEditor31.onDidContentSizeChange(function () {
|
|
494
|
+
_this3.updateEditorSize();
|
|
495
|
+
})) !== null && _this$monacoEditor$on2 !== void 0 ? _this$monacoEditor$on2 : Disposable.NONE);
|
|
496
|
+
this.toDispose.push((_this$monacoEditor$on3 = (_this$monacoEditor32 = this.monacoEditor) === null || _this$monacoEditor32 === void 0 ? void 0 : _this$monacoEditor32.onDidBlurEditorText(function () {
|
|
497
|
+
_this3.blur();
|
|
498
|
+
})) !== null && _this$monacoEditor$on3 !== void 0 ? _this$monacoEditor$on3 : Disposable.NONE);
|
|
499
|
+
this.updateEditorSize();
|
|
500
|
+
this.inspectResize();
|
|
501
|
+
this.handleCommand(this.commandRegistry);
|
|
502
|
+
_context.next = 21;
|
|
503
|
+
return (_this$languageSpec2 = this.languageSpec) === null || _this$languageSpec2 === void 0 || (_this$languageSpec2$a = _this$languageSpec2.afterEditorInit) === null || _this$languageSpec2$a === void 0 ? void 0 : _this$languageSpec2$a.call(_this$languageSpec2, this);
|
|
504
|
+
case 21:
|
|
505
|
+
this.placeholder = new PlaceholderContentWidget(config.placeholder, this.monacoEditor);
|
|
506
|
+
|
|
507
|
+
// console.log(
|
|
508
|
+
// 'editor._themeService.getColorTheme()',
|
|
509
|
+
// this.monacoEditor._themeService,
|
|
510
|
+
// this.monacoEditor._themeService.getColorTheme(),
|
|
511
|
+
// );
|
|
512
|
+
|
|
513
|
+
// setTimeout(() => {
|
|
514
|
+
// this.monacoEditor?.trigger('editor', 'editor.action.formatDocument');
|
|
515
|
+
// console.log('trigger format');
|
|
516
|
+
// }, 5000);
|
|
517
|
+
case 22:
|
|
518
|
+
case "end":
|
|
519
|
+
return _context.stop();
|
|
520
|
+
}
|
|
521
|
+
}, _callee, this);
|
|
522
|
+
}));
|
|
523
|
+
function createEditor(_x, _x2) {
|
|
524
|
+
return _createEditor.apply(this, arguments);
|
|
525
|
+
}
|
|
526
|
+
return createEditor;
|
|
527
|
+
}()
|
|
528
|
+
}, {
|
|
529
|
+
key: "inspectResize",
|
|
530
|
+
value: function inspectResize() {
|
|
531
|
+
var _this4 = this;
|
|
532
|
+
this.resizeObserver = new ResizeObserver(function (entries) {
|
|
533
|
+
entries.forEach(function (entry) {
|
|
534
|
+
var isVisible = entry.contentRect.width !== 0 && entry.contentRect.height !== 0;
|
|
535
|
+
if (isVisible) {
|
|
536
|
+
_this4.updateEditorSize();
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
});
|
|
540
|
+
this.resizeObserver.observe(this.host);
|
|
541
|
+
}
|
|
542
|
+
}, {
|
|
543
|
+
key: "getEditorNode",
|
|
544
|
+
value: function getEditorNode() {
|
|
545
|
+
return Array.from(this.host.getElementsByClassName(E2EditorClassname))[0];
|
|
546
|
+
}
|
|
547
|
+
}, {
|
|
548
|
+
key: "updateEditorSize",
|
|
549
|
+
value: function updateEditorSize() {
|
|
550
|
+
var _this$monacoEditor$ge, _this$monacoEditor33;
|
|
551
|
+
var contentHeight = (_this$monacoEditor$ge = (_this$monacoEditor33 = this.monacoEditor) === null || _this$monacoEditor33 === void 0 ? void 0 : _this$monacoEditor33.getContentHeight()) !== null && _this$monacoEditor$ge !== void 0 ? _this$monacoEditor$ge : 20;
|
|
552
|
+
this.host.style.height = "".concat(contentHeight + 30, "px");
|
|
553
|
+
try {
|
|
554
|
+
var _this$monacoEditor34;
|
|
555
|
+
this.isLayouting = true;
|
|
556
|
+
(_this$monacoEditor34 = this.monacoEditor) === null || _this$monacoEditor34 === void 0 || _this$monacoEditor34.layout({
|
|
557
|
+
width: this.host.offsetWidth,
|
|
558
|
+
height: contentHeight
|
|
559
|
+
});
|
|
560
|
+
} finally {
|
|
561
|
+
this.isLayouting = false;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* 解决e2与libro快捷键冲突
|
|
567
|
+
* @param commandRegistry
|
|
568
|
+
*/
|
|
569
|
+
}, {
|
|
570
|
+
key: "handleCommand",
|
|
571
|
+
value: function handleCommand(commandRegistry) {
|
|
572
|
+
var _this$monacoEditor35, _this$monacoEditor36, _this$monacoEditor37, _this$monacoEditor38, _this$monacoEditor39, _this$monacoEditor40;
|
|
573
|
+
// need monaco 0.34
|
|
574
|
+
// editor.addKeybindingRules([
|
|
575
|
+
// {
|
|
576
|
+
// // disable show command center
|
|
577
|
+
// keybinding: KeyCode.F1,
|
|
578
|
+
// command: null,
|
|
579
|
+
// },
|
|
580
|
+
// {
|
|
581
|
+
// // disable show error command
|
|
582
|
+
// keybinding: KeyCode.F8,
|
|
583
|
+
// command: null,
|
|
584
|
+
// },
|
|
585
|
+
// {
|
|
586
|
+
// // disable toggle debugger breakpoint
|
|
587
|
+
// keybinding: KeyCode.F9,
|
|
588
|
+
// command: null,
|
|
589
|
+
// },
|
|
590
|
+
(_this$monacoEditor35 = this.monacoEditor) === null || _this$monacoEditor35 === void 0 || _this$monacoEditor35.addCommand(9, function () {
|
|
591
|
+
commandRegistry.executeCommand(NotebookCommands['EnterCommandMode'].id);
|
|
592
|
+
}, '!editorHasSelection && !editorHasSelection && !editorHasMultipleSelections');
|
|
593
|
+
(_this$monacoEditor36 = this.monacoEditor) === null || _this$monacoEditor36 === void 0 || _this$monacoEditor36.addCommand(2048 | 3, function () {
|
|
594
|
+
commandRegistry.executeCommand(NotebookCommands['RunCell'].id);
|
|
595
|
+
}, '!findWidgetVisible && !referenceSearchVisible');
|
|
596
|
+
(_this$monacoEditor37 = this.monacoEditor) === null || _this$monacoEditor37 === void 0 || _this$monacoEditor37.addCommand(1024 | 3, function () {
|
|
597
|
+
commandRegistry.executeCommand(NotebookCommands['RunCellAndSelectNext'].id);
|
|
598
|
+
}, '!findInputFocussed');
|
|
599
|
+
(_this$monacoEditor38 = this.monacoEditor) === null || _this$monacoEditor38 === void 0 || _this$monacoEditor38.addCommand(512 | 3, function () {
|
|
600
|
+
commandRegistry.executeCommand(NotebookCommands['RunCellAndInsertBelow'].id);
|
|
601
|
+
}, '!findWidgetVisible');
|
|
602
|
+
(_this$monacoEditor39 = this.monacoEditor) === null || _this$monacoEditor39 === void 0 || _this$monacoEditor39.addCommand(2048 | 1024 | 83, function () {
|
|
603
|
+
commandRegistry.executeCommand(NotebookCommands['SplitCellAntCursor'].id);
|
|
604
|
+
}
|
|
605
|
+
// '!findWidgetVisible',
|
|
606
|
+
);
|
|
607
|
+
|
|
608
|
+
(_this$monacoEditor40 = this.monacoEditor) === null || _this$monacoEditor40 === void 0 || _this$monacoEditor40.addCommand(2048 | 36, function () {
|
|
609
|
+
commandRegistry.executeCommand('libro-search:toggle');
|
|
610
|
+
}
|
|
611
|
+
// '!findWidgetVisible',
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
}, {
|
|
615
|
+
key: "onValueChange",
|
|
616
|
+
value: function onValueChange() {
|
|
617
|
+
// this.editor?.codeEditor.setValue(this.model.value);
|
|
618
|
+
}
|
|
619
|
+
}, {
|
|
620
|
+
key: "onSelectionChange",
|
|
621
|
+
value: function onSelectionChange() {
|
|
622
|
+
this.setSelections(this.model.selections);
|
|
623
|
+
}
|
|
624
|
+
}, {
|
|
625
|
+
key: "onMimeTypeChanged",
|
|
626
|
+
value:
|
|
627
|
+
/**
|
|
628
|
+
* Handles a mime type change.
|
|
629
|
+
* 切换语言
|
|
630
|
+
* cell 切换没走这里
|
|
631
|
+
*/
|
|
632
|
+
function onMimeTypeChanged() {
|
|
633
|
+
var _this$monacoEditor41;
|
|
634
|
+
var model = (_this$monacoEditor41 = this.monacoEditor) === null || _this$monacoEditor41 === void 0 ? void 0 : _this$monacoEditor41.getModel();
|
|
635
|
+
if (this.languageSpec && model) {
|
|
636
|
+
editor.setModelLanguage(model, this.languageSpec.language);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Handles a cursor activity event.
|
|
642
|
+
*/
|
|
643
|
+
}, {
|
|
644
|
+
key: "onCursorActivity",
|
|
645
|
+
value: function onCursorActivity() {
|
|
646
|
+
// Only add selections if the editor has focus. This avoids unwanted
|
|
647
|
+
// triggering of cursor activity due to collaborator actions.
|
|
648
|
+
if (this.hasFocus()) {
|
|
649
|
+
// const selections = this.getSelections();
|
|
650
|
+
// this.model.selections = selections;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}, {
|
|
654
|
+
key: "getOption",
|
|
655
|
+
value: function getOption(option) {
|
|
656
|
+
return this._config[option];
|
|
657
|
+
}
|
|
658
|
+
}, {
|
|
659
|
+
key: "onModalChange",
|
|
660
|
+
get: function get() {
|
|
661
|
+
return this.modalChangeEmitter.event;
|
|
662
|
+
}
|
|
663
|
+
}, {
|
|
664
|
+
key: "toMonacoRange",
|
|
665
|
+
value: function toMonacoRange(range) {
|
|
666
|
+
var selection = range !== null && range !== void 0 ? range : this.getSelection();
|
|
667
|
+
var monacoSelection = {
|
|
668
|
+
startLineNumber: selection.start.line || 1,
|
|
669
|
+
startColumn: selection.start.column || 1,
|
|
670
|
+
endLineNumber: selection.end.line || 1,
|
|
671
|
+
endColumn: selection.end.column || 1
|
|
672
|
+
};
|
|
673
|
+
return monacoSelection;
|
|
674
|
+
}
|
|
675
|
+
}, {
|
|
676
|
+
key: "toMonacoMatch",
|
|
677
|
+
value: function toMonacoMatch(match) {
|
|
678
|
+
var _start$line, _start$column, _end$line, _end$column;
|
|
679
|
+
var start = this.getPositionAt(match.position);
|
|
680
|
+
var end = this.getPositionAt(match.position + match.text.length);
|
|
681
|
+
return {
|
|
682
|
+
range: new MonacoRange((_start$line = start === null || start === void 0 ? void 0 : start.line) !== null && _start$line !== void 0 ? _start$line : 1, (_start$column = start === null || start === void 0 ? void 0 : start.column) !== null && _start$column !== void 0 ? _start$column : 1, (_end$line = end === null || end === void 0 ? void 0 : end.line) !== null && _end$line !== void 0 ? _end$line : 1, (_end$column = end === null || end === void 0 ? void 0 : end.column) !== null && _end$column !== void 0 ? _end$column : 1),
|
|
683
|
+
matches: [match.text],
|
|
684
|
+
_findMatchBrand: undefined
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
}, {
|
|
688
|
+
key: "disposed",
|
|
689
|
+
get:
|
|
690
|
+
/**
|
|
691
|
+
* Tests whether the editor is disposed.
|
|
692
|
+
*/
|
|
693
|
+
function get() {
|
|
694
|
+
return this._isDisposed;
|
|
695
|
+
}
|
|
696
|
+
}, {
|
|
697
|
+
key: "dispose",
|
|
698
|
+
value: function dispose() {
|
|
699
|
+
if (this.disposed) {
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
this.placeholder.dispose();
|
|
703
|
+
this.toDispose.dispose();
|
|
704
|
+
this.disposeResizeObserver();
|
|
705
|
+
this.lspContribution.beforeDestory();
|
|
706
|
+
this._isDisposed = true;
|
|
707
|
+
}
|
|
708
|
+
}]);
|
|
709
|
+
return LibroE2Editor;
|
|
710
|
+
}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "commandRegistry", [_dec2], {
|
|
711
|
+
configurable: true,
|
|
712
|
+
enumerable: true,
|
|
713
|
+
writable: true,
|
|
714
|
+
initializer: null
|
|
715
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "lspContribution", [_dec3], {
|
|
716
|
+
configurable: true,
|
|
717
|
+
enumerable: true,
|
|
718
|
+
writable: true,
|
|
719
|
+
initializer: null
|
|
720
|
+
})), _class2)) || _class);
|