@difizen/libro-code-cell 0.2.34 → 0.2.35-next.0

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,23 +1,18 @@
1
1
  /// <reference types="react" resolution-mode="require"/>
2
- import type { CodeEditorViewOptions, CodeEditorView } from '@difizen/libro-code-editor';
2
+ import type { CodeEditorViewOptions } from '@difizen/libro-code-editor';
3
3
  import { CodeEditorManager } from '@difizen/libro-code-editor';
4
4
  import type { IOutput } from '@difizen/libro-common';
5
5
  import type { LibroCell, CellViewOptions } from '@difizen/libro-core';
6
- import { CellService, EditorStatus, LibroExecutableCellView, LibroOutputArea, LibroContextKey } from '@difizen/libro-core';
6
+ import { CellService, EditorStatus, LibroEditableExecutableCellView, LibroOutputArea } from '@difizen/libro-core';
7
7
  import type { ViewSize } from '@difizen/mana-app';
8
- import { DisposableCollection } from '@difizen/mana-app';
9
8
  import { ViewManager, Deferred } from '@difizen/mana-app';
10
9
  import type { LibroCodeCellModel } from './code-cell-model.js';
11
10
  export declare const CellEditorMemo: import("react").NamedExoticComponent<{}>;
12
- export declare class LibroCodeCellView extends LibroExecutableCellView {
13
- protected toDisposeOnEditor: DisposableCollection;
14
- protected readonly libroContextKey: LibroContextKey;
11
+ export declare class LibroCodeCellView extends LibroEditableExecutableCellView {
15
12
  view: import("react").ForwardRefExoticComponent<import("react").RefAttributes<HTMLDivElement>>;
16
13
  viewManager: ViewManager;
17
- codeEditorManager: CodeEditorManager;
18
14
  model: LibroCodeCellModel;
19
15
  outputs: IOutput[];
20
- editorView?: CodeEditorView;
21
16
  editorAreaHeight: number;
22
17
  noEditorAreaHeight: number;
23
18
  cellViewTopPos: number;
@@ -33,12 +28,6 @@ export declare class LibroCodeCellView extends LibroExecutableCellView {
33
28
  onViewMount(): void;
34
29
  setEditorHost(ref: React.RefObject<HTMLDivElement>): void;
35
30
  protected getEditorOption(): CodeEditorViewOptions;
36
- protected createEditor(): Promise<void>;
37
- protected afterEditorReady(): Promise<void>;
38
- protected focusEditor(): void;
39
- shouldEnterEditorMode(e: React.FocusEvent<HTMLElement>): boolean;
40
- blur: () => void;
41
- focus: (toEdit: boolean) => void;
42
31
  clearExecution: () => void;
43
32
  }
44
33
  //# sourceMappingURL=code-cell-view.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"code-cell-view.d.ts","sourceRoot":"","sources":["../src/code-cell-view.tsx"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAa,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAGhE,OAAO,KAAK,EAEV,SAAS,EACT,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,eAAe,EAEf,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAQL,WAAW,EAIX,QAAQ,EACT,MAAM,mBAAmB,CAAC;AAG3B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AA2C/D,eAAO,MAAM,cAAc,0CAAmB,CAAC;AAmB/C,qBAEa,iBAAkB,SAAQ,uBAAuB;IAC5D,SAAS,CAAC,iBAAiB,uBAA8B;IAChC,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;IACpE,IAAI,2FAA2B;IAExC,WAAW,EAAE,WAAW,CAAC;IAEzB,iBAAiB,EAAE,iBAAiB,CAAC;IAE7B,KAAK,EAAE,kBAAkB,CAAC;IAElC,OAAO,EAAE,OAAO,EAAE,CAAC;IAGnB,UAAU,CAAC,EAAE,cAAc,CAAC;IAG5B,gBAAgB,SAAK;IAGZ,kBAAkB,SAAK;IAGvB,cAAc,SAAK;IAGnB,YAAY,EAAE,YAAY,CAA0B;IAE7D,SAAS,CAAC,kBAAkB,4BAAmC;IAC/D,IAAI,eAAe,6BAElB;IAEQ,YAAY,uDAKnB;IAEO,YAAY,CAAC,IAAI,EAAE,QAAQ;IAMpC,oBAAoB;gBAqBE,OAAO,EAAE,eAAe,EACvB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EAClB,iBAAiB,EAAE,iBAAiB;IA6BxD,WAAW;IAQX,MAAM,IAAI,SAAS;IAQnB,WAAW;IAIpB,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC;IAKlD,SAAS,CAAC,eAAe,IAAI,qBAAqB;cAclC,YAAY;cA0BZ,gBAAgB;IAoBhC,SAAS,CAAC,WAAW;IAgBZ,qBAAqB,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC;IAMtD,IAAI,aAGX;IAEO,KAAK,WAAY,OAAO,UAS/B;IAEO,cAAc,aAGrB;CACH"}
1
+ {"version":3,"file":"code-cell-view.d.ts","sourceRoot":"","sources":["../src/code-cell-view.tsx"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAa,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAGhE,OAAO,KAAK,EAEV,SAAS,EACT,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,WAAW,EACX,YAAY,EACZ,+BAA+B,EAC/B,eAAe,EAEhB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAQL,WAAW,EAIX,QAAQ,EACT,MAAM,mBAAmB,CAAC;AAG3B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AA2C/D,eAAO,MAAM,cAAc,0CAAmB,CAAC;AAmB/C,qBAEa,iBAAkB,SAAQ,+BAA+B;IAC3D,IAAI,2FAA2B;IAExC,WAAW,EAAE,WAAW,CAAC;IAEjB,KAAK,EAAE,kBAAkB,CAAC;IAElC,OAAO,EAAE,OAAO,EAAE,CAAC;IAGnB,gBAAgB,SAAK;IAGZ,kBAAkB,SAAK;IAGvB,cAAc,SAAK;IAGnB,YAAY,EAAE,YAAY,CAA0B;IAE7D,SAAS,CAAC,kBAAkB,4BAAmC;IAC/D,IAAI,eAAe,6BAElB;IAEQ,YAAY,uDAKnB;IAEO,YAAY,CAAC,IAAI,EAAE,QAAQ;IAMpC,oBAAoB;gBAqBE,OAAO,EAAE,eAAe,EACvB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EAClB,iBAAiB,EAAE,iBAAiB;IA6BxD,WAAW;IAQX,MAAM,IAAI,SAAS;IAQnB,WAAW;IAIpB,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC;cAK/B,eAAe,IAAI,qBAAqB;IAclD,cAAc,aAGrB;CACH"}
@@ -1,5 +1,5 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6;
2
+ var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4;
3
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
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
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; }
@@ -30,9 +30,7 @@ function _initializerWarningHelper(descriptor, context) { throw new Error('Decor
30
30
  import { CodeEditorManager } from '@difizen/libro-code-editor';
31
31
  import { CellUri } from '@difizen/libro-common';
32
32
  import { isOutput } from '@difizen/libro-common';
33
- import { CellService, EditorStatus, LibroExecutableCellView, LibroOutputArea, VirtualizedManagerHelper, LibroContextKey } from '@difizen/libro-core';
34
- import { Disposable } from '@difizen/mana-app';
35
- import { DisposableCollection } from '@difizen/mana-app';
33
+ import { CellService, EditorStatus, LibroEditableExecutableCellView, LibroOutputArea, VirtualizedManagerHelper } from '@difizen/libro-core';
36
34
  import { getOrigin, inject, prop, transient, useInject, view, ViewInstance, ViewManager, ViewOption, ViewRender, watch, Deferred } from '@difizen/mana-app';
37
35
  import { useEffect, useRef, memo, forwardRef } from 'react';
38
36
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -86,25 +84,21 @@ var CodeEditorViewComponent = /*#__PURE__*/forwardRef(function CodeEditorViewCom
86
84
  children: /*#__PURE__*/_jsx(CellEditorMemo, {})
87
85
  });
88
86
  });
89
- export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-cell-view'), _dec3 = inject(LibroContextKey), _dec4 = prop(), _dec5 = prop(), _dec6 = prop(), _dec7 = prop(), _dec8 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroExecutableCellV) {
90
- _inherits(LibroCodeCellView, _LibroExecutableCellV);
87
+ export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-cell-view'), _dec3 = prop(), _dec4 = prop(), _dec5 = prop(), _dec6 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroEditableExecuta) {
88
+ _inherits(LibroCodeCellView, _LibroEditableExecuta);
91
89
  var _super = _createSuper(LibroCodeCellView);
92
90
  function LibroCodeCellView(options, cellService, viewManager, codeEditorManager) {
93
91
  var _options$cell;
94
92
  var _this;
95
93
  _classCallCheck(this, LibroCodeCellView);
96
94
  _this = _super.call(this, options, cellService);
97
- _this.toDisposeOnEditor = new DisposableCollection();
98
- _initializerDefineProperty(_this, "libroContextKey", _descriptor, _assertThisInitialized(_this));
99
95
  _this.view = CodeEditorViewComponent;
100
96
  _this.viewManager = void 0;
101
- _this.codeEditorManager = void 0;
102
97
  _this.outputs = void 0;
103
- _initializerDefineProperty(_this, "editorView", _descriptor2, _assertThisInitialized(_this));
104
- _initializerDefineProperty(_this, "editorAreaHeight", _descriptor3, _assertThisInitialized(_this));
105
- _initializerDefineProperty(_this, "noEditorAreaHeight", _descriptor4, _assertThisInitialized(_this));
106
- _initializerDefineProperty(_this, "cellViewTopPos", _descriptor5, _assertThisInitialized(_this));
107
- _initializerDefineProperty(_this, "editorStatus", _descriptor6, _assertThisInitialized(_this));
98
+ _initializerDefineProperty(_this, "editorAreaHeight", _descriptor, _assertThisInitialized(_this));
99
+ _initializerDefineProperty(_this, "noEditorAreaHeight", _descriptor2, _assertThisInitialized(_this));
100
+ _initializerDefineProperty(_this, "cellViewTopPos", _descriptor3, _assertThisInitialized(_this));
101
+ _initializerDefineProperty(_this, "editorStatus", _descriptor4, _assertThisInitialized(_this));
108
102
  _this.outputAreaDeferred = new Deferred();
109
103
  _this.renderEditor = function () {
110
104
  if (_this.editorView) {
@@ -114,22 +108,6 @@ export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-ce
114
108
  }
115
109
  return null;
116
110
  };
117
- _this.blur = function () {
118
- var _this$editorView, _this$editorView2;
119
- (_this$editorView = _this.editorView) === null || _this$editorView === void 0 || (_this$editorView = _this$editorView.editor) === null || _this$editorView === void 0 || _this$editorView.setOption('styleActiveLine', false);
120
- (_this$editorView2 = _this.editorView) === null || _this$editorView2 === void 0 || (_this$editorView2 = _this$editorView2.editor) === null || _this$editorView2 === void 0 || _this$editorView2.setOption('highlightActiveLineGutter', false);
121
- };
122
- _this.focus = function (toEdit) {
123
- if (toEdit) {
124
- _this.focusEditor();
125
- } else {
126
- var _this$container, _this$container2;
127
- if ((_this$container = _this.container) !== null && _this$container !== void 0 && (_this$container = _this$container.current) !== null && _this$container !== void 0 && (_this$container = _this$container.parentElement) !== null && _this$container !== void 0 && _this$container.contains(document.activeElement)) {
128
- return;
129
- }
130
- (_this$container2 = _this.container) === null || _this$container2 === void 0 || (_this$container2 = _this$container2.current) === null || _this$container2 === void 0 || (_this$container2 = _this$container2.parentElement) === null || _this$container2 === void 0 || _this$container2.focus();
131
- }
132
- };
133
111
  _this.clearExecution = function () {
134
112
  _this.model.clearExecution();
135
113
  _this.outputArea.clear();
@@ -252,143 +230,30 @@ export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-ce
252
230
  };
253
231
  return option;
254
232
  }
255
- }, {
256
- key: "createEditor",
257
- value: function () {
258
- var _createEditor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
259
- var _this3 = this;
260
- var option, editorView;
261
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
262
- while (1) switch (_context2.prev = _context2.next) {
263
- case 0:
264
- option = this.getEditorOption();
265
- this.editorStatus = EditorStatus.LOADING;
266
-
267
- // 防止虚拟滚动中编辑器被频繁创建
268
- if (!this.editorView) {
269
- _context2.next = 5;
270
- break;
271
- }
272
- this.editorStatus = EditorStatus.LOADED;
273
- return _context2.abrupt("return");
274
- case 5:
275
- _context2.next = 7;
276
- return this.codeEditorManager.getOrCreateEditorView(option);
277
- case 7:
278
- editorView = _context2.sent;
279
- this.editorView = editorView;
280
- this.editorStatus = EditorStatus.LOADED;
281
- editorView.onEditorStatusChange(function (e) {
282
- if (e.status === 'ready') {
283
- _this3.editor = _this3.editorView.editor;
284
- _this3.afterEditorReady();
285
- } else if (e.status === 'disposed') {
286
- _this3.toDisposeOnEditor.dispose();
287
- }
288
- });
289
- case 11:
290
- case "end":
291
- return _context2.stop();
292
- }
293
- }, _callee2, this);
294
- }));
295
- function createEditor() {
296
- return _createEditor.apply(this, arguments);
297
- }
298
- return createEditor;
299
- }()
300
- }, {
301
- key: "afterEditorReady",
302
- value: function () {
303
- var _afterEditorReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
304
- var _this4 = this,
305
- _this$editorView$onMo,
306
- _this$editorView3,
307
- _this$editor$onModelC,
308
- _this$editor,
309
- _this$editor$onModelC2;
310
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
311
- while (1) switch (_context3.prev = _context3.next) {
312
- case 0:
313
- this.focusEditor();
314
- this.toDisposeOnEditor.push(watch(this.parent.model, 'inputEditable', function () {
315
- var _this4$editorView;
316
- (_this4$editorView = _this4.editorView) === null || _this4$editorView === void 0 || (_this4$editorView = _this4$editorView.editor) === null || _this4$editorView === void 0 || _this4$editorView.setOption('readOnly', getOrigin(!_this4.parent.model.inputEditable));
317
- }));
318
- this.toDisposeOnEditor.push((_this$editorView$onMo = (_this$editorView3 = this.editorView) === null || _this$editorView3 === void 0 ? void 0 : _this$editorView3.onModalChange(function (val) {
319
- return _this4.hasModal = val;
320
- })) !== null && _this$editorView$onMo !== void 0 ? _this$editorView$onMo : Disposable.NONE);
321
- this.toDisposeOnEditor.push((_this$editor$onModelC = (_this$editor = this.editor) === null || _this$editor === void 0 || (_this$editor$onModelC2 = _this$editor.onModelContentChanged) === null || _this$editor$onModelC2 === void 0 ? void 0 : _this$editor$onModelC2.call(_this$editor, function (e) {
322
- _this4.parent.model.onCellContentChange({
323
- cell: _this4,
324
- changes: e
325
- });
326
- })) !== null && _this$editor$onModelC !== void 0 ? _this$editor$onModelC : Disposable.NONE);
327
- case 4:
328
- case "end":
329
- return _context3.stop();
330
- }
331
- }, _callee3, this);
332
- }));
333
- function afterEditorReady() {
334
- return _afterEditorReady.apply(this, arguments);
335
- }
336
- return afterEditorReady;
337
- }()
338
- }, {
339
- key: "focusEditor",
340
- value: function focusEditor() {
341
- var _this$editorView4, _this$parent$model$ac;
342
- //选中cell、编辑模式、非只读时才focus
343
- if ((_this$editorView4 = this.editorView) !== null && _this$editorView4 !== void 0 && _this$editorView4.editor && this.editorView.editorStatus === 'ready' && ((_this$parent$model$ac = this.parent.model.active) === null || _this$parent$model$ac === void 0 ? void 0 : _this$parent$model$ac.id) === this.id && !this.parent.model.commandMode && this.libroContextKey.commandModeEnabled === true &&
344
- // 排除弹窗等情况
345
- this.parent.model.inputEditable) {
346
- var _this$editorView5, _this$editorView6, _this$editorView7;
347
- (_this$editorView5 = this.editorView) === null || _this$editorView5 === void 0 || _this$editorView5.editor.setOption('styleActiveLine', true);
348
- (_this$editorView6 = this.editorView) === null || _this$editorView6 === void 0 || _this$editorView6.editor.setOption('highlightActiveLineGutter', true);
349
- (_this$editorView7 = this.editorView) === null || _this$editorView7 === void 0 || _this$editorView7.editor.focus();
350
- }
351
- }
352
- }, {
353
- key: "shouldEnterEditorMode",
354
- value: function shouldEnterEditorMode(e) {
355
- var _getOrigin;
356
- return (_getOrigin = getOrigin(this.editorView)) !== null && _getOrigin !== void 0 && (_getOrigin = _getOrigin.editor) !== null && _getOrigin !== void 0 && (_getOrigin = _getOrigin.host) !== null && _getOrigin !== void 0 && _getOrigin.contains(e.target) ? true : false;
357
- }
358
233
  }]);
359
234
  return LibroCodeCellView;
360
- }(LibroExecutableCellView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "libroContextKey", [_dec3], {
361
- configurable: true,
362
- enumerable: true,
363
- writable: true,
364
- initializer: null
365
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "editorView", [_dec4], {
366
- configurable: true,
367
- enumerable: true,
368
- writable: true,
369
- initializer: null
370
- }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "editorAreaHeight", [_dec5], {
235
+ }(LibroEditableExecutableCellView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "editorAreaHeight", [_dec3], {
371
236
  configurable: true,
372
237
  enumerable: true,
373
238
  writable: true,
374
239
  initializer: function initializer() {
375
240
  return 0;
376
241
  }
377
- }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "noEditorAreaHeight", [_dec6], {
242
+ }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "noEditorAreaHeight", [_dec4], {
378
243
  configurable: true,
379
244
  enumerable: true,
380
245
  writable: true,
381
246
  initializer: function initializer() {
382
247
  return 0;
383
248
  }
384
- }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "cellViewTopPos", [_dec7], {
249
+ }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "cellViewTopPos", [_dec5], {
385
250
  configurable: true,
386
251
  enumerable: true,
387
252
  writable: true,
388
253
  initializer: function initializer() {
389
254
  return 0;
390
255
  }
391
- }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "editorStatus", [_dec8], {
256
+ }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "editorStatus", [_dec6], {
392
257
  configurable: true,
393
258
  enumerable: true,
394
259
  writable: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@difizen/libro-code-cell",
3
- "version": "0.2.34",
3
+ "version": "0.2.35-next.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "libro",
@@ -32,9 +32,9 @@
32
32
  "src"
33
33
  ],
34
34
  "dependencies": {
35
- "@difizen/libro-code-editor": "^0.2.34",
36
- "@difizen/libro-common": "^0.2.34",
37
- "@difizen/libro-core": "^0.2.34",
35
+ "@difizen/libro-code-editor": "^0.2.35-next.0",
36
+ "@difizen/libro-common": "^0.2.35-next.0",
37
+ "@difizen/libro-core": "^0.2.35-next.0",
38
38
  "@difizen/mana-app": "latest"
39
39
  },
40
40
  "peerDependencies": {
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable react-hooks/exhaustive-deps */
2
2
  /* eslint-disable @typescript-eslint/no-parameter-properties */
3
3
  /* eslint-disable @typescript-eslint/parameter-properties */
4
- import type { CodeEditorViewOptions, CodeEditorView } from '@difizen/libro-code-editor';
4
+ import type { CodeEditorViewOptions } from '@difizen/libro-code-editor';
5
5
  import { CodeEditorManager } from '@difizen/libro-code-editor';
6
6
  import type { ICodeCell, IOutput } from '@difizen/libro-common';
7
7
  import { CellUri } from '@difizen/libro-common';
@@ -14,14 +14,11 @@ import type {
14
14
  import {
15
15
  CellService,
16
16
  EditorStatus,
17
- LibroExecutableCellView,
17
+ LibroEditableExecutableCellView,
18
18
  LibroOutputArea,
19
19
  VirtualizedManagerHelper,
20
- LibroContextKey,
21
20
  } from '@difizen/libro-core';
22
21
  import type { ViewSize } from '@difizen/mana-app';
23
- import { Disposable } from '@difizen/mana-app';
24
- import { DisposableCollection } from '@difizen/mana-app';
25
22
  import {
26
23
  getOrigin,
27
24
  inject,
@@ -102,22 +99,15 @@ const CodeEditorViewComponent = forwardRef<HTMLDivElement>(
102
99
 
103
100
  @transient()
104
101
  @view('code-editor-cell-view')
105
- export class LibroCodeCellView extends LibroExecutableCellView {
106
- protected toDisposeOnEditor = new DisposableCollection();
107
- @inject(LibroContextKey) protected readonly libroContextKey: LibroContextKey;
102
+ export class LibroCodeCellView extends LibroEditableExecutableCellView {
108
103
  override view = CodeEditorViewComponent;
109
104
 
110
105
  viewManager: ViewManager;
111
106
 
112
- codeEditorManager: CodeEditorManager;
113
-
114
107
  declare model: LibroCodeCellModel;
115
108
 
116
109
  outputs: IOutput[];
117
110
 
118
- @prop()
119
- editorView?: CodeEditorView;
120
-
121
111
  @prop()
122
112
  editorAreaHeight = 0;
123
113
 
@@ -226,7 +216,7 @@ export class LibroCodeCellView extends LibroExecutableCellView {
226
216
  this.codeEditorManager.setEditorHostRef(editorHostId, ref);
227
217
  }
228
218
 
229
- protected getEditorOption(): CodeEditorViewOptions {
219
+ protected override getEditorOption(): CodeEditorViewOptions {
230
220
  const option: CodeEditorViewOptions = {
231
221
  uuid: CellUri.from(this.parent.model.id, this.model.id).toString(),
232
222
  editorHostId: this.parent.id + this.id,
@@ -240,90 +230,6 @@ export class LibroCodeCellView extends LibroExecutableCellView {
240
230
  return option;
241
231
  }
242
232
 
243
- protected async createEditor() {
244
- const option = this.getEditorOption();
245
-
246
- this.editorStatus = EditorStatus.LOADING;
247
-
248
- // 防止虚拟滚动中编辑器被频繁创建
249
- if (this.editorView) {
250
- this.editorStatus = EditorStatus.LOADED;
251
- return;
252
- }
253
-
254
- const editorView = await this.codeEditorManager.getOrCreateEditorView(option);
255
-
256
- this.editorView = editorView;
257
- this.editorStatus = EditorStatus.LOADED;
258
-
259
- editorView.onEditorStatusChange((e) => {
260
- if (e.status === 'ready') {
261
- this.editor = this.editorView!.editor;
262
- this.afterEditorReady();
263
- } else if (e.status === 'disposed') {
264
- this.toDisposeOnEditor.dispose();
265
- }
266
- });
267
- }
268
-
269
- protected async afterEditorReady() {
270
- this.focusEditor();
271
- this.toDisposeOnEditor.push(
272
- watch(this.parent.model, 'inputEditable', () => {
273
- this.editorView?.editor?.setOption(
274
- 'readOnly',
275
- getOrigin(!this.parent.model.inputEditable),
276
- );
277
- }),
278
- );
279
- this.toDisposeOnEditor.push(
280
- this.editorView?.onModalChange((val) => (this.hasModal = val)) ?? Disposable.NONE,
281
- );
282
- this.toDisposeOnEditor.push(
283
- this.editor?.onModelContentChanged?.((e) => {
284
- this.parent.model.onCellContentChange({ cell: this, changes: e });
285
- }) ?? Disposable.NONE,
286
- );
287
- }
288
-
289
- protected focusEditor() {
290
- //选中cell、编辑模式、非只读时才focus
291
- if (
292
- this.editorView?.editor &&
293
- this.editorView.editorStatus === 'ready' &&
294
- this.parent.model.active?.id === this.id &&
295
- !this.parent.model.commandMode &&
296
- this.libroContextKey.commandModeEnabled === true && // 排除弹窗等情况
297
- this.parent.model.inputEditable
298
- ) {
299
- this.editorView?.editor.setOption('styleActiveLine', true);
300
- this.editorView?.editor.setOption('highlightActiveLineGutter', true);
301
- this.editorView?.editor.focus();
302
- }
303
- }
304
-
305
- override shouldEnterEditorMode(e: React.FocusEvent<HTMLElement>) {
306
- return getOrigin(this.editorView)?.editor?.host?.contains(e.target as HTMLElement)
307
- ? true
308
- : false;
309
- }
310
-
311
- override blur = () => {
312
- this.editorView?.editor?.setOption('styleActiveLine', false);
313
- this.editorView?.editor?.setOption('highlightActiveLineGutter', false);
314
- };
315
-
316
- override focus = (toEdit: boolean) => {
317
- if (toEdit) {
318
- this.focusEditor();
319
- } else {
320
- if (this.container?.current?.parentElement?.contains(document.activeElement)) {
321
- return;
322
- }
323
- this.container?.current?.parentElement?.focus();
324
- }
325
- };
326
-
327
233
  override clearExecution = () => {
328
234
  this.model.clearExecution();
329
235
  this.outputArea.clear();