@datalayer/jupyter-react 0.19.2 → 0.19.4

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 (109) hide show
  1. package/lib/components/console/Console.js +5 -5
  2. package/lib/components/console/Console.js.map +1 -1
  3. package/lib/components/jupyterlab/JupyterLabApp.js +3 -4
  4. package/lib/components/jupyterlab/JupyterLabApp.js.map +1 -1
  5. package/lib/components/jupyterlab/JupyterLabAppPlugins.d.ts +1 -1
  6. package/lib/components/jupyterlab/JupyterLabAppPlugins.js +1 -1
  7. package/lib/components/jupyterlab/JupyterLabAppPlugins.js.map +1 -1
  8. package/lib/components/notebook/BaseNotebook.d.ts +148 -0
  9. package/lib/components/notebook/BaseNotebook.js +717 -0
  10. package/lib/components/notebook/BaseNotebook.js.map +1 -0
  11. package/lib/components/notebook/Notebook.d.ts +16 -14
  12. package/lib/components/notebook/Notebook.js +153 -28
  13. package/lib/components/notebook/Notebook.js.map +1 -1
  14. package/lib/components/notebook/NotebookAdapter.js +2 -2
  15. package/lib/components/notebook/NotebookAdapter.js.map +1 -1
  16. package/lib/components/notebook/NotebookCommands.d.ts +14 -4
  17. package/lib/components/notebook/NotebookCommands.js +213 -149
  18. package/lib/components/notebook/NotebookCommands.js.map +1 -1
  19. package/lib/components/notebook/NotebookState.js +15 -15
  20. package/lib/components/notebook/NotebookState.js.map +1 -1
  21. package/lib/components/notebook/SimpleNotebook.d.ts +34 -0
  22. package/lib/components/notebook/SimpleNotebook.js +84 -0
  23. package/lib/components/notebook/SimpleNotebook.js.map +1 -0
  24. package/lib/components/notebook/content/JupyterReactContentFactory.js +2 -1
  25. package/lib/components/notebook/content/JupyterReactContentFactory.js.map +1 -1
  26. package/lib/components/notebook/index.d.ts +2 -0
  27. package/lib/components/notebook/index.js +2 -0
  28. package/lib/components/notebook/index.js.map +1 -1
  29. package/lib/components/output/Output.js +1 -1
  30. package/lib/components/output/Output.js.map +1 -1
  31. package/lib/components/output/OutputAdapter.js +2 -2
  32. package/lib/components/output/OutputAdapter.js.map +1 -1
  33. package/lib/components/utils/Loader.d.ts +4 -0
  34. package/lib/components/utils/Loader.js +23 -0
  35. package/lib/components/utils/Loader.js.map +1 -0
  36. package/lib/components/utils/SpinnerCentered.d.ts +2 -1
  37. package/lib/components/utils/SpinnerCentered.js +2 -2
  38. package/lib/components/utils/SpinnerCentered.js.map +1 -1
  39. package/lib/components/utils/index.d.ts +1 -0
  40. package/lib/components/utils/index.js +1 -0
  41. package/lib/components/utils/index.js.map +1 -1
  42. package/lib/examples/CellLite.js +2 -2
  43. package/lib/examples/CellLite.js.map +1 -1
  44. package/lib/examples/ConsoleLite.js +2 -2
  45. package/lib/examples/ConsoleLite.js.map +1 -1
  46. package/lib/examples/KernelExecute.js +1 -1
  47. package/lib/examples/KernelExecute.js.map +1 -1
  48. package/lib/examples/KernelExecutor.js +1 -1
  49. package/lib/examples/KernelExecutor.js.map +1 -1
  50. package/lib/examples/Kernels.js +1 -1
  51. package/lib/examples/Kernels.js.map +1 -1
  52. package/lib/examples/NotebookCellSidebar.js +1 -1
  53. package/lib/examples/NotebookCellSidebar.js.map +1 -1
  54. package/lib/examples/NotebookCellToolbar.js +1 -1
  55. package/lib/examples/NotebookCellToolbar.js.map +1 -1
  56. package/lib/examples/NotebookCollaborative.d.ts +1 -0
  57. package/lib/examples/NotebookCollaborative.js +20 -0
  58. package/lib/examples/NotebookCollaborative.js.map +1 -0
  59. package/lib/examples/NotebookColormode.js +1 -1
  60. package/lib/examples/NotebookColormode.js.map +1 -1
  61. package/lib/examples/NotebookLite.js +1 -1
  62. package/lib/examples/NotebookLite.js.map +1 -1
  63. package/lib/examples/NotebookReadonly.js +1 -1
  64. package/lib/examples/NotebookReadonly.js.map +1 -1
  65. package/lib/examples/NotebookSimple.d.ts +1 -0
  66. package/lib/examples/NotebookSimple.js +36 -0
  67. package/lib/examples/NotebookSimple.js.map +1 -0
  68. package/lib/examples/Output.js +3 -3
  69. package/lib/examples/Output.js.map +1 -1
  70. package/lib/examples/OutputWithMonitoring.js +1 -1
  71. package/lib/examples/OutputWithMonitoring.js.map +1 -1
  72. package/lib/examples/Outputs.js +3 -3
  73. package/lib/examples/Outputs.js.map +1 -1
  74. package/lib/examples/extensions/celltoolbar/CellToolbarExtension.d.ts +1 -1
  75. package/lib/examples/extensions/celltoolbar/CellToolbarExtension.js +6 -2
  76. package/lib/examples/extensions/celltoolbar/CellToolbarExtension.js.map +1 -1
  77. package/lib/examples/extensions/exectime/ExecTimeExtension.d.ts +1 -1
  78. package/lib/examples/extensions/exectime/ExecTimeExtension.js +1 -1
  79. package/lib/examples/extensions/exectime/ExecTimeExtension.js.map +1 -1
  80. package/lib/examples/notebooks/Lite.ipynb.json +146 -0
  81. package/lib/examples/toolbars/NotebookToolbarAutoSave.js +3 -3
  82. package/lib/examples/toolbars/NotebookToolbarAutoSave.js.map +1 -1
  83. package/lib/jupyter/JupyterConfig.d.ts +1 -2
  84. package/lib/jupyter/JupyterConfig.js +1 -2
  85. package/lib/jupyter/JupyterConfig.js.map +1 -1
  86. package/lib/jupyter/JupyterContext.d.ts +0 -15
  87. package/lib/jupyter/JupyterContext.js +2 -6
  88. package/lib/jupyter/JupyterContext.js.map +1 -1
  89. package/lib/jupyter/collaboration/DatalayerCollaboration.d.ts +7 -0
  90. package/lib/jupyter/collaboration/DatalayerCollaboration.js +30 -0
  91. package/lib/jupyter/collaboration/DatalayerCollaboration.js.map +1 -0
  92. package/lib/jupyter/collaboration/ICollaborative.d.ts +2 -0
  93. package/lib/jupyter/collaboration/ICollaborative.js +7 -0
  94. package/lib/jupyter/collaboration/ICollaborative.js.map +1 -0
  95. package/lib/jupyter/collaboration/JupyterCollaboration.d.ts +27 -0
  96. package/lib/jupyter/collaboration/JupyterCollaboration.js +39 -0
  97. package/lib/jupyter/collaboration/JupyterCollaboration.js.map +1 -0
  98. package/lib/jupyter/collaboration/index.d.ts +3 -0
  99. package/lib/jupyter/collaboration/index.js +9 -0
  100. package/lib/jupyter/collaboration/index.js.map +1 -0
  101. package/lib/jupyter/index.d.ts +1 -0
  102. package/lib/jupyter/index.js +1 -0
  103. package/lib/jupyter/index.js.map +1 -1
  104. package/lib/state/JupyterReactState.js +2 -2
  105. package/lib/state/JupyterReactState.js.map +1 -1
  106. package/lib/utils/Utils.d.ts +6 -0
  107. package/lib/utils/Utils.js +9 -1
  108. package/lib/utils/Utils.js.map +1 -1
  109. package/package.json +3 -3
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * MIT License
5
5
  */
6
+ import { DisposableSet } from '@lumino/disposable';
6
7
  import { SessionContextDialogs } from '@jupyterlab/apputils';
7
8
  import { NotebookActions, NotebookSearchProvider, } from '@jupyterlab/notebook';
8
9
  import { SearchDocumentModel, SearchDocumentView, } from '@jupyterlab/documentsearch';
@@ -11,7 +12,7 @@ import { nullTranslator } from '@jupyterlab/translation';
11
12
  /**
12
13
  * The map of command ids used by the notebook.
13
14
  */
14
- export const cmdIds = {
15
+ export const NotebookCommandIds = {
15
16
  changeCellType: 'notebook-cell:change-cell-type',
16
17
  changeCellTypeToCode: 'notebook-cell:change-cell-to-code',
17
18
  changeCellTypeToMarkdown: 'notebook-cell:change-cell-to-markdown',
@@ -46,62 +47,77 @@ export const cmdIds = {
46
47
  switchKernel: 'notebook:switch-kernel',
47
48
  undo: 'notebook-cells:undo',
48
49
  };
49
- export const NotebookCommands = (commandRegistry, notebookPanel, completerHandler, tracker, path) => {
50
+ /**
51
+ * Register notebook commands.
52
+ *
53
+ * @param commandRegistry Command registry
54
+ * @param completerHandler Completion handler
55
+ * @param tracker Notebook tracker
56
+ * @param path Notebook path
57
+ * @returns Commands disposer
58
+ */
59
+ export function addNotebookCommands(commandRegistry, completerHandler, tracker, path) {
60
+ const allCommands = new DisposableSet();
61
+ // Add commands.
50
62
  if (path) {
51
- commandRegistry.addCommand(cmdIds.save, {
63
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.save, {
52
64
  label: 'Save',
53
- execute: () => notebookPanel.context.save(),
54
- });
55
- commandRegistry.addKeyBinding({
65
+ execute: () => {
66
+ tracker.currentWidget?.context.save();
67
+ },
68
+ }));
69
+ allCommands.add(commandRegistry.addKeyBinding({
56
70
  selector: '.jp-Notebook',
57
71
  keys: ['Accel S'],
58
- command: cmdIds.save,
59
- });
72
+ command: NotebookCommandIds.save,
73
+ }));
60
74
  }
61
- // Add commands.
62
- commandRegistry.addCommand(cmdIds.invoke, {
75
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.invoke, {
63
76
  label: 'Completer: Invoke',
64
77
  execute: () => completerHandler.invoke(),
65
- });
66
- commandRegistry.addCommand(cmdIds.select, {
78
+ }));
79
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.select, {
67
80
  label: 'Completer: Select',
68
81
  execute: () => completerHandler.completer.selectActive(),
69
- });
70
- commandRegistry.addCommand(cmdIds.invokeNotebook, {
82
+ }));
83
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.invokeNotebook, {
71
84
  label: 'Invoke Notebook',
72
85
  execute: () => {
73
- if (notebookPanel.content.activeCell?.model.type === 'code') {
74
- return commandRegistry.execute(cmdIds.invoke);
86
+ if (tracker.currentWidget?.content.activeCell?.model.type === 'code') {
87
+ return commandRegistry.execute(NotebookCommandIds.invoke);
75
88
  }
76
89
  },
77
- });
78
- commandRegistry.addCommand(cmdIds.selectNotebook, {
90
+ }));
91
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.selectNotebook, {
79
92
  label: 'Select Notebook',
80
93
  execute: () => {
81
- if (notebookPanel.content.activeCell?.model.type === 'code') {
82
- return commandRegistry.execute(cmdIds.select);
94
+ if (tracker.currentWidget?.content.activeCell?.model.type === 'code') {
95
+ return commandRegistry.execute(NotebookCommandIds.select);
83
96
  }
84
97
  },
85
- });
98
+ }));
86
99
  let searchInstance;
87
- commandRegistry.addCommand(cmdIds.startSearch, {
100
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.startSearch, {
88
101
  label: 'Find…',
89
102
  execute: () => {
90
- if (!searchInstance) {
91
- const provider = new NotebookSearchProvider(notebookPanel, nullTranslator);
103
+ if (!tracker.currentWidget) {
104
+ searchInstance = undefined;
105
+ }
106
+ else if (!searchInstance) {
107
+ const provider = new NotebookSearchProvider(tracker.currentWidget, nullTranslator);
92
108
  const searchModel = new SearchDocumentModel(provider, 500);
93
109
  searchInstance = new SearchDocumentView(searchModel);
94
110
  /**
95
111
  * Activate the target widget when the search panel is closing
96
112
  */
97
113
  searchInstance.closed.connect(() => {
98
- if (!notebookPanel.isDisposed) {
99
- notebookPanel.activate();
114
+ if (!tracker.currentWidget?.isDisposed) {
115
+ tracker.currentWidget?.activate();
100
116
  }
101
117
  });
102
118
  searchInstance.disposed.connect(() => {
103
- if (!notebookPanel.isDisposed) {
104
- notebookPanel.activate();
119
+ if (!tracker.currentWidget?.isDisposed) {
120
+ tracker.currentWidget?.activate();
105
121
  }
106
122
  // find next and previous are now disabled
107
123
  commandRegistry.notifyCommandChanged();
@@ -109,24 +125,27 @@ export const NotebookCommands = (commandRegistry, notebookPanel, completerHandle
109
125
  /**
110
126
  * Dispose resources when the widget is disposed.
111
127
  */
112
- notebookPanel.disposed.connect(() => {
128
+ tracker.currentWidget?.disposed.connect(() => {
113
129
  searchInstance?.dispose();
114
130
  searchModel.dispose();
115
131
  provider.dispose();
116
132
  });
117
133
  }
118
- if (!searchInstance.isAttached) {
119
- Widget.attach(searchInstance, notebookPanel.node);
120
- searchInstance.node.style.top = `${notebookPanel.toolbar.node.getBoundingClientRect().height +
121
- notebookPanel.contentHeader.node.getBoundingClientRect().height}px`;
134
+ if (searchInstance &&
135
+ tracker.currentWidget &&
136
+ !searchInstance.isAttached) {
137
+ Widget.attach(searchInstance, tracker.currentWidget?.node);
138
+ searchInstance.node.style.top = `${tracker.currentWidget?.toolbar.node.getBoundingClientRect().height +
139
+ tracker.currentWidget?.contentHeader.node.getBoundingClientRect()
140
+ .height}px`;
122
141
  if (searchInstance.model.searchExpression) {
123
142
  searchInstance.model.refresh();
124
143
  }
125
144
  }
126
- searchInstance.focusSearchInput();
145
+ searchInstance?.focusSearchInput();
127
146
  },
128
- });
129
- commandRegistry.addCommand(cmdIds.findNext, {
147
+ }));
148
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.findNext, {
130
149
  label: 'Find Next',
131
150
  isEnabled: () => !!searchInstance,
132
151
  execute: async () => {
@@ -135,8 +154,8 @@ export const NotebookCommands = (commandRegistry, notebookPanel, completerHandle
135
154
  }
136
155
  await searchInstance.model.highlightNext();
137
156
  },
138
- });
139
- commandRegistry.addCommand(cmdIds.findPrevious, {
157
+ }));
158
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.findPrevious, {
140
159
  label: 'Find Previous',
141
160
  isEnabled: () => !!searchInstance,
142
161
  execute: async () => {
@@ -145,153 +164,197 @@ export const NotebookCommands = (commandRegistry, notebookPanel, completerHandle
145
164
  }
146
165
  await searchInstance.model.highlightPrevious();
147
166
  },
148
- });
149
- commandRegistry.addCommand(cmdIds.interrupt, {
167
+ }));
168
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.interrupt, {
150
169
  label: 'Interrupt',
151
- execute: async () => notebookPanel.context.sessionContext.session?.kernel?.interrupt(),
152
- });
170
+ execute: async () => tracker.currentWidget?.context.sessionContext.session?.kernel?.interrupt(),
171
+ }));
153
172
  const sessionContextDialogs = new SessionContextDialogs();
154
- commandRegistry.addCommand(cmdIds.restart, {
173
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.restart, {
155
174
  label: 'Restart Kernel',
156
- execute: () => sessionContextDialogs.restart(notebookPanel.context.sessionContext),
157
- });
158
- commandRegistry.addCommand(cmdIds.switchKernel, {
175
+ execute: () => {
176
+ if (tracker.currentWidget) {
177
+ sessionContextDialogs.restart(tracker.currentWidget.context.sessionContext);
178
+ }
179
+ },
180
+ }));
181
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.switchKernel, {
159
182
  label: 'Switch Kernel',
160
- execute: () => sessionContextDialogs.selectKernel(notebookPanel.context.sessionContext),
161
- });
162
- commandRegistry.addCommand(cmdIds.runAndAdvance, {
183
+ execute: () => {
184
+ if (tracker.currentWidget) {
185
+ sessionContextDialogs.selectKernel(tracker.currentWidget.context.sessionContext);
186
+ }
187
+ },
188
+ }));
189
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.runAndAdvance, {
163
190
  label: 'Run and Advance',
164
191
  execute: () => {
165
- return NotebookActions.runAndAdvance(notebookPanel.content, notebookPanel.context.sessionContext);
192
+ return tracker.currentWidget
193
+ ? NotebookActions.runAndAdvance(tracker.currentWidget.content, tracker.currentWidget.context.sessionContext)
194
+ : undefined;
166
195
  },
167
- });
168
- commandRegistry.addCommand(cmdIds.run, {
196
+ }));
197
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.run, {
169
198
  label: 'Run',
170
199
  execute: () => {
171
- return NotebookActions.run(notebookPanel.content, notebookPanel.context.sessionContext);
200
+ return tracker.currentWidget
201
+ ? NotebookActions.run(tracker.currentWidget.content, tracker.currentWidget.context.sessionContext)
202
+ : undefined;
172
203
  },
173
- });
174
- commandRegistry.addCommand(cmdIds.runAll, {
204
+ }));
205
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.runAll, {
175
206
  label: 'Run all',
176
207
  execute: () => {
177
- return NotebookActions.runAll(notebookPanel.content, notebookPanel.context.sessionContext);
208
+ return tracker.currentWidget
209
+ ? NotebookActions.runAll(tracker.currentWidget.content, tracker.currentWidget.context.sessionContext)
210
+ : undefined;
178
211
  },
179
- });
180
- commandRegistry.addCommand(cmdIds.deleteCells, {
212
+ }));
213
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.deleteCells, {
181
214
  label: 'Delete Cells',
182
215
  execute: () => {
183
- return NotebookActions.deleteCells(notebookPanel.content);
216
+ return tracker.currentWidget
217
+ ? NotebookActions.deleteCells(tracker.currentWidget.content)
218
+ : undefined;
184
219
  },
185
- });
186
- commandRegistry.addCommand(cmdIds.insertAbove, {
220
+ }));
221
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.insertAbove, {
187
222
  label: 'Insert Above',
188
223
  execute: () => {
189
- return NotebookActions.insertAbove(notebookPanel.content);
224
+ return tracker.currentWidget
225
+ ? NotebookActions.insertAbove(tracker.currentWidget.content)
226
+ : undefined;
190
227
  },
191
- });
192
- commandRegistry.addCommand(cmdIds.insertBelow, {
228
+ }));
229
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.insertBelow, {
193
230
  label: 'Insert Below',
194
231
  execute: () => {
195
- return NotebookActions.insertBelow(notebookPanel.content);
232
+ return tracker.currentWidget
233
+ ? NotebookActions.insertBelow(tracker.currentWidget.content)
234
+ : undefined;
196
235
  },
197
- });
198
- commandRegistry.addCommand(cmdIds.editMode, {
236
+ }));
237
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.editMode, {
199
238
  label: 'Edit Mode',
200
239
  execute: () => {
201
- notebookPanel.content.mode = 'edit';
240
+ if (tracker.currentWidget) {
241
+ tracker.currentWidget.content.mode = 'edit';
242
+ }
202
243
  },
203
- });
204
- commandRegistry.addCommand(cmdIds.commandMode, {
244
+ }));
245
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.commandMode, {
205
246
  label: 'Command Mode',
206
247
  execute: () => {
207
- notebookPanel.content.mode = 'command';
248
+ if (tracker.currentWidget) {
249
+ tracker.currentWidget.content.mode = 'command';
250
+ }
208
251
  },
209
- });
210
- commandRegistry.addCommand(cmdIds.selectBelow, {
252
+ }));
253
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.selectBelow, {
211
254
  label: 'Select Below',
212
- execute: () => NotebookActions.selectBelow(notebookPanel.content),
213
- });
214
- commandRegistry.addCommand(cmdIds.selectAbove, {
255
+ execute: () => tracker.currentWidget
256
+ ? NotebookActions.selectBelow(tracker.currentWidget.content)
257
+ : undefined,
258
+ }));
259
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.selectAbove, {
215
260
  label: 'Select Above',
216
- execute: () => NotebookActions.selectAbove(notebookPanel.content),
217
- });
218
- commandRegistry.addCommand(cmdIds.extendAbove, {
261
+ execute: () => tracker.currentWidget
262
+ ? NotebookActions.selectAbove(tracker.currentWidget.content)
263
+ : undefined,
264
+ }));
265
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.extendAbove, {
219
266
  label: 'Extend Above',
220
- execute: () => NotebookActions.extendSelectionAbove(notebookPanel.content),
221
- });
222
- commandRegistry.addCommand(cmdIds.extendTop, {
267
+ execute: () => tracker.currentWidget
268
+ ? NotebookActions.extendSelectionAbove(tracker.currentWidget.content)
269
+ : undefined,
270
+ }));
271
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.extendTop, {
223
272
  label: 'Extend to Top',
224
- execute: () => NotebookActions.extendSelectionAbove(notebookPanel.content, true),
225
- });
226
- commandRegistry.addCommand(cmdIds.extendBelow, {
273
+ execute: () => tracker.currentWidget
274
+ ? NotebookActions.extendSelectionAbove(tracker.currentWidget.content, true)
275
+ : undefined,
276
+ }));
277
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.extendBelow, {
227
278
  label: 'Extend Below',
228
- execute: () => NotebookActions.extendSelectionBelow(notebookPanel.content),
229
- });
230
- commandRegistry.addCommand(cmdIds.extendBottom, {
279
+ execute: () => tracker.currentWidget
280
+ ? NotebookActions.extendSelectionBelow(tracker.currentWidget.content)
281
+ : undefined,
282
+ }));
283
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.extendBottom, {
231
284
  label: 'Extend to Bottom',
232
- execute: () => NotebookActions.extendSelectionBelow(notebookPanel.content, true),
233
- });
234
- commandRegistry.addCommand(cmdIds.merge, {
285
+ execute: () => tracker.currentWidget
286
+ ? NotebookActions.extendSelectionBelow(tracker.currentWidget.content, true)
287
+ : undefined,
288
+ }));
289
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.merge, {
235
290
  label: 'Merge Cells',
236
- execute: () => NotebookActions.mergeCells(notebookPanel.content),
237
- });
238
- commandRegistry.addCommand(cmdIds.split, {
291
+ execute: () => tracker.currentWidget
292
+ ? NotebookActions.mergeCells(tracker.currentWidget.content)
293
+ : undefined,
294
+ }));
295
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.split, {
239
296
  label: 'Split Cell',
240
- execute: () => NotebookActions.splitCell(notebookPanel.content),
241
- });
242
- commandRegistry.addCommand(cmdIds.undo, {
297
+ execute: () => tracker.currentWidget
298
+ ? NotebookActions.splitCell(tracker.currentWidget.content)
299
+ : undefined,
300
+ }));
301
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.undo, {
243
302
  label: 'Undo',
244
303
  execute: () => {
245
- const activeCell = notebookPanel.content.activeCell;
304
+ const activeCell = tracker.currentWidget?.content.activeCell;
246
305
  if (activeCell) {
247
- const sharedModel = activeCell.model
248
- .sharedModel;
306
+ const sharedModel = activeCell.model.sharedModel;
249
307
  if (sharedModel.undoManager) {
250
308
  sharedModel.undoManager.undo();
251
309
  }
252
310
  else {
253
311
  // Fallback to default undo if Yjs undo manager is not available
254
- NotebookActions.undo(notebookPanel.content);
312
+ NotebookActions.undo(tracker.currentWidget.content);
255
313
  }
256
314
  }
257
315
  },
258
- });
259
- commandRegistry.addCommand(cmdIds.redo, {
316
+ }));
317
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.redo, {
260
318
  label: 'Redo',
261
319
  execute: () => {
262
- const activeCell = notebookPanel.content.activeCell;
320
+ const activeCell = tracker.currentWidget?.content.activeCell;
263
321
  if (activeCell) {
264
- const sharedModel = activeCell.model
265
- .sharedModel;
322
+ const sharedModel = activeCell.model.sharedModel;
266
323
  if (sharedModel.undoManager) {
267
324
  sharedModel.undoManager.redo();
268
325
  }
269
326
  else {
270
327
  // Fallback to default redo if Yjs undo manager is not available
271
- NotebookActions.redo(notebookPanel.content);
328
+ NotebookActions.redo(tracker.currentWidget.content);
272
329
  }
273
330
  }
274
331
  },
275
- });
276
- commandRegistry.addCommand(cmdIds.changeCellTypeToCode, {
332
+ }));
333
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.changeCellTypeToCode, {
277
334
  label: 'Change Cell Type to Code',
278
- execute: args => NotebookActions.changeCellType(notebookPanel.content, 'code'),
279
- });
280
- commandRegistry.addCommand(cmdIds.changeCellTypeToMarkdown, {
335
+ execute: args => tracker.currentWidget
336
+ ? NotebookActions.changeCellType(tracker.currentWidget.content, 'code')
337
+ : undefined,
338
+ }));
339
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.changeCellTypeToMarkdown, {
281
340
  label: 'Change Cell Type to Markdown',
282
- execute: args => NotebookActions.changeCellType(notebookPanel.content, 'markdown'),
283
- });
284
- commandRegistry.addCommand(cmdIds.changeCellTypeToRaw, {
341
+ execute: args => tracker.currentWidget
342
+ ? NotebookActions.changeCellType(tracker.currentWidget.content, 'markdown')
343
+ : undefined,
344
+ }));
345
+ allCommands.add(commandRegistry.addCommand(NotebookCommandIds.changeCellTypeToRaw, {
285
346
  label: 'Change Cell Type to Raw',
286
- execute: args => NotebookActions.changeCellType(notebookPanel.content, 'raw'),
287
- });
347
+ execute: args => tracker.currentWidget
348
+ ? NotebookActions.changeCellType(tracker.currentWidget.content, 'raw')
349
+ : undefined,
350
+ }));
288
351
  function getCurrent(args) {
289
352
  return tracker.currentWidget;
290
353
  }
291
354
  function isEnabled() {
292
355
  return tracker.currentWidget !== null;
293
356
  }
294
- commandRegistry.addCommand('run-selected-codecell', {
357
+ allCommands.add(commandRegistry.addCommand('run-selected-codecell', {
295
358
  label: 'Run Cell',
296
359
  execute: args => {
297
360
  const current = getCurrent(args);
@@ -301,145 +364,146 @@ export const NotebookCommands = (commandRegistry, notebookPanel, completerHandle
301
364
  }
302
365
  },
303
366
  isEnabled,
304
- });
367
+ }));
305
368
  const bindings = [
306
369
  {
307
370
  selector: '.jp-Notebook.jp-mod-editMode .jp-mod-completer-enabled',
308
371
  keys: ['Tab'],
309
- command: cmdIds.invokeNotebook,
372
+ command: NotebookCommandIds.invokeNotebook,
310
373
  },
311
374
  {
312
375
  selector: '.jp-mod-completer-active',
313
376
  keys: ['Enter'],
314
- command: cmdIds.selectNotebook,
377
+ command: NotebookCommandIds.selectNotebook,
315
378
  },
316
379
  {
317
380
  selector: '.jp-Notebook',
318
381
  keys: ['Ctrl Enter'],
319
- command: cmdIds.run,
382
+ command: NotebookCommandIds.run,
320
383
  },
321
384
  {
322
385
  selector: '.jp-Notebook',
323
386
  keys: ['Shift Enter'],
324
- command: cmdIds.runAndAdvance,
387
+ command: NotebookCommandIds.runAndAdvance,
325
388
  },
326
389
  {
327
390
  selector: '.jp-Notebook',
328
391
  keys: ['Accel F'],
329
- command: cmdIds.startSearch,
392
+ command: NotebookCommandIds.startSearch,
330
393
  },
331
394
  {
332
395
  selector: '.jp-Notebook:focus',
333
396
  keys: ['D', 'D'],
334
- command: cmdIds.deleteCells,
397
+ command: NotebookCommandIds.deleteCells,
335
398
  },
336
399
  {
337
400
  selector: '.jp-Notebook',
338
401
  keys: ['Accel G'],
339
- command: cmdIds.findNext,
402
+ command: NotebookCommandIds.findNext,
340
403
  },
341
404
  {
342
405
  selector: '.jp-Notebook',
343
406
  keys: ['Accel Shift G'],
344
- command: cmdIds.findPrevious,
407
+ command: NotebookCommandIds.findPrevious,
345
408
  },
346
409
  {
347
410
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
348
411
  keys: ['I', 'I'],
349
- command: cmdIds.interrupt,
412
+ command: NotebookCommandIds.interrupt,
350
413
  },
351
414
  {
352
415
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
353
416
  keys: ['0', '0'],
354
- command: cmdIds.restart,
417
+ command: NotebookCommandIds.restart,
355
418
  },
356
419
  {
357
420
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
358
421
  keys: ['Enter'],
359
- command: cmdIds.editMode,
422
+ command: NotebookCommandIds.editMode,
360
423
  },
361
424
  {
362
425
  selector: '.jp-Notebook.jp-mod-editMode',
363
426
  keys: ['Escape'],
364
- command: cmdIds.commandMode,
427
+ command: NotebookCommandIds.commandMode,
365
428
  },
366
429
  {
367
430
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
368
431
  keys: ['Shift M'],
369
- command: cmdIds.merge,
432
+ command: NotebookCommandIds.merge,
370
433
  },
371
434
  {
372
435
  selector: '.jp-Notebook.jp-mod-editMode',
373
436
  keys: ['Ctrl Shift -'],
374
- command: cmdIds.split,
437
+ command: NotebookCommandIds.split,
375
438
  },
376
439
  {
377
440
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
378
441
  keys: ['J'],
379
- command: cmdIds.selectBelow,
442
+ command: NotebookCommandIds.selectBelow,
380
443
  },
381
444
  {
382
445
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
383
446
  keys: ['ArrowDown'],
384
- command: cmdIds.selectBelow,
447
+ command: NotebookCommandIds.selectBelow,
385
448
  },
386
449
  {
387
450
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
388
451
  keys: ['A'],
389
- command: cmdIds.insertAbove,
452
+ command: NotebookCommandIds.insertAbove,
390
453
  },
391
454
  {
392
455
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
393
456
  keys: ['B'],
394
- command: cmdIds.insertBelow,
457
+ command: NotebookCommandIds.insertBelow,
395
458
  },
396
459
  {
397
460
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
398
461
  keys: ['K'],
399
- command: cmdIds.selectAbove,
462
+ command: NotebookCommandIds.selectAbove,
400
463
  },
401
464
  {
402
465
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
403
466
  keys: ['ArrowUp'],
404
- command: cmdIds.selectAbove,
467
+ command: NotebookCommandIds.selectAbove,
405
468
  },
406
469
  {
407
470
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
408
471
  keys: ['Shift K'],
409
- command: cmdIds.extendAbove,
472
+ command: NotebookCommandIds.extendAbove,
410
473
  },
411
474
  {
412
475
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
413
476
  keys: ['Shift J'],
414
- command: cmdIds.extendBelow,
477
+ command: NotebookCommandIds.extendBelow,
415
478
  },
416
479
  {
417
480
  selector: '.jp-Notebook',
418
481
  keys: ['Ctrl Z'],
419
- command: cmdIds.undo,
482
+ command: NotebookCommandIds.undo,
420
483
  },
421
484
  {
422
485
  selector: '.jp-Notebook',
423
486
  keys: ['Ctrl Y'],
424
- command: cmdIds.redo,
487
+ command: NotebookCommandIds.redo,
425
488
  },
426
489
  {
427
490
  selector: '.jp-Notebook:focus',
428
491
  keys: ['M'],
429
- command: cmdIds.changeCellTypeToMarkdown,
492
+ command: NotebookCommandIds.changeCellTypeToMarkdown,
430
493
  },
431
494
  {
432
495
  selector: '.jp-Notebook:focus',
433
496
  keys: ['R'],
434
- command: cmdIds.changeCellTypeToRaw,
497
+ command: NotebookCommandIds.changeCellTypeToRaw,
435
498
  },
436
499
  {
437
500
  selector: '.jp-Notebook:focus',
438
501
  keys: ['Y'],
439
- command: cmdIds.changeCellTypeToCode,
502
+ command: NotebookCommandIds.changeCellTypeToCode,
440
503
  },
441
504
  ];
442
- bindings.map(binding => commandRegistry.addKeyBinding(binding));
443
- };
444
- export default NotebookCommands;
505
+ bindings.forEach(binding => allCommands.add(commandRegistry.addKeyBinding(binding)));
506
+ return allCommands;
507
+ }
508
+ export default addNotebookCommands;
445
509
  //# sourceMappingURL=NotebookCommands.js.map