@difizen/libro-code-cell 0.0.0-snapshot-20241017072317
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/LICENSE +21 -0
- package/README.md +3 -0
- package/es/code-cell-contribution.d.ts +15 -0
- package/es/code-cell-contribution.d.ts.map +1 -0
- package/es/code-cell-contribution.js +75 -0
- package/es/code-cell-model.d.ts +25 -0
- package/es/code-cell-model.d.ts.map +1 -0
- package/es/code-cell-model.js +108 -0
- package/es/code-cell-protocol.d.ts +5 -0
- package/es/code-cell-protocol.d.ts.map +1 -0
- package/es/code-cell-protocol.js +1 -0
- package/es/code-cell-view.d.ts +33 -0
- package/es/code-cell-view.d.ts.map +1 -0
- package/es/code-cell-view.js +263 -0
- package/es/index.d.ts +6 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +5 -0
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +21 -0
- package/package.json +60 -0
- package/src/code-cell-contribution.ts +45 -0
- package/src/code-cell-model.ts +73 -0
- package/src/code-cell-protocol.ts +6 -0
- package/src/code-cell-view.tsx +237 -0
- package/src/index.spec.ts +10 -0
- package/src/index.ts +5 -0
- package/src/module.ts +25 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present Difizen Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LanguageSpecRegistry } from '@difizen/libro-code-editor';
|
|
2
|
+
import { LanguageSpecContribution } from '@difizen/libro-code-editor';
|
|
3
|
+
import { CellModelContribution, CellViewContribution } from '@difizen/libro-core';
|
|
4
|
+
import type { CellMeta, CellModel, CellOptions } from '@difizen/libro-core';
|
|
5
|
+
import { CodeCellModelFactory } from './code-cell-protocol.js';
|
|
6
|
+
import { LibroCodeCellView } from './code-cell-view.js';
|
|
7
|
+
export declare class CodeEditorCellContribution implements CellModelContribution, CellViewContribution, LanguageSpecContribution {
|
|
8
|
+
libroCellModelFactory: CodeCellModelFactory;
|
|
9
|
+
cellMeta: CellMeta;
|
|
10
|
+
canHandle(options: CellOptions): number;
|
|
11
|
+
createModel(options: CellOptions): Promise<CellModel>;
|
|
12
|
+
view: typeof LibroCodeCellView;
|
|
13
|
+
registerLanguageSpec: (register: LanguageSpecRegistry) => void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=code-cell-contribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-cell-contribution.d.ts","sourceRoot":"","sources":["../src/code-cell-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAG5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,qBAGa,0BACX,YAAW,qBAAqB,EAAE,oBAAoB,EAAE,wBAAwB;IAElD,qBAAqB,EAAE,oBAAoB,CAAC;IAE1E,QAAQ,EAAE,QAAQ,CAIhB;IAEF,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM;IAIjC,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC;IAO3D,IAAI,2BAAqB;IAEzB,oBAAoB,aAAc,oBAAoB,UAOpD;CACH"}
|
|
@@ -0,0 +1,75 @@
|
|
|
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, _class, _class2, _descriptor;
|
|
3
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
4
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
5
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
6
|
+
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
|
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
11
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
12
|
+
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
|
|
13
|
+
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
|
|
14
|
+
import { LanguageSpecContribution } from '@difizen/libro-code-editor';
|
|
15
|
+
import { CellModelContribution, CellViewContribution } from '@difizen/libro-core';
|
|
16
|
+
import { inject, singleton } from '@difizen/mana-app';
|
|
17
|
+
import { CodeCellModelFactory } from "./code-cell-protocol.js";
|
|
18
|
+
import { LibroCodeCellView } from "./code-cell-view.js";
|
|
19
|
+
export var CodeEditorCellContribution = (_dec = singleton({
|
|
20
|
+
contrib: [CellModelContribution, CellViewContribution, LanguageSpecContribution]
|
|
21
|
+
}), _dec2 = inject(CodeCellModelFactory), _dec(_class = (_class2 = /*#__PURE__*/function () {
|
|
22
|
+
function CodeEditorCellContribution() {
|
|
23
|
+
_classCallCheck(this, CodeEditorCellContribution);
|
|
24
|
+
_initializerDefineProperty(this, "libroCellModelFactory", _descriptor, this);
|
|
25
|
+
this.cellMeta = {
|
|
26
|
+
type: 'code',
|
|
27
|
+
name: 'Python',
|
|
28
|
+
order: 'b'
|
|
29
|
+
};
|
|
30
|
+
this.view = LibroCodeCellView;
|
|
31
|
+
this.registerLanguageSpec = function (register) {
|
|
32
|
+
register.registerLanguageSpec({
|
|
33
|
+
name: 'Python',
|
|
34
|
+
language: 'python',
|
|
35
|
+
ext: ['.py'],
|
|
36
|
+
mime: 'text/x-python'
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
_createClass(CodeEditorCellContribution, [{
|
|
41
|
+
key: "canHandle",
|
|
42
|
+
value: function canHandle(options) {
|
|
43
|
+
var _options$cell;
|
|
44
|
+
return (options === null || options === void 0 || (_options$cell = options.cell) === null || _options$cell === void 0 ? void 0 : _options$cell.cell_type) === this.cellMeta.type ? 1000 : 1;
|
|
45
|
+
}
|
|
46
|
+
}, {
|
|
47
|
+
key: "createModel",
|
|
48
|
+
value: function () {
|
|
49
|
+
var _createModel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
|
|
50
|
+
var model;
|
|
51
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
52
|
+
while (1) switch (_context.prev = _context.next) {
|
|
53
|
+
case 0:
|
|
54
|
+
model = this.libroCellModelFactory(options); // await model.outputAreaReady;
|
|
55
|
+
// model.outputArea.setupCellModel(model);
|
|
56
|
+
return _context.abrupt("return", model);
|
|
57
|
+
case 2:
|
|
58
|
+
case "end":
|
|
59
|
+
return _context.stop();
|
|
60
|
+
}
|
|
61
|
+
}, _callee, this);
|
|
62
|
+
}));
|
|
63
|
+
function createModel(_x) {
|
|
64
|
+
return _createModel.apply(this, arguments);
|
|
65
|
+
}
|
|
66
|
+
return createModel;
|
|
67
|
+
}()
|
|
68
|
+
}]);
|
|
69
|
+
return CodeEditorCellContribution;
|
|
70
|
+
}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "libroCellModelFactory", [_dec2], {
|
|
71
|
+
configurable: true,
|
|
72
|
+
enumerable: true,
|
|
73
|
+
writable: true,
|
|
74
|
+
initializer: null
|
|
75
|
+
})), _class2)) || _class);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ICodeCell, ExecutionCount } from '@difizen/libro-common';
|
|
2
|
+
import type { ExecutableCellModel } from '@difizen/libro-core';
|
|
3
|
+
import { CellOptions, LibroCellModel } from '@difizen/libro-core';
|
|
4
|
+
import type { Event as ManaEvent } from '@difizen/mana-app';
|
|
5
|
+
import { ViewManager } from '@difizen/mana-app';
|
|
6
|
+
import { Emitter } from '@difizen/mana-app';
|
|
7
|
+
/**
|
|
8
|
+
* 基础的可执行代码的cell, 带有执行能力
|
|
9
|
+
*/
|
|
10
|
+
export declare class LibroCodeCellModel extends LibroCellModel implements ExecutableCellModel {
|
|
11
|
+
executeCount: ExecutionCount;
|
|
12
|
+
executing: boolean;
|
|
13
|
+
hasOutputHidden: boolean;
|
|
14
|
+
hasOutputsScrolled: boolean;
|
|
15
|
+
libroFormatType: string;
|
|
16
|
+
viewManager: ViewManager;
|
|
17
|
+
msgChangeEmitter: Emitter<any>;
|
|
18
|
+
get msgChange(): ManaEvent<any>;
|
|
19
|
+
constructor(options: CellOptions, viewManager: ViewManager);
|
|
20
|
+
toJSON(): Omit<ICodeCell, 'outputs'>;
|
|
21
|
+
clearExecution: () => void;
|
|
22
|
+
dispose(): void;
|
|
23
|
+
getSource(): string;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=code-cell-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-cell-model.d.ts","sourceRoot":"","sources":["../src/code-cell-model.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAA2B,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C;;GAEG;AACH,qBACa,kBAAmB,SAAQ,cAAe,YAAW,mBAAmB;IAEnF,YAAY,EAAE,cAAc,CAAC;IAE7B,SAAS,EAAE,OAAO,CAAC;IAEnB,eAAe,EAAE,OAAO,CAAC;IAEzB,kBAAkB,EAAE,OAAO,CAAC;IAEpB,eAAe,EAAE,MAAM,CAAC;IAEhC,WAAW,EAAE,WAAW,CAAC;IAGzB,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAE/B,IAAI,SAAS,IAAI,SAAS,CAAC,GAAG,CAAC,CAE9B;gBAGsB,OAAO,EAAE,WAAW,EACpB,WAAW,EAAE,WAAW;IAYtC,MAAM,IAAI,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC;IAY7C,cAAc,aAGZ;IAEO,OAAO;IAKhB,SAAS;CAGV"}
|
|
@@ -0,0 +1,108 @@
|
|
|
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, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4;
|
|
3
|
+
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
|
|
4
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
6
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
8
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
9
|
+
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
|
10
|
+
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
11
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
12
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
13
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
14
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
15
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
16
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
17
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
18
|
+
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
|
|
19
|
+
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
|
|
20
|
+
import { MIME } from '@difizen/libro-common';
|
|
21
|
+
import { CellOptions, LibroCellModel } from '@difizen/libro-core';
|
|
22
|
+
import { inject, prop, transient, ViewManager } from '@difizen/mana-app';
|
|
23
|
+
import { Emitter } from '@difizen/mana-app';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 基础的可执行代码的cell, 带有执行能力
|
|
27
|
+
*/
|
|
28
|
+
export var LibroCodeCellModel = (_dec = transient(), _dec2 = prop(), _dec3 = prop(), _dec4 = prop(), _dec5 = prop(), _dec(_class = (_class2 = /*#__PURE__*/function (_LibroCellModel) {
|
|
29
|
+
_inherits(LibroCodeCellModel, _LibroCellModel);
|
|
30
|
+
var _super = _createSuper(LibroCodeCellModel);
|
|
31
|
+
function LibroCodeCellModel(options, viewManager) {
|
|
32
|
+
var _this;
|
|
33
|
+
_classCallCheck(this, LibroCodeCellModel);
|
|
34
|
+
_this = _super.call(this, options);
|
|
35
|
+
_initializerDefineProperty(_this, "executeCount", _descriptor, _assertThisInitialized(_this));
|
|
36
|
+
_initializerDefineProperty(_this, "executing", _descriptor2, _assertThisInitialized(_this));
|
|
37
|
+
_initializerDefineProperty(_this, "hasOutputHidden", _descriptor3, _assertThisInitialized(_this));
|
|
38
|
+
_initializerDefineProperty(_this, "hasOutputsScrolled", _descriptor4, _assertThisInitialized(_this));
|
|
39
|
+
_this.viewManager = void 0;
|
|
40
|
+
// Emitter Msg
|
|
41
|
+
_this.msgChangeEmitter = void 0;
|
|
42
|
+
_this.clearExecution = function () {
|
|
43
|
+
_this.executeCount = null;
|
|
44
|
+
_this.executing = false;
|
|
45
|
+
};
|
|
46
|
+
_this.executing = false;
|
|
47
|
+
_this.msgChangeEmitter = new Emitter();
|
|
48
|
+
_this.executeCount = options.cell.execution_count || null;
|
|
49
|
+
_this.mimeType = MIME.python;
|
|
50
|
+
_this.hasOutputHidden = false;
|
|
51
|
+
_this.hasOutputsScrolled = false;
|
|
52
|
+
_this.viewManager = viewManager;
|
|
53
|
+
return _this;
|
|
54
|
+
}
|
|
55
|
+
LibroCodeCellModel = inject(ViewManager)(LibroCodeCellModel, undefined, 1) || LibroCodeCellModel;
|
|
56
|
+
LibroCodeCellModel = inject(CellOptions)(LibroCodeCellModel, undefined, 0) || LibroCodeCellModel;
|
|
57
|
+
_createClass(LibroCodeCellModel, [{
|
|
58
|
+
key: "msgChange",
|
|
59
|
+
get: function get() {
|
|
60
|
+
return this.msgChangeEmitter.event;
|
|
61
|
+
}
|
|
62
|
+
}, {
|
|
63
|
+
key: "toJSON",
|
|
64
|
+
value: function toJSON() {
|
|
65
|
+
// const outputs = this.outputArea?.toJSON() ?? this.outputs;
|
|
66
|
+
return {
|
|
67
|
+
id: this.id,
|
|
68
|
+
cell_type: this.type,
|
|
69
|
+
source: this.source,
|
|
70
|
+
metadata: this.metadata,
|
|
71
|
+
execution_count: this.executeCount
|
|
72
|
+
// outputs: this.outputs,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}, {
|
|
76
|
+
key: "dispose",
|
|
77
|
+
value: function dispose() {
|
|
78
|
+
_get(_getPrototypeOf(LibroCodeCellModel.prototype), "dispose", this).call(this);
|
|
79
|
+
this.msgChangeEmitter.dispose();
|
|
80
|
+
}
|
|
81
|
+
}, {
|
|
82
|
+
key: "getSource",
|
|
83
|
+
value: function getSource() {
|
|
84
|
+
return this.value;
|
|
85
|
+
}
|
|
86
|
+
}]);
|
|
87
|
+
return LibroCodeCellModel;
|
|
88
|
+
}(LibroCellModel), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "executeCount", [_dec2], {
|
|
89
|
+
configurable: true,
|
|
90
|
+
enumerable: true,
|
|
91
|
+
writable: true,
|
|
92
|
+
initializer: null
|
|
93
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "executing", [_dec3], {
|
|
94
|
+
configurable: true,
|
|
95
|
+
enumerable: true,
|
|
96
|
+
writable: true,
|
|
97
|
+
initializer: null
|
|
98
|
+
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "hasOutputHidden", [_dec4], {
|
|
99
|
+
configurable: true,
|
|
100
|
+
enumerable: true,
|
|
101
|
+
writable: true,
|
|
102
|
+
initializer: null
|
|
103
|
+
}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "hasOutputsScrolled", [_dec5], {
|
|
104
|
+
configurable: true,
|
|
105
|
+
enumerable: true,
|
|
106
|
+
writable: true,
|
|
107
|
+
initializer: null
|
|
108
|
+
})), _class2)) || _class);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CellOptions } from '@difizen/libro-core';
|
|
2
|
+
import type { LibroCodeCellModel } from './code-cell-model.js';
|
|
3
|
+
export type CodeCellModelFactory = (options: CellOptions) => LibroCodeCellModel;
|
|
4
|
+
export declare const CodeCellModelFactory: unique symbol;
|
|
5
|
+
//# sourceMappingURL=code-cell-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-cell-protocol.d.ts","sourceRoot":"","sources":["../src/code-cell-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK,kBAAkB,CAAC;AAChF,eAAO,MAAM,oBAAoB,eAAiC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var CodeCellModelFactory = Symbol('CodeCellModelFactory');
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="react" resolution-mode="require"/>
|
|
2
|
+
import type { CodeEditorViewOptions } from '@difizen/libro-code-editor';
|
|
3
|
+
import { CodeEditorManager } from '@difizen/libro-code-editor';
|
|
4
|
+
import type { IOutput } from '@difizen/libro-common';
|
|
5
|
+
import type { LibroCell, CellViewOptions } from '@difizen/libro-core';
|
|
6
|
+
import { CellService, EditorStatus, LibroEditableExecutableCellView, LibroOutputArea } from '@difizen/libro-core';
|
|
7
|
+
import type { ViewSize } from '@difizen/mana-app';
|
|
8
|
+
import { ViewManager, Deferred } from '@difizen/mana-app';
|
|
9
|
+
import type { LibroCodeCellModel } from './code-cell-model.js';
|
|
10
|
+
export declare const CellEditorMemo: import("react").NamedExoticComponent<{}>;
|
|
11
|
+
export declare class LibroCodeCellView extends LibroEditableExecutableCellView {
|
|
12
|
+
view: import("react").ForwardRefExoticComponent<import("react").RefAttributes<HTMLDivElement>>;
|
|
13
|
+
viewManager: ViewManager;
|
|
14
|
+
model: LibroCodeCellModel;
|
|
15
|
+
outputs: IOutput[];
|
|
16
|
+
editorAreaHeight: number;
|
|
17
|
+
noEditorAreaHeight: number;
|
|
18
|
+
cellViewTopPos: number;
|
|
19
|
+
editorStatus: EditorStatus;
|
|
20
|
+
protected outputAreaDeferred: Deferred<LibroOutputArea>;
|
|
21
|
+
get outputAreaReady(): Promise<LibroOutputArea>;
|
|
22
|
+
renderEditor: () => import("react/jsx-runtime").JSX.Element | null;
|
|
23
|
+
onViewResize(size: ViewSize): void;
|
|
24
|
+
calcEditorAreaHeight(): number;
|
|
25
|
+
constructor(options: CellViewOptions, cellService: CellService, viewManager: ViewManager, codeEditorManager: CodeEditorManager);
|
|
26
|
+
outputWatch(): void;
|
|
27
|
+
toJSON(): LibroCell;
|
|
28
|
+
onViewMount(): void;
|
|
29
|
+
setEditorHost(ref: React.RefObject<HTMLDivElement>): void;
|
|
30
|
+
protected getEditorOption(): CodeEditorViewOptions;
|
|
31
|
+
clearExecution: () => void;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=code-cell-view.d.ts.map
|
|
@@ -0,0 +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,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAa,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAGhE,OAAO,KAAK,EAEV,SAAS,EACT,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,WAAW,EACX,YAAY,EACZ,+BAA+B,EAC/B,eAAe,EAEhB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAQL,WAAW,EAIX,QAAQ,EACT,MAAM,mBAAmB,CAAC;AAG3B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AA2C/D,eAAO,MAAM,cAAc,0CAAmB,CAAC;AAmB/C,qBAEa,iBAAkB,SAAQ,+BAA+B;IAC3D,IAAI,2FAA2B;IAExC,WAAW,EAAE,WAAW,CAAC;IAEjB,KAAK,EAAE,kBAAkB,CAAC;IAElC,OAAO,EAAE,OAAO,EAAE,CAAC;IAGnB,gBAAgB,SAAK;IAGZ,kBAAkB,SAAK;IAGvB,cAAc,SAAK;IAGnB,YAAY,EAAE,YAAY,CAA0B;IAE7D,SAAS,CAAC,kBAAkB,4BAAmC;IAC/D,IAAI,eAAe,6BAElB;IAEQ,YAAY,uDAKnB;IAEO,YAAY,CAAC,IAAI,EAAE,QAAQ;IAMpC,oBAAoB;gBAqBE,OAAO,EAAE,eAAe,EACvB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EAClB,iBAAiB,EAAE,iBAAiB;IA6BxD,WAAW;IAQX,MAAM,IAAI,SAAS;IAQnB,WAAW;IAIpB,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC;cAK/B,eAAe,IAAI,qBAAqB;IAclD,cAAc,aAGrB;CACH"}
|
|
@@ -0,0 +1,263 @@
|
|
|
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, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4;
|
|
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
|
+
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
|
+
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; }
|
|
6
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
7
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
8
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
9
|
+
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
|
|
10
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
12
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
14
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
15
|
+
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
|
16
|
+
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
17
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
18
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
19
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
20
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
21
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
22
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
23
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
24
|
+
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
|
|
25
|
+
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
|
|
26
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
27
|
+
/* eslint-disable @typescript-eslint/no-parameter-properties */
|
|
28
|
+
/* eslint-disable @typescript-eslint/parameter-properties */
|
|
29
|
+
|
|
30
|
+
import { CodeEditorManager } from '@difizen/libro-code-editor';
|
|
31
|
+
import { CellUri } from '@difizen/libro-common';
|
|
32
|
+
import { isOutput } from '@difizen/libro-common';
|
|
33
|
+
import { CellService, EditorStatus, LibroEditableExecutableCellView, LibroOutputArea, VirtualizedManagerHelper } from '@difizen/libro-core';
|
|
34
|
+
import { getOrigin, inject, prop, transient, useInject, view, ViewInstance, ViewManager, ViewOption, ViewRender, watch, Deferred } from '@difizen/mana-app';
|
|
35
|
+
import { useEffect, useRef, memo, forwardRef } from 'react';
|
|
36
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
37
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
38
|
+
function countLines(inputString) {
|
|
39
|
+
var lines = inputString.split('\n');
|
|
40
|
+
return lines.length;
|
|
41
|
+
}
|
|
42
|
+
var CellEditor = function CellEditor() {
|
|
43
|
+
var _instance$editorView3;
|
|
44
|
+
var instance = useInject(ViewInstance);
|
|
45
|
+
var virtualizedManagerHelper = useInject(VirtualizedManagerHelper);
|
|
46
|
+
var virtualizedManager = virtualizedManagerHelper.getOrCreate(instance.parent.model);
|
|
47
|
+
var editorRef = useRef(null);
|
|
48
|
+
useEffect(function () {
|
|
49
|
+
var _instance$editorView;
|
|
50
|
+
if ((_instance$editorView = instance.editorView) !== null && _instance$editorView !== void 0 && _instance$editorView.editor) {
|
|
51
|
+
var _instance$editorView2;
|
|
52
|
+
instance.editor = getOrigin((_instance$editorView2 = instance.editorView) === null || _instance$editorView2 === void 0 ? void 0 : _instance$editorView2.editor);
|
|
53
|
+
}
|
|
54
|
+
}, [instance, (_instance$editorView3 = instance.editorView) === null || _instance$editorView3 === void 0 ? void 0 : _instance$editorView3.editor]);
|
|
55
|
+
if (virtualizedManager.isVirtualized) {
|
|
56
|
+
instance.renderEditorIntoVirtualized = true;
|
|
57
|
+
if (instance.setEditorHost) {
|
|
58
|
+
instance.setEditorHost(editorRef);
|
|
59
|
+
}
|
|
60
|
+
var editorAreaHeight = instance.calcEditorAreaHeight();
|
|
61
|
+
return /*#__PURE__*/_jsx("div", {
|
|
62
|
+
style: {
|
|
63
|
+
height: "".concat(editorAreaHeight || 0, "px"),
|
|
64
|
+
width: '100%'
|
|
65
|
+
},
|
|
66
|
+
ref: editorRef
|
|
67
|
+
});
|
|
68
|
+
} else {
|
|
69
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
70
|
+
children: instance.editorView && /*#__PURE__*/_jsx(ViewRender, {
|
|
71
|
+
view: instance.editorView
|
|
72
|
+
})
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
export var CellEditorMemo = /*#__PURE__*/memo(CellEditor);
|
|
77
|
+
var CodeEditorViewComponent = /*#__PURE__*/forwardRef(function CodeEditorViewComponent(props, ref) {
|
|
78
|
+
var instance = useInject(ViewInstance);
|
|
79
|
+
return /*#__PURE__*/_jsx("div", {
|
|
80
|
+
className: "libro-codemirror-cell-editor",
|
|
81
|
+
ref: ref,
|
|
82
|
+
tabIndex: 10,
|
|
83
|
+
onBlur: instance.blur,
|
|
84
|
+
children: /*#__PURE__*/_jsx(CellEditorMemo, {})
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
export var LibroCodeCellView = (_dec = transient(), _dec2 = view('code-editor-cell-view'), _dec3 = prop(), _dec4 = prop(), _dec5 = prop(), _dec6 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroEditableExecuta) {
|
|
88
|
+
_inherits(LibroCodeCellView, _LibroEditableExecuta);
|
|
89
|
+
var _super = _createSuper(LibroCodeCellView);
|
|
90
|
+
function LibroCodeCellView(options, cellService, viewManager, codeEditorManager) {
|
|
91
|
+
var _options$cell;
|
|
92
|
+
var _this;
|
|
93
|
+
_classCallCheck(this, LibroCodeCellView);
|
|
94
|
+
_this = _super.call(this, options, cellService);
|
|
95
|
+
_this.view = CodeEditorViewComponent;
|
|
96
|
+
_this.viewManager = void 0;
|
|
97
|
+
_this.outputs = void 0;
|
|
98
|
+
_initializerDefineProperty(_this, "editorAreaHeight", _descriptor, _assertThisInitialized(_this));
|
|
99
|
+
_initializerDefineProperty(_this, "noEditorAreaHeight", _descriptor2, _assertThisInitialized(_this));
|
|
100
|
+
_initializerDefineProperty(_this, "cellViewTopPos", _descriptor3, _assertThisInitialized(_this));
|
|
101
|
+
_initializerDefineProperty(_this, "editorStatus", _descriptor4, _assertThisInitialized(_this));
|
|
102
|
+
_this.outputAreaDeferred = new Deferred();
|
|
103
|
+
_this.renderEditor = function () {
|
|
104
|
+
if (_this.editorView) {
|
|
105
|
+
return /*#__PURE__*/_jsx(ViewRender, {
|
|
106
|
+
view: _this.editorView
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
};
|
|
111
|
+
_this.clearExecution = function () {
|
|
112
|
+
_this.model.clearExecution();
|
|
113
|
+
_this.outputArea.clear();
|
|
114
|
+
};
|
|
115
|
+
_this.options = options;
|
|
116
|
+
_this.viewManager = viewManager;
|
|
117
|
+
_this.codeEditorManager = codeEditorManager;
|
|
118
|
+
_this.outputs = (_options$cell = options.cell) === null || _options$cell === void 0 ? void 0 : _options$cell.outputs;
|
|
119
|
+
_this.className = _this.className + ' code';
|
|
120
|
+
|
|
121
|
+
// 创建outputArea
|
|
122
|
+
_this.viewManager.getOrCreateView(LibroOutputArea, {
|
|
123
|
+
cellId: _this.id,
|
|
124
|
+
cell: _assertThisInitialized(_this)
|
|
125
|
+
}).then( /*#__PURE__*/function () {
|
|
126
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(outputArea) {
|
|
127
|
+
var output;
|
|
128
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
129
|
+
while (1) switch (_context.prev = _context.next) {
|
|
130
|
+
case 0:
|
|
131
|
+
_this.outputArea = outputArea;
|
|
132
|
+
output = _this.outputs;
|
|
133
|
+
if (!isOutput(output)) {
|
|
134
|
+
_context.next = 5;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
_context.next = 5;
|
|
138
|
+
return _this.outputArea.fromJSON(output);
|
|
139
|
+
case 5:
|
|
140
|
+
_this.outputAreaDeferred.resolve(outputArea);
|
|
141
|
+
_this.outputWatch();
|
|
142
|
+
return _context.abrupt("return");
|
|
143
|
+
case 8:
|
|
144
|
+
case "end":
|
|
145
|
+
return _context.stop();
|
|
146
|
+
}
|
|
147
|
+
}, _callee);
|
|
148
|
+
}));
|
|
149
|
+
return function (_x) {
|
|
150
|
+
return _ref.apply(this, arguments);
|
|
151
|
+
};
|
|
152
|
+
}()).catch(console.error);
|
|
153
|
+
return _this;
|
|
154
|
+
}
|
|
155
|
+
LibroCodeCellView = inject(CodeEditorManager)(LibroCodeCellView, undefined, 3) || LibroCodeCellView;
|
|
156
|
+
LibroCodeCellView = inject(ViewManager)(LibroCodeCellView, undefined, 2) || LibroCodeCellView;
|
|
157
|
+
LibroCodeCellView = inject(CellService)(LibroCodeCellView, undefined, 1) || LibroCodeCellView;
|
|
158
|
+
LibroCodeCellView = inject(ViewOption)(LibroCodeCellView, undefined, 0) || LibroCodeCellView;
|
|
159
|
+
_createClass(LibroCodeCellView, [{
|
|
160
|
+
key: "outputAreaReady",
|
|
161
|
+
get: function get() {
|
|
162
|
+
return this.outputAreaDeferred.promise;
|
|
163
|
+
}
|
|
164
|
+
}, {
|
|
165
|
+
key: "onViewResize",
|
|
166
|
+
value: function onViewResize(size) {
|
|
167
|
+
if (size.height) {
|
|
168
|
+
this.editorAreaHeight = size.height;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}, {
|
|
172
|
+
key: "calcEditorAreaHeight",
|
|
173
|
+
value: function calcEditorAreaHeight() {
|
|
174
|
+
if (this.editorStatus === EditorStatus.NOTLOADED || this.editorStatus === EditorStatus.LOADING) {
|
|
175
|
+
var _this$codeEditorManag = this.codeEditorManager.getUserEditorConfig(this.model),
|
|
176
|
+
lineHeight = _this$codeEditorManag.lineHeight,
|
|
177
|
+
paddingTop = _this$codeEditorManag.paddingTop,
|
|
178
|
+
paddingBottom = _this$codeEditorManag.paddingBottom,
|
|
179
|
+
scrollBarHeight = _this$codeEditorManag.scrollBarHeight;
|
|
180
|
+
var codeHeight = countLines(this.model.value) * (lineHeight !== null && lineHeight !== void 0 ? lineHeight : 20);
|
|
181
|
+
var editorPadding = paddingTop + paddingBottom;
|
|
182
|
+
var editorAreaHeight = codeHeight + editorPadding + scrollBarHeight;
|
|
183
|
+
this.editorAreaHeight = editorAreaHeight;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// 编辑器已经加载的情况下cell高度都由对它的高度监听得到。
|
|
187
|
+
return this.editorAreaHeight;
|
|
188
|
+
}
|
|
189
|
+
}, {
|
|
190
|
+
key: "outputWatch",
|
|
191
|
+
value: function outputWatch() {
|
|
192
|
+
var _this2 = this;
|
|
193
|
+
this.toDispose.push(watch(this.outputArea, 'outputs', function () {
|
|
194
|
+
var _this2$parent$model$o, _this2$parent$model;
|
|
195
|
+
(_this2$parent$model$o = (_this2$parent$model = _this2.parent.model).onChange) === null || _this2$parent$model$o === void 0 || _this2$parent$model$o.call(_this2$parent$model);
|
|
196
|
+
}));
|
|
197
|
+
}
|
|
198
|
+
}, {
|
|
199
|
+
key: "toJSON",
|
|
200
|
+
value: function toJSON() {
|
|
201
|
+
var _this$outputArea$toJS, _this$outputArea;
|
|
202
|
+
var meta = _get(_getPrototypeOf(LibroCodeCellView.prototype), "toJSON", this).call(this);
|
|
203
|
+
return _objectSpread(_objectSpread({}, meta), {}, {
|
|
204
|
+
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
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}, {
|
|
208
|
+
key: "onViewMount",
|
|
209
|
+
value: function onViewMount() {
|
|
210
|
+
this.createEditor();
|
|
211
|
+
}
|
|
212
|
+
}, {
|
|
213
|
+
key: "setEditorHost",
|
|
214
|
+
value: function setEditorHost(ref) {
|
|
215
|
+
var editorHostId = this.parent.id + this.id;
|
|
216
|
+
this.codeEditorManager.setEditorHostRef(editorHostId, ref);
|
|
217
|
+
}
|
|
218
|
+
}, {
|
|
219
|
+
key: "getEditorOption",
|
|
220
|
+
value: function getEditorOption() {
|
|
221
|
+
var option = {
|
|
222
|
+
uuid: CellUri.from(this.parent.model.id, this.model.id).toString(),
|
|
223
|
+
editorHostId: this.parent.id + this.id,
|
|
224
|
+
model: this.model,
|
|
225
|
+
config: {
|
|
226
|
+
readOnly: !this.parent.model.inputEditable,
|
|
227
|
+
editable: this.parent.model.inputEditable,
|
|
228
|
+
placeholder: '请输入代码'
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
return option;
|
|
232
|
+
}
|
|
233
|
+
}]);
|
|
234
|
+
return LibroCodeCellView;
|
|
235
|
+
}(LibroEditableExecutableCellView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "editorAreaHeight", [_dec3], {
|
|
236
|
+
configurable: true,
|
|
237
|
+
enumerable: true,
|
|
238
|
+
writable: true,
|
|
239
|
+
initializer: function initializer() {
|
|
240
|
+
return 0;
|
|
241
|
+
}
|
|
242
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "noEditorAreaHeight", [_dec4], {
|
|
243
|
+
configurable: true,
|
|
244
|
+
enumerable: true,
|
|
245
|
+
writable: true,
|
|
246
|
+
initializer: function initializer() {
|
|
247
|
+
return 0;
|
|
248
|
+
}
|
|
249
|
+
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "cellViewTopPos", [_dec5], {
|
|
250
|
+
configurable: true,
|
|
251
|
+
enumerable: true,
|
|
252
|
+
writable: true,
|
|
253
|
+
initializer: function initializer() {
|
|
254
|
+
return 0;
|
|
255
|
+
}
|
|
256
|
+
}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "editorStatus", [_dec6], {
|
|
257
|
+
configurable: true,
|
|
258
|
+
enumerable: true,
|
|
259
|
+
writable: true,
|
|
260
|
+
initializer: function initializer() {
|
|
261
|
+
return EditorStatus.NOTLOADED;
|
|
262
|
+
}
|
|
263
|
+
})), _class2)) || _class) || _class);
|
package/es/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC"}
|
package/es/index.js
ADDED
package/es/module.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAO/C,eAAO,MAAM,cAAc,YAeE,CAAC"}
|
package/es/module.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CodeEditorModule } from '@difizen/libro-code-editor';
|
|
2
|
+
import { CellOptions } from '@difizen/libro-core';
|
|
3
|
+
import { ManaModule } from '@difizen/mana-app';
|
|
4
|
+
import { CodeEditorCellContribution } from "./code-cell-contribution.js";
|
|
5
|
+
import { LibroCodeCellModel } from "./code-cell-model.js";
|
|
6
|
+
import { CodeCellModelFactory } from "./code-cell-protocol.js";
|
|
7
|
+
import { LibroCodeCellView } from "./code-cell-view.js";
|
|
8
|
+
export var CodeCellModule = ManaModule.create().register(CodeEditorCellContribution, LibroCodeCellView, LibroCodeCellModel, {
|
|
9
|
+
token: CodeCellModelFactory,
|
|
10
|
+
useFactory: function useFactory(ctx) {
|
|
11
|
+
return function (options) {
|
|
12
|
+
var child = ctx.container.createChild();
|
|
13
|
+
child.register({
|
|
14
|
+
token: CellOptions,
|
|
15
|
+
useValue: options
|
|
16
|
+
});
|
|
17
|
+
var model = child.get(LibroCodeCellModel);
|
|
18
|
+
return model;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}).dependOn(CodeEditorModule);
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@difizen/libro-code-cell",
|
|
3
|
+
"version": "0.0.0-snapshot-20241017072317",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"libro",
|
|
7
|
+
"notebook"
|
|
8
|
+
],
|
|
9
|
+
"repository": "git@github.com:difizen/libro.git",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"typings": "./es/index.d.ts",
|
|
15
|
+
"default": "./es/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./mock": {
|
|
18
|
+
"typings": "./es/mock/index.d.ts",
|
|
19
|
+
"default": "./es/mock/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./es/mock": {
|
|
22
|
+
"typings": "./es/mock/index.d.ts",
|
|
23
|
+
"default": "./es/mock/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"main": "es/index.js",
|
|
28
|
+
"module": "es/index.js",
|
|
29
|
+
"typings": "es/index.d.ts",
|
|
30
|
+
"files": [
|
|
31
|
+
"es",
|
|
32
|
+
"src"
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@difizen/libro-code-editor": "0.0.0-snapshot-20241017072317",
|
|
36
|
+
"@difizen/libro-common": "0.0.0-snapshot-20241017072317",
|
|
37
|
+
"@difizen/libro-core": "0.0.0-snapshot-20241017072317",
|
|
38
|
+
"@difizen/mana-app": "latest",
|
|
39
|
+
"@difizen/mana-l10n": "latest"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"react": ">=16"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/react": "^18.2.25"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"setup": "father build",
|
|
49
|
+
"build": "father build",
|
|
50
|
+
"test": ": Note: lint task is delegated to test:* scripts",
|
|
51
|
+
"test:vitest": "vitest run",
|
|
52
|
+
"test:jest": "jest",
|
|
53
|
+
"coverage": ": Note: lint task is delegated to coverage:* scripts",
|
|
54
|
+
"coverage:vitest": "vitest run --coverage",
|
|
55
|
+
"coverage:jest": "jest --coverage",
|
|
56
|
+
"lint": ": Note: lint task is delegated to lint:* scripts",
|
|
57
|
+
"lint:eslint": "eslint src",
|
|
58
|
+
"typecheck:tsc": "tsc --noEmit"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { LanguageSpecRegistry } from '@difizen/libro-code-editor';
|
|
2
|
+
import { LanguageSpecContribution } from '@difizen/libro-code-editor';
|
|
3
|
+
import { CellModelContribution, CellViewContribution } from '@difizen/libro-core';
|
|
4
|
+
import type { CellMeta, CellModel, CellOptions } from '@difizen/libro-core';
|
|
5
|
+
import { inject, singleton } from '@difizen/mana-app';
|
|
6
|
+
|
|
7
|
+
import { CodeCellModelFactory } from './code-cell-protocol.js';
|
|
8
|
+
import { LibroCodeCellView } from './code-cell-view.js';
|
|
9
|
+
|
|
10
|
+
@singleton({
|
|
11
|
+
contrib: [CellModelContribution, CellViewContribution, LanguageSpecContribution],
|
|
12
|
+
})
|
|
13
|
+
export class CodeEditorCellContribution
|
|
14
|
+
implements CellModelContribution, CellViewContribution, LanguageSpecContribution
|
|
15
|
+
{
|
|
16
|
+
@inject(CodeCellModelFactory) libroCellModelFactory: CodeCellModelFactory;
|
|
17
|
+
|
|
18
|
+
cellMeta: CellMeta = {
|
|
19
|
+
type: 'code',
|
|
20
|
+
name: 'Python',
|
|
21
|
+
order: 'b',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
canHandle(options: CellOptions): number {
|
|
25
|
+
return options?.cell?.cell_type === this.cellMeta.type ? 1000 : 1;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async createModel(options: CellOptions): Promise<CellModel> {
|
|
29
|
+
const model = this.libroCellModelFactory(options);
|
|
30
|
+
// await model.outputAreaReady;
|
|
31
|
+
// model.outputArea.setupCellModel(model);
|
|
32
|
+
return model;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
view = LibroCodeCellView;
|
|
36
|
+
|
|
37
|
+
registerLanguageSpec = (register: LanguageSpecRegistry) => {
|
|
38
|
+
register.registerLanguageSpec({
|
|
39
|
+
name: 'Python',
|
|
40
|
+
language: 'python',
|
|
41
|
+
ext: ['.py'],
|
|
42
|
+
mime: 'text/x-python',
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { MIME } from '@difizen/libro-common';
|
|
2
|
+
import type { ICodeCell, ExecutionCount } from '@difizen/libro-common';
|
|
3
|
+
import type { ExecutableCellModel } from '@difizen/libro-core';
|
|
4
|
+
import { CellOptions, LibroCellModel } from '@difizen/libro-core';
|
|
5
|
+
import type { Event as ManaEvent } from '@difizen/mana-app';
|
|
6
|
+
import { inject, prop, transient, ViewManager } from '@difizen/mana-app';
|
|
7
|
+
import { Emitter } from '@difizen/mana-app';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 基础的可执行代码的cell, 带有执行能力
|
|
11
|
+
*/
|
|
12
|
+
@transient()
|
|
13
|
+
export class LibroCodeCellModel extends LibroCellModel implements ExecutableCellModel {
|
|
14
|
+
@prop()
|
|
15
|
+
executeCount: ExecutionCount;
|
|
16
|
+
@prop()
|
|
17
|
+
executing: boolean;
|
|
18
|
+
@prop()
|
|
19
|
+
hasOutputHidden: boolean;
|
|
20
|
+
@prop()
|
|
21
|
+
hasOutputsScrolled: boolean;
|
|
22
|
+
|
|
23
|
+
declare libroFormatType: string;
|
|
24
|
+
|
|
25
|
+
viewManager: ViewManager;
|
|
26
|
+
|
|
27
|
+
// Emitter Msg
|
|
28
|
+
msgChangeEmitter: Emitter<any>;
|
|
29
|
+
|
|
30
|
+
get msgChange(): ManaEvent<any> {
|
|
31
|
+
return this.msgChangeEmitter.event;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
constructor(
|
|
35
|
+
@inject(CellOptions) options: CellOptions,
|
|
36
|
+
@inject(ViewManager) viewManager: ViewManager,
|
|
37
|
+
) {
|
|
38
|
+
super(options);
|
|
39
|
+
this.executing = false;
|
|
40
|
+
this.msgChangeEmitter = new Emitter<any>();
|
|
41
|
+
this.executeCount = (options.cell as ICodeCell).execution_count || null;
|
|
42
|
+
this.mimeType = MIME.python;
|
|
43
|
+
this.hasOutputHidden = false;
|
|
44
|
+
this.hasOutputsScrolled = false;
|
|
45
|
+
this.viewManager = viewManager;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
override toJSON(): Omit<ICodeCell, 'outputs'> {
|
|
49
|
+
// const outputs = this.outputArea?.toJSON() ?? this.outputs;
|
|
50
|
+
return {
|
|
51
|
+
id: this.id,
|
|
52
|
+
cell_type: this.type,
|
|
53
|
+
source: this.source,
|
|
54
|
+
metadata: this.metadata,
|
|
55
|
+
execution_count: this.executeCount,
|
|
56
|
+
// outputs: this.outputs,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
clearExecution = () => {
|
|
61
|
+
this.executeCount = null;
|
|
62
|
+
this.executing = false;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
override dispose() {
|
|
66
|
+
super.dispose();
|
|
67
|
+
this.msgChangeEmitter.dispose();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
getSource() {
|
|
71
|
+
return this.value;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CellOptions } from '@difizen/libro-core';
|
|
2
|
+
|
|
3
|
+
import type { LibroCodeCellModel } from './code-cell-model.js';
|
|
4
|
+
|
|
5
|
+
export type CodeCellModelFactory = (options: CellOptions) => LibroCodeCellModel;
|
|
6
|
+
export const CodeCellModelFactory = Symbol('CodeCellModelFactory');
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-parameter-properties */
|
|
2
|
+
/* eslint-disable @typescript-eslint/parameter-properties */
|
|
3
|
+
import type { CodeEditorViewOptions } from '@difizen/libro-code-editor';
|
|
4
|
+
import { CodeEditorManager } from '@difizen/libro-code-editor';
|
|
5
|
+
import type { ICodeCell, IOutput } from '@difizen/libro-common';
|
|
6
|
+
import { CellUri } from '@difizen/libro-common';
|
|
7
|
+
import { isOutput } from '@difizen/libro-common';
|
|
8
|
+
import type {
|
|
9
|
+
IOutputAreaOption,
|
|
10
|
+
LibroCell,
|
|
11
|
+
CellViewOptions,
|
|
12
|
+
} from '@difizen/libro-core';
|
|
13
|
+
import {
|
|
14
|
+
CellService,
|
|
15
|
+
EditorStatus,
|
|
16
|
+
LibroEditableExecutableCellView,
|
|
17
|
+
LibroOutputArea,
|
|
18
|
+
VirtualizedManagerHelper,
|
|
19
|
+
} from '@difizen/libro-core';
|
|
20
|
+
import type { ViewSize } from '@difizen/mana-app';
|
|
21
|
+
import {
|
|
22
|
+
getOrigin,
|
|
23
|
+
inject,
|
|
24
|
+
prop,
|
|
25
|
+
transient,
|
|
26
|
+
useInject,
|
|
27
|
+
view,
|
|
28
|
+
ViewInstance,
|
|
29
|
+
ViewManager,
|
|
30
|
+
ViewOption,
|
|
31
|
+
ViewRender,
|
|
32
|
+
watch,
|
|
33
|
+
Deferred,
|
|
34
|
+
} from '@difizen/mana-app';
|
|
35
|
+
import { l10n } from '@difizen/mana-l10n'; /* eslint-disable react-hooks/exhaustive-deps */
|
|
36
|
+
import { useEffect, useRef, memo, forwardRef } from 'react';
|
|
37
|
+
|
|
38
|
+
import type { LibroCodeCellModel } from './code-cell-model.js';
|
|
39
|
+
|
|
40
|
+
function countLines(inputString: string) {
|
|
41
|
+
const lines = inputString.split('\n');
|
|
42
|
+
return lines.length;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const CellEditor: React.FC = () => {
|
|
46
|
+
const instance = useInject<LibroCodeCellView>(ViewInstance);
|
|
47
|
+
const virtualizedManagerHelper = useInject(VirtualizedManagerHelper);
|
|
48
|
+
const virtualizedManager = virtualizedManagerHelper.getOrCreate(
|
|
49
|
+
instance.parent.model,
|
|
50
|
+
);
|
|
51
|
+
const editorRef = useRef<HTMLDivElement>(null);
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (instance.editorView?.editor) {
|
|
55
|
+
instance.editor = getOrigin(instance.editorView?.editor);
|
|
56
|
+
}
|
|
57
|
+
}, [instance, instance.editorView?.editor]);
|
|
58
|
+
|
|
59
|
+
if (virtualizedManager.isVirtualized) {
|
|
60
|
+
instance.renderEditorIntoVirtualized = true;
|
|
61
|
+
if (instance.setEditorHost) {
|
|
62
|
+
instance.setEditorHost(editorRef);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const editorAreaHeight = instance.calcEditorAreaHeight();
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div
|
|
69
|
+
style={{
|
|
70
|
+
height: `${editorAreaHeight || 0}px`,
|
|
71
|
+
width: '100%',
|
|
72
|
+
}}
|
|
73
|
+
ref={editorRef}
|
|
74
|
+
/>
|
|
75
|
+
);
|
|
76
|
+
} else {
|
|
77
|
+
return <>{instance.editorView && <ViewRender view={instance.editorView} />}</>;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const CellEditorMemo = memo(CellEditor);
|
|
82
|
+
|
|
83
|
+
const CodeEditorViewComponent = forwardRef<HTMLDivElement>(
|
|
84
|
+
function CodeEditorViewComponent(props, ref) {
|
|
85
|
+
const instance = useInject<LibroCodeCellView>(ViewInstance);
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div
|
|
89
|
+
className="libro-codemirror-cell-editor"
|
|
90
|
+
ref={ref}
|
|
91
|
+
tabIndex={10}
|
|
92
|
+
onBlur={instance.blur}
|
|
93
|
+
>
|
|
94
|
+
<CellEditorMemo />
|
|
95
|
+
</div>
|
|
96
|
+
);
|
|
97
|
+
},
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
@transient()
|
|
101
|
+
@view('code-editor-cell-view')
|
|
102
|
+
export class LibroCodeCellView extends LibroEditableExecutableCellView {
|
|
103
|
+
override view = CodeEditorViewComponent;
|
|
104
|
+
|
|
105
|
+
viewManager: ViewManager;
|
|
106
|
+
|
|
107
|
+
declare model: LibroCodeCellModel;
|
|
108
|
+
|
|
109
|
+
outputs: IOutput[];
|
|
110
|
+
|
|
111
|
+
@prop()
|
|
112
|
+
editorAreaHeight = 0;
|
|
113
|
+
|
|
114
|
+
@prop()
|
|
115
|
+
override noEditorAreaHeight = 0;
|
|
116
|
+
|
|
117
|
+
@prop()
|
|
118
|
+
override cellViewTopPos = 0;
|
|
119
|
+
|
|
120
|
+
@prop()
|
|
121
|
+
override editorStatus: EditorStatus = EditorStatus.NOTLOADED;
|
|
122
|
+
|
|
123
|
+
protected outputAreaDeferred = new Deferred<LibroOutputArea>();
|
|
124
|
+
get outputAreaReady() {
|
|
125
|
+
return this.outputAreaDeferred.promise;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
override renderEditor = () => {
|
|
129
|
+
if (this.editorView) {
|
|
130
|
+
return <ViewRender view={this.editorView} />;
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
override onViewResize(size: ViewSize) {
|
|
136
|
+
if (size.height) {
|
|
137
|
+
this.editorAreaHeight = size.height;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
calcEditorAreaHeight() {
|
|
142
|
+
if (
|
|
143
|
+
this.editorStatus === EditorStatus.NOTLOADED ||
|
|
144
|
+
this.editorStatus === EditorStatus.LOADING
|
|
145
|
+
) {
|
|
146
|
+
const { lineHeight, paddingTop, paddingBottom, scrollBarHeight } =
|
|
147
|
+
this.codeEditorManager.getUserEditorConfig(this.model);
|
|
148
|
+
|
|
149
|
+
const codeHeight = countLines(this.model.value) * (lineHeight ?? 20);
|
|
150
|
+
const editorPadding = paddingTop + paddingBottom;
|
|
151
|
+
|
|
152
|
+
const editorAreaHeight = codeHeight + editorPadding + scrollBarHeight;
|
|
153
|
+
|
|
154
|
+
this.editorAreaHeight = editorAreaHeight;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// 编辑器已经加载的情况下cell高度都由对它的高度监听得到。
|
|
158
|
+
return this.editorAreaHeight;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
constructor(
|
|
162
|
+
@inject(ViewOption) options: CellViewOptions,
|
|
163
|
+
@inject(CellService) cellService: CellService,
|
|
164
|
+
@inject(ViewManager) viewManager: ViewManager,
|
|
165
|
+
@inject(CodeEditorManager) codeEditorManager: CodeEditorManager,
|
|
166
|
+
) {
|
|
167
|
+
super(options, cellService);
|
|
168
|
+
this.options = options;
|
|
169
|
+
this.viewManager = viewManager;
|
|
170
|
+
this.codeEditorManager = codeEditorManager;
|
|
171
|
+
|
|
172
|
+
this.outputs = options.cell?.outputs as IOutput[];
|
|
173
|
+
this.className = this.className + ' code';
|
|
174
|
+
|
|
175
|
+
// 创建outputArea
|
|
176
|
+
this.viewManager
|
|
177
|
+
.getOrCreateView<LibroOutputArea, IOutputAreaOption>(LibroOutputArea, {
|
|
178
|
+
cellId: this.id,
|
|
179
|
+
cell: this,
|
|
180
|
+
})
|
|
181
|
+
.then(async (outputArea) => {
|
|
182
|
+
this.outputArea = outputArea;
|
|
183
|
+
const output = this.outputs;
|
|
184
|
+
if (isOutput(output)) {
|
|
185
|
+
await this.outputArea.fromJSON(output);
|
|
186
|
+
}
|
|
187
|
+
this.outputAreaDeferred.resolve(outputArea);
|
|
188
|
+
this.outputWatch();
|
|
189
|
+
return;
|
|
190
|
+
})
|
|
191
|
+
.catch(console.error);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
override outputWatch() {
|
|
195
|
+
this.toDispose.push(
|
|
196
|
+
watch(this.outputArea, 'outputs', () => {
|
|
197
|
+
this.parent.model.onChange?.();
|
|
198
|
+
}),
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
override toJSON(): LibroCell {
|
|
203
|
+
const meta = super.toJSON();
|
|
204
|
+
return {
|
|
205
|
+
...meta,
|
|
206
|
+
outputs: this.outputArea?.toJSON() ?? this.outputs,
|
|
207
|
+
} as ICodeCell;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
override onViewMount() {
|
|
211
|
+
this.createEditor();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
setEditorHost(ref: React.RefObject<HTMLDivElement>) {
|
|
215
|
+
const editorHostId = this.parent.id + this.id;
|
|
216
|
+
this.codeEditorManager.setEditorHostRef(editorHostId, ref);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
protected override getEditorOption(): CodeEditorViewOptions {
|
|
220
|
+
const option: CodeEditorViewOptions = {
|
|
221
|
+
uuid: CellUri.from(this.parent.model.id, this.model.id).toString(),
|
|
222
|
+
editorHostId: this.parent.id + this.id,
|
|
223
|
+
model: this.model,
|
|
224
|
+
config: {
|
|
225
|
+
readOnly: !this.parent.model.inputEditable,
|
|
226
|
+
editable: this.parent.model.inputEditable,
|
|
227
|
+
placeholder: l10n.t('请输入代码'),
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
return option;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
override clearExecution = () => {
|
|
234
|
+
this.model.clearExecution();
|
|
235
|
+
this.outputArea.clear();
|
|
236
|
+
};
|
|
237
|
+
}
|
package/src/index.ts
ADDED
package/src/module.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CodeEditorModule } from '@difizen/libro-code-editor';
|
|
2
|
+
import { CellOptions } from '@difizen/libro-core';
|
|
3
|
+
import { ManaModule } from '@difizen/mana-app';
|
|
4
|
+
|
|
5
|
+
import { CodeEditorCellContribution } from './code-cell-contribution.js';
|
|
6
|
+
import { LibroCodeCellModel } from './code-cell-model.js';
|
|
7
|
+
import { CodeCellModelFactory } from './code-cell-protocol.js';
|
|
8
|
+
import { LibroCodeCellView } from './code-cell-view.js';
|
|
9
|
+
|
|
10
|
+
export const CodeCellModule = ManaModule.create()
|
|
11
|
+
.register(CodeEditorCellContribution, LibroCodeCellView, LibroCodeCellModel, {
|
|
12
|
+
token: CodeCellModelFactory,
|
|
13
|
+
useFactory: (ctx) => {
|
|
14
|
+
return (options: CellOptions) => {
|
|
15
|
+
const child = ctx.container.createChild();
|
|
16
|
+
child.register({
|
|
17
|
+
token: CellOptions,
|
|
18
|
+
useValue: options,
|
|
19
|
+
});
|
|
20
|
+
const model = child.get(LibroCodeCellModel);
|
|
21
|
+
return model;
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
})
|
|
25
|
+
.dependOn(CodeEditorModule);
|