-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c05e02d
commit f644370
Showing
2 changed files
with
55 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters