I would like to listen to cell events of JupyterLab notebooks (version 3.2.0) in a custom extension. How can I do so?
a) Searching the documentation on "events" did not give helpful information:
https://jupyterlab.readthedocs.io/en/latest/search.html?q=events&check_keywords=yes&area=default
b) Here is some outdated example I could find:
Jupyter.events.on('execute.CodeCell', function(evt, data) {
// data.cell is the cell object
});
https://github.com/jupyter/notebook/issues/2321
c) Here is another outdated code snipped:
require([
"base/js/namespace",
"base/js/events"
],
function(Jupyter, events){
console.log("hello2");
events.on('notebook_loaded.Notebook', function(){
console.log("hello3");
});
events.on('app_initialized.NotebookApp', function(){
console.log("hello4");
});
});
https://github.com/jupyter/notebook/issues/2499
d) I would expect to use something like
app.events
or
var { Events } = require('@jupyterlab/events');
However, those variants did not work.
Edit
I found another code snippet:
panel.notebook.model.cells.changed.connect((list, changed) => {
if (changed.type == 'add') {
each(changed.newValues, cellmodel => {
let cell = panel.notebook.widgets.find(x => x.model.id === cellmodel.id);
// do something with cell widget.
});
}
});
https://github.com/jupyterlab/jupyterlab/issues/4316
Maybe there is no global "event registry" any more, but the events need to be accessed via the model property?
Related:
Where is a docs for Jupyter front-end extensions JavaScript API?