@difizen/libro-sql-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.
package/es/index.less CHANGED
@@ -16,14 +16,10 @@
16
16
  border-right: 1px solid var(--mana-libro-cell-border-color);
17
17
  }
18
18
 
19
- .libro-sql-input-warning-text,
20
- .libro-sql-variable-name-input {
21
- display: block !important;
22
- }
23
-
24
19
  .libro-sql-variable-name-input {
25
20
  width: 120px !important;
26
21
  height: 32px;
22
+ margin-left: 6px;
27
23
  border: 1px solid #d6d8da !important;
28
24
  border-radius: 6px !important;
29
25
  box-shadow: unset !important;
@@ -53,8 +49,14 @@
53
49
  letter-spacing: 0;
54
50
  }
55
51
 
52
+ .libro-sql-variable-content {
53
+ padding-left: 18px;
54
+ }
55
+
56
56
  .libro-sql-variable-name {
57
+ display: flex;
57
58
  margin-left: 8px;
59
+ align-items: center;
58
60
 
59
61
  svg {
60
62
  margin-left: 4px;
@@ -99,8 +101,8 @@
99
101
  }
100
102
 
101
103
  .libro-sql-input-warning-text {
102
- width: 112px;
103
- height: 20px;
104
+ display: flex;
105
+ align-items: center;
104
106
  margin-top: 4px;
105
107
  color: #faad14;
106
108
  font-weight: 400;
@@ -1,25 +1,20 @@
1
- import type { CodeEditorView } from '@difizen/libro-code-editor';
2
1
  import { CodeEditorManager } from '@difizen/libro-code-editor';
3
2
  import type { IOutput } from '@difizen/libro-common';
4
3
  import type { CellViewOptions, LibroCell, KernelMessage } from '@difizen/libro-jupyter';
5
- import { CellService, EditorStatus, LibroContextKey, LibroExecutableCellView, LibroViewTracker, LibroOutputArea } from '@difizen/libro-jupyter';
4
+ import { CellService, EditorStatus, LibroEditableExecutableCellView, LibroViewTracker, LibroOutputArea } from '@difizen/libro-jupyter';
6
5
  import type { ViewSize } from '@difizen/mana-app';
7
- import { Deferred, DisposableCollection, ViewManager } from '@difizen/mana-app';
6
+ import { Deferred, ViewManager } from '@difizen/mana-app';
8
7
  import React from 'react';
9
8
  import './index.less';
10
9
  import { LibroSqlCellModel } from './libro-sql-cell-model.js';
11
10
  import type { DatabaseConfig } from './libro-sql-cell-protocol.js';
12
11
  import { SqlScript } from './libro-sql-cell-script.js';
13
12
  export declare const LibroSqlCell: React.ForwardRefExoticComponent<React.RefAttributes<HTMLDivElement>>;
14
- export declare class LibroSqlCellView extends LibroExecutableCellView {
13
+ export declare class LibroSqlCellView extends LibroEditableExecutableCellView {
15
14
  view: React.ForwardRefExoticComponent<React.RefAttributes<HTMLDivElement>>;
16
15
  model: LibroSqlCellModel;
17
16
  libroViewTracker: LibroViewTracker;
18
- codeEditorManager: CodeEditorManager;
19
- protected toDisposeOnEditor: DisposableCollection;
20
- protected readonly libroContextKey: LibroContextKey;
21
17
  outputs: IOutput[];
22
- editorView?: CodeEditorView;
23
18
  databaseConfig?: DatabaseConfig;
24
19
  editorStatus: EditorStatus;
25
20
  editorAreaHeight: number;
@@ -35,18 +30,13 @@ export declare class LibroSqlCellView extends LibroExecutableCellView {
35
30
  constructor(options: CellViewOptions, cellService: CellService, viewManager: ViewManager, libroViewTracker: LibroViewTracker, codeEditorManager: CodeEditorManager);
36
31
  onViewMount: () => Promise<void>;
37
32
  setEditorHost(ref: any): void;
38
- createEditor(): Promise<void>;
39
- protected afterEditorReady(): Promise<void>;
40
- protected focusEditor(): void;
41
33
  onViewResize: (size: ViewSize) => void;
42
34
  toJSON(): LibroCell;
43
35
  focus: (toEdit: boolean) => void;
44
- blur: () => void;
45
36
  clearExecution: () => void;
46
37
  run(): Promise<boolean>;
47
38
  fetch: (content: KernelMessage.IExecuteRequestMsg['content'], ioCallback: (msg: KernelMessage.IIOPubMessage) => any) => Promise<KernelMessage.IExecuteReplyMsg>;
48
39
  handleQueryResponse: (response: KernelMessage.IIOPubMessage, cb: (result: string) => void) => void;
49
40
  getDatabaseConfig: () => Promise<KernelMessage.IExecuteReplyMsg>;
50
- shouldEnterEditorMode(e: React.FocusEvent<HTMLElement>): boolean;
51
41
  }
52
42
  //# sourceMappingURL=libro-sql-cell-view.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"libro-sql-cell-view.d.ts","sourceRoot":"","sources":["../src/libro-sql-cell-view.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAyB,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAa,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhE,OAAO,KAAK,EACV,eAAe,EAGf,SAAS,EACT,aAAa,EACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,WAAW,EACX,YAAY,EACZ,eAAe,EACf,uBAAuB,EACvB,gBAAgB,EAIhB,eAAe,EAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EACL,QAAQ,EAER,oBAAoB,EAQpB,WAAW,EAIZ,MAAM,mBAAmB,CAAC;AAG3B,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAgHvD,eAAO,MAAM,YAAY,sEAgExB,CAAC;AAEF,qBAEa,gBAAiB,SAAQ,uBAAuB;IAClD,IAAI,uEAAgB;IACrB,KAAK,EAAE,iBAAiB,CAAC;IACjC,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,SAAS,CAAC,iBAAiB,uBAA8B;IAEhC,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;IAE7E,OAAO,EAAE,OAAO,EAAE,CAAC;IAGnB,UAAU,CAAC,EAAE,cAAc,CAAC;IAG5B,cAAc,CAAC,EAAE,cAAc,CAAC;IAGvB,YAAY,EAAE,YAAY,CAA0B;IAG7D,gBAAgB,SAAK;IAGZ,kBAAkB,SAAK;IAEb,SAAS,EAAE,SAAS,CAAC;IAExC,SAAS,CAAC,uBAAuB,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAwB;IAEzE,IAAI,WAAW,kBAEd;IAEQ,YAAY,uDAMnB;IAGO,gBAAgB;IAIzB,oBAAoB;IAuBpB,SAAS,CAAC,kBAAkB,4BAAmC;IAC/D,IAAI,eAAe,6BAElB;gBAGqB,OAAO,EAAE,eAAe,EACvB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACnB,gBAAgB,EAAE,gBAAgB,EACjC,iBAAiB,EAAE,iBAAiB;IAsCxD,WAAW,sBAElB;IAEF,aAAa,CAAC,GAAG,EAAE,GAAG;IAKhB,YAAY;cAgCF,gBAAgB;IAoBhC,SAAS,CAAC,WAAW;IAgBZ,YAAY,SAAU,QAAQ,KAAG,IAAI,CAK5C;IAEO,MAAM,IAAI,SAAS;IASnB,KAAK,WAAY,OAAO,UAU/B;IAEO,IAAI,aAGX;IAEO,cAAc,aAGrB;IAEa,GAAG;IAqElB,KAAK,YACM,cAAc,kBAAkB,CAAC,SAAS,CAAC,oBAClC,cAAc,aAAa,KAAK,GAAG,6CAUrD;IAEF,mBAAmB,aACP,cAAc,aAAa,eACxB,MAAM,KAAK,IAAI,UA6B5B;IAEF,iBAAiB,gDAef;IAEO,qBAAqB,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC;CAKhE"}
1
+ {"version":3,"file":"libro-sql-cell-view.d.ts","sourceRoot":"","sources":["../src/libro-sql-cell-view.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAa,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhE,OAAO,KAAK,EACV,eAAe,EAGf,SAAS,EACT,aAAa,EACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,WAAW,EACX,YAAY,EAEZ,+BAA+B,EAC/B,gBAAgB,EAIhB,eAAe,EAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EACL,QAAQ,EAQR,WAAW,EAGZ,MAAM,mBAAmB,CAAC;AAI3B,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAsHvD,eAAO,MAAM,YAAY,sEAsDxB,CAAC;AAEF,qBAEa,gBAAiB,SAAQ,+BAA+B;IAC1D,IAAI,uEAAgB;IACrB,KAAK,EAAE,iBAAiB,CAAC;IACjC,gBAAgB,EAAE,gBAAgB,CAAC;IAEnC,OAAO,EAAE,OAAO,EAAE,CAAC;IAGnB,cAAc,CAAC,EAAE,cAAc,CAAC;IAGvB,YAAY,EAAE,YAAY,CAA0B;IAG7D,gBAAgB,SAAK;IAGZ,kBAAkB,SAAK;IAEb,SAAS,EAAE,SAAS,CAAC;IAExC,SAAS,CAAC,uBAAuB,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAwB;IAEzE,IAAI,WAAW,kBAEd;IAEQ,YAAY,uDAMnB;IAGO,gBAAgB;IAIzB,oBAAoB;IAuBpB,SAAS,CAAC,kBAAkB,4BAAmC;IAC/D,IAAI,eAAe,6BAElB;gBAGqB,OAAO,EAAE,eAAe,EACvB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACnB,gBAAgB,EAAE,gBAAgB,EACjC,iBAAiB,EAAE,iBAAiB;IAsCxD,WAAW,sBAElB;IAEF,aAAa,CAAC,GAAG,EAAE,GAAG;IAKb,YAAY,SAAU,QAAQ,KAAG,IAAI,CAK5C;IAEO,MAAM,IAAI,SAAS;IASnB,KAAK,WAAY,OAAO,UAU/B;IAEO,cAAc,aAGrB;IAEa,GAAG;IAqElB,KAAK,YACM,cAAc,kBAAkB,CAAC,SAAS,CAAC,oBAClC,cAAc,aAAa,KAAK,GAAG,6CAUrD;IAEF,mBAAmB,aACP,cAAc,aAAa,eACxB,MAAM,KAAK,IAAI,UA6B5B;IAEF,iBAAiB,gDAef;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, _dec9, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7;
2
+ var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5;
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; }
@@ -31,11 +31,11 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
31
31
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
32
32
  import { EditFilled, DatabaseOutlined } from '@ant-design/icons';
33
33
  import { CodeEditorManager } from '@difizen/libro-code-editor';
34
- import { CellUri, isOutput } from '@difizen/libro-common';
35
- import { CellService, EditorStatus, LibroContextKey, LibroExecutableCellView, LibroViewTracker, VirtualizedManagerHelper, KernelError, LibroJupyterModel, LibroOutputArea } from '@difizen/libro-jupyter';
36
- import { Deferred, Disposable, DisposableCollection, getOrigin, inject, prop, transient, useInject, view, ViewInstance, ViewManager, ViewOption, ViewRender, watch } from '@difizen/mana-app';
34
+ import { isOutput } from '@difizen/libro-common';
35
+ import { CellService, EditorStatus, LibroContextKey, LibroEditableExecutableCellView, LibroViewTracker, VirtualizedManagerHelper, KernelError, LibroJupyterModel, LibroOutputArea } from '@difizen/libro-jupyter';
36
+ import { Deferred, getOrigin, inject, prop, transient, useInject, view, ViewInstance, ViewManager, ViewOption, ViewRender } from '@difizen/mana-app';
37
37
  import { l10n } from '@difizen/mana-l10n';
38
- import { Input, Popover } from 'antd';
38
+ import { Input } from 'antd';
39
39
  import React from 'react';
40
40
  import { useCallback, useEffect, useRef, useState } from 'react';
41
41
  import "./index.less";
@@ -86,6 +86,8 @@ var CellEditor = function CellEditor() {
86
86
  var LibroSqlVariableNameInput = function LibroSqlVariableNameInput(_ref) {
87
87
  var handCancel = _ref.handCancel;
88
88
  var cellView = useInject(ViewInstance);
89
+ var contextKey = useInject(LibroContextKey);
90
+ var inputRef = useRef(null);
89
91
  var _useState = useState(true),
90
92
  _useState2 = _slicedToArray(_useState, 2),
91
93
  resultVariableAvailable = _useState2[0],
@@ -104,6 +106,13 @@ var LibroSqlVariableNameInput = function LibroSqlVariableNameInput(_ref) {
104
106
  }
105
107
  setVariableName(e.target.value);
106
108
  }, [cellView.parent.model.cells]);
109
+ useEffect(function () {
110
+ if (inputRef.current !== null) {
111
+ inputRef.current.focus({
112
+ cursor: 'end'
113
+ });
114
+ }
115
+ });
107
116
  var handValueSave = useCallback(function () {
108
117
  cellView.model.resultVariable = getDfVariableName(cellView.parent.model.cells.filter(function (cell) {
109
118
  return cell.model.type === 'sql';
@@ -119,34 +128,28 @@ var LibroSqlVariableNameInput = function LibroSqlVariableNameInput(_ref) {
119
128
  status: "".concat(resultVariableAvailable ? '' : 'warning'),
120
129
  className: "libro-sql-variable-name-input",
121
130
  onChange: handleValueChange,
131
+ onBlur: handValueSave,
132
+ onFocus: function onFocus() {
133
+ contextKey.disableCommandMode();
134
+ },
135
+ ref: inputRef,
122
136
  defaultValue: cellView.model.resultVariable
123
137
  }), !resultVariableAvailable && /*#__PURE__*/_jsx("span", {
124
138
  className: "libro-sql-input-warning-text",
125
139
  children: l10n.t('当前变量名已存在')
126
- }), /*#__PURE__*/_jsxs("div", {
127
- className: "libro-sql-input-button",
128
- children: [/*#__PURE__*/_jsx("span", {
129
- onClick: handCancel,
130
- className: "libro-sql-input-cancel",
131
- children: l10n.t('取消')
132
- }), /*#__PURE__*/_jsx("span", {
133
- onClick: handValueSave,
134
- className: "libro-sql-input-save",
135
- children: l10n.t('保存')
136
- })]
137
140
  })]
138
141
  });
139
142
  };
140
143
  export var LibroSqlCell = /*#__PURE__*/React.forwardRef(function SqlEditorViewComponent(props, ref) {
141
- var _useState5 = useState(false),
142
- _useState6 = _slicedToArray(_useState5, 2),
143
- isVariableNameEdit = _useState6[0],
144
- setIsVariableNameEdit = _useState6[1];
145
144
  var instance = useInject(ViewInstance);
146
145
  var contextKey = useInject(LibroContextKey);
146
+ var _useState5 = useState(false),
147
+ _useState6 = _slicedToArray(_useState5, 2),
148
+ edit = _useState6[0],
149
+ setEdit = _useState6[1];
147
150
  var handCancelEdit = function handCancelEdit() {
148
151
  contextKey.enableCommandMode();
149
- setIsVariableNameEdit(false);
152
+ setEdit(false);
150
153
  };
151
154
  return /*#__PURE__*/_jsxs("div", {
152
155
  tabIndex: 10,
@@ -168,45 +171,26 @@ export var LibroSqlCell = /*#__PURE__*/React.forwardRef(function SqlEditorViewCo
168
171
  children: [/*#__PURE__*/_jsx("span", {
169
172
  className: "libro-sql-variable-name-title",
170
173
  children: "Name: "
171
- }), /*#__PURE__*/_jsx("span", {
174
+ }), edit ? /*#__PURE__*/_jsx(LibroSqlVariableNameInput, {
175
+ handCancel: handCancelEdit
176
+ }) : /*#__PURE__*/_jsx("span", {
172
177
  className: "libro-sql-variable-content",
173
- children: instance.model.resultVariable
174
- }), /*#__PURE__*/_jsx("div", {
175
- className: "libro-sql-variable-name-popover",
176
- style: {
177
- display: 'inline-block'
178
+ onDoubleClick: function onDoubleClick() {
179
+ setEdit(true);
178
180
  },
179
- children: /*#__PURE__*/_jsx(Popover, {
180
- content: /*#__PURE__*/_jsx(LibroSqlVariableNameInput, {
181
- handCancel: handCancelEdit
182
- }),
183
- placement: "bottomLeft",
184
- open: instance.parent.model.inputEditable ? isVariableNameEdit : false,
185
- onOpenChange: function onOpenChange(visible) {
186
- if (visible) {
187
- contextKey.disableCommandMode();
188
- } else {
189
- contextKey.enableCommandMode();
190
- }
191
- setIsVariableNameEdit(visible);
192
- },
193
- getPopupContainer: function getPopupContainer() {
194
- var _instance$container;
195
- return (_instance$container = instance.container) === null || _instance$container === void 0 || (_instance$container = _instance$container.current) === null || _instance$container === void 0 ? void 0 : _instance$container.getElementsByClassName('libro-sql-variable-name')[0];
196
- },
197
- trigger: "click",
198
- overlayClassName: "libro-sql-popover-container",
199
- children: /*#__PURE__*/_jsx(EditFilled, {
200
- className: "libro-sql-edit-icon"
201
- })
202
- })
181
+ children: instance.model.resultVariable
182
+ }), !edit && /*#__PURE__*/_jsx(EditFilled, {
183
+ className: "libro-sql-edit-icon",
184
+ onClick: function onClick() {
185
+ setEdit(true);
186
+ }
203
187
  })]
204
188
  })]
205
189
  }), /*#__PURE__*/_jsx(CellEditor, {})]
206
190
  });
207
191
  });
208
- export var LibroSqlCellView = (_dec = transient(), _dec2 = view('libro-sql-cell-view'), _dec3 = inject(LibroContextKey), _dec4 = prop(), _dec5 = prop(), _dec6 = prop(), _dec7 = prop(), _dec8 = prop(), _dec9 = inject(SqlScript), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroExecutableCellV) {
209
- _inherits(LibroSqlCellView, _LibroExecutableCellV);
192
+ export var LibroSqlCellView = (_dec = transient(), _dec2 = view('libro-sql-cell-view'), _dec3 = prop(), _dec4 = prop(), _dec5 = prop(), _dec6 = prop(), _dec7 = inject(SqlScript), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroEditableExecuta) {
193
+ _inherits(LibroSqlCellView, _LibroEditableExecuta);
210
194
  var _super = _createSuper(LibroSqlCellView);
211
195
  function LibroSqlCellView(options, cellService, viewManager, libroViewTracker, codeEditorManager) {
212
196
  var _options$cell;
@@ -215,16 +199,12 @@ export var LibroSqlCellView = (_dec = transient(), _dec2 = view('libro-sql-cell-
215
199
  _this = _super.call(this, options, cellService);
216
200
  _this.view = LibroSqlCell;
217
201
  _this.libroViewTracker = void 0;
218
- _this.codeEditorManager = void 0;
219
- _this.toDisposeOnEditor = new DisposableCollection();
220
- _initializerDefineProperty(_this, "libroContextKey", _descriptor, _assertThisInitialized(_this));
221
202
  _this.outputs = void 0;
222
- _initializerDefineProperty(_this, "editorView", _descriptor2, _assertThisInitialized(_this));
223
- _initializerDefineProperty(_this, "databaseConfig", _descriptor3, _assertThisInitialized(_this));
224
- _initializerDefineProperty(_this, "editorStatus", _descriptor4, _assertThisInitialized(_this));
225
- _initializerDefineProperty(_this, "editorAreaHeight", _descriptor5, _assertThisInitialized(_this));
226
- _initializerDefineProperty(_this, "noEditorAreaHeight", _descriptor6, _assertThisInitialized(_this));
227
- _initializerDefineProperty(_this, "sqlScript", _descriptor7, _assertThisInitialized(_this));
203
+ _initializerDefineProperty(_this, "databaseConfig", _descriptor, _assertThisInitialized(_this));
204
+ _initializerDefineProperty(_this, "editorStatus", _descriptor2, _assertThisInitialized(_this));
205
+ _initializerDefineProperty(_this, "editorAreaHeight", _descriptor3, _assertThisInitialized(_this));
206
+ _initializerDefineProperty(_this, "noEditorAreaHeight", _descriptor4, _assertThisInitialized(_this));
207
+ _initializerDefineProperty(_this, "sqlScript", _descriptor5, _assertThisInitialized(_this));
228
208
  _this.editorViewReadyDeferred = new Deferred();
229
209
  _this.renderEditor = function () {
230
210
  if (_this.editorView) {
@@ -266,11 +246,6 @@ export var LibroSqlCellView = (_dec = transient(), _dec2 = view('libro-sql-cell-
266
246
  (_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();
267
247
  }
268
248
  };
269
- _this.blur = function () {
270
- var _this$editorView, _this$editorView2;
271
- (_this$editorView = _this.editorView) === null || _this$editorView === void 0 || (_this$editorView = _this$editorView.editor) === null || _this$editorView === void 0 || _this$editorView.setOption('styleActiveLine', false);
272
- (_this$editorView2 = _this.editorView) === null || _this$editorView2 === void 0 || (_this$editorView2 = _this$editorView2.editor) === null || _this$editorView2 === void 0 || _this$editorView2.setOption('highlightActiveLineGutter', false);
273
- };
274
249
  _this.clearExecution = function () {
275
250
  _this.model.clearExecution();
276
251
  _this.outputArea.clear();
@@ -448,110 +423,6 @@ export var LibroSqlCellView = (_dec = transient(), _dec2 = view('libro-sql-cell-
448
423
  var editorHostId = this.parent.id + this.id;
449
424
  this.codeEditorManager.setEditorHostRef(editorHostId, ref);
450
425
  }
451
- }, {
452
- key: "createEditor",
453
- value: function () {
454
- var _createEditor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
455
- var _this2 = this;
456
- var editorHostId, option, editorView;
457
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
458
- while (1) switch (_context5.prev = _context5.next) {
459
- case 0:
460
- editorHostId = this.parent.id + this.id;
461
- option = {
462
- uuid: CellUri.from(this.parent.model.id, this.model.id).toString(),
463
- editorHostId: editorHostId,
464
- model: this.model,
465
- config: {
466
- readOnly: !this.parent.model.inputEditable,
467
- editable: this.parent.model.inputEditable
468
- }
469
- }; // 防止虚拟滚动中编辑器被频繁创建
470
- if (!this.editorView) {
471
- _context5.next = 5;
472
- break;
473
- }
474
- this.editorStatus = EditorStatus.LOADED;
475
- return _context5.abrupt("return");
476
- case 5:
477
- _context5.next = 7;
478
- return this.codeEditorManager.getOrCreateEditorView(option);
479
- case 7:
480
- editorView = _context5.sent;
481
- this.editorView = editorView;
482
- this.editorStatus = EditorStatus.LOADED;
483
- this.editorViewReadyDeferred.resolve();
484
- editorView.onEditorStatusChange(function (e) {
485
- if (e.status === 'ready') {
486
- _this2.editor = _this2.editorView.editor;
487
- _this2.afterEditorReady();
488
- } else if (e.status === 'disposed') {
489
- _this2.toDisposeOnEditor.dispose();
490
- }
491
- });
492
- case 12:
493
- case "end":
494
- return _context5.stop();
495
- }
496
- }, _callee5, this);
497
- }));
498
- function createEditor() {
499
- return _createEditor.apply(this, arguments);
500
- }
501
- return createEditor;
502
- }()
503
- }, {
504
- key: "afterEditorReady",
505
- value: function () {
506
- var _afterEditorReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
507
- var _this3 = this,
508
- _this$editorView$onMo,
509
- _this$editorView3,
510
- _this$editor$onModelC,
511
- _this$editor,
512
- _this$editor$onModelC2;
513
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
514
- while (1) switch (_context6.prev = _context6.next) {
515
- case 0:
516
- this.focusEditor();
517
- this.toDisposeOnEditor.push(watch(this.parent.model, 'inputEditable', function () {
518
- var _this3$editorView;
519
- (_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));
520
- }));
521
- this.toDisposeOnEditor.push((_this$editorView$onMo = (_this$editorView3 = this.editorView) === null || _this$editorView3 === void 0 ? void 0 : _this$editorView3.onModalChange(function (val) {
522
- return _this3.hasModal = val;
523
- })) !== null && _this$editorView$onMo !== void 0 ? _this$editorView$onMo : Disposable.NONE);
524
- 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) {
525
- _this3.parent.model.onCellContentChange({
526
- cell: _this3,
527
- changes: e
528
- });
529
- })) !== null && _this$editor$onModelC !== void 0 ? _this$editor$onModelC : Disposable.NONE);
530
- case 4:
531
- case "end":
532
- return _context6.stop();
533
- }
534
- }, _callee6, this);
535
- }));
536
- function afterEditorReady() {
537
- return _afterEditorReady.apply(this, arguments);
538
- }
539
- return afterEditorReady;
540
- }()
541
- }, {
542
- key: "focusEditor",
543
- value: function focusEditor() {
544
- var _this$editorView4, _this$parent$model$ac;
545
- //选中cell、编辑模式、非只读时才focus
546
- 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 &&
547
- // 排除弹窗等情况
548
- this.parent.model.inputEditable) {
549
- var _this$editorView5, _this$editorView6, _this$editorView7;
550
- (_this$editorView5 = this.editorView) === null || _this$editorView5 === void 0 || _this$editorView5.editor.setOption('styleActiveLine', true);
551
- (_this$editorView6 = this.editorView) === null || _this$editorView6 === void 0 || _this$editorView6.editor.setOption('highlightActiveLineGutter', true);
552
- (_this$editorView7 = this.editorView) === null || _this$editorView7 === void 0 || _this$editorView7.editor.focus();
553
- }
554
- }
555
426
  }, {
556
427
  key: "toJSON",
557
428
  value: function toJSON() {
@@ -565,22 +436,22 @@ export var LibroSqlCellView = (_dec = transient(), _dec2 = view('libro-sql-cell-
565
436
  }, {
566
437
  key: "run",
567
438
  value: function () {
568
- var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
569
- var _this4 = this;
439
+ var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
440
+ var _this2 = this;
570
441
  var libroModel, kernelConnection, cellContent, future, startTimeStr, msgPromise, endTimeStr;
571
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
572
- while (1) switch (_context7.prev = _context7.next) {
442
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
443
+ while (1) switch (_context5.prev = _context5.next) {
573
444
  case 0:
574
445
  libroModel = this.parent.model;
575
446
  if (!(!libroModel || !(libroModel instanceof LibroJupyterModel) || !libroModel.kernelConnection || libroModel.kernelConnection.isDisposed)) {
576
- _context7.next = 3;
447
+ _context5.next = 3;
577
448
  break;
578
449
  }
579
- return _context7.abrupt("return", false);
450
+ return _context5.abrupt("return", false);
580
451
  case 3:
581
452
  kernelConnection = getOrigin(libroModel.kernelConnection);
582
453
  cellContent = this.model.source;
583
- _context7.prev = 5;
454
+ _context5.prev = 5;
584
455
  // Promise.resolve().then(() => {
585
456
  this.clearExecution();
586
457
  // });
@@ -596,26 +467,26 @@ export var LibroSqlCellView = (_dec = transient(), _dec2 = view('libro-sql-cell-
596
467
  };
597
468
  // Handle iopub messages
598
469
  future.onIOPub = function (msg) {
599
- _this4.model.msgChangeEmitter.fire(msg);
470
+ _this2.model.msgChangeEmitter.fire(msg);
600
471
  if (msg.header.msg_type === 'execute_input') {
601
- _this4.model.kernelExecuting = true;
472
+ _this2.model.kernelExecuting = true;
602
473
  startTimeStr = msg.header.date;
603
- var meta = _this4.model.metadata['execution'];
474
+ var meta = _this2.model.metadata['execution'];
604
475
  if (meta) {
605
476
  meta['shell.execute_reply.started'] = startTimeStr;
606
477
  }
607
478
  }
608
479
  if (msg.header.msg_type === 'execute_result') {
609
- _this4.model.metadata['isVariableSaved'] = msg.content.data['application/vnd.libro.sql+json'].isVariableSaved;
480
+ _this2.model.metadata['isVariableSaved'] = msg.content.data['application/vnd.libro.sql+json'].isVariableSaved;
610
481
  }
611
482
  if (msg.header.msg_type === 'error') {
612
- _this4.model.hasExecutedError = true;
483
+ _this2.model.hasExecutedError = true;
613
484
  }
614
485
  };
615
- _context7.next = 14;
486
+ _context5.next = 14;
616
487
  return future.done;
617
488
  case 14:
618
- msgPromise = _context7.sent;
489
+ msgPromise = _context5.sent;
619
490
  this.model.executing = false;
620
491
  this.model.kernelExecuting = false;
621
492
  this.model.hasExecutedSuccess = !this.model.hasExecutedError;
@@ -624,87 +495,71 @@ export var LibroSqlCellView = (_dec = transient(), _dec2 = view('libro-sql-cell-
624
495
  this.model.metadata['execution']['shell.execute_reply.started'] = startTimeStr;
625
496
  this.model.metadata['execution']['shell.execute_reply.end'] = endTimeStr;
626
497
  if (msgPromise) {
627
- _context7.next = 24;
498
+ _context5.next = 24;
628
499
  break;
629
500
  }
630
- return _context7.abrupt("return", true);
501
+ return _context5.abrupt("return", true);
631
502
  case 24:
632
503
  if (!(msgPromise.content.status === 'ok')) {
633
- _context7.next = 28;
504
+ _context5.next = 28;
634
505
  break;
635
506
  }
636
- return _context7.abrupt("return", true);
507
+ return _context5.abrupt("return", true);
637
508
  case 28:
638
509
  throw new KernelError(msgPromise.content);
639
510
  case 29:
640
- _context7.next = 36;
511
+ _context5.next = 36;
641
512
  break;
642
513
  case 31:
643
- _context7.prev = 31;
644
- _context7.t0 = _context7["catch"](5);
645
- if (!_context7.t0.message.startsWith('Canceled')) {
646
- _context7.next = 35;
514
+ _context5.prev = 31;
515
+ _context5.t0 = _context5["catch"](5);
516
+ if (!_context5.t0.message.startsWith('Canceled')) {
517
+ _context5.next = 35;
647
518
  break;
648
519
  }
649
- return _context7.abrupt("return", false);
520
+ return _context5.abrupt("return", false);
650
521
  case 35:
651
- throw _context7.t0;
522
+ throw _context5.t0;
652
523
  case 36:
653
524
  case "end":
654
- return _context7.stop();
525
+ return _context5.stop();
655
526
  }
656
- }, _callee7, this, [[5, 31]]);
527
+ }, _callee5, this, [[5, 31]]);
657
528
  }));
658
529
  function run() {
659
530
  return _run.apply(this, arguments);
660
531
  }
661
532
  return run;
662
533
  }()
663
- }, {
664
- key: "shouldEnterEditorMode",
665
- value: function shouldEnterEditorMode(e) {
666
- var _getOrigin;
667
- 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;
668
- }
669
534
  }]);
670
535
  return LibroSqlCellView;
671
- }(LibroExecutableCellView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "libroContextKey", [_dec3], {
672
- configurable: true,
673
- enumerable: true,
674
- writable: true,
675
- initializer: null
676
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "editorView", [_dec4], {
677
- configurable: true,
678
- enumerable: true,
679
- writable: true,
680
- initializer: null
681
- }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "databaseConfig", [_dec5], {
536
+ }(LibroEditableExecutableCellView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "databaseConfig", [_dec3], {
682
537
  configurable: true,
683
538
  enumerable: true,
684
539
  writable: true,
685
540
  initializer: null
686
- }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "editorStatus", [_dec6], {
541
+ }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "editorStatus", [_dec4], {
687
542
  configurable: true,
688
543
  enumerable: true,
689
544
  writable: true,
690
545
  initializer: function initializer() {
691
546
  return EditorStatus.NOTLOADED;
692
547
  }
693
- }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "editorAreaHeight", [_dec7], {
548
+ }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "editorAreaHeight", [_dec5], {
694
549
  configurable: true,
695
550
  enumerable: true,
696
551
  writable: true,
697
552
  initializer: function initializer() {
698
553
  return 0;
699
554
  }
700
- }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "noEditorAreaHeight", [_dec8], {
555
+ }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "noEditorAreaHeight", [_dec6], {
701
556
  configurable: true,
702
557
  enumerable: true,
703
558
  writable: true,
704
559
  initializer: function initializer() {
705
560
  return 0;
706
561
  }
707
- }), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "sqlScript", [_dec9], {
562
+ }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "sqlScript", [_dec7], {
708
563
  configurable: true,
709
564
  enumerable: true,
710
565
  writable: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@difizen/libro-sql-cell",
3
- "version": "0.2.34",
3
+ "version": "0.2.35",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "libro",
@@ -32,10 +32,10 @@
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",
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
39
  "@ant-design/icons": "^5.1.0",
40
40
  "@difizen/mana-app": "latest",
41
41
  "@difizen/mana-l10n": "latest"
package/src/index.less CHANGED
@@ -16,14 +16,10 @@
16
16
  border-right: 1px solid var(--mana-libro-cell-border-color);
17
17
  }
18
18
 
19
- .libro-sql-input-warning-text,
20
- .libro-sql-variable-name-input {
21
- display: block !important;
22
- }
23
-
24
19
  .libro-sql-variable-name-input {
25
20
  width: 120px !important;
26
21
  height: 32px;
22
+ margin-left: 6px;
27
23
  border: 1px solid #d6d8da !important;
28
24
  border-radius: 6px !important;
29
25
  box-shadow: unset !important;
@@ -53,8 +49,14 @@
53
49
  letter-spacing: 0;
54
50
  }
55
51
 
52
+ .libro-sql-variable-content {
53
+ padding-left: 18px;
54
+ }
55
+
56
56
  .libro-sql-variable-name {
57
+ display: flex;
57
58
  margin-left: 8px;
59
+ align-items: center;
58
60
 
59
61
  svg {
60
62
  margin-left: 4px;
@@ -99,8 +101,8 @@
99
101
  }
100
102
 
101
103
  .libro-sql-input-warning-text {
102
- width: 112px;
103
- height: 20px;
104
+ display: flex;
105
+ align-items: center;
104
106
  margin-top: 4px;
105
107
  color: #faad14;
106
108
  font-weight: 400;
@@ -1,8 +1,7 @@
1
1
  import { EditFilled, DatabaseOutlined } from '@ant-design/icons';
2
- import type { CodeEditorViewOptions, CodeEditorView } from '@difizen/libro-code-editor';
3
2
  import { CodeEditorManager } from '@difizen/libro-code-editor';
4
3
  import type { ICodeCell, IOutput } from '@difizen/libro-common';
5
- import { CellUri, isOutput } from '@difizen/libro-common';
4
+ import { isOutput } from '@difizen/libro-common';
6
5
  import type {
7
6
  CellViewOptions,
8
7
  ExecutionMeta,
@@ -14,7 +13,7 @@ import {
14
13
  CellService,
15
14
  EditorStatus,
16
15
  LibroContextKey,
17
- LibroExecutableCellView,
16
+ LibroEditableExecutableCellView,
18
17
  LibroViewTracker,
19
18
  VirtualizedManagerHelper,
20
19
  KernelError,
@@ -24,8 +23,6 @@ import {
24
23
  import type { ViewSize } from '@difizen/mana-app';
25
24
  import {
26
25
  Deferred,
27
- Disposable,
28
- DisposableCollection,
29
26
  getOrigin,
30
27
  inject,
31
28
  prop,
@@ -36,10 +33,10 @@ import {
36
33
  ViewManager,
37
34
  ViewOption,
38
35
  ViewRender,
39
- watch,
40
36
  } from '@difizen/mana-app';
41
37
  import { l10n } from '@difizen/mana-l10n';
42
- import { Input, Popover } from 'antd';
38
+ import type { InputRef } from 'antd';
39
+ import { Input } from 'antd';
43
40
  import React from 'react';
44
41
  import { useCallback, useEffect, useRef, useState } from 'react';
45
42
 
@@ -98,6 +95,8 @@ const LibroSqlVariableNameInput: React.FC<LibroSqlVariableProps> = ({
98
95
  handCancel,
99
96
  }: LibroSqlVariableProps) => {
100
97
  const cellView = useInject<LibroSqlCellView>(ViewInstance);
98
+ const contextKey = useInject<LibroContextKey>(LibroContextKey);
99
+ const inputRef = useRef<InputRef>(null);
101
100
  const [resultVariableAvailable, setVariableNameAvailable] = useState(true);
102
101
  const [resultVariable, setVariableName] = useState(cellView.model.resultVariable);
103
102
  const handleValueChange = useCallback(
@@ -118,6 +117,14 @@ const LibroSqlVariableNameInput: React.FC<LibroSqlVariableProps> = ({
118
117
  [cellView.parent.model.cells],
119
118
  );
120
119
 
120
+ useEffect(() => {
121
+ if (inputRef.current !== null) {
122
+ inputRef.current.focus({
123
+ cursor: 'end',
124
+ });
125
+ }
126
+ });
127
+
121
128
  const handValueSave = useCallback(() => {
122
129
  cellView.model.resultVariable = getDfVariableName(
123
130
  cellView.parent.model.cells.filter(
@@ -137,6 +144,11 @@ const LibroSqlVariableNameInput: React.FC<LibroSqlVariableProps> = ({
137
144
  status={`${resultVariableAvailable ? '' : 'warning'}`}
138
145
  className="libro-sql-variable-name-input"
139
146
  onChange={handleValueChange}
147
+ onBlur={handValueSave}
148
+ onFocus={() => {
149
+ contextKey.disableCommandMode();
150
+ }}
151
+ ref={inputRef}
140
152
  defaultValue={cellView.model.resultVariable}
141
153
  />
142
154
 
@@ -145,28 +157,19 @@ const LibroSqlVariableNameInput: React.FC<LibroSqlVariableProps> = ({
145
157
  {l10n.t('当前变量名已存在')}
146
158
  </span>
147
159
  )}
148
-
149
- <div className="libro-sql-input-button">
150
- <span onClick={handCancel} className="libro-sql-input-cancel">
151
- {l10n.t('取消')}
152
- </span>
153
- <span onClick={handValueSave} className="libro-sql-input-save">
154
- {l10n.t('保存')}
155
- </span>
156
- </div>
157
160
  </>
158
161
  );
159
162
  };
160
163
 
161
164
  export const LibroSqlCell = React.forwardRef<HTMLDivElement>(
162
165
  function SqlEditorViewComponent(props, ref) {
163
- const [isVariableNameEdit, setIsVariableNameEdit] = useState(false);
164
166
  const instance = useInject<LibroSqlCellView>(ViewInstance);
165
167
  const contextKey = useInject(LibroContextKey);
168
+ const [edit, setEdit] = useState(false);
166
169
 
167
170
  const handCancelEdit = () => {
168
171
  contextKey.enableCommandMode();
169
- setIsVariableNameEdit(false);
172
+ setEdit(false);
170
173
  };
171
174
 
172
175
  return (
@@ -186,36 +189,26 @@ export const LibroSqlCell = React.forwardRef<HTMLDivElement>(
186
189
  </div>
187
190
  <div className="libro-sql-variable-name">
188
191
  <span className="libro-sql-variable-name-title">Name: </span>
189
- <span className="libro-sql-variable-content">
190
- {instance.model.resultVariable}
191
- </span>
192
- <div
193
- className="libro-sql-variable-name-popover"
194
- style={{ display: 'inline-block' }}
195
- >
196
- <Popover
197
- content={<LibroSqlVariableNameInput handCancel={handCancelEdit} />}
198
- placement="bottomLeft"
199
- open={instance.parent.model.inputEditable ? isVariableNameEdit : false}
200
- onOpenChange={(visible) => {
201
- if (visible) {
202
- contextKey.disableCommandMode();
203
- } else {
204
- contextKey.enableCommandMode();
205
- }
206
- setIsVariableNameEdit(visible);
192
+ {edit ? (
193
+ <LibroSqlVariableNameInput handCancel={handCancelEdit} />
194
+ ) : (
195
+ <span
196
+ className="libro-sql-variable-content"
197
+ onDoubleClick={() => {
198
+ setEdit(true);
207
199
  }}
208
- getPopupContainer={() => {
209
- return instance.container?.current?.getElementsByClassName(
210
- 'libro-sql-variable-name',
211
- )[0] as HTMLElement;
212
- }}
213
- trigger="click"
214
- overlayClassName="libro-sql-popover-container"
215
200
  >
216
- <EditFilled className="libro-sql-edit-icon" />
217
- </Popover>
218
- </div>
201
+ {instance.model.resultVariable}
202
+ </span>
203
+ )}
204
+ {!edit && (
205
+ <EditFilled
206
+ className="libro-sql-edit-icon"
207
+ onClick={() => {
208
+ setEdit(true);
209
+ }}
210
+ />
211
+ )}
219
212
  </div>
220
213
  </div>
221
214
  <CellEditor />
@@ -226,20 +219,13 @@ export const LibroSqlCell = React.forwardRef<HTMLDivElement>(
226
219
 
227
220
  @transient()
228
221
  @view('libro-sql-cell-view')
229
- export class LibroSqlCellView extends LibroExecutableCellView {
222
+ export class LibroSqlCellView extends LibroEditableExecutableCellView {
230
223
  override view = LibroSqlCell;
231
224
  declare model: LibroSqlCellModel;
232
225
  libroViewTracker: LibroViewTracker;
233
- codeEditorManager: CodeEditorManager;
234
- protected toDisposeOnEditor = new DisposableCollection();
235
-
236
- @inject(LibroContextKey) protected readonly libroContextKey: LibroContextKey;
237
226
 
238
227
  outputs: IOutput[];
239
228
 
240
- @prop()
241
- editorView?: CodeEditorView;
242
-
243
229
  @prop()
244
230
  databaseConfig?: DatabaseConfig;
245
231
 
@@ -353,74 +339,6 @@ export class LibroSqlCellView extends LibroExecutableCellView {
353
339
  this.codeEditorManager.setEditorHostRef(editorHostId, ref);
354
340
  }
355
341
 
356
- async createEditor() {
357
- const editorHostId = this.parent.id + this.id;
358
- const option: CodeEditorViewOptions = {
359
- uuid: CellUri.from(this.parent.model.id, this.model.id).toString(),
360
- editorHostId: editorHostId,
361
- model: this.model,
362
- config: {
363
- readOnly: !this.parent.model.inputEditable,
364
- editable: this.parent.model.inputEditable,
365
- },
366
- };
367
- // 防止虚拟滚动中编辑器被频繁创建
368
- if (this.editorView) {
369
- this.editorStatus = EditorStatus.LOADED;
370
- return;
371
- }
372
-
373
- const editorView = await this.codeEditorManager.getOrCreateEditorView(option);
374
-
375
- this.editorView = editorView;
376
- this.editorStatus = EditorStatus.LOADED;
377
- this.editorViewReadyDeferred.resolve();
378
- editorView.onEditorStatusChange((e) => {
379
- if (e.status === 'ready') {
380
- this.editor = this.editorView!.editor;
381
- this.afterEditorReady();
382
- } else if (e.status === 'disposed') {
383
- this.toDisposeOnEditor.dispose();
384
- }
385
- });
386
- }
387
-
388
- protected async afterEditorReady() {
389
- this.focusEditor();
390
- this.toDisposeOnEditor.push(
391
- watch(this.parent.model, 'inputEditable', () => {
392
- this.editorView?.editor?.setOption(
393
- 'readOnly',
394
- getOrigin(!this.parent.model.inputEditable),
395
- );
396
- }),
397
- );
398
- this.toDisposeOnEditor.push(
399
- this.editorView?.onModalChange((val) => (this.hasModal = val)) ?? Disposable.NONE,
400
- );
401
- this.toDisposeOnEditor.push(
402
- this.editor?.onModelContentChanged?.((e) => {
403
- this.parent.model.onCellContentChange({ cell: this, changes: e });
404
- }) ?? Disposable.NONE,
405
- );
406
- }
407
-
408
- protected focusEditor() {
409
- //选中cell、编辑模式、非只读时才focus
410
- if (
411
- this.editorView?.editor &&
412
- this.editorView.editorStatus === 'ready' &&
413
- this.parent.model.active?.id === this.id &&
414
- !this.parent.model.commandMode &&
415
- this.libroContextKey.commandModeEnabled === true && // 排除弹窗等情况
416
- this.parent.model.inputEditable
417
- ) {
418
- this.editorView?.editor.setOption('styleActiveLine', true);
419
- this.editorView?.editor.setOption('highlightActiveLineGutter', true);
420
- this.editorView?.editor.focus();
421
- }
422
- }
423
-
424
342
  override onViewResize = (size: ViewSize): void => {
425
343
  // 把 header 部分高度也放在这部分,用来撑开高度
426
344
  if (size.height) {
@@ -449,11 +367,6 @@ export class LibroSqlCellView extends LibroExecutableCellView {
449
367
  }
450
368
  };
451
369
 
452
- override blur = () => {
453
- this.editorView?.editor?.setOption('styleActiveLine', false);
454
- this.editorView?.editor?.setOption('highlightActiveLineGutter', false);
455
- };
456
-
457
370
  override clearExecution = () => {
458
371
  this.model.clearExecution();
459
372
  this.outputArea.clear();
@@ -591,10 +504,4 @@ export class LibroSqlCellView extends LibroExecutableCellView {
591
504
  }),
592
505
  );
593
506
  };
594
-
595
- override shouldEnterEditorMode(e: React.FocusEvent<HTMLElement>) {
596
- return getOrigin(this.editorView)?.editor?.host?.contains(e.target as HTMLElement)
597
- ? true
598
- : false;
599
- }
600
507
  }