@datalayer/jupyter-react 0.19.3 → 0.19.5

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 (168) hide show
  1. package/lib/app/tabs/components/NotebookComponent.js +3 -2
  2. package/lib/app/tabs/components/NotebookComponent.js.map +1 -1
  3. package/lib/components/cell/CellCommands.d.ts +1 -1
  4. package/lib/components/cell/CellCommands.js +7 -7
  5. package/lib/components/cell/CellCommands.js.map +1 -1
  6. package/lib/components/notebook/BaseNotebook.d.ts +148 -0
  7. package/lib/components/notebook/BaseNotebook.js +732 -0
  8. package/lib/components/notebook/BaseNotebook.js.map +1 -0
  9. package/lib/components/notebook/Notebook.css +13 -0
  10. package/lib/components/notebook/Notebook.d.ts +14 -16
  11. package/lib/components/notebook/Notebook.js +143 -65
  12. package/lib/components/notebook/Notebook.js.map +1 -1
  13. package/lib/components/notebook/NotebookAdapter.d.ts +7 -9
  14. package/lib/components/notebook/NotebookAdapter.js +18 -22
  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 +230 -156
  18. package/lib/components/notebook/NotebookCommands.js.map +1 -1
  19. package/lib/components/notebook/NotebookState.js +6 -6
  20. package/lib/components/notebook/NotebookState.js.map +1 -1
  21. package/lib/components/notebook/SimpleNotebook.d.ts +40 -0
  22. package/lib/components/notebook/SimpleNotebook.js +73 -0
  23. package/lib/components/notebook/SimpleNotebook.js.map +1 -0
  24. package/lib/components/notebook/cell/metadata/CellMetadataEditor.d.ts +14 -6
  25. package/lib/components/notebook/cell/metadata/CellMetadataEditor.js +35 -37
  26. package/lib/components/notebook/cell/metadata/CellMetadataEditor.js.map +1 -1
  27. package/lib/components/notebook/cell/metadata/NbGraderCells.d.ts +2 -2
  28. package/lib/components/notebook/cell/metadata/NbGraderCells.js +2 -2
  29. package/lib/components/notebook/cell/metadata/NbGraderCells.js.map +1 -1
  30. package/lib/components/notebook/cell/sidebar/CellSidebar.d.ts +28 -2
  31. package/lib/components/notebook/cell/sidebar/CellSidebar.js +64 -78
  32. package/lib/components/notebook/cell/sidebar/CellSidebar.js.map +1 -1
  33. package/lib/components/notebook/cell/sidebar/CellSidebarButton.d.ts +3 -2
  34. package/lib/components/notebook/cell/sidebar/CellSidebarButton.js +57 -72
  35. package/lib/components/notebook/cell/sidebar/CellSidebarButton.js.map +1 -1
  36. package/lib/components/notebook/cell/sidebar/CellSidebarRun.d.ts +3 -2
  37. package/lib/components/notebook/cell/sidebar/CellSidebarRun.js +14 -29
  38. package/lib/components/notebook/cell/sidebar/CellSidebarRun.js.map +1 -1
  39. package/lib/components/notebook/cell/sidebar/extension.d.ts +31 -0
  40. package/lib/components/notebook/cell/sidebar/extension.js +121 -0
  41. package/lib/components/notebook/cell/sidebar/extension.js.map +1 -0
  42. package/lib/components/notebook/cell/sidebar/index.d.ts +1 -1
  43. package/lib/components/notebook/cell/sidebar/index.js +1 -1
  44. package/lib/components/notebook/cell/sidebar/index.js.map +1 -1
  45. package/lib/components/notebook/content/JupyterReactContentFactory.d.ts +1 -12
  46. package/lib/components/notebook/content/JupyterReactContentFactory.js +4 -22
  47. package/lib/components/notebook/content/JupyterReactContentFactory.js.map +1 -1
  48. package/lib/components/notebook/index.d.ts +2 -0
  49. package/lib/components/notebook/index.js +2 -0
  50. package/lib/components/notebook/index.js.map +1 -1
  51. package/lib/components/utils/Loader.d.ts +4 -0
  52. package/lib/components/utils/Loader.js +23 -0
  53. package/lib/components/utils/Loader.js.map +1 -0
  54. package/lib/components/utils/SpinnerCentered.d.ts +2 -1
  55. package/lib/components/utils/SpinnerCentered.js +2 -2
  56. package/lib/components/utils/SpinnerCentered.js.map +1 -1
  57. package/lib/components/utils/index.d.ts +1 -0
  58. package/lib/components/utils/index.js +1 -0
  59. package/lib/components/utils/index.js.map +1 -1
  60. package/lib/examples/Bokeh.js +8 -4
  61. package/lib/examples/Bokeh.js.map +1 -1
  62. package/lib/examples/Bqplot.js +8 -4
  63. package/lib/examples/Bqplot.js.map +1 -1
  64. package/lib/examples/Dashboard.js +8 -9
  65. package/lib/examples/Dashboard.js.map +1 -1
  66. package/lib/examples/Deno.js +8 -4
  67. package/lib/examples/Deno.js.map +1 -1
  68. package/lib/examples/GeoJson.js +10 -5
  69. package/lib/examples/GeoJson.js.map +1 -1
  70. package/lib/examples/IPyLeaflet.js +8 -4
  71. package/lib/examples/IPyLeaflet.js.map +1 -1
  72. package/lib/examples/IPyReact.js +8 -4
  73. package/lib/examples/IPyReact.js.map +1 -1
  74. package/lib/examples/IPyWidgets.js +8 -9
  75. package/lib/examples/IPyWidgets.js.map +1 -1
  76. package/lib/examples/IPyWidgetsState.js +8 -9
  77. package/lib/examples/IPyWidgetsState.js.map +1 -1
  78. package/lib/examples/JupyterContext.js +20 -22
  79. package/lib/examples/JupyterContext.js.map +1 -1
  80. package/lib/examples/Matplotlib.js +8 -9
  81. package/lib/examples/Matplotlib.js.map +1 -1
  82. package/lib/examples/Notebook.js +4 -3
  83. package/lib/examples/Notebook.js.map +1 -1
  84. package/lib/examples/NotebookCellSidebar.js +4 -8
  85. package/lib/examples/NotebookCellSidebar.js.map +1 -1
  86. package/lib/examples/NotebookCellToolbar.js +11 -12
  87. package/lib/examples/NotebookCellToolbar.js.map +1 -1
  88. package/lib/examples/NotebookCollaborative.js +6 -3
  89. package/lib/examples/NotebookCollaborative.js.map +1 -1
  90. package/lib/examples/NotebookColormode.js +6 -10
  91. package/lib/examples/NotebookColormode.js.map +1 -1
  92. package/lib/examples/NotebookExtension.js +11 -12
  93. package/lib/examples/NotebookExtension.js.map +1 -1
  94. package/lib/examples/NotebookExternalContent.js +10 -12
  95. package/lib/examples/NotebookExternalContent.js.map +1 -1
  96. package/lib/examples/NotebookInit.js +5 -4
  97. package/lib/examples/NotebookInit.js.map +1 -1
  98. package/lib/examples/NotebookKernelChange.js +7 -6
  99. package/lib/examples/NotebookKernelChange.js.map +1 -1
  100. package/lib/examples/NotebookLess.js +8 -12
  101. package/lib/examples/NotebookLess.js.map +1 -1
  102. package/lib/examples/NotebookLite.js +5 -10
  103. package/lib/examples/NotebookLite.js.map +1 -1
  104. package/lib/examples/NotebookLiteContext.js +9 -10
  105. package/lib/examples/NotebookLiteContext.js.map +1 -1
  106. package/lib/examples/NotebookLocalServer.js +10 -7
  107. package/lib/examples/NotebookLocalServer.js.map +1 -1
  108. package/lib/examples/NotebookNbformat.js +8 -9
  109. package/lib/examples/NotebookNbformat.js.map +1 -1
  110. package/lib/examples/NotebookNbformatChange.js +9 -11
  111. package/lib/examples/NotebookNbformatChange.js.map +1 -1
  112. package/lib/examples/NotebookNoContext.js +4 -3
  113. package/lib/examples/NotebookNoContext.js.map +1 -1
  114. package/lib/examples/NotebookNoPrimer.js +5 -4
  115. package/lib/examples/NotebookNoPrimer.js.map +1 -1
  116. package/lib/examples/NotebookOnSessionConnection.js +7 -11
  117. package/lib/examples/NotebookOnSessionConnection.js.map +1 -1
  118. package/lib/examples/NotebookPath.js +4 -3
  119. package/lib/examples/NotebookPath.js.map +1 -1
  120. package/lib/examples/NotebookPathChange.js +9 -6
  121. package/lib/examples/NotebookPathChange.js.map +1 -1
  122. package/lib/examples/NotebookReadonly.js +6 -4
  123. package/lib/examples/NotebookReadonly.js.map +1 -1
  124. package/lib/examples/NotebookServiceManager.js +10 -14
  125. package/lib/examples/NotebookServiceManager.js.map +1 -1
  126. package/lib/examples/NotebookSkeleton.js +5 -4
  127. package/lib/examples/NotebookSkeleton.js.map +1 -1
  128. package/lib/examples/NotebookTheme.js +6 -10
  129. package/lib/examples/NotebookTheme.js.map +1 -1
  130. package/lib/examples/NotebookThemeColormode.js +6 -10
  131. package/lib/examples/NotebookThemeColormode.js.map +1 -1
  132. package/lib/examples/NotebookURL.js +4 -3
  133. package/lib/examples/NotebookURL.js.map +1 -1
  134. package/lib/examples/NotebookUnmount.js +7 -11
  135. package/lib/examples/NotebookUnmount.js.map +1 -1
  136. package/lib/examples/ObservableHQ.js +8 -4
  137. package/lib/examples/ObservableHQ.js.map +1 -1
  138. package/lib/examples/Panel.js +6 -3
  139. package/lib/examples/Panel.js.map +1 -1
  140. package/lib/examples/Plotly.js +8 -4
  141. package/lib/examples/Plotly.js.map +1 -1
  142. package/lib/examples/PyGWalker.js +8 -9
  143. package/lib/examples/PyGWalker.js.map +1 -1
  144. package/lib/examples/Vega.js +5 -4
  145. package/lib/examples/Vega.js.map +1 -1
  146. package/lib/examples/extensions/celltoolbar/CellToolbarExtension.d.ts +1 -1
  147. package/lib/examples/extensions/celltoolbar/CellToolbarExtension.js +6 -2
  148. package/lib/examples/extensions/celltoolbar/CellToolbarExtension.js.map +1 -1
  149. package/lib/examples/extensions/exectime/ExecTimeExtension.d.ts +1 -1
  150. package/lib/examples/extensions/exectime/ExecTimeExtension.js +1 -1
  151. package/lib/examples/extensions/exectime/ExecTimeExtension.js.map +1 -1
  152. package/lib/examples/sidebars/CellSidebarSource.js +56 -73
  153. package/lib/examples/sidebars/CellSidebarSource.js.map +1 -1
  154. package/lib/examples/toolbars/NotebookToolbarAutoSave.js +3 -3
  155. package/lib/examples/toolbars/NotebookToolbarAutoSave.js.map +1 -1
  156. package/lib/jupyter/collaboration/DatalayerCollaboration.d.ts +7 -2
  157. package/lib/jupyter/collaboration/DatalayerCollaboration.js +24 -1
  158. package/lib/jupyter/collaboration/DatalayerCollaboration.js.map +1 -1
  159. package/lib/jupyter/collaboration/JupyterCollaboration.d.ts +2 -2
  160. package/lib/jupyter/collaboration/JupyterCollaboration.js +3 -3
  161. package/lib/jupyter/collaboration/JupyterCollaboration.js.map +1 -1
  162. package/lib/utils/Utils.d.ts +6 -0
  163. package/lib/utils/Utils.js +9 -1
  164. package/lib/utils/Utils.js.map +1 -1
  165. package/package.json +1 -1
  166. package/lib/components/notebook/cell/sidebar/CellSidebarWidget.d.ts +0 -16
  167. package/lib/components/notebook/cell/sidebar/CellSidebarWidget.js +0 -37
  168. package/lib/components/notebook/cell/sidebar/CellSidebarWidget.js.map +0 -1
@@ -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,87 +47,105 @@ 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 commands 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(commands, completerHandler, tracker, path) {
60
+ const allCommands = new DisposableSet();
61
+ // Add commands.
50
62
  if (path) {
51
- commandRegistry.addCommand(cmdIds.save, {
63
+ allCommands.add(commands.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(commands.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(commands.addCommand(NotebookCommandIds.invoke, {
63
76
  label: 'Completer: Invoke',
64
77
  execute: () => completerHandler.invoke(),
65
- });
66
- commandRegistry.addCommand(cmdIds.select, {
78
+ }));
79
+ allCommands.add(commands.addCommand(NotebookCommandIds.select, {
67
80
  label: 'Completer: Select',
68
81
  execute: () => completerHandler.completer.selectActive(),
69
- });
70
- commandRegistry.addCommand(cmdIds.invokeNotebook, {
82
+ }));
83
+ allCommands.add(commands.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 commands.execute(NotebookCommandIds.invoke);
75
88
  }
76
89
  },
77
- });
78
- commandRegistry.addCommand(cmdIds.selectNotebook, {
90
+ }));
91
+ allCommands.add(commands.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 commands.execute(NotebookCommandIds.select);
83
96
  }
84
97
  },
85
- });
98
+ }));
86
99
  let searchInstance;
87
- commandRegistry.addCommand(cmdIds.startSearch, {
100
+ allCommands.add(commands.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
- commandRegistry.notifyCommandChanged();
123
+ commands.notifyCommandChanged();
108
124
  });
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(commands.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(commands.addCommand(NotebookCommandIds.findPrevious, {
140
159
  label: 'Find Previous',
141
160
  isEnabled: () => !!searchInstance,
142
161
  execute: async () => {
@@ -145,153 +164,207 @@ 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(commands.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(commands.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(commands.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(commands.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(commands.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(commands.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(commands.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(commands.addCommand(NotebookCommandIds.insertAbove, {
187
222
  label: 'Insert Above',
188
- execute: () => {
189
- return NotebookActions.insertAbove(notebookPanel.content);
223
+ execute: args => {
224
+ const { cellType } = (args ?? {});
225
+ const notebook = tracker.currentWidget?.content;
226
+ if (notebook) {
227
+ NotebookActions.insertAbove(notebook);
228
+ if (cellType) {
229
+ NotebookActions.changeCellType(notebook, cellType);
230
+ }
231
+ }
190
232
  },
191
- });
192
- commandRegistry.addCommand(cmdIds.insertBelow, {
233
+ }));
234
+ allCommands.add(commands.addCommand(NotebookCommandIds.insertBelow, {
193
235
  label: 'Insert Below',
194
- execute: () => {
195
- return NotebookActions.insertBelow(notebookPanel.content);
236
+ execute: args => {
237
+ const { cellType } = (args ?? {});
238
+ const notebook = tracker.currentWidget?.content;
239
+ if (notebook) {
240
+ NotebookActions.insertBelow(notebook);
241
+ if (cellType) {
242
+ NotebookActions.changeCellType(notebook, cellType);
243
+ }
244
+ }
196
245
  },
197
- });
198
- commandRegistry.addCommand(cmdIds.editMode, {
246
+ }));
247
+ allCommands.add(commands.addCommand(NotebookCommandIds.editMode, {
199
248
  label: 'Edit Mode',
200
249
  execute: () => {
201
- notebookPanel.content.mode = 'edit';
250
+ if (tracker.currentWidget) {
251
+ tracker.currentWidget.content.mode = 'edit';
252
+ }
202
253
  },
203
- });
204
- commandRegistry.addCommand(cmdIds.commandMode, {
254
+ }));
255
+ allCommands.add(commands.addCommand(NotebookCommandIds.commandMode, {
205
256
  label: 'Command Mode',
206
257
  execute: () => {
207
- notebookPanel.content.mode = 'command';
258
+ if (tracker.currentWidget) {
259
+ tracker.currentWidget.content.mode = 'command';
260
+ }
208
261
  },
209
- });
210
- commandRegistry.addCommand(cmdIds.selectBelow, {
262
+ }));
263
+ allCommands.add(commands.addCommand(NotebookCommandIds.selectBelow, {
211
264
  label: 'Select Below',
212
- execute: () => NotebookActions.selectBelow(notebookPanel.content),
213
- });
214
- commandRegistry.addCommand(cmdIds.selectAbove, {
265
+ execute: () => tracker.currentWidget
266
+ ? NotebookActions.selectBelow(tracker.currentWidget.content)
267
+ : undefined,
268
+ }));
269
+ allCommands.add(commands.addCommand(NotebookCommandIds.selectAbove, {
215
270
  label: 'Select Above',
216
- execute: () => NotebookActions.selectAbove(notebookPanel.content),
217
- });
218
- commandRegistry.addCommand(cmdIds.extendAbove, {
271
+ execute: () => tracker.currentWidget
272
+ ? NotebookActions.selectAbove(tracker.currentWidget.content)
273
+ : undefined,
274
+ }));
275
+ allCommands.add(commands.addCommand(NotebookCommandIds.extendAbove, {
219
276
  label: 'Extend Above',
220
- execute: () => NotebookActions.extendSelectionAbove(notebookPanel.content),
221
- });
222
- commandRegistry.addCommand(cmdIds.extendTop, {
277
+ execute: () => tracker.currentWidget
278
+ ? NotebookActions.extendSelectionAbove(tracker.currentWidget.content)
279
+ : undefined,
280
+ }));
281
+ allCommands.add(commands.addCommand(NotebookCommandIds.extendTop, {
223
282
  label: 'Extend to Top',
224
- execute: () => NotebookActions.extendSelectionAbove(notebookPanel.content, true),
225
- });
226
- commandRegistry.addCommand(cmdIds.extendBelow, {
283
+ execute: () => tracker.currentWidget
284
+ ? NotebookActions.extendSelectionAbove(tracker.currentWidget.content, true)
285
+ : undefined,
286
+ }));
287
+ allCommands.add(commands.addCommand(NotebookCommandIds.extendBelow, {
227
288
  label: 'Extend Below',
228
- execute: () => NotebookActions.extendSelectionBelow(notebookPanel.content),
229
- });
230
- commandRegistry.addCommand(cmdIds.extendBottom, {
289
+ execute: () => tracker.currentWidget
290
+ ? NotebookActions.extendSelectionBelow(tracker.currentWidget.content)
291
+ : undefined,
292
+ }));
293
+ allCommands.add(commands.addCommand(NotebookCommandIds.extendBottom, {
231
294
  label: 'Extend to Bottom',
232
- execute: () => NotebookActions.extendSelectionBelow(notebookPanel.content, true),
233
- });
234
- commandRegistry.addCommand(cmdIds.merge, {
295
+ execute: () => tracker.currentWidget
296
+ ? NotebookActions.extendSelectionBelow(tracker.currentWidget.content, true)
297
+ : undefined,
298
+ }));
299
+ allCommands.add(commands.addCommand(NotebookCommandIds.merge, {
235
300
  label: 'Merge Cells',
236
- execute: () => NotebookActions.mergeCells(notebookPanel.content),
237
- });
238
- commandRegistry.addCommand(cmdIds.split, {
301
+ execute: () => tracker.currentWidget
302
+ ? NotebookActions.mergeCells(tracker.currentWidget.content)
303
+ : undefined,
304
+ }));
305
+ allCommands.add(commands.addCommand(NotebookCommandIds.split, {
239
306
  label: 'Split Cell',
240
- execute: () => NotebookActions.splitCell(notebookPanel.content),
241
- });
242
- commandRegistry.addCommand(cmdIds.undo, {
307
+ execute: () => tracker.currentWidget
308
+ ? NotebookActions.splitCell(tracker.currentWidget.content)
309
+ : undefined,
310
+ }));
311
+ allCommands.add(commands.addCommand(NotebookCommandIds.undo, {
243
312
  label: 'Undo',
244
313
  execute: () => {
245
- const activeCell = notebookPanel.content.activeCell;
314
+ const activeCell = tracker.currentWidget?.content.activeCell;
246
315
  if (activeCell) {
247
- const sharedModel = activeCell.model
248
- .sharedModel;
316
+ const sharedModel = activeCell.model.sharedModel;
249
317
  if (sharedModel.undoManager) {
250
318
  sharedModel.undoManager.undo();
251
319
  }
252
320
  else {
253
321
  // Fallback to default undo if Yjs undo manager is not available
254
- NotebookActions.undo(notebookPanel.content);
322
+ NotebookActions.undo(tracker.currentWidget.content);
255
323
  }
256
324
  }
257
325
  },
258
- });
259
- commandRegistry.addCommand(cmdIds.redo, {
326
+ }));
327
+ allCommands.add(commands.addCommand(NotebookCommandIds.redo, {
260
328
  label: 'Redo',
261
329
  execute: () => {
262
- const activeCell = notebookPanel.content.activeCell;
330
+ const activeCell = tracker.currentWidget?.content.activeCell;
263
331
  if (activeCell) {
264
- const sharedModel = activeCell.model
265
- .sharedModel;
332
+ const sharedModel = activeCell.model.sharedModel;
266
333
  if (sharedModel.undoManager) {
267
334
  sharedModel.undoManager.redo();
268
335
  }
269
336
  else {
270
337
  // Fallback to default redo if Yjs undo manager is not available
271
- NotebookActions.redo(notebookPanel.content);
338
+ NotebookActions.redo(tracker.currentWidget.content);
272
339
  }
273
340
  }
274
341
  },
275
- });
276
- commandRegistry.addCommand(cmdIds.changeCellTypeToCode, {
342
+ }));
343
+ allCommands.add(commands.addCommand(NotebookCommandIds.changeCellTypeToCode, {
277
344
  label: 'Change Cell Type to Code',
278
- execute: args => NotebookActions.changeCellType(notebookPanel.content, 'code'),
279
- });
280
- commandRegistry.addCommand(cmdIds.changeCellTypeToMarkdown, {
345
+ execute: args => tracker.currentWidget
346
+ ? NotebookActions.changeCellType(tracker.currentWidget.content, 'code')
347
+ : undefined,
348
+ }));
349
+ allCommands.add(commands.addCommand(NotebookCommandIds.changeCellTypeToMarkdown, {
281
350
  label: 'Change Cell Type to Markdown',
282
- execute: args => NotebookActions.changeCellType(notebookPanel.content, 'markdown'),
283
- });
284
- commandRegistry.addCommand(cmdIds.changeCellTypeToRaw, {
351
+ execute: args => tracker.currentWidget
352
+ ? NotebookActions.changeCellType(tracker.currentWidget.content, 'markdown')
353
+ : undefined,
354
+ }));
355
+ allCommands.add(commands.addCommand(NotebookCommandIds.changeCellTypeToRaw, {
285
356
  label: 'Change Cell Type to Raw',
286
- execute: args => NotebookActions.changeCellType(notebookPanel.content, 'raw'),
287
- });
357
+ execute: args => tracker.currentWidget
358
+ ? NotebookActions.changeCellType(tracker.currentWidget.content, 'raw')
359
+ : undefined,
360
+ }));
288
361
  function getCurrent(args) {
289
362
  return tracker.currentWidget;
290
363
  }
291
364
  function isEnabled() {
292
365
  return tracker.currentWidget !== null;
293
366
  }
294
- commandRegistry.addCommand('run-selected-codecell', {
367
+ allCommands.add(commands.addCommand('run-selected-codecell', {
295
368
  label: 'Run Cell',
296
369
  execute: args => {
297
370
  const current = getCurrent(args);
@@ -301,145 +374,146 @@ export const NotebookCommands = (commandRegistry, notebookPanel, completerHandle
301
374
  }
302
375
  },
303
376
  isEnabled,
304
- });
377
+ }));
305
378
  const bindings = [
306
379
  {
307
380
  selector: '.jp-Notebook.jp-mod-editMode .jp-mod-completer-enabled',
308
381
  keys: ['Tab'],
309
- command: cmdIds.invokeNotebook,
382
+ command: NotebookCommandIds.invokeNotebook,
310
383
  },
311
384
  {
312
385
  selector: '.jp-mod-completer-active',
313
386
  keys: ['Enter'],
314
- command: cmdIds.selectNotebook,
387
+ command: NotebookCommandIds.selectNotebook,
315
388
  },
316
389
  {
317
390
  selector: '.jp-Notebook',
318
391
  keys: ['Ctrl Enter'],
319
- command: cmdIds.run,
392
+ command: NotebookCommandIds.run,
320
393
  },
321
394
  {
322
395
  selector: '.jp-Notebook',
323
396
  keys: ['Shift Enter'],
324
- command: cmdIds.runAndAdvance,
397
+ command: NotebookCommandIds.runAndAdvance,
325
398
  },
326
399
  {
327
400
  selector: '.jp-Notebook',
328
401
  keys: ['Accel F'],
329
- command: cmdIds.startSearch,
402
+ command: NotebookCommandIds.startSearch,
330
403
  },
331
404
  {
332
- selector: '.jp-Notebook:focus',
405
+ selector: '.jp-Notebook.jp-mod-commandMode :focus',
333
406
  keys: ['D', 'D'],
334
- command: cmdIds.deleteCells,
407
+ command: NotebookCommandIds.deleteCells,
335
408
  },
336
409
  {
337
410
  selector: '.jp-Notebook',
338
411
  keys: ['Accel G'],
339
- command: cmdIds.findNext,
412
+ command: NotebookCommandIds.findNext,
340
413
  },
341
414
  {
342
415
  selector: '.jp-Notebook',
343
416
  keys: ['Accel Shift G'],
344
- command: cmdIds.findPrevious,
417
+ command: NotebookCommandIds.findPrevious,
345
418
  },
346
419
  {
347
420
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
348
421
  keys: ['I', 'I'],
349
- command: cmdIds.interrupt,
422
+ command: NotebookCommandIds.interrupt,
350
423
  },
351
424
  {
352
425
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
353
426
  keys: ['0', '0'],
354
- command: cmdIds.restart,
427
+ command: NotebookCommandIds.restart,
355
428
  },
356
429
  {
357
430
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
358
431
  keys: ['Enter'],
359
- command: cmdIds.editMode,
432
+ command: NotebookCommandIds.editMode,
360
433
  },
361
434
  {
362
435
  selector: '.jp-Notebook.jp-mod-editMode',
363
436
  keys: ['Escape'],
364
- command: cmdIds.commandMode,
437
+ command: NotebookCommandIds.commandMode,
365
438
  },
366
439
  {
367
440
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
368
441
  keys: ['Shift M'],
369
- command: cmdIds.merge,
442
+ command: NotebookCommandIds.merge,
370
443
  },
371
444
  {
372
445
  selector: '.jp-Notebook.jp-mod-editMode',
373
446
  keys: ['Ctrl Shift -'],
374
- command: cmdIds.split,
447
+ command: NotebookCommandIds.split,
375
448
  },
376
449
  {
377
450
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
378
451
  keys: ['J'],
379
- command: cmdIds.selectBelow,
452
+ command: NotebookCommandIds.selectBelow,
380
453
  },
381
454
  {
382
455
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
383
456
  keys: ['ArrowDown'],
384
- command: cmdIds.selectBelow,
457
+ command: NotebookCommandIds.selectBelow,
385
458
  },
386
459
  {
387
460
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
388
461
  keys: ['A'],
389
- command: cmdIds.insertAbove,
462
+ command: NotebookCommandIds.insertAbove,
390
463
  },
391
464
  {
392
465
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
393
466
  keys: ['B'],
394
- command: cmdIds.insertBelow,
467
+ command: NotebookCommandIds.insertBelow,
395
468
  },
396
469
  {
397
470
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
398
471
  keys: ['K'],
399
- command: cmdIds.selectAbove,
472
+ command: NotebookCommandIds.selectAbove,
400
473
  },
401
474
  {
402
475
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
403
476
  keys: ['ArrowUp'],
404
- command: cmdIds.selectAbove,
477
+ command: NotebookCommandIds.selectAbove,
405
478
  },
406
479
  {
407
480
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
408
481
  keys: ['Shift K'],
409
- command: cmdIds.extendAbove,
482
+ command: NotebookCommandIds.extendAbove,
410
483
  },
411
484
  {
412
485
  selector: '.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)',
413
486
  keys: ['Shift J'],
414
- command: cmdIds.extendBelow,
487
+ command: NotebookCommandIds.extendBelow,
415
488
  },
416
489
  {
417
490
  selector: '.jp-Notebook',
418
491
  keys: ['Ctrl Z'],
419
- command: cmdIds.undo,
492
+ command: NotebookCommandIds.undo,
420
493
  },
421
494
  {
422
495
  selector: '.jp-Notebook',
423
496
  keys: ['Ctrl Y'],
424
- command: cmdIds.redo,
497
+ command: NotebookCommandIds.redo,
425
498
  },
426
499
  {
427
- selector: '.jp-Notebook:focus',
500
+ selector: '.jp-Notebook.jp-mod-commandMode :focus',
428
501
  keys: ['M'],
429
- command: cmdIds.changeCellTypeToMarkdown,
502
+ command: NotebookCommandIds.changeCellTypeToMarkdown,
430
503
  },
431
504
  {
432
- selector: '.jp-Notebook:focus',
505
+ selector: '.jp-Notebook.jp-mod-commandMode :focus',
433
506
  keys: ['R'],
434
- command: cmdIds.changeCellTypeToRaw,
507
+ command: NotebookCommandIds.changeCellTypeToRaw,
435
508
  },
436
509
  {
437
- selector: '.jp-Notebook:focus',
510
+ selector: '.jp-Notebook.jp-mod-commandMode :focus',
438
511
  keys: ['Y'],
439
- command: cmdIds.changeCellTypeToCode,
512
+ command: NotebookCommandIds.changeCellTypeToCode,
440
513
  },
441
514
  ];
442
- bindings.map(binding => commandRegistry.addKeyBinding(binding));
443
- };
444
- export default NotebookCommands;
515
+ bindings.forEach(binding => allCommands.add(commands.addKeyBinding(binding)));
516
+ return allCommands;
517
+ }
518
+ export default addNotebookCommands;
445
519
  //# sourceMappingURL=NotebookCommands.js.map