@difizen/libro-cofine-editor-contribution 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/es/editor-options-registry.d.ts +7 -0
- package/es/editor-options-registry.d.ts.map +1 -0
- package/es/editor-options-registry.js +26 -0
- package/es/index.d.ts +14 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +6 -0
- package/es/language-worker-registry.d.ts +20 -0
- package/es/language-worker-registry.d.ts.map +1 -0
- package/es/language-worker-registry.js +72 -0
- package/es/lazy-loader-registry.d.ts +14 -0
- package/es/lazy-loader-registry.d.ts.map +1 -0
- package/es/lazy-loader-registry.js +30 -0
- package/es/options-registry.d.ts +6 -0
- package/es/options-registry.d.ts.map +1 -0
- package/es/options-registry.js +26 -0
- package/package.json +54 -0
- package/src/editor-options-registry.ts +15 -0
- package/src/index.spec.ts +10 -0
- package/src/index.ts +26 -0
- package/src/language-worker-registry.ts +64 -0
- package/src/lazy-loader-registry.ts +29 -0
- package/src/options-registry.ts +14 -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
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type monaco from '@difizen/monaco-editor-core';
|
|
2
|
+
export declare class EditorOptionsRegistry {
|
|
3
|
+
protected optionsMap: Map<monaco.Uri, any>;
|
|
4
|
+
set(uri: monaco.Uri, data: any): void;
|
|
5
|
+
get(uri: monaco.Uri): any;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=editor-options-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor-options-registry.d.ts","sourceRoot":"","sources":["../src/editor-options-registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,6BAA6B,CAAC;AAEtD,qBACa,qBAAqB;IAChC,SAAS,CAAC,UAAU,uBAA8B;IAElD,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG;IAI9B,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG;CAGpB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
+
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); }
|
|
8
|
+
import { singleton } from '@difizen/mana-app';
|
|
9
|
+
export var EditorOptionsRegistry = (_dec = singleton(), _dec(_class = /*#__PURE__*/function () {
|
|
10
|
+
function EditorOptionsRegistry() {
|
|
11
|
+
_classCallCheck(this, EditorOptionsRegistry);
|
|
12
|
+
this.optionsMap = new Map();
|
|
13
|
+
}
|
|
14
|
+
_createClass(EditorOptionsRegistry, [{
|
|
15
|
+
key: "set",
|
|
16
|
+
value: function set(uri, data) {
|
|
17
|
+
this.optionsMap.set(uri, data);
|
|
18
|
+
}
|
|
19
|
+
}, {
|
|
20
|
+
key: "get",
|
|
21
|
+
value: function get(uri) {
|
|
22
|
+
return this.optionsMap.get(uri);
|
|
23
|
+
}
|
|
24
|
+
}]);
|
|
25
|
+
return EditorOptionsRegistry;
|
|
26
|
+
}()) || _class);
|
package/es/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Disposable } from '@difizen/mana-app';
|
|
2
|
+
import { Syringe } from '@difizen/mana-app';
|
|
3
|
+
import type monaco from '@difizen/monaco-editor-core';
|
|
4
|
+
export declare const EditorHandlerContribution: Syringe.DefinedToken;
|
|
5
|
+
export interface EditorHandlerContribution extends Disposable {
|
|
6
|
+
beforeCreate: (coreMonaco: typeof monaco) => void;
|
|
7
|
+
afterCreate: (editor: monaco.editor.IStandaloneCodeEditor | monaco.editor.IStandaloneDiffEditor, coreMonaco: typeof monaco) => void;
|
|
8
|
+
canHandle: (language: string) => boolean;
|
|
9
|
+
}
|
|
10
|
+
export { EditorOptionsRegistry } from './editor-options-registry.js';
|
|
11
|
+
export { LanguageWorkerContribution, LanguageWorkerRegistry, } from './language-worker-registry.js';
|
|
12
|
+
export { LazyLoaderRegistry, LazyLoaderRegistryContribution, } from './lazy-loader-registry.js';
|
|
13
|
+
export { LanguageOptionsRegistry } from './options-registry.js';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,6BAA6B,CAAC;AAEtD,eAAO,MAAM,yBAAyB,sBAErC,CAAC;AAEF,MAAM,WAAW,yBAA0B,SAAQ,UAAU;IAC3D,YAAY,EAAE,CAAC,UAAU,EAAE,OAAO,MAAM,KAAK,IAAI,CAAC;IAClD,WAAW,EAAE,CACX,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC,qBAAqB,EACjF,UAAU,EAAE,OAAO,MAAM,KACtB,IAAI,CAAC;IACV,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;CAC1C;AACD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,kBAAkB,EAClB,8BAA8B,GAC/B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/es/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Syringe } from '@difizen/mana-app';
|
|
2
|
+
export var EditorHandlerContribution = Syringe.defineToken('LanguageWorkerContribution');
|
|
3
|
+
export { EditorOptionsRegistry } from "./editor-options-registry.js";
|
|
4
|
+
export { LanguageWorkerContribution, LanguageWorkerRegistry } from "./language-worker-registry.js";
|
|
5
|
+
export { LazyLoaderRegistry, LazyLoaderRegistryContribution } from "./lazy-loader-registry.js";
|
|
6
|
+
export { LanguageOptionsRegistry } from "./options-registry.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Contribution } from '@difizen/mana-app';
|
|
2
|
+
import { Syringe } from '@difizen/mana-app';
|
|
3
|
+
export declare const LanguageWorkerContribution: Syringe.DefinedToken;
|
|
4
|
+
export interface LanguageWorkerContribution {
|
|
5
|
+
registerLanguageWorkers: (registry: LanguageWorkerRegistry) => void;
|
|
6
|
+
}
|
|
7
|
+
export interface LanguageWorkerConfig {
|
|
8
|
+
language: string;
|
|
9
|
+
priority?: number;
|
|
10
|
+
getWorkerUrl: (language: string, moduleId?: string) => string;
|
|
11
|
+
}
|
|
12
|
+
export declare class LanguageWorkerRegistry {
|
|
13
|
+
protected configs: LanguageWorkerConfig[];
|
|
14
|
+
protected readonly provider: Contribution.Provider<LanguageWorkerContribution>;
|
|
15
|
+
constructor(provider: Contribution.Provider<LanguageWorkerContribution>);
|
|
16
|
+
registerWorker(config: LanguageWorkerConfig): void;
|
|
17
|
+
getLanguageWorker(language: string, moduleId?: string): string | undefined;
|
|
18
|
+
getLanguageConfig(language: string): LanguageWorkerConfig | undefined;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=language-worker-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-worker-registry.d.ts","sourceRoot":"","sources":["../src/language-worker-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAsB,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEhE,eAAO,MAAM,0BAA0B,sBAEtC,CAAC;AACF,MAAM,WAAW,0BAA0B;IACzC,uBAAuB,EAAE,CAAC,QAAQ,EAAE,sBAAsB,KAAK,IAAI,CAAC;CACrE;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;CAC/D;AAED,qBACa,sBAAsB;IACjC,SAAS,CAAC,OAAO,EAAE,oBAAoB,EAAE,CAAM;IAC/C,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,0BAA0B,CAAC,CAAC;gBAG7E,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,0BAA0B,CAAC;IAQ7D,cAAc,CAAC,MAAM,EAAE,oBAAoB;IAiB3C,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAW1E,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS;CAKtE"}
|
|
@@ -0,0 +1,72 @@
|
|
|
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 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; }
|
|
10
|
+
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; }
|
|
11
|
+
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; }
|
|
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
|
+
export var LanguageWorkerContribution = Syringe.defineToken('LanguageWorkerContribution');
|
|
19
|
+
export var LanguageWorkerRegistry = (_dec = singleton(), _dec(_class = /*#__PURE__*/function () {
|
|
20
|
+
function LanguageWorkerRegistry(provider) {
|
|
21
|
+
var _this = this;
|
|
22
|
+
_classCallCheck(this, LanguageWorkerRegistry);
|
|
23
|
+
this.configs = [];
|
|
24
|
+
this.provider = provider;
|
|
25
|
+
this.provider.getContributions().forEach(function (contribution) {
|
|
26
|
+
contribution.registerLanguageWorkers(_this);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
LanguageWorkerRegistry = contrib(LanguageWorkerContribution)(LanguageWorkerRegistry, undefined, 0) || LanguageWorkerRegistry;
|
|
30
|
+
_createClass(LanguageWorkerRegistry, [{
|
|
31
|
+
key: "registerWorker",
|
|
32
|
+
value: function registerWorker(config) {
|
|
33
|
+
var conf = _objectSpread(_objectSpread({}, config), {}, {
|
|
34
|
+
language: config.language.toUpperCase()
|
|
35
|
+
});
|
|
36
|
+
if (this.configs.find(function (c) {
|
|
37
|
+
return c.language === conf.language;
|
|
38
|
+
})) {
|
|
39
|
+
console.warn("Language ".concat(conf.language, " has already registed, this will overwrite the previous configuration"));
|
|
40
|
+
}
|
|
41
|
+
this.configs = [].concat(_toConsumableArray(this.configs), [conf]).sort(function (a, b) {
|
|
42
|
+
var aPriority = a.priority || 100;
|
|
43
|
+
var bPriority = b.priority || 100;
|
|
44
|
+
return bPriority - aPriority;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}, {
|
|
48
|
+
key: "getLanguageWorker",
|
|
49
|
+
value: function getLanguageWorker(language, moduleId) {
|
|
50
|
+
var _this2 = this;
|
|
51
|
+
this.configs = [];
|
|
52
|
+
this.provider.getContributions({
|
|
53
|
+
cache: false
|
|
54
|
+
}).forEach(function (contribution) {
|
|
55
|
+
contribution.registerLanguageWorkers(_this2);
|
|
56
|
+
});
|
|
57
|
+
var config = this.getLanguageConfig(language);
|
|
58
|
+
if (config) {
|
|
59
|
+
return config.getWorkerUrl(language, moduleId);
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
}, {
|
|
64
|
+
key: "getLanguageConfig",
|
|
65
|
+
value: function getLanguageConfig(language) {
|
|
66
|
+
return this.configs.find(function (item) {
|
|
67
|
+
return item.language.toUpperCase() === language.toUpperCase();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}]);
|
|
71
|
+
return LanguageWorkerRegistry;
|
|
72
|
+
}()) || _class);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import type { Contribution } from '@difizen/mana-app';
|
|
3
|
+
import { Syringe } from '@difizen/mana-app';
|
|
4
|
+
export declare const LazyLoaderRegistryContribution: Syringe.DefinedToken;
|
|
5
|
+
export interface LazyLoaderRegistryContribution extends Disposable {
|
|
6
|
+
handleLazyLoder: () => void;
|
|
7
|
+
isLazyLoader?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class LazyLoaderRegistry {
|
|
10
|
+
provider: Contribution.Provider<LazyLoaderRegistryContribution>;
|
|
11
|
+
constructor(provider: Contribution.Provider<LazyLoaderRegistryContribution>);
|
|
12
|
+
handleLazyLoder(): void;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=lazy-loader-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-loader-registry.d.ts","sourceRoot":"","sources":["../src/lazy-loader-registry.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAsB,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEhE,eAAO,MAAM,8BAA8B,sBAE1C,CAAC;AACF,MAAM,WAAW,8BAA+B,SAAQ,UAAU;IAChE,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,qBACa,kBAAkB;IAC7B,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,8BAA8B,CAAC,CAAC;gBAG9D,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,8BAA8B,CAAC;IAIjE,eAAe;CAQhB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
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(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
+
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); }
|
|
8
|
+
import { contrib, singleton, Syringe } from '@difizen/mana-app';
|
|
9
|
+
export var LazyLoaderRegistryContribution = Syringe.defineToken('LazyLoaderRegistryContribution');
|
|
10
|
+
export var LazyLoaderRegistry = (_dec = singleton(), _dec(_class = /*#__PURE__*/function () {
|
|
11
|
+
function LazyLoaderRegistry(provider) {
|
|
12
|
+
_classCallCheck(this, LazyLoaderRegistry);
|
|
13
|
+
this.provider = provider;
|
|
14
|
+
}
|
|
15
|
+
LazyLoaderRegistry = contrib(LazyLoaderRegistryContribution)(LazyLoaderRegistry, undefined, 0) || LazyLoaderRegistry;
|
|
16
|
+
_createClass(LazyLoaderRegistry, [{
|
|
17
|
+
key: "handleLazyLoder",
|
|
18
|
+
value: function handleLazyLoder() {
|
|
19
|
+
this.provider.getContributions({
|
|
20
|
+
cache: false
|
|
21
|
+
}).forEach(function (c) {
|
|
22
|
+
if (c.isLazyLoader) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
c.handleLazyLoder();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}]);
|
|
29
|
+
return LazyLoaderRegistry;
|
|
30
|
+
}()) || _class);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options-registry.d.ts","sourceRoot":"","sources":["../src/options-registry.ts"],"names":[],"mappings":"AAEA,qBACa,uBAAuB;IAClC,SAAS,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAa;IAEnD,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG;IAItC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG;CAG7B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
+
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); }
|
|
8
|
+
import { singleton } from '@difizen/mana-app';
|
|
9
|
+
export var LanguageOptionsRegistry = (_dec = singleton(), _dec(_class = /*#__PURE__*/function () {
|
|
10
|
+
function LanguageOptionsRegistry() {
|
|
11
|
+
_classCallCheck(this, LanguageOptionsRegistry);
|
|
12
|
+
this.optionsMap = new Map();
|
|
13
|
+
}
|
|
14
|
+
_createClass(LanguageOptionsRegistry, [{
|
|
15
|
+
key: "registerOptions",
|
|
16
|
+
value: function registerOptions(key, data) {
|
|
17
|
+
this.optionsMap.set(key, data);
|
|
18
|
+
}
|
|
19
|
+
}, {
|
|
20
|
+
key: "getOptions",
|
|
21
|
+
value: function getOptions(key) {
|
|
22
|
+
return this.optionsMap.get(key);
|
|
23
|
+
}
|
|
24
|
+
}]);
|
|
25
|
+
return LanguageOptionsRegistry;
|
|
26
|
+
}()) || _class);
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@difizen/libro-cofine-editor-contribution",
|
|
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/mana-app": "latest"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@difizen/monaco-editor-core": "latest"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"setup": "father build",
|
|
43
|
+
"build": "father build",
|
|
44
|
+
"test": ": Note: lint task is delegated to test:* scripts",
|
|
45
|
+
"test:vitest": "vitest run",
|
|
46
|
+
"test:jest": "jest",
|
|
47
|
+
"coverage": ": Note: lint task is delegated to coverage:* scripts",
|
|
48
|
+
"coverage:vitest": "vitest run --coverage",
|
|
49
|
+
"coverage:jest": "jest --coverage",
|
|
50
|
+
"lint": ": Note: lint task is delegated to lint:* scripts",
|
|
51
|
+
"lint:eslint": "eslint src",
|
|
52
|
+
"lint:tsc": "tsc --noEmit"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { singleton } from '@difizen/mana-app';
|
|
2
|
+
import type monaco from '@difizen/monaco-editor-core';
|
|
3
|
+
|
|
4
|
+
@singleton()
|
|
5
|
+
export class EditorOptionsRegistry {
|
|
6
|
+
protected optionsMap = new Map<monaco.Uri, any>();
|
|
7
|
+
|
|
8
|
+
set(uri: monaco.Uri, data: any) {
|
|
9
|
+
this.optionsMap.set(uri, data);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
get(uri: monaco.Uri) {
|
|
13
|
+
return this.optionsMap.get(uri);
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Disposable } from '@difizen/mana-app';
|
|
2
|
+
import { Syringe } from '@difizen/mana-app';
|
|
3
|
+
import type monaco from '@difizen/monaco-editor-core';
|
|
4
|
+
|
|
5
|
+
export const EditorHandlerContribution = Syringe.defineToken(
|
|
6
|
+
'LanguageWorkerContribution',
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
export interface EditorHandlerContribution extends Disposable {
|
|
10
|
+
beforeCreate: (coreMonaco: typeof monaco) => void;
|
|
11
|
+
afterCreate: (
|
|
12
|
+
editor: monaco.editor.IStandaloneCodeEditor | monaco.editor.IStandaloneDiffEditor,
|
|
13
|
+
coreMonaco: typeof monaco,
|
|
14
|
+
) => void;
|
|
15
|
+
canHandle: (language: string) => boolean;
|
|
16
|
+
}
|
|
17
|
+
export { EditorOptionsRegistry } from './editor-options-registry.js';
|
|
18
|
+
export {
|
|
19
|
+
LanguageWorkerContribution,
|
|
20
|
+
LanguageWorkerRegistry,
|
|
21
|
+
} from './language-worker-registry.js';
|
|
22
|
+
export {
|
|
23
|
+
LazyLoaderRegistry,
|
|
24
|
+
LazyLoaderRegistryContribution,
|
|
25
|
+
} from './lazy-loader-registry.js';
|
|
26
|
+
export { LanguageOptionsRegistry } from './options-registry.js';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Contribution } from '@difizen/mana-app';
|
|
2
|
+
import { contrib, singleton, Syringe } from '@difizen/mana-app';
|
|
3
|
+
|
|
4
|
+
export const LanguageWorkerContribution = Syringe.defineToken(
|
|
5
|
+
'LanguageWorkerContribution',
|
|
6
|
+
);
|
|
7
|
+
export interface LanguageWorkerContribution {
|
|
8
|
+
registerLanguageWorkers: (registry: LanguageWorkerRegistry) => void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface LanguageWorkerConfig {
|
|
12
|
+
language: string;
|
|
13
|
+
priority?: number;
|
|
14
|
+
getWorkerUrl: (language: string, moduleId?: string) => string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@singleton()
|
|
18
|
+
export class LanguageWorkerRegistry {
|
|
19
|
+
protected configs: LanguageWorkerConfig[] = [];
|
|
20
|
+
protected readonly provider: Contribution.Provider<LanguageWorkerContribution>;
|
|
21
|
+
constructor(
|
|
22
|
+
@contrib(LanguageWorkerContribution)
|
|
23
|
+
provider: Contribution.Provider<LanguageWorkerContribution>,
|
|
24
|
+
) {
|
|
25
|
+
this.provider = provider;
|
|
26
|
+
this.provider.getContributions().forEach((contribution) => {
|
|
27
|
+
contribution.registerLanguageWorkers(this);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
registerWorker(config: LanguageWorkerConfig) {
|
|
32
|
+
const conf = {
|
|
33
|
+
...config,
|
|
34
|
+
language: config.language.toUpperCase(),
|
|
35
|
+
};
|
|
36
|
+
if (this.configs.find((c) => c.language === conf.language)) {
|
|
37
|
+
console.warn(
|
|
38
|
+
`Language ${conf.language} has already registed, this will overwrite the previous configuration`,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
this.configs = [...this.configs, conf].sort((a, b) => {
|
|
42
|
+
const aPriority = a.priority || 100;
|
|
43
|
+
const bPriority = b.priority || 100;
|
|
44
|
+
return bPriority - aPriority;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getLanguageWorker(language: string, moduleId?: string): string | undefined {
|
|
49
|
+
this.configs = [];
|
|
50
|
+
this.provider.getContributions({ cache: false }).forEach((contribution) => {
|
|
51
|
+
contribution.registerLanguageWorkers(this);
|
|
52
|
+
});
|
|
53
|
+
const config = this.getLanguageConfig(language);
|
|
54
|
+
if (config) {
|
|
55
|
+
return config.getWorkerUrl(language, moduleId);
|
|
56
|
+
}
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
getLanguageConfig(language: string): LanguageWorkerConfig | undefined {
|
|
60
|
+
return this.configs.find(
|
|
61
|
+
(item) => item.language.toUpperCase() === language.toUpperCase(),
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Contribution } from '@difizen/mana-app';
|
|
2
|
+
import { contrib, singleton, Syringe } from '@difizen/mana-app';
|
|
3
|
+
|
|
4
|
+
export const LazyLoaderRegistryContribution = Syringe.defineToken(
|
|
5
|
+
'LazyLoaderRegistryContribution',
|
|
6
|
+
);
|
|
7
|
+
export interface LazyLoaderRegistryContribution extends Disposable {
|
|
8
|
+
handleLazyLoder: () => void;
|
|
9
|
+
isLazyLoader?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@singleton()
|
|
13
|
+
export class LazyLoaderRegistry {
|
|
14
|
+
provider: Contribution.Provider<LazyLoaderRegistryContribution>;
|
|
15
|
+
constructor(
|
|
16
|
+
@contrib(LazyLoaderRegistryContribution)
|
|
17
|
+
provider: Contribution.Provider<LazyLoaderRegistryContribution>,
|
|
18
|
+
) {
|
|
19
|
+
this.provider = provider;
|
|
20
|
+
}
|
|
21
|
+
handleLazyLoder() {
|
|
22
|
+
this.provider.getContributions({ cache: false }).forEach((c) => {
|
|
23
|
+
if (c.isLazyLoader) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
c.handleLazyLoder();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { singleton } from '@difizen/mana-app';
|
|
2
|
+
|
|
3
|
+
@singleton()
|
|
4
|
+
export class LanguageOptionsRegistry {
|
|
5
|
+
protected optionsMap: Map<string, any> = new Map();
|
|
6
|
+
|
|
7
|
+
registerOptions(key: string, data: any) {
|
|
8
|
+
this.optionsMap.set(key, data);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
getOptions(key: string): any {
|
|
12
|
+
return this.optionsMap.get(key);
|
|
13
|
+
}
|
|
14
|
+
}
|