@difizen/libro-code-editor 0.1.13 → 0.1.15

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.
@@ -1,34 +1,26 @@
1
1
  import type { Contribution } from '@difizen/mana-app';
2
- import { ViewManager, Syringe } from '@difizen/mana-app';
2
+ import { ViewManager } from '@difizen/mana-app';
3
3
  import { CodeEditorInfoManager } from './code-editor-info-manager.js';
4
4
  import type { IModel } from './code-editor-model.js';
5
- import type { IEditor, IEditorConfig, IEditorOptions } from './code-editor-protocol.js';
5
+ import { CodeEditorContribution } from './code-editor-protocol.js';
6
+ import type { EditorState } from './code-editor-protocol.js';
6
7
  import { CodeEditorSettings } from './code-editor-settings.js';
7
8
  import type { CodeEditorViewOptions } from './code-editor-view.js';
8
9
  import { CodeEditorView } from './code-editor-view.js';
9
- /**
10
- * A factory used to create a code editor.
11
- */
12
- export type CodeEditorFactory = (options: IEditorOptions) => IEditor;
13
- export declare const CodeEditorContribution: Syringe.DefinedToken;
14
- export interface CodeEditorContribution {
15
- canHandle(mime: string): number;
16
- factory: CodeEditorFactory;
17
- defaultConfig: IEditorConfig;
18
- }
19
10
  export declare class CodeEditorManager {
20
11
  protected readonly codeEditorProvider: Contribution.Provider<CodeEditorContribution>;
21
12
  protected readonly viewManager: ViewManager;
22
13
  protected codeEditorInfoManager: CodeEditorInfoManager;
23
14
  protected readonly codeEditorSettings: CodeEditorSettings;
15
+ protected stateCache: Map<string, EditorState>;
24
16
  setEditorHostRef(id: string, ref: any): void;
25
- protected findCodeEditorProvider(model: IModel): CodeEditorContribution;
17
+ protected findCodeEditorProvider(model: IModel): CodeEditorContribution<any>;
26
18
  /**
27
19
  * 获取默认配置
28
20
  * @param model
29
21
  * @returns
30
22
  */
31
- getEditorDefaultConfig(model: IModel): IEditorConfig;
23
+ getEditorDefaultConfig(model: IModel): import("./code-editor-protocol.js").IEditorConfig;
32
24
  /**
33
25
  * 用户配置+默认配置(还有一部分配置在cell中指定)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C,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"}
@@ -14,16 +14,11 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
14
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
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
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, Syringe } from '@difizen/mana-app';
17
+ import { Priority, ViewManager, contrib, inject, singleton } from '@difizen/mana-app';
18
18
  import { CodeEditorInfoManager } from "./code-editor-info-manager.js";
19
+ import { CodeEditorContribution } from "./code-editor-protocol.js";
19
20
  import { CodeEditorSettings } from "./code-editor-settings.js";
20
21
  import { CodeEditorView } from "./code-editor-view.js";
21
-
22
- /**
23
- * A factory used to create a code editor.
24
- */
25
-
26
- export var CodeEditorContribution = Syringe.defineToken('CodeEditorContribution');
27
22
  export var CodeEditorManager = (_dec = singleton(), _dec2 = contrib(CodeEditorContribution), _dec3 = inject(ViewManager), _dec4 = inject(CodeEditorInfoManager), _dec5 = inject(CodeEditorSettings), _dec(_class = (_class2 = /*#__PURE__*/function () {
28
23
  function CodeEditorManager() {
29
24
  _classCallCheck(this, CodeEditorManager);
@@ -31,6 +26,7 @@ export var CodeEditorManager = (_dec = singleton(), _dec2 = contrib(CodeEditorCo
31
26
  _initializerDefineProperty(this, "viewManager", _descriptor2, this);
32
27
  _initializerDefineProperty(this, "codeEditorInfoManager", _descriptor3, this);
33
28
  _initializerDefineProperty(this, "codeEditorSettings", _descriptor4, this);
29
+ this.stateCache = new Map();
34
30
  }
35
31
  _createClass(CodeEditorManager, [{
36
32
  key: "setEditorHostRef",
@@ -85,7 +81,7 @@ export var CodeEditorManager = (_dec = singleton(), _dec2 = contrib(CodeEditorCo
85
81
  _context.next = 3;
86
82
  break;
87
83
  }
88
- throw new Error("no code editor found for mimetype: ".concat(option.model.mimeType));
84
+ throw new Error("no code editor factory registered for mimetype: ".concat(option.model.mimeType));
89
85
  case 3:
90
86
  _context.next = 5;
91
87
  return this.viewManager.getOrCreateView(CodeEditorView, _objectSpread({
@@ -1,5 +1,6 @@
1
- import type { JSONObject } from '@difizen/libro-common';
1
+ import type { JSONObject, JSONValue } from '@difizen/libro-common';
2
2
  import type { Disposable, Event, ThemeType } from '@difizen/mana-app';
3
+ import { Syringe } from '@difizen/mana-app';
3
4
  import type { IModel } from './code-editor-model.js';
4
5
  /**
5
6
  * A one-based position in the editor.
@@ -176,7 +177,8 @@ export type EdgeLocation = 'top' | 'topLine' | 'bottom';
176
177
  /**
177
178
  * A widget that provides a code editor.
178
179
  */
179
- export interface IEditor extends ISelectionOwner, Disposable {
180
+ export interface IEditor<S = any> extends ISelectionOwner, Disposable {
181
+ editorReady: Promise<void>;
180
182
  /**
181
183
  * A signal emitted when either the top or bottom edge is requested.
182
184
  */
@@ -271,6 +273,7 @@ export interface IEditor extends ISelectionOwner, Disposable {
271
273
  getPositionForCoordinate: (coordinate: ICoordinate) => IPosition | null;
272
274
  onModalChange: Event<boolean>;
273
275
  dispose: () => void;
276
+ getState: () => EditorState<S>;
274
277
  }
275
278
  export type EditorTheme = Record<ThemeType, string>;
276
279
  /**
@@ -380,13 +383,9 @@ export type CompletionReply = {
380
383
  };
381
384
  export type CompletionProvider = (option: CompletionProviderOption) => Promise<CompletionReply>;
382
385
  /**
383
- * The options used to initialize an editor.
386
+ * The options used to initialize an editor state.
384
387
  */
385
- export interface IEditorOptions {
386
- /**
387
- * The host widget used by the editor.
388
- */
389
- host: HTMLElement;
388
+ export interface IEditorStateOptions {
390
389
  /**
391
390
  * The model used by the editor.
392
391
  */
@@ -394,7 +393,16 @@ export interface IEditorOptions {
394
393
  /**
395
394
  * The desired uuid for the editor.
396
395
  */
397
- uuid?: string;
396
+ uuid: string;
397
+ }
398
+ /**
399
+ * The options used to initialize an editor.
400
+ */
401
+ export interface IEditorOptions extends IEditorStateOptions {
402
+ /**
403
+ * The host widget used by the editor.
404
+ */
405
+ host: HTMLElement;
398
406
  /**
399
407
  * The default selection style for the editor.
400
408
  */
@@ -419,4 +427,29 @@ export interface SearchMatch {
419
427
  */
420
428
  position: number;
421
429
  }
430
+ export interface EditorState<T = any> {
431
+ state: T;
432
+ cursorPosition?: IPosition;
433
+ selections?: IRange[];
434
+ toJSON: () => JSONValue;
435
+ dispose: (state: T) => void;
436
+ }
437
+ export type EditorStateFactory<T = any> = (options: IEditorStateOptions) => EditorState<T>;
438
+ /**
439
+ * A factory used to create a code editor.
440
+ */
441
+ export type CodeEditorFactory<T = EditorState> = (options: IEditorOptions, state?: T) => IEditor<T>;
442
+ export declare const CodeEditorContribution: Syringe.DefinedToken;
443
+ export interface CodeEditorContribution<T = any> {
444
+ canHandle(mime: string): number;
445
+ /**
446
+ * editor factory
447
+ */
448
+ factory: CodeEditorFactory<T>;
449
+ /**
450
+ * editor state factory
451
+ */
452
+ stateFactory?: EditorStateFactory<T>;
453
+ defaultConfig: IEditorConfig;
454
+ }
422
455
  //# sourceMappingURL=code-editor-protocol.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"code-editor-protocol.d.ts","sourceRoot":"","sources":["../src/code-editor-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,SAAU,SAAQ,UAAU;IAC3C;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AACD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,eAAe,CAAC;AAC1C;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAE1B;;;;;;OAMG;IACH,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,qBAInC,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,MAAM;IAC5C;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,qBAAqB,CAAC;CACvC;AAED;;GAEG;AACH,MAAM,WAA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,20 @@ export var defaultConfig = {
92
94
  placeholder: ''
93
95
  };
94
96
 
97
+ /**
98
+ * The options used to initialize an editor state.
99
+ */
100
+
95
101
  /**
96
102
  * The options used to initialize an editor.
97
103
  */
98
104
 
99
105
  /**
100
106
  * Base search match interface
101
- */
107
+ */
108
+
109
+ /**
110
+ * A factory used to create a code editor.
111
+ */
112
+
113
+ export var CodeEditorContribution = Syringe.defineToken('CodeEditorContribution');
@@ -0,0 +1,14 @@
1
+ import type { Contribution } from '@difizen/mana-app';
2
+ import type { IModel } from './code-editor-model.js';
3
+ import type { EditorState, IEditorStateOptions } from './code-editor-protocol.js';
4
+ import { CodeEditorContribution } from './code-editor-protocol.js';
5
+ export declare class CodeEditorStateManager {
6
+ protected readonly codeEditorProvider: Contribution.Provider<CodeEditorContribution>;
7
+ protected stateCache: Map<string, EditorState>;
8
+ constructor(codeEditorProvider: Contribution.Provider<CodeEditorContribution>);
9
+ protected findCodeEditorProvider(model: IModel): CodeEditorContribution<any>;
10
+ getOrCreateEditorState(option: IEditorStateOptions): Promise<EditorState>;
11
+ updateEditorState(id: string, state: EditorState): void;
12
+ removeEditorState(id: string): void;
13
+ }
14
+ //# sourceMappingURL=code-editor-state-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-editor-state-manager.d.ts","sourceRoot":"","sources":["../src/code-editor-state-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAKtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,qBACa,sBAAsB;IACjC,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,YAAY,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC;IACrF,SAAS,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAa;gBAIzD,kBAAkB,EAAE,YAAY,CAAC,QAAQ,CAAC,sBAAsB,CAAC;IAKnE,SAAS,CAAC,sBAAsB,CAAC,KAAK,EAAE,MAAM;IASxC,sBAAsB,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,CAAC;IAgB/E,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW;IAIhD,iBAAiB,CAAC,EAAE,EAAE,MAAM;CAG7B"}
@@ -0,0 +1,82 @@
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 _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 _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(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
10
+ 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); }
11
+ import { Priority } from '@difizen/mana-app';
12
+ import { contrib } from '@difizen/mana-app';
13
+ import { singleton } from '@difizen/mana-app';
14
+ import { CodeEditorContribution } from "./code-editor-protocol.js";
15
+ export var CodeEditorStateManager = (_dec = singleton(), _dec(_class = /*#__PURE__*/function () {
16
+ function CodeEditorStateManager(codeEditorProvider) {
17
+ _classCallCheck(this, CodeEditorStateManager);
18
+ this.stateCache = new Map();
19
+ this.codeEditorProvider = codeEditorProvider;
20
+ }
21
+ CodeEditorStateManager = contrib(CodeEditorContribution)(CodeEditorStateManager, undefined, 0) || CodeEditorStateManager;
22
+ _createClass(CodeEditorStateManager, [{
23
+ key: "findCodeEditorProvider",
24
+ value: function findCodeEditorProvider(model) {
25
+ var prioritized = Priority.sortSync(this.codeEditorProvider.getContributions(), function (contribution) {
26
+ return contribution.canHandle(model.mimeType);
27
+ });
28
+ var sorted = prioritized.map(function (c) {
29
+ return c.value;
30
+ });
31
+ return sorted[0];
32
+ }
33
+ }, {
34
+ key: "getOrCreateEditorState",
35
+ value: function () {
36
+ var _getOrCreateEditorState = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(option) {
37
+ var _this$findCodeEditorP;
38
+ var _state, factory, state;
39
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
40
+ while (1) switch (_context.prev = _context.next) {
41
+ case 0:
42
+ if (!this.stateCache.has(option.uuid)) {
43
+ _context.next = 3;
44
+ break;
45
+ }
46
+ _state = this.stateCache.get(option.uuid);
47
+ return _context.abrupt("return", _state);
48
+ case 3:
49
+ factory = (_this$findCodeEditorP = this.findCodeEditorProvider(option.model)) === null || _this$findCodeEditorP === void 0 ? void 0 : _this$findCodeEditorP.stateFactory;
50
+ if (factory) {
51
+ _context.next = 6;
52
+ break;
53
+ }
54
+ throw new Error("no code editor state factory registered for mimetype: ".concat(option.model.mimeType));
55
+ case 6:
56
+ state = factory(option);
57
+ this.stateCache.set(option.uuid, state);
58
+ return _context.abrupt("return", state);
59
+ case 9:
60
+ case "end":
61
+ return _context.stop();
62
+ }
63
+ }, _callee, this);
64
+ }));
65
+ function getOrCreateEditorState(_x) {
66
+ return _getOrCreateEditorState.apply(this, arguments);
67
+ }
68
+ return getOrCreateEditorState;
69
+ }()
70
+ }, {
71
+ key: "updateEditorState",
72
+ value: function updateEditorState(id, state) {
73
+ this.stateCache.set(id, state);
74
+ }
75
+ }, {
76
+ key: "removeEditorState",
77
+ value: function removeEditorState(id) {
78
+ this.stateCache.delete(id);
79
+ }
80
+ }]);
81
+ return CodeEditorStateManager;
82
+ }()) || _class);
@@ -1,17 +1,19 @@
1
1
  /// <reference types="react" resolution-mode="require"/>
2
- import { Deferred, Emitter, BaseView, ThemeService } from '@difizen/mana-app';
2
+ import { Emitter, BaseView, ThemeService } from '@difizen/mana-app';
3
3
  import { CodeEditorInfoManager } from './code-editor-info-manager.js';
4
- import type { CodeEditorFactory } from './code-editor-manager.js';
5
4
  import type { IModel } from './code-editor-model.js';
6
- import type { CompletionProvider, IEditorConfig, IEditor, IEditorSelectionStyle, TooltipProvider } from './code-editor-protocol.js';
5
+ import type { CompletionProvider, IEditorConfig, IEditor, IEditorSelectionStyle, TooltipProvider, CodeEditorFactory } from './code-editor-protocol.js';
7
6
  import { CodeEditorSettings } from './code-editor-settings.js';
7
+ import { CodeEditorStateManager } from './code-editor-state-manager.js';
8
8
  export declare const CodeEditorRender: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<import("react").RefAttributes<HTMLDivElement>>>;
9
+ export type CodeEditorViewStatus = 'init' | 'ready' | 'disposed';
9
10
  /**
10
11
  * A widget which hosts a code editor.
11
12
  */
12
13
  export declare class CodeEditorView extends BaseView {
13
14
  protected readonly themeService: ThemeService;
14
15
  protected readonly codeEditorSettings: CodeEditorSettings;
16
+ protected readonly codeEditorStateManager: CodeEditorStateManager;
15
17
  codeEditorInfoManager: CodeEditorInfoManager;
16
18
  view: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<import("react").RefAttributes<HTMLDivElement>>>;
17
19
  protected classlist: string[];
@@ -23,12 +25,20 @@ export declare class CodeEditorView extends BaseView {
23
25
  * Get the editor wrapped by the widget.
24
26
  */
25
27
  editor: IEditor;
26
- protected editorReadyDeferred: Deferred<void>;
27
- get editorReady(): Promise<void>;
28
+ editorStatus: CodeEditorViewStatus;
29
+ protected editorStatusChangeEmitter: Emitter<{
30
+ status: CodeEditorViewStatus;
31
+ prevState: CodeEditorViewStatus;
32
+ }>;
33
+ onEditorStatusChange: import("@difizen/mana-app").Event<{
34
+ status: CodeEditorViewStatus;
35
+ prevState: CodeEditorViewStatus;
36
+ }>;
28
37
  /**
29
38
  * Construct a new code editor widget.
30
39
  */
31
40
  constructor(options: CodeEditorViewOptions, codeEditorInfoManager: CodeEditorInfoManager);
41
+ protected getEditorHost(): any;
32
42
  onViewMount(): Promise<void>;
33
43
  removeChildNodes: (parent: any) => void;
34
44
  onViewUnmount: () => void;
@@ -94,8 +104,9 @@ export interface CodeEditorViewOptions<Config extends IEditorConfig = IEditorCon
94
104
  model: IModel;
95
105
  /**
96
106
  * The desired uuid for the editor.
107
+ * editor share id with cell.
97
108
  */
98
- uuid?: string;
109
+ uuid: string;
99
110
  /**
100
111
  * The configuration options for the editor.
101
112
  */
@@ -1 +1 @@
1
- {"version":3,"file":"code-editor-view.d.ts","sourceRoot":"","sources":["../src/code-editor-view.tsx"],"names":[],"mappings":";AACA,OAAO,EAGL,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,YAAY,EAGb,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,qBAAqB,EAAE,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AED;;OAEG;IACM,OAAO,IAAI,IAAI;IAQxB,SAAS,CAAC,YAAY,QAAO,IAAI,CAE/B;IAEF;;OAEG;IACH,SAAS,CAAC,QAAQ,IAAI,IAAI;IAM1B,QAAQ,CAAC,SAAS,EAAE,MAAM;IAI1B,WAAW,CAAC,SAAS,EAAE,MAAM;IAO7B;;OAEG;IACH,SAAS,CAAC,oBAAoB,IAAI,IAAI;IAqBtC;;OAEG;IACH,SAAS,CAAC,aAAa,UAAW,SAAS,KAAG,IAAI,CAWhD;IAEF;;OAEG;IACH,SAAS,CAAC,aAAa,UAAW,SAAS,KAAG,IAAI,CAWhD;IAEF;;OAEG;IACH,SAAS,CAAC,YAAY,UAAW,SAAS,KAAG,IAAI,CAa/C;IAEF;;OAEG;IACH,SAAS,CAAC,QAAQ,UAAW,SAAS,KAAG,IAAI,CA+B3C;CACH;AAED;;GAEG;AACH;;GAEG;AACH,MAAM,WAAW,qBAAqB,CAAC,MAAM,SAAS,aAAa,GAAG,aAAa;IACjF;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAE5B;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAEzB;;OAEG;IACH,cAAc,CAAC,EAAE,qBAAqB,CAAC;IAEvC,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IAExC,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB"}
@@ -23,14 +23,15 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
23
23
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
24
24
  function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
25
25
  function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
26
- import { getOrigin, prop } from '@difizen/mana-app';
27
- import { inject, transient, Deferred, Emitter, BaseView, ThemeService, view, ViewOption } from '@difizen/mana-app';
26
+ import { inject, transient, Emitter, BaseView, ThemeService, view, ViewOption } from '@difizen/mana-app';
28
27
  import { forwardRef, memo } from 'react';
29
28
  import { CodeEditorInfoManager } from "./code-editor-info-manager.js";
30
29
  import { CodeEditorSettings } from "./code-editor-settings.js";
30
+ import { CodeEditorStateManager } from "./code-editor-state-manager.js";
31
31
  import { jsx as _jsx } from "react/jsx-runtime";
32
32
  export var CodeEditorRender = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (props, ref) {
33
33
  return /*#__PURE__*/_jsx("div", {
34
+ tabIndex: 0,
34
35
  ref: ref
35
36
  });
36
37
  }));
@@ -55,11 +56,10 @@ var DROP_TARGET_CLASS = 'jp-mod-dropTarget';
55
56
  * RegExp to test for leading whitespace
56
57
  */
57
58
  var leadingWhitespaceRe = /^\s+$/;
58
-
59
59
  /**
60
60
  * A widget which hosts a code editor.
61
61
  */
62
- export var CodeEditorView = (_dec = transient(), _dec2 = view('code-editor-view'), _dec3 = inject(ThemeService), _dec4 = inject(CodeEditorSettings), _dec5 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_BaseView) {
62
+ export var CodeEditorView = (_dec = transient(), _dec2 = view('code-editor-view'), _dec3 = inject(ThemeService), _dec4 = inject(CodeEditorSettings), _dec5 = inject(CodeEditorStateManager), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_BaseView) {
63
63
  _inherits(CodeEditorView, _BaseView);
64
64
  var _super = _createSuper(CodeEditorView);
65
65
  /**
@@ -71,25 +71,37 @@ export var CodeEditorView = (_dec = transient(), _dec2 = view('code-editor-view'
71
71
  _this = _super.call(this);
72
72
  _initializerDefineProperty(_this, "themeService", _descriptor, _assertThisInitialized(_this));
73
73
  _initializerDefineProperty(_this, "codeEditorSettings", _descriptor2, _assertThisInitialized(_this));
74
+ _initializerDefineProperty(_this, "codeEditorStateManager", _descriptor3, _assertThisInitialized(_this));
74
75
  _this.view = CodeEditorRender;
75
76
  _this.classlist = [];
76
77
  _this.modalChangeEmitter = new Emitter();
77
- /**
78
- * Get the editor wrapped by the widget.
79
- */
80
- _initializerDefineProperty(_this, "editor", _descriptor3, _assertThisInitialized(_this));
81
- _this.editorReadyDeferred = new Deferred();
78
+ _this.editorStatus = 'init';
79
+ _this.editorStatusChangeEmitter = new Emitter();
80
+ _this.onEditorStatusChange = _this.editorStatusChangeEmitter.event;
82
81
  _this.removeChildNodes = function (parent) {
83
82
  while (parent.firstChild) {
84
83
  parent.removeChild(parent.firstChild);
85
84
  }
86
85
  };
87
86
  _this.onViewUnmount = function () {
88
- var _this$editorHostRef;
89
- if (_this.editor.dispose) {
90
- _this.editor.dispose();
87
+ var _this$editorHostRef2;
88
+ if (_this.editor.hasFocus()) {
89
+ var _this$editorHostRef;
90
+ // 保存编辑器状态
91
+ var editorState = _this.editor.getState();
92
+ _this.codeEditorStateManager.updateEditorState(_this.options.uuid, editorState);
93
+ // focus 到 host 避免进入命令模式
94
+ _this.editorHostRef = _this.getEditorHost();
95
+ (_this$editorHostRef = _this.editorHostRef) === null || _this$editorHostRef === void 0 || (_this$editorHostRef = _this$editorHostRef.current) === null || _this$editorHostRef === void 0 || _this$editorHostRef.focus();
91
96
  }
92
- var node = (_this$editorHostRef = _this.editorHostRef) === null || _this$editorHostRef === void 0 ? void 0 : _this$editorHostRef.current;
97
+ _this.editor.dispose();
98
+ var prevState = _this.editorStatus;
99
+ _this.editorStatus = 'disposed';
100
+ _this.editorStatusChangeEmitter.fire({
101
+ status: 'disposed',
102
+ prevState: prevState
103
+ });
104
+ var node = (_this$editorHostRef2 = _this.editorHostRef) === null || _this$editorHostRef2 === void 0 ? void 0 : _this$editorHostRef2.current;
93
105
  if (node) {
94
106
  node.removeEventListener('focus', _this.onViewActive);
95
107
  node.removeEventListener('dragenter', _this._evtDragEnter);
@@ -195,53 +207,81 @@ export var CodeEditorView = (_dec = transient(), _dec2 = view('code-editor-view'
195
207
  get: function get() {
196
208
  return this.modalChangeEmitter.event;
197
209
  }
210
+
211
+ /**
212
+ * Get the editor wrapped by the widget.
213
+ */
198
214
  }, {
199
- key: "editorReady",
200
- get: function get() {
201
- return this.editorReadyDeferred.promise;
215
+ key: "getEditorHost",
216
+ value: function getEditorHost() {
217
+ var editorHostId = this.options.editorHostId;
218
+ var editorHostRef = editorHostId ? this.codeEditorInfoManager.getEditorHostRef(editorHostId) : undefined;
219
+ return editorHostRef && editorHostRef.current ? editorHostRef : this.container;
202
220
  }
203
221
  }, {
204
222
  key: "onViewMount",
205
223
  value: function () {
206
224
  var _onViewMount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
207
225
  var _this2 = this;
208
- var settings, editorHostId, editorHostRef;
226
+ var state, settings, cursorPosition, selections, prevState;
209
227
  return _regeneratorRuntime().wrap(function _callee$(_context) {
210
228
  while (1) switch (_context.prev = _context.next) {
211
229
  case 0:
230
+ _context.next = 2;
231
+ return this.codeEditorStateManager.getOrCreateEditorState({
232
+ uuid: this.options.uuid,
233
+ model: this.options.model
234
+ });
235
+ case 2:
236
+ state = _context.sent;
212
237
  settings = this.codeEditorSettings.getUserEditorSettings();
213
- editorHostId = this.options.editorHostId;
214
- editorHostRef = editorHostId ? this.codeEditorInfoManager.getEditorHostRef(editorHostId) : undefined;
215
- this.editorHostRef = editorHostRef && editorHostRef.current ? editorHostRef : this.container;
216
- if (this.editorHostRef.current && this.options.factory) {
217
- this.editor = this.options.factory(_objectSpread(_objectSpread({}, this.options), {}, {
218
- host: this.editorHostRef.current,
219
- model: this.options.model,
220
- uuid: this.options.uuid,
221
- config: _objectSpread(_objectSpread({}, settings), this.options.config),
222
- selectionStyle: this.options.selectionStyle,
223
- tooltipProvider: this.options.tooltipProvider,
224
- completionProvider: this.options.completionProvider
225
- }));
226
- this.editorReadyDeferred.resolve();
227
- this.editor.onModalChange(function (val) {
228
- return _this2.modalChangeEmitter.fire(val);
229
- });
230
- // this.editor.model.selections.changed(this._onSelectionsChanged);
238
+ this.editorHostRef = this.getEditorHost();
239
+ if (!(this.editorHostRef.current && this.options.factory)) {
240
+ _context.next = 23;
241
+ break;
242
+ }
243
+ this.editor = this.options.factory(_objectSpread(_objectSpread({}, this.options), {}, {
244
+ host: this.editorHostRef.current,
245
+ model: this.options.model,
246
+ uuid: this.options.uuid,
247
+ config: _objectSpread(_objectSpread({}, settings), this.options.config),
248
+ selectionStyle: this.options.selectionStyle,
249
+ tooltipProvider: this.options.tooltipProvider,
250
+ completionProvider: this.options.completionProvider
251
+ }), state);
252
+ _context.next = 9;
253
+ return this.editor.editorReady;
254
+ case 9:
255
+ cursorPosition = state.cursorPosition, selections = state.selections;
256
+ prevState = this.editorStatus;
257
+ this.editorStatus = 'ready';
258
+ this.editorStatusChangeEmitter.fire({
259
+ status: 'ready',
260
+ prevState: prevState
261
+ });
262
+ if (cursorPosition) {
263
+ this.editor.setCursorPosition(cursorPosition);
264
+ }
265
+ if (selections) {
266
+ this.editor.setSelections(selections);
267
+ }
268
+ this.editor.onModalChange(function (val) {
269
+ return _this2.modalChangeEmitter.fire(val);
270
+ });
271
+ // this.editor.model.selections.changed(this._onSelectionsChanged);
231
272
 
232
- if (this.options.autoFocus) {
233
- getOrigin(this.editor).focus();
234
- }
235
- this.editorHostRef.current.addEventListener('focus', this.onViewActive);
236
- this.editorHostRef.current.addEventListener('dragenter', this._evtDragEnter);
237
- this.editorHostRef.current.addEventListener('dragleave', this._evtDragLeave);
238
- this.editorHostRef.current.addEventListener('dragover', this._evtDragOver);
239
- this.editorHostRef.current.addEventListener('drop', this._evtDrop);
240
- this.toDispose.push(this.codeEditorSettings.onCodeEditorSettingsChange(function (e) {
241
- _this2.editor.setOption(e.key, e.value);
242
- }));
273
+ if (this.options.autoFocus) {
274
+ this.editor.focus();
243
275
  }
244
- case 5:
276
+ this.editorHostRef.current.addEventListener('focus', this.onViewActive);
277
+ this.editorHostRef.current.addEventListener('dragenter', this._evtDragEnter);
278
+ this.editorHostRef.current.addEventListener('dragleave', this._evtDragLeave);
279
+ this.editorHostRef.current.addEventListener('dragover', this._evtDragOver);
280
+ this.editorHostRef.current.addEventListener('drop', this._evtDrop);
281
+ this.toDispose.push(this.codeEditorSettings.onCodeEditorSettingsChange(function (e) {
282
+ _this2.editor.setOption(e.key, e.value);
283
+ }));
284
+ case 23:
245
285
  case "end":
246
286
  return _context.stop();
247
287
  }
@@ -340,7 +380,7 @@ export var CodeEditorView = (_dec = transient(), _dec2 = view('code-editor-view'
340
380
  enumerable: true,
341
381
  writable: true,
342
382
  initializer: null
343
- }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "editor", [_dec5], {
383
+ }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "codeEditorStateManager", [_dec5], {
344
384
  configurable: true,
345
385
  enumerable: true,
346
386
  writable: true,
@@ -1 +1 @@
1
- {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAQ/C,eAAO,MAAM,gBAAgB,YAQU,CAAC"}
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAU/C,eAAO,MAAM,gBAAgB,YASU,CAAC"}
package/es/module.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import { ManaModule } from '@difizen/mana-app';
2
2
  import { CodeEditorInfoManager } from "./code-editor-info-manager.js";
3
- import { CodeEditorContribution, CodeEditorManager } from "./code-editor-manager.js";
3
+ import { CodeEditorManager } from "./code-editor-manager.js";
4
4
  import { Model } from "./code-editor-model.js";
5
+ import { CodeEditorContribution } from "./code-editor-protocol.js";
5
6
  import { CodeEditorSettings } from "./code-editor-settings.js";
7
+ import { CodeEditorStateManager } from "./code-editor-state-manager.js";
6
8
  import { CodeEditorView } from "./code-editor-view.js";
7
- export var CodeEditorModule = ManaModule.create().register(CodeEditorInfoManager, CodeEditorView, CodeEditorManager, Model, CodeEditorSettings).contribution(CodeEditorContribution);
9
+ export var CodeEditorModule = ManaModule.create().register(CodeEditorInfoManager, CodeEditorView, CodeEditorManager, Model, CodeEditorSettings, CodeEditorStateManager).contribution(CodeEditorContribution);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@difizen/libro-code-editor",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "libro",
@@ -34,7 +34,7 @@
34
34
  "dependencies": {
35
35
  "@difizen/mana-app": "latest",
36
36
  "@difizen/mana-l10n": "latest",
37
- "@difizen/libro-common": "^0.1.13",
37
+ "@difizen/libro-common": "^0.1.15",
38
38
  "uuid": "^9.0.0"
39
39
  },
40
40
  "peerDependencies": {
@@ -1,32 +1,14 @@
1
1
  import type { Contribution } from '@difizen/mana-app';
2
- import {
3
- Priority,
4
- ViewManager,
5
- contrib,
6
- inject,
7
- singleton,
8
- Syringe,
9
- } from '@difizen/mana-app';
2
+ import { Priority, ViewManager, contrib, inject, singleton } from '@difizen/mana-app';
10
3
 
11
4
  import { CodeEditorInfoManager } from './code-editor-info-manager.js';
12
5
  import type { IModel } from './code-editor-model.js';
13
- import type { IEditor, IEditorConfig, IEditorOptions } from './code-editor-protocol.js';
6
+ import { CodeEditorContribution } from './code-editor-protocol.js';
7
+ import type { EditorState } from './code-editor-protocol.js';
14
8
  import { CodeEditorSettings } from './code-editor-settings.js';
15
9
  import type { CodeEditorViewOptions } from './code-editor-view.js';
16
10
  import { CodeEditorView } from './code-editor-view.js';
17
11
 
18
- /**
19
- * A factory used to create a code editor.
20
- */
21
- export type CodeEditorFactory = (options: IEditorOptions) => IEditor;
22
-
23
- export const CodeEditorContribution = Syringe.defineToken('CodeEditorContribution');
24
- export interface CodeEditorContribution {
25
- canHandle(mime: string): number;
26
- factory: CodeEditorFactory;
27
- defaultConfig: IEditorConfig;
28
- }
29
-
30
12
  @singleton()
31
13
  export class CodeEditorManager {
32
14
  @contrib(CodeEditorContribution)
@@ -34,6 +16,7 @@ export class CodeEditorManager {
34
16
  @inject(ViewManager) protected readonly viewManager: ViewManager;
35
17
  @inject(CodeEditorInfoManager) protected codeEditorInfoManager: CodeEditorInfoManager;
36
18
  @inject(CodeEditorSettings) protected readonly codeEditorSettings: CodeEditorSettings;
19
+ protected stateCache: Map<string, EditorState> = new Map();
37
20
 
38
21
  setEditorHostRef(id: string, ref: any) {
39
22
  this.codeEditorInfoManager.setEditorHostRef(id, ref);
@@ -72,7 +55,9 @@ export class CodeEditorManager {
72
55
  async getOrCreateEditorView(option: CodeEditorViewOptions): Promise<CodeEditorView> {
73
56
  const factory = this.findCodeEditorProvider(option.model)?.factory;
74
57
  if (!factory) {
75
- throw new Error(`no code editor found for mimetype: ${option.model.mimeType}`);
58
+ throw new Error(
59
+ `no code editor factory registered for mimetype: ${option.model.mimeType}`,
60
+ );
76
61
  }
77
62
  const editorView = await this.viewManager.getOrCreateView<
78
63
  CodeEditorView,
@@ -1,5 +1,6 @@
1
- import type { JSONObject } from '@difizen/libro-common';
1
+ import type { JSONObject, JSONValue } from '@difizen/libro-common';
2
2
  import type { Disposable, Event, ThemeType } from '@difizen/mana-app';
3
+ import { Syringe } from '@difizen/mana-app';
3
4
 
4
5
  import type { IModel } from './code-editor-model.js';
5
6
 
@@ -203,7 +204,8 @@ export type EdgeLocation = 'top' | 'topLine' | 'bottom';
203
204
  /**
204
205
  * A widget that provides a code editor.
205
206
  */
206
- export interface IEditor extends ISelectionOwner, Disposable {
207
+ export interface IEditor<S = any> extends ISelectionOwner, Disposable {
208
+ editorReady: Promise<void>;
207
209
  /**
208
210
  * A signal emitted when either the top or bottom edge is requested.
209
211
  */
@@ -390,6 +392,8 @@ export interface IEditor extends ISelectionOwner, Disposable {
390
392
  onModalChange: Event<boolean>;
391
393
 
392
394
  dispose: () => void;
395
+
396
+ getState: () => EditorState<S>;
393
397
  }
394
398
 
395
399
  export type EditorTheme = Record<ThemeType, string>;
@@ -560,14 +564,9 @@ export type CompletionProvider = (
560
564
  ) => Promise<CompletionReply>;
561
565
 
562
566
  /**
563
- * The options used to initialize an editor.
567
+ * The options used to initialize an editor state.
564
568
  */
565
- export interface IEditorOptions {
566
- /**
567
- * The host widget used by the editor.
568
- */
569
- host: HTMLElement;
570
-
569
+ export interface IEditorStateOptions {
571
570
  /**
572
571
  * The model used by the editor.
573
572
  */
@@ -576,7 +575,17 @@ export interface IEditorOptions {
576
575
  /**
577
576
  * The desired uuid for the editor.
578
577
  */
579
- uuid?: string;
578
+ uuid: string;
579
+ }
580
+
581
+ /**
582
+ * The options used to initialize an editor.
583
+ */
584
+ export interface IEditorOptions extends IEditorStateOptions {
585
+ /**
586
+ * The host widget used by the editor.
587
+ */
588
+ host: HTMLElement;
580
589
 
581
590
  /**
582
591
  * The default selection style for the editor.
@@ -612,3 +621,38 @@ export interface SearchMatch {
612
621
  */
613
622
  position: number;
614
623
  }
624
+
625
+ export interface EditorState<T = any> {
626
+ // monaco model or codemirror state or other editor state
627
+ state: T;
628
+ cursorPosition?: IPosition;
629
+ selections?: IRange[];
630
+ toJSON: () => JSONValue;
631
+ dispose: (state: T) => void;
632
+ }
633
+
634
+ export type EditorStateFactory<T = any> = (
635
+ options: IEditorStateOptions,
636
+ ) => EditorState<T>;
637
+
638
+ /**
639
+ * A factory used to create a code editor.
640
+ */
641
+ export type CodeEditorFactory<T = EditorState> = (
642
+ options: IEditorOptions,
643
+ state?: T,
644
+ ) => IEditor<T>;
645
+
646
+ export const CodeEditorContribution = Syringe.defineToken('CodeEditorContribution');
647
+ export interface CodeEditorContribution<T = any> {
648
+ canHandle(mime: string): number;
649
+ /**
650
+ * editor factory
651
+ */
652
+ factory: CodeEditorFactory<T>;
653
+ /**
654
+ * editor state factory
655
+ */
656
+ stateFactory?: EditorStateFactory<T>;
657
+ defaultConfig: IEditorConfig;
658
+ }
@@ -0,0 +1,54 @@
1
+ import type { Contribution } from '@difizen/mana-app';
2
+ import { Priority } from '@difizen/mana-app';
3
+ import { contrib } from '@difizen/mana-app';
4
+ import { singleton } from '@difizen/mana-app';
5
+
6
+ import type { IModel } from './code-editor-model.js';
7
+ import type { EditorState, IEditorStateOptions } from './code-editor-protocol.js';
8
+ import { CodeEditorContribution } from './code-editor-protocol.js';
9
+
10
+ @singleton()
11
+ export class CodeEditorStateManager {
12
+ protected readonly codeEditorProvider: Contribution.Provider<CodeEditorContribution>;
13
+ protected stateCache: Map<string, EditorState> = new Map();
14
+
15
+ constructor(
16
+ @contrib(CodeEditorContribution)
17
+ codeEditorProvider: Contribution.Provider<CodeEditorContribution>,
18
+ ) {
19
+ this.codeEditorProvider = codeEditorProvider;
20
+ }
21
+
22
+ protected findCodeEditorProvider(model: IModel) {
23
+ const prioritized = Priority.sortSync(
24
+ this.codeEditorProvider.getContributions(),
25
+ (contribution) => contribution.canHandle(model.mimeType),
26
+ );
27
+ const sorted = prioritized.map((c) => c.value);
28
+ return sorted[0];
29
+ }
30
+
31
+ async getOrCreateEditorState(option: IEditorStateOptions): Promise<EditorState> {
32
+ if (this.stateCache.has(option.uuid)) {
33
+ const state = this.stateCache.get(option.uuid)!;
34
+ return state;
35
+ }
36
+ const factory = this.findCodeEditorProvider(option.model)?.stateFactory;
37
+ if (!factory) {
38
+ throw new Error(
39
+ `no code editor state factory registered for mimetype: ${option.model.mimeType}`,
40
+ );
41
+ }
42
+ const state = factory(option);
43
+ this.stateCache.set(option.uuid, state);
44
+ return state;
45
+ }
46
+
47
+ updateEditorState(id: string, state: EditorState) {
48
+ this.stateCache.set(id, state);
49
+ }
50
+
51
+ removeEditorState(id: string) {
52
+ this.stateCache.delete(id);
53
+ }
54
+ }
@@ -1,8 +1,6 @@
1
- import { getOrigin, prop } from '@difizen/mana-app';
2
1
  import {
3
2
  inject,
4
3
  transient,
5
- Deferred,
6
4
  Emitter,
7
5
  BaseView,
8
6
  ThemeService,
@@ -12,7 +10,6 @@ import {
12
10
  import { forwardRef, memo } from 'react';
13
11
 
14
12
  import { CodeEditorInfoManager } from './code-editor-info-manager.js';
15
- import type { CodeEditorFactory } from './code-editor-manager.js';
16
13
  import type { IModel } from './code-editor-model.js';
17
14
  import type {
18
15
  CompletionProvider,
@@ -21,12 +18,14 @@ import type {
21
18
  IEditor,
22
19
  IEditorSelectionStyle,
23
20
  TooltipProvider,
21
+ CodeEditorFactory,
24
22
  } from './code-editor-protocol.js';
25
23
  import { CodeEditorSettings } from './code-editor-settings.js';
24
+ import { CodeEditorStateManager } from './code-editor-state-manager.js';
26
25
 
27
26
  export const CodeEditorRender = memo(
28
27
  forwardRef<HTMLDivElement>((props, ref) => {
29
- return <div ref={ref} />;
28
+ return <div tabIndex={0} ref={ref} />;
30
29
  }),
31
30
  );
32
31
 
@@ -51,6 +50,8 @@ const DROP_TARGET_CLASS = 'jp-mod-dropTarget';
51
50
  */
52
51
  const leadingWhitespaceRe = /^\s+$/;
53
52
 
53
+ export type CodeEditorViewStatus = 'init' | 'ready' | 'disposed';
54
+
54
55
  /**
55
56
  * A widget which hosts a code editor.
56
57
  */
@@ -59,6 +60,8 @@ const leadingWhitespaceRe = /^\s+$/;
59
60
  export class CodeEditorView extends BaseView {
60
61
  @inject(ThemeService) protected readonly themeService: ThemeService;
61
62
  @inject(CodeEditorSettings) protected readonly codeEditorSettings: CodeEditorSettings;
63
+ @inject(CodeEditorStateManager)
64
+ protected readonly codeEditorStateManager: CodeEditorStateManager;
62
65
 
63
66
  codeEditorInfoManager: CodeEditorInfoManager;
64
67
 
@@ -79,12 +82,16 @@ export class CodeEditorView extends BaseView {
79
82
  /**
80
83
  * Get the editor wrapped by the widget.
81
84
  */
82
- @prop()
83
85
  editor: IEditor;
84
- protected editorReadyDeferred: Deferred<void> = new Deferred<void>();
85
- get editorReady() {
86
- return this.editorReadyDeferred.promise;
87
- }
86
+
87
+ editorStatus: CodeEditorViewStatus = 'init';
88
+
89
+ protected editorStatusChangeEmitter = new Emitter<{
90
+ status: CodeEditorViewStatus;
91
+ prevState: CodeEditorViewStatus;
92
+ }>();
93
+ onEditorStatusChange = this.editorStatusChangeEmitter.event;
94
+
88
95
  /**
89
96
  * Construct a new code editor widget.
90
97
  */
@@ -97,34 +104,60 @@ export class CodeEditorView extends BaseView {
97
104
  this.codeEditorInfoManager = codeEditorInfoManager;
98
105
  }
99
106
 
100
- override async onViewMount() {
101
- const settings = this.codeEditorSettings.getUserEditorSettings();
102
-
107
+ protected getEditorHost() {
103
108
  const editorHostId = this.options.editorHostId;
104
109
  const editorHostRef = editorHostId
105
110
  ? this.codeEditorInfoManager.getEditorHostRef(editorHostId)
106
111
  : undefined;
107
112
 
108
- this.editorHostRef =
109
- editorHostRef && editorHostRef.current ? editorHostRef : this.container;
113
+ return editorHostRef && editorHostRef.current ? editorHostRef : this.container;
114
+ }
115
+
116
+ override async onViewMount() {
117
+ const state = await this.codeEditorStateManager.getOrCreateEditorState({
118
+ uuid: this.options.uuid,
119
+ model: this.options.model,
120
+ });
121
+
122
+ const settings = this.codeEditorSettings.getUserEditorSettings();
123
+
124
+ this.editorHostRef = this.getEditorHost();
110
125
 
111
126
  if (this.editorHostRef.current && this.options.factory) {
112
- this.editor = this.options.factory({
113
- ...this.options,
114
- host: this.editorHostRef.current,
115
- model: this.options.model,
116
- uuid: this.options.uuid,
117
- config: { ...settings, ...this.options.config },
118
- selectionStyle: this.options.selectionStyle,
119
- tooltipProvider: this.options.tooltipProvider,
120
- completionProvider: this.options.completionProvider,
121
- });
122
- this.editorReadyDeferred.resolve();
127
+ this.editor = this.options.factory(
128
+ {
129
+ ...this.options,
130
+ host: this.editorHostRef.current,
131
+ model: this.options.model,
132
+ uuid: this.options.uuid,
133
+ config: { ...settings, ...this.options.config },
134
+ selectionStyle: this.options.selectionStyle,
135
+ tooltipProvider: this.options.tooltipProvider,
136
+ completionProvider: this.options.completionProvider,
137
+ },
138
+ state,
139
+ );
140
+
141
+ await this.editor.editorReady;
142
+
143
+ const { cursorPosition, selections } = state;
144
+
145
+ const prevState = this.editorStatus;
146
+ this.editorStatus = 'ready';
147
+ this.editorStatusChangeEmitter.fire({ status: 'ready', prevState: prevState });
148
+
149
+ if (cursorPosition) {
150
+ this.editor.setCursorPosition(cursorPosition);
151
+ }
152
+ if (selections) {
153
+ this.editor.setSelections(selections);
154
+ }
155
+
123
156
  this.editor.onModalChange((val) => this.modalChangeEmitter.fire(val));
124
157
  // this.editor.model.selections.changed(this._onSelectionsChanged);
125
158
 
126
159
  if (this.options.autoFocus) {
127
- getOrigin(this.editor).focus();
160
+ this.editor.focus();
128
161
  }
129
162
 
130
163
  this.editorHostRef.current.addEventListener('focus', this.onViewActive);
@@ -148,9 +181,19 @@ export class CodeEditorView extends BaseView {
148
181
  };
149
182
 
150
183
  override onViewUnmount = () => {
151
- if (this.editor.dispose) {
152
- this.editor.dispose();
184
+ if (this.editor.hasFocus()) {
185
+ // 保存编辑器状态
186
+ const editorState = this.editor.getState();
187
+ this.codeEditorStateManager.updateEditorState(this.options.uuid, editorState);
188
+ // focus 到 host 避免进入命令模式
189
+ this.editorHostRef = this.getEditorHost();
190
+ this.editorHostRef?.current?.focus();
153
191
  }
192
+ this.editor.dispose();
193
+
194
+ const prevState = this.editorStatus;
195
+ this.editorStatus = 'disposed';
196
+ this.editorStatusChangeEmitter.fire({ status: 'disposed', prevState: prevState });
154
197
 
155
198
  const node = this.editorHostRef?.current;
156
199
  if (node) {
@@ -349,8 +392,9 @@ export interface CodeEditorViewOptions<Config extends IEditorConfig = IEditorCon
349
392
 
350
393
  /**
351
394
  * The desired uuid for the editor.
395
+ * editor share id with cell.
352
396
  */
353
- uuid?: string;
397
+ uuid: string;
354
398
 
355
399
  /**
356
400
  * The configuration options for the editor.
package/src/module.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import { ManaModule } from '@difizen/mana-app';
2
2
 
3
3
  import { CodeEditorInfoManager } from './code-editor-info-manager.js';
4
- import { CodeEditorContribution, CodeEditorManager } from './code-editor-manager.js';
4
+ import { CodeEditorManager } from './code-editor-manager.js';
5
5
  import { Model } from './code-editor-model.js';
6
+ import { CodeEditorContribution } from './code-editor-protocol.js';
6
7
  import { CodeEditorSettings } from './code-editor-settings.js';
8
+ import { CodeEditorStateManager } from './code-editor-state-manager.js';
7
9
  import { CodeEditorView } from './code-editor-view.js';
8
10
 
9
11
  export const CodeEditorModule = ManaModule.create()
@@ -13,5 +15,6 @@ export const CodeEditorModule = ManaModule.create()
13
15
  CodeEditorManager,
14
16
  Model,
15
17
  CodeEditorSettings,
18
+ CodeEditorStateManager,
16
19
  )
17
20
  .contribution(CodeEditorContribution);