jupyterlab-ipyflow 0.0.159 → 0.0.160

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.
Files changed (2) hide show
  1. package/lib/index.js +77 -46
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -9,8 +9,9 @@ const readyMakingClass = 'ready-making-cell';
9
9
  const readyMakingInputClass = 'ready-making-input-cell';
10
10
  const linkedWaitingClass = 'linked-waiting';
11
11
  const linkedReadyMakerClass = 'linked-ready-maker';
12
+ const cleanup = new Event('cleanup');
12
13
  // ipyflow frontend state
13
- const dirtyCells = new Set();
14
+ let dirtyCells = new Set();
14
15
  let waitingCells = new Set();
15
16
  let readyCells = new Set();
16
17
  let waiterLinks = {};
@@ -28,7 +29,26 @@ let lastExecutionHighlights = null;
28
29
  let executedReactiveReadyCells = new Set();
29
30
  let newReadyCells = new Set();
30
31
  let forcedReactiveCells = new Set();
31
- const cleanup = new Event('cleanup');
32
+ function resetState() {
33
+ dirtyCells = new Set();
34
+ waitingCells = new Set();
35
+ readyCells = new Set();
36
+ waiterLinks = {};
37
+ readyMakerLinks = {};
38
+ activeCell = null;
39
+ activeCellId = null;
40
+ cellsById = {};
41
+ cellModelsById = {};
42
+ orderIdxById = {};
43
+ cellPendingExecution = null;
44
+ lastExecutionMode = null;
45
+ isReactivelyExecuting = false;
46
+ isAltModeExecuting = false;
47
+ lastExecutionHighlights = null;
48
+ executedReactiveReadyCells = new Set();
49
+ newReadyCells = new Set();
50
+ forcedReactiveCells = new Set();
51
+ }
32
52
  /**
33
53
  * Initialization data for the jupyterlab-ipyflow extension.
34
54
  */
@@ -43,20 +63,27 @@ const extension = {
43
63
  isVisible: () => true,
44
64
  isToggled: () => false,
45
65
  execute: () => {
46
- if (!isAltModeExecuting && notebooks.activeCell.model.type === 'code') {
66
+ const session = notebooks.currentWidget.sessionContext;
67
+ if (!session.isReady) {
68
+ return;
69
+ }
70
+ if (session.session.kernel.name !== IPYFLOW_KERNEL_NAME) {
71
+ app.commands.execute('notebook:enter-command-mode');
72
+ CodeCell.execute(notebooks.activeCell, session);
73
+ }
74
+ else if (!isAltModeExecuting &&
75
+ notebooks.activeCell.model.type === 'code') {
47
76
  isAltModeExecuting = true;
48
- const session = notebooks.currentWidget.sessionContext;
49
- if (session.isReady && notebooks.activeCell.model.type === 'code') {
50
- session.session.kernel
51
- .requestExecute({
52
- code: '%flow toggle-reactivity-until-next-reset',
53
- silent: true,
54
- store_history: false,
55
- })
56
- .done.then(() => {
57
- CodeCell.execute(notebooks.activeCell, session);
58
- });
59
- }
77
+ app.commands.execute('notebook:enter-command-mode');
78
+ session.session.kernel
79
+ .requestExecute({
80
+ code: '%flow toggle-reactivity-until-next-reset',
81
+ silent: true,
82
+ store_history: false,
83
+ })
84
+ .done.then(() => {
85
+ CodeCell.execute(notebooks.activeCell, session);
86
+ });
60
87
  }
61
88
  },
62
89
  });
@@ -75,45 +102,45 @@ const extension = {
75
102
  category: 'execution',
76
103
  args: {},
77
104
  });
105
+ app.commands.addCommand('alt-execute', {
106
+ label: 'Alt Execute',
107
+ isEnabled: () => true,
108
+ isVisible: () => true,
109
+ isToggled: () => false,
110
+ execute: () => {
111
+ const session = notebooks.currentWidget.sessionContext;
112
+ if (session.isReady) {
113
+ app.commands.execute('notebook:enter-command-mode');
114
+ CodeCell.execute(notebooks.activeCell, session);
115
+ }
116
+ },
117
+ });
118
+ app.commands.addKeyBinding({
119
+ command: 'alt-execute',
120
+ keys: ['Accel Enter'],
121
+ selector: '.jp-Notebook',
122
+ });
78
123
  notebooks.widgetAdded.connect((sender, nbPanel) => {
79
124
  const session = nbPanel.sessionContext;
80
125
  session.ready.then(() => {
81
126
  clearCellState(nbPanel.content);
82
- activeCell = nbPanel.content.activeCell;
83
- activeCellId = nbPanel.content.activeCell.model.id;
84
- let commDisconnectHandler = function () {
85
- // do nothing if not connected.
86
- };
127
+ let commDisconnectHandler = resetState;
87
128
  if (session.session.kernel.name === IPYFLOW_KERNEL_NAME) {
88
- commDisconnectHandler = connectToComm(session, nbPanel.content);
129
+ session.ready.then(() => {
130
+ commDisconnectHandler = connectToComm(session, nbPanel.content);
131
+ });
89
132
  }
90
133
  session.kernelChanged.connect((_, args) => {
134
+ if (args.newValue == null) {
135
+ return;
136
+ }
137
+ resetState();
91
138
  clearCellState(nbPanel.content);
92
139
  commDisconnectHandler();
93
- commDisconnectHandler = function () {
94
- // do nothing if not connected.
95
- };
96
- if (args.newValue !== null &&
97
- args.newValue.name === IPYFLOW_KERNEL_NAME) {
98
- commDisconnectHandler = connectToComm(session, nbPanel.content);
99
- }
100
- });
101
- let shouldReconnect = false;
102
- session.statusChanged.connect((session, status) => {
103
- if (status === 'restarting' || status === 'autorestarting') {
104
- shouldReconnect = true;
105
- }
106
- if ((status === 'idle' || status === 'busy') && shouldReconnect) {
107
- shouldReconnect = false;
140
+ commDisconnectHandler = resetState;
141
+ if (args.newValue.name === IPYFLOW_KERNEL_NAME) {
108
142
  session.ready.then(() => {
109
- clearCellState(nbPanel.content);
110
- commDisconnectHandler();
111
- commDisconnectHandler = function () {
112
- // do nothing if not connected.
113
- };
114
- if (session.session.kernel.name === IPYFLOW_KERNEL_NAME) {
115
- commDisconnectHandler = connectToComm(session, nbPanel.content);
116
- }
143
+ commDisconnectHandler = connectToComm(session, nbPanel.content);
117
144
  });
118
145
  }
119
146
  });
@@ -175,7 +202,7 @@ const refreshNodeMapping = (notebook) => {
175
202
  });
176
203
  };
177
204
  const clearCellState = (notebook) => {
178
- notebook.widgets.forEach((cell, idx) => {
205
+ notebook.widgets.forEach((cell) => {
179
206
  cell.node.classList.remove(waitingClass);
180
207
  cell.node.classList.remove(readyMakingClass);
181
208
  cell.node.classList.remove(readyClass);
@@ -216,6 +243,9 @@ const addUnsafeCellInteraction = (elem, linkedElems, cellsById, collapserFun, ev
216
243
  attachCleanupListener(elem, evt, listener);
217
244
  };
218
245
  const connectToComm = (session, notebook) => {
246
+ resetState();
247
+ activeCell = notebook.activeCell;
248
+ activeCellId = activeCell.model.id;
219
249
  const comm = session.session.kernel.createComm('ipyflow');
220
250
  let disconnected = false;
221
251
  const gatherCellMetadataAndContent = () => {
@@ -255,7 +285,7 @@ const connectToComm = (session, notebook) => {
255
285
  if (args.name !== 'executionCount' || args.newValue === null) {
256
286
  return;
257
287
  }
258
- notebook.widgets.forEach((itercell, idx) => {
288
+ notebook.widgets.forEach((itercell) => {
259
289
  if (itercell.model.id === cell.id) {
260
290
  itercell.node.classList.remove(readyClass);
261
291
  itercell.node.classList.remove(readyMakingInputClass);
@@ -475,6 +505,7 @@ const connectToComm = (session, notebook) => {
475
505
  // return a disconnection handle
476
506
  return () => {
477
507
  disconnected = true;
508
+ resetState();
478
509
  };
479
510
  };
480
511
  export default extension;
package/package.json CHANGED
@@ -67,5 +67,5 @@
67
67
  "extension": true,
68
68
  "outputDir": "../../core/ipyflow/resources/labextension/"
69
69
  },
70
- "version": "0.0.159"
71
- }
70
+ "version": "0.0.160"
71
+ }