@difizen/libro-code-editor 0.0.0-snapshot-20241017072317

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +0 -0
  3. package/es/code-editor-info-manager.d.ts +8 -0
  4. package/es/code-editor-info-manager.d.ts.map +1 -0
  5. package/es/code-editor-info-manager.js +32 -0
  6. package/es/code-editor-manager.d.ts +60 -0
  7. package/es/code-editor-manager.d.ts.map +1 -0
  8. package/es/code-editor-manager.js +126 -0
  9. package/es/code-editor-model.d.ts +80 -0
  10. package/es/code-editor-model.d.ts.map +1 -0
  11. package/es/code-editor-model.js +108 -0
  12. package/es/code-editor-protocol.d.ts +475 -0
  13. package/es/code-editor-protocol.d.ts.map +1 -0
  14. package/es/code-editor-protocol.js +113 -0
  15. package/es/code-editor-settings.d.ts +34 -0
  16. package/es/code-editor-settings.d.ts.map +1 -0
  17. package/es/code-editor-settings.js +225 -0
  18. package/es/code-editor-state-manager.d.ts +14 -0
  19. package/es/code-editor-state-manager.d.ts.map +1 -0
  20. package/es/code-editor-state-manager.js +82 -0
  21. package/es/code-editor-view.d.ts +123 -0
  22. package/es/code-editor-view.d.ts.map +1 -0
  23. package/es/code-editor-view.js +420 -0
  24. package/es/index.d.ts +9 -0
  25. package/es/index.d.ts.map +1 -0
  26. package/es/index.js +8 -0
  27. package/es/language-specs.d.ts +38 -0
  28. package/es/language-specs.d.ts.map +1 -0
  29. package/es/language-specs.js +58 -0
  30. package/es/mimetype.d.ts +33 -0
  31. package/es/mimetype.d.ts.map +1 -0
  32. package/es/mimetype.js +11 -0
  33. package/es/module.d.ts +3 -0
  34. package/es/module.d.ts.map +1 -0
  35. package/es/module.js +10 -0
  36. package/package.json +60 -0
  37. package/src/code-editor-info-manager.ts +25 -0
  38. package/src/code-editor-manager.ts +71 -0
  39. package/src/code-editor-model.ts +120 -0
  40. package/src/code-editor-protocol.ts +681 -0
  41. package/src/code-editor-settings.ts +214 -0
  42. package/src/code-editor-state-manager.ts +54 -0
  43. package/src/code-editor-view.tsx +434 -0
  44. package/src/index.spec.ts +10 -0
  45. package/src/index.ts +8 -0
  46. package/src/language-specs.ts +69 -0
  47. package/src/mimetype.ts +37 -0
  48. package/src/module.ts +22 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Difizen Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
File without changes
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" resolution-mode="require"/>
2
+ export declare class CodeEditorInfoManager {
3
+ editorHostRefMap: Map<string, React.RefObject<HTMLDivElement>>;
4
+ constructor();
5
+ setEditorHostRef(id: string, ref: React.RefObject<HTMLDivElement>): void;
6
+ getEditorHostRef(id: string): import("react").RefObject<HTMLDivElement> | undefined;
7
+ }
8
+ //# sourceMappingURL=code-editor-info-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-editor-info-manager.d.ts","sourceRoot":"","sources":["../src/code-editor-info-manager.ts"],"names":[],"mappings":";AAEA,qBACa,qBAAqB;IAChC,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC;;IAM/D,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC;IAQjE,gBAAgB,CAAC,EAAE,EAAE,MAAM;CAM5B"}
@@ -0,0 +1,32 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _dec, _class;
3
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
5
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
+ import { singleton } from '@difizen/mana-app';
9
+ export var CodeEditorInfoManager = (_dec = singleton(), _dec(_class = /*#__PURE__*/function () {
10
+ function CodeEditorInfoManager() {
11
+ _classCallCheck(this, CodeEditorInfoManager);
12
+ this.editorHostRefMap = new Map();
13
+ }
14
+ _createClass(CodeEditorInfoManager, [{
15
+ key: "setEditorHostRef",
16
+ value: function setEditorHostRef(id, ref) {
17
+ if (!this.editorHostRefMap) {
18
+ this.editorHostRefMap = new Map();
19
+ }
20
+ this.editorHostRefMap.set(id, ref);
21
+ }
22
+ }, {
23
+ key: "getEditorHostRef",
24
+ value: function getEditorHostRef(id) {
25
+ if (!this.editorHostRefMap) {
26
+ return undefined;
27
+ }
28
+ return this.editorHostRefMap.get(id);
29
+ }
30
+ }]);
31
+ return CodeEditorInfoManager;
32
+ }()) || _class);
@@ -0,0 +1,60 @@
1
+ /// <reference types="react" resolution-mode="require"/>
2
+ import type { Contribution } from '@difizen/mana-app';
3
+ import { ViewManager } from '@difizen/mana-app';
4
+ import { CodeEditorInfoManager } from './code-editor-info-manager.js';
5
+ import type { IModel } from './code-editor-model.js';
6
+ import { CodeEditorContribution } from './code-editor-protocol.js';
7
+ import type { EditorState } from './code-editor-protocol.js';
8
+ import { CodeEditorSettings } from './code-editor-settings.js';
9
+ import type { CodeEditorViewOptions } from './code-editor-view.js';
10
+ import { CodeEditorView } from './code-editor-view.js';
11
+ export declare class CodeEditorManager {
12
+ protected readonly codeEditorProvider: Contribution.Provider<CodeEditorContribution>;
13
+ protected readonly viewManager: ViewManager;
14
+ protected codeEditorInfoManager: CodeEditorInfoManager;
15
+ protected readonly codeEditorSettings: CodeEditorSettings;
16
+ protected stateCache: Map<string, EditorState>;
17
+ setEditorHostRef(id: string, ref: React.RefObject<HTMLDivElement>): void;
18
+ protected findCodeEditorProvider(model: IModel): CodeEditorContribution<any>;
19
+ /**
20
+ * 获取默认配置
21
+ * @param model
22
+ * @returns
23
+ */
24
+ getEditorDefaultConfig(model: IModel): import("./code-editor-protocol.js").IEditorConfig;
25
+ /**
26
+ * 用户配置+默认配置(还有一部分配置在cell中指定)
27
+ * @param model
28
+ * @returns
29
+ */
30
+ getUserEditorConfig(model: IModel): {
31
+ theme: import("./code-editor-protocol.js").EditorTheme;
32
+ cursorBlinkRate: number;
33
+ fontFamily: string | null;
34
+ fontSize: number | null;
35
+ lineHeight: number | null;
36
+ lineNumbers: boolean;
37
+ lineWrap: "wordWrapColumn" | "off" | "on" | "bounded";
38
+ readOnly: boolean;
39
+ editable: boolean;
40
+ tabSize: number;
41
+ insertSpaces: boolean;
42
+ matchBrackets: boolean;
43
+ autoClosingBrackets: boolean;
44
+ handlePaste?: boolean | undefined;
45
+ wordWrapColumn: number;
46
+ rulers: number[];
47
+ codeFolding: boolean;
48
+ showTrailingSpace: boolean;
49
+ foldGutter?: boolean | undefined;
50
+ styleActiveLine?: boolean | undefined;
51
+ highlightActiveLineGutter?: boolean | undefined;
52
+ placeholder?: string | HTMLElement | undefined;
53
+ lspEnabled: boolean;
54
+ paddingTop: number;
55
+ paddingBottom: number;
56
+ scrollBarHeight: number;
57
+ };
58
+ getOrCreateEditorView(option: CodeEditorViewOptions): Promise<CodeEditorView>;
59
+ }
60
+ //# sourceMappingURL=code-editor-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-editor-manager.d.ts","sourceRoot":"","sources":["../src/code-editor-manager.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAY,WAAW,EAA8B,MAAM,mBAAmB,CAAC;AAEtF,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,qBACa,iBAAiB;IAE5B,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,YAAY,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC;IAChE,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,SAAS,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;IAC1D,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;IACtF,SAAS,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAa;IAE3D,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC;IAIjE,SAAS,CAAC,sBAAsB,CAAC,KAAK,EAAE,MAAM;IAS9C;;;;OAIG;IACH,sBAAsB,CAAC,KAAK,EAAE,MAAM;IAIpC;;;;OAIG;IACH,mBAAmB,CAAC,KAAK,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAO3B,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC;CAgBpF"}
@@ -0,0 +1,126 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4;
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 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; }
7
+ 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; }
8
+ 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; }
9
+ function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
10
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
12
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
14
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
15
+ function _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; }
16
+ 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.'); }
17
+ import { Priority, ViewManager, contrib, inject, singleton } from '@difizen/mana-app';
18
+ import { CodeEditorInfoManager } from "./code-editor-info-manager.js";
19
+ import { CodeEditorContribution } from "./code-editor-protocol.js";
20
+ import { CodeEditorSettings } from "./code-editor-settings.js";
21
+ import { CodeEditorView } from "./code-editor-view.js";
22
+ export var CodeEditorManager = (_dec = singleton(), _dec2 = contrib(CodeEditorContribution), _dec3 = inject(ViewManager), _dec4 = inject(CodeEditorInfoManager), _dec5 = inject(CodeEditorSettings), _dec(_class = (_class2 = /*#__PURE__*/function () {
23
+ function CodeEditorManager() {
24
+ _classCallCheck(this, CodeEditorManager);
25
+ _initializerDefineProperty(this, "codeEditorProvider", _descriptor, this);
26
+ _initializerDefineProperty(this, "viewManager", _descriptor2, this);
27
+ _initializerDefineProperty(this, "codeEditorInfoManager", _descriptor3, this);
28
+ _initializerDefineProperty(this, "codeEditorSettings", _descriptor4, this);
29
+ this.stateCache = new Map();
30
+ }
31
+ _createClass(CodeEditorManager, [{
32
+ key: "setEditorHostRef",
33
+ value: function setEditorHostRef(id, ref) {
34
+ this.codeEditorInfoManager.setEditorHostRef(id, ref);
35
+ }
36
+ }, {
37
+ key: "findCodeEditorProvider",
38
+ value: function findCodeEditorProvider(model) {
39
+ var prioritized = Priority.sortSync(this.codeEditorProvider.getContributions(), function (contribution) {
40
+ return contribution.canHandle(model.mimeType);
41
+ });
42
+ var sorted = prioritized.map(function (c) {
43
+ return c.value;
44
+ });
45
+ return sorted[0];
46
+ }
47
+
48
+ /**
49
+ * 获取默认配置
50
+ * @param model
51
+ * @returns
52
+ */
53
+ }, {
54
+ key: "getEditorDefaultConfig",
55
+ value: function getEditorDefaultConfig(model) {
56
+ var _this$findCodeEditorP;
57
+ return (_this$findCodeEditorP = this.findCodeEditorProvider(model)) === null || _this$findCodeEditorP === void 0 ? void 0 : _this$findCodeEditorP.defaultConfig;
58
+ }
59
+
60
+ /**
61
+ * 用户配置+默认配置(还有一部分配置在cell中指定)
62
+ * @param model
63
+ * @returns
64
+ */
65
+ }, {
66
+ key: "getUserEditorConfig",
67
+ value: function getUserEditorConfig(model) {
68
+ return _objectSpread(_objectSpread({}, this.getEditorDefaultConfig(model)), this.codeEditorSettings.getUserEditorSettings());
69
+ }
70
+ }, {
71
+ key: "getOrCreateEditorView",
72
+ value: function () {
73
+ var _getOrCreateEditorView = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(option) {
74
+ var _this$findCodeEditorP2;
75
+ var factory, editorView;
76
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
77
+ while (1) switch (_context.prev = _context.next) {
78
+ case 0:
79
+ factory = (_this$findCodeEditorP2 = this.findCodeEditorProvider(option.model)) === null || _this$findCodeEditorP2 === void 0 ? void 0 : _this$findCodeEditorP2.factory;
80
+ if (factory) {
81
+ _context.next = 3;
82
+ break;
83
+ }
84
+ throw new Error("no code editor factory registered for mimetype: ".concat(option.model.mimeType));
85
+ case 3:
86
+ _context.next = 5;
87
+ return this.viewManager.getOrCreateView(CodeEditorView, _objectSpread({
88
+ factory: factory
89
+ }, option));
90
+ case 5:
91
+ editorView = _context.sent;
92
+ return _context.abrupt("return", editorView);
93
+ case 7:
94
+ case "end":
95
+ return _context.stop();
96
+ }
97
+ }, _callee, this);
98
+ }));
99
+ function getOrCreateEditorView(_x) {
100
+ return _getOrCreateEditorView.apply(this, arguments);
101
+ }
102
+ return getOrCreateEditorView;
103
+ }()
104
+ }]);
105
+ return CodeEditorManager;
106
+ }(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "codeEditorProvider", [_dec2], {
107
+ configurable: true,
108
+ enumerable: true,
109
+ writable: true,
110
+ initializer: null
111
+ }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "viewManager", [_dec3], {
112
+ configurable: true,
113
+ enumerable: true,
114
+ writable: true,
115
+ initializer: null
116
+ }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "codeEditorInfoManager", [_dec4], {
117
+ configurable: true,
118
+ enumerable: true,
119
+ writable: true,
120
+ initializer: null
121
+ }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "codeEditorSettings", [_dec5], {
122
+ configurable: true,
123
+ enumerable: true,
124
+ writable: true,
125
+ initializer: null
126
+ })), _class2)) || _class);
@@ -0,0 +1,80 @@
1
+ import type { CellType } from '@difizen/libro-common';
2
+ import type { Disposable, Event } from '@difizen/mana-app';
3
+ import { Emitter } from '@difizen/mana-app';
4
+ import type { ITextSelection } from './code-editor-protocol.js';
5
+ export interface IModelOptions {
6
+ /**
7
+ * A unique identifier for the model.
8
+ */
9
+ id?: string;
10
+ /**
11
+ * The initial value of the model.
12
+ */
13
+ value?: string;
14
+ /**
15
+ * The mimetype of the model.
16
+ */
17
+ mimeType?: string;
18
+ }
19
+ /**
20
+ * An editor model.
21
+ */
22
+ export interface IModel extends Disposable {
23
+ /**
24
+ * The text stored in the model.
25
+ */
26
+ value: string;
27
+ /**
28
+ * A mime type of the model.
29
+ *
30
+ * #### Notes
31
+ * It is never `null`, the default mime type is `text/plain`.
32
+ */
33
+ mimeType: string;
34
+ /**
35
+ * The currently selected code.
36
+ */
37
+ selections: ITextSelection[];
38
+ }
39
+ /**
40
+ * The default implementation of the editor model.
41
+ */
42
+ export declare class Model implements IModel {
43
+ id: string;
44
+ /**
45
+ * The text stored in the model.
46
+ */
47
+ value: string;
48
+ /**
49
+ * A mime type of the model.
50
+ *
51
+ * #### Notes
52
+ * It is never `null`, the default mime type is `text/plain`.
53
+ */
54
+ mimeType: string;
55
+ type: CellType;
56
+ /**
57
+ * The currently selected code.
58
+ */
59
+ selections: ITextSelection[];
60
+ /**
61
+ * Construct a new Model.
62
+ */
63
+ constructor(options?: IModelOptions);
64
+ /**
65
+ * A signal emitted when the shared model was switched.
66
+ */
67
+ get sharedModelSwitched(): Event<boolean>;
68
+ /**
69
+ * Whether the model is disposed.
70
+ */
71
+ get isDisposed(): boolean;
72
+ /**
73
+ * Dispose of the resources used by the model.
74
+ */
75
+ dispose(): void;
76
+ protected _isDisposed: boolean;
77
+ protected _sharedModelSwitchedEmitter: Emitter<boolean>;
78
+ protected _sharedModelSwitched: Event<boolean>;
79
+ }
80
+ //# sourceMappingURL=code-editor-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-editor-model.d.ts","sourceRoot":"","sources":["../src/code-editor-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAmB,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,MAAO,SAAQ,UAAU;IACxC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;OAKG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,UAAU,EAAE,cAAc,EAAE,CAAC;CAC9B;AAED;;GAEG;AACH,qBACa,KAAM,YAAW,MAAM;IAClC,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IAEH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;OAKG;IAEH,QAAQ,EAAE,MAAM,CAAC;IAGjB,IAAI,EAAE,QAAQ,CAAU;IAExB;;OAEG;IAEH,UAAU,EAAE,cAAc,EAAE,CAAC;IAE7B;;OAEG;gBACS,OAAO,CAAC,EAAE,aAAa;IAUnC;;OAEG;IACH,IAAI,mBAAmB,IAAI,KAAK,CAAC,OAAO,CAAC,CAExC;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,OAAO,CAExB;IAED;;OAEG;IACH,OAAO,IAAI,IAAI;IAOf,SAAS,CAAC,WAAW,UAAS;IAE9B,SAAS,CAAC,2BAA2B,mBAA0B;IAC/D,SAAS,CAAC,oBAAoB,iBAA0C;CACzE"}
@@ -0,0 +1,108 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4;
3
+ 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
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ 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); } }
6
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
8
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
9
+ 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; }
10
+ 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.'); }
11
+ import { prop, transient, Emitter } from '@difizen/mana-app';
12
+ import { v4 } from 'uuid';
13
+
14
+ /**
15
+ * An editor model.
16
+ */
17
+
18
+ /**
19
+ * The default implementation of the editor model.
20
+ */
21
+ export var Model = (_dec = transient(), _dec2 = prop(), _dec3 = prop(), _dec4 = prop(), _dec5 = prop(), _dec(_class = (_class2 = /*#__PURE__*/function () {
22
+ /**
23
+ * Construct a new Model.
24
+ */
25
+ function Model(options) {
26
+ var _options$id, _options$value, _options$mimeType;
27
+ _classCallCheck(this, Model);
28
+ /**
29
+ * The text stored in the model.
30
+ */
31
+ _initializerDefineProperty(this, "value", _descriptor, this);
32
+ /**
33
+ * A mime type of the model.
34
+ *
35
+ * #### Notes
36
+ * It is never `null`, the default mime type is `text/plain`.
37
+ */
38
+ _initializerDefineProperty(this, "mimeType", _descriptor2, this);
39
+ _initializerDefineProperty(this, "type", _descriptor3, this);
40
+ /**
41
+ * The currently selected code.
42
+ */
43
+ _initializerDefineProperty(this, "selections", _descriptor4, this);
44
+ this._isDisposed = false;
45
+ this._sharedModelSwitchedEmitter = new Emitter();
46
+ this._sharedModelSwitched = this._sharedModelSwitchedEmitter.event;
47
+ // this.sharedModel = models.createStandaloneCell(this.type, options.id) as models.ISharedText;
48
+ // this.sharedModel.changed.connect(this._onSharedModelChanged, this);
49
+ this.id = (_options$id = options === null || options === void 0 ? void 0 : options.id) !== null && _options$id !== void 0 ? _options$id : v4();
50
+ this.value = (_options$value = options === null || options === void 0 ? void 0 : options.value) !== null && _options$value !== void 0 ? _options$value : '';
51
+ this.mimeType = (_options$mimeType = options === null || options === void 0 ? void 0 : options.mimeType) !== null && _options$mimeType !== void 0 ? _options$mimeType : 'text/plain';
52
+ this.selections = [];
53
+ }
54
+
55
+ /**
56
+ * A signal emitted when the shared model was switched.
57
+ */
58
+ _createClass(Model, [{
59
+ key: "sharedModelSwitched",
60
+ get: function get() {
61
+ return this._sharedModelSwitched;
62
+ }
63
+
64
+ /**
65
+ * Whether the model is disposed.
66
+ */
67
+ }, {
68
+ key: "isDisposed",
69
+ get: function get() {
70
+ return this._isDisposed;
71
+ }
72
+
73
+ /**
74
+ * Dispose of the resources used by the model.
75
+ */
76
+ }, {
77
+ key: "dispose",
78
+ value: function dispose() {
79
+ if (this._isDisposed) {
80
+ return;
81
+ }
82
+ this._isDisposed = true;
83
+ }
84
+ }]);
85
+ return Model;
86
+ }(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "value", [_dec2], {
87
+ configurable: true,
88
+ enumerable: true,
89
+ writable: true,
90
+ initializer: null
91
+ }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "mimeType", [_dec3], {
92
+ configurable: true,
93
+ enumerable: true,
94
+ writable: true,
95
+ initializer: null
96
+ }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "type", [_dec4], {
97
+ configurable: true,
98
+ enumerable: true,
99
+ writable: true,
100
+ initializer: function initializer() {
101
+ return 'code';
102
+ }
103
+ }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "selections", [_dec5], {
104
+ configurable: true,
105
+ enumerable: true,
106
+ writable: true,
107
+ initializer: null
108
+ })), _class2)) || _class);