@difizen/libro-raw-cell 0.1.2
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/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 +20 -0
- package/es/raw-cell-contribution.d.ts +12 -0
- package/es/raw-cell-contribution.d.ts.map +1 -0
- package/es/raw-cell-contribution.js +65 -0
- package/es/raw-cell-model.d.ts +13 -0
- package/es/raw-cell-model.d.ts.map +1 -0
- package/es/raw-cell-model.js +62 -0
- package/es/raw-cell-protocol.d.ts +5 -0
- package/es/raw-cell-protocol.d.ts.map +1 -0
- package/es/raw-cell-protocol.js +1 -0
- package/es/raw-cell-view.d.ts +26 -0
- package/es/raw-cell-view.d.ts.map +1 -0
- package/es/raw-cell-view.js +213 -0
- package/package.json +59 -0
- package/src/index.spec.ts +10 -0
- package/src/index.ts +5 -0
- package/src/module.ts +27 -0
- package/src/raw-cell-contribution.ts +30 -0
- package/src/raw-cell-model.ts +39 -0
- package/src/raw-cell-protocol.ts +6 -0
- package/src/raw-cell-view.tsx +158 -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
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,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,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":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAO/C,eAAO,MAAM,aAAa,YAkBzB,CAAC"}
|
package/es/module.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CellOptions } from '@difizen/libro-core';
|
|
2
|
+
import { ManaModule } from '@difizen/mana-app';
|
|
3
|
+
import { RawCellContribution } from "./raw-cell-contribution.js";
|
|
4
|
+
import { LibroRawCellModel } from "./raw-cell-model.js";
|
|
5
|
+
import { RawCellModelFactory } from "./raw-cell-protocol.js";
|
|
6
|
+
import { LibroRawCellView } from "./raw-cell-view.js";
|
|
7
|
+
export var RawCellModule = ManaModule.create().register(RawCellContribution, LibroRawCellView, LibroRawCellModel, {
|
|
8
|
+
token: RawCellModelFactory,
|
|
9
|
+
useFactory: function useFactory(ctx) {
|
|
10
|
+
return function (options) {
|
|
11
|
+
var child = ctx.container.createChild();
|
|
12
|
+
child.register({
|
|
13
|
+
token: CellOptions,
|
|
14
|
+
useValue: options
|
|
15
|
+
});
|
|
16
|
+
var model = child.get(LibroRawCellModel);
|
|
17
|
+
return model;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CellMeta, CellModel, CellOptions } from '@difizen/libro-core';
|
|
2
|
+
import { CellModelContribution, CellViewContribution } from '@difizen/libro-core';
|
|
3
|
+
import { RawCellModelFactory } from './raw-cell-protocol.js';
|
|
4
|
+
import { LibroRawCellView } from './raw-cell-view.js';
|
|
5
|
+
export declare class RawCellContribution implements CellModelContribution, CellViewContribution {
|
|
6
|
+
libroCellModelFactory: RawCellModelFactory;
|
|
7
|
+
cellMeta: CellMeta;
|
|
8
|
+
canHandle(options: CellOptions): number;
|
|
9
|
+
createModel(options: CellOptions): Promise<CellModel>;
|
|
10
|
+
view: typeof LibroRawCellView;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=raw-cell-contribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raw-cell-contribution.d.ts","sourceRoot":"","sources":["../src/raw-cell-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAGlF,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,qBACa,mBACX,YAAW,qBAAqB,EAAE,oBAAoB;IAEzB,qBAAqB,EAAE,mBAAmB,CAAC;IAExE,QAAQ,EAAE,QAAQ,CAIhB;IAEF,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM;IAIjC,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC;IAK3D,IAAI,0BAAoB;CACzB"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
11
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
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 { CellModelContribution, CellViewContribution } from '@difizen/libro-core';
|
|
15
|
+
import { inject, singleton } from '@difizen/mana-app';
|
|
16
|
+
import { RawCellModelFactory } from "./raw-cell-protocol.js";
|
|
17
|
+
import { LibroRawCellView } from "./raw-cell-view.js";
|
|
18
|
+
export var RawCellContribution = (_dec = singleton({
|
|
19
|
+
contrib: [CellModelContribution, CellViewContribution]
|
|
20
|
+
}), _dec2 = inject(RawCellModelFactory), _dec(_class = (_class2 = /*#__PURE__*/function () {
|
|
21
|
+
function RawCellContribution() {
|
|
22
|
+
_classCallCheck(this, RawCellContribution);
|
|
23
|
+
_initializerDefineProperty(this, "libroCellModelFactory", _descriptor, this);
|
|
24
|
+
this.cellMeta = {
|
|
25
|
+
type: 'raw',
|
|
26
|
+
name: 'Raw',
|
|
27
|
+
order: 'e'
|
|
28
|
+
};
|
|
29
|
+
this.view = LibroRawCellView;
|
|
30
|
+
}
|
|
31
|
+
_createClass(RawCellContribution, [{
|
|
32
|
+
key: "canHandle",
|
|
33
|
+
value: function canHandle(options) {
|
|
34
|
+
var _options$cell;
|
|
35
|
+
return (options === null || options === void 0 || (_options$cell = options.cell) === null || _options$cell === void 0 ? void 0 : _options$cell.cell_type) === this.cellMeta.type ? 100 : 1;
|
|
36
|
+
}
|
|
37
|
+
}, {
|
|
38
|
+
key: "createModel",
|
|
39
|
+
value: function () {
|
|
40
|
+
var _createModel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
|
|
41
|
+
var model;
|
|
42
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
43
|
+
while (1) switch (_context.prev = _context.next) {
|
|
44
|
+
case 0:
|
|
45
|
+
model = this.libroCellModelFactory(options);
|
|
46
|
+
return _context.abrupt("return", model);
|
|
47
|
+
case 2:
|
|
48
|
+
case "end":
|
|
49
|
+
return _context.stop();
|
|
50
|
+
}
|
|
51
|
+
}, _callee, this);
|
|
52
|
+
}));
|
|
53
|
+
function createModel(_x) {
|
|
54
|
+
return _createModel.apply(this, arguments);
|
|
55
|
+
}
|
|
56
|
+
return createModel;
|
|
57
|
+
}()
|
|
58
|
+
}]);
|
|
59
|
+
return RawCellContribution;
|
|
60
|
+
}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "libroCellModelFactory", [_dec2], {
|
|
61
|
+
configurable: true,
|
|
62
|
+
enumerable: true,
|
|
63
|
+
writable: true,
|
|
64
|
+
initializer: null
|
|
65
|
+
})), _class2)) || _class);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IRawCell } from '@difizen/libro-common';
|
|
2
|
+
import { CellOptions, LibroCellModel } from '@difizen/libro-core';
|
|
3
|
+
import type { Event as ManaEvent } from '@difizen/mana-app';
|
|
4
|
+
import { Emitter } from '@difizen/mana-app';
|
|
5
|
+
export declare class LibroRawCellModel extends LibroCellModel {
|
|
6
|
+
msgChangeEmitter: Emitter<any>;
|
|
7
|
+
get msgChange(): ManaEvent<any>;
|
|
8
|
+
constructor(options: CellOptions);
|
|
9
|
+
toJSON(): IRawCell;
|
|
10
|
+
dispose(): void;
|
|
11
|
+
getSource(): string;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=raw-cell-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raw-cell-model.d.ts","sourceRoot":"","sources":["../src/raw-cell-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C,qBACa,iBAAkB,SAAQ,cAAc;IAEnD,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAE/B,IAAI,SAAS,IAAI,SAAS,CAAC,GAAG,CAAC,CAE9B;gBAEgC,OAAO,EAAE,WAAW;IAM5C,MAAM,IAAI,QAAQ;IASlB,OAAO;IAKhB,SAAS;CAGV"}
|
|
@@ -0,0 +1,62 @@
|
|
|
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, _class;
|
|
3
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
+
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); } }
|
|
5
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
+
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); }
|
|
9
|
+
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
10
|
+
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); }
|
|
11
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
12
|
+
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); }; }
|
|
13
|
+
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); }
|
|
14
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
15
|
+
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; } }
|
|
16
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
17
|
+
import { CellOptions, LibroCellModel } from '@difizen/libro-core';
|
|
18
|
+
import { Emitter } from '@difizen/mana-app';
|
|
19
|
+
import { inject, transient } from '@difizen/mana-app';
|
|
20
|
+
export var LibroRawCellModel = (_dec = transient(), _dec(_class = /*#__PURE__*/function (_LibroCellModel) {
|
|
21
|
+
_inherits(LibroRawCellModel, _LibroCellModel);
|
|
22
|
+
var _super = _createSuper(LibroRawCellModel);
|
|
23
|
+
function LibroRawCellModel(options) {
|
|
24
|
+
var _this;
|
|
25
|
+
_classCallCheck(this, LibroRawCellModel);
|
|
26
|
+
_this = _super.call(this, options);
|
|
27
|
+
// Emitter Msg
|
|
28
|
+
_this.msgChangeEmitter = void 0;
|
|
29
|
+
_this.msgChangeEmitter = new Emitter();
|
|
30
|
+
_this.mimeType = 'text/plain';
|
|
31
|
+
return _this;
|
|
32
|
+
}
|
|
33
|
+
LibroRawCellModel = inject(CellOptions)(LibroRawCellModel, undefined, 0) || LibroRawCellModel;
|
|
34
|
+
_createClass(LibroRawCellModel, [{
|
|
35
|
+
key: "msgChange",
|
|
36
|
+
get: function get() {
|
|
37
|
+
return this.msgChangeEmitter.event;
|
|
38
|
+
}
|
|
39
|
+
}, {
|
|
40
|
+
key: "toJSON",
|
|
41
|
+
value: function toJSON() {
|
|
42
|
+
return {
|
|
43
|
+
id: this.id,
|
|
44
|
+
cell_type: 'raw',
|
|
45
|
+
source: this.source,
|
|
46
|
+
metadata: this.metadata
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
50
|
+
key: "dispose",
|
|
51
|
+
value: function dispose() {
|
|
52
|
+
_get(_getPrototypeOf(LibroRawCellModel.prototype), "dispose", this).call(this);
|
|
53
|
+
this.msgChangeEmitter.dispose();
|
|
54
|
+
}
|
|
55
|
+
}, {
|
|
56
|
+
key: "getSource",
|
|
57
|
+
value: function getSource() {
|
|
58
|
+
return this.value;
|
|
59
|
+
}
|
|
60
|
+
}]);
|
|
61
|
+
return LibroRawCellModel;
|
|
62
|
+
}(LibroCellModel)) || _class);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CellOptions } from '@difizen/libro-core';
|
|
2
|
+
import type { LibroRawCellModel } from './raw-cell-model.js';
|
|
3
|
+
export type RawCellModelFactory = (options: CellOptions) => LibroRawCellModel;
|
|
4
|
+
export declare const RawCellModelFactory: unique symbol;
|
|
5
|
+
//# sourceMappingURL=raw-cell-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raw-cell-protocol.d.ts","sourceRoot":"","sources":["../src/raw-cell-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK,iBAAiB,CAAC;AAC9E,eAAO,MAAM,mBAAmB,eAAgC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var RawCellModelFactory = Symbol('RawCellModelFactory');
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CodeEditorViewOptions, CodeEditorView } from '@difizen/libro-code-editor';
|
|
2
|
+
import { CodeEditorManager } from '@difizen/libro-code-editor';
|
|
3
|
+
import type { CellViewOptions } from '@difizen/libro-core';
|
|
4
|
+
import { CellService, LibroEditorCellView } from '@difizen/libro-core';
|
|
5
|
+
import { Deferred } from '@difizen/mana-app';
|
|
6
|
+
import { ViewManager } from '@difizen/mana-app';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import type { LibroRawCellModel } from './raw-cell-model.js';
|
|
9
|
+
export declare class LibroRawCellView extends LibroEditorCellView {
|
|
10
|
+
model: LibroRawCellModel;
|
|
11
|
+
view: React.ForwardRefExoticComponent<React.RefAttributes<HTMLDivElement>>;
|
|
12
|
+
viewManager: ViewManager;
|
|
13
|
+
codeEditorManager: CodeEditorManager;
|
|
14
|
+
editorView?: CodeEditorView;
|
|
15
|
+
protected editorViewReadyDeferred: Deferred<void>;
|
|
16
|
+
get editorReady(): Promise<void>;
|
|
17
|
+
constructor(options: CellViewOptions, cellService: CellService, viewManager: ViewManager, codeEditorManager: CodeEditorManager);
|
|
18
|
+
onViewMount(): void;
|
|
19
|
+
protected getEditorOption(): CodeEditorViewOptions;
|
|
20
|
+
createEditor(): Promise<void>;
|
|
21
|
+
protected afterEditorReady(): Promise<void>;
|
|
22
|
+
shouldEnterEditorMode(e: React.FocusEvent<HTMLElement>): boolean;
|
|
23
|
+
blur: () => void;
|
|
24
|
+
focus: (toEdit: boolean) => void;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=raw-cell-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raw-cell-view.d.ts","sourceRoot":"","sources":["../src/raw-cell-view.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAEvE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAGL,WAAW,EAGZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAoB,MAAM,OAAO,CAAC;AAEzC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAyB7D,qBAEa,gBAAiB,SAAQ,mBAAmB;IAC/C,KAAK,EAAE,iBAAiB,CAAC;IACxB,IAAI,uEAA2B;IAExC,WAAW,EAAE,WAAW,CAAC;IAEzB,iBAAiB,EAAE,iBAAiB,CAAC;IAGrC,UAAU,CAAC,EAAE,cAAc,CAAC;IAE5B,SAAS,CAAC,uBAAuB,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAwB;IAEzE,IAAI,WAAW,kBAEd;gBAGqB,OAAO,EAAE,eAAe,EACvB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EAClB,iBAAiB,EAAE,iBAAiB;IAQxD,WAAW;IAQpB,SAAS,CAAC,eAAe,IAAI,qBAAqB;IAgB5C,YAAY;cAUF,gBAAgB;IAMvB,qBAAqB,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC;IAQtD,IAAI,aAEX;IAEO,KAAK,WAAY,OAAO,UA8B/B;CACH"}
|
|
@@ -0,0 +1,213 @@
|
|
|
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, _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(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
11
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
12
|
+
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); }
|
|
13
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
14
|
+
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); }; }
|
|
15
|
+
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); }
|
|
16
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
17
|
+
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; } }
|
|
18
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
19
|
+
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; }
|
|
20
|
+
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.'); }
|
|
21
|
+
/* eslint-disable @typescript-eslint/no-parameter-properties */
|
|
22
|
+
/* eslint-disable @typescript-eslint/parameter-properties */
|
|
23
|
+
|
|
24
|
+
import { CodeEditorManager } from '@difizen/libro-code-editor';
|
|
25
|
+
import { CellService, LibroEditorCellView } from '@difizen/libro-core';
|
|
26
|
+
import { getOrigin, prop, useInject, watch } from '@difizen/mana-app';
|
|
27
|
+
import { Deferred } from '@difizen/mana-app';
|
|
28
|
+
import { view, ViewInstance, ViewManager, ViewOption, ViewRender } from '@difizen/mana-app';
|
|
29
|
+
import { inject, transient } from '@difizen/mana-app';
|
|
30
|
+
import React, { useEffect } from 'react';
|
|
31
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
32
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
33
|
+
var CellEditor = function CellEditor() {
|
|
34
|
+
var _instance$editorView3;
|
|
35
|
+
var instance = useInject(ViewInstance);
|
|
36
|
+
useEffect(function () {
|
|
37
|
+
var _instance$editorView;
|
|
38
|
+
if ((_instance$editorView = instance.editorView) !== null && _instance$editorView !== void 0 && _instance$editorView.editor) {
|
|
39
|
+
var _instance$editorView2;
|
|
40
|
+
instance.editor = getOrigin((_instance$editorView2 = instance.editorView) === null || _instance$editorView2 === void 0 ? void 0 : _instance$editorView2.editor);
|
|
41
|
+
}
|
|
42
|
+
}, [instance, (_instance$editorView3 = instance.editorView) === null || _instance$editorView3 === void 0 ? void 0 : _instance$editorView3.editor]);
|
|
43
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
44
|
+
children: instance.editorView && /*#__PURE__*/_jsx(ViewRender, {
|
|
45
|
+
view: instance.editorView
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
var CellEditorMemo = /*#__PURE__*/React.memo(CellEditor);
|
|
50
|
+
var CodeEditorViewComponent = /*#__PURE__*/React.forwardRef(function CodeEditorViewComponent(props, ref) {
|
|
51
|
+
var instance = useInject(ViewInstance);
|
|
52
|
+
return /*#__PURE__*/_jsx("div", {
|
|
53
|
+
className: instance.className,
|
|
54
|
+
ref: ref,
|
|
55
|
+
children: /*#__PURE__*/_jsx(CellEditorMemo, {})
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
export var LibroRawCellView = (_dec = transient(), _dec2 = view('raw-cell-view'), _dec3 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroEditorCellView) {
|
|
59
|
+
_inherits(LibroRawCellView, _LibroEditorCellView);
|
|
60
|
+
var _super = _createSuper(LibroRawCellView);
|
|
61
|
+
function LibroRawCellView(options, cellService, viewManager, codeEditorManager) {
|
|
62
|
+
var _this;
|
|
63
|
+
_classCallCheck(this, LibroRawCellView);
|
|
64
|
+
_this = _super.call(this, options, cellService);
|
|
65
|
+
_this.view = CodeEditorViewComponent;
|
|
66
|
+
_this.viewManager = void 0;
|
|
67
|
+
_this.codeEditorManager = void 0;
|
|
68
|
+
_initializerDefineProperty(_this, "editorView", _descriptor, _assertThisInitialized(_this));
|
|
69
|
+
_this.editorViewReadyDeferred = new Deferred();
|
|
70
|
+
_this.blur = function () {
|
|
71
|
+
//
|
|
72
|
+
};
|
|
73
|
+
_this.focus = function (toEdit) {
|
|
74
|
+
if (toEdit) {
|
|
75
|
+
if (_this.parent.model.readOnly === true) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (!_this.editorView) {
|
|
79
|
+
_this.editorReady.then(function () {
|
|
80
|
+
var _this$editorView;
|
|
81
|
+
(_this$editorView = _this.editorView) === null || _this$editorView === void 0 || _this$editorView.editorReady.then(function () {
|
|
82
|
+
var _this$editorView2, _this$editorView3;
|
|
83
|
+
if ((_this$editorView2 = _this.editorView) !== null && _this$editorView2 !== void 0 && _this$editorView2.editor.hasFocus()) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
(_this$editorView3 = _this.editorView) === null || _this$editorView3 === void 0 || _this$editorView3.editor.focus();
|
|
87
|
+
return;
|
|
88
|
+
});
|
|
89
|
+
return;
|
|
90
|
+
}).catch(console.error);
|
|
91
|
+
} else {
|
|
92
|
+
var _this$editorView4, _this$editorView5;
|
|
93
|
+
if ((_this$editorView4 = _this.editorView) !== null && _this$editorView4 !== void 0 && _this$editorView4.editor.hasFocus()) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
(_this$editorView5 = _this.editorView) === null || _this$editorView5 === void 0 || _this$editorView5.editor.focus();
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
var _this$container, _this$container2;
|
|
100
|
+
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)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
(_this$container2 = _this.container) === null || _this$container2 === void 0 || (_this$container2 = _this$container2.current) === null || _this$container2 === void 0 || (_this$container2 = _this$container2.parentElement) === null || _this$container2 === void 0 || _this$container2.focus();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
_this.viewManager = viewManager;
|
|
107
|
+
_this.className = _this.className + ' raw';
|
|
108
|
+
_this.codeEditorManager = codeEditorManager;
|
|
109
|
+
return _this;
|
|
110
|
+
}
|
|
111
|
+
LibroRawCellView = inject(CodeEditorManager)(LibroRawCellView, undefined, 3) || LibroRawCellView;
|
|
112
|
+
LibroRawCellView = inject(ViewManager)(LibroRawCellView, undefined, 2) || LibroRawCellView;
|
|
113
|
+
LibroRawCellView = inject(CellService)(LibroRawCellView, undefined, 1) || LibroRawCellView;
|
|
114
|
+
LibroRawCellView = inject(ViewOption)(LibroRawCellView, undefined, 0) || LibroRawCellView;
|
|
115
|
+
_createClass(LibroRawCellView, [{
|
|
116
|
+
key: "editorReady",
|
|
117
|
+
get: function get() {
|
|
118
|
+
return this.editorViewReadyDeferred.promise;
|
|
119
|
+
}
|
|
120
|
+
}, {
|
|
121
|
+
key: "onViewMount",
|
|
122
|
+
value: function onViewMount() {
|
|
123
|
+
var _this$parent$model$ac;
|
|
124
|
+
this.createEditor();
|
|
125
|
+
//选中cell时才focus
|
|
126
|
+
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) {
|
|
127
|
+
this.focus(!this.parent.model.commandMode);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}, {
|
|
131
|
+
key: "getEditorOption",
|
|
132
|
+
value: function getEditorOption() {
|
|
133
|
+
var option = {
|
|
134
|
+
model: this.model,
|
|
135
|
+
config: {
|
|
136
|
+
readOnly: this.parent.model.readOnly,
|
|
137
|
+
editable: !this.parent.model.readOnly,
|
|
138
|
+
lineNumbers: false,
|
|
139
|
+
foldGutter: false,
|
|
140
|
+
lineWrap: 'on',
|
|
141
|
+
matchBrackets: false,
|
|
142
|
+
autoClosingBrackets: false
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
return option;
|
|
146
|
+
}
|
|
147
|
+
}, {
|
|
148
|
+
key: "createEditor",
|
|
149
|
+
value: function () {
|
|
150
|
+
var _createEditor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
151
|
+
var option, editorView;
|
|
152
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
153
|
+
while (1) switch (_context.prev = _context.next) {
|
|
154
|
+
case 0:
|
|
155
|
+
option = this.getEditorOption();
|
|
156
|
+
_context.next = 3;
|
|
157
|
+
return this.codeEditorManager.getOrCreateEditorView(option);
|
|
158
|
+
case 3:
|
|
159
|
+
editorView = _context.sent;
|
|
160
|
+
this.editorView = editorView;
|
|
161
|
+
_context.next = 7;
|
|
162
|
+
return editorView.editorReady;
|
|
163
|
+
case 7:
|
|
164
|
+
_context.next = 9;
|
|
165
|
+
return this.afterEditorReady();
|
|
166
|
+
case 9:
|
|
167
|
+
case "end":
|
|
168
|
+
return _context.stop();
|
|
169
|
+
}
|
|
170
|
+
}, _callee, this);
|
|
171
|
+
}));
|
|
172
|
+
function createEditor() {
|
|
173
|
+
return _createEditor.apply(this, arguments);
|
|
174
|
+
}
|
|
175
|
+
return createEditor;
|
|
176
|
+
}()
|
|
177
|
+
}, {
|
|
178
|
+
key: "afterEditorReady",
|
|
179
|
+
value: function () {
|
|
180
|
+
var _afterEditorReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
181
|
+
var _this2 = this;
|
|
182
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
183
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
184
|
+
case 0:
|
|
185
|
+
watch(this.parent.model, 'readOnly', function () {
|
|
186
|
+
var _this2$editorView;
|
|
187
|
+
(_this2$editorView = _this2.editorView) === null || _this2$editorView === void 0 || _this2$editorView.editor.setOption('readOnly', _this2.parent.model.readOnly);
|
|
188
|
+
});
|
|
189
|
+
case 1:
|
|
190
|
+
case "end":
|
|
191
|
+
return _context2.stop();
|
|
192
|
+
}
|
|
193
|
+
}, _callee2, this);
|
|
194
|
+
}));
|
|
195
|
+
function afterEditorReady() {
|
|
196
|
+
return _afterEditorReady.apply(this, arguments);
|
|
197
|
+
}
|
|
198
|
+
return afterEditorReady;
|
|
199
|
+
}()
|
|
200
|
+
}, {
|
|
201
|
+
key: "shouldEnterEditorMode",
|
|
202
|
+
value: function shouldEnterEditorMode(e) {
|
|
203
|
+
var _getOrigin;
|
|
204
|
+
return (_getOrigin = getOrigin(this.editorView)) !== null && _getOrigin !== void 0 && (_getOrigin = _getOrigin.editor) !== null && _getOrigin !== void 0 && (_getOrigin = _getOrigin.host) !== null && _getOrigin !== void 0 && _getOrigin.contains(e.target) && this.parent.model.commandMode ? true : false;
|
|
205
|
+
}
|
|
206
|
+
}]);
|
|
207
|
+
return LibroRawCellView;
|
|
208
|
+
}(LibroEditorCellView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "editorView", [_dec3], {
|
|
209
|
+
configurable: true,
|
|
210
|
+
enumerable: true,
|
|
211
|
+
writable: true,
|
|
212
|
+
initializer: null
|
|
213
|
+
})), _class2)) || _class) || _class);
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@difizen/libro-raw-cell",
|
|
3
|
+
"version": "0.1.2",
|
|
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.1.2",
|
|
36
|
+
"@difizen/libro-common": "^0.1.2",
|
|
37
|
+
"@difizen/libro-core": "^0.1.2",
|
|
38
|
+
"@difizen/mana-app": "latest"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react": "^18.2.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/react": "^18.2.25"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"setup": "father build",
|
|
48
|
+
"build": "father build",
|
|
49
|
+
"test": ": Note: lint task is delegated to test:* scripts",
|
|
50
|
+
"test:vitest": "vitest run",
|
|
51
|
+
"test:jest": "jest",
|
|
52
|
+
"coverage": ": Note: lint task is delegated to coverage:* scripts",
|
|
53
|
+
"coverage:vitest": "vitest run --coverage",
|
|
54
|
+
"coverage:jest": "jest --coverage",
|
|
55
|
+
"lint": ": Note: lint task is delegated to lint:* scripts",
|
|
56
|
+
"lint:eslint": "eslint src",
|
|
57
|
+
"lint:tsc": "tsc --noEmit"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/index.ts
ADDED
package/src/module.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CellOptions } from '@difizen/libro-core';
|
|
2
|
+
import { ManaModule } from '@difizen/mana-app';
|
|
3
|
+
|
|
4
|
+
import { RawCellContribution } from './raw-cell-contribution.js';
|
|
5
|
+
import { LibroRawCellModel } from './raw-cell-model.js';
|
|
6
|
+
import { RawCellModelFactory } from './raw-cell-protocol.js';
|
|
7
|
+
import { LibroRawCellView } from './raw-cell-view.js';
|
|
8
|
+
|
|
9
|
+
export const RawCellModule = ManaModule.create().register(
|
|
10
|
+
RawCellContribution,
|
|
11
|
+
LibroRawCellView,
|
|
12
|
+
LibroRawCellModel,
|
|
13
|
+
{
|
|
14
|
+
token: RawCellModelFactory,
|
|
15
|
+
useFactory: (ctx) => {
|
|
16
|
+
return (options: CellOptions) => {
|
|
17
|
+
const child = ctx.container.createChild();
|
|
18
|
+
child.register({
|
|
19
|
+
token: CellOptions,
|
|
20
|
+
useValue: options,
|
|
21
|
+
});
|
|
22
|
+
const model = child.get(LibroRawCellModel);
|
|
23
|
+
return model;
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { CellMeta, CellModel, CellOptions } from '@difizen/libro-core';
|
|
2
|
+
import { CellModelContribution, CellViewContribution } from '@difizen/libro-core';
|
|
3
|
+
import { inject, singleton } from '@difizen/mana-app';
|
|
4
|
+
|
|
5
|
+
import { RawCellModelFactory } from './raw-cell-protocol.js';
|
|
6
|
+
import { LibroRawCellView } from './raw-cell-view.js';
|
|
7
|
+
|
|
8
|
+
@singleton({ contrib: [CellModelContribution, CellViewContribution] })
|
|
9
|
+
export class RawCellContribution
|
|
10
|
+
implements CellModelContribution, CellViewContribution
|
|
11
|
+
{
|
|
12
|
+
@inject(RawCellModelFactory) libroCellModelFactory: RawCellModelFactory;
|
|
13
|
+
|
|
14
|
+
cellMeta: CellMeta = {
|
|
15
|
+
type: 'raw',
|
|
16
|
+
name: 'Raw',
|
|
17
|
+
order: 'e',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
canHandle(options: CellOptions): number {
|
|
21
|
+
return options?.cell?.cell_type === this.cellMeta.type ? 100 : 1;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async createModel(options: CellOptions): Promise<CellModel> {
|
|
25
|
+
const model = this.libroCellModelFactory(options);
|
|
26
|
+
return model;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
view = LibroRawCellView;
|
|
30
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { IRawCell } from '@difizen/libro-common';
|
|
2
|
+
import { CellOptions, LibroCellModel } from '@difizen/libro-core';
|
|
3
|
+
import type { Event as ManaEvent } from '@difizen/mana-app';
|
|
4
|
+
import { Emitter } from '@difizen/mana-app';
|
|
5
|
+
import { inject, transient } from '@difizen/mana-app';
|
|
6
|
+
|
|
7
|
+
@transient()
|
|
8
|
+
export class LibroRawCellModel extends LibroCellModel {
|
|
9
|
+
// Emitter Msg
|
|
10
|
+
msgChangeEmitter: Emitter<any>;
|
|
11
|
+
|
|
12
|
+
get msgChange(): ManaEvent<any> {
|
|
13
|
+
return this.msgChangeEmitter.event;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
constructor(@inject(CellOptions) options: CellOptions) {
|
|
17
|
+
super(options);
|
|
18
|
+
this.msgChangeEmitter = new Emitter<any>();
|
|
19
|
+
this.mimeType = 'text/plain';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
override toJSON(): IRawCell {
|
|
23
|
+
return {
|
|
24
|
+
id: this.id,
|
|
25
|
+
cell_type: 'raw',
|
|
26
|
+
source: this.source,
|
|
27
|
+
metadata: this.metadata,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
override dispose() {
|
|
32
|
+
super.dispose();
|
|
33
|
+
this.msgChangeEmitter.dispose();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getSource() {
|
|
37
|
+
return this.value;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CellOptions } from '@difizen/libro-core';
|
|
2
|
+
|
|
3
|
+
import type { LibroRawCellModel } from './raw-cell-model.js';
|
|
4
|
+
|
|
5
|
+
export type RawCellModelFactory = (options: CellOptions) => LibroRawCellModel;
|
|
6
|
+
export const RawCellModelFactory = Symbol('RawCellModelFactory');
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-parameter-properties */
|
|
2
|
+
/* eslint-disable @typescript-eslint/parameter-properties */
|
|
3
|
+
import type { CodeEditorViewOptions, CodeEditorView } from '@difizen/libro-code-editor';
|
|
4
|
+
import { CodeEditorManager } from '@difizen/libro-code-editor';
|
|
5
|
+
import type { CellViewOptions } from '@difizen/libro-core';
|
|
6
|
+
import { CellService, LibroEditorCellView } from '@difizen/libro-core';
|
|
7
|
+
import { getOrigin, prop, useInject, watch } from '@difizen/mana-app';
|
|
8
|
+
import { Deferred } from '@difizen/mana-app';
|
|
9
|
+
import {
|
|
10
|
+
view,
|
|
11
|
+
ViewInstance,
|
|
12
|
+
ViewManager,
|
|
13
|
+
ViewOption,
|
|
14
|
+
ViewRender,
|
|
15
|
+
} from '@difizen/mana-app';
|
|
16
|
+
import { inject, transient } from '@difizen/mana-app';
|
|
17
|
+
import React, { useEffect } from 'react';
|
|
18
|
+
|
|
19
|
+
import type { LibroRawCellModel } from './raw-cell-model.js';
|
|
20
|
+
|
|
21
|
+
const CellEditor: React.FC = () => {
|
|
22
|
+
const instance = useInject<LibroRawCellView>(ViewInstance);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (instance.editorView?.editor) {
|
|
25
|
+
instance.editor = getOrigin(instance.editorView?.editor);
|
|
26
|
+
}
|
|
27
|
+
}, [instance, instance.editorView?.editor]);
|
|
28
|
+
return <>{instance.editorView && <ViewRender view={instance.editorView} />}</>;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const CellEditorMemo = React.memo(CellEditor);
|
|
32
|
+
|
|
33
|
+
const CodeEditorViewComponent = React.forwardRef<HTMLDivElement>(
|
|
34
|
+
function CodeEditorViewComponent(props, ref) {
|
|
35
|
+
const instance = useInject<LibroRawCellView>(ViewInstance);
|
|
36
|
+
return (
|
|
37
|
+
<div className={instance.className} ref={ref}>
|
|
38
|
+
<CellEditorMemo />
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
41
|
+
},
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
@transient()
|
|
45
|
+
@view('raw-cell-view')
|
|
46
|
+
export class LibroRawCellView extends LibroEditorCellView {
|
|
47
|
+
declare model: LibroRawCellModel;
|
|
48
|
+
override view = CodeEditorViewComponent;
|
|
49
|
+
|
|
50
|
+
viewManager: ViewManager;
|
|
51
|
+
|
|
52
|
+
codeEditorManager: CodeEditorManager;
|
|
53
|
+
|
|
54
|
+
@prop()
|
|
55
|
+
editorView?: CodeEditorView;
|
|
56
|
+
|
|
57
|
+
protected editorViewReadyDeferred: Deferred<void> = new Deferred<void>();
|
|
58
|
+
|
|
59
|
+
get editorReady() {
|
|
60
|
+
return this.editorViewReadyDeferred.promise;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
constructor(
|
|
64
|
+
@inject(ViewOption) options: CellViewOptions,
|
|
65
|
+
@inject(CellService) cellService: CellService,
|
|
66
|
+
@inject(ViewManager) viewManager: ViewManager,
|
|
67
|
+
@inject(CodeEditorManager) codeEditorManager: CodeEditorManager,
|
|
68
|
+
) {
|
|
69
|
+
super(options, cellService);
|
|
70
|
+
this.viewManager = viewManager;
|
|
71
|
+
this.className = this.className + ' raw';
|
|
72
|
+
this.codeEditorManager = codeEditorManager;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
override onViewMount() {
|
|
76
|
+
this.createEditor();
|
|
77
|
+
//选中cell时才focus
|
|
78
|
+
if (this.parent.model.active?.id === this.id) {
|
|
79
|
+
this.focus(!this.parent.model.commandMode);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
protected getEditorOption(): CodeEditorViewOptions {
|
|
84
|
+
const option: CodeEditorViewOptions = {
|
|
85
|
+
model: this.model,
|
|
86
|
+
config: {
|
|
87
|
+
readOnly: this.parent.model.readOnly,
|
|
88
|
+
editable: !this.parent.model.readOnly,
|
|
89
|
+
lineNumbers: false,
|
|
90
|
+
foldGutter: false,
|
|
91
|
+
lineWrap: 'on',
|
|
92
|
+
matchBrackets: false,
|
|
93
|
+
autoClosingBrackets: false,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
return option;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async createEditor() {
|
|
100
|
+
const option = this.getEditorOption();
|
|
101
|
+
|
|
102
|
+
const editorView = await this.codeEditorManager.getOrCreateEditorView(option);
|
|
103
|
+
|
|
104
|
+
this.editorView = editorView;
|
|
105
|
+
await editorView.editorReady;
|
|
106
|
+
await this.afterEditorReady();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
protected async afterEditorReady() {
|
|
110
|
+
watch(this.parent.model, 'readOnly', () => {
|
|
111
|
+
this.editorView?.editor.setOption('readOnly', this.parent.model.readOnly);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
override shouldEnterEditorMode(e: React.FocusEvent<HTMLElement>) {
|
|
116
|
+
return getOrigin(this.editorView)?.editor?.host?.contains(
|
|
117
|
+
e.target as HTMLElement,
|
|
118
|
+
) && this.parent.model.commandMode
|
|
119
|
+
? true
|
|
120
|
+
: false;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
override blur = () => {
|
|
124
|
+
//
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
override focus = (toEdit: boolean) => {
|
|
128
|
+
if (toEdit) {
|
|
129
|
+
if (this.parent.model.readOnly === true) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (!this.editorView) {
|
|
133
|
+
this.editorReady
|
|
134
|
+
.then(() => {
|
|
135
|
+
this.editorView?.editorReady.then(() => {
|
|
136
|
+
if (this.editorView?.editor.hasFocus()) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
this.editorView?.editor.focus();
|
|
140
|
+
return;
|
|
141
|
+
});
|
|
142
|
+
return;
|
|
143
|
+
})
|
|
144
|
+
.catch(console.error);
|
|
145
|
+
} else {
|
|
146
|
+
if (this.editorView?.editor.hasFocus()) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
this.editorView?.editor.focus();
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
if (this.container?.current?.parentElement?.contains(document.activeElement)) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
this.container?.current?.parentElement?.focus();
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|