@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present Difizen Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# libro-widget
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { JSONObject } from '@difizen/libro-common';
|
|
2
|
+
import type { IComm, IKernelConnection, IShellFuture } from '@difizen/libro-kernel';
|
|
3
|
+
import type { ICallbacks, IClassicComm } from './protocal.js';
|
|
4
|
+
import { WidgetCommOption } from './protocal.js';
|
|
5
|
+
/**
|
|
6
|
+
* Public constructor
|
|
7
|
+
* @param {IComm} jsServicesComm - @jupyterlab/services IComm instance
|
|
8
|
+
*/
|
|
9
|
+
export declare class Comm implements IClassicComm {
|
|
10
|
+
constructor(options: WidgetCommOption);
|
|
11
|
+
/**
|
|
12
|
+
* Comm id
|
|
13
|
+
* @return {string}
|
|
14
|
+
*/
|
|
15
|
+
get comm_id(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Target name
|
|
18
|
+
* @return {string}
|
|
19
|
+
*/
|
|
20
|
+
get target_name(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Opens a sibling comm in the backend
|
|
23
|
+
* @param data
|
|
24
|
+
* @param callbacks
|
|
25
|
+
* @param metadata
|
|
26
|
+
* @return msg id
|
|
27
|
+
*/
|
|
28
|
+
open(data: JSONObject, callbacks?: ICallbacks, metadata?: JSONObject, buffers?: ArrayBuffer[] | ArrayBufferView[]): string;
|
|
29
|
+
/**
|
|
30
|
+
* Sends a message to the sibling comm in the backend
|
|
31
|
+
* @param data
|
|
32
|
+
* @param callbacks
|
|
33
|
+
* @param metadata
|
|
34
|
+
* @param buffers
|
|
35
|
+
* @return message id
|
|
36
|
+
*/
|
|
37
|
+
send(data: JSONObject, callbacks?: ICallbacks, metadata?: JSONObject, buffers?: ArrayBuffer[] | ArrayBufferView[]): string;
|
|
38
|
+
/**
|
|
39
|
+
* Closes the sibling comm in the backend
|
|
40
|
+
* @param data
|
|
41
|
+
* @param callbacks
|
|
42
|
+
* @param metadata
|
|
43
|
+
* @return msg id
|
|
44
|
+
*/
|
|
45
|
+
close(data?: JSONObject, callbacks?: ICallbacks, metadata?: JSONObject, buffers?: ArrayBuffer[] | ArrayBufferView[]): string;
|
|
46
|
+
/**
|
|
47
|
+
* Register a message handler
|
|
48
|
+
* @param callback, which is given a message
|
|
49
|
+
*/
|
|
50
|
+
on_msg(callback: (x: any) => void): void;
|
|
51
|
+
/**
|
|
52
|
+
* Register a handler for when the comm is closed by the backend
|
|
53
|
+
* @param callback, which is given a message
|
|
54
|
+
*/
|
|
55
|
+
on_close(callback: (x: any) => void): void;
|
|
56
|
+
/**
|
|
57
|
+
* Hooks callback object up with @jupyterlab/services IKernelFuture
|
|
58
|
+
* @param @jupyterlab/services IKernelFuture instance
|
|
59
|
+
* @param callbacks
|
|
60
|
+
*/
|
|
61
|
+
_hookupCallbacks(future: IShellFuture, callbacks?: ICallbacks): void;
|
|
62
|
+
jsServicesComm: IComm;
|
|
63
|
+
kernel: IKernelConnection;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=comm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comm.d.ts","sourceRoot":"","sources":["../../src/base/comm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAGpF,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD;;;GAGG;AACH,qBACa,IAAK,YAAW,YAAY;gBACD,OAAO,EAAE,gBAAgB;IAI/D;;;OAGG;IACH,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED;;;OAGG;IACH,IAAI,WAAW,IAAI,MAAM,CAExB;IAED;;;;;;OAMG;IACH,IAAI,CACF,IAAI,EAAE,UAAU,EAChB,SAAS,CAAC,EAAE,UAAU,EACtB,QAAQ,CAAC,EAAE,UAAU,EACrB,OAAO,CAAC,EAAE,WAAW,EAAE,GAAG,eAAe,EAAE,GAC1C,MAAM;IAMT;;;;;;;OAOG;IACH,IAAI,CACF,IAAI,EAAE,UAAU,EAChB,SAAS,CAAC,EAAE,UAAU,EACtB,QAAQ,CAAC,EAAE,UAAU,EACrB,OAAO,CAAC,EAAE,WAAW,EAAE,GAAG,eAAe,EAAE,GAC1C,MAAM;IAMT;;;;;;OAMG;IACH,KAAK,CACH,IAAI,CAAC,EAAE,UAAU,EACjB,SAAS,CAAC,EAAE,UAAU,EACtB,QAAQ,CAAC,EAAE,UAAU,EACrB,OAAO,CAAC,EAAE,WAAW,EAAE,GAAG,eAAe,EAAE,GAC1C,MAAM;IAMT;;;OAGG;IACH,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI;IAIxC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI;IAI1C;;;;OAIG;IACH,gBAAgB,CAAC,MAAM,EAAE,YAAY,EAAE,SAAS,CAAC,EAAE,UAAU,GAAG,IAAI;IAwCpE,cAAc,EAAE,KAAK,CAAC;IACtB,MAAM,EAAE,iBAAiB,CAAC;CAC3B"}
|
package/es/base/comm.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
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, _class;
|
|
3
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
5
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
+
import { inject, transient } from '@difizen/mana-app';
|
|
9
|
+
import { WidgetCommOption } from "./protocal.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Public constructor
|
|
13
|
+
* @param {IComm} jsServicesComm - @jupyterlab/services IComm instance
|
|
14
|
+
*/
|
|
15
|
+
export var Comm = (_dec = transient(), _dec(_class = /*#__PURE__*/function () {
|
|
16
|
+
function Comm(options) {
|
|
17
|
+
_classCallCheck(this, Comm);
|
|
18
|
+
this.jsServicesComm = options.comm;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Comm id
|
|
23
|
+
* @return {string}
|
|
24
|
+
*/
|
|
25
|
+
Comm = inject(WidgetCommOption)(Comm, undefined, 0) || Comm;
|
|
26
|
+
_createClass(Comm, [{
|
|
27
|
+
key: "comm_id",
|
|
28
|
+
get: function get() {
|
|
29
|
+
return this.jsServicesComm.commId;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Target name
|
|
34
|
+
* @return {string}
|
|
35
|
+
*/
|
|
36
|
+
}, {
|
|
37
|
+
key: "target_name",
|
|
38
|
+
get: function get() {
|
|
39
|
+
return this.jsServicesComm.targetName;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Opens a sibling comm in the backend
|
|
44
|
+
* @param data
|
|
45
|
+
* @param callbacks
|
|
46
|
+
* @param metadata
|
|
47
|
+
* @return msg id
|
|
48
|
+
*/
|
|
49
|
+
}, {
|
|
50
|
+
key: "open",
|
|
51
|
+
value: function open(data, callbacks, metadata, buffers) {
|
|
52
|
+
var future = this.jsServicesComm.open(data, metadata, buffers);
|
|
53
|
+
this._hookupCallbacks(future, callbacks);
|
|
54
|
+
return future.msg.header.msg_id;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Sends a message to the sibling comm in the backend
|
|
59
|
+
* @param data
|
|
60
|
+
* @param callbacks
|
|
61
|
+
* @param metadata
|
|
62
|
+
* @param buffers
|
|
63
|
+
* @return message id
|
|
64
|
+
*/
|
|
65
|
+
}, {
|
|
66
|
+
key: "send",
|
|
67
|
+
value: function send(data, callbacks, metadata, buffers) {
|
|
68
|
+
var future = this.jsServicesComm.send(data, metadata, buffers);
|
|
69
|
+
this._hookupCallbacks(future, callbacks);
|
|
70
|
+
return future.msg.header.msg_id;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Closes the sibling comm in the backend
|
|
75
|
+
* @param data
|
|
76
|
+
* @param callbacks
|
|
77
|
+
* @param metadata
|
|
78
|
+
* @return msg id
|
|
79
|
+
*/
|
|
80
|
+
}, {
|
|
81
|
+
key: "close",
|
|
82
|
+
value: function close(data, callbacks, metadata, buffers) {
|
|
83
|
+
var future = this.jsServicesComm.close(data, metadata, buffers);
|
|
84
|
+
this._hookupCallbacks(future, callbacks);
|
|
85
|
+
return future.msg.header.msg_id;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Register a message handler
|
|
90
|
+
* @param callback, which is given a message
|
|
91
|
+
*/
|
|
92
|
+
}, {
|
|
93
|
+
key: "on_msg",
|
|
94
|
+
value: function on_msg(callback) {
|
|
95
|
+
this.jsServicesComm.onMsg = callback.bind(this);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Register a handler for when the comm is closed by the backend
|
|
100
|
+
* @param callback, which is given a message
|
|
101
|
+
*/
|
|
102
|
+
}, {
|
|
103
|
+
key: "on_close",
|
|
104
|
+
value: function on_close(callback) {
|
|
105
|
+
this.jsServicesComm.onClose = callback.bind(this);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Hooks callback object up with @jupyterlab/services IKernelFuture
|
|
110
|
+
* @param @jupyterlab/services IKernelFuture instance
|
|
111
|
+
* @param callbacks
|
|
112
|
+
*/
|
|
113
|
+
}, {
|
|
114
|
+
key: "_hookupCallbacks",
|
|
115
|
+
value: function _hookupCallbacks(future, callbacks) {
|
|
116
|
+
if (callbacks) {
|
|
117
|
+
future.onReply = function (msg) {
|
|
118
|
+
if (callbacks.shell && callbacks.shell['reply']) {
|
|
119
|
+
callbacks.shell['reply'](msg);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
future.onStdin = function (msg) {
|
|
123
|
+
if (callbacks.input) {
|
|
124
|
+
callbacks.input(msg);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
future.onIOPub = function (msg) {
|
|
128
|
+
if (callbacks.iopub) {
|
|
129
|
+
if (callbacks.iopub['status'] && msg.header.msg_type === 'status') {
|
|
130
|
+
callbacks.iopub['status'](msg);
|
|
131
|
+
} else if (callbacks.iopub['clear_output'] && msg.header.msg_type === 'clear_output') {
|
|
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
|
+
return Comm;
|
|
151
|
+
}()) || _class);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,WAAW,CAAC;AAC1B,cAAc,+BAA+B,CAAC"}
|
package/es/base/index.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
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 './protocal.js';
|
|
7
|
+
import { WidgetsOption, WidgetViewContribution } from './protocal.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
|
+
private models;
|
|
73
|
+
/**
|
|
74
|
+
* The comm target name to register
|
|
75
|
+
*/
|
|
76
|
+
id: string;
|
|
77
|
+
readonly commTargetName = "jupyter.widget";
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=libro-widgets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libro-widgets.d.ts","sourceRoot":"","sources":["../../src/base/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;IAYtE,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;IActB;;;OAGG;IACH,UAAU;IAGV;;;OAGG;IACH,UAAU,IAAI,IAAI;IAGlB;;OAEG;IAEH,OAAO,CAAC,MAAM,CAAsC;IAEpD;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,cAAc,oBAAoB;CAC5C"}
|
|
@@ -0,0 +1,285 @@
|
|
|
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, _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 exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
4
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
5
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
6
|
+
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
|
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
11
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
12
|
+
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
|
|
13
|
+
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
|
|
14
|
+
import { contrib, inject, Priority, prop, transient } from '@difizen/mana-app';
|
|
15
|
+
import { Emitter } from '@difizen/mana-app';
|
|
16
|
+
import { LibroWidgetCommFactory, WidgetsOption, WidgetViewContribution } from "./protocal.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
|
+
/**
|
|
27
|
+
* Dictionary of model ids and model instance promises
|
|
28
|
+
*/
|
|
29
|
+
_initializerDefineProperty(this, "models", _descriptor2, this);
|
|
30
|
+
this.commTargetName = 'jupyter.widget';
|
|
31
|
+
this.kernelConnection = options.kc;
|
|
32
|
+
this.id = options.id;
|
|
33
|
+
this.widgetCommFactory = widgetCommFactory;
|
|
34
|
+
this.kernelConnection.registerCommTarget(this.commTargetName, /*#__PURE__*/function () {
|
|
35
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(comm, msg) {
|
|
36
|
+
var widgetComm;
|
|
37
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
38
|
+
while (1) switch (_context.prev = _context.next) {
|
|
39
|
+
case 0:
|
|
40
|
+
widgetComm = _this.widgetCommFactory({
|
|
41
|
+
comm: comm
|
|
42
|
+
});
|
|
43
|
+
_context.next = 3;
|
|
44
|
+
return _this.handleCommOpen(widgetComm, msg);
|
|
45
|
+
case 3:
|
|
46
|
+
case "end":
|
|
47
|
+
return _context.stop();
|
|
48
|
+
}
|
|
49
|
+
}, _callee);
|
|
50
|
+
}));
|
|
51
|
+
return function (_x, _x2) {
|
|
52
|
+
return _ref.apply(this, arguments);
|
|
53
|
+
};
|
|
54
|
+
}());
|
|
55
|
+
}
|
|
56
|
+
LibroWidgets = inject(LibroWidgetCommFactory)(LibroWidgets, undefined, 1) || LibroWidgets;
|
|
57
|
+
LibroWidgets = inject(WidgetsOption)(LibroWidgets, undefined, 0) || LibroWidgets;
|
|
58
|
+
_createClass(LibroWidgets, [{
|
|
59
|
+
key: "onWidgetRender",
|
|
60
|
+
get: function get() {
|
|
61
|
+
return this.widgetEmitter.event;
|
|
62
|
+
}
|
|
63
|
+
}, {
|
|
64
|
+
key: "findProvider",
|
|
65
|
+
value: function findProvider(attributes) {
|
|
66
|
+
var prioritized = Priority.sortSync(this.WidgetViewProvider.getContributions(), function (contribution) {
|
|
67
|
+
return contribution.canHandle(attributes);
|
|
68
|
+
});
|
|
69
|
+
var sorted = prioritized.map(function (c) {
|
|
70
|
+
return c.value;
|
|
71
|
+
});
|
|
72
|
+
return sorted[0];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Create a comm which can be used for communication for a widget.
|
|
77
|
+
*
|
|
78
|
+
* If the data/metadata is passed in, open the comm before returning (i.e.,
|
|
79
|
+
* send the comm_open message). If the data and metadata is undefined, we
|
|
80
|
+
* want to reconstruct a comm that already exists in the kernel, so do not
|
|
81
|
+
* open the comm by sending the comm_open message.
|
|
82
|
+
*
|
|
83
|
+
* @param comm_target_name Comm target name
|
|
84
|
+
* @param model_id The comm id
|
|
85
|
+
* @param data The initial data for the comm
|
|
86
|
+
* @param metadata The metadata in the open message
|
|
87
|
+
*/
|
|
88
|
+
}, {
|
|
89
|
+
key: "createComm",
|
|
90
|
+
value: function () {
|
|
91
|
+
var _createComm = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(comm_target_name, model_id, data, metadata, buffers) {
|
|
92
|
+
var kernel, comm;
|
|
93
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
94
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
95
|
+
case 0:
|
|
96
|
+
kernel = this.kernelConnection;
|
|
97
|
+
if (kernel) {
|
|
98
|
+
_context2.next = 3;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
throw new Error('No current kernel');
|
|
102
|
+
case 3:
|
|
103
|
+
comm = kernel.createComm(comm_target_name, model_id);
|
|
104
|
+
if (data || metadata) {
|
|
105
|
+
comm.open(data, metadata, buffers);
|
|
106
|
+
}
|
|
107
|
+
return _context2.abrupt("return", this.widgetCommFactory({
|
|
108
|
+
comm: comm
|
|
109
|
+
}));
|
|
110
|
+
case 6:
|
|
111
|
+
case "end":
|
|
112
|
+
return _context2.stop();
|
|
113
|
+
}
|
|
114
|
+
}, _callee2, this);
|
|
115
|
+
}));
|
|
116
|
+
function createComm(_x3, _x4, _x5, _x6, _x7) {
|
|
117
|
+
return _createComm.apply(this, arguments);
|
|
118
|
+
}
|
|
119
|
+
return createComm;
|
|
120
|
+
}()
|
|
121
|
+
/**
|
|
122
|
+
* Get a model by model id.
|
|
123
|
+
*
|
|
124
|
+
* #### Notes
|
|
125
|
+
* If the model is not found, throw error.
|
|
126
|
+
*
|
|
127
|
+
* If you would like to synchronously test if a model exists, use .hasModel().
|
|
128
|
+
*/
|
|
129
|
+
}, {
|
|
130
|
+
key: "getModel",
|
|
131
|
+
value: function getModel(model_id) {
|
|
132
|
+
var model = this.models.get(model_id);
|
|
133
|
+
if (model === undefined) {
|
|
134
|
+
throw new Error('widget model not found');
|
|
135
|
+
}
|
|
136
|
+
return model;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Returns true if the given model is registered, otherwise false.
|
|
141
|
+
*
|
|
142
|
+
* #### Notes
|
|
143
|
+
* This is a synchronous way to check if a model is registered.
|
|
144
|
+
*/
|
|
145
|
+
}, {
|
|
146
|
+
key: "hasModel",
|
|
147
|
+
value: function hasModel(model_id) {
|
|
148
|
+
return this.models.get(model_id) !== undefined;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Handle when a comm is opened.
|
|
153
|
+
*/
|
|
154
|
+
}, {
|
|
155
|
+
key: "handleCommOpen",
|
|
156
|
+
value: function () {
|
|
157
|
+
var _handleCommOpen = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(comm, msg) {
|
|
158
|
+
var protocolVersion, error, data, buffer_paths, buffers;
|
|
159
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
160
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
161
|
+
case 0:
|
|
162
|
+
protocolVersion = (msg.metadata || {})['version'] || '';
|
|
163
|
+
if (!(protocolVersion.split('.', 1)[0] !== PROTOCOL_MAJOR_VERSION)) {
|
|
164
|
+
_context3.next = 5;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
error = "Wrong widget protocol version: received protocol version '".concat(protocolVersion, "', but was expecting major version '").concat(PROTOCOL_MAJOR_VERSION, "'");
|
|
168
|
+
console.error(error);
|
|
169
|
+
return _context3.abrupt("return", Promise.reject(error));
|
|
170
|
+
case 5:
|
|
171
|
+
data = msg.content.data;
|
|
172
|
+
buffer_paths = data.buffer_paths || [];
|
|
173
|
+
buffers = msg.buffers || [];
|
|
174
|
+
put_buffers(data.state, buffer_paths, buffers);
|
|
175
|
+
// this.createComm(msg.content.target_name, msg.content.comm_id, msg.content.data, msg.metadata);
|
|
176
|
+
return _context3.abrupt("return", this.newWidgetView(data.state, {
|
|
177
|
+
model_id: msg.content.comm_id,
|
|
178
|
+
comm: comm
|
|
179
|
+
}).catch(reject('Could not create a model.', true)));
|
|
180
|
+
case 10:
|
|
181
|
+
case "end":
|
|
182
|
+
return _context3.stop();
|
|
183
|
+
}
|
|
184
|
+
}, _callee3, this);
|
|
185
|
+
}));
|
|
186
|
+
function handleCommOpen(_x8, _x9) {
|
|
187
|
+
return _handleCommOpen.apply(this, arguments);
|
|
188
|
+
}
|
|
189
|
+
return handleCommOpen;
|
|
190
|
+
}()
|
|
191
|
+
}, {
|
|
192
|
+
key: "registerWidgetView",
|
|
193
|
+
value: function registerWidgetView(model_id, model) {
|
|
194
|
+
var _this2 = this;
|
|
195
|
+
model.then(function (WidgetView) {
|
|
196
|
+
_this2.models.set(model_id, WidgetView);
|
|
197
|
+
_this2.widgetEmitter.fire({
|
|
198
|
+
WidgetViewName: WidgetView.model_name
|
|
199
|
+
});
|
|
200
|
+
return;
|
|
201
|
+
}).catch(function () {
|
|
202
|
+
//
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}, {
|
|
206
|
+
key: "handleCommClose",
|
|
207
|
+
value: function handleCommClose(msg) {
|
|
208
|
+
var comm_id = msg.content.comm_id;
|
|
209
|
+
var model = this.getModel(comm_id);
|
|
210
|
+
model.isCommClosed = true;
|
|
211
|
+
}
|
|
212
|
+
}, {
|
|
213
|
+
key: "unregisterWidgetView",
|
|
214
|
+
value: function unregisterWidgetView(model_id) {
|
|
215
|
+
var model = this.models.get(model_id);
|
|
216
|
+
model === null || model === void 0 ? void 0 : model.dispose();
|
|
217
|
+
this.models.delete(model_id);
|
|
218
|
+
}
|
|
219
|
+
}, {
|
|
220
|
+
key: "newWidgetView",
|
|
221
|
+
value: function () {
|
|
222
|
+
var _newWidgetView = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(attributes, options) {
|
|
223
|
+
var model_id, provider, WidgetView;
|
|
224
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
225
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
226
|
+
case 0:
|
|
227
|
+
model_id = options.model_id;
|
|
228
|
+
if (model_id) {
|
|
229
|
+
_context4.next = 3;
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
throw new Error('Neither comm nor model_id provided in options object. At least one must exist.');
|
|
233
|
+
case 3:
|
|
234
|
+
options.model_id = model_id;
|
|
235
|
+
provider = this.findProvider(attributes);
|
|
236
|
+
WidgetView = provider.factory({
|
|
237
|
+
attributes: attributes,
|
|
238
|
+
options: options
|
|
239
|
+
});
|
|
240
|
+
this.registerWidgetView(model_id, WidgetView);
|
|
241
|
+
return _context4.abrupt("return", WidgetView);
|
|
242
|
+
case 8:
|
|
243
|
+
case "end":
|
|
244
|
+
return _context4.stop();
|
|
245
|
+
}
|
|
246
|
+
}, _callee4, this);
|
|
247
|
+
}));
|
|
248
|
+
function newWidgetView(_x10, _x11) {
|
|
249
|
+
return _newWidgetView.apply(this, arguments);
|
|
250
|
+
}
|
|
251
|
+
return newWidgetView;
|
|
252
|
+
}()
|
|
253
|
+
/**
|
|
254
|
+
* Close all widgets and empty the widget state.
|
|
255
|
+
* @return Promise that resolves when the widget state is cleared.
|
|
256
|
+
*/
|
|
257
|
+
}, {
|
|
258
|
+
key: "clearState",
|
|
259
|
+
value: function clearState() {
|
|
260
|
+
this.models.clear();
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Disconnect the widget manager from the kernel, setting each model's comm
|
|
264
|
+
* as dead.
|
|
265
|
+
*/
|
|
266
|
+
}, {
|
|
267
|
+
key: "disconnect",
|
|
268
|
+
value: function disconnect() {
|
|
269
|
+
// this.models.forEach(model => model.clear());
|
|
270
|
+
}
|
|
271
|
+
}]);
|
|
272
|
+
return LibroWidgets;
|
|
273
|
+
}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "WidgetViewProvider", [_dec2], {
|
|
274
|
+
configurable: true,
|
|
275
|
+
enumerable: true,
|
|
276
|
+
writable: true,
|
|
277
|
+
initializer: null
|
|
278
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "models", [_dec3], {
|
|
279
|
+
configurable: true,
|
|
280
|
+
enumerable: true,
|
|
281
|
+
writable: true,
|
|
282
|
+
initializer: function initializer() {
|
|
283
|
+
return new Map();
|
|
284
|
+
}
|
|
285
|
+
})), _class2)) || _class);
|