@difizen/libro-prompt-cell 0.2.34 → 0.2.35

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,9 +1,8 @@
1
- import { CodeEditorManager } from '@difizen/libro-code-editor';
2
- import type { CodeEditorViewOptions, IRange, CodeEditorView } from '@difizen/libro-code-editor';
1
+ import type { IRange } from '@difizen/libro-code-editor';
3
2
  import type { IOutput } from '@difizen/libro-common';
4
3
  import type { LibroCell, CellViewOptions } from '@difizen/libro-core';
5
4
  import { LibroOutputArea } from '@difizen/libro-core';
6
- import { CellService, LibroExecutableCellView, LibroViewTracker, LibroContextKey } from '@difizen/libro-core';
5
+ import { CellService, LibroEditableExecutableCellView } from '@difizen/libro-core';
7
6
  import type { KernelMessage } from '@difizen/libro-jupyter';
8
7
  import { ViewManager } from '@difizen/mana-app';
9
8
  import { Deferred } from '@difizen/mana-app';
@@ -23,8 +22,7 @@ export interface ChatObjectOptions {
23
22
  color?: string;
24
23
  }
25
24
  export declare const CellEditor: React.NamedExoticComponent<{}>;
26
- export declare class LibroPromptCellView extends LibroExecutableCellView {
27
- protected libroContextKey: LibroContextKey;
25
+ export declare class LibroPromptCellView extends LibroEditableExecutableCellView {
28
26
  view: React.ForwardRefExoticComponent<React.RefAttributes<HTMLDivElement>>;
29
27
  model: LibroPromptCellModel;
30
28
  chatObjects: ChatObject[];
@@ -32,24 +30,15 @@ export declare class LibroPromptCellView extends LibroExecutableCellView {
32
30
  get sortedChatObjects(): ChatObject[];
33
31
  get chatRecords(): string[];
34
32
  viewManager: ViewManager;
35
- codeEditorManager: CodeEditorManager;
36
33
  promptScript: PromptScript;
37
34
  outputs: IOutput[];
38
- libroViewTracker: LibroViewTracker;
39
- editorView?: CodeEditorView;
40
35
  protected outputAreaDeferred: Deferred<LibroOutputArea>;
41
36
  get outputAreaReady(): Promise<LibroOutputArea>;
42
- constructor(options: CellViewOptions, cellService: CellService, viewManager: ViewManager, libroViewTracker: LibroViewTracker);
37
+ constructor(options: CellViewOptions, cellService: CellService, viewManager: ViewManager);
43
38
  outputWatch(): void;
44
39
  toJSON(): LibroCell;
45
- onViewMount(): void;
46
- protected getEditorOption(): CodeEditorViewOptions;
47
- createEditor(): Promise<void>;
48
- protected afterEditorReady(): Promise<void>;
49
40
  shouldEnterEditorMode(e: React.FocusEvent<HTMLElement>): boolean;
50
41
  blur: () => void;
51
- protected focusEditor(): void;
52
- focus: (toEdit: boolean) => void;
53
42
  clearExecution: () => void;
54
43
  getSelections: () => [];
55
44
  getSelectionsOffsetAt: (selection: IRange) => {
@@ -1 +1 @@
1
- {"version":3,"file":"prompt-cell-view.d.ts","sourceRoot":"","sources":["../src/prompt-cell-view.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EACV,qBAAqB,EACrB,MAAM,EACN,cAAc,EACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAa,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAGhE,OAAO,KAAK,EAEV,SAAS,EACT,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EACL,WAAW,EACX,uBAAuB,EACvB,gBAAgB,EAEhB,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE3E,OAAO,EAQL,WAAW,EAIZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG7C,OAAO,KAA8B,MAAM,OAAO,CAAC;AAGnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,cAAc,CAAC;AAEtB,MAAM,WAAW,UAAU;IACzB,IA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AAK,IAAI,UA6B5B;IAEF,0BAA0B,iBAAkB,MAAM,aAQhD;IACF,qBAAqB,UAAW,MAAM,UAEpC;IACF,wBAAwB,UAAW,MAAM,UAEvC;IACF,kBAAkB,UAAW,MAAM,GAAG,SAAS,UAE7C;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, _class, _class2, _descriptor, _descriptor2, _descriptor3;
3
3
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
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
5
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
@@ -33,11 +33,9 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
33
33
  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; }
34
34
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
35
35
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
36
- import { CodeEditorManager } from '@difizen/libro-code-editor';
37
- import { CellUri } from '@difizen/libro-common';
38
36
  import { isOutput } from '@difizen/libro-common';
39
37
  import { LibroOutputArea } from '@difizen/libro-core';
40
- import { CellService, LibroExecutableCellView, LibroViewTracker, EditorStatus, LibroContextKey } from '@difizen/libro-core';
38
+ import { CellService, LibroEditableExecutableCellView } from '@difizen/libro-core';
41
39
  import { KernelError, LibroJupyterModel } from '@difizen/libro-jupyter';
42
40
  import { getOrigin, inject, prop, transient, useInject, view, ViewInstance, ViewManager, ViewOption, ViewRender, watch } from '@difizen/mana-app';
43
41
  import { Deferred } from '@difizen/mana-app';
@@ -208,42 +206,27 @@ var PropmtEditorViewComponent = /*#__PURE__*/React.forwardRef(function MaxPropmt
208
206
  }), /*#__PURE__*/_jsx(CellEditor, {})]
209
207
  });
210
208
  });
211
- export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-editor-cell-view'), _dec3 = inject(LibroContextKey), _dec4 = prop(), _dec5 = prop(), _dec6 = inject(CodeEditorManager), _dec7 = inject(PromptScript), _dec8 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroExecutableCellV) {
212
- _inherits(LibroPromptCellView, _LibroExecutableCellV);
209
+ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-editor-cell-view'), _dec3 = prop(), _dec4 = prop(), _dec5 = inject(PromptScript), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroEditableExecuta) {
210
+ _inherits(LibroPromptCellView, _LibroEditableExecuta);
213
211
  var _super = _createSuper(LibroPromptCellView);
214
- function LibroPromptCellView(options, cellService, viewManager, libroViewTracker) {
212
+ function LibroPromptCellView(options, cellService, viewManager) {
215
213
  var _options$cell;
216
214
  var _this;
217
215
  _classCallCheck(this, LibroPromptCellView);
218
216
  _this = _super.call(this, options, cellService);
219
- _initializerDefineProperty(_this, "libroContextKey", _descriptor, _assertThisInitialized(_this));
220
217
  _this.view = PropmtEditorViewComponent;
221
218
  // TODO: Chat objects and chat message records should belong to libro rather than cell
222
- _initializerDefineProperty(_this, "chatObjects", _descriptor2, _assertThisInitialized(_this));
223
- _initializerDefineProperty(_this, "contextChatRecords", _descriptor3, _assertThisInitialized(_this));
219
+ _initializerDefineProperty(_this, "chatObjects", _descriptor, _assertThisInitialized(_this));
220
+ _initializerDefineProperty(_this, "contextChatRecords", _descriptor2, _assertThisInitialized(_this));
224
221
  _this.viewManager = void 0;
225
- _initializerDefineProperty(_this, "codeEditorManager", _descriptor4, _assertThisInitialized(_this));
226
- _initializerDefineProperty(_this, "promptScript", _descriptor5, _assertThisInitialized(_this));
222
+ _initializerDefineProperty(_this, "promptScript", _descriptor3, _assertThisInitialized(_this));
227
223
  _this.outputs = void 0;
228
- _this.libroViewTracker = void 0;
229
- _initializerDefineProperty(_this, "editorView", _descriptor6, _assertThisInitialized(_this));
230
224
  _this.outputAreaDeferred = new Deferred();
231
225
  _this.blur = function () {
232
226
  var _this$editorView, _this$editorView2;
233
227
  (_this$editorView = _this.editorView) === null || _this$editorView === void 0 || (_this$editorView = _this$editorView.editor) === null || _this$editorView === void 0 || _this$editorView.setOption('styleActiveLine', false);
234
228
  (_this$editorView2 = _this.editorView) === null || _this$editorView2 === void 0 || (_this$editorView2 = _this$editorView2.editor) === null || _this$editorView2 === void 0 || _this$editorView2.setOption('highlightActiveLineGutter', false);
235
229
  };
236
- _this.focus = function (toEdit) {
237
- if (toEdit) {
238
- _this.focusEditor();
239
- } else {
240
- var _this$container, _this$container2;
241
- 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)) {
242
- return;
243
- }
244
- (_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();
245
- }
246
- };
247
230
  _this.clearExecution = function () {
248
231
  _this.model.clearExecution();
249
232
  _this.outputArea.clear();
@@ -395,7 +378,6 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
395
378
  _this.viewManager = viewManager;
396
379
  _this.className = _this.className + ' prompt';
397
380
  _this.outputs = (_options$cell = options.cell) === null || _options$cell === void 0 ? void 0 : _options$cell.outputs;
398
- _this.libroViewTracker = libroViewTracker;
399
381
 
400
382
  // 创建outputArea
401
383
  _this.viewManager.getOrCreateView(LibroOutputArea, {
@@ -433,7 +415,6 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
433
415
  });
434
416
  return _this;
435
417
  }
436
- LibroPromptCellView = inject(LibroViewTracker)(LibroPromptCellView, undefined, 3) || LibroPromptCellView;
437
418
  LibroPromptCellView = inject(ViewManager)(LibroPromptCellView, undefined, 2) || LibroPromptCellView;
438
419
  LibroPromptCellView = inject(CellService)(LibroPromptCellView, undefined, 1) || LibroPromptCellView;
439
420
  LibroPromptCellView = inject(ViewOption)(LibroPromptCellView, undefined, 0) || LibroPromptCellView;
@@ -509,134 +490,31 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
509
490
  outputs: (_this$outputArea$toJS = (_this$outputArea = this.outputArea) === null || _this$outputArea === void 0 ? void 0 : _this$outputArea.toJSON()) !== null && _this$outputArea$toJS !== void 0 ? _this$outputArea$toJS : this.outputs
510
491
  });
511
492
  }
512
- }, {
513
- key: "onViewMount",
514
- value: function onViewMount() {
515
- var _this$parent$model$ac;
516
- this.createEditor();
517
- //选中cell时才focus
518
- if (((_this$parent$model$ac = this.parent.model.active) === null || _this$parent$model$ac === void 0 ? void 0 : _this$parent$model$ac.id) === this.id) {
519
- this.focus(!this.parent.model.commandMode);
520
- }
521
- }
522
- }, {
523
- key: "getEditorOption",
524
- value: function getEditorOption() {
525
- var option = {
526
- uuid: CellUri.from(this.parent.model.id, this.model.id).toString(),
527
- editorHostId: this.parent.id + this.id,
528
- model: this.model,
529
- config: {
530
- readOnly: !this.parent.model.inputEditable,
531
- editable: this.parent.model.inputEditable
532
- }
533
- };
534
- return option;
535
- }
536
- }, {
537
- key: "createEditor",
538
- value: function () {
539
- var _createEditor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
540
- var option, editorView;
541
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
542
- while (1) switch (_context6.prev = _context6.next) {
543
- case 0:
544
- option = this.getEditorOption();
545
- this.editorStatus = EditorStatus.LOADING;
546
-
547
- // 防止虚拟滚动中编辑器被频繁创建
548
- if (!this.editorView) {
549
- _context6.next = 5;
550
- break;
551
- }
552
- this.editorStatus = EditorStatus.LOADED;
553
- return _context6.abrupt("return");
554
- case 5:
555
- _context6.next = 7;
556
- return this.codeEditorManager.getOrCreateEditorView(option);
557
- case 7:
558
- editorView = _context6.sent;
559
- this.editorView = editorView;
560
- this.editorStatus = EditorStatus.LOADED;
561
- _context6.next = 12;
562
- return this.afterEditorReady();
563
- case 12:
564
- case "end":
565
- return _context6.stop();
566
- }
567
- }, _callee6, this);
568
- }));
569
- function createEditor() {
570
- return _createEditor.apply(this, arguments);
571
- }
572
- return createEditor;
573
- }()
574
- }, {
575
- key: "afterEditorReady",
576
- value: function () {
577
- var _afterEditorReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
578
- var _this3 = this,
579
- _this$editorView3;
580
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
581
- while (1) switch (_context7.prev = _context7.next) {
582
- case 0:
583
- watch(this.parent.model, 'inputEditable', function () {
584
- var _this3$editorView;
585
- (_this3$editorView = _this3.editorView) === null || _this3$editorView === void 0 || (_this3$editorView = _this3$editorView.editor) === null || _this3$editorView === void 0 || _this3$editorView.setOption('readOnly', getOrigin(!_this3.parent.model.inputEditable));
586
- });
587
- (_this$editorView3 = this.editorView) === null || _this$editorView3 === void 0 || _this$editorView3.onModalChange(function (val) {
588
- return _this3.hasModal = val;
589
- });
590
- case 2:
591
- case "end":
592
- return _context7.stop();
593
- }
594
- }, _callee7, this);
595
- }));
596
- function afterEditorReady() {
597
- return _afterEditorReady.apply(this, arguments);
598
- }
599
- return afterEditorReady;
600
- }()
601
493
  }, {
602
494
  key: "shouldEnterEditorMode",
603
495
  value: function shouldEnterEditorMode(e) {
604
496
  var _getOrigin;
605
497
  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) && this.parent.model.commandMode ? true : false;
606
498
  }
607
- }, {
608
- key: "focusEditor",
609
- value: function focusEditor() {
610
- var _this$editorView4, _this$parent$model$ac2;
611
- //选中cell、编辑模式、非只读时才focus
612
- if ((_this$editorView4 = this.editorView) !== null && _this$editorView4 !== void 0 && _this$editorView4.editor && this.editorView.editorStatus === 'ready' && ((_this$parent$model$ac2 = this.parent.model.active) === null || _this$parent$model$ac2 === void 0 ? void 0 : _this$parent$model$ac2.id) === this.id && !this.parent.model.commandMode && this.libroContextKey.commandModeEnabled === true &&
613
- // 排除弹窗等情况
614
- this.parent.model.inputEditable) {
615
- var _this$editorView5, _this$editorView6, _this$editorView7;
616
- (_this$editorView5 = this.editorView) === null || _this$editorView5 === void 0 || _this$editorView5.editor.setOption('styleActiveLine', true);
617
- (_this$editorView6 = this.editorView) === null || _this$editorView6 === void 0 || _this$editorView6.editor.setOption('highlightActiveLineGutter', true);
618
- (_this$editorView7 = this.editorView) === null || _this$editorView7 === void 0 || _this$editorView7.editor.focus();
619
- }
620
- }
621
499
  }, {
622
500
  key: "run",
623
501
  value: function () {
624
- var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
625
- var _this4 = this;
502
+ var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
503
+ var _this3 = this;
626
504
  var libroModel, kernelConnection, cellContent, future, startTimeStr, msgPromise, endTimeStr;
627
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
628
- while (1) switch (_context8.prev = _context8.next) {
505
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
506
+ while (1) switch (_context6.prev = _context6.next) {
629
507
  case 0:
630
508
  libroModel = this.parent.model;
631
509
  if (!(!libroModel || !(libroModel instanceof LibroJupyterModel) || !libroModel.kernelConnection || libroModel.kernelConnection.isDisposed)) {
632
- _context8.next = 3;
510
+ _context6.next = 3;
633
511
  break;
634
512
  }
635
- return _context8.abrupt("return", false);
513
+ return _context6.abrupt("return", false);
636
514
  case 3:
637
515
  kernelConnection = getOrigin(libroModel.kernelConnection);
638
516
  cellContent = this.model.source;
639
- _context8.prev = 5;
517
+ _context6.prev = 5;
640
518
  // Promise.resolve().then(() => {
641
519
  this.clearExecution();
642
520
  // });
@@ -653,23 +531,23 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
653
531
 
654
532
  // Handle iopub messages
655
533
  future.onIOPub = function (msg) {
656
- _this4.model.msgChangeEmitter.fire(msg);
534
+ _this3.model.msgChangeEmitter.fire(msg);
657
535
  if (msg.header.msg_type === 'execute_input') {
658
- _this4.model.kernelExecuting = true;
536
+ _this3.model.kernelExecuting = true;
659
537
  startTimeStr = msg.header.date;
660
- var meta = _this4.model.metadata.execution;
538
+ var meta = _this3.model.metadata.execution;
661
539
  if (meta) {
662
540
  meta['shell.execute_reply.started'] = startTimeStr;
663
541
  }
664
542
  }
665
543
  if (msg.header.msg_type === 'error') {
666
- _this4.model.hasExecutedError = true;
544
+ _this3.model.hasExecutedError = true;
667
545
  }
668
546
  };
669
- _context8.next = 14;
547
+ _context6.next = 14;
670
548
  return future.done;
671
549
  case 14:
672
- msgPromise = _context8.sent;
550
+ msgPromise = _context6.sent;
673
551
  this.model.executing = false;
674
552
  this.model.kernelExecuting = false;
675
553
  this.model.hasExecutedSuccess = !this.model.hasExecutedError;
@@ -678,36 +556,36 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
678
556
  this.model.metadata['execution']['shell.execute_reply.started'] = startTimeStr;
679
557
  this.model.metadata['execution']['shell.execute_reply.end'] = endTimeStr;
680
558
  if (msgPromise) {
681
- _context8.next = 24;
559
+ _context6.next = 24;
682
560
  break;
683
561
  }
684
- return _context8.abrupt("return", true);
562
+ return _context6.abrupt("return", true);
685
563
  case 24:
686
564
  if (!(msgPromise.content.status === 'ok')) {
687
- _context8.next = 28;
565
+ _context6.next = 28;
688
566
  break;
689
567
  }
690
- return _context8.abrupt("return", true);
568
+ return _context6.abrupt("return", true);
691
569
  case 28:
692
570
  throw new KernelError(msgPromise.content);
693
571
  case 29:
694
- _context8.next = 36;
572
+ _context6.next = 36;
695
573
  break;
696
574
  case 31:
697
- _context8.prev = 31;
698
- _context8.t0 = _context8["catch"](5);
699
- if (!_context8.t0.message.startsWith('Canceled')) {
700
- _context8.next = 35;
575
+ _context6.prev = 31;
576
+ _context6.t0 = _context6["catch"](5);
577
+ if (!_context6.t0.message.startsWith('Canceled')) {
578
+ _context6.next = 35;
701
579
  break;
702
580
  }
703
- return _context8.abrupt("return", false);
581
+ return _context6.abrupt("return", false);
704
582
  case 35:
705
- throw _context8.t0;
583
+ throw _context6.t0;
706
584
  case 36:
707
585
  case "end":
708
- return _context8.stop();
586
+ return _context6.stop();
709
587
  }
710
- }, _callee8, this, [[5, 31]]);
588
+ }, _callee6, this, [[5, 31]]);
711
589
  }));
712
590
  function run() {
713
591
  return _run.apply(this, arguments);
@@ -716,36 +594,21 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
716
594
  }()
717
595
  }]);
718
596
  return LibroPromptCellView;
719
- }(LibroExecutableCellView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "libroContextKey", [_dec3], {
720
- configurable: true,
721
- enumerable: true,
722
- writable: true,
723
- initializer: null
724
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "chatObjects", [_dec4], {
597
+ }(LibroEditableExecutableCellView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "chatObjects", [_dec3], {
725
598
  configurable: true,
726
599
  enumerable: true,
727
600
  writable: true,
728
601
  initializer: function initializer() {
729
602
  return [];
730
603
  }
731
- }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "contextChatRecords", [_dec5], {
604
+ }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "contextChatRecords", [_dec4], {
732
605
  configurable: true,
733
606
  enumerable: true,
734
607
  writable: true,
735
608
  initializer: function initializer() {
736
609
  return [];
737
610
  }
738
- }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "codeEditorManager", [_dec6], {
739
- configurable: true,
740
- enumerable: true,
741
- writable: true,
742
- initializer: null
743
- }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "promptScript", [_dec7], {
744
- configurable: true,
745
- enumerable: true,
746
- writable: true,
747
- initializer: null
748
- }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "editorView", [_dec8], {
611
+ }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "promptScript", [_dec5], {
749
612
  configurable: true,
750
613
  enumerable: true,
751
614
  writable: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@difizen/libro-prompt-cell",
3
- "version": "0.2.34",
3
+ "version": "0.2.35",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "libro",
@@ -32,11 +32,11 @@
32
32
  "src"
33
33
  ],
34
34
  "dependencies": {
35
- "@difizen/libro-code-editor": "^0.2.34",
36
- "@difizen/libro-jupyter": "^0.2.34",
37
- "@difizen/libro-rendermime": "^0.2.34",
38
- "@difizen/libro-common": "^0.2.34",
39
- "@difizen/libro-core": "^0.2.34",
35
+ "@difizen/libro-code-editor": "^0.2.35",
36
+ "@difizen/libro-jupyter": "^0.2.35",
37
+ "@difizen/libro-rendermime": "^0.2.35",
38
+ "@difizen/libro-common": "^0.2.35",
39
+ "@difizen/libro-core": "^0.2.35",
40
40
  "@ant-design/icons": "^5.1.0",
41
41
  "@difizen/mana-l10n": "latest",
42
42
  "@difizen/mana-app": "latest",
@@ -1,11 +1,5 @@
1
- import { CodeEditorManager } from '@difizen/libro-code-editor';
2
- import type {
3
- CodeEditorViewOptions,
4
- IRange,
5
- CodeEditorView,
6
- } from '@difizen/libro-code-editor';
1
+ import type { IRange } from '@difizen/libro-code-editor';
7
2
  import type { ICodeCell, IOutput } from '@difizen/libro-common';
8
- import { CellUri } from '@difizen/libro-common';
9
3
  import { isOutput } from '@difizen/libro-common';
10
4
  import type {
11
5
  IOutputAreaOption,
@@ -13,13 +7,7 @@ import type {
13
7
  CellViewOptions,
14
8
  } from '@difizen/libro-core';
15
9
  import { LibroOutputArea } from '@difizen/libro-core';
16
- import {
17
- CellService,
18
- LibroExecutableCellView,
19
- LibroViewTracker,
20
- EditorStatus,
21
- LibroContextKey,
22
- } from '@difizen/libro-core';
10
+ import { CellService, LibroEditableExecutableCellView } from '@difizen/libro-core';
23
11
  import type { ExecutionMeta, KernelMessage } from '@difizen/libro-jupyter';
24
12
  import { KernelError, LibroJupyterModel } from '@difizen/libro-jupyter';
25
13
  import {
@@ -214,8 +202,7 @@ const PropmtEditorViewComponent = React.forwardRef<HTMLDivElement>(
214
202
 
215
203
  @transient()
216
204
  @view('prompt-editor-cell-view')
217
- export class LibroPromptCellView extends LibroExecutableCellView {
218
- @inject(LibroContextKey) protected libroContextKey: LibroContextKey;
205
+ export class LibroPromptCellView extends LibroEditableExecutableCellView {
219
206
  override view = PropmtEditorViewComponent;
220
207
 
221
208
  declare model: LibroPromptCellModel;
@@ -275,16 +262,10 @@ export class LibroPromptCellView extends LibroExecutableCellView {
275
262
 
276
263
  viewManager: ViewManager;
277
264
 
278
- @inject(CodeEditorManager) codeEditorManager: CodeEditorManager;
279
265
  @inject(PromptScript) promptScript: PromptScript;
280
266
 
281
267
  outputs: IOutput[];
282
268
 
283
- libroViewTracker: LibroViewTracker;
284
-
285
- @prop()
286
- editorView?: CodeEditorView;
287
-
288
269
  protected outputAreaDeferred = new Deferred<LibroOutputArea>();
289
270
  get outputAreaReady() {
290
271
  return this.outputAreaDeferred.promise;
@@ -294,7 +275,6 @@ export class LibroPromptCellView extends LibroExecutableCellView {
294
275
  @inject(ViewOption) options: CellViewOptions,
295
276
  @inject(CellService) cellService: CellService,
296
277
  @inject(ViewManager) viewManager: ViewManager,
297
- @inject(LibroViewTracker) libroViewTracker: LibroViewTracker,
298
278
  ) {
299
279
  super(options, cellService);
300
280
  this.options = options;
@@ -302,7 +282,6 @@ export class LibroPromptCellView extends LibroExecutableCellView {
302
282
  this.className = this.className + ' prompt';
303
283
 
304
284
  this.outputs = options.cell?.outputs as IOutput[];
305
- this.libroViewTracker = libroViewTracker;
306
285
 
307
286
  // 创建outputArea
308
287
  this.viewManager
@@ -342,55 +321,6 @@ export class LibroPromptCellView extends LibroExecutableCellView {
342
321
  } as ICodeCell;
343
322
  }
344
323
 
345
- override onViewMount() {
346
- this.createEditor();
347
- //选中cell时才focus
348
- if (this.parent.model.active?.id === this.id) {
349
- this.focus(!this.parent.model.commandMode);
350
- }
351
- }
352
-
353
- protected getEditorOption(): CodeEditorViewOptions {
354
- const option: CodeEditorViewOptions = {
355
- uuid: CellUri.from(this.parent.model.id, this.model.id).toString(),
356
- editorHostId: this.parent.id + this.id,
357
- model: this.model,
358
- config: {
359
- readOnly: !this.parent.model.inputEditable,
360
- editable: this.parent.model.inputEditable,
361
- },
362
- };
363
- return option;
364
- }
365
-
366
- async createEditor() {
367
- const option = this.getEditorOption();
368
-
369
- this.editorStatus = EditorStatus.LOADING;
370
-
371
- // 防止虚拟滚动中编辑器被频繁创建
372
- if (this.editorView) {
373
- this.editorStatus = EditorStatus.LOADED;
374
- return;
375
- }
376
- const editorView = await this.codeEditorManager.getOrCreateEditorView(option);
377
-
378
- this.editorView = editorView;
379
- this.editorStatus = EditorStatus.LOADED;
380
-
381
- await this.afterEditorReady();
382
- }
383
-
384
- protected async afterEditorReady() {
385
- watch(this.parent.model, 'inputEditable', () => {
386
- this.editorView?.editor?.setOption(
387
- 'readOnly',
388
- getOrigin(!this.parent.model.inputEditable),
389
- );
390
- });
391
- this.editorView?.onModalChange((val) => (this.hasModal = val));
392
- }
393
-
394
324
  override shouldEnterEditorMode(e: React.FocusEvent<HTMLElement>) {
395
325
  return getOrigin(this.editorView)?.editor?.host?.contains(
396
326
  e.target as HTMLElement,
@@ -404,33 +334,6 @@ export class LibroPromptCellView extends LibroExecutableCellView {
404
334
  this.editorView?.editor?.setOption('highlightActiveLineGutter', false);
405
335
  };
406
336
 
407
- protected focusEditor() {
408
- //选中cell、编辑模式、非只读时才focus
409
- if (
410
- this.editorView?.editor &&
411
- this.editorView.editorStatus === 'ready' &&
412
- this.parent.model.active?.id === this.id &&
413
- !this.parent.model.commandMode &&
414
- this.libroContextKey.commandModeEnabled === true && // 排除弹窗等情况
415
- this.parent.model.inputEditable
416
- ) {
417
- this.editorView?.editor.setOption('styleActiveLine', true);
418
- this.editorView?.editor.setOption('highlightActiveLineGutter', true);
419
- this.editorView?.editor.focus();
420
- }
421
- }
422
-
423
- override focus = (toEdit: boolean) => {
424
- if (toEdit) {
425
- this.focusEditor();
426
- } else {
427
- if (this.container?.current?.parentElement?.contains(document.activeElement)) {
428
- return;
429
- }
430
- this.container?.current?.parentElement?.focus();
431
- }
432
- };
433
-
434
337
  override clearExecution = () => {
435
338
  this.model.clearExecution();
436
339
  this.outputArea.clear();