@difizen/libro-code-cell 0.1.14 → 0.1.16
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/code-cell-view.d.ts +3 -3
- package/es/code-cell-view.d.ts.map +1 -1
- package/es/code-cell-view.js +51 -62
- package/package.json +4 -4
- package/src/code-cell-view.tsx +27 -39
package/es/code-cell-view.d.ts
CHANGED
|
@@ -3,12 +3,13 @@ import type { CodeEditorViewOptions, CodeEditorView } from '@difizen/libro-code-
|
|
|
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 } from '@difizen/libro-core';
|
|
6
|
+
import { CellService, EditorStatus, LibroExecutableCellView, LibroOutputArea, LirboContextKey } from '@difizen/libro-core';
|
|
7
7
|
import type { ViewSize } from '@difizen/mana-app';
|
|
8
8
|
import { ViewManager, Deferred } from '@difizen/mana-app';
|
|
9
9
|
import type { LibroCodeCellModel } from './code-cell-model.js';
|
|
10
10
|
export declare const CellEditorMemo: import("react").NamedExoticComponent<{}>;
|
|
11
11
|
export declare class LibroCodeCellView extends LibroExecutableCellView {
|
|
12
|
+
protected readonly lirboContextKey: LirboContextKey;
|
|
12
13
|
view: import("react").ForwardRefExoticComponent<import("react").RefAttributes<HTMLDivElement>>;
|
|
13
14
|
viewManager: ViewManager;
|
|
14
15
|
codeEditorManager: CodeEditorManager;
|
|
@@ -19,8 +20,6 @@ export declare class LibroCodeCellView extends LibroExecutableCellView {
|
|
|
19
20
|
noEditorAreaHeight: number;
|
|
20
21
|
cellViewTopPos: number;
|
|
21
22
|
editorStatus: EditorStatus;
|
|
22
|
-
protected editorViewReadyDeferred: Deferred<void>;
|
|
23
|
-
get editorReady(): Promise<void>;
|
|
24
23
|
protected outputAreaDeferred: Deferred<LibroOutputArea>;
|
|
25
24
|
get outputAreaReady(): Promise<LibroOutputArea>;
|
|
26
25
|
renderEditor: () => import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -34,6 +33,7 @@ export declare class LibroCodeCellView extends LibroExecutableCellView {
|
|
|
34
33
|
protected getEditorOption(): CodeEditorViewOptions;
|
|
35
34
|
protected createEditor(): Promise<void>;
|
|
36
35
|
protected afterEditorReady(): Promise<void>;
|
|
36
|
+
protected focusEditor(): void;
|
|
37
37
|
shouldEnterEditorMode(e: React.FocusEvent<HTMLElement>): boolean;
|
|
38
38
|
blur: () => void;
|
|
39
39
|
focus: (toEdit: boolean) => void;
|
|
@@ -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;AAEhE,OAAO,KAAK,EAEV,SAAS,EACT,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,eAAe,
|
|
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;AAEhE,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;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,uBAAuB;IACnC,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,GAAG;IAKtB,SAAS,CAAC,eAAe,IAAI,qBAAqB;cAclC,YAAY;cAwBZ,gBAAgB;IAWhC,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"}
|
package/es/code-cell-view.js
CHANGED
|
@@ -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, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5;
|
|
2
|
+
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6;
|
|
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; }
|
|
@@ -29,7 +29,7 @@ function _initializerWarningHelper(descriptor, context) { throw new Error('Decor
|
|
|
29
29
|
|
|
30
30
|
import { CodeEditorManager } from '@difizen/libro-code-editor';
|
|
31
31
|
import { isOutput } from '@difizen/libro-common';
|
|
32
|
-
import { CellService, EditorStatus, LibroExecutableCellView, LibroOutputArea, VirtualizedManagerHelper } from '@difizen/libro-core';
|
|
32
|
+
import { CellService, EditorStatus, LibroExecutableCellView, LibroOutputArea, VirtualizedManagerHelper, LirboContextKey } from '@difizen/libro-core';
|
|
33
33
|
import { getOrigin, inject, prop, transient, useInject, view, ViewInstance, ViewManager, ViewOption, ViewRender, watch, Deferred } from '@difizen/mana-app';
|
|
34
34
|
import { useEffect, useRef, memo, forwardRef } from 'react';
|
|
35
35
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -83,7 +83,7 @@ var CodeEditorViewComponent = /*#__PURE__*/forwardRef(function CodeEditorViewCom
|
|
|
83
83
|
children: /*#__PURE__*/_jsx(CellEditorMemo, {})
|
|
84
84
|
});
|
|
85
85
|
});
|
|
86
|
-
export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-cell-view'), _dec3 =
|
|
86
|
+
export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-cell-view'), _dec3 = inject(LirboContextKey), _dec4 = prop(), _dec5 = prop(), _dec6 = prop(), _dec7 = prop(), _dec8 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroExecutableCellV) {
|
|
87
87
|
_inherits(LibroCodeCellView, _LibroExecutableCellV);
|
|
88
88
|
var _super = _createSuper(LibroCodeCellView);
|
|
89
89
|
function LibroCodeCellView(options, cellService, viewManager, codeEditorManager) {
|
|
@@ -91,16 +91,16 @@ export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-ce
|
|
|
91
91
|
var _this;
|
|
92
92
|
_classCallCheck(this, LibroCodeCellView);
|
|
93
93
|
_this = _super.call(this, options, cellService);
|
|
94
|
+
_initializerDefineProperty(_this, "lirboContextKey", _descriptor, _assertThisInitialized(_this));
|
|
94
95
|
_this.view = CodeEditorViewComponent;
|
|
95
96
|
_this.viewManager = void 0;
|
|
96
97
|
_this.codeEditorManager = void 0;
|
|
97
98
|
_this.outputs = void 0;
|
|
98
|
-
_initializerDefineProperty(_this, "editorView",
|
|
99
|
-
_initializerDefineProperty(_this, "editorAreaHeight",
|
|
100
|
-
_initializerDefineProperty(_this, "noEditorAreaHeight",
|
|
101
|
-
_initializerDefineProperty(_this, "cellViewTopPos",
|
|
102
|
-
_initializerDefineProperty(_this, "editorStatus",
|
|
103
|
-
_this.editorViewReadyDeferred = new Deferred();
|
|
99
|
+
_initializerDefineProperty(_this, "editorView", _descriptor2, _assertThisInitialized(_this));
|
|
100
|
+
_initializerDefineProperty(_this, "editorAreaHeight", _descriptor3, _assertThisInitialized(_this));
|
|
101
|
+
_initializerDefineProperty(_this, "noEditorAreaHeight", _descriptor4, _assertThisInitialized(_this));
|
|
102
|
+
_initializerDefineProperty(_this, "cellViewTopPos", _descriptor5, _assertThisInitialized(_this));
|
|
103
|
+
_initializerDefineProperty(_this, "editorStatus", _descriptor6, _assertThisInitialized(_this));
|
|
104
104
|
_this.outputAreaDeferred = new Deferred();
|
|
105
105
|
_this.renderEditor = function () {
|
|
106
106
|
if (_this.editorView) {
|
|
@@ -117,33 +117,7 @@ export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-ce
|
|
|
117
117
|
};
|
|
118
118
|
_this.focus = function (toEdit) {
|
|
119
119
|
if (toEdit) {
|
|
120
|
-
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if (!_this.editorView) {
|
|
124
|
-
_this.editorReady.then(function () {
|
|
125
|
-
var _this$editorView3;
|
|
126
|
-
(_this$editorView3 = _this.editorView) === null || _this$editorView3 === void 0 || _this$editorView3.editorReady.then(function () {
|
|
127
|
-
var _this$editorView4, _this$editorView5, _this$editorView6, _this$editorView7;
|
|
128
|
-
(_this$editorView4 = _this.editorView) === null || _this$editorView4 === void 0 || (_this$editorView4 = _this$editorView4.editor) === null || _this$editorView4 === void 0 || _this$editorView4.setOption('styleActiveLine', true);
|
|
129
|
-
(_this$editorView5 = _this.editorView) === null || _this$editorView5 === void 0 || (_this$editorView5 = _this$editorView5.editor) === null || _this$editorView5 === void 0 || _this$editorView5.setOption('highlightActiveLineGutter', true);
|
|
130
|
-
if ((_this$editorView6 = _this.editorView) !== null && _this$editorView6 !== void 0 && (_this$editorView6 = _this$editorView6.editor) !== null && _this$editorView6 !== void 0 && _this$editorView6.hasFocus()) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
(_this$editorView7 = _this.editorView) === null || _this$editorView7 === void 0 || (_this$editorView7 = _this$editorView7.editor) === null || _this$editorView7 === void 0 || _this$editorView7.focus();
|
|
134
|
-
return;
|
|
135
|
-
});
|
|
136
|
-
return;
|
|
137
|
-
}).catch(console.error);
|
|
138
|
-
} else {
|
|
139
|
-
var _this$editorView8, _this$editorView9, _this$editorView10, _this$editorView11;
|
|
140
|
-
(_this$editorView8 = _this.editorView) === null || _this$editorView8 === void 0 || (_this$editorView8 = _this$editorView8.editor) === null || _this$editorView8 === void 0 || _this$editorView8.setOption('styleActiveLine', true);
|
|
141
|
-
(_this$editorView9 = _this.editorView) === null || _this$editorView9 === void 0 || (_this$editorView9 = _this$editorView9.editor) === null || _this$editorView9 === void 0 || _this$editorView9.setOption('highlightActiveLineGutter', true);
|
|
142
|
-
if ((_this$editorView10 = _this.editorView) !== null && _this$editorView10 !== void 0 && (_this$editorView10 = _this$editorView10.editor) !== null && _this$editorView10 !== void 0 && _this$editorView10.hasFocus()) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
(_this$editorView11 = _this.editorView) === null || _this$editorView11 === void 0 || (_this$editorView11 = _this$editorView11.editor) === null || _this$editorView11 === void 0 || _this$editorView11.focus();
|
|
146
|
-
}
|
|
120
|
+
_this.focusEditor();
|
|
147
121
|
} else {
|
|
148
122
|
var _this$container, _this$container2;
|
|
149
123
|
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)) {
|
|
@@ -201,11 +175,6 @@ export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-ce
|
|
|
201
175
|
LibroCodeCellView = inject(CellService)(LibroCodeCellView, undefined, 1) || LibroCodeCellView;
|
|
202
176
|
LibroCodeCellView = inject(ViewOption)(LibroCodeCellView, undefined, 0) || LibroCodeCellView;
|
|
203
177
|
_createClass(LibroCodeCellView, [{
|
|
204
|
-
key: "editorReady",
|
|
205
|
-
get: function get() {
|
|
206
|
-
return this.editorViewReadyDeferred.promise;
|
|
207
|
-
}
|
|
208
|
-
}, {
|
|
209
178
|
key: "outputAreaReady",
|
|
210
179
|
get: function get() {
|
|
211
180
|
return this.outputAreaDeferred.promise;
|
|
@@ -256,12 +225,7 @@ export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-ce
|
|
|
256
225
|
}, {
|
|
257
226
|
key: "onViewMount",
|
|
258
227
|
value: function onViewMount() {
|
|
259
|
-
var _this$parent$model$ac;
|
|
260
228
|
this.createEditor();
|
|
261
|
-
//选中cell时才focus
|
|
262
|
-
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) {
|
|
263
|
-
this.focus(!this.parent.model.commandMode);
|
|
264
|
-
}
|
|
265
229
|
}
|
|
266
230
|
}, {
|
|
267
231
|
key: "setEditorHost",
|
|
@@ -273,6 +237,7 @@ export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-ce
|
|
|
273
237
|
key: "getEditorOption",
|
|
274
238
|
value: function getEditorOption() {
|
|
275
239
|
var option = {
|
|
240
|
+
uuid: "".concat(this.parent.model.id, "-").concat(this.model.id),
|
|
276
241
|
editorHostId: this.parent.id + this.id,
|
|
277
242
|
model: this.model,
|
|
278
243
|
config: {
|
|
@@ -287,6 +252,7 @@ export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-ce
|
|
|
287
252
|
key: "createEditor",
|
|
288
253
|
value: function () {
|
|
289
254
|
var _createEditor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
255
|
+
var _this3 = this;
|
|
290
256
|
var option, editorView;
|
|
291
257
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
292
258
|
while (1) switch (_context2.prev = _context2.next) {
|
|
@@ -307,11 +273,14 @@ export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-ce
|
|
|
307
273
|
case 7:
|
|
308
274
|
editorView = _context2.sent;
|
|
309
275
|
this.editorView = editorView;
|
|
310
|
-
this.editorViewReadyDeferred.resolve();
|
|
311
276
|
this.editorStatus = EditorStatus.LOADED;
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
277
|
+
editorView.onEditorStatusChange(function (e) {
|
|
278
|
+
if (e.status === 'ready') {
|
|
279
|
+
_this3.editor = _this3.editorView.editor;
|
|
280
|
+
_this3.afterEditorReady();
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
case 11:
|
|
315
284
|
case "end":
|
|
316
285
|
return _context2.stop();
|
|
317
286
|
}
|
|
@@ -326,19 +295,20 @@ export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-ce
|
|
|
326
295
|
key: "afterEditorReady",
|
|
327
296
|
value: function () {
|
|
328
297
|
var _afterEditorReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
329
|
-
var
|
|
330
|
-
_this$
|
|
298
|
+
var _this4 = this,
|
|
299
|
+
_this$editorView3;
|
|
331
300
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
332
301
|
while (1) switch (_context3.prev = _context3.next) {
|
|
333
302
|
case 0:
|
|
334
303
|
watch(this.parent.model, 'readOnly', function () {
|
|
335
|
-
var
|
|
336
|
-
(
|
|
304
|
+
var _this4$editorView;
|
|
305
|
+
(_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.readOnly));
|
|
337
306
|
});
|
|
338
|
-
(_this$
|
|
339
|
-
return
|
|
307
|
+
(_this$editorView3 = this.editorView) === null || _this$editorView3 === void 0 || _this$editorView3.onModalChange(function (val) {
|
|
308
|
+
return _this4.hasModal = val;
|
|
340
309
|
});
|
|
341
|
-
|
|
310
|
+
this.focusEditor();
|
|
311
|
+
case 3:
|
|
342
312
|
case "end":
|
|
343
313
|
return _context3.stop();
|
|
344
314
|
}
|
|
@@ -349,6 +319,20 @@ export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-ce
|
|
|
349
319
|
}
|
|
350
320
|
return afterEditorReady;
|
|
351
321
|
}()
|
|
322
|
+
}, {
|
|
323
|
+
key: "focusEditor",
|
|
324
|
+
value: function focusEditor() {
|
|
325
|
+
var _this$editorView4, _this$parent$model$ac;
|
|
326
|
+
//选中cell、编辑模式、非只读时才focus
|
|
327
|
+
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.lirboContextKey.commandModeEnabled === true &&
|
|
328
|
+
// 排除弹窗等情况
|
|
329
|
+
this.parent.model.readOnly === false) {
|
|
330
|
+
var _this$editorView5, _this$editorView6, _this$editorView7;
|
|
331
|
+
(_this$editorView5 = this.editorView) === null || _this$editorView5 === void 0 || _this$editorView5.editor.setOption('styleActiveLine', true);
|
|
332
|
+
(_this$editorView6 = this.editorView) === null || _this$editorView6 === void 0 || _this$editorView6.editor.setOption('highlightActiveLineGutter', true);
|
|
333
|
+
(_this$editorView7 = this.editorView) === null || _this$editorView7 === void 0 || _this$editorView7.editor.focus();
|
|
334
|
+
}
|
|
335
|
+
}
|
|
352
336
|
}, {
|
|
353
337
|
key: "shouldEnterEditorMode",
|
|
354
338
|
value: function shouldEnterEditorMode(e) {
|
|
@@ -357,33 +341,38 @@ export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-ce
|
|
|
357
341
|
}
|
|
358
342
|
}]);
|
|
359
343
|
return LibroCodeCellView;
|
|
360
|
-
}(LibroExecutableCellView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "
|
|
344
|
+
}(LibroExecutableCellView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "lirboContextKey", [_dec3], {
|
|
345
|
+
configurable: true,
|
|
346
|
+
enumerable: true,
|
|
347
|
+
writable: true,
|
|
348
|
+
initializer: null
|
|
349
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "editorView", [_dec4], {
|
|
361
350
|
configurable: true,
|
|
362
351
|
enumerable: true,
|
|
363
352
|
writable: true,
|
|
364
353
|
initializer: null
|
|
365
|
-
}),
|
|
354
|
+
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "editorAreaHeight", [_dec5], {
|
|
366
355
|
configurable: true,
|
|
367
356
|
enumerable: true,
|
|
368
357
|
writable: true,
|
|
369
358
|
initializer: function initializer() {
|
|
370
359
|
return 0;
|
|
371
360
|
}
|
|
372
|
-
}),
|
|
361
|
+
}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "noEditorAreaHeight", [_dec6], {
|
|
373
362
|
configurable: true,
|
|
374
363
|
enumerable: true,
|
|
375
364
|
writable: true,
|
|
376
365
|
initializer: function initializer() {
|
|
377
366
|
return 0;
|
|
378
367
|
}
|
|
379
|
-
}),
|
|
368
|
+
}), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "cellViewTopPos", [_dec7], {
|
|
380
369
|
configurable: true,
|
|
381
370
|
enumerable: true,
|
|
382
371
|
writable: true,
|
|
383
372
|
initializer: function initializer() {
|
|
384
373
|
return 0;
|
|
385
374
|
}
|
|
386
|
-
}),
|
|
375
|
+
}), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "editorStatus", [_dec8], {
|
|
387
376
|
configurable: true,
|
|
388
377
|
enumerable: true,
|
|
389
378
|
writable: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@difizen/libro-code-cell",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
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.1.
|
|
36
|
-
"@difizen/libro-common": "^0.1.
|
|
37
|
-
"@difizen/libro-core": "^0.1.
|
|
35
|
+
"@difizen/libro-code-editor": "^0.1.16",
|
|
36
|
+
"@difizen/libro-common": "^0.1.16",
|
|
37
|
+
"@difizen/libro-core": "^0.1.16",
|
|
38
38
|
"@difizen/mana-app": "latest"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
package/src/code-cell-view.tsx
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
LibroExecutableCellView,
|
|
17
17
|
LibroOutputArea,
|
|
18
18
|
VirtualizedManagerHelper,
|
|
19
|
+
LirboContextKey,
|
|
19
20
|
} from '@difizen/libro-core';
|
|
20
21
|
import type { ViewSize } from '@difizen/mana-app';
|
|
21
22
|
import {
|
|
@@ -99,6 +100,7 @@ const CodeEditorViewComponent = forwardRef<HTMLDivElement>(
|
|
|
99
100
|
@transient()
|
|
100
101
|
@view('code-editor-cell-view')
|
|
101
102
|
export class LibroCodeCellView extends LibroExecutableCellView {
|
|
103
|
+
@inject(LirboContextKey) protected readonly lirboContextKey: LirboContextKey;
|
|
102
104
|
override view = CodeEditorViewComponent;
|
|
103
105
|
|
|
104
106
|
viewManager: ViewManager;
|
|
@@ -124,12 +126,6 @@ export class LibroCodeCellView extends LibroExecutableCellView {
|
|
|
124
126
|
@prop()
|
|
125
127
|
override editorStatus: EditorStatus = EditorStatus.NOTLOADED;
|
|
126
128
|
|
|
127
|
-
protected editorViewReadyDeferred: Deferred<void> = new Deferred<void>();
|
|
128
|
-
|
|
129
|
-
get editorReady() {
|
|
130
|
-
return this.editorViewReadyDeferred.promise;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
129
|
protected outputAreaDeferred = new Deferred<LibroOutputArea>();
|
|
134
130
|
get outputAreaReady() {
|
|
135
131
|
return this.outputAreaDeferred.promise;
|
|
@@ -219,20 +215,16 @@ export class LibroCodeCellView extends LibroExecutableCellView {
|
|
|
219
215
|
|
|
220
216
|
override onViewMount() {
|
|
221
217
|
this.createEditor();
|
|
222
|
-
//选中cell时才focus
|
|
223
|
-
if (this.parent.model.active?.id === this.id) {
|
|
224
|
-
this.focus(!this.parent.model.commandMode);
|
|
225
|
-
}
|
|
226
218
|
}
|
|
227
219
|
|
|
228
220
|
setEditorHost(ref: any) {
|
|
229
221
|
const editorHostId = this.parent.id + this.id;
|
|
230
|
-
|
|
231
222
|
this.codeEditorManager.setEditorHostRef(editorHostId, ref);
|
|
232
223
|
}
|
|
233
224
|
|
|
234
225
|
protected getEditorOption(): CodeEditorViewOptions {
|
|
235
226
|
const option: CodeEditorViewOptions = {
|
|
227
|
+
uuid: `${this.parent.model.id}-${this.model.id}`,
|
|
236
228
|
editorHostId: this.parent.id + this.id,
|
|
237
229
|
model: this.model,
|
|
238
230
|
config: {
|
|
@@ -258,10 +250,14 @@ export class LibroCodeCellView extends LibroExecutableCellView {
|
|
|
258
250
|
const editorView = await this.codeEditorManager.getOrCreateEditorView(option);
|
|
259
251
|
|
|
260
252
|
this.editorView = editorView;
|
|
261
|
-
this.editorViewReadyDeferred.resolve();
|
|
262
253
|
this.editorStatus = EditorStatus.LOADED;
|
|
263
254
|
|
|
264
|
-
|
|
255
|
+
editorView.onEditorStatusChange((e) => {
|
|
256
|
+
if (e.status === 'ready') {
|
|
257
|
+
this.editor = this.editorView!.editor;
|
|
258
|
+
this.afterEditorReady();
|
|
259
|
+
}
|
|
260
|
+
});
|
|
265
261
|
}
|
|
266
262
|
|
|
267
263
|
protected async afterEditorReady() {
|
|
@@ -272,6 +268,23 @@ export class LibroCodeCellView extends LibroExecutableCellView {
|
|
|
272
268
|
);
|
|
273
269
|
});
|
|
274
270
|
this.editorView?.onModalChange((val) => (this.hasModal = val));
|
|
271
|
+
this.focusEditor();
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
protected focusEditor() {
|
|
275
|
+
//选中cell、编辑模式、非只读时才focus
|
|
276
|
+
if (
|
|
277
|
+
this.editorView?.editor &&
|
|
278
|
+
this.editorView.editorStatus === 'ready' &&
|
|
279
|
+
this.parent.model.active?.id === this.id &&
|
|
280
|
+
!this.parent.model.commandMode &&
|
|
281
|
+
this.lirboContextKey.commandModeEnabled === true && // 排除弹窗等情况
|
|
282
|
+
this.parent.model.readOnly === false
|
|
283
|
+
) {
|
|
284
|
+
this.editorView?.editor.setOption('styleActiveLine', true);
|
|
285
|
+
this.editorView?.editor.setOption('highlightActiveLineGutter', true);
|
|
286
|
+
this.editorView?.editor.focus();
|
|
287
|
+
}
|
|
275
288
|
}
|
|
276
289
|
|
|
277
290
|
override shouldEnterEditorMode(e: React.FocusEvent<HTMLElement>) {
|
|
@@ -287,32 +300,7 @@ export class LibroCodeCellView extends LibroExecutableCellView {
|
|
|
287
300
|
|
|
288
301
|
override focus = (toEdit: boolean) => {
|
|
289
302
|
if (toEdit) {
|
|
290
|
-
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
if (!this.editorView) {
|
|
294
|
-
this.editorReady
|
|
295
|
-
.then(() => {
|
|
296
|
-
this.editorView?.editorReady.then(() => {
|
|
297
|
-
this.editorView?.editor?.setOption('styleActiveLine', true);
|
|
298
|
-
this.editorView?.editor?.setOption('highlightActiveLineGutter', true);
|
|
299
|
-
if (this.editorView?.editor?.hasFocus()) {
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
this.editorView?.editor?.focus();
|
|
303
|
-
return;
|
|
304
|
-
});
|
|
305
|
-
return;
|
|
306
|
-
})
|
|
307
|
-
.catch(console.error);
|
|
308
|
-
} else {
|
|
309
|
-
this.editorView?.editor?.setOption('styleActiveLine', true);
|
|
310
|
-
this.editorView?.editor?.setOption('highlightActiveLineGutter', true);
|
|
311
|
-
if (this.editorView?.editor?.hasFocus()) {
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
this.editorView?.editor?.focus();
|
|
315
|
-
}
|
|
303
|
+
this.focusEditor();
|
|
316
304
|
} else {
|
|
317
305
|
if (this.container?.current?.parentElement?.contains(document.activeElement)) {
|
|
318
306
|
return;
|