utils.ts 2.0 KB

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