@difizen/libro-jupyter 0.3.51 → 0.3.52

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.
@@ -1 +1 @@
1
- {"version":3,"file":"jupyter-code-cell-view.d.ts","sourceRoot":"","sources":["../../src/cell/jupyter-code-cell-view.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EAElB,eAAe,EAEhB,MAAM,4BAA4B,CAAC;AAUpC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,qBAEa,mBAAoB,SAAQ,iBAAiB;IACxD,UAAkB,OAAO,EAAE,gBAAgB,CAAC;IAE5C,IAAa,MAAM,IAGQ,gBAAgB,CAD1C;IACD,IAAa,MAAM,CAAC,KAAK,EAAE,gBAAgB,EAG1C;IAGO,KAAK,EAAE,oBAAoB,CAAC;IAE3B,cAAc,aAQrB;cAEiB,eAAe,IAAI,qBAAqB;IAU5C,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB3C,eAAe,EAAE,eAAe,CAqB9B;IAEF,kBAAkB,EAAE,kBAAkB,CA8BpC;IAEa,GAAG;CA8EnB"}
1
+ {"version":3,"file":"jupyter-code-cell-view.d.ts","sourceRoot":"","sources":["../../src/cell/jupyter-code-cell-view.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EAElB,eAAe,EAEhB,MAAM,4BAA4B,CAAC;AAUpC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,qBAEa,mBAAoB,SAAQ,iBAAiB;IACxD,UAAkB,OAAO,EAAE,gBAAgB,CAAC;IAE5C,IAAa,MAAM,IAGQ,gBAAgB,CAD1C;IACD,IAAa,MAAM,CAAC,KAAK,EAAE,gBAAgB,EAG1C;IAGO,KAAK,EAAE,oBAAoB,CAAC;IAE3B,cAAc,aAQrB;cAEiB,eAAe,IAAI,qBAAqB;IAU5C,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAmE3C,eAAe,EAAE,eAAe,CAqB9B;IAEF,kBAAkB,EAAE,kBAAkB,CA8BpC;IAEa,GAAG;CA4FnB"}
@@ -163,7 +163,7 @@ export var JupyterCodeCellView = (_dec = transient(), _dec2 = view('jupyter-code
163
163
  value: function () {
164
164
  var _onViewMount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
165
165
  var _this2 = this;
166
- var kcReady, kernelConnection;
166
+ var kcReady, kernelConnection, execution, msgId, _disposable, statusDisposable, disposable;
167
167
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
168
168
  while (1) switch (_context3.prev = _context3.next) {
169
169
  case 0:
@@ -173,15 +173,56 @@ export var JupyterCodeCellView = (_dec = transient(), _dec2 = view('jupyter-code
173
173
  return kcReady;
174
174
  case 4:
175
175
  kernelConnection = _context3.sent;
176
+ // 渲染后检查 cell 是否处于执行中,如果还在执行则恢复输出
177
+ if (kernelConnection && !kernelConnection.isDisposed) {
178
+ execution = this.model.metadata.execution;
179
+ msgId = execution === null || execution === void 0 ? void 0 : execution['libro_execution_msg_id'];
180
+ if (msgId) {
181
+ if (kernelConnection.status === 'idle') {
182
+ delete execution['libro_execution_msg_id'];
183
+ // 触发保存
184
+ this.parent.model.saveNotebookContent();
185
+ this.model.kernelExecuting = false;
186
+ } else {
187
+ this.model.kernelExecuting = true;
188
+ _disposable = kernelConnection.iopubMessage(function (msg) {
189
+ if (msg.parent_header && msg.parent_header.msg_id === msgId) {
190
+ _this2.model.msgChangeEmitter.fire(msg);
191
+ if (msg.header.msg_type === 'status' && msg.content.execution_state === 'idle') {
192
+ _this2.model.kernelExecuting = false;
193
+ delete execution['libro_execution_msg_id'];
194
+ // 触发保存
195
+ _this2.parent.model.saveNotebookContent();
196
+ _disposable.dispose();
197
+ }
198
+ }
199
+ });
200
+ this.toDispose.push(_disposable);
201
+ statusDisposable = kernelConnection.statusChanged(function (status) {
202
+ if (status === 'idle') {
203
+ _this2.model.kernelExecuting = false;
204
+ delete execution['libro_execution_msg_id'];
205
+ // 触发保存
206
+ _this2.parent.model.saveNotebookContent();
207
+ _disposable.dispose();
208
+ statusDisposable.dispose();
209
+ }
210
+ });
211
+ this.toDispose.push(statusDisposable);
212
+ }
213
+ }
214
+ }
215
+
176
216
  // kernel重启后,清除执行状态,输出不变
177
- kernelConnection === null || kernelConnection === void 0 || kernelConnection.statusChanged(function (e) {
217
+ disposable = kernelConnection === null || kernelConnection === void 0 ? void 0 : kernelConnection.statusChanged(function (e) {
178
218
  var terminateStatus = ['autorestarting', 'starting', 'restarting'];
179
219
  if (terminateStatus.includes(e)) {
180
220
  _this2.model.clearExecution();
181
221
  _this2.model.executing = false;
182
222
  }
183
223
  });
184
- case 6:
224
+ this.toDispose.push(disposable);
225
+ case 8:
185
226
  case "end":
186
227
  return _context3.stop();
187
228
  }
@@ -196,6 +237,7 @@ export var JupyterCodeCellView = (_dec = transient(), _dec2 = view('jupyter-code
196
237
  key: "run",
197
238
  value: function () {
198
239
  var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
240
+ var _this3 = this;
199
241
  var libroModel, kernelConnection, cellContent, cellModel, future, startTimeStr, msgPromise, endTimeStr;
200
242
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
201
243
  while (1) switch (_context4.prev = _context4.next) {
@@ -220,6 +262,12 @@ export var JupyterCodeCellView = (_dec = transient(), _dec2 = view('jupyter-code
220
262
  });
221
263
  startTimeStr = '';
222
264
  this.clearExecution();
265
+ if (!cellModel.metadata.execution) {
266
+ cellModel.metadata.execution = {};
267
+ }
268
+ cellModel.metadata.execution['libro_execution_msg_id'] = future.msg.header.msg_id;
269
+ // 触发保存
270
+ this.parent.model.saveNotebookContent();
223
271
 
224
272
  // Handle iopub messages
225
273
  future.onIOPub = function (msg) {
@@ -227,8 +275,11 @@ export var JupyterCodeCellView = (_dec = transient(), _dec2 = view('jupyter-code
227
275
  cellModel.metadata.execution = {
228
276
  'shell.execute_reply.started': '',
229
277
  'shell.execute_reply.end': '',
230
- to_execute: new Date().toISOString()
278
+ to_execute: new Date().toISOString(),
279
+ libro_execution_msg_id: future.msg.header.msg_id
231
280
  };
281
+ // 触发保存
282
+ _this3.parent.model.saveNotebookContent();
232
283
  cellModel.kernelExecuting = true;
233
284
  startTimeStr = msg.header.date;
234
285
  var meta = cellModel.metadata.execution;
@@ -242,47 +293,50 @@ export var JupyterCodeCellView = (_dec = transient(), _dec2 = view('jupyter-code
242
293
  future.onReply = function (msg) {
243
294
  cellModel.msgChangeEmitter.fire(msg);
244
295
  };
245
- _context4.next = 15;
296
+ _context4.next = 18;
246
297
  return future.done;
247
- case 15:
298
+ case 18:
248
299
  msgPromise = _context4.sent;
249
300
  cellModel.executing = false;
250
301
  cellModel.kernelExecuting = false;
302
+ if (cellModel.metadata.execution) {
303
+ delete cellModel.metadata.execution['libro_execution_msg_id'];
304
+ }
251
305
  startTimeStr = msgPromise.metadata['started'];
252
306
  endTimeStr = msgPromise.header.date;
253
307
  cellModel.metadata.execution['shell.execute_reply.started'] = startTimeStr;
254
308
  cellModel.metadata.execution['shell.execute_reply.end'] = endTimeStr;
255
309
  if (msgPromise) {
256
- _context4.next = 24;
310
+ _context4.next = 28;
257
311
  break;
258
312
  }
259
313
  return _context4.abrupt("return", true);
260
- case 24:
314
+ case 28:
261
315
  if (!(msgPromise.content.status === 'ok')) {
262
- _context4.next = 28;
316
+ _context4.next = 32;
263
317
  break;
264
318
  }
265
319
  return _context4.abrupt("return", true);
266
- case 28:
320
+ case 32:
267
321
  throw new KernelError(msgPromise.content);
268
- case 29:
269
- _context4.next = 36;
322
+ case 33:
323
+ _context4.next = 40;
270
324
  break;
271
- case 31:
272
- _context4.prev = 31;
325
+ case 35:
326
+ _context4.prev = 35;
273
327
  _context4.t0 = _context4["catch"](6);
274
328
  if (!_context4.t0.message.startsWith('Canceled')) {
275
- _context4.next = 35;
329
+ _context4.next = 39;
276
330
  break;
277
331
  }
278
332
  return _context4.abrupt("return", false);
279
- case 35:
333
+ case 39:
280
334
  throw _context4.t0;
281
- case 36:
335
+ case 40:
282
336
  case "end":
283
337
  return _context4.stop();
284
338
  }
285
- }, _callee4, this, [[6, 31]]);
339
+ }, _callee4, this, [[6, 35]]);
286
340
  }));
287
341
  function run() {
288
342
  return _run.apply(this, arguments);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@difizen/libro-jupyter",
3
- "version": "0.3.51",
3
+ "version": "0.3.52",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "libro"
@@ -37,22 +37,22 @@
37
37
  "dependencies": {
38
38
  "@ant-design/colors": "^7.0.0",
39
39
  "@ant-design/icons": "^5.1.0",
40
- "@difizen/libro-code-cell": "^0.3.51",
41
- "@difizen/libro-code-editor": "^0.3.51",
42
- "@difizen/libro-codemirror": "^0.3.51",
43
- "@difizen/libro-cofine-editor": "^0.3.51",
44
- "@difizen/libro-common": "^0.3.51",
45
- "@difizen/libro-core": "^0.3.51",
46
- "@difizen/libro-kernel": "^0.3.51",
47
- "@difizen/libro-l10n": "^0.3.51",
48
- "@difizen/libro-language-client": "^0.3.51",
49
- "@difizen/libro-lsp": "^0.3.51",
50
- "@difizen/libro-markdown-cell": "^0.3.51",
51
- "@difizen/libro-output": "^0.3.51",
52
- "@difizen/libro-raw-cell": "^0.3.51",
53
- "@difizen/libro-rendermime": "^0.3.51",
54
- "@difizen/libro-search": "^0.3.51",
55
- "@difizen/libro-search-code-cell": "^0.3.51",
40
+ "@difizen/libro-code-cell": "^0.3.52",
41
+ "@difizen/libro-code-editor": "^0.3.52",
42
+ "@difizen/libro-codemirror": "^0.3.52",
43
+ "@difizen/libro-cofine-editor": "^0.3.52",
44
+ "@difizen/libro-common": "^0.3.52",
45
+ "@difizen/libro-core": "^0.3.52",
46
+ "@difizen/libro-kernel": "^0.3.52",
47
+ "@difizen/libro-l10n": "^0.3.52",
48
+ "@difizen/libro-language-client": "^0.3.52",
49
+ "@difizen/libro-lsp": "^0.3.52",
50
+ "@difizen/libro-markdown-cell": "^0.3.52",
51
+ "@difizen/libro-output": "^0.3.52",
52
+ "@difizen/libro-raw-cell": "^0.3.52",
53
+ "@difizen/libro-rendermime": "^0.3.52",
54
+ "@difizen/libro-search": "^0.3.52",
55
+ "@difizen/libro-search-code-cell": "^0.3.52",
56
56
  "@difizen/mana-app": "latest",
57
57
  "@difizen/mana-l10n": "latest",
58
58
  "classnames": "^2.3.2",
@@ -59,8 +59,56 @@ export class JupyterCodeCellView extends LibroCodeCellView {
59
59
  super.onViewMount();
60
60
  const kcReady = getOrigin((this.parent.model as LibroJupyterModel).kcReady);
61
61
  const kernelConnection = await kcReady;
62
+
63
+ // 渲染后检查 cell 是否处于执行中,如果还在执行则恢复输出
64
+ if (kernelConnection && !kernelConnection.isDisposed) {
65
+ const execution = this.model.metadata.execution as any;
66
+ const msgId = execution?.['libro_execution_msg_id'];
67
+ if (msgId) {
68
+ if (kernelConnection.status === 'idle') {
69
+ delete execution['libro_execution_msg_id'];
70
+ // 触发保存
71
+ this.parent.model.saveNotebookContent();
72
+ this.model.kernelExecuting = false;
73
+ } else {
74
+ this.model.kernelExecuting = true;
75
+ const disposable = kernelConnection.iopubMessage(
76
+ (msg: KernelMessage.IIOPubMessage) => {
77
+ if (msg.parent_header && (msg.parent_header as any).msg_id === msgId) {
78
+ this.model.msgChangeEmitter.fire(msg);
79
+ if (
80
+ msg.header.msg_type === 'status' &&
81
+ (msg.content as any).execution_state === 'idle'
82
+ ) {
83
+ this.model.kernelExecuting = false;
84
+ delete execution['libro_execution_msg_id'];
85
+ // 触发保存
86
+ this.parent.model.saveNotebookContent();
87
+ disposable.dispose();
88
+ }
89
+ }
90
+ },
91
+ );
92
+ this.toDispose.push(disposable);
93
+ const statusDisposable = kernelConnection.statusChanged(
94
+ (status: KernelMessage.Status) => {
95
+ if (status === 'idle') {
96
+ this.model.kernelExecuting = false;
97
+ delete execution['libro_execution_msg_id'];
98
+ // 触发保存
99
+ this.parent.model.saveNotebookContent();
100
+ disposable.dispose();
101
+ statusDisposable.dispose();
102
+ }
103
+ },
104
+ );
105
+ this.toDispose.push(statusDisposable);
106
+ }
107
+ }
108
+ }
109
+
62
110
  // kernel重启后,清除执行状态,输出不变
63
- kernelConnection?.statusChanged((e) => {
111
+ const disposable = kernelConnection?.statusChanged((e: KernelMessage.Status) => {
64
112
  const terminateStatus: KernelMessage.Status[] = [
65
113
  'autorestarting',
66
114
  'starting',
@@ -71,6 +119,7 @@ export class JupyterCodeCellView extends LibroCodeCellView {
71
119
  this.model.executing = false;
72
120
  }
73
121
  });
122
+ this.toDispose.push(disposable);
74
123
  }
75
124
 
76
125
  tooltipProvider: TooltipProvider = async (option: TooltipProviderOption) => {
@@ -156,6 +205,14 @@ export class JupyterCodeCellView extends LibroCodeCellView {
156
205
  let startTimeStr = '';
157
206
  this.clearExecution();
158
207
 
208
+ if (!cellModel.metadata.execution) {
209
+ cellModel.metadata.execution = {} as ExecutionMeta;
210
+ }
211
+ (cellModel.metadata.execution as any)['libro_execution_msg_id'] =
212
+ future.msg.header.msg_id;
213
+ // 触发保存
214
+ this.parent.model.saveNotebookContent();
215
+
159
216
  // Handle iopub messages
160
217
  future.onIOPub = (msg: any) => {
161
218
  if (msg.header.msg_type === 'execute_input') {
@@ -163,7 +220,10 @@ export class JupyterCodeCellView extends LibroCodeCellView {
163
220
  'shell.execute_reply.started': '',
164
221
  'shell.execute_reply.end': '',
165
222
  to_execute: new Date().toISOString(),
223
+ libro_execution_msg_id: future.msg.header.msg_id,
166
224
  } as ExecutionMeta;
225
+ // 触发保存
226
+ this.parent.model.saveNotebookContent();
167
227
  cellModel.kernelExecuting = true;
168
228
  startTimeStr = msg.header.date as string;
169
229
  const meta = cellModel.metadata.execution as ExecutionMeta;
@@ -181,6 +241,9 @@ export class JupyterCodeCellView extends LibroCodeCellView {
181
241
  const msgPromise = await future.done;
182
242
  cellModel.executing = false;
183
243
  cellModel.kernelExecuting = false;
244
+ if (cellModel.metadata.execution) {
245
+ delete (cellModel.metadata.execution as any)['libro_execution_msg_id'];
246
+ }
184
247
 
185
248
  startTimeStr = msgPromise.metadata['started'] as string;
186
249
  const endTimeStr = msgPromise.header.date;