jupyterlab-ipyflow 0.0.150 → 0.0.152
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/lib/index.js +78 -47
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,14 +1,70 @@
|
|
|
1
|
+
import { ICommandPalette } from '@jupyterlab/apputils';
|
|
1
2
|
import { CodeCell } from '@jupyterlab/cells';
|
|
2
3
|
import { INotebookTracker } from '@jupyterlab/notebook';
|
|
3
4
|
const IPYFLOW_KERNEL_NAME = 'ipyflow';
|
|
5
|
+
const waitingClass = 'waiting-cell';
|
|
6
|
+
const readyClass = 'ready-cell';
|
|
7
|
+
const readyMakingClass = 'ready-making-cell';
|
|
8
|
+
const readyMakingInputClass = 'ready-making-input-cell';
|
|
9
|
+
const linkedWaitingClass = 'linked-waiting';
|
|
10
|
+
const linkedReadyMakerClass = 'linked-ready-maker';
|
|
11
|
+
// ipyflow frontend state
|
|
12
|
+
let dirtyCells = new Set();
|
|
13
|
+
let waitingCells = new Set();
|
|
14
|
+
let readyCells = new Set();
|
|
15
|
+
let waiterLinks = {};
|
|
16
|
+
let readyMakerLinks = {};
|
|
17
|
+
let activeCell = null;
|
|
18
|
+
let activeCellId = null;
|
|
19
|
+
let cellsById = {};
|
|
20
|
+
let cellModelsById = {};
|
|
21
|
+
let orderIdxById = {};
|
|
22
|
+
let cellPendingExecution = null;
|
|
23
|
+
let lastExecutionMode = null;
|
|
24
|
+
let isReactivelyExecuting = false;
|
|
25
|
+
let lastExecutionHighlights = null;
|
|
26
|
+
let executedReactiveReadyCells = new Set();
|
|
27
|
+
let newReadyCells = new Set();
|
|
28
|
+
let forcedReactiveCells = new Set();
|
|
29
|
+
const cleanup = new Event('cleanup');
|
|
4
30
|
/**
|
|
5
31
|
* Initialization data for the jupyterlab-ipyflow extension.
|
|
6
32
|
*/
|
|
7
33
|
const extension = {
|
|
8
34
|
id: 'jupyterlab-ipyflow',
|
|
9
|
-
requires: [INotebookTracker],
|
|
35
|
+
requires: [INotebookTracker, ICommandPalette],
|
|
10
36
|
autoStart: true,
|
|
11
|
-
activate: (app, notebooks) => {
|
|
37
|
+
activate: (app, notebooks, palette) => {
|
|
38
|
+
app.commands.addCommand('alt-mode-execute', {
|
|
39
|
+
label: 'Alt Mode Execute',
|
|
40
|
+
isEnabled: () => true,
|
|
41
|
+
isVisible: () => true,
|
|
42
|
+
isToggled: () => false,
|
|
43
|
+
execute: () => {
|
|
44
|
+
if (notebooks.activeCell.model.type === 'code') {
|
|
45
|
+
const session = notebooks.currentWidget.sessionContext;
|
|
46
|
+
if (session.isReady && notebooks.activeCell.model.type === 'code') {
|
|
47
|
+
session.session.kernel.requestExecute({
|
|
48
|
+
code: '%flow toggle-reactivity-until-next-reset',
|
|
49
|
+
silent: true,
|
|
50
|
+
store_history: false,
|
|
51
|
+
}).done.then(() => {
|
|
52
|
+
CodeCell.execute(notebooks.activeCell, session);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
app.commands.addKeyBinding({
|
|
59
|
+
command: 'alt-mode-execute',
|
|
60
|
+
keys: ['Accel Shift Enter'],
|
|
61
|
+
selector: '.jp-Notebook',
|
|
62
|
+
});
|
|
63
|
+
palette.addItem({
|
|
64
|
+
command: 'alt-mode-execute',
|
|
65
|
+
category: 'execution',
|
|
66
|
+
args: {},
|
|
67
|
+
});
|
|
12
68
|
notebooks.widgetAdded.connect((sender, nbPanel) => {
|
|
13
69
|
const session = nbPanel.sessionContext;
|
|
14
70
|
session.ready.then(() => {
|
|
@@ -48,35 +104,6 @@ const extension = {
|
|
|
48
104
|
});
|
|
49
105
|
}
|
|
50
106
|
};
|
|
51
|
-
const waitingClass = 'waiting-cell';
|
|
52
|
-
const readyClass = 'ready-cell';
|
|
53
|
-
const readyMakingClass = 'ready-making-cell';
|
|
54
|
-
const readyMakingInputClass = 'ready-making-input-cell';
|
|
55
|
-
const linkedWaitingClass = 'linked-waiting';
|
|
56
|
-
const linkedReadyMakerClass = 'linked-ready-maker';
|
|
57
|
-
let dirtyCells = new Set();
|
|
58
|
-
let waitingCells = new Set();
|
|
59
|
-
let readyCells = new Set();
|
|
60
|
-
let waiterLinks = {};
|
|
61
|
-
let readyMakerLinks = {};
|
|
62
|
-
let activeCell = null;
|
|
63
|
-
let activeCellId = null;
|
|
64
|
-
let cellsById = {};
|
|
65
|
-
let cellModelsById = {};
|
|
66
|
-
let orderIdxById = {};
|
|
67
|
-
let cellPendingExecution = null;
|
|
68
|
-
let lastExecutionMode = null;
|
|
69
|
-
let isReactivelyExecuting = false;
|
|
70
|
-
let lastExecutionHighlights = null;
|
|
71
|
-
let executedReactiveReadyCells = new Set();
|
|
72
|
-
let newReadyCells = new Set();
|
|
73
|
-
let forcedReactiveCells = new Set();
|
|
74
|
-
const cleanup = new Event('cleanup');
|
|
75
|
-
const resetReactiveState = () => {
|
|
76
|
-
newReadyCells = new Set();
|
|
77
|
-
forcedReactiveCells = new Set();
|
|
78
|
-
executedReactiveReadyCells = new Set();
|
|
79
|
-
};
|
|
80
107
|
const getJpInputCollapser = (elem) => {
|
|
81
108
|
if (elem === null || elem === undefined) {
|
|
82
109
|
return null;
|
|
@@ -322,8 +349,14 @@ const connectToComm = (session, notebook) => {
|
|
|
322
349
|
else if (msg.content.data['type'] === 'compute_exec_schedule') {
|
|
323
350
|
waitingCells = new Set(msg.content.data['waiting_cells']);
|
|
324
351
|
readyCells = new Set(msg.content.data['ready_cells']);
|
|
325
|
-
newReadyCells = new Set([
|
|
326
|
-
|
|
352
|
+
newReadyCells = new Set([
|
|
353
|
+
...newReadyCells,
|
|
354
|
+
...msg.content.data['new_ready_cells'],
|
|
355
|
+
]);
|
|
356
|
+
forcedReactiveCells = new Set([
|
|
357
|
+
...forcedReactiveCells,
|
|
358
|
+
...msg.content.data['forced_reactive_cells'],
|
|
359
|
+
]);
|
|
327
360
|
waiterLinks = msg.content.data['waiter_links'];
|
|
328
361
|
readyMakerLinks = msg.content.data['ready_maker_links'];
|
|
329
362
|
cellPendingExecution = null;
|
|
@@ -332,17 +365,19 @@ const connectToComm = (session, notebook) => {
|
|
|
332
365
|
const exec_schedule = msg.content.data['exec_schedule'];
|
|
333
366
|
lastExecutionMode = exec_mode;
|
|
334
367
|
lastExecutionHighlights = msg.content.data['highlights'];
|
|
335
|
-
|
|
368
|
+
const lastExecutedCellId = msg.content.data['last_executed_cell_id'];
|
|
369
|
+
executedReactiveReadyCells.add(lastExecutedCellId);
|
|
336
370
|
const last_execution_was_error = msg.content.data['last_execution_was_error'];
|
|
337
371
|
if (!last_execution_was_error) {
|
|
338
372
|
for (const cell of notebook.widgets) {
|
|
339
373
|
if (cell.model.type !== 'code' || executedReactiveReadyCells.has(cell.model.id)) {
|
|
340
374
|
continue;
|
|
341
375
|
}
|
|
342
|
-
if (!
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
376
|
+
if (!newReadyCells.has(cell.model.id)) {
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (!forcedReactiveCells.has(cell.model.id) && exec_mode !== 'reactive') {
|
|
380
|
+
continue;
|
|
346
381
|
}
|
|
347
382
|
const codeCell = cell;
|
|
348
383
|
if (cellPendingExecution === null) {
|
|
@@ -362,22 +397,18 @@ const connectToComm = (session, notebook) => {
|
|
|
362
397
|
}
|
|
363
398
|
}
|
|
364
399
|
if (cellPendingExecution === null) {
|
|
365
|
-
if (
|
|
400
|
+
if (isReactivelyExecuting) {
|
|
366
401
|
if (lastExecutionHighlights === 'reactive') {
|
|
367
402
|
readyCells = executedReactiveReadyCells;
|
|
368
403
|
}
|
|
369
|
-
updateUI(notebook);
|
|
370
|
-
resetReactiveState();
|
|
371
|
-
}
|
|
372
|
-
else {
|
|
373
|
-
resetReactiveState();
|
|
374
|
-
updateUI(notebook);
|
|
375
|
-
}
|
|
376
|
-
if (isReactivelyExecuting) {
|
|
377
404
|
comm.send({
|
|
378
405
|
type: 'reactivity_cleanup',
|
|
379
406
|
});
|
|
380
407
|
}
|
|
408
|
+
forcedReactiveCells = new Set();
|
|
409
|
+
newReadyCells = new Set();
|
|
410
|
+
executedReactiveReadyCells = new Set();
|
|
411
|
+
updateUI(notebook);
|
|
381
412
|
isReactivelyExecuting = false;
|
|
382
413
|
}
|
|
383
414
|
else {
|
package/package.json
CHANGED