diff --git a/.gitignore b/.gitignore index 5c6e90d..6f37390 100644 --- a/.gitignore +++ b/.gitignore @@ -123,3 +123,8 @@ dmypy.json # Yarn cache .yarn/ + +# Miscellaneous +playground/ + +.vscode/ diff --git a/jupyter_rtc_core/app.py b/jupyter_rtc_core/app.py index 7ca43be..129b1a4 100644 --- a/jupyter_rtc_core/app.py +++ b/jupyter_rtc_core/app.py @@ -13,9 +13,9 @@ class RtcExtensionApp(ExtensionApp): # this can be deleted prior to initial release. (r"jupyter-rtc-core/get-example/?", RouteHandler), # global awareness websocket - (r"api/collaboration/room/JupyterLab:globalAwareness/?", GlobalAwarenessWebsocket), + #(r"api/collaboration/room/JupyterLab:globalAwareness/?", GlobalAwarenessWebsocket), # ydoc websocket - (r"api/collaboration/room/(.*)", YRoomWebsocket) + #(r"api/collaboration/room/(.*)", YRoomWebsocket) ] def initialize(self): diff --git a/src/index.ts b/src/index.ts index ea982ca..67fa9f7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,8 +4,10 @@ import { } from '@jupyterlab/application'; import { ISettingRegistry } from '@jupyterlab/settingregistry'; - +import { IEditorServices } from '@jupyterlab/codeeditor'; import { requestAPI } from './handler'; +import { NotebookPanel } from '@jupyterlab/notebook'; +import { YNotebookContentFactory } from './notebook'; /** * Initialization data for the @jupyter/rtc-core extension. @@ -41,4 +43,24 @@ const plugin: JupyterFrontEndPlugin = { } }; -export default plugin; +/** + * The notebook cell factory provider. + */ +const factory: JupyterFrontEndPlugin = { + id: '@jupyter-rtc-core/notebook-extension:factory', + description: 'Provides the notebook cell factory.', + provides: NotebookPanel.IContentFactory, + requires: [IEditorServices], + autoStart: true, + activate: (app: JupyterFrontEnd, editorServices: IEditorServices) => { + const editorFactory = editorServices.factoryService.newInlineEditor; + return new YNotebookContentFactory({ editorFactory }); + } +}; + +const plugins: JupyterFrontEndPlugin[] = [ + plugin, + factory +]; + +export default plugins; diff --git a/src/notebook.ts b/src/notebook.ts new file mode 100644 index 0000000..d452076 --- /dev/null +++ b/src/notebook.ts @@ -0,0 +1,22 @@ +import { CodeCell, CodeCellLayout } from '@jupyterlab/cells'; +import { NotebookPanel } from '@jupyterlab/notebook'; +import { KernelMessage } from '@jupyterlab/services' + +class YCodeCell extends CodeCell { + /** + * Construct a code cell widget. + */ + constructor(options: CodeCell.IOptions) { + super({ layout: new CodeCellLayout(), ...options, placeholder: true }); + this["_output"]["_onIOPub"] = (msg: KernelMessage.IIOPubMessage) => { + const log = { ...msg.content, output_type: msg.header.msg_type }; + console.log(log) + } + } +} + +export class YNotebookContentFactory extends NotebookPanel.ContentFactory { + createCodeCell(options: CodeCell.IOptions): YCodeCell { + return new YCodeCell(options).initializeState() + } +} \ No newline at end of file