documents.rst 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. Documents
  2. ---------
  3. JupyterLab can be extended in two ways via:
  4. - Extensions (top level): Application extensions extend the
  5. functionality of JupyterLab itself, and we cover them in the
  6. `Extensions <extension_dev.md>`__ developer tutorial.
  7. - **document widget extensions (lower level):** Document widget
  8. extensions extend the functionality of document widgets added to the
  9. application, and we cover them in this section.
  10. For this section, the term, 'document', refers to any visual thing that
  11. is backed by a file stored on disk (i.e. uses Contents API).
  12. The `Document
  13. Registry <http://jupyterlab.github.io/jupyterlab/classes/_docregistry_src_registry_.documentregistry.html>`__
  14. is where document types and factories are registered. Plugins can
  15. require a document registry instance and register their content types
  16. and providers.
  17. The `Document
  18. Manager <http://jupyterlab.github.io/jupyterlab/classes/_docmanager_src_manager_.documentmanager.html>`__
  19. uses the Document Registry to create models and widgets for documents.
  20. The Document Manager is only meant to be accessed by the File Browser
  21. itself.
  22. Document Registry
  23. ~~~~~~~~~~~~~~~~~
  24. *Document widget extensions* in the JupyterLab application can register:
  25. - widget factories
  26. - model factories
  27. - widget extension factories
  28. - file types
  29. - file creators
  30. `Widget Factories <http://jupyterlab.github.io/jupyterlab/classes/_docregistry_src_registry_.documentregistry.html#addwidgetfactory>`__
  31. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  32. Create a widget for a given file.
  33. *Example*
  34. - The notebook widget factory that creates NotebookPanel widgets.
  35. `Model Factories <http://jupyterlab.github.io/jupyterlab/classes/_docregistry_src_registry_.documentregistry.html#addmodelfactory>`__
  36. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  37. Create a model for a given file.
  38. Models are generally differentiated by the contents options used to
  39. fetch the model (e.g. text, base64, notebook).
  40. `Widget Extension Factories <http://jupyterlab.github.io/jupyterlab/classes/_docregistry_src_registry_.documentregistry.html#addwidgetextension>`__
  41. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  42. Adds additional functionality to a widget type. An extension instance is
  43. created for each widget instance, allowing the extension to add
  44. functionality to each widget or observe the widget and/or its context.
  45. *Examples*
  46. - The ipywidgets extension that is created for NotebookPanel widgets.
  47. - Adding a button to the toolbar of each NotebookPanel widget.
  48. `File Types <http://jupyterlab.github.io/jupyterlab/classes/_docregistry_src_registry_.documentregistry.html#addfiletype>`__
  49. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  50. Intended to be used in a "Create New" dialog, providing a list of known
  51. file types.
  52. `File Creators <http://jupyterlab.github.io/jupyterlab/classes/_docregistry_src_registry_.documentregistry.html>`__
  53. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  54. Intended for create quick launch file creators.
  55. The default use will be for the "create new" dropdown in the file
  56. browser, giving list of items that can be created with default options
  57. (e.g. "Python 3 Notebook").
  58. `Document Models <http://jupyterlab.github.io/jupyterlab/interfaces/_docregistry_src_registry_.documentregistry.imodel.html>`__
  59. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  60. Created by the model factories and passed to widget factories and widget
  61. extension factories. Models are the way in which we interact with the
  62. data of a document. For a simple text file, we typically only use the
  63. ``to/fromString()`` methods. A more complex document like a Notebook
  64. contains more points of interaction like the Notebook metadata.
  65. `Document Contexts <http://jupyterlab.github.io/jupyterlab/interfaces/_docregistry_src_registry_.documentregistry.icontext.html>`__
  66. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  67. Created by the Document Manager and passed to widget factories and
  68. widget extensions. The context contains the model as one of its
  69. properties so that we can pass a single object around.
  70. They are used to provide an abstracted interface to the session and
  71. contents API from ``@jupyterlab/services`` for the given model. They can
  72. be shared between widgets.
  73. The reason for a separate context and model is so that it is easy to
  74. create model factories and the heavy lifting of the context is left to
  75. the Document Manager. Contexts are not meant to be subclassed or
  76. re-implemented. Instead, the contexts are intended to be the glue
  77. between the document model and the wider application.
  78. Document Manager
  79. ~~~~~~~~~~~~~~~~
  80. The *Document Manager* handles:
  81. - document models
  82. - document contexts
  83. The *File Browser* uses the *Document Manager* to open documents and
  84. manage them.