@difizen/libro-cofine-editor-core 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/default-worker-contribution.d.ts +9 -0
- package/es/default-worker-contribution.d.ts.map +1 -0
- package/es/default-worker-contribution.js +32 -0
- package/es/e2-editor.d.ts +30 -0
- package/es/e2-editor.d.ts.map +1 -0
- package/es/e2-editor.js +131 -0
- package/es/editor-handler-registry.d.ts +12 -0
- package/es/editor-handler-registry.d.ts.map +1 -0
- package/es/editor-handler-registry.js +59 -0
- package/es/editor-provider.d.ts +15 -0
- package/es/editor-provider.d.ts.map +1 -0
- package/es/editor-provider.js +1 -0
- package/es/editor.worker.d.ts +2 -0
- package/es/editor.worker.d.ts.map +1 -0
- package/es/editor.worker.js +23 -0
- package/es/global.d.ts +7 -0
- package/es/index.d.ts +18 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +23 -0
- package/es/initialize-provider.d.ts +18 -0
- package/es/initialize-provider.d.ts.map +1 -0
- package/es/initialize-provider.js +120 -0
- package/es/mana-export.d.ts +4 -0
- package/es/mana-export.d.ts.map +1 -0
- package/es/mana-export.js +23 -0
- package/es/monaco-compability.esm.d.ts +4 -0
- package/es/monaco-compability.esm.d.ts.map +1 -0
- package/es/monaco-compability.esm.js +10 -0
- package/es/monaco-environment.d.ts +29 -0
- package/es/monaco-environment.d.ts.map +1 -0
- package/es/monaco-environment.js +276 -0
- package/es/monaco-loader.d.ts +22 -0
- package/es/monaco-loader.d.ts.map +1 -0
- package/es/monaco-loader.js +139 -0
- package/es/monaco-module.d.ts +5 -0
- package/es/monaco-module.d.ts.map +1 -0
- package/es/monaco-module.js +71 -0
- package/es/snippets-suggest-registry.d.ts +31 -0
- package/es/snippets-suggest-registry.d.ts.map +1 -0
- package/es/snippets-suggest-registry.js +110 -0
- package/es/theme-registry.d.ts +58 -0
- package/es/theme-registry.d.ts.map +1 -0
- package/es/theme-registry.js +91 -0
- package/package.json +64 -0
- package/src/default-worker-contribution.ts +25 -0
- package/src/e2-editor.ts +161 -0
- package/src/editor-handler-registry.ts +47 -0
- package/src/editor-provider.ts +29 -0
- package/src/editor.worker.ts +25 -0
- package/src/global.d.ts +7 -0
- package/src/index.spec.ts +8 -0
- package/src/index.ts +46 -0
- package/src/initialize-provider.ts +54 -0
- package/src/mana-export.ts +8 -0
- package/src/monaco-compability.esm.ts +4 -0
- package/src/monaco-environment.ts +115 -0
- package/src/monaco-loader.ts +100 -0
- package/src/monaco-module.ts +101 -0
- package/src/snippets-suggest-registry.ts +101 -0
- package/src/theme-registry.ts +116 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { EditorHandlerContribution, EditorOptionsRegistry, LanguageOptionsRegistry, LanguageWorkerContribution, LanguageWorkerRegistry, LazyLoaderRegistry, LazyLoaderRegistryContribution } from '@difizen/libro-cofine-editor-contribution';
|
|
2
|
+
import { Contribution, Module, Syringe } from '@difizen/mana-app';
|
|
3
|
+
import 'reflect-metadata';
|
|
4
|
+
import { DefaultWorkerContribution } from "./default-worker-contribution.js";
|
|
5
|
+
import { E2Editor, EditorNode, IsDiff, LazyCallback, MonacoOptions } from "./e2-editor.js";
|
|
6
|
+
import { EditorHanlerRegistry } from "./editor-handler-registry.js";
|
|
7
|
+
import { EditorProvider } from "./editor-provider.js";
|
|
8
|
+
import { InitializeContribution, InitializeContributionProvider, InitializeProvider } from "./initialize-provider.js";
|
|
9
|
+
import { SnippetSuggestContribution, SnippetSuggestRegistry } from "./snippets-suggest-registry.js";
|
|
10
|
+
import { MixedThemeRegistry, ThemeContribution, ThemeRegistry } from "./theme-registry.js";
|
|
11
|
+
export var MonacoModule = Module().register({
|
|
12
|
+
token: {
|
|
13
|
+
token: Contribution.Provider,
|
|
14
|
+
named: InitializeContribution
|
|
15
|
+
},
|
|
16
|
+
useDynamic: function useDynamic(ctx) {
|
|
17
|
+
return new InitializeContributionProvider(InitializeContribution, ctx.container);
|
|
18
|
+
},
|
|
19
|
+
lifecycle: Syringe.Lifecycle.singleton
|
|
20
|
+
}, InitializeProvider, LanguageWorkerRegistry, LanguageOptionsRegistry, EditorOptionsRegistry, DefaultWorkerContribution, SnippetSuggestRegistry, LazyLoaderRegistry, {
|
|
21
|
+
token: MixedThemeRegistry,
|
|
22
|
+
useValue: {}
|
|
23
|
+
}, ThemeRegistry, {
|
|
24
|
+
token: EditorProvider,
|
|
25
|
+
lifecycle: Syringe.Lifecycle.singleton,
|
|
26
|
+
useDynamic: function useDynamic(ctx) {
|
|
27
|
+
return {
|
|
28
|
+
create: function create(node, options, lazyCallback) {
|
|
29
|
+
var child = ctx.container.createChild();
|
|
30
|
+
child.register(EditorNode, {
|
|
31
|
+
useValue: node
|
|
32
|
+
});
|
|
33
|
+
child.register(MonacoOptions, {
|
|
34
|
+
useValue: options
|
|
35
|
+
});
|
|
36
|
+
child.register(LazyCallback, {
|
|
37
|
+
useValue: lazyCallback
|
|
38
|
+
});
|
|
39
|
+
child.register({
|
|
40
|
+
token: IsDiff,
|
|
41
|
+
useValue: false
|
|
42
|
+
});
|
|
43
|
+
child.register(EditorHanlerRegistry);
|
|
44
|
+
child.register(E2Editor);
|
|
45
|
+
return child.get(E2Editor);
|
|
46
|
+
},
|
|
47
|
+
createDiff: function createDiff(node, options, lazyCallback) {
|
|
48
|
+
var child = ctx.container.createChild();
|
|
49
|
+
child.register(EditorNode, {
|
|
50
|
+
useValue: node
|
|
51
|
+
});
|
|
52
|
+
child.register(MonacoOptions, {
|
|
53
|
+
useValue: options
|
|
54
|
+
});
|
|
55
|
+
child.register(LazyCallback, {
|
|
56
|
+
useValue: lazyCallback
|
|
57
|
+
});
|
|
58
|
+
child.register({
|
|
59
|
+
token: IsDiff,
|
|
60
|
+
useValue: true
|
|
61
|
+
});
|
|
62
|
+
child.register(EditorHanlerRegistry);
|
|
63
|
+
child.register(E2Editor);
|
|
64
|
+
return child.get(E2Editor);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
// 语言 worker 扩展点
|
|
70
|
+
.contribution(LanguageWorkerContribution, EditorHandlerContribution, ThemeContribution, SnippetSuggestContribution, LazyLoaderRegistryContribution);
|
|
71
|
+
export default MonacoModule;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Contribution } from '@difizen/mana-app';
|
|
2
|
+
import { Syringe } from '@difizen/mana-app';
|
|
3
|
+
import * as monaco from '@difizen/monaco-editor-core';
|
|
4
|
+
import { InitializeContribution } from './initialize-provider.js';
|
|
5
|
+
export interface SnippetLoadOptions {
|
|
6
|
+
language?: string | string[];
|
|
7
|
+
source: string;
|
|
8
|
+
}
|
|
9
|
+
export type JsonSerializedSnippets = Record<string, JsonSerializedSnippet>;
|
|
10
|
+
export interface JsonSerializedSnippet {
|
|
11
|
+
body: string[];
|
|
12
|
+
scope: string;
|
|
13
|
+
prefix: string;
|
|
14
|
+
description: string;
|
|
15
|
+
}
|
|
16
|
+
export interface SnippetSuggestContribution {
|
|
17
|
+
registerSnippetSuggest: (registry: SnippetSuggestRegistry) => void;
|
|
18
|
+
_initRegisterSnippetSuggest?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare const SnippetSuggestContribution: Syringe.DefinedToken;
|
|
21
|
+
export declare class SnippetSuggestRegistry implements InitializeContribution {
|
|
22
|
+
registerCompletion: boolean;
|
|
23
|
+
awaysInitialized: boolean;
|
|
24
|
+
onInitialize(): void;
|
|
25
|
+
protected languageSnippets: Record<string, JsonSerializedSnippet[]>;
|
|
26
|
+
snippetsSuggestContrbutions: Contribution.Provider<SnippetSuggestContribution>;
|
|
27
|
+
constructor(snippetsSuggestContrbutions: Contribution.Provider<SnippetSuggestContribution>);
|
|
28
|
+
provideCompletionItems(model: monaco.editor.ITextModel): Promise<monaco.languages.CompletionList | undefined>;
|
|
29
|
+
fromJSON(snippets: JsonSerializedSnippets | undefined, { language }: SnippetLoadOptions): void;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=snippets-suggest-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snippets-suggest-registry.d.ts","sourceRoot":"","sources":["../../src/snippets-suggest-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAsB,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,MAAM,MAAM,6BAA6B,CAAC;AAEtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;AAC3E,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,0BAA0B;IACzC,sBAAsB,EAAE,CAAC,QAAQ,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACnE,2BAA2B,CAAC,EAAE,OAAO,CAAC;CACvC;AAED,eAAO,MAAM,0BAA0B,sBAEtC,CAAC;AAEF,qBACa,sBAAuB,YAAW,sBAAsB;IACnE,kBAAkB,UAAS;IAC3B,gBAAgB,UAAQ;IACxB,YAAY;IAWZ,SAAS,CAAC,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,EAAE,CAAC,CAAM;IAEzE,2BAA2B,EAAE,YAAY,CAAC,QAAQ,CAAC,0BAA0B,CAAC,CAAC;gBAG7E,2BAA2B,EAAE,YAAY,CAAC,QAAQ,CAAC,0BAA0B,CAAC;IAK1E,sBAAsB,CAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,GAC9B,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,GAAG,SAAS,CAAC;IAiBvD,QAAQ,CACN,QAAQ,EAAE,sBAAsB,GAAG,SAAS,EAC5C,EAAE,QAAQ,EAAE,EAAE,kBAAkB;CA0BnC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
7
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
8
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
9
|
+
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; }
|
|
10
|
+
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); } }
|
|
11
|
+
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); }); }; }
|
|
12
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
+
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); } }
|
|
14
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
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 { contrib, singleton, Syringe } from '@difizen/mana-app';
|
|
18
|
+
import * as monaco from '@difizen/monaco-editor-core';
|
|
19
|
+
import { InitializeContribution } from "./initialize-provider.js";
|
|
20
|
+
export var SnippetSuggestContribution = Syringe.defineToken('SnippetSuggestContribution');
|
|
21
|
+
export var SnippetSuggestRegistry = (_dec = singleton({
|
|
22
|
+
contrib: InitializeContribution
|
|
23
|
+
}), _dec(_class = /*#__PURE__*/function () {
|
|
24
|
+
function SnippetSuggestRegistry(snippetsSuggestContrbutions) {
|
|
25
|
+
_classCallCheck(this, SnippetSuggestRegistry);
|
|
26
|
+
this.registerCompletion = false;
|
|
27
|
+
this.awaysInitialized = true;
|
|
28
|
+
this.languageSnippets = {};
|
|
29
|
+
this.snippetsSuggestContrbutions = snippetsSuggestContrbutions;
|
|
30
|
+
}
|
|
31
|
+
SnippetSuggestRegistry = contrib(SnippetSuggestContribution)(SnippetSuggestRegistry, undefined, 0) || SnippetSuggestRegistry;
|
|
32
|
+
_createClass(SnippetSuggestRegistry, [{
|
|
33
|
+
key: "onInitialize",
|
|
34
|
+
value: function onInitialize() {
|
|
35
|
+
var _this = this;
|
|
36
|
+
this.snippetsSuggestContrbutions.getContributions({
|
|
37
|
+
cache: false
|
|
38
|
+
}).forEach(function (contribution) {
|
|
39
|
+
if (contribution._initRegisterSnippetSuggest) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
contribution.registerSnippetSuggest(_this);
|
|
43
|
+
contribution._initRegisterSnippetSuggest = true;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}, {
|
|
47
|
+
key: "provideCompletionItems",
|
|
48
|
+
value: function () {
|
|
49
|
+
var _provideCompletionItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(model) {
|
|
50
|
+
var _language, _snippets, suggestions;
|
|
51
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
52
|
+
while (1) switch (_context.prev = _context.next) {
|
|
53
|
+
case 0:
|
|
54
|
+
_language = model.getLanguageId();
|
|
55
|
+
_snippets = this.languageSnippets[_language] || [];
|
|
56
|
+
suggestions = _snippets.map(function (it) {
|
|
57
|
+
return {
|
|
58
|
+
label: it.prefix,
|
|
59
|
+
insertText: it.body.join('\n'),
|
|
60
|
+
documentation: it.description,
|
|
61
|
+
detail: 'snippet',
|
|
62
|
+
insertTextRules: 4,
|
|
63
|
+
kind: 27,
|
|
64
|
+
range: undefined
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
return _context.abrupt("return", {
|
|
68
|
+
suggestions: suggestions
|
|
69
|
+
});
|
|
70
|
+
case 4:
|
|
71
|
+
case "end":
|
|
72
|
+
return _context.stop();
|
|
73
|
+
}
|
|
74
|
+
}, _callee, this);
|
|
75
|
+
}));
|
|
76
|
+
function provideCompletionItems(_x) {
|
|
77
|
+
return _provideCompletionItems.apply(this, arguments);
|
|
78
|
+
}
|
|
79
|
+
return provideCompletionItems;
|
|
80
|
+
}()
|
|
81
|
+
}, {
|
|
82
|
+
key: "fromJSON",
|
|
83
|
+
value: function fromJSON(snippets, _ref) {
|
|
84
|
+
var _this2 = this;
|
|
85
|
+
var language = _ref.language;
|
|
86
|
+
if (!language || !(language !== null && language !== void 0 && language.length) || !snippets) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
var _languages = typeof language === 'string' ? [language] : language;
|
|
90
|
+
_languages.forEach(function (it) {
|
|
91
|
+
var _this2$languageSnippe;
|
|
92
|
+
if (!_this2.languageSnippets[it]) {
|
|
93
|
+
_this2.languageSnippets[it] = [];
|
|
94
|
+
}
|
|
95
|
+
(_this2$languageSnippe = _this2.languageSnippets[it]).push.apply(_this2$languageSnippe, _toConsumableArray(Object.values(snippets)));
|
|
96
|
+
});
|
|
97
|
+
// 采集数据
|
|
98
|
+
if (this.registerCompletion) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this.registerCompletion = true;
|
|
102
|
+
monaco.languages.registerCompletionItemProvider({
|
|
103
|
+
pattern: '**'
|
|
104
|
+
}, {
|
|
105
|
+
provideCompletionItems: this.provideCompletionItems.bind(this)
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}]);
|
|
109
|
+
return SnippetSuggestRegistry;
|
|
110
|
+
}()) || _class);
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Contribution } from '@difizen/mana-app';
|
|
2
|
+
import { Syringe } from '@difizen/mana-app';
|
|
3
|
+
import * as monaco from '@difizen/monaco-editor-core';
|
|
4
|
+
import { InitializeContribution } from './initialize-provider.js';
|
|
5
|
+
export declare const ThemeContribution: Syringe.DefinedToken;
|
|
6
|
+
export interface ITextmateThemeSetting {
|
|
7
|
+
colors: Record<string, string>;
|
|
8
|
+
tokenColors: IRawThemeSetting[];
|
|
9
|
+
include?: string;
|
|
10
|
+
name: string;
|
|
11
|
+
givenName?: string;
|
|
12
|
+
base?: monaco.editor.BuiltinTheme;
|
|
13
|
+
givenBase?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ThemeContribution {
|
|
16
|
+
registerItem: (registry: ThemeRegistry) => void;
|
|
17
|
+
_registerFinish?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A single theme setting.
|
|
21
|
+
*/
|
|
22
|
+
export interface IRawThemeSetting {
|
|
23
|
+
readonly name?: string;
|
|
24
|
+
readonly scope?: string | string[];
|
|
25
|
+
readonly settings: {
|
|
26
|
+
readonly fontStyle?: string;
|
|
27
|
+
readonly foreground?: string;
|
|
28
|
+
readonly background?: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A TextMate theme.
|
|
33
|
+
*/
|
|
34
|
+
export interface IRawTheme {
|
|
35
|
+
readonly name?: string;
|
|
36
|
+
readonly settings: IRawThemeSetting[];
|
|
37
|
+
}
|
|
38
|
+
export interface MixedTheme extends IRawTheme, monaco.editor.IStandaloneThemeData {
|
|
39
|
+
}
|
|
40
|
+
export interface MixedThemeRegistry {
|
|
41
|
+
registerThemes: (themeOptions: Record<string, ITextmateThemeSetting>, setTheme: (name: string, data: monaco.editor.IStandaloneThemeData) => void) => void;
|
|
42
|
+
}
|
|
43
|
+
export declare const MixedThemeRegistry: unique symbol;
|
|
44
|
+
export declare class ThemeRegistry implements InitializeContribution {
|
|
45
|
+
contributions: ThemeContribution[];
|
|
46
|
+
themeOptions: Record<string, ITextmateThemeSetting>;
|
|
47
|
+
themes: Map<string, MixedTheme | monaco.editor.IStandaloneThemeData>;
|
|
48
|
+
awaysInitialized: boolean;
|
|
49
|
+
onInitialize(): void;
|
|
50
|
+
protected readonly provider: Contribution.Provider<ThemeContribution>;
|
|
51
|
+
protected readonly mixedThemeRegistry: MixedThemeRegistry;
|
|
52
|
+
constructor(provider: Contribution.Provider<ThemeContribution>, mixedThemeRegistry: MixedThemeRegistry);
|
|
53
|
+
get mixedThemeEnable(): boolean;
|
|
54
|
+
setTheme(name: string, data: monaco.editor.IStandaloneThemeData): void;
|
|
55
|
+
registerMonacoTheme(setting: monaco.editor.IStandaloneThemeData, name: string, monacoBase?: monaco.editor.BuiltinTheme): void;
|
|
56
|
+
registerMixedTheme(setting: ITextmateThemeSetting, givenName: string, givenBase?: monaco.editor.BuiltinTheme): void;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=theme-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-registry.d.ts","sourceRoot":"","sources":["../../src/theme-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAA8B,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,KAAK,MAAM,MAAM,6BAA6B,CAAC;AAEtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,eAAO,MAAM,iBAAiB,sBAA2C,CAAC;AAE1E,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,WAAW,EAAE,gBAAgB,EAAE,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAI,CAAC;IAChD,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,QAAQ,EAAE;QACjB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAC7B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;KAC9B,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,EAAE,CAAC;CACvC;AAED,MAAM,WAAW,UAAW,SAAQ,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,oBAAoB;CAAG;AAEpF,MAAM,WAAW,kBAAkB;IACjC,cAAc,EAAE,CACd,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,EACnD,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,oBAAoB,KAAK,IAAI,KACvE,IAAI,CAAC;CACX;AACD,eAAO,MAAM,kBAAkB,eAA+B,CAAC;AAC/D,qBACa,aAAc,YAAW,sBAAsB;IAC1D,aAAa,EAAE,iBAAiB,EAAE,CAAC;IACnC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAM;IACzD,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAa;IACjF,gBAAgB,UAAQ;IAExB,YAAY;IAeZ,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IACtE,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;gBAE5B,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAClD,kBAAkB,EAAE,kBAAkB;IAOpE,IAAI,gBAAgB,IAAI,OAAO,CAE9B;IAED,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,oBAAoB,GAAG,IAAI;IAUtE,mBAAmB,CACjB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,oBAAoB,EAC3C,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,GACtC,IAAI;IAGP,kBAAkB,CAChB,OAAO,EAAE,qBAAqB,EAC9B,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,GACrC,IAAI;CAIR"}
|
|
@@ -0,0 +1,91 @@
|
|
|
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 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; }
|
|
4
|
+
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; }
|
|
5
|
+
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; }
|
|
6
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
7
|
+
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); } }
|
|
8
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
9
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
10
|
+
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); }
|
|
11
|
+
import { contrib, inject, singleton, Syringe } from '@difizen/mana-app';
|
|
12
|
+
import * as monaco from '@difizen/monaco-editor-core';
|
|
13
|
+
import { InitializeContribution } from "./initialize-provider.js";
|
|
14
|
+
export var ThemeContribution = Syringe.defineToken('ThemeContribution');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A single theme setting.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A TextMate theme.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export var MixedThemeRegistry = Symbol('MixedThemeRegistry');
|
|
25
|
+
export var ThemeRegistry = (_dec = singleton({
|
|
26
|
+
contrib: InitializeContribution
|
|
27
|
+
}), _dec(_class = /*#__PURE__*/function () {
|
|
28
|
+
function ThemeRegistry(provider, mixedThemeRegistry) {
|
|
29
|
+
_classCallCheck(this, ThemeRegistry);
|
|
30
|
+
this.themeOptions = {};
|
|
31
|
+
this.themes = new Map();
|
|
32
|
+
this.awaysInitialized = true;
|
|
33
|
+
this.provider = provider;
|
|
34
|
+
this.mixedThemeRegistry = mixedThemeRegistry;
|
|
35
|
+
this.contributions = this.provider.getContributions();
|
|
36
|
+
}
|
|
37
|
+
ThemeRegistry = inject(MixedThemeRegistry)(ThemeRegistry, undefined, 1) || ThemeRegistry;
|
|
38
|
+
ThemeRegistry = contrib(ThemeContribution)(ThemeRegistry, undefined, 0) || ThemeRegistry;
|
|
39
|
+
_createClass(ThemeRegistry, [{
|
|
40
|
+
key: "onInitialize",
|
|
41
|
+
value: function onInitialize() {
|
|
42
|
+
var _this = this;
|
|
43
|
+
this.provider.getContributions({
|
|
44
|
+
cache: false
|
|
45
|
+
}).forEach(function (item) {
|
|
46
|
+
if (item._registerFinish) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
item.registerItem(_this);
|
|
50
|
+
item._registerFinish = true;
|
|
51
|
+
});
|
|
52
|
+
if (this.mixedThemeEnable) {
|
|
53
|
+
this.mixedThemeRegistry.registerThemes(this.themeOptions, this.setTheme.bind(this));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, {
|
|
57
|
+
key: "mixedThemeEnable",
|
|
58
|
+
get: function get() {
|
|
59
|
+
return !!(this.mixedThemeRegistry && this.mixedThemeRegistry.registerThemes);
|
|
60
|
+
}
|
|
61
|
+
}, {
|
|
62
|
+
key: "setTheme",
|
|
63
|
+
value: function setTheme(name, data) {
|
|
64
|
+
try {
|
|
65
|
+
this.themes.set(name, data);
|
|
66
|
+
// monaco auto refreshes a theme with new data
|
|
67
|
+
monaco.editor.defineTheme(name, data);
|
|
68
|
+
} catch (ex) {
|
|
69
|
+
console.error(ex);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}, {
|
|
73
|
+
key: "registerMonacoTheme",
|
|
74
|
+
value: function registerMonacoTheme(setting, name, monacoBase) {
|
|
75
|
+
this.setTheme(name, _objectSpread(_objectSpread({}, setting), {}, {
|
|
76
|
+
base: monacoBase || setting.base || 'vs'
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
}, {
|
|
80
|
+
key: "registerMixedTheme",
|
|
81
|
+
value: function registerMixedTheme(setting, givenName, givenBase) {
|
|
82
|
+
var name = givenName || setting.name;
|
|
83
|
+
this.themeOptions[givenName] = _objectSpread(_objectSpread({}, setting), {}, {
|
|
84
|
+
givenName: givenName,
|
|
85
|
+
name: name,
|
|
86
|
+
base: givenBase
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}]);
|
|
90
|
+
return ThemeRegistry;
|
|
91
|
+
}()) || _class);
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@difizen/libro-cofine-editor-core",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"libro",
|
|
7
|
+
"notebook",
|
|
8
|
+
"monaco"
|
|
9
|
+
],
|
|
10
|
+
"repository": "git@github.com:difizen/libro.git",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"typings": "./es/index.d.ts",
|
|
16
|
+
"default": "./es/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./mock": {
|
|
19
|
+
"typings": "./es/mock/index.d.ts",
|
|
20
|
+
"default": "./es/mock/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./es/mock": {
|
|
23
|
+
"typings": "./es/mock/index.d.ts",
|
|
24
|
+
"default": "./es/mock/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"main": "es/index.js",
|
|
29
|
+
"module": "es/index.js",
|
|
30
|
+
"typings": "es/index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"es",
|
|
33
|
+
"src"
|
|
34
|
+
],
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@difizen/libro-cofine-editor-contribution": "^0.1.2",
|
|
37
|
+
"@difizen/mana-app": "latest",
|
|
38
|
+
"@difizen/monaco-editor-core": "latest",
|
|
39
|
+
"debug": "^4.3.2",
|
|
40
|
+
"reflect-metadata": "^0.1.13"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/debug": "^4.1.6",
|
|
44
|
+
"file-loader": "^6.2.0",
|
|
45
|
+
"source-map-loader": "^4.0.1",
|
|
46
|
+
"ts-loader": "^9.5.1",
|
|
47
|
+
"webpack": "^5.89.0",
|
|
48
|
+
"webpack-cli": "^5.1.4"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"setup": "father build",
|
|
52
|
+
"build": "pnpm run build:worker && father build",
|
|
53
|
+
"test": ": Note: lint task is delegated to test:* scripts",
|
|
54
|
+
"test:vitest": "vitest run",
|
|
55
|
+
"test:jest": "jest",
|
|
56
|
+
"coverage": ": Note: lint task is delegated to coverage:* scripts",
|
|
57
|
+
"coverage:vitest": "vitest run --coverage",
|
|
58
|
+
"coverage:jest": "jest --coverage",
|
|
59
|
+
"lint": ": Note: lint task is delegated to lint:* scripts",
|
|
60
|
+
"lint:eslint": "eslint src",
|
|
61
|
+
"build:worker": "webpack --config ./scripts/webpack.worker.cjs",
|
|
62
|
+
"lint:tsc": "tsc --noEmit"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { LanguageWorkerRegistry } from '@difizen/libro-cofine-editor-contribution';
|
|
2
|
+
import { LanguageWorkerContribution } from '@difizen/libro-cofine-editor-contribution';
|
|
3
|
+
import { inject, singleton } from '@difizen/mana-app';
|
|
4
|
+
|
|
5
|
+
import pkg from '../package.json';
|
|
6
|
+
|
|
7
|
+
import { MonacoLoaderConfig } from './monaco-loader.js';
|
|
8
|
+
|
|
9
|
+
@singleton({ contrib: LanguageWorkerContribution })
|
|
10
|
+
export class DefaultWorkerContribution implements LanguageWorkerContribution {
|
|
11
|
+
config: MonacoLoaderConfig;
|
|
12
|
+
constructor(@inject(MonacoLoaderConfig) config: MonacoLoaderConfig) {
|
|
13
|
+
this.config = config;
|
|
14
|
+
}
|
|
15
|
+
registerLanguageWorkers(registry: LanguageWorkerRegistry) {
|
|
16
|
+
registry.registerWorker({
|
|
17
|
+
language: 'editorWorkerService',
|
|
18
|
+
getWorkerUrl: () => {
|
|
19
|
+
return `data:text/javascript;charset=utf-8,${encodeURIComponent(
|
|
20
|
+
`importScripts('https://unpkg.com/@difizen/libro-cofine-editor-core@${pkg.version}/dist/worker/editor.worker.min.js')`,
|
|
21
|
+
)}`;
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/e2-editor.ts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { DisposableCollection } from '@difizen/mana-app';
|
|
2
|
+
import { inject, singleton } from '@difizen/mana-app';
|
|
3
|
+
import * as monaco from '@difizen/monaco-editor-core';
|
|
4
|
+
|
|
5
|
+
import { EditorHanlerRegistry } from './editor-handler-registry.js';
|
|
6
|
+
import type { LazyCallbackType, Options } from './editor-provider.js';
|
|
7
|
+
import { MonacoEnvironment } from './monaco-environment.js';
|
|
8
|
+
import { ThemeRegistry } from './theme-registry.js';
|
|
9
|
+
|
|
10
|
+
export const EditorNode = Symbol('EditorNode');
|
|
11
|
+
export const MonacoOptions = Symbol('MonacoOptions');
|
|
12
|
+
export const LazyCallback = Symbol('LazyCallback');
|
|
13
|
+
export const IsDiff = Symbol('IsDiff');
|
|
14
|
+
/**
|
|
15
|
+
* E2 Editor
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
@singleton()
|
|
19
|
+
export class E2Editor<
|
|
20
|
+
T extends monaco.editor.IStandaloneCodeEditor | monaco.editor.IStandaloneDiffEditor,
|
|
21
|
+
> {
|
|
22
|
+
codeEditor!: T;
|
|
23
|
+
model!: monaco.editor.ITextModel;
|
|
24
|
+
modified!: monaco.editor.ITextModel;
|
|
25
|
+
original!: monaco.editor.ITextModel;
|
|
26
|
+
language?: string;
|
|
27
|
+
protected toDispose: DisposableCollection = new DisposableCollection();
|
|
28
|
+
node: HTMLElement;
|
|
29
|
+
options: Options;
|
|
30
|
+
editorHandlerRegistry: EditorHanlerRegistry;
|
|
31
|
+
themeRegistry: ThemeRegistry;
|
|
32
|
+
isDiff: boolean;
|
|
33
|
+
lazyCallback?: LazyCallbackType;
|
|
34
|
+
constructor(
|
|
35
|
+
@inject(EditorNode) node: HTMLElement,
|
|
36
|
+
@inject(MonacoOptions) options: Options,
|
|
37
|
+
@inject(EditorHanlerRegistry) editorHandlerRegistry: EditorHanlerRegistry,
|
|
38
|
+
@inject(ThemeRegistry) themeRegistry: ThemeRegistry,
|
|
39
|
+
@inject(IsDiff) isDiff: boolean,
|
|
40
|
+
@inject(LazyCallback) lazycallback?: LazyCallbackType,
|
|
41
|
+
) {
|
|
42
|
+
this.node = node;
|
|
43
|
+
this.options = options;
|
|
44
|
+
this.editorHandlerRegistry = editorHandlerRegistry;
|
|
45
|
+
this.themeRegistry = themeRegistry;
|
|
46
|
+
this.isDiff = isDiff;
|
|
47
|
+
this.lazyCallback = lazycallback;
|
|
48
|
+
|
|
49
|
+
if (MonacoEnvironment.lazy) {
|
|
50
|
+
// 资源懒加载场景
|
|
51
|
+
if (!isDiff) {
|
|
52
|
+
this.model = monaco.editor.createModel(
|
|
53
|
+
options.value || '',
|
|
54
|
+
options.language,
|
|
55
|
+
options.uri,
|
|
56
|
+
);
|
|
57
|
+
const language = this.model.getLanguageId();
|
|
58
|
+
(this as E2Editor<monaco.editor.IStandaloneCodeEditor>).codeEditor =
|
|
59
|
+
monaco.editor.create(node, { ...options, model: this.model });
|
|
60
|
+
this.handleEditorLanguageFeatureBefore(language);
|
|
61
|
+
MonacoEnvironment.initModule()
|
|
62
|
+
.then(() => {
|
|
63
|
+
// 设置方言和主题
|
|
64
|
+
const codeEditor = (this as E2Editor<monaco.editor.IStandaloneCodeEditor>)
|
|
65
|
+
.codeEditor;
|
|
66
|
+
// 为了触发onCreate事件
|
|
67
|
+
codeEditor.setModel(
|
|
68
|
+
monaco.editor.createModel(codeEditor.getValue() || '', language),
|
|
69
|
+
);
|
|
70
|
+
this.language = options.language;
|
|
71
|
+
monaco.editor.setTheme(options.theme || '');
|
|
72
|
+
// 调用回调函数
|
|
73
|
+
this.handleEditorLanguageFeatureAfter();
|
|
74
|
+
if (this.lazyCallback) {
|
|
75
|
+
this.lazyCallback(
|
|
76
|
+
(this as E2Editor<monaco.editor.IStandaloneCodeEditor>).codeEditor,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
})
|
|
81
|
+
.catch(console.error);
|
|
82
|
+
} else {
|
|
83
|
+
this.modified = monaco.editor.createModel(options.modified || '');
|
|
84
|
+
this.original = monaco.editor.createModel(options.original || '');
|
|
85
|
+
(this as E2Editor<monaco.editor.IStandaloneDiffEditor>).codeEditor =
|
|
86
|
+
monaco.editor.createDiffEditor(node, { ...options });
|
|
87
|
+
(this as E2Editor<monaco.editor.IStandaloneDiffEditor>).codeEditor.setModel({
|
|
88
|
+
original: this.original,
|
|
89
|
+
modified: this.modified,
|
|
90
|
+
});
|
|
91
|
+
this.handleEditorLanguageFeatureBefore(options.language);
|
|
92
|
+
MonacoEnvironment.initModule()
|
|
93
|
+
.then(() => {
|
|
94
|
+
monaco.editor.setModelLanguage(this.modified, options.language!);
|
|
95
|
+
monaco.editor.setModelLanguage(this.original, options.language!);
|
|
96
|
+
this.language = this.original.getLanguageId();
|
|
97
|
+
|
|
98
|
+
monaco.editor.setTheme(options.theme || '');
|
|
99
|
+
// 调用回调函数
|
|
100
|
+
this.handleEditorLanguageFeatureAfter();
|
|
101
|
+
if (this.lazyCallback) {
|
|
102
|
+
this.lazyCallback(
|
|
103
|
+
(this as E2Editor<monaco.editor.IStandaloneDiffEditor>).codeEditor,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
return;
|
|
107
|
+
})
|
|
108
|
+
.catch(console.error);
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
// create前钩子函数调用
|
|
112
|
+
this.handleEditorLanguageFeatureBefore(options.language);
|
|
113
|
+
|
|
114
|
+
if (!isDiff) {
|
|
115
|
+
this.model = monaco.editor.createModel(options.value || '', options.language);
|
|
116
|
+
(this as E2Editor<monaco.editor.IStandaloneCodeEditor>).codeEditor =
|
|
117
|
+
monaco.editor.create(node, { ...options, model: this.model });
|
|
118
|
+
this.toDispose.push(
|
|
119
|
+
this.model.onDidChangeLanguage((e) => {
|
|
120
|
+
this.language = e.newLanguage;
|
|
121
|
+
}),
|
|
122
|
+
);
|
|
123
|
+
this.language = this.model.getLanguageId();
|
|
124
|
+
} else {
|
|
125
|
+
this.modified = monaco.editor.createModel(
|
|
126
|
+
options.modified || '',
|
|
127
|
+
options.language,
|
|
128
|
+
);
|
|
129
|
+
this.original = monaco.editor.createModel(
|
|
130
|
+
options.original || '',
|
|
131
|
+
options.language,
|
|
132
|
+
);
|
|
133
|
+
(this as E2Editor<monaco.editor.IStandaloneDiffEditor>).codeEditor =
|
|
134
|
+
monaco.editor.createDiffEditor(node, { ...options });
|
|
135
|
+
(this as E2Editor<monaco.editor.IStandaloneDiffEditor>).codeEditor.setModel({
|
|
136
|
+
original: this.original,
|
|
137
|
+
modified: this.modified,
|
|
138
|
+
});
|
|
139
|
+
this.toDispose.push(
|
|
140
|
+
this.modified.onDidChangeLanguage((e) => {
|
|
141
|
+
this.language = e.newLanguage;
|
|
142
|
+
}),
|
|
143
|
+
);
|
|
144
|
+
this.language = this.modified.getLanguageId();
|
|
145
|
+
}
|
|
146
|
+
this.handleEditorLanguageFeatureAfter();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
protected handleEditorLanguageFeatureBefore(language: string | undefined) {
|
|
151
|
+
if (language) {
|
|
152
|
+
this.editorHandlerRegistry.handleBefore(language);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
protected handleEditorLanguageFeatureAfter() {
|
|
157
|
+
if (this.language) {
|
|
158
|
+
this.editorHandlerRegistry.handleAfter(this.language, this.codeEditor);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|