@difizen/libro-code-editor 0.1.0 → 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/es/code-editor-info-manager.d.ts +7 -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 +67 -0
- package/es/code-editor-manager.d.ts.map +1 -0
- package/es/code-editor-manager.js +130 -0
- package/es/{model.d.ts → code-editor-model.d.ts} +2 -2
- package/es/code-editor-model.d.ts.map +1 -0
- package/es/{model.js → code-editor-model.js} +1 -3
- package/es/{code-editor.d.ts → code-editor-protocol.d.ts} +70 -145
- package/es/code-editor-protocol.d.ts.map +1 -0
- package/es/{code-editor.js → code-editor-protocol.js} +17 -15
- 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-view.d.ts +26 -14
- package/es/code-editor-view.d.ts.map +1 -1
- package/es/code-editor-view.js +108 -72
- package/es/index.d.ts +5 -3
- package/es/index.d.ts.map +1 -1
- package/es/index.js +6 -4
- package/es/mimetype.d.ts.map +1 -1
- package/es/mimetype.js +3 -0
- package/es/module.d.ts.map +1 -1
- package/es/module.js +5 -2
- package/package.json +4 -5
- package/src/code-editor-info-manager.ts +25 -0
- package/src/code-editor-manager.ts +86 -0
- package/src/{model.ts → code-editor-model.ts} +4 -4
- package/src/{code-editor.ts → code-editor-protocol.ts} +136 -189
- package/src/code-editor-settings.ts +214 -0
- package/src/code-editor-view.tsx +93 -49
- package/src/index.spec.ts +1 -3
- package/src/index.ts +5 -3
- package/src/mimetype.ts +3 -0
- package/src/module.ts +13 -2
- package/es/code-editor.d.ts.map +0 -1
- package/es/completer/completer-protocol.d.ts +0 -210
- package/es/completer/completer-protocol.d.ts.map +0 -1
- package/es/completer/completer-protocol.js +0 -34
- package/es/model.d.ts.map +0 -1
- package/src/completer/completer-protocol.ts +0 -259
package/es/code-editor-view.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
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, _class, _class2, _descriptor;
|
|
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); }); }; }
|
|
3
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 }); }
|
|
4
10
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
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); } }
|
|
@@ -17,13 +23,16 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
17
23
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
18
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; }
|
|
19
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
|
+
// Copyright (c) Jupyter Development Team.
|
|
27
|
+
// Distributed under the terms of the Modified BSD License.
|
|
28
|
+
|
|
20
29
|
import { getOrigin, prop } from '@difizen/mana-app';
|
|
21
|
-
import { BaseView, view, ViewOption } from '@difizen/mana-app';
|
|
22
|
-
import { inject, transient } from '@difizen/mana-app';
|
|
23
|
-
import { Deferred, Emitter } from '@difizen/mana-app';
|
|
30
|
+
import { inject, transient, Deferred, Emitter, BaseView, ThemeService, view, ViewOption } from '@difizen/mana-app';
|
|
24
31
|
import { forwardRef, memo } from 'react';
|
|
32
|
+
import { CodeEditorInfoManager } from "./code-editor-info-manager.js";
|
|
33
|
+
import { CodeEditorSettings } from "./code-editor-settings.js";
|
|
25
34
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
26
|
-
export var CodeEditorRender = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (
|
|
35
|
+
export var CodeEditorRender = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (props, ref) {
|
|
27
36
|
return /*#__PURE__*/_jsx("div", {
|
|
28
37
|
ref: ref
|
|
29
38
|
});
|
|
@@ -53,35 +62,53 @@ var leadingWhitespaceRe = /^\s+$/;
|
|
|
53
62
|
/**
|
|
54
63
|
* A widget which hosts a code editor.
|
|
55
64
|
*/
|
|
56
|
-
export var CodeEditorView = (_dec = transient(), _dec2 = view('code-editor-view'), _dec3 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_BaseView) {
|
|
65
|
+
export var CodeEditorView = (_dec = transient(), _dec2 = view('code-editor-view'), _dec3 = inject(ThemeService), _dec4 = inject(CodeEditorSettings), _dec5 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_BaseView) {
|
|
57
66
|
_inherits(CodeEditorView, _BaseView);
|
|
58
67
|
var _super = _createSuper(CodeEditorView);
|
|
59
68
|
/**
|
|
60
69
|
* Construct a new code editor widget.
|
|
61
70
|
*/
|
|
62
|
-
function CodeEditorView(options) {
|
|
71
|
+
function CodeEditorView(options, codeEditorInfoManager) {
|
|
63
72
|
var _this;
|
|
64
73
|
_classCallCheck(this, CodeEditorView);
|
|
65
74
|
_this = _super.call(this);
|
|
75
|
+
_initializerDefineProperty(_this, "themeService", _descriptor, _assertThisInitialized(_this));
|
|
76
|
+
_initializerDefineProperty(_this, "codeEditorSettings", _descriptor2, _assertThisInitialized(_this));
|
|
66
77
|
_this.view = CodeEditorRender;
|
|
67
78
|
_this.classlist = [];
|
|
68
79
|
_this.modalChangeEmitter = new Emitter();
|
|
69
80
|
/**
|
|
70
81
|
* Get the editor wrapped by the widget.
|
|
71
82
|
*/
|
|
72
|
-
_initializerDefineProperty(_this, "editor",
|
|
83
|
+
_initializerDefineProperty(_this, "editor", _descriptor3, _assertThisInitialized(_this));
|
|
73
84
|
_this.editorReadyDeferred = new Deferred();
|
|
85
|
+
_this.removeChildNodes = function (parent) {
|
|
86
|
+
while (parent.firstChild) {
|
|
87
|
+
parent.removeChild(parent.firstChild);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
_this.onViewUnmount = function () {
|
|
91
|
+
var _this$editorHostRef;
|
|
92
|
+
if (_this.editor.dispose) {
|
|
93
|
+
_this.editor.dispose();
|
|
94
|
+
}
|
|
95
|
+
var node = (_this$editorHostRef = _this.editorHostRef) === null || _this$editorHostRef === void 0 ? void 0 : _this$editorHostRef.current;
|
|
96
|
+
if (node) {
|
|
97
|
+
node.removeEventListener('focus', _this.onViewActive);
|
|
98
|
+
node.removeEventListener('dragenter', _this._evtDragEnter);
|
|
99
|
+
node.removeEventListener('dragleave', _this._evtDragLeave);
|
|
100
|
+
node.removeEventListener('dragover', _this._evtDragOver);
|
|
101
|
+
node.removeEventListener('drop', _this._evtDrop);
|
|
102
|
+
_this.removeChildNodes(node);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
74
105
|
_this.onViewActive = function () {
|
|
75
|
-
|
|
76
|
-
(_this$editor = _this.editor) === null || _this$editor === void 0 || _this$editor.focus();
|
|
106
|
+
_this.editor.focus();
|
|
77
107
|
};
|
|
78
108
|
/**
|
|
79
109
|
* Handle the `'lm-dragenter'` event for the widget.
|
|
80
110
|
*/
|
|
81
111
|
_this._evtDragEnter = function (event) {
|
|
82
|
-
if (!_this.editor) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
112
|
if (_this.editor.getOption('readOnly') === true) {
|
|
86
113
|
return;
|
|
87
114
|
}
|
|
@@ -97,9 +124,6 @@ export var CodeEditorView = (_dec = transient(), _dec2 = view('code-editor-view'
|
|
|
97
124
|
* Handle the `'lm-dragleave'` event for the widget.
|
|
98
125
|
*/
|
|
99
126
|
_this._evtDragLeave = function (event) {
|
|
100
|
-
if (!_this.editor) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
127
|
_this.removeClass(DROP_TARGET_CLASS);
|
|
104
128
|
if (_this.editor.getOption('readOnly') === true) {
|
|
105
129
|
return;
|
|
@@ -115,9 +139,6 @@ export var CodeEditorView = (_dec = transient(), _dec2 = view('code-editor-view'
|
|
|
115
139
|
* Handle the `'lm-dragover'` event for the widget.
|
|
116
140
|
*/
|
|
117
141
|
_this._evtDragOver = function (event) {
|
|
118
|
-
if (!_this.editor) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
142
|
_this.removeClass(DROP_TARGET_CLASS);
|
|
122
143
|
if (_this.editor.getOption('readOnly') === true) {
|
|
123
144
|
return;
|
|
@@ -135,9 +156,6 @@ export var CodeEditorView = (_dec = transient(), _dec2 = view('code-editor-view'
|
|
|
135
156
|
* Handle the `'lm-drop'` event for the widget.
|
|
136
157
|
*/
|
|
137
158
|
_this._evtDrop = function (event) {
|
|
138
|
-
if (!_this.editor) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
159
|
if (_this.editor.getOption('readOnly') === true) {
|
|
142
160
|
return;
|
|
143
161
|
}
|
|
@@ -170,8 +188,10 @@ export var CodeEditorView = (_dec = transient(), _dec2 = view('code-editor-view'
|
|
|
170
188
|
// this.model.value.insert(offset, data);
|
|
171
189
|
};
|
|
172
190
|
_this.options = options;
|
|
191
|
+
_this.codeEditorInfoManager = codeEditorInfoManager;
|
|
173
192
|
return _this;
|
|
174
193
|
}
|
|
194
|
+
CodeEditorView = inject(CodeEditorInfoManager)(CodeEditorView, undefined, 1) || CodeEditorView;
|
|
175
195
|
CodeEditorView = inject(ViewOption)(CodeEditorView, undefined, 0) || CodeEditorView;
|
|
176
196
|
_createClass(CodeEditorView, [{
|
|
177
197
|
key: "onModalChange",
|
|
@@ -185,49 +205,61 @@ export var CodeEditorView = (_dec = transient(), _dec2 = view('code-editor-view'
|
|
|
185
205
|
}
|
|
186
206
|
}, {
|
|
187
207
|
key: "onViewMount",
|
|
188
|
-
value: function
|
|
189
|
-
var
|
|
190
|
-
_this2 = this;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
+
value: function () {
|
|
209
|
+
var _onViewMount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
210
|
+
var _this2 = this;
|
|
211
|
+
var settings, editorHostId, editorHostRef;
|
|
212
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
213
|
+
while (1) switch (_context.prev = _context.next) {
|
|
214
|
+
case 0:
|
|
215
|
+
settings = this.codeEditorSettings.getUserEditorSettings();
|
|
216
|
+
editorHostId = this.options.editorHostId;
|
|
217
|
+
editorHostRef = editorHostId ? this.codeEditorInfoManager.getEditorHostRef(editorHostId) : undefined;
|
|
218
|
+
this.editorHostRef = editorHostRef && editorHostRef.current ? editorHostRef : this.container;
|
|
219
|
+
if (this.editorHostRef.current && this.options.factory) {
|
|
220
|
+
this.editor = this.options.factory(_objectSpread(_objectSpread({}, this.options), {}, {
|
|
221
|
+
host: this.editorHostRef.current,
|
|
222
|
+
model: this.options.model,
|
|
223
|
+
uuid: this.options.uuid,
|
|
224
|
+
config: _objectSpread(_objectSpread({}, settings), this.options.config),
|
|
225
|
+
selectionStyle: this.options.selectionStyle,
|
|
226
|
+
tooltipProvider: this.options.tooltipProvider,
|
|
227
|
+
completionProvider: this.options.completionProvider
|
|
228
|
+
}));
|
|
229
|
+
this.editorReadyDeferred.resolve();
|
|
230
|
+
this.editor.onModalChange(function (val) {
|
|
231
|
+
return _this2.modalChangeEmitter.fire(val);
|
|
232
|
+
});
|
|
233
|
+
// this.editor.model.selections.changed(this._onSelectionsChanged);
|
|
208
234
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
235
|
+
if (this.options.autoFocus) {
|
|
236
|
+
getOrigin(this.editor).focus();
|
|
237
|
+
}
|
|
238
|
+
this.editorHostRef.current.addEventListener('focus', this.onViewActive);
|
|
239
|
+
this.editorHostRef.current.addEventListener('dragenter', this._evtDragEnter);
|
|
240
|
+
this.editorHostRef.current.addEventListener('dragleave', this._evtDragLeave);
|
|
241
|
+
this.editorHostRef.current.addEventListener('dragover', this._evtDragOver);
|
|
242
|
+
this.editorHostRef.current.addEventListener('drop', this._evtDrop);
|
|
243
|
+
this.toDispose.push(this.codeEditorSettings.onCodeEditorSettingsChange(function (e) {
|
|
244
|
+
_this2.editor.setOption(e.key, e.value);
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
247
|
+
case 5:
|
|
248
|
+
case "end":
|
|
249
|
+
return _context.stop();
|
|
250
|
+
}
|
|
251
|
+
}, _callee, this);
|
|
252
|
+
}));
|
|
253
|
+
function onViewMount() {
|
|
254
|
+
return _onViewMount.apply(this, arguments);
|
|
217
255
|
}
|
|
218
|
-
|
|
256
|
+
return onViewMount;
|
|
257
|
+
}()
|
|
219
258
|
}, {
|
|
220
|
-
key: "
|
|
221
|
-
value: function
|
|
222
|
-
var _this$
|
|
223
|
-
|
|
224
|
-
if (node) {
|
|
225
|
-
node.removeEventListener('focus', this.onViewActive);
|
|
226
|
-
node.removeEventListener('dragenter', this._evtDragEnter);
|
|
227
|
-
node.removeEventListener('dragleave', this._evtDragLeave);
|
|
228
|
-
node.removeEventListener('dragover', this._evtDragOver);
|
|
229
|
-
node.removeEventListener('drop', this._evtDrop);
|
|
230
|
-
}
|
|
259
|
+
key: "onViewResize",
|
|
260
|
+
value: function onViewResize() {
|
|
261
|
+
var _this$editor;
|
|
262
|
+
(_this$editor = this.editor) === null || _this$editor === void 0 || _this$editor.resizeToFit();
|
|
231
263
|
}
|
|
232
264
|
|
|
233
265
|
/**
|
|
@@ -236,8 +268,7 @@ export var CodeEditorView = (_dec = transient(), _dec2 = view('code-editor-view'
|
|
|
236
268
|
}, {
|
|
237
269
|
key: "model",
|
|
238
270
|
get: function get() {
|
|
239
|
-
|
|
240
|
-
return (_this$editor2 = this.editor) === null || _this$editor2 === void 0 ? void 0 : _this$editor2.model;
|
|
271
|
+
return this.editor.model;
|
|
241
272
|
}
|
|
242
273
|
|
|
243
274
|
/**
|
|
@@ -246,12 +277,11 @@ export var CodeEditorView = (_dec = transient(), _dec2 = view('code-editor-view'
|
|
|
246
277
|
}, {
|
|
247
278
|
key: "dispose",
|
|
248
279
|
value: function dispose() {
|
|
249
|
-
var _this$editor3;
|
|
250
280
|
if (this.isDisposed) {
|
|
251
281
|
return;
|
|
252
282
|
}
|
|
253
283
|
_get(_getPrototypeOf(CodeEditorView.prototype), "dispose", this).call(this);
|
|
254
|
-
|
|
284
|
+
this.editor.dispose();
|
|
255
285
|
}
|
|
256
286
|
}, {
|
|
257
287
|
key: "onResize",
|
|
@@ -261,8 +291,7 @@ export var CodeEditorView = (_dec = transient(), _dec2 = view('code-editor-view'
|
|
|
261
291
|
*/
|
|
262
292
|
function onResize() {
|
|
263
293
|
if (this.isVisible) {
|
|
264
|
-
|
|
265
|
-
(_this$editor4 = this.editor) === null || _this$editor4 === void 0 || _this$editor4.resizeToFit();
|
|
294
|
+
this.editor.resizeToFit();
|
|
266
295
|
}
|
|
267
296
|
}
|
|
268
297
|
}, {
|
|
@@ -285,9 +314,6 @@ export var CodeEditorView = (_dec = transient(), _dec2 = view('code-editor-view'
|
|
|
285
314
|
}, {
|
|
286
315
|
key: "_onSelectionsChanged",
|
|
287
316
|
value: function _onSelectionsChanged() {
|
|
288
|
-
if (!this.editor) {
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
317
|
var _this$editor$getSelec = this.editor.getSelection(),
|
|
292
318
|
start = _this$editor$getSelec.start,
|
|
293
319
|
end = _this$editor$getSelec.end;
|
|
@@ -307,7 +333,17 @@ export var CodeEditorView = (_dec = transient(), _dec2 = view('code-editor-view'
|
|
|
307
333
|
}
|
|
308
334
|
}]);
|
|
309
335
|
return CodeEditorView;
|
|
310
|
-
}(BaseView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "
|
|
336
|
+
}(BaseView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "themeService", [_dec3], {
|
|
337
|
+
configurable: true,
|
|
338
|
+
enumerable: true,
|
|
339
|
+
writable: true,
|
|
340
|
+
initializer: null
|
|
341
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "codeEditorSettings", [_dec4], {
|
|
342
|
+
configurable: true,
|
|
343
|
+
enumerable: true,
|
|
344
|
+
writable: true,
|
|
345
|
+
initializer: null
|
|
346
|
+
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "editor", [_dec5], {
|
|
311
347
|
configurable: true,
|
|
312
348
|
enumerable: true,
|
|
313
349
|
writable: true,
|
package/es/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export * from './code-editor.js';
|
|
2
|
-
export * from './
|
|
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';
|
|
3
5
|
export * from './code-editor-view.js';
|
|
6
|
+
export * from './mimetype.js';
|
|
4
7
|
export * from './module.js';
|
|
5
|
-
export * from './model.js';
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
package/es/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
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"}
|
package/es/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export * from "./code-editor.js";
|
|
2
|
-
export * from "./
|
|
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";
|
|
3
5
|
export * from "./code-editor-view.js";
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
+
export * from "./mimetype.js";
|
|
7
|
+
export * from "./module.js";
|
package/es/mimetype.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mimetype.d.ts","sourceRoot":"","sources":["../src/mimetype.ts"],"names":[],"mappings":"
|
|
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
CHANGED
package/es/module.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAQ/C,eAAO,MAAM,gBAAgB,YAQU,CAAC"}
|
package/es/module.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { ManaModule } from '@difizen/mana-app';
|
|
2
|
+
import { CodeEditorInfoManager } from "./code-editor-info-manager.js";
|
|
3
|
+
import { CodeEditorContribution, CodeEditorManager } from "./code-editor-manager.js";
|
|
4
|
+
import { Model } from "./code-editor-model.js";
|
|
5
|
+
import { CodeEditorSettings } from "./code-editor-settings.js";
|
|
2
6
|
import { CodeEditorView } from "./code-editor-view.js";
|
|
3
|
-
|
|
4
|
-
export var CodeEditorModule = ManaModule.create().register(CodeEditorView, Model);
|
|
7
|
+
export var CodeEditorModule = ManaModule.create().register(CodeEditorInfoManager, CodeEditorView, CodeEditorManager, Model, CodeEditorSettings).contribution(CodeEditorContribution);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@difizen/libro-code-editor",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"libro",
|
|
@@ -33,10 +33,9 @@
|
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@difizen/mana-app": "latest",
|
|
36
|
-
"@difizen/
|
|
37
|
-
"@difizen/libro-
|
|
38
|
-
"uuid": "^9.0.0"
|
|
39
|
-
"vscode-languageserver-protocol": "^3.17.0"
|
|
36
|
+
"@difizen/mana-l10n": "latest",
|
|
37
|
+
"@difizen/libro-common": "^0.1.2",
|
|
38
|
+
"uuid": "^9.0.0"
|
|
40
39
|
},
|
|
41
40
|
"peerDependencies": {
|
|
42
41
|
"react": "^18.2.0"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { singleton } from '@difizen/mana-app';
|
|
2
|
+
|
|
3
|
+
@singleton()
|
|
4
|
+
export class CodeEditorInfoManager {
|
|
5
|
+
editorHostRefMap: Map<string, any>;
|
|
6
|
+
|
|
7
|
+
constructor() {
|
|
8
|
+
this.editorHostRefMap = new Map();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
setEditorHostRef(id: string, ref: any) {
|
|
12
|
+
if (!this.editorHostRefMap) {
|
|
13
|
+
this.editorHostRefMap = new Map();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
this.editorHostRefMap.set(id, ref);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getEditorHostRef(id: string) {
|
|
20
|
+
if (!this.editorHostRefMap) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return this.editorHostRefMap.get(id);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Contribution } from '@difizen/mana-app';
|
|
2
|
+
import {
|
|
3
|
+
Priority,
|
|
4
|
+
ViewManager,
|
|
5
|
+
contrib,
|
|
6
|
+
inject,
|
|
7
|
+
singleton,
|
|
8
|
+
Syringe,
|
|
9
|
+
} from '@difizen/mana-app';
|
|
10
|
+
|
|
11
|
+
import { CodeEditorInfoManager } from './code-editor-info-manager.js';
|
|
12
|
+
import type { IModel } from './code-editor-model.js';
|
|
13
|
+
import type { IEditor, IEditorConfig, IEditorOptions } from './code-editor-protocol.js';
|
|
14
|
+
import { CodeEditorSettings } from './code-editor-settings.js';
|
|
15
|
+
import type { CodeEditorViewOptions } from './code-editor-view.js';
|
|
16
|
+
import { CodeEditorView } from './code-editor-view.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A factory used to create a code editor.
|
|
20
|
+
*/
|
|
21
|
+
export type CodeEditorFactory = (options: IEditorOptions) => IEditor;
|
|
22
|
+
|
|
23
|
+
export const CodeEditorContribution = Syringe.defineToken('CodeEditorContribution');
|
|
24
|
+
export interface CodeEditorContribution {
|
|
25
|
+
canHandle(mime: string): number;
|
|
26
|
+
factory: CodeEditorFactory;
|
|
27
|
+
defaultConfig: IEditorConfig;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@singleton()
|
|
31
|
+
export class CodeEditorManager {
|
|
32
|
+
@contrib(CodeEditorContribution)
|
|
33
|
+
protected readonly codeEditorProvider: Contribution.Provider<CodeEditorContribution>;
|
|
34
|
+
@inject(ViewManager) protected readonly viewManager: ViewManager;
|
|
35
|
+
@inject(CodeEditorInfoManager) protected codeEditorInfoManager: CodeEditorInfoManager;
|
|
36
|
+
@inject(CodeEditorSettings) protected readonly codeEditorSettings: CodeEditorSettings;
|
|
37
|
+
|
|
38
|
+
setEditorHostRef(id: string, ref: any) {
|
|
39
|
+
this.codeEditorInfoManager.setEditorHostRef(id, ref);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
protected findCodeEditorProvider(model: IModel) {
|
|
43
|
+
const prioritized = Priority.sortSync(
|
|
44
|
+
this.codeEditorProvider.getContributions(),
|
|
45
|
+
(contribution) => contribution.canHandle(model.mimeType),
|
|
46
|
+
);
|
|
47
|
+
const sorted = prioritized.map((c) => c.value);
|
|
48
|
+
return sorted[0];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 获取默认配置
|
|
53
|
+
* @param model
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
getEditorDefaultConfig(model: IModel) {
|
|
57
|
+
return this.findCodeEditorProvider(model)?.defaultConfig;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 用户配置+默认配置(还有一部分配置在cell中指定)
|
|
62
|
+
* @param model
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
getUserEditorConfig(model: IModel) {
|
|
66
|
+
return {
|
|
67
|
+
...this.getEditorDefaultConfig(model),
|
|
68
|
+
...this.codeEditorSettings.getUserEditorSettings(),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async getOrCreateEditorView(option: CodeEditorViewOptions): Promise<CodeEditorView> {
|
|
73
|
+
const factory = this.findCodeEditorProvider(option.model)?.factory;
|
|
74
|
+
if (!factory) {
|
|
75
|
+
throw new Error(`no code editor found for mimetype: ${option.model.mimeType}`);
|
|
76
|
+
}
|
|
77
|
+
const editorView = await this.viewManager.getOrCreateView<
|
|
78
|
+
CodeEditorView,
|
|
79
|
+
CodeEditorViewOptions
|
|
80
|
+
>(CodeEditorView, {
|
|
81
|
+
factory,
|
|
82
|
+
...option,
|
|
83
|
+
});
|
|
84
|
+
return editorView;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { CellType } from '@difizen/libro-common';
|
|
2
2
|
import type { Disposable, Event } from '@difizen/mana-app';
|
|
3
|
-
import { prop } from '@difizen/mana-app';
|
|
4
|
-
import { Emitter } from '@difizen/mana-app';
|
|
5
|
-
import { transient } from '@difizen/mana-app';
|
|
3
|
+
import { prop, transient, Emitter } from '@difizen/mana-app';
|
|
6
4
|
import { v4 } from 'uuid';
|
|
7
5
|
|
|
8
|
-
import type { ITextSelection } from './code-editor.js';
|
|
6
|
+
import type { ITextSelection } from './code-editor-protocol.js';
|
|
9
7
|
|
|
10
8
|
export interface IModelOptions {
|
|
11
9
|
/**
|
|
@@ -53,6 +51,7 @@ export interface IModel extends Disposable {
|
|
|
53
51
|
@transient()
|
|
54
52
|
export class Model implements IModel {
|
|
55
53
|
id: string;
|
|
54
|
+
|
|
56
55
|
/**
|
|
57
56
|
* The text stored in the model.
|
|
58
57
|
*/
|
|
@@ -84,6 +83,7 @@ export class Model implements IModel {
|
|
|
84
83
|
// this.sharedModel = models.createStandaloneCell(this.type, options.id) as models.ISharedText;
|
|
85
84
|
// this.sharedModel.changed.connect(this._onSharedModelChanged, this);
|
|
86
85
|
this.id = options?.id ?? v4();
|
|
86
|
+
|
|
87
87
|
this.value = options?.value ?? '';
|
|
88
88
|
this.mimeType = options?.mimeType ?? 'text/plain';
|
|
89
89
|
this.selections = [];
|