Skip to content

Commit

Permalink
Create cell widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc committed Nov 26, 2024
1 parent c05e02d commit f644370
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 8 deletions.
47 changes: 47 additions & 0 deletions packages/base/src/suggestionsPanel/cellWidget.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Cell, CodeCell, CodeCellModel } from '@jupyterlab/cells';
import {
CodeMirrorEditorFactory,
EditorLanguageRegistry
} from '@jupyterlab/codemirror';
import { ICell } from '@jupyterlab/nbformat';
import {
RenderMimeRegistry,
standardRendererFactories as initialFactories
} from '@jupyterlab/rendermime';
import { Panel } from '@lumino/widgets';
import { suggestionCellStyle } from './style';

export class CellWidget extends Panel {
constructor(options: CellWidget.IOptions) {
super(options);
this.addClass(suggestionCellStyle);
const rendermime = new RenderMimeRegistry({ initialFactories });
const languages = new EditorLanguageRegistry();
EditorLanguageRegistry.getDefaultLanguages()
.filter(language =>
['ipython', 'julia', 'python'].includes(language.name.toLowerCase())
)
.forEach(language => {
languages.addLanguage(language);
});
const factoryService = new CodeMirrorEditorFactory({
languages
});
const model = new CodeCellModel();
model.sharedModel.setSource(options.cellModel.source as string);
const cellWidget = new CodeCell({
contentFactory: new Cell.ContentFactory({
editorFactory: factoryService.newInlineEditor.bind(factoryService)
}),
rendermime,
model
});
this.addWidget(cellWidget);
}
}

export namespace CellWidget {
export interface IOptions extends Panel.IOptions {
cellModel: ICell;
}
}
16 changes: 8 additions & 8 deletions packages/base/src/suggestionsPanel/widget.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { PanelWithToolbar } from '@jupyterlab/ui-components';
import { Panel } from '@lumino/widgets';

import { ISuggestionChange, ISuggestionsModel } from '../types';
import { Panel, Widget } from '@lumino/widgets';
import { suggestionCellStyle, suggestionsWidgetAreaStyle } from './style';
import { CellWidget } from './cellWidget';
import { suggestionsWidgetAreaStyle } from './style';

export class SuggestionsWidget extends PanelWithToolbar {
constructor(options: SuggestionsWidget.IOptions) {
Expand Down Expand Up @@ -30,10 +32,9 @@ export class SuggestionsWidget extends PanelWithToolbar {
case 'added': {
const suggestion = this._model.getSuggestion({ cellId, suggestionId });
if (suggestion) {
const w = new Widget();
w.addClass(suggestionCellStyle);
const w = new CellWidget({ cellModel: suggestion.content });
w.id = suggestionId;
w.node.innerHTML = `<pre>${JSON.stringify(suggestion, null, 2)}</pre>`;
// w.node.innerHTML = `<pre>${JSON.stringify(suggestion, null, 2)}</pre>`;
this._suggestionsArea.addWidget(w);
}
break;
Expand All @@ -56,10 +57,9 @@ export class SuggestionsWidget extends PanelWithToolbar {
if (allSuggestions) {
for (const [_, val] of allSuggestions.entries()) {

Check warning on line 58 in packages/base/src/suggestionsPanel/widget.ts

View workflow job for this annotation

GitHub Actions / build

'_' is assigned a value but never used
Object.entries(val).forEach(([suggestionId, suggestionDef]) => {
const w = new Widget();
w.addClass(suggestionCellStyle);
const w = new CellWidget({ cellModel: suggestionDef.content });
w.id = suggestionId;
w.node.innerHTML = `<pre>${JSON.stringify(suggestionDef, null, 2)}</pre>`;
// w.node.innerHTML = `<pre>${JSON.stringify(suggestionDef, null, 2)}</pre>`;
this._suggestionsArea.addWidget(w);
});
}
Expand Down

0 comments on commit f644370

Please sign in to comment.