@difizen/libro-jupyter 0.1.32 → 0.1.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.
- 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/components/icons.js +1 -1
- package/es/index.d.ts +1 -0
- package/es/index.d.ts.map +1 -1
- package/es/index.js +2 -1
- package/es/keybind-instructions/index.less +0 -5
- package/es/keybind-instructions/keybind-instructions-view.d.ts.map +1 -1
- package/es/keybind-instructions/keybind-instructions-view.js +67 -61
- 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/toolbar/save-file-error.d.ts.map +1 -1
- package/es/toolbar/save-file-error.js +20 -13
- 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/components/icons.tsx +1 -1
- package/src/index.ts +1 -0
- package/src/keybind-instructions/index.less +0 -5
- package/src/keybind-instructions/keybind-instructions-view.tsx +70 -60
- package/src/module.ts +1 -3
- package/src/output/libro-jupyter-outputarea.tsx +56 -49
- package/src/toolbar/save-file-error.tsx +25 -15
- 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,180 @@
|
|
|
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, _class, _class2, _descriptor, _descriptor2;
|
|
3
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
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); }
|
|
6
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
7
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
8
|
+
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; }
|
|
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 _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
22
|
+
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; }
|
|
23
|
+
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.'); }
|
|
24
|
+
import { LibroContextKey } from '@difizen/libro-core';
|
|
25
|
+
import { useInject, view, ViewInstance, ViewOption, transient, inject, prop } from '@difizen/mana-app';
|
|
26
|
+
import { forwardRef } from 'react';
|
|
27
|
+
import { WidgetView } from "../widget-view.js";
|
|
28
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
29
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
30
|
+
export var LibroInstancesProgressWidgetViewComponent = /*#__PURE__*/forwardRef(function LibroInstancesProgressWidgetViewComponent(_props, ref) {
|
|
31
|
+
var widgetView = useInject(ViewInstance);
|
|
32
|
+
if (widgetView.isCommClosed) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
36
|
+
ref: ref,
|
|
37
|
+
className: "libro-instances-progress-widget",
|
|
38
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
39
|
+
style: {
|
|
40
|
+
paddingRight: 5
|
|
41
|
+
},
|
|
42
|
+
children: widgetView.prefix
|
|
43
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
44
|
+
children: widgetView.workingProgressKeys.map(function (progressKey) {
|
|
45
|
+
var progressItem = widgetView.progressMap[progressKey];
|
|
46
|
+
return /*#__PURE__*/_jsx("a", {
|
|
47
|
+
className: "pyodps-progress-launcher",
|
|
48
|
+
style: {
|
|
49
|
+
marginRight: 5
|
|
50
|
+
},
|
|
51
|
+
children: progressItem && progressItem.name
|
|
52
|
+
}, progressKey);
|
|
53
|
+
})
|
|
54
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
55
|
+
children: widgetView.suffix
|
|
56
|
+
})]
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
export var InstancesProgressWidget = (_dec = transient(), _dec2 = view('libro-widget-instances-progress-view'), _dec3 = prop(), _dec4 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_WidgetView) {
|
|
60
|
+
_inherits(InstancesProgressWidget, _WidgetView);
|
|
61
|
+
var _super = _createSuper(InstancesProgressWidget);
|
|
62
|
+
function InstancesProgressWidget(props, libroContextKey) {
|
|
63
|
+
var _this;
|
|
64
|
+
_classCallCheck(this, InstancesProgressWidget);
|
|
65
|
+
_this = _super.call(this, props, libroContextKey);
|
|
66
|
+
_this.view = LibroInstancesProgressWidgetViewComponent;
|
|
67
|
+
_initializerDefineProperty(_this, "prefix", _descriptor, _assertThisInitialized(_this));
|
|
68
|
+
_initializerDefineProperty(_this, "suffix", _descriptor2, _assertThisInitialized(_this));
|
|
69
|
+
_this.progressMap = {};
|
|
70
|
+
_this.workingProgressKeys = [];
|
|
71
|
+
// Order of groups by time of insertion
|
|
72
|
+
_this.instanceRecords = {};
|
|
73
|
+
_this.modalVisible = false;
|
|
74
|
+
_this.modalProgressItemKey = '';
|
|
75
|
+
_this.prefix = props.attributes.prefix;
|
|
76
|
+
_this.suffix = props.attributes.suffix;
|
|
77
|
+
return _this;
|
|
78
|
+
}
|
|
79
|
+
InstancesProgressWidget = inject(LibroContextKey)(InstancesProgressWidget, undefined, 1) || InstancesProgressWidget;
|
|
80
|
+
InstancesProgressWidget = inject(ViewOption)(InstancesProgressWidget, undefined, 0) || InstancesProgressWidget;
|
|
81
|
+
_createClass(InstancesProgressWidget, [{
|
|
82
|
+
key: "updateRecords",
|
|
83
|
+
value: function updateRecords(progressKey) {
|
|
84
|
+
var _this2 = this;
|
|
85
|
+
var progressItem = this.progressMap[progressKey];
|
|
86
|
+
if (progressItem) {
|
|
87
|
+
var _progressItem$instanc = progressItem.instances,
|
|
88
|
+
instances = _progressItem$instanc === void 0 ? [] : _progressItem$instanc;
|
|
89
|
+
instances.forEach(function (instance) {
|
|
90
|
+
var id = instance.id,
|
|
91
|
+
status = instance.status;
|
|
92
|
+
if (!_this2.instanceRecords[id]) {
|
|
93
|
+
_this2.instanceRecords[id] = {
|
|
94
|
+
startDate: Date.now()
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (status === 'Terminated') {
|
|
98
|
+
if (!_this2.instanceRecords[id].endDate) {
|
|
99
|
+
_this2.instanceRecords[id].endDate = Date.now();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Handle incoming comm msg.
|
|
107
|
+
*/
|
|
108
|
+
}, {
|
|
109
|
+
key: "handleCommMsg",
|
|
110
|
+
value: function handleCommMsg(msg) {
|
|
111
|
+
var _this3 = this;
|
|
112
|
+
var data = msg.content.data;
|
|
113
|
+
var method = data.method;
|
|
114
|
+
switch (method) {
|
|
115
|
+
case 'update':
|
|
116
|
+
if (data.state.prefix) {
|
|
117
|
+
this.prefix = data.state.prefix;
|
|
118
|
+
}
|
|
119
|
+
if (data.state.suffix) {
|
|
120
|
+
this.suffix = data.state.suffix;
|
|
121
|
+
}
|
|
122
|
+
// eslint-disable-next-line no-fallthrough
|
|
123
|
+
case 'custom':
|
|
124
|
+
// eslint-disable-next-line no-case-declarations
|
|
125
|
+
var customMsg = data.content;
|
|
126
|
+
if (customMsg) {
|
|
127
|
+
// message format: '{"action": "action", content: ["content1", "content2"]}'
|
|
128
|
+
var msgObj = JSON.parse(customMsg);
|
|
129
|
+
var action = msgObj.action;
|
|
130
|
+
var content = [];
|
|
131
|
+
if (msgObj.content) {
|
|
132
|
+
content.push.apply(content, _toConsumableArray(msgObj.content));
|
|
133
|
+
}
|
|
134
|
+
switch (action) {
|
|
135
|
+
case 'update':
|
|
136
|
+
content.forEach(function (groupJson) {
|
|
137
|
+
var parsedProgressItem = JSON.parse(groupJson);
|
|
138
|
+
if (!_this3.progressMap[parsedProgressItem.key]) {
|
|
139
|
+
_this3.workingProgressKeys.push(parsedProgressItem.key);
|
|
140
|
+
}
|
|
141
|
+
_this3.progressMap[parsedProgressItem.key] = parsedProgressItem;
|
|
142
|
+
_this3.updateRecords(parsedProgressItem.key);
|
|
143
|
+
});
|
|
144
|
+
// ? TODO: 发出一个更新 modal signal 的信号,这里需要取到之前的 key
|
|
145
|
+
break;
|
|
146
|
+
case 'delete':
|
|
147
|
+
content.forEach(function (groupKey) {
|
|
148
|
+
if (!_this3.progressMap[groupKey]) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
var i = _this3.workingProgressKeys.indexOf(groupKey);
|
|
152
|
+
if (i >= 0) {
|
|
153
|
+
_this3.workingProgressKeys.splice(i, 1);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
break;
|
|
157
|
+
case 'clear':
|
|
158
|
+
this.progressMap = {};
|
|
159
|
+
this.workingProgressKeys = [];
|
|
160
|
+
// ? TODO: 发出更新 overview 以及 modal 的 signal
|
|
161
|
+
break;
|
|
162
|
+
default:
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return Promise.resolve();
|
|
167
|
+
}
|
|
168
|
+
}]);
|
|
169
|
+
return InstancesProgressWidget;
|
|
170
|
+
}(WidgetView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "prefix", [_dec3], {
|
|
171
|
+
configurable: true,
|
|
172
|
+
enumerable: true,
|
|
173
|
+
writable: true,
|
|
174
|
+
initializer: null
|
|
175
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "suffix", [_dec4], {
|
|
176
|
+
configurable: true,
|
|
177
|
+
enumerable: true,
|
|
178
|
+
writable: true,
|
|
179
|
+
initializer: null
|
|
180
|
+
})), _class2)) || _class) || _class);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { JSONObject } from '@difizen/libro-common';
|
|
2
|
+
import type { IKernelConnection, KernelMessage } from '@difizen/libro-kernel';
|
|
3
|
+
import type { Contribution } from '@difizen/mana-app';
|
|
4
|
+
import { Emitter } from '@difizen/mana-app';
|
|
5
|
+
import type { Comm } from './comm.js';
|
|
6
|
+
import type { IWidgets, IWidgetViewOptions, IClassicComm, WidgetCommOption } from './protocol.js';
|
|
7
|
+
import { WidgetsOption, WidgetViewContribution } from './protocol.js';
|
|
8
|
+
import type { WidgetView } from './widget-view.js';
|
|
9
|
+
export declare class LibroWidgets implements IWidgets {
|
|
10
|
+
WidgetViewProvider: Contribution.Provider<WidgetViewContribution>;
|
|
11
|
+
widgetEmitter: Emitter<{
|
|
12
|
+
WidgetViewName: string;
|
|
13
|
+
}>;
|
|
14
|
+
widgetCommFactory: (options: WidgetCommOption) => Comm;
|
|
15
|
+
kernelConnection: IKernelConnection;
|
|
16
|
+
constructor(options: WidgetsOption, widgetCommFactory: (options: WidgetCommOption) => Comm);
|
|
17
|
+
get onWidgetRender(): import("@difizen/mana-app").Event<{
|
|
18
|
+
WidgetViewName: string;
|
|
19
|
+
}>;
|
|
20
|
+
protected findProvider(attributes: any): WidgetViewContribution;
|
|
21
|
+
/**
|
|
22
|
+
* Create a comm which can be used for communication for a widget.
|
|
23
|
+
*
|
|
24
|
+
* If the data/metadata is passed in, open the comm before returning (i.e.,
|
|
25
|
+
* send the comm_open message). If the data and metadata is undefined, we
|
|
26
|
+
* want to reconstruct a comm that already exists in the kernel, so do not
|
|
27
|
+
* open the comm by sending the comm_open message.
|
|
28
|
+
*
|
|
29
|
+
* @param comm_target_name Comm target name
|
|
30
|
+
* @param model_id The comm id
|
|
31
|
+
* @param data The initial data for the comm
|
|
32
|
+
* @param metadata The metadata in the open message
|
|
33
|
+
*/
|
|
34
|
+
createComm(comm_target_name: string, model_id?: string, data?: JSONObject, metadata?: JSONObject, buffers?: ArrayBuffer[] | ArrayBufferView[]): Promise<IClassicComm>;
|
|
35
|
+
/**
|
|
36
|
+
* Get a model by model id.
|
|
37
|
+
*
|
|
38
|
+
* #### Notes
|
|
39
|
+
* If the model is not found, throw error.
|
|
40
|
+
*
|
|
41
|
+
* If you would like to synchronously test if a model exists, use .hasModel().
|
|
42
|
+
*/
|
|
43
|
+
getModel(model_id: string): WidgetView;
|
|
44
|
+
/**
|
|
45
|
+
* Returns true if the given model is registered, otherwise false.
|
|
46
|
+
*
|
|
47
|
+
* #### Notes
|
|
48
|
+
* This is a synchronous way to check if a model is registered.
|
|
49
|
+
*/
|
|
50
|
+
hasModel(model_id: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Handle when a comm is opened.
|
|
53
|
+
*/
|
|
54
|
+
handleCommOpen(comm: IClassicComm, msg: KernelMessage.ICommOpenMsg): Promise<WidgetView>;
|
|
55
|
+
registerWidgetView(model_id: string, model: Promise<WidgetView>): void;
|
|
56
|
+
handleCommClose(msg: KernelMessage.ICommCloseMsg): void;
|
|
57
|
+
unregisterWidgetView(model_id: string): void;
|
|
58
|
+
newWidgetView(attributes: any, options: IWidgetViewOptions): Promise<WidgetView>;
|
|
59
|
+
/**
|
|
60
|
+
* Close all widgets and empty the widget state.
|
|
61
|
+
* @return Promise that resolves when the widget state is cleared.
|
|
62
|
+
*/
|
|
63
|
+
clearState(): void;
|
|
64
|
+
/**
|
|
65
|
+
* Disconnect the widget manager from the kernel, setting each model's comm
|
|
66
|
+
* as dead.
|
|
67
|
+
*/
|
|
68
|
+
disconnect(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Dictionary of model ids and model instance promises
|
|
71
|
+
*/
|
|
72
|
+
protected models: Map<string, WidgetView>;
|
|
73
|
+
/**
|
|
74
|
+
* The comm target name to register
|
|
75
|
+
*/
|
|
76
|
+
id: string;
|
|
77
|
+
readonly commTargetName = "jupyter.widget";
|
|
78
|
+
/**
|
|
79
|
+
* Serialize the model. See the deserialization function at the top of this file
|
|
80
|
+
* and the kernel-side serializer/deserializer.
|
|
81
|
+
*/
|
|
82
|
+
toJSON(): string;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=libro-widgets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libro-widgets.d.ts","sourceRoot":"","sources":["../../src/widget/libro-widgets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAEV,QAAQ,EACR,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAEL,aAAa,EACb,sBAAsB,EACvB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD,qBACa,YAAa,YAAW,QAAQ;IAE3C,kBAAkB,EAAE,YAAY,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC;IAClE,aAAa,EAAE,OAAO,CAAC;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE,CAAC,CAAiB;IACnE,iBAAiB,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACvD,gBAAgB,EAAE,iBAAiB,CAAC;gBAGX,OAAO,EAAE,aAAa,EAE7C,iBAAiB,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,IAAI;IAUxD,IAAI,cAAc;;OAEjB;IAED,SAAS,CAAC,YAAY,CAAC,UAAU,EAAE,GAAG,GAAG,sBAAsB;IAS/D;;;;;;;;;;;;OAYG;IACG,UAAU,CACd,gBAAgB,EAAE,MAAM,EACxB,QAAQ,CAAC,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,UAAU,EACjB,QAAQ,CAAC,EAAE,UAAU,EACrB,OAAO,CAAC,EAAE,WAAW,EAAE,GAAG,eAAe,EAAE,GAC1C,OAAO,CAAC,YAAY,CAAC;IAYxB;;;;;;;OAOG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU;IAQtC;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAInC;;OAEG;IACG,cAAc,CAClB,IAAI,EAAE,YAAY,EAClB,GAAG,EAAE,aAAa,CAAC,YAAY,GAC9B,OAAO,CAAC,UAAU,CAAC;IAkBtB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI;IAatE,eAAe,CAAC,GAAG,EAAE,aAAa,CAAC,aAAa;IAMhD,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAMtC,aAAa,CACjB,UAAU,EAAE,GAAG,EACf,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,UAAU,CAAC;IAkBtB;;;OAGG;IACH,UAAU;IAGV;;;OAGG;IACH,UAAU,IAAI,IAAI;IAGlB;;OAEG;IAEH,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAa;IAEtD;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,cAAc,oBAAoB;IAE3C;;;OAGG;IACH,MAAM,IAAI,MAAM;CAMjB"}
|
|
@@ -0,0 +1,307 @@
|
|
|
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, _descriptor2;
|
|
3
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
4
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
5
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
6
|
+
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
|
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
11
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
12
|
+
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
|
|
13
|
+
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
|
|
14
|
+
import { contrib, inject, Priority, prop, transient } from '@difizen/mana-app';
|
|
15
|
+
import { Emitter } from '@difizen/mana-app';
|
|
16
|
+
import { LibroWidgetCommFactory, WidgetsOption, WidgetViewContribution } from "./protocol.js";
|
|
17
|
+
import { put_buffers, reject } from "./utils.js";
|
|
18
|
+
import { PROTOCOL_VERSION } from "./version.js";
|
|
19
|
+
var PROTOCOL_MAJOR_VERSION = PROTOCOL_VERSION.split('.', 1)[0];
|
|
20
|
+
export var LibroWidgets = (_dec = transient(), _dec2 = contrib(WidgetViewContribution), _dec3 = prop(), _dec(_class = (_class2 = /*#__PURE__*/function () {
|
|
21
|
+
function LibroWidgets(options, widgetCommFactory) {
|
|
22
|
+
var _this = this;
|
|
23
|
+
_classCallCheck(this, LibroWidgets);
|
|
24
|
+
_initializerDefineProperty(this, "WidgetViewProvider", _descriptor, this);
|
|
25
|
+
this.widgetEmitter = new Emitter();
|
|
26
|
+
this.widgetCommFactory = void 0;
|
|
27
|
+
this.kernelConnection = void 0;
|
|
28
|
+
/**
|
|
29
|
+
* Dictionary of model ids and model instance promises
|
|
30
|
+
*/
|
|
31
|
+
_initializerDefineProperty(this, "models", _descriptor2, this);
|
|
32
|
+
/**
|
|
33
|
+
* The comm target name to register
|
|
34
|
+
*/
|
|
35
|
+
this.id = void 0;
|
|
36
|
+
this.commTargetName = 'jupyter.widget';
|
|
37
|
+
this.kernelConnection = options.kc;
|
|
38
|
+
this.id = options.id;
|
|
39
|
+
this.widgetCommFactory = widgetCommFactory;
|
|
40
|
+
this.kernelConnection.registerCommTarget(this.commTargetName, /*#__PURE__*/function () {
|
|
41
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(comm, msg) {
|
|
42
|
+
var widgetComm;
|
|
43
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
44
|
+
while (1) switch (_context.prev = _context.next) {
|
|
45
|
+
case 0:
|
|
46
|
+
widgetComm = _this.widgetCommFactory({
|
|
47
|
+
comm: comm
|
|
48
|
+
});
|
|
49
|
+
_context.next = 3;
|
|
50
|
+
return _this.handleCommOpen(widgetComm, msg);
|
|
51
|
+
case 3:
|
|
52
|
+
case "end":
|
|
53
|
+
return _context.stop();
|
|
54
|
+
}
|
|
55
|
+
}, _callee);
|
|
56
|
+
}));
|
|
57
|
+
return function (_x, _x2) {
|
|
58
|
+
return _ref.apply(this, arguments);
|
|
59
|
+
};
|
|
60
|
+
}());
|
|
61
|
+
}
|
|
62
|
+
LibroWidgets = inject(LibroWidgetCommFactory)(LibroWidgets, undefined, 1) || LibroWidgets;
|
|
63
|
+
LibroWidgets = inject(WidgetsOption)(LibroWidgets, undefined, 0) || LibroWidgets;
|
|
64
|
+
_createClass(LibroWidgets, [{
|
|
65
|
+
key: "onWidgetRender",
|
|
66
|
+
get: function get() {
|
|
67
|
+
return this.widgetEmitter.event;
|
|
68
|
+
}
|
|
69
|
+
}, {
|
|
70
|
+
key: "findProvider",
|
|
71
|
+
value: function findProvider(attributes) {
|
|
72
|
+
var prioritized = Priority.sortSync(this.WidgetViewProvider.getContributions(), function (contribution) {
|
|
73
|
+
return contribution.canHandle(attributes);
|
|
74
|
+
});
|
|
75
|
+
var sorted = prioritized.map(function (c) {
|
|
76
|
+
return c.value;
|
|
77
|
+
});
|
|
78
|
+
return sorted[0];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Create a comm which can be used for communication for a widget.
|
|
83
|
+
*
|
|
84
|
+
* If the data/metadata is passed in, open the comm before returning (i.e.,
|
|
85
|
+
* send the comm_open message). If the data and metadata is undefined, we
|
|
86
|
+
* want to reconstruct a comm that already exists in the kernel, so do not
|
|
87
|
+
* open the comm by sending the comm_open message.
|
|
88
|
+
*
|
|
89
|
+
* @param comm_target_name Comm target name
|
|
90
|
+
* @param model_id The comm id
|
|
91
|
+
* @param data The initial data for the comm
|
|
92
|
+
* @param metadata The metadata in the open message
|
|
93
|
+
*/
|
|
94
|
+
}, {
|
|
95
|
+
key: "createComm",
|
|
96
|
+
value: (function () {
|
|
97
|
+
var _createComm = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(comm_target_name, model_id, data, metadata, buffers) {
|
|
98
|
+
var kernel, comm;
|
|
99
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
100
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
101
|
+
case 0:
|
|
102
|
+
kernel = this.kernelConnection;
|
|
103
|
+
if (kernel) {
|
|
104
|
+
_context2.next = 3;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
throw new Error('No current kernel');
|
|
108
|
+
case 3:
|
|
109
|
+
comm = kernel.createComm(comm_target_name, model_id);
|
|
110
|
+
if (data || metadata) {
|
|
111
|
+
comm.open(data, metadata, buffers);
|
|
112
|
+
}
|
|
113
|
+
return _context2.abrupt("return", this.widgetCommFactory({
|
|
114
|
+
comm: comm
|
|
115
|
+
}));
|
|
116
|
+
case 6:
|
|
117
|
+
case "end":
|
|
118
|
+
return _context2.stop();
|
|
119
|
+
}
|
|
120
|
+
}, _callee2, this);
|
|
121
|
+
}));
|
|
122
|
+
function createComm(_x3, _x4, _x5, _x6, _x7) {
|
|
123
|
+
return _createComm.apply(this, arguments);
|
|
124
|
+
}
|
|
125
|
+
return createComm;
|
|
126
|
+
}()
|
|
127
|
+
/**
|
|
128
|
+
* Get a model by model id.
|
|
129
|
+
*
|
|
130
|
+
* #### Notes
|
|
131
|
+
* If the model is not found, throw error.
|
|
132
|
+
*
|
|
133
|
+
* If you would like to synchronously test if a model exists, use .hasModel().
|
|
134
|
+
*/
|
|
135
|
+
)
|
|
136
|
+
}, {
|
|
137
|
+
key: "getModel",
|
|
138
|
+
value: function getModel(model_id) {
|
|
139
|
+
var model = this.models.get(model_id);
|
|
140
|
+
if (model === undefined) {
|
|
141
|
+
throw new Error('widget model not found');
|
|
142
|
+
}
|
|
143
|
+
return model;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Returns true if the given model is registered, otherwise false.
|
|
148
|
+
*
|
|
149
|
+
* #### Notes
|
|
150
|
+
* This is a synchronous way to check if a model is registered.
|
|
151
|
+
*/
|
|
152
|
+
}, {
|
|
153
|
+
key: "hasModel",
|
|
154
|
+
value: function hasModel(model_id) {
|
|
155
|
+
return this.models.get(model_id) !== undefined;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Handle when a comm is opened.
|
|
160
|
+
*/
|
|
161
|
+
}, {
|
|
162
|
+
key: "handleCommOpen",
|
|
163
|
+
value: (function () {
|
|
164
|
+
var _handleCommOpen = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(comm, msg) {
|
|
165
|
+
var protocolVersion, error, data, buffer_paths, buffers;
|
|
166
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
167
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
168
|
+
case 0:
|
|
169
|
+
protocolVersion = (msg.metadata || {})['version'] || '';
|
|
170
|
+
if (!(protocolVersion.split('.', 1)[0] !== PROTOCOL_MAJOR_VERSION)) {
|
|
171
|
+
_context3.next = 5;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
error = "Wrong widget protocol version: received protocol version '".concat(protocolVersion, "', but was expecting major version '").concat(PROTOCOL_MAJOR_VERSION, "'");
|
|
175
|
+
console.error(error);
|
|
176
|
+
return _context3.abrupt("return", Promise.reject(error));
|
|
177
|
+
case 5:
|
|
178
|
+
data = msg.content.data;
|
|
179
|
+
buffer_paths = data.buffer_paths || [];
|
|
180
|
+
buffers = msg.buffers || [];
|
|
181
|
+
put_buffers(data.state, buffer_paths, buffers);
|
|
182
|
+
// this.createComm(msg.content.target_name, msg.content.comm_id, msg.content.data, msg.metadata);
|
|
183
|
+
return _context3.abrupt("return", this.newWidgetView(data.state, {
|
|
184
|
+
model_id: msg.content.comm_id,
|
|
185
|
+
comm: comm
|
|
186
|
+
}).catch(reject('Could not create a model.', true)));
|
|
187
|
+
case 10:
|
|
188
|
+
case "end":
|
|
189
|
+
return _context3.stop();
|
|
190
|
+
}
|
|
191
|
+
}, _callee3, this);
|
|
192
|
+
}));
|
|
193
|
+
function handleCommOpen(_x8, _x9) {
|
|
194
|
+
return _handleCommOpen.apply(this, arguments);
|
|
195
|
+
}
|
|
196
|
+
return handleCommOpen;
|
|
197
|
+
}())
|
|
198
|
+
}, {
|
|
199
|
+
key: "registerWidgetView",
|
|
200
|
+
value: function registerWidgetView(model_id, model) {
|
|
201
|
+
var _this2 = this;
|
|
202
|
+
model.then(function (model) {
|
|
203
|
+
_this2.models.set(model_id, model);
|
|
204
|
+
_this2.models.set(model.toModelKey(), model);
|
|
205
|
+
_this2.widgetEmitter.fire({
|
|
206
|
+
WidgetViewName: model.model_name
|
|
207
|
+
});
|
|
208
|
+
return;
|
|
209
|
+
}).catch(function () {
|
|
210
|
+
//
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}, {
|
|
214
|
+
key: "handleCommClose",
|
|
215
|
+
value: function handleCommClose(msg) {
|
|
216
|
+
var comm_id = msg.content.comm_id;
|
|
217
|
+
var model = this.getModel(comm_id);
|
|
218
|
+
model.isCommClosed = true;
|
|
219
|
+
}
|
|
220
|
+
}, {
|
|
221
|
+
key: "unregisterWidgetView",
|
|
222
|
+
value: function unregisterWidgetView(model_id) {
|
|
223
|
+
var model = this.models.get(model_id);
|
|
224
|
+
model === null || model === void 0 || model.dispose();
|
|
225
|
+
this.models.delete(model_id);
|
|
226
|
+
}
|
|
227
|
+
}, {
|
|
228
|
+
key: "newWidgetView",
|
|
229
|
+
value: function () {
|
|
230
|
+
var _newWidgetView = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(attributes, options) {
|
|
231
|
+
var model_id, provider, WidgetView;
|
|
232
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
233
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
234
|
+
case 0:
|
|
235
|
+
model_id = options.model_id;
|
|
236
|
+
if (model_id) {
|
|
237
|
+
_context4.next = 3;
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
throw new Error('Neither comm nor model_id provided in options object. At least one must exist.');
|
|
241
|
+
case 3:
|
|
242
|
+
options.model_id = model_id;
|
|
243
|
+
provider = this.findProvider(attributes);
|
|
244
|
+
WidgetView = provider.factory({
|
|
245
|
+
attributes: attributes,
|
|
246
|
+
options: options,
|
|
247
|
+
widgetsId: this.id
|
|
248
|
+
});
|
|
249
|
+
this.registerWidgetView(model_id, WidgetView);
|
|
250
|
+
return _context4.abrupt("return", WidgetView);
|
|
251
|
+
case 8:
|
|
252
|
+
case "end":
|
|
253
|
+
return _context4.stop();
|
|
254
|
+
}
|
|
255
|
+
}, _callee4, this);
|
|
256
|
+
}));
|
|
257
|
+
function newWidgetView(_x10, _x11) {
|
|
258
|
+
return _newWidgetView.apply(this, arguments);
|
|
259
|
+
}
|
|
260
|
+
return newWidgetView;
|
|
261
|
+
}()
|
|
262
|
+
/**
|
|
263
|
+
* Close all widgets and empty the widget state.
|
|
264
|
+
* @return Promise that resolves when the widget state is cleared.
|
|
265
|
+
*/
|
|
266
|
+
}, {
|
|
267
|
+
key: "clearState",
|
|
268
|
+
value: function clearState() {
|
|
269
|
+
this.models.clear();
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Disconnect the widget manager from the kernel, setting each model's comm
|
|
273
|
+
* as dead.
|
|
274
|
+
*/
|
|
275
|
+
}, {
|
|
276
|
+
key: "disconnect",
|
|
277
|
+
value: function disconnect() {
|
|
278
|
+
// this.models.forEach(model => model.clear());
|
|
279
|
+
}
|
|
280
|
+
}, {
|
|
281
|
+
key: "toJSON",
|
|
282
|
+
value:
|
|
283
|
+
/**
|
|
284
|
+
* Serialize the model. See the deserialization function at the top of this file
|
|
285
|
+
* and the kernel-side serializer/deserializer.
|
|
286
|
+
*/
|
|
287
|
+
function toJSON() {
|
|
288
|
+
return JSON.stringify({
|
|
289
|
+
kc_id: this.kernelConnection.id,
|
|
290
|
+
id: this.id
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}]);
|
|
294
|
+
return LibroWidgets;
|
|
295
|
+
}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "WidgetViewProvider", [_dec2], {
|
|
296
|
+
configurable: true,
|
|
297
|
+
enumerable: true,
|
|
298
|
+
writable: true,
|
|
299
|
+
initializer: null
|
|
300
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "models", [_dec3], {
|
|
301
|
+
configurable: true,
|
|
302
|
+
enumerable: true,
|
|
303
|
+
writable: true,
|
|
304
|
+
initializer: function initializer() {
|
|
305
|
+
return new Map();
|
|
306
|
+
}
|
|
307
|
+
})), _class2)) || _class);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/widget/module.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAsB/C,eAAO,MAAM,gBAAgB,YAoCO,CAAC;AAErC,eAAO,MAAM,YAAY,YAWI,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { LibroKernelManageModule } from '@difizen/libro-kernel';
|
|
2
|
+
import { ManaModule } from '@difizen/mana-app';
|
|
3
|
+
import { VBoxWidget, VBoxWidgetContribution } from "./box/index.js";
|
|
4
|
+
import { Comm } from "./comm.js";
|
|
5
|
+
import { InstancesProgressWidget, InstancesProgressWidgetViewContribution } from "./instance-progress/index.js";
|
|
6
|
+
import { LibroWidgets } from "./libro-widgets.js";
|
|
7
|
+
import { ProgressWidget, ProgressWidgetViewContribution } from "./progress/index.js";
|
|
8
|
+
import { LibroWidgetCommFactory, LibroWidgetsFactory, WidgetCommOption, WidgetsOption, WidgetViewContribution } from "./protocol.js";
|
|
9
|
+
import { LibroWidgetManager } from "./widget-manager.js";
|
|
10
|
+
import { LibroWidgetMimeContribution } from "./widget-rendermime-contribution.js";
|
|
11
|
+
import { DefaultWidgetViewContribution } from "./widget-view-contribution.js";
|
|
12
|
+
import { WidgetView } from "./widget-view.js";
|
|
13
|
+
export var BaseWidgetModule = ManaModule.create().contribution(WidgetViewContribution).register(Comm, {
|
|
14
|
+
token: LibroWidgetCommFactory,
|
|
15
|
+
useFactory: function useFactory(ctx) {
|
|
16
|
+
return function (options) {
|
|
17
|
+
var child = ctx.container.createChild();
|
|
18
|
+
child.register({
|
|
19
|
+
token: WidgetCommOption,
|
|
20
|
+
useValue: options
|
|
21
|
+
});
|
|
22
|
+
return child.get(Comm);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}, LibroWidgets, {
|
|
26
|
+
token: LibroWidgetsFactory,
|
|
27
|
+
useFactory: function useFactory(ctx) {
|
|
28
|
+
return function (options) {
|
|
29
|
+
var child = ctx.container.createChild();
|
|
30
|
+
child.register({
|
|
31
|
+
token: WidgetsOption,
|
|
32
|
+
useValue: options
|
|
33
|
+
});
|
|
34
|
+
return child.get(LibroWidgets);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}, LibroWidgetManager, WidgetView, DefaultWidgetViewContribution, LibroWidgetMimeContribution).dependOn(LibroKernelManageModule);
|
|
38
|
+
export var WidgetModule = ManaModule.create().register(VBoxWidget, VBoxWidgetContribution, ProgressWidget, ProgressWidgetViewContribution, InstancesProgressWidget, InstancesProgressWidgetViewContribution).dependOn(BaseWidgetModule);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ViewManager } from '@difizen/mana-app';
|
|
2
|
+
import type { IWidgetViewProps } from '../protocol.js';
|
|
3
|
+
import { WidgetViewContribution } from '../protocol.js';
|
|
4
|
+
import { ProgressWidget } from './view.js';
|
|
5
|
+
export declare class ProgressWidgetViewContribution implements WidgetViewContribution {
|
|
6
|
+
viewManager: ViewManager;
|
|
7
|
+
canHandle: (attributes: any) => 1 | 100;
|
|
8
|
+
factory(props: IWidgetViewProps): Promise<ProgressWidget>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=contribution.d.ts.map
|