utils.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import { Context } from '@jupyterlab/docregistry';
  4. import { INotebookModel, NotebookPanel, Notebook, NotebookModel } from '../src';
  5. import { NBTestUtils } from '@jupyterlab/testutils';
  6. /**
  7. * Local versions of the NBTestUtils that import from `src` instead of `lib`.
  8. */
  9. /**
  10. * Create a default notebook content factory.
  11. */
  12. export function createNotebookFactory(): Notebook.IContentFactory {
  13. return new Notebook.ContentFactory({
  14. editorFactory: NBTestUtils.editorFactory
  15. });
  16. }
  17. /**
  18. * Create a default notebook panel content factory.
  19. */
  20. export function createNotebookPanelFactory(): NotebookPanel.IContentFactory {
  21. return new NotebookPanel.ContentFactory({
  22. editorFactory: NBTestUtils.editorFactory
  23. });
  24. }
  25. /**
  26. * Create a notebook widget.
  27. */
  28. export function createNotebook(): Notebook {
  29. return new Notebook({
  30. rendermime: NBTestUtils.defaultRenderMime(),
  31. contentFactory: createNotebookFactory(),
  32. mimeTypeService: NBTestUtils.mimeTypeService
  33. });
  34. }
  35. /**
  36. * Create a notebook panel widget.
  37. */
  38. export function createNotebookPanel(
  39. context: Context<INotebookModel>
  40. ): NotebookPanel {
  41. return new NotebookPanel({
  42. content: createNotebook(),
  43. context
  44. });
  45. }
  46. /**
  47. * Populate a notebook with default content.
  48. */
  49. export function populateNotebook(notebook: Notebook): void {
  50. const model = new NotebookModel();
  51. model.fromJSON(NBTestUtils.DEFAULT_CONTENT);
  52. notebook.model = model;
  53. }
  54. export const DEFAULT_CONTENT = NBTestUtils.DEFAULT_CONTENT;
  55. export const editorFactory = NBTestUtils.editorFactory;
  56. export const mimeTypeService = NBTestUtils.mimeTypeService;
  57. export const defaultEditorConfig = NBTestUtils.defaultEditorConfig;
  58. export const clipboard = NBTestUtils.clipboard;
  59. export function defaultRenderMime() {
  60. return NBTestUtils.defaultRenderMime();
  61. }