@difizen/libro-sql-cell 0.2.34

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.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/es/index.d.ts +2 -0
  4. package/es/index.d.ts.map +1 -0
  5. package/es/index.js +1 -0
  6. package/es/index.less +116 -0
  7. package/es/libro-formatter-sql-magic-contribution.d.ts +25 -0
  8. package/es/libro-formatter-sql-magic-contribution.d.ts.map +1 -0
  9. package/es/libro-formatter-sql-magic-contribution.js +50 -0
  10. package/es/libro-formatter-sql-trans-contribution.d.ts +13 -0
  11. package/es/libro-formatter-sql-trans-contribution.d.ts.map +1 -0
  12. package/es/libro-formatter-sql-trans-contribution.js +26 -0
  13. package/es/libro-sql-cell-color-registry.d.ts +6 -0
  14. package/es/libro-sql-cell-color-registry.d.ts.map +1 -0
  15. package/es/libro-sql-cell-color-registry.js +57 -0
  16. package/es/libro-sql-cell-contribution.d.ts +15 -0
  17. package/es/libro-sql-cell-contribution.d.ts.map +1 -0
  18. package/es/libro-sql-cell-contribution.js +75 -0
  19. package/es/libro-sql-cell-model.d.ts +33 -0
  20. package/es/libro-sql-cell-model.d.ts.map +1 -0
  21. package/es/libro-sql-cell-model.js +161 -0
  22. package/es/libro-sql-cell-protocol.d.ts +16 -0
  23. package/es/libro-sql-cell-protocol.d.ts.map +1 -0
  24. package/es/libro-sql-cell-protocol.js +1 -0
  25. package/es/libro-sql-cell-script.d.ts +4 -0
  26. package/es/libro-sql-cell-script.d.ts.map +1 -0
  27. package/es/libro-sql-cell-script.js +12 -0
  28. package/es/libro-sql-cell-view.d.ts +52 -0
  29. package/es/libro-sql-cell-view.d.ts.map +1 -0
  30. package/es/libro-sql-cell-view.js +712 -0
  31. package/es/libro-sql-utils.d.ts +3 -0
  32. package/es/libro-sql-utils.d.ts.map +1 -0
  33. package/es/libro-sql-utils.js +33 -0
  34. package/es/module.d.ts +3 -0
  35. package/es/module.d.ts.map +1 -0
  36. package/es/module.js +25 -0
  37. package/package.json +65 -0
  38. package/src/index.less +116 -0
  39. package/src/index.spec.ts +9 -0
  40. package/src/index.ts +1 -0
  41. package/src/libro-formatter-sql-magic-contribution.ts +53 -0
  42. package/src/libro-formatter-sql-trans-contribution.ts +22 -0
  43. package/src/libro-sql-cell-color-registry.ts +35 -0
  44. package/src/libro-sql-cell-contribution.ts +46 -0
  45. package/src/libro-sql-cell-model.ts +111 -0
  46. package/src/libro-sql-cell-protocol.ts +19 -0
  47. package/src/libro-sql-cell-script.ts +7 -0
  48. package/src/libro-sql-cell-view.tsx +600 -0
  49. package/src/libro-sql-utils.ts +22 -0
  50. package/src/module.ts +38 -0
@@ -0,0 +1,712 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7;
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 _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); }
16
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
17
+ 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); }; }
18
+ 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); }
19
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
20
+ 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; } }
21
+ 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); }
22
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
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
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
27
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
28
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
29
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
30
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
31
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
32
+ import { EditFilled, DatabaseOutlined } from '@ant-design/icons';
33
+ import { CodeEditorManager } from '@difizen/libro-code-editor';
34
+ import { CellUri, isOutput } from '@difizen/libro-common';
35
+ import { CellService, EditorStatus, LibroContextKey, LibroExecutableCellView, LibroViewTracker, VirtualizedManagerHelper, KernelError, LibroJupyterModel, LibroOutputArea } from '@difizen/libro-jupyter';
36
+ import { Deferred, Disposable, DisposableCollection, getOrigin, inject, prop, transient, useInject, view, ViewInstance, ViewManager, ViewOption, ViewRender, watch } from '@difizen/mana-app';
37
+ import { l10n } from '@difizen/mana-l10n';
38
+ import { Input, Popover } from 'antd';
39
+ import React from 'react';
40
+ import { useCallback, useEffect, useRef, useState } from 'react';
41
+ import "./index.less";
42
+ import { LibroSqlCellModel } from "./libro-sql-cell-model.js";
43
+ import { SqlScript } from "./libro-sql-cell-script.js";
44
+ import { getDfVariableName } from "./libro-sql-utils.js";
45
+ import { jsx as _jsx } from "react/jsx-runtime";
46
+ import { Fragment as _Fragment } from "react/jsx-runtime";
47
+ import { jsxs as _jsxs } from "react/jsx-runtime";
48
+ function countLines(inputString) {
49
+ var lines = inputString.split('\n');
50
+ return lines.length;
51
+ }
52
+ var CellEditor = function CellEditor() {
53
+ var _instance$editorView3;
54
+ var instance = useInject(ViewInstance);
55
+ var virtualizedManagerHelper = useInject(VirtualizedManagerHelper);
56
+ var virtualizedManager = virtualizedManagerHelper.getOrCreate(instance.parent.model);
57
+ var editorRef = useRef(null);
58
+ useEffect(function () {
59
+ var _instance$editorView;
60
+ if ((_instance$editorView = instance.editorView) !== null && _instance$editorView !== void 0 && _instance$editorView.editor) {
61
+ var _instance$editorView2;
62
+ instance.editor = getOrigin((_instance$editorView2 = instance.editorView) === null || _instance$editorView2 === void 0 ? void 0 : _instance$editorView2.editor);
63
+ }
64
+ }, [instance, (_instance$editorView3 = instance.editorView) === null || _instance$editorView3 === void 0 ? void 0 : _instance$editorView3.editor]);
65
+ if (virtualizedManager.isVirtualized) {
66
+ instance.renderEditorIntoVirtualized = true;
67
+ var editorAreaHeight = instance.calcEditorAreaHeight();
68
+ if (instance.setEditorHost) {
69
+ instance.setEditorHost(editorRef);
70
+ }
71
+ return /*#__PURE__*/_jsx("div", {
72
+ style: {
73
+ height: "".concat(editorAreaHeight || 0, "px"),
74
+ width: '100%'
75
+ },
76
+ ref: editorRef
77
+ });
78
+ } else {
79
+ return /*#__PURE__*/_jsx(_Fragment, {
80
+ children: instance.editorView && /*#__PURE__*/_jsx(ViewRender, {
81
+ view: instance.editorView
82
+ })
83
+ });
84
+ }
85
+ };
86
+ var LibroSqlVariableNameInput = function LibroSqlVariableNameInput(_ref) {
87
+ var handCancel = _ref.handCancel;
88
+ var cellView = useInject(ViewInstance);
89
+ var _useState = useState(true),
90
+ _useState2 = _slicedToArray(_useState, 2),
91
+ resultVariableAvailable = _useState2[0],
92
+ setVariableNameAvailable = _useState2[1];
93
+ var _useState3 = useState(cellView.model.resultVariable),
94
+ _useState4 = _slicedToArray(_useState3, 2),
95
+ resultVariable = _useState4[0],
96
+ setVariableName = _useState4[1];
97
+ var handleValueChange = useCallback(function (e) {
98
+ if (cellView.parent.model.cells.findIndex(function (cell) {
99
+ return cell.model instanceof LibroSqlCellModel && cell.model.resultVariable === e.target.value;
100
+ }) > -1) {
101
+ setVariableNameAvailable(false);
102
+ } else {
103
+ setVariableNameAvailable(true);
104
+ }
105
+ setVariableName(e.target.value);
106
+ }, [cellView.parent.model.cells]);
107
+ var handValueSave = useCallback(function () {
108
+ cellView.model.resultVariable = getDfVariableName(cellView.parent.model.cells.filter(function (cell) {
109
+ return cell.model.type === 'sql';
110
+ }));
111
+ cellView.model.resultVariable = resultVariable;
112
+ if (cellView.parent.model.onChange) {
113
+ cellView.parent.model.onChange();
114
+ }
115
+ handCancel();
116
+ }, [cellView.model, cellView.parent.model, handCancel, resultVariable]);
117
+ return /*#__PURE__*/_jsxs(_Fragment, {
118
+ children: [/*#__PURE__*/_jsx(Input, {
119
+ status: "".concat(resultVariableAvailable ? '' : 'warning'),
120
+ className: "libro-sql-variable-name-input",
121
+ onChange: handleValueChange,
122
+ defaultValue: cellView.model.resultVariable
123
+ }), !resultVariableAvailable && /*#__PURE__*/_jsx("span", {
124
+ className: "libro-sql-input-warning-text",
125
+ children: l10n.t('当前变量名已存在')
126
+ }), /*#__PURE__*/_jsxs("div", {
127
+ className: "libro-sql-input-button",
128
+ children: [/*#__PURE__*/_jsx("span", {
129
+ onClick: handCancel,
130
+ className: "libro-sql-input-cancel",
131
+ children: l10n.t('取消')
132
+ }), /*#__PURE__*/_jsx("span", {
133
+ onClick: handValueSave,
134
+ className: "libro-sql-input-save",
135
+ children: l10n.t('保存')
136
+ })]
137
+ })]
138
+ });
139
+ };
140
+ export var LibroSqlCell = /*#__PURE__*/React.forwardRef(function SqlEditorViewComponent(props, ref) {
141
+ var _useState5 = useState(false),
142
+ _useState6 = _slicedToArray(_useState5, 2),
143
+ isVariableNameEdit = _useState6[0],
144
+ setIsVariableNameEdit = _useState6[1];
145
+ var instance = useInject(ViewInstance);
146
+ var contextKey = useInject(LibroContextKey);
147
+ var handCancelEdit = function handCancelEdit() {
148
+ contextKey.enableCommandMode();
149
+ setIsVariableNameEdit(false);
150
+ };
151
+ return /*#__PURE__*/_jsxs("div", {
152
+ tabIndex: 10,
153
+ ref: ref,
154
+ className: instance.className,
155
+ children: [/*#__PURE__*/_jsxs("div", {
156
+ className: "libro-sql-cell-header",
157
+ children: [/*#__PURE__*/_jsxs("div", {
158
+ className: "libro-sql-source",
159
+ children: [/*#__PURE__*/_jsx("span", {
160
+ className: "libro-sql-source-title",
161
+ children: /*#__PURE__*/_jsx(DatabaseOutlined, {})
162
+ }), /*#__PURE__*/_jsx("span", {
163
+ className: "libro-sql-source-content",
164
+ children: instance.databaseConfig ? instance.databaseConfig.db_type + ': ' + instance.databaseConfig.database : '暂未配置数据库'
165
+ })]
166
+ }), /*#__PURE__*/_jsxs("div", {
167
+ className: "libro-sql-variable-name",
168
+ children: [/*#__PURE__*/_jsx("span", {
169
+ className: "libro-sql-variable-name-title",
170
+ children: "Name: "
171
+ }), /*#__PURE__*/_jsx("span", {
172
+ className: "libro-sql-variable-content",
173
+ children: instance.model.resultVariable
174
+ }), /*#__PURE__*/_jsx("div", {
175
+ className: "libro-sql-variable-name-popover",
176
+ style: {
177
+ display: 'inline-block'
178
+ },
179
+ children: /*#__PURE__*/_jsx(Popover, {
180
+ content: /*#__PURE__*/_jsx(LibroSqlVariableNameInput, {
181
+ handCancel: handCancelEdit
182
+ }),
183
+ placement: "bottomLeft",
184
+ open: instance.parent.model.inputEditable ? isVariableNameEdit : false,
185
+ onOpenChange: function onOpenChange(visible) {
186
+ if (visible) {
187
+ contextKey.disableCommandMode();
188
+ } else {
189
+ contextKey.enableCommandMode();
190
+ }
191
+ setIsVariableNameEdit(visible);
192
+ },
193
+ getPopupContainer: function getPopupContainer() {
194
+ var _instance$container;
195
+ return (_instance$container = instance.container) === null || _instance$container === void 0 || (_instance$container = _instance$container.current) === null || _instance$container === void 0 ? void 0 : _instance$container.getElementsByClassName('libro-sql-variable-name')[0];
196
+ },
197
+ trigger: "click",
198
+ overlayClassName: "libro-sql-popover-container",
199
+ children: /*#__PURE__*/_jsx(EditFilled, {
200
+ className: "libro-sql-edit-icon"
201
+ })
202
+ })
203
+ })]
204
+ })]
205
+ }), /*#__PURE__*/_jsx(CellEditor, {})]
206
+ });
207
+ });
208
+ export var LibroSqlCellView = (_dec = transient(), _dec2 = view('libro-sql-cell-view'), _dec3 = inject(LibroContextKey), _dec4 = prop(), _dec5 = prop(), _dec6 = prop(), _dec7 = prop(), _dec8 = prop(), _dec9 = inject(SqlScript), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroExecutableCellV) {
209
+ _inherits(LibroSqlCellView, _LibroExecutableCellV);
210
+ var _super = _createSuper(LibroSqlCellView);
211
+ function LibroSqlCellView(options, cellService, viewManager, libroViewTracker, codeEditorManager) {
212
+ var _options$cell;
213
+ var _this;
214
+ _classCallCheck(this, LibroSqlCellView);
215
+ _this = _super.call(this, options, cellService);
216
+ _this.view = LibroSqlCell;
217
+ _this.libroViewTracker = void 0;
218
+ _this.codeEditorManager = void 0;
219
+ _this.toDisposeOnEditor = new DisposableCollection();
220
+ _initializerDefineProperty(_this, "libroContextKey", _descriptor, _assertThisInitialized(_this));
221
+ _this.outputs = void 0;
222
+ _initializerDefineProperty(_this, "editorView", _descriptor2, _assertThisInitialized(_this));
223
+ _initializerDefineProperty(_this, "databaseConfig", _descriptor3, _assertThisInitialized(_this));
224
+ _initializerDefineProperty(_this, "editorStatus", _descriptor4, _assertThisInitialized(_this));
225
+ _initializerDefineProperty(_this, "editorAreaHeight", _descriptor5, _assertThisInitialized(_this));
226
+ _initializerDefineProperty(_this, "noEditorAreaHeight", _descriptor6, _assertThisInitialized(_this));
227
+ _initializerDefineProperty(_this, "sqlScript", _descriptor7, _assertThisInitialized(_this));
228
+ _this.editorViewReadyDeferred = new Deferred();
229
+ _this.renderEditor = function () {
230
+ if (_this.editorView) {
231
+ return /*#__PURE__*/_jsx(ViewRender, {
232
+ view: _this.editorView
233
+ });
234
+ } else {
235
+ return null;
236
+ }
237
+ };
238
+ _this.outputAreaDeferred = new Deferred();
239
+ _this.onViewMount = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
240
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
241
+ while (1) switch (_context.prev = _context.next) {
242
+ case 0:
243
+ _context.next = 2;
244
+ return _this.createEditor();
245
+ case 2:
246
+ case "end":
247
+ return _context.stop();
248
+ }
249
+ }, _callee);
250
+ }));
251
+ _this.onViewResize = function (size) {
252
+ // 把 header 部分高度也放在这部分,用来撑开高度
253
+ if (size.height) {
254
+ _this.editorAreaHeight = size.height + 36;
255
+ }
256
+ };
257
+ _this.focus = function (toEdit) {
258
+ if (toEdit) {
259
+ _this.focusEditor();
260
+ _this.getDatabaseConfig();
261
+ } else {
262
+ var _this$container, _this$container2;
263
+ 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)) {
264
+ return;
265
+ }
266
+ (_this$container2 = _this.container) === null || _this$container2 === void 0 || (_this$container2 = _this$container2.current) === null || _this$container2 === void 0 || (_this$container2 = _this$container2.parentElement) === null || _this$container2 === void 0 || _this$container2.focus();
267
+ }
268
+ };
269
+ _this.blur = function () {
270
+ var _this$editorView, _this$editorView2;
271
+ (_this$editorView = _this.editorView) === null || _this$editorView === void 0 || (_this$editorView = _this$editorView.editor) === null || _this$editorView === void 0 || _this$editorView.setOption('styleActiveLine', false);
272
+ (_this$editorView2 = _this.editorView) === null || _this$editorView2 === void 0 || (_this$editorView2 = _this$editorView2.editor) === null || _this$editorView2 === void 0 || _this$editorView2.setOption('highlightActiveLineGutter', false);
273
+ };
274
+ _this.clearExecution = function () {
275
+ _this.model.clearExecution();
276
+ _this.outputArea.clear();
277
+ };
278
+ _this.fetch = /*#__PURE__*/function () {
279
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(content, ioCallback) {
280
+ var _this$parent;
281
+ var model, connection, future;
282
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
283
+ while (1) switch (_context2.prev = _context2.next) {
284
+ case 0:
285
+ model = (_this$parent = _this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.model;
286
+ _context2.next = 3;
287
+ return model.kcReady;
288
+ case 3:
289
+ connection = model.kernelConnection;
290
+ future = connection.requestExecute(content);
291
+ future.onIOPub = function (msg) {
292
+ ioCallback(msg);
293
+ };
294
+ return _context2.abrupt("return", future.done);
295
+ case 7:
296
+ case "end":
297
+ return _context2.stop();
298
+ }
299
+ }, _callee2);
300
+ }));
301
+ return function (_x, _x2) {
302
+ return _ref3.apply(this, arguments);
303
+ };
304
+ }();
305
+ _this.handleQueryResponse = function (response, cb) {
306
+ var msgType = response.header.msg_type;
307
+ switch (msgType) {
308
+ case 'execute_result':
309
+ case 'display_data':
310
+ {
311
+ var payload = response;
312
+ var content = payload.content.data['text/plain'];
313
+ if (content.slice(0, 1) === "'" || content.slice(0, 1) === '"') {
314
+ content = content.slice(1, -1);
315
+ content = content.replace(/\\"/g, '"').replace(/\\'/g, "'");
316
+ }
317
+ cb(content);
318
+ break;
319
+ }
320
+ case 'stream':
321
+ {
322
+ var payloadDisplay = response;
323
+ var contentStream = payloadDisplay.content.text;
324
+ if (contentStream.slice(0, 1) === "'" || contentStream.slice(0, 1) === '"') {
325
+ contentStream = contentStream.slice(1, -1);
326
+ contentStream = contentStream.replace(/\\"/g, '"').replace(/\\'/g, "'");
327
+ }
328
+ cb(contentStream);
329
+ break;
330
+ }
331
+ default:
332
+ break;
333
+ }
334
+ };
335
+ _this.getDatabaseConfig = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
336
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
337
+ while (1) switch (_context3.prev = _context3.next) {
338
+ case 0:
339
+ return _context3.abrupt("return", _this.fetch({
340
+ code: _this.sqlScript.getDbConfig,
341
+ store_history: false
342
+ }, function (msg) {
343
+ return _this.handleQueryResponse(msg, function (result) {
344
+ try {
345
+ _this.databaseConfig = JSON.parse(result);
346
+ } catch (e) {
347
+ _this.databaseConfig = undefined;
348
+ }
349
+ });
350
+ }));
351
+ case 1:
352
+ case "end":
353
+ return _context3.stop();
354
+ }
355
+ }, _callee3);
356
+ }));
357
+ _this.codeEditorManager = codeEditorManager;
358
+ _this.outputs = (_options$cell = options.cell) === null || _options$cell === void 0 ? void 0 : _options$cell.outputs;
359
+ _this.className = _this.className + ' sql';
360
+ viewManager.getOrCreateView(LibroOutputArea, {
361
+ cellId: _this.id,
362
+ cell: _assertThisInitialized(_this)
363
+ }).then( /*#__PURE__*/function () {
364
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(outputArea) {
365
+ var output;
366
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
367
+ while (1) switch (_context4.prev = _context4.next) {
368
+ case 0:
369
+ _this.outputArea = outputArea;
370
+ output = _this.outputs;
371
+ if (!isOutput(output)) {
372
+ _context4.next = 5;
373
+ break;
374
+ }
375
+ _context4.next = 5;
376
+ return _this.outputArea.fromJSON(output);
377
+ case 5:
378
+ _this.outputAreaDeferred.resolve(outputArea);
379
+ _this.outputWatch();
380
+ return _context4.abrupt("return");
381
+ case 8:
382
+ case "end":
383
+ return _context4.stop();
384
+ }
385
+ }, _callee4);
386
+ }));
387
+ return function (_x3) {
388
+ return _ref5.apply(this, arguments);
389
+ };
390
+ }()).catch(function () {
391
+ //
392
+ });
393
+ _this.libroViewTracker = libroViewTracker;
394
+ if (!_this.model.resultVariable) {
395
+ var _this$libroViewTracke;
396
+ _this.model.resultVariable = getDfVariableName((_this$libroViewTracke = _this.libroViewTracker.viewCache.get(options.parentId)) === null || _this$libroViewTracke === void 0 ? void 0 : _this$libroViewTracke.model.cells.filter(function (cell) {
397
+ return cell.model.type === 'sql';
398
+ }));
399
+ }
400
+ return _this;
401
+ }
402
+ LibroSqlCellView = inject(CodeEditorManager)(LibroSqlCellView, undefined, 4) || LibroSqlCellView;
403
+ LibroSqlCellView = inject(LibroViewTracker)(LibroSqlCellView, undefined, 3) || LibroSqlCellView;
404
+ LibroSqlCellView = inject(ViewManager)(LibroSqlCellView, undefined, 2) || LibroSqlCellView;
405
+ LibroSqlCellView = inject(CellService)(LibroSqlCellView, undefined, 1) || LibroSqlCellView;
406
+ LibroSqlCellView = inject(ViewOption)(LibroSqlCellView, undefined, 0) || LibroSqlCellView;
407
+ _createClass(LibroSqlCellView, [{
408
+ key: "editorReady",
409
+ get: function get() {
410
+ return this.editorViewReadyDeferred.promise;
411
+ }
412
+ }, {
413
+ key: "calcEditorOffset",
414
+ value:
415
+ // 计算编辑器区相对于编辑器区垂直方向的偏移量
416
+ function calcEditorOffset() {
417
+ return _get(_getPrototypeOf(LibroSqlCellView.prototype), "calcEditorOffset", this).call(this) + 36;
418
+ }
419
+ }, {
420
+ key: "calcEditorAreaHeight",
421
+ value: function calcEditorAreaHeight() {
422
+ if (this.editorStatus === EditorStatus.NOTLOADED || this.editorStatus === EditorStatus.LOADING) {
423
+ var _this$codeEditorManag = this.codeEditorManager.getUserEditorConfig(this.model),
424
+ lineHeight = _this$codeEditorManag.lineHeight,
425
+ paddingTop = _this$codeEditorManag.paddingTop,
426
+ paddingBottom = _this$codeEditorManag.paddingBottom;
427
+ var codeHeight = countLines(this.model.value) * lineHeight;
428
+ var editorPadding = paddingTop + paddingBottom;
429
+ var scrollbarHeight = 12;
430
+
431
+ // TODO: 滚动条有条件显示
432
+
433
+ var editorAreaHeight = codeHeight + editorPadding + scrollbarHeight;
434
+ this.editorAreaHeight = editorAreaHeight;
435
+ }
436
+
437
+ // 编辑器已经加载的情况下cell高度都由对它的高度监听得到。
438
+ return this.editorAreaHeight;
439
+ }
440
+ }, {
441
+ key: "outputAreaReady",
442
+ get: function get() {
443
+ return this.outputAreaDeferred.promise;
444
+ }
445
+ }, {
446
+ key: "setEditorHost",
447
+ value: function setEditorHost(ref) {
448
+ var editorHostId = this.parent.id + this.id;
449
+ this.codeEditorManager.setEditorHostRef(editorHostId, ref);
450
+ }
451
+ }, {
452
+ key: "createEditor",
453
+ value: function () {
454
+ var _createEditor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
455
+ var _this2 = this;
456
+ var editorHostId, option, editorView;
457
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
458
+ while (1) switch (_context5.prev = _context5.next) {
459
+ case 0:
460
+ editorHostId = this.parent.id + this.id;
461
+ option = {
462
+ uuid: CellUri.from(this.parent.model.id, this.model.id).toString(),
463
+ editorHostId: editorHostId,
464
+ model: this.model,
465
+ config: {
466
+ readOnly: !this.parent.model.inputEditable,
467
+ editable: this.parent.model.inputEditable
468
+ }
469
+ }; // 防止虚拟滚动中编辑器被频繁创建
470
+ if (!this.editorView) {
471
+ _context5.next = 5;
472
+ break;
473
+ }
474
+ this.editorStatus = EditorStatus.LOADED;
475
+ return _context5.abrupt("return");
476
+ case 5:
477
+ _context5.next = 7;
478
+ return this.codeEditorManager.getOrCreateEditorView(option);
479
+ case 7:
480
+ editorView = _context5.sent;
481
+ this.editorView = editorView;
482
+ this.editorStatus = EditorStatus.LOADED;
483
+ this.editorViewReadyDeferred.resolve();
484
+ editorView.onEditorStatusChange(function (e) {
485
+ if (e.status === 'ready') {
486
+ _this2.editor = _this2.editorView.editor;
487
+ _this2.afterEditorReady();
488
+ } else if (e.status === 'disposed') {
489
+ _this2.toDisposeOnEditor.dispose();
490
+ }
491
+ });
492
+ case 12:
493
+ case "end":
494
+ return _context5.stop();
495
+ }
496
+ }, _callee5, this);
497
+ }));
498
+ function createEditor() {
499
+ return _createEditor.apply(this, arguments);
500
+ }
501
+ return createEditor;
502
+ }()
503
+ }, {
504
+ key: "afterEditorReady",
505
+ value: function () {
506
+ var _afterEditorReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
507
+ var _this3 = this,
508
+ _this$editorView$onMo,
509
+ _this$editorView3,
510
+ _this$editor$onModelC,
511
+ _this$editor,
512
+ _this$editor$onModelC2;
513
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
514
+ while (1) switch (_context6.prev = _context6.next) {
515
+ case 0:
516
+ this.focusEditor();
517
+ this.toDisposeOnEditor.push(watch(this.parent.model, 'inputEditable', function () {
518
+ var _this3$editorView;
519
+ (_this3$editorView = _this3.editorView) === null || _this3$editorView === void 0 || (_this3$editorView = _this3$editorView.editor) === null || _this3$editorView === void 0 || _this3$editorView.setOption('readOnly', getOrigin(!_this3.parent.model.inputEditable));
520
+ }));
521
+ this.toDisposeOnEditor.push((_this$editorView$onMo = (_this$editorView3 = this.editorView) === null || _this$editorView3 === void 0 ? void 0 : _this$editorView3.onModalChange(function (val) {
522
+ return _this3.hasModal = val;
523
+ })) !== null && _this$editorView$onMo !== void 0 ? _this$editorView$onMo : Disposable.NONE);
524
+ this.toDisposeOnEditor.push((_this$editor$onModelC = (_this$editor = this.editor) === null || _this$editor === void 0 || (_this$editor$onModelC2 = _this$editor.onModelContentChanged) === null || _this$editor$onModelC2 === void 0 ? void 0 : _this$editor$onModelC2.call(_this$editor, function (e) {
525
+ _this3.parent.model.onCellContentChange({
526
+ cell: _this3,
527
+ changes: e
528
+ });
529
+ })) !== null && _this$editor$onModelC !== void 0 ? _this$editor$onModelC : Disposable.NONE);
530
+ case 4:
531
+ case "end":
532
+ return _context6.stop();
533
+ }
534
+ }, _callee6, this);
535
+ }));
536
+ function afterEditorReady() {
537
+ return _afterEditorReady.apply(this, arguments);
538
+ }
539
+ return afterEditorReady;
540
+ }()
541
+ }, {
542
+ key: "focusEditor",
543
+ value: function focusEditor() {
544
+ var _this$editorView4, _this$parent$model$ac;
545
+ //选中cell、编辑模式、非只读时才focus
546
+ if ((_this$editorView4 = this.editorView) !== null && _this$editorView4 !== void 0 && _this$editorView4.editor && this.editorView.editorStatus === 'ready' && ((_this$parent$model$ac = this.parent.model.active) === null || _this$parent$model$ac === void 0 ? void 0 : _this$parent$model$ac.id) === this.id && !this.parent.model.commandMode && this.libroContextKey.commandModeEnabled === true &&
547
+ // 排除弹窗等情况
548
+ this.parent.model.inputEditable) {
549
+ var _this$editorView5, _this$editorView6, _this$editorView7;
550
+ (_this$editorView5 = this.editorView) === null || _this$editorView5 === void 0 || _this$editorView5.editor.setOption('styleActiveLine', true);
551
+ (_this$editorView6 = this.editorView) === null || _this$editorView6 === void 0 || _this$editorView6.editor.setOption('highlightActiveLineGutter', true);
552
+ (_this$editorView7 = this.editorView) === null || _this$editorView7 === void 0 || _this$editorView7.editor.focus();
553
+ }
554
+ }
555
+ }, {
556
+ key: "toJSON",
557
+ value: function toJSON() {
558
+ var _meta$source, _this$outputArea$toJS, _this$outputArea;
559
+ var meta = _get(_getPrototypeOf(LibroSqlCellView.prototype), "toJSON", this).call(this);
560
+ return _objectSpread(_objectSpread({}, meta), {}, {
561
+ source: (_meta$source = meta.source) !== null && _meta$source !== void 0 ? _meta$source : this.options.cell.source,
562
+ 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
563
+ });
564
+ }
565
+ }, {
566
+ key: "run",
567
+ value: function () {
568
+ var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
569
+ var _this4 = this;
570
+ var libroModel, kernelConnection, cellContent, future, startTimeStr, msgPromise, endTimeStr;
571
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
572
+ while (1) switch (_context7.prev = _context7.next) {
573
+ case 0:
574
+ libroModel = this.parent.model;
575
+ if (!(!libroModel || !(libroModel instanceof LibroJupyterModel) || !libroModel.kernelConnection || libroModel.kernelConnection.isDisposed)) {
576
+ _context7.next = 3;
577
+ break;
578
+ }
579
+ return _context7.abrupt("return", false);
580
+ case 3:
581
+ kernelConnection = getOrigin(libroModel.kernelConnection);
582
+ cellContent = this.model.source;
583
+ _context7.prev = 5;
584
+ // Promise.resolve().then(() => {
585
+ this.clearExecution();
586
+ // });
587
+ future = kernelConnection.requestExecute({
588
+ code: cellContent
589
+ });
590
+ startTimeStr = null;
591
+ this.model.executing = true;
592
+ this.model.metadata['execution'] = {
593
+ 'shell.execute_reply.started': '',
594
+ 'shell.execute_reply.end': '',
595
+ to_execute: new Date().toISOString()
596
+ };
597
+ // Handle iopub messages
598
+ future.onIOPub = function (msg) {
599
+ _this4.model.msgChangeEmitter.fire(msg);
600
+ if (msg.header.msg_type === 'execute_input') {
601
+ _this4.model.kernelExecuting = true;
602
+ startTimeStr = msg.header.date;
603
+ var meta = _this4.model.metadata['execution'];
604
+ if (meta) {
605
+ meta['shell.execute_reply.started'] = startTimeStr;
606
+ }
607
+ }
608
+ if (msg.header.msg_type === 'execute_result') {
609
+ _this4.model.metadata['isVariableSaved'] = msg.content.data['application/vnd.libro.sql+json'].isVariableSaved;
610
+ }
611
+ if (msg.header.msg_type === 'error') {
612
+ _this4.model.hasExecutedError = true;
613
+ }
614
+ };
615
+ _context7.next = 14;
616
+ return future.done;
617
+ case 14:
618
+ msgPromise = _context7.sent;
619
+ this.model.executing = false;
620
+ this.model.kernelExecuting = false;
621
+ this.model.hasExecutedSuccess = !this.model.hasExecutedError;
622
+ startTimeStr = msgPromise.metadata['started']; // 更新startTimeStr
623
+ endTimeStr = msgPromise.header.date;
624
+ this.model.metadata['execution']['shell.execute_reply.started'] = startTimeStr;
625
+ this.model.metadata['execution']['shell.execute_reply.end'] = endTimeStr;
626
+ if (msgPromise) {
627
+ _context7.next = 24;
628
+ break;
629
+ }
630
+ return _context7.abrupt("return", true);
631
+ case 24:
632
+ if (!(msgPromise.content.status === 'ok')) {
633
+ _context7.next = 28;
634
+ break;
635
+ }
636
+ return _context7.abrupt("return", true);
637
+ case 28:
638
+ throw new KernelError(msgPromise.content);
639
+ case 29:
640
+ _context7.next = 36;
641
+ break;
642
+ case 31:
643
+ _context7.prev = 31;
644
+ _context7.t0 = _context7["catch"](5);
645
+ if (!_context7.t0.message.startsWith('Canceled')) {
646
+ _context7.next = 35;
647
+ break;
648
+ }
649
+ return _context7.abrupt("return", false);
650
+ case 35:
651
+ throw _context7.t0;
652
+ case 36:
653
+ case "end":
654
+ return _context7.stop();
655
+ }
656
+ }, _callee7, this, [[5, 31]]);
657
+ }));
658
+ function run() {
659
+ return _run.apply(this, arguments);
660
+ }
661
+ return run;
662
+ }()
663
+ }, {
664
+ key: "shouldEnterEditorMode",
665
+ value: function shouldEnterEditorMode(e) {
666
+ var _getOrigin;
667
+ return (_getOrigin = getOrigin(this.editorView)) !== null && _getOrigin !== void 0 && (_getOrigin = _getOrigin.editor) !== null && _getOrigin !== void 0 && (_getOrigin = _getOrigin.host) !== null && _getOrigin !== void 0 && _getOrigin.contains(e.target) ? true : false;
668
+ }
669
+ }]);
670
+ return LibroSqlCellView;
671
+ }(LibroExecutableCellView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "libroContextKey", [_dec3], {
672
+ configurable: true,
673
+ enumerable: true,
674
+ writable: true,
675
+ initializer: null
676
+ }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "editorView", [_dec4], {
677
+ configurable: true,
678
+ enumerable: true,
679
+ writable: true,
680
+ initializer: null
681
+ }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "databaseConfig", [_dec5], {
682
+ configurable: true,
683
+ enumerable: true,
684
+ writable: true,
685
+ initializer: null
686
+ }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "editorStatus", [_dec6], {
687
+ configurable: true,
688
+ enumerable: true,
689
+ writable: true,
690
+ initializer: function initializer() {
691
+ return EditorStatus.NOTLOADED;
692
+ }
693
+ }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "editorAreaHeight", [_dec7], {
694
+ configurable: true,
695
+ enumerable: true,
696
+ writable: true,
697
+ initializer: function initializer() {
698
+ return 0;
699
+ }
700
+ }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "noEditorAreaHeight", [_dec8], {
701
+ configurable: true,
702
+ enumerable: true,
703
+ writable: true,
704
+ initializer: function initializer() {
705
+ return 0;
706
+ }
707
+ }), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "sqlScript", [_dec9], {
708
+ configurable: true,
709
+ enumerable: true,
710
+ writable: true,
711
+ initializer: null
712
+ })), _class2)) || _class) || _class);