@difizen/libro-widget 0.0.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/es/base/comm.d.ts +65 -0
- package/es/base/comm.d.ts.map +1 -0
- package/es/base/comm.js +151 -0
- package/es/base/index.d.ts +7 -0
- package/es/base/index.d.ts.map +1 -0
- package/es/base/index.js +6 -0
- package/es/base/libro-widgets.d.ts +79 -0
- package/es/base/libro-widgets.d.ts.map +1 -0
- package/es/base/libro-widgets.js +285 -0
- package/es/base/protocal.d.ts +171 -0
- package/es/base/protocal.d.ts.map +1 -0
- package/es/base/protocal.js +21 -0
- package/es/base/utils.d.ts +27 -0
- package/es/base/utils.d.ts.map +1 -0
- package/es/base/utils.js +59 -0
- package/es/base/version.d.ts +3 -0
- package/es/base/version.d.ts.map +1 -0
- package/es/base/version.js +2 -0
- package/es/base/widget-manager.d.ts +18 -0
- package/es/base/widget-manager.d.ts.map +1 -0
- package/es/base/widget-manager.js +68 -0
- package/es/base/widget-view-contribution.d.ts +10 -0
- package/es/base/widget-view-contribution.d.ts.map +1 -0
- package/es/base/widget-view-contribution.js +36 -0
- package/es/base/widget-view.d.ts +52 -0
- package/es/base/widget-view.d.ts.map +1 -0
- package/es/base/widget-view.js +137 -0
- package/es/components/index.d.ts +3 -0
- package/es/components/index.d.ts.map +1 -0
- package/es/components/index.js +2 -0
- package/es/components/progressBar.d.ts +15 -0
- package/es/components/progressBar.d.ts.map +1 -0
- package/es/components/progressBar.js +20 -0
- package/es/components/progressCircle.d.ts +11 -0
- package/es/components/progressCircle.d.ts.map +1 -0
- package/es/components/progressCircle.js +16 -0
- package/es/index.d.ts +5 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +4 -0
- package/es/widget-module.d.ts +3 -0
- package/es/widget-module.d.ts.map +1 -0
- package/es/widget-module.js +39 -0
- package/es/widgets/hbox-widget-view-contribution.d.ts +10 -0
- package/es/widgets/hbox-widget-view-contribution.d.ts.map +1 -0
- package/es/widgets/hbox-widget-view-contribution.js +39 -0
- package/es/widgets/hbox-widget-view.d.ts +17 -0
- package/es/widgets/hbox-widget-view.d.ts.map +1 -0
- package/es/widgets/hbox-widget-view.js +69 -0
- package/es/widgets/index.d.ts +9 -0
- package/es/widgets/index.d.ts.map +1 -0
- package/es/widgets/index.js +8 -0
- package/es/widgets/index.less +3 -0
- package/es/widgets/instances-progress-widget-view-contribution.d.ts +10 -0
- package/es/widgets/instances-progress-widget-view-contribution.d.ts.map +1 -0
- package/es/widgets/instances-progress-widget-view-contribution.js +39 -0
- package/es/widgets/instances-progress-widget-view.d.ts +31 -0
- package/es/widgets/instances-progress-widget-view.d.ts.map +1 -0
- package/es/widgets/instances-progress-widget-view.js +181 -0
- package/es/widgets/progress-widget-view-contribution.d.ts +10 -0
- package/es/widgets/progress-widget-view-contribution.d.ts.map +1 -0
- package/es/widgets/progress-widget-view-contribution.js +39 -0
- package/es/widgets/progress-widget-view.d.ts +25 -0
- package/es/widgets/progress-widget-view.d.ts.map +1 -0
- package/es/widgets/progress-widget-view.js +103 -0
- package/es/widgets/text-widget-view-contribution.d.ts +10 -0
- package/es/widgets/text-widget-view-contribution.d.ts.map +1 -0
- package/es/widgets/text-widget-view-contribution.js +39 -0
- package/es/widgets/text-widget-view.d.ts +19 -0
- package/es/widgets/text-widget-view.d.ts.map +1 -0
- package/es/widgets/text-widget-view.js +91 -0
- package/package.json +60 -0
- package/src/base/comm.ts +152 -0
- package/src/base/index.ts +6 -0
- package/src/base/libro-widgets.ts +207 -0
- package/src/base/protocal.ts +218 -0
- package/src/base/utils.ts +67 -0
- package/src/base/version.ts +2 -0
- package/src/base/widget-manager.ts +41 -0
- package/src/base/widget-view-contribution.ts +14 -0
- package/src/base/widget-view.tsx +146 -0
- package/src/components/index.ts +3 -0
- package/src/components/progressBar.tsx +29 -0
- package/src/components/progressCircle.tsx +18 -0
- package/src/index.ts +4 -0
- package/src/widget-module.ts +68 -0
- package/src/widgets/hbox-widget-view-contribution.ts +20 -0
- package/src/widgets/hbox-widget-view.tsx +64 -0
- package/src/widgets/index.less +3 -0
- package/src/widgets/index.ts +8 -0
- package/src/widgets/instances-progress-widget-view-contribution.ts +20 -0
- package/src/widgets/instances-progress-widget-view.tsx +160 -0
- package/src/widgets/progress-widget-view-contribution.ts +24 -0
- package/src/widgets/progress-widget-view.tsx +85 -0
- package/src/widgets/text-widget-view-contribution.ts +20 -0
- package/src/widgets/text-widget-view.tsx +83 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ViewManager } from '@difizen/mana-app';
|
|
2
|
+
import type { IWidgetViewProps } from '../base/protocal.js';
|
|
3
|
+
import { WidgetViewContribution } from '../base/protocal.js';
|
|
4
|
+
import { ProgressWidget } from './progress-widget-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=progress-widget-view-contribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress-widget-view-contribution.d.ts","sourceRoot":"","sources":["../../src/widgets/progress-widget-view-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAqB,MAAM,mBAAmB,CAAC;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,qBACa,8BAA+B,YAAW,sBAAsB;IACtD,WAAW,EAAE,WAAW,CAAC;IAC9C,SAAS,eAAgB,GAAG,aAS1B;IACF,OAAO,CAAC,KAAK,EAAE,gBAAgB;CAGhC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
var _dec, _dec2, _class, _class2, _descriptor;
|
|
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(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
8
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
9
|
+
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; }
|
|
10
|
+
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.'); }
|
|
11
|
+
import { ViewManager, inject, singleton } from '@difizen/mana-app';
|
|
12
|
+
import { WidgetViewContribution } from "../base/protocal.js";
|
|
13
|
+
import { ProgressWidget } from "./progress-widget-view.js";
|
|
14
|
+
export var ProgressWidgetViewContribution = (_dec = singleton({
|
|
15
|
+
contrib: WidgetViewContribution
|
|
16
|
+
}), _dec2 = inject(ViewManager), _dec(_class = (_class2 = /*#__PURE__*/function () {
|
|
17
|
+
function ProgressWidgetViewContribution() {
|
|
18
|
+
_classCallCheck(this, ProgressWidgetViewContribution);
|
|
19
|
+
_initializerDefineProperty(this, "viewManager", _descriptor, this);
|
|
20
|
+
this.canHandle = function (attributes) {
|
|
21
|
+
if (attributes._model_name === 'FloatProgressModel' || attributes._model_name === 'IntProgressModel' || attributes._model_name === 'TransientProgressModel') {
|
|
22
|
+
return 100;
|
|
23
|
+
}
|
|
24
|
+
return 1;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
_createClass(ProgressWidgetViewContribution, [{
|
|
28
|
+
key: "factory",
|
|
29
|
+
value: function factory(props) {
|
|
30
|
+
return this.viewManager.getOrCreateView(ProgressWidget, props);
|
|
31
|
+
}
|
|
32
|
+
}]);
|
|
33
|
+
return ProgressWidgetViewContribution;
|
|
34
|
+
}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "viewManager", [_dec2], {
|
|
35
|
+
configurable: true,
|
|
36
|
+
enumerable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
initializer: null
|
|
39
|
+
})), _class2)) || _class);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="react" resolution-mode="require"/>
|
|
2
|
+
import { LirboContextKey } from '@difizen/libro-core';
|
|
3
|
+
import type { KernelMessage } from '@difizen/libro-kernel';
|
|
4
|
+
import type { IWidgetViewProps } from '../base/protocal.js';
|
|
5
|
+
import { WidgetView } from '../base/widget-view.js';
|
|
6
|
+
import './index.less';
|
|
7
|
+
export declare const LibroProgressWidgetComponent: import("react").ForwardRefExoticComponent<import("react").RefAttributes<HTMLDivElement>>;
|
|
8
|
+
export declare class ProgressWidget extends WidgetView {
|
|
9
|
+
view: import("react").ForwardRefExoticComponent<import("react").RefAttributes<HTMLDivElement>>;
|
|
10
|
+
bar_style: string;
|
|
11
|
+
description: string;
|
|
12
|
+
description_tooltip: null;
|
|
13
|
+
layout: string;
|
|
14
|
+
max: number;
|
|
15
|
+
min: number;
|
|
16
|
+
orientation: string;
|
|
17
|
+
style: string;
|
|
18
|
+
value: number;
|
|
19
|
+
constructor(props: IWidgetViewProps, lirboContextKey: LirboContextKey);
|
|
20
|
+
/**
|
|
21
|
+
* Handle incoming comm msg.
|
|
22
|
+
*/
|
|
23
|
+
handleCommMsg(msg: KernelMessage.ICommMsgMsg): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=progress-widget-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress-widget-view.d.ts","sourceRoot":"","sources":["../../src/widgets/progress-widget-view.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAY3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,cAAc,CAAC;AAEtB,eAAO,MAAM,4BAA4B,0FAgBxC,CAAC;AACF,qBAEa,cAAe,SAAQ,UAAU;IACnC,IAAI,2FAAgC;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,IAAI,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IAEf,GAAG,EAAE,MAAM,CAAC;IAEZ,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IAEd,KAAK,EAAE,MAAM,CAAC;gBAEQ,KAAK,EAAE,gBAAgB,EAClB,eAAe,EAAE,eAAe;IAa3D;;OAEG;IACM,aAAa,CAAC,GAAG,EAAE,aAAa,CAAC,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAetE"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
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(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
8
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
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 { LirboContextKey } from '@difizen/libro-core';
|
|
19
|
+
import { view, ViewOption, transient, useInject, ViewInstance, inject, prop } from '@difizen/mana-app';
|
|
20
|
+
import { forwardRef } from 'react';
|
|
21
|
+
import { WidgetView } from "../base/widget-view.js";
|
|
22
|
+
import { ProgressBar } from "../components/index.js";
|
|
23
|
+
import "./index.less";
|
|
24
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
25
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
26
|
+
export var LibroProgressWidgetComponent = /*#__PURE__*/forwardRef(function LibroProgressWidgetComponent() {
|
|
27
|
+
var widgetView = useInject(ViewInstance);
|
|
28
|
+
var percent = widgetView.value / ((widgetView.max - widgetView.min) / 100);
|
|
29
|
+
if (widgetView.isCommClosed) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
33
|
+
className: "libro-progress-widget",
|
|
34
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
35
|
+
className: "libro-progress-widget-description",
|
|
36
|
+
children: widgetView.description
|
|
37
|
+
}), /*#__PURE__*/_jsx(ProgressBar, {
|
|
38
|
+
percent: percent
|
|
39
|
+
})]
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
export var ProgressWidget = (_dec = transient(), _dec2 = view('libro-widget-progress-view'), _dec3 = prop(), _dec4 = prop(), _dec5 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_WidgetView) {
|
|
43
|
+
_inherits(ProgressWidget, _WidgetView);
|
|
44
|
+
var _super = _createSuper(ProgressWidget);
|
|
45
|
+
function ProgressWidget(props, lirboContextKey) {
|
|
46
|
+
var _this;
|
|
47
|
+
_classCallCheck(this, ProgressWidget);
|
|
48
|
+
_this = _super.call(this, props, lirboContextKey);
|
|
49
|
+
_this.view = LibroProgressWidgetComponent;
|
|
50
|
+
_initializerDefineProperty(_this, "max", _descriptor, _assertThisInitialized(_this));
|
|
51
|
+
_initializerDefineProperty(_this, "min", _descriptor2, _assertThisInitialized(_this));
|
|
52
|
+
_initializerDefineProperty(_this, "value", _descriptor3, _assertThisInitialized(_this));
|
|
53
|
+
_this.bar_style = props.attributes.bar_style;
|
|
54
|
+
_this.description = props.attributes.description;
|
|
55
|
+
_this.description_tooltip = props.attributes.description_tooltip;
|
|
56
|
+
_this.layout = props.attributes.layout;
|
|
57
|
+
_this.max = props.attributes.max;
|
|
58
|
+
_this.min = props.attributes.min;
|
|
59
|
+
_this.orientation = props.attributes.orientation;
|
|
60
|
+
_this.style = props.attributes.style;
|
|
61
|
+
_this.value = props.attributes.value;
|
|
62
|
+
return _this;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Handle incoming comm msg.
|
|
66
|
+
*/
|
|
67
|
+
ProgressWidget = inject(LirboContextKey)(ProgressWidget, undefined, 1) || ProgressWidget;
|
|
68
|
+
ProgressWidget = inject(ViewOption)(ProgressWidget, undefined, 0) || ProgressWidget;
|
|
69
|
+
_createClass(ProgressWidget, [{
|
|
70
|
+
key: "handleCommMsg",
|
|
71
|
+
value: function handleCommMsg(msg) {
|
|
72
|
+
var data = msg.content.data;
|
|
73
|
+
var method = data.method;
|
|
74
|
+
switch (method) {
|
|
75
|
+
case 'update':
|
|
76
|
+
case 'echo_update':
|
|
77
|
+
if (data.state.value) {
|
|
78
|
+
this.value = data.state.value;
|
|
79
|
+
}
|
|
80
|
+
if (data.state.description) {
|
|
81
|
+
this.description = data.state.description;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return Promise.resolve();
|
|
85
|
+
}
|
|
86
|
+
}]);
|
|
87
|
+
return ProgressWidget;
|
|
88
|
+
}(WidgetView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "max", [_dec3], {
|
|
89
|
+
configurable: true,
|
|
90
|
+
enumerable: true,
|
|
91
|
+
writable: true,
|
|
92
|
+
initializer: null
|
|
93
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "min", [_dec4], {
|
|
94
|
+
configurable: true,
|
|
95
|
+
enumerable: true,
|
|
96
|
+
writable: true,
|
|
97
|
+
initializer: null
|
|
98
|
+
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "value", [_dec5], {
|
|
99
|
+
configurable: true,
|
|
100
|
+
enumerable: true,
|
|
101
|
+
writable: true,
|
|
102
|
+
initializer: null
|
|
103
|
+
})), _class2)) || _class) || _class);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ViewManager } from '@difizen/mana-app';
|
|
2
|
+
import type { IWidgetViewProps } from '../base/protocal.js';
|
|
3
|
+
import { WidgetViewContribution } from '../base/protocal.js';
|
|
4
|
+
import { LibroTextWidget } from './text-widget-view.js';
|
|
5
|
+
export declare class TextModelContribution implements WidgetViewContribution {
|
|
6
|
+
viewManager: ViewManager;
|
|
7
|
+
canHandle: (attributes: any) => 1 | 100;
|
|
8
|
+
factory(props: IWidgetViewProps): Promise<LibroTextWidget>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=text-widget-view-contribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-widget-view-contribution.d.ts","sourceRoot":"","sources":["../../src/widgets/text-widget-view-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAqB,MAAM,mBAAmB,CAAC;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,qBACa,qBAAsB,YAAW,sBAAsB;IAC7C,WAAW,EAAE,WAAW,CAAC;IAC9C,SAAS,eAAgB,GAAG,aAK1B;IACF,OAAO,CAAC,KAAK,EAAE,gBAAgB;CAGhC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
var _dec, _dec2, _class, _class2, _descriptor;
|
|
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(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
8
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
9
|
+
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; }
|
|
10
|
+
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.'); }
|
|
11
|
+
import { ViewManager, inject, singleton } from '@difizen/mana-app';
|
|
12
|
+
import { WidgetViewContribution } from "../base/protocal.js";
|
|
13
|
+
import { LibroTextWidget } from "./text-widget-view.js";
|
|
14
|
+
export var TextModelContribution = (_dec = singleton({
|
|
15
|
+
contrib: WidgetViewContribution
|
|
16
|
+
}), _dec2 = inject(ViewManager), _dec(_class = (_class2 = /*#__PURE__*/function () {
|
|
17
|
+
function TextModelContribution() {
|
|
18
|
+
_classCallCheck(this, TextModelContribution);
|
|
19
|
+
_initializerDefineProperty(this, "viewManager", _descriptor, this);
|
|
20
|
+
this.canHandle = function (attributes) {
|
|
21
|
+
if (attributes._model_name === 'TextModel') {
|
|
22
|
+
return 100;
|
|
23
|
+
}
|
|
24
|
+
return 1;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
_createClass(TextModelContribution, [{
|
|
28
|
+
key: "factory",
|
|
29
|
+
value: function factory(props) {
|
|
30
|
+
return this.viewManager.getOrCreateView(LibroTextWidget, props);
|
|
31
|
+
}
|
|
32
|
+
}]);
|
|
33
|
+
return TextModelContribution;
|
|
34
|
+
}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "viewManager", [_dec2], {
|
|
35
|
+
configurable: true,
|
|
36
|
+
enumerable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
initializer: null
|
|
39
|
+
})), _class2)) || _class);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="react" resolution-mode="require"/>
|
|
2
|
+
import { LirboContextKey } from '@difizen/libro-core';
|
|
3
|
+
import type { IWidgetViewProps } from '../base/protocal.js';
|
|
4
|
+
import { WidgetView } from '../base/widget-view.js';
|
|
5
|
+
import './index.less';
|
|
6
|
+
export declare const LibroTextWidgetComponent: import("react").ForwardRefExoticComponent<import("react").RefAttributes<HTMLDivElement>>;
|
|
7
|
+
export declare class LibroTextWidget extends WidgetView {
|
|
8
|
+
view: import("react").ForwardRefExoticComponent<import("react").RefAttributes<HTMLDivElement>>;
|
|
9
|
+
bar_style: string;
|
|
10
|
+
description: string;
|
|
11
|
+
description_tooltip: null;
|
|
12
|
+
layout: string;
|
|
13
|
+
orientation: string;
|
|
14
|
+
style: string;
|
|
15
|
+
placeholder: string;
|
|
16
|
+
value: number;
|
|
17
|
+
constructor(props: IWidgetViewProps, lirboContextKey: LirboContextKey);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=text-widget-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-widget-view.d.ts","sourceRoot":"","sources":["../../src/widgets/text-widget-view.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAatD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,cAAc,CAAC;AAEtB,eAAO,MAAM,wBAAwB,0FAoCpC,CAAC;AACF,qBAEa,eAAgB,SAAQ,UAAU;IACpC,IAAI,2FAA4B;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,IAAI,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IAEpB,KAAK,EAAE,MAAM,CAAC;gBAEQ,KAAK,EAAE,gBAAgB,EAClB,eAAe,EAAE,eAAe;CAY5D"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
var _dec, _dec2, _dec3, _class, _class2, _descriptor;
|
|
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 _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
5
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
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 { LirboContextKey } from '@difizen/libro-core';
|
|
19
|
+
import { view, ViewOption, transient, useInject, ViewInstance, inject, prop } from '@difizen/mana-app';
|
|
20
|
+
import { Input } from 'antd';
|
|
21
|
+
import { forwardRef } from 'react';
|
|
22
|
+
import { WidgetView } from "../base/widget-view.js";
|
|
23
|
+
import "./index.less";
|
|
24
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
25
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
26
|
+
export var LibroTextWidgetComponent = /*#__PURE__*/forwardRef(function LibroTextWidgetComponent(_props, ref) {
|
|
27
|
+
var widgetView = useInject(ViewInstance);
|
|
28
|
+
if (widgetView.isCommClosed) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
var handleChange = function handleChange(e) {
|
|
32
|
+
var data = {
|
|
33
|
+
buffer_paths: [],
|
|
34
|
+
method: 'update',
|
|
35
|
+
state: {
|
|
36
|
+
value: e.target.value
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
widgetView.send(data);
|
|
40
|
+
};
|
|
41
|
+
var handlePressEnter = function handlePressEnter() {
|
|
42
|
+
var data = {
|
|
43
|
+
method: 'custom',
|
|
44
|
+
content: {
|
|
45
|
+
event: 'submit'
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
widgetView.send(data);
|
|
49
|
+
};
|
|
50
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
51
|
+
className: "libro-input-widget",
|
|
52
|
+
ref: ref,
|
|
53
|
+
children: [/*#__PURE__*/_jsxs("span", {
|
|
54
|
+
className: "libro-input-widget-description",
|
|
55
|
+
children: [' ', widgetView.description]
|
|
56
|
+
}), /*#__PURE__*/_jsx(Input, {
|
|
57
|
+
placeholder: widgetView.placeholder,
|
|
58
|
+
size: "small",
|
|
59
|
+
onChange: handleChange,
|
|
60
|
+
onPressEnter: handlePressEnter
|
|
61
|
+
})]
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
export var LibroTextWidget = (_dec = transient(), _dec2 = view('libro-widget-text-view'), _dec3 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_WidgetView) {
|
|
65
|
+
_inherits(LibroTextWidget, _WidgetView);
|
|
66
|
+
var _super = _createSuper(LibroTextWidget);
|
|
67
|
+
function LibroTextWidget(props, lirboContextKey) {
|
|
68
|
+
var _this;
|
|
69
|
+
_classCallCheck(this, LibroTextWidget);
|
|
70
|
+
_this = _super.call(this, props, lirboContextKey);
|
|
71
|
+
_this.view = LibroTextWidgetComponent;
|
|
72
|
+
_initializerDefineProperty(_this, "value", _descriptor, _assertThisInitialized(_this));
|
|
73
|
+
_this.bar_style = props.attributes.bar_style;
|
|
74
|
+
_this.description = props.attributes.description;
|
|
75
|
+
_this.description_tooltip = props.attributes.description_tooltip;
|
|
76
|
+
_this.layout = props.attributes.layout;
|
|
77
|
+
_this.orientation = props.attributes.orientation;
|
|
78
|
+
_this.style = props.attributes.style;
|
|
79
|
+
_this.value = props.attributes.value;
|
|
80
|
+
_this.placeholder = props.attributes.placeholder;
|
|
81
|
+
return _this;
|
|
82
|
+
}
|
|
83
|
+
LibroTextWidget = inject(LirboContextKey)(LibroTextWidget, undefined, 1) || LibroTextWidget;
|
|
84
|
+
LibroTextWidget = inject(ViewOption)(LibroTextWidget, undefined, 0) || LibroTextWidget;
|
|
85
|
+
return _createClass(LibroTextWidget);
|
|
86
|
+
}(WidgetView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "value", [_dec3], {
|
|
87
|
+
configurable: true,
|
|
88
|
+
enumerable: true,
|
|
89
|
+
writable: true,
|
|
90
|
+
initializer: null
|
|
91
|
+
})), _class2)) || _class) || _class);
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@difizen/libro-widget",
|
|
3
|
+
"version": "0.0.2-alpha.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"libro"
|
|
7
|
+
],
|
|
8
|
+
"repository": "git@github.com:difizen/libro.git",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"typings": "./es/index.d.ts",
|
|
14
|
+
"default": "./es/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./mock": {
|
|
17
|
+
"typings": "./es/mock/index.d.ts",
|
|
18
|
+
"default": "./es/mock/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./es/mock": {
|
|
21
|
+
"typings": "./es/mock/index.d.ts",
|
|
22
|
+
"default": "./es/mock/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"main": "es/index.js",
|
|
27
|
+
"module": "es/index.js",
|
|
28
|
+
"typings": "es/index.d.ts",
|
|
29
|
+
"files": [
|
|
30
|
+
"es",
|
|
31
|
+
"src"
|
|
32
|
+
],
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@difizen/libro-core": "^0.0.2-alpha.0",
|
|
35
|
+
"@difizen/libro-common": "^0.0.2-alpha.0",
|
|
36
|
+
"@difizen/libro-kernel": "^0.0.2-alpha.0",
|
|
37
|
+
"@difizen/libro-rendermime": "^0.0.2-alpha.0",
|
|
38
|
+
"@difizen/mana-app": "alpha"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"antd": "^5.8.6",
|
|
42
|
+
"react": "^18.2.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/react": "^18.2.25"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"setup": "father build",
|
|
49
|
+
"build": "father build",
|
|
50
|
+
"test": ": Note: lint task is delegated to test:* scripts",
|
|
51
|
+
"test:vitest": "vitest run",
|
|
52
|
+
"test:jest": "jest",
|
|
53
|
+
"coverage": ": Note: lint task is delegated to coverage:* scripts",
|
|
54
|
+
"coverage:vitest": "vitest run --coverage",
|
|
55
|
+
"coverage:jest": "jest --coverage",
|
|
56
|
+
"lint": ": Note: lint task is delegated to lint:* scripts",
|
|
57
|
+
"lint:eslint": "eslint src",
|
|
58
|
+
"lint:tsc": "tsc --noEmit"
|
|
59
|
+
}
|
|
60
|
+
}
|
package/src/base/comm.ts
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { JSONObject } from '@difizen/libro-common';
|
|
2
|
+
import type { IComm, IKernelConnection, IShellFuture } from '@difizen/libro-kernel';
|
|
3
|
+
import { inject, transient } from '@difizen/mana-app';
|
|
4
|
+
|
|
5
|
+
import type { ICallbacks, IClassicComm } from './protocal.js';
|
|
6
|
+
import { WidgetCommOption } from './protocal.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Public constructor
|
|
10
|
+
* @param {IComm} jsServicesComm - @jupyterlab/services IComm instance
|
|
11
|
+
*/
|
|
12
|
+
@transient()
|
|
13
|
+
export class Comm implements IClassicComm {
|
|
14
|
+
constructor(@inject(WidgetCommOption) options: WidgetCommOption) {
|
|
15
|
+
this.jsServicesComm = options.comm;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Comm id
|
|
20
|
+
* @return {string}
|
|
21
|
+
*/
|
|
22
|
+
get comm_id(): string {
|
|
23
|
+
return this.jsServicesComm.commId;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Target name
|
|
28
|
+
* @return {string}
|
|
29
|
+
*/
|
|
30
|
+
get target_name(): string {
|
|
31
|
+
return this.jsServicesComm.targetName;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Opens a sibling comm in the backend
|
|
36
|
+
* @param data
|
|
37
|
+
* @param callbacks
|
|
38
|
+
* @param metadata
|
|
39
|
+
* @return msg id
|
|
40
|
+
*/
|
|
41
|
+
open(
|
|
42
|
+
data: JSONObject,
|
|
43
|
+
callbacks?: ICallbacks,
|
|
44
|
+
metadata?: JSONObject,
|
|
45
|
+
buffers?: ArrayBuffer[] | ArrayBufferView[],
|
|
46
|
+
): string {
|
|
47
|
+
const future = this.jsServicesComm.open(data, metadata, buffers);
|
|
48
|
+
this._hookupCallbacks(future, callbacks);
|
|
49
|
+
return future.msg.header.msg_id;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Sends a message to the sibling comm in the backend
|
|
54
|
+
* @param data
|
|
55
|
+
* @param callbacks
|
|
56
|
+
* @param metadata
|
|
57
|
+
* @param buffers
|
|
58
|
+
* @return message id
|
|
59
|
+
*/
|
|
60
|
+
send(
|
|
61
|
+
data: JSONObject,
|
|
62
|
+
callbacks?: ICallbacks,
|
|
63
|
+
metadata?: JSONObject,
|
|
64
|
+
buffers?: ArrayBuffer[] | ArrayBufferView[],
|
|
65
|
+
): string {
|
|
66
|
+
const future = this.jsServicesComm.send(data, metadata, buffers);
|
|
67
|
+
this._hookupCallbacks(future, callbacks);
|
|
68
|
+
return future.msg.header.msg_id;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Closes the sibling comm in the backend
|
|
73
|
+
* @param data
|
|
74
|
+
* @param callbacks
|
|
75
|
+
* @param metadata
|
|
76
|
+
* @return msg id
|
|
77
|
+
*/
|
|
78
|
+
close(
|
|
79
|
+
data?: JSONObject,
|
|
80
|
+
callbacks?: ICallbacks,
|
|
81
|
+
metadata?: JSONObject,
|
|
82
|
+
buffers?: ArrayBuffer[] | ArrayBufferView[],
|
|
83
|
+
): string {
|
|
84
|
+
const future = this.jsServicesComm.close(data, metadata, buffers);
|
|
85
|
+
this._hookupCallbacks(future, callbacks);
|
|
86
|
+
return future.msg.header.msg_id;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Register a message handler
|
|
91
|
+
* @param callback, which is given a message
|
|
92
|
+
*/
|
|
93
|
+
on_msg(callback: (x: any) => void): void {
|
|
94
|
+
this.jsServicesComm.onMsg = callback.bind(this);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Register a handler for when the comm is closed by the backend
|
|
99
|
+
* @param callback, which is given a message
|
|
100
|
+
*/
|
|
101
|
+
on_close(callback: (x: any) => void): void {
|
|
102
|
+
this.jsServicesComm.onClose = callback.bind(this);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Hooks callback object up with @jupyterlab/services IKernelFuture
|
|
107
|
+
* @param @jupyterlab/services IKernelFuture instance
|
|
108
|
+
* @param callbacks
|
|
109
|
+
*/
|
|
110
|
+
_hookupCallbacks(future: IShellFuture, callbacks?: ICallbacks): void {
|
|
111
|
+
if (callbacks) {
|
|
112
|
+
future.onReply = function (msg): void {
|
|
113
|
+
if (callbacks.shell && callbacks.shell['reply']) {
|
|
114
|
+
callbacks.shell['reply'](msg);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
future.onStdin = function (msg): void {
|
|
119
|
+
if (callbacks.input) {
|
|
120
|
+
callbacks.input(msg);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
future.onIOPub = function (msg): void {
|
|
125
|
+
if (callbacks.iopub) {
|
|
126
|
+
if (callbacks.iopub['status'] && msg.header.msg_type === 'status') {
|
|
127
|
+
callbacks.iopub['status'](msg);
|
|
128
|
+
} else if (
|
|
129
|
+
callbacks.iopub['clear_output'] &&
|
|
130
|
+
msg.header.msg_type === 'clear_output'
|
|
131
|
+
) {
|
|
132
|
+
callbacks.iopub['clear_output'](msg);
|
|
133
|
+
} else if (callbacks.iopub['output']) {
|
|
134
|
+
switch (msg.header.msg_type) {
|
|
135
|
+
case 'display_data':
|
|
136
|
+
case 'execute_result':
|
|
137
|
+
case 'stream':
|
|
138
|
+
case 'error':
|
|
139
|
+
callbacks.iopub['output'](msg);
|
|
140
|
+
break;
|
|
141
|
+
default:
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
jsServicesComm: IComm;
|
|
151
|
+
kernel: IKernelConnection;
|
|
152
|
+
}
|