@difizen/libro-jupyter 0.1.33 → 0.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/cell/jupyter-code-cell-view.d.ts +3 -1
- package/es/cell/jupyter-code-cell-view.d.ts.map +1 -1
- package/es/cell/jupyter-code-cell-view.js +9 -0
- package/es/index.d.ts +1 -0
- package/es/index.d.ts.map +1 -1
- package/es/index.js +2 -1
- package/es/module.d.ts.map +1 -1
- package/es/module.js +2 -3
- package/es/output/libro-jupyter-outputarea.d.ts.map +1 -1
- package/es/output/libro-jupyter-outputarea.js +60 -56
- package/es/widget/box/contribution.d.ts +10 -0
- package/es/widget/box/contribution.d.ts.map +1 -0
- package/es/widget/box/contribution.js +48 -0
- package/es/widget/box/index.d.ts +3 -0
- package/es/widget/box/index.d.ts.map +1 -0
- package/es/widget/box/index.js +2 -0
- package/es/widget/box/index.less +3 -0
- package/es/widget/box/view.d.ts +19 -0
- package/es/widget/box/view.d.ts.map +1 -0
- package/es/widget/box/view.js +114 -0
- package/es/widget/comm.d.ts +65 -0
- package/es/widget/comm.d.ts.map +1 -0
- package/es/widget/comm.js +153 -0
- package/es/widget/index.d.ts +7 -0
- package/es/widget/index.d.ts.map +1 -1
- package/es/widget/index.js +8 -1
- package/es/widget/instance-progress/contribution.d.ts +10 -0
- package/es/widget/instance-progress/contribution.d.ts.map +1 -0
- package/es/widget/instance-progress/contribution.js +39 -0
- package/es/widget/instance-progress/index.d.ts +3 -0
- package/es/widget/instance-progress/index.d.ts.map +1 -0
- package/es/widget/instance-progress/index.js +2 -0
- package/es/widget/instance-progress/view.d.ts +30 -0
- package/es/widget/instance-progress/view.d.ts.map +1 -0
- package/es/widget/instance-progress/view.js +180 -0
- package/es/widget/libro-widgets.d.ts +84 -0
- package/es/widget/libro-widgets.d.ts.map +1 -0
- package/es/widget/libro-widgets.js +307 -0
- package/es/widget/module.d.ts +4 -0
- package/es/widget/module.d.ts.map +1 -0
- package/es/widget/module.js +38 -0
- package/es/widget/progress/contribution.d.ts +10 -0
- package/es/widget/progress/contribution.d.ts.map +1 -0
- package/es/widget/progress/contribution.js +39 -0
- package/es/widget/progress/index.d.ts +3 -0
- package/es/widget/progress/index.d.ts.map +1 -0
- package/es/widget/progress/index.js +2 -0
- package/es/widget/progress/progressBar.d.ts +15 -0
- package/es/widget/progress/progressBar.d.ts.map +1 -0
- package/es/widget/progress/progressBar.js +20 -0
- package/es/widget/progress/view.d.ts +19 -0
- package/es/widget/progress/view.d.ts.map +1 -0
- package/es/widget/progress/view.js +74 -0
- package/es/widget/protocol.d.ts +193 -0
- package/es/widget/protocol.d.ts.map +1 -0
- package/es/widget/protocol.js +33 -0
- package/es/widget/utils.d.ts +27 -0
- package/es/widget/utils.d.ts.map +1 -0
- package/es/widget/utils.js +59 -0
- package/es/widget/version.d.ts +3 -0
- package/es/widget/version.d.ts.map +1 -0
- package/es/widget/version.js +2 -0
- package/es/widget/widget-manager.d.ts +19 -0
- package/es/widget/widget-manager.d.ts.map +1 -0
- package/es/widget/widget-manager.js +77 -0
- package/es/widget/widget-render.d.ts.map +1 -1
- package/es/widget/widget-render.js +7 -3
- package/es/widget/widget-rendermime-contribution.d.ts +2 -1
- package/es/widget/widget-rendermime-contribution.d.ts.map +1 -1
- package/es/widget/widget-rendermime-contribution.js +2 -1
- package/es/widget/widget-view-contribution.d.ts +10 -0
- package/es/widget/widget-view-contribution.d.ts.map +1 -0
- package/es/widget/widget-view-contribution.js +36 -0
- package/es/widget/widget-view.d.ts +71 -0
- package/es/widget/widget-view.d.ts.map +1 -0
- package/es/widget/widget-view.js +273 -0
- package/package.json +17 -18
- package/src/cell/jupyter-code-cell-view.tsx +10 -1
- package/src/index.ts +1 -0
- package/src/module.ts +1 -3
- package/src/output/libro-jupyter-outputarea.tsx +56 -49
- package/src/widget/box/contribution.ts +29 -0
- package/src/widget/box/index.less +3 -0
- package/src/widget/box/index.ts +2 -0
- package/src/widget/box/view.tsx +112 -0
- package/src/widget/comm.ts +152 -0
- package/src/widget/index.ts +7 -0
- package/src/widget/instance-progress/contribution.ts +20 -0
- package/src/widget/instance-progress/index.ts +2 -0
- package/src/widget/instance-progress/view.tsx +155 -0
- package/src/widget/libro-widgets.ts +223 -0
- package/src/widget/module.ts +73 -0
- package/src/widget/progress/contribution.ts +24 -0
- package/src/widget/progress/index.ts +2 -0
- package/src/widget/progress/progressBar.tsx +29 -0
- package/src/widget/progress/view.tsx +70 -0
- package/src/widget/protocol.ts +255 -0
- package/src/widget/utils.ts +67 -0
- package/src/widget/version.ts +2 -0
- package/src/widget/widget-manager.ts +45 -0
- package/src/widget/widget-render.tsx +10 -5
- package/src/widget/widget-rendermime-contribution.ts +2 -1
- package/src/widget/widget-view-contribution.ts +14 -0
- package/src/widget/widget-view.tsx +259 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget-view.d.ts","sourceRoot":"","sources":["../../src/widget/widget-view.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAuB,MAAM,uBAAuB,CAAC;AACxF,OAAO,KAAK,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAE7E,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAKL,QAAQ,EAGT,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAMnE,OAAO,KAAK,EACV,IAAI,EACJ,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,WAAW,EACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,eAAO,MAAM,oBAAoB,0FAIhC,CAAC;AAEF,qBAEa,UAAW,SAAQ,QAAS,YAAW,WAAW;IACpD,IAAI,EAAE,aAAa,CAAwB;IACpD,eAAe,EAAE,eAAe,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,aAAa,CAAC,aAAa,KAAK,OAAO,CAAC;IAEtC,kBAAkB,EAAE,kBAAkB,CAAC;IAGnE,KAAK,EAAE,UAAU,GAAG,WAAW,CAAsB;IAErD,IAAI,CAAC,EAAE,uBAAuB,CAAC;IAE/B,IAAI,OAAO,6DAKV;IAED,kBAAkB,UAAQ;IAE1B,qBAAqB,CAAC,EAAE,UAAU,CAAC;gBAGb,KAAK,EAAE,gBAAgB,EAClB,eAAe,EAAE,eAAe;IAqC3D,OAAO,CAAC,IAAI,EAAE,QAAQ;IAiBtB;;OAEG;IACH,mBAAmB,QAAO,IAAI,CAE5B;IAEF;;OAEG;IACH,UAAU,IAAI,IAAI;IAelB,cAAc,CAAC,GAAG,EAAE,aAAa,CAAC,aAAa;IAoB/C,WAAW,CAAC,IAAI,UAAQ,GAAG,IAAI;IAItB,WAAW;IAiBpB;;OAEG;IACH,aAAa,CAAC,GAAG,EAAE,aAAa,CAAC,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAW5D,gBAAgB,aAEd;IACF;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI;IAUhC;;;OAGG;IACH,MAAM,IAAI,MAAM;IAIhB,UAAU,IAAI,MAAM;IAIpB;;OAEG;IACH,IAAI,SACI,SAAS,cACH,UAAU,YACZ,WAAW,EAAE,GAAG,eAAe,EAAE,wBAM3C;IAEF,IAAI,EAAE,YAAY,CAAC;IACX,OAAO,CAAC,EAAE,QAAQ,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,UAAS;IAErB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B"}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _descriptor3;
|
|
3
|
+
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
|
|
4
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
6
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
8
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
9
|
+
function _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); }
|
|
10
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
11
|
+
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); }; }
|
|
12
|
+
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); }
|
|
13
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
14
|
+
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; } }
|
|
15
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
16
|
+
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; }
|
|
17
|
+
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.'); }
|
|
18
|
+
import { ExecutableCellView } from '@difizen/libro-core';
|
|
19
|
+
import { LibroContextKey } from '@difizen/libro-core';
|
|
20
|
+
import { inject, transient, ViewOption, view, BaseView, prop, watch } from '@difizen/mana-app';
|
|
21
|
+
import { forwardRef } from 'react';
|
|
22
|
+
import { LibroJupyterModel } from "../libro-jupyter-model.js";
|
|
23
|
+
import { defaultWidgetState } from "./protocol.js";
|
|
24
|
+
import { LibroWidgetManager } from "./widget-manager.js";
|
|
25
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
26
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
27
|
+
export var LibroWidgetComponent = /*#__PURE__*/forwardRef(function LibroWidgetComponent() {
|
|
28
|
+
return /*#__PURE__*/_jsx(_Fragment, {});
|
|
29
|
+
});
|
|
30
|
+
export var WidgetView = (_dec = transient(), _dec2 = view('libro-widget-view'), _dec3 = inject(LibroWidgetManager), _dec4 = prop(), _dec5 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_BaseView) {
|
|
31
|
+
_inherits(WidgetView, _BaseView);
|
|
32
|
+
var _super = _createSuper(WidgetView);
|
|
33
|
+
function WidgetView(props, libroContextKey) {
|
|
34
|
+
var _this;
|
|
35
|
+
_classCallCheck(this, WidgetView);
|
|
36
|
+
_this = _super.call(this);
|
|
37
|
+
_this.view = LibroWidgetComponent;
|
|
38
|
+
_this.libroContextKey = void 0;
|
|
39
|
+
_this.widgetsId = void 0;
|
|
40
|
+
_this._msgHook = void 0;
|
|
41
|
+
_initializerDefineProperty(_this, "libroWidgetManager", _descriptor, _assertThisInitialized(_this));
|
|
42
|
+
_initializerDefineProperty(_this, "state", _descriptor2, _assertThisInitialized(_this));
|
|
43
|
+
_this.cell = void 0;
|
|
44
|
+
_this.disableCommandMode = true;
|
|
45
|
+
_this.toDisposeOnMsgChanged = void 0;
|
|
46
|
+
/**
|
|
47
|
+
* Register a new kernel
|
|
48
|
+
*/
|
|
49
|
+
_this.handleKernelChanged = function () {
|
|
50
|
+
_this.setState({
|
|
51
|
+
msg_id: undefined
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
_this.handleCommClosed = function () {
|
|
55
|
+
_this.isCommClosed = true;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Send a custom msg over the comm.
|
|
59
|
+
*/
|
|
60
|
+
_this.send = function (data, callbacks, buffers) {
|
|
61
|
+
if (_this.comm !== undefined) {
|
|
62
|
+
return _this.comm.send(data, callbacks, {}, buffers);
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
};
|
|
66
|
+
_this.comm = void 0;
|
|
67
|
+
_initializerDefineProperty(_this, "widgets", _descriptor3, _assertThisInitialized(_this));
|
|
68
|
+
_this.model_id = void 0;
|
|
69
|
+
_this.state_change = void 0;
|
|
70
|
+
_this.name = void 0;
|
|
71
|
+
_this.module = void 0;
|
|
72
|
+
_this.isCommClosed = false;
|
|
73
|
+
_this.model_module = void 0;
|
|
74
|
+
_this.model_name = void 0;
|
|
75
|
+
_this.model_module_version = void 0;
|
|
76
|
+
_this.view_module = void 0;
|
|
77
|
+
_this.view_name = void 0;
|
|
78
|
+
_this.view_module_version = void 0;
|
|
79
|
+
_this.view_count = void 0;
|
|
80
|
+
_this.widgetsId = props.widgetsId;
|
|
81
|
+
var attributes = props.attributes;
|
|
82
|
+
_this.model_module = attributes._model_module;
|
|
83
|
+
_this.model_name = attributes._model_name;
|
|
84
|
+
_this.model_module_version = attributes._model_module_version;
|
|
85
|
+
_this.view_module = attributes._view_module;
|
|
86
|
+
_this.view_name = attributes._view_name;
|
|
87
|
+
_this.view_module_version = attributes._view_module_version;
|
|
88
|
+
_this.view_count = attributes._view_count;
|
|
89
|
+
_this._msgHook = function (msg) {
|
|
90
|
+
_this.addFromMessage(msg);
|
|
91
|
+
return false;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Attributes should be initialized here, since user initialization may depend on it
|
|
95
|
+
var comm = props.options.comm;
|
|
96
|
+
if (comm) {
|
|
97
|
+
// Remember comm associated with the model.
|
|
98
|
+
_this.comm = comm;
|
|
99
|
+
|
|
100
|
+
// Hook comm messages up to model.
|
|
101
|
+
comm.onClose(_this.handleCommClosed.bind(_assertThisInitialized(_this)));
|
|
102
|
+
comm.onMsg(_this.handleCommMsg.bind(_assertThisInitialized(_this)));
|
|
103
|
+
} else {
|
|
104
|
+
_this.isCommClosed = false;
|
|
105
|
+
}
|
|
106
|
+
_this.model_id = props.options.model_id;
|
|
107
|
+
_this.state_change = Promise.resolve();
|
|
108
|
+
_this.setState(attributes);
|
|
109
|
+
_this.libroContextKey = libroContextKey;
|
|
110
|
+
return _this;
|
|
111
|
+
}
|
|
112
|
+
WidgetView = inject(LibroContextKey)(WidgetView, undefined, 1) || WidgetView;
|
|
113
|
+
WidgetView = inject(ViewOption)(WidgetView, undefined, 0) || WidgetView;
|
|
114
|
+
_createClass(WidgetView, [{
|
|
115
|
+
key: "outputs",
|
|
116
|
+
get: function get() {
|
|
117
|
+
if (this.cell) {
|
|
118
|
+
return this.cell.outputArea;
|
|
119
|
+
}
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
}, {
|
|
123
|
+
key: "setCell",
|
|
124
|
+
value: function setCell(cell) {
|
|
125
|
+
var _this2 = this;
|
|
126
|
+
if (ExecutableCellView.is(cell)) {
|
|
127
|
+
this.cell = cell;
|
|
128
|
+
if (this.cell) {
|
|
129
|
+
this.cell.parentReady.then(function () {
|
|
130
|
+
var _this2$cell;
|
|
131
|
+
var notebookModel = (_this2$cell = _this2.cell) === null || _this2$cell === void 0 ? void 0 : _this2$cell.parent.model;
|
|
132
|
+
if (notebookModel instanceof LibroJupyterModel) {
|
|
133
|
+
watch(notebookModel, 'kernelConnection', _this2.handleKernelChanged);
|
|
134
|
+
}
|
|
135
|
+
return;
|
|
136
|
+
}).catch(console.error);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}, {
|
|
141
|
+
key: "resetMsgId",
|
|
142
|
+
value:
|
|
143
|
+
/**
|
|
144
|
+
* Reset the message id.
|
|
145
|
+
*/
|
|
146
|
+
function resetMsgId() {
|
|
147
|
+
var _this$toDisposeOnMsgC, _this$cell;
|
|
148
|
+
(_this$toDisposeOnMsgC = this.toDisposeOnMsgChanged) === null || _this$toDisposeOnMsgC === void 0 || _this$toDisposeOnMsgC.dispose();
|
|
149
|
+
var notebookModel = (_this$cell = this.cell) === null || _this$cell === void 0 || (_this$cell = _this$cell.parent) === null || _this$cell === void 0 ? void 0 : _this$cell.model;
|
|
150
|
+
if (notebookModel instanceof LibroJupyterModel) {
|
|
151
|
+
var kernel = notebookModel.kernelConnection;
|
|
152
|
+
if (kernel && this.state['msg_id']) {
|
|
153
|
+
this.toDisposeOnMsgChanged = kernel.registerMessageHook(this.state['msg_id'], this._msgHook);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}, {
|
|
158
|
+
key: "addFromMessage",
|
|
159
|
+
value: function addFromMessage(msg) {
|
|
160
|
+
var msgType = msg.header.msg_type;
|
|
161
|
+
switch (msgType) {
|
|
162
|
+
case 'execute_result':
|
|
163
|
+
case 'display_data':
|
|
164
|
+
case 'stream':
|
|
165
|
+
case 'error':
|
|
166
|
+
{
|
|
167
|
+
var _this$outputs;
|
|
168
|
+
var model = msg.content;
|
|
169
|
+
model.output_type = msgType;
|
|
170
|
+
(_this$outputs = this.outputs) === null || _this$outputs === void 0 || _this$outputs.add(model);
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
case 'clear_output':
|
|
174
|
+
this.clearOutput(msg.content.wait);
|
|
175
|
+
break;
|
|
176
|
+
default:
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}, {
|
|
181
|
+
key: "clearOutput",
|
|
182
|
+
value: function clearOutput() {
|
|
183
|
+
var _this$outputs2;
|
|
184
|
+
var wait = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
185
|
+
(_this$outputs2 = this.outputs) === null || _this$outputs2 === void 0 || _this$outputs2.clear(wait);
|
|
186
|
+
}
|
|
187
|
+
}, {
|
|
188
|
+
key: "onViewMount",
|
|
189
|
+
value: function onViewMount() {
|
|
190
|
+
var _this3 = this;
|
|
191
|
+
this.widgets = this.libroWidgetManager.getWidgets(this.widgetsId);
|
|
192
|
+
if (this.container && this.container.current && this.disableCommandMode) {
|
|
193
|
+
this.container.current.addEventListener('focusin', function () {
|
|
194
|
+
_this3.libroContextKey.disableCommandMode();
|
|
195
|
+
});
|
|
196
|
+
this.container.current.addEventListener('blur', function (e) {
|
|
197
|
+
var _this3$container;
|
|
198
|
+
if ((_this3$container = _this3.container) !== null && _this3$container !== void 0 && (_this3$container = _this3$container.current) !== null && _this3$container !== void 0 && _this3$container.contains(e.relatedTarget)) {
|
|
199
|
+
_this3.libroContextKey.disableCommandMode();
|
|
200
|
+
} else {
|
|
201
|
+
_this3.libroContextKey.enableCommandMode();
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Handle incoming comm msg.
|
|
209
|
+
*/
|
|
210
|
+
}, {
|
|
211
|
+
key: "handleCommMsg",
|
|
212
|
+
value: function handleCommMsg(msg) {
|
|
213
|
+
var data = msg.content.data;
|
|
214
|
+
var method = data.method;
|
|
215
|
+
switch (method) {
|
|
216
|
+
case 'update':
|
|
217
|
+
case 'echo_update':
|
|
218
|
+
this.setState(data.state);
|
|
219
|
+
}
|
|
220
|
+
return Promise.resolve();
|
|
221
|
+
}
|
|
222
|
+
}, {
|
|
223
|
+
key: "setState",
|
|
224
|
+
value:
|
|
225
|
+
/**
|
|
226
|
+
* Handle when a widget is updated from the backend.
|
|
227
|
+
*
|
|
228
|
+
* This function is meant for internal use only. Values set here will not be propagated on a sync.
|
|
229
|
+
*/
|
|
230
|
+
function setState(state) {
|
|
231
|
+
for (var key in state) {
|
|
232
|
+
var oldMsgId = this.state['msg_id'];
|
|
233
|
+
this.state[key] = state[key];
|
|
234
|
+
if (key === 'msg_id' && oldMsgId !== state['msg_id']) {
|
|
235
|
+
this.resetMsgId();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Serialize the model. See the deserialization function at the top of this file
|
|
242
|
+
* and the kernel-side serializer/deserializer.
|
|
243
|
+
*/
|
|
244
|
+
}, {
|
|
245
|
+
key: "toJSON",
|
|
246
|
+
value: function toJSON() {
|
|
247
|
+
return this.toModelKey();
|
|
248
|
+
}
|
|
249
|
+
}, {
|
|
250
|
+
key: "toModelKey",
|
|
251
|
+
value: function toModelKey() {
|
|
252
|
+
return "IPY_MODEL_".concat(this.model_id);
|
|
253
|
+
}
|
|
254
|
+
}]);
|
|
255
|
+
return WidgetView;
|
|
256
|
+
}(BaseView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "libroWidgetManager", [_dec3], {
|
|
257
|
+
configurable: true,
|
|
258
|
+
enumerable: true,
|
|
259
|
+
writable: true,
|
|
260
|
+
initializer: null
|
|
261
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "state", [_dec4], {
|
|
262
|
+
configurable: true,
|
|
263
|
+
enumerable: true,
|
|
264
|
+
writable: true,
|
|
265
|
+
initializer: function initializer() {
|
|
266
|
+
return defaultWidgetState;
|
|
267
|
+
}
|
|
268
|
+
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "widgets", [_dec5], {
|
|
269
|
+
configurable: true,
|
|
270
|
+
enumerable: true,
|
|
271
|
+
writable: true,
|
|
272
|
+
initializer: null
|
|
273
|
+
})), _class2)) || _class) || _class);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@difizen/libro-jupyter",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.35",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"libro"
|
|
@@ -31,23 +31,22 @@
|
|
|
31
31
|
"src"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@difizen/libro-cofine-editor": "^0.1.
|
|
35
|
-
"@difizen/libro-code-editor": "^0.1.
|
|
36
|
-
"@difizen/libro-code-cell": "^0.1.
|
|
37
|
-
"@difizen/libro-codemirror": "^0.1.
|
|
38
|
-
"@difizen/libro-rendermime": "^0.1.
|
|
39
|
-
"@difizen/libro-common": "^0.1.
|
|
40
|
-
"@difizen/libro-core": "^0.1.
|
|
41
|
-
"@difizen/libro-kernel": "^0.1.
|
|
42
|
-
"@difizen/libro-l10n": "^0.1.
|
|
43
|
-
"@difizen/libro-output": "^0.1.
|
|
44
|
-
"@difizen/libro-search": "^0.1.
|
|
45
|
-
"@difizen/libro-search-code-cell": "^0.1.
|
|
46
|
-
"@difizen/libro-lsp": "^0.1.
|
|
47
|
-
"@difizen/libro-markdown-cell": "^0.1.
|
|
48
|
-
"@difizen/libro-raw-cell": "^0.1.
|
|
49
|
-
"@difizen/libro-language-client": "^0.1.
|
|
50
|
-
"@difizen/libro-widget": "^0.1.33",
|
|
34
|
+
"@difizen/libro-cofine-editor": "^0.1.35",
|
|
35
|
+
"@difizen/libro-code-editor": "^0.1.35",
|
|
36
|
+
"@difizen/libro-code-cell": "^0.1.35",
|
|
37
|
+
"@difizen/libro-codemirror": "^0.1.35",
|
|
38
|
+
"@difizen/libro-rendermime": "^0.1.35",
|
|
39
|
+
"@difizen/libro-common": "^0.1.35",
|
|
40
|
+
"@difizen/libro-core": "^0.1.35",
|
|
41
|
+
"@difizen/libro-kernel": "^0.1.35",
|
|
42
|
+
"@difizen/libro-l10n": "^0.1.35",
|
|
43
|
+
"@difizen/libro-output": "^0.1.35",
|
|
44
|
+
"@difizen/libro-search": "^0.1.35",
|
|
45
|
+
"@difizen/libro-search-code-cell": "^0.1.35",
|
|
46
|
+
"@difizen/libro-lsp": "^0.1.35",
|
|
47
|
+
"@difizen/libro-markdown-cell": "^0.1.35",
|
|
48
|
+
"@difizen/libro-raw-cell": "^0.1.35",
|
|
49
|
+
"@difizen/libro-language-client": "^0.1.35",
|
|
51
50
|
"@difizen/mana-app": "latest",
|
|
52
51
|
"@difizen/mana-l10n": "latest",
|
|
53
52
|
"@ant-design/colors": "^7.0.0",
|
|
@@ -39,7 +39,16 @@ const JupyterCodeCellComponent = forwardRef<HTMLDivElement>(
|
|
|
39
39
|
@transient()
|
|
40
40
|
@view('jupyter-code-cell-view')
|
|
41
41
|
export class JupyterCodeCellView extends LibroCodeCellView {
|
|
42
|
-
declare
|
|
42
|
+
protected declare _parent: LibroJupyterView;
|
|
43
|
+
|
|
44
|
+
override get parent() {
|
|
45
|
+
return this._parent;
|
|
46
|
+
}
|
|
47
|
+
override set parent(value: LibroJupyterView) {
|
|
48
|
+
this._parent = value;
|
|
49
|
+
this.parentDefer.resolve(this.parent);
|
|
50
|
+
}
|
|
51
|
+
|
|
43
52
|
override view = JupyterCodeCellComponent;
|
|
44
53
|
declare model: JupyterCodeCellModel;
|
|
45
54
|
|
package/src/index.ts
CHANGED
package/src/module.ts
CHANGED
|
@@ -25,7 +25,6 @@ import {
|
|
|
25
25
|
import { RawCellModule } from '@difizen/libro-raw-cell';
|
|
26
26
|
import { LibroSearchModule } from '@difizen/libro-search';
|
|
27
27
|
import { SearchCodeCellModule } from '@difizen/libro-search-code-cell';
|
|
28
|
-
import { WidgetModule } from '@difizen/libro-widget';
|
|
29
28
|
import { ManaModule } from '@difizen/mana-app';
|
|
30
29
|
|
|
31
30
|
import { LibroBetweenCellModule } from './add-between-cell/index.js';
|
|
@@ -57,7 +56,7 @@ import {
|
|
|
57
56
|
LibroJupyterToolbarContribution,
|
|
58
57
|
SaveFileErrorContribution,
|
|
59
58
|
} from './toolbar/index.js';
|
|
60
|
-
import {
|
|
59
|
+
import { WidgetModule } from './widget/index.js';
|
|
61
60
|
|
|
62
61
|
export const LibroJupyterModule = ManaModule.create()
|
|
63
62
|
.register(
|
|
@@ -76,7 +75,6 @@ export const LibroJupyterModule = ManaModule.create()
|
|
|
76
75
|
LibroJupyterSettingContribution,
|
|
77
76
|
JupyterServerLaunchManager,
|
|
78
77
|
LibroJupyterView,
|
|
79
|
-
LibroWidgetMimeContribution,
|
|
80
78
|
{
|
|
81
79
|
token: CellExecutionTimeProvider,
|
|
82
80
|
useValue: CellExecutionTip,
|
|
@@ -6,8 +6,10 @@ import type {
|
|
|
6
6
|
} from '@difizen/libro-core';
|
|
7
7
|
import { LibroOutputArea } from '@difizen/libro-core';
|
|
8
8
|
import {
|
|
9
|
+
isClearOutputMsg,
|
|
9
10
|
isDisplayDataMsg,
|
|
10
11
|
isErrorMsg,
|
|
12
|
+
isExecuteInputMsg,
|
|
11
13
|
isExecuteReplyMsg,
|
|
12
14
|
isExecuteResultMsg,
|
|
13
15
|
isStreamMsg,
|
|
@@ -31,58 +33,61 @@ export class LibroJupyterOutputArea extends LibroOutputArea {
|
|
|
31
33
|
cellModel.msgChangeEmitter.event((msg) => {
|
|
32
34
|
const transientMsg = (msg.content.transient || {}) as nbformat.JSONObject;
|
|
33
35
|
const displayId = transientMsg['display_id'] as string;
|
|
34
|
-
if (msg
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this.set(index, output);
|
|
56
|
-
}
|
|
36
|
+
if (isExecuteInputMsg(msg)) {
|
|
37
|
+
cellModel.executeCount = msg.content.execution_count;
|
|
38
|
+
}
|
|
39
|
+
if (
|
|
40
|
+
isDisplayDataMsg(msg) ||
|
|
41
|
+
isStreamMsg(msg) ||
|
|
42
|
+
isErrorMsg(msg) ||
|
|
43
|
+
isExecuteResultMsg(msg)
|
|
44
|
+
) {
|
|
45
|
+
const output: nbformat.IOutput = {
|
|
46
|
+
...msg.content,
|
|
47
|
+
output_type: msg.header.msg_type,
|
|
48
|
+
};
|
|
49
|
+
this.add(output);
|
|
50
|
+
}
|
|
51
|
+
if (isUpdateDisplayDataMsg(msg)) {
|
|
52
|
+
const output = { ...msg.content, output_type: 'display_data' };
|
|
53
|
+
const targets = this.displayIdMap.get(displayId);
|
|
54
|
+
if (targets) {
|
|
55
|
+
for (const index of targets) {
|
|
56
|
+
this.set(index, output);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
}
|
|
60
|
+
if (displayId && isDisplayDataMsg(msg)) {
|
|
61
|
+
const targets = this.displayIdMap.get(displayId) || [];
|
|
62
|
+
targets.push(this.outputs.length);
|
|
63
|
+
this.displayIdMap.set(displayId, targets);
|
|
64
|
+
}
|
|
65
|
+
//Handle an execute reply message.
|
|
66
|
+
if (isExecuteReplyMsg(msg)) {
|
|
67
|
+
const content = msg.content;
|
|
68
|
+
if (content.status !== 'ok') {
|
|
69
|
+
return;
|
|
63
70
|
}
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (!payload || !payload.length) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const pages = payload.filter((i: any) => i.source === 'page');
|
|
75
|
-
if (!pages.length) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
const page = JSON.parse(JSON.stringify(pages[0]));
|
|
79
|
-
const output: nbformat.IOutput = {
|
|
80
|
-
output_type: 'display_data',
|
|
81
|
-
data: page.data as nbformat.IMimeBundle,
|
|
82
|
-
metadata: {},
|
|
83
|
-
};
|
|
84
|
-
this.add(output);
|
|
71
|
+
const payload = content && content.payload;
|
|
72
|
+
if (!payload || !payload.length) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const pages = payload.filter((i: any) => i.source === 'page');
|
|
76
|
+
if (!pages.length) {
|
|
77
|
+
return;
|
|
85
78
|
}
|
|
79
|
+
const page = JSON.parse(JSON.stringify(pages[0]));
|
|
80
|
+
const output: nbformat.IOutput = {
|
|
81
|
+
output_type: 'display_data',
|
|
82
|
+
data: page.data as nbformat.IMimeBundle,
|
|
83
|
+
metadata: {},
|
|
84
|
+
};
|
|
85
|
+
this.add(output);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (isClearOutputMsg(msg)) {
|
|
89
|
+
const wait = msg.content.wait;
|
|
90
|
+
this.clear(wait);
|
|
86
91
|
}
|
|
87
92
|
});
|
|
88
93
|
}
|
|
@@ -94,6 +99,8 @@ export class LibroJupyterOutputArea extends LibroOutputArea {
|
|
|
94
99
|
|
|
95
100
|
override clear(wait?: boolean | undefined): void {
|
|
96
101
|
super.clear(wait);
|
|
97
|
-
|
|
102
|
+
if (!wait) {
|
|
103
|
+
this.displayIdMap.clear();
|
|
104
|
+
}
|
|
98
105
|
}
|
|
99
106
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ViewManager, inject, singleton } from '@difizen/mana-app';
|
|
2
|
+
|
|
3
|
+
import type { IWidgetViewProps } from '../protocol.js';
|
|
4
|
+
import { WidgetViewContribution } from '../protocol.js';
|
|
5
|
+
|
|
6
|
+
import { VBoxWidget } from './view.js';
|
|
7
|
+
|
|
8
|
+
@singleton({ contrib: WidgetViewContribution })
|
|
9
|
+
export class VBoxWidgetContribution implements WidgetViewContribution {
|
|
10
|
+
@inject(ViewManager) viewManager: ViewManager;
|
|
11
|
+
canHandle = (attributes: any) => {
|
|
12
|
+
if (attributes._model_name === 'VBoxModel') {
|
|
13
|
+
return 100;
|
|
14
|
+
}
|
|
15
|
+
if (attributes.__view_name === 'VBoxView') {
|
|
16
|
+
return 100;
|
|
17
|
+
}
|
|
18
|
+
if (attributes._model_name === 'HBoxModel') {
|
|
19
|
+
return 100;
|
|
20
|
+
}
|
|
21
|
+
if (attributes.__view_name === 'HBoxView') {
|
|
22
|
+
return 100;
|
|
23
|
+
}
|
|
24
|
+
return 1;
|
|
25
|
+
};
|
|
26
|
+
factory(props: IWidgetViewProps) {
|
|
27
|
+
return this.viewManager.getOrCreateView(VBoxWidget, props);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { CellView } from '@difizen/libro-core';
|
|
2
|
+
import { LibroContextKey } from '@difizen/libro-core';
|
|
3
|
+
import {
|
|
4
|
+
view,
|
|
5
|
+
transient,
|
|
6
|
+
useInject,
|
|
7
|
+
ViewInstance,
|
|
8
|
+
prop,
|
|
9
|
+
inject,
|
|
10
|
+
ViewOption,
|
|
11
|
+
ViewRender,
|
|
12
|
+
getOrigin,
|
|
13
|
+
} from '@difizen/mana-app';
|
|
14
|
+
import { forwardRef } from 'react';
|
|
15
|
+
|
|
16
|
+
import type { IWidgets, IWidgetViewProps, WidgetState } from '../protocol.js';
|
|
17
|
+
import { defaultWidgetState } from '../protocol.js';
|
|
18
|
+
import { WidgetView } from '../widget-view.js';
|
|
19
|
+
|
|
20
|
+
import './index.less';
|
|
21
|
+
|
|
22
|
+
const WidgetRender = (props: {
|
|
23
|
+
cell?: CellView;
|
|
24
|
+
widgets: IWidgets | undefined;
|
|
25
|
+
modelId: string;
|
|
26
|
+
}) => {
|
|
27
|
+
const { widgets, modelId, cell } = props;
|
|
28
|
+
if (!widgets) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
let widgetView;
|
|
32
|
+
try {
|
|
33
|
+
widgetView = widgets.getModel(modelId);
|
|
34
|
+
} catch (ex) {
|
|
35
|
+
//
|
|
36
|
+
}
|
|
37
|
+
if (!widgetView) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
if (cell) {
|
|
41
|
+
widgetView.setCell(getOrigin(cell));
|
|
42
|
+
}
|
|
43
|
+
if (widgetView.isCommClosed) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return (
|
|
47
|
+
<div className="libro-widget-render-container">
|
|
48
|
+
<div className="libro-widget-render">
|
|
49
|
+
<ViewRender view={widgetView} />
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const LibroWidgetBoxComponent = forwardRef<HTMLDivElement>(
|
|
56
|
+
function LibroWidgetBoxComponent(props, ref) {
|
|
57
|
+
const widget = useInject<VBoxWidget>(ViewInstance);
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<div className={`libro-widget-box ${widget.getCls()}`} ref={ref}>
|
|
61
|
+
{widget.state.children.map((modelId) => (
|
|
62
|
+
<WidgetRender
|
|
63
|
+
key={modelId}
|
|
64
|
+
cell={widget.cell}
|
|
65
|
+
widgets={widget.widgets}
|
|
66
|
+
modelId={modelId}
|
|
67
|
+
/>
|
|
68
|
+
))}
|
|
69
|
+
</div>
|
|
70
|
+
);
|
|
71
|
+
},
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
interface BoxState extends WidgetState {
|
|
75
|
+
children: string[];
|
|
76
|
+
box_style?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@transient()
|
|
80
|
+
@view('libro-widget-box-view')
|
|
81
|
+
export class VBoxWidget extends WidgetView {
|
|
82
|
+
override view = LibroWidgetBoxComponent;
|
|
83
|
+
|
|
84
|
+
@prop()
|
|
85
|
+
override state: BoxState = {
|
|
86
|
+
...defaultWidgetState,
|
|
87
|
+
children: [],
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
constructor(
|
|
91
|
+
@inject(ViewOption) props: IWidgetViewProps,
|
|
92
|
+
@inject(LibroContextKey) libroContextKey: LibroContextKey,
|
|
93
|
+
) {
|
|
94
|
+
super(props, libroContextKey);
|
|
95
|
+
this.initialize(props);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
protected initialize(props: IWidgetViewProps): void {
|
|
99
|
+
const attributes = props.attributes;
|
|
100
|
+
this.setState(attributes);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
getCls = () => {
|
|
104
|
+
if (this.model_name === 'HBoxModel') {
|
|
105
|
+
return 'libro-widget-hbox';
|
|
106
|
+
}
|
|
107
|
+
if (this.model_name === 'VBoxModel') {
|
|
108
|
+
return 'libro-widget-vbox';
|
|
109
|
+
}
|
|
110
|
+
return '';
|
|
111
|
+
};
|
|
112
|
+
}
|